From e98f41ae8382a98915cbabdb1e4f331bc2438bd2 Mon Sep 17 00:00:00 2001 From: mbalmer Date: Fri, 2 Nov 2012 12:24:52 +0000 Subject: [PATCH] - Update to the version on github.com. - Fix stmt_bind(): SQLite makes a copy of the string passed (which can be garbage collected). Problem found by Kubo Takehiro. --- lib/lua/sqlite/sqlite.c | 55 +++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/lib/lua/sqlite/sqlite.c b/lib/lua/sqlite/sqlite.c index 3d1f7b056ab0..f533a2dd4e62 100644 --- a/lib/lua/sqlite/sqlite.c +++ b/lib/lua/sqlite/sqlite.c @@ -1,4 +1,4 @@ -/* $NetBSD: sqlite.c,v 1.4 2012/03/15 02:02:21 joerg Exp $ */ +/* $NetBSD: sqlite.c,v 1.5 2012/11/02 12:24:52 mbalmer Exp $ */ /* * Copyright (c) 2011 Marc Balmer @@ -207,7 +207,7 @@ stmt_bind(lua_State *L) break; case LUA_TSTRING: lua_pushinteger(L, sqlite3_bind_text(*stmt, pidx, - lua_tostring(L, 3), -1, NULL)); + lua_tostring(L, 3), -1, SQLITE_TRANSIENT)); break; case LUA_TNIL: lua_pushinteger(L, sqlite3_bind_null(*stmt, pidx)); @@ -391,13 +391,14 @@ static void gpio_set_info(lua_State *L) { lua_pushliteral(L, "_COPYRIGHT"); - lua_pushliteral(L, "Copyright (C) 2011 Marc Balmer "); + lua_pushliteral(L, "Copyright (C) 2011, 2012 by " + "Marc Balmer "); lua_settable(L, -3); lua_pushliteral(L, "_DESCRIPTION"); lua_pushliteral(L, "SQLite interface for Lua"); lua_settable(L, -3); lua_pushliteral(L, "_VERSION"); - lua_pushliteral(L, "sqlite 1.0.0"); + lua_pushliteral(L, "sqlite 1.0.2"); lua_settable(L, -3); } @@ -405,36 +406,36 @@ int luaopen_sqlite(lua_State* L) { static const struct luaL_Reg sqlite_methods[] = { - { "initialize", sqlite_initialize }, - { "shutdown", sqlite_shutdown }, - { "open", sqlite_open }, - { "libversion", sqlite_libversion }, - { "libversion_number", sqlite_libversion_number }, - { "sourceid", sqlite_sourceid }, - { NULL, NULL } + { "initialize", sqlite_initialize }, + { "shutdown", sqlite_shutdown }, + { "open", sqlite_open }, + { "libversion", sqlite_libversion }, + { "libversion_number", sqlite_libversion_number }, + { "sourceid", sqlite_sourceid }, + { NULL, NULL } }; static const struct luaL_Reg db_methods[] = { - { "close", db_close }, - { "prepare", db_prepare }, - { "exec", db_exec }, - { "errcode", db_errcode }, - { "errmsg", db_errmsg }, - { "get_autocommit", db_get_autocommit }, - { "changes", db_changes }, - { NULL, NULL } + { "close", db_close }, + { "prepare", db_prepare }, + { "exec", db_exec }, + { "errcode", db_errcode }, + { "errmsg", db_errmsg }, + { "get_autocommit", db_get_autocommit }, + { "changes", db_changes }, + { NULL, NULL } }; static const struct luaL_Reg stmt_methods[] = { - { "bind", stmt_bind }, + { "bind", stmt_bind }, { "bind_parameter_count", stmt_bind_parameter_count }, { "bind_parameter_index", stmt_bind_parameter_index }, { "bind_parameter_name", stmt_bind_parameter_name }, - { "step", stmt_step }, - { "column", stmt_column }, - { "reset", stmt_reset }, - { "clear_bindings", stmt_clear_bindings }, - { "finalize", stmt_finalize }, - { "column_name", stmt_column_name }, - { "column_count", stmt_column_count }, + { "step", stmt_step }, + { "column", stmt_column }, + { "reset", stmt_reset }, + { "clear_bindings", stmt_clear_bindings }, + { "finalize", stmt_finalize }, + { "column_name", stmt_column_name }, + { "column_count", stmt_column_count }, { NULL, NULL } }; int n;