I must confess that for my purposes I'd prefer the columns to have
prefixes if prefixes were used in the query, or there is more than one
table in the query. In other words:

SELECT A.* FROM A
A.a_col, A.b_col

SELECT * FROM A
a_col, b_col

SELECT * FROM A, B WHERE A.a_col = B.b_col
A.a_col, A.b_col, B.a_col

SELECT A.*, B.* FROM A, B WHERE A.a_col = B.b_col
A.a_col, A.b_col, B.a_col

Obviously this can be overridden by using aliases:

SELECT A.a_col aa_col, A.b_col ab_col, B.a_col ba_col
aa_col, ab_col, ba_col

Regards,
Steve

-----Original Message-----
From: CARIOTOGLOU MIKE [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, January 26, 2005 10:07 AM
To: 'sqlite-users@sqlite.org'
Subject: RE: [sqlite] SQLite 3.1.0 Column Names

Ok, since this issue with column names has gone on long enough, and we
seem to be getting nowhere, I would like to propose an API change.

Here is the rationale :

Normally, a query does not need or can use "qualified" names (like
something.something). An explicit, hard-coded query knows the structure
of The result set, so it should/would not rely on column names as such.
It is only generic code, and tool-level code that worries about these
things. For example, an ODBC or OLEDB driver that uses sqlite
underneath, needs to know the column *origin*. 
Also, the semantics and current buggy implementation of the pragmas
relating to this issue, have been very frustrating to tool writers, I
believe.
So, what about this :

A. Drop the pragmas (short_column and full_column) completely. They are
stateful, which implies an extra headache for driver-level code.

B. always name the columns using short names (ie just a column name, no
qualification). If duplicate column names result in this way, either
de-dupe them by adding a numeric suffix (ID, ID_1 etc) or just leave the
duplicates alone. Higher-level code can handle this anyway.

C. Add a new API: sqlite3_column_table(idx). It should return the table
associated with a column, if it can be defined (and, by the way, it
should probably NOT return the table ALIAS, as the current
implementation of short_column_names does, but the real table name. who
cares about the alias,anyway). If not known, return NIL. 

D. nice to have : this should work for views as well, either when a view
is queried by itself, or if it is part of a join. 
In other words :

If :
Create table t1 (id,name)
Create table t2(id,name)
Create view v1 as select * from t1

Then:

Select * from v1

Gives sqlite3_column_table(0)="t1", not "v1" (and perhaps a flag leting
the user know that this came from a view)

And,

Select t2.*,v1.* from t2,v1 where t2.id=v1.id

Also returns table name of "t1" for all columns coming from v1.

I am not sure if this is doable, but it would be nice to have. Why ?
Because a resolver engine, that generates sql, can effectively make
views updateable.

This proposed change would clean up the issue with the pragmas, give
default column names that are compatible with all other sql engines I
know of,
*and* it would still give the ability to the interested user to find out
the
*origin* of a result set column.

The idea can be expanded: we could also have this api function:

Int sqlite3_column_origin(idx)

Result:
 0 = comes from table
 1 = comes from view
 2 = comes from expression

Etc etc

Why don't we vote on this issue, and if we can find enough support, try
to convince DRH to implement it ?

I, for one, am strongly in favor, since I am developing both an OLEDB
driver (which I intend to make public), and a utility (SqliteExplorer)
which would benefit a lot by such APIs, and I am sure I am not the only
one.

Reply via email to