Diff

util/sql.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
parent 13240:a378937103cb
child 13715:edd006093533
line wrap: on
line diff
--- a/util/sql.lua	Tue Jan 21 17:21:48 2025 +0100
+++ b/util/sql.lua	Thu Jan 23 16:38:56 2025 +0100
@@ -84,6 +84,12 @@
 	dbh:autocommit(false); -- don't commit automatically
 	self.conn = dbh;
 	self.prepared = {};
+	if params.password then
+		local ok, err = self:execute(("PRAGMA key='%s'"):format(dbh:quote(params.password)));
+		if not ok then
+			return ok, err;
+		end
+	end
 	local ok, err = self:set_encoding();
 	if not ok then
 		return ok, err;