예제 #1
0
파일: db.c 프로젝트: BPotato/fluffos
void f_db_close (void)
{
	int ret = 0;
	db_t *db;

	valid_database("close", &the_null_array);

	db = find_db_conn(sp->u.number);
	if (!db) {
		error("Attempt to close an invalid database handle\n");
	}

	/* Cleanup any memory structures left around */
	if (db->type->cleanup) {
		db->type->cleanup(&(db->c));
	}

	if (db->type->close) {
		ret = db->type->close(&(db->c));
	}

	/* Remove the entry from the linked list */
	free_db_conn(db);

	sp->u.number = ret;
}
예제 #2
0
파일: db.c 프로젝트: BPotato/fluffos
void f_db_fetch (void)
{
	db_t *db;
	array_t *ret;

	valid_database("fetch", &the_null_array);

	db = find_db_conn((sp-1)->u.number);
	if (!db) {
		error("Attempt to fetch from an invalid database handle\n");
	}

	if (db->type->fetch) {
		ret = db->type->fetch(&(db->c), sp->u.number);
	} else {
		ret = &the_null_array;
	}

	pop_stack();
	if (!ret) {
		if (db->type->error) {
			char *errormsg;

			errormsg = db->type->error(&(db->c));
			put_malloced_string(errormsg);
		} else {
			sp->u.number = 0;
		}
	} else {
		put_array(ret);
	}
}
예제 #3
0
void f_async_db_exec(){
    array_t *info;
    db_t *db;
    info = allocate_empty_array(1);
    info->item[0].type = T_STRING;
    info->item[0].subtype = STRING_MALLOC;
    info->item[0].u.string = string_copy((sp-1)->u.string, "f_db_exec");
    valid_database("exec", info);

    db = find_db_conn((sp-1)->u.number);
    if (!db) {
        error("Attempt to exec on an invalid database handle\n");
    }

    if (db->type->cleanup) {
        db->type->cleanup(&(db->c));
    }

    function_to_call_t *cb = get_cb();
    process_efun_callback(2, cb, F_ASYNC_READ);
    cb->f.fp->hdr.ref++;

    add_db_exec(db, (sp-1)->u.string, cb);
    pop_2_elems();
}
예제 #4
0
파일: async.c 프로젝트: Elohim/FGmud
void f_async_db_exec(){
	array_t *info;
	db_t *db;
	info = allocate_empty_array(1);
	info->item[0].type = T_STRING;
	info->item[0].subtype = STRING_MALLOC;
	info->item[0].u.string = string_copy((sp-1)->u.string, "f_db_exec");
	int num_arg = st_num_arg;
	valid_database("exec", info);

	db = find_db_conn((sp-2)->u.number);
	if (!db) {
		error("Attempt to exec on an invalid database handle\n");
	}
	if(!db_mut){
		db_mut = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t));
		pthread_mutex_init(db_mut, NULL);
	}
	st_num_arg = num_arg;
	function_to_call_t *cb = get_cb();
	process_efun_callback(2, cb, F_ASYNC_DB_EXEC);
	cb->f.fp->hdr.ref++;

	add_db_exec((sp-2)->u.number, cb);
	pop_3_elems();
}
예제 #5
0
파일: db.c 프로젝트: BPotato/fluffos
void f_db_exec (void)
{
	int ret = 0;
	db_t *db;
	array_t *info;
	info = allocate_empty_array(1);
	info->item[0].type = T_STRING;
	info->item[0].subtype = STRING_MALLOC;
	info->item[0].u.string = string_copy(sp->u.string, "f_db_exec");
	valid_database("exec", info);

	db = find_db_conn((sp-1)->u.number);
	if (!db) {
		error("Attempt to exec on an invalid database handle\n");
	}

#ifdef PACKAGE_ASYNC
	if(!db_mut){
		db_mut = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
		pthread_mutex_init(db_mut, NULL);
	}
	pthread_mutex_lock(db_mut);
#endif
	if (db->type->cleanup) {
		db->type->cleanup(&(db->c));
	}

	if (db->type->execute) {
		ret = db->type->execute(&(db->c), sp->u.string);
	}

	pop_stack();
	if (ret == -1) {
		if (db->type->error) {
			char *errormsg;

			errormsg = db->type->error(&(db->c));
			put_malloced_string(errormsg);
		} else {
			put_constant_string("Unknown error");
		}
	} else {
		sp->u.number = ret;
	}
#ifdef PACKAGE_ASYNC
	pthread_mutex_unlock(db_mut);
#endif
}
예제 #6
0
파일: db.c 프로젝트: BPotato/fluffos
void f_db_commit (void)
{
	int ret = 0;
	db_t *db;

	valid_database("commit", &the_null_array);

	db = find_db_conn(sp->u.number);
	if (!db) {
		error("Attempt to commit an invalid database handle\n");
	}

	if (db->type->commit) {
		ret = db->type->commit(&(db->c));
	}

	sp->u.number = ret;
}
예제 #7
0
파일: db.c 프로젝트: BPotato/fluffos
void f_db_rollback (void)
{
	int ret = 0;
	db_t *db;

	valid_database("rollback", &the_null_array);

	db = find_db_conn(sp->u.number);
	if (!db) {
		error("Attempt to rollback an invalid database handle\n");
	}

	if (db->type->rollback) {
		ret = db->type->rollback(&(db->c));
	}

	if (ret > 0) {
		if (db->type->cleanup) {
			db->type->cleanup(&(db->c));
		}
	}

	sp->u.number = ret;
}
예제 #8
0
파일: db.c 프로젝트: BPotato/fluffos
void f_db_connect (void)
{
	char *errormsg = 0;
	const char *user = "", *database, *host;
	db_t *db;
	array_t *info;
	svalue_t *mret;
	int handle, ret = 0, args = 0, type;

#ifdef DEFAULT_DB
	type = DEFAULT_DB;
#else
	type = 0;
#endif

	switch (st_num_arg) {
	case 4: type     = (sp - (args++))->u.number;
	case 3: user     = (sp - (args++))->u.string;
	case 2: database = (sp - (args++))->u.string;
	case 1: host     = (sp - (args++))->u.string;
	}

	info = allocate_empty_array(3);
	info->item[0].type = info->item[1].type = info->item[2].type = T_STRING;
	info->item[0].subtype = info->item[1].subtype = info->item[2].subtype = STRING_MALLOC;
	info->item[0].u.string = string_copy(database, "f_db_connect:1");
	if (*host)
		info->item[1].u.string = string_copy(host, "f_db_connect:2");
	else
		info->item[1] = const0;
	info->item[2].u.string = string_copy(user, "f_db_connect:3");

	mret = valid_database("connect", info);

	handle = create_db_conn();
	if (!handle) {
		pop_n_elems(args);
		push_number(0);
		return;
	}
	db = find_db_conn(handle);

	switch (type) {
	default:
		/* fallthrough */
#ifdef USE_MSQL
#if USE_MSQL - 0
	case USE_MSQL:
#endif
		db->type = &msql;
		break;
#endif
#ifdef USE_MYSQL
#if USE_MYSQL - 0
	case USE_MYSQL:
#endif
		db->type = &mysql;
		break;
#endif
#ifdef USE_SQLITE2
#if USE_SQLITE2 - 0
	case USE_SQLITE2:
#endif
		db->type = &SQLite2;
		break;
#endif
#ifdef USE_SQLITE3
#if USE_SQLITE3 - 0
	case USE_SQLITE3:
#endif
		db->type = &SQLite3;
		break;
#endif
#ifdef USE_POSTGRES
#if USE_POSTGRES - 0
	case USE_POSTGRES:
#endif
		db->type = &postgres;
		break;
#endif
	}

	if (db->type->connect) {
		ret = db->type->connect(&(db->c), host, database, user,
				(mret != (svalue_t *)-1 && mret->type == T_STRING ? mret->u.string : 0));
	}

	pop_n_elems(args);

	if (!ret) {
		if (db->type->error) {
			errormsg = db->type->error(&(db->c));
			push_malloced_string(errormsg);
		} else {
			push_number(0);
		}
		free_db_conn(db);
	} else {
		push_number(handle);
	}
}