mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-22 08:56:34 +03:00
NOTIFY works again.
This commit is contained in:
parent
c7c2c38bcd
commit
ec31179c9e
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
2005-10-18 Federico Di Gregorio <fog@initd.org>
|
||||
|
||||
* NOTIFY is back end working.
|
||||
|
||||
* psycopg/connection_type.c: fixed problem with initialization of
|
||||
notifies list (also fixed small memory leak in connection dealloc.)
|
||||
|
||||
* examples/notify.py: added NOTIFY example.
|
||||
|
||||
* psycopg/cursor_type.c: added per-cursor type-casters dictionaries.
|
||||
|
||||
2005-10-18 Federico Di Gregorio <fog@initd.org>
|
||||
|
||||
* psycopg/typecast.c: temporary fix to typecasting objects to return
|
||||
|
|
2
NEWS
2
NEWS
|
@ -19,6 +19,8 @@ What's new in psycopg 2.0 rc 1
|
|||
|
||||
* All classes have been renamed to exist in the psycopg2._psycopg module,
|
||||
to fix problems with automatic documentation generators like epydoc.
|
||||
|
||||
* NOTIFY is correctly trapped (see examples/notify.py for example code.)
|
||||
|
||||
What's new in psycopg 2.0 beta 4
|
||||
--------------------------------
|
||||
|
|
43
examples/notify.py
Normal file
43
examples/notify.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
# notify.py - example of getting notifies
|
||||
#
|
||||
# Copyright (C) 2001-2005 Federico Di Gregorio <fog@debian.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by the
|
||||
# Free Software Foundation; either version 2, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
|
||||
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# for more details.
|
||||
|
||||
## put in DSN your DSN string
|
||||
|
||||
DSN = 'dbname=test'
|
||||
|
||||
## don't modify anything below tis line (except for experimenting)
|
||||
|
||||
import sys
|
||||
import psycopg2
|
||||
import select
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
DSN = sys.argv[1]
|
||||
|
||||
print "Opening connection using dns:", DSN
|
||||
conn = psycopg2.connect(DSN)
|
||||
print "Encoding for this connection is", conn.encoding
|
||||
|
||||
conn.set_isolation_level(0)
|
||||
curs = conn.cursor()
|
||||
|
||||
curs.execute("listen test")
|
||||
|
||||
print "Waiting for 'NOTIFY test'"
|
||||
while 1:
|
||||
if select.select([curs],[],[],5)==([],[],[]):
|
||||
print "Timeout"
|
||||
else:
|
||||
if curs.isready():
|
||||
print "Got NOTIFY: %s" % str(curs.connection.notifies.pop())
|
|
@ -110,7 +110,6 @@ psyco_conn_commit(connectionObject *self, PyObject *args)
|
|||
return Py_None;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* rollback method - roll back all changes done to the database */
|
||||
|
||||
|
@ -131,7 +130,6 @@ psyco_conn_rollback(connectionObject *self, PyObject *args)
|
|||
return Py_None;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef PSYCOPG_EXTENSIONS
|
||||
/* set_isolation_level method - switch connection isolation level */
|
||||
|
@ -186,7 +184,7 @@ psyco_conn_set_client_encoding(connectionObject *self, PyObject *args)
|
|||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/** the connection object **/
|
||||
|
||||
|
@ -215,28 +213,28 @@ static struct PyMethodDef connectionObject_methods[] = {
|
|||
|
||||
static struct PyMemberDef connectionObject_members[] = {
|
||||
/* DBAPI-2.0 extensions (exception objects) */
|
||||
{"Error", T_OBJECT, offsetof(connectionObject,exc_Error), RO},
|
||||
{"Error", T_OBJECT, offsetof(connectionObject, exc_Error), RO},
|
||||
{"Warning", T_OBJECT, offsetof(connectionObject, exc_Warning), RO},
|
||||
{"InterfaceError", T_OBJECT,
|
||||
offsetof(connectionObject, exc_InterfaceError), RO},
|
||||
offsetof(connectionObject, exc_InterfaceError), RO},
|
||||
{"DatabaseError", T_OBJECT,
|
||||
offsetof(connectionObject, exc_DatabaseError), RO},
|
||||
offsetof(connectionObject, exc_DatabaseError), RO},
|
||||
{"InternalError", T_OBJECT,
|
||||
offsetof(connectionObject, exc_InternalError), RO},
|
||||
offsetof(connectionObject, exc_InternalError), RO},
|
||||
{"OperationalError", T_OBJECT,
|
||||
offsetof(connectionObject, exc_OperationalError), RO},
|
||||
offsetof(connectionObject, exc_OperationalError), RO},
|
||||
{"ProgrammingError", T_OBJECT,
|
||||
offsetof(connectionObject, exc_ProgrammingError), RO},
|
||||
offsetof(connectionObject, exc_ProgrammingError), RO},
|
||||
{"IntegrityError", T_OBJECT,
|
||||
offsetof(connectionObject, exc_IntegrityError), RO},
|
||||
offsetof(connectionObject, exc_IntegrityError), RO},
|
||||
{"DataError", T_OBJECT,
|
||||
offsetof(connectionObject, exc_DataError), RO},
|
||||
offsetof(connectionObject, exc_DataError), RO},
|
||||
{"NotSupportedError", T_OBJECT,
|
||||
offsetof(connectionObject, exc_NotSupportedError), RO},
|
||||
#ifdef PSYCOPG_EXTENSIONS
|
||||
{"closed", T_LONG, offsetof(connectionObject, closed), RO},
|
||||
{"isolation_level", T_LONG,
|
||||
offsetof(connectionObject, isolation_level), RO},
|
||||
offsetof(connectionObject, isolation_level), RO},
|
||||
{"encoding", T_STRING, offsetof(connectionObject, encoding), RO},
|
||||
{"notices", T_OBJECT, offsetof(connectionObject, notice_list), RO},
|
||||
{"notifies", T_OBJECT, offsetof(connectionObject, notifies), RO},
|
||||
|
@ -255,6 +253,7 @@ connection_setup(connectionObject *self, char *dsn)
|
|||
|
||||
self->dsn = strdup(dsn);
|
||||
self->notice_list = PyList_New(0);
|
||||
self->notifies = PyList_New(0);
|
||||
self->closed = 0;
|
||||
self->status = CONN_STATUS_READY;
|
||||
self->critical = NULL;
|
||||
|
@ -285,6 +284,9 @@ connection_dealloc(PyObject* obj)
|
|||
if (self->encoding) free(self->encoding);
|
||||
if (self->critical) free(self->critical);
|
||||
|
||||
Py_XDECREF(self->notice_list);
|
||||
Py_XDECREF(self->notifies);
|
||||
|
||||
pthread_mutex_destroy(&(self->lock));
|
||||
|
||||
Dprintf("connection_dealloc: deleted connection object at %p, refcnt = %d",
|
||||
|
|
|
@ -68,6 +68,10 @@ typedef struct {
|
|||
char *qattr; /* quoting attr, used when quoting strings */
|
||||
char *notice; /* a notice from the backend */
|
||||
char *query; /* last query executed */
|
||||
|
||||
PyObject *string_types; /* a set of typecasters for string types */
|
||||
PyObject *binary_types; /* a set of typecasters for binary types */
|
||||
|
||||
} cursorObject;
|
||||
|
||||
/* C-callable functions in cursor_int.c and cursor_ext.c */
|
||||
|
|
|
@ -1227,6 +1227,8 @@ static struct PyMemberDef cursorObject_members[] = {
|
|||
{"row_factory", T_OBJECT, OFFSETOF(tuple_factory), 0},
|
||||
{"tzinfo_factory", T_OBJECT, OFFSETOF(tzinfo_factory), 0},
|
||||
{"typecaster", T_OBJECT, OFFSETOF(caster), RO},
|
||||
{"string_types", T_OBJECT, OFFSETOF(string_types), 0},
|
||||
{"binary_types", T_OBJECT, OFFSETOF(binary_types), 0},
|
||||
#endif
|
||||
{NULL}
|
||||
};
|
||||
|
@ -1254,6 +1256,9 @@ cursor_setup(cursorObject *self, connectionObject *conn)
|
|||
self->notice = NULL;
|
||||
self->query = NULL;
|
||||
|
||||
self->string_types = NULL;
|
||||
self->binary_types = NULL;
|
||||
|
||||
self->description = Py_None;
|
||||
Py_INCREF(Py_None);
|
||||
self->pgstatus = Py_None;
|
||||
|
|
Loading…
Reference in New Issue
Block a user