本文整理汇总了C++中PQexecPrepared函数的典型用法代码示例。如果您正苦于以下问题:C++ PQexecPrepared函数的具体用法?C++ PQexecPrepared怎么用?C++ PQexecPrepared使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PQexecPrepared函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PQexecPrepared_stub
CAMLprim value PQexecPrepared_stub(
value v_conn, value v_stm_name, value v_params, value v_binary_params)
{
CAMLparam1(v_conn);
PGconn *conn = get_conn(v_conn);
np_callback *np_cb = get_conn_cb(v_conn);
PGresult *res;
size_t len = caml_string_length(v_stm_name) + 1;
char *stm_name = caml_stat_alloc(len);
size_t nparams = Wosize_val(v_params);
const char * const *params = copy_params(v_params, nparams);
int *formats, *lengths;
copy_binary_params(v_params, v_binary_params, nparams, &formats, &lengths);
memcpy(stm_name, String_val(v_stm_name), len);
caml_enter_blocking_section();
res = PQexecPrepared(conn, stm_name, nparams, params, lengths, formats, 0);
free(stm_name);
free_binary_params(formats, lengths);
free_params(params, nparams);
caml_leave_blocking_section();
CAMLreturn(alloc_result(res, np_cb));
#else
CAMLprim value PQexecPrepared_stub(
value __unused v_conn, value __unused v_stm_name, value __unused v_params,
value __unused v_binary_params)
{
caml_failwith("Postgresql.exec_prepared: not supported");
return Val_unit;
#endif
}
示例2: htonl64
void PgTblFmncMUsergroup::updateRec(
FmncMUsergroup* rec
) {
PGresult* res;
ubigint _grp = htonl64(rec->grp);
ubigint _own = htonl64(rec->own);
ubigint _ref = htonl64(rec->ref);
const char* vals[] = {
(char*) &_grp,
(char*) &_own,
rec->sref.c_str(),
rec->Comment.c_str(),
(char*) &_ref
};
const int l[] = {
sizeof(ubigint),
sizeof(ubigint),
0,
0,
sizeof(ubigint)
};
const int f[] = {1, 1, 0, 0, 1};
res = PQexecPrepared(dbs, "TblFmncMUsergroup_updateRec", 5, vals, l, f, 0);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
throw DbsException("DbsException / PgSQL: error executing statement! (TblFmncMUsergroup_updateRec)\n");
PQclear(res);
};
示例3: db_select1
void db_select1(int32_t* value) {
if (debug) {
fprintf(stderr, "db_select1()\n");
}
PGresult* res = PQexecPrepared(conn,
STMT_ID_SELECT1,
0,
NULL,
NULL,
NULL,
1);
CHECK_RESULT(res);
*value = -1;
if (PQntuples(res) == 0) {
fprintf(stderr, "db_select1() return no rows\n");
if (exit_on_error) {
exit(EXIT_FAILURE);
}
PQclear(res);
} else {
*value = ntohl(*(int32_t *) PQgetvalue(res, 0, 0));
if (debug) {
fprintf(stderr, "db_select1() return %d\n", *value);
}
}
PQclear(res);
}
示例4: htonl64
void PgTblFmncQSelect::updateRec(
FmncQSelect* rec
) {
PGresult* res;
ubigint _jref = htonl64(rec->jref);
uint _jnum = htonl(rec->jnum);
uint _ix = htonl(rec->ix);
ubigint _ref = htonl64(rec->ref);
ubigint _qref = htonl64(rec->qref);
const char* vals[] = {
(char*) &_jref,
(char*) &_jnum,
(char*) &_ix,
(char*) &_ref,
(char*) &_qref
};
const int l[] = {
sizeof(ubigint),
sizeof(uint),
sizeof(uint),
sizeof(ubigint),
sizeof(ubigint)
};
const int f[] = {1, 1, 1, 1, 1};
res = PQexecPrepared(dbs, "TblFmncQSelect_updateRec", 5, vals, l, f, 0);
if (PQresultStatus(res) != PGRES_COMMAND_OK) throw DbsException("DbsException / PgSQL: error executing statement! (TblFmncQSelect_updateRec)\n");
PQclear(res);
};
示例5: htonl64
void PgTblPlnrRMStackMStructure::updateRec(
PlnrRMStackMStructure* rec
) {
PGresult* res;
ubigint _refPlnrMStack = htonl64(rec->refPlnrMStack);
ubigint _refPlnrMStructure = htonl64(rec->refPlnrMStructure);
ubigint _ref = htonl64(rec->ref);
const char* vals[] = {
(char*) &_refPlnrMStack,
(char*) &_refPlnrMStructure,
rec->fromSrefPlnrMLayer.c_str(),
rec->toSrefPlnrMLayer.c_str(),
(char*) &_ref
};
const int l[] = {
sizeof(ubigint),
sizeof(ubigint),
0,
0,
sizeof(ubigint)
};
const int f[] = {1, 1, 0, 0, 1};
res = PQexecPrepared(dbs, "TblPlnrRMStackMStructure_updateRec", 5, vals, l, f, 0);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
throw DbsException("DbsException / PgSQL: error executing statement! (TblPlnrRMStackMStructure_updateRec)\n");
PQclear(res);
};
示例6: PrepareQuery
void PgStatement::ExecutePrepared(const ArrayRecord& raParameters)
{
if(pgr == NULL)
PrepareQuery(raParameters);
else
CleanUpResult();
PgParameters pgp(raParameters);
int * pnParamFormats = pgp.GetParamFormats();
try
{
pgr = PQexecPrepared
(
pg->conn,
sQueryHandle.mbc_str(),
pgp.GetParamCount(),
pgp.GetParamValues(),
pgp.GetParamLengths(),
pnParamFormats,
0
);
}
catch(...)
{
ThrowPgError(wxT("PgStatement::ExecutePrepared() Query caused exception: %s."));
}
ExecStatusType exs = PQresultStatus(pgr);
if(exs == PGRES_FATAL_ERROR)
ThrowPgError(wxT("PgStatement::ExecutePrepared() Query execution failed: %s."));
nCurrentRecord = 0;
}
示例7: execPrepared
static PGresult *
execPrepared(char *qName, List *values)
{
char **params;
int i;
int nParams = LIST_LENGTH(values);
PGresult *res = NULL;
params = CALLOC(sizeof(char*),LIST_LENGTH(values));
ASSERT(postgresIsInitialized());
i = 0;
FOREACH(Constant,c,values)
params[i++] = STRING_VALUE(c);
DEBUG_LOG("run query %s with parameters <%s>",
qName, exprToSQL((Node *) values));
res = PQexecPrepared(plugin->conn,
qName,
nParams,
(const char *const *) params,
NULL,
NULL,
0);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
CLOSE_RES_CONN_AND_FATAL(res, "query %s failed:\n%s", qName,
PQresultErrorMessage(res));
return res;
}
示例8: htonl64
void PgTblPlnrAMUserAccess::updateRec(
PlnrAMUserAccess* rec
) {
PGresult* res;
ubigint _refPlnrMUser = htonl64(rec->refPlnrMUser);
uint _x1IxPlnrVCard = htonl(rec->x1IxPlnrVCard);
uint _ixPlnrWUiaccess = htonl(rec->ixPlnrWUiaccess);
ubigint _ref = htonl64(rec->ref);
const char* vals[] = {
(char*) &_refPlnrMUser,
(char*) &_x1IxPlnrVCard,
(char*) &_ixPlnrWUiaccess,
(char*) &_ref
};
const int l[] = {
sizeof(ubigint),
sizeof(uint),
sizeof(uint),
sizeof(ubigint)
};
const int f[] = {1, 1, 1, 1};
res = PQexecPrepared(dbs, "TblPlnrAMUserAccess_updateRec", 4, vals, l, f, 0);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
throw DbsException("DbsException / PgSQL: error executing statement! (TblPlnrAMUserAccess_updateRec)\n");
PQclear(res);
};
示例9: htonl64
void PgTblPlnrAccRMUserUniversal::updateRec(
PlnrAccRMUserUniversal* rec
) {
PGresult* res;
ubigint _refPlnrMUser = htonl64(rec->refPlnrMUser);
uint _unvIxPlnrVMaintable = htonl(rec->unvIxPlnrVMaintable);
ubigint _unvUref = htonl64(rec->unvUref);
uint _ixPlnrVAccess = htonl(rec->ixPlnrVAccess);
ubigint _ref = htonl64(rec->ref);
const char* vals[] = {
(char*) &_refPlnrMUser,
(char*) &_unvIxPlnrVMaintable,
(char*) &_unvUref,
(char*) &_ixPlnrVAccess,
(char*) &_ref
};
const int l[] = {
sizeof(ubigint),
sizeof(uint),
sizeof(ubigint),
sizeof(uint),
sizeof(ubigint)
};
const int f[] = {1, 1, 1, 1, 1};
res = PQexecPrepared(dbs, "TblPlnrAccRMUserUniversal_updateRec", 5, vals, l, f, 0);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
throw DbsException("DbsException / PgSQL: error executing statement! (TblPlnrAccRMUserUniversal_updateRec)\n");
PQclear(res);
};
示例10: fill_query_column_types
void fill_query_column_types(pgsnmpd_query *query)
{
int i;
Oid type; /* NB! PostgreSQL's Oid, not Net-SNMP's oid */
PGresult *res;
const char *values[1];
char param[10];
/* This translates SQL types to SNMP types, as follows:
* Conversions for these four types are obvious
* ASN_INTEGER
* ASN_FLOAT
* ASN_BOOLEAN
* ASN_OBJECT_ID
*
* Everything else becomes a string:
* ASN_OCTET_STR
*
* Perhaps one day we'll also use ASN_DOUBLE
*/
if (query->result == NULL)
return;
values[0] = param;
for (i = 0; i < query->colcount; i++) {
if (query->types[i] != 255) {
continue;
}
type = PQftype(query->result, i);
/*
* TODO: query pg_type table (including pg_type.h to use builtin
* constants got all kinds of errors I'd rather not deal with
*/
sprintf(param, "%d", type);
res = PQexecPrepared(dbconn, "TYPEQUERY", 1, values, NULL, NULL, 0);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
snmp_log(LOG_ERR, "Couldn't determine column type\n");
else {
switch (atoi(PQgetvalue(res, 0, 0))) {
case 0:
query->types[i] = ASN_INTEGER;
break;
case 1:
query->types[i] = ASN_FLOAT;
break;
case 2:
query->types[i] = ASN_BOOLEAN;
break;
case 3:
query->types[i] = ASN_OCTET_STR;
break;
default: /* If we get here, it's because the TYPEQUERY is b0rken */
snmp_log(LOG_ERR, "Unknown column type translation. This is a bug.\n");
}
}
PQclear(res);
}
}
示例11: htonl64
void PgTblFmncAMToolChar::updateRec(
FmncAMToolChar* rec
) {
PGresult* res;
ubigint _refFmncMTool = htonl64(rec->refFmncMTool);
ubigint _ref = htonl64(rec->ref);
const char* vals[] = {
(char*) &_refFmncMTool,
rec->x1OsrefFmncKToolchar.c_str(),
rec->Val.c_str(),
rec->Comment.c_str(),
(char*) &_ref
};
const int l[] = {
sizeof(ubigint),
0,
0,
0,
sizeof(ubigint)
};
const int f[] = {1, 0, 0, 0, 1};
res = PQexecPrepared(dbs, "TblFmncAMToolChar_updateRec", 5, vals, l, f, 0);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
throw DbsException("DbsException / PgSQL: error executing statement! (TblFmncAMToolChar_updateRec)\n");
PQclear(res);
};
示例12: htonl64
void PgTblPlnrQPrjList::updateRec(
PlnrQPrjList* rec
) {
PGresult* res;
ubigint _jref = htonl64(rec->jref);
uint _jnum = htonl(rec->jnum);
ubigint _ref = htonl64(rec->ref);
uint _ixVState = htonl(rec->ixVState);
ubigint _qref = htonl64(rec->qref);
const char* vals[] = {
(char*) &_jref,
(char*) &_jnum,
(char*) &_ref,
rec->Title.c_str(),
(char*) &_ixVState,
(char*) &_qref
};
const int l[] = {
sizeof(ubigint),
sizeof(uint),
sizeof(ubigint),
0,
sizeof(uint),
sizeof(ubigint)
};
const int f[] = {1, 1, 1, 0, 1, 1};
res = PQexecPrepared(dbs, "TblPlnrQPrjList_updateRec", 6, vals, l, f, 0);
if (PQresultStatus(res) != PGRES_COMMAND_OK) throw DbsException("DbsException / PgSQL: error executing statement! (TblPlnrQPrjList_updateRec)\n");
PQclear(res);
};
示例13: htonl64
void PgTblFmncJMRunState::updateRec(
FmncJMRunState* rec
) {
PGresult* res;
ubigint _refFmncMRun = htonl64(rec->refFmncMRun);
uint _x1Start = htonl(rec->x1Start);
uint _ixVState = htonl(rec->ixVState);
ubigint _ref = htonl64(rec->ref);
const char* vals[] = {
(char*) &_refFmncMRun,
(char*) &_x1Start,
(char*) &_ixVState,
(char*) &_ref
};
const int l[] = {
sizeof(ubigint),
sizeof(uint),
sizeof(uint),
sizeof(ubigint)
};
const int f[] = {1, 1, 1, 1};
res = PQexecPrepared(dbs, "TblFmncJMRunState_updateRec", 4, vals, l, f, 0);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
throw DbsException("DbsException / PgSQL: error executing statement! (TblFmncJMRunState_updateRec)\n");
PQclear(res);
};
示例14: db_list_contains
int db_list_contains(brain_t brain, enum list type, word_t word) {
PGresult *res;
const char *param[3];
char tmp[3][32];
if (brain == 0 || word == 0) return -EINVAL;
if (db_connect())
return -EDB;
SET_PARAM(param, tmp, 0, brain);
SET_PARAM(param, tmp, 1, type);
SET_PARAM(param, tmp, 2, word);
res = PQexecPrepared(conn, "list_get", 3, param, NULL, NULL, 0);
if (PQresultStatus(res) != PGRES_TUPLES_OK) goto fail;
if (PQntuples(res) == 0) goto not_found;
PQclear(res);
return OK;
fail:
log_error("db_list_contains", PQresultStatus(res), PQresultErrorMessage(res));
PQclear(res);
return -EDB;
not_found:
PQclear(res);
return -ENOTFOUND;
}
示例15: sparams
int postgresql_statement::execute(const vector<shared_ptr<sql_value> > &args)
{
int n=args.size();
vector<shared_ptr<string> > sparams(n);
vector<const char *> params(n);
vector<int> param_lens(n);
for (int i=0;i<n;i++){
sparams[i]=sql_to_str(args[i]);
if (sparams[i]){
params[i]=sparams[i]->c_str();
param_lens[i]=sparams[i]->length();
}
else{
params[i]=NULL;
param_lens[i]=0;
}
}
PGresult *r=PQexecPrepared(conn->get(), "", n, ¶ms[0], ¶m_lens[0], NULL, 0);
if (r==NULL)
throw database_error("PQexecPrepared failed");
shared_ptr<postgresql_result> rtmp=
shared_ptr<postgresql_result>(new postgresql_result(r));
if (!rtmp->command_ok() &&
!rtmp->tuple_ok())
throw database_error(PQresultErrorMessage(rtmp->get()));
res.swap(rtmp);
// TODO: return modified row count
return 0;
}