Software / code / prosody
Comparison
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 |
comparison
equal
deleted
inserted
replaced
| 3743:5adfb8d0444d | 3744:ed76b64da9d1 |
|---|---|
| 113 | 113 |
| 114 local keyval_store = {}; | 114 local keyval_store = {}; |
| 115 keyval_store.__index = keyval_store; | 115 keyval_store.__index = keyval_store; |
| 116 function keyval_store:get(username) | 116 function keyval_store:get(username) |
| 117 user,store = username,self.store; | 117 user,store = username,self.store; |
| 118 local stmt, err = getsql("SELECT * FROM Prosody WHERE host=? AND user=? AND store=? AND subkey=NULL"); | 118 local stmt, err = getsql("SELECT * FROM Prosody WHERE host IS ? AND user IS ? AND store IS ? AND subkey IS NULL"); |
| 119 if not stmt then return nil, err; end | 119 if not stmt then return nil, err; end |
| 120 | 120 |
| 121 local haveany; | 121 local haveany; |
| 122 local result = {}; | 122 local result = {}; |
| 123 for row in stmt:rows(true) do | 123 for row in stmt:rows(true) do |
| 135 return haveany and result or nil; | 135 return haveany and result or nil; |
| 136 end | 136 end |
| 137 function keyval_store:set(username, data) | 137 function keyval_store:set(username, data) |
| 138 user,store = username,self.store; | 138 user,store = username,self.store; |
| 139 -- start transaction | 139 -- start transaction |
| 140 local affected, err = setsql("DELETE FROM Prosody WHERE host=? AND user=? AND store=? AND subkey=NULL"); | 140 local affected, err = setsql("DELETE FROM Prosody WHERE host IS ? AND user IS ? AND store IS ? AND subkey IS NULL"); |
| 141 | 141 |
| 142 if data and next(data) ~= nil then | 142 if data and next(data) ~= nil then |
| 143 local extradata = {}; | 143 local extradata = {}; |
| 144 for key, value in pairs(data) do | 144 for key, value in pairs(data) do |
| 145 if type(key) == "string" then | 145 if type(key) == "string" then |
| 163 | 163 |
| 164 local map_store = {}; | 164 local map_store = {}; |
| 165 map_store.__index = map_store; | 165 map_store.__index = map_store; |
| 166 function map_store:get(username, key) | 166 function map_store:get(username, key) |
| 167 user,store = username,self.store; | 167 user,store = username,self.store; |
| 168 local stmt, err = getsql("SELECT * FROM Prosody WHERE host=? AND user=? AND store=? AND key=?", key); | 168 local stmt, err = getsql("SELECT * FROM Prosody WHERE host IS ? AND user IS ? AND store IS ? AND key IS ?", key); |
| 169 if not stmt then return nil, err; end | 169 if not stmt then return nil, err; end |
| 170 | 170 |
| 171 local haveany; | 171 local haveany; |
| 172 local result = {}; | 172 local result = {}; |
| 173 for row in stmt:rows(true) do | 173 for row in stmt:rows(true) do |
| 185 return haveany and result or nil; | 185 return haveany and result or nil; |
| 186 end | 186 end |
| 187 function map_store:set(username, key, data) | 187 function map_store:set(username, key, data) |
| 188 user,store = username,self.store; | 188 user,store = username,self.store; |
| 189 -- start transaction | 189 -- start transaction |
| 190 local affected, err = setsql("DELETE FROM Prosody WHERE host=? AND user=? AND store=? AND key=?", key); | 190 local affected, err = setsql("DELETE FROM Prosody WHERE host IS ? AND user IS ? AND store IS ? AND key IS ?", key); |
| 191 | 191 |
| 192 if data and next(data) ~= nil then | 192 if data and next(data) ~= nil then |
| 193 local extradata = {}; | 193 local extradata = {}; |
| 194 for subkey, value in pairs(data) do | 194 for subkey, value in pairs(data) do |
| 195 if type(subkey) == "string" then | 195 if type(subkey) == "string" then |
| 217 user,store = username,self.store; | 217 user,store = username,self.store; |
| 218 | 218 |
| 219 local cols = {"from", "to", "jid", "typ"}; | 219 local cols = {"from", "to", "jid", "typ"}; |
| 220 local vals = { from , to , jid , typ }; | 220 local vals = { from , to , jid , typ }; |
| 221 local stmt, err; | 221 local stmt, err; |
| 222 local query = "SELECT * FROM ProsodyArchive WHERE host=? AND user=? AND store=?"; | 222 local query = "SELECT * FROM ProsodyArchive WHERE host IS ? AND user IS ? AND store IS ?"; |
| 223 | 223 |
| 224 query = query.." ORDER BY time"; | 224 query = query.." ORDER BY time"; |
| 225 --local stmt, err = getsql("SELECT * FROM Prosody WHERE host=? AND user=? AND store=? AND key=?", key); | 225 --local stmt, err = getsql("SELECT * FROM Prosody WHERE host IS ? AND user IS ? AND store IS ? AND key IS ?", key); |
| 226 | 226 |
| 227 return nil, "not-implemented" | 227 return nil, "not-implemented" |
| 228 end | 228 end |
| 229 | 229 |
| 230 local driver = { name = "sql" }; | 230 local driver = { name = "sql" }; |