Added: freeswitch/trunk/contrib/hunmonk/lua/support_functions_database.lua (0 => 15053)
--- freeswitch/trunk/contrib/hunmonk/lua/support_functions_database.lua (rev 0)
+++ freeswitch/trunk/contrib/hunmonk/lua/support_functions_database.lua 2009-10-02 17:09:02 UTC (rev 15053)
@@ -0,0 +1,28 @@
+--[[
+ Helper functions for database operations.
+]]
+
+--[[
+ Escapes special characters for the MySQL database.
+]]
+function mysql_escape(string_to_escape)
+ -- Single quote, double quote, backspace.
+ escaped_string, replacements = string.gsub(string_to_escape, "(['\"\\])", function(x) return "\\" .. x end)
+ -- Null byte.
+ escaped_string, replacements = string.gsub(escaped_string, "%z", "\\0")
+
+ return escaped_string
+end
+
+--[[
+ Escapes special characters for the Postgres database.
+]]
+function pgsql_escape(string_to_escape)
+ -- Single quote..
+ escaped_string, replacements = string.gsub(string_to_escape, "'", "''")
+ -- Null byte.
+ escaped_string, replacements = string.gsub(escaped_string, "%z", "")
+
+ return escaped_string
+end
+