comparison util/sqlite3.lua @ 13632:844e7bf7b48a

util.sql: SQLCipher support This enables use of encrypted databases if LuaDBI or LuaSQLite3 has been linked against SQLCipher. Using `LD_PRELOAD` may work as well. Requires SQLCipher >= 4.0.0 due to the use of UPSERT
author Kim Alvefur <zash@zash.se>
date Thu, 23 Jan 2025 16:38:56 +0100
parents f2578a69ccf4
children e7c52d0b0e0d
comparison
equal deleted inserted replaced
13631:0fe27632a837 13632:844e7bf7b48a
112 assert(params.driver == "SQLite3", "Only sqlite3 is supported"); 112 assert(params.driver == "SQLite3", "Only sqlite3 is supported");
113 local dbh, err = sqlite_errors.coerce(lsqlite3.open(params.database)); 113 local dbh, err = sqlite_errors.coerce(lsqlite3.open(params.database));
114 if not dbh then return nil, err; end 114 if not dbh then return nil, err; end
115 self.conn = dbh; 115 self.conn = dbh;
116 self.prepared = {}; 116 self.prepared = {};
117 if params.password then
118 local ok, err = self:execute(("PRAGMA key='%s'"):format((params.password:gsub("'", "''"))));
119 if not ok then
120 return ok, err;
121 end
122 end
117 local ok, err = self:set_encoding(); 123 local ok, err = self:set_encoding();
118 if not ok then 124 if not ok then
119 return ok, err; 125 return ok, err;
120 end 126 end
121 local ok, err = self:onconnect(); 127 local ok, err = self:onconnect();