About mogrify

Oswaldo Hernández <[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
Hello,

I have a special case in i need to use mogrify() before call execute.

I try:

 >>> con = pg.connect('dbname=sc user=postgres')
 >>> sql = u"select id, desc from tabla where desc = %s"
 >>> params = ("aaa",)
 >>>
 >>> sqlmog = con.cursor().mogrify(sql, params)
Traceback (most recent call last):
   File "<input>", line 1, in <module>
NotSupportedError: unicode queries not yet supported

To solve the error (I'm using wx unicode version) i encode the sql string using the encoding used in 
the connection: 'sql = sql.encode(con.encoding)'

. Question 1:
Is this the correct way to do it?

. Question 2:
In an old message (01/30/2007) Federico says:
 > is there for DEBUG ONLY. There's really no reason to use .mogrify() directly; .execute() and
 > psycopg2.extensions.adapt() should be enough for almost any need.

It's safe the use of mogrify() directly?


Thanks.
-- 
*****************************************
Oswaldo Hernández
oswaldo (@) soft-com (.) es
*****************************************
PD:
Antes de imprimir este mensaje, asegúrese de que es necesario.
El medio ambiente está en nuestra mano.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.