本文整理汇总了C++中PQnfields函数的典型用法代码示例。如果您正苦于以下问题:C++ PQnfields函数的具体用法?C++ PQnfields怎么用?C++ PQnfields使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PQnfields函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pgresult_ftablecol
/*
* call-seq:
* res.ftablecol( column_number ) -> Fixnum
*
* Returns the column number (within its table) of the table from
* which the column _column_number_ is made up.
*
* Raises ArgumentError if _column_number_ is out of range or if
* the column number from its table is undefined for that column.
*/
static VALUE
pgresult_ftablecol(VALUE self, VALUE column_number)
{
int col_number = NUM2INT(column_number);
PGresult *pgresult = pgresult_get(self);
int n;
if( col_number < 0 || col_number >= PQnfields(pgresult))
rb_raise(rb_eArgError,"Invalid column index: %d", col_number);
n = PQftablecol(pgresult, col_number);
return INT2FIX(n);
}
示例2: pgconn_select_value
/*
* call-seq:
* conn.select_value( query, *bind_values)
*
* Return the first value of the first row of the query results.
* Equivalent to conn.query( query, *bind_values).first.first
*/
VALUE
pgconn_select_value( int argc, VALUE *argv, VALUE self)
{
VALUE cmd, par;
VALUE res;
struct pgresult_data *r;
pg_parse_parameters( argc, argv, &cmd, &par);
res = pg_statement_exec( self, cmd, par);
Data_Get_Struct( res, struct pgresult_data, r);
return PQntuples( r->res) > 0 && PQnfields( r->res) > 0 ?
pg_fetchresult( r, 0, 0) : Qnil;
}
示例3: StoreQueryTuple
/*
* StoreQueryTuple: assuming query result is OK, save data into variables
*
* Returns true if successful, false otherwise.
*/
static bool
StoreQueryTuple(const PGresult *result)
{
bool success = true;
if (PQntuples(result) < 1)
{
psql_error("no rows returned for \\gset\n");
success = false;
}
else if (PQntuples(result) > 1)
{
psql_error("more than one row returned for \\gset\n");
success = false;
}
else
{
int i;
for (i = 0; i < PQnfields(result); i++)
{
char *colname = PQfname(result, i);
char *varname;
char *value;
/* concate prefix and column name */
varname = psprintf("%s%s", pset.gset_prefix, colname);
if (!PQgetisnull(result, 0, i))
value = PQgetvalue(result, 0, i);
else
{
/* for NULL value, unset rather than set the variable */
value = NULL;
}
if (!SetVariable(pset.vars, varname, value))
{
psql_error("could not set variable \"%s\"\n", varname);
free(varname);
success = false;
break;
}
free(varname);
}
}
return success;
}
示例4: GetRow
bool GetRow(SQLEntries& result)
{
if (currentrow >= PQntuples(res))
return false;
int ncols = PQnfields(res);
for(int i = 0; i < ncols; i++)
{
result.push_back(GetValue(currentrow, i));
}
currentrow++;
return true;
}
示例5: do_pg_nfields
static awk_value_t *
do_pg_nfields(int nargs, awk_value_t *result)
{
PGresult *res;
if (do_lint && (nargs > 1))
lintwarn(ext_id, _("pg_nfields: called with too many arguments"));
if (!(res = find_handle(results, 0))) {
set_ERRNO(_("pg_nfields called with unknown result handle"));
RET_NUM(-1);
}
RET_NUM(PQnfields(res));
}
示例6: pgresult_fmod
/*
* call-seq:
* res.fmod( column_number )
*
* Returns the type modifier associated with column _column_number_. See
* the #ftype method for an example of how to use this.
*
* Raises an ArgumentError if _column_number_ is out of range.
*/
static VALUE
pgresult_fmod(VALUE self, VALUE column_number)
{
PGresult *result = pgresult_get(self);
int fnumber = NUM2INT(column_number);
int modifier;
if (fnumber < 0 || fnumber >= PQnfields(result)) {
rb_raise(rb_eArgError, "Column number is out of range: %d",
fnumber);
}
modifier = PQfmod(result,fnumber);
return INT2NUM(modifier);
}
示例7: libpqProcessFileList
/*
* Get a file list.
*/
void
libpqProcessFileList(void)
{
PGresult *res;
const char *sql;
int i;
sql =
"-- Create a recursive directory listing of the whole data directory\n"
"with recursive files (path, size, isdir) as (\n"
" select filename as path, size, isdir\n"
" from (select pg_ls_dir('.') as filename) as filenames,\n"
" pg_stat_file(filename) as this\n"
" union all\n"
" select parent.path || '/' || filename, this.size, this.isdir\n"
" from files as parent,\n"
" pg_ls_dir(parent.path) as filename,\n"
" pg_stat_file(parent.path || '/' || filename) as this\n"
" where parent.isdir = 't'\n"
")\n"
"-- Using the cte, fetch all files in chunks.\n"
"select path, size, isdir from files\n";
res = PQexec(conn, sql);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
fprintf(stderr, "unexpected result while fetching file list: %s\n",
PQresultErrorMessage(res));
exit(1);
}
/* sanity check the result set */
if (!(PQnfields(res) == 3))
{
fprintf(stderr, "unexpected result set while fetching file list\n");
exit(1);
}
/* Read result to local variables */
for (i = 0; i < PQntuples(res); i++)
{
char *path = PQgetvalue(res, i, 0);
int filesize = atoi(PQgetvalue(res, i, 1));
bool isdir = (strcmp(PQgetvalue(res, i, 2), "t") == 0);
process_remote_file(path, filesize, isdir);
}
}
示例8: rprintf
char *pw_pgsql_getquery(PGconn * const id_sql_server,
const char * const orig_query,
const char * const account,
const char * const ip,
const char * const port,
const char * const peer_ip,
const char * const decimal_ip)
{
PGresult *qresult = NULL;
size_t length;
char *answer = NULL;
char query[PGSQL_MAX_REQUEST_LENGTH];
if (orig_query == NULL || *orig_query == 0) {
rprintf(FLOG,"ERR1\n");
goto bye;
}
if (sqlsubst(orig_query, query, sizeof query,
account, ip, port, peer_ip, decimal_ip) == NULL) {
rprintf(FLOG,"ERR2\n");
goto bye;
}
if ((qresult = PQexec(id_sql_server, query)) == NULL) {
//logfile(LOG_WARNING, MSG_SQL_WRONG_PARMS " : [%s]", query);
rprintf(FLOG,"MSG_SQL_WRONG_PARMS : [%s]\n", query);
goto bye;
}
if (PQresultStatus(qresult) != PGRES_TUPLES_OK ||
PQnfields(qresult) != 1 ||
PQntuples(qresult) != 1 ||
PQgetisnull(qresult, 0, 0)) {
rprintf(FLOG,"ERR Multiples\n");
goto bye;
}
if ((length = (size_t) PQgetlength(qresult, 0, 0) + (size_t) 1U)
<= (size_t) 1U || (answer = malloc(length)) == NULL) {
rprintf(FLOG,"ERR4\n");
goto bye;
}
strncpy(answer, PQgetvalue(qresult, 0, 0), length - (size_t) 1U);
answer[length - (size_t) 1U] = 0;
bye:
if (qresult != NULL) {
PQclear(qresult);
}
return answer;
}
示例9: query_connection_guard
QueryResult* DatabasePostgre::Query(const char *sql)
{
if (!mPGconn)
return 0;
uint64 rowCount = 0;
uint32 fieldCount = 0;
// guarded block for thread-safe request
ACE_Guard<ACE_Thread_Mutex> query_connection_guard(mMutex);
#ifdef MANGOS_DEBUG
uint32 _s = getMSTime();
#endif
// Send the query
PGresult * result = PQexec(mPGconn, sql);
if (!result )
{
return NULL;
}
if (PQresultStatus(result) != PGRES_TUPLES_OK)
{
sLog.outErrorDb( "SQL : %s", sql );
sLog.outErrorDb( "SQL %s", PQerrorMessage(mPGconn));
PQclear(result);
return NULL;
}
else
{
#ifdef MANGOS_DEBUG
sLog.outDebug("[%u ms] SQL: %s", getMSTime() - _s, sql );
#endif
}
rowCount = PQntuples(result);
fieldCount = PQnfields(result);
// end guarded block
if (!rowCount)
{
PQclear(result);
return NULL;
}
QueryResultPostgre * queryResult = new QueryResultPostgre(result, rowCount, fieldCount);
queryResult->NextRow();
return queryResult;
}
示例10: be_pg_getuser
int be_pg_getuser(void *handle, const char *username, const char *password, char **phash, const char *clientid)
{
struct pg_backend *conf = (struct pg_backend *)handle;
char *value = NULL, *v = NULL;
long nrows;
PGresult *res = NULL;
_log(LOG_DEBUG, "GETTING USERS: %s", username);
if (!conf || !conf->userquery || !username || !*username)
return BACKEND_DEFER;
const char *values[1] = {username};
int lengths[1] = {strlen(username)};
int binary[1] = {0};
res = PQexecParams(conf->conn, conf->userquery, 1, NULL, values, lengths, binary, 0);
if (PQresultStatus(res) != PGRES_TUPLES_OK) {
_log(LOG_DEBUG, "%s\n", PQresultErrorMessage(res));
if(PQstatus(conf->conn) == CONNECTION_BAD){
_log(LOG_NOTICE, "Noticed a postgres connection loss. Trying to reconnect ...\n");
//try to reinitiate the database connection
PQreset(conf->conn);
}
goto out;
}
if ((nrows = PQntuples(res)) != 1) {
//DEBUG fprintf(stderr, "rowcount = %ld; not ok\n", nrows);
goto out;
}
if (PQnfields(res) != 1) {
//DEBUG fprintf(stderr, "numfields not ok\n");
goto out;
}
if ((v = PQgetvalue(res, 0, 0)) == NULL) {
goto out;
}
value = (v) ? strdup(v) : NULL;
out:
PQclear(res);
*phash = value;
return BACKEND_DEFER;
}
示例11: show_column_info
void show_column_info(PGresult* result)
{
int num_columns=0;
int i;
if(!result)
return;
num_columns=PQnfields(result);
printf("%d columns in the result set\n",num_columns);
for(i=0;i<num_columns;i++)
printf("Field: %d,Name: %s,Internal size: %d\n",
i,
PQfname(result,i),
PQfsize(result,i));
}
示例12: schema_for_table_row
boost::shared_ptr<avro::RecordSchema> schema_for_table_row(std::string schema_name, boost::shared_ptr<PGresult> res)
{
boost::shared_ptr<avro::RecordSchema> record_schema = boost::make_shared<avro::RecordSchema>(schema_name);
int nFields = PQnfields(res.get());
for (int i = 0; i < nFields; i++)
{
Oid col_type = PQftype(res.get(), i);
std::string col_name = PQfname(res.get(), i);
boost::shared_ptr<avro::Schema> col_schema = schema_for_oid(col_type);
/* TODO ensure that names abide by Avro's requirements */
record_schema->addField(col_name, *col_schema);
}
return record_schema;
}
示例13: PQntuples
const HashMap<String, String> *DatabaseQueryResult::FetchRow()
{
const uint32 nRow = PQntuples(m_pPostgreSQLResult);
if (m_nCurrentRow >= nRow)
return nullptr; // Error!
const uint32 nColumn = PQnfields(m_pPostgreSQLResult);
m_mapRow.Clear();
for (uint32 i=0; i<nColumn; i++)
m_mapRow.Add(PQfname(m_pPostgreSQLResult, i), PQgetvalue(m_pPostgreSQLResult, m_nCurrentRow, i));
m_nCurrentRow++;
// Return a pointer to the row map
return &m_mapRow;
}
示例14: ResultadoConsulta
ResultadoConsulta* PG::select(const char* query)
{
ResultadoConsulta *resultado = new ResultadoConsulta();
PGresult *res = PQexec(conn,query);
for (int i=0;i<PQntuples(res);i++)
{
std::vector<const char*> unVector;
for(int j=0;j<PQnfields(res);j++)
{
unVector.push_back(PQgetvalue(res, i, j));
}
resultado->push_back(unVector);
}
return resultado;
}
示例15: pgresult_fname
/*
* call-seq:
* res.fname( index ) -> String
*
* Returns the name of the column corresponding to _index_.
*/
static VALUE
pgresult_fname(VALUE self, VALUE index)
{
VALUE fname;
PGresult *result;
int i = NUM2INT(index);
result = pgresult_get(self);
if (i < 0 || i >= PQnfields(result)) {
rb_raise(rb_eArgError,"invalid field number %d", i);
}
fname = rb_tainted_str_new2(PQfname(result, i));
ASSOCIATE_INDEX(fname, self);
return fname;
}