本文整理汇总了C++中PQresultErrorMessage函数的典型用法代码示例。如果您正苦于以下问题:C++ PQresultErrorMessage函数的具体用法?C++ PQresultErrorMessage怎么用?C++ PQresultErrorMessage使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PQresultErrorMessage函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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 );
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}