From: Billy G. A. <bil...@mu...> - 2003-06-27 01:53:35
|
Karsten Hilbert wrote: >Dear all, > >suppose I want to find occurrences of "test" in a column >"data" in a table "testtable". SQL would be: > >select * from testtable where data='test'; > >Rewriting that for use with pyPgSQL: > >query = "select * from testtable where data=%s;" >arg = "test" >curs.execute(query, arg) > >Right ? > >However, this will produce the query: > > select * from testtable where data='test;' > >which is wrong. > >Is this a bug or am I not using pyPgSQL properly (if so it >needs to be in the docs) ? > >Thanks, >Karsten >PS: I do know how to rewrite the query so it works. I am just >wondering about the above behaviour. > > I can't seem to re-create the problem you seem to be having: $ python Python 2.2.2 (#7, Nov 27 2002, 17:10:05) [C] on openunix8 Type "help", "copyright", "credits" or "license" for more information. >>> from pyPgSQL import PgSQL >>> cx = PgSQL.connect(password='********') >>> cx.conn.toggleShowQuery 'On' >>> cu = cx.cursor() QUERY: BEGIN WORK >>> arg = '424022' >>> cu.execute('select * from a where s = %s;', arg) QUERY: DECLARE "PgSQL_0819742C" CURSOR FOR *select * from a where s = '424022';* QUERY: FETCH 1 FROM "PgSQL_0819742C" QUERY: SELECT typname, -1 , typelem FROM pg_type WHERE oid = 23 QUERY: SELECT typname, -1 , typelem FROM pg_type WHERE oid = 25 >>> cu.close() QUERY: CLOSE "PgSQL_0819742C" >>> query = "select * from a where s = %s;" >>> cu = cx.cursor() >>> cu.execute(query, arg) QUERY: DECLARE "PgSQL_081921B4" CURSOR FOR select * from a where s = '424022'; QUERY: FETCH 1 FROM "PgSQL_081921B4" >>> cu.fetchone() [152, 3, '424022'] >>> Can you provide more detail of what you were doing when the problem occured? You can show the query being sent to the backend by entering the following command: cx.conn.toggleShowQuery Where cx is the connection object. If you can send the output of a python session that shows the error, I will be able to provide more help. -- ___________________________________________________________________________ ____ | Billy G. Allie | Domain....: Bil...@mu... | /| | 7436 Hartwell | MSN.......: B_G...@em... |-/-|----- | Dearborn, MI 48126| |/ |LLIE | (313) 582-1540 | |