summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/supportlib.lua31
1 files changed, 30 insertions, 1 deletions
diff --git a/lib/supportlib.lua b/lib/supportlib.lua
index 8c53825..68c223c 100644
--- a/lib/supportlib.lua
+++ b/lib/supportlib.lua
@@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: supportlib.lua,v 1.6 2007-05-31 16:02:34 pixel Exp $ */
+/* $Id: supportlib.lua,v 1.7 2007-06-11 21:25:06 pixel Exp $ */
]]--
@@ -157,3 +157,32 @@ function split(str, at)
return splut
end
+
+
+--
+-- String replacement functions.
+--
+
+local sql_replacements = {
+ { "\\", "\\\\" },
+ { "'", "\\'" },
+ { '"', '\\"' },
+ { "\n", "\\n" },
+ { "\r", "\\r" },
+-- { "\0", "\\0" },
+ { "\026", "\\Z" },
+}
+
+function generic_escape(str, replacements)
+ local _, r
+
+ for _, r in ipairs(replacements) do
+ str = string.gsub(str, r[1], r[2])
+ end
+
+ return str
+end
+
+function sql_escape(name)
+ return generic_escape(name, sql_replacements)
+end