Description
I am having an issue where I cannot add tables using UNIQUE or PRIMARY KEY. This produces an disk i/o error. my DB file is on SPIFFS. I do not have an SD card, so can't test if this happens on SD.
To reproduce the issue:
- load example code sqlite3_spiffs (I can compile and run fine here, no issues) https://github.com/siara-cc/esp32_arduino_sqlite3_lib/tree/master/examples/sqlite3_spiffs
- Change the SQL command on line 102 to have either PRIMARY KEY or UNIQUE for any column
rc = db_exec(db1, "CREATE TABLE test1 (id INTEGER UNIQUE, content);");
- compile and run. Now the i/o error shows up.
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:9720
ho 0 tail 12 room 4
load:0x40080400,len:6352
entry 0x400806b8
FILE: /test1.db SIZE: 0
FILE: /test2.db SIZE: 0
FILE: /test1.db-journal SIZE: 1024
Opened database successfully
Opened database successfully
CREATE TABLE test1 (id INTEGER UNIQUE, content);
SQL error: disk I/O error
Time taken:17245
From https://www.sqlite.org/rescode.html#ioerr_write:
(778) SQLITE_IOERR_WRITE
The SQLITE_IOERR_WRITE error code is an extended error code for SQLITE_IOERR indicating an I/O error in the VFS layer while trying to write into a file on disk. This error might result from a hardware malfunction or because a filesystem came unmounted while the file was open. This error should not occur if the filesystem is full as there is a separate error code (SQLITE_FULL) for that purpose.
And here's some info on the VFS layer: https://www.sqlite.org/vfs.html
I can't figure out why adding UNIQUE to the sql would cause a disk error. Even with debugging set to verbose, I'm not getting any more information. Using the console example, I was able to get the 778 error code when entering the same CREATE TABLE sql command, but I'm stuck there. I can't seem to get any more info.
Based on the nature of the 778 error being related to the VFS layer, it seems like the issue might be in the library.
Any thoughts?