Author: turnstep
Date: Sat Apr 12 13:04:00 2008
New Revision: 11070
Modified:
DBD-Pg/trunk/dbdimp.c
DBD-Pg/trunk/dbdimp.h
Log:
Get the number of tuples ourselves, some other minor cleanups.
Modified: DBD-Pg/trunk/dbdimp.c
==============================================================================
--- DBD-Pg/trunk/dbdimp.c (original)
+++ DBD-Pg/trunk/dbdimp.c Sat Apr 12 13:04:00 2008
@@ -76,7 +76,7 @@
static int pg_st_deallocate_statement(pTHX_ SV *sth, imp_sth_t *imp_sth);
static PGTransactionStatusType pg_db_txn_status (pTHX_ imp_dbh_t *imp_dbh);
static int pg_db_start_txn (pTHX_ SV *dbh, imp_dbh_t *imp_dbh);
-static int handle_old_async(pTHX_ SV * handle, imp_dbh_t * imp_dbh, int
asyncflag);
+static int handle_old_async(pTHX_ SV * handle, imp_dbh_t * imp_dbh, const int
asyncflag);
/* ================================================================== */
void dbd_init (dbistate_t *dbistate)
@@ -2564,7 +2564,7 @@
/* ================================================================== */
-int pg_quickexec (SV * dbh, const char * sql, int asyncflag)
+int pg_quickexec (SV * dbh, const char * sql, const int asyncflag)
{
dTHX;
D_imp_dbh(dbh);
@@ -2647,10 +2647,20 @@
/* non-select statement */
TRACE_PQCMDSTATUS;
cmdStatus = PQcmdStatus(result);
- if ((0==strncmp(cmdStatus, "DELETE", 6)) ||
(0==strncmp(cmdStatus, "INSERT", 6)) ||
- (0==strncmp(cmdStatus, "UPDATE", 6))) {
- TRACE_PQCMDTUPLES;
- rows = atoi(PQcmdTuples(result));
+ /* If the statement indicates a number of rows, we want to
return that */
+ /* Note: COPY and FETCH do not currently reach here, although
they return numbers */
+ if (0 == strncmp(cmdStatus, "INSERT", 6)) {
+ /* INSERT(space)oid(space)numrows */
+ for (rows=8; cmdStatus[rows-1] != ' '; rows++) {
+ }
+ rows = atoi(cmdStatus + rows);
+ }
+ else if (0 == strncmp(cmdStatus, "MOVE", 4)) {
+ rows = atoi(cmdStatus + 5);
+ }
+ else if (0 == strncmp(cmdStatus, "DELETE", 6)
+ || 0 == strncmp(cmdStatus, "UPDATE", 6)) {
+ rows = atoi(cmdStatus + 7);
}
break;
case PGRES_COPY_OUT:
@@ -3081,19 +3091,32 @@
else if (PGRES_COMMAND_OK == status) {
/* non-select statement */
char *cmdStatus = NULL;
+ bool gotrows = DBDPG_FALSE;
+
+ if (TRACE5)
+ TRC(DBILOGFP, "%sStatus was PGRES_COMMAND_OK\n",
THEADER);
+
if (imp_sth->result) {
TRACE_PQCMDSTATUS;
cmdStatus = PQcmdStatus(imp_sth->result);
+ if (0 == strncmp(cmdStatus, "INSERT", 6)) {
+ /* INSERT(space)oid(space)numrows */
+ for (ret=8; cmdStatus[ret-1] != ' '; ret++) {
+ }
+ ret = atoi(cmdStatus + ret);
+ gotrows = DBDPG_TRUE;
+ }
+ else if (0 == strncmp(cmdStatus, "MOVE", 4)) {
+ ret = atoi(cmdStatus + 5);
+ gotrows = DBDPG_TRUE;
+ }
+ else if (0 == strncmp(cmdStatus, "DELETE", 6)
+ || 0 == strncmp(cmdStatus, "UPDATE",
6)) {
+ ret = atoi(cmdStatus + 7);
+ gotrows = DBDPG_TRUE;
+ }
}
- if (TRACE5)
- TRC(DBILOGFP, "%sStatus was PGRES_COMMAND_OK\n",
THEADER);
- /* XXX DANGER We could be comparing against NULL */
- if ((0==strncmp(cmdStatus, "DELETE", 6)) ||
(0==strncmp(cmdStatus, "INSERT", 6)) ||
- (0==strncmp(cmdStatus, "UPDATE", 6))) {
- TRACE_PQCMDTUPLES;
- ret = atoi(PQcmdTuples(imp_sth->result));
- }
- else {
+ if (!gotrows) {
/* No rows affected, but check for change of state */
TRACE_PQTRANSACTIONSTATUS;
if (PQTRANS_IDLE == PQtransactionStatus(imp_dbh->conn))
{
@@ -4260,10 +4283,18 @@
/* non-select statement */
TRACE_PQCMDSTATUS;
cmdStatus = PQcmdStatus(result);
- if ((0==strncmp(cmdStatus, "DELETE", 6)) ||
(0==strncmp(cmdStatus, "INSERT", 6)) ||
- (0==strncmp(cmdStatus, "UPDATE", 6))) {
- TRACE_PQCMDTUPLES;
- rows = atoi(PQcmdTuples(result));
+ if (0 == strncmp(cmdStatus, "INSERT", 6)) {
+ /* INSERT(space)oid(space)numrows */
+ for (rows=8; cmdStatus[rows-1] != ' '; rows++) {
+ }
+ rows = atoi(cmdStatus + rows);
+ }
+ else if (0 == strncmp(cmdStatus, "MOVE", 4)) {
+ rows = atoi(cmdStatus + 5);
+ }
+ else if (0 == strncmp(cmdStatus, "DELETE", 6)
+ || 0 == strncmp(cmdStatus, "UPDATE",
6)) {
+ rows = atoi(cmdStatus + 7);
}
break;
case PGRES_COPY_OUT:
@@ -4464,7 +4495,7 @@
*/
/* ================================================================== */
-static int handle_old_async(pTHX_ SV * handle, imp_dbh_t * imp_dbh, int
asyncflag) {
+static int handle_old_async(pTHX_ SV * handle, imp_dbh_t * imp_dbh, const int
asyncflag) {
PGresult *result;
ExecStatusType status;
Modified: DBD-Pg/trunk/dbdimp.h
==============================================================================
--- DBD-Pg/trunk/dbdimp.h (original)
+++ DBD-Pg/trunk/dbdimp.h Sat Apr 12 13:04:00 2008
@@ -183,7 +183,7 @@
SV * pg_stringify_array(SV * input, const char * array_delim, int
server_version);
-int pg_quickexec (SV *dbh, const char *sql, int asyncflag);
+int pg_quickexec (SV *dbh, const char *sql, const int asyncflag);
int pg_db_putline (SV *dbh, const char *buffer);