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


C++ PQfname函数代码示例

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


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


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