Merge 0.8->trunk
authorMatthew Wild <mwild1@gmail.com>
Thu, 02 Jun 2011 02:31:18 +0100
changeset 4286 1bceebe2b117
parent 4283 ffaaa3fd3189 (current diff)
parent 4285 c806a599224a (diff)
child 4290 aaa06e68a9e4
Merge 0.8->trunk
--- a/plugins/mod_storage_sql.lua	Thu Jun 02 00:26:48 2011 +0100
+++ b/plugins/mod_storage_sql.lua	Thu Jun 02 02:31:18 2011 +0100
@@ -68,6 +68,8 @@
 	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("`", "\"");
+	elseif params.driver == "MySQL" then
+		create_sql = create_sql:gsub("`value` TEXT", "`value` MEDIUMTEXT");
 	end
 	
 	local stmt = connection:prepare(create_sql);
@@ -91,6 +93,22 @@
 			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
+		else -- COMPAT: Upgrade tables from 0.8.0
+			-- Failed to create, but check existing MySQL table here
+			local stmt = connection:prepare("SHOW COLUMNS FROM prosody WHERE Field='value' and Type='text'");
+			local ok = stmt:execute();
+			local commit_ok = connection:commit();
+			if ok and commit_ok then
+				if stmt:rowcount() > 0 then
+					local stmt = connection:prepare("ALTER TABLE prosody MODIFY COLUMN `value` MEDIUMTEXT");
+					local ok = stmt:execute();
+					local commit_ok = connection:commit();
+					if ok and commit_ok then
+						module:log("info", "Database table automatically upgraded");
+					end
+				end
+				repeat until not stmt:fetch();
+			end
 		end
 	end
 end
--- a/util/json.lua	Thu Jun 02 00:26:48 2011 +0100
+++ b/util/json.lua	Thu Jun 02 02:31:18 2011 +0100
@@ -134,12 +134,14 @@
 
 
 function json.decode(json)
+	json = json.." "; -- appending a space ensures valid json wouldn't touch EOF
 	local pos = 1;
 	local current = {};
 	local stack = {};
 	local ch, peek;
 	local function next()
 		ch = json:sub(pos, pos);
+		if ch == "" then error("Unexpected EOF"); end
 		pos = pos+1;
 		peek = json:sub(pos, pos);
 		return ch;