mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-26 02:43:43 +03:00
Added some file-like attributes to lobject.
This commit is contained in:
parent
64bd7ae61c
commit
269156d9bf
|
@ -4,6 +4,7 @@ This module holds all the extensions to the DBAPI-2.0 provided by psycopg.
|
|||
|
||||
- `connection` -- the new-type inheritable connection class
|
||||
- `cursor` -- the new-type inheritable cursor class
|
||||
- `lobject` -- the new-type inheritable large object class
|
||||
- `adapt()` -- exposes the PEP-246_ compatible adapting mechanism used
|
||||
by psycopg to adapt Python types to PostgreSQL ones
|
||||
|
||||
|
@ -38,7 +39,7 @@ try:
|
|||
except:
|
||||
pass
|
||||
|
||||
from _psycopg import adapt, adapters, encodings, connection, cursor
|
||||
from _psycopg import adapt, adapters, encodings, connection, cursor, lobject
|
||||
from _psycopg import string_types, binary_types, new_type, register_type
|
||||
from _psycopg import ISQLQuote
|
||||
|
||||
|
|
|
@ -217,7 +217,7 @@ psyco_conn_lobject(connectionObject *self, PyObject *args, PyObject *keywds)
|
|||
static char *kwlist[] = {"oid", "mode", "new_oid", "new_file",
|
||||
"cursor_factory", NULL};
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, keywds, "|izisO", kwlist,
|
||||
if (!PyArg_ParseTupleAndKeywords(args, keywds, "|izizO", kwlist,
|
||||
&oid, &smode, &new_oid, &new_file,
|
||||
&factory)) {
|
||||
return NULL;
|
||||
|
|
|
@ -39,8 +39,10 @@ typedef struct {
|
|||
|
||||
connectionObject *conn; /* connection owning the lobject */
|
||||
|
||||
int closed:1; /* 1 if the lobject is closed */
|
||||
|
||||
int closed; /* 1 if the lobject is closed */
|
||||
int mode; /* numeric mode, tells if lobject was opened */
|
||||
char *smode; /* string mode if lobject was opened */
|
||||
|
||||
long int mark; /* copied from conn->mark */
|
||||
|
||||
Oid oid; /* the oid for this lobject */
|
||||
|
|
|
@ -86,6 +86,18 @@ lobject_open(lobjectObject *self, connectionObject *conn,
|
|||
return -1;
|
||||
}
|
||||
else {
|
||||
/* set the mode for future reference and return */
|
||||
self->mode = mode;
|
||||
switch (mode) {
|
||||
case -1:
|
||||
self->smode = "n"; break;
|
||||
case INV_READ:
|
||||
self->smode = "r"; break;
|
||||
case INV_WRITE:
|
||||
self->smode = "w"; break;
|
||||
case INV_READ+INV_WRITE:
|
||||
self->smode = "rw"; break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -230,9 +230,12 @@ static struct PyMethodDef lobjectObject_methods[] = {
|
|||
/* object member list */
|
||||
|
||||
static struct PyMemberDef lobjectObject_members[] = {
|
||||
{"oid", T_LONG,
|
||||
offsetof(lobjectObject, oid), RO,
|
||||
{"oid", T_LONG, offsetof(lobjectObject, oid), RO,
|
||||
"The backend OID associated to this lobject."},
|
||||
{"closed", T_LONG, offsetof(lobjectObject, closed), RO,
|
||||
"The if the large object is closed (no file-like methods)."},
|
||||
{"mode", T_STRING, offsetof(lobjectObject, smode), RO,
|
||||
"Open mode ('r', 'w', 'rw' or 'n')."},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
|
@ -261,12 +264,11 @@ lobject_setup(lobjectObject *self, connectionObject *conn,
|
|||
|
||||
if (lobject_open(self, conn, oid, mode, new_oid, new_file) == -1)
|
||||
return -1;
|
||||
else {
|
||||
Dprintf("lobject_setup: good lobject object at %p, refcnt = %d",
|
||||
self, ((PyObject *)self)->ob_refcnt);
|
||||
Dprintf("lobject_setup: oid = %d, fd = %d", self->oid, self->fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Dprintf("lobject_setup: good lobject object at %p, refcnt = %d",
|
||||
self, ((PyObject *)self)->ob_refcnt);
|
||||
Dprintf("lobject_setup: oid = %d, fd = %d", self->oid, self->fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in New Issue
Block a user