Merge pull request #13 from echiesse/master

Fixed compilation error on function "conn_escape" on Visual Studio 2008.
This commit is contained in:
Hisham Muhammad 2016-03-22 00:37:41 -03:00
commit 25eebb2222

View File

@ -320,7 +320,7 @@ static void sql_commit(conn_data *conn) {
static void sql_begin(conn_data *conn) { static void sql_begin(conn_data *conn) {
PQclear(PQexec(conn->pg_conn, "BEGIN")); PQclear(PQexec(conn->pg_conn, "BEGIN"));
} }
@ -371,14 +371,17 @@ static int conn_escape (lua_State *L) {
conn_data *conn = getconnection (L); conn_data *conn = getconnection (L);
size_t len; size_t len;
const char *from = luaL_checklstring (L, 2, &len); const char *from = luaL_checklstring (L, 2, &len);
char to[len*sizeof(char)*2+1]; char *to = malloc(len*sizeof(char)*2+1);
int error; int error;
int ret = 1;
len = PQescapeStringConn (conn->pg_conn, to, from, len, &error); len = PQescapeStringConn (conn->pg_conn, to, from, len, &error);
if (error == 0) { /* success ! */ if (error == 0) { /* success ! */
lua_pushlstring (L, to, len); lua_pushlstring (L, to, len);
return 1; } else {
} else ret = luasql_failmsg (L, "cannot escape string. PostgreSQL: ", PQerrorMessage (conn->pg_conn));
return luasql_failmsg (L, "cannot escape string. PostgreSQL: ", PQerrorMessage (conn->pg_conn)); }
free(to);
return ret;
} }
@ -415,7 +418,7 @@ static int conn_commit (lua_State *L) {
conn_data *conn = getconnection (L); conn_data *conn = getconnection (L);
sql_commit(conn); sql_commit(conn);
if (conn->auto_commit == 0) { if (conn->auto_commit == 0) {
sql_begin(conn); sql_begin(conn);
lua_pushboolean (L, 1); lua_pushboolean (L, 1);
} else } else
lua_pushboolean (L, 0); lua_pushboolean (L, 0);
@ -430,7 +433,7 @@ static int conn_rollback (lua_State *L) {
conn_data *conn = getconnection (L); conn_data *conn = getconnection (L);
sql_rollback(conn); sql_rollback(conn);
if (conn->auto_commit == 0) { if (conn->auto_commit == 0) {
sql_begin(conn); sql_begin(conn);
lua_pushboolean (L, 1); lua_pushboolean (L, 1);
} else } else
lua_pushboolean (L, 0); lua_pushboolean (L, 0);