コード例 #1
0
ファイル: bdb_cmd.c プロジェクト: adubovikov/kamailio
int bdb_cmd(db_cmd_t *cmd)
{
	bdb_cmd_t *bcmd;
	db_con_t *con;
	bdb_con_t *bcon;

	bcmd = (bdb_cmd_t *)pkg_malloc(sizeof(bdb_cmd_t));
	if(bcmd == NULL) {
		ERR("bdb: No memory left\n");
		goto error;
	}
	memset(bcmd, '\0', sizeof(bdb_cmd_t));
	if(db_drv_init(&bcmd->gen, bdb_cmd_free) < 0)
		goto error;

	con = cmd->ctx->con[db_payload_idx];
	bcon = DB_GET_PAYLOAD(con);
	bcmd->bcon = bcon;

	switch(cmd->type) {
		case DB_PUT:
		case DB_DEL:
		case DB_UPD:
			ERR("bdb: The driver does not support DB modifications yet.\n");
			goto error;
			break;

		case DB_GET:
			if(bdb_prepare_query(cmd, bcmd) != 0) {
				ERR("bdb: error preparing query.\n");
				goto error;
			}
			break;

		case DB_SQL:
			ERR("bdb: The driver does not support raw queries yet.\n");
			goto error;
	}

	DB_SET_PAYLOAD(cmd, bcmd);
	return 0;

error:
	if(bcmd) {
		DB_SET_PAYLOAD(cmd, NULL);
		db_drv_free(&bcmd->gen);
		pkg_free(bcmd);
	}
	return -1;
}
コード例 #2
0
int erlang_srdb2_con(db_con_t* con) {
	LM_DBG("erlang_srdb2_con %p\n",con);
	DB_SET_PAYLOAD(con, NULL);
	con->connect = erlang_srdb2_con_connect;
	con->disconnect = erlang_srdb2_con_disconnect;
	return 0;
};
コード例 #3
0
int erlang_srdb2_uri(db_uri_t* uri) {
	LM_DBG("erlang_srdb2_uri %p %*s %*s\n",uri, uri->scheme.len,uri->scheme.s,uri->body.len,uri->body.s);
	DB_SET_PAYLOAD(uri, NULL);
	uri->cmp = erlang_srdb2_uri_cmp;
	
	return 0;
};
コード例 #4
0
ファイル: ld_uri.c プロジェクト: BackupTheBerlios/ser
int ld_uri(db_uri_t* uri)
{
	struct ld_uri* luri;

	luri = (struct ld_uri*)pkg_malloc(sizeof(struct ld_uri));
	if (luri == NULL) {
		ERR("ldap: No memory left\n");
		goto error;
	}
	memset(luri, '\0', sizeof(struct ld_uri));
	if (db_drv_init(&luri->drv, ld_uri_free) < 0) goto error;
    if (parse_ldap_uri(luri,  &uri->scheme, &uri->body) < 0) goto error;

	DB_SET_PAYLOAD(uri, luri);
	uri->cmp = ld_uri_cmp;
	return 0;

 error:
	if (luri) {
		if (luri->uri) pkg_free(luri->uri);
		if (luri->ldap_url) ldap_free_urldesc(luri->ldap_url);
		db_drv_free(&luri->drv);
		pkg_free(luri);
	}
	return -1;
}
コード例 #5
0
int flat_uri(db_uri_t* uri)
{
	struct flat_uri* furi;

	if ((furi = (struct flat_uri*)pkg_malloc(sizeof(*furi))) == NULL) {
		ERR("flatstore: No memory left\n");
		return -1;
	}
	memset(furi, '\0', sizeof(*furi));
	if (db_drv_init(&furi->drv, flat_uri_free) < 0) goto error;

	if ((furi->path.s = get_abs_pathname(NULL, &uri->body)) == NULL) {
		ERR("flatstore: Error while obtaining absolute pathname for '%.*s'\n",
			STR_FMT(&uri->body));
		goto error;
	}
	furi->path.len = strlen(furi->path.s);

	DB_SET_PAYLOAD(uri, furi);
	return 0;

 error:
	if (furi) {
		if (furi->path.s) pkg_free(furi->path.s);
		db_drv_free(&furi->drv);
		pkg_free(furi);
	}
	return -1;	
}
コード例 #6
0
ファイル: my_con.c プロジェクト: BackupTheBerlios/ser
int my_con(db_con_t* con)
{
	struct my_con* ptr;
	struct my_uri* uri;

	/* First try to lookup the connection in the connection pool and
	 * re-use it if a match is found
	 */
	ptr = (struct my_con*)db_pool_get(con->uri);
	if (ptr) {
		DBG("mysql: Connection to %.*s:%.*s found in connection pool\n",
			con->uri->scheme.len, ZSW(con->uri->scheme.s),
			con->uri->body.len, ZSW(con->uri->body.s));
		goto found;
	}

	ptr = (struct my_con*)pkg_malloc(sizeof(struct my_con));
	if (!ptr) {
		LOG(L_ERR, "mysql: No memory left\n");
		goto error;
	}
	memset(ptr, '\0', sizeof(struct my_con));
	if (db_pool_entry_init(&ptr->gen, my_con_free, con->uri) < 0) goto error;

	ptr->con = (MYSQL*)pkg_malloc(sizeof(MYSQL));
	if (!ptr->con) {
		LOG(L_ERR, "mysql: No enough memory\n");
		goto error;
	}
	mysql_init(ptr->con);

	uri = DB_GET_PAYLOAD(con->uri);
	DBG("mysql: Creating new connection to: %.*s:%.*s\n",
		con->uri->scheme.len, ZSW(con->uri->scheme.s),
		con->uri->body.len, ZSW(con->uri->body.s));

	/* Put the newly created mysql connection into the pool */
	db_pool_put((struct db_pool_entry*)ptr);
	DBG("mysql: Connection stored in connection pool\n");

 found:
	/* Attach driver payload to the db_con structure and set connect and
	 * disconnect functions
	 */
	DB_SET_PAYLOAD(con, ptr);
	con->connect = my_con_connect;
	con->disconnect = my_con_disconnect;
	return 0;

 error:
	if (ptr) {
		db_pool_entry_free(&ptr->gen);
		if (ptr->con) pkg_free(ptr->con);
		pkg_free(ptr);
	}
	return 0;
}
コード例 #7
0
ファイル: bdb_con.c プロジェクト: 4N7HR4X/kamailio
int bdb_con(db_con_t* con)
{
	bdb_con_t* bcon;
	bdb_uri_t* buri;

	buri = DB_GET_PAYLOAD(con->uri);

	/* First try to lookup the connection in the connection pool and
	 * re-use it if a match is found
	 */
	bcon = (bdb_con_t*)db_pool_get(con->uri);
	if (bcon) {
		DBG("bdb: Connection to %s found in connection pool\n",
			buri->uri);
		goto found;
	}

	bcon = (bdb_con_t*)pkg_malloc(sizeof(bdb_con_t));
	if (!bcon) {
		ERR("bdb: No memory left\n");
		goto error;
	}
	memset(bcon, '\0', sizeof(bdb_con_t));
	if (db_pool_entry_init(&bcon->gen, bdb_con_free, con->uri) < 0) goto error;

	DBG("bdb: Preparing new connection to %s\n", buri->uri);
	if(bdb_is_database(buri->path.s)!=0)
	{	
		ERR("bdb: database [%.*s] does not exists!\n",
				buri->path.len, buri->path.s);
		goto error;
	}

	/* Put the newly created BDB connection into the pool */
	db_pool_put((struct db_pool_entry*)bcon);
	DBG("bdb: Connection stored in connection pool\n");

found:
	/* Attach driver payload to the db_con structure and set connect and
	 * disconnect functions
	 */
	DB_SET_PAYLOAD(con, bcon);
	con->connect = bdb_con_connect;
	con->disconnect = bdb_con_disconnect;
	return 0;

error:
	if (bcon) {
		db_pool_entry_free(&bcon->gen);
		pkg_free(bcon);
	}
	return -1;
}
コード例 #8
0
ファイル: flat_cmd.c プロジェクト: 2pac/kamailio
int flat_cmd(db_cmd_t* cmd)
{
	struct flat_cmd* fcmd;
	db_con_t* con;

	if (cmd->type != DB_PUT) {
		ERR("flatstore: The driver supports PUT operation only.\n");
		return -1;
	}

	if (DB_FLD_EMPTY(cmd->vals)) {
		ERR("flatstore: PUT command with no values encountered\n");
		return -1;
	}

	fcmd = (struct flat_cmd*)pkg_malloc(sizeof(struct flat_cmd));
	if (fcmd == NULL) {
		ERR("flatstore: No memory left\n");
		return -1;
	}
	memset(fcmd, '\0', sizeof(struct flat_cmd));
	if (db_drv_init(&fcmd->gen, flat_cmd_free) < 0) goto error;

	/* FIXME */
	con = cmd->ctx->con[db_payload_idx];
	if (flat_open_table(&fcmd->file_index, con, &cmd->table) < 0) goto error;

	DB_SET_PAYLOAD(cmd, fcmd);
	return 0;

 error:
	if (fcmd) {
		DB_SET_PAYLOAD(cmd, NULL);
		db_drv_free(&fcmd->gen);
		pkg_free(fcmd);
	}
	return -1;
}
コード例 #9
0
ファイル: pg_con.c プロジェクト: GreenfieldTech/kamailio
int pg_con(db_con_t *con)
{
	struct pg_con *pcon;

	/* First try to lookup the connection in the connection pool and
	 * re-use it if a match is found
	 */
	pcon = (struct pg_con *)db_pool_get(con->uri);
	if(pcon) {
		DBG("postgres: Connection to %.*s:%.*s found in connection pool\n",
				con->uri->scheme.len, ZSW(con->uri->scheme.s),
				con->uri->body.len, ZSW(con->uri->body.s));
		goto found;
	}

	pcon = (struct pg_con *)pkg_malloc(sizeof(struct pg_con));
	if(!pcon) {
		LOG(L_ERR, "postgres: No memory left\n");
		goto error;
	}
	memset(pcon, '\0', sizeof(struct pg_con));
	if(db_pool_entry_init(&pcon->gen, pg_con_free, con->uri) < 0)
		goto error;

	DBG("postgres: Preparing new connection to: %.*s:%.*s\n",
			con->uri->scheme.len, ZSW(con->uri->scheme.s), con->uri->body.len,
			ZSW(con->uri->body.s));

	/* Put the newly created postgres connection into the pool */
	db_pool_put((struct db_pool_entry *)pcon);
	DBG("postgres: Connection stored in connection pool\n");

found:
	/* Attach driver payload to the db_con structure and set connect and
	 * disconnect functions
	 */
	DB_SET_PAYLOAD(con, pcon);
	con->connect = pg_con_connect;
	con->disconnect = pg_con_disconnect;
	return 0;

error:
	if(pcon) {
		db_pool_entry_free(&pcon->gen);
		pkg_free(pcon);
	}
	return -1;
}
コード例 #10
0
ファイル: ld_con.c プロジェクト: 2pac/kamailio
int ld_con(db_con_t* con)
{
	struct ld_con* lcon;
	struct ld_uri* luri;

	luri = DB_GET_PAYLOAD(con->uri);

	/* First try to lookup the connection in the connection pool and
	 * re-use it if a match is found
	 */
	lcon = (struct ld_con*)db_pool_get(con->uri);
	if (lcon) {
		DBG("ldap: Connection to %s found in connection pool\n",
			luri->uri);
		goto found;
	}

	lcon = (struct ld_con*)pkg_malloc(sizeof(struct ld_con));
	if (!lcon) {
		ERR("ldap: No memory left\n");
		goto error;
	}
	memset(lcon, '\0', sizeof(struct ld_con));
	if (db_pool_entry_init(&lcon->gen, ld_con_free, con->uri) < 0) goto error;

	DBG("ldap: Preparing new connection to %s\n", luri->uri);

	/* Put the newly created LDAP connection into the pool */
	db_pool_put((struct db_pool_entry*)lcon);
	DBG("ldap: Connection stored in connection pool\n");

 found:
	/* Attach driver payload to the db_con structure and set connect and
	 * disconnect functions
	 */
	DB_SET_PAYLOAD(con, lcon);
	con->connect = ld_con_connect;
	con->disconnect = ld_con_disconnect;
	return 0;

 error:
	if (lcon) {
		db_pool_entry_free(&lcon->gen);
		pkg_free(lcon);
	}
	return -1;
}
コード例 #11
0
ファイル: my_fld.c プロジェクト: AndreyRybkin/kamailio
int my_fld(db_fld_t* fld, char* table)
{
	struct my_fld* res;

	res = (struct my_fld*)pkg_malloc(sizeof(struct my_fld));
	if (res == NULL) {
		ERR("mysql: No memory left\n");
		return -1;
	}
	memset(res, '\0', sizeof(struct my_fld));
	if (db_drv_init(&res->gen, my_fld_free) < 0) goto error;

	DB_SET_PAYLOAD(fld, res);
	return 0;

 error:
	if (res) pkg_free(res);
	return -1;
}
コード例 #12
0
ファイル: bdb_res.c プロジェクト: GreenfieldTech/kamailio
/*
 * Attach bdb specific structure to db_res, this structure contains a pointer
 * to bdb_res_free which releases the result stored in the oracle statement
 * and if there is a cursor open in the statement then it will be closed as well
 */
int bdb_res(db_res_t* res)
{
	bdb_res_t *br;

	br = (bdb_res_t*)pkg_malloc(sizeof(bdb_res_t));
	if (br == NULL) {
		ERR("bdb: No memory left\n");
		return -1;
	}
	if (db_drv_init(&br->gen, bdb_res_free) < 0) goto error;
	DB_SET_PAYLOAD(res, br);
	return 0;
	
error:
	if (br) {
		db_drv_free(&br->gen);
		pkg_free(br);
	}
	return -1;
}
コード例 #13
0
ファイル: bdb_fld.c プロジェクト: SibghatullahSheikh/kamailio
int bdb_fld(db_fld_t* fld, char* table)
{
	bdb_fld_t *res;

	res = (bdb_fld_t*)pkg_malloc(sizeof(bdb_fld_t));
	if (res == NULL) {
		ERR("oracle: No memory left\n");
		return -1;
	}
	memset(res, '\0', sizeof(bdb_fld_t));
	res->col_pos = -1;
	if (db_drv_init(&res->gen, bdb_fld_free) < 0) goto error;

	DB_SET_PAYLOAD(fld, res);
	return 0;

error:
	if (res) pkg_free(res);
	return -1;
}
コード例 #14
0
ファイル: my_res.c プロジェクト: GreenfieldTech/kamailio
/*
 * Attach a mysql specific structure to db_res, this structure contains a pointer
 * to my_res_free which releases the mysql result stored in the mysql statement
 * and if there is a cursor open in the statement then it will be closed as well
 */
int my_res(db_res_t* res)
{
	struct my_res* mr;

	mr = (struct my_res*)pkg_malloc(sizeof(struct my_res));
	if (mr == NULL) {
		ERR("mysql: No memory left\n");
		return -1;
	}
	if (db_drv_init(&mr->gen, my_res_free) < 0) goto error;
	DB_SET_PAYLOAD(res, mr);
	return 0;

error:
	if (mr) {
		db_drv_free(&mr->gen);
		pkg_free(mr);
	}
	return -1;
}
コード例 #15
0
ファイル: ld_res.c プロジェクト: 2pac/kamailio
int ld_res(db_res_t* res)
{
	struct ld_res* lres;

	lres = (struct ld_res*)pkg_malloc(sizeof(struct ld_res));
	if (lres == NULL) {
		ERR("ldap: No memory left\n");
		return -1;
	}
	memset(lres, '\0', sizeof(struct ld_res));
	if (db_drv_init(&lres->gen, ld_res_free) < 0) goto error;
	DB_SET_PAYLOAD(res, lres);
	return 0;
	
 error:
	if (lres) {
		db_drv_free(&lres->gen);
		pkg_free(lres);
	}
	return -1;
}
コード例 #16
0
ファイル: pg_uri.c プロジェクト: 4N7HR4X/kamailio
int pg_uri(db_uri_t* uri)
{
	struct pg_uri* puri;

	puri = (struct pg_uri*)pkg_malloc(sizeof(struct pg_uri));
	if (puri == NULL) {
		ERR("postgres: No memory left\n");
		goto error;
	}
	memset(puri, '\0', sizeof(struct pg_uri));
	if (db_drv_init(&puri->drv, pg_uri_free) < 0) goto error;
	if (parse_postgres_uri(puri, &uri->body) < 0) goto error;

	DB_SET_PAYLOAD(uri, puri);
	uri->cmp = pg_uri_cmp;
	return 0;

 error:
	if (puri) {
		db_drv_free(&puri->drv);
		if (puri) pkg_free(puri);
	}
	return -1;
}
コード例 #17
0
ファイル: my_uri.c プロジェクト: SipSeb/kamailio
int my_uri(db_uri_t* uri)
{
	struct my_uri* res;

	res = (struct my_uri*)pkg_malloc(sizeof(struct my_uri));
	if (res == NULL) {
		ERR("mysql: No memory left\n");
		goto error;
	}
	memset(res, '\0', sizeof(struct my_uri));
	if (db_drv_init(&res->drv, my_uri_free) < 0) goto error;
	if (parse_mysql_uri(res, &uri->body) < 0) goto error;

	DB_SET_PAYLOAD(uri, res);
	uri->cmp = my_uri_cmp;
	return 0;

 error:
	if (res) {
		db_drv_free(&res->drv);
		if (res) pkg_free(res);
	}
	return -1;
}
コード例 #18
0
ファイル: my_cmd.c プロジェクト: aphistic/kamailio
int my_cmd(db_cmd_t* cmd)
{
	struct my_cmd* res;
 
	res = (struct my_cmd*)pkg_malloc(sizeof(struct my_cmd));
	if (res == NULL) {
		ERR("mysql: No memory left\n");
		goto error;
	}
	memset(res, '\0', sizeof(struct my_cmd));
	/* Fetch all data to client at once by default */
	res->flags |= MY_FETCH_ALL;
	if (db_drv_init(&res->gen, my_cmd_free) < 0) goto error;

	switch(cmd->type) {
	case DB_PUT:
		if (DB_FLD_EMPTY(cmd->vals)) {
			BUG("mysql: No parameters provided for DB_PUT in context '%.*s'\n", 
				cmd->ctx->id.len, ZSW(cmd->ctx->id.s));
			goto error;
		}
		if (build_replace_cmd(&res->sql_cmd, cmd) < 0) goto error;
		break;

	case DB_DEL:
		if (build_delete_cmd(&res->sql_cmd, cmd) < 0) goto error;
		break;

	case DB_GET:
		if (build_select_cmd(&res->sql_cmd, cmd) < 0) goto error;
		break;

	case DB_UPD:
		if (build_update_cmd(&res->sql_cmd, cmd) < 0) goto error;
		break;

	case DB_SQL:
		res->sql_cmd.s = (char*)pkg_malloc(cmd->table.len);
		if (res->sql_cmd.s == NULL) {
			ERR("mysql: Out of private memory\n");
			goto error;
		}
		memcpy(res->sql_cmd.s,cmd->table.s, cmd->table.len);
		res->sql_cmd.len = cmd->table.len;
        break;
	}

	DB_SET_PAYLOAD(cmd, res);

	/* In order to check all the parameters and results, we need to upload
	 * the command to the server. We need to do that here before we report
	 * back that the command was created successfully. Hence, this
	 * function requires the corresponding connection be established. We
	 * would not be able to check parameters if we don't do that there and
	 * that could result in repeated execution failures at runtime.
	 */
	if (upload_cmd(cmd)) goto error;
	return 0;

 error:
	if (res) {
		DB_SET_PAYLOAD(cmd, NULL);
		db_drv_free(&res->gen);
		if (res->sql_cmd.s) pkg_free(res->sql_cmd.s);
		pkg_free(res);
	}
	return -1;
}
コード例 #19
0
ファイル: pg_cmd.c プロジェクト: billyyh/kamailio
int pg_cmd(db_cmd_t* cmd)
{
	struct pg_cmd* pcmd;
 
	pcmd = (struct pg_cmd*)pkg_malloc(sizeof(struct pg_cmd));
	if (pcmd == NULL) {
		ERR("postgres: No memory left\n");
		goto error;
	}
	memset(pcmd, '\0', sizeof(struct pg_cmd));
	if (db_drv_init(&pcmd->gen, pg_cmd_free) < 0) goto error;

	switch(cmd->type) {
	case DB_PUT:
		if (build_insert_sql(&pcmd->sql_cmd, cmd) < 0) goto error;
		break;
		
	case DB_DEL:
		if (build_delete_sql(&pcmd->sql_cmd, cmd) < 0) goto error;
		break;

	case DB_GET:
		if (build_select_sql(&pcmd->sql_cmd, cmd) < 0) goto error;
		break;

	case DB_UPD:
		if (build_update_sql(&pcmd->sql_cmd, cmd) < 0) goto error;
		break;
		
	case DB_SQL:
		pcmd->sql_cmd.s = (char*)pkg_malloc(cmd->table.len + 1);
		if (pcmd->sql_cmd.s == NULL) {
			ERR("postgres: Out of private memory\n");
			goto error;
		}
		memcpy(pcmd->sql_cmd.s,cmd->table.s, cmd->table.len);
		pcmd->sql_cmd.s[cmd->table.len] = '\0';
		pcmd->sql_cmd.len = cmd->table.len;
        break;
	}

	DB_SET_PAYLOAD(cmd, pcmd);

	/* Create parameter arrays for PostgreSQL API functions */
	if (create_pg_params(cmd) < 0) goto error;	

	/* Generate a unique name for the command on the server */
	if (gen_cmd_name(cmd) != 0) goto error; 

	/* Upload the command to the server */
	if (upload_cmd(cmd) != 0) goto error;

	/* Obtain the description of the uploaded command, this includes
	 * information about result and parameter fields */
	if (get_types(cmd) != 0) goto error;

	/* Update fields based on the information retrieved from the */
	if (pg_resolve_param_oids(cmd->vals, cmd->match,
							  cmd->vals_count, cmd->match_count,
							  pcmd->types)) 
		goto error;
	if (pg_resolve_result_oids(cmd->result, cmd->result_count, pcmd->types)) 
		goto error;

	if (check_types(cmd)) goto error;

	return 0;

 error:
	if (pcmd) {
		DB_SET_PAYLOAD(cmd, NULL);
		free_pg_params(&pcmd->params);

		if (pcmd->types) PQclear(pcmd->types);
		if (pcmd->name) pkg_free(pcmd->name);
		if (pcmd->sql_cmd.s) pkg_free(pcmd->sql_cmd.s);

		db_drv_free(&pcmd->gen);
		pkg_free(pcmd);
	}
	return -1;
}
コード例 #20
0
ファイル: ld_cmd.c プロジェクト: 2pac/kamailio
int ld_cmd(db_cmd_t* cmd)
{
	struct ld_cmd* lcmd;
	struct ld_cfg* cfg;
	struct ld_fld* lfld;
	int i, j;

	lcmd = (struct ld_cmd*)pkg_malloc(sizeof(struct ld_cmd));
	if (lcmd == NULL) {
		ERR("ldap: No memory left\n");
		goto error;
	}
	memset(lcmd, '\0', sizeof(struct ld_cmd));
	if (db_drv_init(&lcmd->gen, ld_cmd_free) < 0) goto error;

	switch(cmd->type) {
	case DB_PUT:
	case DB_DEL:
	case DB_UPD:
		ERR("ldap: The driver does not support directory modifications yet.\n");
		goto error;
		break;

	case DB_GET:
		break;

	case DB_SQL:
		ERR("ldap: The driver does not support raw queries yet.\n");
		goto error;
	}

	cfg = ld_find_cfg(&cmd->table);
	if (cfg == NULL) {
		ERR("ldap: Cannot find configuration for '%.*s', giving up\n",
			STR_FMT(&cmd->table));
		goto error;
	}

	lcmd->base = cfg->base.s;
	lcmd->scope = cfg->scope;

	lcmd->sizelimit = cfg->sizelimit;
	if (cfg->timelimit) {
		lcmd->timelimit.tv_sec = cfg->timelimit;
		lcmd->timelimit.tv_usec = 0;
	}

	if (cfg->filter.s) {
		lcmd->filter = cfg->filter;
	}
	lcmd->chase_references = cfg->chase_references;
	lcmd->chase_referrals = cfg->chase_referrals;

	if (ld_resolve_fld(cmd->match, cfg) < 0) goto error;
	if (ld_resolve_fld(cmd->result, cfg) < 0) goto error;

	/* prepare filter for each result field */
	for(i = 0; !DB_FLD_EMPTY(cmd->result) && !DB_FLD_LAST(cmd->result[i]); i++) {
		int n;
		lfld = DB_GET_PAYLOAD(cmd->result + i);
		lfld->filter = NULL;
	
		for(j = 0, n = 0; !DB_FLD_EMPTY(cmd->match) && !DB_FLD_LAST(cmd->match[j]); j++) {
			if (strcmp(cmd->result[i].name, cmd->match[j].name) == 0)
				n++;	
		}
		
		if (n > 0) {
			lfld->filter = pkg_malloc((n+1)*sizeof(*(lfld->filter)));
			if (!lfld->filter) return -1 /* E_OUT_OF_MEM*/;
			for(j = 0, n = 0; !DB_FLD_EMPTY(cmd->match) && !DB_FLD_LAST(cmd->match[j]); j++) {
				if (strcmp(cmd->result[i].name, cmd->match[j].name) == 0) {
					lfld->filter[n] = cmd->match+j;
					n++;
				}
			}
			lfld->filter[n] = NULL;
		}
	}
	if (build_result_array(&lcmd->result, cmd) < 0) goto error;

	DB_SET_PAYLOAD(cmd, lcmd);
	return 0;

 error:
	if (lcmd) {
		DB_SET_PAYLOAD(cmd, NULL);
		db_drv_free(&lcmd->gen);
		if (lcmd->result) pkg_free(lcmd->result);
		pkg_free(lcmd);
	}
	return -1;
}