aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_storage_sql.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2014-04-02 17:41:38 +0100
committerMatthew Wild <mwild1@gmail.com>2014-04-02 17:41:38 +0100
commitda820882348572de470a13a1a50f529a51243aa5 (patch)
tree39ca42dddf3935546a0c3c37b2e2456a554899f1 /plugins/mod_storage_sql.lua
parent618661cda2a68afbe445ce079c15af25bdaa177b (diff)
parentf7d4b04bf17c8b634eae00e814a995a88c5ba6cb (diff)
downloadprosody-da820882348572de470a13a1a50f529a51243aa5.tar.gz
prosody-da820882348572de470a13a1a50f529a51243aa5.zip
Merge 0.9->0.10
Diffstat (limited to 'plugins/mod_storage_sql.lua')
-rw-r--r--plugins/mod_storage_sql.lua26
1 files changed, 13 insertions, 13 deletions
diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua
index eed3fec9..1f453d42 100644
--- a/plugins/mod_storage_sql.lua
+++ b/plugins/mod_storage_sql.lua
@@ -93,7 +93,7 @@ local function create_table()
elseif params.driver == "MySQL" then
create_sql = create_sql:gsub("`value` TEXT", "`value` MEDIUMTEXT");
end
-
+
local stmt, err = connection:prepare(create_sql);
if stmt then
local ok = stmt:execute();
@@ -159,18 +159,18 @@ do -- process options to get a db connection
end
params = params or { driver = "SQLite3" };
-
+
if params.driver == "SQLite3" then
params.database = resolve_relative_path(prosody.paths.data or ".", params.database or "prosody.sqlite");
end
-
+
assert(params.driver and params.database, "Both the SQL driver and the database need to be specified");
dburi = db2uri(params);
connection = connections[dburi];
-
+
assert(connect());
-
+
-- Automatically create table, ignore failure (table probably already exists)
create_table();
end
@@ -209,7 +209,7 @@ local function dosql(sql, ...)
local ok, err = stmt:execute(...);
if not ok and not test_connection() then error("connection failed"); end
if not ok then return nil, err; end
-
+
return stmt;
end
local function getsql(sql, ...)
@@ -236,7 +236,7 @@ end
local function keyval_store_get()
local stmt, err = getsql("SELECT * FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=?");
if not stmt then return rollback(nil, err); end
-
+
local haveany;
local result = {};
for row in stmt:rows(true) do
@@ -256,7 +256,7 @@ end
local function keyval_store_set(data)
local affected, err = setsql("DELETE FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=?");
if not affected then return rollback(affected, err); end
-
+
if data and next(data) ~= nil then
local extradata = {};
for key, value in pairs(data) do
@@ -314,7 +314,7 @@ end
local function map_store_get(key)
local stmt, err = getsql("SELECT * FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", key or "");
if not stmt then return rollback(nil, err); end
-
+
local haveany;
local result = {};
for row in stmt:rows(true) do
@@ -334,7 +334,7 @@ end
local function map_store_set(key, data)
local affected, err = setsql("DELETE FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", key or "");
if not affected then return rollback(affected, err); end
-
+
if data and next(data) ~= nil then
if type(key) == "string" and key ~= "" then
local t, value = serialize(data);
@@ -365,15 +365,15 @@ local list_store = {};
list_store.__index = list_store;
function list_store:scan(username, from, to, jid, typ)
user,store = username,self.store;
-
+
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`=?";
-
+
query = query.." ORDER BY time";
--local stmt, err = getsql("SELECT * FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", key or "");
-
+
return nil, "not-implemented"
end