Software /
code /
prosody
Comparison
plugins/mod_storage_sql2.lua @ 5732:4aa1d6f5083a
mod_storage_sql2: Make sure the user field is not NULL
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 10 Jul 2013 12:01:23 +0200 |
parent | 5711:254a9420e53d |
child | 5733:aeeced7b0149 |
comparison
equal
deleted
inserted
replaced
5731:902927f1c96f | 5732:4aa1d6f5083a |
---|---|
146 local user, store; | 146 local user, store; |
147 | 147 |
148 local function keyval_store_get() | 148 local function keyval_store_get() |
149 local haveany; | 149 local haveany; |
150 local result = {}; | 150 local result = {}; |
151 for row in engine:select("SELECT `key`,`type`,`value` FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=?", host, user, store) do | 151 for row in engine:select("SELECT `key`,`type`,`value` FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=?", host, user or "", store) do |
152 haveany = true; | 152 haveany = true; |
153 local k = row[1]; | 153 local k = row[1]; |
154 local v = deserialize(row[2], row[3]); | 154 local v = deserialize(row[2], row[3]); |
155 if k and v then | 155 if k and v then |
156 if k ~= "" then result[k] = v; elseif type(v) == "table" then | 156 if k ~= "" then result[k] = v; elseif type(v) == "table" then |
163 if haveany then | 163 if haveany then |
164 return result; | 164 return result; |
165 end | 165 end |
166 end | 166 end |
167 local function keyval_store_set(data) | 167 local function keyval_store_set(data) |
168 engine:delete("DELETE FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=?", host, user, store); | 168 engine:delete("DELETE FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=?", host, user or "", store); |
169 | 169 |
170 if data and next(data) ~= nil then | 170 if data and next(data) ~= nil then |
171 local extradata = {}; | 171 local extradata = {}; |
172 for key, value in pairs(data) do | 172 for key, value in pairs(data) do |
173 if type(key) == "string" and key ~= "" then | 173 if type(key) == "string" and key ~= "" then |
174 local t, value = serialize(value); | 174 local t, value = serialize(value); |
175 assert(t, value); | 175 assert(t, value); |
176 engine:insert("INSERT INTO `prosody` (`host`,`user`,`store`,`key`,`type`,`value`) VALUES (?,?,?,?,?,?)", host, user, store, key, t, value); | 176 engine:insert("INSERT INTO `prosody` (`host`,`user`,`store`,`key`,`type`,`value`) VALUES (?,?,?,?,?,?)", host, user or "", store, key, t, value); |
177 else | 177 else |
178 extradata[key] = value; | 178 extradata[key] = value; |
179 end | 179 end |
180 end | 180 end |
181 if next(extradata) ~= nil then | 181 if next(extradata) ~= nil then |
182 local t, extradata = serialize(extradata); | 182 local t, extradata = serialize(extradata); |
183 assert(t, extradata); | 183 assert(t, extradata); |
184 engine:insert("INSERT INTO `prosody` (`host`,`user`,`store`,`key`,`type`,`value`) VALUES (?,?,?,?,?,?)", host, user, store, "", t, extradata); | 184 engine:insert("INSERT INTO `prosody` (`host`,`user`,`store`,`key`,`type`,`value`) VALUES (?,?,?,?,?,?)", host, user or "", store, "", t, extradata); |
185 end | 185 end |
186 end | 186 end |
187 return true; | 187 return true; |
188 end | 188 end |
189 | 189 |