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

C++ PQftype函数代码示例

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

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



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

示例1: PQnfields

QSqlRecord QPSQLResult::record() const
{
    QSqlRecord info;
    if (!isActive() || !isSelect())
        return info;

    int count = PQnfields(d->result);
    for (int i = 0; i < count; ++i) {
        QSqlField f;
        if (d->driver->isUtf8)
            f.setName(QString::fromUtf8(PQfname(d->result, i)));
        else
            f.setName(QString::fromLocal8Bit(PQfname(d->result, i)));
        f.setType(qDecodePSQLType(PQftype(d->result, i)));
        int len = PQfsize(d->result, i);
        int precision = PQfmod(d->result, i);
        // swap length and precision if length == -1
        if (len == -1 && precision > -1) {
            len = precision - 4;
            precision = -1;
        }
        f.setLength(len);
        f.setPrecision(precision);
        f.setSqlType(PQftype(d->result, i));
        info.append(f);
    }
    return info;
}
开发者ID:FilipBE,项目名称:qtextended,代码行数:28,代码来源:qsql_psql.cpp


示例2: fill_query_column_types

void fill_query_column_types(pgsnmpd_query *query)
{
    int i;
    Oid type;  /* NB! PostgreSQL's Oid, not Net-SNMP's oid */
    PGresult *res;
    const char *values[1];
    char param[10];
    
    /* This translates SQL types to SNMP types, as follows:
     * Conversions for these four types are obvious
     * ASN_INTEGER
     * ASN_FLOAT
     * ASN_BOOLEAN
     * ASN_OBJECT_ID
     * 
     * Everything else becomes a string:
     * ASN_OCTET_STR
     * 
     * Perhaps one day we'll also use ASN_DOUBLE
     */

    if (query->result == NULL)
        return;

    values[0] = param;

    for (i = 0; i < query->colcount; i++) {
        if (query->types[i] != 255) {
            continue;
        }
        type = PQftype(query->result, i);
        /* 
         * TODO: query pg_type table (including pg_type.h to use builtin
         * constants got all kinds of errors I'd rather not deal with
         */
        sprintf(param, "%d", type);
        res = PQexecPrepared(dbconn, "TYPEQUERY", 1, values, NULL, NULL, 0);
        if (PQresultStatus(res) != PGRES_TUPLES_OK)
            snmp_log(LOG_ERR, "Couldn't determine column type\n");
        else {
            switch (atoi(PQgetvalue(res, 0, 0))) {
                case 0:
                    query->types[i] = ASN_INTEGER;
                    break;
                case 1:
                    query->types[i] = ASN_FLOAT;
                    break;
                case 2: 
                    query->types[i] = ASN_BOOLEAN;
                    break;
                case 3: 
                    query->types[i] = ASN_OCTET_STR;
                    break;
                default: /* If we get here, it's because the TYPEQUERY is b0rken */
                    snmp_log(LOG_ERR, "Unknown column type translation. This is a bug.\n");
            }
        }
        PQclear(res);
    }
}
开发者ID:GunioRobot,项目名称:pgsnmpd,代码行数:60,代码来源:customquery.c


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


示例4: no_such_column_exception

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


示例5: PQresultStatus

//==================================================================================
//Create a cursor result set
bool PostgresqlCursor::drv_open(const KDbEscapedString& sql)
{
    d->res = d->executeSQL(sql);
    d->resultStatus = PQresultStatus(d->res);
    if (d->resultStatus != PGRES_TUPLES_OK && d->resultStatus != PGRES_COMMAND_OK) {
        storeResultAndClear(&d->res, d->resultStatus);
        return false;
    }
    m_fieldsToStoreInRecord = PQnfields(d->res);
    m_fieldCount = m_fieldsToStoreInRecord - (containsRecordIdInfo() ? 1 : 0);
    m_numRows = PQntuples(d->res);
    m_records_in_buf = m_numRows;
    m_buffering_completed = true;

    // get real types for all fields
    PostgresqlDriver* drv = static_cast<PostgresqlDriver*>(connection()->driver());

    m_realTypes.resize(m_fieldsToStoreInRecord);
    m_realLengths.resize(m_fieldsToStoreInRecord);
    for (int i = 0; i < int(m_fieldsToStoreInRecord); i++) {
        const int pqtype = PQftype(d->res, i);
        const int pqfmod = PQfmod(d->res, i);
        m_realTypes[i] = drv->pgsqlToKDbType(pqtype, pqfmod, &m_realLengths[i]);
    }
    return true;
}
开发者ID:KDE,项目名称:kdb,代码行数:28,代码来源:PostgresqlCursor.cpp


示例6: 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:0xhacking,项目名称:php-src,代码行数:60,代码来源:pgsql_statement.c


示例7: ecpg_build_native_sqlda

struct sqlda_struct *
ecpg_build_native_sqlda(int line, PGresult *res, int row, enum COMPAT_MODE compat)
{
	struct sqlda_struct *sqlda;
	long		size;
	int			i;

	size = sqlda_native_total_size(res, row, compat);
	sqlda = (struct sqlda_struct *) ecpg_alloc(size, line);
	if (!sqlda)
		return NULL;

	memset(sqlda, 0, size);

	sprintf(sqlda->sqldaid, "SQLDA  ");
	sqlda->sqld = sqlda->sqln = PQnfields(res);
	ecpg_log("ecpg_build_native_sqlda on line %d sqld = %d\n", line, sqlda->sqld);
	sqlda->sqldabc = sizeof(struct sqlda_struct) + (sqlda->sqld - 1) * sizeof(struct sqlvar_struct);

	for (i = 0; i < sqlda->sqld; i++)
	{
		char	   *fname;

		sqlda->sqlvar[i].sqltype = sqlda_dynamic_type(PQftype(res, i), compat);
		fname = PQfname(res, i);
		sqlda->sqlvar[i].sqlname.length = strlen(fname);
		strcpy(sqlda->sqlvar[i].sqlname.data, fname);
	}

	return sqlda;
}
开发者ID:alvherre,项目名称:postgres,代码行数:31,代码来源:sqlda.c


示例8: result_each

static VALUE result_each(VALUE self) {
    int r, c, rows, cols, *types, failed;
    PGresult *res;
    Data_Get_Struct(self, PGresult, res);

    VALUE fields = rb_ary_new();
    rows  = PQntuples(res);
    cols  = PQnfields(res);
    types = (int*)malloc(sizeof(int)*cols);
    for (c = 0; c < cols; c++) {
        rb_ary_push(fields, ID2SYM(rb_intern(PQfname(res, c))));
        types[c] = PQftype(res, c);
    }

    for (r = 0; r < rows; r++) {
        VALUE tuple = rb_hash_new();
        for (c = 0; c < cols; c++) {
            rb_hash_aset(tuple, rb_ary_entry(fields, c),
                PQgetisnull(res, r, c) ? Qnil : typecast(PQgetvalue(res, r, c), PQgetlength(res, r, c), types[c]));
        }
        rb_protect(rb_yield, tuple, &failed);
        if (failed) {
            free(types);
            rb_jump_tag(failed);
        }
    }

    free(types);
    return Qnil;
}
开发者ID:deepfryed,项目名称:pg_typecast,代码行数:30,代码来源:pg_typecast.c


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


示例10: CI_read_fields_from_pgres

/*
 *	Read in field descriptions from a libpq result set.
 *	If self is not null, then also store the information.
 *	If self is null, then just read, don't store.
 */
BOOL
CI_read_fields_from_pgres(ColumnInfoClass *self, PGresult *pgres)
{
	CSTR		func = "CI_read_fields";
	Int2		lf;
	int			new_num_fields;
	OID		new_adtid, new_relid = 0, new_attid = 0;
	Int2		new_adtsize;
	Int4		new_atttypmod = -1;
	char	   *new_field_name;

	/* at first read in the number of fields that are in the query */
	new_num_fields = PQnfields(pgres);

	mylog("num_fields = %d\n", new_num_fields);

	if (self)
	{
		/* according to that allocate memory */
		CI_set_num_fields(self, new_num_fields);
		if (NULL == self->coli_array)
			return FALSE;
	}

	/* now read in the descriptions */
	for (lf = 0; lf < new_num_fields; lf++)
	{
		new_field_name = PQfname(pgres, lf);
		new_relid = PQftable(pgres, lf);
		new_attid = PQftablecol(pgres, lf);
		new_adtid = PQftype(pgres, lf);
		new_adtsize = PQfsize(pgres, lf);

		mylog("READING ATTTYPMOD\n");
		new_atttypmod = PQfmod(pgres, lf);

		/* Subtract the header length */
		switch (new_adtid)
		{
			case PG_TYPE_DATETIME:
			case PG_TYPE_TIMESTAMP_NO_TMZONE:
			case PG_TYPE_TIME:
			case PG_TYPE_TIME_WITH_TMZONE:
				break;
			default:
				new_atttypmod -= 4;
		}
		if (new_atttypmod < 0)
			new_atttypmod = -1;

		mylog("%s: fieldname='%s', adtid=%d, adtsize=%d, atttypmod=%d (rel,att)=(%d,%d)\n", func, new_field_name, new_adtid, new_adtsize, new_atttypmod, new_relid, new_attid);

		if (self)
			CI_set_field_info(self, lf, new_field_name, new_adtid, new_adtsize, new_atttypmod, new_relid, new_attid);
	}

	return TRUE;
}
开发者ID:hiinoue,项目名称:psqlodbc,代码行数:63,代码来源:columninfo.c


示例11: PQgetisnull

void PgStatement::GetFieldValue
  (
  int         nIndex,
  wxVariant&  v
  )
  {
  int nIsNull = PQgetisnull(pgr, nCurrentRecord, nIndex);
  if(nIsNull != 0)
    {
    v.MakeNull();
    return;
    }

	char * sz = PQgetvalue(pgr, nCurrentRecord, nIndex);

  Oid typ = PQftype(pgr, nIndex);
  switch(typ)
    {
    case PG_OID_BOOLEAN:
      {
      bool b = (sz[0] == 't')? true : false;
      v = b;
      break;
      }
    case PG_OID_OID:
    case PG_OID_INT4:
    case PG_OID_TRANSACTIONID:
      {
      long n = atol(sz);
      v = n;
      break;
      }
    case PG_OID_DOUBLE:
      {
      double d = atof(sz);
      v = d;
      break;
      }
    case PG_OID_NAME:
    case PG_OID_TEXT:
    case PG_OID_VARCHAR_LENGTH:
      {
      //int nFormat = PQfformat(pgr, nIndex); // 0 => text, 1 => binary
      wxString s(sz, wxConvLocal);
      //wxString s = wxConvUTF8.cMB2WX(sz);
      v = s;
      break;
      }
    // Items we don't know how to handle
    case PG_OID_TEXTARRAY:
    case PG_OID_ACLITEMARRAY:
      v = wxT("");
      break;

    default:
      throw wx::Exception(wxT("PgStatement::GetFieldValue() Unhandled data type %d"), typ);
    }
  }
开发者ID:joeyates,项目名称:sherpa,代码行数:58,代码来源:postgres.cpp


示例12: Exception

unsigned ResultSet::getColumnTypeId(int column_idx)
{
	//Throws an error in case the column index is invalid
	if(column_idx < 0 || column_idx >= getColumnCount())
		throw Exception(ERR_REF_TUPLE_COL_INV_INDEX, __PRETTY_FUNCTION__, __FILE__, __LINE__);

	//Returns the column type id on the specified index
	return(static_cast<unsigned>(PQftype(sql_result, column_idx)));
}
开发者ID:bgalok,项目名称:pgmodeler,代码行数:9,代码来源:resultset.cpp


示例13: getTypeOID

 virtual int getTypeOID(const char* name) const
 {
     int col = PQfnumber(res_, name);
     if (col >= 0)
     {
         return PQftype(res_, col);
     }
     return 0;
 }
开发者ID:Airphrame,项目名称:mapnik,代码行数:9,代码来源:resultset.hpp


示例14: ecpg_build_compat_sqlda

/*
 * Build "struct sqlda_compat" (metadata only) from PGresult
 * leaving enough space for the field values in
 * the given row number
 */
struct sqlda_compat *
ecpg_build_compat_sqlda(int line, PGresult *res, int row, enum COMPAT_MODE compat)
{
	struct sqlda_compat *sqlda;
	struct sqlvar_compat *sqlvar;
	char	   *fname;
	long		size;
	int			sqld;
	int			i;

	size = sqlda_compat_total_size(res, row, compat);
	sqlda = (struct sqlda_compat *) ecpg_alloc(size, line);
	if (!sqlda)
		return NULL;

	memset(sqlda, 0, size);
	sqlvar = (struct sqlvar_compat *) (sqlda + 1);
	sqld = PQnfields(res);
	fname = (char *) (sqlvar + sqld);

	sqlda->sqld = sqld;
	ecpg_log("ecpg_build_compat_sqlda on line %d sqld = %d\n", line, sqld);
	sqlda->desc_occ = size;		/* cheat here, keep the full allocated size */
	sqlda->sqlvar = sqlvar;

	for (i = 0; i < sqlda->sqld; i++)
	{
		sqlda->sqlvar[i].sqltype = sqlda_dynamic_type(PQftype(res, i), compat);
		strcpy(fname, PQfname(res, i));
		sqlda->sqlvar[i].sqlname = fname;
		fname += strlen(sqlda->sqlvar[i].sqlname) + 1;

		/*
		 * this is reserved for future use, so we leave it empty for the time
		 * being
		 */
		/* sqlda->sqlvar[i].sqlformat = (char *) (long) PQfformat(res, i); */
		sqlda->sqlvar[i].sqlxid = PQftype(res, i);
		sqlda->sqlvar[i].sqltypelen = PQfsize(res, i);
	}

	return sqlda;
}
开发者ID:alvherre,项目名称:postgres,代码行数:48,代码来源:sqlda.c


示例15: pgresult_ftype

/*
 * call-seq:
 *    res.ftype( column_number )
 *
 * Returns the data type associated with _column_number_.
 *
 * The integer returned is the internal +OID+ number (in PostgreSQL)
 * of the type. To get a human-readable value for the type, use the
 * returned OID and the field's #fmod value with the format_type() SQL
 * function:
 *
 *   # Get the type of the second column of the result 'res'
 *   typename = conn.
 *     exec( "SELECT format_type($1,$2)", [res.ftype(1), res.fmod(1)] ).
 *     getvalue( 0, 0 )
 *
 * Raises an ArgumentError if _column_number_ is out of range.
 */
static VALUE
pgresult_ftype(VALUE self, VALUE index)
{
	PGresult* result = pgresult_get(self);
	int i = NUM2INT(index);
	if (i < 0 || i >= PQnfields(result)) {
		rb_raise(rb_eArgError, "invalid field number %d", i);
	}
	return INT2NUM(PQftype(result, i));
}
开发者ID:ldmosquera,项目名称:ruby-pg,代码行数:28,代码来源:pg_result.c


示例16: QueryResult

QueryResultPostgre::QueryResultPostgre(PGresult *result, uint64 rowCount, uint32 fieldCount) :
    QueryResult(rowCount, fieldCount), mResult(result),  mTableIndex(0)
{

    mCurrentRow = new Field[mFieldCount];
    ASSERT(mCurrentRow);

    for (uint32 i = 0; i < mFieldCount; i++)
        mCurrentRow[i].SetType(ConvertNativeType(PQftype( result, i )));
}
开发者ID:LordVoldemort,项目名称:Shindorei,代码行数:10,代码来源:QueryResultPostgre.cpp


示例17: esql_module_setup_cb

static void
esql_module_setup_cb(PGresult *pres, int col, Eina_Value_Struct_Member *m)
{
   m->name = eina_stringshare_add(PQfname(pres, col));

   switch (PQftype(pres, col))
     {
      case TIMESTAMPOID:
      case ABSTIMEOID:
        m->type = EINA_VALUE_TYPE_TIMESTAMP;
        break;

      case BYTEAOID:
      case NAMEOID:
      case TEXTOID:
      case VARCHAROID:
      case BPCHAROID:
        m->type = EINA_VALUE_TYPE_STRING;
        break;

      case BOOLOID:
      case CHAROID:
        m->type = EINA_VALUE_TYPE_CHAR;
        break;

      case INT2OID:
        m->type = EINA_VALUE_TYPE_SHORT;
        break;

      case INT4OID:
        m->type = EINA_VALUE_TYPE_LONG;
        break;

      case INT8OID:
        m->type = EINA_VALUE_TYPE_INT64;
        break;

      case FLOAT4OID:
        m->type = EINA_VALUE_TYPE_FLOAT;
        break;

      case FLOAT8OID:
      case TINTERVALOID:
      case RELTIMEOID:
        m->type = EINA_VALUE_TYPE_DOUBLE;
        break;

      default:
        m->type = EINA_VALUE_TYPE_BLOB;
     }
}
开发者ID:Limsik,项目名称:e17,代码行数:51,代码来源:esql_postgresql_backend.c


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


示例19: schema_for_table_key

boost::shared_ptr<avro::RecordSchema> schema_for_table_key(std::string schema_name, const std::vector<std::string>& keys, boost::shared_ptr<PGresult> res)
{
    boost::shared_ptr<avro::RecordSchema> record_schema = boost::make_shared<avro::RecordSchema>(schema_name);
    for (std::vector<std::string>::const_iterator i = keys.begin(); i != keys.end(); i++)
    {
        int column_index = PQfnumber(res.get(), i->c_str());
        assert(column_index >= 0);
        if (column_index >= 0)
        {
            Oid col_type = PQftype(res.get(), column_index);
            boost::shared_ptr<avro::Schema> col_schema = schema_for_oid(col_type);
            /* TODO ensure that names abide by Avro's requirements */
            record_schema->addField(*i, *col_schema);
        }
    }
    return record_schema;
}
开发者ID:bitbouncer,项目名称:phoebe,代码行数:17,代码来源:avro_postgres.cpp


示例20: checkColumnsTypes

// returns true if checks passed, false if they failed
// We check the types of columns 0 and 1.
static bool checkColumnsTypes(PGresult * const result, const int numCols) {
  BOOST_ASSERT_MSG( (EXPECTED_NUM_COLS == numCols), "Unexpected bad number of columns: this should have been handled earlier" );

  bool typesAreCorrect = true; // leave as true until we find a bad type

  for (int i = 0; i != EXPECTED_NUM_COLS; ++i) {

    const Oid typeForCol = PQftype(result, i);
    if (expectedTypes[i] == typeForCol) {
      std::cout << "Correct type found for column " << i << '\n';
    } else {
      typesAreCorrect = false;
      std::cerr << "Incorrect type for column " << i << ": OID number of " << typeForCol << '\n';
    }

  }

  return typesAreCorrect;
}
开发者ID:MaxBarraclough,项目名称:libpqhw,代码行数:21,代码来源:hellolibpq.cpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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