On Thu, 03 Jul 2014 23:22:46 +0200, Martin Kleusberg
<mkleusb...@gmail.com> wrote:

> 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:
>
> $ sqlite3 test.db
> create table test(id integer primary key, bla integer);
> insert into test(bla) values(5);
> .quit
>
> Part 2: A C program using the sqlite3_column_name function
> to determine the column names of the result set of a statement:

[snip]

>  "SELECT rowid,* FROM test",

[snip]

> 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
>
> I've tested this using the latest version of SQLite, i.e. 3.8.5, and did a 
> (admittedly very quick) search but couldn't find anything.
>
> If there's any required information I didn't provide or any
> sane explanation please let me know :)

My explanation:
By stating id INTEGER PRIMARY KEY, you aliased ROWID to id.
In this case there is no separate ROWID column, id takes its place.

Whenever you use ROWID for this table, you will get the value of id,
in the internal schema stucture, only one name can be stored, and a
separate (implicit, not aliased) ROWID column will be hidden, yet
accessible.

Without INTEGER PRIMARY KEY, the ROWID is still there, but it is hidden.
Check it with PRAGMA table_info(test);
You will see the id column, never a ROWID column.

I think this behaviour is consistent with
http://sqlite.org/lang_createtable.html#rowid
, and the naming you observe reminds you of the role of id in the table.

-- 
Groet, Cordialement, Pozdrawiam, Regards,

Kees Nuyt

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to