本文整理汇总了C++中PQresultErrorMessage函数的典型用法代码示例。如果您正苦于以下问题:C++ PQresultErrorMessage函数的具体用法?C++ PQresultErrorMessage怎么用?C++ PQresultErrorMessage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PQresultErrorMessage函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: sql_request
inline int sql_request(const char *format, ...) {
va_list args;
PGresult *res;
if (format == NULL || *format == '\0')
return 0;
va_start(args, format);
vsprintf(inbuf, format, args);
va_end(args);
priv_pgsql_adapt((char *)&inbuf);
strcpy(last_request, inbuf);
#ifdef MYSQL_DEBUG
printf("Query: %s\n", inbuf);
#endif
res = PQexec(pgsql_handle, inbuf);
if (PQresultStatus(res) == PGRES_COMMAND_OK) return 1; /* no data returned */
if (PQresultStatus(res) != PGRES_TUPLES_OK) { /* some error occured */
printf("SQLERR: Req: %s, Error: %s \n", last_request, PQresultErrorMessage(res));
PQclear(res);
return 0;
}
if (pgsql_db_res) {
PQclear(pgsql_db_res);
pgsql_db_res = NULL;
pgsql_db_row = 0;
}
pgsql_db_res = res;
return 1;
}
开发者ID:MagicalTux,项目名称:nezumi,代码行数:33,代码来源:db_pgsql.c
示例2: 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:xiul,项目名称:pgadmin3,代码行数:60,代码来源:dlgDirectDbg.cpp
示例3: execute_nonquery_statement
int execute_nonquery_statement(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_COMMAND_OK)
{
msg(MSG_FATAL,"ERROR: %s",PQresultErrorMessage(res));
msg(MSG_FATAL,"while executing '%s'",stmt);
result = 0;
}
else
{
result = 1; // success
}
PQfinish(psql);
return result;
}
开发者ID:tumi8,项目名称:trumanbox,代码行数:31,代码来源:log_postgres.c
示例4: va_start
bool PostgreDatabase::WaitExecute(const char* QueryString, ...)
{
if(QueryString == NULL) return false;
va_list vlist;
va_start(vlist, QueryString);
mSearchMutex.acquire();
uint32 Connection = GetConnection();
InUseMarkers[Connection] = true;
mSearchMutex.release();
vsprintf(QueryBuffer[Connection], QueryString, vlist);
PGresult * res = SendQuery(Connection, QueryBuffer[Connection], false);
if(res == 0) return false;
InUseMarkers[Connection] = false;
ExecStatusType result = PQresultStatus(res);
bool passed = false;
if(result == PGRES_TUPLES_OK || result == PGRES_COMMAND_OK)
passed = true;
else
sLog.outError("Execute failed because of [%s]", PQresultErrorMessage(res));
// free up the memory
PQclear(res);
return passed;
}
开发者ID:AwkwardDev,项目名称:WoWD,代码行数:31,代码来源:PostgreDatabase.cpp
示例5: connection
PgsqlReaderProvider::PgsqlReaderProvider(PgsqlConnectionProvider *connection, PgsqlCommandProvider *command)
: connection(connection), command(command), closed(false), current_row(-1)
{
auto deleter = [](PGresult *ptr) {if (ptr) {PQclear(ptr);} };
std::unique_ptr<PGresult, decltype(deleter)> result_uniqueptr(command->exec_command(), deleter);
result = result_uniqueptr.get();
switch (PQresultStatus(result))
{
case PGRES_EMPTY_QUERY:
throw Exception("Empty query");
case PGRES_COMMAND_OK:
type = ResultType::EMPTY_RESULT;
break;
case PGRES_TUPLES_OK:
type = ResultType::TUPLES_RESULT;
break;
case PGRES_NONFATAL_ERROR:
throw Exception("Server gave an unknow answer");
case PGRES_FATAL_ERROR:
throw Exception(PQerrorMessage(connection->db));
default:
throw Exception(StringHelp::text_to_local8(PQresultErrorMessage(result)));
}
nb_rows = PQntuples(result);
result_uniqueptr.release();
}
开发者ID:Zenol,项目名称:ClanPgsql,代码行数:31,代码来源:pgsql_reader_provider.cpp
示例6: 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
示例7: exec_remote_start
/*
* Call pgpool_remote_start() function.
*/
static int exec_remote_start(PGconn *conn, BackendInfo *backend)
{
PGresult *result;
char *hostname;
int r;
if (strlen(backend->backend_hostname) == 0 || *(backend->backend_hostname) == '/')
hostname = "localhost";
else
hostname = backend->backend_hostname;
snprintf(recovery_command, sizeof(recovery_command),
"SELECT pgpool_remote_start('%s', '%s')",
hostname,
backend->backend_data_directory);
pool_debug("exec_remote_start: start pgpool_remote_start");
result = PQexec(conn, recovery_command);
r = (PQresultStatus(result) != PGRES_TUPLES_OK);
if (r != 0)
pool_error("exec_remote_start: pgpool_remote_start failed: %s", PQresultErrorMessage(result));
PQclear(result);
pool_debug("exec_remote_start: finish pgpool_remote_start");
return r;
}
开发者ID:ZheYuan,项目名称:prestogres,代码行数:28,代码来源:recovery.c
示例8: pgresult_error_message
/*
* call-seq:
* res.error_message() -> String
*
* Returns the error message of the command as a string.
*/
static VALUE
pgresult_error_message(VALUE self)
{
VALUE ret = rb_tainted_str_new2(PQresultErrorMessage(pgresult_get(self)));
ASSOCIATE_INDEX(ret, self);
return ret;
}
开发者ID:camilo,项目名称:ruby-pg,代码行数:13,代码来源:pg_result.c
示例9: doSQL
void doSQL(PGconn *conn, char *command){
PGresult *result;
printf("%s\n", command);
result = PQexec(conn, command);
printf("Result message: %s\n", PQresultErrorMessage(result));
switch(PQresultStatus(result)) {
case PGRES_TUPLES_OK:{
int n = 0, m = 0;
int nrows = PQntuples(result);
int nfields = PQnfields(result);
for(m = 0; m < nrows; m++) {
for(n = 0; n < nfields; n++)
printf(" %s = %s", PQfname(result, n),PQgetvalue(result,m,n));
printf("\n");
}
if(nrows == 0 || nfields == 0){
printf("Car does not exist in database!");
searchT = 0;
}
}
}
PQclear(result);
}
开发者ID:henio180,项目名称:AplikacjeBazodanowe,代码行数:26,代码来源:pr1.c
示例10: PQresultStatus
bool PostgreSQLInterface::IsResultSuccessful(PGresult *result, bool rollbackOnFailure)
{
if (result==0)
return false;
bool success=false;
ExecStatusType execStatus = PQresultStatus(result);
strcpy(lastError,PQresultErrorMessage(result));
switch (execStatus)
{
case PGRES_COMMAND_OK:
success=true;
break;
case PGRES_EMPTY_QUERY:
break;
case PGRES_TUPLES_OK:
success=true;
break;
case PGRES_COPY_OUT:
break;
case PGRES_COPY_IN:
break;
case PGRES_BAD_RESPONSE:
break;
case PGRES_NONFATAL_ERROR:
break;
case PGRES_FATAL_ERROR:
if (rollbackOnFailure)
Rollback();
break;
}
return success;
}
开发者ID:0521guo,项目名称:RakNet,代码行数:33,代码来源:PostgreSQLInterface.cpp
示例11: PQreset
void DatabasePostgreSQL::UpdateLSAccountData(unsigned int id, string ip_address)
{
if(!db)
{
return;
}
/**
* PostgreSQL doesn't have automatic reconnection option like mysql
* but it's easy to check and reconnect
*/
if(PQstatus(db) != CONNECTION_OK)
{
PQreset(db);
if(PQstatus(db) != CONNECTION_OK)
{
return;
}
}
stringstream query(stringstream::in | stringstream::out);
query << "UPDATE " << server.options.GetAccountTable() << " SET LastIPAddress = '";
query << ip_address;
query << "', LastLoginDate = current_date where LoginServerID = ";
query << id;
PGresult *res = PQexec(db, query.str().c_str());
char *error = PQresultErrorMessage(res);
if(strlen(error) > 0)
{
Log.Out(Logs::General, Logs::Error, "Database error in DatabasePostgreSQL::GetLoginDataFromAccountName(): %s", error);
}
PQclear(res);
}
开发者ID:9thsector,项目名称:Server,代码行数:34,代码来源:database_postgresql.cpp
示例12: raise_error
static void raise_error(VALUE self, PGresult *result, VALUE query) {
VALUE exception;
char *message;
char *sqlstate;
int postgres_errno;
message = PQresultErrorMessage(result);
sqlstate = PQresultErrorField(result, PG_DIAG_SQLSTATE);
postgres_errno = MAKE_SQLSTATE(sqlstate[0], sqlstate[1], sqlstate[2], sqlstate[3], sqlstate[4]);
PQclear(result);
const char *exception_type = "SQLError";
struct errcodes *errs;
for (errs = errors; errs->error_name; errs++) {
if(errs->error_no == postgres_errno) {
exception_type = errs->exception;
break;
}
}
VALUE uri = rb_funcall(rb_iv_get(self, "@connection"), rb_intern("to_s"), 0);
exception = rb_funcall(CONST_GET(mDO, exception_type), ID_NEW, 5,
rb_str_new2(message),
INT2NUM(postgres_errno),
rb_str_new2(sqlstate),
query,
uri);
rb_exc_raise(exception);
}
开发者ID:ckoenig,项目名称:do,代码行数:32,代码来源:do_postgres.c
示例13: pgsql_update
static int pgsql_update(void *theconn, const Octstr *sql, List *binds)
{
int rows;
PGresult *res = NULL;
PGconn *conn = (PGconn*) theconn;
res = PQexec(conn, octstr_get_cstr(sql));
if (res == NULL)
return -1;
switch (PQresultStatus(res)) {
case PGRES_BAD_RESPONSE:
case PGRES_NONFATAL_ERROR:
case PGRES_FATAL_ERROR:
error(0, "PGSQL: %s", octstr_get_cstr(sql));
error(0, "PGSQL: %s", PQresultErrorMessage(res));
PQclear(res);
return -1;
default: /* for compiler please */
break;
}
rows = atoi(PQcmdTuples(res));
PQclear(res);
return rows;
}
开发者ID:Jayriq,项目名称:kannel-gateway,代码行数:26,代码来源:dbpool_pgsql.c
示例14: EXE_SQL_CMD
void EXE_SQL_CMD(const char* cmd){
PGresult* res = PQexec(conn,cmd);
if(!res || PQresultStatus(res) != PGRES_COMMAND_OK){
fprintf(stderr, "SQL Error in cmd: %s\n", PQresultErrorMessage(res));
}
PQclear(res);
}
开发者ID:dekel2003,项目名称:DBS_HW2,代码行数:7,代码来源:wet.c
示例15: 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 n = 0, r = 0;
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", PQfname(result, n),PQgetvalue(result,r,n));
printf("\n");
}
}
}
PQclear(result);
}
开发者ID:swistak,项目名称:skarbnik,代码行数:28,代码来源:create2.c
示例16: TBL_DeleteTable
CONDITION
TBL_DeleteTable(TBL_HANDLE ** handle, const TBL_CRITERIA * criteriaList,
const char* tableName)
{
TBL_CONTEXT* tc;
char* dbName;
/*char *tableName;*/
int foundit;
char deleteCommand[2048];
PGresult* res;
PGconn* conn;
#ifdef CTN_USE_THREADS
THR_ObtainMutex(FAC_TBL);
#endif
tc = G_ContextHead;
foundit = 0;
while (tc != (TBL_CONTEXT *) NULL) {
if (tc == (TBL_CONTEXT *) (*handle)) {
dbName = tc->databaseName;
/*tableName = tc->tableName;*/
conn = (PGconn*)tc->dbSpecific;
foundit = 1;
break;
}
tc = tc->next;
}
if (!foundit) {
#ifdef CTN_USE_THREADS
THR_ReleaseMutex(FAC_TBL);
#endif
return COND_PushCondition(TBL_ERROR(TBL_BADHANDLE), "TBL_Delete");
}
strcpy(deleteCommand, "DELETE FROM ");
strcat(deleteCommand, tableName);
if ((criteriaList != (TBL_CRITERIA *) NULL) && (criteriaList->FieldName != 0)) {
strcat(deleteCommand, " WHERE ");
addCriteria(criteriaList, deleteCommand);
}
strcat(deleteCommand, ";" );
res = PQexec(conn, deleteCommand);
if (PQresultStatus(res) != PGRES_COMMAND_OK) {
fprintf(stderr, PQresultErrorMessage(res));
fprintf(stderr, "<%s>\n", deleteCommand);
exit(1);
}
PQclear(res);
#ifdef CTN_USE_THREADS
THR_ReleaseMutex(FAC_TBL);
#endif
return TBL_NORMAL;
}
开发者ID:stl-steve-moore,项目名称:ctn,代码行数:59,代码来源:tbl_psql.c
示例17: SMSDPgSQL_LogError
static void SMSDPgSQL_LogError(GSM_SMSDConfig * Config, PGresult * Res)
{
if (Res == NULL) {
SMSD_Log(DEBUG_INFO, Config, "Error: %s", PQerrorMessage(Config->conn.pg));
} else {
SMSD_Log(DEBUG_INFO, Config, "Error: %s", PQresultErrorMessage(Res));
}
}
开发者ID:AndyLavr,项目名称:gammu,代码行数:8,代码来源:pgsql.c
示例18: pg_error_msg
static SCM pg_error_msg(SCM res) {
struct pg_res *pgr;
scm_assert_smob_type(pg_res_tag, res);
pgr = (struct pg_res *)SCM_SMOB_DATA(res);
if ((pgr->status != PGRES_FATAL_ERROR) &&
(pgr->status != PGRES_NONFATAL_ERROR)) return SCM_BOOL_F;
return c2s(PQresultErrorMessage(pgr->res));
}
开发者ID:pmyadlowsky,项目名称:gusher,代码行数:8,代码来源:postgres.c
示例19: RS_PostgreSQL_getResult
s_object *
RS_PostgreSQL_getResult(Con_Handle * conHandle)
{
S_EVALUATOR RS_DBI_connection * con;
S_EVALUATOR RS_DBI_resultSet * result;
PGconn *my_connection;
Res_Handle *rsHandle;
Sint res_id;
PGresult *my_result;
con = RS_DBI_getConnection(conHandle);
my_connection = (PGconn *) con->drvConnection;
if (con->num_res > 0) {
res_id = (Sint) con->resultSetIds[0];
rsHandle = RS_DBI_asResHandle(MGR_ID(conHandle), CON_ID(conHandle), res_id);
result = RS_DBI_getResultSet(rsHandle);
if (result->completed == 0) {
RS_DBI_errorMessage("connection with pending rows, close resultSet before continuing", RS_DBI_ERROR);
}
else {
RS_PostgreSQL_closeResultSet(rsHandle);
}
}
my_result = PQgetResult(my_connection);
if(my_result == NULL)
return S_NULL_ENTRY;
if (strcmp(PQresultErrorMessage(my_result), "") != 0) {
char *errResultMsg;
const char *omsg;
size_t len;
omsg = PQerrorMessage(my_connection);
len = strlen(omsg);
errResultMsg = malloc(len + 80); /* 80 should be larger than the length of "could not ..."*/
snprintf(errResultMsg, len + 80, "could not Retrieve the result : %s", omsg);
RS_DBI_errorMessage(errResultMsg, RS_DBI_ERROR);
free(errResultMsg);
/* Frees the storage associated with a PGresult.
* void PQclear(PGresult *res); */
PQclear(my_result);
}
/* we now create the wrapper and copy values */
PROTECT(rsHandle = RS_DBI_allocResultSet(conHandle));
result = RS_DBI_getResultSet(rsHandle);
result->drvResultSet = (void *) my_result;
result->rowCount = (Sint) 0;
result->isSelect = 0;
result->rowsAffected = 0;
result->completed = 1;
UNPROTECT(1);
return rsHandle;
}
开发者ID:Kevin-M-Smith,项目名称:RPostgreSQL,代码行数:58,代码来源:RS-pgsql-getResult.c
示例20: pg_result_check
/*
* call-seq:
* res.check -> nil
*
* Raises appropriate exception if PG::Result is in a bad state.
*/
VALUE
pg_result_check( VALUE self )
{
VALUE error, exception, klass;
VALUE rb_pgconn = rb_iv_get( self, "@connection" );
PGconn *conn = pg_get_pgconn(rb_pgconn);
PGresult *result;
#ifdef M17N_SUPPORTED
rb_encoding *enc = pg_conn_enc_get( conn );
#endif
char * sqlstate;
Data_Get_Struct(self, PGresult, result);
if(result == NULL)
{
error = rb_str_new2( PQerrorMessage(conn) );
}
else
{
switch (PQresultStatus(result))
{
case PGRES_TUPLES_OK:
case PGRES_COPY_OUT:
case PGRES_COPY_IN:
#ifdef HAVE_CONST_PGRES_COPY_BOTH
case PGRES_COPY_BOTH:
#endif
#ifdef HAVE_CONST_PGRES_SINGLE_TUPLE
case PGRES_SINGLE_TUPLE:
#endif
case PGRES_EMPTY_QUERY:
case PGRES_COMMAND_OK:
return Qnil;
case PGRES_BAD_RESPONSE:
case PGRES_FATAL_ERROR:
case PGRES_NONFATAL_ERROR:
error = rb_str_new2( PQresultErrorMessage(result) );
break;
default:
error = rb_str_new2( "internal error : unknown result status." );
}
}
#ifdef M17N_SUPPORTED
rb_enc_set_index( error, rb_enc_to_index(enc) );
#endif
sqlstate = PQresultErrorField( result, PG_DIAG_SQLSTATE );
klass = lookup_error_class( sqlstate );
exception = rb_exc_new3( klass, error );
rb_iv_set( exception, "@connection", rb_pgconn );
rb_iv_set( exception, "@result", self );
rb_exc_raise( exception );
/* Not reached */
return Qnil;
}
开发者ID:ldmosquera,项目名称:ruby-pg,代码行数:64,代码来源:pg_result.c
注:本文中的PQresultErrorMessage函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论