Module Name:    src
Committed By:   mbalmer
Date:           Sun Oct 27 12:38:08 UTC 2013

Modified Files:
        src/lib/lua/sqlite: sqlite.c

Log Message:
More user friendly sqlite.open() function.
Add a few more symbols.
Register all function in the sqlite table.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/lua/sqlite/sqlite.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/lua/sqlite/sqlite.c
diff -u src/lib/lua/sqlite/sqlite.c:1.5 src/lib/lua/sqlite/sqlite.c:1.6
--- src/lib/lua/sqlite/sqlite.c:1.5	Fri Nov  2 12:24:52 2012
+++ src/lib/lua/sqlite/sqlite.c	Sun Oct 27 12:38:08 2013
@@ -1,7 +1,7 @@
-/*	$NetBSD: sqlite.c,v 1.5 2012/11/02 12:24:52 mbalmer Exp $ */
+/*	$NetBSD: sqlite.c,v 1.6 2013/10/27 12:38:08 mbalmer Exp $ */
 
 /*
- * Copyright (c) 2011 Marc Balmer <[email protected]>
+ * Copyright (c) 2011, 2013 Marc Balmer <[email protected]>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -81,11 +81,14 @@ sqlite_open(lua_State *L)
 	sqlite3 **db;
 
 	db = lua_newuserdata(L, sizeof(sqlite3 *));
-	lua_pushinteger(L, sqlite3_open_v2(luaL_checkstring(L, -3), db,
-	    (int)luaL_checkinteger(L, -2), NULL));
-
 	luaL_getmetatable(L, SQLITE_DB_METATABLE);
-	lua_setmetatable(L, -3);
+	lua_setmetatable(L, -2);
+
+	if (lua_gettop(L) > 2)
+		lua_pushinteger(L, sqlite3_open_v2(luaL_checkstring(L, -3), db,
+		    (int)luaL_checkinteger(L, -2), NULL));
+	else
+		lua_pushinteger(L, sqlite3_open(luaL_checkstring(L, -2), db));
 	return 2;
 
 }
@@ -362,8 +365,10 @@ static const struct constant sqlite_cons
 	{ "INTERRUPT",		SQLITE_INTERRUPT },
 	{ "IOERR",		SQLITE_IOERR },
 	{ "CORRUPT",		SQLITE_CORRUPT },
+	{ "NOTFOUND",		SQLITE_NOTFOUND },
 	{ "FULL",		SQLITE_FULL },
 	{ "CANTOPEN",		SQLITE_CANTOPEN },
+	{ "PROTOCOL",		SQLITE_PROTOCOL },
 	{ "EMPTY",		SQLITE_EMPTY },
 	{ "SCHEMA",		SQLITE_SCHEMA },
 	{ "TOOBIG",		SQLITE_TOOBIG },
@@ -375,14 +380,13 @@ static const struct constant sqlite_cons
 	{ "FORMAT",		SQLITE_FORMAT },
 	{ "RANGE",		SQLITE_RANGE },
 	{ "NOTADB",		SQLITE_NOTADB },
-
 	{ "ROW",		SQLITE_ROW },
 	{ "DONE",		SQLITE_DONE },
 
 	/* File modes */
 	{ "OPEN_READONLY",	SQLITE_OPEN_READONLY },
 	{ "OPEN_READWRITE",	SQLITE_OPEN_READWRITE },
-	{ "OPEN_CREATE",	SQLITE_OPEN_CREATE },
+	{ "OPEN_CREATE",	SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE },
 
 	{ NULL,			0 }
 };
@@ -391,14 +395,14 @@ static void
 gpio_set_info(lua_State *L)
 {
 	lua_pushliteral(L, "_COPYRIGHT");
-	lua_pushliteral(L, "Copyright (C) 2011, 2012 by "
+	lua_pushliteral(L, "Copyright (C) 2011, 2012, 2013 by "
 	    "Marc Balmer <[email protected]>");
 	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.2");
+	lua_pushliteral(L, "sqlite 1.0.3");
 	lua_settable(L, -3);
 }
 
@@ -443,6 +447,8 @@ luaopen_sqlite(lua_State* L)
 	sqlite3_initialize();
 
 	luaL_register(L, "sqlite", sqlite_methods);
+	luaL_register(L, NULL, db_methods);
+	luaL_register(L, NULL, stmt_methods);
 	gpio_set_info(L);
 
 	/* The database connection metatable */

Reply via email to