mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-05-03 06:33:41 +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>
|
2005-10-18 Federico Di Gregorio <fog@initd.org>
|
||||||
|
|
||||||
* psycopg/typecast.c: temporary fix to typecasting objects to return
|
* psycopg/typecast.c: temporary fix to typecasting objects to return
|
||||||
|
|
2
NEWS
2
NEWS
|
@ -20,6 +20,8 @@ What's new in psycopg 2.0 rc 1
|
||||||
* All classes have been renamed to exist in the psycopg2._psycopg module,
|
* All classes have been renamed to exist in the psycopg2._psycopg module,
|
||||||
to fix problems with automatic documentation generators like epydoc.
|
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
|
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;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* rollback method - roll back all changes done to the database */
|
/* rollback method - roll back all changes done to the database */
|
||||||
|
|
||||||
|
@ -131,7 +130,6 @@ psyco_conn_rollback(connectionObject *self, PyObject *args)
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef PSYCOPG_EXTENSIONS
|
#ifdef PSYCOPG_EXTENSIONS
|
||||||
/* set_isolation_level method - switch connection isolation level */
|
/* set_isolation_level method - switch connection isolation level */
|
||||||
|
@ -186,7 +184,7 @@ psyco_conn_set_client_encoding(connectionObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/** the connection object **/
|
/** the connection object **/
|
||||||
|
|
||||||
|
@ -255,6 +253,7 @@ connection_setup(connectionObject *self, char *dsn)
|
||||||
|
|
||||||
self->dsn = strdup(dsn);
|
self->dsn = strdup(dsn);
|
||||||
self->notice_list = PyList_New(0);
|
self->notice_list = PyList_New(0);
|
||||||
|
self->notifies = PyList_New(0);
|
||||||
self->closed = 0;
|
self->closed = 0;
|
||||||
self->status = CONN_STATUS_READY;
|
self->status = CONN_STATUS_READY;
|
||||||
self->critical = NULL;
|
self->critical = NULL;
|
||||||
|
@ -285,6 +284,9 @@ connection_dealloc(PyObject* obj)
|
||||||
if (self->encoding) free(self->encoding);
|
if (self->encoding) free(self->encoding);
|
||||||
if (self->critical) free(self->critical);
|
if (self->critical) free(self->critical);
|
||||||
|
|
||||||
|
Py_XDECREF(self->notice_list);
|
||||||
|
Py_XDECREF(self->notifies);
|
||||||
|
|
||||||
pthread_mutex_destroy(&(self->lock));
|
pthread_mutex_destroy(&(self->lock));
|
||||||
|
|
||||||
Dprintf("connection_dealloc: deleted connection object at %p, refcnt = %d",
|
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 *qattr; /* quoting attr, used when quoting strings */
|
||||||
char *notice; /* a notice from the backend */
|
char *notice; /* a notice from the backend */
|
||||||
char *query; /* last query executed */
|
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;
|
} cursorObject;
|
||||||
|
|
||||||
/* C-callable functions in cursor_int.c and cursor_ext.c */
|
/* 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},
|
{"row_factory", T_OBJECT, OFFSETOF(tuple_factory), 0},
|
||||||
{"tzinfo_factory", T_OBJECT, OFFSETOF(tzinfo_factory), 0},
|
{"tzinfo_factory", T_OBJECT, OFFSETOF(tzinfo_factory), 0},
|
||||||
{"typecaster", T_OBJECT, OFFSETOF(caster), RO},
|
{"typecaster", T_OBJECT, OFFSETOF(caster), RO},
|
||||||
|
{"string_types", T_OBJECT, OFFSETOF(string_types), 0},
|
||||||
|
{"binary_types", T_OBJECT, OFFSETOF(binary_types), 0},
|
||||||
#endif
|
#endif
|
||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
|
@ -1254,6 +1256,9 @@ cursor_setup(cursorObject *self, connectionObject *conn)
|
||||||
self->notice = NULL;
|
self->notice = NULL;
|
||||||
self->query = NULL;
|
self->query = NULL;
|
||||||
|
|
||||||
|
self->string_types = NULL;
|
||||||
|
self->binary_types = NULL;
|
||||||
|
|
||||||
self->description = Py_None;
|
self->description = Py_None;
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
self->pgstatus = Py_None;
|
self->pgstatus = Py_None;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user