ejabberdsql2prosody: Fix typo, and improve the warning message
[prosody.git] / tools / ejabberdsql2prosody.lua
index 2943103f9351501e987a437967a13bfe41ce95e2..ddbe3ee2638418733c27a57fc6880fbbbad66110 100644 (file)
@@ -36,11 +36,21 @@ local function peek()
        return last;
 end
 
+local escapes = {
+       ["\\0"] = "\0";
+       ["\\'"] = "'";
+       ["\\\""] = "\"";
+       ["\\b"] = "\b";
+       ["\\n"] = "\n";
+       ["\\r"] = "\r";
+       ["\\t"] = "\t";
+       ["\\Z"] = "\26";
+       ["\\\\"] = "\\";
+       ["\\%"] = "%";
+       ["\\_"] = "_";
+}
 local function unescape(s)
-       if s == "\\'" then return "'"; end
-       if s == "\\n" then return "\n"; end
-       if s == "\\\\" then return "\\"; end
-       error("Unknown escape sequence: "..s);
+       return escapes[s] or error("Unknown escape sequence: "..s);
 end
 local function readString()
        read("'");
@@ -168,9 +178,12 @@ local t = parseFile(arg);
 for name, data in pairs(t) do
        local m = map[name];
        if m then
+               if #data > 0 and #data[1] ~= #m then
+                       print("[warning] expected "..#m.." columns for table `"..name.."`, found "..#data[1]);
+               end
                for i=1,#data do
                        local row = data[i];
-                       for j=1,#row do
+                       for j=1,#m do
                                row[m[j]] = row[j];
                                row[j] = nil;
                        end