mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-23 01:16:34 +03:00
Fixed .rowcount (closes: #6).
This commit is contained in:
parent
f4ad71fc1d
commit
5db7764207
|
@ -39,7 +39,7 @@
|
||||||
#define binary_escape PQescapeBytea
|
#define binary_escape PQescapeBytea
|
||||||
#else
|
#else
|
||||||
static unsigned char *
|
static unsigned char *
|
||||||
binary_escape(char *from, size_t from_length, size_t *to_length)
|
binary_escape(char *from, int from_length, int *to_length)
|
||||||
{
|
{
|
||||||
unsigneed char *quoted, *chptr, *newptr;
|
unsigneed char *quoted, *chptr, *newptr;
|
||||||
int i, space, new_space;
|
int i, space, new_space;
|
||||||
|
|
|
@ -80,7 +80,7 @@ qstring_quote(qstringObject *self)
|
||||||
{
|
{
|
||||||
PyObject *str;
|
PyObject *str;
|
||||||
char *s, *buffer;
|
char *s, *buffer;
|
||||||
size_t len;
|
int len;
|
||||||
|
|
||||||
/* if the wrapped object is an unicode object we can encode it to match
|
/* if the wrapped object is an unicode object we can encode it to match
|
||||||
self->encoding but if the encoding is not specified we don't know what
|
self->encoding but if the encoding is not specified we don't know what
|
||||||
|
|
|
@ -790,18 +790,11 @@ pq_fetch(cursorObject *curs)
|
||||||
Py_XDECREF(curs->pgstatus);
|
Py_XDECREF(curs->pgstatus);
|
||||||
curs->pgstatus = PyString_FromString(PQcmdStatus(curs->pgres));
|
curs->pgstatus = PyString_FromString(PQcmdStatus(curs->pgres));
|
||||||
|
|
||||||
/* rowcount has a meaning even for INSERT and UPDATES but to get the right
|
|
||||||
number we need to check two times, one with PQntuples for SELECts and
|
|
||||||
one with PQcmdTuples for other queries */
|
|
||||||
curs->rowcount = PQntuples(curs->pgres);
|
|
||||||
if (curs->rowcount == 0)
|
|
||||||
curs->rowcount = atoi(PQcmdTuples(curs->pgres));
|
|
||||||
|
|
||||||
switch(pgstatus) {
|
switch(pgstatus) {
|
||||||
|
|
||||||
case PGRES_COMMAND_OK:
|
case PGRES_COMMAND_OK:
|
||||||
Dprintf("pq_fetch: command returned OK (no tuples)");
|
Dprintf("pq_fetch: command returned OK (no tuples)");
|
||||||
curs->rowcount = 0;
|
curs->rowcount = atoi(PQcmdTuples(curs->pgres));
|
||||||
curs->lastoid = PQoidValue(curs->pgres);
|
curs->lastoid = PQoidValue(curs->pgres);
|
||||||
CLEARPGRES(curs->pgres);
|
CLEARPGRES(curs->pgres);
|
||||||
ex = 1;
|
ex = 1;
|
||||||
|
@ -809,7 +802,6 @@ pq_fetch(cursorObject *curs)
|
||||||
|
|
||||||
case PGRES_COPY_OUT:
|
case PGRES_COPY_OUT:
|
||||||
Dprintf("pq_fetch: data from a COPY TO (no tuples)");
|
Dprintf("pq_fetch: data from a COPY TO (no tuples)");
|
||||||
curs->rowcount = 0;
|
|
||||||
#ifdef HAVE_PQPROTOCOL3
|
#ifdef HAVE_PQPROTOCOL3
|
||||||
if (curs->conn->protocol == 3)
|
if (curs->conn->protocol == 3)
|
||||||
ex = _pq_copy_out_v3(curs);
|
ex = _pq_copy_out_v3(curs);
|
||||||
|
@ -823,7 +815,6 @@ pq_fetch(cursorObject *curs)
|
||||||
|
|
||||||
case PGRES_COPY_IN:
|
case PGRES_COPY_IN:
|
||||||
Dprintf("pq_fetch: data from a COPY FROM (no tuples)");
|
Dprintf("pq_fetch: data from a COPY FROM (no tuples)");
|
||||||
curs->rowcount = 0;
|
|
||||||
#ifdef HAVE_PQPROTOCOL3
|
#ifdef HAVE_PQPROTOCOL3
|
||||||
if (curs->conn->protocol == 3)
|
if (curs->conn->protocol == 3)
|
||||||
ex = _pq_copy_in_v3(curs);
|
ex = _pq_copy_in_v3(curs);
|
||||||
|
@ -837,6 +828,7 @@ pq_fetch(cursorObject *curs)
|
||||||
|
|
||||||
case PGRES_TUPLES_OK:
|
case PGRES_TUPLES_OK:
|
||||||
Dprintf("pq_fetch: data from a SELECT (got tuples)");
|
Dprintf("pq_fetch: data from a SELECT (got tuples)");
|
||||||
|
curs->rowcount = PQntuples(curs->pgres);
|
||||||
_pq_fetch_tuples(curs); ex = 0;
|
_pq_fetch_tuples(curs); ex = 0;
|
||||||
/* don't clear curs->pgres, because it contains the results! */
|
/* don't clear curs->pgres, because it contains the results! */
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user