[clug] Python & databases

Brendan Jurd direvus at gmail.com
Mon Feb 22 00:29:51 MST 2010

On 22 February 2010 18:12, Hal Ashburner <hal.ashburner at gmail.com> wrote:
> On 22/02/2010 5:44 PM, Brendan Jurd wrote:
>> The idea of dbapi is to provide an API that is consistent regardless
>> of which driver you're using, so I'm not sure what you're driving at
>> when you say "seems fairly backend specific".  In what sense?
> In the sense that there is so much discretion left to the implementation
> that the interface will never be consistent between different backends.
> Casts are not handled the same way between back ends,  sqlite3 uses
> different place holders to psycopg2 (eg  ? vs %s)... and so on.
> Either I'm reading it wrong or there doesn't seem to be a good way of doing
> very simple things and making it work with both backends. ie, nothing you
> list below, the resulting sql should be the same.

Right, I'm with you now.  The paramstyle thing is unfortunate.

To solve that problem, how about writing a little bit of Python to
interrogate the paramstyle [1] of the database driver you happen to be
using and put the appropriate parameter markers into your SQL?

I realise it's not a beautiful solution, but it'll do the job.


More information about the linux mailing list