VirtualPG can't insert 64bit integer into pg tables

10 views
Skip to first unread message

Dingyuan Wang

unread,
Mar 20, 2018, 9:53:16 PM3/20/18
to SpatiaLite Users
Hi,

Using VirtualPG such as

INSERT INTO pg_table(id) VALUES (110100014258002);

where pg_table is the virtual table, which connects to a pg table with a bigint field, actually inserts a value -1472374958.

I'm using the latest version of VirtualPG/SQLite/PostgreSQL.

mj10777

unread,
Mar 20, 2018, 10:49:30 PM3/20/18
to SpatiaLite Users


On Wednesday, 21 March 2018 02:53:16 UTC+1, Dingyuan Wang wrote:
Hi,

Using VirtualPG such as

INSERT INTO pg_table(id) VALUES (110100014258002);

where pg_table is the virtual table, which connects to a pg table with a bigint field, actually inserts a value -1472374958.
(bigint = int8 = signed long) 

This is possibly caused in 2 places in the 'virtualpg.c' code where:

 sql = sqlite3_mprintf ("%d", sqlite3_value_int (argv[c2])); 

is being used.

If you can compile the code, try changing these 2 statements in

- vpgInsertRow
sql = sqlite3_mprintf ("%ld", sqlite3_value_int64 (argv[c]));

- vpgUpdateRow
sql = sqlite3_mprintf ("%ld", sqlite3_value_int64 (argv[c2]));

Everything else seems to properly support int64 (vpgSetIntValue formats from string to sqlite3_int64 value).

Hope this helps

Mark

mj10777

unread,
Mar 20, 2018, 11:38:20 PM3/20/18
to SpatiaLite Users


On Wednesday, 21 March 2018 02:53:16 UTC+1, Dingyuan Wang wrote:
Hi,

Using VirtualPG such as

INSERT INTO pg_table(id) VALUES (110100014258002);

where pg_table is the virtual table, which connects to a pg table with a bigint field, actually inserts a value -1472374958.

Dingyuan Wang

unread,
Mar 21, 2018, 12:44:09 AM3/21/18
to SpatiaLite Users
The suggested fix works correctly.

Thanks.

2018-03-21 UTC+8 10:49:30, mj10777:
Reply all
Reply to author
Forward
0 new messages