mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-07-11 16:52:35 +03:00
Check for Python errors during copy (closes: #134).
This commit is contained in:
parent
8c2c72a48a
commit
5c425f5294
|
@ -1,5 +1,8 @@
|
||||||
2007-01-16 Federico Di Gregorio <fog@initd.org>
|
2007-01-16 Federico Di Gregorio <fog@initd.org>
|
||||||
|
|
||||||
|
* psycopg/pqpath.cs: new checks for NULL values (meaning an
|
||||||
|
exception was raised) in all method calls (fixes #134).
|
||||||
|
|
||||||
* psycopg/psycopgmodule.c: applied LATIN patch from #148.
|
* psycopg/psycopgmodule.c: applied LATIN patch from #148.
|
||||||
|
|
||||||
* psycopg/connection_type.c: obfuscate password after using it.
|
* psycopg/connection_type.c: obfuscate password after using it.
|
||||||
|
|
|
@ -610,6 +610,8 @@ _pq_copy_in_v3(cursorObject *curs)
|
||||||
|
|
||||||
Py_XDECREF(o);
|
Py_XDECREF(o);
|
||||||
|
|
||||||
|
Dprintf("_pq_copy_in_v3: error = %d", error);
|
||||||
|
|
||||||
if (error == 0 || error == 2)
|
if (error == 0 || error == 2)
|
||||||
/* 0 means that the copy went well, 2 that there was an error on the
|
/* 0 means that the copy went well, 2 that there was an error on the
|
||||||
backend: in both cases we'll get the error message from the
|
backend: in both cases we'll get the error message from the
|
||||||
|
@ -626,7 +628,7 @@ _pq_copy_in_v3(cursorObject *curs)
|
||||||
IFCLEARPGRES(curs->pgres);
|
IFCLEARPGRES(curs->pgres);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return error == 0 ? 1 : -1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
static int
|
static int
|
||||||
|
@ -639,7 +641,8 @@ _pq_copy_in(cursorObject *curs)
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
o = PyObject_CallMethod(curs->copyfile, "readline", NULL);
|
o = PyObject_CallMethod(curs->copyfile, "readline", NULL);
|
||||||
if (!o || o == Py_None || PyString_GET_SIZE(o) == 0) break;
|
if (o == NULL) return -1;
|
||||||
|
if (o == Py_None || PyString_GET_SIZE(o) == 0) break;
|
||||||
if (PQputline(curs->conn->pgconn, PyString_AS_STRING(o)) != 0) {
|
if (PQputline(curs->conn->pgconn, PyString_AS_STRING(o)) != 0) {
|
||||||
Py_DECREF(o);
|
Py_DECREF(o);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -666,6 +669,8 @@ _pq_copy_in(cursorObject *curs)
|
||||||
static int
|
static int
|
||||||
_pq_copy_out_v3(cursorObject *curs)
|
_pq_copy_out_v3(cursorObject *curs)
|
||||||
{
|
{
|
||||||
|
PyObject *tmp = NULL;
|
||||||
|
|
||||||
char *buffer;
|
char *buffer;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
|
@ -675,8 +680,13 @@ _pq_copy_out_v3(cursorObject *curs)
|
||||||
Py_END_ALLOW_THREADS;
|
Py_END_ALLOW_THREADS;
|
||||||
|
|
||||||
if (len > 0 && buffer) {
|
if (len > 0 && buffer) {
|
||||||
PyObject_CallMethod(curs->copyfile, "write", "s#", buffer, len);
|
tmp = PyObject_CallMethod(curs->copyfile,
|
||||||
|
"write", "s#", buffer, len);
|
||||||
PQfreemem(buffer);
|
PQfreemem(buffer);
|
||||||
|
if (tmp == NULL)
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
Py_DECREF(tmp);
|
||||||
}
|
}
|
||||||
/* we break on len == 0 but note that that should *not* happen,
|
/* we break on len == 0 but note that that should *not* happen,
|
||||||
because we are not doing an async call (if it happens blame
|
because we are not doing an async call (if it happens blame
|
||||||
|
@ -703,6 +713,8 @@ _pq_copy_out_v3(cursorObject *curs)
|
||||||
static int
|
static int
|
||||||
_pq_copy_out(cursorObject *curs)
|
_pq_copy_out(cursorObject *curs)
|
||||||
{
|
{
|
||||||
|
PyObject *tmp = NULL;
|
||||||
|
|
||||||
char buffer[4096];
|
char buffer[4096];
|
||||||
int status, len;
|
int status, len;
|
||||||
|
|
||||||
|
@ -723,7 +735,11 @@ _pq_copy_out(cursorObject *curs)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject_CallMethod(curs->copyfile, "write", "s#", buffer, len);
|
tmp = PyObject_CallMethod(curs->copyfile, "write", "s#", buffer, len);
|
||||||
|
if (tmp == NULL)
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
Py_DECREF(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
status = 1;
|
status = 1;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[build_ext]
|
[build_ext]
|
||||||
define=PSYCOPG_EXTENSIONS,PSYCOPG_DISPLAY_SIZE,PSYCOPG_NEW_BOOLEAN,HAVE_PQFREEMEM,HAVE_PQPROTOCOL3
|
define=PSYCOPG_DEBUG,PSYCOPG_EXTENSIONS,PSYCOPG_DISPLAY_SIZE,PSYCOPG_NEW_BOOLEAN,HAVE_PQFREEMEM,HAVE_PQPROTOCOL3
|
||||||
# PSYCOPG_EXTENSIONS enables extensions to PEP-249 (you really want this)
|
# PSYCOPG_EXTENSIONS enables extensions to PEP-249 (you really want this)
|
||||||
# PSYCOPG_DISPLAY_SIZE enable display size calculation (a little slower)
|
# PSYCOPG_DISPLAY_SIZE enable display size calculation (a little slower)
|
||||||
# HAVE_PQFREEMEM should be defined on PostgreSQL >= 7.4
|
# HAVE_PQFREEMEM should be defined on PostgreSQL >= 7.4
|
||||||
|
|
Loading…
Reference in New Issue
Block a user