On 2014/07/03 23:22, Martin Kleusberg wrote:
Hi everybody,
I've encountered some odd behaviour when using the sqlite3_column_name
function. Here's my attempt to build a minimal example.
Part 1: The database. Note that the table is not a 'without rowid' table and
has a primary key:
The output of this program is:
column #1: id
column #2: id
column #3: bla
However, I'd have expected the following:
column #1: rowid
column #2: id
column #3: bla
Other answers describe the notion of column name accuracy and is valid in the regard and moreover essentially why it ISN'T a bug at
all, so I will just quickly elaborate on WHY SQLite is showing you what it does:
When you make a column in a table that is defined as "INTEGER PRIMARY KEY" it becomes immediately an alias for the rowid (it has
other aliases even) and so there are not 2 physical columns or datasets, but just 1 and now that 1 is named: "id".
SQLite returns what it has inside the table based on what you asked for, but there is no reason it should or would return the exact
name of what you asked for, just the exact data, and since it now knows that column as "id" there is no reason why it should return
it as anything else - unless of course, you added a specification for what you wish it to return using "AS", which changes things
dramatically and now SQLite (or any SQL engine really) is bound by law to return it exactly "AS" requested.
The fact that it returns the real column name mostly is a convention in SQLite and most other Engines and one that can be trusted
mostly, if it tests correct today, it should do the same tomorrow. But if ever you need a guaranteed specific name for a column
returned, i.e. id the data destination depends on that name being exact, then you should always specify the AS heading.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users