I just started messing around with SQLite recently (about a week now), and I'm 
pretty thrilled with the results so far.� One of the first things I started 
working on was an ADO.NET 2.0 data provider for it.��There's mainly just one 
little stumbling block I'm trying to fix.� For any given SELECT statement, I 
need to yank out the detailed schema information for all table-bound columns 
returned in the resultset.

The simplest thing I found I could manage in hacking SQLite was adding a new 
pragma called "real_column_names" which sets the FullColNames to 1 and adds 
another flag for RealColNames.� I then�made a change to generateColumnNames() 
around line 781:

From:
��� if( pEList->a[i].zName ){

To:
��� if( pEList->a[i].zName && (realNames == 0 || p->op != TK_COLUMN)){

So�given SELECT A.ID As C, B.ID As D FROM Foo As A INNER JOIN Bar As B ON C = D 
LIMIT 1

The column names given back are Foo.ID and Bar.ID.� Given that, I can then 
query each table for its schema and obtain the primary key information etc 
needed to build dynamic queries.

BTW: full_column_names is still broken.� Before I added this new pragma a 
SELECT * FROM Foo with full_column_names set to 1 would still only return the 
base column name.� Primarily because at line 781 in generateColumnNames, the 
zName is populated for columns expanded from a * in a select.

Anyway ... without this little hack, it'd be impossible short of rewriting a 
SQL parser to determine from that SELECT example what underlying columns and 
tables were used.

So I'm wondering, is this useful to anyone else, or is there an easier way to 
do this?

Robert Simpson
Programmer at Large

Reply via email to