Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/lua/sqlite More user friendly sqlite.open() function.
details: https://anonhg.NetBSD.org/src/rev/aa32fe2a8314
branches: trunk
changeset: 790940:aa32fe2a8314
user: mbalmer <mbalmer%NetBSD.org@localhost>
date: Sun Oct 27 12:38:08 2013 +0000
description:
More user friendly sqlite.open() function.
Add a few more symbols.
Register all function in the sqlite table.
diffstat:
lib/lua/sqlite/sqlite.c | 26 ++++++++++++++++----------
1 files changed, 16 insertions(+), 10 deletions(-)
diffs (85 lines):
diff -r bace806344bd -r aa32fe2a8314 lib/lua/sqlite/sqlite.c
--- a/lib/lua/sqlite/sqlite.c Sun Oct 27 11:56:18 2013 +0000
+++ b/lib/lua/sqlite/sqlite.c Sun Oct 27 12:38:08 2013 +0000
@@ -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 <marc%msys.ch@localhost>
+ * Copyright (c) 2011, 2013 Marc Balmer <marc%msys.ch@localhost>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -81,11 +81,14 @@
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, -2);
- luaL_getmetatable(L, SQLITE_DB_METATABLE);
- lua_setmetatable(L, -3);
+ 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 @@
{ "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 @@
{ "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 @@
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 <marc%msys.ch@localhost>");
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 @@
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 */
Home |
Main Index |
Thread Index |
Old Index