本文整理汇总了C++中ROW_VALUES函数的典型用法代码示例。如果您正苦于以下问题:C++ ROW_VALUES函数的具体用法?C++ ROW_VALUES怎么用?C++ ROW_VALUES使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ROW_VALUES函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load_location_number
int load_location_number(db_func_t * dbf, db1_con_t* dbh, int *loc_nr){
static char query[UL_DB_QUERY_LEN];
db1_res_t * res;
db_row_t * row;
int query_len;
str tmp;
if(!loc_nr || !dbf || !dbh){
LM_ERR("NULL parameter passed \n");
return -1;
}
query_len = 30 + id_col.len + reg_table.len + status_col.len;
if(query_len > UL_DB_QUERY_LEN) {
LM_ERR("weird: query larger than %i bytes.\n", UL_DB_QUERY_LEN);
return -1;
}
memset(query, 0, UL_DB_QUERY_LEN);
if(sprintf(query,
"SELECT MAX(%.*s) "
"FROM "
"%.*s "
"WHERE %.*s = 1;", id_col.len, id_col.s, reg_table.len, reg_table.s, status_col.len, status_col.s) < 0){
LM_ERR("could not sprinf query\n");
return -1;
}
LM_DBG("%s\n",query);
tmp.s = query;
tmp.len = strlen(query);
if (dbf->raw_query (dbh, &tmp, &res) < 0) {
LM_ERR("in database query.\n");
return -1;
}
if (RES_ROW_N (res) == 0) {
dbf->free_result (dbh, res);
LM_DBG ("no data found\n");
return 1;
}
row = RES_ROWS(res) + 0; /* only one row in answer */
if (VAL_NULL (ROW_VALUES(row) + 0)) {
LM_ERR("Weird: Empty Max ID Number\n");
dbf->free_result (dbh, res);
return 1;
}
*loc_nr = VAL_INT (ROW_VALUES(row) + 0);
dbf->free_result (dbh, res);
if(*loc_nr == 0){
LM_ERR("No location in DB?!\n");
return 1;
}
return 0;
}
示例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;
}
示例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;
}
示例4: free_row
/*
* Release memory used by row
*/
int free_row(db_row_t* _r)
{
#ifndef PARANOID
if (!_r) {
LOG(L_ERR, "free_row(): Invalid parameter value\n");
return -1;
}
#endif
if (ROW_VALUES(_r)) pkg_free(ROW_VALUES(_r));
return 0;
}
示例5: load_user_carrier
int load_user_carrier(str * user, str * domain) {
db1_res_t * res;
db_key_t cols[1];
db_key_t keys[2];
db_val_t vals[2];
db_op_t op[2];
int id;
int use_domain = cfg_get(carrierroute, carrierroute_cfg, use_domain);
if (!user || (use_domain && !domain)) {
LM_ERR("NULL pointer in parameter\n");
return -1;
}
cols[0] = subscriber_columns[SUBSCRIBER_CARRIER_COL];
keys[0] = subscriber_columns[SUBSCRIBER_USERNAME_COL];
op[0] = OP_EQ;
VAL_TYPE(vals) = DB1_STR;
VAL_NULL(vals) = 0;
VAL_STR(vals) = *user;
keys[1] = subscriber_columns[SUBSCRIBER_DOMAIN_COL];
op[1] = OP_EQ;
VAL_TYPE(vals+1) = DB1_STR;
VAL_NULL(vals+1) = 0;
VAL_STR(vals+1) = *domain;
if (carrierroute_dbf.use_table(carrierroute_dbh, &subscriber_table) < 0) {
LM_ERR("can't use table\n");
return -1;
}
if (carrierroute_dbf.query(carrierroute_dbh, keys, op, vals, cols, use_domain ? 2 : 1, 1, NULL, &res) < 0) {
LM_ERR("can't query database\n");
return -1;
}
if (RES_ROW_N(res) == 0) {
carrierroute_dbf.free_result(carrierroute_dbh, res);
return 0;
}
if (VAL_NULL(ROW_VALUES(RES_ROWS(res)))) {
carrierroute_dbf.free_result(carrierroute_dbh, res);
return 0;
}
id = VAL_INT(ROW_VALUES(RES_ROWS(res)));
carrierroute_dbf.free_result(carrierroute_dbh, res);
return id;
}
示例6: load_user_carrier
int load_user_carrier(str * user, str * domain) {
db_res_t * res;
db_key_t cols[1];
db_key_t keys[2];
db_val_t vals[2];
db_op_t op[2];
int id;
if (!user || (use_domain && !domain)) {
LM_ERR("NULL pointer in parameter\n");
return -1;
}
cols[0] = subscriber_columns[SUBSCRIBER_CARRIER_COL];
keys[0] = subscriber_columns[SUBSCRIBER_USERNAME_COL];
op[0] = OP_EQ;
vals[0].type = DB_STR;
vals[0].nul = 0;
vals[0].val.str_val = *user;
keys[1] = subscriber_columns[SUBSCRIBER_DOMAIN_COL];
op[1] = OP_EQ;
vals[1].type = DB_STR;
vals[1].nul = 0;
vals[1].val.str_val = *domain;
if (dbf.use_table(dbh, &subscriber_table) < 0) {
LM_ERR("can't use table\n");
return -1;
}
if (dbf.query(dbh, keys, op, vals, cols, use_domain ? 2 : 1, 1, NULL, &res) < 0) {
LM_ERR("can't query database\n");
return -1;
}
if (RES_ROW_N(res) == 0) {
dbf.free_result(dbh, res);
return 0;
}
if (VAL_NULL(ROW_VALUES(RES_ROWS(res)))) {
dbf.free_result(dbh, res);
return 0;
}
id = VAL_INT(ROW_VALUES(RES_ROWS(res)));
dbf.free_result(dbh, res);
return id;
}
示例7: 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;
}
示例8: 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;
}
示例9: 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;
}
示例10: db_postgres_convert_row
/*!
* \brief Convert a row from the result query into db API representation
* \param _h database connection
* \param _r result set
* \param _row row
* \param row_buf row buffer
* \return 0 on success, negative on error
*/
int db_postgres_convert_row(const db1_con_t* _h, db1_res_t* _r, db_row_t* _row,
char **row_buf)
{
int col, col_len;
if (!_h || !_r || !_row) {
LM_ERR("invalid parameter value\n");
return -1;
}
if (db_allocate_row(_r, _row) != 0) {
LM_ERR("could not allocate row\n");
return -2;
}
/* For each column in the row */
for(col = 0; col < ROW_N(_row); col++) {
/* because it can contain NULL */
if (!row_buf[col]) {
col_len = 0;
} else {
col_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], col_len) < 0) {
LM_ERR("failed to convert value\n");
LM_DBG("free row at %p\n", _row);
db_free_row(_row);
return -3;
}
}
return 0;
}
示例11: 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;
}
示例12: get_max_no_of_db_id
int get_max_no_of_db_id(db_func_t * dbf, db1_con_t * dbh, int id){
db1_res_t * res;
db_row_t * row;
int query_len, max;
str tmp;
query_len = 50 + reg_table.len + id_col.len + num_col.len;
if(query_len > UL_DB_QUERY_LEN){
LM_ERR("weird: query too long.\n");
return -1;
}
memset(query, 0, UL_DB_QUERY_LEN);
if (sprintf(query,
"SELECT MAX(%.*s) "
"FROM %.*s "
"WHERE %.*s='%i'",
num_col.len, num_col.s,
reg_table.len, reg_table.s,
id_col.len, id_col.s, id) < 0) {
LM_ERR("could not print query\n");
return -1;
}
tmp.s = query;
tmp.len = strlen(query);
if(dbf->raw_query(dbh, &tmp, &res) < 0){
LM_ERR("weird: could not query %.*s.\n",
reg_table.len, reg_table.s);
return -1;
}
if(RES_ROW_N(res) == 0){
LM_ERR("weird: no data found for id %i\n", id);
dbf->free_result(dbh, res);
return -1;
}
row = RES_ROWS(res);
max = VAL_INT(ROW_VALUES(row));
dbf->free_result(dbh, res);
return max;
}
示例13: bdb_row_match
int bdb_row_match(db_key_t* _k, db_op_t* _op, db_val_t* _v, int _n, db_res_t* _r, int* _lkey )
{
int i, res;
db_row_t* row = NULL;
if(!_r || !_lkey)
return 1;
row = RES_ROWS(_r);
for(i=0; i<_n; i++) {
res = bdb_cmp_val(&(ROW_VALUES(row)[_lkey[i]]), &_v[i]);
if(!_op || !strcmp(_op[i], OP_EQ)) {
if(res!=0)
return 0;
} else {
if(!strcmp(_op[i], OP_LT)) {
if(res!=-1)
return 0;
} else {
if(!strcmp(_op[i], OP_GT)) {
if(res!=1)
return 0;
} else {
if(!strcmp(_op[i], OP_LEQ)) {
if(res==1)
return 0;
} else {
if(!strcmp(_op[i], OP_GEQ)) {
if(res==-1)
return 0;
} else {
return res;
}}}}}
}
return 1;
}
示例14: 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;
}
示例15: 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;
}