diff options
author | Federico Di Gregorio <fog@initd.org> | 2006-09-02 05:33:03 +0000 |
---|---|---|
committer | Federico Di Gregorio <fog@initd.org> | 2006-09-02 05:33:03 +0000 |
commit | 269156d9bfef52ad5f2dd865fe4a69c34574939b (patch) | |
tree | d0a270b460e474bc67d9b334535ddc1a1a5e8c02 /psycopg | |
parent | 64bd7ae61cd1d71888a594cb3d1fc3c647a4baa3 (diff) | |
download | psycopg2-269156d9bfef52ad5f2dd865fe4a69c34574939b.tar.gz |
Added some file-like attributes to lobject.
Diffstat (limited to 'psycopg')
-rw-r--r-- | psycopg/connection_type.c | 2 | ||||
-rw-r--r-- | psycopg/lobject.h | 6 | ||||
-rw-r--r-- | psycopg/lobject_int.c | 12 | ||||
-rw-r--r-- | psycopg/lobject_type.c | 18 |
4 files changed, 27 insertions, 11 deletions
diff --git a/psycopg/connection_type.c b/psycopg/connection_type.c index 009955a..32ce861 100644 --- a/psycopg/connection_type.c +++ b/psycopg/connection_type.c @@ -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; diff --git a/psycopg/lobject.h b/psycopg/lobject.h index 76c5cfb..4b84021 100644 --- a/psycopg/lobject.h +++ b/psycopg/lobject.h @@ -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 */ diff --git a/psycopg/lobject_int.c b/psycopg/lobject_int.c index 9b40608..d4cc38f 100644 --- a/psycopg/lobject_int.c +++ b/psycopg/lobject_int.c @@ -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; } } diff --git a/psycopg/lobject_type.c b/psycopg/lobject_type.c index 6903609..8d299e9 100644 --- a/psycopg/lobject_type.c +++ b/psycopg/lobject_type.c @@ -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 |