It happens that the statement "there is no reliable way to distinguish a
mapping from a sequence" is not true.  I submit the following example.

 Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]
> on win
> 32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from collections import Mapping
> >>> seq = [1, 2]
> >>> map = {'one':1, 'two':2}
> >>> params = seq
> >>> isinstance(params, Mapping)
> False
> >>> params = map
> >>> isinstance(params, Mapping)
> True
> >>>
>

The  current production version of adodbapi
<http://sf.net/projects/adodbapi> does exactly what Tony proposes, if the
programmer sets the paramstye to "dynamic".  Yes, it does work reliably.  I
challenge anyone who claims otherwise to prove their assertion.



On Mon, Sep 16, 2013 at 4:15 AM, Dieter Maurer <die...@handshake.de> wrote:

> Tony Locke wrote at 2013-9-13 18:54 +0100:
> > ...
> >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?
>
> This has been suggested and found one objection: there is no reliable
> way to distinguish a mapping from a sequence -- or put in
> different words: it is easy to define a class which supports both
> the sequence as well as the mapping protocol.
>
>
>
> --
> Dieter
> _______________________________________________
> 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

Reply via email to