本文整理汇总了C++中CON_TABLE函数的典型用法代码示例。如果您正苦于以下问题:C++ CON_TABLE函数的具体用法?C++ CON_TABLE怎么用?C++ CON_TABLE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CON_TABLE函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: flat_use_table
/*
* Store name of table that will be used by
* subsequent database functions
*/
int flat_use_table(db1_con_t* h, const str* t)
{
struct flat_con* con;
if (!h || !t || !t->s) {
LM_ERR("invalid parameter value\n");
return -1;
}
if (CON_TABLE(h)->s != t->s) {
if (CON_TAIL(h)) {
/* Decrement the reference count
* of the connection but do not remove
* it from the connection pool
*/
con = (struct flat_con*)CON_TAIL(h);
con->ref--;
}
CON_TAIL(h) = (unsigned long)
flat_get_connection((char*)CON_TABLE(h)->s, (char*)t->s);
if (!CON_TAIL(h)) {
return -1;
}
}
return 0;
}
示例2: db_query
/*
* Query table for specified rows
* _h: structure representing database connection
* _k: key names
* _op: operators
* _v: values of the keys that must match
* _c: column names to return
* _n: nmber of key=values pairs to compare
* _nc: number of columns to return
* _o: order by the specified column
*/
int db_query(db_con_t* _h, db_key_t* _k, db_op_t* _op,
db_val_t* _v, db_key_t* _c, int _n, int _nc,
db_key_t _o, db_res_t** _r)
{
int off, rv;
if (!_c) {
off = snprintf(sql_buf, SQL_BUF_LEN,
"select * from %s ", CON_TABLE(_h));
} else {
off = snprintf(sql_buf, SQL_BUF_LEN, "select ");
off += print_columns(sql_buf + off, SQL_BUF_LEN - off, _c, _nc);
off += snprintf(sql_buf + off, SQL_BUF_LEN - off,
"from %s ", CON_TABLE(_h));
}
if (_n) {
off += snprintf(sql_buf + off, SQL_BUF_LEN - off, "where ");
off += print_where(sql_buf + off, SQL_BUF_LEN - off,
_k, _op, _v, _n);
}
if (_o) {
off += snprintf(sql_buf + off, SQL_BUF_LEN - off,
"order by %s", _o);
}
if(begin_transaction(_h, sql_buf)) return(-1);
if (submit_query(_h, sql_buf) < 0) {
LOG(L_ERR, "db_query(): Error while submitting query\n");
return -2;
}
rv = get_result(_h, _r);
free_query(_h);
commit_transaction(_h);
return(rv);
}
示例3: erlang_srdb1_insert_update
/**
* Insert a row into a specified table, update on duplicate key.
* \param _h structure representing database connection
* \param _k key names
* \param _v values of the keys
* \param _n number of key=value pairs
*/
int erlang_srdb1_insert_update(const db1_con_t* _h, const db_key_t* _k, const db_val_t* _v,
const int _n)
{
ei_x_buff argbuf;
int retcode;
if ((!_h) || (!_k) || (!_v) || (!_n)) {
LM_ERR("invalid parameter value\n");
return -1;
}
LM_DBG("erlang_srdb1_insert_update table %.*s\n",CON_TABLE(_h)->len, CON_TABLE(_h)->s);
ei_x_new(&argbuf);
//encode tuple {db_op, table, [cols], [keys], [vals]}
ei_x_encode_tuple_header(&argbuf, 5);
ei_x_encode_atom(&argbuf,"insert_update");
ei_x_encode_atom_len(&argbuf,CON_TABLE(_h)->s,CON_TABLE(_h)->len);
ei_x_encode_list_header(&argbuf, 0); //_c
// ei_x_encode_list_header(&argbuf, 0); //_k
srdb1_encode_k(_k, NULL, _v, _n, &argbuf); //_k
srdb1_encode_v(_k, _v, _n, &argbuf); //_v
retcode=erl_bind.do_erlang_call(&(CON_ERLANG(_h)->con),&(CON_ERLANG(_h)->regname), &argbuf, NULL /*&retbuf*/);
ei_x_free(&argbuf);
if (retcode<0) {
// if(retbuf.buff) shm_free(retbuf.buff);
return retcode;
}
return 0;
}
示例4: db_mysql_query
/*
* Query table for specified rows
* _h: structure representing database connection
* _k: key names
* _op: operators
* _v: values of the keys that must match
* _c: column names to return
* _n: number of key=values pairs to compare
* _nc: number of columns to return
* _o: order by the specified column
*/
int db_mysql_query(db_con_t* _h, db_key_t* _k, db_op_t* _op,
db_val_t* _v, db_key_t* _c, int _n, int _nc,
db_key_t _o, db_res_t** _r)
{
int off, ret;
if (!_h) {
LM_ERR("invalid parameter value\n");
return -1;
}
if (!_c) {
ret = snprintf(sql_buf, SQL_BUF_LEN, "select * from %s ", CON_TABLE(_h));
if (ret < 0 || ret >= SQL_BUF_LEN) goto error;
off = ret;
} else {
ret = snprintf(sql_buf, SQL_BUF_LEN, "select ");
if (ret < 0 || ret >= SQL_BUF_LEN) goto error;
off = ret;
ret = db_print_columns(sql_buf + off, SQL_BUF_LEN - off, _c, _nc);
if (ret < 0) return -1;
off += ret;
ret = snprintf(sql_buf + off, SQL_BUF_LEN - off, "from %s ", CON_TABLE(_h));
if (ret < 0 || ret >= (SQL_BUF_LEN - off)) goto error;
off += ret;
}
if (_n) {
ret = snprintf(sql_buf + off, SQL_BUF_LEN - off, "where ");
if (ret < 0 || ret >= (SQL_BUF_LEN - off)) goto error;
off += ret;
ret = db_print_where(_h, sql_buf + off,
SQL_BUF_LEN - off, _k, _op, _v, _n, val2str);
if (ret < 0) return -1;;
off += ret;
}
if (_o) {
ret = snprintf(sql_buf + off, SQL_BUF_LEN - off, " order by %s", _o);
if (ret < 0 || ret >= (SQL_BUF_LEN - off)) goto error;
off += ret;
}
*(sql_buf + off) = '\0';
if (db_mysql_submit_query(_h, sql_buf) < 0) {
LM_ERR("error while submitting query\n");
return -2;
}
if(_r)
return db_mysql_store_result(_h, _r);
return 0;
error:
LM_ERR("error in snprintf\n");
return -1;
}
示例5: db_do_delete
int db_do_delete( db_con_t* _h, db_key_t* _k, db_op_t* _o,
db_val_t* _v, int _n, int (*val2str) ( db_con_t*,
db_val_t*, char*, int*), int (*submit_query)( db_con_t* _h,
str* _c),str *query_holder)
{
int off, ret;
str sql_str;
char sql_buf[SQL_BUF_LEN];
if (!_h || !val2str || (!submit_query && !query_holder)) {
LM_ERR("invalid parameter value\n");
return -1;
}
ret = snprintf(sql_buf, SQL_BUF_LEN, "delete from %.*s", CON_TABLE(_h)->len, CON_TABLE(_h)->s);
if (ret < 0 || ret >= SQL_BUF_LEN) goto error;
off = ret;
if (_n) {
ret = snprintf(sql_buf + off, SQL_BUF_LEN - off, " where ");
if (ret < 0 || ret >= (SQL_BUF_LEN - off)) goto error;
off += ret;
ret = db_print_where(_h, sql_buf + off,
SQL_BUF_LEN - off, _k, _o, _v, _n, val2str);
if (ret < 0) return -1;
off += ret;
}
if (off + 1 > SQL_BUF_LEN) goto error;
sql_buf[off] = '\0';
sql_str.s = sql_buf;
sql_str.len = off;
if (submit_query)
{
if (submit_query(_h, &sql_str) < 0) {
LM_ERR("error while submitting query\n");
return -2;
}
}
else
{
query_holder->s = pkg_malloc(off);
if (!query_holder->s)
{
LM_ERR("no more pkg mem\n");
return -2;
}
memcpy(query_holder->s,sql_buf,off);
query_holder->len = off;
}
return 0;
error:
LM_ERR("error while preparing delete operation\n");
return -1;
}
示例6: db_insert_update
/**
* Insert a row into a specified table, update on duplicate key.
* \param _h structure representing database connection
* \param _k key names
* \param _v values of the keys
* \param _n number of key=value pairs
*/
int db_insert_update(const db1_con_t* _h, const db_key_t* _k, const db_val_t* _v,
const int _n)
{
int off, ret;
static str sql_str;
static char sql_buf[SQL_BUF_LEN];
if ((!_h) || (!_k) || (!_v) || (!_n)) {
LM_ERR("invalid parameter value\n");
return -1;
}
ret = snprintf(sql_buf, SQL_BUF_LEN, "insert into %.*s (", CON_TABLE(_h)->len, CON_TABLE(_h)->s);
if (ret < 0 || ret >= SQL_BUF_LEN) goto error;
off = ret;
ret = db_print_columns(sql_buf + off, SQL_BUF_LEN - off, _k, _n);
if (ret < 0) return -1;
off += ret;
ret = snprintf(sql_buf + off, SQL_BUF_LEN - off, ") values (");
if (ret < 0 || ret >= (SQL_BUF_LEN - off)) goto error;
off += ret;
ret = db_print_values(_h, sql_buf + off, SQL_BUF_LEN - off, _v, _n, db_mysql_val2str);
if (ret < 0) return -1;
off += ret;
*(sql_buf + off++) = ')';
ret = snprintf(sql_buf + off, SQL_BUF_LEN - off, " on duplicate key update ");
if (ret < 0 || ret >= (SQL_BUF_LEN - off)) goto error;
off += ret;
ret = db_print_set(_h, sql_buf + off, SQL_BUF_LEN - off, _k, _v, _n, db_mysql_val2str);
if (ret < 0) return -1;
off += ret;
sql_str.s = sql_buf;
sql_str.len = off;
if (db_mysql_submit_query(_h, &sql_str) < 0) {
LM_ERR("error while submitting query\n");
return -2;
}
return 0;
error:
LM_ERR("error while preparing insert_update operation\n");
return -1;
}
示例7: db_do_update
int db_do_update(const db_con_t* _h, const db_key_t* _k, const db_op_t* _o,
const db_val_t* _v, const db_key_t* _uk, const db_val_t* _uv, const int _n,
const int _un, int (*val2str) (const db_con_t*, const db_val_t*, char*, int*),
int (*submit_query)(const db_con_t* _h, const str* _c))
{
int off, ret;
if (!_h || !_uk || !_uv || !_un || !val2str || !submit_query) {
LM_ERR("invalid parameter value\n");
goto err_exit;
}
ret = snprintf(sql_buf, SQL_BUF_LEN, "update %.*s set ", CON_TABLE(_h)->len, CON_TABLE(_h)->s);
if (ret < 0 || ret >= SQL_BUF_LEN) goto error;
off = ret;
ret = db_print_set(_h, sql_buf + off, SQL_BUF_LEN - off, _uk, _uv, _un, val2str);
if (ret < 0) goto err_exit;
off += ret;
if (_n) {
ret = snprintf(sql_buf + off, SQL_BUF_LEN - off, " where ");
if (ret < 0 || ret >= (SQL_BUF_LEN - off)) goto error;
off += ret;
ret = db_print_where(_h, sql_buf + off, SQL_BUF_LEN - off, _k, _o, _v, _n, val2str);
if (ret < 0) goto err_exit;
off += ret;
}
if (off + 1 > SQL_BUF_LEN) goto error;
sql_buf[off] = '\0';
sql_str.s = sql_buf;
sql_str.len = off;
if (submit_query(_h, &sql_str) < 0) {
LM_ERR("error while submitting query\n");
CON_OR_RESET(_h);
return -2;
}
CON_OR_RESET(_h);
return 0;
error:
LM_ERR("error while preparing update operation\n");
err_exit:
CON_OR_RESET(_h);
return -1;
}
示例8: db_do_insert_cmd
int db_do_insert_cmd(const db1_con_t* _h, const db_key_t* _k, const db_val_t* _v,
const int _n, int (*val2str) (const db1_con_t*, const db_val_t*, char*, int*),
int (*submit_query)(const db1_con_t* _h, const str* _c), int mode)
{
int off, ret;
if (!_h || !_k || !_v || !_n || !val2str || !submit_query) {
LM_ERR("invalid parameter value\n");
return -1;
}
if(mode==1)
ret = snprintf(sql_buf, sql_buffer_size, "insert delayed into %s%.*s%s (",
CON_TQUOTESZ(_h), CON_TABLE(_h)->len, CON_TABLE(_h)->s, CON_TQUOTESZ(_h));
else
ret = snprintf(sql_buf, sql_buffer_size, "insert into %s%.*s%s (",
CON_TQUOTESZ(_h), CON_TABLE(_h)->len, CON_TABLE(_h)->s, CON_TQUOTESZ(_h));
if (ret < 0 || ret >= sql_buffer_size) goto error;
off = ret;
ret = db_print_columns(sql_buf + off, sql_buffer_size - off, _k, _n, CON_TQUOTESZ(_h));
if (ret < 0) return -1;
off += ret;
ret = snprintf(sql_buf + off, sql_buffer_size - off, ") values (");
if (ret < 0 || ret >= (sql_buffer_size - off)) goto error;
off += ret;
ret = db_print_values(_h, sql_buf + off, sql_buffer_size - off, _v, _n, val2str);
if (ret < 0) return -1;
off += ret;
if (off + 2 > sql_buffer_size) goto error;
sql_buf[off++] = ')';
sql_buf[off] = '\0';
sql_str.s = sql_buf;
sql_str.len = off;
if (db_do_submit_query(_h, &sql_str, submit_query) < 0) {
LM_ERR("error while submitting query\n");
return -2;
}
return 0;
error:
LM_ERR("error while preparing insert operation\n");
return -1;
}
示例9: db_oracle_update
/*
* Update some rows in the specified table
* _h: structure representing database connection
* _k: key names
* _o: operators
* _v: values of the keys that must match
* _uk: updated columns
* _uv: updated values of the columns
* _n: number of key=value pairs
* _un: number of columns to update
*/
int db_oracle_update(const db_con_t* _h, const db_key_t* _k, const db_op_t* _o,
const db_val_t* _v, const db_key_t* _uk, const db_val_t* _uv,
int _n, int _un)
{
query_data_t cb;
int rc;
if (!_h || !CON_TABLE(_h)) {
LM_ERR("invalid parameter value\n");
return -1;
}
cb._rs = NULL;
cb._v = _uv;
cb._n = _un;
cb._w = _v;
cb._nw = _n;
CON_ORA(_h)->pqdata = &cb;
CON_ORA(_h)->bindpos = 0;
CON_RESET_CURR_PS(_h); /* no prepared statements support */
rc = db_do_update(_h, _k, _o, _v, _uk, _uv, _n, _un,
db_oracle_val2str, db_oracle_submit_query);
CON_ORA(_h)->pqdata = NULL; /* paranoid for next call */
return rc;
}
示例10: db_mysql_delete
/*
* Delete a row from the specified table
* _h: structure representing database connection
* _k: key names
* _o: operators
* _v: values of the keys that must match
* _n: number of key=value pairs
*/
int db_mysql_delete(db_con_t* _h, db_key_t* _k, db_op_t* _o, db_val_t* _v, int _n)
{
int off, ret;
if (!_h) {
LM_ERR("invalid parameter value\n");
return -1;
}
ret = snprintf(sql_buf, SQL_BUF_LEN, "delete from %s", CON_TABLE(_h));
if (ret < 0 || ret >= SQL_BUF_LEN) goto error;
off = ret;
if (_n) {
ret = snprintf(sql_buf + off, SQL_BUF_LEN - off, " where ");
if (ret < 0 || ret >= (SQL_BUF_LEN - off)) goto error;
off += ret;
ret = db_print_where(_h, sql_buf + off,
SQL_BUF_LEN - off, _k, _o, _v, _n, val2str);
if (ret < 0) return -1;
off += ret;
}
*(sql_buf + off) = '\0';
if (db_mysql_submit_query(_h, sql_buf) < 0) {
LM_ERR("error while submitting query\n");
return -2;
}
return 0;
error:
LM_ERR("error in snprintf\n");
return -1;
}
示例11: db_oracle_query
/*
* Query table for specified rows
* _h: structure representing database connection
* _k: key names
* _op: operators
* _v: values of the keys that must match
* _c: column names to return
* _n: number of key=values pairs to compare
* _nc: number of columns to return
* _o: order by the specified column
*/
int db_oracle_query(const db1_con_t* _h, const db_key_t* _k, const db_op_t* _op,
const db_val_t* _v, const db_key_t* _c, int _n, int _nc,
const db_key_t _o, db1_res_t** _r)
{
query_data_t cb;
OCIStmt* reshp;
int rc;
if (!_h || !CON_TABLE(_h) || !_r) {
LM_ERR("invalid parameter value\n");
return -1;
}
cb._rs = &reshp;
cb._v = _v;
cb._n = _n;
cb._w = NULL;
cb._nw = 0;
CON_ORA(_h)->pqdata = &cb;
CON_ORA(_h)->bindpos = 0;
rc = db_do_query(_h, _k, _op, _v, _c, _n, _nc, _o, _r,
db_oracle_val2str, db_oracle_submit_query, db_oracle_store_result);
CON_ORA(_h)->pqdata = NULL; /* paranoid for next call */
return rc;
}
示例12: flat_use_table
/*
* Store name of table that will be used by
* subsequent database functions
*/
int flat_use_table(db_con_t* h, const str* t)
{
struct flat_con* con;
if (!h || !t || !t->s) {
LM_ERR("invalid parameter value\n");
return -1;
}
if (!CON_TAIL(h) || !(CON_FILENAME(h).len == t->len &&
!memcmp(CON_FILENAME(h).s, t->s, t->len))) {
if (CON_TAIL(h)) {
/* Decrement the reference count
* of the connection but do not remove
* it from the connection pool
*/
con = (struct flat_con*)CON_TAIL(h);
con->ref--;
}
CON_TAIL(h) = (unsigned long)
flat_get_connection(CON_TABLE(h), t);
if (!CON_TAIL(h)) {
return -1;
}
}
return 0;
}
示例13: bdb_use_table
int bdb_use_table(db_con_t* _h, const char* _t)
{
if ((!_h) || (!_t))
return -1;
CON_TABLE(_h) = _t;
return 0;
}
示例14: db_do_replace
int db_do_replace( db_con_t* _h, db_key_t* _k, db_val_t* _v,
int _n, int (*val2str) ( db_con_t*, db_val_t*, char*,
int*), int (*submit_query)( db_con_t* _h, str* _c))
{
int off, ret;
str sql_str;
char sql_buf[SQL_BUF_LEN];
if (!_h || !_k || !_v || !val2str|| !submit_query) {
LM_ERR("invalid parameter value\n");
return -1;
}
ret = snprintf(sql_buf, SQL_BUF_LEN, "replace %.*s (", CON_TABLE(_h)->len, CON_TABLE(_h)->s);
if (ret < 0 || ret >= SQL_BUF_LEN) goto error;
off = ret;
ret = db_print_columns(sql_buf + off, SQL_BUF_LEN - off, _k, _n);
if (ret < 0) return -1;
off += ret;
ret = snprintf(sql_buf + off, SQL_BUF_LEN - off, ") values (");
if (ret < 0 || ret >= (SQL_BUF_LEN - off)) goto error;
off += ret;
ret = db_print_values(_h, sql_buf + off, SQL_BUF_LEN - off, _v, _n,
val2str);
if (ret < 0) return -1;
off += ret;
if (off + 2 > SQL_BUF_LEN) goto error;
sql_buf[off++] = ')';
sql_buf[off] = '\0';
sql_str.s = sql_buf;
sql_str.len = off;
if (submit_query(_h, &sql_str) < 0) {
LM_ERR("error while submitting query\n");
return -2;
}
return 0;
error:
LM_ERR("error while preparing replace operation\n");
return -1;
}
示例15: db_do_update
int db_do_update(const db1_con_t* _h, const db_key_t* _k, const db_op_t* _o,
const db_val_t* _v, const db_key_t* _uk, const db_val_t* _uv, const int _n,
const int _un, int (*val2str) (const db1_con_t*, const db_val_t*, char*, int*),
int (*submit_query)(const db1_con_t* _h, const str* _c))
{
int off, ret;
if (!_h || !_uk || !_uv || !_un || !val2str || !submit_query) {
LM_ERR("invalid parameter value\n");
return -1;
}
ret = snprintf(sql_buf, sql_buffer_size, "update %s%.*s%s set ",
CON_TQUOTESZ(_h), CON_TABLE(_h)->len, CON_TABLE(_h)->s, CON_TQUOTESZ(_h));
if (ret < 0 || ret >= sql_buffer_size) goto error;
off = ret;
ret = db_print_set(_h, sql_buf + off, sql_buffer_size - off, _uk, _uv, _un, val2str);
if (ret < 0) return -1;
off += ret;
if (_n) {
ret = snprintf(sql_buf + off, sql_buffer_size - off, " where ");
if (ret < 0 || ret >= (sql_buffer_size - off)) goto error;
off += ret;
ret = db_print_where(_h, sql_buf + off, sql_buffer_size - off, _k, _o, _v, _n, val2str);
if (ret < 0) return -1;
off += ret;
}
if (off + 1 > sql_buffer_size) goto error;
sql_buf[off] = '\0';
sql_str.s = sql_buf;
sql_str.len = off;
if (db_do_submit_query(_h, &sql_str, submit_query) < 0) {
LM_ERR("error while submitting query\n");
return -2;
}
return 0;
error:
LM_ERR("error while preparing update operation\n");
return -1;
}