Changeset

4319:b46b766ce0af

Merge 0.8->trunk
author Matthew Wild <mwild1@gmail.com>
date Sat, 11 Jun 2011 02:17:11 +0100
parents 4316:2478698bdc52 (current diff) 4318:44b131d7041b (diff)
children 4321:4dcdba6900f2
files
diffstat 1 files changed, 14 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_storage_sql.lua	Tue Jun 07 01:29:34 2011 +0100
+++ b/plugins/mod_storage_sql.lua	Sat Jun 11 02:17:11 2011 +0100
@@ -65,6 +65,9 @@
 end
 
 local function create_table()
+	if not module:get_option("sql_manage_tables", true) then
+		return;
+	end
 	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("`", "\"");
@@ -72,7 +75,7 @@
 		create_sql = create_sql:gsub("`value` TEXT", "`value` MEDIUMTEXT");
 	end
 	
-	local stmt = connection:prepare(create_sql);
+	local stmt, err = connection:prepare(create_sql);
 	if stmt then
 		local ok = stmt:execute();
 		local commit_ok = connection:commit();
@@ -100,18 +103,25 @@
 			local commit_ok = connection:commit();
 			if ok and commit_ok then
 				if stmt:rowcount() > 0 then
+					module:log("info", "Upgrading database schema...");
 					local stmt = connection:prepare("ALTER TABLE prosody MODIFY COLUMN `value` MEDIUMTEXT");
-					local ok = stmt:execute();
+					local ok, err = stmt:execute();
 					local commit_ok = connection:commit();
 					if ok and commit_ok then
 						module:log("info", "Database table automatically upgraded");
+					else
+						module:log("error", "Failed to upgrade database schema (%s), please see "
+							.."http://prosody.im/doc/mysql for help",
+							err or "unknown error");
 					end
 				end
 				repeat until not stmt:fetch();
-			else
-				module:log("error", "Failed to upgrade database schema, please see http://prosody.im/doc/mysql for help");
 			end
 		end
+	elseif params.driver ~= "SQLite3" then -- SQLite normally fails to prepare for existing table
+		module:log("warn", "Prosody was not able to automatically check/create the database table (%s), "
+			.."see http://prosody.im/doc/modules/mod_storage_sql#table_management for help.",
+			err or "unknown error");
 	end
 end