Software /
code /
prosody
Comparison
plugins/mod_storage_sql.lua @ 4318:44b131d7041b 0.8.2
mod_storage_sql: Add extra logging and error handling around table creation
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 11 Jun 2011 02:16:26 +0100 |
parent | 4317:5b0fcc5cdd4d |
child | 5034:2dbb3bf74090 |
comparison
equal
deleted
inserted
replaced
4317:5b0fcc5cdd4d | 4318:44b131d7041b |
---|---|
73 create_sql = create_sql:gsub("`", "\""); | 73 create_sql = create_sql:gsub("`", "\""); |
74 elseif params.driver == "MySQL" then | 74 elseif params.driver == "MySQL" then |
75 create_sql = create_sql:gsub("`value` TEXT", "`value` MEDIUMTEXT"); | 75 create_sql = create_sql:gsub("`value` TEXT", "`value` MEDIUMTEXT"); |
76 end | 76 end |
77 | 77 |
78 local stmt = connection:prepare(create_sql); | 78 local stmt, err = connection:prepare(create_sql); |
79 if stmt then | 79 if stmt then |
80 local ok = stmt:execute(); | 80 local ok = stmt:execute(); |
81 local commit_ok = connection:commit(); | 81 local commit_ok = connection:commit(); |
82 if ok and commit_ok then | 82 if ok and commit_ok then |
83 module:log("info", "Initialized new %s database with prosody table", params.driver); | 83 module:log("info", "Initialized new %s database with prosody table", params.driver); |
101 local stmt = connection:prepare("SHOW COLUMNS FROM prosody WHERE Field='value' and Type='text'"); | 101 local stmt = connection:prepare("SHOW COLUMNS FROM prosody WHERE Field='value' and Type='text'"); |
102 local ok = stmt:execute(); | 102 local ok = stmt:execute(); |
103 local commit_ok = connection:commit(); | 103 local commit_ok = connection:commit(); |
104 if ok and commit_ok then | 104 if ok and commit_ok then |
105 if stmt:rowcount() > 0 then | 105 if stmt:rowcount() > 0 then |
106 module:log("info", "Upgrading database schema..."); | |
106 local stmt = connection:prepare("ALTER TABLE prosody MODIFY COLUMN `value` MEDIUMTEXT"); | 107 local stmt = connection:prepare("ALTER TABLE prosody MODIFY COLUMN `value` MEDIUMTEXT"); |
107 local ok = stmt:execute(); | 108 local ok, err = stmt:execute(); |
108 local commit_ok = connection:commit(); | 109 local commit_ok = connection:commit(); |
109 if ok and commit_ok then | 110 if ok and commit_ok then |
110 module:log("info", "Database table automatically upgraded"); | 111 module:log("info", "Database table automatically upgraded"); |
112 else | |
113 module:log("error", "Failed to upgrade database schema (%s), please see " | |
114 .."http://prosody.im/doc/mysql for help", | |
115 err or "unknown error"); | |
111 end | 116 end |
112 end | 117 end |
113 repeat until not stmt:fetch(); | 118 repeat until not stmt:fetch(); |
114 else | 119 end |
115 module:log("error", "Failed to upgrade database schema, please see http://prosody.im/doc/mysql for help"); | 120 end |
116 end | 121 elseif params.driver ~= "SQLite3" then -- SQLite normally fails to prepare for existing table |
117 end | 122 module:log("warn", "Prosody was not able to automatically check/create the database table (%s), " |
123 .."see http://prosody.im/doc/modules/mod_storage_sql#table_management for help.", | |
124 err or "unknown error"); | |
118 end | 125 end |
119 end | 126 end |
120 | 127 |
121 do -- process options to get a db connection | 128 do -- process options to get a db connection |
122 local ok; | 129 local ok; |