c++ - Why do sqlite columns have different names for views and tables? -
for sample database:
create table atable ( textfield varchar(256) ); create view aview select t.textfield atable t;
and these selects:
select t.textfield atable t; select t.textfield aview t;
calling sqlite's sqlite3_column_name(...)
yields different results select on view , on table. in case of table the alias not included, in case of view is.
here results:
table query - sqlite3_column_name (db, 0) -> "textfield" view query - sqlite3_column_name (db, 0) -> "t.textfield"
why these different?
surprisingly, sqlite provides no guarantees column name returned sqlite_3_column_name
unless provide name using as
keyword.
from sqlite3_column_name
function documentation:
the name of result column value of "as" clause column, if there clause. if there no clause name of column unspecified , may change 1 release of sqlite next.
therefore have manually specify column names if want depend on value returned. change queries :
select t.textfield textfield atable t; select t.textfield textfield aview t;
and in both cases sqlite3_column_name
return textfield
.
Comments
Post a Comment