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

C++ PQfname函数代码示例

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

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



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

示例1: encode_result

void encode_result(ei_x_buff* x, PGresult* res, PGconn* conn)
{
    int row, n_rows, col, n_cols;
    switch (PQresultStatus(res)) {
    case PGRES_TUPLES_OK: 
	n_rows = PQntuples(res); 
	n_cols = PQnfields(res); 
	ei_x_encode_tuple_header(x, 2);
	encode_ok(x);
	ei_x_encode_list_header(x, n_rows+1);
 	ei_x_encode_list_header(x, n_cols);
	for (col = 0; col < n_cols; ++col) {
	    ei_x_encode_string(x, PQfname(res, col));
	}
	ei_x_encode_empty_list(x); 
	for (row = 0; row < n_rows; ++row) {
	    ei_x_encode_list_header(x, n_cols);
	    for (col = 0; col < n_cols; ++col) {
		ei_x_encode_string(x, PQgetvalue(res, row, col));
	    }
	    ei_x_encode_empty_list(x);
	}
	ei_x_encode_empty_list(x); 
	break; 
    case PGRES_COMMAND_OK:
	ei_x_encode_tuple_header(x, 2);
        encode_ok(x);
	ei_x_encode_string(x, PQcmdTuples(res));
        break;
    default:
	encode_error(x, conn);
	break;
    }
}
开发者ID:Dasudian,项目名称:otp,代码行数:34,代码来源:pg_encode.c


示例2: assert

const char *PostgresqlResultSet_getColumnName(T R, int columnIndex) {
        assert(R);
        columnIndex--;
        if (R->columnCount <= 0 || columnIndex < 0 || columnIndex > R->columnCount)
                return NULL;
        return PQfname(R->res, columnIndex);
}
开发者ID:EchoLiao,项目名称:libzdb,代码行数:7,代码来源:PostgresqlResultSet.c


示例3: PQnfields

void ResultSet::init(PGresult* res)
{
	int nFields													= PQnfields(res);

	for (int i = 0; i < nFields; i = i + 1)						{ this->columns.push_back(PQfname(res, i)); }

	int nTuples													= PQntuples(res);
	std::vector<std::string*>* v;
	char* value;

	for (int i = 0; i < nTuples; i = i + 1)
	{
		v														= new std::vector<std::string*>();

		for (int j = 0; j < nFields; j++)
		{
			if (PQgetisnull(res, i, j))							{ v->push_back(nullptr); }
			else
			{
				value											= PQgetvalue(res, i, j);

				v->push_back(new std::string(value, PQgetlength(res, i, j)));
			}
		}

		this->rows.push_back(v);
	}
}
开发者ID:nullquery,项目名称:pgsql4dm,代码行数:28,代码来源:ResultSet.cpp


示例4: KCSQLResultBase

PgSQLResult::PgSQLResult(PgSQLConnection* pConnection, PGresult * sqlResult)
    : KCSQLResultBase(pConnection)
{
    m_sqlResult = sqlResult;
    if (m_sqlResult)
    {
        m_numRows = PQntuples(m_sqlResult);
        m_numFields = PQnfields(m_sqlResult);
        m_sqlRow = -1;

        for (int i = 0; i<m_numFields; ++i)
        {
            m_vName.push_back( PQfname(m_sqlResult, i) );
        }
        m_vValue.resize(m_numFields);
        const char* pszResult = PQcmdTuples(sqlResult);
        if (pszResult)
        {
            m_affectRowCount = atoi(pszResult);
        }
        Seek(0);
    }
    else
    {
        m_sqlRow = -1;
        m_numRows = 0;
        m_numFields = 0;
    }
}
开发者ID:lonsharn,项目名称:lsh_server,代码行数:29,代码来源:kc_pgsql.cpp


示例5: doSQL

void doSQL(PGconn *conn, char *command){
	PGresult *result;
	printf("%s\n", command);
	result = PQexec(conn, command);
	printf("Result message: %s\n", PQresultErrorMessage(result));	
	
	switch(PQresultStatus(result)) {
		case PGRES_TUPLES_OK:{
			int n = 0, m = 0;
			int nrows   = PQntuples(result);
			int nfields = PQnfields(result);
			for(m = 0; m < nrows; m++) {
				for(n = 0; n < nfields; n++)
					printf(" %s = %s", PQfname(result, n),PQgetvalue(result,m,n));
				printf("\n");
      			}

			if(nrows == 0 || nfields == 0){
				printf("Car does not exist in database!");
				searchT = 0;
			}
		}
	}

	PQclear(result);
}
开发者ID:henio180,项目名称:AplikacjeBazodanowe,代码行数:26,代码来源:pr1.c


示例6: ON

bool DataLayer::find(string table, string search_by_attr, string attr_value, vector<map<string, string> >& search_results, string joins){
	string query;
	search_results.clear(); // reset the results
	if(joins == "false"){
		query = "SELECT * FROM " + table + " WHERE " + search_by_attr + " ~* '" + attr_value + "';";
	} else {
		// making this less abstracted than originally planned, since I only use it for one purpose
		query = "SELECT * FROM " + table + " INNER JOIN " + joins + " ON (accounts.client_id = clients.id) WHERE " + search_by_attr + " ~* '" + attr_value + "';";
	}
	PGresult* res = PQexec(conn, query.c_str());
	if(PQresultStatus(res) == PGRES_TUPLES_OK && PQntuples(res) > 0){

		for(int i = 0; i < PQntuples(res); i++){
			map<string, string> row;
			for(int j = 0; j < PQnfields(res); j++){
			  row[PQfname(res, j)] = PQgetvalue(res, i, j);
		  }
			search_results.push_back(row);
			row.clear();

		}
		return true;
	}
	return false;
}
开发者ID:pjr0009,项目名称:cpp-project2,代码行数:25,代码来源:DataLayer.cpp


示例7: where

vector<Author> pgBook::authorsFor(Book book)
{
	string sql = where("authors", book.authorsCondition());
	PGresult *result = driver->selectsDataSQL(sql);
	data itemAttributes;
	vector<Author> authors;
	int rows = PQntuples(result);
	if(rows)
	{
		for(int j=0;j<rows;j++)
		{
			for (int i=0; i<PQnfields(result); i++)
			{
				itemAttributes[PQfname(result, i)] = PQgetvalue(result, j, i);
			}
			Author item(itemAttributes);
			authors.push_back(item);
		}
		PQclear(result);
	}
	else
	{
		cout<<"Authors don\'t exist!"<<endl;
	}
	return authors;
}
开发者ID:Fabel,项目名称:pgsql,代码行数:26,代码来源:pgBook.cpp


示例8: PQfname

wxString PgStatement::GetFieldName(int nIndex)
  {
  char * szName = PQfname(pgr, nIndex);
	wxString sName = wxString::FromAscii(szName);

  return sName;
  }
开发者ID:joeyates,项目名称:sherpa,代码行数:7,代码来源:postgres.cpp


示例9: PQnfields

   int 
   PGRecordset::GetColumnIndex_(const AnsiString &sColumnName) const
   //---------------------------------------------------------------------------()
   // DESCRIPTION:
   // Returns the index of a column in the recordset, based on the columns name.
   //---------------------------------------------------------------------------()
   {
      if (!result_)
      {
         // Result set wasn't initialized. Shouldn't happen.
         ErrorManager::Instance()->ReportError(HM::ErrorManager::High, 5093, "PGConnection::Close", "An unknown error occurred while closing recordset.");
         return 0;
      }

      unsigned int iFieldCount = PQnfields(result_);

      for (unsigned int i = 0; i <= iFieldCount; i++)
      {
         AnsiString sColName = PQfname(result_, i);

         if (sColName == sColumnName)
            return i;

      }      

      // Result set wasn't initialized. Shouldn't happen.
      ErrorManager::Instance()->ReportError(ErrorManager::High, 5092, "MySQLRecordset::GetColumnIndex_", "The requested column was not found. Column name: " + sColumnName);

      return -1;
   }
开发者ID:David-Polehonski,项目名称:hmailserver,代码行数:30,代码来源:PGRecordset.cpp


示例10: postgres_ingest_stats

static void postgres_ingest_stats(postgres_check_info_t *ci) {
  if(ci->rv == PGRES_TUPLES_OK) {
    /* metrics */
    int nrows, ncols, i, j;
    nrows = PQntuples(ci->result);
    ncols = PQnfields(ci->result);
    noit_stats_set_metric(&ci->current, "row_count", METRIC_INT32, &nrows);
    for (i=0; i<nrows; i++) {
      noitL(nldeb, "postgres: row %d [%d cols]:\n", i, ncols);
      if(ncols<2) continue;
      if(PQgetisnull(ci->result, i, 0)) continue;
      for (j=1; j<ncols; j++) {
        Oid coltype;
        int iv, *piv;
        int64_t lv, *plv;
        double dv, *pdv;
        char *sv;
        char mname[128];
  
        snprintf(mname, sizeof(mname), "%s`%s",
                 PQgetvalue(ci->result, i, 0), PQfname(ci->result, j));
        coltype = PQftype(ci->result, j);
        noitL(nldeb, "postgres:   col %d (%s) type %d:\n", j, mname, coltype);
        switch(coltype) {
          case BOOLOID:
            if(PQgetisnull(ci->result, i, j)) piv = NULL;
            else {
              iv = strcmp(PQgetvalue(ci->result, i, j), "f") ? 1 : 0;
              piv = &iv;
            }
            noit_stats_set_metric(&ci->current, mname, METRIC_INT32, piv);
            break;
          case INT2OID:
          case INT4OID:
          case INT8OID:
            if(PQgetisnull(ci->result, i, j)) plv = NULL;
            else {
              lv = strtoll(PQgetvalue(ci->result, i, j), NULL, 10);
              plv = &lv;
            }
            noit_stats_set_metric(&ci->current, mname, METRIC_INT64, plv);
          case FLOAT4OID:
          case FLOAT8OID:
          case NUMERICOID:
            if(PQgetisnull(ci->result, i, j)) pdv = NULL;
            else {
              dv = atof(PQgetvalue(ci->result, i, j));
              pdv = &dv;
            }
            noit_stats_set_metric(&ci->current, mname, METRIC_DOUBLE, pdv);
          default:
            if(PQgetisnull(ci->result, i, j)) sv = NULL;
            else sv = PQgetvalue(ci->result, i, j);
            noit_stats_set_metric(&ci->current, mname, METRIC_GUESS, sv);
            break;
        }
      }
    }
  }
}
开发者ID:meineerde,项目名称:reconnoiter,代码行数:60,代码来源:postgres.c


示例11: PQfname

std::string PgsqlReaderProvider::get_column_name(int index) const
{
	const char *const string = PQfname(result, index);
	if (string == nullptr)
		throw ("Index out of range");
	return std::string(string);
}
开发者ID:Zenol,项目名称:ClanPgsql,代码行数:7,代码来源:pgsql_reader_provider.cpp


示例12: pgsql_stmt_describe

static int pgsql_stmt_describe(pdo_stmt_t *stmt, int colno)
{
	pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
	struct pdo_column_data *cols = stmt->columns;
	struct pdo_bound_param_data *param;
	char *str;

	if (!S->result) {
		return 0;
	}

	str = PQfname(S->result, colno);
	cols[colno].name = zend_string_init(str, strlen(str), 0);
	cols[colno].maxlen = PQfsize(S->result, colno);
	cols[colno].precision = PQfmod(S->result, colno);
	S->cols[colno].pgsql_type = PQftype(S->result, colno);

	switch (S->cols[colno].pgsql_type) {

		case BOOLOID:
			cols[colno].param_type = PDO_PARAM_BOOL;
			break;

		case OIDOID:
			/* did the user bind the column as a LOB ? */
			if (stmt->bound_columns && (
					(param = zend_hash_index_find_ptr(stmt->bound_columns, colno)) != NULL ||
					(param = zend_hash_find_ptr(stmt->bound_columns, cols[colno].name)) != NULL)) {

				if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_LOB) {
					cols[colno].param_type = PDO_PARAM_LOB;
					break;
				}
			}
			cols[colno].param_type = PDO_PARAM_INT;
			break;

		case INT2OID:
		case INT4OID:
			cols[colno].param_type = PDO_PARAM_INT;
			break;

		case INT8OID:
			if (sizeof(zend_long)>=8) {
				cols[colno].param_type = PDO_PARAM_INT;
			} else {
				cols[colno].param_type = PDO_PARAM_STR;
			}
			break;

		case BYTEAOID:
			cols[colno].param_type = PDO_PARAM_LOB;
			break;

		default:
			cols[colno].param_type = PDO_PARAM_STR;
	}

	return 1;
}
开发者ID:Furgas,项目名称:php-src,代码行数:60,代码来源:pgsql_statement.c


示例13: string

 string column::name() const
 {
     if (!is_valid()) {
         return string();
     }
     return PQfname(stmt_.get(), column_);
 }
开发者ID:skyformat99,项目名称:arg3db,代码行数:7,代码来源:column.cpp


示例14: doSQL

void doSQL(PGconn *conn, char *command)
{
  PGresult *result;

  printf("%s\n", command);

  result = PQexec(conn, command);
  printf("status is %s\n", PQresStatus(PQresultStatus(result)));
  printf("#rows affected %s\n", PQcmdTuples(result));
  printf("result message: %s\n", PQresultErrorMessage(result));

  switch(PQresultStatus(result)) {
  case PGRES_TUPLES_OK:
    {
      int r, n;
      int nrows = PQntuples(result);
      int nfields = PQnfields(result);
      printf("number of rows returned = %d\n", nrows);
      printf("number of fields returned = %d\n", nfields);
      for(r = 0; r < nrows; r++) {
	for(n = 0; n < nfields; n++)
	  printf(" %s = %s(%d),", 
		 PQfname(result, n), 
		 PQgetvalue(result, r, n),
		 // rozmiar pola w bajtach
		 PQgetlength(result, r, n));
	printf("\n");
      }
    }
  }
  PQclear(result);
}
开发者ID:swistak,项目名称:skarbnik,代码行数:32,代码来源:select1.c


示例15: Lisp_PQfname

LispObj *
Lisp_PQfname(LispBuiltin *builtin)
/*
 pq-fname result field-number
 */
{
    char *string;
    int field;
    PGresult *res;

    LispObj *result, *field_number;

    field_number = ARGUMENT(1);
    result = ARGUMENT(0);

    if (!CHECKO(result, PGresult_t))
	LispDestroy("%s: cannot convert %s to PGresult*",
		    STRFUN(builtin), STROBJ(result));
    res = (PGresult*)(result->data.opaque.data);

    CHECK_INDEX(field_number);
    field = FIXNUM_VALUE(field_number);

    string = PQfname(res, field);

    return (string ? STRING(string) : NIL);
}
开发者ID:aosm,项目名称:X11,代码行数:27,代码来源:psql.c


示例16: execute_put_values

/**********************************
 * execute_put_values

 Put the values of one tuple into Tcl variables named like the
 column names, or into an array indexed by the column names.
 **********************************/
static int
execute_put_values(Tcl_Interp *interp, CONST84 char *array_varname,
				   PGresult *result, int tupno)
{
	int			i;
	int			n;
	char	   *fname;
	char	   *value;

	/*
	 * For each column get the column name and value and put it into a Tcl
	 * variable (either scalar or array item)
	 */
	n = PQnfields(result);
	for (i = 0; i < n; i++)
	{
		fname = PQfname(result, i);
		value = PQgetvalue(result, tupno, i);

		if (array_varname != NULL)
		{
			if (Tcl_SetVar2(interp, array_varname, fname, value,
							TCL_LEAVE_ERR_MSG) == NULL)
				return TCL_ERROR;
		}
		else
		{
			if (Tcl_SetVar(interp, fname, value, TCL_LEAVE_ERR_MSG) == NULL)
				return TCL_ERROR;
		}
	}

	return TCL_OK;
}
开发者ID:sunyangkobe,项目名称:cscd43,代码行数:40,代码来源:pgtclCmds.c


示例17: PQnfields

Row::Row(PGresult *exec_result, int row) {
  int field_count = PQnfields( exec_result );
  for(int column = 0; column < field_count; ++column) {
    string name = PQfname(exec_result, column);
    attributes_[name] = Attribute::from_field(exec_result, row, column);
  }
}
开发者ID:wqx081,项目名称:cpp-active-record,代码行数:7,代码来源:postgresql_row.cpp


示例18: cCommand_execute_reader

static VALUE cCommand_execute_reader(int argc, VALUE *argv[], VALUE self) {
  VALUE reader, query;
  VALUE field_names, field_types;

  int i;
  int field_count;
  int infer_types = 0;

  VALUE connection = rb_iv_get(self, "@connection");
  VALUE postgres_connection = rb_iv_get(connection, "@connection");
  if (Qnil == postgres_connection) {
    rb_raise(eConnectionError, "This connection has already been closed.");
  }

  PGconn *db = DATA_PTR(postgres_connection);
  PGresult *response;

  query = build_query_from_args(self, argc, argv);

  response = cCommand_execute(self, db, query);

  if ( PQresultStatus(response) != PGRES_TUPLES_OK ) {
    raise_error(self, response, query);
  }

  field_count = PQnfields(response);

  reader = rb_funcall(cReader, ID_NEW, 0);
  rb_iv_set(reader, "@connection", connection);
  rb_iv_set(reader, "@reader", Data_Wrap_Struct(rb_cObject, 0, 0, response));
  rb_iv_set(reader, "@field_count", INT2NUM(field_count));
  rb_iv_set(reader, "@row_count", INT2NUM(PQntuples(response)));

  field_names = rb_ary_new();
  field_types = rb_iv_get(self, "@field_types");

  if ( field_types == Qnil || 0 == RARRAY_LEN(field_types) ) {
    field_types = rb_ary_new();
    infer_types = 1;
  } else if (RARRAY_LEN(field_types) != field_count) {
    // Whoops...  wrong number of types passed to set_types.  Close the reader and raise
    // and error
    rb_funcall(reader, rb_intern("close"), 0);
    rb_raise(eArgumentError, "Field-count mismatch. Expected %ld fields, but the query yielded %d", RARRAY_LEN(field_types), field_count);
  }

  for ( i = 0; i < field_count; i++ ) {
    rb_ary_push(field_names, rb_str_new2(PQfname(response, i)));
    if ( infer_types == 1 ) {
      rb_ary_push(field_types, infer_ruby_type(PQftype(response, i)));
    }
  }

  rb_iv_set(reader, "@position", INT2NUM(0));
  rb_iv_set(reader, "@fields", field_names);
  rb_iv_set(reader, "@field_types", field_types);

  return reader;
}
开发者ID:matthewd,项目名称:do,代码行数:59,代码来源:do_postgres_ext.c


示例19: CPLStrdup

OGRPGResultLayer::OGRPGResultLayer( OGRPGDataSource *poDSIn, 
                                    const char * pszRawQueryIn,
                                    PGresult *hInitialResultIn )
{
    poDS = poDSIn;

    iNextShapeId = 0;

    pszRawStatement = CPLStrdup(pszRawQueryIn);

    osWHERE = "";

    BuildFullQueryStatement();

    ReadResultDefinition(hInitialResultIn);

    pszGeomTableName = NULL;
    pszGeomTableSchemaName = NULL;

    /* Find at which index the geometry column is */
    int iGeomCol = -1;
    if (poFeatureDefn->GetGeomFieldCount() == 1)
    {
        int iRawField;
        for( iRawField = 0; iRawField < PQnfields(hInitialResultIn); iRawField++ )
        {
            if( strcmp(PQfname(hInitialResultIn,iRawField),
                    poFeatureDefn->GetGeomFieldDefn(0)->GetNameRef()) == 0 )
            {
                iGeomCol = iRawField;
                break;
            }
        }
    }

#ifndef PG_PRE74
    /* Determine the table from which the geometry column is extracted */
    if (iGeomCol != -1)
    {
        Oid tableOID = PQftable(hInitialResultIn, iGeomCol);
        if (tableOID != InvalidOid)
        {
            CPLString osGetTableName;
            osGetTableName.Printf("SELECT c.relname, n.nspname FROM pg_class c "
                                  "JOIN pg_namespace n ON c.relnamespace=n.oid WHERE c.oid = %d ", tableOID);
            PGresult* hTableNameResult = OGRPG_PQexec(poDS->GetPGConn(), osGetTableName );
            if( hTableNameResult && PQresultStatus(hTableNameResult) == PGRES_TUPLES_OK)
            {
                if ( PQntuples(hTableNameResult) > 0 )
                {
                    pszGeomTableName = CPLStrdup(PQgetvalue(hTableNameResult,0,0));
                    pszGeomTableSchemaName = CPLStrdup(PQgetvalue(hTableNameResult,0,1));
                }
            }
            OGRPGClearResult( hTableNameResult );
        }
    }
#endif
}
开发者ID:0004c,项目名称:node-gdal,代码行数:59,代码来源:ogrpgresultlayer.cpp


示例20: no_such_column_exception

            string row::column_name(size_t nPosition) const
            {
                if (nPosition >= size()) {
                    throw no_such_column_exception();
                }

                return PQfname(stmt_.get(), nPosition);
            }
开发者ID:ryjen,项目名称:db,代码行数:8,代码来源:row.cpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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