[DB-SIG] DBAPI-2.0 clarifications

brian zimmer bzimmer@ziclix.com
Sat, 17 Mar 2001 08:28:36 -0600


This is a multi-part message in MIME format.

------=_NextPart_000_0000_01C0AEBC.4338E260
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

Federico,

Thanks for asking some of the same questions I have while writing zxJDBC (http://www.ziclix.com/zxjdbc).  Below I'll add a bit of
follow up to what you asked.

>
> Scavenging the mail folder uncovered M.-A. Lemburg's letter:
> > Federico Di Gregorio wrote:
> > >
> > >   if a db support transactions, how two cursors derived from the same
> > >   connection are supposed to see changes done to the db? if cursor A
> > >   does an insert, is cursor B supposed to see the change suddenly or
> > >   only after a commit() on the connection? imho, it would be better
> >
> > This is left undefined in the DB API spec since database usually
> > have their own specific idea about how to handle such a situation
> > (it is called transaction isolation level in the ODBC docs). The
> > transaction isolation level can be specified on a per connection
> > basis if the ODBC driver supports this.
>
> yes, i know what isolation level is. my question was about cursors
> *derived from the same connection*. now, as you say, isolation level,
> where vailable can be set on a "per connection" basis, so, are two
> cursors created from the *same* connection **required** to see the
> changes immediately or not?
>

I believe they are required to see the changes immediately.  Opening two connections is the only way to isolate the transactions.
Essentially, and please correct me if I'm wrong, a cursor is only a statement from a connection and has no transactional ability on
it's own, so the connection must handle them as all together or commit on each one.

> > >   the api is not very clear on what a "set" is. it just says that not
> > >   all db support "multiple result sets". imho, it is logical that a call
> > >   to executemany() (with a SELECT operation) produces multiple sets.
> > >   is this the right interpretation or multiple result sets are something
> > >   different? what should happen if a SELECT is passed to executemany()
> > >   and the driver does not support nextset()?
> >
> > No, .executemany() is there to allow passing multiple rows of
> > arguments to the database in one go. The statement is then executed
> > for each row of arguments binding those arguments to the parameter
> > markers.
>
> exactly as we implemented it in psycopg.
>
> > Multiple result sets refer to the output format and only comes
> > into play for stored procedure which may return multiple result
> > sets. .nextset() then switches to the next available result set.
>
> ok. now, how are multiple SELECTs derived from calling executemany()
> on a SELECT statement supposed to work? all the results should be
> concatenated into a single set? or we can extend .nextset() to cover
> this situation?

I have the same question.  Consider this example:

>>> c = db.cursor()
>>> c.execute("select b from x where id = ?", [(3,), (4,), (5,)])
>>> f = c.fetchall()

What is the expected result?  In zxJDBC it's implemented as such:

>>> print f
[(172,)]
>>> c.nextset()
>>> f = c.fetchall()
>>> print f
[(728,)]

and so on.  Or should it be:

>>> print f
[(172, 728, 827)]



> > > 5/ the description field
> > >
> > >   how are the precision and scale field to be interpreted? are the fields
>
> nobody knows what precision and scale are? i'll bet on number of significant
> digits for precision and number of digits to the right of the decimal point
> for scale, but that's *my* interpretation, and i really don't know how to
> extract both from the results the db backend sends to me.
>
> > >   mandatory? sometimes obtaining the information in the description is
> > >   plain slow (like the display_size, you have to scan every single row
> > >   in the result set) or requires accessing system tables. very few programs
> > >   use the most esoteric fields (most programs only use type_code and name.)
> > >   what about (i know that this will make people flame me) add a new method
> > >   to obtain a detailed description and put a shorter description in the
> > >   current .description field?
> >
> > These two fields can probably be safely set to None (mxODBC does
> > this), since today 132-column printers and ASCII terminals
> > for formatting result set outputs are not really relevant anymore ;-)
>
> an api specification is there to provide uniformity. the answer
> "These two fields can probably be safely set to None" is, imho, not good
> *unless* the api specifies that the two fields are optional. this is
> why i am asking all that questions and why (in the future) i will probably
> propose a little revision of the API to clarify the obscure points.
>

For what it's worth I set them to None as well.

> thank you again for your answer, ciao,
> federico
>
> p.s. a beginning of the test suite is available in the suite/ subdirectory
> of the psycopg package. the only well-implemented tests are, at now, the
> ones on type singletons (STRING, NUMBER, etc...) but i plan to have a full
> suite in a month or so. the suite will be included in psycopg 0.4.7 but
> if you want to contribute you can already get it from the cvs, see
> http://initd.org/Software/psycopg for more information on our cvs server.
>

I've included my small testing framework as an example of how I test.  I utilize PyUnit and can test just about any DB API 2.0
compliant implementation.  I essentially read an xml document describing the factory method which opens the connection and then run
the connection through any number of tests.  It works in jython as well as cpython with no additional changes.  Try changing the
sample 'test.xml' to your factory method and see if it works, I'd be quite curious.  It works perfectly well for mxODBC and zxJDBC
at the moment as both are set in the xml document.

try:

D:\home\development\src\sourceforge\zxJDBC\src\test>python runner.py test.xml

testing [mysql]
checking connection ... ok
checking simple queries with cursor.execute(), no parameters ... ok
------------------------------------------------------------------------------
Ran 2 tests in 0.230s

OK

Stay tuned for a new release of zxJDBC to coincide with some awesome changes to the Jython internals coming out with the 2.1
release.  Finn rocked!

thanks,

brian


------=_NextPart_000_0000_01C0AEBC.4338E260
Content-Type: application/x-zip-compressed;
	name="test.zip"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
	filename="test.zip"

UEsDBBQAAAAIAH0/cSrXTMacVgQAAOMKAAANAAAAc2ltcGxldGVzdC5wea1WW0/bSBR+TqX+h6Oo
FQ5yUycpoIVltSGFNrsU2FxUsQitJuNjMurY450ZQ8yv3zNjk0uBFQ+82ePvfOc713Gz2Xz7Brbh
j9LOVQafmWUzZhDGOXKRCM6soOP+xRC67cghPfrdMN6H+4VFY9t5Gd5Cp93dhW4UdT5GvY+dXejs
7vd6+509mN2LNEUNx4sc3i3tByovtbiZWwgGLWcXwZEWLIO/K/Svtdnv94JLsWhzlf62NJ7MhYFc
qxvNUqDHRCOCUYm9YxoPoFQFcKLSGAtjtZgVFkFYYFn8UWnPkKpYJKU7LLKY3Nk5gkWdGlCJf/ly
NoUvmKFmEi6KmRQcTgXHzKC3Z+TfnZo5xjArvcmJUzGuVcCJImafuwNAQd813KI2LpddT1E7qllD
UBoCZp14DSp3hi1SXIJkdmXbfjYHq1BjEJmnnqucopoTKcV5J6SEGUJhMClk6DkIDd+Hk6/n0wn0
zy7he3806p9NLg8ITc1AX/EWKy6R5lIQNcWmWWZLku8pvh2PBl/Jpn80PB1OLl0UJ8PJ2fF4DCfn
I+jDRX80GQ6mp/0RXExHF+fj4zbAGJ2wKpXPZxoSYksVJTNGy4Q0q+gvqcSGFMoY5uwWqdQcxS3p
Y8Cps15aRamyGx8roVfpPACRQKZsCHdaUOtY9bi+3n5V4xCGGW+HsPMLTJBShXAhGUf4AOPCU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