[DB-SIG] Database Abstraction in Python
james at pythonweb.org
Mon Apr 18 20:35:58 CEST 2005
>- As I understand it there is "metadata" that is needed to perform the abstraction in web.database and this is stored in the database itself.
That's right, the metadata is simply a table which tells PDBC
(web.database) what the field types are and what the table relationships
are so that it can perform correct type conversions and enforce foreign
key constraints. This isn't actually completely necessary in the
architecture because type data could be obtained from the
cursor.description object but I found that DB-API implementors tended to
change their type codes between versions so storing the information in a
table seemed an easier option.
> I'd also read somewhere that if you make some data changes to directly on the database that it might cause issues for web.database.
That's right too, if you altered the table structure externally without
updating the meta data, PDBC would get incorrect information about the
database structure. Most of the time you wouldn't want to alter a table
structure after you have created it and if you did it is easy to also
update the meta data table (just not documented yet, hence the warning
in the current documentation).
The other issue is that it is possible that a field type used by PDBC is
supported in the database engine by a field which natively accepts a
broader range of values than PDBC allows so an external program could
potentially set a value which PDBC wouldn't understand. This isn't an
issue in any of the current implementations as far as I know, I was just
thinking ahead to possible future implementations. Most of the time it
is perfectly alright to update the information from an external program.
Again, this isn't documented fully, hence the warning.
>- Just wondering about it's relationship to the web module. Is it really part of/dependant on the rest of the web module, or is it more accurately a separate database module? My preference would be separate as otherwise it seems like the implication is that it's only applicable for/suitable for web applications.
It is a separate module which grew out of my initial attempts to create
the sort of abstraction layer for the web modules which Marc-Andre was
advocating earlier in this thread. I am currently refactoring it so that
I can distribute it as a separate package named PDBC so that it can be
used with any program requiring database access, not just the web modules.
Hope that helps,
More information about the DB-SIG