[DB-SIG] db-api suggestions / zike data classes

Michal Wallace (sabren) sabren@manifestation.com
Fri, 14 Apr 2000 02:14:31 -0400 (EDT)


Hello Everybody :)

   I'm attempting to build an abstraction layer on top of the DB-API,
that gives an object-oriented interface to individual records. Here's
an example:


##################################

import someDBAPIcompliantModule
dbc = someDBAPIcompiantModule.connect("blah blah")

import zdc.Record
rec = zdc.Record(dbc, "myTable")

rec.new()
rec["name"] = "Michal"
rec["age"] = 23
rec.save()


rec.select(name="Fred")
print "Fred is " + rec["age"] + "years old."
# or:
print "Fred is " + rec[1] + "years old."

##################################


  I've actually gotten most of it done (coming soon to sourceforge),
but I've hit a couple snags because some things a scheme like this
needs are missing from the (otherwise excellent) API.  Anyway, I
thought I'd bounce some ideas off the group:

-----------------------
 module - agnosticism
-----------------------

  First, if I'm just looking at some random connection object, and I
use it to create a cursor object... How can I get the fieldtypes out
of the description? The fieldtypes are arbitrary values that have to
be compared against something back in the module's namespace... But
since this is a random connection object, *I don't know what module
to look in!!!*

  I'm testing with MySQLdb and ODBC.Windows. With MySQLdb, the task
is simple: module = dbc.__class__.__module__ ... But with ODBC.Windows,
and (I suspect) any other pure C/C++ module, there IS no .__class__
attribute.

  My workaround for ODBC.Windows was to create a wrapper class/module
in python (which also brings ODBC.Windows quite a bit closer to the
DB-API 2.0 standard)... But wouldn't it be nicer if either

   a) all Connection objects had to have a .__class__ , or:
   b) STRING, NUMBER, etc were part of the Connection class?


-----------------------
  autonumbers
-----------------------

  Suppose I have an autonumber / auto_increment / whatever field. I
run an INSERT statement. How do I get the generated number? As far
as I can tell, I have to use a module-specific function call. Wouldn't
this be a fairly useful process to standardize?


-----------------------
  table names
-----------------------

  I personally don't have any particular need for this at the moment,
but I'm sure it would be nice to have down the line: dbc.tables() to
give a list of tables?  Possibly even dbc.queries() or dbc.sprocs()
for providers that had queries and stored procedures.. I'm guessing
most modules have something like this already, but it's no fun without
a standard. :)





  Anyway, I'm probably going to come up with a proposal for actual
syntax and stuff, and make some wrapper modules just to get my classes
working for now, but I'd really like to talk about the issues involved
in updating the standard. (I'm willing to help code changes, too, btw)

Cheers,

- Michal
-------------------------------------------------------------------------
http://www.manifestation.com/         http://www.linkwatcher.com/metalog/
-------------------------------------------------------------------------