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


C++ PQgetResult函数代码示例

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


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

示例1: 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

示例2: finishHim

    void finishHim(PGconn *conn) {
        PGresult *res;
        if(PQputCopyEnd(conn, NULL)) {
            //std::cerr << std::endl << "Copy End..." << std::endl;
        }
        while((res = PQgetResult(conn)) != NULL) {
            //std::cerr << "\r" << "Waiting for Copy to finish";
        }
        //std::cerr << "\r" << "Copy finished             " << std:: endl;
        PQendcopy(conn);
        while((res = PQgetResult(conn)) != NULL) {
            //std::cerr << "\r" << "Waiting for Server to Sync";
        }
        //std::cerr << "Sync Done" << std:: endl;

        res = PQexec(conn, "END;");
        if (PQresultStatus(res) != PGRES_COMMAND_OK) {
            std::cerr << "COMMAND END failded: ";
            std::cerr << PQerrorMessage(conn) << std::endl;
            PQclear(res);
            PQfinish(conn);
            return;
        }
        PQfinish(conn);
    }
开发者ID:osm-spline,项目名称:whosh,代码行数:25,代码来源:whosh.cpp

示例3: pq_event

static void pq_event(evutil_socket_t fd, short event, void *arg) {
  struct connection_struct* database = (struct connection_struct*) arg;
  if (database->queries) {
    if (database->queries->sent == 0) {
      PQsendQuery(database->conn, database->queries->query);
      database->queries->sent = 1;
    }
    if (PQconsumeInput(database->conn) && !PQisBusy(database->conn)) {
      PGresult* res = PQgetResult(database->conn);
      while (res) {
        if (database->queries->callback)
          database->queries->callback(res, database->queries->context, database->queries->query);
        if (database->report_errors && PQresultStatus(res) != PGRES_COMMAND_OK)
          fprintf(stderr, "Query: '%s' returned error\n\t%s\n", database->queries->query, PQresultErrorMessage(res));
        PQclear(res);
        res = PQgetResult(database->conn);
      }
      database->query_count--;
      struct query_struct* old = database->queries;
      database->queries = database->queries->next;
      free(old->query);
      free(old);
      pq_event(fd, event, arg);
    }
  }
}
开发者ID:schoentoon,项目名称:smnl,代码行数:26,代码来源:postgres.c

示例4: ClearRemainingResults

/*
 * ClearRemainingResults reads result objects from the connection until we get
 * null, and clears these results. This is the last step in completing an async
 * query.
 */
static void
ClearRemainingResults(PGconn *connection)
{
	PGresult *result = PQgetResult(connection);
	while (result != NULL)
	{
		PQclear(result);
		result = PQgetResult(connection);
	}
}
开发者ID:amosbird,项目名称:citus,代码行数:15,代码来源:multi_client_executor.c

示例5: fprintf

void output_gazetteer_t::stop_copy(void)
{
   PGresult *res;

   /* Do we have a copy active? */
   if (!CopyActive) return;

   /* Terminate the copy */
   if (PQputCopyEnd(Connection, NULL) != 1)
   {
      fprintf(stderr, "COPY_END for place failed: %s\n", PQerrorMessage(Connection));
      util::exit_nicely();
   }

   /* Check the result */
   res = PQgetResult(Connection);
   if (PQresultStatus(res) != PGRES_COMMAND_OK)
   {
      fprintf(stderr, "COPY_END for place failed: %s\n", PQerrorMessage(Connection));
      PQclear(res);
      util::exit_nicely();
   }

   /* Discard the result */
   PQclear(res);

   /* We no longer have an active copy */
   CopyActive = 0;

   return;
}
开发者ID:Captain-Pixel,项目名称:osm2pgsql,代码行数:31,代码来源:output-gazetteer.cpp

示例6: 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

示例7: 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

示例8: pgpool_getfreeconn

PGconn * pgpool_getfreeconn(void)
{
	assert(initialized);
	int id = last_used;
	while (1) {
		id = (id+1) % poolsize;
		PGconn *c = pool[id];
		assert(c);
		PGresult *res;
		int rc;
		// can we get state AND is the server 
		// not blocking and any results?
		while ((rc=PQconsumeInput(c)) && !PQisBusy(c) 
				&& (res=PQgetResult(c))) {
			// we have results. we need to clear those resultsets
			if (reshandler(c, res)) { 
				return NULL;
			}
		}
		if (!rc) {
			log_fatal("pgpool", "Error in PQconsumeInput. %s",
					PQerrorMessage(c));
			return NULL;
		} else if (!PQisBusy(c)) {
			last_used = id;
			return c;
		}
		if (id == last_used) {
			usleep(150000);
		}
	}
}
开发者ID:zakird,项目名称:zdlibc,代码行数:32,代码来源:pgpool.c

示例9: 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

示例10: GetQueryResult

/*
 * GetQueryResult
 *
 * Process the query result.  Returns true if there's no error, false
 * otherwise -- but errors about trying to vacuum a missing relation are
 * reported and subsequently ignored.
 */
static bool
GetQueryResult(PGconn *conn, const char *dbname, const char *progname)
{
	PGresult   *result;

	SetCancelConn(conn);
	while ((result = PQgetResult(conn)) != NULL)
	{
		/*
		 * If errors are found, report them.  Errors about a missing table are
		 * harmless so we continue processing; but die for other errors.
		 */
		if (PQresultStatus(result) != PGRES_COMMAND_OK)
		{
			char	   *sqlState = PQresultErrorField(result, PG_DIAG_SQLSTATE);

			fprintf(stderr, _("%s: vacuuming of database \"%s\" failed: %s"),
					progname, dbname, PQerrorMessage(conn));

			if (sqlState && strcmp(sqlState, ERRCODE_UNDEFINED_TABLE) != 0)
			{
				PQclear(result);
				return false;
			}
		}

		PQclear(result);
	}
	ResetCancelConn();

	return true;
}
开发者ID:liuhb86,项目名称:postgres,代码行数:39,代码来源:vacuumdb.c

示例11: stop_error_copy

static void stop_error_copy(void)
{
   PGresult *res;

   /* Do we have a copy active? */
   if (!CopyErrorActive) return;

   /* Terminate the copy */
   if (PQputCopyEnd(ConnectionError, NULL) != 1)
   {
      fprintf(stderr, "COPY_END for import_polygon_error failed: %s\n", PQerrorMessage(ConnectionError));
      exit_nicely();
   }

   /* Check the result */
   res = PQgetResult(ConnectionError);
   if (PQresultStatus(res) != PGRES_COMMAND_OK)
   {
      fprintf(stderr, "COPY_END for import_polygon_error failed: %s\n", PQerrorMessage(ConnectionError));
      PQclear(res);
      exit_nicely();
   }

   /* Discard the result */
   PQclear(res);

   /* We no longer have an active copy */
   CopyErrorActive = 0;

   return;
}
开发者ID:Megalithikum,项目名称:osm2pgsql,代码行数:31,代码来源:output-gazetteer.c

示例12: libpqrcv_PQexec

/*
 * Send a query and wait for the results by using the asynchronous libpq
 * functions and the backend version of select().
 *
 * We must not use the regular blocking libpq functions like PQexec()
 * since they are uninterruptible by signals on some platforms, such as
 * Windows.
 *
 * We must also not use vanilla select() here since it cannot handle the
 * signal emulation layer on Windows.
 *
 * The function is modeled on PQexec() in libpq, but only implements
 * those parts that are in use in the walreceiver.
 *
 * Queries are always executed on the connection in streamConn.
 */
static PGresult *
libpqrcv_PQexec(const char *query)
{
	PGresult   *result = NULL;
	PGresult   *lastResult = NULL;

	/*
	 * PQexec() silently discards any prior query results on the connection.
	 * This is not required for walreceiver since it's expected that walsender
	 * won't generate any such junk results.
	 */

	/*
	 * Submit a query. Since we don't use non-blocking mode, this also can
	 * block. But its risk is relatively small, so we ignore that for now.
	 */
	if (!PQsendQuery(streamConn, query))
		return NULL;

	for (;;)
	{
		/*
		 * Receive data until PQgetResult is ready to get the result without
		 * blocking.
		 */
		while (PQisBusy(streamConn))
		{
			/*
			 * We don't need to break down the sleep into smaller increments,
			 * and check for interrupts after each nap, since we can just
			 * elog(FATAL) within SIGTERM signal handler if the signal arrives
			 * in the middle of establishment of replication connection.
			 */
			if (!libpq_select(-1))
				continue;		/* interrupted */
			if (PQconsumeInput(streamConn) == 0)
				return NULL;	/* trouble */
		}

		/*
		 * Emulate the PQexec()'s behavior of returning the last result when
		 * there are many. Since walsender will never generate multiple
		 * results, we skip the concatenation of error messages.
		 */
		result = PQgetResult(streamConn);
		if (result == NULL)
			break;				/* query is complete */

		PQclear(lastResult);
		lastResult = result;

		if (PQresultStatus(lastResult) == PGRES_COPY_IN ||
			PQresultStatus(lastResult) == PGRES_COPY_OUT ||
			PQresultStatus(lastResult) == PGRES_COPY_BOTH ||
			PQstatus(streamConn) == CONNECTION_BAD)
			break;
	}

	return lastResult;
}
开发者ID:gurjeet,项目名称:postgres,代码行数:76,代码来源:libpqwalreceiver.c

示例13: pgsql_CopyData

void output_gazetteer_t::stop_copy(void)
{
    /* Do we have a copy active? */
    if (!copy_active) return;

    if (buffer.length() > 0)
    {
        pgsql_CopyData("place", Connection, buffer);
        buffer.clear();
    }

    /* Terminate the copy */
    if (PQputCopyEnd(Connection, nullptr) != 1)
    {
        std::cerr << "COPY_END for place failed: " << PQerrorMessage(Connection) << "\n";
        util::exit_nicely();
    }

    /* Check the result */
    PGresult *res = PQgetResult(Connection);
    if (PQresultStatus(res) != PGRES_COMMAND_OK)
    {
        std::cerr << "COPY_END for place failed: " << PQerrorMessage(Connection) << "\n";
        PQclear(res);
        util::exit_nicely();
    }

    /* Discard the result */
    PQclear(res);

    /* We no longer have an active copy */
    copy_active = false;
}
开发者ID:JesseCrocker,项目名称:osm2pgsql,代码行数:33,代码来源:output-gazetteer.cpp

示例14: 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

示例15: evpg_query_finished

static void
evpg_query_finished(int sock, short which, void **data)
{
    struct evpg_db_node *dbnode;
    struct evpg_cfg *config;
    const char *querystr;
    void (*cb)(PGresult *, void *); 
    void *usrdata;
    struct event *event;

    config   = data[0];
    querystr = data[1];
    cb       = data[2];
    usrdata  = data[3];
    dbnode   = data[4];
    event    = data[5];

    PQconsumeInput(dbnode->dbconn);

    if (PQisBusy(dbnode->dbconn) == 0)
    {
	PGresult *result;
	result = PQgetResult(dbnode->dbconn);
	cb(result, usrdata);
	PQclear(result);
	free(event);
	free(data);
	evpg_set_ready(config, dbnode);
	return;
    }

    /* this query has not finished */
    event_set(event, sock, EV_READ, (void *)evpg_query_finished, data);
    event_add(event, 0);
}
开发者ID:ellzey,项目名称:evpg,代码行数:35,代码来源:evpg.c


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