Exemplo n.º 1
0
static void
db_open_reap(struct lem_async *a)
{
	struct db *db = (struct db *)a;
	lua_State *T = db->T;
	int ret;

	if (db->handle == NULL) {
		lem_debug("db->handle == NULL");
		lua_pushnil(T);
		lua_pushliteral(T, "out of memory");
		db_unref(db);
		ret = 2;
	} else if (db->ret != SQLITE_OK) {
		lem_debug("db->ret != SQLITE_OK");
		lua_pushnil(T);
		lua_pushstring(T, sqlite3_errmsg(db->handle));
		db_unref(db);
		ret = 2;
	} else {
		struct box *box = lua_newuserdata(T, sizeof(struct box));

		lem_debug("Success!");
		box->db = db;

		/* set metatable */
		lua_pushvalue(T, 2);
		lua_setmetatable(T, -2);

		ret = 1;
	}

	lem_queue(T, ret);
	db->T = NULL;
}
Exemplo n.º 2
0
static int
stmt_finalize(lua_State *T)
{
	struct stmt *stmt;
	struct db *db;
	int ret;

	luaL_checktype(T, 1, LUA_TUSERDATA);
	stmt = lua_touserdata(T, 1);
	if (stmt->handle == NULL)
		return stmt_finalized(T);
	db = stmt->db;
	if (db->T != NULL)
		return db_busy(T);

	if (sqlite3_finalize(stmt->handle) == SQLITE_OK) {
		lua_pushboolean(T, 1);
		ret = 1;
	} else {
		lua_pushnil(T);
		lua_pushstring(T, sqlite3_errmsg(db->handle));
		ret = 2;
	}

	stmt->handle = NULL;
	db_unref(db);
	return ret;
}
Exemplo n.º 3
0
/*
 * Closes the database
 */
VALUE
rpm_db_close(VALUE db)
{
	db_unref((rpm_db_t*)DATA_PTR(db));
	DATA_PTR(db) = NULL;
    rb_gc();
    return Qnil;
}
Exemplo n.º 4
0
static void
mi_free(rpm_mi_t* mi)
{
	rpmdbFreeIterator(mi->mi);
#if RPM_VERSION_CODE < RPM_VERSION(4,9,0) || RPM_VERSION_CODE >= RPM_VERSION(5,0,0)
	db_unref(mi->db);
#endif
	free(mi);
}
Exemplo n.º 5
0
static void
db_prepare_reap(struct lem_async *a)
{
	struct db *db = (struct db *)a;
	lua_State *T = db->T;
	int ret;

	if (db->ret != SQLITE_OK) {
		lem_debug("db->ret != SQLITE_OK");
		lua_pushnil(T);
		lua_pushstring(T, sqlite3_errmsg(db->handle));
		ret = 2;
		db_unref(db);
	} else if (db->req.prep.stmt == NULL) {
		lem_debug("db->req.prep.stmt == NULL");
		lua_pushnil(T);
		lua_pushliteral(T, "nosql");
		ret = 2;
		db_unref(db);
	} else {
		struct stmt *stmt = lua_newuserdata(T, sizeof(struct stmt));

		lem_debug("Success!");
		stmt->handle = db->req.prep.stmt;
		stmt->db = db;

		/* set metatable */
		lua_pushvalue(T, 3);
		lua_setmetatable(T, -2);

		ret = 1;
	}

	lem_queue(T, ret);
	db->T = NULL;
}
Exemplo n.º 6
0
static void
transaction_free(rpm_trans_t* trans)
{
	if (trans->script_fd)
		Fclose(trans->script_fd);
#if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
	rpmtransFree(trans->ts);
#else
	rpmtsFree(trans->ts);
#endif
#if RPM_VERSION_CODE < RPM_VERSION(4,9,0) || RPM_VERSION_CODE >= RPM_VERSION(5,0,0)
	db_unref(trans->db);
#endif
	free(trans);
}
Exemplo n.º 7
0
static int
db_close(lua_State *T)
{
	struct box *box;
	struct db *db;

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

	db_unref(db);
	box->db = NULL;

	lua_pushboolean(T, 1);
	return 1;
}
Exemplo n.º 8
0
static void
db_free(rpm_db_t* db)
{
	if (db)
		db_unref(db);
}