diff options
-rw-r--r-- | AUTHORS | 5 | ||||
-rw-r--r-- | ChangeLog | 2124 | ||||
-rw-r--r-- | INSTALL | 192 | ||||
-rw-r--r-- | NEWS | 408 | ||||
-rw-r--r-- | README | 173 | ||||
-rw-r--r-- | ZPsycopgDA/DA.py | 397 | ||||
-rw-r--r-- | ZPsycopgDA/DABase.py | 286 | ||||
-rw-r--r-- | ZPsycopgDA/__init__.py | 127 | ||||
-rw-r--r-- | ZPsycopgDA/db.py | 296 | ||||
-rw-r--r-- | ZPsycopgDA/icons/bin.gif | bin | 924 -> 924 bytes | |||
-rw-r--r-- | ZPsycopgDA/icons/float.gif | bin | 929 -> 929 bytes | |||
-rw-r--r-- | ZPsycopgDA/icons/int.gif | bin | 918 -> 918 bytes | |||
-rw-r--r-- | ZPsycopgDA/icons/table.gif | bin | 878 -> 878 bytes | |||
-rw-r--r-- | ZPsycopgDA/icons/text.gif | bin | 918 -> 918 bytes | |||
-rw-r--r-- | ZPsycopgDA/icons/what.gif | bin | 894 -> 894 bytes |
15 files changed, 727 insertions, 3281 deletions
@@ -1,9 +1,8 @@ Main authors: - Michele Comitini <mcm@initd.org> Federico Di Gregorio <fog@debian.org> For the win32 port: - Jason Erickson <jerickso@indian.com> + Jason Erickson <jerickso@indian.com> (most of his changes are still in 2.0) Additional Help: - Tom Jenkins <tjenkins@devis.com> (COPY FROM/COPY TO backport) + @@ -1,2020 +1,362 @@ -2004-10-29 Federico Di Gregorio <fog@debian.org> +2004-10-14 Federico Di Gregorio <fog@debian.org> - * cursor.c (_mogrify): fixed problem with %% not being transformed - into % when calling .execute() with a zero-length tuple or dict. + * psycopg/cursor_type.c (_psyco_curs_buildrow_fill): now we use + PySequence_SetItem to avoid problems with containers created from + cursor's .tuple_factory attribute. -2004-9-27 Federico Di Gregorio <fog@lana.initd.org> + * lib/extras.py (DictCursor.execute): fixed stupid bug with cursor + setting self.tuplefactory instead of self.tuple_factory. - * cursor.c (_psyco_curs_execute): atoi->atol as suggested by Sylvain - Falardeau. +2004-10-02 Federico Di Gregorio <fog@debian.org> -2004-09-17 Federico Di Gregorio <fog@debian.org> - - * ZPsycopgDA/DA.py (cast_DateTime): implemented suggestion by - Andreas Jung to speed-up cast_Date and cast_dateTime. cast_Time - will need some more work. - -2004-09-11 Federico Di Gregorio <fog@debian.org> - - * connection.c (_psyco_conn_close): applied "trivial patch" by - Marco Bizzarri. - -2004-09-04 Federico Di Gregorio <fog@debian.org> - - * cursor.c (_psyco_curs_execute): fixed rowcount by using - PQcmdTuples as suggested by Vsevolod Lobko. - -2004-07-29 Federico Di Gregorio <fog@debian.org> - - * Release 1.1.15. - - * cursor.c (_psyco_curs_execute): reverted change to rowcount - -2004-07-15 Federico Di Gregorio <fog@debian.org> - - * typemod.c (psyco_Binary): fixed two memory leaks in QuotedString - and Binary; many thanks to Stefan Schwarzer and valgrind. - -2004-07-13 Federico Di Gregorio <fog@debian.org> - - * cursor.c (_mogrify): move Dprintf some lines below to avoid - dereferencing zero pointer. Thanks to Manuele Rampazzo for - reporting it and Jason Erickson for the fix. - -2004-07-10 Federico Di Gregorio <fog@debian.org> - - * typeobj.c (psyco_INTERVAL_cast): argh, fixed typo in interval - conversion. - -2004-07-09 Federico Di Gregorio <fog@debian.org> - - * Release 1.1.14. - -2004-07-04 Federico Di Gregorio <fog@debian.org> - - * Release 1.1.14pre2. - - * cursor.c (pgconn_notice_callback): if the message is an error, - set the right Python exception. (_psyco_curs_execute): if the - notice callback set an error during a COPY, now exit with NULL to - raise the exception. - -2004-07-01 Federico Di Gregorio <fog@debian.org> - - * Release 1.1.14pre1. - - * ZPsycopgDA/DA.py: added support for backend encodings. - - * ZPsycopgDA/db.py (DB.query): added query_data to pass - arguments to the execute method; also added query string encoding. - - * cursor.c: fixed DBAPI-2.0 compliance: - - psyco_curs_executemany: rowcount set to -1 because number of - affected columns can't be determined - - psyco_curs_setoutputsize: parse aguments - - _psyco_curs_execute: set rowcount to -1 for PGRES_COMMAND_OK - (INSERT or UPDATE executed) - - * typeobj.c (psyco_INTERVAL_cast): fixed sign problem in interval - by directly checking last sign encountered instead of hours's. - - * doc/examples/interval.py: added script to check for problem - reported by Marcin Engelmann. - -2004-06-21 Federico Di Gregorio <fog@debian.org> - - * configure.in: applied patch from Anthony Baxter to build on - Fedora core 2. - -2004-05-21 Federico Di Gregorio <fog@debian.org> - - * Release 1.1.13. - - * ZPsycopgDA/DA.py (manage_addZPsycopgConnection): fixed bug - reported by Hiroyuki SHINDO (check and tilevel parameter inverted - in Connection call.) - -2004-05-16 Federico Di Gregorio <fog@debian.org> - - * Release 1.1.12. - -2004-04-24 Federico Di Gregorio <fog@debian.org> - - * typeobj.c (psyco_INTERVAL_cast): applied patch from Ross Cohen - to fix time intervals in range (00:00, -01:00). - -2004-04-14 Federico Di Gregorio <fog@debian.org> - - * cursor.c (psyco_curs_destroy): added slightly modified patch - from Ricardo Caesar Lenzi to reduce the number of opened - connections when cursors are closed. - -2004-02-29 Federico Di Gregorio <fog@debian.org> - - * cursor.c (alloc_keeper): PQprotocolVersion used in debug - statement only if available (postgresql version >= 7.4). - -2004-02-23 Federico Di Gregorio <fog@debian.org> - - * ZPsycopgDA/DA.py: small changes to make transaction level patch - compatible with old connection objects without the need to - recreate them. - -2004-02-18 Federico Di Gregorio <fog@debian.org> - - * connection.c (_curs_doall): removed some redundant code by - passing the right function pointer to _curs_doall (patch from - David Gould.) - -2004-02-17 Federico Di Gregorio <fog@debian.org> - - * connection.c (_psyco_conn_set_isolation_level): bounds check on - the isolation level added (as suggested by David Gould.) - -2004-02-12 Federico Di Gregorio <fog@debian.org> - - * ZPsycopgDA: applied patch from Yury Don to added transaction - isolation level to ZPsycopgDA. - -2004-01-17 Federico Di Gregorio <fog@debian.org> - - * typeobj.c (psyco_TIME_cast): now we correctly use a - DateTimeDelta for postgresql times (as suggested by Daniele - Varrazzo.) - - * cursor.c (curs_switch_isolation_level): removed ALLOW_THREADS - macros to avoid deadlock while calling cursor() on the same - connection. Remember to redo the whole locking thing in psycopg 2. - -2004-01-10 Federico Di Gregorio <fog@debian.org> - - * module.c (psyco_connect): added "sslmode" parameter. - -2004-01-08 Federico Di Gregorio <fog@debian.org> - - * cursor.c (_mogrify): now raise the correct excetion instead of a - generic TypeError (bug reported by Mark McClain). - - * psycopg.spec: added updated RPM spec file from Simon Willison. - - * cursor.c (_mogrify): applied patch from Menno Smits to fix - mogrification of strings containing %%. - -2003-12-21 Federico Di Gregorio <fog@debian.org> - - * connection.c (_psyco_conn_set_isolation_level): applied patch - discussed with Sebastien Bigaret to avoid other threads to modify - the cursor list while switching isolation level. This should fix - the segfault reported some time ago. - -2003-12-18 Federico Di Gregorio <fog@debian.org> - - * Release 1.1.11. - - * cursor.c (_psyco_curs_execute): removed some cruft in COPY_IN, - "psyco_curs_reset(self, 0);" some 20 lines before already cleans - the cursor. - - * cursor.c (COPY FROM implementation): plugged possible memory - leak reported by Paul Reznicek: - - in _psyco_curs_copy_from "o" was not DECREFfed when exiting - cycle via break - - in psyco_curs_copy_from PyObject_GetAttrString return a new - reference, substitued with PyObject_HasAttrString - -2003-12-15 Federico Di Gregorio,,, <fog@localhost.localdomain> - - * connection.c: moved some declaration before code to avoid - non-standard compilers to complain. - -2003-12-12 Federico Di Gregorio <fog@debian.org> - - * connection.c: applied patch from Sebastien Bigaret to make - commit and rollback methods raise an exception on database errors. - - * ZPsycopgDA/db.py (DB.query): as per Geoff Davis suggestion, - changed string compare (note: we need a better way, maybe return - new numeric error code from protocol 3.0 in psycopg exception?) - -2003-11-21 Federico Di Gregorio <fog@debian.org> - - * cursor.c (_psyco_curs_execute): now use PQresultErrorField when - protocol 3.0 in use. - - * VERSION: removed, it is now generated when running autoconf. - - * module.h & co.: moved around a lot of #includes trying to get - rid of re-definition warnings. *this need testing* on all - platforms. - -2003-11-08 Federico Di Gregorio <fog@debian.org> - - * Ehi, this is 1.1.10. - - * cursor.c (_mogrify): removed memory leak by adding some DECREFs - (see also mail+patch from Chris Douty on psycopg mailing list.) - - * ZPsycopgDA/DA.py: shortened list of compatible versions: nobody - should be using <1.1.7 anyway.) - -2003-09-10 Federico Di Gregorio <fog@debian.org> - - * Release 1.1.9. - - * Makefile.pre.in (dist): we now include the GeoTypes package in - psycopg distribution. - -2003-09-08 Federico Di Gregorio <fog@debian.org> - - * Makefile.pre.in: added PYTHONFRAMEWORK to fix MacOS X - builds. - -2003-09-06 Federico Di Gregorio <fog@debian.org> - - * cursor.c (_mogrify): sequences were mogrified wrong because of - index being initialized to -1. it is now initialized to 0 (thanks - to Vsevolod Lobko.) - -2003-09-03 Federico Di Gregorio <fog@debian.org> - - * cursor.c (_mogrify): no more problems when passing an empty - (without markers) format string. - -2003-08-31 Federico Di Gregorio <fog@debian.org> - - * cursor.c (_mogrify): fixed the sequence/dict problem by - completely rewriting the mogrification code. - -2003-08-22 Federico Di Gregorio <fog@debian.org> - - * Release 1.1.9pre1. - -2003-08-19 Federico Di Gregorio <fog@debian.org> - - * configure.in: added check for PQfreeNotify. - - * cursor.c (psyco_curs_execute): added check on python version to - fix problem with python 2.3 PyMapping_Check() returning true while - checking list or sequences. - -2003-08-01 Federico Di Gregorio <fog@debian.org> - - * Release 1.1.8. - - * configure.in: patch from Vsevolod Lobko to find postgresql - headers under BSD ports. - - * cursor.c (alloc_keeper): PQconnectdb is not thread safe, removed - Py_*_THREADS wrapper to fix problem reported by Vsevolod Lobko. - -2003-07-31 Federico Di Gregorio <fog@debian.org> - - * cursor.c (psyco_curs_execute): in python 2.3 *every* object - supports the mapping protocol breaking sequence mogrification: - problem fixed by checking first for sequences, then for - mappings. (psycopg really needs a regression tests suite!) - -2003-07-26 Federico Di Gregorio <fog@debian.org> - - * Release 1.1.7. - - * ZPsycopgDA/db.py: added _cursor method that checks for self.db - before returning a new cursor. Should fix problem reported with - Zope 2.7. - -2003-07-23 Federico Di Gregorio <fog@debian.org> - - * cursor.c: applied notify and fileno patch from Vsevolod Lobko. - -2003-07-20 Federico Di Gregorio <fog@debian.org> - - * cursor.c (_mogrify_dict): applied (slightly modofied) patch from - Tobias Sargeant: now .execute() accept not only dictionaries but - every type that has a __getitem__ method. - -2003-07-13 Federico Di Gregorio <fog@debian.org> - - * Release 1.1.6. - - * cursor.c (psyco_curs_scroll): added scroll method, patch from - Jason D.Hildebrand. - - * typemod.c (new_psyco_quotedstringobject): discard NUL characters - (\0) in quoted strings (fix problem reported by Richard Taylor.) - -2003-07-10 Federico Di Gregorio <fog@debian.org> - - * Added python-taylor.txt in doc directory: very nice introduction - to DBAPI programming by Richard Taylor. - -2003-07-09 Federico Di Gregorio <fog@debian.org> - - * cursor.c (_psyco_curs_execute): another MT problem exposed and - fixed by Sebastien Bigaret (self->keeper->status still LOCKED - after a fatal error during PQexec call.) - -2003-06-23 Federico Di Gregorio <fog@debian.org> - - * Release 1.1.5.1. - - * ZPsycopgDA/db.py (DB.query): stupid error making ZPsycopgDA - unusable fixed (else->except). - -2003-06-22 Federico Di Gregorio <fog@debian.org> - - * Release 1.1.5 candidate. - - * cursor.c (psyco_curs_copy_to): now any object with the write - method can be used as a copy_to target. - -2003-06-20 Federico Di Gregorio <fog@debian.org> - - * cursor.c (psyco_curs_copy_from): applied patch to allow copy_to - from any object having a "readline" attribute (patch from Lex - Berezhny.) (psyco_curs_copy_from): another patch from Lex to make - psycopg raise an error on COPY FROM errors. - - * ZPsycopgDA/db.py (DB.query): if a query raise an exception, - first self._abort() is called to rollback current - "sub-transaction". this is a backward-compatible change for - people that think continuing to work in the same zope transaction - after an exception is a Good Thing (TM). - - * finally updated check_types.expected. checked by hand the - conversions work the right way. - - * doc/examples/work.py: fixed example. note that it is a long time - (at least two releases) that psycopg does not END a transaction - initiated explicitly by the user while in autocommit mode. - -2003-06-19 Federico Di Gregorio <fog@debian.org> - - * cursor.c (_mogrify_dict): fixed dictionary mogrification (patch - by Vsevolod Lobko.) (_psyco_curs_execute): fixed keeper status - trashing problem by letting only one thread at time play with - keeper->status (as suggested by Sebastien Bigaret.) - -2003-05-07 Federico Di Gregorio <fog@debian.org> - - * Release 1.1.4. - - * cursor.c: Added "statusmessage" attribute that holds the backend - message (modified lots of functions, look for self->status). - -2003-05-06 Federico Di Gregorio <fog@debian.org> - - * typemod.c (new_psyco_datetimeobject): moved Py_INCREF into - XXX_FromMx functions, to fix memory leak reported by Jim Crumpler. - -2003-04-11 Federico Di Gregorio <fog@debian.org> - - * module.h (PyObject_TypeCheck): fixed leak in python 2.1 - (Guido van Rossum). - -2003-04-08 Federico Di Gregorio <fog@debian.org> - - * buildtypes.py (basic_types): removed LXTEXT (never user, does - not exists anymore.) - -2003-04-07 Federico Di Gregorio <fog@debian.org> - - * setup.py: added very lame setup.py script. - -2003-04-02 Federico Di Gregorio <fog@debian.org> - - * Release 1.3. - - * psycopg.spec: Added (but modified) spec file by William - K. Volkman (again, this change was lost somewhere in time...) - -2003-04-01 Federico Di Gregorio <fog@debian.org> - - * cursor.c (_psyco_curs_execute): psycopg was reporting everything - as IntegrityError; reported and fix suggested by Amin Abdulghani. - -2003-03-21 Federico Di Gregorio <fog@debian.org> - - * cursor.c (psyco_curs_fetchone): debug statements sometimes made - psycopg segfault: fixed by a patch by Ken Simpson. - -2003-03-18 Federico Di Gregorio <fog@debian.org> - - * cursor.c (alloc_keeper): patch from Dieter Maurer to unlock GIL - whaile calling PQconnectdb(). - -2003-03-05 Federico Di Gregorio <fog@debian.org> - - * Release 1.1.2. - - * Applied cygwin patch from Hajime Nakagami. - -2003-02-25 Federico Di Gregorio <fog@debian.org> - - * Release 1.1.2pre1. - - * cursor.c: added .lastrowid attribute to cursors (lastoid is - deprecated and will be removed sometime in the future.) - - * cursor.c (begin_pgconn): implemented various isolation levels - (also, in abort_pgconn, commit_pgconn.) - - * Added keyword parameters to psycopg.connect(): all take strings - (even port): database, host, port, user, password. - - * configure.in: fixed test for postgres version > 7.2. - - * cursor.c (_psyco_curs_execute): removed if on pgerr in default - case (if we enter default pgerr can't be one of the cased ones.) - Also applied slightly modified patch from William K. Volkman. - -2003-02-24 Federico Di Gregorio <fog@debian.org> - - * Merged in changes from 1.0.15.1 (see below for merged - ChangeLog.) - -2003-02-14 Federico Di Gregorio <fog@debian.org> - - * Release 1.0.15.1. - - * cursor.c (_mogrify_fmt): in some cases we where removing one - character too much from the format string, resulting in BIG BAD - BUG. <g> Fixed. - -2003-02-13 Federico Di Gregorio <fog@debian.org> - - * Release 1.0.15. <g> - - * connection.c (_psyco_conn_close): now call dispose_pgconn on all - cursors, to make sure all phisical connections to the db are - closed (problem first reported by Amin Abdulghani.) - - * DBAPI-2.0 fixed mainly due to Stuart Bishop: - - cursor.c (psyco_curs_setinputsizes): removed PARSEARGS, as - this method does nothing. - - cursor.c (psyco_curs_setoutputsize): .setoutputsize was - spelled .setoutputsizes! fixed. Also removed PARSEARGS, as this - method does nothing. - -2003-02-12 Federico Di Gregorio <fog@debian.org> - - * module.h (Dprintf): check on __APPLE__ to avoid variadic macros - on macos x (as reported by Stuart Bishop, btw, why gcc seems to - not support them on macos?) - - * cursor.c (_mogrify_fmt): non-alphabetic characters are dropped - after the closing ")" until a real alphabetic, formatting one is - found. (Fix bug reported by Randall Randall.) - -2003-02-05 Federico Di Gregorio <fog@debian.org> - - * typeobj.c (psyco_INTERVAL_cast): patched again to take into - account leading zeroes. - -2003-02-02 Federico Di Gregorio <fog@debian.org> - - * Makefile.pre.in: applied patch from Albert Chin-A-Young to - define BLDSHARED. - - * README: added explicit permission to link with OpenSSL. - -2003-01-30 Federico Di Gregorio <fog@debian.org> - - * config.h.in: applied patch from Albert Chin-A-Young to fix - asprintf prototype. - -2003-01-29 Federico Di Gregorio <fog@debian.org> - - * cursor.c (_mogrify_seq): fixed little refcount leak, as - suggested by Yves Bastide. - -2003-01-24 Federico Di Gregorio <fog@debian.org> - - * Merged-in changes from 1.0.14.2 (emacs diff mode is great..) - - * Release 1.0.14.2. - - * ZPsycopgDA/db.py (DB.query): back to allowing up to 1000 db - errors before trying to reopen the connection by ourselves. - - * ZPsycopgDA/db.py: a false (None preferred, 0 allowed) max_rows - value now means "fetch all results". - -2003-01-22 Federico Di Gregorio <fog@debian.org> - - * cursor.c (psyco_curs_fetchone): fixed little memory leak - reported by Dieter Maurer. - -2003-01-20 Federico Di Gregorio <fog@debian.org> - - * ZPsycopgDA/db.py (DB.tables/columns): added registration with - Zope's transaction machinery. - - * Release 1.0.14.1. - - * ZPsycopgDA/db.py: applied some fixes and cleanups by Dieter - Maurer (serialization problem were no more correctly detected!) - - * Release 1.0.14. - - * Merged in 1.0.14. - - * Import of 1.1.1 done. - - * Moved everything to cvs HEAD. - -2003-01-20 Federico Di Gregorio <fog@debian.org> - - * ZPsycopgDA/connectionAdd.dtml: fixed typo (thanks to Andrew - Veitch.) - - * typeobj.c (psyco_INTERVAL_cast): applied patch from Karl Putland - to fix problems with fractional seconds. - -2002-12-03 Federico Di Gregorio <fog@debian.org> - - * Release 1.0.14-pre2. - - * module.h: added macro for PyObject_TypeCheck if python version <2.2. - - * typeobj.c (psyco_DBAPITypeObject_coerce): added error message to - coercion errors. - -2002-12-02 Federico Di Gregorio <fog@debian.org> - - * Release 1.0.14-pre1. - - * ZPsycopgDA/db.py (DB.sortKey): added sortKey(). - - * ZPsycopgDA/DA.py: applied a patch that was lost on hard disk - (sic), if you sent me a patch names psycopg-1.0.13.diff modifying - DA.py imports and want your name here, send me an email. :) - [btw, the patch fix the ImageFile import, getting it from Globals - as it is right.] - - * typeobj.c (psyco_DBAPITypeObject_coerce): Fixed coerce segfault - by checking explicitly for all the allowed types. - -2002-11-25 Federico Di Gregorio <fog@debian.org> - - * doc/examples/*.py: added .rollback() to all exceptions before - deleteing the old table. - - * cursor.c: Apllied patch from John Goerzen (fix memory leak in - executemany). - -2002-10-25 Federico Di Gregorio <fog@debian.org> - - * Release 1.0.13. - - * connection.c (_psyco_conn_close): remove cursors from the list - starting from last and moving backward (as suggested by Jeremy - Hylton; this is not such a big gain because python lists are - *linked* lists, but not removing the element 0 makes the code a - little bit clear.) - - * cursor.c (_psyco_curs_execute): now IntegrityError is raised - instead of ProgrammingError when adding NULL values to a non-NULL - column (suggested by Edmund Lian) and on referential integrity - violation (as per debian bug #165791.) - - * typeobj.c (psyco_DATE_cast): now we use 999999 instead of - 5867440 for very large (both signs) dates. This allow to re-insert - the DateTime object into postgresql (suggested by Zahid Malik.) - -2002-09-13 Federico Di Gregorio <fog@debian.org> - - * Release 1.0.12. - - * Removed code to support COPY FROM/TO, will be added to new 1.1 - branch to be released next week. - - * cursor.c (_mogrify_seq): Fixed memory leak reported by Menno - Smits (values obtained by calling PySequence_GetItem are *new* - references!) - -2002-09-07 Federico Di Gregorio <fog@debian.org> - - * cursor.c (_psyco_curs_execute): Added skeleton to support COPY - FROM/TO. - -2002-09-06 Federico Di Gregorio <fog@debian.org> - - * configure.in: if libcrypt can't be found we probably are on - MacOS X: check for libcrypto, as suggested by Aparajita Fishman. - -2002-09-03 Federico Di Gregorio <fog@debian.org> - - * ZPsycopgDA/db.py (DB.columns): Applied patch from Dieter Maurer - to allow the DA-browser to work with mixed case table names. - -2002-08-30 Federico Di Gregorio <fog@debian.org> - - * ZPsycopgDA/DA.py (cast_DateTime): Applied patch from Yury to fix - timestamps (before they were returned with time always set to 0.) - -2002-08-26 Federico Di Gregorio <fog@debian.org> - - * Release 1.0.11.1 (to fix a %&£$"! bug in ZPsycopgDA not - accepting psycopg 1.0.11 as a valid version. - - * Release 1.0.11. - -2002-08-22 Federico Di Gregorio <fog@debian.org> - - * Release 1.0.11pre2. - - * cursor.c (_psyco_curs_execute): fixed IntegrityError as reported - by Andy Dustman. (psyco_curs_execute): converting TypeError to - ProgrammingError on wrong number of % and/or aeguments. - - * doc/examples/integrity.py: added example and check for - IntegrityError. - -2002-08-08 Federico Di Gregorio <fog@debian.org> - - * Release 1.0.11pre1. - -2002-08-06 Federico Di Gregorio <fog@debian.org> - - * ZPsycopgDA/DA.py (cast_DateTime): patched as suggested by Tom - Jenkins; now it shouldwork with time zones too. - -2002-08-01 Federico Di Gregorio <fog@debian.org> - - * ZPsycopgDA/DA.py (cast_DateTime): fixed problem with missing - AM/PM, as reported by Tom Jenkins. - -2002-07-23 Federico Di Gregorio <fog@debian.org> - - * Fixed buglets reported by Mike Coleman. - -2002-07-22 Federico Di Gregorio <fog@debian.org> - - * Release 1.0.10. - -2002-07-14 Federico Di Gregorio <fog@debian.org> - - * Release 1.0.10pre2. + * Release 1.99.10. - * typeobj.c (psyco_LONGINTEGER_cast): fixed bad segfault by - INCREFfing Py_None when it is the result of a NULL conversion. - -2002-07-04 Federico Di Gregorio <fog@debian.org> - - * Release 1.0.10pre1. - - * buildtypes.py (basic_types): added TIMESTAMPTZ to the types - converted by the DATE builtin. - - * ZPsycopgDA/DA.py (Connection.connect): Added version check. - -2002-07-03 Federico Di Gregorio <fog@debian.org> + * psycopg/cursor_type.c (_psyco_curs_buildrow_*): unified normal + and factory code into the _psyco_curs_buildrow_fill function; no + more memory leaks here. - * typeobj.c (psyco_XXX_cast): fixed bug reported by multiple users - by appliying Matt patch. + * psycopg/config.h (round): added check for __FreeBSD__ (that + should be defined when compiling with gcc, I hope.) -2002-06-30 Federico Di Gregorio <fog@debian.org> + * setup.py: removed a lot of code now in setup.cfg. - * ZPsycopgDA/DA.py (Connection.set_type_casts): applied patch from - Tom Jenkins to parse dates with TZ. +2004-09-24 Federico Di Gregorio <fog@debian.org> -2002-06-20 Federico Di Gregorio <fog@debian.org> + * psycopg/cursor_type.c (cursor_dealloc): fixed small memory leak + due to missing disposal of self->pgres. - * Preparing for release 1.0.9. +2004-9-14 Federico Di Gregorio <fog@initd.org> - * Makefile.pre.in (dist): now we really include psycopg.spec. + * examples/dialtone.py: Added adapt() example by Valentino + Volonghi. -2002-06-17 Federico Di Gregorio <fog@debian.org> +2004-09-14 Federico Di Gregorio <fog@debian.org> - * ZPsycopgDA/db.py (_finish, _abort): fixed problem with - connection left in invalid state by applying Tom Jenkins patch. + * psycopg/microprotocols.c (microprotocols_adapt): lots of changes + to the microprotocols layer (it is not micro anymore); + implementing almost all the PEP 246. The adapter registry is now + indexed by (type, protocol) and not by type alone. -2002-06-06 Federico Di Gregorio <fog@debian.org> - - * ZPsycopgDA/db.py (DB._abort): fixed exception raising after an - error in execute triggerer deletion of self.db. - -2002-05-16 Federico Di Gregorio <fog@debian.org> - - * cursor.c (psyco_curs_fetchone): None values passed to the - internal typecasters. - - * typeobj.c: added management of None to all the builtin - typecasters. - -2002-04-29 Federico Di Gregorio <fog@debian.org> - - * ZPsycopgDA/DA.py (cast_Time): applied 'seconds as a float' patch - from Jelle. - -2002-04-23 Federico Di Gregorio <fog@debian.org> - - * Release 1.0.8. - - * Makefile.pre.in: we now include win32 related files in the - distribution. - - * connection.c (psyco_conn_destroy): fixed segfault reported by - Scott Leerssen (we were double calling _psyco_conn_close().) - - * typemod.c (new_psyco_quotedstringobject): fixed memory stomping - catched by assert(); thanks to Matt Hoskins for reporting this - one. - -2002-04-22 Federico Di Gregorio <fog@debian.org> - - * configure.in: grmpf. we need a VERSION file for windows, we'll - use it for configue and debian/rules too. - - * Integrated win32 changes from Jason Erickson. Moved his - Readme.txt to README.win32, removed VERSION and DATE, patched - source where required. Renamed HISTORY to ChangeLog.win32, hoping - Jason will start adding changes to the real ChangeLog file. - -2002-04-07 Federico Di Gregorio <fog@debian.org> - - * Release 1.0.7.1. - - * configure.in: fixed little bug as reported by ron. - -2002-04-05 Federico Di Gregorio <fog@debian.org> - - * Release 1.0.7? - - * typemod.c (new_psyco_bufferobject): fixed encoding problem (0xff - now encoded as \377 and not \777.) Also encoding *all* chars as - quoted octal values to prevent "Invalid UNICODE character sequence - found" errors. +2004-09-13 Federico Di Gregorio <fog@debian.org> - * Release 1.0.7. (Real this time.) (Ok, it was a joke....) + * psycopg/cursor_type.c (_mogrify): and qattr is gone. -2002-04-03 Federico Di Gregorio <fog@debian.org> +2004-09-05 Federico Di Gregorio <fog@debian.org> - * configure.in: fixed problem with postgres versions in the format - 7.2.x (sic.) - - * connection.c (psyco_conn_destroy): moved most of the destroy - stuff into its own function (_psyco_conn_close) and added a call - to it from psyco_conn_close. This should fix the "psycopg does not - release postgres connections on .close()" problem. - -2002-03-29 Federico Di Gregorio <fog@debian.org> - - * Release 1.0.7. Delayed. - - * buildtypes.py (basic_types): added TIMESTAMPTZ postgres type to - the list of valid DATETIME types (incredible luck, no changes to - the parse are needed!) - - * typeobj.c (psyco_DATE_cast): fixed wrong managment of sign in - infinity. - -2002-03-27 Federico Di Gregorio <fog@debian.org> - - * configure.in (INSTALLOPTS): added AC_PROG_CPP test, now uses - AC_TRY_CPP to test for _all_ required mx includes. - -2002-03-19 Federico Di Gregorio <fog@debian.org> - - * configure.in: added check for both pg_config.h and config.h to - detect postgres version. - - * cursor.c: now None values are correctly handled when the format - string is not %s but %d, etc. - -2002-03-08 Federico Di Gregorio <fog@debian.org> - - * ZPsycopgDA/DA.py: added MessageDialog import suggested by - Guido. - -2002-03-07 Federico Di Gregorio <fog@debian.org> - - * psycopg.spec: added RPM specs by William K. Volkman. - - * Release 1.0.6. - - * configure.in: imported changes to allow postgres 7.2 builds from - unstable branch. - -2002-03-04 Federico Di Gregorio <fog@debian.org> - - * Release 1.0.5. - - * applied table browser patch from Andy Dustman. - -2002-02-26 Federico Di Gregorio <fog@debian.org> - - * typeobj.c (psyco_DATE_cast): added management of infinity - values, this can be done in a better way, by accessing the - MaxDateTime and MinDateTime constants of the mx.DateTime module. - -2002-02-20 Federico Di Gregorio <fog@debian.org> - - * configure.in: Release 1.0.4. - -2002-02-12 Federico Di Gregorio <fog@debian.org> - - * ZPsycopgDA/db.py (DB.columns): fixed select to reenable column - expansion in table browsing. - - * ZPsycopgDA/__init__.py: removed code that made psycopg think - double. - -2002-02-11 Federico Di Gregorio <fog@debian.org> - - * cursor.c (_mogrify_dict): removed Py_DECREF of Py_None, - references returned by PyDict_Next() are borrowed (thanks to - Michael Lausch for this one.) - -2002-02-08 Federico Di Gregorio <fog@debian.org> - - * A little bug slipped in ZPsycopgDA, releasing 1.0.3 immediately. - - * Release 1.0.2. - - * tests/check_types.py (TYPES): added check for hundredths of a - second. - -2002-02-07 Federico Di Gregorio <fog@debian.org> - - * typeobj.c (psyco_INTERVAL_cast): patched to correct wrong - interpretation of hundredths of a second (patch from - A. R. Beresford, kudos!) - -2002-01-31 Federico Di Gregorio <fog@debian.org> - - * FAQ: added. - -2002-01-16 Federico Di Gregorio <fog@debian.org> - - * Preparing for release 1.0.1. - - * cursor.c (alloc_keeper): removed ALLOW_THREADS wrapper around - PQconnectdb: libpq calls crypt() that is *not* reentrant. + * Release 1.99.9 (or, the "twisting by the pool" release). -2001-12-19 Federico Di Gregorio <fog@debian.org> + * psycopg/pqpath.c (_pq_fetch_tuples): changed to "static void" + instead of "static int", no ways for this function to fail. - * typeobj.c (psyco_DBAPITypeObject_cmp): added check to simply - return false when two type objects are compared (type objects are - meaned to be compared to integers!) - - * typeobj.c: fixed the memory leak reported by the guys at - racemi, for real this time. (added about 5 DECREFS and 2 INCREFS, - ouch!) - -2001-12-17 Federico Di Gregorio <fog@debian.org> - - * typeobj.c (psyco_DBAPITypeObject_cmp): fixed memory leak by - using PyTuple_GET_ITEM (we are sure the tuple has at least one - element, we built it, after all...) (many thanks to Scott Leerssen - for reporting the *exact line* for this one.) - -2001-12-13 Federico Di Gregorio <fog@debian.org> - - * cursor.c: fixed memory leak due to extra strdup (thanks - to Leonardo Rochael Almeida.) - -2001-11-14 Federico Di Gregorio <fog@debian.org> - - * Release 1.0. - - * doc/README: added explanation about guide work in progess but - examples working. - - * debian/*: lots of changes to release 1.0 in debian too. - -2001-11-12 Federico Di Gregorio <fog@debian.org> - - * RELEASE-1.0: added release file, to celebrate 1.0. - - * tests/zope/typecheck.zexp: regression test on types for zope. - -2001-11-11 Federico Di Gregorio <fog@debian.org> - - * ZPsycopgDA/DA.py (cast_Interval): removed typecast of interval - into zope DateTime. intervals are reported as strings when using - zope DateTime and as DateTimeDeltas when using mx. - -2001-11-09 Federico Di Gregorio <fog@debian.org> - - * typeobj.c (psyco_INTERVAL_cast): complete rewrite of the - interval parsing code. now we don't use sscanf anymore and all is - done with custom code in a very tight and fast loop. - -2001-11-08 Federico Di Gregorio <fog@debian.org> - - * ZPsycopgDA/DA.py (Connection.set_type_casts): added mx INTERVAL - type restore. - - * ZPsycopgDA/db.py (DB.query): now we return column names even if - there are no rows in the result set. also, cleaned up a little bit - the code. - -2001-11-7 Federico Di Gregorio, <fog@debian.org> - - * Makefile.pre.in: fixed small problem with zcat on True64 - (thank you stefan.) - -2001-11-06 Federico Di Gregorio <fog@debian.org> - - * ZPsycopgDA/db.py (DB.query): added fix for concurrent update - from Chris Kratz. - -2001-11-05 Federico Di Gregorio <fog@debian.org> - - * cursor.c: now we include postgres.h if InvalidOid is still - undefined after all other #includes. - - * README: clarified use of configure args related to python - versions. - - * aclocal.m4: patched to work with symlinks installations (thanks - to Stuart Bishop.) - - * cursor.c (_psyco_curs_execute): now reset the keeper's status to - the old value and not to BEGIN (solve problem with autocommit not - switching back.) - -2001-11-01 Federico Di Gregorio <fog@debian.org> - - * doc/examples/dt.py: added example on how to use the date and - time constructors. - - * Makefile.pre.in (dist-zope): removed dependencies on GNU install - and tar commands. Also a little general cleanup on various targets. - - * ZPsycopgDA/DA.py: fixed mx.DateTime importing. - -2001-10-31 Federico Di Gregorio <fog@debian.org> - - * typemod.c (psyco_xxxFromMx): fixed bug in argument parsing (we - weren't usigng the right type object.) - - * aclocal.m4: now builds OPT and LDFLAGS on the values of the env - variables instead of overwriting them. - - * Makefile.pre.in (CFLAGS): removed -Wall, you can add it back at - compile time with OPT="-Wall" ./configure ... - - * Setup.in (OPT): removed -Wall. - -2001-10-30 Michele Comitini <mcm@initd.net> - - * module.h: ANSI C compatibility patch from Daniel Plagge. - -2001-10-30 Federico Di Gregorio <fog@debian.org> - - * README: added common building problems and solutions. - - * configure.in: removed check for install command, already done by - james's aclocal.m4 for python. removed install-sh. removed -s from - INSTALLOPTS. - -2001-10-29 Federico Di Gregorio <fog@debian.org> - - * Makefile.pre.in (dist): removed examples/ directory from - distribution. - - * merge with cvs head. preparing to fork again on PSYCOPG-1-0 (i - admit BRANCH_1_0 was quite a silly name.) - - * doc/examples/usercast.py: now works. - - * connection.c (curs_rollbackall): fixed little bug (exposed by - the deadlock below) by changing KEEPER_READY to KEEPER_READY. - - * doc/examples/commit.py: deadlock problem solved, was the - example script, _not_ psycopg. pew... :) - - * examples/*: removed the examples moved to doc/examples/. - - * doc/examples/commit.py,dictfetch.py: moved from examples/ and - changed to work for 1.0. unfortunately commit.py locks psycopg!!! - -2001-10-24 Federico Di Gregorio <fog@debian.org> - - * modified all files neede for the 1.0 release. - - * configure.in (MXFLAGS): removed electric fence support. - - * Makefile.pre.in (dist): now we remove CVS working files before - packing the tarball. - - * tests: files in this directory are not coding examples, but - regression tests. we need a sufficient number of tests to follow - every single code path in psycopg at least once. first test is - about datatypes. - - * doc/examples: moved new example code to examples directory, old - tests and code samples will stay in examples/ until the manual will - be finished. - -2001-10-16 Federico Di Gregorio <fog@debian.org> - - * typeobj.c (psyco_INTERVAL_cast): completely revised interval - casting code. (psyco_TIME_cast): we use the unix epoch when the - date is undefined. - - * cursor.c (psyco_curs_executemany): modified sanity check to - accept sequences of tuples too and not just dictionaries. - -2001-10-15 Federico Di Gregorio <fog@debian.org> - - * typeobj.c (psyco_INTERVAL_cast): fixed bug caused by wrong - parsing on '1 day' (no hours, minutes and seconds.) - -2001-10-15 Michele Comitini <mcm@initd.net> - - * cursor.c (_execute): use the correct cast functions even on - retrival of binary cursors. - -2001-10-12 Federico Di Gregorio <fog@debian.org> - - * typemod.c (new_psyco_bufferobject): space not quoted anymore, - smarter formula to calculate realloc size. - - * cursor.c (psyco_curs_fetchone): removed static tuple (using - static variable in multithreaded code is *crazy*, why did i do it? - who knows...) - - * typeobj.c (psyco_init_types): exports the binary converter (will - be used in cursor.c:_execute.) - - * typeobj.h: added export of psyco_binary_cast object. - -2001-10-05 Federico Di Gregorio <fog@debian.org> - - * cursor.c (_psyco_curs_execute): added missing Py_XDECREF on - casts list. - - * Makefile.pre.in (dist): added install-sh file to the - distribution. - - * replaced PyMem_DEL with PyObject_Del where necessary. - - * connection.c (psyco_conn_destroy): added missing - pthread_mutex_destroy on keeper lock. - -2001-10-01 Michele Comitini <mcm@initd.net> - - * typemod.c(new_psyco_bufferobject()): using unsigned char for - binary objects to avoid too many chars escaped. A quick and - simple formula to avoid memory wasting and too much reallocating - for the converted object. Needs _testing_, but it is faster. - - * cursor.c: #include <postgres.h> - - * module.h: now debugging should be active only when asked by - ./configure --enable-devel - -2001-09-29 Federico Di Gregorio <fog@debian.org> - - * cursor.c (new_psyco_cursobject): added locking of connection, - still unsure if necessary. - -2001-09-26 Federico Di Gregorio <fog@debian.org> - - * configure.in: changed DEBUG into PSYCOTIC_DEBUG, to allow other - includes (postgres.h) to use the former. better compiler checks: - inline, ansi, gcc specific extensions. removed MXMODULE: we don't - need it anymore. - - * general #include cleanup, should compile on MacOS X too. - - * typeobj.c (psyco_DATE_cast): uses sscanf. should be faster too. - (psyco_TIME_cast): dixit. - - * applied patch from Daniel Plagge (SUN cc changes.) - -2001-09-22 Federico Di Gregorio <fog@debian.org> - - * ZPsycopgDA/db.py (DB._finish, DB._begin): fix for the - self.db == None problem. - -2001-09-19 Michele Comitini <mcm@initd.net> - - * typemod.c (new_psyco_bufferobject): better memory managment - (now it allocates only needed space dinamically). - - * typeobj.c (psyco_BINARY_cast): ripped a useless check, now - it assumes that binary streams come out from the db correctly - escaped. Should be a lot faster. - -2001-09-18 Federico Di Gregorio <fog@debian.org> - - * typeobj.c (psyco_INTERVAL_cast): fixed interval conversion - (hours were incorrectly converted into seconds.) - -2001-09-17 Federico Di Gregorio <fog@debian.org> - - * cursor.c (_mogrify_seq, _mogrify_dict): added check for None - value and conversion of None -> NULL (fixes bug reported by Hamish - Lawson.) - -2001-09-12 Federico Di Gregorio <fog@debian.org> - - * module.c: added handles to new date and time conversion - functions (see below.) - - * typemod.c (psyco_XXXFromMx): added conversion functions that - simply wrap the mxDateTime objects instead of creating - them. DBAPI-2.0 extension, off-curse. - -2001-09-10 Federico Di Gregorio <fog@debian.org> - - * buildtypes.py: solved hidden bug by changing from dictionary to - list, to maintain ordering of types. sometimes (and just - sometimes) the type definitions were printed unsorted, resulting - is psycopg initializing the type system using the type objects in - the wrong order. you were getting float values from an int4 - column? be happy, this is now fixed... - - * cursor.c (psyco_curs_lastoid): added method to get oid of the - last inserted row (it was sooo easy, it even works...) - -2001-09-08 Federico Di Gregorio <fog@debian.org> - - * typeobj.c (psyco_INTERVAL_cast): added casting function for the - postgres INTERVAL and TINTERVAL types (create a DateTimeDelta - object.) - -2001-09-05 Federico Di Gregorio <fog@debian.org> - - * cursor.c: moved all calls to begin_pgconn to a single call in - _psyco_curs_execute, to leave the connection in a not-idle status - after a commit or a rollback. this should free a lot of resources - on the backend side. kudos to the webware-discuss mailing list - members and to Clark C. Evans who suggested a nice solution. - - * connection.c (curs_rollbackall, curs_commitall): removed calls - to begin_pgconn, see above. - - * module.c (initpsycopg): cleaned up mxDateTime importing; we now - use the right function from mxDateTime.h. Is not necessary anymore - to include our own mx headers. This makes psycopg to depend on - mxDateTime >= 2.0.0. - -2001-09-04 Federico Di Gregorio <fog@debian.org> - - * doc/*.tex: added documentation directory and skeleton of the - psycopg guide. - -2001-09-03 Federico Di Gregorio <fog@debian.org> - - * merged in changes from HEAD (mostly mcm fixes to binary - objects.) - - * preparing for release 0.99.6. - -2001-09-03 Michele Comitini <mcm@initd.net> - - * typemod.c: much faster Binary encoding routine. - - * typeobj.c: much faster Binary decoding routine. - -2001-08-28 Michele Comitini <mcm@initd.net> - - * typemod.c: Working binary object to feed data to bytea type - fields. - - * typeobj.c: Added BINARY typecast to extract data from - bytea type fields. - - * cursor.c: Added handling for SQL binary cursors. - -2001-08-3 Michele Comitini <mcm@initd.net> - - * cursor.c: fixed DATESTYLE problem thanx to Steve Drees. - -2001-07-26 Federico Di Gregorio <fog@debian.org> - - * Makefile.pre.in: applied change suggested by Stefan H. Holek to - clobber and distclean targets. - -2001-07-23 Federico Di Gregorio <fog@debian.org> - - * ZPsycopgDA/db.py: fixed little bugs exposed by multiple select - changes, not we correctly import ListType and we don't override - the type() function with a variable. - -2001-07-17 Federico Di Gregorio <fog@debian.org> - - * configure.in: Release 0.99.5. - -2001-07-12 Federico Di Gregorio <fog@debian.org> - - * debian/* fixed some little packaging problems. - -2001-07-11 Federico Di Gregorio <fog@debian.org> - - * cursor.c, typeobj.c: removed some Py_INCREF on PyDict_SetItem - keys and values to avoid memory leaks. - -2001-07-03 Federico Di Gregorio <fog@debian.org> - - * cursor.c (_mogrify_dict): added dictionary mogrification: all - Strings in the dictionary are translated into QuotedStrings. it - even works... (_mogrify_seq): added sequence mogrification and - code to automagically mogrify all strings passed to .execute(). - -2001-07-02 Federico Di Gregorio <fog@debian.org> - - * Release 0.99.4. - - * typemod.c: added QuotedString class and methods. - - * module.c: added QuotedString method to module psycopg. - - * typemod.c: changed Binary objects into something usefull. now - the buffer object quotes the input by translatin every char into - its octal representation. this consumes 4x memory but guarantees - that even binary data containing '\0' can go into the Binary - object. - - * typemod.h: added definition of QuotedString object. - -2001-06-28 Federico Di Gregorio <fog@debian.org> - - * ZPsycopgDA/db.py, ZPsycopgDA/DABase.py: applied patch sent by - yury to fix little buglet. - -2001-06-22 Federico Di Gregorio <fog@debian.org> - - * Release 0.99.3. - - * connection.c (new_psyco_connobject): now we strdup dsn, as a fix - for the problem reported by Jack Moffitt. - - * Ok, this will be the stable branch from now on... - - * Merged in stuff from 0.99.3. About to re-branch with a better - name (BRANCH_1_0) - -2001-06-20 Federico Di Gregorio <fog@debian.org> - - * Release 0.99.3. Showstoppers for 1.0 are: - - documentation - - mxDateTime module loading - - bug reported by Yury. - - * Integrated patches from Michele: - - searching for libcrypt in configure now works - - removed memory leak in asprintf.c - -2001-06-15 Federico Di Gregorio <fog@debian.org> - - * ZPsycopgDA/__init__.py (initialize): applied patch from Jelle to - resolve problem with Zope 2.4.0a1. - -2001-06-14 Federico Di Gregorio <fog@debian.org> - - * configure.in: added code to check for missing functions (only - asprintf at now.) - - * asprintf.c: added compatibility code for oses that does not have - the asprintf() function. - -2001-06-10 Federico Di Gregorio <fog@debian.org> - - * Branched PSYCOPG_0_99_3. Development will continue on the cvs - HEAD, final adjustements and bugfixing should go to this newly - created branch. - -2001-06-08 Michele Comitini <mcm@initd.net> - - * ZPsycopgDA/DA.py: DateTime casts simplified and corrected - as suggested by Yury. - -2001-06-05 Federico Di Gregorio <fog@debian.org> - - * Release 0.99.2. - - * Makefile.pre.in (dist): added typemod.h and typemod.c to - distribution. - - * cursor.c (commit_pgconn, abort_pgconn, begin_pgconn): resolved - segfault reported by Andre by changing PyErr_SetString invokations - into pgconn_set_critical. the problem was that the python - interpreter simply segfaults when we touch its internal data (like - exception message) inside an ALLOW_THREADS wrapper. - - * now that we are 100% DBAPI-2.0 compliant is time for the - one-dot-o release (at last!) Para-pa-pa! This one is tagged - PSYCOPG_0_99_1 but you can call it 1.0pre1, if you better like. - (A very long text just to say 'Release 0.99.1') - - * typemod.[ch]: to reach complete DBAPI-2.0 compliance we - introduce some new objects returned by the constructors Date(), - Time(), Binary(), etc. Those objects are module-to-database only, - the type system still takes care of the database-to-python - conversion. - -2001-06-01 Federico Di Gregorio <fog@debian.org> - - * Release 0.5.5. - - * module.h: better error message when trying to commit on a - cursor derived from serialized connection. - - * ZPsycopgDA/db.py (DB.close): now self.cursor is set to None when - the connection is closed. - - * module.c (initpsycopg): added missing (sic) DBAPI module - parameters (paramstyle, apilevel, threadsafety, etc...) - -2001-05-24 Michele Comitini <mcm@initd.net> - - * ZPsycopgDA: Support for Zope's internal DateTime, option - to leave mxDateTime is available on the management interface so - to switch with little effort :). - - * cursor.c: more aggressive cleanup of postgres results - to avoid the risk of memory leaking. - - * typeobj.c, connection.c: deleted some Py_INCREF which - wasted memory. - -2001-05-18 Federico Di Gregorio <fog@debian.org> - - * Release 0.5.4. - -2001-05-17 Michele Comitini <mcm@initd.net> - - * ZPsycopgDA/db.py: The connection closed by the management - interface of zope now raises error instead of reopening itself. - - * cursor.c (psyco_curs_close): does not try to free the cursor - list, as it caused a segfault on subsequent operations on the same - cursor. - -2001-05-07 Federico Di Gregorio <fog@debian.org> - - * Release 0.5.3. - - * Merged in changes from me and mcm. - -2001-05-06 Michele Comitini <mcm@initd.net> - - * ZPsycopgDA/db.py (DB.close): Fixes a bug report by Andre - Shubert, which was still open since there was a tiny typo in - method definition. - - * ZPsycopgDA/DA.py (Connection.sql_quote__): overriding standard - sql_quote__ method to provide correct quoting (thank to Philip - Mayers and Casey Duncan for this bug report). - -2001-05-04 Federico Di Gregorio <fog@debian.org> - - * ZPsycopgDA/db.py: added .close() method (as suffested by Andre - Schubert.) - -2001-05-04 Michele Comitini <mcm@initd.net> - - * module.h: working on a closed object now raises an - InterfaceError. - - * ZPsycopgDA/db.py: fixed problems with dead connections detection. - - * ZPsycopgDA/__init__.py: corrected SOFTWARE_HOME bug for zope - icon. - -2001-05-04 Federico Di Gregorio <fog@debian.org> - - * examples/thread_test.py: now that the serialization bug is - fixed, it is clear that thread_test.py is bugged! added a commit() - after the creation of the first table to avoid loosing it on the - exception raised by the CREATE of an existing table_b. - -2001-05-03 Federico Di Gregorio <fog@debian.org> - - * connection.c (psyco_conn_cursor): reverted to old locking - policy, the new caused a nasty deadlock. apparently the multiple - connection problem has been solved as a side-effect of the other - fixes... (?!) - - * module.h: removes stdkeeper field from connobject, we don't need - it anymore. - - * cursor.c (dispose_pgconn): now sets self->keeper to NULL to - avoid decrementing the keeper refcnt two times when the cursor is - first closed and then destroyed. - - * connection.c (psyco_conn_cursor): fixed little bug in cursor - creation: now the connection is locked for the entire duration of - the cursor creation, to avoid a new cursor to be created with a - new keeper due to a delay in assigning the stdmanager cursor. - - * cursor.c: added calls to pgconn_set_critical() and to - EXC_IFCRITICAL() where we expect problems. Still segfaults but at - least raise an exception... - - * cursor.c (psyco_curs_autocommit): added exception if the - cursor's keeper is shared between more than 1 cursor. - - * module.h (EXC_IFCRITICAL): added this macro that call - pgconn_resolve_critical) on critical errors. - - * cursor.c (alloc_keeper): added check for pgres == NULL. - - * cursor.c (psyco_curs_destroy): merged psyco_curs_destroy() and - psyco_curs_close(): now both call _psyco_curs_close() and destroy - does only some extra cleanup. - -2001-05-03 Michele Comitini <mcm@initd.net> - - * ZPsycopgDA/db.py: Some cleanup to bring the zope product up to - date with the python module. Some bugs found thanks to Andre - Schubert. Now the ZDA should rely on the new serialized version - of psycopg. - - * cursor.c: while looking for problems in the ZDA some come out - here, with the inability to handle dropping connection correctly. - This leads to segfaults and is not fixed yet for lack of time. - Some problems found in cursors not willing to share the same - connection even if they should. Hopefully it should be fixed - soon. - -2001-04-26 Federico Di Gregorio <fog@debian.org> - - * fixed bug reported by Andre Schubert by adding a new cast - function for long integers (int8 postgresql type.) at now they are - converted to python LongIntegers: not sure f simply convert to - floats. - - * michele applied patch from Ivo van der Wijk to make zpsycopgda - behave better when INSTANCE_HOME != SOFTWARE_HOME. - - * cursor.c (_psyco_curs_execute): also fill the 'columns' field. - - * module.h: added a 'columns' field to cursobject, to better - support the new dictionary fetch functions (dictfetchone(), - dictfetchmany(), dictfetchall().) - - * cursor.c: added the afore-mentioned functions (function names - are not definitive, they will follow decisions on the DBAPI SIG.) - -2001-04-03 Federico Di Gregorio <fog@debian.org> - - * Release 0.5.1. - - * mcm fixed a nasty bug by correcting a typo in module.h. - -2001-03-30 Federico Di Gregorio <fog@debian.org> - - * module.c (psyco_connect): added `serialized' named argument to - the .connect() method (takes 1 or 0 and initialize the connection - to the right serialization state.) - - * Makefile.pre.in (dist): fixed little bug, a missing -f argument - to rm. - - * examples/thread_test.py: removed all extension cruft. - - * examples/thread_test_x.py: this one uses extensions like the - per-cursor commit, autocommit, etc. - - * README (psycopg): added explanation on how .serialize() works. - - * connection.c (psyco_conn_serialize): added cursor serialization - and .serialize() method on the connection object. now we are - definitely DBAPI-2.0 compliant. - -2001-03-20 Federico Di Gregorio <fog@debian.org> - - * cursor.c (_psyco_curs_execute): replaced some fields in - description with None, as suggested on the DB-SIG ML. - - * something like one hundred of little changes to allow cursors - share the same postgres connection. added connkeeper object and - pthread mutexes (both in connobject and connkeeper.) apparently it - works. this one will be 0.5.0, i think. - -2001-03-19 Michele Comitini <mcm@initd.net> - - * cursor.c: added mutexes, they do not interact well with python - threads :(. - -2001-03-16 Michele Comitini <mcm@initd.net> - - * ZPsycopgDA/db.py (ZDA): some fixes in table browsing. - -2001-03-16 Federico Di Gregorio <fog@debian.org> - - * suite/tables.postgresql (TABLE_DESCRIPTIONS): fixed some typos - introduced by copying by hand the type values from pg_type.h. - - * suite/*: added some (badly) structured code to test for - DBAPI-2.0 compliance. - - * cursor.c (pgconn_notice_callback): now the NOTICE processor only - prints NOTICEs when psycopg has been compiled with the - --enable-devel switch. - - * connection.c: removed 'autocommit' attribute, now is a method as - specified in the DBAPI-2.0 document. - -2001-03-15 Federico Di Gregorio <fog@debian.org> - - * connection.c (curs_commitall): splitted for cycle in two to - avoid the "bad snapshot" problem. - -2001-03-14 Federico Di Gregorio <fog@debian.org> - - * Release 0.4.6. - - * cursor.c (_psyco_curs_execute): fixed nasty bug, there was an - free(query) left from before the execute/callproc split. - - * Preparing for 0.4.6. - -2001-03-13 Federico Di Gregorio <fog@debian.org> +2004-09-04 Federico Di Gregorio <fog@debian.org> - * cursor.c (psyco_curs_execute): fixed some memory leaks in - argument parsing (the query string was not free()ed.) - (psyco_curs_callproc): implemented callproc() method on cursors. - (_psyco_curs_execute): this is the function that does the real - stuff for callproc() and execute(). - (pgconn_notice_*): added translation of notices into python - exceptions (do we really want that?) + * psycopg/pqpath.c (_pq_fetch_tuples): ported rowcount fix from + 1.1.15. - * configure.in: removed some cruft (old comments and strncasecmp() - check) + * ZPsycopgDA/*: ZPsycopgDA back in action, using the new pooling + code. -2001-03-12 Federico Di Gregorio <fog@debian.org> +2004-08-29 Federico Di Gregorio <fog@debian.org> - * examples/thread_test.py: added moronic argument parsing: now you - can give the dsn string on the command line... :( + * psycopg/typecast_basic.c (typecast_DECIMAL_cast): added DECIMAL + typecaster; it even works :). - * Release 0.4.5. + * scripts/buildtypes.py (basic_types): added DECIMAL typecaster + for the NUMERIC oid. -2001-03-10 Federico Di Gregorio <fog@debian.org> + * examples/threads.py: updated threads example to use pooling code. - * cursor.c (request_pgconn): added code to set datestyle to ISO on - new connections (many thanks to Yury <yura@vpcit.ru> for the code, - i changed it just a little bit to raise an exception on error.) + * lib/pool.py: added very simple and thread-safe connection + pooling class. -2001-03-09 Federico Di Gregorio <fog@debian.org> + * psycopg/cursor_type.c (psyco_curs_fetchmany): fixed problem with + .fetchall() and .fetchmany() returning None instead of [] on empty + result sets. - * Release 0.4.4. + * Release 1.99.8. - * ZPsycopgDA/db.py: michele fixed a nasty bug here. +2004-08-28 Federico Di Gregorio <fog@debian.org> -2001-03-08 Federico Di Gregorio <fog@debian.org> + * psycopg/cursor_type.c (psyco_curs_execute): added processing of + unicode queries. - * Release 0.4.3. + * examples/encoding.py: much better encoding example, also using + the new UNICODE typecaster. -2001-03-07 Federico Di Gregorio <fog@debian.org> + * psycopg/typecast_basic.c (typecast_UNICODE_cast): added UNICODE + typecaster. - * Makefile.pre.in (dist): typeobj_builtins.c included for people - without pg_type.h. if you encounter type-casting problems like - results cast to the wrong type, simply "rm typeobj_builtins.c" and - rebuild. + * lib/extensions.py: the encodings dictionary is not available by + default but can be accessed from the psycopg.extensions module. - * typeobj.c (psyco_*_cast): removed RETURNIFNULL() macro from all - the builtin casting functions. (psyco_STRING_cast) does not create - a new string anymore, simply Py_INCREF its argument and return it. + * psycopg/adapter_qstring.h: remove encoding information from + qstring adapter and moved it into psycopg module. - * cursor.c (psyco_curs_fetchone): removed strdup() call. added - PQgetisnull() test to differentiate between real NULLs and empty - strings. +2004-08-26 Federico Di Gregorio <fog@debian.org> - * Removed cursor.py (mcm, put tests in examples) and fixed some - typos in the dtml code. + * psycopg/cursor_type.c (_psyco_curs_prefetch): added check for + asynchronous fetch by wrong cursor. -2001-03-04 Michele Comitini <mcm@initd.net> + * psycopg/pqpath.c (pq_fetch): fixed backend status message (bug + reported by Daniele Varrazzo.) - * examples/commit_test.py: Modifications to test argument passing - and string substitution to cursor functions, nothing more. +2004-07-29 Federico Di Gregorio <fog@debian.org> - * ZPsycopgDA/db.py: now it exploits some of the good features of - the psycopg driver, such as connection reusage and type - comparison. Code is smaller although it handles (and - reports) errors much better. + * psycopg/typecast_basic.c (typecast_BINARY_cast): reverted to + using strings instead of buffers when converting postgresql binary + objects (should *temporarily* fix corruption bug reported on + win32.) - * cursor.c: corrected a bug that left a closed cursor in the - cursor list of the connection. Now cursors are removed from the - lists either when they are close or when they are destroyed. - Better connection (TCP) error reporting and handling. +2004-07-21 Federico Di Gregorio <fog@debian.org> + * psycopg/cursor_type.c: removed __iter__ and next methods from + object methods and moved them where they do belong (tp_iter and + tp_iternext.) Bug reported by Daniele Varrazzo (again!) -2001-03-02 Federico Di Gregorio <fog@debian.org> +2004-07-19 Federico Di Gregorio <fog@debian.org> - * examples commit_test.py: added code to test autocommit. - - * examples/thread_test.py (ab_select): modified select thread to - test autocommit mode. - - * Release 0.4.1. - - * module.h, connection.c, cursor.c: added autocommit support. + * psycopg/typecast_datetime.c (typecast_PYINTERVAL_cast): replaced + round() with micro() when rounding seconds (fixes bugs reported by + Daniele Varrazzo.) -2001-02-28 Federico Di Gregorio <fog@debian.org> +2004-07-16 Federico Di Gregorio <fog@debian.org> - * Release 0.4. + * psycopg/pqpath.c (pq_set_critical): allow for a custom message + insted of the one from PQerrorMessage. + (pq_resolve_critical): added argument to specify if connection is + to be closed (used to not close it during COPY FROM/TO criticals.) -2001-02-27 Michele Comitini <mcm@initd.net> + * psycopg/cursor_type.c (psyco_curs_fileno, psyco_curs_isready): + added extension methods related to async queries. - * cursor.py: cut some unuseful code in psyco_curs_fetchmany() and - psyco_curs_fetchall() inserted an assert in case someting goes - wrong. +2004-07-15 Federico Di Gregorio <fog@debian.org> -2001-02-27 Federico Di Gregorio <fog@debian.org> + * Release 1.99.7. - * debian/*: various changes to build both the python module and - the zope db adapter in different packages (respectively - python-psycopg and zope-psycopgda.) + * examples/tz.py: added example about time zones. - * examples/type_test.py: better and more modular tests. + * psycopg/typecast_datetime.c (typecast_PYDATETIME_cast): create + FixedOffsetTimezone for postgresql "timestamp with time zone" + types. - * typeobj.c: added DATE, TIME, DATETIME, BOOLEAN, BINARY and ROWID - types. (RETURNIFNULL) added NULL-test to builtin conversion - functions (using the RETURNIFNULL macro.) + * lib/tz.py: added (even more than) needed tzinfo classes. -2001-02-26 Federico Di Gregorio <fog@debian.org> + * psycopg/typecast.c (typecast_call): changed typecast call code + to take the additional cursor parameter, needed for + cursor-dependent type casting (tzinfo & friends.) - * releasing 0.3 (added NEWS file.) + * psycopg/cursor_type.c (_psyco_curs_buildrow_with_factory): added + use of tuple factories to fetcXXX methods. -2001-02-26 Michele Comitini <mcm@initd.net> + * lib/extras.py: little extra goodies for psycopg. - * cursor.c: fetchmany() some cleanup done. +2004-07-14 Federico Di Gregorio <fog@debian.org> - * ZPsycopgDA/db.py, ZPsycopgDA/__init__.py, : fixes to make the - ZDA work some way. WARNING WARNING WARNING the zda is still - alpha code, but we need some feed back on it so please give it - a try. + * Release 1.99.6. -2001-02-26 Federico Di Gregorio <fog@debian.org> + * psycopg/connection_type.c: added .dsn attribute to connection + objects. - * typeobj.c (psyco_STRING_cast): fixed bad bad bad bug. we - returned the string without coping it and the type-system was more - than happy to Py_DECREF() it and trash the whole system. fixed at - last! + * psycopg/cursor_type.c (psyco_curs_mogrify): added .mogrify() + method. - * module.h (Dprintf): added pid to every Dprintf() call, to - facilitate multi-threaded debug. + * psycopg/adapter_qstring.c: copy the connection encoding only if + wrapped object is unicode and added table of encodings. -2001-02-26 Michele Comitini <mcm@initd.net> +2004-07-13 Federico Di Gregorio <fog@debian.org> - * module.c: added code so that DateTime package need not to be - loaded to have mxDateTime. This should avoid clashing with - DateTime from the zope distribution. + * psycopg/cursor_type.c (_mogrify): moved Dprintf statement to + avoid dereferencing empty pointer (from 1.1.x) + (psyco_curs_execute): now we save the query in self->query instead + of freeing the memory ASAP. + (cursorObject_members): and we finally export the saved query + through the cursor members interface. that's all folks. - * cursor.c: setting error message in fetchmany when no more tuples - are left. This has to be fixed in fetch and fetchall to. + * lib/extensions.py: added extensions module to clearly separate + psycopg own extensions from DBAPI-2.0 -2001-02-26 Federico Di Gregorio <fog@debian.org> +2004-07-10 Federico Di Gregorio <fog@debian.org> - * configure.in: stepped up version to 0.3, ready to release - tomorrow morning. added check for path to DateTime module. + * psycopg/typecast_datetime.c: ported interval fix from 1.1.x. - * examples/usercast_test.py: generate some random boxes and - points, select the boxes with at least one point inside and print - them converting the PostgeSQL output using a user-specified cast - object. nice. +2004-05-16 Federico Di Gregorio <fog@debian.org> -2001-02-24 Federico Di Gregorio <fog@debian.org> + * psycopg/typecast_datetime.c (typecast_*_cast): fixed Value error + when seconds > 59 by setting minutes += 1 and seconds -= 60 + (reported by Marcel Gsteiger.) - * cursor.c (psyco_curs_fetchone): now an error in the python - callback when typecasting results raise the correct exception. +2004-04-24 Federico Di Gregorio <fog@debian.org> - * typeobj.c (psyco_DBAPITypeObject_call): removed extra Py_INCREF(). + * ported time interval patch by Ross Cohen from 1.1.12. -2001-02-23 Federico Di Gregorio <fog@debian.org> +2004-04-19 Federico Di Gregorio <fog@debian.org> - * replaced every single instance of the string 'pgpy' with 'psyco' - (this was part of the general cleanup.) + * psycopg/typecast_datetime.c (typecast_PYDATE_cast): applied + patch from Jason Erickson: min and max taken from datetime.Date + type. - * type_test.py: added this little test program to the distribution - (use the new_type() method to create new instances of the type - objects.) - - * typeobj.c: general cleanup. fixed some bugs related to - refcounting (again!) - - * cursor.c: general cleanup. (request_pgconn) simplified by adding - a support function (_extract_pgconn.) - - * connection.c: general cleanup. replaced some ifs with asserts() - in utility functions when errors depend on programming errors and - not on runtime exceptions. (pgpy_conn_destroy) fixed little bug - when deleting available connections from the list. - - * module.h: general cleanup. +2004-04-18 Federico Di Gregorio <fog@debian.org> - * typeobj.h: general cleanup, better comments, made some function - declarations extern. + * Applied changes from Jason Erickson to build on win32; see his + (slightly edited) entry below. (Still builds on Linux :) - * module.c: general cleanup, double-checked every function for - memory leaks. (pgpy_connect) removed unused variable 'connection'. + * psycopg/*.c: removed inclusion of pthread.h from all files + except psycopg/config.h to build on win32 without faking the file. -2001-02-22 Federico Di Gregorio <fog@debian.org> +2004-04-15 Jason Erickson <jerickso@stickpeople.com> + + * setup.py: Various changes. The critical ones: + - Make an empty pthread.h file so all the code doing an + #include <pthread.h> will find something. + - Appended the winsock2 library and the PostgreSQL library to + the library path. + - Setup the include path. + - Have the PSYCOPG_VERSION macro be included with quotes. + + * config.h: Added/Cleaned up Win32 includes, defines, stub functions. + + * typecast.h: Removed ';' after PyObject_HEAD in the + typecastObject structure since Microsoft Visual Studio does not + like it. - * typeobj.c: fixed lots of bugs, added NUMBER type object. now the - basic tests in type_test.py work pretty well. - - * cursor.c (pgpy_curs_fetchmany): fixed little bug, fetchmany() - reported one less row than available. - - * fixed lots of bugs in typeobj.c, typeobj.h, cursor.c. apparently - now the type system works. it is time to clean up things a little - bit. - -2001-02-21 Federico Di Gregorio <fog@debian.org> - - * typeobj.c: separated type objects stuff from module.c - - * typeobj.h: separated type objects stuff from module.h +2004-04-15 Federico Di Gregorio <fog@debian.org> -2001-02-19 Federico Di Gregorio <fog@debian.org> + * Release 1.99.5 (bug-fixing and reorganization) - * cursor.c (pgpy_curs_fetchmany): now check size and adjust it to - be lesser or equal than the nuber of available rows. + * setup.py et al.: moved psycopg to psycopg._psycopg to make + easier to provide high level python-only utilities (like the + promised pooling code). psycopg/__init__.py imports _psycopg and + make all the default DBAPI-2.0 stuff available. -2001-02-18 Michele Comitini <mcm@initd.net> - - * module.c, module.h: added optional args maxconn and minconn to - connection functions +2004-04-14 Federico Di Gregorio <fog@debian.org> - * cursor.c: better error checking in request_pgconn. + * psycopg/psycopgmodule.c (initpsycopg): wrapped initialization of + date/time adapters in #ifdefs to have psycopg compile without mx + or builtin datetime. - * connection.c: changed new_connect_obj to take as optional args - maxconn and minconn. Added the corresponding ro attributes to - connection objects. +2004-04-10 Federico Di Gregorio <fog@debian.org> - * cursor.py: added some code to stress test cursor reusage. + * Release 1.99.4. - * cursor.c: some fixes on closed cursors. +2004-04-09 Federico Di Gregorio <fog@debian.org> - * connection.c: corrections on some assert calls. + * psycopg/typecast_builtins.c: changed DATE to not include + DATETIME types anymore. -2001-02-16 Federico Di Gregorio <fog@debian.org> + * psycopg/adapter_datetime.c (pydatetime_str): switched from + strftime to isoformat to preserve fractional seconds. - * configure.in: added --enable-priofile sqitch. changed VERSION to - 0.2: preparing for a new release. +2004-04-08 Federico Di Gregorio <fog@debian.org> - * cursor.c: added a couple of asserts. + * psycopg/psycopgmodule.c (psyco_connect): ported sslmode + parameter from 1.1 branch. -2001-02-16 Michele Comitini <mcm@initd.net> + * psycopg/adapter_datetime.*: added python built-in datetime + adapters. also added the datetime typecasters (still using mx as + default). - * cursor.c, connection.c: fixed the assert problem: assert must - take just the value to be tested! no assignemente must be done in - the argument of assert() otherwise is wiped when NDEBUG is set. + * psycopg/typecast.h: removed aliases, they now live in the right + typecast_xxx.c file. - * module.h: some syntax error fixed. Error in allocating a tuple - corrected in macro DBAPITypeObject_NEW(). - - * module.c: pgpy_DBAPITypeObject_init() is not declared static anymore. +2004-03-08 Federico Di Gregorio <fog@debian.org> - * cursor.c: executemany() now does not create and destroy tuples - for each list item, so it is much faster. + * Release 1.99.3 (alpha 4). -2001-02-14 Michele Comitini <mcm@initd.net> - - * cursor.c: added again Py_DECREF on the cpcon after disposing - it. assert() with -DNDEBUG makes the driver segfault while it - should not. - + * examples/lastrowid.py: and the .lastrowid example is in. -2001-02-13 Federico Di Gregorio <fog@debian.org> + * psycopg/cursor_type.c (_mogrify): added call to .prepare() + method in both dict and sequence path. - * some of the memory leak were memprof errors, bleah. resumed some - old code, fixed segfault, fixed other bugs, improved speed. almost - ready for a new release. - - * connection.c (pgpy_conn_destroy): replaced some impossible ifs - with aseert()s. + * psycopg/connection_int.c (conn_set_client_encoding): added + encoding-change code. - * cursor.c (pgpy_curs_close): added Py_DECREF() to - self->descritpion to prevent a memory leak after an execute(). + * psycopg/adapter_qstring.c (qstring_quote): added hard-coded + support for utf8 and latin1 encodings. - * connection.c (pgpy_conn_destroy): always access first element of - lists inside for cycles because removing items from the list makes - higher indices invalid. +2004-03-01 Federico Di Gregorio <fog@debian.org> - * cursor.c (dispose_pgconn): fixed memory leak, there was a - missing Py_DECREF() after the addition of the C object wrapping - the postgresql connection to the list of available connections. + * psycopg/connection_int.c (conn_close): does not use libpq + functions on NULL pgconn (this can happen when conn_close is + called after a failed PQconnect.) - * cursor.c (dispose_pgconn): fixed another memory leak: an - orphaned cursor should call PQfinish() on its postgresql - connection because it has no python connection to give the - postgresql ine back. +2004-02-29 Federico Di Gregorio <fog@debian.org> - * cursor.c (pgpy_curs_execute): added Py_DECREF() of description - tuple after adding it to self->description. this one fixes the - execute() memory leak. + * Release 1.99.2 (alpha 3). - * cursor.c (pgpy_curs_fetchall): added missing Py_DECREF() on row - data (obtained from fetchone().) this fixes the last memory leak. - (thread_test.py now runs without leaking memory!) - -2001-02-12 Federico Di Gregorio <fog@debian.org> - - * INSTALL: removed wok cruft from head of this file. - - * debian/rules: debianized the sources. python-psycopg is about to - enter debian. mxDateTime header locally included until the - maintainer of python-mxdatetime includes them in his package - (where they do belong.) - - * autogen.sh: added option --dont-run-configure. + * psycopg/cursor_type.c: added .rownumber and .connection + attributes. Also added .scroll(), .next() and .__iter__() methods + (see DBAPI2-.0 extensions on PEP.) -2001-02-09 Federico Di Gregorio <fog@debian.org> - - * module.c (initpsycopg): changed name of init function to match - new module name (also changed all the exception definitions.) - - * README: updated psycopg description (we have a new name!) - - * Ready for 0.1 release. - -2001-02-07 Michele Comitini <mcm@initd.net> - - * cursor.c: now executemany takes sequences and not just - tuples - -2001-02-07 Federico Di Gregorio <fog@debian.org> - - * Makefile.pre.in: now dist target includes test programs - (thread_test.py) and README and INSTALL files. - - * configure.in: changed --with-devel to --enable-devel. little - cosmetical fixes to the option management. - - * connection.c, module.c, cursor.c, module.h: removed 'postgres/' - from #include directive. it is ./configure task to find the right - directory. + * psycopg/connection_type.c (psyco_conn_set_isolation_level): + added connection method .set_isolation_level(). Also added all + error objects to the connection (see DBAPI2-.0 extensions on PEP.) - * thread_test.py: added thread testing program. + * psycopg/connection_int.c (conn_switch_isolation_level): added + isolation level switching code. -2001-02-07 Michele Comitini <mcm@initd.net> + * setup.py: removed all references to PSYCOPG_NEWSTYLE: support + for python < 2.2 has been dropped. - * cursor.c: added code to allow threads during PQexec() calls. - - * cursor.c: added begin_pgconn to rollback() and commit() - so that the cursror is not in autocommit mode. + * typecast_basic.c (typecast_BINARY_cast): now binary objects are + returned as true buffers. - * cursor.c: added rollback() and commit() methods to cursor + * adapter_binary.*: added adapter for buffers and binary (bytea) objects. + * Release 1.99.1 (alpha 2). -2001-02-07 Federico Di Gregorio <fog@debian.org> - - * connection.c (pgpy_conn_destroy): always delete item at index - 0 and not i (because items shift in the list while deleting and - accessing items at len(list)/2 segfaults.) - -2001-02-07 Michele Comitini <mcm@initd.net> - - * connection.c: added some more checking to avoid - clearing of already cleared pgresults. Calling curs_closall() - in conn_destroy() since cursors have to live even without - their parent connection, otherwise explicit deletion of - object referencing to those cursors can cause arbitrary code - to be executed. - - * cursor.c: some more checking to avoid trying to close - already close pgconnections. - -2001-02-06 Federico Di Gregorio <fog@debian.org> - - * Makefile.pre.in (CFLAGS): added -Wall to catch bad programming - habits. - - * cursor.c, connection.c: lots of fixes to the destroy stuff. now - all the cursor are destroyed *before* the connection goes away. - - * cursor.c (request_pgconn): another idiot error done by not - replacing dsn with owner_conn->dsn. fixed. - (dispose_pgconn): commented if to guarantee that the connection is - returned to the pool of available connections. - - * merged changes done by mcm. - - * cursor.c: general cleanup and better debugging/error - messages. changed xxx_conn into xxx_pgconn where still - missing. some pretty big changes to the way pgconn_request() - allocates new connections. - - * connection.c: removed all 'register' integers. obsolete, gcc - does a much better job optimizing cycles than a programmer - specifying how to use registers. - - * module.h: some general cleanup and better definition of DPrintf - macro. now the DEBUG variable can be specified at configure time by - the --with-devel switch to ./configure. - -2001-02-02 Michele Comitini <mcm@initd.net> - - * cursor.c (Repository): Added functions for managing a connection - pool. Segfaults. - - * configure.in (Repository): removed check for mxdatetime headers. - -2001-01-24 Federico Di Gregorio <fog@debian.org> - - * first checkout from shinning new init.d cvs. - - * autotoolized build system. note that the mx headers are missing - from the cvs, you should get them someplace else (this is the - right way to do it, just require the headers in the configure - script.) - -2001-01-21 Michele Comitini <mcm@initd.net> + * adapter_mxdatetime.*: added adapters for all mx.DateTime types. - * cursor.c (Repository): commit, abort, begin functions now check - the right exit status of the command. +2004-02-28 Federico Di Gregorio <fog@debian.org> - * connection.c (Repository): working commit() and rollback() - methods. + * cursor_type.c (_mogrify): complete rework of the mogrification + code to use the microprotocols_adapt function. -2001-01-20 Michele Comitini <mcm@initd.net> + * typecast_basic.c (typecast_BOOLEAN_cast): we now return real + Py_True and Py_False values. - * module.h (Repository): added member to cursor struct to handle - queries without output tuples. + * microprotocols.h: added very simple microprotocols + implementation to allow for python->postgresql types registry. - * cursor.c (Repository): new working methods: executemany, - fetchone, fetchmany, fetchall. +2004-01-05 Federico Di Gregorio <fog@debian.org> -2001-01-18 Michele Comitini <mcm@initd.net> + * connection_int.c (conn_commit/conn_rollback): added code to + commit/rollback and connection methods. - * cursor.c (Repository): close working. destroy calling close. - close frees pg structures correctly. +2004-01-04 Federico Di Gregorio <fog@debian.org> - * connection.c (Repository): close method working. destroy seems - working. + * cursor_type.c (psyco_curs_fetchone): added fetchone method. -2001-01-17 Michele Comitini <mcm@initd.net> +2004-01-03 Federico Di Gregorio <fog@debian.org> - * cursor.c (Repository): now each python cursor has its own - connection. Each cursor works in a transaction block. + * added (empty) INSTALL file. - * connection.c (Repository): added cursor list to connection - object + * cursor_type.c (cursor_dealloc): added qattr for custom object + quoting using a callable attribute. + (_mogrify): ported new, fixed mogrification code from 1.1.12. -2001-01-14 Michele Comitini <mcm@initd.net> - - * cursor.c (Repository): Beginning of code to implement cursor - functionalities as specified in DBA API 2.0, through the use of - transactions not cursors. - - * connection.c (Repository): Added some error checking code for pg - connection (will be moved to cursor?). - -2001-01-13 Michele Comitini <mcm@initd.net> - - * connection.c (Repository): Added error checking in connection - code to fail if connection to the db could not be opened. - - * module.h (Repository): New macro to help creating - DBAPITypeObjects. - - * module.c (Repository): DBAPITypeObject __cmp__ function is now - very simplified using recursion. - - * module.h (Repository): "DBAPIObject" changed to - "DBAPITypeObject". - - * module.c (Repository): Fixes for coerce function of DBAPIObjects - by Federico Di Gregorio <fog@initd.net>. - (Repository): Clean up and better naming for DBAPITypeObjects. - -2001-01-08 Michele Comitini <mcm@initd.net> - - * module.c (Repository): Corrected the exception hierarcy - - * connection.c (Repository): Begun to use the connection objects - of libpq - -2001-01-07 Michele Comitini <mcm@initd.net> - - * module.c (Repository): Added the Date/Time functions. +2003-08-01 Federico Di Gregorio <fog@debian.org> -2001-01-06 Michele Comitini <mcm@initd.net> + * cursor_type.c (_mogrify_sequence): added sequence mogrification, + can be done better, on the dict model. - * cursor.c (Repository): Skeleton of cursor interface. All - methods and attributes of cursor objects are now available - in python. They do nothing now. +2003-07-28 Federico Di Gregorio <fog@debian.org> -2001-01-05 Michele Comitini <mcm@initd.net> + * typeobj_qstring.c: added quoted strings (can use both own code, + like psycopg 1.x or PQescapeString from lipq.) - * module.c (Repository): Test version; module loaded with - exception defined. - -2001-01-05 Michele Comitini <mcm@initd.net> +2003-07-21 Federico Di Gregorio <fog@debian.org> - * Setup.in (Repository): Setup file. + * connection_type.c (psyco_conn_close): added .close() + method. wow. - * Makefile.pre.in (Repository): from the python source. + * cursor_*.c: added basic cursor interface (new-style.) -2001-01-05 Michele Comitini <mcm@initd.net> +2003-07-20 Federico Di Gregorio <fog@debian.org> - * module.c: Written some code for defining exceptions. - - * module.h: Static variable for exceptions. - -2001-01-04 Michele Comitini <mcm@initd.net> + * psycopg/*: beginning of new source layout. if you think this + changelog is somewhat empty, you're right. look at + doc/ChangeLog-1.x for psycopg 1.x changelog just before the + branch. - * Changelog: pre-release just a few prototypes to get started. - @@ -1,184 +1,18 @@ -Basic Installation -================== +Compiling and installing psycopg +******************************** - These are generic installation instructions. Before building and -installing make sure you read carefully the "Install" section in the -README file. +While psycopg 1.x used autoconf for its build process psycopg 2 switched to +the more pythoning setup.py. Currently both psycopg's author and distutils +have some limitations so the file setup.cfg is almost unused and most build +options are hidden in setup.py. Before building psycopg look at the very +first lines of setup.py and change any settings to follow your system (or +taste); then: - The `configure' shell script attempts to guess correct values for -various system-dependent variables used during compilation. It uses -those values to create a `Makefile' in each directory of the package. -It may also create one or more `.h' files containing system-dependent -definitions. Finally, it creates a shell script `config.status' that -you can run in the future to recreate the current configuration, a file -`config.cache' that saves the results of its tests to speed up -reconfiguring, and a file `config.log' containing compiler output -(useful mainly for debugging `configure'). + python setup.py build - If you need to do unusual things to compile the package, please try -to figure out how `configure' could check whether to do them, and mail -diffs or instructions to the address given in the `README' so they can -be considered for the next release. If at some point `config.cache' -contains results you don't want to keep, you may remove or edit it. +to build in the local directory; and: - The file `configure.in' is used to create `configure' by a program -called `autoconf'. You only need `configure.in' if you want to change -it or regenerate `configure' using a newer version of `autoconf'. + python setup.py install + +to install system-wide. -The simplest way to compile this package is: - - 1. `cd' to the directory containing the package's source code and type - `./configure' to configure the package for your system. If you're - using `csh' on an old version of System V, you might need to type - `sh ./configure' instead to prevent `csh' from trying to execute - `configure' itself. - - Running `configure' takes awhile. While running, it prints some - messages telling which features it is checking for. - - 2. Type `make' to compile the package. - - 3. Optionally, type `make check' to run any self-tests that come with - the package. - - 4. Type `make install' to install the programs and any data files and - documentation. - - 5. You can remove the program binaries and object files from the - source code directory by typing `make clean'. To also remove the - files that `configure' created (so you can compile the package for - a different kind of computer), type `make distclean'. There is - also a `make maintainer-clean' target, but that is intended mainly - for the package's developers. If you use it, you may have to get - all sorts of other programs in order to regenerate files that came - with the distribution. - -Compilers and Options -===================== - - Some systems require unusual options for compilation or linking that -the `configure' script does not know about. You can give `configure' -initial values for variables by setting them in the environment. Using -a Bourne-compatible shell, you can do that on the command line like -this: - CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure - -Or on systems that have the `env' program, you can do it like this: - env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure - -Compiling For Multiple Architectures -==================================== - - You can compile the package for more than one kind of computer at the -same time, by placing the object files for each architecture in their -own directory. To do this, you must use a version of `make' that -supports the `VPATH' variable, such as GNU `make'. `cd' to the -directory where you want the object files and executables to go and run -the `configure' script. `configure' automatically checks for the -source code in the directory that `configure' is in and in `..'. - - If you have to use a `make' that does not supports the `VPATH' -variable, you have to compile the package for one architecture at a time -in the source code directory. After you have installed the package for -one architecture, use `make distclean' before reconfiguring for another -architecture. - -Installation Names -================== - - By default, `make install' will install the package's files in -`/usr/local/bin', `/usr/local/man', etc. You can specify an -installation prefix other than `/usr/local' by giving `configure' the -option `--prefix=PATH'. - - You can specify separate installation prefixes for -architecture-specific files and architecture-independent files. If you -give `configure' the option `--exec-prefix=PATH', the package will use -PATH as the prefix for installing programs and libraries. -Documentation and other data files will still use the regular prefix. - - In addition, if you use an unusual directory layout you can give -options like `--bindir=PATH' to specify different values for particular -kinds of files. Run `configure --help' for a list of the directories -you can set and what kinds of files go in them. - - If the package supports it, you can cause programs to be installed -with an extra prefix or suffix on their names by giving `configure' the -option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. - -Optional Features -================= - - Some packages pay attention to `--enable-FEATURE' options to -`configure', where FEATURE indicates an optional part of the package. -They may also pay attention to `--with-PACKAGE' options, where PACKAGE -is something like `gnu-as' or `x' (for the X Window System). The -`README' should mention any `--enable-' and `--with-' options that the -package recognizes. - - For packages that use the X Window System, `configure' can usually -find the X include and library files automatically, but if it doesn't, -you can use the `configure' options `--x-includes=DIR' and -`--x-libraries=DIR' to specify their locations. - -Specifying the System Type -========================== - - There may be some features `configure' can not figure out -automatically, but needs to determine by the type of host the package -will run on. Usually `configure' can figure that out, but if it prints -a message saying it can not guess the host type, give it the -`--host=TYPE' option. TYPE can either be a short name for the system -type, such as `sun4', or a canonical name with three fields: - CPU-COMPANY-SYSTEM - -See the file `config.sub' for the possible values of each field. If -`config.sub' isn't included in this package, then this package doesn't -need to know the host type. - - If you are building compiler tools for cross-compiling, you can also -use the `--target=TYPE' option to select the type of system they will -produce code for and the `--build=TYPE' option to select the type of -system on which you are compiling the package. - -Sharing Defaults -================ - - If you want to set default values for `configure' scripts to share, -you can create a site shell script called `config.site' that gives -default values for variables like `CC', `cache_file', and `prefix'. -`configure' looks for `PREFIX/share/config.site' if it exists, then -`PREFIX/etc/config.site' if it exists. Or, you can set the -`CONFIG_SITE' environment variable to the location of the site script. -A warning: not all `configure' scripts look for a site script. - -Operation Controls -================== - - `configure' recognizes the following options to control how it -operates. - -`--cache-file=FILE' - Use and save the results of the tests in FILE instead of - `./config.cache'. Set FILE to `/dev/null' to disable caching, for - debugging `configure'. - -`--help' - Print a summary of the options to `configure', and exit. - -`--quiet' -`--silent' -`-q' - Do not print messages saying which checks are being made. To - suppress all normal output, redirect it to `/dev/null' (any error - messages will still be shown). - -`--srcdir=DIR' - Look for the package's source code in directory DIR. Usually - `configure' can determine that directory automatically. - -`--version' - Print the version of Autoconf used to generate the `configure' - script, and exit. - -`configure' also accepts some other, not widely useful, options. @@ -1,355 +1,155 @@ -psycopg news for 1.1.15 ------------------------ +What's new in psycopg 1.99.10 +----------------------------- -* Interval typecasting eventually-eventually works the Right Way (TM). +* The adapt() function now fully supports the adaptation protocol + described in PEP 246. Note that the adapters registry now is indexed + by (type, protocol) and not by type alone. Change your adapters + accordingly. -* Fixed two bad memory leaks in QuotedString and Binary objects. +* More configuration options moved from setup.py to setup.cfg. -* Reverted change on rowcount attribute, now it is always set to the real - number of affected columns. +* Fixed two memory leaks: one in cursor deallocation and one in row + fetching (.fetchXXX() methods.) -psycopg news for 1.1.14 ------------------------ +What's new in psycopg 1.99.9 +---------------------------- -* Interval typecasting eventually works the Right Way (TM). +* Added simple pooling code (psycopg.pool module); see the reworked + examples/threads.py for example code. -* ZPsycopgDA now support unicode strings and different backend encodings. +* Added DECIMAL typecaster to convert postgresql DECIMAL and NUMERIC + types (i.e, all types with an OID of NUMERICOID.) Note that the + DECIMAL typecaster does not set scale and precision on the created + objects but uses Python defaults. -* ZPsycopgDA accept query data as an extra parameter to execute() (but - still no way to give it extra data from inside a ZSQL Method.) +* ZPsycopgDA back in and working using the new pooling code. -* Better DBAPI-2.0 compliance (rowcount attribute and argument passing.) +* Isn't that enough? :) -* Now builds on Fedora Core 2 (but remember that the real psycopg - aficionado runs on Debian ;-P ) +What's new in psycopg 1.99.8 +---------------------------- -* COPY FROM raise an exception and return usefull information on error. +* added support for UNICODE queries. -psycopg news for 1.1.13 ------------------------ - -* ZPsycopgDA works again. - -psycopg news for 1.1.12 ------------------------ - -* Fixed nasty segfault/deadlock in switch_isolation_level. - -* Now the PostgreSQL TIME type is correctly converted to a DateTimeDelta - instead of a DateTime. This is much better because you can now add two - times and a time and a date. - -* Added an "sslmode" parameter (look at PostgreSQL documentation for - possible values.) - -* .execute() now rise the right exception if called with a wrong - tuple/dict. Also, %% in queries does not raise an exception anymore. - -* Updated RPM specs (thanks to Mark McClain we now have updated RPMs on - initd.org too.) - -psycopg news for 1.1.11 ------------------------ - -* a modern autoconf is now needed to build psycopg. - -* now an error during commit or rollback is correctly reported by raising - an exception. - -* when the libpq protocol 3.0 is available, psycopg uses a smater method - to determine exception type (unfortunately the old string compare method - is still neede for postgresql <= 7.3.x.) - -* plugged a memory leak in copy_from(). - -* where did the news for 1.1.10 go? - -psycopg news for 1.1.9 ----------------------- - -* psycopg distribution now includes the GeoTypes package by Richard Taylor - (QinetiQ Plc)! - -* Problems with sequences and mappings non correctly used in .execute() - should be gone (mogrification code completely rewritten.) Many thanks - to Richard Taylor and Vsevolod Lobko that helped by testing the "pre" - releases. - -* no more libpq 7.1.x linking problems related to PQfreeNotify. - -psycopg news for 1.1.7 ----------------------- - -* added notifies and fileno methods to cursor objects. - -* now execute accept any object that defined __getitem__ and not only - dictionaries. - -* little fix in ZPsycopgDA, should work with Zope 2.7. - -psycopg news for 1.1.6 ----------------------- - -* cursor objects now have the .scroll() method. - -* NUL characters in strings are discarded in quoting; use a Binary object if - you need strings with embedded NULs. - -* Fixed another MT problem in .execute(). - -psycopg news for 1.1.5 ----------------------- - -* ZPsycopgDA now rollback before raising an exception; should be a backward - compatible change for people that really want to continue executing queries - after an exception. - -* fixed problem with dictionary mogrification (i.e., specifying the same key - multiple times and having the None value in the dict should work now.) - -* fixed keeper status trashing problem: no more psycopg stuck in transaction - (maybe this will also solve ZPsycopgDA problems: will see...) - -* now copy_from and copy_to can be passed instances of classes with "readline" - and "write" methods and not only file instances. - -psycopg news for 1.1.4 ----------------------- - -* Fixed various memory leak problems. - -* Implemented "statusmessage" attribute on cursors. - -psycopg news for 1.1.3 ----------------------- - -* Fixed problem with psycopg always reporting IntegrityError. - -* Fixed segfault in debug statements. - -* Now Python GIL is unlocked during PQconnectdb() calls (better - multithreading.) - -psycopg news for 1.1.2 ----------------------- - -* Skipped version 1.1.1 (never released 'cause of a cvs tag error) - -* Much better cursor.description fields (many thanks to William K. Volkman) - -* psycopg.connect() now takes keyword parameters for host, dbname, port, - user and password (they are all strings, even "port".) - -* connection.set_isolation_level() implemented to help switching from default - isolation to other levels supported by PostgreSQL. [autocommit now simply - does a set_isolation_level(0)] - -* Implemented .lastrowid attribute for cursors. - -* Now psycopg should build on win32/cygwin, thank to Hajime Nakagami patches. - -* Includes every fix from 1.0.x up to 1.0.15.1: - - - Fixed connection-stay-open-when-i-do-conn.close() bug. - - Better DBAPI-2.0 compliance for setinputsizes and setoutputsize methods. - - Better support for build on MacOS X. - - Fixed problem with formats in string mogrification. - - Fixed other miscellaneous buglets in Zope Adapter. - - Fixed small memory leak in .fetchXXX() methods. - - Fixed serialization problem in ZPsycopgDA reported by Dieter Maurer. - -psycopg news for 1.1 --------------------- - -* COPY TO/COPY FROM implemented by Tom Jenkins - -* Merged changes from 1.0.13. - -psycopg news for 1.0.12 ------------------------ - -* Maintenance release fixing some little buglets: - - Fixed memory leak in .execute(). - - Better configure under MacOS X. - - DA-browser now works even with tables with mixed-case names. - - timestamps time is now set to correct value instead of 0. - -psycopg news for 1.0.11.1 -------------------------- - -* Fixed orrible bug in ZPsycopgDA not acception psycopg 1.0.11 as a valid - version. - -psycopg news for 1.0.11 ------------------------ - -* last problems from "None passed to typecasters" (introduced in 1.0.9) in - ZPsycopgDA solved (hopefully.) - -* psycopg now reports meaningfull exception types for some errors (like - IntegrityError for duplicate insertions in unique indices, etc.) - -psycopg news for 1.0.10 ------------------------ - -* fixed an exception problem introduced in 1.0.9 (patch by Matt - Hoskins.) - -* ZPsycopgDA now checks psycopg version and raise an exception if it - does not match. - -psycopg news for 1.0.9 ----------------------- - -* fixed problem with connection left in invalid state by applying - Tom Jenkins patch. - -* None values passed to the typecasters, it is now possible to - translate None into "" to achieve pygrsql compatibilty. - -* applied 'seconds as a float' patch from Jelle. - -psycopg news for 1.0.8 ----------------------- - -* fixed a segfault introduced in 1.0.7 and another little bug when - dealing with empty strings in QuotedString objects. - -* Added win32 compatibility (many many thanks to Jason Erickson). - -psycopg news for 1.0.7 ----------------------- - -* Fixed little bugs in type management (infinity problems and the - TIMESTAMPTZ type) and Zope import. Better configure script. - -* Now psycopg really close the physical connection to PostgreSQL on - connection .close(). - -psycopg news for 1.0.5 ----------------------- - -* Applied a little patch to make table browser in zope show system tables - correctly. +* added UNICODE typecaster; to activate it just do: + + psycopg.extensions.register_type(psycopg.extensions.UNICODE) + + Note that the UNICODE typecaster override the STRING one, so it is + not activated by default. -* Infinity values are now converted the correct way. +* cursors now really support the iterator protocol. -psycopg news for 1.0.4 ----------------------- +* solved the rounding errors in time conversions. -* ZPsycopgDA does not duplicate itself anymore. +* now cursors support .fileno() and .isready() methods, to be used in + select() calls. -* Table browsing works again. +* .copy_from() and .copy_in() methods are back in (still using the old + protocol, will be updated to use new one in next releasae.) -psycopg news for 1.0.3 ----------------------- +* fixed memory corruption bug reported on win32 platform. -* bugfix for b0rken ZPsycopgDA in 1.0.2. +What's new in psycopg 1.99.7 +---------------------------- -psycopg news for 1.0.2 ----------------------- +* added support for tuple factories in cursor objects (removed factory + argument in favor of a .tuple_factory attribute on the cursor object); + see the new module psycopg.extras for a cursor (DictCursor) that + return rows as objects that support indexing both by position and + column name. -* Fixed problem with incorrect interpretation of hundredths of a second. +* added support for tzinfo objects in datetime.timestamp objects: the + PostgreSQL type "timestamp with time zone" is converted to + datetime.timestamp with a FixedOffsetTimezone initialized as necessary. -psycopg news for 1.0.1 ----------------------- +What's new in psycopg 1.99.6 +---------------------------- -* fixed two little memory leaks, see ChangeLog for details. +* sslmode parameter from 1.1.x -* fixed problem with garbled passwords when using crypt autentication. +* various datetime conversion improvements. -psycopg news for 1.0 --------------------- +* now psycopg should compile without mx or without native datetime + (not both, obviously.) -* added regression tests, first result is much better conversion of date and - time types. - -* fixed last know segfault (psycopg runs stable for a lot of people now.) +* included various win32/MSVC fixes (pthread.h changes, winsock2 + library, include path in setup.py, etc.) -* psycopg compile and run on FreeBSD and MacOS X. +* ported interval fixes from 1.1.14/1.1.15. -* much better binary objects, they use less memory and quoting is faster, - thank to the new, smarter memory allocator. - -* fixed all reported buglets (mostly dbapi and type-system related.) +* the last query executed by a cursor is now available in the + .query attribute. -* hey, this is one-dot-oh! +* conversion of unicode strings to backend encoding now uses a table + (that still need to be filled.) -* the following features are missing from psycopg 1.0 and will be added when - we have a little more time (i.e., there will be no _feature_ releases after - 1.0, only bugfixes): +* cursors now have a .mogrify() method that return the query string + instead of executing it. - - documentation is incomplete (we are slowly writing it, track CVS if you - want up-to-date docs) +* connection objects now have a .dsn read-only attribute that holds the + connection string. - - dbapi-2.0 testsuite is incomplete (need to move code to the unittest - framework) +* moved psycopg C module to _psycopg and made psycopg a python module: + this allows for a neat separation of DBAPI-2.0 functionality and psycopg + extensions; the psycopg namespace will be also used to provide + python-only extensions (like the pooling code, some ZPsycopgDA support + functions and the like.) - - psycopg needs a full suite of regression tests to be sure we don't break - things while implementing new features (i think we'll add them _while_ - writing new features :) +What's new in psycopg 1.99.3 +---------------------------- -psycopg news for 0.99.7 ------------------------ +* added support for python 2.3 datetime types (both ways) and made datetime + the default set of typecasters when available. -* time intervals are correctly recognized and converted into DateTimeInterval - objects. +* added example: dt.py. -* almost complete (bugs apart) DBAPI-2.0 support. switched psycopg to use - QuotedString for every string passed as a bound argument. Binary now works - (but still consumes lots of memory). +What's new in psycopg 1.99.3 +---------------------------- -* added doc/ to hold documentation. +* initial working support for unicode bound variables: UTF-8 and latin-1 + backend encodings are natively supported (and the encoding.py example even + works!) -* added lastoid() method to cursor objects, to retrieve the OID of the last - inserted row. +* added .set_client_encoding() method on the connection object. -psycopg news for 0.99.4 ------------------------ +* added examples: encoding.py, binary.py, lastrowid.py. -* psycopg is approaching 1.0, so only DBAPI compliance patches and bug fixes - are getting in. +What's new in psycopg 1.99.2 +---------------------------- -* added Binary and QuotedString objects. note that sometime before 1.0 we'll - switch turn every string passed to psycopg into a QuotedString, possibily - breaking Zope compatibility and old scripts doing their own quoting. +* better typecasting: + - DateTimeDelta used for postgresql TIME (merge from 1.1) + - BYTEA now is converted to a real buffer object, not to a string -psycopg news for 0.5.x ----------------------- +* buffer objects are now adapted into Binary objects automatically. -* this is the development branch, if you want stability, stick with 0.4.6. +* ported scroll method from 1.1 (DBAPI-2.0 extension for cursors) -* added pthread locks so that different threads (cursors) can use the same - postgres connection (this was done *only* to respect the dbapi on cursor - isolation.) +* initial support for some DBAPI-2.0 extensions: + - .rownumber attribute for cursors + - .connection attribute for cursors + - .next() and .__iter__() methods to have cursors support the iterator + protocol + - all exception objects are exported to the connection object -* now the default for the .cursor() method is to associate every cursor to - the same physical connection, to avoid isolation (as the DBAPI-2.0 specify), - you can change that by calling the .serialize() method on the connection and - giving it 0 as the argument, e.g., "o.serialize(0)". +What's new in psycopg 1.99.1 +---------------------------- -psycopg news for 0.4.1 ----------------------- +* implemented microprotocols to adapt arbitrary types to the interface used by + psycopg to bind variables in execute; -* autocommit mode is now supported on cursors and connections. +* moved qstring, pboolean and mxdatetime to the new adapter layout (binary is + still missing; python 2.3 datetime needs to be written). -psycopg news for 0.4 --------------------- -* implemented all the remaining DBAPI-2.0 type singletons (DATETIME and - BINARY included) +What's new in psycopg 1.99.0 +---------------------------- -psycopg news for 0.3 --------------------- +* reorganized the whole source tree; -* threading problems resolved +* async core is in place; -* added type casting from postgres to python (the user can now specify - its own casting objects, the default singletons NUMBER and STRING are - included [and act as default cast objects] plus INTEGER and FLOAT as - an extension to the DBAPI-2.0.) - investigate the code in examples/usercast_test.py to understand how to - add your own types... +* splitted QuotedString objects from mx stuff; -* beginning of the Zope Database Adapter: give it a try even it it is - broken! +* dropped autotools and moved to pythonic setup.py (needs work.) @@ -1,145 +1,26 @@ psycopg - Python-PostgreSQL Database Adapter ******************************************** -psycopg is a PostgreSQL database adapter for the Python programming language -(just like pygresql and popy.) It was written from scratch with the aim of -being very small and fast, and stable as a rock. The main advantages of -psycopg are that it supports (well... *will* support) the full Python -DBAPI-2.0 and being thread safe at level 2. +psycopg is a PostgreSQL database adapter for the Python programming +language. This is version 2, a complete rewrite of the original code to +provide new-style classes for connection and cursor objects and other sweet +candies. Like the original, psycopg 2 was written with the aim of being +very small and fast, and stable as a rock. -psycopg is different from the other database adapter because it was designed -for heavily multi-threaded applications that create and destroy lots of -cursors and make a conspicuous number of concurrent INSERTs or UPDATEs. -Every open Python connection keeps a pool of real (UNIX or TCP/IP) connections -to the database. Every time a new cursor is created, a new connection does not -need to be opened; instead one of the unused connections from the pool is -used. That makes psycopg very fast in typical client-server applications that -create a servicing thread every time a client request arrives. +psycopg is different from the other database adapter because it was +designed for heavily multi-threaded applications that create and destroy +lots of cursors and make a conspicuous number of concurrent INSERTs or +UPDATEs. psycopg 2 also provide full asycronous operations for the really +brave programmer. -psycopg now support the Python DBAPI-2.0 completely. There are confirmed -reports of psycopg compiling and running on Linux and FreeBSD on i386, Solaris -and MacOS X. +There are confirmed reports of psycopg 1.x compiling and running on Linux +and FreeBSD on i386, Solaris, MacOS X and win32 architectures. psycopg 2 +does not introduce build-wise incompatible changes so it should be able to +compile on all architectures just as its predecessor did. +Now go read the INSTALL file. More information about psycopg extensions to +the DBAPI-2.0 is available in the files located in the doc/ direcory. -Extensions to the Python DBAPI-2.0 ----------------------------------- - -psycopg offers some little extensions on the Python DBAPI-2.0. Note that the -extension do not make psycopg incompatible and you can still use it without -ever knowing the extensions are here. - -The DBAPI-2.0 mandates that cursors derived from the same connection are not -isolated, i.e., changes done to the database by one of them should be -immediately visible by all the others. This is done by serializing the queries -on the same physical connection to the database (PGconn struct in C.) -Serializing queries when the network latencies are hight (and network speed is -low) dramatically lowers performance, so it is possible to put a connection -into not-serialized mode, by calling the .serialize() method giving it a -0-value argument or by creating a connection using the following code: - - conn = psycopg.connect("dbname=...", serialize=0) - -After that every cursor will get its own physical connection to the database -and multiple threads will go at full speed. Note that this feature makes the -new cursors non-compliant respect to the DBAPI-2.0. - -The main extension is that we support (on not-serialized cursors) per-cursor -commits. If you do a commit() on the connection all the changes on all the -cursors derived from that connection are committed to the database (in random -order, so take your care.) But you can also call commit() on a single cursor -to commit just the operations done on that cursor. Pretty nice. - -Note that you *do have* to call .commit() on the cursors or on the connection -if you want to change your database. Note also that you *do have* to call -commit() on a cursor even before a SELECT if you want to see the changes -apported by other threads to the database. - -Also note that you *can't* (I repeat: *you* *can't*) call .commit() on cursor -derived from a serialized connection: trying that will give you an exception -with the message: "serialized connection: cannot commit on this cursor". If -you want to use the per-cursor commit feature you need to create a -non-serialized connection, as explained above. - -From version 0.4.1 psycopg supports autocommit mode. You can set the default -mode for new cursor by setting the 'autocommit' variable to 0 or 1 on the -connection before creating a new cursor with the cursor() method. On an -already created cursor you can change the commit mode by calling the -autocommit() method. Giving no arguments or 1 switches autocommit on, 0 -switches it off. - -Obviously everything said about commit is valid for rollbacks too. - - -The type system ---------------- - -The DBAPI-2.0 specify that should be possible to check for the column type -reported in the second field of the description tuple of the cursor used for a -SELECT using 'singletons' like NUMBER, STRING, etc. While this is fully -supported by psycopg from release 0.3 on, we went forward and implemented -support for custom typecasting from PostgreSQL to Python types using -user-defined functions. See the examples test/check_types.py and -doc/examples/usercast.py for more information. In particular usercast_test.py -shows how to implement a callback that translates the PostgreSQL box type to -an ad-hoc Python class with instances created automagically on SELECT. - - -Compile-time configuration options ----------------------------------- - -To build psycopg you will need a C compiler (gcc), the Python development -files (headers and libraries), the PostgreSQL header and libraries and the -mxDateTime header files (and the mxDateTime Python package installed, version ->= 2.0.0, of curse.) - -The following options are specific to psycopg and can be set when running -configure before issuing 'make' to compile the package. - - --with-postgres-libraries=DIR - PostgreSQL 7.x libraries (libpq.so) are in directory DIR - - --with-postgres-includes=DIR - PostgreSQL 7.x header files are located in directory DIR - - --with-mxdatetime-includes=DIR - MXDateTime Python extension header files are located in directory DIR - - --with-zope=DIR - install the ZPsycopgDA Zope Product into DIR (use 'make install-zope') - - --enable-devel[=yes/no] - Enable developer features like debugging output and extra assertions. - -Some random notes about python versions and paths: - - 1/ If possible, don't use the configure arguments --with-python-prefix - and --with-python-exec-prefix; the configure script is able to guess - the correct values from you python installation. - - 2/ If you have more than one Python version installed, use the arguments - --with-python (giving it the *full*, *absolute* path to the Python - interpreter) and --with-python-version (giving it the corresponding - version, like 1.5 or 2.1.) - -Common problems while building psycopg: - - 1/ if your compiler does not find some postgres headers try copying all the - headers from the postgres _source_ distribution to a single place. Also, - if building postgresql from source, make sure to install all headers by - the "make install-all-headers" target. - - 2/ if you have the same problem with mx.DateTime, try using the source - directory again; the install script does not copy all the headers, same - way as postgres install procedure does. - - 3/ under MacOS X you may need to run the runlib program on the posgres - installed libraries before trying to compile psycopg. Also, if you - get compilation errors there is a change your python was not compiled - correctly and psycopg is grabbing the wrong compile-time options from - python's Makefile. try setting the OPT and LDFLAG environment variables - to something usefull, as in the next example: - - OPT="-no-cpp-precomp" LDFLAGS="-flat-namespace" ./configure ... Licence ------- @@ -149,16 +30,16 @@ it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. See file COPYING for details. -As a special exception, specific permission is granted for the GPLed -code in this distribition to be linked to OpenSSL and PostgreSQL libpq -without invoking GPL clause 2(b). - -If you prefer you can use the Zope Database Adapter ZPsycopgDA (i.e., -every file inside the ZPsycopgDA directory) user the ZPL license as -published on the Zope web site, http://www.zope.org/Resources/ZPL. +As a special exception, specific permission is granted for the GPLed code in +this distribition to be linked to OpenSSL and PostgreSQL libpq without +invoking GPL clause 2(b). -psycopg is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. +If you prefer you can use the Zope Database Adapter ZPsycopgDA (i.e., every +file inside the ZPsycopgDA directory) under the ZPL license as published on +the Zope web site, http://www.zope.org/Resources/ZPL. The ZPL is perfectly +compatible with the GPL +psycopg is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. diff --git a/ZPsycopgDA/DA.py b/ZPsycopgDA/DA.py index 2242e2a..b9979b7 100644 --- a/ZPsycopgDA/DA.py +++ b/ZPsycopgDA/DA.py @@ -1,287 +1,202 @@ -############################################################################## -# -# Zope Public License (ZPL) Version 1.0 -# ------------------------------------- -# -# Copyright (c) Digital Creations. All rights reserved. -# -# This license has been certified as Open Source(tm). -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# 1. Redistributions in source code must retain the above copyright -# notice, this list of conditions, and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions, and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# -# 3. Digital Creations requests that attribution be given to Zope -# in any manner possible. Zope includes a "Powered by Zope" -# button that is installed by default. While it is not a license -# violation to remove this button, it is requested that the -# attribution remain. A significant investment has been put -# into Zope, and this effort will continue if the Zope community -# continues to grow. This is one way to assure that growth. -# -# 4. All advertising materials and documentation mentioning -# features derived from or use of this software must display -# the following acknowledgement: -# -# "This product includes software developed by Digital Creations -# for use in the Z Object Publishing Environment -# (http://www.zope.org/)." -# -# In the event that the product being advertised includes an -# intact Zope distribution (with copyright and license included) -# then this clause is waived. -# -# 5. Names associated with Zope or Digital Creations must not be used to -# endorse or promote products derived from this software without -# prior written permission from Digital Creations. -# -# 6. Modified redistributions of any form whatsoever must retain -# the following acknowledgment: -# -# "This product includes software developed by Digital Creations -# for use in the Z Object Publishing Environment -# (http://www.zope.org/)." -# -# Intact (re-)distributions of any official Zope release do not -# require an external acknowledgement. -# -# 7. Modifications are encouraged but must be packaged separately as -# patches to official Zope releases. Distributions that do not -# clearly separate the patches from the original work must be clearly -# labeled as unofficial distributions. Modifications which do not -# carry the name Zope may be packaged in any form, as long as they -# conform to all of the clauses above. -# -# -# Disclaimer -# -# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY -# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL CREATIONS OR ITS -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF -# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT -# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# -# This software consists of contributions made by Digital Creations and -# many individuals on behalf of Digital Creations. Specific -# attributions are listed in the accompanying credits file. -# -############################################################################## -database_type='Psycopg' -__doc__='''%s Database Connection - -$Id: DA.py 531 2004-09-18 09:54:40Z fog $''' % database_type -__version__='$Revision: 1.20.2.14 $'[11:-2] -__psycopg_versions__ = ('1.1.12', '1.1.13', '1.1.14', '1.1.15', '1.1.16') - +# ZPsycopgDA/DA.py - ZPsycopgDA Zope product: Database Connection +# +# Copyright (C) 2004 Federico Di Gregorio <fog@initd.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. +# +# Or, at your option this program (ZPsycopgDA) can be distributed under the +# Zope Public License (ZPL) Version 1.0, as published on the Zope web site, +# http://www.zope.org/Resources/ZPL. +# +# 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 LICENSE file for details. + + +ALLOWED_PSYCOPG_VERSIONS = ('1.99.9',) + +import sys +import db +import DABase +import Shared.DC.ZRDB.Connection from db import DB -import Shared.DC.ZRDB.Connection, sys, DABase, time -from Globals import HTMLFile, ImageFile +from Globals import DTMLFile +from Globals import HTMLFile +from ImageFile import ImageFile from ExtensionClass import Base -from string import find, join, split, rindex -try: - import psycopg - from psycopg import new_type, register_type, DATETIME, TIME, DATE, INTERVAL -except StandardError, err: - print err -try: - from DateTime import DateTime -except StandardError, err: - print err -try: - from App.Dialogs import MessageDialog -except: - pass -import time - -manage_addZPsycopgConnectionForm = HTMLFile('connectionAdd', globals()) -def manage_addZPsycopgConnection(self, id, title, - connection_string, zdatetime=None, - tilevel=2, check=None, REQUEST=None): - """Add a DB connection to a folder""" - self._setObject(id, Connection(id, title, connection_string, zdatetime, - check, tilevel)) - if REQUEST is not None: return self.manage_main(self,REQUEST) - - -# Convert an ISO timestamp string from postgres to a DateTime (zope version) -# object. -def cast_DateTime(str): - if str: - # this will split us into [date, time, GMT/AM/PM(if there)] - dt = split(str, ' ') - if len(dt) > 1: - # we now should split out any timezone info - dt[1] = split(dt[1], '-')[0] - dt[1] = split(dt[1], '+')[0] - t = time.mktime(time.strptime(join(dt[:2], ' '), '%Y-%m-%d %H:%M:%S')) - else: - t = time.mktime(time.strptime(dt[0], '%Y-%m-%d %H:%M:%S')) - return DateTime(t) +from DateTime import DateTime -# Convert an ISO date string from postgres to a DateTime(zope version) -# object. -def cast_Date(str): - if str: - return DateTime(time.mktime(time.strptime(str, '%Y-%m-%d'))) +# import psycopg and functions/singletons needed for date/time conversions -# Convert a time string from postgres to a DateTime(zope version) object. -# WARNING: We set the day as today before feeding to DateTime so -# that it has the same DST settings. -def cast_Time(str): - if str: - return DateTime(time.strftime('%Y-%m-%d %H:%M:%S', - time.localtime(time.time())[:3]+ - time.strptime(str[:8], "%H:%M:%S")[3:])) +import psycopg +from psycopg import DATETIME +from psycopg.extensions import TIME, DATE, INTERVAL +from psycopg.extensions import new_type, register_type -# Convert a time string from postgres to a DateTime(zope version) object. -# WARNING: We set the day as the epoch day (1970-01-01) since this -# DateTime does not support time deltas. (EXPERIMENTAL USE WITH CARE!) -def cast_Interval(str): - return str + + +# add a new connection to a folder + +manage_addZPsycopgConnectionForm = DTMLFile('dtml/add',globals()) + +def manage_addZPsycopgConnection(self, id, title, connection_string, + zdatetime=None, tilevel=2, + check=None, REQUEST=None): + """Add a DB connection to a folder.""" + self._setObject(id, Connection(id, title, connection_string, + zdatetime, check, tilevel)) + if REQUEST is not None: return self.manage_main(self, REQUEST) + + +# the connection object class Connection(DABase.Connection): - "The connection class." - database_type = database_type - id = '%s_database_connection' % database_type - meta_type = title = 'Z %s Database Connection' % database_type - icon = 'misc_/Z%sDA/conn' % database_type - - def __init__(self, id, title, connection_string, zdatetime, - check=None, tilevel=2, encoding='UTF-8'): - self.zdatetime=zdatetime - self.id=str(id) + """ZPsycopg Connection.""" + id = 'Psycopg_database_connection' + database_type = 'Psycopg' + meta_type = title = 'Z Psycopg Database Connection' + icon = 'misc_/ZPsycopg/conn' + + def __init__(self, id, title, connection_string, + zdatetime, check=None, tilevel=2, encoding=''): + self.zdatetime = zdatetime + self.id = str(id) self.edit(title, connection_string, zdatetime, check=check, tilevel=tilevel, encoding=encoding) + + def factory(self): + return DB + + def table_info(self): + return self._v_database_connection.table_info() + + def edit(self, title, connection_string, + zdatetime, check=None, tilevel=2, encoding=''): + self.title = title + self.connection_string = connection_string + self.zdatetime = zdatetime + self.tilevel = tilevel + self.encoding = encoding - def edit(self, title, connection_string, zdatetime, - check=1, tilevel=2, encoding='UTF-8'): - self.title=title - self.connection_string=connection_string - self.zdatetime=zdatetime - self.tilevel=tilevel - self.encoding=encoding self.set_type_casts() - if check: self.connect(connection_string) + + if check: self.connect(self.connection_string) - manage_properties=HTMLFile('connectionEdit', globals()) + manage_properties = DTMLFile('dtml/edit', globals()) def manage_edit(self, title, connection_string, zdatetime=None, check=None, tilevel=2, encoding='UTF-8', REQUEST=None): - """Change connection - """ + """Edit the DB connection.""" self.edit(title, connection_string, zdatetime, check=check, tilevel=tilevel, encoding=encoding) if REQUEST is not None: - return MessageDialog( - title='Edited', - message='<strong>%s</strong> has been edited.' % self.id, - action ='./manage_main', - ) + msg = "Connection edited." + return self.manage_main(self,REQUEST,manage_tabs_message=msg) + + def connect(self, s): + try: + self._v_database_connection.close() + except: + pass + + # check psycopg version and raise exception if does not match + if psycopg.__version__ not in ALLOWED_PSYCOPG_VERSIONS: + raise ImportError("psycopg version mismatch (imported %s)" + + psycopg.__version__) + + self.set_type_casts() + self._v_connected = '' + dbf = self.factory() + # TODO: let the psycopg exception propagate, or not? + self._v_database_connection = dbf( + self.connection_string, self.tilevel, self.encoding) + self._v_database_connection.open() + self._v_connected = DateTime() + + return self + def set_type_casts(self): - "Make changes to psycopg default typecast list" + # note that in both cases order *is* important if self.zdatetime: - #use zope internal datetime routines - ZDATETIME=new_type((1184,1114), "ZDATETIME", cast_DateTime) - ZDATE=new_type((1082,), "ZDATE", cast_Date) - ZTIME=new_type((1083,), "ZTIME", cast_Time) - ZINTERVAL=new_type((1186,), "ZINTERVAL", cast_Interval) + # use zope internal datetime routines register_type(ZDATETIME) register_type(ZDATE) register_type(ZTIME) register_type(ZINTERVAL) else: - #use the standard. WARN: order is important! + # use the standard register_type(DATETIME) register_type(DATE) register_type(TIME) register_type(INTERVAL) - - def factory(self): - return DB + +# database connection registration data - def table_info(self): - return self._v_database_connection.table_info() +classes = (Connection,) - def connect(self,s): - try: self._v_database_connection.close() - except: pass +meta_types = ({'name':'Z Psycopg Database Connection', + 'action':'manage_addZPsycopgConnectionForm'},) - # check psycopg version and raise exception if does not match - if psycopg.__version__ not in __psycopg_versions__: - raise ImportError("psycopg version mismatch: " + - psycopg.__version__) +folder_methods = { + 'manage_addZPsycopgConnection': manage_addZPsycopgConnection, + 'manage_addZPsycopgConnectionForm': manage_addZPsycopgConnectionForm} - self.set_type_casts() - self._v_connected='' - DB=self.factory() - try: - try: - # this is necessary when upgrading from old installs without - # having to recreate the connection object - if not hasattr(self, 'tilevel'): - self.tilevel = 2 - if not hasattr(self, 'encoding'): - self.encoding = 'UTF-8' - self._v_database_connection=DB(s, self.tilevel, self.encoding) - except: - t, v, tb = sys.exc_info() - raise 'BadRequest', ( - '<strong>Could not open connection.<br>' - 'Connection string: </strong><CODE>%s</CODE><br>\n' - '<pre>\n%s\n%s\n</pre>\n' - % (s,t,v)), tb - finally: tb=None - self._v_connected=DateTime() +__ac_permissions__ = ( + ('Add Z Psycopg Database Connections', + ('manage_addZPsycopgConnectionForm', 'manage_addZPsycopgConnection')),) - return self +# add icons - def sql_quote__(self, v): - # quote dictionary - quote_dict = {"\'": "''", "\\": "\\\\"} - for dkey in quote_dict.keys(): - if find(v, dkey) >= 0: - v=join(split(v,dkey),quote_dict[dkey]) - return "'%s'" % v +misc_={'conn': ImageFile('Shared/DC/ZRDB/www/DBAdapterFolder_icon.gif')} +for icon in ('table', 'view', 'stable', 'what', 'field', 'text', 'bin', + 'int', 'float', 'date', 'time', 'datetime'): + misc_[icon] = ImageFile('icons/%s.gif' % icon, globals()) -classes = ('DA.Connection',) +# zope-specific psycopg typecasters -meta_types=( - {'name':'Z %s Database Connection' % database_type, - 'action':'manage_addZ%sConnectionForm' % database_type},) +# convert an ISO timestamp string from postgres to a Zope DateTime object +def _cast_DateTime(str): + if str: + # this will split us into [date, time, GMT/AM/PM(if there)] + dt = split(str, ' ') + if len(dt) > 1: + # we now should split out any timezone info + dt[1] = split(dt[1], '-')[0] + dt[1] = split(dt[1], '+')[0] + return DateTime(join(dt[:2], ' ')) + else: + return DateTime(dt[0]) -folder_methods={ - 'manage_addZPsycopgConnection': manage_addZPsycopgConnection, - 'manage_addZPsycopgConnectionForm': manage_addZPsycopgConnectionForm} +# convert an ISO date string from postgres to a Zope DateTime object +def _cast_Date(str): + if str: + return DateTime(str) -__ac_permissions__=( - ('Add Z Psycopg Database Connections', - ('manage_addZPsycopgConnectionForm', 'manage_addZPsycopgConnection')),) +# Convert a time string from postgres to a Zope DateTime object. +# NOTE: we set the day as today before feeding to DateTime so +# that it has the same DST settings. +def _cast_Time(str): + if str: + return DateTime(time.strftime('%Y-%m-%d %H:%M:%S', + time.localtime(time.time())[:3]+ + time.strptime(str[:8], "%H:%M:%S")[3:])) + +# TODO: DateTime does not support intervals: what's the best we can do? +def _cast_Interval(str): + return str -misc_={ - 'conn': ImageFile('Shared/DC/ZRDB/www/DBAdapterFolder_icon.gif')} +ZDATETIME = new_type((1184, 1114), "ZDATETIME", _cast_DateTime) +ZINTERVAL = new_type((1186,), "ZINTERVAL", _cast_Interval) +ZDATE = new_type((1082,), "ZDATE", _cast_Date) +ZTIME = new_type((1083,), "ZTIME", _cast_Time) -for icon in ('table', 'view', 'stable', 'what', - 'field', 'text','bin','int','float', - 'date','time','datetime'): - misc_[icon] = ImageFile('icons/%s.gif' % icon, globals()) diff --git a/ZPsycopgDA/DABase.py b/ZPsycopgDA/DABase.py index 163f1ed..03102c3 100644 --- a/ZPsycopgDA/DABase.py +++ b/ZPsycopgDA/DABase.py @@ -1,150 +1,61 @@ -############################################################################## -# -# Zope Public License (ZPL) Version 1.0 -# ------------------------------------- -# -# Copyright (c) Digital Creations. All rights reserved. -# -# This license has been certified as Open Source(tm). -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# 1. Redistributions in source code must retain the above copyright -# notice, this list of conditions, and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions, and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# -# 3. Digital Creations requests that attribution be given to Zope -# in any manner possible. Zope includes a "Powered by Zope" -# button that is installed by default. While it is not a license -# violation to remove this button, it is requested that the -# attribution remain. A significant investment has been put -# into Zope, and this effort will continue if the Zope community -# continues to grow. This is one way to assure that growth. -# -# 4. All advertising materials and documentation mentioning -# features derived from or use of this software must display -# the following acknowledgement: -# -# "This product includes software developed by Digital Creations -# for use in the Z Object Publishing Environment -# (http://www.zope.org/)." -# -# In the event that the product being advertised includes an -# intact Zope distribution (with copyright and license included) -# then this clause is waived. -# -# 5. Names associated with Zope or Digital Creations must not be used to -# endorse or promote products derived from this software without -# prior written permission from Digital Creations. -# -# 6. Modified redistributions of any form whatsoever must retain -# the following acknowledgment: -# -# "This product includes software developed by Digital Creations -# for use in the Z Object Publishing Environment -# (http://www.zope.org/)." -# -# Intact (re-)distributions of any official Zope release do not -# require an external acknowledgement. -# -# 7. Modifications are encouraged but must be packaged separately as -# patches to official Zope releases. Distributions that do not -# clearly separate the patches from the original work must be clearly -# labeled as unofficial distributions. Modifications which do not -# carry the name Zope may be packaged in any form, as long as they -# conform to all of the clauses above. -# -# -# Disclaimer -# -# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY -# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL CREATIONS OR ITS -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF -# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT -# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# -# This software consists of contributions made by Digital Creations and -# many individuals on behalf of Digital Creations. Specific -# attributions are listed in the accompanying credits file. -# -############################################################################## -__doc__='''Database Connection +# ZPsycopgDA/DABase.py - ZPsycopgDA Zope product: Database inspection +# +# Copyright (C) 2004 Federico Di Gregorio <fog@initd.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. +# +# Or, at your option this program (ZPsycopgDA) can be distributed under the +# Zope Public License (ZPL) Version 1.0, as published on the Zope web site, +# http://www.zope.org/Resources/ZPL. +# +# 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 LICENSE file for details. + +import sys +import Shared.DC.ZRDB.Connection + +from db import DB +from Globals import HTMLFile +from ImageFile import ImageFile +from ExtensionClass import Base +from DateTime import DateTime -$Id: DABase.py 400 2003-01-20 14:39:34Z fog $''' -__version__='$Revision: 1.10 $'[11:-2] +# import psycopg and functions/singletons needed for date/time conversions +import psycopg +from psycopg.extensions import INTEGER, LONGINTEGER, FLOAT, BOOLEAN +from psycopg import NUMBER, STRING, ROWID, DATETIME -import Shared.DC.ZRDB.Connection, sys -from App.Dialogs import MessageDialog -from Globals import HTMLFile, ImageFile -from ExtensionClass import Base -import Acquisition -from psycopg import NUMBER, ROWID, STRING, INTEGER, FLOAT -from psycopg import BOOLEAN, DATETIME, LONGINTEGER + class Connection(Shared.DC.ZRDB.Connection.Connection): _isAnSQLConnection = 1 + info = None - manage_options=Shared.DC.ZRDB.Connection.Connection.manage_options+( - {'label': 'Browse', 'action':'manage_browse'}, - # {'label': 'Design', 'action':'manage_tables'} - ) - - manage_tables = HTMLFile('tables',globals()) - manage_browse = HTMLFile('browse',globals()) - - info=None - - def tpValues(self): - #if hasattr(self, '_v_tpValues'): return self._v_tpValues - r=[] - # self._v_tables=tables=TableBrowserCollection() - #tables=tables.__dict__ - c = self._v_database_connection - try: - for d in c.tables(rdb=0): - try: - name=d['TABLE_NAME'] - b=TableBrowser() - b.__name__=name - b._d=d - b._c=c - # b._columns=c.columns(name) - try: b.icon=table_icons[d['TABLE_TYPE']] - except: pass - r.append(b) - # tables[name]=b - except: - # print d['TABLE_NAME'], sys.exc_type, sys.exc_value - pass + #manage_options = Shared.DC.ZRDB.Connection.Connection.manage_options + ( + # {'label': 'Browse', 'action':'manage_browse'},) - finally: pass #print sys.exc_type, sys.exc_value - #self._v_tpValues=r - return r + #manage_tables = HTMLFile('tables', globals()) + #manage_browse = HTMLFile('browse',globals()) def __getitem__(self, name): - if name=='tableNamed': + if name == 'tableNamed': if not hasattr(self, '_v_tables'): self.tpValues() return self._v_tables.__of__(self) raise KeyError, name + + ## old stuff from ZPsycopgDA 1.1 (never implemented) ## + def manage_wizard(self, tables): - " " + "Wizard of what? Oozing?" def manage_join(self, tables, select_cols, join_cols, REQUEST=None): """Create an SQL join""" @@ -154,116 +65,3 @@ class Connection(Shared.DC.ZRDB.Connection.Connection): def manage_update(self, table, keys, cols, REQUEST=None): """Create an SQL update""" - -class TableBrowserCollection(Acquisition.Implicit): - "Helper class for accessing tables via URLs" - pass - -class Browser(Base): - def __getattr__(self, name): - try: return self._d[name] - except KeyError: raise AttributeError, name - -class values: - - def len(self): return 1 - - def __getitem__(self, i): - try: return self._d[i] - except AttributeError: - pass - self._d=self._f() - return self._d[i] - -class TableBrowser(Browser, Acquisition.Implicit): - icon='what' - Description=check='' - info=HTMLFile('table_info',globals()) - menu=HTMLFile('table_menu',globals()) - - def tpValues(self): - v=values() - v._f=self.tpValues_ - return v - - def tpValues_(self): - r=[] - tname=self.__name__ - for d in self._c.columns(tname): - b=ColumnBrowser() - b._d=d - try: b.icon=field_icons[d['Type']] - except: pass - b.TABLE_NAME=tname - r.append(b) - return r - - def tpId(self): return self._d['TABLE_NAME'] - def tpURL(self): return "Table/%s" % self._d['TABLE_NAME'] - def Name(self): return self._d['TABLE_NAME'] - def Type(self): return self._d['TABLE_TYPE'] - - manage_designInput=HTMLFile('designInput',globals()) - def manage_buildInput(self, id, source, default, REQUEST=None): - "Create a database method for an input form" - args=[] - values=[] - names=[] - columns=self._columns - for i in range(len(source)): - s=source[i] - if s=='Null': continue - c=columns[i] - d=default[i] - t=c['Type'] - n=c['Name'] - names.append(n) - if s=='Argument': - values.append("<dtml-sqlvar %s type=%s>'" % - (n, vartype(t))) - a='%s%s' % (n, boboType(t)) - if d: a="%s=%s" % (a,d) - args.append(a) - elif s=='Property': - values.append("<dtml-sqlvar %s type=%s>'" % - (n, vartype(t))) - else: - if isStringType(t): - if find(d,"\'") >= 0: d=join(split(d,"\'"),"''") - values.append("'%s'" % d) - elif d: - values.append(str(d)) - else: - raise ValueError, ( - 'no default was given for <em>%s</em>' % n) - -class ColumnBrowser(Browser): - icon='field' - - def check(self): - return ('\t<input type=checkbox name="%s.%s">' % - (self.TABLE_NAME, self._d['Name'])) - def tpId(self): return self._d['Name'] - def tpURL(self): return "Column/%s" % self._d['Name'] - def Description(self): - d=self._d - if d['Scale']: - return " %(Type)s(%(Precision)s,%(Scale)s) %(Nullable)s" % d - else: - return " %(Type)s(%(Precision)s) %(Nullable)s" % d - -table_icons={ - 'TABLE': 'table', - 'VIEW':'view', - 'SYSTEM_TABLE': 'stable', - } - -field_icons={ - NUMBER.name: 'int', - STRING.name: 'text', - DATETIME.name: 'date', - INTEGER.name: 'int', - FLOAT.name: 'float', - BOOLEAN.name: 'bin', - ROWID.name: 'int' - } diff --git a/ZPsycopgDA/__init__.py b/ZPsycopgDA/__init__.py index b793e2f..b0e2a45 100644 --- a/ZPsycopgDA/__init__.py +++ b/ZPsycopgDA/__init__.py @@ -1,105 +1,32 @@ -############################################################################## -# -# Zope Public License (ZPL) Version 1.0 -# ------------------------------------- -# -# Copyright (c) Digital Creations. All rights reserved. -# -# This license has been certified as Open Source(tm). -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# 1. Redistributions in source code must retain the above copyright -# notice, this list of conditions, and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions, and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# -# 3. Digital Creations requests that attribution be given to Zope -# in any manner possible. Zope includes a "Powered by Zope" -# button that is installed by default. While it is not a license -# violation to remove this button, it is requested that the -# attribution remain. A significant investment has been put -# into Zope, and this effort will continue if the Zope community -# continues to grow. This is one way to assure that growth. -# -# 4. All advertising materials and documentation mentioning -# features derived from or use of this software must display -# the following acknowledgement: -# -# "This product includes software developed by Digital Creations -# for use in the Z Object Publishing Environment -# (http://www.zope.org/)." -# -# In the event that the product being advertised includes an -# intact Zope distribution (with copyright and license included) -# then this clause is waived. -# -# 5. Names associated with Zope or Digital Creations must not be used to -# endorse or promote products derived from this software without -# prior written permission from Digital Creations. -# -# 6. Modified redistributions of any form whatsoever must retain -# the following acknowledgment: -# -# "This product includes software developed by Digital Creations -# for use in the Z Object Publishing Environment -# (http://www.zope.org/)." -# -# Intact (re-)distributions of any official Zope release do not -# require an external acknowledgement. -# -# 7. Modifications are encouraged but must be packaged separately as -# patches to official Zope releases. Distributions that do not -# clearly separate the patches from the original work must be clearly -# labeled as unofficial distributions. Modifications which do not -# carry the name Zope may be packaged in any form, as long as they -# conform to all of the clauses above. -# -# -# Disclaimer -# -# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY -# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL CREATIONS OR ITS -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF -# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT -# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# -# This software consists of contributions made by Digital Creations and -# many individuals on behalf of Digital Creations. Specific -# attributions are listed in the accompanying credits file. -# -############################################################################## -# Modified by mcm@initd.net for the psycopg driver -__doc__='''Generic Database Adapter Package Registration +# ZPsycopgDA/__init__.py - ZPsycopgDA Zope product +# +# Copyright (C) 2004 Federico Di Gregorio <fog@initd.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. +# +# Or, at your option this program (ZPsycopgDA) can be distributed under the +# Zope Public License (ZPL) Version 1.0, as published on the Zope web site, +# http://www.zope.org/Resources/ZPL. +# +# 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 LICENSE file for details. -$Id: __init__.py 400 2003-01-20 14:39:34Z fog $''' -__version__='$Revision: 1.11 $'[11:-2] +__doc__ = "ZPsycopg Database Adalper Registration." +__version__ = '2.0' -import sys, string +import sys +import string import DA -methods=DA.folder_methods -misc_ = DA.misc_ +methods = DA.folder_methods +classes = DA.classes +meta_types = DA.meta_types +misc_ = DA.misc_ -def initialize(context): - """Initialize the DBA product. - """ - context.registerClass( - DA.Connection, - permission = 'Add Z Psycopg Database Connections', - constructors = (DA.manage_addZPsycopgConnectionForm, - DA.manage_addZPsycopgConnection), - icon = SOFTWARE_HOME + '/Shared/DC/ZRDB/www/DBAdapterFolder_icon.gif') +__ac_permissions__=DA.__ac_permissions__ diff --git a/ZPsycopgDA/db.py b/ZPsycopgDA/db.py index 6c9f39b..c859535 100644 --- a/ZPsycopgDA/db.py +++ b/ZPsycopgDA/db.py @@ -1,171 +1,126 @@ -############################################################################## -# -# Zope Public License (ZPL) Version 1.0 -# ------------------------------------- -# -# Copyright (c) Digital Creations. All rights reserved. -# -# This license has been certified as Open Source(tm). -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# 1. Redistributions in source code must retain the above copyright -# notice, this list of conditions, and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions, and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# -# 3. Digital Creations requests that attribution be given to Zope -# in any manner possible. Zope includes a "Powered by Zope" -# button that is installed by default. While it is not a license -# violation to remove this button, it is requested that the -# attribution remain. A significant investment has been put -# into Zope, and this effort will continue if the Zope community -# continues to grow. This is one way to assure that growth. -# -# 4. All advertising materials and documentation mentioning -# features derived from or use of this software must display -# the following acknowledgement: -# -# "This product includes software developed by Digital Creations -# for use in the Z Object Publishing Environment -# (http://www.zope.org/)." -# -# In the event that the product being advertised includes an -# intact Zope distribution (with copyright and license included) -# then this clause is waived. -# -# 5. Names associated with Zope or Digital Creations must not be used to -# endorse or promote products derived from this software without -# prior written permission from Digital Creations. -# -# 6. Modified redistributions of any form whatsoever must retain -# the following acknowledgment: -# -# "This product includes software developed by Digital Creations -# for use in the Z Object Publishing Environment -# (http://www.zope.org/)." -# -# Intact (re-)distributions of any official Zope release do not -# require an external acknowledgement. -# -# 7. Modifications are encouraged but must be packaged separately as -# patches to official Zope releases. Distributions that do not -# clearly separate the patches from the original work must be clearly -# labeled as unofficial distributions. Modifications which do not -# carry the name Zope may be packaged in any form, as long as they -# conform to all of the clauses above. -# -# -# Disclaimer -# -# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY -# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL CREATIONS OR ITS -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF -# USE, DATA, OR PROFITS; OR BUSINESS INTERUPTION) HOWEVER CAUSED AND -# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT -# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# -# This software consists of contributions made by Digital Creations and -# many individuals on behalf of Digital Creations. Specific -# attributions are listed in the accompanying credits file. -# -############################################################################## - -'''$Id: db.py 532 2004-09-27 18:35:25Z fog $''' -__version__='$Revision: 1.31.2.7 $'[11:-2] - +# ZPsycopgDA/db.py - query execution +# +# Copyright (C) 2004 Federico Di Gregorio <fog@initd.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. +# +# Or, at your option this program (ZPsycopgDA) can be distributed under the +# Zope Public License (ZPL) Version 1.0, as published on the Zope web site, +# http://www.zope.org/Resources/ZPL. +# +# 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 LICENSE file for details. from Shared.DC.ZRDB.TM import TM from Shared.DC.ZRDB import dbi_db -import string, sys -from string import strip, split, find -from time import time -from types import ListType +from ZODB.POSException import ConflictError + +import time import site +import pool import psycopg -from psycopg import NUMBER, STRING, INTEGER, FLOAT, DATETIME -from psycopg import BOOLEAN, ROWID, LONGINTEGER -from ZODB.POSException import ConflictError +from psycopg.extensions import INTEGER, LONGINTEGER, FLOAT, BOOLEAN +from psycopg import NUMBER, STRING, ROWID, DATETIME -class DB(TM,dbi_db.DB): + +# the DB object, managing all the real query work + +class DB(TM, dbi_db.DB): + _p_oid = _p_changed = _registered = None - def __init__(self, connection, tilevel, enc='utf-8'): - self.connection = connection + def __init__(self, dsn, tilevel, enc='utf-8'): + self.dsn = dsn self.tilevel = tilevel - self.encoding = enc - self.db = self.connect(self.connection) + self.encoding = enc self.failures = 0 self.calls = 0 - def connect(self, connection): - o = psycopg.connect(connection) - o.set_isolation_level(int(self.tilevel)) - return o - + def getconn(self, create=True): + conn = pool.getconn(self.dsn) + conn.set_isolation_level(int(self.tilevel)) + return conn + + def putconn(self, close=False): + try: + conn = pool.getconn(self.dsn, False) + except AttributeError: + pass + pool.putconn(self.dsn, conn, close) + + def getcursor(self): + conn = self.getconn() + return conn.cursor() + def _finish(self, *ignored): - if hasattr(self, 'db') and self.db: - self.db.commit() + try: + conn = self.getconn(False) + conn.commit() + self.putconn() + except AttributeError: + pass def _abort(self, *ignored): - if hasattr(self, 'db') and self.db: - self.db.rollback() - - def _cursor(self): - """Obtains a cursor in a safe way.""" - if not hasattr(self, 'db') or not self.db: - self.db = self.connect(self.connection) - return self.db.cursor() - + try: + conn = self.getconn(False) + conn.rollback() + self.putconn() + except AttributeError: + pass + + def open(self): + # this will create a new pool for our DSN if not already existing, + # then get and immediately release a connection + self.getconn() + self.putconn() + + def close(self): + # FIXME: if this connection is closed we flush all the pool associated + # with the current DSN; does this makes sense? + pool.flushpool(self.dsn) + + def sortKey(self): + return 1 + + ## tables and rows ## + def tables(self, rdb=0, _care=('TABLE', 'VIEW')): self._register() - c = self._cursor() - c.execute('SELECT t.tablename AS NAME, ' - '\'TABLE\' AS TYPE FROM pg_tables t ' - 'WHERE tableowner <> \'postgres\' ' - 'UNION SELECT v.viewname AS NAME, ' - '\'VIEW\' AS TYPE FROM pg_views v ' - 'WHERE viewowner <> \'postgres\' ' - 'UNION SELECT t.tablename AS NAME, ' - '\'SYSTEM_TABLE\' AS TYPE FROM pg_tables t ' - 'WHERE tableowner = \'postgres\' ' - 'UNION SELECT v.viewname AS NAME, ' - '\'SYSTEM_TABLE\' AS TYPE FROM pg_views v ' - 'WHERE viewowner = \'postgres\' ' ) - r = [] - a = r.append + c = self.getcursor() + c.execute( + "SELECT t.tablename AS NAME, 'TABLE' AS TYPE " + " FROM pg_tables t WHERE tableowner <> 'postgres' " + "UNION SELECT v.viewname AS NAME, 'VIEW' AS TYPE " + " FROM pg_views v WHERE viewowner <> 'postgres' " + "UNION SELECT t.tablename AS NAME, 'SYSTEM_TABLE\' AS TYPE " + " FROM pg_tables t WHERE tableowner = 'postgres' " + "UNION SELECT v.viewname AS NAME, 'SYSTEM_TABLE' AS TYPE " + "FROM pg_views v WHERE viewowner = 'postgres'") + res = [] for name, typ in c.fetchall(): if typ in _care: - a({'TABLE_NAME': name, 'TABLE_TYPE': typ}) - c.close() - return r + res.append({'TABLE_NAME': name, 'TABLE_TYPE': typ}) + self.putconn() + return res def columns(self, table_name): self._register() - c = self._cursor() + c = self.getcursor() try: - r = c.execute('select * from "%s" where 1=0' % table_name) + r = c.execute('SELECT * FROM "%s" WHERE 1=0' % table_name) except: return () - desc = c.description - r = [] - a = r.append - for name, type, width, ds, p, scale, null_ok in desc: + res = [] + for name, type, width, ds, p, scale, null_ok in c.description: if type == NUMBER: if type == INTEGER: type = INTEGER @@ -180,49 +135,53 @@ class DB(TM,dbi_db.DB): type = DATETIME else: type = STRING - a({ 'Name': name, - 'Type': type.name, - 'Precision': 0, - 'Scale': 0, - 'Nullable': 0}) - return r + + res.append({'Name': name, + 'Type': type.name, + 'Precision': 0, + 'Scale': 0, + 'Nullable': 0}) + self.putconn() + return res + + ## query execution ## def query(self, query_string, max_rows=None, query_data=None): self._register() self.calls = self.calls+1 - + desc = () - result = [] + res = [] nselects = 0 - - c = self._cursor() - + + c = self.getcursor() + try: - for qs in filter(None, map(strip, split(query_string, '\0'))): + for qs in [x for x in query_string.split('\0') if x]: if type(qs) == unicode: if self.encoding: qs = qs.encode(self.encoding) try: if (query_data): - r = c.execute(qs, query_data) + c.execute(qs, query_data) else: - r = c.execute(qs) - except (psycopg.ProgrammingError,psycopg.IntegrityError), perr: - if perr.args[0].find("concurrent update") > -1: + c.execute(qs) + except (psycopg.ProgrammingError, psycopg.IntegrityError), e: + if e.args[0].find("concurrent update") > -1: raise ConflictError - raise perr + raise e if c.description is not None: - nselects = nselects + 1 + nselects += 1 if c.description != desc and nselects > 1: - raise 'Query Error', \ - 'Multiple select schema are not allowed' + raise psycopg.ProgrammingError( + 'multiple selects in single query not allowed') if max_rows: - result = c.fetchmany(max_rows) + res = c.fetchmany(max_rows) else: - result = c.fetchall() + res = c.fetchall() desc = c.description self.failures = 0 - + except StandardError, err: self._abort() raise err @@ -247,13 +206,4 @@ class DB(TM,dbi_db.DB): 'null': null_ok, }) - return items, result - - def close(self): - """Close the connection.""" - self.db.close() - self.db = None - - def sortKey(self): - """Zope 2.6 added this one.""" - return 1 + return items, res diff --git a/ZPsycopgDA/icons/bin.gif b/ZPsycopgDA/icons/bin.gif Binary files differindex e469126..fa4fdd0 100644 --- a/ZPsycopgDA/icons/bin.gif +++ b/ZPsycopgDA/icons/bin.gif diff --git a/ZPsycopgDA/icons/float.gif b/ZPsycopgDA/icons/float.gif Binary files differindex dd42729..efc5c78 100644 --- a/ZPsycopgDA/icons/float.gif +++ b/ZPsycopgDA/icons/float.gif diff --git a/ZPsycopgDA/icons/int.gif b/ZPsycopgDA/icons/int.gif Binary files differindex ef2c5e3..5ee3ced 100644 --- a/ZPsycopgDA/icons/int.gif +++ b/ZPsycopgDA/icons/int.gif diff --git a/ZPsycopgDA/icons/table.gif b/ZPsycopgDA/icons/table.gif Binary files differindex cce83be..4fb32d9 100644 --- a/ZPsycopgDA/icons/table.gif +++ b/ZPsycopgDA/icons/table.gif diff --git a/ZPsycopgDA/icons/text.gif b/ZPsycopgDA/icons/text.gif Binary files differindex a2e5aab..c9d5365 100644 --- a/ZPsycopgDA/icons/text.gif +++ b/ZPsycopgDA/icons/text.gif diff --git a/ZPsycopgDA/icons/what.gif b/ZPsycopgDA/icons/what.gif Binary files differindex 8b5516e..0214a4d 100644 --- a/ZPsycopgDA/icons/what.gif +++ b/ZPsycopgDA/icons/what.gif |