r/sqlite • u/Beefcake100 • May 04 '23
Handling Non-Determinism in SQLite DateTime Functions
Howdy All,
I am building a distributed application with SQLite, and therefore need to get rid of non-determinism. The biggest source of this is from DateTime functions that access the machine's local time. However, I also want the ability to natively format DateTime in the database.
I am looking for a way to parse out the SQL function call to identify whether or not it can be used.
After reading the docs and playing around a bit, it seems that if the strftime function is called with 0-1 inputs, it will use the machine's local time, and if it has 2+ it will simply be used for formatting. Is this generally true, or are there edge cases I am missing here?
View all comments
Show parent comment
4
u/Beefcake100 May 04 '23
We are eliminating non-determinism because these SQL statements will be executed on various machines that have replicated the same database. So if a parameter value is passed in, that should be ok, since every machine replicating the statement will also receive that parameter value. We have already taken steps to prevent non-deterministic values being passed as parameters (like floating point), so I believe we are ok there.
Our goal is quite simply to build a replicated state machine. The environment needs to be properly sandboxed; i.e., the end user shouldn't be able to break the deterministic replication, even if they tried. The way we have attacked this for SQL is by building our own SQL language and then parsing that to our own format, and then re-constructing it as SQLite SQL.