Tony: You are not the first one to notice that .paramstyle is rather an obtuse and ungainly creature. I also submitted a suggestion that introspection of the second argument to exectute() could potentially make it nearly obsolete (when there are only two alternative choices). As you have seen, that approach has been rejected by the group as "unreliable" due to "difficulties in detecting..." -- even though I have published code which shows how easy it actually is (in Python). I have also pointed out that the Python3 print() function uses this same technique. I suppose it is more challenging to do it in C code, however, and really not all _that_ useful, compared to being explicit.
On Fri, Sep 13, 2013 at 6:54 PM, Tony Locke <tlo...@tlocke.org.uk> wrote: > Hi, I'm a contributor to the PG8000 Postgres driver: > > https://github.com/mfenniak/pg8000/tree/py3 > > Having read the interesting DBAPI 3.0 wiki page: > > https://wiki.python.org/moin/DbApi3 > > I thought I'd give a suggestion for unified parameters. Apologies if > this has been suggested before, I did have a look at the archives :-) > > In DBAPI 2.0, the parameters to execute() can be a sequence or a > mapping. In DBAPI 3.0, the paramstyle attribute should be removed, and > the style determined by whether the parameters are a sequence or > mapping. For a sequence the 'numeric' style is expected, and for a > mapping the 'named' style. For example: > > execute("select * from emp where name = :1", ['horatio']) > > execute("select * from emp where name = :name", {'name': 'horatio'}) > > The reason I like this solution is that if someone asked me how > parameters work in DBAPI, this one would be the easiest to explain! > > Any thoughts? > > Cheers, > > Tony. > _______________________________________________ > DB-SIG maillist - DB-SIG@python.org > https://mail.python.org/mailman/listinfo/db-sig >
_______________________________________________ DB-SIG maillist - DB-SIG@python.org https://mail.python.org/mailman/listinfo/db-sig