--- a/dbd/postgresql/connection.c Fri Dec 19 09:17:16 2008 +0000 +++ b/dbd/postgresql/connection.c Sat Dec 20 02:37:22 2008 +0000 @@ -199,6 +199,35 @@ } /* + * quoted = connection:quote(str) + */ +static int connection_quote(lua_State *L) { + connection_t *conn = (connection_t *)luaL_checkudata(L, 1, DBD_POSTGRESQL_CONNECTION); + size_t len; + const char *from = luaL_checklstring(L, 2, &len); + char *to = (char *)calloc(len*2+1, sizeof(char)); + int err = 0; + int quoted_len; + + if (!conn->postgresql) { + luaL_error(L, DBI_ERR_DB_UNAVAILABLE); + } + + quoted_len = PQescapeStringConn(conn->postgresql, to, from, len, &err); + + if (err) { + free(to); + + luaL_error(L, DBI_ERR_QUOTING_STR, PQerrorMessage(conn->postgresql)); + } + + lua_pushlstring(L, to, quoted_len); + free(to); + + return 1; +} + +/* * success = connection:rollback() */ static int connection_rollback(lua_State *L) { @@ -235,6 +264,7 @@ {"commit", connection_commit}, {"ping", connection_ping}, {"prepare", connection_prepare}, + {"quote", connection_quote}, {"rollback", connection_rollback}, {NULL, NULL} };