Feature #2093 ยป 0028-luasql-Update-to-version-2.8.1.patch
| dependencies/luasql/Version.txt | ||
|---|---|---|
|
Sources here are from luasql git tag 2.7.0
|
||
|
(https://github.com/lunarmodules/luasql/tree/2.7.0)
|
||
|
Sources here are from luasql git tag 2.8.1
|
||
|
(https://github.com/lunarmodules/luasql/tree/2.8.1)
|
||
|
Some modifications have been done to them:
|
||
|
- Commit 10ed75b36bf909f57b3c1a070dd87669c323cff0 backported
|
||
|
- Fixed compile error on ls_sqlite3.c raw_readparams_table()
|
||
|
Fix has been submitted to upstream.
|
||
|
- Cleared trailing spaces
|
||
|
- LUASQL_VERSION_NUMBER defined in luasql.h
|
||
|
- Cleared trailing tabs from ls_mysql.c
|
||
|
Equivalent patch submitted to upstream.
|
||
|
- Fixed comment typos found by codespell
|
||
|
Fix has been submitted to upstream.
|
||
|
- Fixed misleading indentation in ls_sqlite3.c
|
||
|
- Removed unused variables from ls_odbc.c
|
||
|
- Cleared trailing tabs from ls_odbc.c
|
||
|
Only the files needed by freeciv are included here, not entire luasql
|
||
|
source directory hierarchy.
|
||
| dependencies/luasql/src/ls_odbc.c | ||
|---|---|---|
|
#include <string.h>
|
||
|
#include <time.h>
|
||
|
#define SQL_NOUNICODEMAP
|
||
|
#if defined(_WIN32)
|
||
|
#include <windows.h>
|
||
|
#include <sqlext.h>
|
||
| ... | ... | |
|
*/
|
||
|
static const char *sqltypetolua (const SQLSMALLINT type) {
|
||
|
switch (type) {
|
||
|
case SQL_UNKNOWN_TYPE: case SQL_CHAR: case SQL_VARCHAR:
|
||
|
case SQL_TYPE_DATE: case SQL_TYPE_TIME: case SQL_TYPE_TIMESTAMP:
|
||
|
case SQL_DATE: case SQL_INTERVAL: case SQL_TIMESTAMP:
|
||
|
case SQL_LONGVARCHAR:
|
||
|
case SQL_WCHAR: case SQL_WVARCHAR: case SQL_WLONGVARCHAR:
|
||
|
#if (ODBCVER >= 0x0350)
|
||
|
case SQL_GUID:
|
||
|
#endif
|
||
|
return "string";
|
||
|
case SQL_BIGINT: case SQL_TINYINT:
|
||
|
case SQL_INTEGER: case SQL_SMALLINT:
|
||
|
#if LUA_VERSION_NUM>=503
|
||
| ... | ... | |
|
case SQL_BIT:
|
||
|
return "boolean";
|
||
|
default:
|
||
|
assert(0);
|
||
|
return NULL;
|
||
|
return "string";
|
||
|
}
|
||
|
}
|
||
| ... | ... | |
|
#if LUA_VERSION_NUM>=503
|
||
|
/* iNteger */
|
||
|
case 'n': {
|
||
|
SQLINTEGER num;
|
||
|
SQLLEN num;
|
||
|
SQLLEN got;
|
||
|
SQLRETURN rc = SQLGetData(hstmt, i, SQL_C_SLONG, &num, 0, &got);
|
||
|
if (error(rc))
|
||
| ... | ... | |
|
return fail(L, hSTMT, stmt->hstmt);
|
||
|
}
|
||
|
lua_pushnumber(L, numrows);
|
||
|
#if LUA_VERSION_NUM >= 503
|
||
|
lua_pushinteger(L, (lua_Integer)numrows);
|
||
|
#else
|
||
|
lua_pushnumber(L, (lua_Number)numrows);
|
||
|
#endif
|
||
|
return 1;
|
||
|
}
|
||
|
}
|
||
| ... | ... | |
|
if (error(ret))
|
||
|
return luasql_faildirect (L, "connection allocation error.");
|
||
|
/* detect if sourcename is DSN / connection string by checking for '=' char */
|
||
|
int is_connection_string = 0;
|
||
|
const char *src = (const char*)sourcename;
|
||
|
if (strstr(src, "=") != NULL) {
|
||
|
is_connection_string = 1;
|
||
|
}
|
||
|
/* tries to connect handle */
|
||
|
ret = SQLConnect (hdbc, sourcename, SQL_NTS,
|
||
|
username, SQL_NTS, password, SQL_NTS);
|
||
|
if (is_connection_string) {
|
||
|
ret = SQLDriverConnect(
|
||
|
hdbc,
|
||
|
NULL, /* window handle */
|
||
|
sourcename,
|
||
|
SQL_NTS,
|
||
|
NULL, /* output connection string buffer */
|
||
|
0, /* sizeof output buffer */
|
||
|
NULL, /* actual length of output string buffer */
|
||
|
SQL_DRIVER_NOPROMPT
|
||
|
);
|
||
|
} else {
|
||
|
ret = SQLConnect (hdbc, sourcename, SQL_NTS,
|
||
|
username, SQL_NTS, password, SQL_NTS);
|
||
|
}
|
||
|
if (error(ret)) {
|
||
|
ret = fail(L, hDBC, hdbc);
|
||
|
SQLFreeHandle(hDBC, hdbc);
|
||
| dependencies/luasql/src/ls_sqlite3.c | ||
|---|---|---|
|
typedef struct
|
||
|
{
|
||
|
short closed;
|
||
|
short first_fetch;
|
||
|
int conn; /* reference to connection */
|
||
|
int numcols; /* number of columns */
|
||
|
int colnames, coltypes; /* reference to column information tables */
|
||
| ... | ... | |
|
if (vm == NULL)
|
||
|
return 0;
|
||
|
res = sqlite3_step(vm);
|
||
|
/* no more results? */
|
||
|
if (res == SQLITE_DONE)
|
||
|
return finalize(L, cur);
|
||
|
if (!cur->first_fetch) {
|
||
|
res = sqlite3_step(vm);
|
||
|
if (res != SQLITE_ROW)
|
||
|
return finalize(L, cur);
|
||
|
if (res == SQLITE_DONE || res != SQLITE_ROW)
|
||
|
return finalize(L, cur);
|
||
|
} else {
|
||
|
cur->first_fetch = 0;
|
||
|
}
|
||
|
if (lua_istable (L, 2))
|
||
|
{
|
||
| ... | ... | |
|
/* fill in structure */
|
||
|
cur->closed = 0;
|
||
|
cur->first_fetch = 1;
|
||
|
cur->conn = LUA_NOREF;
|
||
|
cur->numcols = numcols;
|
||
|
cur->colnames = LUA_NOREF;
|
||
| ... | ... | |
|
}
|
||
|
conn->closed = 1;
|
||
|
luaL_unref(L, LUA_REGISTRYINDEX, conn->env);
|
||
|
sqlite3_close(conn->sql_conn);
|
||
|
lua_pushboolean(L, 1);
|
||
|
return 1;
|
||
| ... | ... | |
|
while (lua_next(L, arg)) { // [arg]=table, [-2]=key, [-1]=val
|
||
|
#if defined(lua_isinteger)
|
||
|
int tt =
|
||
|
#endif
|
||
|
lua_type(L, -2);
|
||
|
#if defined(lua_isinteger)
|
||
|
if (tt == LUA_TNUMBER && lua_isinteger(L, -2)) {
|
||
|
if (lua_type(L, -2) == LUA_TNUMBER && lua_isinteger(L, -2)) {
|
||
|
param_nr = lua_tointeger(L, -2);
|
||
|
} else {
|
||
|
#endif
|
||
| ... | ... | |
|
/* real query? if empty, must have numcols!=0 */
|
||
|
if ((res == SQLITE_ROW) || ((res == SQLITE_DONE) && numcols))
|
||
|
{
|
||
|
sqlite3_reset(vm);
|
||
|
return create_cursor(L, 1, conn, vm, numcols);
|
||
|
}
|
||
| dependencies/luasql/src/luasql.c | ||
|---|---|---|
|
/*
|
||
|
** $Id: luasql.c,v 1.28 2009/02/11 12:08:50 tomas Exp $
|
||
|
** See Copyright Notice in license.html
|
||
|
*/
|
||
| ... | ... | |
|
*/
|
||
|
LUASQL_API void luasql_set_info (lua_State *L) {
|
||
|
lua_pushliteral (L, "_COPYRIGHT");
|
||
|
lua_pushliteral (L, "Copyright (C) 2003-2025 Kepler Project");
|
||
|
lua_pushliteral (L, "Copyright (C) 2003-2026 Lunar Modules Project");
|
||
|
lua_settable (L, -3);
|
||
|
lua_pushliteral (L, "_DESCRIPTION");
|
||
|
lua_pushliteral (L, "LuaSQL is a simple interface from Lua to a DBMS");
|
||
|
lua_settable (L, -3);
|
||
|
lua_pushliteral (L, "_VERSION");
|
||
|
lua_pushliteral (L, "LuaSQL 2.7.0 (for "LUA_VERSION")");
|
||
|
lua_pushliteral (L, "LuaSQL "LUASQL_VERSION_NUMBER" (for "LUA_VERSION")");
|
||
|
lua_settable (L, -3);
|
||
|
}
|
||
| dependencies/luasql/src/luasql.h | ||
|---|---|---|
|
#define LUASQL_API
|
||
|
#endif
|
||
|
#define LUASQL_VERSION_NUMBER "2.8.1"
|
||
|
#if !defined LUA_VERSION_NUM
|
||
|
/* Lua 5.0 */
|
||
|
#define luaL_Reg luaL_reg
|
||
| ... | ... | |
|
#endif
|
||
|
/* Driver initialization functions prototypes */
|
||
|
LUASQL_API int luaopen_luasql_duckdb (lua_State *L);
|
||
|
LUASQL_API int luaopen_luasql_firebird (lua_State *L);
|
||
|
LUASQL_API int luaopen_luasql_mysql (lua_State *L);
|
||
|
LUASQL_API int luaopen_luasql_oci8 (lua_State *L);
|
||