本文整理汇总了C++中PQresStatus函数的典型用法代码示例。如果您正苦于以下问题:C++ PQresStatus函数的具体用法?C++ PQresStatus怎么用?C++ PQresStatus使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PQresStatus函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:MGwynne,项目名称:oklibrary,代码行数:26,代码来源:DatabaseHandler01.hpp
示例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);
}
开发者ID:markokr,项目名称:pqtest,代码行数:35,代码来源:rowdump.c
示例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;
}
开发者ID:ldmosquera,项目名称:ruby-pg,代码行数:14,代码来源:pg_result.c
示例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);
}
开发者ID:swistak,项目名称:skarbnik,代码行数:31,代码来源:select2.c
示例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;
}
开发者ID:SanthoshPrasad,项目名称:bottledwater-pg,代码行数:37,代码来源:connect.c
示例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;
}
开发者ID:RangelReale,项目名称:sandbox,代码行数:30,代码来源:PgSQLException.cpp
示例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 );
}
开发者ID:Joe-xXx,项目名称:pgadmin3,代码行数:60,代码来源:dlgDirectDbg.cpp
示例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;
}
开发者ID:po1vo,项目名称:aide,代码行数:58,代码来源:be.c
示例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);
}
开发者ID:gvlx,项目名称:gawkextlib,代码行数:9,代码来源:pgsql.c
示例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;
}
开发者ID:50wu,项目名称:gpdb,代码行数:59,代码来源:cdbrelsize.c
示例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;
}
开发者ID:Limsik,项目名称:e17,代码行数:11,代码来源:esql_postgresql_backend.c
示例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);
}
开发者ID:aweber,项目名称:pg-utf8-transcoder,代码行数:13,代码来源:transcoder-utils.c
示例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;
}
开发者ID:BlueSkyGjj,项目名称:impala,代码行数:50,代码来源:sql.c
示例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));
}
}
开发者ID:Limsik,项目名称:e17,代码行数:39,代码来源:esql_postgresql_backend.c
示例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);
}
}
开发者ID:markokr,项目名称:pqtest,代码行数:40,代码来源:rowdump.c
示例16: execute_query_statement_singlevalue
int execute_query_statement_singlevalue(char* dst, char* stmt) {
int result = 0;
char connect_string[MAX_STATEMENT];
snprintf(connect_string, MAX_STATEMENT, "hostaddr = '%s' port = '%s' dbname = '%s' user = '%s' password = '%s' connect_timeout = '10'", lg_psql.hostaddr, lg_psql.port, lg_psql.dbname, lg_psql.user, lg_psql.pw);
PGconn* psql = PQconnectdb(connect_string);
if (!psql) {
msg(MSG_FATAL,"libpq error : PQconnectdb returned NULL.\n\n");
return result;
}
if (PQstatus(psql) != CONNECTION_OK) {
msg(MSG_FATAL,"libpq error: PQstatus(psql) != CONNECTION_OK\n\n");
return result;
}
PGresult *res = PQexec(psql, stmt);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
msg(MSG_FATAL,"Status: %s",PQresStatus(PQresultStatus(res)));
msg(MSG_FATAL,"%s",PQresultErrorMessage(res));
}
else {
if (PQntuples(res) > 0 && PQnfields(res) > 0) {
result = 1;
char* value = PQgetvalue(res,0,0);
msg(MSG_DEBUG,"we have value: %s",value);
strcpy(dst,value);
}
}
PQfinish(psql);
return result;
}
开发者ID:tumi8,项目名称:trumanbox,代码行数:38,代码来源:log_postgres.c
示例17: execute_one_statement
int execute_one_statement(const char* stmt_to_exec,PGresult** res_ptr)
{
int retcode=1;
PGresult* local_result;
const char* str_res=NULL;
printf("about to execute %s\n",stmt_to_exec);
local_result=PQexec(conn,stmt_to_exec);
*res_ptr=local_result;
if(!local_result)
{
printf("PQexec command failed, no error code.\n");
retcode=0;
}
else
{
switch(PQresultStatus(local_result))
{
case PGRES_COMMAND_OK:
str_res=PQcmdTuples(local_result);
printf("Command executed ok,%s rows affected\n",str_res);
break;
case PGRES_TUPLES_OK:
printf("Query may have returned data,%d rows returned\n",PQntuples(local_result));
break;
default:
printf("Command failed with code %s,error message %s\n",
PQresStatus(PQresultStatus(local_result)),
PQresultErrorMessage(local_result));
PQclear(local_result);
retcode=0;
break;
}
}
return retcode;
}
开发者ID:polyactis,项目名称:test,代码行数:38,代码来源:sel3.c
示例18: execSql
void execSql(PGconn *connection, char *query){
PGresult *status;
system("clear");
printf("wykonywanie polecenia : \n%s \n\n",query);
status=PQexec(connection,query);
printf("Status polecenia: %s \n",PQresStatus(PQresultStatus(status)));
printf("%s \n",PQresultErrorMessage(status));
switch(PQresultStatus(status)) {
case PGRES_TUPLES_OK:
{
int rec_num, col_num;
int cols = PQnfields(status);
int records = PQntuples(status);
for(rec_num = 0; rec_num < records; rec_num++) {
for(col_num = 0; col_num < cols; col_num++)
printf(" %s = %s", PQfname(status, col_num),PQgetvalue(status,rec_num,col_num));
printf("\n\n");
}
}
}
PQclear(status);
}
开发者ID:mateuszdargacz,项目名称:aplikacje_bazy_C,代码行数:24,代码来源:connect.c
示例19: exec_query_full
/* load everything to single PGresult */
static void exec_query_full(struct Context *ctx, const char *q)
{
PGconn *db = ctx->db;
PGresult *r;
ExecStatusType s;
int i;
ctx->count = 0;
if (!PQsendQuery(db, q))
die(db, "PQsendQuery");
/* get next result */
r = PQgetResult(db);
s = PQresultStatus(r);
if (s != PGRES_TUPLES_OK)
die(db, PQresStatus(s));
for (i = 0; i < PQntuples(r); i++) {
proc_row(ctx, r, i);
ctx->count++;
}
PQclear(r);
}
开发者ID:markokr,项目名称:pqtest,代码行数:25,代码来源:rowdump.c
示例20: DEBUG
bool PgQuery::sendQueryDirect (const string & query)
{
DEBUG (DEBUG_DB, "[" << this << "->" << __FUNCTION__ << "] " << query);
if (!_conn)
{
ERROR ("[" << this << "->" << __FUNCTION__ << "] " << "NULL connection.");
return false;
}
if (_res)
{
DEBUG (DEBUG9, "[" << this << "->" << __FUNCTION__ << "] PQclear(" << _res << ")");
PQclear (_res);
}
_res = PQexec (_conn->_pgconn, query.c_str ());
DEBUG (DEBUG9, "[" << this << "->" << __FUNCTION__ << "] PQexec(" << _conn->_pgconn << ", " << query << ") = " << _res);
int status = PQresultStatus (_res);
DEBUG (DEBUG9, "[" << this << "->" << __FUNCTION__ << "] PQresultStatus(" << _res << ") = " << PQresStatus((ExecStatusType)status));
if ((status != PGRES_COMMAND_OK) && (status != PGRES_TUPLES_OK))
{
ERROR ("[" << this << "->" << __FUNCTION__ << "] " << PQerrorMessage (_conn->_pgconn));
DEBUG (DEBUG9, "[" << this << "->" << __FUNCTION__ << "] PQclear(" << _res << ")");
PQclear (_res);
_res = NULL;
return false;
}
_current_row = 0;
return true;
}
开发者ID:Chugajstyr,项目名称:sams2,代码行数:35,代码来源:pgquery.cpp
注:本文中的PQresStatus函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论