From 6973062b94aa251169f6d69cc68ae6a3387700c7 Mon Sep 17 00:00:00 2001 From: jasper Date: Thu, 16 Aug 2012 15:21:30 +0000 Subject: [PATCH] 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@ --- databases/luadbi/Makefile | 62 ++++++++++ databases/luadbi/distinfo | 2 + .../patches/patch-dbd_sqlite3_connection_c | 111 ++++++++++++++++++ .../patches/patch-dbd_sqlite3_dbd_sqlite3_h | 24 ++++ .../patches/patch-dbd_sqlite3_statement_c | 81 +++++++++++++ databases/luadbi/pkg/DESCR-main | 4 + databases/luadbi/pkg/DESCR-mysql | 1 + databases/luadbi/pkg/DESCR-pgsql | 1 + databases/luadbi/pkg/PLIST-main | 3 + databases/luadbi/pkg/PLIST-mysql | 2 + databases/luadbi/pkg/PLIST-pgsql | 2 + 11 files changed, 293 insertions(+) create mode 100644 databases/luadbi/Makefile create mode 100644 databases/luadbi/distinfo create mode 100644 databases/luadbi/patches/patch-dbd_sqlite3_connection_c create mode 100644 databases/luadbi/patches/patch-dbd_sqlite3_dbd_sqlite3_h create mode 100644 databases/luadbi/patches/patch-dbd_sqlite3_statement_c create mode 100644 databases/luadbi/pkg/DESCR-main create mode 100644 databases/luadbi/pkg/DESCR-mysql create mode 100644 databases/luadbi/pkg/DESCR-pgsql create mode 100644 databases/luadbi/pkg/PLIST-main create mode 100644 databases/luadbi/pkg/PLIST-mysql create mode 100644 databases/luadbi/pkg/PLIST-pgsql diff --git a/databases/luadbi/Makefile b/databases/luadbi/Makefile new file mode 100644 index 00000000000..6c3d30b6d2e --- /dev/null +++ b/databases/luadbi/Makefile @@ -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 diff --git a/databases/luadbi/distinfo b/databases/luadbi/distinfo new file mode 100644 index 00000000000..cf9ca345ba2 --- /dev/null +++ b/databases/luadbi/distinfo @@ -0,0 +1,2 @@ +SHA256 (luadbi.0.5.tar.gz) = SRFkWN2ABSU2v11+KyofWg+kKmcc538ctzVe9/rrMx4= +SIZE (luadbi.0.5.tar.gz) = 22454 diff --git a/databases/luadbi/patches/patch-dbd_sqlite3_connection_c b/databases/luadbi/patches/patch-dbd_sqlite3_connection_c new file mode 100644 index 00000000000..ebf67eee151 --- /dev/null +++ b/databases/luadbi/patches/patch-dbd_sqlite3_connection_c @@ -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); diff --git a/databases/luadbi/patches/patch-dbd_sqlite3_dbd_sqlite3_h b/databases/luadbi/patches/patch-dbd_sqlite3_dbd_sqlite3_h new file mode 100644 index 00000000000..de7ce0e6f51 --- /dev/null +++ b/databases/luadbi/patches/patch-dbd_sqlite3_dbd_sqlite3_h @@ -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; diff --git a/databases/luadbi/patches/patch-dbd_sqlite3_statement_c b/databases/luadbi/patches/patch-dbd_sqlite3_statement_c new file mode 100644 index 00000000000..3628605ace1 --- /dev/null +++ b/databases/luadbi/patches/patch-dbd_sqlite3_statement_c @@ -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; + } + diff --git a/databases/luadbi/pkg/DESCR-main b/databases/luadbi/pkg/DESCR-main new file mode 100644 index 00000000000..b5f993f1c66 --- /dev/null +++ b/databases/luadbi/pkg/DESCR-main @@ -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. diff --git a/databases/luadbi/pkg/DESCR-mysql b/databases/luadbi/pkg/DESCR-mysql new file mode 100644 index 00000000000..da9bc0389fd --- /dev/null +++ b/databases/luadbi/pkg/DESCR-mysql @@ -0,0 +1 @@ +MySQL driver for luadbi. diff --git a/databases/luadbi/pkg/DESCR-pgsql b/databases/luadbi/pkg/DESCR-pgsql new file mode 100644 index 00000000000..bdee9a3475f --- /dev/null +++ b/databases/luadbi/pkg/DESCR-pgsql @@ -0,0 +1 @@ +PostgreSQL driver for luadbi. diff --git a/databases/luadbi/pkg/PLIST-main b/databases/luadbi/pkg/PLIST-main new file mode 100644 index 00000000000..fff5adb3772 --- /dev/null +++ b/databases/luadbi/pkg/PLIST-main @@ -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 diff --git a/databases/luadbi/pkg/PLIST-mysql b/databases/luadbi/pkg/PLIST-mysql new file mode 100644 index 00000000000..79a79770e9f --- /dev/null +++ b/databases/luadbi/pkg/PLIST-mysql @@ -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 diff --git a/databases/luadbi/pkg/PLIST-pgsql b/databases/luadbi/pkg/PLIST-pgsql new file mode 100644 index 00000000000..dd3626a4a31 --- /dev/null +++ b/databases/luadbi/pkg/PLIST-pgsql @@ -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