Diff

plugins/mod_storage_sql.lua @ 3744:ed76b64da9d1

mod_storage_sql: Use 'IS' for comparison instead of '=', to avoid SQL's NULL insanity.
author Waqas Hussain <waqas20@gmail.com>
date Mon, 13 Dec 2010 19:28:57 +0500
parent 3743:5adfb8d0444d
child 3772:e1f6fe098404
line wrap: on
line diff
--- a/plugins/mod_storage_sql.lua	Mon Dec 13 19:27:14 2010 +0500
+++ b/plugins/mod_storage_sql.lua	Mon Dec 13 19:28:57 2010 +0500
@@ -115,7 +115,7 @@
 keyval_store.__index = keyval_store;
 function keyval_store:get(username)
 	user,store = username,self.store;
-	local stmt, err = getsql("SELECT * FROM Prosody WHERE host=? AND user=? AND store=? AND subkey=NULL");
+	local stmt, err = getsql("SELECT * FROM Prosody WHERE host IS ? AND user IS ? AND store IS ? AND subkey IS NULL");
 	if not stmt then return nil, err; end
 	
 	local haveany;
@@ -137,7 +137,7 @@
 function keyval_store:set(username, data)
 	user,store = username,self.store;
 	-- start transaction
-	local affected, err = setsql("DELETE FROM Prosody WHERE host=? AND user=? AND store=? AND subkey=NULL");
+	local affected, err = setsql("DELETE FROM Prosody WHERE host IS ? AND user IS ? AND store IS ? AND subkey IS NULL");
 	
 	if data and next(data) ~= nil then
 		local extradata = {};
@@ -165,7 +165,7 @@
 map_store.__index = map_store;
 function map_store:get(username, key)
 	user,store = username,self.store;
-	local stmt, err = getsql("SELECT * FROM Prosody WHERE host=? AND user=? AND store=? AND key=?", key);
+	local stmt, err = getsql("SELECT * FROM Prosody WHERE host IS ? AND user IS ? AND store IS ? AND key IS ?", key);
 	if not stmt then return nil, err; end
 	
 	local haveany;
@@ -187,7 +187,7 @@
 function map_store:set(username, key, data)
 	user,store = username,self.store;
 	-- start transaction
-	local affected, err = setsql("DELETE FROM Prosody WHERE host=? AND user=? AND store=? AND key=?", key);
+	local affected, err = setsql("DELETE FROM Prosody WHERE host IS ? AND user IS ? AND store IS ? AND key IS ?", key);
 	
 	if data and next(data) ~= nil then
 		local extradata = {};
@@ -219,10 +219,10 @@
 	local cols = {"from", "to", "jid", "typ"};
 	local vals = { from ,  to ,  jid ,  typ };
 	local stmt, err;
-	local query = "SELECT * FROM ProsodyArchive WHERE host=? AND user=? AND store=?";
+	local query = "SELECT * FROM ProsodyArchive WHERE host IS ? AND user IS ? AND store IS ?";
 	
 	query = query.." ORDER BY time";
-	--local stmt, err = getsql("SELECT * FROM Prosody WHERE host=? AND user=? AND store=? AND key=?", key);
+	--local stmt, err = getsql("SELECT * FROM Prosody WHERE host IS ? AND user IS ? AND store IS ? AND key IS ?", key);
 	
 	return nil, "not-implemented"
 end