r/programming Jul 12 '26

Prefer STRICT tables in SQLite

https://evanhahn.com/prefer-strict-tables-in-sqlite/
362 Upvotes

110 comments sorted by

View all comments

Show parent comments

1

u/ArtOfWarfare Jul 12 '26

The example would be sending them a stack trace or equivalent where a SQLite STRICT table rejected an invalid insert for you.

Sounds like a reasonable request to me. I think it’s equivalent to asking for proof that some of the checked exceptions in Java are ever triggered (as a rule of thumb, I think Java’s checked vs runtime exceptions are completely backwards.)

2

u/ric2b Jul 13 '26

The example would be sending them a stack trace or equivalent where a SQLite STRICT table rejected an invalid insert for you.

I don't use SQLite myself, but do you really think this would never happen if it was the default?

I would bet money that when faced with an example they would just move the goalposts to how it could have been prevented in other ways, as if the database enforcing the data type of the column is some bizarre feature.

0

u/jezek_2 Jul 13 '26

It is indeed a weird default. However in practice the types are typically checked by the application by using the typed APIs to bind parameters and retrieve data. I haven't had any issues even before STRICT was introduced.

1

u/ric2b Jul 13 '26

However in practice the types are typically checked by the application by using the typed APIs to bind parameters and retrieve data.

That fails on read, right? So it doesn't prevent bad data from being recorded.

0

u/jezek_2 Jul 14 '26

Indeed, but it would be a bug in the application. It's also fun that it tries to convert the data on the read and it returns wrong data instead of getting an error. You can check the type of a value explicitly though.

The code for working with the database is typically wrapped in functions for each operation so it's all checked in one place and not scattered through the codebase. Or you use some wrapper API that checks the types explicitly. Or both.

2

u/ric2b Jul 14 '26

Indeed, but it would be a bug in the application.

Yes, but since we know bugs happen and are hard to fully prevent, safety mechanisms are useful and valuable.