Re: apsw: Wrapping Results into a Key/Value dictionary
Roger Binns <[email protected]>
| Newsgroups | gmane.comp.python.db.pysqlite.user |
|---|---|
| Message-ID | <[email protected]> |
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Franz Buchinger wrote: > Unfortunately there is no binding in the opposite direction, meaning > when you SELECT data, there is no elegant way to build a result > tuple/dictionary in the form result[row#][columnname] = value. It is perfectly legal for there to be multiple columns with the same name, and lots of fun issues when the columns come from different tables (there are various pragmas to include/exclude the table name along with the column name). In both pysqlite and apsw you are able to control how rows are returned. For apsw you can use the row tracer to munge each row into anything you want. However I recommend you wrap a cursor as a whole. That way you can issue whatever pragmas you want, and then use the (get)description function/property to get the field names for each row. You can also use the cursor to get more detailed table information such as the pragmas that tell you about the schema, primary keys etc. > As I want to pass on the resulting data to my template system, I am > looking for a way to build such dictionaries for arbitrary tables/queries. You may also want to consider higher level libraries such as SQLObject which abstract all this stuff out for you. Roger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFGER/kmOOfHg372QQRAiAUAJ92C66k4yEc8vz+NdvZS3pOz4U6lwCeNrCE bPdIJEzOtbSLPkqWvbubv9Q= =Edbi -----END PGP SIGNATURE-----