本文整理汇总了C++中PQresStatus函数的典型用法代码示例。如果您正苦于以下问题:C++ PQresStatus函数的具体用法?C++ PQresStatus怎么用?C++ PQresStatus使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PQresStatus函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: issue
void issue(const std::string& command) {
PQclear(res);
#ifdef DEBUG
std::cout << "Command.issue mit " << command << std::endl;
#endif
res = PQexec(conn, command.c_str());
#ifdef DEBUG
std::cout << "PQexec erfolgreich, *res = " << res << std::endl;
#endif
ExecStatusType status(PQresultStatus(res));
#ifdef DEBUG
std::cout << "PQresultStatus erfolgreich, status = " << status << std::endl;
#endif
if (status != PGRES_COMMAND_OK) {
#ifdef DEBUG
std::cout << "status != PGRES_COMMAND_OK" << std::endl;
std::cout << "PQresultErrorMessage(res): " << PQresultErrorMessage(res) << std::endl;
std::cout << "conn.getName(): " << conn.getName() << std::endl;
std::cout << "PQresStatus(status): " << PQresStatus(status) << std::endl;
#endif
throw Error::command_failed(PQresultErrorMessage(res), conn.getName(), PQresStatus(status));
}
#ifdef DEBUG
std::cout << "PGRES_COMMAND_OK" << std::endl;
#endif
}
示例2: exec_query_zero_copy
/* load rows directly from network buffer */
static void exec_query_zero_copy(struct Context *ctx, const char *q)
{
PGconn *db = ctx->db;
PGresult *r;
ExecStatusType s;
PGdataValue *cols;
ctx->count = 0;
if (!PQsendQuery(db, q))
die(db, "PQsendQuery");
if (!PQsetSingleRowMode(db))
die(NULL, "PQsetSingleRowMode");
/* loop until all resultset is done */
while (PQgetRowData(db, &r, &cols)) {
proc_row_zcopy(ctx, r, cols);
}
/* get final result */
r = PQgetResult(db);
s = PQresultStatus(r);
switch (s) {
case PGRES_TUPLES_OK:
//printf("query successful, got %d rows\n", ctx->count);
ctx->count = 0;
break;
default:
printf("result: %s\n", PQresStatus(s));
break;
}
PQclear(r);
}
示例3: pgresult_res_status
/*
* call-seq:
* res.res_status( status ) -> String
*
* Returns the string representation of status +status+.
*
*/
static VALUE
pgresult_res_status(VALUE self, VALUE status)
{
VALUE ret = rb_tainted_str_new2(PQresStatus(NUM2INT(status)));
ASSOCIATE_INDEX(ret, self);
return ret;
}
示例4: doSQL
void doSQL(PGconn *conn, char *command)
{
PGresult *result;
printf("%s\n", command);
result = PQexec(conn, command);
printf("status is %s\n", PQresStatus(PQresultStatus(result)));
printf("#rows affected %s\n", PQcmdTuples(result));
printf("result message: %s\n", PQresultErrorMessage(result));
switch(PQresultStatus(result)) {
case PGRES_TUPLES_OK:
{
int r, n;
int nrows = PQntuples(result);
int nfields = PQnfields(result);
printf("number of rows returned = %d\n", nrows);
printf("number of fields returned = %d\n", nfields);
for(r = 0; r < nrows; r++) {
for(n = 0; n < nfields; n++)
printf(" %s = %s(%d),",
PQfname(result, n),
PQgetvalue(result, r, n),
PQgetlength(result, r, n));
printf("\n");
}
}
}
PQclear(result);
}
示例5: snapshot_poll
/* Reads the next result row from the snapshot query, parses and processes it.
* Blocks until a new row is available, if necessary. */
int snapshot_poll(client_context_t context) {
int err = 0;
PGresult *res = PQgetResult(context->sql_conn);
/* null result indicates that there are no more rows */
if (!res) {
check(err, exec_sql(context, "COMMIT"));
PQfinish(context->sql_conn);
context->sql_conn = NULL;
// Invoke the commit callback with xid==0 to indicate end of snapshot
commit_txn_cb on_commit = context->repl.frame_reader->on_commit_txn;
void *cb_context = context->repl.frame_reader->cb_context;
if (on_commit) {
check(err, on_commit(cb_context, context->repl.start_lsn, 0));
}
return 0;
}
ExecStatusType status = PQresultStatus(res);
if (status != PGRES_SINGLE_TUPLE && status != PGRES_TUPLES_OK) {
client_error(context, "While reading snapshot: %s: %s",
PQresStatus(PQresultStatus(res)),
PQresultErrorMessage(res));
PQclear(res);
return EIO;
}
int tuples = PQntuples(res);
for (int tuple = 0; tuple < tuples; tuple++) {
check(err, snapshot_tuple(context, res, tuple));
}
PQclear(res);
return err;
}
示例6: PQresultErrorMessage
std::string StatementException::compose(const std::string& text, PgSQL_STMT* h, const std::string& stmt)
{
std::string str;
str += "[Comment]: ";
str += text;
if (h != 0)
{
str += "\t[PgSQL_stmt_error]: ";
str += PQresultErrorMessage(h);
// FIXME:
/*
str += "\t[PgSQL_stmt_errno]: ";
char buff[30];
sprintf(buff, "%d", PQresultErrorField(h, fieldCode));
str += buff;
*/
str += "\t[PgSQL_stmt_sqlstate]: ";
str += PQresStatus(PQresultStatus(h));
}
if (stmt.length() > 0)
{
str += "\t[statemnt]: ";
str += stmt;
}
return str;
}
示例7: wxLogInfo
void dlgDirectDbg::OnTargetComplete( wxCommandEvent &event )
{
// Extract the result set handle from the event and log the status info
PGresult *result = (PGresult *)event.GetClientData();
wxLogInfo( wxT( "OnTargetComplete() called\n" ));
wxLogInfo( wxT( "%s\n" ), wxString(PQresStatus( PQresultStatus( result )), wxConvUTF8).c_str());
// If the query failed, write the error message to the status line, otherwise, copy the result set into the grid
if(( PQresultStatus( result ) == PGRES_NONFATAL_ERROR ) || ( PQresultStatus( result ) == PGRES_FATAL_ERROR ))
{
wxString message( PQresultErrorMessage( result ), wxConvUTF8 );
message.Replace( wxT( "\n" ), wxT( " " ));
m_parent->getStatusBar()->SetStatusText( message, 1 );
char *state = PQresultErrorField(result, PG_DIAG_SQLSTATE);
// Don't bother telling the user that he aborted - he already knows!
// Depending on the stage, m_conn might not be set all! so check for
// that first
if (m_conn)
{
if (state != NULL && strcmp(state, "57014"))
wxLogError( wxT( "%s\n" ), wxString(PQerrorMessage(m_conn->getConnection()), wxConvUTF8).c_str());
else
wxLogInfo( wxT( "%s\n" ), wxString(PQerrorMessage(m_conn->getConnection()), wxConvUTF8).c_str());
}
}
else
{
wxString message( PQcmdStatus( result ), wxConvUTF8 );
message.Replace( wxT( "\r" ), wxT( "" ));
message.Replace( wxT( "\n" ), wxT( " " ));
m_parent->getStatusBar()->SetStatusText( message, 1 );
// If this result set has any columns, add a result grid to the code window so
// we can show the results to the user
if( m_codeWindow && PQnfields( result ))
{
m_codeWindow->OnResultSet( result );
}
}
if (m_codeWindow)
{
m_codeWindow->m_targetComplete = true;
m_codeWindow->disableTools( );
}
// Do not show if aborted
if ( m_codeWindow && m_codeWindow->m_targetAborted )
return;
this->Show( true );
}
示例8: be_sql_readinit
static int be_sql_readinit(psql_data* ret) {
/* Yes.. we don't want to know about two first result..
and we want no memoryleaking.
*/
int i,j,nFields;
char* s;
char declare []="DECLARE aidecursor CURSOR FOR select * from ";
s = (char*)malloc(strlen(declare)+strlen(ret->table)+1);
s[0]=0;
s=strcat(s,declare);
s=strcat(s,ret->table);
ret->res=PQexec(ret->conn,s);
if (!ret->res || PQresultStatus(ret->res) != PGRES_COMMAND_OK) {
if (ret->res!=NULL) {
error(255,"Psql error: %s\n",PQresStatus(PQresultStatus(ret->res)));
PQclear(ret->res);
}
return RETFAIL;
}
PQclear(ret->res);
ret -> res = PQexec(ret->conn, "FETCH ALL in aidecursor");
if (!ret->res || PQresultStatus(ret->res) != PGRES_TUPLES_OK)
{
error(0, "FETCH ALL command didn't return tuples properly\n");
PQclear(ret->res);
abort();
}
/* first, print out the attribute names */
nFields = PQnfields(ret->res);
for (i = 0; i < nFields; i++)
error(255,"%-15s", PQfname(ret->res, i));
error(255,"\n\n");
for(i=0;i<db_unknown;i++){
ret->des[i]=PQfnumber(ret->res,db_names[i]);
if (ret->des[i]!=-1) {
error(255,"Field %i,%s \n",ret->des[i],db_names[i]);
}
}
ret->curread=0;
ret->maxread=PQntuples(ret->res);
/* And now we know how many fields we have.. */
error(10,"%i tuples\n",ret->maxread);
return RETOK;
}
示例9: set_error
static awk_value_t *
set_error(PGconn *conn, ExecStatusType status, awk_value_t *result)
{
char buf[100];
snprintf(buf, sizeof(buf), "ERROR %s%s",
((PQstatus(conn) != CONNECTION_OK) ? "BADCONN " : ""),
PQresStatus(status));
return make_string_malloc(buf, strlen(buf), result);
}
示例10: cdbRelMaxSegSize
/*
* Get the max size of the relation across segments
*/
int64
cdbRelMaxSegSize(Relation rel)
{
int64 size = 0;
int i;
CdbPgResults cdb_pgresults = {NULL, 0};
StringInfoData buffer;
char *schemaName;
char *relName;
/*
* Let's ask the QEs for the size of the relation
*/
initStringInfo(&buffer);
schemaName = get_namespace_name(RelationGetNamespace(rel));
if (schemaName == NULL)
elog(ERROR, "cache lookup failed for namespace %d",
RelationGetNamespace(rel));
relName = RelationGetRelationName(rel);
/*
* Safer to pass names than oids, just in case they get out of sync between QD and QE,
* which might happen with a toast table or index, I think (but maybe not)
*/
appendStringInfo(&buffer, "select pg_relation_size('%s.%s')",
quote_identifier(schemaName), quote_identifier(relName));
CdbDispatchCommand(buffer.data, DF_WITH_SNAPSHOT, &cdb_pgresults);
for (i = 0; i < cdb_pgresults.numResults; i++)
{
struct pg_result * pgresult = cdb_pgresults.pg_results[i];
if (PQresultStatus(pgresult) != PGRES_TUPLES_OK)
{
cdbdisp_clearCdbPgResults(&cdb_pgresults);
elog(ERROR,"cdbRelMaxSegSize: resultStatus not tuples_Ok: %s %s",
PQresStatus(PQresultStatus(pgresult)),PQresultErrorMessage(pgresult));
}
else
{
Assert(PQntuples(pgresult) == 1);
int64 tempsize = 0;
(void) scanint8(PQgetvalue(pgresult, 0, 0), false, &tempsize);
if (tempsize > size)
size = tempsize;
}
}
pfree(buffer.data);
cdbdisp_clearCdbPgResults(&cdb_pgresults);
return size;
}
示例11: esql_postgresql_error_get
static const char *
esql_postgresql_error_get(Esql *e)
{
const char *p;
p = PQerrorMessage(e->backend.db);
if ((!p) || (!*p))
p = PQresStatus(PQresultStatus(e->res->backend.res));
return p;
}
示例12: pq_escape
char * pq_escape (PGconn* cxn, const char* input, int len)
{
char *output;
output = PQescapeLiteral(cxn, input, len);
if (output == NULL)
LOGSTDERR(ERROR, PQresStatus(PGRES_FATAL_ERROR),
"Failed to escape string: %s", input);
// free output in caller
return(output);
}
示例13: _pgsql_exec
static int _pgsql_exec(void *conn, const char *cmd, char *value, size_t size,
size_t *value_len, const sasl_utils_t *utils)
{
PGresult *result;
int row_count;
ExecStatusType status;
/* run the query */
result = PQexec(conn, cmd);
/* check the status */
status = PQresultStatus(result);
if (status == PGRES_COMMAND_OK) {
/* no results (BEGIN, COMMIT, DELETE, INSERT, UPDATE) */
PQclear(result);
return 0;
}
else if (status != PGRES_TUPLES_OK) {
/* error */
utils->log(NULL, SASL_LOG_DEBUG, "sql plugin: %s ",
PQresStatus(status));
PQclear(result);
return -1;
}
/* quick row check */
row_count = PQntuples(result);
if (!row_count) {
/* umm nothing found */
utils->log(NULL, SASL_LOG_NOTE, "sql plugin: no result found");
PQclear(result);
return -1;
}
if (row_count > 1) {
utils->log(NULL, SASL_LOG_WARN,
"sql plugin: found duplicate row for query %s", cmd);
}
/* now get the result set value and value_len */
/* we only fetch one because we don't care about the rest */
if (value) {
strncpy(value, PQgetvalue(result,0,0), size-2);
value[size-1] = '\0';
if (value_len) *value_len = strlen(value);
}
/* free result */
PQclear(result);
return 0;
}
示例14: esql_postgresql_res
static void
esql_postgresql_res(Esql_Res *res)
{
Esql_Row *r;
PGresult *pres;
int i;
pres = res->backend.res = PQgetResult(res->e->backend.db);
EINA_SAFETY_ON_NULL_RETURN(pres);
switch (PQresultStatus(pres))
{
case PGRES_COMMAND_OK:
{
const char *a;
a = PQcmdTuples(pres);
if (a && (*a))
res->affected = strtol(a, NULL, 10);
res->id = PQoidValue(pres);
}
return;
case PGRES_TUPLES_OK:
break;
default:
res->error = PQresultErrorMessage(pres);
ERR("Error %s:'%s'!", PQresStatus(PQresultStatus(pres)), res->error);
return;
}
res->desc = esql_module_desc_get(PQntuples(pres), (Esql_Module_Setup_Cb)esql_module_setup_cb, res);
for (i = 0; i < res->row_count; i++)
{
r = esql_row_calloc(1);
EINA_SAFETY_ON_NULL_RETURN(r);
r->res = res;
esql_postgresql_row_init(r, i);
res->rows = eina_inlist_append(res->rows, EINA_INLIST_GET(r));
}
}
示例15: exec_query_single_row
/* load each row as PGresult */
static void exec_query_single_row(struct Context *ctx, const char *q)
{
PGconn *db = ctx->db;
PGresult *r;
ExecStatusType s;
ctx->count = 0;
if (!PQsendQuery(db, q))
die(db, "PQsendQuery");
if (!PQsetSingleRowMode(db))
die(NULL, "PQsetSingleRowMode");
/* loop until all resultset is done */
while (1) {
/* get next result */
r = PQgetResult(db);
if (!r)
break;
s = PQresultStatus(r);
switch (s) {
case PGRES_TUPLES_OK:
//printf("query successful, got %d rows\n", ctx->count);
ctx->count = 0;
break;
case PGRES_SINGLE_TUPLE:
/* process first (only) row */
proc_row(ctx, r, 0);
break;
default:
fprintf(stderr, "result: %s\n", PQresStatus(s));
exit(1);
break;
}
PQclear(r);
}
}