You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unclear error when trying to empy a primary key cell #859
Thanks for the detailed analysis, @prutz1311! This helps a lot! 👍 There's probably no need to ask the SQLite developers, it kind of makes sense now. The column is a INTEGER PRIMARY KEY and we're trying to set it to an empty string. Usually SQLite (more or less) ignores the data type of a field but when they've built an primary key index for this column assuming it's an integer data type it only makes sense to not allow empty strings.
I've just pushed a workaround that checks for all cases in which we're trying to set an integer primary key field to an empty string, and sets the field to '0' instead. Of course you can only do this when there is no row with an ID of 0 yet.
I think the variable type in C doesn't matter for SQLite. If it's convertible to an integer it is treated as an integer, even though in C it's a char*.
There is also int sqlite3_bind_int(sqlite3_stmt*, int, int) and some others https://sqlite.org/c3ref/bind_blob.html.
Now (fd1f4f2) if I press backspace, the value changes to zero:
But if I press backspace the second time on another cell, I see another error:
@prutz1311 Thanks for the report. I'll close this, since that behaviour is expected due to the UNIQUE constraint of the primary key. It also matches Martin's expectations:
I've just pushed a workaround that checks for all cases in which we're trying to set an integer primary key field to an empty string, and sets the field to '0' instead. Of course you can only do this when there is no row with an ID of 0 yet.
Activity
prutz1311 commentedon Feb 14, 2017
This error message comes from sqlite when you are trying to empty a primary key cell (
sqlitebrowser/src/sqlitedb.cpp
Line 988 in b5345fe
Example:
gcc -o issue859 issue859.c -lsqlite3 ./issue859 prepared bound not done code: 20 datatype mismatch not finalized code: 20 datatype mismatchNever set integer primary key fields to empty string
MKleusberg commentedon Feb 15, 2017
Thanks for the detailed analysis, @prutz1311! This helps a lot! 👍 There's probably no need to ask the SQLite developers, it kind of makes sense now. The column is a
INTEGER PRIMARY KEYand we're trying to set it to an empty string. Usually SQLite (more or less) ignores the data type of a field but when they've built an primary key index for this column assuming it's an integer data type it only makes sense to not allow empty strings.I've just pushed a workaround that checks for all cases in which we're trying to set an integer primary key field to an empty string, and sets the field to '0' instead. Of course you can only do this when there is no row with an ID of 0 yet.
Does this work for you, @revolter and @prutz1311? 😃
prutz1311 commentedon Feb 16, 2017
It seems like the actual data type doesn't matter, e.g. you can insert this value:
and it will proceed just fine (an integer gets inserted).
I will check your commit later, have to go now.
MKleusberg commentedon Feb 17, 2017
I think the variable type in C doesn't matter for SQLite. If it's convertible to an integer it is treated as an integer, even though in C it's a char*.
prutz1311 commentedon Feb 17, 2017
There is also

int sqlite3_bind_int(sqlite3_stmt*, int, int)and some others https://sqlite.org/c3ref/bind_blob.html.Now (fd1f4f2) if I press backspace, the value changes to zero:
But if I press backspace the second time on another cell, I see another error:
mgrojo commentedon Oct 12, 2018
@prutz1311 Thanks for the report. I'll close this, since that behaviour is expected due to the UNIQUE constraint of the primary key. It also matches Martin's expectations: