[DB-SIG] API 3.0 limiting paramstyle to ['named', 'qmark'] is okay. ('format' is not desirable)

Vernon D. Cole vernondcole at gmail.com
Fri May 17 19:30:34 CEST 2013

On Fri, May 17, 2013 at 6:00 PM, M.-A. Lemburg <mal at egenix.com> wrote:

> > IMHO it is explicit, whether you say:
> >
> > cursor.execute(stmt, { < dictionary>} )
> >
> > vs.
> >
> > cursor.execute(stmt, [ <list>] )
> >
> > the type of parameters passed indicates the style of params to search
> for.   It's explicit via type inference.    if a dictionary is passed, "?"
> symbols are left alone.  If a list is passed, ":param" symbols are left
> alone.  If neither is passed, then neither ? nor :param are searched for.
> Hmm, then how do you tell whether this code is correct or not ? :-)
> cursor.execute('select * from mytable where id=?', parameters)
> Type inference also doesn't help universally, since objects can
> easily implement both the sequence and mapping ABC.

I don't need to "tell whether the code is correct".  I am not writing a
compiler -- just acting on what my user tells me to do.  This happens at
run time, so I will know at that moment whether the parameters passed to me
have keys or not.  If there are keys, I will run my "named-to-qmark"
converter.  If not, I will hand off the command as is (since my target
engine expects qmark).  There is no guess work here. Try for a key (and use
'named').  No key? Use the sequence (and use qmark). No sequence? Send the
command as is.

If the SQL engine complains about the result, tell the user.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/db-sig/attachments/20130517/c1f573e9/attachment.html>

More information about the DB-SIG mailing list