本文整理汇总了C++中PQgetisnull函数的典型用法代码示例。如果您正苦于以下问题:C++ PQgetisnull函数的具体用法?C++ PQgetisnull怎么用?C++ PQgetisnull使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PQgetisnull函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
}
}
}
}
示例2: getSequences
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;
}
示例3: row_to_sam_account
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 ;
}
示例4: assert
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);
}
示例5: GetNextResult
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;
}
示例6: 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);
}
}
示例7: show_one_row_data
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));
}
示例8: EXToutOfRange
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);
}
示例9: pdo_pgsql_translate_oid_to_table
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;
}
示例10: dumpUserConfig
/*
* 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);
}
示例11: _pgsql_result_text
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);
}
示例12: _pgsql_result_double
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);
}
示例13: pgsql_mdb_query_getv
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') {
示例14: pgresult_getvalue
/*
* 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;
}
示例15: dumpDatabaseConfig
/*
* 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);
}