• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ RES_COL_N函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中RES_COL_N函数的典型用法代码示例。如果您正苦于以下问题:C++ RES_COL_N函数的具体用法?C++ RES_COL_N怎么用?C++ RES_COL_N使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了RES_COL_N函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: db_free_columns

/*
 * Release memory used by columns
 */
int db_free_columns(db1_res_t* _r)
{
	int col;

	if (!_r) {
		LM_ERR("invalid parameter value\n");
		return -1;
	}
	LM_DBG("freeing %d columns\n", RES_COL_N(_r));
	/* free memory previously allocated to save column names */
	for(col = 0; col < RES_COL_N(_r); col++) {
		if (RES_NAMES(_r)[col]!=NULL) {
			LM_DBG("freeing RES_NAMES[%d] at %p\n", col, RES_NAMES(_r)[col]);
			pkg_free((str *)RES_NAMES(_r)[col]);
			RES_NAMES(_r)[col] = NULL;
		}
	}
	RES_COL_N(_r) = 0;

	/* free names and types */
	if (RES_NAMES(_r)) {
		LM_DBG("freeing result names at %p\n", RES_NAMES(_r));
		pkg_free(RES_NAMES(_r));
		RES_NAMES(_r) = NULL;
	}
	if (RES_TYPES(_r)) {
		LM_DBG("freeing result types at %p\n", RES_TYPES(_r));
		pkg_free(RES_TYPES(_r));
		RES_TYPES(_r) = NULL;
	}
	return 0;
}
开发者ID:SipCoSystems,项目名称:hush,代码行数:35,代码来源:db_res.c


示例2: convert_row

/*
 * Convert a row from result into db API representation
 */
int convert_row(db_con_t* _h, db_res_t* _res, db_row_t* _r)
{
	unsigned long* lengths;
	int i;
#ifndef PARANOID
	if ((!_h) || (!_r) || (!_n)) {
		log(L_ERR, "convert_row(): Invalid parameter value\n");
		return -1;
	}
#endif

	ROW_VALUES(_r) = (db_val_t*)pkg_malloc(sizeof(db_val_t) * RES_COL_N(_res));
	ROW_N(_r) = RES_COL_N(_res);
	if (!ROW_VALUES(_r)) {
		LOG(L_ERR, "convert_row(): No memory left\n");
		return -1;
	}

	lengths = mysql_fetch_lengths(CON_RESULT(_h));

	for(i = 0; i < RES_COL_N(_res); i++) {
		if (str2val(RES_TYPES(_res)[i], &(ROW_VALUES(_r)[i]), 
			    ((MYSQL_ROW)CON_ROW(_h))[i], lengths[i]) < 0) {
			LOG(L_ERR, "convert_row(): Error while converting value\n");
			free_row(_r);
			return -3;
		}
	}
	return 0;
}
开发者ID:miettal,项目名称:armadillo420_standard,代码行数:33,代码来源:db_row.c


示例3: bdb_free_result

/*
 * Free all memory allocated by get_result
 */
int bdb_free_result(db_con_t* _h, db_res_t* _r)
{
	db_row_t* r;
	db_val_t* v;
	int i, j;

	if (!_r) {
#ifdef BDB_EXTRA_DEBUG
	LOG(L_NOTICE, "BDB:bdb_free_result: NULL pointer\n");
#endif
		return 0;
	}

	for (i = 0; i < RES_ROW_N(_r); i++) {
		r = &(RES_ROWS(_r)[i]);
		for (j = 0; j < RES_COL_N(_r); j++) {
			v = &(ROW_VALUES(r)[j]);
			if (VAL_TYPE(v) == DB_STRING || VAL_TYPE(v) == DB_STR || VAL_TYPE(v) == DB_BLOB) {
				free(VAL_STR(v).s);
			}
		}
		free(ROW_VALUES(r));
	}
	free(RES_ROWS(_r));

	for (i = 0; i < RES_COL_N(_r); i++) {
		pkg_free((void *)RES_NAMES(_r)[i]);
	}
	pkg_free(RES_NAMES(_r));
	pkg_free(RES_TYPES(_r));

	pkg_free(_r);

        return 0;
}
开发者ID:4N7HR4X,项目名称:kamailio,代码行数:38,代码来源:bdb_base.c


示例4: sql_do_pvquery

int sql_do_pvquery(struct sip_msg *msg, sql_con_t *con, pv_elem_t *query,
		pvname_list_t *res)
{
	db1_res_t* db_res = NULL;
	pvname_list_t* pv;
	str sv;
	int i, j;

	if(msg==NULL || query==NULL || res==NULL)
	{
		LM_ERR("bad parameters\n");
		return -1;
	}
	if(pv_printf_s(msg, query, &sv)!=0)
	{
		LM_ERR("cannot print the sql query\n");
		return -1;
	}

	if(con->dbf.raw_query(con->dbh, &sv, &db_res)!=0)
	{
		LM_ERR("cannot do the query\n");
		return -1;
	}

	if(db_res==NULL || RES_ROW_N(db_res)<=0 || RES_COL_N(db_res)<=0)
	{
		LM_DBG("no result after query\n");
		con->dbf.free_result(con->dbh, db_res);
		return 2;
	}

	for(i=RES_ROW_N(db_res)-1; i>=0; i--)
	{
		pv = res;
		for(j=0; j<RES_COL_N(db_res); j++)
		{
			if (pv == NULL) {
				LM_ERR("Missing pv spec for column %d\n", j+1);
				goto error;
			}
			if (db_val2pv_spec(msg, &RES_ROWS(db_res)[i].values[j], &pv->sname) != 0) {
				LM_ERR("Failed to convert value for column %.*s (row %d)\n",
				       RES_NAMES(db_res)[j]->len, RES_NAMES(db_res)[j]->s, i);
				goto error;
			}
			pv = pv->next;
		}
	}

	con->dbf.free_result(con->dbh, db_res);
	return 1;

error:
	con->dbf.free_result(con->dbh, db_res);
	return -1;
}
开发者ID:SipCoSystems,项目名称:hush,代码行数:57,代码来源:sql_api.c


示例5: dbt_get_columns

/*
 * Get and convert columns from a result
 */
static int dbt_get_columns(db1_res_t* _r, dbt_result_p _dres)
{
	int col;
	
	if (!_r || !_dres) {
		LM_ERR("invalid parameter\n");
		return -1;
	}
	
	RES_COL_N(_r) = _dres->nrcols;
	if (!RES_COL_N(_r)) {
		LM_ERR("no columns\n");
		return -2;
	}
	if (db_allocate_columns(_r, RES_COL_N(_r)) != 0) {
		LM_ERR("could not allocate columns");
		return -3;
	}

	for(col = 0; col < RES_COL_N(_r); col++) {
		/* 
		 * Its would be not necessary to allocate here new memory, because of
		 * the internal structure of the db_text module. But we do this anyway
		 * to stay confirm to the other database modules.
		 */
		RES_NAMES(_r)[col] = (str*)pkg_malloc(sizeof(str));
		if (! RES_NAMES(_r)[col]) {
			LM_ERR("no private memory left\n");
			db_free_columns(_r);
			return -4;
		}
		LM_DBG("allocate %d bytes for RES_NAMES[%d] at %p",
				(int)sizeof(str), col,
				RES_NAMES(_r)[col]);
		RES_NAMES(_r)[col]->s = _dres->colv[col].name.s;
		RES_NAMES(_r)[col]->len = _dres->colv[col].name.len;

		switch(_dres->colv[col].type)
		{
			case DB1_STR:
			case DB1_STRING:
			case DB1_BLOB:
			case DB1_INT:
			case DB1_DATETIME:
			case DB1_DOUBLE:
				RES_TYPES(_r)[col] = _dres->colv[col].type;
			break;
			default:
				LM_WARN("unhandled data type column (%.*s) type id (%d), "
						"use STR as default\n", RES_NAMES(_r)[col]->len,
						RES_NAMES(_r)[col]->s, _dres->colv[col].type);
				RES_TYPES(_r)[col] = DB1_STR;
			break;
		}
	}
	return 0;
}
开发者ID:AndreyRybkin,项目名称:kamailio,代码行数:60,代码来源:dbt_api.c


示例6: print_res

static int print_res(db_res_t* _r)
{
	int i, j;

	for(i = 0; i < RES_COL_N(_r); i++) {
		printf("%s ", RES_NAMES(_r)[i]);
	}
	printf("\n");

	for(i = 0; i < RES_ROW_N(_r); i++) {
		for(j = 0; j < RES_COL_N(_r); j++) {
			if (RES_ROWS(_r)[i].values[j].nul == TRUE) {
				printf("NULL ");
				continue;
			}
			switch(RES_ROWS(_r)[i].values[j].type) {
			case DB_INT:
				printf("%d ", RES_ROWS(_r)[i].values[j].val.int_val);
				break;
			case DB_DOUBLE:
				printf("%f ", RES_ROWS(_r)[i].values[j].val.double_val);
				break;
			case DB_DATETIME:
				printf("%s ", ctime(&(RES_ROWS(_r)[i].values[j].val.time_val)));
				break;
			case DB_STRING:
				printf("%s ", RES_ROWS(_r)[i].values[j].val.string_val);
				break;
			case DB_STR:
				printf("%.*s ", 
				       RES_ROWS(_r)[i].values[j].val.str_val.len,
				       RES_ROWS(_r)[i].values[j].val.str_val.s);
				break;

			case DB_BLOB:
				printf("%.*s ",
				       RES_ROWS(_r)[i].values[j].val.blob_val.len,
				       RES_ROWS(_r)[i].values[j].val.blob_val.s);
				break;

			case DB_BITMAP:
				printf("%d ", RES_ROWS(_r)[i].values[j].val.bitmap_val);
				break;
			}
			
		}
		printf("\n");
	}
			
	return TRUE;
}
开发者ID:miettal,项目名称:armadillo420_standard,代码行数:51,代码来源:dbexample.c


示例7: db_postgres_convert_row

/**
 * Convert a row from the result query into db API representation
 */
int db_postgres_convert_row(const db_con_t* _h, db_res_t* _r, db_row_t* _row,
		char **row_buf)
{
	int col, len;

	if (!_h || !_r || !_row)  {
		LM_ERR("invalid parameter value\n");
		return -1;
	}

	/* Save the number of columns in the ROW structure */
	ROW_N(_row) = RES_COL_N(_r);

	/* For each column in the row */
	for(col = 0; col < ROW_N(_row); col++) {
		/* compute the len of the value */
		if ( row_buf[col]==NULL || row_buf[col][0]=='\0')
			len = 0;
		else
			len =  strlen(row_buf[col]);

		/* Convert the string representation into the value representation */
		if (db_postgres_str2val(RES_TYPES(_r)[col], &(ROW_VALUES(_row)[col]),
		row_buf[col], len) < 0) {
			LM_ERR("failed to convert value\n");
			LM_DBG("free row at %pn", _row);
			db_free_row(_row);
			return -3;
		}
	}
	return 0;
}
开发者ID:mtulio,项目名称:mtulio,代码行数:35,代码来源:res.c


示例8: db_mysql_convert_row

/*!
 * \brief Convert a row from result into DB API representation
 * \param _h database connection
 * \param _res database result in the DB API representation
 * \param _r database result row
 * \return 0 on success, -1 on failure
 */
int db_mysql_convert_row(const db1_con_t* _h, db1_res_t* _res, db_row_t* _r)
{
	unsigned long* lengths;
	int i;

	if ((!_h) || (!_res) || (!_r)) {
		LM_ERR("invalid parameter value\n");
		return -1;
	}

	if (db_allocate_row(_res, _r) != 0) {
		LM_ERR("could not allocate row");
		return -2;
	}
	
	lengths = mysql_fetch_lengths(CON_RESULT(_h));

	for(i = 0; i < RES_COL_N(_res); i++) {
		if (db_str2val(RES_TYPES(_res)[i], &(ROW_VALUES(_r)[i]),
			    ((MYSQL_ROW)CON_ROW(_h))[i], lengths[i], 0) < 0) {
			LM_ERR("failed to convert value\n");
			LM_DBG("free row at %p\n", _r);
			db_free_row(_r);
			return -3;
		}
	}
	return 0;
}
开发者ID:billyyh,项目名称:kamailio,代码行数:35,代码来源:km_row.c


示例9: db_allocate_row

/**
 * Allocate memory for row value.
 * \param _res result set
 * \param _row filled row
 * \return zero on success, negative on errors
 */
inline int db_allocate_row(const db1_res_t* _res, db_row_t* _row)
{
	int len = sizeof(db_val_t) * RES_COL_N(_res);
	ROW_VALUES(_row) = (db_val_t*)pkg_malloc(len);
	if (!ROW_VALUES(_row)) {
		LM_ERR("no private memory left\n");
		return -1;
	}
	LM_DBG("allocate %d bytes for row values at %p\n", len, ROW_VALUES(_row));

	memset(ROW_VALUES(_row), 0, len);
	/* Save the number of columns in the ROW structure */
	ROW_N(_row) = RES_COL_N(_res);

	return 0;
}
开发者ID:MohammedYaseen,项目名称:kamailio,代码行数:22,代码来源:db_row.c


示例10: bdb_get_columns

int bdb_get_columns(table_p _tp, db_res_t* _res, int* _lres, int _nc)
{
	int col;

	if (!_res) {
		LM_ERR("invalid parameter\n");
		return -1;
	}

	if (_nc < 0 ) {
		LM_ERR("_nc parameter cannot be negative \n");
		return -1;
	}
    /* the number of rows (tuples) in the query result. */
	RES_NUM_ROWS(_res) = 1;

	if (!_lres)
		_nc = _tp->ncols;

	/* Save number of columns in the result structure */
	RES_COL_N(_res) = _nc;

	if (db_allocate_columns(_res, RES_COL_N(_res)) != 0) {
		LM_ERR("could not allocate columns");
		return -2;
	}

	/*
	 * For each column both the name and the data type are saved.
	 */
	for(col = 0; col < RES_COL_N(_res); col++) {
		column_p cp = NULL;
		cp = (_lres) ? _tp->colp[_lres[col]] : _tp->colp[col];

		/* The pointer that is here returned is part of the result structure.*/
		RES_NAMES(_res)[col]->s = cp->name.s;
		RES_NAMES(_res)[col]->len = cp->name.len;

		LM_DBG("RES_NAMES(%p)[%d]=[%.*s]\n", RES_NAMES(_res)[col]
			, col, RES_NAMES(_res)[col]->len, RES_NAMES(_res)[col]->s);

		RES_TYPES(_res)[col] = cp->type;
	}
	return 0;
}
开发者ID:KISSMonX,项目名称:opensips,代码行数:45,代码来源:bdb_res.c


示例11: dbt_get_columns

/*
 * Get and convert columns from a result
 */
static int dbt_get_columns(db_con_t* _h, db_res_t* _r)
{
	int col;

	if (!_h || !_r) {
		LM_ERR("invalid parameter\n");
		return -1;
	}

	RES_COL_N(_r) = DBT_CON_RESULT(_h)->nrcols;
	if (!RES_COL_N(_r)) {
		LM_ERR("no columns\n");
		return -2;
	}
	if (db_allocate_columns(_r, RES_COL_N(_r)) != 0) {
		LM_ERR("could not allocate columns\n");
		return -3;
	}

	for(col = 0; col < RES_COL_N(_r); col++) {

		RES_NAMES(_r)[col]->s = DBT_CON_RESULT(_h)->colv[col].name.s;
		RES_NAMES(_r)[col]->len = DBT_CON_RESULT(_h)->colv[col].name.len;

		switch(DBT_CON_RESULT(_h)->colv[col].type)
		{
			case DB_STR:
			case DB_STRING:
			case DB_BLOB:
			case DB_INT:
			case DB_BIGINT:
			case DB_DATETIME:
			case DB_DOUBLE:
				RES_TYPES(_r)[col] = DBT_CON_RESULT(_h)->colv[col].type;
			break;
			default:
				LM_WARN("unhandled data type column (%.*s) type id (%d), "
						"use STR as default\n", RES_NAMES(_r)[col]->len,
						RES_NAMES(_r)[col]->s, DBT_CON_RESULT(_h)->colv[col].type);
				RES_TYPES(_r)[col] = DB_STR;
			break;
		}
	}
	return 0;
}
开发者ID:OpenSIPS,项目名称:opensips,代码行数:48,代码来源:dbt_api.c


示例12: db_build_userbl_tree

int db_build_userbl_tree(const str *username, const str *domain, const str *table, struct dtrie_node_t *root, int use_domain)
{
	db_key_t columns[2] = { &userblacklist_prefix_col, &userblacklist_whitelist_col };
	db_key_t key[2] = { &userblacklist_username_col, &userblacklist_domain_col };

	db_val_t val[2];
	db1_res_t *res;
	int i;
	int n = 0;
	void *nodeflags;
	VAL_TYPE(val) = VAL_TYPE(val + 1) = DB1_STR;
	VAL_NULL(val) = VAL_NULL(val + 1) = 0;
	VAL_STR(val).s = username->s;
	VAL_STR(val).len = username->len;
	VAL_STR(val + 1).s = domain->s;
	VAL_STR(val + 1).len = domain->len;

	
	if (userblacklist_dbf.use_table(userblacklist_dbh, table) < 0) {
		LM_ERR("cannot use table '%.*s'.\n", table->len, table->s);
		return -1;
	}
	if (userblacklist_dbf.query(userblacklist_dbh, key, 0, val, columns, (!use_domain) ? (1) : (2), 2, 0, &res) < 0) {
		LM_ERR("error while executing query.\n");
		return -1;
	}

	dtrie_clear(root, NULL, match_mode);

	if (RES_COL_N(res) > 1) {
		for(i = 0; i < RES_ROW_N(res); i++) {
			if ((!RES_ROWS(res)[i].values[0].nul) && (!RES_ROWS(res)[i].values[1].nul)) {
				if ((RES_ROWS(res)[i].values[0].type == DB1_STRING) &&
					(RES_ROWS(res)[i].values[1].type == DB1_INT)) {

					/* LM_DBG("insert into tree prefix %s, whitelist %d",
						RES_ROWS(res)[i].values[0].val.string_val,
						RES_ROWS(res)[i].values[1].val.int_val); */
					if (RES_ROWS(res)[i].values[1].val.int_val == 0) {
						nodeflags=(void *)MARK_BLACKLIST;
					} else {
						nodeflags=(void *)MARK_WHITELIST;
					}
					if (dtrie_insert(root, RES_ROWS(res)[i].values[0].val.string_val, strlen(RES_ROWS(res)[i].values[0].val.string_val),
						nodeflags, match_mode) < 0) LM_ERR("could not insert values into trie.\n");
					n++;
				}
				else {
					LM_ERR("got invalid result type from query.\n");
				}
			}
		}
	}
	userblacklist_dbf.free_result(userblacklist_dbh, res);

	return n;
}
开发者ID:AlessioCasco,项目名称:kamailio,代码行数:57,代码来源:db.c


示例13: db_sqlite_free_result

/**
 * Release a result set from memory.
 * \param _h handle to the database
 * \param _r result set that should be freed
 * \return zero on success, negative value on failure
 */
int db_sqlite_free_result(db_con_t* _h, db_res_t* _r)
{
	int i;
	int j;
	db_val_t* v;
	db_row_t* res_col;

	if (!_h) {
		LM_ERR("invalid database handle\n");
		return -1;
	}

	if (!_r) {
		LM_DBG("nothing to free!\n");
		return 0;
	}


	if (RES_ROWS(_r)) {
		LM_DBG("freeing rows at %p\n", RES_ROWS(_r));
		for (i = 0; i < RES_ROW_N(_r); i++) {
			for (j = 0; j < RES_COL_N(_r); j++) {
				res_col = &_r->rows[i];
				v = &res_col->values[j];

				if (VAL_NULL(v))
					continue;

				/* only allocated types; STR and BLOB;*/
				if (VAL_TYPE(v) == DB_STR) {
					pkg_free(VAL_STR(v).s);
					VAL_STR(v).s = 0;
				} else if (VAL_TYPE(v) == DB_BLOB) {
					pkg_free(VAL_BLOB(v).s);
					VAL_BLOB(v).s = 0;
				}
			}
		}

		pkg_free(_r->rows[0].values);
		pkg_free(_r->rows);
		RES_ROWS(_r) = NULL;
	}

	RES_ROW_N(_r) = 0;


	pkg_free(_r);
	_r = NULL;

	return 0;
}
开发者ID:AndreiPlesa,项目名称:opensips,代码行数:58,代码来源:dbase.c


示例14: db_build_userbl_tree

/**
 * Builds a d-tree using database entries.
 * \return negative on failure, postive on success, indicating the number of d-tree entries
 */
int db_build_userbl_tree(const str *username, const str *domain, const str *table, struct dt_node_t *root, int use_domain)
{
	db_key_t columns[2] = { &prefix_col, &whitelist_col };
	db_key_t key[2] = { &username_key, &domain_key };

	db_val_t val[2];
	VAL_TYPE(val) = VAL_TYPE(val + 1) = DB_STR;
	VAL_NULL(val) = VAL_NULL(val + 1) = 0;
	VAL_STR(val).s = username->s;
	VAL_STR(val).len = username->len;
	VAL_STR(val + 1).s = domain->s;
	VAL_STR(val + 1).len = domain->len;

	db_res_t *res;
	int i;
	int n = 0;
	
	if (dbf.use_table(dbc, table) < 0) {
		LM_ERR("cannot use table '%.*s'.\n", table->len, table->s);
		return -1;
	}
	if (dbf.query(dbc, key, 0, val, columns, (!use_domain) ? (1) : (2), 2, 0, &res) < 0) {
		LM_ERR("error while executing query.\n");
		return -1;
	}

	dt_clear(root);

	if (RES_COL_N(res) > 1) {
		for(i = 0; i < RES_ROW_N(res); i++) {
			if ((!RES_ROWS(res)[i].values[0].nul) && (!RES_ROWS(res)[i].values[1].nul)) {
				if ((RES_ROWS(res)[i].values[0].type == DB_STRING) &&
					(RES_ROWS(res)[i].values[1].type == DB_INT)) {

					/* LM_DBG("insert into tree prefix %s, whitelist %d",
						RES_ROWS(res)[i].values[0].val.string_val,
						RES_ROWS(res)[i].values[1].val.int_val); */
					dt_insert(root, RES_ROWS(res)[i].values[0].val.string_val,
						RES_ROWS(res)[i].values[1].val.int_val);
					n++;
				}
				else {
					LM_ERR("got invalid result type from query.\n");
				}
			}
		}
	}
	dbf.free_result(dbc, res);

	return n;
}
开发者ID:UIKit0,项目名称:OpenSIPS,代码行数:55,代码来源:db.c


示例15: db_unixodbc_convert_row

/*
 * Convert a row from result into db API representation
 */
int db_unixodbc_convert_row(const db_con_t* _h, const db_res_t* _res, 
									db_row_t* _r, const unsigned long* lengths)
{
	int i;

	if ((!_h) || (!_res) || (!_r)) {
		LM_ERR("invalid parameter value\n");
		return -1;
	}

	/* Save the number of columns in the ROW structure */
	ROW_N(_r) = RES_COL_N(_res);
	for(i = 0; i < RES_COL_N(_res); i++) {
		if (db_unixodbc_str2val(RES_TYPES(_res)[i], &(ROW_VALUES(_r)[i]),
			((CON_ROW(_h))[i]), lengths[i]) < 0) {
			LM_ERR("failed to convert value\n");
			LM_DBG("free row at %p\n", _r);
			db_free_row(_r);
			return -3;
		}
	}
	return 0;
}
开发者ID:UIKit0,项目名称:OpenSIPS,代码行数:26,代码来源:row.c


示例16: db_mysql_convert_row

/**
 * Convert a row from result into db API representation
 */
int db_mysql_convert_row(const db_con_t* _h, db_res_t* _res, db_row_t* _r)
{
	unsigned long* lengths;
	int i;

	if ((!_h) || (!_res) || (!_r)) {
		LM_ERR("invalid parameter value\n");
		return -1;
	}

	/* Save the number of columns in the ROW structure */
	ROW_N(_r) = RES_COL_N(_res);

	if (CON_HAS_PS(_h)) {
		for(i=0; i < CON_MYSQL_PS(_h)->cols_out; i++) {
			if (db_mysql_str2val(RES_TYPES(_res)[i], &(ROW_VALUES(_r)[i]),
			CON_PS_OUTCOL(_h, i).null?NULL:CON_PS_OUTCOL(_h, i).buf,
			CON_PS_OUTCOL(_h,i).len) < 0) {
				LM_ERR("failed to convert value from stmt\n");
				db_free_row(_r);
				return -3;
			}
		}
	} else {
		lengths = mysql_fetch_lengths(CON_RESULT(_h));
		for(i = 0; i < RES_COL_N(_res); i++) {
			if (db_mysql_str2val(RES_TYPES(_res)[i], &(ROW_VALUES(_r)[i]),
			((MYSQL_ROW)CON_ROW(_h))[i], lengths[i]) < 0) {
				LM_ERR("failed to convert value\n");
				LM_DBG("free row at %p\n", _r);
				db_free_row(_r);
				return -3;
			}
		}
	}
	return 0;
}
开发者ID:KISSMonX,项目名称:opensips,代码行数:40,代码来源:row.c


示例17: db_allocate_rows

/*
 * Allocate storage for rows in existing
 * result structure.
 */
int db_allocate_rows(db_res_t* _res, const unsigned int rows)
{
    unsigned int i;

    RES_ROWS(_res) = (struct db_row*)pkg_malloc
                     (rows * (sizeof(db_row_t) + sizeof(db_val_t) * RES_COL_N(_res)) );
    if (!RES_ROWS(_res)) {
        LM_ERR("no memory left\n");
        return -1;
    }
    memset( RES_ROWS(_res), 0 ,
            rows * (sizeof(db_row_t) + sizeof(db_val_t) * RES_COL_N(_res)));

    LM_DBG("allocate %d bytes for result rows and values at %p\n",
           (int)(rows * (sizeof(db_row_t) + sizeof(db_val_t) * RES_COL_N(_res))),
           RES_ROWS(_res));

    for( i=0 ; i<rows ; i++ )
        /* the values of the row i */
        ROW_VALUES( &(RES_ROWS(_res)[i]) ) =
            ((db_val_t*)(RES_ROWS(_res)+rows)) + RES_COL_N(_res)*i;

    return 0;
}
开发者ID:vladpaiu,项目名称:opensips,代码行数:28,代码来源:db_res.c


示例18: db_reload_matrix

/**
 * Rebuild matrix using database entries
 * \return negative on failure, positive on success, indicating the number of matrix entries
 */
static int db_reload_matrix(void)
{
	db_key_t columns[3] = { &matrix_first_col, &matrix_second_col, &matrix_res_col };
	db1_res_t *res;
	int i;
	int n = 0;
	
	if (matrix_dbf.use_table(matrix_dbh, &matrix_table) < 0) {
		LM_ERR("cannot use table '%.*s'.\n", matrix_table.len, matrix_table.s);
		return -1;
	}
	if (matrix_dbf.query(matrix_dbh, NULL, NULL, NULL, columns, 0, 3, NULL, &res) < 0) {
		LM_ERR("error while executing query.\n");
		return -1;
	}

	/* critical section start: avoids dirty reads when updating d-tree */
	lock_get(lock);

	matrix_clear();

	if (RES_COL_N(res) > 2) {
		for(i = 0; i < RES_ROW_N(res); i++) {
			if ((!RES_ROWS(res)[i].values[0].nul) && (!RES_ROWS(res)[i].values[1].nul)) {
				if ((RES_ROWS(res)[i].values[0].type == DB1_INT) &&
						(RES_ROWS(res)[i].values[1].type == DB1_INT) &&
						(RES_ROWS(res)[i].values[2].type == DB1_INT)) {
					matrix_insert(RES_ROWS(res)[i].values[0].val.int_val, RES_ROWS(res)[i].values[1].val.int_val, RES_ROWS(res)[i].values[2].val.int_val);
					n++;
				}
				else {
					LM_ERR("got invalid result type from query.\n");
				}
			}
		}
	}

	/* critical section end */
	lock_release(lock);

	matrix_dbf.free_result(matrix_dbh, res);

	LM_INFO("loaded %d matrix entries.", n);
	return n;
}
开发者ID:kiryu,项目名称:kamailio,代码行数:49,代码来源:matrix.c


示例19: cql_get_columns

/** 
 *  This function check the CQLresult of the CQL query and   
 *  adds the columns to the returning result structure. 
 *
 * \param _cql_res  handle for the CQLResult
 * \param _r result set for storage
 * \return zero on success, negative value on failure
 */
int cql_get_columns(oac::CqlResult& _cql_res, db1_res_t* _r)
{
	std::vector<oac::CqlRow>  res_cql_rows = _cql_res.rows;
	int rows_no = res_cql_rows.size();
	int cols_no = 0;

	LM_DBG("cqlrow Vector size =%d\n", rows_no);
	
	if (rows_no > 0) {
		cols_no = res_cql_rows[0].columns.size();
		LM_DBG("There are %d columns available, this should be the case for all %d rows (consider cql).\n", cols_no, rows_no);
	} else {
		LM_DBG("Got 0 rows. There is no result from the query.\n");
		return 0;
	}

	RES_COL_N(_r) = cols_no;
	if (!RES_COL_N(_r)) {
		LM_ERR("no columns returned from the query\n");
		return -2;
	} else {
		LM_DBG("%d columns returned from the query\n", RES_COL_N(_r));
	}

	if (db_allocate_columns(_r, RES_COL_N(_r)) != 0) {
		LM_ERR("Could not allocate columns\n");
		return -3;
	}

	/* For fields we will use the columns inside the first columns */

	for(int col = 0; col < RES_COL_N(_r); col++) {
		RES_NAMES(_r)[col] = (str*)pkg_malloc(sizeof(str));
		if (! RES_NAMES(_r)[col]) {
			LM_ERR("no private memory left\n");
			RES_COL_N(_r) = col;
			db_free_columns(_r);
			return -4;
		}
		LM_DBG("Allocated %lu bytes for RES_NAMES[%d] at %p\n",
			(unsigned long)sizeof(str), col, RES_NAMES(_r)[col]);

		/* The pointer that is here returned is part of the result structure. */
		RES_NAMES(_r)[col]->s = (char*) res_cql_rows[0].columns[col].name.c_str();
		RES_NAMES(_r)[col]->len = strlen(RES_NAMES(_r)[col]->s);
		RES_TYPES(_r)[col] = DB1_STR;

		LM_DBG("RES_NAMES(%p)[%d]=[%.*s]\n", RES_NAMES(_r)[col], col,
			RES_NAMES(_r)[col]->len, RES_NAMES(_r)[col]->s);
	}
	return 0;
}
开发者ID:aallamaa,项目名称:kamailio,代码行数:60,代码来源:dbcassa_base.cpp


示例20: db_reload_source

/**
 * Rebuild d-tree using database entries
 * \return negative on failure, positive on success, indicating the number of d-tree entries
 */
int db_reload_source(const str *table, struct dtrie_node_t *root)
{
	db_key_t columns[2] = { &globalblacklist_prefix_col, &globalblacklist_whitelist_col };
	db1_res_t *res;
	int i;
	int n = 0;
	void *nodeflags;
	
	if (userblacklist_dbf.use_table(userblacklist_dbh, table) < 0) {
		LM_ERR("cannot use table '%.*s'.\n", table->len, table->s);
		return -1;
	}
	if (userblacklist_dbf.query(userblacklist_dbh, NULL, NULL, NULL, columns, 0, 2, NULL, &res) < 0) {
		LM_ERR("error while executing query.\n");
		return -1;
	}

	dtrie_clear(root, NULL, match_mode);

	if (RES_COL_N(res) > 1) {
		for(i = 0; i < RES_ROW_N(res); i++) {
			if ((!RES_ROWS(res)[i].values[0].nul) && (!RES_ROWS(res)[i].values[1].nul)) {
				if ((RES_ROWS(res)[i].values[0].type == DB1_STRING) &&
					(RES_ROWS(res)[i].values[1].type == DB1_INT)) {

					/* LM_DBG("insert into tree prefix %s, whitelist %d",
						RES_ROWS(res)[i].values[0].val.string_val,
						RES_ROWS(res)[i].values[1].val.int_val); */
					if (RES_ROWS(res)[i].values[1].val.int_val == 0) nodeflags=(void *) MARK_BLACKLIST;
					else nodeflags=(void *)MARK_WHITELIST;
					if (dtrie_insert(root, RES_ROWS(res)[i].values[0].val.string_val, strlen(RES_ROWS(res)[i].values[0].val.string_val),
						nodeflags, match_mode) < 0) LM_ERR("could not insert values into trie.\n");
					n++;
				}
				else {
					LM_ERR("got invalid result type from query.\n");
				}
			}
		}
	}
	userblacklist_dbf.free_result(userblacklist_dbh, res);

	return n;
}
开发者ID:AlessioCasco,项目名称:kamailio,代码行数:48,代码来源:db.c



注:本文中的RES_COL_N函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ RES_K函数代码示例发布时间:2022-05-30
下一篇:
C++ RESTORE函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap