提交 0dc7bdcf authored 作者: Chad Phillips's avatar Chad Phillips

support functions for database operations in Lua. currently includes simple…

support functions for database operations in Lua.  currently includes simple escaping functions for MySQL and Postgres database queries -- good to use with LuaSQL's ODBC driver, for example...

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk/contrib@15053 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 bdaff449
--[[
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
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论