Bugs item #2424606, was opened at 2008-12-13 23:02
Message generated for change (Settings changed) made by nat__
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=512945&aid=2424606&group_id=65979

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
>Status: Deleted
Resolution: None
Priority: 5
Private: No
Submitted By: Nathan Catlow (nat__)
Assigned to: Nobody/Anonymous (nobody)
Summary: sqlite3 - primary index type confusion

Initial Comment:
libdbi thinks primary index is an INTEGER and returns a long. Documentation 
states "Do not forget to use dbi_result_get_longlong() or 
dbi_result_get_ulonglong to retrieve values from columns declared as INTEGER 
PRIMARY KEY."

I think sqlite has changed/doesn't work, looking briefly at dbd_sqlite3.c it 
seems to rely on PRAGMA table_info() and look for "INTEGER PRIMARY KEY". sqlite 
seems to only return INTEGER.

$ sqlite3 testdb
SQLite version 3.6.2
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>  CREATE TABLE test(id INTEGER PRIMARY KEY, int INTEGER, bigint BIGINT);
sqlite> PRAGMA table_info(test);
0|id|INTEGER|0||1
1|int|INTEGER|0||0
2|bigint|BIGINT|0||0

So dbd_sqlite3.c (_get_row_data) ends up setting data->d_long (line 
dbd_sqlite3.c:1549).

But the call to dbi_get_ulonglong untimately returns from 
dbi_result_get_longlong_idx (from libdbi) which returns data->d_longlong 
(dbi_result.c:1004). This is a union (dbi_data_u).

On little endian this fudges though, but on big endian this is incorrect.

Getting a primary key of decimal 1 from a database;

Little Endian:

<--d_longlong--------->
<--d_long->
01 00 00 00 00 00 00 00    = decimal 1

Big Endian:

<--d_longlong--------->
<--d_long->
00 00 00 01 00 00 00 00    = decimal 4294967296

I'm not sure of the fix if you can't get sqlite to tell you what the primary 
key field is properly.

maybe an api added to libdbi, dbi_result_get_primarykey() which ensures a long 
long. (this would only be needed for databases like sqlite) but would be still 
compatible for code moving to mysql for example.

regards,

nat

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=512945&aid=2424606&group_id=65979

------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Libdbi-drivers-devel mailing list
Libdbi-drivers-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libdbi-drivers-devel

Reply via email to