Software /
code /
prosody
Comparison
plugins/mod_storage_sql.lua @ 7273:7e659f87973d
mod_storage_sql: Add LIMIT clause to queries where only a single row is expected
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 13 Mar 2016 17:42:22 +0100 |
parent | 7178:5953f415c815 |
child | 7274:e0727512bb99 |
comparison
equal
deleted
inserted
replaced
7272:a23ca90d1984 | 7273:7e659f87973d |
---|---|
132 map_store.__index = map_store; | 132 map_store.__index = map_store; |
133 map_store.remove = {}; | 133 map_store.remove = {}; |
134 function map_store:get(username, key) | 134 function map_store:get(username, key) |
135 local ok, result = engine:transaction(function() | 135 local ok, result = engine:transaction(function() |
136 if type(key) == "string" and key ~= "" then | 136 if type(key) == "string" and key ~= "" then |
137 for row in engine:select("SELECT `type`, `value` FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", host, username or "", self.store, key) do | 137 for row in engine:select("SELECT `type`, `value` FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=? LIMIT 1", host, username or "", self.store, key) do |
138 return deserialize(row[1], row[2]); | 138 return deserialize(row[1], row[2]); |
139 end | 139 end |
140 else | 140 else |
141 for row in engine:select("SELECT `type`, `value` FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", host, username or "", self.store, "") do | 141 for row in engine:select("SELECT `type`, `value` FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=? LIMIT 1", host, username or "", self.store, "") do |
142 local data = deserialize(row[1], row[2]); | 142 local data = deserialize(row[1], row[2]); |
143 return data and data[key] or nil; | 143 return data and data[key] or nil; |
144 end | 144 end |
145 end | 145 end |
146 end); | 146 end); |
161 local t, value = assert(serialize(data)); | 161 local t, value = assert(serialize(data)); |
162 engine:insert("INSERT INTO `prosody` (`host`,`user`,`store`,`key`,`type`,`value`) VALUES (?,?,?,?,?,?)", host, username or "", self.store, key, t, value); | 162 engine:insert("INSERT INTO `prosody` (`host`,`user`,`store`,`key`,`type`,`value`) VALUES (?,?,?,?,?,?)", host, username or "", self.store, key, t, value); |
163 end | 163 end |
164 else | 164 else |
165 local extradata = {}; | 165 local extradata = {}; |
166 for row in engine:select("SELECT `type`, `value` FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", host, username or "", self.store, "") do | 166 for row in engine:select("SELECT `type`, `value` FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=? LIMIT 1", host, username or "", self.store, "") do |
167 extradata = deserialize(row[1], row[2]); | 167 extradata = deserialize(row[1], row[2]); |
168 break; | 168 break; |
169 end | 169 end |
170 engine:delete("DELETE FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", | 170 engine:delete("DELETE FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", |
171 host, username or "", self.store, ""); | 171 host, username or "", self.store, ""); |