<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal>Hello all,<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>I have been attempting to integrate PyGreSQL&#8217;s DBAPI
compliant module as the database driver for SQLAlchemy.&nbsp; After initial
searching, I found that you can pass the driver as the &#8220;module&#8221; argument
when initializing SQLAlchemy, and that this was the way to get it to start
working with PyGreSQL.&nbsp; <o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>The only Python PostgreSQL driver that SQLAlchemy
&#8220;supports&#8221; is Psycopg2, but I am unable to use that library due to
its license restrictions, and I have been using PyGreSQL for quite some time
now, so it&#8217;s a much more attractive alternative.<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>I had been attempting to write the code using Psycopg2 as
the Postgres driver for SQLAlchemy and was able to reflect my schema without
hang-ups, but wanted to try using PyGreSQL.&nbsp; My first attempt at replacing
the driver and reflecting my schema resulted in the following error:<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>&#8220;sqlalchemy.exc.OperationalError: (OperationalError)
internal error in 'BEGIN': not all arguments converted during string formatting
'select current_schema()' [None]&#8221;.<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>Obviously, this is not in the PyGreSQL code, so I chased
this error down the stack trace to the method Connection_<i>cursor</i>_execute()
method in base.py (SQLAlchemy).&nbsp; I changed the exception that is caught there
to look into exactly what is happening, and then ran my code again, resulting
in an error being thrown in PyGreSQL:<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>&#8220;pg.OperationalError: internal error in 'BEGIN': not
all arguments converted during string formatting&#8221;<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>I chased this error to where it was being raised, which was
in lines 290-291 in pgdbCursor.executemany() method in pgdb.py.&nbsp; I removed
the exception handling so I could further find where things were going
wrong.&nbsp; I found that the error in question was:<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>&#8220;TypeError: not all arguments converted during string
formatting&#8221;<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>This was occurring at line 222 in pgdb.py in the method
pgdbCursor._quoteparams().&nbsp; After some more inspection, I found that the
params argument was a list containing only the value None, that is,
[None].&nbsp; I added a check at the beginning of that method for this value:<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>if params == [None]:<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
return string<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>After this change, my code functioned exactly the same as
when I was working with Psycopg2, and I&#8217;ve been running fine for about a
month of work. <o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>My question is whether or not this is something that is OK
to change, as I am not familiar with the inner workings of PyGreSQL and wanted
to see if there are any repercussions of this change that I could potentially
be missing.<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>I am using Python 2.5.4, working on Windows XP SP 2,&nbsp;
Using SQLAlchemy 0.5.6 and the latest stable version of PyGreSQL.<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>Thanks in advance,<o:p></o:p></p>

<p class=MsoNormal>Mike<o:p></o:p></p>

</div>

</body>

</html>