コード例 #1
0
ファイル: core.c プロジェクト: ra-kalai/lem-sqlite3
static int
db_prepare(lua_State *T)
{
	struct db *db;
	const char *sql;
	size_t len;

	luaL_checktype(T, 1, LUA_TUSERDATA);
	sql = luaL_checklstring(T, 2, &len);

	db = db_unbox(T, 1);
	if (db == NULL)
		return db_closed(T);
	if (db->T != NULL)
		return db_busy(T);

	db->T = T;
	db->refs++;
	db->req.prep.sql = sql;
	db->req.prep.len = len+1;
	lem_async_do(&db->a, db_prepare_work, db_prepare_reap);

	lua_settop(T, 2);
	lua_pushvalue(T, lua_upvalueindex(1));
	return lua_yield(T, 3);
}
コード例 #2
0
ファイル: core.c プロジェクト: ra-kalai/lem-sqlite3
static int
db_exec(lua_State *T)
{
	struct db *db;
	const char *sql;
	size_t len;
	unsigned int bind;

	luaL_checktype(T, 1, LUA_TUSERDATA);
	sql = luaL_checklstring(T, 2, &len);
	bind = lua_gettop(T) > 2;
	if (bind) {
		luaL_checktype(T, 3, LUA_TTABLE);
		lua_settop(T, 3);
		lua_replace(T, 2);
	}

	db = db_unbox(T, 1);
	if (db == NULL)
		return db_closed(T);
	if (db->T != NULL)
		return db_busy(T);

	db->T = T;
	db->req.prep.sql = sql;
	db->req.prep.len = len+1;
	lem_async_do(&db->a, db_prepare_work, db_exec_prepare_reap);

	return lua_yield(T, bind ? 2 : 1);
}
コード例 #3
0
ファイル: core.c プロジェクト: ra-kalai/lem-sqlite3
static int
db_autocommit(lua_State *T)
{
	struct db *db;

	luaL_checktype(T, 1, LUA_TUSERDATA);
	db = db_unbox(T, 1);
	if (db == NULL)
		return db_closed(T);
	if (db->T != NULL)
		return db_busy(T);

	lua_pushboolean(T, sqlite3_get_autocommit(db->handle));
	return 1;
}
コード例 #4
0
ファイル: core.c プロジェクト: ra-kalai/lem-sqlite3
static int
db_changes(lua_State *T)
{
	struct db *db;

	luaL_checktype(T, 1, LUA_TUSERDATA);
	db = db_unbox(T, 1);
	if (db == NULL)
		return db_closed(T);
	if (db->T != NULL)
		return db_busy(T);

	lua_pushinteger(T, sqlite3_changes(db->handle));
	return 1;
}
コード例 #5
0
ファイル: core.c プロジェクト: esmil/lem-sqlite3
static int
db_last_insert_rowid(lua_State *T)
{
	struct db *db;

	luaL_checktype(T, 1, LUA_TUSERDATA);
	db = db_unbox(T, 1);
	if (db == NULL)
		return db_closed(T);
	if (db->T != NULL)
		return db_busy(T);

	lua_pushnumber(T, sqlite3_last_insert_rowid(db->handle));
	return 1;
}