Thank you all for your replies! Good to hear that this actually is sort of a
sane behaviour. I think I wasn't fully aware of the fact that the primary key
and the rowid column actually are *exactly* the same - it does make sense that
way though.
Thankfully I'm not relying on the column names but was working on a SQLite GUI
and wondered why I got the same column name twice after executing that SELECT
statement. It is good to know, however, better not to start relying on the
column names at all; so this is definitely a valuable piece of advice I got
here :)
Martin
On Thursday 03 July 2014 23:22:46 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:
>
> $ 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:
>
> #include <stdio.h>
> #include "sqlite3.h"
>
> int main()
> {
> sqlite3* db;
> if(sqlite3_open_v2("test.db", &db, SQLITE_OPEN_READONLY, NULL))
> return 1;
>
> sqlite3_stmt* stmt;
> int status = sqlite3_prepare_v2(db,
> "SELECT rowid,*
> FROM test",
> -1,
> &stmt,
> NULL);
> if(status == SQLITE_OK)
> {
> status = sqlite3_step(stmt);
> int columns = sqlite3_data_count(stmt);
> int i;
> for(i=0;i<columns;i++)
> printf("column #%d: %s\n", i+1,
> sqlite3_column_name(stmt, i));
> } else {
> return 2;
> }
> sqlite3_finalize(stmt);
>
> sqlite3_close(db);
> return 0;
> }
>
> 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 :)
>
> Cheers
> Martin
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users