Author: Uranus Zhou

SQLite error in lighttpd

Currently I am using lighttpd’s WebDAV plugin to provide file service, while I encountered very strange SQLite database error, here is the error message: (mod_webdav.c.2182) sql-set failed: SQL logic error or missing database(mod_webdav.c.2182) sql-set failed: not an error(mod_webdav.c.2182) sql-set failed: not an error(mod_webdav.c.2182) sql-set failed: not an error(mod_webdav.c.2182) sql-set failed: not an error(mod_webdav.c.2182) sql-set failed: not an error(mod_webdav.c.2182) sql-set failed: not an error(mod_webdav.c.2182) sql-set failed: not an error(mod_webdav.c.2511) remove lock: bind or column index out of range(mod_webdav.c.2511) remove lock: bind or column index out of range(mod_webdav.c.2511) remove lock: bind or column index out of range Let’s check the SQLite processing code in 'mod_webdav.c' of lighttpd: lighttpd use SQLite’s 'sqlite3_bind_text' and 'sqlite3_step' function to bind data and do database operation. Now we can check opening SQLite database and creating SQL statement code in mod_webdav.c of lighttpd: We can see lighttpd open SQLite database first, create 'properties' table, use 'sqlite3_prepare' function to create SQL statement, then create 'locks' table, also use 'sqlite3_prepare' function to create SQL statement about 'locks' table. 'sqlite3_prepare' function can be used to convert SQL string to SQLite bytecode, we can avoid lots of duplicate SQL string instead of 'sqlite3_exec' function, we can direct query or update data after binding data. However after checking previous code, it seems there is nothing wrong with 'stmt_update_prop' related SQL statement. I suspect there is some wrong with 'sqlite3_bind_text' function, maybe there are some special characters need to be transferred before 'sqlite3_step' function, but SQLite database error still happens after I changing binded text to regular text. After some searching in mod_webdav.c, I finally find something in 'sqlite3.h' header file: 'sqlite3.h' recommends using 'sqlite3_prepare_v2' function to replace old 'sqlite3_prepare' function, if database schema changes after 'sqlite3_prepare' function, 'sqlite3_step' function may fail. Now we check database initialize code in 'mod_webdav.c' again, we find that […]