本文整理汇总了C++中PQexecPrepared函数的典型用法代码示例。如果您正苦于以下问题:C++ PQexecPrepared函数的具体用法?C++ PQexecPrepared怎么用?C++ PQexecPrepared使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PQexecPrepared函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:Nevor,项目名称:postgresql-ocaml,代码行数:30,代码来源:postgresql_stubs.c
示例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);
};
开发者ID:epsitech,项目名称:fabmaniac,代码行数:32,代码来源:FmncMUsergroup.cpp
示例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);
}
开发者ID:vvromanov,项目名称:db_test,代码行数:27,代码来源:test_dao_libpq.cpp
示例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);
};
开发者ID:epsitech,项目名称:fabmaniac,代码行数:33,代码来源:FmncQSelect.cpp
示例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);
};
开发者ID:epsitech,项目名称:planar,代码行数:32,代码来源:PlnrRMStackMStructure.cpp
示例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;
}
开发者ID:joeyates,项目名称:sherpa,代码行数:34,代码来源:postgres.cpp
示例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;
}
开发者ID:dayu070,项目名称:GProm,代码行数:32,代码来源:metadata_lookup_postgres.c
示例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);
};
开发者ID:epsitech,项目名称:planar,代码行数:31,代码来源:PlnrAMUserAccess.cpp
示例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);
};
开发者ID:epsitech,项目名称:planar,代码行数:34,代码来源:PlnrAccRMUserUniversal.cpp
示例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);
}
}
开发者ID:GunioRobot,项目名称:pgsnmpd,代码行数:60,代码来源:customquery.c
示例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);
};
开发者ID:epsitech,项目名称:fabmaniac,代码行数:31,代码来源:FmncAMToolChar.cpp
示例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);
};
开发者ID:epsitech,项目名称:planar,代码行数:35,代码来源:PlnrQPrjList.cpp
示例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);
};
开发者ID:epsitech,项目名称:fabmaniac,代码行数:31,代码来源:FmncJMRunState.cpp
示例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;
}
开发者ID:lp0,项目名称:sqlhal,代码行数:30,代码来源:db_list_postgres.c
示例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;
}
开发者ID:beam2d,项目名称:pficommon,代码行数:35,代码来源:statement.cpp
示例16: fsal_posixdb_lockHandleForUpdate
/**
* @brief Lock the line of the Handle table with inode & devid defined in p_info
*
* @param p_conn
* Database connection
* @param p_info
* Information about the file
*
* @return ERR_FSAL_POSIXDB_NOERR if no error,
* another error code else.
*/
fsal_posixdb_status_t fsal_posixdb_lockHandleForUpdate(fsal_posixdb_conn * p_conn, /* IN */
fsal_posixdb_fileinfo_t *
p_info /* IN */ )
{
PGresult *p_res;
char devid_str[MAX_DEVICEIDSTR_SIZE];
char inode_str[MAX_INODESTR_SIZE];
const char *paramValues[2];
CheckConn(p_conn);
BeginTransaction(p_conn, p_res);
snprintf(devid_str, MAX_DEVICEIDSTR_SIZE, "%lli", (long long int)p_info->devid);
snprintf(inode_str, MAX_INODESTR_SIZE, "%lli", (long long int)p_info->inode);
paramValues[0] = devid_str;
paramValues[1] = inode_str;
p_res = PQexecPrepared(p_conn, "lookupHandleByInodeFU", 2, paramValues, NULL, NULL, 0);
CheckResult(p_res);
PQclear(p_res);
/* Do not end the transaction, because it will be closed by the next call to a posixdb function */
ReturnCodeDB(ERR_FSAL_POSIXDB_NOERR, 0);
}
开发者ID:MeghanaM,项目名称:nfs-ganesha,代码行数:36,代码来源:posixdb_lock.c
示例17: db_select
void db_select(int32_t id, int32_t* value) {
if (debug) {
fprintf(stderr, "db_select(%d)\n", id);
}
int32_t _id = htonl(id);
const char* paramValues[] = {
(const char*) &_id,
};
PGresult* res = PQexecPrepared(conn,
STMT_ID_SELECT,
1,
paramValues,
paramLengths,
paramFormats,
1);
CHECK_RESULT(res);
*value = -1;
if (PQntuples(res) == 0) {
fprintf(stderr, "db_select(%d) return no rows\n", id);
if (exit_on_error) {
exit(EXIT_FAILURE);
}
PQclear(res);
} else {
*value = ntohl(*(int32_t *) PQgetvalue(res, 0, 0));
if (debug) {
fprintf(stderr, "db_select(%d) return %d\n", id, *value);
}
}
PQclear(res);
}
开发者ID:vvromanov,项目名称:db_test,代码行数:31,代码来源:test_dao_libpq.cpp
示例18: htonl64
void PgTblFmncSvcRMOrgMTool::updateRec(
FmncSvcRMOrgMTool* rec
) {
PGresult* res;
ubigint _refFmncMOrg = htonl64(rec->refFmncMOrg);
ubigint _refFmncMTool = htonl64(rec->refFmncMTool);
ubigint _ref = htonl64(rec->ref);
const char* vals[] = {
(char*) &_refFmncMOrg,
(char*) &_refFmncMTool,
(char*) &_ref
};
const int l[] = {
sizeof(ubigint),
sizeof(ubigint),
sizeof(ubigint)
};
const int f[] = {1, 1, 1};
res = PQexecPrepared(dbs, "TblFmncSvcRMOrgMTool_updateRec", 3, vals, l, f, 0);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
throw DbsException("DbsException / PgSQL: error executing statement! (TblFmncSvcRMOrgMTool_updateRec)\n");
PQclear(res);
};
开发者ID:epsitech,项目名称:fabmaniac,代码行数:28,代码来源:FmncSvcRMOrgMTool.cpp
示例19: PQclear
query_result sql_database::send_query(connection & c, const query_list & sql, std::string & error)
{
if (sql.size() > 1)
PQclear(PQexec(c.conn, "BEGIN;"));
std::vector<sql_statement> results;
for (auto && query : sql)
{
std::vector<const char *> args;
for (auto && arg : query.args)
args.push_back(arg.c_str());
auto res = PQexecPrepared(c.conn, query.name.c_str(), args.size(), args.data(),
nullptr, nullptr, 0);
auto status = PQresultStatus(res);
if (status == PGRES_FATAL_ERROR)
{
if (sql.size() > 1)
PQclear(PQexec(c.conn, "ROLLBACK;"));
error = "sql query failed due to "_s + PQresultErrorMessage(res)
+ ", query: " + query.name;
PQclear(res);
break;
}
else if (status == PGRES_TUPLES_OK && PQntuples(res) > 0)
results.emplace_back(res, PQnfields(res), PQntuples(res));
else
PQclear(res);
}
if (sql.size() > 1)
PQclear(PQexec(c.conn, "COMMIT;"));
if (!results.empty())
return query_result { std::move(results) };
return { };
}
开发者ID:Ryuuke,项目名称:desperion,代码行数:35,代码来源:sql_database.cpp
示例20: real_query
void real_query()
{
char const * const *pvalues = 0;
int *plengths = 0;
int *pformats = 0;
std::vector<char const *> values;
std::vector<int> lengths;
std::vector<int> formats;
if(params_>0) {
values.resize(params_,0);
lengths.resize(params_,0);
formats.resize(params_,0);
for(unsigned i=0;i<params_;i++) {
if(params_set_[i]!=null_param) {
if(params_pvalues_[i]!=0) {
values[i]=params_pvalues_[i];
lengths[i]=params_plengths_[i];
}
else {
values[i]=params_values_[i].c_str();
lengths[i]=params_values_[i].size();
}
if(params_set_[i]==binary_param) {
formats[i]=1;
}
}
}
pvalues=&values.front();
plengths=&lengths.front();
pformats=&formats.front();
}
if(res_) {
PQclear(res_);
res_ = 0;
}
if(prepared_id_.empty()) {
res_ = PQexecParams(
conn_,
query_.c_str(),
params_,
0, // param types
pvalues,
plengths,
pformats, // format - text
0 // result format - text
);
}
else {
res_ = PQexecPrepared(
conn_,
prepared_id_.c_str(),
params_,
pvalues,
plengths,
pformats, // format - text
0 // result format - text
);
}
}
开发者ID:aspectron,项目名称:jsx,代码行数:59,代码来源:postgres_backend.cpp
注:本文中的PQexecPrepared函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论