Re: quoting - bug ?

Karsten Hilbert <[email protected]> Fri, 27 Jun 2003 10:48:57 +0200
Newsgroups gmane.comp.python.db.pypgsql.user
Message-ID <[email protected]>
Billy,

I am CC'ing this to the one of our developers who experienced
the problem (under Debian unstable, with Python 2.2.*).

He may be able to provide more detail.

Regards,
Karsten

Ian, this is what I posted:
>> 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) ?

> 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.
-- 
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346


-------------------------------------------------------
This SF.Net email is sponsored by: INetU
Attention Web Developers & Consultants: Become An INetU Hosting Partner.
Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission!
INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php