当前位置: 首页>>代码示例>>C++>>正文


C++ PQreset函数代码示例

本文整理汇总了C++中PQreset函数的典型用法代码示例。如果您正苦于以下问题:C++ PQreset函数的具体用法?C++ PQreset怎么用?C++ PQreset使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了PQreset函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: is_pgup

/* check the PQStatus and try to 'select 1' to confirm good connection */
bool
is_pgup(PGconn *conn, int timeout)
{
	char		sqlquery[QUERY_STR_LEN];

	/* Check the connection status twice in case it changes after reset */
	bool		twice = false;

	/* Check the connection status twice in case it changes after reset */
	for (;;)
	{
		if (PQstatus(conn) != CONNECTION_OK)
		{
			if (twice)
				return false;
			PQreset(conn);		/* reconnect */
			twice = true;
		}
		else
		{
			/*
			 * Send a SELECT 1 just to check if the connection is OK
			 */
			if (!cancel_query(conn, timeout))
				goto failed;
			if (wait_connection_availability(conn, timeout) != 1)
				goto failed;

			sqlquery_snprintf(sqlquery, "SELECT 1");
			if (PQsendQuery(conn, sqlquery) == 0)
			{
				log_warning(_("PQsendQuery: Query could not be sent to primary. %s\n"),
							PQerrorMessage(conn));
				goto failed;
			}
			if (wait_connection_availability(conn, timeout) != 1)
				goto failed;

			break;

	failed:

			/*
			 * we need to retry, because we might just have lost the
			 * connection once
			 */
			if (twice)
				return false;
			PQreset(conn);		/* reconnect */
			twice = true;
		}
	}
	return true;
}
开发者ID:Bazoozoo,项目名称:repmgr,代码行数:55,代码来源:dbutils.c

示例2: do_postgres_cCommand_execute_sync

PGresult * do_postgres_cCommand_execute_sync(VALUE self, VALUE connection, PGconn *db, VALUE query) {
  char *str = StringValuePtr(query);
  PGresult *response;

  while ((response = PQgetResult(db))) {
    PQclear(response);
  }

  struct timeval start;

  gettimeofday(&start, NULL);
  response = PQexec(db, str);

  if (!response) {
    if (PQstatus(db) != CONNECTION_OK) {
      PQreset(db);

      if (PQstatus(db) == CONNECTION_OK) {
        response = PQexec(db, str);
      }
      else {
        do_postgres_full_connect(connection, db);
        response = PQexec(db, str);
      }
    }

    if(!response) {
      rb_raise(eDO_ConnectionError, PQerrorMessage(db));
    }
  }

  data_objects_debug(connection, query, &start);
  return response;
}
开发者ID:Jpoehlman,项目名称:wildtrack,代码行数:34,代码来源:do_postgres.c

示例3: pg_connect

/* Guckt ob Verbindung da und versucht aufzubauen. 
 * gibt 1 zurueck, wenn erfolgreich, sonst 0 */
static int pg_connect(){
  if (PQstatus(connection) == CONNECTION_OK){
    PQexec(connection,"SELECT 1");				/* Status neusetzen erzwingen */
  }
  if(PQstatus(connection) != CONNECTION_OK){
    if (connection == NULL){
      if(conn_string == NULL){
	conn_string = malloc(sizeof(char)*512);
	snprintf(conn_string, 512, "host=%s dbname=%s user=%s password=%s connect_timeout=%s", global_opts.pg_host, global_opts.pg_database, global_opts.pg_user, global_opts.pg_pass, global_opts.pg_timeout);
      }
      connection = PQconnectdb(conn_string);			/* Connection aufbauen */
      add_clean(clean_write, connection);			/* Callbackfunktion zum Aufraeumen registrieren */
    } else {
      PQreset(connection);					/* Connecion resetten */
    }
    if(PQstatus(connection) != CONNECTION_OK){
      DEBUGOUT2("\nFehler beim Aufbau der Datenbankverbindung\n%s\n", PQerrorMessage(connection));
      #ifndef NO_LOGING
      snprintf(get_error_buffer(), ERR_BUFFERSIZE, "Fehler beim Aufbau der Datenbankverbindung: %s", PQerrorMessage(connection));
      log_error(get_error_buffer());
      #endif
      return 0;
    }
    DEBUGOUT1("\nDatenbankverbindung erfolgreich hergestellt\n");
  } 
  return 1;
}
开发者ID:agdsn,项目名称:ancient-weatherstation,代码行数:29,代码来源:write.c

示例4: do_postgres_cCommand_execute_async

PGresult * do_postgres_cCommand_execute_async(VALUE self, VALUE connection, PGconn *db, VALUE query) {
  PGresult *response;
  char* str = StringValuePtr(query);

  while ((response = PQgetResult(db))) {
    PQclear(response);
  }

  struct timeval start;
  int retval;

  gettimeofday(&start, NULL);
  retval = PQsendQuery(db, str);

  if (!retval) {
    if (PQstatus(db) != CONNECTION_OK) {
      PQreset(db);

      if (PQstatus(db) == CONNECTION_OK) {
        retval = PQsendQuery(db, str);
      }
      else {
        do_postgres_full_connect(connection, db);
        retval = PQsendQuery(db, str);
      }
    }

    if (!retval) {
      rb_raise(eDO_ConnectionError, "%s", PQerrorMessage(db));
    }
  }

  int socket_fd = PQsocket(db);
  fd_set rset;

  while (1) {
    FD_ZERO(&rset);
    FD_SET(socket_fd, &rset);
    retval = rb_thread_select(socket_fd + 1, &rset, NULL, NULL, NULL);

    if (retval < 0) {
      rb_sys_fail(0);
    }

    if (retval == 0) {
      continue;
    }

    if (PQconsumeInput(db) == 0) {
      rb_raise(eDO_ConnectionError, "%s", PQerrorMessage(db));
    }

    if (PQisBusy(db) == 0) {
      break;
    }
  }

  data_objects_debug(connection, query, &start);
  return PQgetResult(db);
}
开发者ID:CompendiumSoftware,项目名称:do,代码行数:60,代码来源:do_postgres.c

示例5: pool

/* Functions we export for modules to use:
	- open acquires a connection from the pool (opens one if necessary)
	- close releases it back in to the pool
*/
PGconn* pgasp_pool_open(server_rec* s) {
  PGconn* ret = NULL ;
  pgasp_config* pgasp = (pgasp_config*)
	ap_get_module_config(s->module_config, &pgasp_module) ;
  apr_uint32_t acquired_cnt ;

  if (pgasp->dbpool == NULL) {
    pgasp = apr_hash_get(pgasp_pool_config, pgasp->key, APR_HASH_KEY_STRING);
  }
  if ( apr_reslist_acquire(pgasp->dbpool, (void**)&ret) != APR_SUCCESS ) {
    ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "mod_pgasp: Failed to acquire PgSQL connection from pool!") ;
    return NULL ;
  }
  if (PQstatus(ret) != CONNECTION_OK) {
    PQreset(ret);
    if (PQstatus(ret) != CONNECTION_OK) {
      ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
	"PgSQL Error: %s", PQerrorMessage(ret) ) ;
      apr_reslist_release(pgasp->dbpool, ret) ;
      return NULL ;
    }
  }
  if (pgasp->nkeep < (acquired_cnt = apr_reslist_acquired_count	( pgasp->dbpool	))) {
    ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, "mod_pgasp: %d connections in the %s pool acquired (%d,%d,%d)",
		 acquired_cnt, pgasp->key, pgasp->nmin, pgasp->nkeep, pgasp->nmax
		 ) ;
  }
  return ret ;
}
开发者ID:Maxime2,项目名称:pgasp,代码行数:33,代码来源:mod_pgasp.c

示例6: aPGSQL_reset

static int aPGSQL_reset(struct cw_channel *chan, void *data) {

    char *s1,*s3;
    int l;
    PGconn *karoto;
    int id;
    char *stringp=NULL;


    l=strlen(data)+2;
    s1=malloc(l);
    strncpy(s1, data, l - 1);
    stringp=s1;
    strsep(&stringp," "); /* eat the first token, we already know it :P  */
    s3=strsep(&stringp," ");
    id=atoi(s3);
    if ((karoto=find_identifier(id,CW_PGSQL_ID_CONNID))==NULL) {
        cw_log(LOG_WARNING,"Invalid connection identifier %d passed in aPGSQL_reset\n",id);
    } else {
        PQreset(karoto);
    }
    free(s1);
    return(0);

}
开发者ID:wildzero-cw,项目名称:callweaver,代码行数:25,代码来源:app_sql_postgres.c

示例7: cCommand_execute_sync

static PGresult* cCommand_execute_sync(VALUE self, PGconn *db, VALUE query) {
  PGresult *response;
  struct timeval start;
  char* str = StringValuePtr(query);

  while ((response = PQgetResult(db)) != NULL) {
    PQclear(response);
  }

  gettimeofday(&start, NULL);

  response = PQexec(db, str);

  if (response == NULL) {
    if(PQstatus(db) != CONNECTION_OK) {
      PQreset(db);
      if (PQstatus(db) == CONNECTION_OK) {
        response = PQexec(db, str);
      } else {
        VALUE connection = rb_iv_get(self, "@connection");
        full_connect(connection, db);
        response = PQexec(db, str);
      }
    }

    if(response == NULL) {
      rb_raise(eConnectionError, PQerrorMessage(db));
    }
  }

  data_objects_debug(query, &start);
  return response;
}
开发者ID:matthewd,项目名称:do,代码行数:33,代码来源:do_postgres_ext.c

示例8: CheckConnection

/* CheckConnection
 *
 * Verify that we still have a good connection to the backend, and if not,
 * see if it can be restored.
 *
 * Returns true if either the connection was still there, or it could be
 * restored successfully; false otherwise.	If, however, there was no
 * connection and the session is non-interactive, this will exit the program
 * with a code of EXIT_BADCONN.
 */
static bool
CheckConnection(void)
{
	bool		OK;

	OK = ConnectionUp();
	if (!OK)
	{
		if (!pset.cur_cmd_interactive)
		{
			psql_error("connection to server was lost\n");
			exit(EXIT_BADCONN);
		}

		fputs(_("The connection to the server was lost. Attempting reset: "), stderr);
		PQreset(pset.db);
		OK = ConnectionUp();
		if (!OK)
		{
			fputs(_("Failed.\n"), stderr);
			PQfinish(pset.db);
			pset.db = NULL;
			ResetCancelConn();
			UnsyncVariables();
		}
		else
			fputs(_("Succeeded.\n"), stderr);
	}

	return OK;
}
开发者ID:GisKook,项目名称:Gis,代码行数:41,代码来源:common.c

示例9: c_psql_check_connection

static int c_psql_check_connection (c_psql_database_t *db)
{
	/* "ping" */
	PQclear (PQexec (db->conn, "SELECT 42;"));

	if (CONNECTION_OK != PQstatus (db->conn)) {
		PQreset (db->conn);

		/* trigger c_release() */
		if (0 == db->conn_complaint.interval)
			db->conn_complaint.interval = 1;

		if (CONNECTION_OK != PQstatus (db->conn)) {
			c_complain (LOG_ERR, &db->conn_complaint,
					"Failed to connect to database %s: %s",
					db->database, PQerrorMessage (db->conn));
			return -1;
		}

		db->proto_version = PQprotocolVersion (db->conn);
		if (3 > db->proto_version)
			log_warn ("Protocol version %d does not support parameters.",
					db->proto_version);
	}

	db->server_version = PQserverVersion (db->conn);

	c_release (LOG_INFO, &db->conn_complaint,
			"Successfully reconnected to database %s", PQdb (db->conn));
	return 0;
} /* c_psql_check_connection */
开发者ID:absperf,项目名称:collectd,代码行数:31,代码来源:postgresql.c

示例10: 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)
	{
		server_log->Log(log_database, "Database error in DatabasePostgreSQL::GetLoginDataFromAccountName(): %s", error);
	}
	PQclear(res);
}
开发者ID:vingiarrusso,项目名称:Server,代码行数:34,代码来源:database_postgresql.cpp

示例11: c_psql_check_connection

static int c_psql_check_connection (c_psql_database_t *db)
{
	_Bool init = 0;

	if (! db->conn) {
		init = 1;

		/* trigger c_release() */
		if (0 == db->conn_complaint.interval)
			db->conn_complaint.interval = 1;

		c_psql_connect (db);
	}

	/* "ping" */
	PQclear (PQexec (db->conn, "SELECT 42;"));

	if (CONNECTION_OK != PQstatus (db->conn)) {
		PQreset (db->conn);

		/* trigger c_release() */
		if (0 == db->conn_complaint.interval)
			db->conn_complaint.interval = 1;

		if (CONNECTION_OK != PQstatus (db->conn)) {
			c_complain (LOG_ERR, &db->conn_complaint,
					"Failed to connect to database %s (%s): %s",
					db->database, db->instance,
					PQerrorMessage (db->conn));
			return -1;
		}

		db->proto_version = PQprotocolVersion (db->conn);
	}

	db->server_version = PQserverVersion (db->conn);

	if (c_would_release (&db->conn_complaint)) {
		char *server_host;
		int   server_version;

		server_host    = PQhost (db->conn);
		server_version = PQserverVersion (db->conn);

		c_do_release (LOG_INFO, &db->conn_complaint,
				"Successfully %sconnected to database %s (user %s) "
				"at server %s%s%s (server version: %d.%d.%d, "
				"protocol version: %d, pid: %d)", init ? "" : "re",
				PQdb (db->conn), PQuser (db->conn),
				C_PSQL_SOCKET3 (server_host, PQport (db->conn)),
				C_PSQL_SERVER_VERSION3 (server_version),
				db->proto_version, PQbackendPID (db->conn));

		if (3 > db->proto_version)
			log_warn ("Protocol version %d does not support parameters.",
					db->proto_version);
	}
	return 0;
} /* c_psql_check_connection */
开发者ID:clopez,项目名称:collectd,代码行数:59,代码来源:postgresql.c

示例12: PQreset

void Database_PostgreSQL::verifyDatabase()
{
	if (PQstatus(m_conn) == CONNECTION_OK)
		return;

	PQreset(m_conn);
	ping();
}
开发者ID:Gael-de-Sailly,项目名称:minetest,代码行数:8,代码来源:database-postgresql.cpp

示例13: pdo_pgsql_check_liveness

/* {{{ */
static int pdo_pgsql_check_liveness(pdo_dbh_t *dbh)
{
	pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data;
	if (PQstatus(H->server) == CONNECTION_BAD) {
		PQreset(H->server);
	}
	return (PQstatus(H->server) == CONNECTION_OK) ? SUCCESS : FAILURE;
}
开发者ID:mdesign83,项目名称:php-src,代码行数:9,代码来源:pgsql_driver.c

示例14: PQexecParams

int CHttpThread::PgExecuteSQL(PGconn *conn,
                              PGresult * &dataset,
                              const char * szSQL,
                              int nParams,
                              const char * const *paramValues,
                              char * szErrMsg)
{
    int retrycnt=0;

sqlexecretry:
    dataset = PQexecParams(m_pq,
                       szSQL,
                       nParams,       /* 参数个数 */
                       NULL,    /* 让后端推出参数类型 */
                       paramValues,
                       NULL,    /* 因为是文本,所以必须要参数长度 */
                       NULL,    /* 缺省是全部文本参数 */
                       0);      /* 是否是二进制结果 */

    if(  (PQresultStatus(dataset) == PGRES_COMMAND_OK ) ||(PQresultStatus(dataset) == PGRES_TUPLES_OK))
    {
         printf("Successfully execute SQL : %s\n",szSQL);
         return 0;
    }
    else
    {
        sprintf(szErrMsg,"%s",PQerrorMessage(m_pq));
        printf("%s\n",szErrMsg);

        PQclear(dataset);
        if(PQstatus(m_pq) != CONNECTION_OK)
        {
            if(retrycnt > 3)
            {
                return -1;
            }
            sleep(1);
            PQreset(m_pq);
            retrycnt++;

            if(PQstatus(m_pq)!=CONNECTION_OK)
            {
                printf("Thread %d reconnect database fail!\n",m_id);
                PQclear(dataset);
                goto sqlexecretry;
            }
            else
            {
                printf("Thread %d reconnect database success!\n",m_id);
            }
        }
        else //非连接性错误,可能是SQL语句错误等原因
        {
            return -1;
        }
    }

}
开发者ID:osdba,项目名称:fgstats,代码行数:58,代码来源:CHttpThread.cpp

示例15: Excecao

//-----------------------------------------------------------
void ConexaoBD::reiniciar(void)
{
//Dispara um erro caso o usuário tente reiniciar uma conexão não iniciada
    if(!conexao)
        throw Excecao(ERR_CONEXBD_OPRCONEXNAOALOC, __PRETTY_FUNCTION__, __FILE__, __LINE__);

//Reinicia a conexão
    PQreset(conexao);
}
开发者ID:spanc29,项目名称:pgmodeler,代码行数:10,代码来源:conexaobd.cpp


注:本文中的PQreset函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。