Ricardo posted something that surprised me, where a field name in cursor.description would be "menu.Name" instead of "Name" when an alias wasn't specified.
Here's some sample code (non-Dabo) that shows the behavior:
import sqlite3.dbapi2 as sqlite con = sqlite.connect(":memory:") cur = con.cursor() # Ricardo, please modify the DDL below so the tables have the structure you need, with # sample data inserted into each. cur.executescript(""" create table menu (MenuId int, Name char); create table path (Id int); insert into menu (MenuId, Name) values (1, "Hijo"); insert into menu (MenuId, Name) values (2, "OtroHijo"); insert into path (Id) values (1); insert into path (Id) values (2); """) def test(sql): cur.execute(sql) rs = cur.fetchall() print "================" print sql print "field names: ", [r[0] for r in cur.description] print "result set: ", rs # Test 1: test(""" select Name from menu inner join path on path.Id = menu.MenuId group by path.Id having count(*) = 1 """) # Test 2 (this surprised me that the field name is 'menu.Name' and not 'Name'): test(""" select menu.Name from menu inner join path on path.Id = menu.MenuId group by path.Id having count(*) = 1 """) # Test 3: test(""" select menu.Name as Name from menu inner join path on path.Id = menu.MenuId group by path.Id having count(*) = 1 """)
Ok Paul, I am attaching two files, DumpMenu?.sql has a dump of my database (very small, easy to work with), ErrorSQLite.txt is code to trigger the oddity and some comments on what to look for.
Ricardo, I think we need to open a ticket. Originally, I thought we could blame sqlite, but I recrafted your test and it seems that sqlite is consistent in the naming. See my attachment which depends on your sql file.
Attachments
- dumpMenu.sql (1.8 kB) - added by raraoz on 03/05/09 14:56:11.
- ErrorSQLite.txt (2.8 kB) - added by raraoz on 03/05/09 14:57:41.
- ricardo.py (2.9 kB) -
sqlite test showing that sqlite does it consistently
, added by paul on 06/24/09 11:52:44.
