Page 1 of 1

Sqlite question

Posted: Tue Oct 13, 2020 9:17 pm
by doctorized
First of all, I am not very familiar with sqlite. In a SQLite db I have defined: Grade CHAR(3) (it was supposed to store integer values 0 to 10 or a letter, like A, B, C, etc). I noticed that a value like "8.12345" or "katana" can be stored and the table doesn't seem to be altered by some overflow. How is it possible? The value stored is defined as grage.s, that means it should be stored "8.1" or "kat" and not "8.12345" or "katana". What am I missing? I did a google search but didn't help.

Re: Sqlite question

Posted: Tue Oct 13, 2020 10:20 pm
by spikey
SQLite accepts types in schemas but doesn't rigidly enforce them in queries and updates.
If you insert/update something that doesn't match the column's defined type - it can and will store it without complaint.
If you want to impose rigid type definitions your application must implement them.
The only exception is an INTEGER PRIMARY KEY column, which is an alias for the internal RowID and must be enforced.

See https://www.sqlite.org/datatype3.html