I seem to misunderstand a basic syntax, why this sample works:
sqlite3_prepare_v2(db, "insert into test values('boo','boo',0);", strlen(querystring)+1 , &stmt, NULL);
if ((rc = sqlite3_step(stmt)) != SQLITE_DONE)
fprintf(stderr, "Error: sqlite3_step() %d. Error Message %s;\n",rc,sqlite3_errmsg(db));
But when I try this query:
“insert into test(strtest) values(‘boo’);”
I get an error:
Error: sqlite3_step() 19. Error Message constraint failed;
What am I missing?
table test is: “create table test (blobtest BLOB(4) NOT NULL, strtest VARCHAR NOT NULL, inttest INTEGER NOT NULL );”
Thanks,
Doori Bar
All three columns are declared as
NOT NULL, and they do not have a default value.So your query:
Is only assigning
blobtesta value, leaving outstrtestandinttestwhich cannot be null.You can fix this by either adding two more values, or you can change the table schema to default to something, e.g.:
(or you could take out
NOT NULLif you would like them to beNULL-able)