本文整理汇总了C++中DB_GET_PAYLOAD函数的典型用法代码示例。如果您正苦于以下问题:C++ DB_GET_PAYLOAD函数的具体用法?C++ DB_GET_PAYLOAD怎么用?C++ DB_GET_PAYLOAD使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DB_GET_PAYLOAD函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bdb_cmd_exec
int bdb_cmd_exec(db_res_t *res, db_cmd_t *cmd)
{
db_con_t *con;
bdb_cmd_t *bcmd;
bdb_con_t *bcon;
/* First things first: retrieve connection info from the currently active
* connection and also mysql payload from the database command
*/
con = cmd->ctx->con[db_payload_idx];
bcmd = DB_GET_PAYLOAD(cmd);
bcon = DB_GET_PAYLOAD(con);
if((bcon->flags & BDB_CONNECTED) == 0) {
ERR("bdb: not connected\n");
return -1;
}
bcmd->next_flag = -1;
switch(cmd->type) {
case DB_DEL:
case DB_PUT:
case DB_UPD:
/* no result expected - cleanup */
DBG("bdb: query with no result.\n");
break;
case DB_GET:
return bdb_query(cmd, bcmd);
break;
default:
/* result expected - no cleanup */
DBG("bdb: query with result.\n");
}
return 0;
}
示例2: my_con_connect
int my_con_connect(db_con_t* con)
{
struct my_con* mcon;
struct my_uri* muri;
mcon = DB_GET_PAYLOAD(con);
muri = DB_GET_PAYLOAD(con->uri);
/* Do not reconnect already connected connections */
if (mcon->flags & MY_CONNECTED) return 0;
DBG("mysql: Connecting to %.*s:%.*s\n",
con->uri->scheme.len, ZSW(con->uri->scheme.s),
con->uri->body.len, ZSW(con->uri->body.s));
if (my_connect_to) {
if (mysql_options(mcon->con, MYSQL_OPT_CONNECT_TIMEOUT,
(char*)&my_connect_to))
WARN("mysql: failed to set MYSQL_OPT_CONNECT_TIMEOUT\n");
}
#if MYSQL_VERSION_ID >= 40101
if ((my_client_ver >= 50025) ||
((my_client_ver >= 40122) &&
(my_client_ver < 50000))) {
if (my_send_to) {
if (mysql_options(mcon->con, MYSQL_OPT_WRITE_TIMEOUT ,
(char*)&my_send_to))
WARN("mysql: failed to set MYSQL_OPT_WRITE_TIMEOUT\n");
}
if (my_recv_to){
if (mysql_options(mcon->con, MYSQL_OPT_READ_TIMEOUT ,
(char*)&my_recv_to))
WARN("mysql: failed to set MYSQL_OPT_READ_TIMEOUT\n");
}
}
#endif
if (!mysql_real_connect(mcon->con, muri->host, muri->username,
muri->password, muri->database, muri->port, 0, 0)) {
LOG(L_ERR, "mysql: %s\n", mysql_error(mcon->con));
return -1;
}
DBG("mysql: Connection type is %s\n", mysql_get_host_info(mcon->con));
DBG("mysql: Protocol version is %d\n", mysql_get_proto_info(mcon->con));
DBG("mysql: Server version is %s\n", mysql_get_server_info(mcon->con));
mcon->flags |= MY_CONNECTED;
/* Increase the variable that keeps track of number of connects performed
* on this connection. The mysql module uses the variable to determine
* when a pre-compiled command needs to be uploaded to the server again.
* If the number in the my_con structure is large than the number kept
* in my_cmd then it means that we have to upload the command to the server
* again because the connection was reconnected meanwhile.
*/
mcon->resets++;
return 0;
}
示例3: bdb_con_connect
int bdb_con_connect(db_con_t* con)
{
bdb_con_t *bcon;
bdb_uri_t *buri;
bcon = DB_GET_PAYLOAD(con);
buri = DB_GET_PAYLOAD(con->uri);
/* Do not reconnect already connected connections */
if (bcon->flags & BDB_CONNECTED) return 0;
DBG("bdb: Connecting to %s\n", buri->uri);
/* create BDB environment */
bcon->dbp = bdblib_get_db(&buri->path);
if(bcon->dbp == NULL)
{
ERR("bdb: error binding to DB %s\n", buri->uri);
return -1;
}
DBG("bdb: Successfully bound to %s\n", buri->uri);
bcon->flags |= BDB_CONNECTED;
return 0;
}
示例4: my_con_connect
int my_con_connect(db_con_t* con)
{
struct my_con* mcon;
struct my_uri* muri;
mcon = DB_GET_PAYLOAD(con);
muri = DB_GET_PAYLOAD(con->uri);
/* Do not reconnect already connected connections */
if (mcon->flags & MY_CONNECTED) return 0;
DBG("mysql: Connecting to %.*s:%.*s\n",
con->uri->scheme.len, ZSW(con->uri->scheme.s),
con->uri->body.len, ZSW(con->uri->body.s));
if (my_connect_to) {
if (mysql_options(mcon->con, MYSQL_OPT_CONNECT_TIMEOUT,
(char*)&my_connect_to))
WARN("mysql: failed to set MYSQL_OPT_CONNECT_TIMEOUT\n");
}
#if MYSQL_VERSION_ID >= 40101
if ((my_client_ver >= 50025) ||
((my_client_ver >= 40122) &&
(my_client_ver < 50000))) {
if (my_send_to) {
if (mysql_options(mcon->con, MYSQL_OPT_WRITE_TIMEOUT ,
(char*)&my_send_to))
WARN("mysql: failed to set MYSQL_OPT_WRITE_TIMEOUT\n");
}
if (my_recv_to){
if (mysql_options(mcon->con, MYSQL_OPT_READ_TIMEOUT ,
(char*)&my_recv_to))
WARN("mysql: failed to set MYSQL_OPT_READ_TIMEOUT\n");
}
}
#endif
if (!mysql_real_connect(mcon->con, muri->host, muri->username,
muri->password, muri->database, muri->port, 0, 0)) {
LOG(L_ERR, "mysql: %s\n", mysql_error(mcon->con));
return -1;
}
DBG("mysql: Connection type is %s\n", mysql_get_host_info(mcon->con));
DBG("mysql: Protocol version is %d\n", mysql_get_proto_info(mcon->con));
DBG("mysql: Server version is %s\n", mysql_get_server_info(mcon->con));
mcon->flags |= MY_CONNECTED;
return 0;
}
示例5: check_types
/** Verify field type compatibility.
* This function verifies the types of all parameters of a database command
* with the types of corresponding fields on the server to make sure that they
* can be converted.
* @param cmd A command structure whose parameters are to be checked.
* @retval 0 on success.
* @retval A negative number if at least one field type does not match.
* @todo Store oid and length as part of pg_fld, instead of the arrays used
* as parameters to PQ functions
*/
static int check_types(db_cmd_t* cmd)
{
struct pg_cmd* pcmd;
struct pg_con* pcon;
pcmd = DB_GET_PAYLOAD(cmd);
/* FIXME: The function should take the connection as one of parameters */
pcon = DB_GET_PAYLOAD(cmd->ctx->con[db_payload_idx]);
if (pg_check_fld2pg(cmd->match, pcon->oid)) return -1;
if (pg_check_fld2pg(cmd->vals, pcon->oid)) return -1;
if (pg_check_pg2fld(cmd->result, pcon->oid)) return -1;
return 0;
}
示例6: ld_uri_cmp
/** Compares two LDAP connection URIs.
* This function is called whenever the database abstraction layer in
* SER needs to compare to URIs with the ldap scheme. The function
* compares hosts and port numbers of both URIs (host part comparison
* is case insensitive). The URI comparison is mainly used to
* by the connection pool to determine if a connection to a given
* server already exists.
**/
static unsigned char ld_uri_cmp(db_uri_t* uri1, db_uri_t* uri2)
{
struct ld_uri* luri1, *luri2;
if (!uri1 || !uri2) return 0;
luri1 = DB_GET_PAYLOAD(uri1);
luri2 = DB_GET_PAYLOAD(uri2);
if (luri1->ldap_url->lud_port != luri2->ldap_url->lud_port) return 0;
if (cmpstr(luri1->ldap_url->lud_host,
luri2->ldap_url->lud_host, strcasecmp))
return 0;
return 1;
}
示例7: create_pg_params
/** Creates parameter data structures for PQexecPrepared.
* This function creates auxiliary data structures that will be used to pass
* parameter value and types to PQexecPrepared. The function only allocates
* memory buffers and determines oids of parameters, actual values will be
* assigned by another function at runtime.
* @param cmd A command where the data strctures will be created.
* @retval 0 on success.
* @retval A negative number on error.
*/
static int create_pg_params(db_cmd_t* cmd)
{
int num;
struct pg_cmd* pcmd;
pcmd = DB_GET_PAYLOAD(cmd);
num = cmd->match_count + cmd->vals_count;
if (num == 0) return 0;
pcmd->params.val = (const char**)pkg_malloc(sizeof(const char*) * num);
pcmd->params.len = (int*)pkg_malloc(sizeof(int) * num);
pcmd->params.fmt = (int*)pkg_malloc(sizeof(int) * num);
if (!pcmd->params.val ||
!pcmd->params.len || !pcmd->params.fmt) {
ERR("postgres: No memory left\n");
goto error;
}
memset(pcmd->params.val, '\0', sizeof(const char*) * num);
memset(pcmd->params.len, '\0', sizeof(int) * num);
memset(pcmd->params.fmt, '\0', sizeof(int) * num);
pcmd->params.n = num;
return 0;
error:
free_pg_params(&pcmd->params);
return -1;
}
示例8: my_getopt
int my_getopt(db_cmd_t* cmd, char* optname, va_list ap)
{
struct my_cmd* mcmd;
long long* id;
int* val;
mcmd = (struct my_cmd*)DB_GET_PAYLOAD(cmd);
if (!strcasecmp("last_id", optname)) {
id = va_arg(ap, long long*);
if (id == NULL) {
BUG("mysql: NULL pointer passed to 'last_id' option\n");
goto error;
}
if (mcmd->st->last_errno != 0) {
BUG("mysql: Option 'last_id' called but previous command failed, "
"check your code\n");
return -1;
}
*id = mysql_stmt_insert_id(mcmd->st);
if ((*id) == 0) {
BUG("mysql: Option 'last_id' called but there is no auto-increment"
" column in table, SQL command: %.*s\n", STR_FMT(&mcmd->sql_cmd));
return -1;
}
} else if (!strcasecmp("fetch_all", optname)) {
示例9: pg_uri_cmp
/** Compare two connection URIs */
static unsigned char pg_uri_cmp(db_uri_t* uri1, db_uri_t* uri2)
{
struct pg_uri* puri1, *puri2;
if (!uri1 || !uri2) return 0;
puri1 = DB_GET_PAYLOAD(uri1);
puri2 = DB_GET_PAYLOAD(uri2);
if (puri1->port != puri2->port) return 0;
if (cmpstr(puri1->username, puri2->username, strcmp)) return 0;
if (cmpstr(puri1->password, puri2->password, strcmp)) return 0;
if (cmpstr(puri1->host, puri2->host, strcasecmp)) return 0;
if (cmpstr(puri1->database, puri2->database, strcmp)) return 0;
return 1;
}
示例10: build_result_array
static int build_result_array(char*** res, db_cmd_t* cmd)
{
struct ld_fld* lfld;
char** t;
int i;
if (cmd->result_count == 0) {
*res = NULL;
return 0;
}
t = (char**)pkg_malloc(sizeof(char*) * (cmd->result_count + 1));
if (t == NULL) {
ERR("ldap: No memory left\n");
return -1;
}
t[cmd->result_count] = NULL;
for(i = 0; i < cmd->result_count; i++) {
lfld = DB_GET_PAYLOAD(cmd->result + i);
/* Attribute names are always zero terminated */
t[i] = lfld->attr.s;
}
*res = t;
return 0;
}
示例11: my_uri_cmp
/*
* Compare two connection identifiers
*/
static unsigned char my_uri_cmp(db_uri_t* uri1, db_uri_t* uri2)
{
struct my_uri* muri1, *muri2;
if (!uri1 || !uri2) return 0;
muri1 = DB_GET_PAYLOAD(uri1);
muri2 = DB_GET_PAYLOAD(uri2);
if (muri1->port != muri2->port) return 0;
if (cmpstr(muri1->username, muri2->username, strcmp)) return 0;
if (cmpstr(muri1->password, muri2->password, strcmp)) return 0;
if (cmpstr(muri1->host, muri2->host, strcasecmp)) return 0;
if (cmpstr(muri1->database, muri2->database, strcmp)) return 0;
return 1;
}
示例12: my_cmd_exec
int my_cmd_exec(db_res_t* res, db_cmd_t* cmd)
{
struct my_cmd* mcmd;
mcmd = DB_GET_PAYLOAD(cmd);
mcmd->next_flag = -1;
return exec_cmd_safe(cmd);
}
示例13: get_types
static int get_types(db_cmd_t* cmd)
{
struct pg_cmd* pcmd;
struct pg_con* pcon;
pcmd = DB_GET_PAYLOAD(cmd);
/* FIXME */
pcon = DB_GET_PAYLOAD(cmd->ctx->con[db_payload_idx]);
pcmd->types = PQdescribePrepared(pcon->con, pcmd->name);
if (PQresultStatus(pcmd->types) != PGRES_COMMAND_OK) {
ERR("postgres: Error while obtaining description of prepared statement\n");
return -1;
}
return 0;
}
示例14: bdb_cmd_next
int bdb_cmd_next(db_res_t* res)
{
bdb_cmd_t *bcmd;
DBT key, data;
int ret;
static char dbuf[MAX_ROW_SIZE];
bcmd = DB_GET_PAYLOAD(res->cmd);
if (bcmd->next_flag == 2 || bcmd->next_flag == -2) return 1;
memset(&key, 0, sizeof(DBT));
memset(&data, 0, sizeof(DBT));
memset(dbuf, 0, MAX_ROW_SIZE);
data.data = dbuf;
data.ulen = MAX_ROW_SIZE;
data.flags = DB_DBT_USERMEM;
ret = 0;
if(bcmd->skey.len==0)
{
while((ret = bcmd->dbcp->c_get(bcmd->dbcp, &key, &data, DB_NEXT))==0)
{
if(!strncasecmp((char*)key.data,"METADATA",8))
continue;
break;
}
if(ret!=0)
{
bcmd->next_flag = bcmd->next_flag<0?-2:2;
return 1;
}
} else {
key.data = bcmd->skey.s;
key.ulen = bcmd->skey_size;
key.flags = DB_DBT_USERMEM;
key.size = bcmd->skey.len;
ret = bcmd->dbcp->c_get(bcmd->dbcp, &key, &data, DB_NEXT);
if(ret!=0)
{
bcmd->next_flag = bcmd->next_flag<0?-2:2;
return 1;
}
}
if (bcmd->next_flag <= 0) {
bcmd->next_flag++;
}
if (bdb_update_result(res->cmd, &data) < 0) {
return -1;
}
res->cur_rec->fld = res->cmd->result;
return 0;
}
示例15: my_con
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;
}