diff -Nru lua-dbi-0.5.hg5ba1dd988961/dbd/common.c lua-dbi-0.6/dbd/common.c --- lua-dbi-0.5.hg5ba1dd988961/dbd/common.c 2013-08-10 18:33:16.000000000 +0000 +++ lua-dbi-0.6/dbd/common.c 2017-08-23 21:14:17.000000000 +0000 @@ -1,6 +1,6 @@ #include -const char *strlower(char *in) { +const char *dbd_strlower(char *in) { char *s = in; while(*s) { @@ -15,7 +15,7 @@ * replace '?' placeholders with {native_prefix}\d+ placeholders * to be compatible with native API */ -char *replace_placeholders(lua_State *L, char native_prefix, const char *sql) { +char *dbd_replace_placeholders(lua_State *L, char native_prefix, const char *sql) { size_t len = strlen(sql); int num_placeholders = 0; int extra_space = 0; @@ -52,9 +52,13 @@ /* * allocate a new string for the converted SQL statement */ - newsql = malloc(sizeof(char) * (len+extra_space+1)); - memset(newsql, 0, sizeof(char) * (len+extra_space+1)); - + newsql = calloc(len+extra_space+1, sizeof(char)); + if(!newsql) { + lua_pushliteral(L, "out of memory"); + /* lua_error does not return. */ + lua_error(L); + } + /* * copy first char. In valid SQL this cannot be a placeholder */ @@ -97,3 +101,34 @@ return newsql; } +void dbd_register(lua_State *L, const char *name, + const luaL_Reg *methods, const luaL_Reg *class_methods, + lua_CFunction gc, lua_CFunction tostring) +{ + /* Create a new metatable with the given name and then assign the methods + * to it. Set the __index, __gc and __tostring fields appropriately. + */ + luaL_newmetatable(L, name); +#if LUA_VERSION_NUM < 502 + luaL_register(L, 0, methods); +#else + luaL_setfuncs(L, methods, 0); +#endif + lua_pushvalue(L, -1); + lua_setfield(L, -2, "__index"); + + lua_pushcfunction(L, gc); + lua_setfield(L, -2, "__gc"); + + lua_pushcfunction(L, tostring); + lua_setfield(L, -2, "__tostring"); + + /* Create a new table and register the class methods with it */ + lua_newtable(L); +#if LUA_VERSION_NUM < 502 + luaL_register(L, 0, class_methods); +#else + luaL_setfuncs(L, class_methods, 0); +#endif +} + diff -Nru lua-dbi-0.5.hg5ba1dd988961/dbd/common.h lua-dbi-0.6/dbd/common.h --- lua-dbi-0.5.hg5ba1dd988961/dbd/common.h 2013-08-10 18:33:16.000000000 +0000 +++ lua-dbi-0.6/dbd/common.h 2017-08-23 21:14:17.000000000 +0000 @@ -39,6 +39,11 @@ lua_pushnumber(L, v); \ lua_rawset(L, -3); +#define LUA_PUSH_ATTRIB_STRING_BY_LENGTH(n, v, len) \ + lua_pushstring(L, n); \ + lua_pushlstring(L, v, len); \ + lua_rawset(L, -3); + #define LUA_PUSH_ATTRIB_STRING(n, v) \ lua_pushstring(L, n); \ lua_pushstring(L, v); \ @@ -71,6 +76,11 @@ lua_rawseti(L, -2, n); \ n++; +#define LUA_PUSH_ARRAY_STRING_BY_LENGTH(n, v, len) \ + lua_pushlstring(L, v, len); \ + lua_rawseti(L, -2, n); \ + n++; + #define LUA_PUSH_ARRAY_BOOL(n, v) \ lua_pushboolean(L, v); \ lua_rawseti(L, -2, n); \ @@ -132,15 +142,19 @@ #define DBI_ERR_INVALID_STATEMENT "Invalid statement handle" #define DBI_ERR_NOT_IMPLEMENTED "Method %s.%s is not implemented" #define DBI_ERR_QUOTING_STR "Error quoting string: %s" +#define DBI_ERR_STATEMENT_BROKEN "Statement unavailable: database closed" /* * convert string to lower case */ -const char *strlower(char *in); +const char *dbd_strlower(char *in); /* * replace '?' placeholders with .\d+ placeholders * to be compatible with the native driver API */ -char *replace_placeholders(lua_State *L, char native_prefix, const char *sql); +char *dbd_replace_placeholders(lua_State *L, char native_prefix, const char *sql); +void dbd_register(lua_State *L, const char *name, + const luaL_Reg *methods, const luaL_Reg *class_methods, + lua_CFunction gc, lua_CFunction tostring); diff -Nru lua-dbi-0.5.hg5ba1dd988961/dbd/db2/connection.c lua-dbi-0.6/dbd/db2/connection.c --- lua-dbi-0.5.hg5ba1dd988961/dbd/db2/connection.c 2013-08-10 18:33:16.000000000 +0000 +++ lua-dbi-0.6/dbd/db2/connection.c 2017-08-23 21:14:17.000000000 +0000 @@ -1,4 +1,5 @@ #include "dbd_db2.h" +#include "db2_common.h" int dbd_db2_statement_create(lua_State *L, connection_t *conn, const char *sql_query); @@ -32,9 +33,6 @@ const char *db = NULL; SQLCHAR message[SQL_MAX_MESSAGE_LENGTH + 1]; - SQLCHAR sqlstate[SQL_SQLSTATE_SIZE + 1]; - SQLINTEGER sqlcode; - SQLSMALLINT length; /* db, user, password */ switch(n) { @@ -90,7 +88,7 @@ /* connect to the database */ rc = SQLConnect(conn->db2, (SQLCHAR *)db, SQL_NTS, (SQLCHAR *)user, SQL_NTS, (SQLCHAR *)password, SQL_NTS); if (rc != SQL_SUCCESS) { - SQLGetDiagRec(SQL_HANDLE_DBC, conn->db2, 1, sqlstate, &sqlcode, message, SQL_MAX_MESSAGE_LENGTH + 1, &length); + db2_dbc_diag(conn->db2, message, sizeof(message)); lua_pushnil(L); lua_pushfstring(L, DBI_ERR_CONNECTION_FAILED, message); @@ -129,23 +127,22 @@ static int connection_close(lua_State *L) { connection_t *conn = (connection_t *)luaL_checkudata(L, 1, DBD_DB2_CONNECTION); int disconnect = 0; - SQLRETURN rc = SQL_SUCCESS; if (conn->db2) { rollback(conn); /* disconnect from the database */ - rc = SQLDisconnect(conn->db2); + (void)SQLDisconnect(conn->db2); /* free connection handle */ - rc = SQLFreeHandle(SQL_HANDLE_DBC, conn->db2); + (void)SQLFreeHandle(SQL_HANDLE_DBC, conn->db2); conn->db2 = 0; } if (conn->env) { /* free environment handle */ - rc = SQLFreeHandle(SQL_HANDLE_ENV, conn->env); + (void)SQLFreeHandle(SQL_HANDLE_ENV, conn->env); } lua_pushboolean(L, disconnect); @@ -221,6 +218,14 @@ } /* + * last_id = connection:last_id() + */ +static int connection_lastid(lua_State *L) { + luaL_error(L, DBI_ERR_NOT_IMPLEMENTED, DBD_POSTGRESQL_CONNECTION, "last_id"); + return 0; +} + +/* * __gc */ static int connection_gc(lua_State *L) { @@ -250,6 +255,7 @@ {"prepare", connection_prepare}, {"quote", connection_quote}, {"rollback", connection_rollback}, + {"last_id", connection_lastid}, {NULL, NULL} }; @@ -258,18 +264,9 @@ {NULL, NULL} }; - luaL_newmetatable(L, DBD_DB2_CONNECTION); - luaL_register(L, 0, connection_methods); - lua_pushvalue(L,-1); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, connection_gc); - lua_setfield(L, -2, "__gc"); - - lua_pushcfunction(L, connection_tostring); - lua_setfield(L, -2, "__tostring"); - - luaL_register(L, DBD_DB2_CONNECTION, connection_class_methods); + dbd_register(L, DBD_DB2_CONNECTION, + connection_methods, connection_class_methods, + connection_gc, connection_tostring); return 1; } diff -Nru lua-dbi-0.5.hg5ba1dd988961/dbd/db2/db2_common.c lua-dbi-0.6/dbd/db2/db2_common.c --- lua-dbi-0.5.hg5ba1dd988961/dbd/db2/db2_common.c 1970-01-01 00:00:00.000000000 +0000 +++ lua-dbi-0.6/dbd/db2/db2_common.c 2017-08-23 21:14:17.000000000 +0000 @@ -0,0 +1,25 @@ +#include "dbd_db2.h" +#include "db2_common.h" + +void db2_stmt_diag(SQLHANDLE stmt, + SQLCHAR *msg, + SQLINTEGER msglen) { + SQLCHAR sqlstate[SQL_SQLSTATE_SIZE + 1]; + SQLINTEGER sqlcode; + SQLSMALLINT length; + + SQLGetDiagRec(SQL_HANDLE_STMT, stmt, 1, sqlstate, &sqlcode, msg, msglen, + &length); +} + +void db2_dbc_diag(SQLHANDLE dbc, + SQLCHAR *msg, + SQLINTEGER msglen) { + SQLCHAR sqlstate[SQL_SQLSTATE_SIZE + 1]; + SQLINTEGER sqlcode; + SQLSMALLINT length; + + SQLGetDiagRec(SQL_HANDLE_DBC, dbc, 1, sqlstate, &sqlcode, msg, msglen, + &length); +} + diff -Nru lua-dbi-0.5.hg5ba1dd988961/dbd/db2/db2_common.h lua-dbi-0.6/dbd/db2/db2_common.h --- lua-dbi-0.5.hg5ba1dd988961/dbd/db2/db2_common.h 1970-01-01 00:00:00.000000000 +0000 +++ lua-dbi-0.6/dbd/db2/db2_common.h 2017-08-23 21:14:17.000000000 +0000 @@ -0,0 +1,12 @@ +#ifndef DBD_DB2_COMMON_H +#define DBD_DB2_COMMON_H + +void db2_stmt_diag(SQLHANDLE stmt, + SQLCHAR *msg, + SQLINTEGER msglen); + +void db2_dbc_diag(SQLHANDLE dbc, + SQLCHAR *msg, + SQLINTEGER msglen); + +#endif /* DBD_DB2_COMMON_H */ diff -Nru lua-dbi-0.5.hg5ba1dd988961/dbd/db2/dbd_db2.h lua-dbi-0.6/dbd/db2/dbd_db2.h --- lua-dbi-0.5.hg5ba1dd988961/dbd/db2/dbd_db2.h 2013-08-10 18:33:16.000000000 +0000 +++ lua-dbi-0.6/dbd/db2/dbd_db2.h 2017-08-23 21:14:17.000000000 +0000 @@ -12,24 +12,25 @@ * result set metadata */ +typedef union _resultset_data { + SQLCHAR *str; + lua_Number number; + lua_Integer integer; + int boolean; +} resultset_data_t; + typedef struct _resultset { SQLSMALLINT name_len; SQLSMALLINT type; SQLUINTEGER size; SQLSMALLINT scale; + SQLINTEGER actual_len; + lua_push_type_t lua_type; + resultset_data_t data; SQLCHAR name[32]; } resultset_t; /* - * bind parameters - */ -typedef struct _bindparams { - SQLCHAR *buffer; - SQLINTEGER len; - SQLINTEGER buffer_len; -} bindparams_t; - -/* * connection object implentation */ typedef struct _connection { @@ -42,11 +43,13 @@ */ typedef struct _statement { resultset_t * resultset; - bindparams_t * bind; unsigned char *buffer; SQLSMALLINT num_result_columns; /* variable for SQLNumResultCols */ SQLHANDLE stmt; SQLHANDLE db2; + int cursor_open; + SQLSMALLINT num_params; + unsigned char *parambuf; } statement_t; diff -Nru lua-dbi-0.5.hg5ba1dd988961/dbd/db2/main.c lua-dbi-0.6/dbd/db2/main.c --- lua-dbi-0.5.hg5ba1dd988961/dbd/db2/main.c 2013-08-10 18:33:16.000000000 +0000 +++ lua-dbi-0.6/dbd/db2/main.c 2017-08-23 21:14:17.000000000 +0000 @@ -6,9 +6,9 @@ /* * library entry point */ -LUA_EXPORT int luaopen_dbddb2(lua_State *L) { - dbd_db2_connection(L); +LUA_EXPORT int luaopen_dbd_db2(lua_State *L) { dbd_db2_statement(L); + dbd_db2_connection(L); return 1; } diff -Nru lua-dbi-0.5.hg5ba1dd988961/dbd/db2/statement.c lua-dbi-0.6/dbd/db2/statement.c --- lua-dbi-0.5.hg5ba1dd988961/dbd/db2/statement.c 2013-08-10 18:33:16.000000000 +0000 +++ lua-dbi-0.6/dbd/db2/statement.c 2017-08-23 21:14:17.000000000 +0000 @@ -1,23 +1,27 @@ #include "dbd_db2.h" +#include "db2_common.h" #define BIND_BUFFER_SIZE 1024 -static lua_push_type_t db2_to_lua_push(unsigned int db2_type, int len) { +static lua_push_type_t db2_to_lua_push(unsigned int db2_type) { lua_push_type_t lua_type; - if (len == SQL_NULL_DATA) - return LUA_PUSH_NIL; - switch(db2_type) { - case SQL_SMALLINT: - case SQL_INTEGER: - lua_type = LUA_PUSH_INTEGER; - break; - case SQL_DECIMAL: - lua_type = LUA_PUSH_NUMBER; - break; - default: - lua_type = LUA_PUSH_STRING; + case SQL_BOOLEAN: + lua_type = LUA_PUSH_BOOLEAN; + case SQL_SMALLINT: + case SQL_INTEGER: + lua_type = LUA_PUSH_INTEGER; + break; + case SQL_FLOAT: + case SQL_REAL: + case SQL_DOUBLE: + case SQL_DECIMAL: + lua_type = LUA_PUSH_NUMBER; + break; + break; + default: + lua_type = LUA_PUSH_STRING; } return lua_type; @@ -28,15 +32,13 @@ */ static int statement_affected(lua_State *L) { statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_DB2_STATEMENT); - SQLRETURN rc = SQL_SUCCESS; SQLINTEGER affected; if (!statement->stmt) { luaL_error(L, DBI_ERR_INVALID_STATEMENT); } - rc = SQLRowCount(statement->stmt, &affected); - + (void)SQLRowCount(statement->stmt, &affected); lua_pushinteger(L, affected); @@ -44,31 +46,38 @@ } /* + * free cursor and associated memory + */ +static void free_cursor(statement_t *statement) { + if (statement->cursor_open) { + SQLFreeStmt(statement->stmt, SQL_CLOSE); + statement->cursor_open = 0; + } +} + +/* * success = statement:close() */ static int statement_close(lua_State *L) { statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_DB2_STATEMENT); - if (statement->stmt) { - SQLFreeHandle(SQL_HANDLE_STMT, statement->stmt); - - if (statement->resultset) { - free(statement->resultset); - statement->resultset = NULL; - } + free_cursor(statement); - if (statement->bind) { - int i; + if (statement->resultset) { + free(statement->resultset); + statement->resultset = NULL; + } - for (i = 0; i < statement->num_result_columns; i++) { - free(statement->bind[i].buffer); - } + if (statement->parambuf) { + free(statement->parambuf); + statement->parambuf = NULL; + } - free(statement->bind); - statement->bind = NULL; - } + statement->num_result_columns = 0; - statement->num_result_columns = 0; + if (statement->stmt) { + SQLFreeHandle(SQL_HANDLE_STMT, statement->stmt); + statement->stmt = SQL_NULL_HSTMT; } return 0; @@ -83,9 +92,7 @@ int i; int d; - SQLRETURN rc = SQL_SUCCESS; - - if (!statement->resultset || !statement->bind) { + if (!statement->resultset) { lua_pushnil(L); return 1; } @@ -93,7 +100,7 @@ d = 1; lua_newtable(L); for (i = 0; i < statement->num_result_columns; i++) { - const char *name = strlower(statement->resultset[i].name); + const char *name = dbd_strlower((char *)statement->resultset[i].name); LUA_PUSH_ARRAY_STRING(d, name); } @@ -107,20 +114,13 @@ statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_DB2_STATEMENT); int n = lua_gettop(L); int p; - int i; int errflag = 0; const char *errstr = NULL; SQLRETURN rc = SQL_SUCCESS; - unsigned char *buffer = NULL; + unsigned char *buffer = statement->parambuf; int offset = 0; - resultset_t *resultset = NULL; - bindparams_t *bind; /* variable to read the results */ - SQLSMALLINT num_params; SQLCHAR message[SQL_MAX_MESSAGE_LENGTH + 1]; - SQLCHAR sqlstate[SQL_SQLSTATE_SIZE + 1]; - SQLINTEGER sqlcode; - SQLSMALLINT length; if (!statement->stmt) { lua_pushboolean(L, 0); @@ -128,30 +128,20 @@ return 2; } - rc = SQLNumParams(statement->stmt, &num_params); - if (rc != SQL_SUCCESS) { - SQLGetDiagRec(SQL_HANDLE_STMT, statement->stmt, 1, sqlstate, &sqlcode, message, SQL_MAX_MESSAGE_LENGTH + 1, &length); - - lua_pushboolean(L, 0); - lua_pushfstring(L, DBI_ERR_PREP_STATEMENT, message); - return 2; - } + /* If the cursor is open from a previous execute, close it */ + free_cursor(statement); - if (num_params != n-1) { + if (statement->num_params != n-1) { /* * SQLExecute does not handle this condition, * and the client library will fill unset params * with NULLs */ lua_pushboolean(L, 0); - lua_pushfstring(L, DBI_ERR_PARAM_MISCOUNT, num_params, n-1); + lua_pushfstring(L, DBI_ERR_PARAM_MISCOUNT, statement->num_params, n-1); return 2; } - if (num_params > 0) { - buffer = (unsigned char *)malloc(sizeof(double) * num_params); - } - for (p = 2; p <= n; p++) { int i = p - 1; int type = lua_type(L, p); @@ -200,16 +190,12 @@ } if (errflag) { - if (buffer) - free(buffer); - lua_pushboolean(L, 0); if (errstr) { lua_pushfstring(L, DBI_ERR_BINDING_PARAMS, errstr); } else { - SQLGetDiagRec(SQL_HANDLE_STMT, statement->stmt, 1, sqlstate, &sqlcode, message, SQL_MAX_MESSAGE_LENGTH + 1, &length); - + db2_stmt_diag(statement->stmt, message, sizeof(message)); lua_pushfstring(L, DBI_ERR_BINDING_PARAMS, message); } @@ -218,175 +204,92 @@ rc = SQLExecute(statement->stmt); if (rc != SQL_SUCCESS) { - if (buffer) - free(buffer); - - SQLGetDiagRec(SQL_HANDLE_STMT, statement->stmt, 1, sqlstate, &sqlcode, message, SQL_MAX_MESSAGE_LENGTH + 1, &length); - + db2_stmt_diag(statement->stmt, message, sizeof(message)); lua_pushnil(L); lua_pushfstring(L, DBI_ERR_PREP_STATEMENT, message); return 2; } - /* - * identify the number of output columns - */ - rc = SQLNumResultCols(statement->stmt, &statement->num_result_columns); - - if (statement->num_result_columns > 0) { - resultset = (resultset_t *)malloc(sizeof(resultset_t) * statement->num_result_columns); - memset(resultset, 0, sizeof(resultset_t) * statement->num_result_columns); - - bind = (bindparams_t *)malloc(sizeof(bindparams_t) * statement->num_result_columns); - memset(bind, 0, sizeof(bindparams_t) * statement->num_result_columns); - - for (i = 0; i < statement->num_result_columns; i++) { - /* - * return a set of attributes for a column - */ - rc = SQLDescribeCol(statement->stmt, - (SQLSMALLINT)(i + 1), - resultset[i].name, - sizeof(resultset[i].name), - &resultset[i].name_len, - &resultset[i].type, - &resultset[i].size, - &resultset[i].scale, - NULL); - - if (rc != SQL_SUCCESS) { - if (buffer) - free(buffer); - - SQLGetDiagRec(SQL_HANDLE_STMT, statement->stmt, 1, sqlstate, &sqlcode, message, SQL_MAX_MESSAGE_LENGTH + 1, &length); - - lua_pushnil(L); - lua_pushfstring(L, DBI_ERR_DESC_RESULT, message); - return 2; - } - - bind[i].buffer_len = resultset[i].size+1; - - /* - *allocate memory to bind a column - */ - bind[i].buffer = (SQLCHAR *)malloc((int)bind[i].buffer_len); - - rc = SQLBindCol(statement->stmt, - (SQLSMALLINT)(i + 1), - SQL_C_CHAR, - bind[i].buffer, - bind[i].buffer_len, - &bind[i].len); - - if (rc != SQL_SUCCESS) { - if (buffer) - free(buffer); - - SQLGetDiagRec(SQL_HANDLE_STMT, statement->stmt, 1, sqlstate, &sqlcode, message, SQL_MAX_MESSAGE_LENGTH + 1, &length); - - lua_pushnil(L); - lua_pushfstring(L, DBI_ERR_ALLOC_RESULT, message); - return 2; - } - } - - statement->resultset = resultset; - statement->bind = bind; - } - - if (buffer) - free(buffer); + statement->cursor_open = 1; lua_pushboolean(L, 1); return 1; } + + /* * must be called after an execute */ -static int statement_fetch_impl(lua_State *L, statement_t *statement, int named_columns) { +static int statement_fetch_impl(lua_State *L, statement_t *statement, + int named_columns) { int i; int d; SQLCHAR message[SQL_MAX_MESSAGE_LENGTH + 1]; - SQLCHAR sqlstate[SQL_SQLSTATE_SIZE + 1]; - SQLINTEGER sqlcode; - SQLSMALLINT length; - - SQLRETURN rc = SQL_SUCCESS; + SQLRETURN rc; - if (!statement->resultset || !statement->bind) { - lua_pushnil(L); - return 1; - } + if (!statement->cursor_open) + goto nodata; /* fetch each row, and display */ rc = SQLFetch(statement->stmt); if (rc == SQL_NO_DATA_FOUND) { - SQLFreeStmt(statement->stmt, SQL_RESET_PARAMS); - lua_pushnil(L); - return 1; + free_cursor(statement); + goto nodata; } if (rc != SQL_SUCCESS) { - SQLGetDiagRec(SQL_HANDLE_STMT, statement->stmt, 1, sqlstate, &sqlcode, message, SQL_MAX_MESSAGE_LENGTH + 1, &length); - + db2_stmt_diag(statement->stmt, message, sizeof(message)); luaL_error(L, DBI_ERR_FETCH_FAILED, message); } d = 1; lua_newtable(L); for (i = 0; i < statement->num_result_columns; i++) { - lua_push_type_t lua_push = db2_to_lua_push(statement->resultset[i].type, statement->bind[i].len); - const char *name = strlower(statement->resultset[i].name); - double val; - char *value = (char *)statement->bind[i].buffer; - - switch (lua_push) { - case LUA_PUSH_NIL: - if (named_columns) { - LUA_PUSH_ATTRIB_NIL(name); - } else { - LUA_PUSH_ARRAY_NIL(d); - } - break; - case LUA_PUSH_INTEGER: - if (named_columns) { - LUA_PUSH_ATTRIB_INT(name, atoi(value)); - } else { - LUA_PUSH_ARRAY_INT(d, atoi(value)); - } - break; - case LUA_PUSH_NUMBER: - val = strtod(value, NULL); + resultset_t *rs = &statement->resultset[i]; + SQLCHAR *name = rs->name; + lua_push_type_t lua_type = rs->lua_type; + resultset_data_t *data = &(rs->data); - if (named_columns) { - LUA_PUSH_ATTRIB_FLOAT(name, val); - } else { - LUA_PUSH_ARRAY_FLOAT(d, val); - } - break; - case LUA_PUSH_BOOLEAN: - if (named_columns) { - LUA_PUSH_ATTRIB_BOOL(name, atoi(value)); - } else { - LUA_PUSH_ARRAY_BOOL(d, atoi(value)); - } - break; - case LUA_PUSH_STRING: - if (named_columns) { - LUA_PUSH_ATTRIB_STRING(name, value); - } else { - LUA_PUSH_ARRAY_STRING(d, value); - } - break; - default: - luaL_error(L, DBI_ERR_UNKNOWN_PUSH); + if (rs->actual_len == SQL_NULL_DATA) + lua_type = LUA_PUSH_NIL; + + if (named_columns) + lua_pushstring(L, (const char *)name); + + switch (lua_type) { + case LUA_PUSH_NIL: + lua_pushnil(L); + break; + case LUA_PUSH_INTEGER: + lua_pushinteger(L, data->integer); + break; + case LUA_PUSH_NUMBER: + lua_pushnumber(L, data->number); + break; + case LUA_PUSH_BOOLEAN: + lua_pushboolean(L, data->boolean); + break; + case LUA_PUSH_STRING: + lua_pushstring(L, (const char *)data->str); + break; + default: + luaL_error(L, DBI_ERR_UNKNOWN_PUSH); + } + + if (named_columns) + lua_rawset(L, -3); + else { + lua_rawseti(L, -2, d); + d++; } } return 1; +nodata: + lua_pushnil(L); + return 1; } @@ -457,16 +360,19 @@ SQLRETURN rc = SQL_SUCCESS; statement_t *statement = NULL; SQLHANDLE stmt; - SQLCHAR message[SQL_MAX_MESSAGE_LENGTH + 1]; - SQLCHAR sqlstate[SQL_SQLSTATE_SIZE + 1]; - SQLINTEGER sqlcode; - SQLSMALLINT length; + SQLCHAR *buffer = NULL; + int buflen; + SQLSMALLINT sqlctype; + SQLPOINTER dataptr; + int datalen; + + resultset_t *resultset = NULL; + int i; rc = SQLAllocHandle(SQL_HANDLE_STMT, conn->db2, &stmt); if (rc != SQL_SUCCESS) { - SQLGetDiagRec(SQL_HANDLE_DBC, conn->db2, 1, sqlstate, &sqlcode, message, SQL_MAX_MESSAGE_LENGTH + 1, &length); - + db2_dbc_diag(conn->db2, message, sizeof(message)); lua_pushnil(L); lua_pushfstring(L, DBI_ERR_ALLOC_STATEMENT, message); return 2; @@ -482,8 +388,7 @@ rc = SQLPrepare(stmt, (SQLCHAR *)sql_query, SQL_NTS); if (rc != SQL_SUCCESS) { - SQLGetDiagRec(SQL_HANDLE_STMT, stmt, 1, sqlstate, &sqlcode, message, SQL_MAX_MESSAGE_LENGTH + 1, &length); - + db2_stmt_diag(stmt, message, sizeof(message)); lua_pushnil(L); lua_pushfstring(L, DBI_ERR_PREP_STATEMENT, message); return 2; @@ -493,8 +398,104 @@ statement->stmt = stmt; statement->db2 = conn->db2; statement->resultset = NULL; - statement->bind = NULL; + statement->cursor_open = 0; + statement->num_params = 0; + statement->parambuf = NULL; + + /* + * identify the number of input parameters + */ + rc = SQLNumParams(stmt, &statement->num_params); + if (rc != SQL_SUCCESS) { + db2_stmt_diag(stmt, message, sizeof(message)); + lua_pushboolean(L, 0); + lua_pushfstring(L, DBI_ERR_PREP_STATEMENT, message); + return 2; + } + if (statement->num_params > 0) { + statement->parambuf = (unsigned char *)malloc(sizeof(double) * + statement->num_params); + } + + /* + * identify the number of output columns + */ + rc = SQLNumResultCols(stmt, &statement->num_result_columns); + + if (statement->num_result_columns > 0) { + resultset = (resultset_t *)malloc(sizeof(resultset_t) * + statement->num_result_columns); + memset(resultset, 0, sizeof(resultset_t) * + statement->num_result_columns); + buflen = 0; + for (i = 0; i < statement->num_result_columns; i++) { + /* + * return a set of attributes for a column + */ + rc = SQLDescribeCol(stmt, + (SQLSMALLINT)(i + 1), + resultset[i].name, + sizeof(resultset[i].name), + &resultset[i].name_len, + &resultset[i].type, + &resultset[i].size, + &resultset[i].scale, + NULL); + + if (rc != SQL_SUCCESS) { + db2_stmt_diag(stmt, message, sizeof(message)); + lua_pushnil(L); + lua_pushfstring(L, DBI_ERR_DESC_RESULT, message); + return 2; + } + + resultset[i].lua_type = db2_to_lua_push(resultset[i].type); + if (resultset[i].lua_type == LUA_PUSH_STRING) + buflen += (resultset[i].size + 1 + 3) & ~3; + } + + if (buflen > 0) + buffer = malloc(buflen); + + for (i = 0; i < statement->num_result_columns; i++) { + switch (resultset[i].lua_type) { + case LUA_PUSH_INTEGER: + sqlctype = SQL_C_LONG; + dataptr = &resultset[i].data.integer; + datalen = 0; + break; + case LUA_PUSH_NUMBER: + sqlctype = SQL_C_DOUBLE; + dataptr = &resultset[i].data.number; + datalen = 0; + break; + default: + sqlctype = SQL_C_CHAR; + resultset[i].data.str = buffer; + dataptr = buffer; + datalen = resultset[i].size + 1; + buffer += (datalen + 3) & ~3; + break; + } + + rc = SQLBindCol(stmt, + (SQLSMALLINT)(i + 1), + sqlctype, + dataptr, + datalen, + &resultset[i].actual_len); + + if (rc != SQL_SUCCESS) { + db2_stmt_diag(stmt, message, sizeof(message)); + lua_pushnil(L); + lua_pushfstring(L, DBI_ERR_ALLOC_RESULT, message); + return 2; + } + } + + statement->resultset = resultset; + } luaL_getmetatable(L, DBD_DB2_STATEMENT); lua_setmetatable(L, -2); @@ -517,18 +518,9 @@ {NULL, NULL} }; - luaL_newmetatable(L, DBD_DB2_STATEMENT); - luaL_register(L, 0, statement_methods); - lua_pushvalue(L,-1); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, statement_gc); - lua_setfield(L, -2, "__gc"); - - lua_pushcfunction(L, statement_tostring); - lua_setfield(L, -2, "__tostring"); - - luaL_register(L, DBD_DB2_STATEMENT, statement_class_methods); + dbd_register(L, DBD_DB2_STATEMENT, + statement_methods, statement_class_methods, + statement_gc, statement_tostring); return 1; } diff -Nru lua-dbi-0.5.hg5ba1dd988961/dbd/mysql/connection.c lua-dbi-0.6/dbd/mysql/connection.c --- lua-dbi-0.5.hg5ba1dd988961/dbd/mysql/connection.c 2013-08-10 18:33:16.000000000 +0000 +++ lua-dbi-0.6/dbd/mysql/connection.c 2017-08-23 21:14:17.000000000 +0000 @@ -16,17 +16,23 @@ const char *db = NULL; int port = 0; - const char *unix_socket = NULL; /* TODO always NULL */ + const char *unix_socket = NULL; int client_flag = 0; /* TODO always 0, set flags from options table */ /* db, user, password, host, port */ switch (n) { case 5: if (lua_isnil(L, 5) == 0) - port = luaL_checkint(L, 5); + port = luaL_checkinteger(L, 5); case 4: if (lua_isnil(L, 4) == 0) host = luaL_checkstring(L, 4); + if (host != NULL) { + if (host[0] == '/') { + unix_socket = host; + host = NULL; + }; + }; case 3: if (lua_isnil(L, 3) == 0) password = luaL_checkstring(L, 3); @@ -178,6 +184,16 @@ } /* + * last_id = statement:last_id() + */ +static int connection_lastid(lua_State *L) { + connection_t *conn = (connection_t *)luaL_checkudata(L, 1, DBD_MYSQL_CONNECTION); + + lua_pushinteger(L, mysql_insert_id( conn->mysql )); + return 1; +} + +/* * __gc */ static int connection_gc(lua_State *L) { @@ -207,6 +223,7 @@ {"prepare", connection_prepare}, {"quote", connection_quote}, {"rollback", connection_rollback}, + {"last_id", connection_lastid}, {NULL, NULL} }; @@ -215,18 +232,9 @@ {NULL, NULL} }; - luaL_newmetatable(L, DBD_MYSQL_CONNECTION); - luaL_register(L, 0, connection_methods); - lua_pushvalue(L,-1); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, connection_gc); - lua_setfield(L, -2, "__gc"); - - lua_pushcfunction(L, connection_tostring); - lua_setfield(L, -2, "__tostring"); - - luaL_register(L, DBD_MYSQL_CONNECTION, connection_class_methods); + dbd_register(L, DBD_MYSQL_CONNECTION, + connection_methods, connection_class_methods, + connection_gc, connection_tostring); return 1; } diff -Nru lua-dbi-0.5.hg5ba1dd988961/dbd/mysql/dbd_mysql.h lua-dbi-0.6/dbd/mysql/dbd_mysql.h --- lua-dbi-0.5.hg5ba1dd988961/dbd/mysql/dbd_mysql.h 2013-08-10 18:33:16.000000000 +0000 +++ lua-dbi-0.6/dbd/mysql/dbd_mysql.h 2017-08-23 21:14:17.000000000 +0000 @@ -20,8 +20,12 @@ * statement object implementation */ typedef struct _statement { - MYSQL *mysql; + connection_t *conn; MYSQL_STMT *stmt; - MYSQL_RES *metadata; /* result dataset metadata */ + MYSQL_RES *metadata; /* result dataset metadata */ + + unsigned long *lengths; /* length of retrieved data + we have to keep this from bind time to + result retrival time */ } statement_t; diff -Nru lua-dbi-0.5.hg5ba1dd988961/dbd/mysql/main.c lua-dbi-0.6/dbd/mysql/main.c --- lua-dbi-0.5.hg5ba1dd988961/dbd/mysql/main.c 2013-08-10 18:33:16.000000000 +0000 +++ lua-dbi-0.6/dbd/mysql/main.c 2017-08-23 21:14:17.000000000 +0000 @@ -4,11 +4,11 @@ int dbd_mysql_statement(lua_State *L); /* - * libabry entry point + * library entry point */ -LUA_EXPORT int luaopen_dbdmysql(lua_State *L) { - dbd_mysql_connection(L); +LUA_EXPORT int luaopen_dbd_mysql(lua_State *L) { dbd_mysql_statement(L); + dbd_mysql_connection(L); return 1; } diff -Nru lua-dbi-0.5.hg5ba1dd988961/dbd/mysql/statement.c lua-dbi-0.6/dbd/mysql/statement.c --- lua-dbi-0.5.hg5ba1dd988961/dbd/mysql/statement.c 2013-08-10 18:33:16.000000000 +0000 +++ lua-dbi-0.6/dbd/mysql/statement.c 2017-08-23 21:14:17.000000000 +0000 @@ -11,10 +11,12 @@ case MYSQL_TYPE_TINY: case MYSQL_TYPE_YEAR: case MYSQL_TYPE_SHORT: - case MYSQL_TYPE_LONG: + case MYSQL_TYPE_INT24: + case MYSQL_TYPE_LONG: lua_type = LUA_PUSH_INTEGER; break; + case MYSQL_TYPE_FLOAT: case MYSQL_TYPE_DOUBLE: case MYSQL_TYPE_LONGLONG: lua_type = LUA_PUSH_NUMBER; @@ -89,13 +91,18 @@ statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_MYSQL_STATEMENT); if (statement->metadata) { - mysql_free_result(statement->metadata); - statement->metadata = NULL; + mysql_free_result(statement->metadata); + statement->metadata = NULL; } + if (statement->lengths) { + free(statement->lengths); + statement->lengths = NULL; + } + if (statement->stmt) { - mysql_stmt_close(statement->stmt); - statement->stmt = NULL; + mysql_stmt_close(statement->stmt); + statement->stmt = NULL; } lua_pushboolean(L, 1); @@ -151,6 +158,17 @@ int p; + + /* + * Sanity check(s) + */ + if (statement->conn->mysql == NULL) + { + lua_pushstring(L, DBI_ERR_STATEMENT_BROKEN); + lua_error(L); + } + + if (statement->metadata) { /* * free existing metadata from any previous executions @@ -288,7 +306,6 @@ static int statement_fetch_impl(lua_State *L, statement_t *statement, int named_columns) { int column_count, fetch_result_ok; MYSQL_BIND *bind = NULL; - unsigned long *real_length = NULL; const char *error_message = NULL; if (!statement->stmt) { @@ -307,7 +324,12 @@ int i; MYSQL_FIELD *fields; - real_length = calloc(column_count, sizeof(unsigned long)); + if (statement->lengths) { + free(statement->lengths); + statement->lengths = NULL; + } + + statement->lengths = calloc(column_count, sizeof(unsigned long)); bind = malloc(sizeof(MYSQL_BIND) * column_count); memset(bind, 0, sizeof(MYSQL_BIND) * column_count); @@ -328,7 +350,7 @@ } bind[i].buffer_type = fields[i].type; - bind[i].length = &real_length[i]; + bind[i].length = &(statement->lengths[i]); } if (mysql_stmt_bind_result(statement->stmt, bind)) { @@ -346,9 +368,9 @@ const char *name = fields[i].name; if (bind[i].buffer == NULL) { - char *buffer = (char *)calloc(real_length[i]+1, sizeof(char)); + char *buffer = (char *)calloc(statement->lengths[i]+1, sizeof(char)); bind[i].buffer = buffer; - bind[i].buffer_length = real_length[i]; + bind[i].buffer_length = statement->lengths[i]; mysql_stmt_fetch_column(statement->stmt, &bind[i], i, 0); } @@ -379,11 +401,25 @@ } } } else if (lua_push == LUA_PUSH_NUMBER) { - if (named_columns) { - LUA_PUSH_ATTRIB_FLOAT(name, *(double *)(bind[i].buffer)); - } else { - LUA_PUSH_ARRAY_FLOAT(d, *(double *)(bind[i].buffer)); - } + if (fields[i].type == MYSQL_TYPE_FLOAT) { + if (named_columns) { + LUA_PUSH_ATTRIB_FLOAT(name, *(float *)(bind[i].buffer)); + } else { + LUA_PUSH_ARRAY_FLOAT(d, *(float *)(bind[i].buffer)); + } + } else if (fields[i].type == MYSQL_TYPE_DOUBLE) { + if (named_columns) { + LUA_PUSH_ATTRIB_FLOAT(name, *(double *)(bind[i].buffer)); + } else { + LUA_PUSH_ARRAY_FLOAT(d, *(double *)(bind[i].buffer)); + } + } else { + if (named_columns) { + LUA_PUSH_ATTRIB_FLOAT(name, *(long long *)(bind[i].buffer)); + } else { + LUA_PUSH_ARRAY_FLOAT(d, *(long long *)(bind[i].buffer)); + } + } } else if (lua_push == LUA_PUSH_STRING) { if (fields[i].type == MYSQL_TYPE_TIMESTAMP || fields[i].type == MYSQL_TYPE_DATETIME) { @@ -422,9 +458,9 @@ } else { if (named_columns) { - LUA_PUSH_ATTRIB_STRING(name, bind[i].buffer); + LUA_PUSH_ATTRIB_STRING_BY_LENGTH(name, bind[i].buffer, *bind[i].length); } else { - LUA_PUSH_ARRAY_STRING(d, bind[i].buffer); + LUA_PUSH_ARRAY_STRING_BY_LENGTH(d, bind[i].buffer, *bind[i].length); } } } else if (lua_push == LUA_PUSH_BOOLEAN) { @@ -443,7 +479,6 @@ } cleanup: - free(real_length); if (bind) { int i; @@ -552,9 +587,10 @@ } statement = (statement_t *)lua_newuserdata(L, sizeof(statement_t)); - statement->mysql = conn->mysql; + statement->conn = conn; statement->stmt = stmt; statement->metadata = NULL; + statement->lengths = NULL; /* mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, (my_bool*)0); @@ -582,18 +618,9 @@ {NULL, NULL} }; - luaL_newmetatable(L, DBD_MYSQL_STATEMENT); - luaL_register(L, 0, statement_methods); - lua_pushvalue(L,-1); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, statement_gc); - lua_setfield(L, -2, "__gc"); - - lua_pushcfunction(L, statement_tostring); - lua_setfield(L, -2, "__tostring"); - - luaL_register(L, DBD_MYSQL_STATEMENT, statement_class_methods); + dbd_register(L, DBD_MYSQL_STATEMENT, + statement_methods, statement_class_methods, + statement_gc, statement_tostring); return 1; } diff -Nru lua-dbi-0.5.hg5ba1dd988961/dbd/oracle/connection.c lua-dbi-0.6/dbd/oracle/connection.c --- lua-dbi-0.5.hg5ba1dd988961/dbd/oracle/connection.c 2013-08-10 18:33:16.000000000 +0000 +++ lua-dbi-0.6/dbd/oracle/connection.c 2017-08-23 21:14:17.000000000 +0000 @@ -207,6 +207,14 @@ } /* + * last_id = connection:last_id() + */ +static int connection_lastid(lua_State *L) { + luaL_error(L, DBI_ERR_NOT_IMPLEMENTED, DBD_POSTGRESQL_CONNECTION, "last_id"); + return 0; +} + +/* * __gc */ static int connection_gc(lua_State *L) { @@ -239,6 +247,7 @@ {"prepare", connection_prepare}, {"quote", connection_quote}, {"rollback", connection_rollback}, + {"last_id", connection_lastid}, {NULL, NULL} }; @@ -250,18 +259,9 @@ {NULL, NULL} }; - luaL_newmetatable(L, DBD_ORACLE_CONNECTION); - luaL_register(L, 0, connection_methods); - lua_pushvalue(L,-1); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, connection_gc); - lua_setfield(L, -2, "__gc"); - - lua_pushcfunction(L, connection_tostring); - lua_setfield(L, -2, "__tostring"); - - luaL_register(L, DBD_ORACLE_CONNECTION, connection_class_methods); + dbd_register(L, DBD_ORACLE_CONNECTION, + connection_methods, connection_class_methods, + connection_gc, connection_tostring); - return 1; + return 1; } diff -Nru lua-dbi-0.5.hg5ba1dd988961/dbd/oracle/main.c lua-dbi-0.6/dbd/oracle/main.c --- lua-dbi-0.5.hg5ba1dd988961/dbd/oracle/main.c 2013-08-10 18:33:16.000000000 +0000 +++ lua-dbi-0.6/dbd/oracle/main.c 2017-08-23 21:14:17.000000000 +0000 @@ -6,9 +6,9 @@ /* * library entry point */ -LUA_EXPORT int luaopen_dbdoracle(lua_State *L) { - dbd_oracle_connection(L); +LUA_EXPORT int luaopen_dbd_oracle(lua_State *L) { dbd_oracle_statement(L); + dbd_oracle_connection(L); return 1; } diff -Nru lua-dbi-0.5.hg5ba1dd988961/dbd/oracle/statement.c lua-dbi-0.6/dbd/oracle/statement.c --- lua-dbi-0.5.hg5ba1dd988961/dbd/oracle/statement.c 2013-08-10 18:33:16.000000000 +0000 +++ lua-dbi-0.6/dbd/oracle/statement.c 2017-08-23 21:14:17.000000000 +0000 @@ -157,7 +157,7 @@ lua_newtable(L); for (i = 0; i < statement->num_columns; i++) { - const char *name = strlower(statement->bind[i].name); + const char *name = dbd_strlower(statement->bind[i].name); LUA_PUSH_ARRAY_STRING(d, name); } @@ -370,7 +370,7 @@ for (i = 0; i < statement->num_columns; i++) { lua_push_type_t lua_push = oracle_to_lua_push(bind[i].data_type, bind[i].null); - const char *name = strlower(bind[i].name); + const char *name = dbd_strlower(bind[i].name); const char *data = bind[i].data; if (lua_push == LUA_PUSH_NIL) { @@ -495,7 +495,7 @@ /* * convert SQL string into a Oracle API compatible SQL statement */ - new_sql = replace_placeholders(L, ':', sql_query); + new_sql = dbd_replace_placeholders(L, ':', sql_query); rc = OCIHandleAlloc((dvoid *)conn->oracle, (dvoid **)&stmt, OCI_HTYPE_STMT, 0, (dvoid **)0); rc = OCIStmtPrepare(stmt, conn->err, new_sql, strlen(new_sql), (ub4)OCI_NTV_SYNTAX, (ub4)OCI_DEFAULT); @@ -531,18 +531,9 @@ {NULL, NULL} }; - luaL_newmetatable(L, DBD_ORACLE_STATEMENT); - luaL_register(L, 0, statement_methods); - lua_pushvalue(L,-1); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, statement_gc); - lua_setfield(L, -2, "__gc"); - - lua_pushcfunction(L, statement_tostring); - lua_setfield(L, -2, "__tostring"); - - luaL_register(L, DBD_ORACLE_STATEMENT, statement_class_methods); + dbd_register(L, DBD_ORACLE_STATEMENT, + statement_methods, statement_class_methods, + statement_gc, statement_tostring); return 1; } diff -Nru lua-dbi-0.5.hg5ba1dd988961/dbd/postgresql/connection.c lua-dbi-0.6/dbd/postgresql/connection.c --- lua-dbi-0.5.hg5ba1dd988961/dbd/postgresql/connection.c 2013-08-10 18:33:16.000000000 +0000 +++ lua-dbi-0.6/dbd/postgresql/connection.c 2017-08-23 21:14:17.000000000 +0000 @@ -56,7 +56,7 @@ case 5: if (lua_isnil(L, 5) == 0) { - int pport = luaL_checkint(L, 5); + int pport = luaL_checkinteger(L, 5); if (pport >= 1 && pport <= 65535) { snprintf(portbuf, sizeof(portbuf), "%d", pport); @@ -250,6 +250,14 @@ } /* + * last_id = connection:last_id() + */ +static int connection_lastid(lua_State *L) { + luaL_error(L, DBI_ERR_NOT_IMPLEMENTED, DBD_POSTGRESQL_CONNECTION, "last_id"); + return 0; +} + +/* * __gc */ static int connection_gc(lua_State *L) { @@ -279,6 +287,7 @@ {"prepare", connection_prepare}, {"quote", connection_quote}, {"rollback", connection_rollback}, + {"last_id", connection_lastid}, {NULL, NULL} }; @@ -287,18 +296,9 @@ {NULL, NULL} }; - luaL_newmetatable(L, DBD_POSTGRESQL_CONNECTION); - luaL_register(L, 0, connection_methods); - lua_pushvalue(L,-1); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, connection_gc); - lua_setfield(L, -2, "__gc"); - - lua_pushcfunction(L, connection_tostring); - lua_setfield(L, -2, "__tostring"); - - luaL_register(L, DBD_POSTGRESQL_CONNECTION, connection_class_methods); + dbd_register(L, DBD_POSTGRESQL_CONNECTION, + connection_methods, connection_class_methods, + connection_gc, connection_tostring); return 1; } diff -Nru lua-dbi-0.5.hg5ba1dd988961/dbd/postgresql/dbd_postgresql.h lua-dbi-0.6/dbd/postgresql/dbd_postgresql.h --- lua-dbi-0.5.hg5ba1dd988961/dbd/postgresql/dbd_postgresql.h 2013-08-10 18:33:16.000000000 +0000 +++ lua-dbi-0.6/dbd/postgresql/dbd_postgresql.h 2017-08-23 21:14:17.000000000 +0000 @@ -1,5 +1,4 @@ #include -#include #include /* @@ -24,7 +23,7 @@ * statement object implementation */ typedef struct _statement { - PGconn *postgresql; + connection_t *conn; PGresult *result; char name[IDLEN]; /* statement ID */ int tuple; /* number of rows returned */ diff -Nru lua-dbi-0.5.hg5ba1dd988961/dbd/postgresql/main.c lua-dbi-0.6/dbd/postgresql/main.c --- lua-dbi-0.5.hg5ba1dd988961/dbd/postgresql/main.c 2013-08-10 18:33:16.000000000 +0000 +++ lua-dbi-0.6/dbd/postgresql/main.c 2017-08-23 21:14:17.000000000 +0000 @@ -6,9 +6,9 @@ /* * library entry point */ -LUA_EXPORT int luaopen_dbdpostgresql(lua_State *L) { - dbd_postgresql_connection(L); +LUA_EXPORT int luaopen_dbd_postgresql(lua_State *L) { dbd_postgresql_statement(L); + dbd_postgresql_connection(L); return 1; } diff -Nru lua-dbi-0.5.hg5ba1dd988961/dbd/postgresql/statement.c lua-dbi-0.6/dbd/postgresql/statement.c --- lua-dbi-0.5.hg5ba1dd988961/dbd/postgresql/statement.c 2013-08-10 18:33:16.000000000 +0000 +++ lua-dbi-0.6/dbd/postgresql/statement.c 2017-08-23 21:14:17.000000000 +0000 @@ -6,6 +6,7 @@ #define INT8OID 20 #define FLOAT4OID 700 #define FLOAT8OID 701 +#define DECIMALOID 1700 static lua_push_type_t postgresql_to_lua_push(unsigned int postgresql_type) { lua_push_type_t lua_type; @@ -19,6 +20,7 @@ case FLOAT4OID: case FLOAT8OID: + case DECIMALOID: lua_type = LUA_PUSH_NUMBER; break; @@ -38,17 +40,24 @@ PGresult *result; ExecStatusType status; - snprintf(command, IDLEN+13, "DEALLOCATE \"%s\"", statement->name); - result = PQexec(statement->postgresql, command); + /* + * It's possible to get here with a closed database handle + * - either by a mistake by the calling Lua program, or by + * garbage collection. Don't die in that case. + */ + if (!statement->conn->postgresql) { + snprintf(command, IDLEN+13, "DEALLOCATE \"%s\"", statement->name); + result = PQexec(statement->conn->postgresql, command); - if (!result) - return 1; + if (!result) + return 1; - status = PQresultStatus(result); - PQclear(result); + status = PQresultStatus(result); + PQclear(result); - if (status != PGRES_COMMAND_OK && status != PGRES_TUPLES_OK) - return 1; + if (status != PGRES_COMMAND_OK && status != PGRES_TUPLES_OK) + return 1; + } return 0; } @@ -82,8 +91,8 @@ */ deallocate(statement); - PQclear(statement->result); - statement->result = NULL; + PQclear(statement->result); + statement->result = NULL; } return 0; @@ -129,6 +138,17 @@ const char **params; PGresult *result = NULL; + + /* + * Sanity check - is database still connected? + */ + if (PQstatus(statement->conn->postgresql) != CONNECTION_OK) + { + lua_pushstring(L, DBI_ERR_STATEMENT_BROKEN); + lua_error(L); + } + + statement->tuple = 0; params = malloc(num_bind_params * sizeof(params)); @@ -168,7 +188,7 @@ } result = PQexecPrepared( - statement->postgresql, + statement->conn->postgresql, statement->name, num_bind_params, (const char **)params, @@ -188,7 +208,7 @@ if (!result) { lua_pushboolean(L, 0); - lua_pushfstring(L, DBI_ERR_ALLOC_RESULT, PQerrorMessage(statement->postgresql)); + lua_pushfstring(L, DBI_ERR_ALLOC_RESULT, PQerrorMessage(statement->conn->postgresql)); return 2; } @@ -378,7 +398,7 @@ /* * convert SQL string into a PSQL API compatible SQL statement */ - new_sql = replace_placeholders(L, '$', sql_query); + new_sql = dbd_replace_placeholders(L, '$', sql_query); snprintf(name, IDLEN, "dbd-postgresql-%017u", ++conn->statement_id); @@ -391,24 +411,24 @@ if (!result) { lua_pushnil(L); - lua_pushfstring(L, DBI_ERR_ALLOC_STATEMENT, PQerrorMessage(statement->postgresql)); + lua_pushfstring(L, DBI_ERR_ALLOC_STATEMENT, PQerrorMessage(statement->conn->postgresql)); return 2; } status = PQresultStatus(result); if (status != PGRES_COMMAND_OK && status != PGRES_TUPLES_OK) { const char *err_string = PQresultErrorMessage(result); - PQclear(result); lua_pushnil(L); lua_pushfstring(L, DBI_ERR_PREP_STATEMENT, err_string); + PQclear(result); return 2; } PQclear(result); statement = (statement_t *)lua_newuserdata(L, sizeof(statement_t)); - statement->postgresql = conn->postgresql; + statement->conn = conn; statement->result = NULL; statement->tuple = 0; strncpy(statement->name, name, IDLEN-1); @@ -436,18 +456,9 @@ {NULL, NULL} }; - luaL_newmetatable(L, DBD_POSTGRESQL_STATEMENT); - luaL_register(L, 0, statement_methods); - lua_pushvalue(L,-1); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, statement_gc); - lua_setfield(L, -2, "__gc"); - - lua_pushcfunction(L, statement_tostring); - lua_setfield(L, -2, "__tostring"); - - luaL_register(L, DBD_POSTGRESQL_STATEMENT, statement_class_methods); + dbd_register(L, DBD_POSTGRESQL_STATEMENT, + statement_methods, statement_class_methods, + statement_gc, statement_tostring); return 1; } diff -Nru lua-dbi-0.5.hg5ba1dd988961/dbd/sqlite3/connection.c lua-dbi-0.6/dbd/sqlite3/connection.c --- lua-dbi-0.5.hg5ba1dd988961/dbd/sqlite3/connection.c 2013-08-10 18:33:16.000000000 +0000 +++ lua-dbi-0.6/dbd/sqlite3/connection.c 2017-08-23 21:14:17.000000000 +0000 @@ -192,6 +192,16 @@ } /* + * last_id = connection:last_id() + */ +static int connection_lastid(lua_State *L) { + connection_t *conn = (connection_t *)luaL_checkudata(L, 1, DBD_SQLITE_CONNECTION); + + lua_pushinteger(L, sqlite3_last_insert_rowid(conn->sqlite)); + return 1; +} + +/* * __gc */ static int connection_gc(lua_State *L) { @@ -224,6 +234,7 @@ {"prepare", connection_prepare}, {"quote", connection_quote}, {"rollback", connection_rollback}, + {"last_id", connection_lastid}, {NULL, NULL} }; @@ -235,18 +246,9 @@ {NULL, NULL} }; - luaL_newmetatable(L, DBD_SQLITE_CONNECTION); - luaL_register(L, 0, connection_methods); - lua_pushvalue(L,-1); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, connection_gc); - lua_setfield(L, -2, "__gc"); - - lua_pushcfunction(L, connection_tostring); - lua_setfield(L, -2, "__tostring"); - - luaL_register(L, DBD_SQLITE_CONNECTION, connection_class_methods); + dbd_register(L, DBD_SQLITE_CONNECTION, + connection_methods, connection_class_methods, + connection_gc, connection_tostring); return 1; } diff -Nru lua-dbi-0.5.hg5ba1dd988961/dbd/sqlite3/dbd_sqlite3.h lua-dbi-0.6/dbd/sqlite3/dbd_sqlite3.h --- lua-dbi-0.5.hg5ba1dd988961/dbd/sqlite3/dbd_sqlite3.h 2013-08-10 18:33:16.000000000 +0000 +++ lua-dbi-0.6/dbd/sqlite3/dbd_sqlite3.h 2017-08-23 21:14:17.000000000 +0000 @@ -10,7 +10,6 @@ typedef struct _connection { sqlite3 *sqlite; int autocommit; -// int txn_in_progress; } connection_t; /* diff -Nru lua-dbi-0.5.hg5ba1dd988961/dbd/sqlite3/main.c lua-dbi-0.6/dbd/sqlite3/main.c --- lua-dbi-0.5.hg5ba1dd988961/dbd/sqlite3/main.c 2013-08-10 18:33:16.000000000 +0000 +++ lua-dbi-0.6/dbd/sqlite3/main.c 2017-08-23 21:14:17.000000000 +0000 @@ -6,9 +6,9 @@ /* * library entry point */ -LUA_EXPORT int luaopen_dbdsqlite3(lua_State *L) { - dbd_sqlite3_connection(L); +LUA_EXPORT int luaopen_dbd_sqlite3(lua_State *L) { dbd_sqlite3_statement(L); + dbd_sqlite3_connection(L); return 1; } diff -Nru lua-dbi-0.5.hg5ba1dd988961/dbd/sqlite3/statement.c lua-dbi-0.6/dbd/sqlite3/statement.c --- lua-dbi-0.5.hg5ba1dd988961/dbd/sqlite3/statement.c 2013-08-10 18:33:16.000000000 +0000 +++ lua-dbi-0.6/dbd/sqlite3/statement.c 2017-08-23 21:14:17.000000000 +0000 @@ -124,6 +124,16 @@ return 2; } + + /* + * sanity check: make sure our database handle is still open + */ + if (!statement->conn->sqlite) { + lua_pushstring(L, DBI_ERR_STATEMENT_BROKEN); + lua_error(L); + } + + /* * reset the handle before binding params * this will be a NOP if the handle has not @@ -161,10 +171,13 @@ case LUA_TNUMBER: errflag = sqlite3_bind_double(statement->stmt, i, lua_tonumber(L, p)) != SQLITE_OK; break; - case LUA_TSTRING: - errflag = sqlite3_bind_text(statement->stmt, i, lua_tostring(L, p), -1, SQLITE_STATIC) != SQLITE_OK; + case LUA_TSTRING: { + size_t len = -1; + const char *str = lua_tolstring(L, p, &len); + errflag = sqlite3_bind_text(statement->stmt, i, str, len, SQLITE_STATIC) != SQLITE_OK; break; - case LUA_TBOOLEAN: + } + case LUA_TBOOLEAN: errflag = sqlite3_bind_int(statement->stmt, i, lua_toboolean(L, p)) != SQLITE_OK; break; default: @@ -335,7 +348,6 @@ */ static int statement_rowcount(lua_State *L) { luaL_error(L, DBI_ERR_NOT_IMPLEMENTED, DBD_SQLITE_STATEMENT, "rowcount"); - return 0; } @@ -396,18 +408,9 @@ {NULL, NULL} }; - luaL_newmetatable(L, DBD_SQLITE_STATEMENT); - luaL_register(L, 0, statement_methods); - lua_pushvalue(L,-1); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, statement_gc); - lua_setfield(L, -2, "__gc"); - - lua_pushcfunction(L, statement_tostring); - lua_setfield(L, -2, "__tostring"); - - luaL_register(L, DBD_SQLITE_STATEMENT, statement_class_methods); + dbd_register(L, DBD_SQLITE_STATEMENT, + statement_methods, statement_class_methods, + statement_gc, statement_tostring); return 1; } diff -Nru lua-dbi-0.5.hg5ba1dd988961/DBI.lua lua-dbi-0.6/DBI.lua --- lua-dbi-0.5.hg5ba1dd988961/DBI.lua 2013-08-10 18:33:16.000000000 +0000 +++ lua-dbi-0.6/DBI.lua 2017-08-23 21:14:17.000000000 +0000 @@ -1,14 +1,15 @@ #!/usr/bin/lua -module('DBI', package.seeall) +local _M = {} -- Driver to module mapping local name_to_module = { - MySQL = 'dbdmysql', - PostgreSQL = 'dbdpostgresql', - SQLite3 = 'dbdsqlite3', - DB2 = 'dbddb2', - Oracle = 'dbdoracle', + MySQL = 'dbd.mysql', + PostgreSQL = 'dbd.postgresql', + SQLite3 = 'dbd.sqlite3', + DB2 = 'dbd.db2', + Oracle = 'dbd.oracle', + ODBC = 'dbd.odbc' } local string = require('string') @@ -19,11 +20,11 @@ local available = {} for driver, modulefile in pairs(name_to_module) do - local m, err = pcall(require, modulefile) + local m, err = pcall(require, modulefile) - if m then - table.insert(available, driver) - end + if m then + table.insert(available, driver) + end end -- no drivers available @@ -36,37 +37,32 @@ -- High level DB connection function -- This should be used rather than DBD.{Driver}.New -function Connect(driver, ...) +function _M.Connect(driver, ...) local modulefile = name_to_module[driver] if not modulefile then local available = table.concat(available_drivers(), ',') - error(string.format("Driver '%s' not found. Available drivers are: %s", driver, available)) + error(string.format("Driver '%s' not found. Available drivers are: %s", driver, available)) end local m, err = pcall(require, modulefile) if not m then - -- cannot load the module, we cannot continue + -- cannot load the module, we cannot continue local available = table.concat(available_drivers(), ',') - error(string.format('Cannot load driver %s. Available drivers are: %s', driver, available)) + error(string.format('Cannot load driver %s. Available drivers are: %s', driver, available)) end - local class_str = string.format('DBD.%s.Connection', driver) - - local connection_class = package.loaded[class_str] - - -- Calls DBD.{Driver}.New(...) - return connection_class.New(...) + return package.loaded[modulefile].New(...) end -- Help function to do prepare and execute in -- a single step -function Do(dbh, sql, ...) +function _M.Do(dbh, sql, ...) local sth,err = dbh:prepare(sql) if not sth then - return false, err + return false, err end local ok, err = sth:execute(...) @@ -78,7 +74,13 @@ return sth:affected() end --- Lit drivers available on this system -function Drivers() +-- List drivers available on this system +function _M.Drivers() return available_drivers() end + + +-- Versioning Information +_M._VERSION = '0.6' + +return _M diff -Nru lua-dbi-0.5.hg5ba1dd988961/debian/changelog lua-dbi-0.6/debian/changelog --- lua-dbi-0.5.hg5ba1dd988961/debian/changelog 2016-12-16 03:46:14.000000000 +0000 +++ lua-dbi-0.6/debian/changelog 2018-03-06 17:07:18.000000000 +0000 @@ -1,3 +1,24 @@ +lua-dbi (0.6-2) unstable; urgency=medium + + * fix coredump on postgresql (already applied upstream master) + * fix capitalization-error-in-description lintian warnings + + -- Victor Seva Tue, 06 Mar 2018 18:07:18 +0100 + +lua-dbi (0.6-1) unstable; urgency=medium + + * add myself to Uploaders. wrap-and-sort -sat + * update Vcs-* migrated to salsa + * update upstream + * New upstream version 0.6 + * update compat to 10, Standards-Version to 4.1.3 and remove dbg packages + * add support for lua5.2 and lua5.3 + * remove remove-shebang.patch (already applied upstream) + * add patches fixing warnings (already applied in upstream master) + * update LUA_MODNAME(_CPART) + + -- Victor Seva Mon, 05 Mar 2018 17:25:16 +0100 + lua-dbi (0.5.hg5ba1dd988961-4) unstable; urgency=medium * Team upload @@ -8,19 +29,19 @@ lua-dbi (0.5.hg5ba1dd988961-3) unstable; urgency=medium - * Do not pre-depend on multiarch-support + * Do not pre-depend on multiarch-support -- Enrico Tassi Sat, 15 Aug 2015 15:56:07 +0200 lua-dbi (0.5.hg5ba1dd988961-2) unstable; urgency=low - * Build-depend on postgresql-server-dev-all + * Build-depend on postgresql-server-dev-all -- Enrico Tassi Wed, 18 Sep 2013 10:39:16 +0200 lua-dbi (0.5.hg5ba1dd988961-1) unstable; urgency=low - * New upstream snapshot fixing mysql bug + * New upstream snapshot fixing mysql bug * Packaging moved to git -- Enrico Tassi Sat, 10 Aug 2013 20:35:27 +0200 @@ -28,23 +49,23 @@ lua-dbi (0.5+svn78-5~dbg4matthew1) unstable; urgency=low * debian/compat set to 9 - * new package lua-dbi-mysql-dbg - * new package lua-dbi-sqlite3-dbg - * new package lua-dbi-postgresql-dbg + * new package lua-dbi-mysql-dbg + * new package lua-dbi-sqlite3-dbg + * new package lua-dbi-postgresql-dbg -- Enrico Tassi Sat, 30 Jun 2012 11:22:38 +0200 lua-dbi (0.5+svn78-4) unstable; urgency=low * Add patch preventing an off by one in mysql driver: - http://code.matthewwild.co.uk/luadbi/rev/5ba1dd988961 + http://code.matthewwild.co.uk/luadbi/rev/5ba1dd988961 -- Enrico Tassi Fri, 29 Jun 2012 19:00:58 +0200 lua-dbi (0.5+svn78-3) unstable; urgency=low * Add path: mysql-memory-consumption from - http://code.matthewwild.co.uk/luadbi/rev/7c968f66bccd + http://code.matthewwild.co.uk/luadbi/rev/7c968f66bccd -- Enrico Tassi Mon, 30 Apr 2012 16:22:07 +0200 diff -Nru lua-dbi-0.5.hg5ba1dd988961/debian/compat lua-dbi-0.6/debian/compat --- lua-dbi-0.5.hg5ba1dd988961/debian/compat 2016-12-16 03:41:05.000000000 +0000 +++ lua-dbi-0.6/debian/compat 2018-03-06 17:07:18.000000000 +0000 @@ -1 +1 @@ -9 +10 diff -Nru lua-dbi-0.5.hg5ba1dd988961/debian/control lua-dbi-0.6/debian/control --- lua-dbi-0.5.hg5ba1dd988961/debian/control 2016-12-16 03:44:28.000000000 +0000 +++ lua-dbi-0.6/debian/control 2018-03-06 17:07:18.000000000 +0000 @@ -2,18 +2,29 @@ Section: interpreters Priority: optional Maintainer: Enrico Tassi -Build-Depends: dh-lua, debhelper (>= 9), libsqlite3-dev, postgresql-server-dev-all, default-libmysqlclient-dev -Standards-Version: 3.9.3 -Homepage: http://code.google.com/p/luadbi/ -Vcs-Git: git://git.debian.org/git/pkg-lua/lua-dbi.git -Vcs-Browser: http://git.debian.org/?p=pkg-lua/lua-dbi.git +Uploaders: + Victor Seva , +Build-Depends: + debhelper (>= 10~), + default-libmysqlclient-dev, + dh-lua, + libsqlite3-dev, + postgresql-server-dev-all, +Standards-Version: 4.1.3 +Homepage: https://github.com/mwild1/luadbi +Vcs-Git: https://salsa.debian.org/lua-team/lua-dbi.git +Vcs-Browser: https://salsa.debian.org/lua-team/lua-dbi Package: lua-dbi-common Architecture: all Multi-Arch: foreign -Pre-Depends: ${misc:Pre-Depends} -Depends: ${shlibs:Depends}, ${misc:Depends} -Provides: ${lua:Provides} +Pre-Depends: + ${misc:Pre-Depends}, +Depends: + ${misc:Depends}, + ${shlibs:Depends}, +Provides: + ${lua:Provides}, XB-Lua-Versions: ${lua:Versions} Description: DBI library for the Lua language, common files Lua DBI is a database interface library for Lua. It is designed to provide a @@ -29,9 +40,14 @@ Package: lua-dbi-sqlite3 Architecture: any Multi-Arch: same -Pre-Depends: ${misc:Pre-Depends} -Depends: ${shlibs:Depends}, ${misc:Depends}, lua-dbi-common -Provides: ${lua:Provides} +Pre-Depends: + ${misc:Pre-Depends}, +Depends: + lua-dbi-common, + ${misc:Depends}, + ${shlibs:Depends}, +Provides: + ${lua:Provides}, XB-Lua-Versions: ${lua:Versions} Description: DBI library for the Lua language, sqlite3 backend Lua DBI is a database interface library for Lua. It is designed to provide a @@ -48,21 +64,31 @@ Architecture: any Multi-Arch: same Section: libdevel -Pre-Depends: ${misc:Pre-Depends} -Depends: ${shlibs:Depends}, ${misc:Depends}, lua-dbi-sqlite3 (= ${binary:Version}) -Provides: ${lua:Provides} +Pre-Depends: + ${misc:Pre-Depends}, +Depends: + lua-dbi-sqlite3 (= ${binary:Version}), + ${misc:Depends}, + ${shlibs:Depends}, +Provides: + ${lua:Provides}, XB-Lua-Versions: ${lua:Versions} Description: DBI library for the Lua language, sqlite3 development files - This package contains the development files of the lua DBI library - (Sqlite3 backend), useful to create a statically linked binary + This package contains the development files of the Lua DBI library + (Sqlite3 backend), useful to create a statically linked binary (like a C application or a standalone Lua interpreter). Package: lua-dbi-mysql Architecture: any Multi-Arch: same -Pre-Depends: ${misc:Pre-Depends} -Depends: ${shlibs:Depends}, ${misc:Depends}, lua-dbi-common -Provides: ${lua:Provides} +Pre-Depends: + ${misc:Pre-Depends}, +Depends: + lua-dbi-common, + ${misc:Depends}, + ${shlibs:Depends}, +Provides: + ${lua:Provides}, XB-Lua-Versions: ${lua:Versions} Description: DBI library for the Lua language, MySQL backend Lua DBI is a database interface library for Lua. It is designed to provide a @@ -78,22 +104,32 @@ Package: lua-dbi-mysql-dev Architecture: any Multi-Arch: same -Pre-Depends: ${misc:Pre-Depends} +Pre-Depends: + ${misc:Pre-Depends}, Section: libdevel -Depends: ${shlibs:Depends}, ${misc:Depends}, lua-dbi-mysql (= ${binary:Version}) -Provides: ${lua:Provides} +Depends: + lua-dbi-mysql (= ${binary:Version}), + ${misc:Depends}, + ${shlibs:Depends}, +Provides: + ${lua:Provides}, XB-Lua-Versions: ${lua:Versions} Description: DBI library for the Lua language, MySQL development files - This package contains the development files of the lua DBI library - (MySQL backend), useful to create a statically linked binary + This package contains the development files of the Lua DBI library + (MySQL backend), useful to create a statically linked binary (like a C application or a standalone Lua interpreter). Package: lua-dbi-postgresql Architecture: any Multi-Arch: same -Pre-Depends: ${misc:Pre-Depends} -Depends: ${shlibs:Depends}, ${misc:Depends}, lua-dbi-common -Provides: ${lua:Provides} +Pre-Depends: + ${misc:Pre-Depends}, +Depends: + lua-dbi-common, + ${misc:Depends}, + ${shlibs:Depends}, +Provides: + ${lua:Provides}, XB-Lua-Versions: ${lua:Versions} Description: DBI library for the Lua language, PostgreSQL backend Lua DBI is a database interface library for Lua. It is designed to provide a @@ -109,45 +145,17 @@ Package: lua-dbi-postgresql-dev Architecture: any Multi-Arch: same -Pre-Depends: ${misc:Pre-Depends} +Pre-Depends: + ${misc:Pre-Depends}, Section: libdevel -Depends: ${shlibs:Depends}, ${misc:Depends}, lua-dbi-postgresql (= ${binary:Version}) -Provides: ${lua:Provides} +Depends: + lua-dbi-postgresql (= ${binary:Version}), + ${misc:Depends}, + ${shlibs:Depends}, +Provides: + ${lua:Provides}, XB-Lua-Versions: ${lua:Versions} Description: DBI library for the Lua language, PostgreSQL development files - This package contains the development files of the lua DBI library - (PostgreSQL backend), useful to create a statically linked binary + This package contains the development files of the Lua DBI library + (PostgreSQL backend), useful to create a statically linked binary (like a C application or a standalone Lua interpreter). - -Package: lua-dbi-mysql-dbg -Architecture: any -Priority: extra -Section: debug -Multi-Arch: same -Pre-Depends: ${misc:Pre-Depends} -Depends: lua-dbi-mysql (= ${binary:Version}), ${shlibs:Depends}, ${misc:Depends} -XB-Lua-Versions: ${lua:Versions} -Description: DBI library for the Lua language, MySQL backend debug symbols - This package contains the debugging symbols for lua-dbi-mysql. - -Package: lua-dbi-postgresql-dbg -Architecture: any -Priority: extra -Section: debug -Multi-Arch: same -Pre-Depends: ${misc:Pre-Depends} -Depends: lua-dbi-postgresql (= ${binary:Version}), ${shlibs:Depends}, ${misc:Depends} -XB-Lua-Versions: ${lua:Versions} -Description: DBI library for the Lua language, PostgreSQL backend debug symbols - This package contains the debugging symbols for lua-dbi-postgresql. - -Package: lua-dbi-sqlite3-dbg -Architecture: any -Priority: extra -Section: debug -Multi-Arch: same -Pre-Depends: ${misc:Pre-Depends} -Depends: lua-dbi-sqlite3 (= ${binary:Version}), ${shlibs:Depends}, ${misc:Depends} -XB-Lua-Versions: ${lua:Versions} -Description: DBI library for the Lua language, sqlite3 backend debug symbols - This package contains the debugging symbols for lua-dbi-sqlite3. diff -Nru lua-dbi-0.5.hg5ba1dd988961/debian/copyright lua-dbi-0.6/debian/copyright --- lua-dbi-0.5.hg5ba1dd988961/debian/copyright 2016-12-16 03:41:05.000000000 +0000 +++ lua-dbi-0.6/debian/copyright 2018-03-06 17:07:18.000000000 +0000 @@ -1,10 +1,10 @@ Format: http://dep.debian.net/deps/dep5/ Upstream-Name: luadbi -Upstream-Contact: Neil Richardson (nrich@ii.net) -Source: http://code.google.com/p/luadbi/ +Upstream-Contact: Matthew James Wild +Source: https://github.com/mwild1/luadbi Files: * -Copyright: 2008-2010 Neil Richardson (nrich@ii.net) +Copyright: 2008-2010 Neil Richardson (nrich@neiltopia.com) License: MIT/X Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff -Nru lua-dbi-0.5.hg5ba1dd988961/debian/lua5.1.mysql.dh-lua.conf lua-dbi-0.6/debian/lua5.1.mysql.dh-lua.conf --- lua-dbi-0.5.hg5ba1dd988961/debian/lua5.1.mysql.dh-lua.conf 2016-12-16 03:41:05.000000000 +0000 +++ lua-dbi-0.6/debian/lua5.1.mysql.dh-lua.conf 2018-03-06 17:07:18.000000000 +0000 @@ -8,12 +8,12 @@ CLIB_LDFLAGS=$(shell mysql_config --libs) CLIB_LDFLAGS_STATIC=$(shell mysql_config --libs) CLIB_OBJS=dbd/common.lo $(patsubst %.c,%.lo,$(wildcard dbd/mysql/*.c)) -LUA_MODNAME_CPART=dbdmysql +LUA_MODNAME_CPART=dbd.mysql ### things relative to the lua library part LUA_HEADER= LUA_SOURCES= -LUA_MODNAME=dbdmysql +LUA_MODNAME=dbd.mysql LUA_TEST= ### this part is relative to pkg-config diff -Nru lua-dbi-0.5.hg5ba1dd988961/debian/lua5.1.postgresql.dh-lua.conf lua-dbi-0.6/debian/lua5.1.postgresql.dh-lua.conf --- lua-dbi-0.5.hg5ba1dd988961/debian/lua5.1.postgresql.dh-lua.conf 2016-12-16 03:41:05.000000000 +0000 +++ lua-dbi-0.6/debian/lua5.1.postgresql.dh-lua.conf 2018-03-06 17:07:18.000000000 +0000 @@ -8,12 +8,12 @@ CLIB_LDFLAGS=-lpq CLIB_LDFLAGS_STATIC=-lpq CLIB_OBJS=dbd/common.lo $(patsubst %.c,%.lo,$(wildcard dbd/postgresql/*.c)) -LUA_MODNAME_CPART=dbdpostgresql +LUA_MODNAME_CPART=dbd.postgresql ### things relative to the lua library part LUA_HEADER= LUA_SOURCES= -LUA_MODNAME=dbdpostgresql +LUA_MODNAME=dbd.postgresql LUA_TEST= ### this part is relative to pkg-config diff -Nru lua-dbi-0.5.hg5ba1dd988961/debian/lua5.1.sqlite3.dh-lua.conf lua-dbi-0.6/debian/lua5.1.sqlite3.dh-lua.conf --- lua-dbi-0.5.hg5ba1dd988961/debian/lua5.1.sqlite3.dh-lua.conf 2016-12-16 03:41:05.000000000 +0000 +++ lua-dbi-0.6/debian/lua5.1.sqlite3.dh-lua.conf 2018-03-06 17:07:18.000000000 +0000 @@ -8,12 +8,12 @@ CLIB_LDFLAGS=$(shell pkg-config sqlite3 --libs) CLIB_LDFLAGS_STATIC=$(shell pkg-config sqlite3 --libs --static) CLIB_OBJS=dbd/common.lo $(patsubst %.c,%.lo,$(wildcard dbd/sqlite3/*.c)) -LUA_MODNAME_CPART=dbdsqlite3 +LUA_MODNAME_CPART=dbd.sqlite3 ### things relative to the lua library part LUA_HEADER= LUA_SOURCES= -LUA_MODNAME=dbdsqlite3 +LUA_MODNAME=dbd.sqlite3 LUA_TEST=test.lua SQLite3 foo.db ### this part is relative to pkg-config diff -Nru lua-dbi-0.5.hg5ba1dd988961/debian/lua5.2.common.dh-lua.conf lua-dbi-0.6/debian/lua5.2.common.dh-lua.conf --- lua-dbi-0.5.hg5ba1dd988961/debian/lua5.2.common.dh-lua.conf 1970-01-01 00:00:00.000000000 +0000 +++ lua-dbi-0.6/debian/lua5.2.common.dh-lua.conf 2018-03-06 17:07:18.000000000 +0000 @@ -0,0 +1,23 @@ +### $Id: Makefile.Debian.conf.sample 1398 2009-11-13 21:10:12Z gareuselesinge $ + +### mandatory fields +PKG_NAME=dbi.common + +### things relative to the C library part +CLIB_CFLAGS= +CLIB_LDFLAGS= +CLIB_LDFLAGS_STATIC= +CLIB_OBJS= + +### things relative to the lua library part +LUA_HEADER= +LUA_SOURCES=DBI.lua +LUA_MODNAME= +LUA_TEST= + +### this part is relative to pkg-config +PKG_VERSION=$(shell dpkg-parsechangelog|grep ^Ver|cut -d ' ' -f 2|cut -d '-' -f 1) +PKG_LIBS_PRIVATE= +PKG_URL= +PKG_REQUIRES= +PKG_CONFLICTS= diff -Nru lua-dbi-0.5.hg5ba1dd988961/debian/lua5.2.mysql.dh-lua.conf lua-dbi-0.6/debian/lua5.2.mysql.dh-lua.conf --- lua-dbi-0.5.hg5ba1dd988961/debian/lua5.2.mysql.dh-lua.conf 1970-01-01 00:00:00.000000000 +0000 +++ lua-dbi-0.6/debian/lua5.2.mysql.dh-lua.conf 2018-03-06 17:07:18.000000000 +0000 @@ -0,0 +1,24 @@ +### $Id: Makefile.Debian.conf.sample 1398 2009-11-13 21:10:12Z gareuselesinge $ + +### mandatory fields +PKG_NAME=dbi.mysql + +### things relative to the C library part +CLIB_CFLAGS=$(shell mysql_config --cflags) -I . +CLIB_LDFLAGS=$(shell mysql_config --libs) +CLIB_LDFLAGS_STATIC=$(shell mysql_config --libs) +CLIB_OBJS=dbd/common.lo $(patsubst %.c,%.lo,$(wildcard dbd/mysql/*.c)) +LUA_MODNAME_CPART=dbd.mysql + +### things relative to the lua library part +LUA_HEADER= +LUA_SOURCES= +LUA_MODNAME=dbd.mysql +LUA_TEST= + +### this part is relative to pkg-config +PKG_VERSION=$(shell dpkg-parsechangelog|grep ^Ver|cut -d ' ' -f 2|cut -d '-' -f 1) +PKG_LIBS_PRIVATE= +PKG_URL= +PKG_REQUIRES= +PKG_CONFLICTS= diff -Nru lua-dbi-0.5.hg5ba1dd988961/debian/lua5.2.postgresql.dh-lua.conf lua-dbi-0.6/debian/lua5.2.postgresql.dh-lua.conf --- lua-dbi-0.5.hg5ba1dd988961/debian/lua5.2.postgresql.dh-lua.conf 1970-01-01 00:00:00.000000000 +0000 +++ lua-dbi-0.6/debian/lua5.2.postgresql.dh-lua.conf 2018-03-06 17:07:18.000000000 +0000 @@ -0,0 +1,24 @@ +### $Id: Makefile.Debian.conf.sample 1398 2009-11-13 21:10:12Z gareuselesinge $ + +### mandatory fields +PKG_NAME=dbi.postgresql + +### things relative to the C library part +CLIB_CFLAGS=-I$(shell pg_config --includedir) -I$(shell pg_config --includedir-server) -I . +CLIB_LDFLAGS=-lpq +CLIB_LDFLAGS_STATIC=-lpq +CLIB_OBJS=dbd/common.lo $(patsubst %.c,%.lo,$(wildcard dbd/postgresql/*.c)) +LUA_MODNAME_CPART=dbd.postgresql + +### things relative to the lua library part +LUA_HEADER= +LUA_SOURCES= +LUA_MODNAME=dbd.postgresql +LUA_TEST= + +### this part is relative to pkg-config +PKG_VERSION=$(shell dpkg-parsechangelog|grep ^Ver|cut -d ' ' -f 2|cut -d '-' -f 1) +PKG_LIBS_PRIVATE= +PKG_URL= +PKG_REQUIRES= +PKG_CONFLICTS= diff -Nru lua-dbi-0.5.hg5ba1dd988961/debian/lua5.2.sqlite3.dh-lua.conf lua-dbi-0.6/debian/lua5.2.sqlite3.dh-lua.conf --- lua-dbi-0.5.hg5ba1dd988961/debian/lua5.2.sqlite3.dh-lua.conf 1970-01-01 00:00:00.000000000 +0000 +++ lua-dbi-0.6/debian/lua5.2.sqlite3.dh-lua.conf 2018-03-06 17:07:18.000000000 +0000 @@ -0,0 +1,24 @@ +### $Id: Makefile.Debian.conf.sample 1398 2009-11-13 21:10:12Z gareuselesinge $ + +### mandatory fields +PKG_NAME=dbi.sqlite3 + +### things relative to the C library part +CLIB_CFLAGS=$(shell pkg-config sqlite3 --cflags) -I . +CLIB_LDFLAGS=$(shell pkg-config sqlite3 --libs) +CLIB_LDFLAGS_STATIC=$(shell pkg-config sqlite3 --libs --static) +CLIB_OBJS=dbd/common.lo $(patsubst %.c,%.lo,$(wildcard dbd/sqlite3/*.c)) +LUA_MODNAME_CPART=dbd.sqlite3 + +### things relative to the lua library part +LUA_HEADER= +LUA_SOURCES= +LUA_MODNAME=dbd.sqlite3 +LUA_TEST=test.lua SQLite3 foo.db + +### this part is relative to pkg-config +PKG_VERSION=$(shell dpkg-parsechangelog|grep ^Ver|cut -d ' ' -f 2|cut -d '-' -f 1) +PKG_LIBS_PRIVATE= +PKG_URL= +PKG_REQUIRES= +PKG_CONFLICTS= diff -Nru lua-dbi-0.5.hg5ba1dd988961/debian/lua5.3.common.dh-lua.conf lua-dbi-0.6/debian/lua5.3.common.dh-lua.conf --- lua-dbi-0.5.hg5ba1dd988961/debian/lua5.3.common.dh-lua.conf 1970-01-01 00:00:00.000000000 +0000 +++ lua-dbi-0.6/debian/lua5.3.common.dh-lua.conf 2018-03-06 17:07:18.000000000 +0000 @@ -0,0 +1,23 @@ +### $Id: Makefile.Debian.conf.sample 1398 2009-11-13 21:10:12Z gareuselesinge $ + +### mandatory fields +PKG_NAME=dbi.common + +### things relative to the C library part +CLIB_CFLAGS= +CLIB_LDFLAGS= +CLIB_LDFLAGS_STATIC= +CLIB_OBJS= + +### things relative to the lua library part +LUA_HEADER= +LUA_SOURCES=DBI.lua +LUA_MODNAME= +LUA_TEST= + +### this part is relative to pkg-config +PKG_VERSION=$(shell dpkg-parsechangelog|grep ^Ver|cut -d ' ' -f 2|cut -d '-' -f 1) +PKG_LIBS_PRIVATE= +PKG_URL= +PKG_REQUIRES= +PKG_CONFLICTS= diff -Nru lua-dbi-0.5.hg5ba1dd988961/debian/lua5.3.mysql.dh-lua.conf lua-dbi-0.6/debian/lua5.3.mysql.dh-lua.conf --- lua-dbi-0.5.hg5ba1dd988961/debian/lua5.3.mysql.dh-lua.conf 1970-01-01 00:00:00.000000000 +0000 +++ lua-dbi-0.6/debian/lua5.3.mysql.dh-lua.conf 2018-03-06 17:07:18.000000000 +0000 @@ -0,0 +1,24 @@ +### $Id: Makefile.Debian.conf.sample 1398 2009-11-13 21:10:12Z gareuselesinge $ + +### mandatory fields +PKG_NAME=dbi.mysql + +### things relative to the C library part +CLIB_CFLAGS=$(shell mysql_config --cflags) -I . +CLIB_LDFLAGS=$(shell mysql_config --libs) +CLIB_LDFLAGS_STATIC=$(shell mysql_config --libs) +CLIB_OBJS=dbd/common.lo $(patsubst %.c,%.lo,$(wildcard dbd/mysql/*.c)) +LUA_MODNAME_CPART=dbd.mysql + +### things relative to the lua library part +LUA_HEADER= +LUA_SOURCES= +LUA_MODNAME=dbd.mysql +LUA_TEST= + +### this part is relative to pkg-config +PKG_VERSION=$(shell dpkg-parsechangelog|grep ^Ver|cut -d ' ' -f 2|cut -d '-' -f 1) +PKG_LIBS_PRIVATE= +PKG_URL= +PKG_REQUIRES= +PKG_CONFLICTS= diff -Nru lua-dbi-0.5.hg5ba1dd988961/debian/lua5.3.postgresql.dh-lua.conf lua-dbi-0.6/debian/lua5.3.postgresql.dh-lua.conf --- lua-dbi-0.5.hg5ba1dd988961/debian/lua5.3.postgresql.dh-lua.conf 1970-01-01 00:00:00.000000000 +0000 +++ lua-dbi-0.6/debian/lua5.3.postgresql.dh-lua.conf 2018-03-06 17:07:18.000000000 +0000 @@ -0,0 +1,24 @@ +### $Id: Makefile.Debian.conf.sample 1398 2009-11-13 21:10:12Z gareuselesinge $ + +### mandatory fields +PKG_NAME=dbi.postgresql + +### things relative to the C library part +CLIB_CFLAGS=-I$(shell pg_config --includedir) -I$(shell pg_config --includedir-server) -I . +CLIB_LDFLAGS=-lpq +CLIB_LDFLAGS_STATIC=-lpq +CLIB_OBJS=dbd/common.lo $(patsubst %.c,%.lo,$(wildcard dbd/postgresql/*.c)) +LUA_MODNAME_CPART=dbd.postgresql + +### things relative to the lua library part +LUA_HEADER= +LUA_SOURCES= +LUA_MODNAME=dbd.postgresql +LUA_TEST= + +### this part is relative to pkg-config +PKG_VERSION=$(shell dpkg-parsechangelog|grep ^Ver|cut -d ' ' -f 2|cut -d '-' -f 1) +PKG_LIBS_PRIVATE= +PKG_URL= +PKG_REQUIRES= +PKG_CONFLICTS= diff -Nru lua-dbi-0.5.hg5ba1dd988961/debian/lua5.3.sqlite3.dh-lua.conf lua-dbi-0.6/debian/lua5.3.sqlite3.dh-lua.conf --- lua-dbi-0.5.hg5ba1dd988961/debian/lua5.3.sqlite3.dh-lua.conf 1970-01-01 00:00:00.000000000 +0000 +++ lua-dbi-0.6/debian/lua5.3.sqlite3.dh-lua.conf 2018-03-06 17:07:18.000000000 +0000 @@ -0,0 +1,24 @@ +### $Id: Makefile.Debian.conf.sample 1398 2009-11-13 21:10:12Z gareuselesinge $ + +### mandatory fields +PKG_NAME=dbi.sqlite3 + +### things relative to the C library part +CLIB_CFLAGS=$(shell pkg-config sqlite3 --cflags) -I . +CLIB_LDFLAGS=$(shell pkg-config sqlite3 --libs) +CLIB_LDFLAGS_STATIC=$(shell pkg-config sqlite3 --libs --static) +CLIB_OBJS=dbd/common.lo $(patsubst %.c,%.lo,$(wildcard dbd/sqlite3/*.c)) +LUA_MODNAME_CPART=dbd.sqlite3 + +### things relative to the lua library part +LUA_HEADER= +LUA_SOURCES= +LUA_MODNAME=dbd.sqlite3 +LUA_TEST=test.lua SQLite3 foo.db + +### this part is relative to pkg-config +PKG_VERSION=$(shell dpkg-parsechangelog|grep ^Ver|cut -d ' ' -f 2|cut -d '-' -f 1) +PKG_LIBS_PRIVATE= +PKG_URL= +PKG_REQUIRES= +PKG_CONFLICTS= diff -Nru lua-dbi-0.5.hg5ba1dd988961/debian/patches/0002-fix-warning-for-fallthrough.patch lua-dbi-0.6/debian/patches/0002-fix-warning-for-fallthrough.patch --- lua-dbi-0.5.hg5ba1dd988961/debian/patches/0002-fix-warning-for-fallthrough.patch 1970-01-01 00:00:00.000000000 +0000 +++ lua-dbi-0.6/debian/patches/0002-fix-warning-for-fallthrough.patch 2018-03-06 17:07:18.000000000 +0000 @@ -0,0 +1,127 @@ +From 2cc2c9236ad6c5ad98098c41b45750300450bb90 Mon Sep 17 00:00:00 2001 +From: Victor Seva +Date: Mon, 5 Mar 2018 14:33:06 +0100 +Subject: [PATCH 1/2] fix warning for fallthrough + +> dbd/postgresql/connection.c:57:5: warning: this statement may fall through [-Wimplicit-fallthrough=] +> if (lua_isnil(L, 5) == 0) +> ^ +> dbd/postgresql/connection.c:68:5: note: here +> case 4: +> ^~~~ +> dbd/postgresql/connection.c:69:5: warning: this statement may fall through [-Wimplicit-fallthrough=] +> if (lua_isnil(L, 4) == 0) +> ^ +> dbd/postgresql/connection.c:71:5: note: here +> case 3: +> ^~~~ +> dbd/postgresql/connection.c:72:5: warning: this statement may fall through [-Wimplicit-fallthrough=] +> if (lua_isnil(L, 3) == 0) +> ^ +> dbd/postgresql/connection.c:74:5: note: here +> case 2: +> ^~~~ +> dbd/postgresql/connection.c:75:5: warning: this statement may fall through [-Wimplicit-fallthrough=] +> if (lua_isnil(L, 2) == 0) +> ^ +> dbd/postgresql/connection.c:77:5: note: here +> case 1: +> ^~~~ + +> dbd/mysql/connection.c: In function 'connection_new': +> dbd/mysql/connection.c:25:5: warning: this statement may fall through [-Wimplicit-fallthrough=] +> if (lua_isnil(L, 5) == 0) +> ^ +> dbd/mysql/connection.c:27:5: note: here +> case 4: +> ^~~~ +> dbd/mysql/connection.c:30:5: warning: this statement may fall through [-Wimplicit-fallthrough=] +> if (host != NULL) { +> ^ +> dbd/mysql/connection.c:36:5: note: here +> case 3: +> ^~~~ +> dbd/mysql/connection.c:37:5: warning: this statement may fall through [-Wimplicit-fallthrough=] +> if (lua_isnil(L, 3) == 0) +> ^ +> dbd/mysql/connection.c:39:5: note: here +> case 2: +> ^~~~ +> dbd/mysql/connection.c:40:5: warning: this statement may fall through [-Wimplicit-fallthrough=] +> if (lua_isnil(L, 2) == 0) +> ^ +> dbd/mysql/connection.c:42:5: note: here +> case 1: +> ^~~~ +--- + dbd/mysql/connection.c | 5 +++++ + dbd/postgresql/connection.c | 5 +++++ + 2 files changed, 10 insertions(+) + +diff --git a/dbd/mysql/connection.c b/dbd/mysql/connection.c +index 1ffe2a0..6f98bf9 100644 +--- a/dbd/mysql/connection.c ++++ b/dbd/mysql/connection.c +@@ -24,6 +24,7 @@ static int connection_new(lua_State *L) { + case 5: + if (lua_isnil(L, 5) == 0) + port = luaL_checkinteger(L, 5); ++ // fallthrough + case 4: + if (lua_isnil(L, 4) == 0) + host = luaL_checkstring(L, 4); +@@ -33,17 +34,21 @@ static int connection_new(lua_State *L) { + host = NULL; + }; + }; ++ // fallthrough + case 3: + if (lua_isnil(L, 3) == 0) + password = luaL_checkstring(L, 3); ++ // fallthrough + case 2: + if (lua_isnil(L, 2) == 0) + user = luaL_checkstring(L, 2); ++ // fallthrough + case 1: + /* + * db is the only mandatory parameter + */ + db = luaL_checkstring(L, 1); ++ // fallthrough + } + + conn = (connection_t *)lua_newuserdata(L, sizeof(connection_t)); +diff --git a/dbd/postgresql/connection.c b/dbd/postgresql/connection.c +index 65a9e07..1c0623b 100644 +--- a/dbd/postgresql/connection.c ++++ b/dbd/postgresql/connection.c +@@ -65,20 +65,25 @@ static int connection_new(lua_State *L) { + luaL_error(L, DBI_ERR_INVALID_PORT, pport); + } + } ++ // fallthrough + case 4: + if (lua_isnil(L, 4) == 0) + host = luaL_checkstring(L, 4); ++ // fallthrough + case 3: + if (lua_isnil(L, 3) == 0) + password = luaL_checkstring(L, 3); ++ // fallthrough + case 2: + if (lua_isnil(L, 2) == 0) + user = luaL_checkstring(L, 2); ++ // fallthrough + case 1: + /* + * db is the only mandatory parameter + */ + db = luaL_checkstring(L, 1); ++ // fallthrough + } + + conn = (connection_t *)lua_newuserdata(L, sizeof(connection_t)); +-- +2.16.1 + diff -Nru lua-dbi-0.5.hg5ba1dd988961/debian/patches/0003-fix-comparison-between-signed-and-unsigned-integer-e.patch lua-dbi-0.6/debian/patches/0003-fix-comparison-between-signed-and-unsigned-integer-e.patch --- lua-dbi-0.5.hg5ba1dd988961/debian/patches/0003-fix-comparison-between-signed-and-unsigned-integer-e.patch 1970-01-01 00:00:00.000000000 +0000 +++ lua-dbi-0.6/debian/patches/0003-fix-comparison-between-signed-and-unsigned-integer-e.patch 2018-03-06 17:07:18.000000000 +0000 @@ -0,0 +1,33 @@ +From 9363f24f606840ad7f7fce4f4305250800bd9510 Mon Sep 17 00:00:00 2001 +From: Victor Seva +Date: Mon, 5 Mar 2018 14:44:29 +0100 +Subject: [PATCH 2/2] fix comparison between signed and unsigned integer + expressions + +> dbd/common.c: In function 'dbd_replace_placeholders': +> dbd/common.c:40:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] +> for (i = 1; i < len; i++) { +> ^ +> dbd/common.c:70:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] +> for (i = 1; i < len; i++) { +> ^ +--- + dbd/common.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/dbd/common.c b/dbd/common.c +index 465380c..410d7f0 100644 +--- a/dbd/common.c ++++ b/dbd/common.c +@@ -19,7 +19,7 @@ char *dbd_replace_placeholders(lua_State *L, char native_prefix, const char *sql + size_t len = strlen(sql); + int num_placeholders = 0; + int extra_space = 0; +- int i; ++ size_t i; + char *newsql; + int newpos = 1; + int ph_num = 1; +-- +2.16.1 + diff -Nru lua-dbi-0.5.hg5ba1dd988961/debian/patches/0004-postgresql-fix-coredump.patch lua-dbi-0.6/debian/patches/0004-postgresql-fix-coredump.patch --- lua-dbi-0.5.hg5ba1dd988961/debian/patches/0004-postgresql-fix-coredump.patch 1970-01-01 00:00:00.000000000 +0000 +++ lua-dbi-0.6/debian/patches/0004-postgresql-fix-coredump.patch 2018-03-06 17:07:18.000000000 +0000 @@ -0,0 +1,34 @@ +From 298ce5c6892f664b9ec06da2513492c57154d0b8 Mon Sep 17 00:00:00 2001 +From: Victor Seva +Date: Tue, 6 Mar 2018 17:27:59 +0100 +Subject: [PATCH] [postgresql] fix coredump + +> Program terminated with signal SIGSEGV, Segmentation fault. +> #0 dbd_postgresql_statement_create (L=0x161c010, conn=0x1809288, sql_query=) at dbd/postgresql/statement.c:414 +> 414 lua_pushfstring(L, DBI_ERR_ALLOC_STATEMENT, PQerrorMessage(statement->conn->postgresql)); +> (gdb) p statement +> $1 = (statement_t *) 0x0 +> (gdb) p conn +> $1 = (connection_t *) 0x1809288 +> (gdb) p conn->postgresql +> $2 = (PGconn *) 0x18092a0 +--- + dbd/postgresql/statement.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/dbd/postgresql/statement.c b/dbd/postgresql/statement.c +index b13afea..acac91c 100644 +--- a/dbd/postgresql/statement.c ++++ b/dbd/postgresql/statement.c +@@ -411,7 +411,7 @@ int dbd_postgresql_statement_create(lua_State *L, connection_t *conn, const char + + if (!result) { + lua_pushnil(L); +- lua_pushfstring(L, DBI_ERR_ALLOC_STATEMENT, PQerrorMessage(statement->conn->postgresql)); ++ lua_pushfstring(L, DBI_ERR_ALLOC_STATEMENT, PQerrorMessage(conn->postgresql)); + return 2; + } + +-- +2.16.1 + diff -Nru lua-dbi-0.5.hg5ba1dd988961/debian/patches/remove-shebang.patch lua-dbi-0.6/debian/patches/remove-shebang.patch --- lua-dbi-0.5.hg5ba1dd988961/debian/patches/remove-shebang.patch 2016-12-16 03:41:05.000000000 +0000 +++ lua-dbi-0.6/debian/patches/remove-shebang.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,10 +0,0 @@ -Index: lua-dbi-0.5/DBI.lua -=================================================================== ---- lua-dbi-0.5.orig/DBI.lua 2010-05-01 08:19:00.000000000 +0200 -+++ lua-dbi-0.5/DBI.lua 2012-04-09 12:24:03.000000000 +0200 -@@ -1,5 +1,3 @@ --#!/usr/bin/lua -- - module('DBI', package.seeall) - - -- Driver to module mapping diff -Nru lua-dbi-0.5.hg5ba1dd988961/debian/patches/series lua-dbi-0.6/debian/patches/series --- lua-dbi-0.5.hg5ba1dd988961/debian/patches/series 2016-12-16 03:41:05.000000000 +0000 +++ lua-dbi-0.6/debian/patches/series 2018-03-06 17:07:18.000000000 +0000 @@ -1,2 +1,4 @@ -remove-shebang.patch test.patch +0002-fix-warning-for-fallthrough.patch +0003-fix-comparison-between-signed-and-unsigned-integer-e.patch +0004-postgresql-fix-coredump.patch diff -Nru lua-dbi-0.5.hg5ba1dd988961/debian/patches/test.patch lua-dbi-0.6/debian/patches/test.patch --- lua-dbi-0.5.hg5ba1dd988961/debian/patches/test.patch 2016-12-16 03:41:05.000000000 +0000 +++ lua-dbi-0.6/debian/patches/test.patch 2018-03-06 17:07:18.000000000 +0000 @@ -1,7 +1,18 @@ -Index: lua-dbi-0.5/test.lua +From: Enrico Tassi +Date: Mon, 5 Mar 2018 14:27:10 +0100 +Subject: test + =================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ lua-dbi-0.5/test.lua 2012-04-09 12:35:21.000000000 +0200 +--- + test.lua | 12 ++++++++++++ + 1 file changed, 12 insertions(+) + create mode 100644 test.lua + +diff --git a/test.lua b/test.lua +new file mode 100644 +index 0000000..70bced1 +--- /dev/null ++++ b/test.lua @@ -0,0 +1,12 @@ +local DBI = require('DBI') + diff -Nru lua-dbi-0.5.hg5ba1dd988961/debian/rules lua-dbi-0.6/debian/rules --- lua-dbi-0.5.hg5ba1dd988961/debian/rules 2016-12-16 03:41:05.000000000 +0000 +++ lua-dbi-0.6/debian/rules 2018-03-06 17:07:18.000000000 +0000 @@ -1,13 +1,13 @@ #!/usr/bin/make -f -%: +%: dh $@ --buildsystem=lua --with lua override_dh_auto_install: dh_auto_install - find debian/tmp -name \*.lua -exec chmod -x {} \; + find debian/tmp -name \*.lua -exec chmod -x {} \; override_dh_strip: - dh_strip -Xdbi-sqlite3 -Xdbi-postgresql --dbg-package=lua-dbi-mysql-dbg - dh_strip -Xdbi-sqlite3 --dbg-package=lua-dbi-postgresql-dbg - dh_strip --dbg-package=lua-dbi-sqlite3-dbg + dh_strip -Xdbi-sqlite3 -Xdbi-postgresql --dbgsym-migration='lua-dbi-mysql-dbg (<< 0.6-1~)' + dh_strip -Xdbi-sqlite3 --dbgsym-migration='lua-dbi-postgresql-dbg (<< 0.6-1~)' + dh_strip --dbgsym-migration='lua-dbi-sqlite3-dbg (<< 0.6-1~)' diff -Nru lua-dbi-0.5.hg5ba1dd988961/debian/watch lua-dbi-0.6/debian/watch --- lua-dbi-0.5.hg5ba1dd988961/debian/watch 2016-12-16 03:41:05.000000000 +0000 +++ lua-dbi-0.6/debian/watch 2018-03-06 17:07:18.000000000 +0000 @@ -2,4 +2,5 @@ # uscan --watchfile debian/watch --upstream-version 0.0.1 --package lua-dbi # version=3 -http://code.google.com/p/luadbi/downloads/list .*luadbi.([\d\.]+).tar.gz +opts="filenamemangle=s/.+\/v?(\d\S*)\.tar\.gz/luadbi_$1\.tar\.gz/" \ + https://github.com/mwild1/luadbi/tags .*/v?(\d\S*)\.tar\.gz diff -Nru lua-dbi-0.5.hg5ba1dd988961/INSTALL lua-dbi-0.6/INSTALL --- lua-dbi-0.5.hg5ba1dd988961/INSTALL 2013-08-10 18:33:16.000000000 +0000 +++ lua-dbi-0.6/INSTALL 2017-08-23 21:14:17.000000000 +0000 @@ -3,17 +3,17 @@ Before attempting to build LuaDBI the development libaries for each database must be installed. For Debian/Ubuntu systems, the list of required dependancies are: - + * libsqlite3-dev * libmysqlclient15-dev * libpq-dev * db2exc (optional for DB2 support) * oracle-xe-client (optional for Oracle support) - + = Building = -Run `make` (or `make free`) in the source directory to build the Open Source -database drivers. To build the drivers for DB2 and Oracle, run `make all`. +Run `make` (or `make free`) in the source directory to build the Open Source +database drivers. To build the drivers for DB2 and Oracle, run `make all`. == Windows == @@ -30,6 +30,16 @@ * make db2 * make oracle += Make Targets (install) = + + * make install_free - builds and installs MySQL, PostgreSQL and SQLite3 drivers + * make install_all - as above, but also builds and installs DB2 and Oracle drivers + * make install_mysql + * make install_psql + * make install_sqlite3 + * make install_db2 + * make install_oracle + = Installation = Please consult your distributions documentation on installing Lua modules. diff -Nru lua-dbi-0.5.hg5ba1dd988961/Makefile lua-dbi-0.6/Makefile --- lua-dbi-0.5.hg5ba1dd988961/Makefile 2013-08-10 18:33:16.000000000 +0000 +++ lua-dbi-0.6/Makefile 2017-08-23 21:14:17.000000000 +0000 @@ -1,92 +1,135 @@ -CC=gcc -CFLAGS=-g -pedantic -Wall -O2 -shared -fpic -I /usr/include/lua5.1 -I /usr/include/mysql -I /usr/include/postgresql/ -I /opt/ibm/db2exc/V9.5/include/ -I /usr/lib/oracle/xe/app/oracle/product/10.2.0/client/rdbms/public/ -I . -AR=ar rcu -RANLIB=ranlib -RM=rm -rf -MKDIR=mkdir -p - -COMMON_LDFLAGS= -MYSQL_LDFLAGS=$(COMMON_LDFLAGS) -lmysqlclient -PSQL_LDFLAGS=$(COMMON_LDFLAGS) -lpq -SQLITE3_LDFLAGS=$(COMMON_LDFLAGS) -lsqlite3 -DB2_LDFLAGS=$(COMMON_LDFLAGS) -L/opt/ibm/db2exc/V9.5/lib64 -L/opt/ibm/db2exc/V9.5/lib32 -ldb2 -ORACLE_LDFLAGS=$(COMMON_LDFLAGS) -L/usr/lib/oracle/xe/app/oracle/product/10.2.0/client/lib/ -locixe - -BUILDDIR=build - -DBDMYSQL=dbdmysql.so -DBDPSQL=dbdpostgresql.so -DBDSQLITE3=dbdsqlite3.so -DBDDB2=dbddb2.so -DBDORACLE=dbdoracle.so - -OBJS=build/dbd_common.o -MYSQL_OBJS=$(OBJS) build/dbd_mysql_main.o build/dbd_mysql_connection.o build/dbd_mysql_statement.o -PSQL_OBJS=$(OBJS) build/dbd_postgresql_main.o build/dbd_postgresql_connection.o build/dbd_postgresql_statement.o -SQLITE3_OBJS=$(OBJS) build/dbd_sqlite3_main.o build/dbd_sqlite3_connection.o build/dbd_sqlite3_statement.o -DB2_OBJS=$(OBJS) build/dbd_db2_main.o build/dbd_db2_connection.o build/dbd_db2_statement.o -ORACLE_OBJS=$(OBJS) build/dbd_oracle_main.o build/dbd_oracle_connection.o build/dbd_oracle_statement.o - +CC ?= cc +AR ?= ar rcu +RANLIB ?= ranlib +RM ?= rm -rf +MKDIR ?= mkdir -p +INSTALL ?= install +INSTALL_PROGRAM ?= $(INSTALL) +INSTALL_DATA ?= $(INSTALL) -m 644 +LUA_V ?= 5.1 +LUA_LDIR ?= /usr/share/lua/$(LUA_V) +LUA_CDIR ?= /usr/lib/lua/$(LUA_V) + +COMMON_CFLAGS ?= -g -pedantic -Wall -O2 -shared -fPIC -DPIC -std=c99 +LUA_INC ?= -I/usr/include/lua$(LUA_V) +MYSQL_INC ?= -I/usr/include/mysql +PSQL_INC ?= -I/usr/include/postgresql +SQLITE3_INC ?= -I/usr/include +DB2_INC ?= -I/opt/ibm/db2exc/V9.5/include +ORACLE_INC ?= -I/usr/lib/oracle/xe/app/oracle/product/10.2.0/client/rdbms/public +CF = $(LUA_INC) $(COMMON_CFLAGS) $(CFLAGS) -I. + +COMMON_LDFLAGS ?= -shared +MYSQL_LDFLAGS ?= -lmysqlclient +PSQL_LDFLAGS ?= -lpq +SQLITE3_LDFLAGS ?= -lsqlite3 +DB2_LDFLAGS ?= -L/opt/ibm/db2exc/V9.5/lib64 -L/opt/ibm/db2exc/V9.5/lib32 -ldb2 +ORACLE_LDFLAGS ?= -L/usr/lib/oracle/xe/app/oracle/product/10.2.0/client/lib/ -locixe +LF = $(COMMON_LDFLAGS) $(LDFLAGS) + +MYSQL_FLAGS = $(CF) $(LF) $(MYSQL_INC) $(MYSQL_LDFLAGS) +PSQL_FLAGS = $(CF) $(LF) $(PSQL_INC) $(PSQL_LDFLAGS) +SQLITE3_FLAGS = $(CF) $(LF) $(SQLITE3_INC) $(SQLITE3_LDFLAGS) +DB2_FLAGS = $(CF) $(LF) $(DB2_INC) $(DB2_LDFLAGS) +ORACLE_FLAGS = $(CF) $(LF) $(ORACLE_INC) $(ORACLE_LDFLAGS) + + +BUILDDIR = build + +DBDMYSQL = dbd/mysql.so +DBDPSQL = dbd/postgresql.so +DBDSQLITE3 = dbd/sqlite3.so +DBDDB2 = dbd/db2.so +DBDORACLE = dbd/oracle.so + +OBJS = build/dbd_common.o +MYSQL_OBJS = $(OBJS) build/dbd_mysql_main.o build/dbd_mysql_connection.o build/dbd_mysql_statement.o +PSQL_OBJS = $(OBJS) build/dbd_postgresql_main.o build/dbd_postgresql_connection.o build/dbd_postgresql_statement.o +SQLITE3_OBJS = $(OBJS) build/dbd_sqlite3_main.o build/dbd_sqlite3_connection.o build/dbd_sqlite3_statement.o +DB2_OBJS = $(OBJS) build/dbd_db2_main.o build/dbd_db2_connection.o build/dbd_db2_statement.o +ORACLE_OBJS = $(OBJS) build/dbd_oracle_main.o build/dbd_oracle_connection.o build/dbd_oracle_statement.o + free: mysql psql sqlite3 all: mysql psql sqlite3 db2 oracle mysql: $(BUILDDIR) $(MYSQL_OBJS) - $(CC) $(CFLAGS) $(MYSQL_OBJS) -o $(DBDMYSQL) $(MYSQL_LDFLAGS) + $(CC) $(MYSQL_OBJS) -o $(DBDMYSQL) $(MYSQL_FLAGS) psql: $(BUILDDIR) $(PSQL_OBJS) - $(CC) $(CFLAGS) $(PSQL_OBJS) -o $(DBDPSQL) $(PSQL_LDFLAGS) + $(CC) $(PSQL_OBJS) -o $(DBDPSQL) $(PSQL_FLAGS) sqlite3: $(BUILDDIR) $(SQLITE3_OBJS) - $(CC) $(CFLAGS) $(SQLITE3_OBJS) -o $(DBDSQLITE3) $(SQLITE3_LDFLAGS) + $(CC) $(SQLITE3_OBJS) -o $(DBDSQLITE3) $(SQLITE3_FLAGS) db2: $(BUILDDIR) $(DB2_OBJS) - $(CC) $(CFLAGS) $(DB2_OBJS) -o $(DBDDB2) $(DB2_LDFLAGS) + $(CC) $(DB2_OBJS) -o $(DBDDB2) $(DB2_FLAGS) oracle: $(BUILDDIR) $(ORACLE_OBJS) - $(CC) $(CFLAGS) $(ORACLE_OBJS) -o $(DBDORACLE) $(ORACLE_LDFLAGS) + $(CC) $(ORACLE_OBJS) -o $(DBDORACLE) $(ORACLE_FLAGS) clean: - $(RM) $(BUILDDIR) $(MYSQL_OBJS) $(PSQL_OBJS) $(SQLITE3_OBJS) $(DB2_OBJS) $(ORACLE_OBJS) $(DBDMYSQL) $(DBDPSQL) $(DBDSQLITE3) $(DBDDB2) $(DBDORACLE) + $(RM) $(MYSQL_OBJS) $(PSQL_OBJS) $(SQLITE3_OBJS) $(DB2_OBJS) $(ORACLE_OBJS) $(DBDMYSQL) $(DBDPSQL) $(DBDSQLITE3) $(DBDDB2) $(DBDORACLE) build/dbd_common.o: dbd/common.c dbd/common.h - $(CC) -c -o $@ $< $(CFLAGS) + $(CC) -c -o $@ $< $(CF) -build/dbd_mysql_connection.o: dbd/mysql/connection.c dbd/mysql/dbd_mysql.h dbd/common.h - $(CC) -c -o $@ $< $(CFLAGS) +build/dbd_mysql_connection.o: dbd/mysql/connection.c dbd/mysql/dbd_mysql.h dbd/common.h + $(CC) -c -o $@ $< $(MYSQL_FLAGS) build/dbd_mysql_main.o: dbd/mysql/main.c dbd/mysql/dbd_mysql.h dbd/common.h - $(CC) -c -o $@ $< $(CFLAGS) + $(CC) -c -o $@ $< $(MYSQL_FLAGS) build/dbd_mysql_statement.o: dbd/mysql/statement.c dbd/mysql/dbd_mysql.h dbd/common.h - $(CC) -c -o $@ $< $(CFLAGS) + $(CC) -c -o $@ $< $(MYSQL_FLAGS) build/dbd_postgresql_connection.o: dbd/postgresql/connection.c dbd/postgresql/dbd_postgresql.h dbd/common.h - $(CC) -c -o $@ $< $(CFLAGS) + $(CC) -c -o $@ $< $(PSQL_FLAGS) build/dbd_postgresql_main.o: dbd/postgresql/main.c dbd/postgresql/dbd_postgresql.h dbd/common.h - $(CC) -c -o $@ $< $(CFLAGS) + $(CC) -c -o $@ $< $(PSQL_FLAGS) build/dbd_postgresql_statement.o: dbd/postgresql/statement.c dbd/postgresql/dbd_postgresql.h dbd/common.h - $(CC) -c -o $@ $< $(CFLAGS) + $(CC) -c -o $@ $< $(PSQL_FLAGS) build/dbd_sqlite3_connection.o: dbd/sqlite3/connection.c dbd/sqlite3/dbd_sqlite3.h dbd/common.h - $(CC) -c -o $@ $< $(CFLAGS) + $(CC) -c -o $@ $< $(SQLITE3_FLAGS) build/dbd_sqlite3_main.o: dbd/sqlite3/main.c dbd/sqlite3/dbd_sqlite3.h dbd/common.h - $(CC) -c -o $@ $< $(CFLAGS) + $(CC) -c -o $@ $< $(SQLITE3_FLAGS) build/dbd_sqlite3_statement.o: dbd/sqlite3/statement.c dbd/sqlite3/dbd_sqlite3.h dbd/common.h - $(CC) -c -o $@ $< $(CFLAGS) + $(CC) -c -o $@ $< $(SQLITE3_FLAGS) build/dbd_db2_connection.o: dbd/db2/connection.c dbd/db2/dbd_db2.h dbd/common.h - $(CC) -c -o $@ $< $(CFLAGS) + $(CC) -c -o $@ $< $(DB2_FLAGS) build/dbd_db2_main.o: dbd/db2/main.c dbd/db2/dbd_db2.h dbd/common.h - $(CC) -c -o $@ $< $(CFLAGS) + $(CC) -c -o $@ $< $(DB2_FLAGS) build/dbd_db2_statement.o: dbd/db2/statement.c dbd/db2/dbd_db2.h dbd/common.h - $(CC) -c -o $@ $< $(CFLAGS) + $(CC) -c -o $@ $< $(DB2_FLAGS) build/dbd_oracle_connection.o: dbd/oracle/connection.c dbd/oracle/dbd_oracle.h dbd/common.h - $(CC) -c -o $@ $< $(CFLAGS) + $(CC) -c -o $@ $< $(ORACLE_FLAGS) build/dbd_oracle_main.o: dbd/oracle/main.c dbd/oracle/dbd_oracle.h dbd/common.h - $(CC) -c -o $@ $< $(CFLAGS) + $(CC) -c -o $@ $< $(ORACLE_FLAGS) build/dbd_oracle_statement.o: dbd/oracle/statement.c dbd/oracle/dbd_oracle.h dbd/common.h - $(CC) -c -o $@ $< $(CFLAGS) + $(CC) -c -o $@ $< $(ORACLE_FLAGS) build: $(MKDIR) ${BUILDDIR} +install_lua: + $(INSTALL_DATA) -D DBI.lua $(DESTDIR)$(LUA_LDIR)/DBI.lua + +install_mysql: mysql install_lua + $(INSTALL_PROGRAM) -D $(DBDMYSQL) $(DESTDIR)$(LUA_CDIR)/$(DBDMYSQL) + +install_psql: psql install_lua + $(INSTALL_PROGRAM) -D $(DBDPSQL) $(DESTDIR)$(LUA_CDIR)/$(DBDPSQL) + +install_sqlite3: sqlite3 install_lua + $(INSTALL_PROGRAM) -D $(DBDSQLITE3) $(DESTDIR)$(LUA_CDIR)/$(DBDSQLITE3) + +install_db2: db2 install_lua + $(INSTALL_PROGRAM) -D $(DBDDB2) $(DESTDIR)$(LUA_CDIR)/$(DBDDB2) + +install_oracle: oracle install_lua + $(INSTALL_PROGRAM) -D $(DBDORACLE) $(DESTDIR)$(LUA_CDIR)/$(DBDORACLE) + +install_free: install_lua install_mysql install_psql install_sqlite3 + +install_all: install_lua install_mysql install_psql install_sqlite3 install_db2 install_oracle diff -Nru lua-dbi-0.5.hg5ba1dd988961/README lua-dbi-0.6/README --- lua-dbi-0.5.hg5ba1dd988961/README 2013-08-10 18:33:16.000000000 +0000 +++ lua-dbi-0.6/README 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -Please visit http://code.google.com/p/luadbi/w/list for details on using LuaDBI diff -Nru lua-dbi-0.5.hg5ba1dd988961/README.md lua-dbi-0.6/README.md --- lua-dbi-0.5.hg5ba1dd988961/README.md 1970-01-01 00:00:00.000000000 +0000 +++ lua-dbi-0.6/README.md 2017-08-23 21:14:17.000000000 +0000 @@ -0,0 +1,12 @@ +LuaDBI is a database interface library for Lua. It is designed to +provide a RDBMS agnostic API for handling database operations. +LuaDBI also provides support for prepared statement handles, +placeholders and bind parameters for all database operations. + +Currently LuaDBI supports DB2, Oracle, MySQL, PostgreSQL and SQLite +databases with native database drivers. + +This version supports Lua 5.1, 5.2, and 5.3. + +Documentation is in the 'wiki' branch. You may also +[browse it online](https://zadzmo.org/code/luadbi/wiki) diff -Nru lua-dbi-0.5.hg5ba1dd988961/tests/configs/MySQL.lua lua-dbi-0.6/tests/configs/MySQL.lua --- lua-dbi-0.5.hg5ba1dd988961/tests/configs/MySQL.lua 1970-01-01 00:00:00.000000000 +0000 +++ lua-dbi-0.6/tests/configs/MySQL.lua 2017-08-23 21:14:17.000000000 +0000 @@ -0,0 +1,39 @@ +#!/usr/bin/env lua + + +return { + + connect = { + host = 'mysqlserver.zadzmo.org', + port = 3306, + name = 'luadbi', + user = 'luadbi', + pass = 'testing12345!!!' + }, + + encoding_test = { + 12435212, + 463769, + 8574678, + -12435212, + 0, + 9998212, + 7653.25, + 7635236, + 0.000, + -7653.25, + 1636.94783, + "string 1", + "another_string", + "really long string with some escapable chars: #&*%#;@'" + }, + + placeholder = '?', + + have_last_insert_id = true, + have_typecasts = false, + have_booleans = false, + have_rowcount = true + +} + diff -Nru lua-dbi-0.5.hg5ba1dd988961/tests/configs/PostgreSQL.lua lua-dbi-0.6/tests/configs/PostgreSQL.lua --- lua-dbi-0.5.hg5ba1dd988961/tests/configs/PostgreSQL.lua 1970-01-01 00:00:00.000000000 +0000 +++ lua-dbi-0.6/tests/configs/PostgreSQL.lua 2017-08-23 21:14:17.000000000 +0000 @@ -0,0 +1,45 @@ +#!/usr/bin/env lua + + +return { + + connect = { + host = 'pgserver.zadzmo.org', + name = 'luadbi', + user = 'luadbi', + pass = 'testinguser-12345!!!' + }, + + encoding_test = { + ['::int'] = 12435212, + ['::int'] = 463769, + ['::int'] = 8574678, + ['::int'] = -12435212, + ['::int'] = 0, + ['::int'] = 9998212, + ['::double precision'] = 123412.5235236199951, + ['::float'] = 7653.25, + ['::float'] = 7635236, + ['::float'] = 0.00, + ['::float'] = -7653.25, + ['::float'] = 1636.94783, + ['::decimal'] = 35.34, + ['::decimal'] = -3.00, + ['::decimal'] = 35848535.24, + ['::decimal'] = 0.00, + ['::boolean'] = true, + ['::boolean'] = false, + ['::varchar'] = "string 1", + ['::varchar'] = "another_string", + ['::text'] = "really long string with some escapable chars: #&*%#;@'" + }, + + placeholder = '$1', + + have_last_insert_id = false, + have_typecasts = true, + have_booleans = true, + have_rowcount = true + +} + diff -Nru lua-dbi-0.5.hg5ba1dd988961/tests/configs/SQLite3.lua lua-dbi-0.6/tests/configs/SQLite3.lua --- lua-dbi-0.5.hg5ba1dd988961/tests/configs/SQLite3.lua 1970-01-01 00:00:00.000000000 +0000 +++ lua-dbi-0.6/tests/configs/SQLite3.lua 2017-08-23 21:14:17.000000000 +0000 @@ -0,0 +1,38 @@ +#!/usr/bin/env lua + + +return { + + connect = { + name = 'sqlite3-test' + }, + + encoding_test = { + ['::int'] = 12435212, + ['::int'] = 463769, + ['::int'] = 8574678, + ['::int'] = -12435212, + ['::int'] = 0, + ['::int'] = 9998212, + ['::float'] = 0.00, + ['::float'] = -7653.25, + ['::float'] = 1636.94783, + ['::decimal'] = 35.34, + ['::decimal'] = -3.00, + ['::decimal'] = 35848535.24, + ['::decimal'] = 0.00, + ['::varchar'] = "string 1", + ['::varchar'] = "another_string", + ['::text'] = "really long string with some escapable chars: #&*%#;@'" + }, + + + placeholder = '$1', + + have_last_insert_id = true, + have_typecasts = true, + have_booleans = false, + have_rowcount = false + +} + diff -Nru lua-dbi-0.5.hg5ba1dd988961/tests/run_tests.lua lua-dbi-0.6/tests/run_tests.lua --- lua-dbi-0.5.hg5ba1dd988961/tests/run_tests.lua 1970-01-01 00:00:00.000000000 +0000 +++ lua-dbi-0.6/tests/run_tests.lua 2017-08-23 21:14:17.000000000 +0000 @@ -0,0 +1,522 @@ +#!/usr/bin/env lua5.2 + +package.path = "../?.lua;" .. package.path +package.cpath = "../?.so;" .. package.cpath + +require "luarocks.loader" +require 'busted.runner'() + + +local sql_code = { + + ['encoding'] = "select %s%s as retval;", + ['select'] = "select * from select_tests where name = %s;", + ['select_multi'] = "select * from select_tests where flag = %s;", + ['select_count'] = "select count(*) as total from insert_tests;", + ['insert'] = "insert into insert_tests ( val ) values ( %s );", + ['insert_returning'] = "insert into insert_tests ( val ) values ( %s ) returning id;", + ['insert_select'] = "select * from insert_tests where id = %s;", + ['update_all'] = "update update_tests set last_update = %s;", + ['update_some'] = "update update_tests set last_update = %s where flag = %s;" + +} + + +local function code( sql_test_code, arg ) + + local ret = string.format(sql_code[sql_test_code], config.placeholder, arg) + --print(ret) + return ret + +end + + + +local function setup_tests() + + DBI = require "DBI" + assert.is_not_nil(DBI) + + dbh, err = DBI.Connect( + db_type, + config.connect.name, + config.connect.user, + config.connect.pass, + config.connect.host, + config.connect.port + ) + + assert.is_nil(err) + assert.is_not_nil(dbh) + assert.is_not_nil(dbh:autocommit( true )) + + assert.is_true( dbh:ping() ) + return dbh + +end + + +local function teardown_tests() + + if dbh then + dbh:close() + dbh = nil + end + +end + + + +local function connection_fail() + + local dbh2, err = DBI.Connect( + db_type, + "Bogus1-3jrn23j4n32j4n23jn4@32^$2j", + "Bogus2-#*%J#@&*FNM@JK#FM#", + "Bogus3-#*NMR@JNM^#M<&$*%" + ) + + assert.is_nil(dbh2) + assert.is_string(err) + +end + +local function syntax_error() + + + local sth, err = dbh:prepare("Break me 3i5m2r3krm3280j648390j@#(J%28903j523890j623") + assert.is_nil(sth) + assert.is_string(err) + +end + + + + +local function test_encoding() + + for vtype, val in pairs(config.encoding_test) do + + if config.have_typecasts then + query = code('encoding', vtype) + else + query = code('encoding', '') + end + + + local sth = assert.is_not_nil(dbh:prepare(query)) + assert.is_not_nil(sth) + assert.is_not_nil(sth:execute(val)) + local row = sth:rows(true)() + assert.is_not_nil(row) + assert.is_equal(val, row['retval']) + assert.is_equal(type(val), type(row['retval'])) + + sth:close() + + end + +end + + +local function test_select() + + local sth, err = dbh:prepare(code('select')) + local count = 0 + local success + + assert.is_nil(err) + assert.is_not_nil(sth) + success, err = sth:execute("Row 1") + + assert.is_true(success) + assert.is_nil(err) + + for row in sth:rows(true) do + count = count + 1 + + if config.have_booleans then + assert.is_true(row['flag']) + else + assert.equals(1, row['flag']) + end + + assert.equals('Row 1', row['name']) + assert.is_number(row['maths']) + end + + assert.equals(1, count) + + if config.have_rowcount then + assert.equals(sth:rowcount(), count) + end + + sth:close() + +end + + +local function test_select_multi() + + local sth, err = dbh:prepare(code('select_multi')) + local count = 0 + + assert.is_nil(err) + assert.is_not_nil(sth) + local success, err = sth:execute(false) + + assert.is_true(success) + assert.is_nil(err) + + for row in sth:rows(false) do + count = count + 1 + + assert.equals(#row, 4) + assert.is_number(row[1]) + assert.is_string(row[2]) + + if config.have_booleans then + assert.is_false(row[3]) + else + assert.equals(0, row[3]) + end + + assert.is_number(row[4]) + end + + assert.equals(2, count) + + if config.have_rowcount then + assert.equals(sth:rowcount(), count) + end + + sth:close() + +end + + +local function test_insert() + + local sth, sth2, err, success, stringy + local stringy = os.date() + + + sth, err = dbh:prepare(code('insert')) + + assert.is_nil(err) + assert.is_not_nil(sth) + + success, err = sth:execute(stringy) + + assert.is_true(success) + assert.is_nil(err) + + assert.is_equal(1, sth:affected()) + + -- + -- Grab it back, make sure it's all good + -- + + local id = dbh:last_id() + assert.is_not_nil(id) + sth:close() + + sth2, err = dbh:prepare(code('insert_select')) + + assert.is_nil(err) + assert.is_not_nil(sth) + + success, err = sth2:execute(id) + + assert.is_true(success) + assert.is_nil(err) + + local row = sth2:rows(false)() + assert.is_not_nil(row) + assert.are_equal(id, row[1]) + assert.are_equal(stringy, row[2]) + + sth:close() + sth2:close() + +end + + +local function test_insert_multi() + + local sth, sth2, err, stringy, rs, count, success + local stringy = os.date() + + sth, err = dbh:prepare(code('insert')) + assert.is_nil(err) + assert.is_not_nil(sth) + + sth2, err = dbh:prepare(sql_code['select_count']) + assert.is_nil(err) + assert.is_not_nil(sth2) + + -- + -- See how many rows are in the table + -- + rs, err = sth2:execute() + assert.is_nil(err) + assert.is_not_nil(rs) + + local itr = sth2:rows(false) + count = itr()[1] + + -- drain the results - should only be one row but let's be correct + while itr() do success = nil end + + -- + -- Reuse the insert statement quite a few times + -- + for i=1,10 do + success, err = sth:execute(stringy .. '-' .. tostring(i)) + + assert.is_true(success) + assert.is_nil(err) + assert.is_not_nil(sth) + + assert.is_equal(1, sth:affected()) + end + + + -- + -- Make sure all ten inserts succeed by comparing how many + -- rows are there now. Also proves selects are reusable. + -- + rs, err = sth2:execute() + assert.is_nil(err) + assert.is_not_nil(rs) + + itr = sth2:rows(false) + assert.is_equal(count + 10, itr()[1]) + while itr() do success = nil end + + sth:close() + sth2:close() + +end + + +local function test_insert_returning() + + local sth, sth2, err, success, stringy + local stringy = os.date() + + + sth, err = dbh:prepare(code('insert_returning')) + + assert.is_nil(err) + assert.is_not_nil(sth) + success, err = sth:execute(stringy) + + assert.is_nil(err) + assert.is_true(success) + + assert.is_equal(1, sth:rowcount()) + + + -- + -- Grab it back, make sure it's all good + -- + local id_row = sth:rows(false)() + assert.is_not_nil(id_row) + local id = id_row[1] + + assert.is_not_nil(id) + sth:close() + + sth2, err = dbh:prepare(code('insert_select')) + + assert.is_nil(err) + assert.is_not_nil(sth) + success, err = sth2:execute(id) + + local row = sth2:rows(false)() + assert.is_not_nil(row) + assert.are_equal(id, row[1]) + assert.are_equal(stringy, row[2]) + +end + + +-- +-- Prove affected() is functional. +-- +local function test_update() + + -- + -- I originally used date handling and set the column + -- to NOW(), but Sqlite3 didn't play nice with that. + -- + + local sth, err = dbh:prepare(code('update_all')) + local success + + assert.is_nil(err) + assert.is_not_nil(sth) + + success, err = sth:execute(os.time() - math.random(50, 500)) + assert.is_nil(err) + assert.is_true(success) + assert.equals(4, sth:affected()) + sth:close() + sth = nil + + -- do it again with the flag set, so we get fewer rows, + -- just to be sure. + -- which also means we need to sleep for a bit. + + if config.have_booleans then + sth, err = dbh:prepare(code('update_some', 'false')) + else + sth, err = dbh:prepare(code('update_some', '0')) + end + + assert.is_nil(err) + assert.is_not_nil(sth) + + success, err = sth:execute(os.time()) + assert.is_nil(err) + assert.is_true(success) + assert.equals(1, sth:affected()) + +end + + + +-- +-- Prove the nonexistant functions aren't there. +-- +local function test_no_rowcount() + + local sth, err = dbh:prepare(code('select')) + local success + + success, err = sth:execute("Row 1") + + assert.is_true(success) + assert.is_nil(err) + + assert.has_error(function() + local x = sth:rowcount() + end) + + sth:close() + +end + + +-- +-- Prove there is no insert_id. +-- +local function test_no_insert_id() + + local sth, sth2, err, success, stringy + local stringy = os.date() + + + sth, err = dbh:prepare(code('insert')) + + assert.is_nil(err) + assert.is_not_nil(sth) + success, err = sth:execute(stringy) + + assert.has_error(function() + local x = dbh:insert_id() + end) + + sth:close() + +end + + +-- +-- Prove something sane happens in the event that the database +-- handle goes away, but statements are still open. +-- +local function test_db_close_doesnt_segfault() + + + local sth, sth2, err + sth = dbh:prepare("SELECT 1"); + + assert.is_nil(err) + assert.is_not_nil(sth) + + dbh:close() + sth2, err = dbh:prepare(code('insert')) + + assert.is_nil(sth2) + assert.is_string(err) + + + dbh = nil + + assert.has_error(function() + sth:execute() + end) + + -- this also shouldn't segfault. + sth:close() + +end + + + +describe("PostgreSQL #psql", function() + db_type = "PostgreSQL" + config = dofile("configs/" .. db_type .. ".lua") + local DBI, dbh + + setup(setup_tests) + it( "Tests login failure", connection_fail ) + it( "Tests syntax error", syntax_error ) + it( "Tests value encoding", test_encoding ) + it( "Tests a simple select", test_select ) + it( "Tests multi-row selects", test_select_multi ) + it( "Tests inserts", test_insert_returning ) + it( "Tests statement reuse", test_insert_multi ) + it( "Tests no insert_id", test_no_insert_id ) + it( "Tests affected rows", test_update ) + it( "Tests closing dbh doesn't segfault", test_db_close_doesnt_segfault ) + teardown(teardown) +end) + +describe("SQLite3 #sqlite3", function() + db_type = "SQLite3" + config = dofile("configs/" .. db_type .. ".lua") + local DBI, dbh + + setup(setup_tests) + it( "Tests syntax error", syntax_error ) + it( "Tests value encoding", test_encoding ) + it( "Tests simple selects", test_select ) + it( "Tests multi-row selects", test_select_multi ) + it( "Tests inserts", test_insert ) + it( "Tests statement reuse", test_insert_multi ) + it( "Tests no rowcount", test_no_rowcount ) + it( "Tests affected rows", test_update ) + it( "Tests closing dbh doesn't segfault", test_db_close_doesnt_segfault ) + teardown(teardown) +end) + +describe("MySQL #mysql", function() + db_type = "MySQL" + config = dofile("configs/" .. db_type .. ".lua") + local DBI, dbh + + setup(setup_tests) + it( "Tests login failure", connection_fail ) + it( "Tests syntax error", syntax_error ) + it( "Tests value encoding", test_encoding ) + it( "Tests simple selects", test_select ) + it( "Tests multi-row selects", test_select_multi ) + it( "Tests inserts", test_insert ) + it( "Tests statement reuse", test_insert_multi ) + it( "Tests affected rows", test_update ) + it( "Tests closing dbh doesn't segfault", test_db_close_doesnt_segfault ) + teardown(teardown) +end) diff -Nru lua-dbi-0.5.hg5ba1dd988961/tests/schemas/mysql.sql lua-dbi-0.6/tests/schemas/mysql.sql --- lua-dbi-0.5.hg5ba1dd988961/tests/schemas/mysql.sql 1970-01-01 00:00:00.000000000 +0000 +++ lua-dbi-0.6/tests/schemas/mysql.sql 2017-08-23 21:14:17.000000000 +0000 @@ -0,0 +1,91 @@ +/* + + MySQL test schema. + +*/ + +drop table if exists select_tests; +create table select_tests + ( + id int not null primary key auto_increment, + + name varchar(255) not null, + flag boolean not null, + + maths int not null + + ); + +insert into select_tests + ( + name, + flag, + maths + ) + values + ( + 'Row 1', + true, + 12345 + ), + ( + 'Row 2', + false, + 54321 + ), + ( + 'Row 3', + false, + 324671 + ); + +grant select on select_tests to 'luadbi'@'%'; + + +drop table if exists insert_tests; +create table insert_tests + ( + id int not null primary key auto_increment, + val varchar(255) not null + ); + +grant insert, select on insert_tests to 'luadbi'@'%'; + +drop table if exists update_tests; +create table update_tests + ( + id int not null primary key auto_increment, + name varchar(255) not null, + last_update int not null, + flag bool not null + ); + +insert into update_tests + ( + name, + last_update, + flag + ) + values + ( + 'Row 1', + UNIX_TIMESTAMP(NOW()), + 1 + ), + ( + 'Row 2', + UNIX_TIMESTAMP(NOW()), + 1 + ), + ( + 'Row 3', + UNIX_TIMESTAMP(NOW()), + 0 + ), + ( + 'Row 4', + UNIX_TIMESTAMP(NOW()), + 1 + ); + +grant select, update on update_tests to 'luadbi'@'%'; diff -Nru lua-dbi-0.5.hg5ba1dd988961/tests/schemas/postgresql.sql lua-dbi-0.6/tests/schemas/postgresql.sql --- lua-dbi-0.5.hg5ba1dd988961/tests/schemas/postgresql.sql 1970-01-01 00:00:00.000000000 +0000 +++ lua-dbi-0.6/tests/schemas/postgresql.sql 2017-08-23 21:14:17.000000000 +0000 @@ -0,0 +1,95 @@ +/* + + PostgreSQL test schema. + +*/ + +drop table if exists select_tests cascade; +create table select_tests + ( + id serial primary key, + + name varchar(255) not null, + flag boolean not null, + + maths int not null + + ); + +insert into select_tests + ( + name, + flag, + maths + ) + values + ( + 'Row 1', + true, + 12345 + ), + ( + 'Row 2', + false, + 54321 + ), + ( + 'Row 3', + false, + 324671 + ); + +grant select on select_tests to luadbi; + + + +drop table if exists insert_tests cascade; +create table insert_tests + ( + id serial primary key, + val varchar(255) not null + ); + +grant insert, select on insert_tests to luadbi; +grant usage, select on insert_tests_id_seq to luadbi; + +drop table if exists update_tests; +create table update_tests + ( + id serial primary key, + name varchar(255) not null, + last_update int not null, + flag bool not null + ); + +insert into update_tests + ( + name, + last_update, + flag + ) + values + ( + 'Row 1', + 0, + true + ), + ( + 'Row 2', + 0, + true + ), + ( + 'Row 3', + 0, + false + ), + ( + 'Row 4', + 0, + true + ); + +grant select, update on update_tests to luadbi; + + diff -Nru lua-dbi-0.5.hg5ba1dd988961/tests/schemas/sqlite3.sql lua-dbi-0.6/tests/schemas/sqlite3.sql --- lua-dbi-0.5.hg5ba1dd988961/tests/schemas/sqlite3.sql 1970-01-01 00:00:00.000000000 +0000 +++ lua-dbi-0.6/tests/schemas/sqlite3.sql 2017-08-23 21:14:17.000000000 +0000 @@ -0,0 +1,85 @@ +/* + + SQLite3 test schema. + +*/ + +drop table if exists select_tests; +create table select_tests + ( + id integer primary key, + + name varchar(255) not null, + flag boolean not null, + + maths int not null + ); + +insert into select_tests + ( + name, + flag, + maths + ) + values + ( + 'Row 1', + 1, + 12345 + ), + ( + 'Row 2', + 0, + 54321 + ), + ( + 'Row 3', + 0, + 324671 + ); + + + +drop table if exists insert_tests; +create table insert_tests + ( + id integer primary key, + val varchar(255) not null + ); + +drop table if exists update_tests; +create table update_tests + ( + id integer primary key, + name varchar(255) not null, + last_update int not null, + flag bool not null + ); + +insert into update_tests + ( + name, + last_update, + flag + ) + values + ( + 'Row 1', + 'now', + 1 + ), + ( + 'Row 2', + 'now', + 1 + ), + ( + 'Row 3', + 'now', + 0 + ), + ( + 'Row 4', + 'now', + 1 + );