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; } } } } }
PQLSequence * getSequences(PGconn *c, int *n) { PQLSequence *s; PGresult *res; int i; logNoise("sequence: server version: %d", PQserverVersion(c)); res = PQexec(c, "SELECT c.oid, n.nspname, c.relname, obj_description(c.oid, 'pg_class') AS description, pg_get_userbyid(c.relowner) AS relowner, relacl FROM pg_class c INNER JOIN pg_namespace n ON (c.relnamespace = n.oid) WHERE relkind = 'S' AND nspname !~ '^pg_' AND nspname <> 'information_schema' ORDER BY nspname, relname"); if (PQresultStatus(res) != PGRES_TUPLES_OK) { logError("query failed: %s", PQresultErrorMessage(res)); PQclear(res); PQfinish(c); /* XXX leak another connection? */ exit(EXIT_FAILURE); } *n = PQntuples(res); if (*n > 0) s = (PQLSequence *) malloc(*n * sizeof(PQLSequence)); else s = NULL; logDebug("number of sequences in server: %d", *n); for (i = 0; i < *n; i++) { s[i].obj.oid = strtoul(PQgetvalue(res, i, PQfnumber(res, "oid")), NULL, 10); s[i].obj.schemaname = strdup(PQgetvalue(res, i, PQfnumber(res, "nspname"))); s[i].obj.objectname = strdup(PQgetvalue(res, i, PQfnumber(res, "relname"))); if (PQgetisnull(res, i, PQfnumber(res, "description"))) s[i].comment = NULL; else s[i].comment = strdup(PQgetvalue(res, i, PQfnumber(res, "description"))); if (PQgetisnull(res, i, PQfnumber(res, "description"))) s[i].comment = NULL; else s[i].comment = strdup(PQgetvalue(res, i, PQfnumber(res, "description"))); s[i].owner = strdup(PQgetvalue(res, i, PQfnumber(res, "relowner"))); if (PQgetisnull(res, i, PQfnumber(res, "relacl"))) s[i].acl = NULL; else s[i].acl = strdup(PQgetvalue(res, i, PQfnumber(res, "relacl"))); logDebug("sequence %s.%s", formatObjectIdentifier(s[i].obj.schemaname), formatObjectIdentifier(s[i].obj.objectname)); } PQclear(res); return s; }
static NTSTATUS row_to_sam_account ( PGresult *r, long row, SAM_ACCOUNT *u ) { pstring temp ; DOM_SID sid ; if ( row >= PQntuples( r ) ) return NT_STATUS_INVALID_PARAMETER ; pdb_set_logon_time ( u, PQgetlong ( r, row, 0 ), PDB_SET ) ; pdb_set_logoff_time ( u, PQgetlong ( r, row, 1 ), PDB_SET ) ; pdb_set_kickoff_time ( u, PQgetlong ( r, row, 2 ), PDB_SET ) ; pdb_set_pass_last_set_time ( u, PQgetlong ( r, row, 3 ), PDB_SET ) ; pdb_set_pass_can_change_time ( u, PQgetlong ( r, row, 4 ), PDB_SET ) ; pdb_set_pass_must_change_time( u, PQgetlong ( r, row, 5 ), PDB_SET ) ; pdb_set_username ( u, PQgetvalue( r, row, 6 ), PDB_SET ) ; pdb_set_domain ( u, PQgetvalue( r, row, 7 ), PDB_SET ) ; pdb_set_nt_username ( u, PQgetvalue( r, row, 8 ), PDB_SET ) ; pdb_set_fullname ( u, PQgetvalue( r, row, 9 ), PDB_SET ) ; pdb_set_homedir ( u, PQgetvalue( r, row, 10 ), PDB_SET ) ; pdb_set_dir_drive ( u, PQgetvalue( r, row, 11 ), PDB_SET ) ; pdb_set_logon_script ( u, PQgetvalue( r, row, 12 ), PDB_SET ) ; pdb_set_profile_path ( u, PQgetvalue( r, row, 13 ), PDB_SET ) ; pdb_set_acct_desc ( u, PQgetvalue( r, row, 14 ), PDB_SET ) ; pdb_set_workstations ( u, PQgetvalue( r, row, 15 ), PDB_SET ) ; pdb_set_unknown_str ( u, PQgetvalue( r, row, 16 ), PDB_SET ) ; pdb_set_munged_dial ( u, PQgetvalue( r, row, 17 ), PDB_SET ) ; pdb_set_acct_ctrl ( u, PQgetlong ( r, row, 23 ), PDB_SET ) ; pdb_set_logon_divs ( u, PQgetlong ( r, row, 24 ), PDB_SET ) ; pdb_set_hours_len ( u, PQgetlong ( r, row, 25 ), PDB_SET ) ; pdb_set_bad_password_count ( u, PQgetlong (r, row, 26 ), PDB_SET ) ; pdb_set_logon_count ( u, PQgetlong ( r, row, 27 ), PDB_SET ) ; pdb_set_unknown_6 ( u, PQgetlong ( r, row, 28 ), PDB_SET ) ; if ( !PQgetisnull( r, row, 18 ) ) { string_to_sid( &sid, PQgetvalue( r, row, 18 ) ) ; pdb_set_user_sid ( u, &sid, PDB_SET ) ; } if ( !PQgetisnull( r, row, 19 ) ) { string_to_sid( &sid, PQgetvalue( r, row, 19 ) ) ; pdb_set_group_sid( u, &sid, PDB_SET ) ; } if ( pdb_gethexpwd( PQgetvalue( r, row, 20 ), temp ), PDB_SET ) pdb_set_lanman_passwd( u, temp, PDB_SET ) ; if ( pdb_gethexpwd( PQgetvalue( r, row, 21 ), temp ), PDB_SET ) pdb_set_nt_passwd ( u, temp, PDB_SET ) ; /* Only use plaintext password storage when lanman and nt are NOT used */ if ( PQgetisnull( r, row, 20 ) || PQgetisnull( r, row, 21 ) ) pdb_set_plaintext_passwd( u, PQgetvalue( r, row, 22 ) ) ; return NT_STATUS_OK ; }
const char *PostgresqlResultSet_getString(T R, int columnIndex) { assert(R); int i = checkAndSetColumnIndex(columnIndex, R->columnCount); if (PQgetisnull(R->res, R->currentRow, i)) return NULL; return PQgetvalue(R->res, R->currentRow, i); }
virtual bool GetNextResult(StringList& rResult) { STAFF_ASSERT(m_pResult, "Execute was not called"); if (m_nCurrentRow == m_nRowsCount) { return false; } if (rResult.size() != m_nFieldsCount) { rResult.resize(m_nFieldsCount); } int nField = 0; const char* szResult = NULL; for (StringList::iterator itResult = rResult.begin(); itResult != rResult.end(); ++itResult, ++nField) { if (PQgetisnull(m_pResult, m_nCurrentRow, nField)) { *itResult = STAFF_DAS_NULL_VALUE; } else { szResult = PQgetvalue(m_pResult, m_nCurrentRow, nField); *itResult = szResult ? szResult : STAFF_DAS_NULL_VALUE; } } ++m_nCurrentRow; return true; }
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); } }
void show_one_row_data(PGresult* result) { int col; for(col=0;col<PQnfields(result);col++) printf("Data: %s\n",PQgetisnull(result,0,col)?"<NULL>":PQgetvalue(result,0,col)); }
bool DTTablePostgres::fieldIsNull(int tupleNumber, int columnNumber) const { if ((tupleNumber ) >= PQntuples(result) || tupleNumber < 0 || (columnNumber) >= PQnfields(result) || columnNumber < 0) { EXToutOfRange("Parameters out of range"); } return (bool) PQgetisnull(result, tupleNumber, columnNumber); }
static zend_always_inline char * pdo_pgsql_translate_oid_to_table(Oid oid, PGconn *conn) { char *table_name = NULL; PGresult *tmp_res; char *querystr = NULL; spprintf(&querystr, 0, "SELECT RELNAME FROM PG_CLASS WHERE OID=%d", oid); if ((tmp_res = PQexec(conn, querystr)) == NULL || PQresultStatus(tmp_res) != PGRES_TUPLES_OK) { if (tmp_res) { PQclear(tmp_res); } efree(querystr); return 0; } efree(querystr); if (1 == PQgetisnull(tmp_res, 0, 0) || (table_name = PQgetvalue(tmp_res, 0, 0)) == NULL) { PQclear(tmp_res); return 0; } table_name = estrdup(table_name); PQclear(tmp_res); return table_name; }
/* * As a "hack" to avoid extra allocation and complications by using PQunescapeBytea() * we instead unescape the buffer retrieved via PQgetvalue 'in-place'. This should * be safe as unescape will only modify internal bytes in the buffer and not change * the buffer pointer. See also unescape_bytea() above. */ const void *PostgresqlResultSet_getBlob(T R, int columnIndex, int *size) { assert(R); int i = checkAndSetColumnIndex(columnIndex, R->columnCount); if (PQgetisnull(R->res, R->currentRow, i)) return NULL; return unescape_bytea((uchar_t*)PQgetvalue(R->res, R->currentRow, i), PQgetlength(R->res, R->currentRow, i), size); }
/* * Dump user-specific configuration */ static void dumpUserConfig(PGconn *conn, const char *username) { PQExpBuffer buf = createPQExpBuffer(); int count = 1; for (;;) { PGresult *res; if (server_version >= 80100) printfPQExpBuffer(buf, "SELECT rolconfig[%d] FROM pg_authid WHERE rolname = ", count); else printfPQExpBuffer(buf, "SELECT useconfig[%d] FROM pg_shadow WHERE usename = ", count); appendStringLiteral(buf, username, true); res = executeQuery(conn, buf->data); if (PQntuples(res) == 1 && !PQgetisnull(res, 0, 0)) { makeAlterConfigCommand(PQgetvalue(res, 0, 0), "ROLE", username); PQclear(res); count++; } else { PQclear(res); break; } } destroyPQExpBuffer(buf); }
static DBStatus _pgsql_result_text( PGresult *pgres, char **result) { char *text; char *value; *result = (char *)NULL; if (PQntuples(pgres) == 1) { if (PQgetisnull(pgres, 0, 0)) { return(DB_NULL_RESULT); } else { text = PQgetvalue(pgres, 0, 0); value = (char *)malloc((strlen(text) + 1) * sizeof(char)); if (value) { strcpy(value, text); *result = value; return(DB_NO_ERROR); } else { return(DB_MEM_ERROR); } } } return(DB_BAD_RESULT); }
static DBStatus _pgsql_result_double( PGresult *pgres, double *result) { char *text; char *endptr; double value; *result = 0; if (PQntuples(pgres) == 1) { if (PQgetisnull(pgres, 0, 0)) { return(DB_NULL_RESULT); } else { text = PQgetvalue(pgres, 0, 0); errno = 0; value = strtod(text, &endptr); if (errno || text == endptr) { return(DB_BAD_RESULT); } else { *result = value; return(DB_NO_ERROR); } } } return(DB_BAD_RESULT); }
static NEOERR* pgsql_mdb_query_getv(mdb_conn* conn, const char* fmt, va_list ap) { PGresult* res = CONN(conn)->pg_res; int row_no = CONN(conn)->row_no; NEOERR *err = STATUS_OK; if (res == NULL) return nerr_raise(NERR_DB, "attemp fetch null res"); if (row_no >= mdb_get_rows(conn)) { if (row_no == 0) return nerr_raise(NERR_NOT_FOUND, "empty result"); return nerr_raise(NERR_OUTOFRANGE, "last row has fetched"); } int param_count = fmt != NULL ? strlen(fmt) : 0; int i, col = 0; for (i = 0; i < param_count; i++) { if (fmt[i] == 's') { char** str_ptr = (char**)va_arg(ap, char**); if (PQgetisnull(res, row_no, col)) *str_ptr = NULL; else *str_ptr = PQgetvalue(res, row_no, col); col++; } else if (fmt[i] == 'S') {
/* * call-seq: * res.getvalue( tup_num, field_num ) * * Returns the value in tuple number _tup_num_, field _field_num_, * or +nil+ if the field is +NULL+. */ static VALUE pgresult_getvalue(VALUE self, VALUE tup_num, VALUE field_num) { VALUE val; 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); } if(PQgetisnull(result, i, j)) return Qnil; val = rb_tainted_str_new(PQgetvalue(result, i, j), PQgetlength(result, i, j)); #ifdef M17N_SUPPORTED /* associate client encoding for text format only */ if ( 0 == PQfformat(result, j) ) { ASSOCIATE_INDEX( val, self ); } else { rb_enc_associate( val, rb_ascii8bit_encoding() ); } #endif return val; }
/* * Dump database-specific configuration */ static void dumpDatabaseConfig(PGconn *conn, const char *dbname) { PQExpBuffer buf = createPQExpBuffer(); int count = 1; for (;;) { PGresult *res; printfPQExpBuffer(buf, "SELECT datconfig[%d] FROM pg_database WHERE datname = ", count); appendStringLiteral(buf, dbname, true); appendPQExpBuffer(buf, ";"); res = executeQuery(conn, buf->data); if (!PQgetisnull(res, 0, 0)) { makeAlterConfigCommand(PQgetvalue(res, 0, 0), "DATABASE", dbname); PQclear(res); count++; } else { PQclear(res); break; } } destroyPQExpBuffer(buf); }
VALUE pg_tmbc_result_value( t_typemap *p_typemap, VALUE result, int tuple, int field ) { t_pg_coder *p_coder = NULL; t_pg_result *p_result = pgresult_get_this(result); t_tmbc *this = (t_tmbc *) p_typemap; t_typemap *default_tm; if (PQgetisnull(p_result->pgresult, tuple, field)) { return Qnil; } p_coder = this->convs[field].cconv; if( p_coder ){ char * val = PQgetvalue( p_result->pgresult, tuple, field ); int len = PQgetlength( p_result->pgresult, tuple, field ); if( p_coder->dec_func ){ return p_coder->dec_func(p_coder, val, len, tuple, field, ENCODING_GET(result)); } else { t_pg_coder_dec_func dec_func; dec_func = pg_coder_dec_func( p_coder, PQfformat(p_result->pgresult, field) ); return dec_func(p_coder, val, len, tuple, field, ENCODING_GET(result)); } } default_tm = DATA_PTR( this->typemap.default_typemap ); return default_tm->funcs.typecast_result_value( default_tm, result, tuple, field ); }
/* * Receive a single file as a malloc'd buffer. */ char * libpqGetFile(const char *filename, size_t *filesize) { PGresult *res; char *result; int len; const char *paramValues[1]; paramValues[0] = filename; res = PQexecParams(conn, "SELECT pg_read_binary_file($1)", 1, NULL, paramValues, NULL, NULL, 1); if (PQresultStatus(res) != PGRES_TUPLES_OK) pg_fatal("could not fetch remote file \"%s\": %s", filename, PQresultErrorMessage(res)); /* sanity check the result set */ if (PQntuples(res) != 1 || PQgetisnull(res, 0, 0)) pg_fatal("unexpected result set while fetching remote file \"%s\"\n", filename); /* Read result to local variables */ len = PQgetlength(res, 0, 0); result = pg_malloc(len + 1); memcpy(result, PQgetvalue(res, 0, 0), len); result[len] = '\0'; PQclear(res); pg_log(PG_DEBUG, "fetched file \"%s\", length %d\n", filename, len); if (filesize) *filesize = len; return result; }
QString QgsPostgresResult::PQgetvalue( int row, int col ) { Q_ASSERT( mRes ); return PQgetisnull( row, col ) ? QString::null : QString::fromUtf8( ::PQgetvalue( mRes, row, col ) ); }
static TXN_STATUS getTxnStatus(PGconn *conn, GlobalTransactionId gxid, int node_idx) { char *node_name; char stmt[1024]; PGresult *res; char *res_s; static const char *STMT_FORM = "EXECUTE DIRECT ON %s 'SELECT pgxc_is_committed(''%d''::xid);'"; node_name = pgxc_clean_node_info[node_idx].node_name; sprintf(stmt, STMT_FORM, node_name, gxid); res = PQexec(conn, stmt); if (res == NULL || PQresultStatus(res) != PGRES_TUPLES_OK) { fprintf(stderr, "Could not obtain transaction status for node %s, gxid %d\n", node_name, gxid); exit(1); } if (PQgetisnull(res, 0, 0)) return TXN_STATUS_UNKNOWN; res_s = PQgetvalue(res, 0, 0); if (strcmp(res_s, "t") == 0) return TXN_STATUS_COMMITTED; else return TXN_STATUS_ABORTED; }
static DBStatus _pgsql_result_bool( PGresult *pgres, int *result) { char *text; *result = 0; if (PQntuples(pgres) == 1) { if (PQgetisnull(pgres, 0, 0)) { return(DB_NULL_RESULT); } else { text = PQgetvalue(pgres, 0, 0); if (*text == 't') { *result = 1; return(DB_NO_ERROR); } else if (*text == 'f') { *result = 0; return(DB_NO_ERROR); } } } return(DB_BAD_RESULT); }
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; }
static void push_query_result(PGresult* res, void* context, char* query) { struct push_info* push_info = (struct push_info*) context; int i; for (i = 0; i < PQntuples(res); i++) { if (!PQgetisnull(res, i, 0) && !PQgetisnull(res, i, 1)) { int type = atoi(PQgetvalue(res, i, 1)); if (type < amount_of_push_functions()) push_functions[type](push_info, PQgetvalue(res, i, 0), push_info->event_base); } } SAFEFREE(push_info->subject); SAFEFREE(push_info->data); SAFEFREE(push_info->sender); SAFEFREE(push_info); }
bool PGRecordset::GetIsNull(const AnsiString &FieldName) const //---------------------------------------------------------------------------() // DESCRIPTION: // Returns true if the column contains NULL //---------------------------------------------------------------------------() { if (IsEOF()) { ReportEOFError_(FieldName); return false; } try { int iColIdx = GetColumnIndex_(FieldName); bool isNull = PQgetisnull(result_, cur_row_num_, iColIdx) == 1; return isNull; } catch (...) { ErrorManager::Instance()->ReportError(ErrorManager::High, 5301, "PGRecordset::GetIsNull", "An error occured while checking for null."); throw; } }
SQLEntry GetValue(int row, int column) { char* v = PQgetvalue(res, row, column); if (!v || PQgetisnull(res, row, column)) return SQLEntry(); return SQLEntry(std::string(v, PQgetlength(res, row, column))); }
static Oid getoid(PGresult *res, int row, int col) { if (PQgetisnull(res, row, col)) return InvalidOid; else return (Oid)strtoul(PQgetvalue(res, row, col), NULL, 10); }
/* result is not copied */ static char * getstr(PGresult *res, int row, int col) { if (PQgetisnull(res, row, col)) return NULL; else return PQgetvalue(res, row, col); }
bool PgSQLResult::IsNullField(const char* szFieldName) { int iFieldOffset = __GetIndex(szFieldName); return m_sqlResult == NULL || m_sqlRow < 0 || m_sqlRow >= m_numRows || iFieldOffset < 0 || iFieldOffset >= m_numFields || PQgetisnull(m_sqlResult, m_sqlRow, iFieldOffset); }
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); } }
PQLExtension * getExtensions(PGconn *c, int *n) { PQLExtension *e; PGresult *res; int i; logNoise("extension: server version: %d", PQserverVersion(c)); /* bail out if we do not support it */ if (PQserverVersion(c) < 90100) { logWarning("ignoring extensions because server does not support it"); return NULL; } res = PQexec(c, "SELECT e.oid, extname AS extensionname, nspname, extversion AS version, extrelocatable, obj_description(e.oid, 'pg_extension') AS description FROM pg_extension e LEFT JOIN pg_namespace n ON (e.extnamespace = n.oid) ORDER BY extname"); if (PQresultStatus(res) != PGRES_TUPLES_OK) { logError("query failed: %s", PQresultErrorMessage(res)); PQclear(res); PQfinish(c); /* XXX leak another connection? */ exit(EXIT_FAILURE); } *n = PQntuples(res); if (*n > 0) e = (PQLExtension *) malloc(*n * sizeof(PQLExtension)); else e = NULL; logDebug("number of extensions in server: %d", *n); for (i = 0; i < *n; i++) { e[i].oid = strtoul(PQgetvalue(res, i, PQfnumber(res, "oid")), NULL, 10); e[i].extensionname = strdup(PQgetvalue(res, i, PQfnumber(res, "extensionname"))); e[i].schemaname = strdup(PQgetvalue(res, i, PQfnumber(res, "nspname"))); e[i].version = strdup(PQgetvalue(res, i, PQfnumber(res, "version"))); e[i].relocatable = (PQgetvalue(res, i, PQfnumber(res, "extrelocatable"))[0] == 't'); if (PQgetisnull(res, i, PQfnumber(res, "description"))) e[i].comment = NULL; else e[i].comment = strdup(PQgetvalue(res, i, PQfnumber(res, "description"))); logDebug("extension \"%s\"", e[i].extensionname); } PQclear(res); return e; }