diff options
author | Matthew Wild <mwild1@gmail.com> | 2011-01-11 04:22:45 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2011-01-11 04:22:45 +0000 |
commit | da14cbf95f70cba5770251871971197bde6fde79 (patch) | |
tree | 9ed8c553764629818d3e6b3fa67df20ee087804a | |
parent | 59f7814f5fdf47d1a7dd673043cbc076b0484f66 (diff) | |
parent | 16e8102a4e0ee8528925952f9b60ef87a4f8aa00 (diff) | |
download | prosody-da14cbf95f70cba5770251871971197bde6fde79.tar.gz prosody-da14cbf95f70cba5770251871971197bde6fde79.zip |
Merge 0.8->trunk
-rw-r--r-- | plugins/mod_storage_sql.lua | 45 | ||||
-rw-r--r-- | util/datamanager.lua | 2 |
2 files changed, 33 insertions, 14 deletions
diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index 07735cb2..7917958d 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -64,6 +64,37 @@ local function connect() end end +local function create_table() + local create_sql = "CREATE TABLE `prosody` (`host` TEXT, `user` TEXT, `store` TEXT, `key` TEXT, `type` TEXT, `value` TEXT);"; + if params.driver == "PostgreSQL" then + create_sql = create_sql:gsub("`", "\""); + end + + local stmt = connection:prepare(create_sql); + if stmt then + local ok = stmt:execute(); + local commit_ok = connection:commit(); + if ok and commit_ok then + module:log("info", "Initialized new %s database with prosody table", params.driver); + local index_sql = "CREATE INDEX `prosody_index` ON `prosody` (`host`, `user`, `store`, `key`)"; + if params.driver == "PostgreSQL" then + index_sql = index_sql:gsub("`", "\""); + elseif params.driver == "MySQL" then + index_sql = index_sql:gsub("`([,)])", "`(20)%1"); + end + local stmt, err = connection:prepare(index_sql); + local ok, commit_ok, commit_err; + if stmt then + ok, err = stmt:execute(); + commit_ok, commit_err = connection:commit(); + end + if not(ok and commit_ok) then + module:log("warn", "Failed to create index (%s), lookups may not be optimised", err or commit_err); + end + end + end +end + do -- process options to get a db connection DBI = require "DBI"; @@ -78,19 +109,7 @@ do -- process options to get a db connection assert(connect()); -- Automatically create table, ignore failure (table probably already exists) - local create_sql = "CREATE TABLE `prosody` (`host` TEXT, `user` TEXT, `store` TEXT, `key` TEXT, `type` TEXT, `value` TEXT);"; - if params.driver == "PostgreSQL" then - create_sql = create_sql:gsub("`", "\""); - end - - local stmt = connection:prepare(create_sql); - if stmt then - local ok = stmt:execute(); - local commit_ok = connection:commit(); - if ok and commit_ok then - module:log("info", "Initialized new %s database with prosody table", params.driver); - end - end + create_table(); end local function serialize(value) diff --git a/util/datamanager.lua b/util/datamanager.lua index 5aee289d..2be3acfd 100644 --- a/util/datamanager.lua +++ b/util/datamanager.lua @@ -57,7 +57,7 @@ local function mkdir(path) return path; end -local data_path = prosody.paths.data; +local data_path = (prosody and prosody.paths and prosody.paths.data) or "."; local callbacks = {}; ------- API ------------- |