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

C++ PQnfields函数代码示例

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

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



在下文中一共展示了PQnfields函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:danielcode,项目名称:ruby-pg,代码行数:24,代码来源:pg_result.c


示例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;
}
开发者ID:BertramScharpf,项目名称:ruby-pgsql,代码行数:21,代码来源:conn_exec.c


示例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;
}
开发者ID:PJMODOS,项目名称:postgres,代码行数:55,代码来源:common.c


示例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;
	}
开发者ID:Renegade334,项目名称:inspircd,代码行数:14,代码来源:m_pgsql.cpp


示例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));
}
开发者ID:gvlx,项目名称:gawkextlib,代码行数:14,代码来源:pgsql.c


示例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);
}
开发者ID:danielcode,项目名称:ruby-pg,代码行数:23,代码来源:pg_result.c


示例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);
	}
}
开发者ID:kotsachin,项目名称:pg_rewind,代码行数:52,代码来源:libpq_fetch.c


示例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;    
}
开发者ID:locked,项目名称:rsync-pgsql,代码行数:49,代码来源:log_pgsql.c


示例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;
}
开发者ID:Aion,项目名称:mangos,代码行数:49,代码来源:DatabasePostgre.cpp


示例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;
}
开发者ID:jpmens,项目名称:mosquitto-auth-plug,代码行数:49,代码来源:be-postgres.c


示例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));
}
开发者ID:polyactis,项目名称:test,代码行数:15,代码来源:sel3.c


示例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;
}
开发者ID:bitbouncer,项目名称:phoebe,代码行数:15,代码来源:avro_postgres.cpp


示例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;
}
开发者ID:ByeDream,项目名称:pixellight,代码行数:15,代码来源:DatabaseQueryResult.cpp


示例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;
}
开发者ID:AndresRicardoTorres,项目名称:IPMPAIS,代码行数:15,代码来源:postgresql.cpp


示例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;
}
开发者ID:ldmosquera,项目名称:ruby-pg,代码行数:21,代码来源:pg_result.c


示例16: query

		virtual uint query( const char * statement ) 
		{
			_clearResult();

			if (this->conn == 0)
				return _error(0,0);

			res = PQexec(this->conn, statement);
			if (this->res == 0)
				return _error(0,0);
			
		    this->ncols = PQnfields(this->res);
			this->nrows = PQntuples(this->res);
			return 1;
		}
开发者ID:berak,项目名称:e6,代码行数:15,代码来源:DataBasePostgres.cpp


示例17: _log

char *be_pg_getuser(void *handle, const char *username, const char *password, int *authenticated)
{
	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 (NULL);

	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));
		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);

	return (value);
}
开发者ID:Aquevix,项目名称:mosquitto-auth-plug,代码行数:48,代码来源:be-postgres.c


示例18: pgresult_fields

/*
 * call-seq:
 *    res.fields() -> Array
 *
 * Returns an array of Strings representing the names of the fields in the result.
 */
static VALUE
pgresult_fields(VALUE self)
{
	PGresult *result = pgresult_get( self );
	int n = PQnfields( result );
	VALUE fields = rb_ary_new2( n );
	int i;

	for ( i = 0; i < n; i++ ) {
		VALUE val = rb_tainted_str_new2(PQfname(result, i));
		ASSOCIATE_INDEX(val, self);
		rb_ary_store( fields, i, val );
	}

	return fields;
}
开发者ID:ldmosquera,项目名称:ruby-pg,代码行数:22,代码来源:pg_result.c


示例19: printResults

void printResults(PGresult *res)
{
    /* first, print out the attribute names */
    int nFields = PQnfields(res);
    for (int i = 0; i < nFields; i++)
        printf("%-15s", PQfname(res, i));
    printf("\n\n");

    /* next, print out the rows */
    for (int i = 0; i < PQntuples(res); i++)
    {
        for (int j = 0; j < nFields; j++)
            printf("%-15s", PQgetvalue(res, i, j));
        printf("\n");
    }
}
开发者ID:andrisama,项目名称:grpc_playground,代码行数:16,代码来源:accessArticles.c


示例20: pgresult_getlength

/*
 * call-seq:
 *    res.getlength( tup_num, field_num ) -> Fixnum
 *
 * Returns the (String) length of the field in bytes.
 *
 * Equivalent to <tt>res.value(<i>tup_num</i>,<i>field_num</i>).length</tt>.
 */
static VALUE
pgresult_getlength(VALUE self, VALUE tup_num, VALUE field_num)
{
	PGresult *result;
	int i = NUM2INT(tup_num);
	int j = NUM2INT(field_num);

	result = pgresult_get(self);
	if (i < 0 || i >= PQntuples(result)) {
		rb_raise(rb_eArgError,"invalid tuple number %d", i);
	}
	if (j < 0 || j >= PQnfields(result)) {
		rb_raise(rb_eArgError,"invalid field number %d", j);
	}
	return INT2FIX(PQgetlength(result, i, j));
}
开发者ID:ldmosquera,项目名称:ruby-pg,代码行数:24,代码来源:pg_result.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ PQntuples函数代码示例发布时间:2022-05-30
下一篇:
C++ PQmblen函数代码示例发布时间: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