opensolutions / ViMbAdmin

Virtual Mailbox Administration
http://www.vimbadmin.net/
GNU General Public License v3.0
485 stars 101 forks source link

SQLite support #270

Closed slavkoja closed 2 years ago

slavkoja commented 4 years ago

I found ViMbAdmin only recently and i found note about SQLite problem on related wiki page. While i am not very experiented with PHP nor here used DB library, i want to share SQLite specific PRIMARY KEY and Null behavior.

Basically, the SQL implies NOT NULL at PRIMARY KEY fields, but SQLite doesn't follow this and behaves differently. It allows NULL values on PRIMARY KEY fields, except if NOT NULL is specified. If NOT NULL is defined, it refuses NULL values for field at all. But when field is defined as INTEGER PRIMARY KEY (without NOT NULL), it replaces NULL value on INSERT by new, unique number. The new number is not monotonic, unless the AUTOINCREMENT is defined too. But using AUTOINCREMENT is discouraged at all, because it requires more CPU and I/O and limits max row count to whole table lifetime.

See details here https://sqlite.org/autoinc.html and here https://sqlite.org/lang_createtable.html#not_null_constraints.

I tried to find, where and how is the admin table created, but i found only the vagrant-base.sql file, where the id field is defined as BIGINT(20) NOT NULL AUTO_INCREMENT and if it is related, then the NOT NULL is root of problem, which AUTOINCREMENT doesn't solve. If this schema is related, here will be needed separate schema where the primary keys will be defined as INTEGER PRIMARY KEY, to get it work (with best performance) on SQLite.

If you feel, that this is not useful, be free to close it

regards

barryo commented 2 years ago

Time out closing on this - please reopen if help still required.