本文整理汇总了C++中PQcmdTuples函数的典型用法代码示例。如果您正苦于以下问题:C++ PQcmdTuples函数的具体用法?C++ PQcmdTuples怎么用?C++ PQcmdTuples使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PQcmdTuples函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SWITCH_DECLARE
SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_finish_results_real(const char* file, const char* func, int line, switch_pgsql_handle_t *handle)
{
#ifdef SWITCH_HAVE_PGSQL
switch_pgsql_result_t *res = NULL;
switch_pgsql_status_t final_status = SWITCH_PGSQL_SUCCESS;
int done = 0;
do {
switch_pgsql_next_result(handle, &res);
if (res && res->err && !switch_stristr("already exists", res->err) && !switch_stristr("duplicate key name", res->err)) {
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "Error executing query:\n%s\n", res->err);
final_status = SWITCH_PGSQL_FAIL;
}
if (!res) {
done = 1;
} else if (res->result) {
char *affected_rows = PQcmdTuples(res->result);
if (!zstr(affected_rows)) {
handle->affected_rows = atoi(affected_rows);
}
}
switch_pgsql_free_result(&res);
} while (!done);
return final_status;
#else
return SWITCH_PGSQL_FAIL;
#endif
}
示例2: pgresult_cmd_tuples
/*
* call-seq:
* res.cmd_tuples() -> Fixnum
*
* Returns the number of tuples (rows) affected by the SQL command.
*
* If the SQL command that generated the PG::Result was not one of:
* * +INSERT+
* * +UPDATE+
* * +DELETE+
* * +MOVE+
* * +FETCH+
* or if no tuples were affected, <tt>0</tt> is returned.
*/
static VALUE
pgresult_cmd_tuples(VALUE self)
{
long n;
n = strtol(PQcmdTuples(pgresult_get(self)),NULL, 10);
return INT2NUM(n);
}
示例3: pgsqlExecute
static HB_ERRCODE pgsqlExecute( SQLDDCONNECTION * pConnection, PHB_ITEM pItem )
{
PGconn * pConn = ( ( SDDCONN * ) pConnection->pSDDConn )->pConn;
int iTuples;
PGresult * pResult;
ExecStatusType status;
unsigned long ulAffectedRows;
pResult = PQexec( pConn, hb_itemGetCPtr( pItem ) );
if( ! pResult )
{
hb_rddsqlSetError( 1, PQerrorMessage( pConn ), hb_itemGetCPtr( pItem ), NULL, 0 );
return HB_FAILURE;
}
status = PQresultStatus( pResult );
if( status != PGRES_TUPLES_OK && status != PGRES_COMMAND_OK )
{
hb_rddsqlSetError( status, PQresultErrorMessage( pResult ), hb_itemGetCPtr( pItem ), NULL, 0 );
return HB_FAILURE;
}
iTuples = PQntuples( pResult );
if( iTuples > 0 )
ulAffectedRows = ( unsigned long ) iTuples;
else
ulAffectedRows = ( unsigned long ) atol( PQcmdTuples( pResult ) );
hb_rddsqlSetError( 0, NULL, hb_itemGetCPtr( pItem ), NULL, ulAffectedRows );
PQclear( pResult );
return HB_SUCCESS;
}
示例4: 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;
}
}
示例5: pq_cmdtuples
/* ML type : pgresult_ -> int */
EXTERNML value pq_cmdtuples(value pgresval)
{
const char* s = PQcmdTuples(PGresult_val(pgresval));
if (s == NULL)
failwith("pq_cmdtuples");
return Val_long(atoi(s));
}
示例6: va_start
unsigned long psMysqlConnection::Command(const char *sql,...)
{
psStopWatch timer;
csString querystr;
va_list args;
va_start(args, sql);
querystr.FormatV(sql, args);
va_end(args);
lastquery = querystr;
timer.Start();
PGresult *res = PQexec(conn, querystr.GetData());
if(res && PQresultStatus(res) != PGRES_FATAL_ERROR)
{
if(timer.Stop() > 1000)
{
csString status;
status.Format("SQL query %s, has taken %u time to process.\n", querystr.GetData(), timer.Stop());
if(logcsv)
logcsv->Write(CSV_STATUS, status);
}
profs.AddSQLTime(querystr, timer.Stop());
lastRow = PQoidValue(res);
const char *const RowsStr = PQcmdTuples(res);
return (unsigned long) (RowsStr[0] ? atoi(RowsStr) : 0);
}
else
{
PQclear(res);
return QUERY_FAILED;
}
}
示例7: 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;
}
}
示例8: pgsql_handle_doer
static zend_long pgsql_handle_doer(pdo_dbh_t *dbh, const char *sql, zend_long sql_len)
{
pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data;
PGresult *res;
zend_long ret = 1;
ExecStatusType qs;
if (!(res = PQexec(H->server, sql))) {
/* fatal error */
pdo_pgsql_error(dbh, PGRES_FATAL_ERROR, NULL);
return -1;
}
qs = PQresultStatus(res);
if (qs != PGRES_COMMAND_OK && qs != PGRES_TUPLES_OK) {
pdo_pgsql_error(dbh, qs, pdo_pgsql_sqlstate(res));
PQclear(res);
return -1;
}
H->pgoid = PQoidValue(res);
if (qs == PGRES_COMMAND_OK) {
ZEND_ATOL(ret, PQcmdTuples(res));
} else {
ret = Z_L(0);
}
PQclear(res);
return ret;
}
示例9: 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),
PQgetlength(result, r, n));
printf("\n");
}
}
}
PQclear(result);
}
示例10: pgsql_update
static int pgsql_update(void *theconn, const Octstr *sql, List *binds)
{
int rows;
PGresult *res = NULL;
PGconn *conn = (PGconn*) theconn;
res = PQexec(conn, octstr_get_cstr(sql));
if (res == NULL)
return -1;
switch (PQresultStatus(res)) {
case PGRES_BAD_RESPONSE:
case PGRES_NONFATAL_ERROR:
case PGRES_FATAL_ERROR:
error(0, "PGSQL: %s", octstr_get_cstr(sql));
error(0, "PGSQL: %s", PQresultErrorMessage(res));
PQclear(res);
return -1;
default: /* for compiler please */
break;
}
rows = atoi(PQcmdTuples(res));
PQclear(res);
return rows;
}
示例11: PQexec
int PG::operacion(const char* query){
PGresult *res = PQexec(conn,query);
int x = atoi(PQcmdTuples(res));
// Para obtener errores :
// char* error = PQresultErrorField(res,PG_DIAG_SQLSTATE);
PQclear(res);
return x;
}
示例12: process_result
static awk_value_t *
process_result(PGconn *conn, PGresult *res, awk_value_t *resp)
{
ExecStatusType rc;
switch (rc = PQresultStatus(res)) {
case PGRES_TUPLES_OK:
{
static unsigned long hnum = 0;
char handle[64];
size_t sl;
snprintf(handle, sizeof(handle), "TUPLES %d pgres%lu",
PQntuples(res), hnum++);
sl = strlen(handle);
strhash_get(results, handle, sl, 1)->data = res;
make_string_malloc(handle, sl, resp);
}
break;
case PGRES_COMMAND_OK:
case PGRES_EMPTY_QUERY:
{
char result[32];
int cnt;
if (sscanf(PQcmdTuples(res), "%d", &cnt) != 1)
cnt = 0;
snprintf(result, sizeof(result), "OK %d", cnt);
PQclear(res);
make_string_malloc(result, strlen(result), resp);
}
break;
case PGRES_COPY_IN:
{
char buf[100];
snprintf(buf, sizeof(buf), "COPY_IN %d %s",
PQnfields(res), (PQbinaryTuples(res) ? "BINARY" : "TEXT"));
make_string_malloc(buf, strlen(buf), resp);
PQclear(res);
}
break;
case PGRES_COPY_OUT:
{
char buf[100];
snprintf(buf, sizeof(buf), "COPY_OUT %d %s",
PQnfields(res), (PQbinaryTuples(res) ? "BINARY" : "TEXT"));
make_string_malloc(buf, strlen(buf), resp);
PQclear(res);
}
break;
default: /* error */
set_error(conn, rc, resp);
set_ERRNO(PQresultErrorMessage(res));
PQclear(res);
}
return resp;
}
示例13: changed_tuples
int changed_tuples() const {
std::string t = PQcmdTuples(res);
if (t.empty())
throw Error::no_tuples("", conn.getName());
std::stringstream s;
s << t;
int r;
s >> r;
return r;
}
示例14: PQcmdTuples
long PgQuery::affectedRows ()
{
long res = 0;
char *str_rows = PQcmdTuples (_res);
if (!str_rows || !*str_rows)
return res;
if (sscanf (str_rows, "%ld", &res) != 1)
return 0;
return res;
}
示例15: evsql_result_affected
size_t evsql_result_affected (const struct evsql_result *res) {
switch (res->evsql->type) {
case EVSQL_EVPQ:
// XXX: errors?
return strtol(PQcmdTuples(res->result.pq), NULL, 10);
default:
FATAL("res->evsql->type");
}
}