Re: SQL interface standard

Jim Fulton (jfulton@disqvarsa.er.usgs.GOV)
Fri, 3 Feb 1995 19:37:41 GMT

>>>>> "C" == C Derek Fields <derek@gamekeeper.bellcore.com> writes:
In article <199502031505.AA12145@marcel.gamekeeper.bellcore.com> "C. Derek Fields" <derek@gamekeeper.bellcore.com> writes:

> I would like to get a sense of how many of you are interested in working
> on a standard interface to SQL-based RDMBSs. I know of at least 4 different
> modules, each of which provides a different interface. I have written
> my own for Oracle, but have not made it publicly available. Among
> the issues that I have struggled with are:

> 2) How should rows returned from the database be represented. My interface
> uses a dictionary, where the key is a string with the column name. However,
> I toyed with just using a list of values and providing the column names
> as a list returned by a separate method. Another approach is to have
> a Row object that hides the representation.

I think the row/tuple object is best. I use Tuple objects that use a
list to hold each row of data. The tuple object has a reference to a
tuple_header object that has meta data such as a list of column names
(for mapping indexes to names), a dictionary for mapping column names
to indexes), and a list of column types. I also have flavors of
tuples that use __getattr__ to allow things like tuple.column_name.

> 3) Should a select return a cursor object that is interrogated for the
> rows? My implementation does not do this. I return one row at a time,
> though internally, I fetch into an array for speed. I am not sure
> that there is any advantages to a cursor at the Python level and I am
> certain that fetching ALL rows from a query automatically can cause
> serious memory concerns

I think the cursor solution is best. I currently use a table object
that acts like a cursor. This object only gets one row at a time. It
keeps a counter that keeps track of the current row number. I support
a getitem operator that has the semantics:

given table[index]:

if index == 0:
Reset the cursor, fetch the first row and return it
if fetch of first row fails:
raise IndexError
elif index == current_row:
Return the most recently fetched tuple
elif index == current_row + 1:
Try to get a new row.
if successful:
increment current row and return the new tuple
else:
raise IndexError
else:
raise IndexError

This allows the use of tables in for loops:

for tuple in table:
...some code that uses a tuple of data...

> 5) How should database-generated error messages be passed back to the
> user? I provide a method to get at the information in the sqlca structure
> but the only exception I return is 'oracle.error'

Raise an exception.

--
-- Jim Fulton      jfulton@mailqvarsa.er.usgs.gov    (703) 648-5622
                   U.S. Geological Survey, Reston VA  22092 
This message is being posted to obtain or provide technical information
relating to my duties at the U.S. Geological Survey.