[Tutor] overview of how data is handled

orbitz at ezabel.com orbitz at ezabel.com
Wed May 19 00:22:50 EDT 2004

I am confused about what your question is.  dbapi2.0 compliant modules return
your object in some sort of list like object, either a tuple or a list. (it is
iterable atleast).

The DB-API 2.0 document says this about getting a dict object:
    The database SIG often sees reoccurring questions about the DB API
    specification. This section covers some of the issues people
    sometimes have with the specification.


       How can I construct a dictionary out of the tuples returned by


       There are several existing tools available which provide
       helpers for this task. Most of them use the approach of using
       the column names defined in the cursor attribute .description
       as basis for the keys in the row dictionary.

       Note that the reason for not extending the DB API specification
       to also support dictionary return values for the .fetchxxx()
       methods is that this approach has several drawbacks:

       * Some databases don't support case-sensitive column names or
         auto-convert them to all lowercase or all uppercase
       * Columns in the result set which are generated by the query
         (e.g.  using SQL functions) don't map to table column names
         and databases usually generate names for these columns in a
         very database specific way.

       As a result, accessing the columns through dictionary keys
       varies between databases and makes writing portable code

I didn't bother looking up what these helper tools are but then again I wasn't
that interested.

Usually you know how many columns your result has so just using the index is not
very difficult.

On Tue, 18 May 2004 20:00:39 -0700
John Fabiani <jfabiani at yolo.com> wrote:

> Hi,
> First let me say that the books and all the online tutorials (that I 
> have seen) do not address how to handle data retrieved from a SQL 
> database. They explain how to get the data but not how the data is to be 
> handled after it is retrieved.   It appears from what I have read and my 
> experiments that the data needs to be in a dict form.  OK I was able to 
> convert the data into a dict.  But doing so required many lines of code 
> (two loops).  If the program has to convert from list into dict for 
> ten's of thousands of records it is going to be very  slow. 
> The handling of data is like nothing I have ever done.  It's nothing 
> like Delphi, Java, .Net or VFP.  Therefore, I think I wrong in the way I 
> am thinking about how data is to be handled.  So can someone provide an 
> over view of how they believe data should be handled in a data centered 
> application - i.e data entry with grids, preparing reports for viewing 
> or printing etc....
> Thanks
> John
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

More information about the Tutor mailing list