On 2014/07/27 12:07, michael walsley wrote:
Why doesn't AUTOINCREMENT work like rowid, in that, with rowid if the value
on insert is not null it doesn't get a new rowid, it just accepts the value
as in the insert?
Im trying to develop a win phone app in that data downloaded from the server
needs to insert as it comes, but rows added on the phone need to use
AUTOINCREMENT, in which case the id is null and the db has to get the next
rowid?
Not sure what happens in your app, but it is likely the fault of something else... AUTOINCREMENT is merely a suggestion what to do
with a value should it not be supplied, with rowid it is implicit, but in either case you can supply the value yourself, so long as
you specify a valid one (meaning no duplicate, etc.).
So if you have this...
CREATE TABLE AutoTest (
"ID" INTEGER PRIMARY KEY AUTOINCREMENT,
"Name" TEXT
);
INSERT INTO AutoTest (Name) VALUES
('This will have ID 1'),
('And this must be ID 2');
INSERT INTO AutoTest (ID, Name) VALUES
(4, 'This should be at ID 4'),
(6, 'and this at ID 6');
INSERT INTO AutoTest (ID, Name) VALUES
(3, 'This should now be "inserted" at ID 3'),
(5, 'and this at ID 5');
SELECT * FROM AutoTest;
ID, Name
1, This will have ID 1
2, And this must be ID 2
3, This should now be "inserted" at ID 3
4, This should be at ID 4
5, and this at ID 5
6, and this at ID 6
See? No Problem.
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users