On Fri, May 17, 2013 at 6:00 PM, M.-A. Lemburg <m...@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.
_______________________________________________
DB-SIG maillist  -  DB-SIG@python.org
http://mail.python.org/mailman/listinfo/db-sig

Reply via email to