I have table with INTEGER PRIMARY KEY and I cannot insert value greater then 2147483647 as a key. Is it possible to increase this value somehow?
UPDATE:
Ok, I have php script:
<?php
$sqlite_db = new SQLite3('test');
$sqlite_db->exec('CREATE TABLE test (n UNSIGNED INTEGER)');
$ns = array(1111111111,2222222222,3333333333,4444444444,5555555555,6666666666,7777777777);
foreach ($ns as $n)
{
$statement = $sqlite_db->prepare('INSERT INTO test (n) VALUES (:n)');
$statement->bindValue(':n', $n, SQLITE3_INTEGER);
$statement->execute();
}
$sqlite_db->close();
?>
and what I get in test database is that:
root@localhost:~# sqlite3 test
SQLite version 3.7.3
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> select * from test;
1111111111
-2072745074
-961633963
149477148
1260588259
-1923267926
-812156815
So my question is: how to insert large values into sqlite database from php?
UPDATE2:
I have changed foreach body to:
$sqlite_db->exec("INSERT INTO test (n) VALUES ({$n})");
and it works ok now.
I’ve never seen that behavior with SQLite3. Edit your question, and paste the output of
.schema your-table-name. Also, make sure the problem isn’t in your application code.Declaring a column as integer in SQLite works differently than declaring a column as integer in a true SQL dbms. In SQLite3, any column declared
INTEGER PRIMARY KEYought to accept any 64-bit, signed integer. 64-bit integers max go to 1.84467441 × 1019. (Your column should accept negative integers, too.)So, it automatically increments . . .
And it accepts the maximum value of a 32-bit signed integer.
And it increments past the maximum value of a 32-bit signed integer.
It accepts values in the range of 233.
And it continues to automatically increment.