import luadbi 0.5

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.

ok sthen@
This commit is contained in:
jasper 2012-08-16 15:21:30 +00:00
parent df68fbe849
commit 6973062b94
11 changed files with 293 additions and 0 deletions

62
databases/luadbi/Makefile Normal file
View File

@ -0,0 +1,62 @@
# $OpenBSD: Makefile,v 1.1.1.1 2012/08/16 15:21:30 jasper Exp $
SHARED_ONLY= Yes
COMMENT-main= database interface library for Lua (including SQLite3)
COMMENT-mysql= MySQL driver for luadbi
COMMENT-pgsql= PostgreSQL driver for luadbi
V= 0.5
DISTNAME= luadbi.$V
PKGNAME-main= luadbi-$V
PKGNAME-mysql= luadbi-mysql-$V
PKGNAME-pgsql= luadbi-pgsql-$V
CATEGORIES= databases
HOMEPAGE= http://luadbi.googlecode.com/
# MIT
PERMIT_PACKAGE_CDROM= Yes
PERMIT_PACKAGE_FTP= Yes
PERMIT_DISTFILES_CDROM= Yes
PERMIT_DISTFILES_FTP= Yes
MASTER_SITES= ${HOMEPAGE}/files/
MULTI_PACKAGES= -main -mysql -pgsql
WANTLIB-main= sqlite3
RUN_DEPENDS-main= #empty
WANTLIB-mysql= mysqlclient
LIB_DEPENDS-mysql= databases/mysql
RUN_DEPENDS-mysql= ${BASE_PKGPATH},-main
WANTLIB-pgsql= pq
BUILD_DEPENDS-pgsql= databases/postgresql,-server
LIB_DEPENDS-pgsql= databases/postgresql
RUN_DEPENDS-pgsql= ${BASE_PKGPATH},-main
MODULES= lang/lua
USE_GMAKE= Yes
ALL_TARGET= free # == sqlite3 mysql postgresql
NO_REGRESS= Yes
MAKE_FLAGS= CC="${CC}" \
COMMON_LDFLAGS="-L${LOCALBASE}/lib" \
CFLAGS="${CFLAGS} -I${MODLUA_INCL_DIR} -I${LOCALBASE}/include/mysql \
-I${LOCALBASE}/include/postgresql/ -I${LOCALBASE}/include/postgresql/server \
-I. -fpic -shared"
WRKDIST= ${WRKDIR}
do-install:
${INSTALL_DATA_DIR} ${MODLUA_LIBDIR} ${MODLUA_DATADIR}
${INSTALL_DATA} ${WRKSRC}/DBI.lua ${MODLUA_DATADIR}
# XXX: Not using INSTALL_PROGRAM, it strips the library.
${INSTALL_SCRIPT} ${WRKSRC}/*.so ${MODLUA_LIBDIR}
.include <bsd.port.mk>

View File

@ -0,0 +1,2 @@
SHA256 (luadbi.0.5.tar.gz) = SRFkWN2ABSU2v11+KyofWg+kKmcc538ctzVe9/rrMx4=
SIZE (luadbi.0.5.tar.gz) = 22454

View File

@ -0,0 +1,111 @@
$OpenBSD: patch-dbd_sqlite3_connection_c,v 1.1.1.1 2012/08/16 15:21:30 jasper Exp $
Fix DBD.SQLite3 transaction handling
From upstream svn rev 75
--- dbd/sqlite3/connection.c.orig Sat May 1 06:25:12 2010
+++ dbd/sqlite3/connection.c Sun Jul 22 22:23:54 2012
@@ -9,20 +9,37 @@ static int run(connection_t *conn, const char *command
}
static int commit(connection_t *conn) {
- return run(conn, "COMMIT");
+ conn->txn_in_progress = 0;
+ return run(conn, "COMMIT TRANSACTION");
}
static int begin(connection_t *conn) {
- return run(conn, "BEGIN");
-}
+ int err = 0;
+ if (conn->txn_in_progress) {
+ err = 0;
+ } else {
+ conn->txn_in_progress = 1;
+ err = run(conn, "BEGIN TRANSACTION");
+ }
+ return err;
+}
+
static int rollback(connection_t *conn) {
- return run(conn, "ROLLBACK");
+ conn->txn_in_progress = 0;
+ return run(conn, "ROLLBACK TRANSACTION");
}
+int try_begin_transaction(connection_t *conn) {
+ if (conn->autocommit) {
+ return 1;
+ }
+ return begin(conn) == 0;
+}
+
/*
* connection,err = DBD.SQLite3.New(dbfile)
*/
@@ -50,7 +67,7 @@ static int connection_new(lua_State *L) {
}
conn->autocommit = 0;
- begin(conn);
+ conn->txn_in_progress = 0;
luaL_getmetatable(L, DBD_SQLITE_CONNECTION);
lua_setmetatable(L, -2);
@@ -67,10 +84,13 @@ static int connection_autocommit(lua_State *L) {
int err = 1;
if (conn->sqlite) {
- if (on)
+ if (on) {
err = rollback(conn);
+ }
+ /*
else
err = begin(conn);
+ */
conn->autocommit = on;
}
@@ -88,6 +108,7 @@ static int connection_close(lua_State *L) {
int disconnect = 0;
if (conn->sqlite) {
+ rollback(conn);
sqlite3_close(conn->sqlite);
disconnect = 1;
conn->sqlite = NULL;
@@ -105,12 +126,7 @@ static int connection_commit(lua_State *L) {
int err = 1;
if (conn->sqlite) {
- commit(conn);
-
- if (!conn->autocommit)
- err = begin(conn);
- else
- err = 1;
+ err = commit(conn);
}
lua_pushboolean(L, !err);
@@ -176,12 +192,14 @@ static int connection_rollback(lua_State *L) {
int err = 1;
if (conn->sqlite) {
- rollback(conn);
+ err =rollback(conn);
+ /*
if (!conn->autocommit)
err = begin(conn);
else
err = 1;
+ */
}
lua_pushboolean(L, !err);

View File

@ -0,0 +1,24 @@
$OpenBSD: patch-dbd_sqlite3_dbd_sqlite3_h,v 1.1.1.1 2012/08/16 15:21:30 jasper Exp $
Fix DBD.SQLite3 transaction handling
From upstream svn rev 75
--- dbd/sqlite3/dbd_sqlite3.h.orig Fri Dec 19 07:33:32 2008
+++ dbd/sqlite3/dbd_sqlite3.h Sun Jul 22 22:23:54 2012
@@ -10,14 +10,15 @@
typedef struct _connection {
sqlite3 *sqlite;
int autocommit;
+ int txn_in_progress;
} connection_t;
/*
* statement object
*/
typedef struct _statement {
+ connection_t *conn;
sqlite3_stmt *stmt;
- sqlite3 *sqlite;
int more_data;
int affected;
} statement_t;

View File

@ -0,0 +1,81 @@
$OpenBSD: patch-dbd_sqlite3_statement_c,v 1.1.1.1 2012/08/16 15:21:30 jasper Exp $
Fix DBD.SQLite3 transaction handling
From upstream svn rev 75
--- dbd/sqlite3/statement.c.orig Sat May 1 06:25:12 2010
+++ dbd/sqlite3/statement.c Sun Jul 22 22:23:54 2012
@@ -1,5 +1,8 @@
#include "dbd_sqlite3.h"
+extern int try_begin_transaction(connection_t *conn);
+extern int try_end_transaction(connection_t *conn);
+
/*
* Converts SQLite types to Lua types
*/
@@ -128,10 +131,12 @@ static int statement_execute(lua_State *L) {
*/
if (sqlite3_reset(statement->stmt) != SQLITE_OK) {
lua_pushboolean(L, 0);
- lua_pushfstring(L, DBI_ERR_EXECUTE_FAILED, sqlite3_errmsg(statement->sqlite));
+ lua_pushfstring(L, DBI_ERR_EXECUTE_FAILED, sqlite3_errmsg(statement->conn->sqlite));
return 2;
}
+ sqlite3_clear_bindings(statement->stmt);
+
expected_params = sqlite3_bind_parameter_count(statement->stmt);
if (expected_params != num_bind_params) {
/*
@@ -180,18 +185,20 @@ static int statement_execute(lua_State *L) {
if (errstr)
lua_pushfstring(L, DBI_ERR_BINDING_PARAMS, errstr);
else
- lua_pushfstring(L, DBI_ERR_BINDING_PARAMS, sqlite3_errmsg(statement->sqlite));
+ lua_pushfstring(L, DBI_ERR_BINDING_PARAMS, sqlite3_errmsg(statement->conn->sqlite));
return 2;
}
+
+ try_begin_transaction(statement->conn);
if (!step(statement)) {
lua_pushboolean(L, 0);
- lua_pushfstring(L, DBI_ERR_EXECUTE_FAILED, sqlite3_errmsg(statement->sqlite));
+ lua_pushfstring(L, DBI_ERR_EXECUTE_FAILED, sqlite3_errmsg(statement->conn->sqlite));
return 2;
}
- statement->affected = sqlite3_changes(statement->sqlite);
+ statement->affected = sqlite3_changes(statement->conn->sqlite);
lua_pushboolean(L, 1);
return 1;
@@ -283,7 +290,7 @@ static int statement_fetch_impl(lua_State *L, statemen
/*
* reset needs to be called to retrieve the 'real' error message
*/
- luaL_error(L, DBI_ERR_FETCH_FAILED, sqlite3_errmsg(statement->sqlite));
+ luaL_error(L, DBI_ERR_FETCH_FAILED, sqlite3_errmsg(statement->conn->sqlite));
}
}
@@ -357,14 +364,14 @@ int dbd_sqlite3_statement_create(lua_State *L, connect
statement_t *statement = NULL;
statement = (statement_t *)lua_newuserdata(L, sizeof(statement_t));
- statement->sqlite = conn->sqlite;
+ statement->conn = conn;
statement->stmt = NULL;
statement->more_data = 0;
statement->affected = 0;
- if (sqlite3_prepare_v2(statement->sqlite, sql_query, strlen(sql_query), &statement->stmt, NULL) != SQLITE_OK) {
+ if (sqlite3_prepare_v2(statement->conn->sqlite, sql_query, strlen(sql_query), &statement->stmt, NULL) != SQLITE_OK) {
lua_pushnil(L);
- lua_pushfstring(L, DBI_ERR_PREP_STATEMENT, sqlite3_errmsg(statement->sqlite));
+ lua_pushfstring(L, DBI_ERR_PREP_STATEMENT, sqlite3_errmsg(statement->conn->sqlite));
return 2;
}

View File

@ -0,0 +1,4 @@
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.

View File

@ -0,0 +1 @@
MySQL driver for luadbi.

View File

@ -0,0 +1 @@
PostgreSQL driver for luadbi.

View File

@ -0,0 +1,3 @@
@comment $OpenBSD: PLIST-main,v 1.1.1.1 2012/08/16 15:21:30 jasper Exp $
lib/lua/${MODLUA_VERSION}/dbdsqlite3.so
share/lua/${MODLUA_VERSION}/DBI.lua

View File

@ -0,0 +1,2 @@
@comment $OpenBSD: PLIST-mysql,v 1.1.1.1 2012/08/16 15:21:30 jasper Exp $
lib/lua/${MODLUA_VERSION}/dbdmysql.so

View File

@ -0,0 +1,2 @@
@comment $OpenBSD: PLIST-pgsql,v 1.1.1.1 2012/08/16 15:21:30 jasper Exp $
lib/lua/${MODLUA_VERSION}/dbdpostgresql.so