How to set the ABORT option in SQLite from Tcl when violating NOT NULL constraint

StackOverflow https://stackoverflow.com/questions/18768006

  •  28-06-2022
  •  | 
  •  

Question

I have a TCL script where i generate a SQLite table:

DB eval {CREATE TABLE StressDat2( LC int NOT NULL, EID int NOT NULL, Xtens float, Ytens float ) } 

When I try to write NULL values they get accepted anyhow. How can I from Tcl, when generating my table, set the ABORT option which shall handle writing attempts of NULL values?

Était-ce utile?

La solution

The Xtens and Ytens columns do not have a NOT NULL constraint. (The default conflict resolution algorithm is ABORT; you don't need to set it.)

Autres conseils

It depends on how do you insert data into the table. If you also do it with Tcl, you need to be aware, that Tcl doesn't understand the idea of NULL value.

Therefore, this is WRONG:

set lc ""
set eid ""
set xtens ""
set utens ""
DB eval {INSERT INTO StressDat2 (LC, EID, Xtens, Ytens) VALUES ($lc, $eid, $xtens, $ytens);

You're obviously inserting empty strings, not null values. To insert null, use null keyword in SQL statement.

This is CORRECT:

DB eval {INSERT INTO StressDat2 (LC, EID, Xtens, Ytens) VALUES (NULL, NULL, NULL, NULL);

Finally, a word about "ABORT" conflict resolution in NOT NULL constraint, that you mentioned. You said this is blank in SQLiteStudio and not "ABORT", as you would like to. Well, the "ABORT" algorithm is a default algorithm used by sqlite when no algorithm was defined, so even you have it blank (default), it means it's "ABORT". Read this for more details: http://sqlite.org/lang_createtable.html

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top