• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ PQreset函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: PQreset_stub

CAMLprim value PQreset_stub(value v_conn)
{
  CAMLparam1(v_conn);
  PGconn *conn = get_conn(v_conn);
  caml_enter_blocking_section();
    PQreset(conn);
  caml_leave_blocking_section();
  CAMLreturn(Val_unit);
}
开发者ID:Nevor,项目名称:postgresql-ocaml,代码行数:9,代码来源:postgresql_stubs.c


示例17: PQstatus

// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool PostgreSQLDatabase::isConnected() const {
	if ( _handle == NULL ) return false;
	ConnStatusType stat = PQstatus(_handle);
	if ( stat == CONNECTION_OK ) return true;

	SEISCOMP_ERROR("connection bad (%d) -> reconnect", stat);
	PQreset(_handle);
	return PQstatus(_handle) == CONNECTION_OK;
}
开发者ID:palminn,项目名称:seiscomp3,代码行数:10,代码来源:postgresqldatabaseinterface.cpp


示例18: PQreset

void pgConn::Reset()
{
	PQreset(conn);

	// Reset any vars that need to be in a defined state before connecting
	needColQuoting = false;

	Initialize();
}
开发者ID:AnnaSkawinska,项目名称:pgadmin3,代码行数:9,代码来源:pgConn.cpp


示例19: Exception

void DBConnection::reset(void)
{
	//Raise an erro in case the user try to reset a not opened connection
	if(!connection)
		throw Exception(ERR_OPR_NOT_ALOC_CONN, __PRETTY_FUNCTION__, __FILE__, __LINE__);

	//Reinicia a conexão
	PQreset(connection);
}
开发者ID:K-Lean,项目名称:pgmodeler,代码行数:9,代码来源:dbconnection.cpp


示例20: PQreset

void postgresql_connection_impl::reconnect()
{
  if (PQstatus(conn)==CONNECTION_OK)
    return;

  PQreset(conn);

  if (PQstatus(conn)!=CONNECTION_OK)
    throw database_error("fail to reconnect");
}
开发者ID:beam2d,项目名称:pficommon,代码行数:10,代码来源:connection.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ PQresultErrorField函数代码示例发布时间:2022-05-30
下一篇:
C++ PQresStatus函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap