diff options
Diffstat (limited to 'psycopg')
| -rw-r--r-- | psycopg/cursor_type.c | 19 | ||||
| -rw-r--r-- | psycopg/pqpath.c | 2 |
2 files changed, 13 insertions, 8 deletions
diff --git a/psycopg/cursor_type.c b/psycopg/cursor_type.c index de32dde..0c48bbf 100644 --- a/psycopg/cursor_type.c +++ b/psycopg/cursor_type.c @@ -896,12 +896,17 @@ psyco_curs_scroll(cursorObject *self, PyObject *args, PyObject *kwargs) "copy_from(file, table, sep='\\t', null='NULL') -> copy file to table." static int -_psyco_curs_copy_from_check(PyObject *o) +_psyco_curs_has_write_check(PyObject* o, void* var) { - if (PyObject_GetAttrString(o, "write") + if (PyObject_HasAttrString(o, "write")) { + Py_INCREF(o); + *((PyObject**)var) = o; return 1; - else - + } + else { + PyErr_SetString(TypeError, "argument 1 must have a .write() method"); + return 0; + } } static PyObject * @@ -912,9 +917,9 @@ psyco_curs_copy_from(cursorObject *self, PyObject *args) long int bufsize = DEFAULT_COPYSIZE; PyObject *file, *res = NULL; - if (!PyArg_ParseTuple(args, "O!s|ssi", - &PyFile_Type, &file, &table_name, - &sep, &null, &bufsize)) { + if (!PyArg_ParseTuple(args, "O&s|ssi", + _psyco_curs_has_write_check, &file, + &table_name, &sep, &null, &bufsize)) { return NULL; } diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c index c1bfdb1..54f9c4b 100644 --- a/psycopg/pqpath.c +++ b/psycopg/pqpath.c @@ -749,7 +749,7 @@ pq_fetch(cursorObject *curs) curs->rowcount = 0; #ifdef HAVE_PQPROTOCOL3 if (curs->conn->protocol == 3) - ex = _pq_copy_out_3(curs); + ex = _pq_copy_out_v3(curs); else #endif ex = _pq_copy_out(curs); |
