Compare commits

...

2906 Commits

Author SHA1 Message Date
dependabot[bot]
dcb302493a build(deps): bump pypa/cibuildwheel from 2.22.0 to 2.23.2
Bumps [pypa/cibuildwheel](https://github.com/pypa/cibuildwheel) from 2.22.0 to 2.23.2.
- [Release notes](https://github.com/pypa/cibuildwheel/releases)
- [Changelog](https://github.com/pypa/cibuildwheel/blob/main/docs/changelog.md)
- [Commits](https://github.com/pypa/cibuildwheel/compare/v2.22.0...v2.23.2)

---
updated-dependencies:
- dependency-name: pypa/cibuildwheel
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-04-02 12:45:46 +01:00
Daniele Varrazzo
5509e01108
Merge pull request #1755 from bwoodsend/fix-macos-deployment-target
ci(macos): Avoid linking against Homebrew
2025-01-06 01:15:51 +01:00
Daniele Varrazzo
6cd0fbdc49 fix(macos): don't crash on undefined variable 2025-01-05 22:00:24 +01:00
Daniele Varrazzo
cee23d83e0 chore(macos): drop unneeded gettext from libpq building 2025-01-05 21:37:12 +01:00
Daniele Varrazzo
5bfba4c961 refactor: use pushd/popd instead of cd 2025-01-05 21:37:12 +01:00
Daniele Varrazzo
b943457896 test: drop brew curl to use the system one 2025-01-05 21:37:12 +01:00
Brénainn Woodsend
d0bc154f31 build(macos): Enable cross compiling libpq across macOS architectures
The GitHub Actions runners look like they're only 1 year away from the
last macOS x86_64 platform being removed. Get ahead of the game and
build x86_64 on arm64.
2025-01-05 20:44:25 +01:00
Daniele Varrazzo
1eac4fd4da test(macos): soften tests to account for macOS polling differences 2025-01-05 04:00:47 +01:00
Daniele Varrazzo
c8abc5ce61 ci(macos): no fast tests on macOS package building
We don't run complete tests in CI, so let's not waste this chance. The
overhead for complete tests is minimal compared to all the pipeline
boilerplate.
2025-01-05 04:00:00 +01:00
Daniele Varrazzo
65626ec565 ci(macos): add libpq build caching 2025-01-05 04:00:00 +01:00
Daniele Varrazzo
310bc75532 ci(macos): move libpq build script to BEFORE_ALL build step
This is is how it is organised in Linux.
2025-01-05 04:00:00 +01:00
Brénainn Woodsend
d43e5fe092 ci(macos): Avoid linking against homebrew
Homebrew binaries are always compiled for exactly the version they're
installed on making them very un-portable. When a wheel is "repaired" by
cibuildwheel, delocate-wheel pulls in _psycopg's dependencies
(libpq.dylib, libssl.dylib and libcrypto.dylib) which, on a GitHub
Actions macOS 14 runner, are provided by Homebrew and are therefore only
macOS >= 14 compatible. The resultant wheel is therefore incompatible
with all but the latest macOS versions.

Build all dependencies from source so that we can set the deployment
target to something sensible. Fixes #1753.
2025-01-04 21:23:15 +01:00
Daniele Varrazzo
3b684f91ca ci: rename merged artifact package
It doesn't contain binary packages only
2025-01-04 21:06:33 +01:00
dependabot[bot]
bf7fc6cfa4 build(deps): bump peter-evans/repository-dispatch from 2 to 3
Bumps [peter-evans/repository-dispatch](https://github.com/peter-evans/repository-dispatch) from 2 to 3.
- [Release notes](https://github.com/peter-evans/repository-dispatch/releases)
- [Commits](https://github.com/peter-evans/repository-dispatch/compare/v2...v3)

---
updated-dependencies:
- dependency-name: peter-evans/repository-dispatch
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-01-04 21:05:08 +01:00
Daniele Varrazzo
979d56a797 chore: update cibuildwheel to 2.22.0 2025-01-04 21:04:14 +01:00
dependabot[bot]
4903f1c5d6 build(deps): bump actions/cache from 3 to 4
Bumps [actions/cache](https://github.com/actions/cache) from 3 to 4.
- [Release notes](https://github.com/actions/cache/releases)
- [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md)
- [Commits](https://github.com/actions/cache/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/cache
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-01-04 21:02:30 +01:00
Daniele Varrazzo
1dc7b5b70b ci: add merge step to download all packages at once 2025-01-04 21:01:09 +01:00
Daniele Varrazzo
ed4ba11d17
Merge pull request #1772 from psycopg/ci-vcpkg
Package psycopg2-binary for windows using vcpkg libpq
2025-01-04 21:00:44 +01:00
Daniele Varrazzo
947f731400 ci: test against final Python 3.13 2025-01-04 19:06:56 +01:00
Daniele Varrazzo
b8d49e6280 test: skip module test on Windows
Life is too short to figure out why it fails.
2025-01-04 19:06:56 +01:00
Daniele Varrazzo
4dfa680a71 ci(macos): use the macos-13 runners
macos-12 is not supported anymore.
2025-01-04 19:06:56 +01:00
Daniele Varrazzo
f4282c6d87 chore: drop Postgres version parsing in setup.py
The macro is in the include files, no idea why parsing it from pg_config
was needed.
2025-01-04 19:06:56 +01:00
Daniele Varrazzo
a8765121d9 fix(ci): handle other pg_config options required by setup.py 2025-01-04 19:06:56 +01:00
Daniele Varrazzo
bb52bcf769 ci(windows): create the psycopg2-binary package in Github 2025-01-04 19:06:56 +01:00
Daniele Varrazzo
fa24c922e7 ci(windows): build binary packages using the vcpkg package 2025-01-04 19:06:56 +01:00
Daniele Varrazzo
3c7889b0e7 chore: drop appveyor CI integration 2025-01-04 19:06:56 +01:00
Daniele Varrazzo
e83754a414 ci: work around the envionment breaking guard 2024-10-15 13:49:08 +02:00
Daniele Varrazzo
a805acf59f chore: bump to version 2.9.10 2024-10-15 10:40:56 +02:00
Daniele Varrazzo
78561ac99d
Merge pull request #1728 from romank0/fetch-notifications-on-commit
Adds notifies processing during commit
2024-10-11 03:13:56 +02:00
Daniele Varrazzo
5283a835dc chore: add TransactionTimeout error, added in PostgreSQL 17
Url to fetch source changed from the official Postgres one to the Github
mirror because the former throttled us.
2024-10-11 02:41:31 +02:00
Daniele Varrazzo
f64dd397fd docs: add news entry about notifications on commit 2024-10-11 00:29:28 +02:00
Roman Konoval
cba6d39be0 removes duplication in tests 2024-10-11 00:26:05 +02:00
Roman Konoval
282360dd04 adds notifications processing after every PQexec 2024-10-11 00:26:05 +02:00
Roman Konoval
362cb00978 Adds notifies processing in pq_commit 2024-10-11 00:24:37 +02:00
Daniele Varrazzo
eaeeb76944
Merge pull request #1729 from edgarrmondragon/1692-py313-wheels
Build Python 3.13 wheels, drop support for Python 3.7
2024-10-11 00:17:47 +02:00
Daniele Varrazzo
4987362fb4 ci(windows): drop Python 3.8 packages
The runner image to build 3.8 package doesn't seem to have a currently
supported database, and the previously used 9.6 is no more supported on
current runners.
2024-10-10 15:48:48 +02:00
Daniele Varrazzo
8c9a35de38 ci: test with PostgreSQL 17 2024-10-09 19:46:48 +02:00
Daniele Varrazzo
563b55a725 docs: bump supported versions to Python 3.13 and Postgres 17 2024-10-08 17:08:02 +02:00
Daniele Varrazzo
dac8fa5632 ci(win): use PostgreSQL 13 for tests
By latest errors, it seems that Postgres 9.6 is no more supported on
VS2019 image. By documentation, it also seem that Postgres 13 is the
most recent supported database and not available in VS2015 image.
Therefore, drop Python 3.8 test (and likely build).

See https://www.appveyor.com/docs/services-databases/#postgresql
2024-10-08 17:04:40 +02:00
Edgar Ramírez-Mondragón
e1cf23d9c7
Drop Python 3.7 in other places 2024-10-05 01:41:20 -06:00
Edgar Ramírez-Mondragón
0eccfbec47
Ensure pg data dir exists 2024-10-05 01:35:47 -06:00
Edgar Ramírez-Mondragón
26f0f13b39
Use py executable in appveyor 2024-10-05 01:29:06 -06:00
Edgar Ramírez-Mondragón
a59079a4f2
Build Python 3.13 wheels 2024-10-04 22:40:03 -06:00
Anoosh Dsouza
f9780aa054 fixed a typo in doc/src/usage.rst file 2024-09-19 20:56:05 +02:00
0xTiger
658afe4cd9 docs: tiny grammar fix "a" -> "one" 2024-07-17 18:44:43 +02:00
Daniele Varrazzo
f79867c9f2 chore: bump to next dev version 2024-07-14 22:01:17 +02:00
Daniele Varrazzo
dc5249ba01
Merge pull request #1695 from befeleme/py3.13
Add support for Python 3.13
2024-07-14 21:58:10 +02:00
Daniele Varrazzo
7c2706a8b4 docs: note Python 3.13 support in news file 2024-07-14 21:57:27 +02:00
Karolina Surma
4a4b5acdc2 Declare the support for Python 3.13 in classifiers 2024-04-26 09:21:05 +02:00
Karolina Surma
efc5ad01e0 Add Python 3.13.0a6 to tox matrix 2024-04-26 09:21:05 +02:00
Karolina Surma
866bcef589 Add Python 3.13.0a6 to CI 2024-04-26 09:21:05 +02:00
Karolina Surma
3b9aa7cf9f Fix tests with Python 3.13
The textual representation of addresses has changed, adapt the code to
expect different values on Python 3.13+.
See: https://github.com/python/cpython/commit/f22bf8e3cf899896cf587099d292
2024-04-24 10:15:54 +02:00
Karolina Surma
829a7a2be9 _PyInterpreterState_Get() has become public in Python 3.13
Since 3.13.0a1 it has been renamed to PyInterpreterStateGet()
Source: https://github.com/python/cpython/pull/106321
2024-04-24 10:15:50 +02:00
Nick Zandbergen
a971c11d50 Update lobject_type.c
Add bytes as accepted input for documentation
2024-02-15 22:26:05 +00:00
dependabot[bot]
00870545b7 build(deps): bump actions/setup-python from 4 to 5
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4 to 5.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-02 03:27:05 +00:00
dependabot[bot]
bf45060074 build(deps): bump actions/upload-artifact from 3 to 4
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3 to 4.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-02 03:26:43 +00:00
Daniele Varrazzo
5fb59cd6ee Merge branch 'macos-arm64-py312' 2023-11-01 11:45:52 +01:00
Daniele Varrazzo
e0d1daf290 Merge branch 'wheel-312-win' 2023-11-01 11:45:35 +01:00
Rene Leonhardt
941ac9a724 chore: add support for Python 3.12 macOS arm64 wheels 2023-11-01 11:33:30 +01:00
Rene Leonhardt
4e473010a3
chore: let dependabot update GitHub actions 2023-10-30 09:19:50 +00:00
Rene Leonhardt
8947b00142 chore: update GitHub actions and Postgres image tags 2023-10-29 18:05:30 +00:00
Daniele Varrazzo
46191f1fde ci(windows): add Python 3.12 to the testing grid 2023-10-28 11:41:40 +02:00
Daniele Varrazzo
e73d2fa9f0 ci(win32): install the setuptools package to build in appveyor
Present so far, it wasn't installed in the first image containing Python 3.12.
2023-10-28 01:57:56 +02:00
Daniele Varrazzo
89005ac5b8 docs: add README blurb pointing to psycopg 3 on PyPI
See #1632.
2023-10-10 23:35:40 +02:00
Panagiotis H.M. Issaris
bfdffc2c57
chore: show a Changelog link on PyPI 2023-10-06 15:05:42 +01:00
Daniele Varrazzo
ad5bee7054 chore: bump version number to 2.9.9 2023-10-03 11:39:35 +02:00
Daniele Varrazzo
37d1de1c8f chore: add support for Python 3.12 2023-10-03 11:39:35 +02:00
Daniele Varrazzo
abf2723c0a chore: drop support for Python 3.6 2023-10-03 11:39:35 +02:00
Daniele Varrazzo
2da65a715c chore: drop leftover Python 2.7 import aliases from setup.py 2023-10-03 11:39:35 +02:00
Daniele Varrazzo
3fa60fd268 chore: bump doc requirement complained by dependabot 2023-10-03 11:39:32 +02:00
Daniele Varrazzo
1c1484e43b ci: better interaction with scaleway build server 2023-10-03 11:39:32 +02:00
Daniele Varrazzo
c81cec604f chore: bump to next dev release 2023-10-03 11:20:17 +02:00
Daniele Varrazzo
7fe8cb77ca chore: bump docs requirements dependabot complains about 2023-09-28 09:29:21 +02:00
Daniele Varrazzo
b39d5d6492 chore: bundle libpq 16
- https://github.com/psycopg/psycopg/issues/650
- https://github.com/psycopg/psycopg/discussions/528
2023-09-28 09:26:33 +02:00
Daniele Varrazzo
921510d5be docs: replace "compiled against" with "bundled with" in news file
Less confrontational...
2023-09-28 09:22:08 +02:00
Daniele Varrazzo
999d7a6d01 test: skip ssl test if libpq runtime > 16
Close #1619
2023-09-11 16:11:07 +01:00
Daniele Varrazzo
3eee3e336d ci: fix passing env vars to build scripts 2023-08-04 17:28:24 +01:00
Daniele Varrazzo
1e0086b1fe chore: bump version to 2.9.7 2023-08-04 17:22:46 +01:00
Daniele Varrazzo
4fe28d661a Merge branch 'dev/init-failure' 2023-08-04 17:20:50 +01:00
Daniele Varrazzo
14e06d8185 docs: mention module init errors fix in news file 2023-08-04 17:20:02 +01:00
Jacob Champion
959339cefb Return NULL on failed module initialization
Previously, any exceptions raised during initialization were swallowed
with a message like

    SystemError: initialization of _psycopg raised unreported exception

Fixes #1598.
2023-08-04 17:19:58 +01:00
Daniele Varrazzo
fb77bdca0b Merge branch 'dev/fix-meson-build' 2023-08-04 17:19:41 +01:00
Daniele Varrazzo
ef7053c070 docs: add pg_config improvement to news file 2023-08-04 17:18:59 +01:00
Jacob Champion
ea71fbcd46 setup.py: handle more corner cases for pg_config
- Differentiate between unexpected empty values and execution failure.
- Accept empty --cppflags and --ldflags output. Fixes #1599.
- Accept UTF-8 output from pg_config, for alternative client locales.
2023-08-04 17:18:56 +01:00
Daniele Varrazzo
0c5b5f4ec3 chore: bump cibuildwheel version to 2.14.1 2023-08-04 17:18:17 +01:00
Daniele Varrazzo
20fcfd6786 chore: upgrade libpq and openssl versions used in packaging 2023-08-04 17:18:17 +01:00
Xing Guo
329f43c762 Use except psycopg2.Error as e in example. 2023-07-27 10:09:03 +01:00
Daniele Varrazzo
9f020124f8 docs: don't show objects in side bar
Too wide, too ugly, useless to navigate.

Close #1587
2023-06-07 12:09:12 +02:00
Christoph Berg
8b17e218be Disable test_ssl_attribute on PG16+
PG15 changed the semantics of some ssl attributes (#1506), and a very
similar regression test failure has now been observed again with PG16.
Disable the test for now.
2023-05-29 17:42:42 +02:00
Brent Wilkins
c96f991a8d Updated from deprecated license_file parameter 2023-05-25 19:01:27 +02:00
Amirsoroush
3450d159b5 fix typo in Usage.html page in documentation 2023-04-23 22:47:26 +02:00
Daniele Varrazzo
5108191aa5 chore: upgrade docs build dependencies 2023-04-17 20:11:47 +02:00
Daniele Varrazzo
638be85eb6 docs: drop use of print statement, use the print() function instead
Close #1556
2023-04-17 20:07:17 +02:00
Daniele Varrazzo
0b01ded426 ci: drop github download script
Easier to do interactively, now that all the artifacts are packaged in
the same archive.
2023-04-03 05:10:36 +02:00
Daniele Varrazzo
46238ba351 ci: fix cache key by setting lib versions in job env 2023-04-03 05:07:01 +02:00
Daniele Varrazzo
51dd59ef9d chore: drop Python 3.6 from Windows packages 2023-04-03 05:06:13 +02:00
Daniele Varrazzo
333b3b7ac4 ci: use cibuildwheel to build linux wheel packages 2023-04-02 17:56:29 +02:00
Daniele Varrazzo
7a8f4d6222 chore: bump version to 2.9.6 2023-04-02 13:00:38 +02:00
Daniele Varrazzo
b747b5b0fd ci: bundle all build artifacts in a single directory 2023-04-02 12:59:29 +02:00
Daniele Varrazzo
1781e8b2c9 build: package openssl 1.1.1t with binary packages 2023-04-02 12:47:29 +02:00
Daniele Varrazzo
fdb204b4e3 docs: mention manylinux2014 packages in news file 2023-04-02 12:47:25 +02:00
Daniele Varrazzo
09b82e4094 ci: bump qemu action version to drop node deprecation warning 2023-03-30 17:09:23 +02:00
Daniele Varrazzo
97df29a312 ci: build macOS packages using cibuildwheel
Close #1558.
2023-03-30 13:31:30 +02:00
Daniele Varrazzo
daeec37fab
Merge pull request #1545 from AmirBitaraf/aarch64_manylinux2014_libpq
Move to manylinux2014 for aarch64, ppc64le builds.
2023-03-27 17:11:28 +02:00
Amir Bitaraf
c0666b0935 Modify LD_LIBRARY_PATH to support all architectures 2023-03-26 18:35:00 +01:00
Amir Bitaraf
cc21faa4f4 Move to manylinux2014 for aarch64, ppc64le builds. 2023-03-26 18:35:00 +01:00
Daniele Varrazzo
63947e2552 ci: drop test on Python 3.6
The image is not available anymore
2023-02-25 16:07:21 +01:00
Daniele Varrazzo
52df8371f3 ci: pin tox to v3
Not interested in fixing incompatibility changes.
2023-02-25 16:05:14 +01:00
Daniele Varrazzo
feeb989323 docs: use https url in license file
Close #1549.
2023-02-25 15:36:35 +01:00
Daniele Varrazzo
e8d92b74fd Merge branch 'py311-win32' 2022-11-07 23:42:28 +01:00
Daniele Varrazzo
026b5bf3ab ci: re-enable builds suspended for build win32 packages for Python 3.11 2022-11-07 23:41:50 +01:00
Daniele Varrazzo
02b5e226f4 ci: build packages for Python 3.11 for Workgroup... for Windows! 2022-11-07 22:38:07 +01:00
Daniele Varrazzo
57009707b1 ci: Test Python 3.11 on Appveyor 2022-11-07 22:32:56 +01:00
Daniele Varrazzo
3182ea2303 ci: adapt macOS arm64 build script to changes in Python 3.11 and PostgreSQL 15 2022-10-27 00:41:09 +02:00
Daniele Varrazzo
ea32730a39 Merge branch 'build-macos-py311' 2022-10-27 00:40:23 +02:00
Daniele Varrazzo
deb00e5454 ci: re-enable builds suspended to build macOS packages for Python 3.11 2022-10-27 00:39:11 +02:00
Daniele Varrazzo
8c824d0e47 Build packages for macOS x86_64 Python 3.11
The required images weren't available at the time of building the other
packages. See #1514.

The changeset includes temporary changes to skip other builds. They will
be reverted before merging.
2022-10-27 00:28:04 +02:00
Daniele Varrazzo
1bf8e77ea2 chore: remove macOS 3.11 build from build grid
Not available yet on Github: see build failure at
https://github.com/psycopg/psycopg2/actions/runs/3320363567/jobs/5486654852
2022-10-25 13:34:29 +02:00
Daniele Varrazzo
af3ee06ec0 chore: upgrade Github action versions 2022-10-25 13:04:28 +02:00
Daniele Varrazzo
963fb1190b chore: fix yaml syntax in Github Action workflow 2022-10-25 12:59:23 +02:00
Daniele Varrazzo
27a99dac72 chore: bump version number to release 2.9.5 2022-10-25 12:55:57 +02:00
Daniele Varrazzo
78690cfaf8 lint: reformat appveyor yaml 2022-10-25 12:54:34 +02:00
Daniele Varrazzo
259d15ae3e chore: build binary packages with OpenSSL 1.1.1q 2022-10-25 12:47:46 +02:00
Daniele Varrazzo
77039cad63 chore: fix directory where to find binary package after build 2022-10-25 12:47:02 +02:00
Daniele Varrazzo
e6e465c509 chore: build binary packages using libpq from PostgreSQL 15
fix #1497 as a side effect of using libpq 15.
2022-10-25 12:47:02 +02:00
Daniele Varrazzo
12700a5f02 Build packages for Python 3.11 2022-10-25 12:37:23 +02:00
Daniele Varrazzo
271dd1fce7 chore: move cache_rebuild file into appveyor dir 2022-10-25 12:24:10 +02:00
Daniele Varrazzo
e4b2a197c6 chore: bump to next dev version 2022-10-25 12:20:46 +02:00
Daniele Varrazzo
20bb486663 Merge branch 'doc_examples_executemanybatch' 2022-10-20 21:33:46 +02:00
Daniele Varrazzo
f401d0b738 docs: fix reST syntax and whitespace in executemany examples 2022-10-20 21:31:18 +02:00
Ion Alberdi
4912be0e7f [test_basic_types] Add test for array[%s] on NULL arrays
Add test to verifity the fix for #1507.
2022-10-11 13:02:22 +01:00
Hannes
aabac5df31
Add executemany & execute_batch examples 2022-10-10 19:08:46 +02:00
Daniele Varrazzo
a12dbc4357 docs: fix typos in release notes 2022-10-06 03:58:50 +01:00
Daniele Varrazzo
bc82c8f9cc fix: set default SYSCONFDIR to the quasi-standard /etc/postgresql-common
Fix #1365.
2022-10-06 03:49:25 +01:00
Daniele Varrazzo
c38aa27d7d chore: bump version number to release 2.9.4 2022-10-06 03:32:17 +01:00
Daniele Varrazzo
bd96594e2d docs: add link to release notes page to find which Python version is supported
Close #1418.
2022-10-06 03:27:40 +01:00
Daniele Varrazzo
182a51a33f chore: upgrade packaged libpq version and dependencies
appveyor.cache_rebuild reformatted for greppability.
2022-10-06 03:27:40 +01:00
Daniele Varrazzo
76b703e910 Merge branch 'pg15' 2022-10-06 02:59:28 +01:00
Daniele Varrazzo
29a65f756c chore: upgrade error codes to PostgreSQL 15 2022-10-06 02:26:09 +01:00
Daniele Varrazzo
6d815f5df9 test: adapt ssl test to libpq 15
See #1506, PostgreSQL bug 17625
(https://www.postgresql.org/message-id/17625-fc47c78b7d71b534%40postgresql.org)
2022-10-06 02:09:19 +01:00
Daniele Varrazzo
c7326f8da7 test: add PostgreSQL 15 to the test grid 2022-10-06 02:09:19 +01:00
Daniele Varrazzo
68d786b610 Merge branch 'fix-1487' 2022-10-06 02:09:06 +01:00
Daniele Varrazzo
7054e1aadf test: add test to verify register_range() with names requiring escape
Unlike for register_composite(), this works already.
2022-10-06 02:05:49 +01:00
Daniele Varrazzo
ac25d3bdc0 fix: look up for range types defined in schemas in the search path 2022-10-06 02:05:39 +01:00
Daniele Varrazzo
9535462ce9 fix: correctly handle composites with names or schema requiring escape 2022-10-06 01:56:28 +01:00
Daniele Varrazzo
d88e4c2a3c fix: handle types in the search path in register_composite()
Fix #1487.
2022-10-06 01:10:07 +01:00
Daniele Varrazzo
31a80410db chore: bump to next dev release 2022-10-06 00:21:27 +01:00
Daniele Varrazzo
d6c81b4ff0 docs: mention MacOS ARM wheel support 2022-10-05 19:48:04 +01:00
Magnus Watn
c6f30880a2 Remove Apple M1 bullet point from issue template
https://github.com/psycopg/psycopg2/issues/1286 is now closed.
2022-10-03 10:09:46 +01:00
Daniele Varrazzo
e3664380c4 build: fix starting Postgres in macOS build script
The brew command fails with:

    Could not enable service: 125: Domain does not support specified action
    Error: Failure while executing; `/bin/launchctl enable gui/501/homebrew.mxcl.postgresql@14` exited with 125.
2022-09-25 02:49:16 +01:00
Daniele Varrazzo
fdf957dcbd build: use "latest" version of github builders 2022-09-25 02:46:21 +01:00
Nikita Sobolev
3e7bb8d1aa Remove __nonzero__ method 2022-07-30 14:03:10 +02:00
Tim Tisdall
07c83ef8bb Link to the right PR for adding alpine wheels 2022-07-28 14:39:33 +02:00
Daniele Varrazzo
f07b3ad0a6 Merge branch 'build-macos-arm64' 2022-07-28 13:30:32 +02:00
Daniele Varrazzo
611c610041 docs: fixed quote_ident() example
Close #1481
2022-07-27 02:54:17 +02:00
Daniele Varrazzo
25c40f8ac3 build: add scripts to build macOS arm64 packages 2022-07-17 00:20:08 +01:00
Daniele Varrazzo
ba92a22bc9 test: drop test table if exist
It might be a residue of a psycopg 3 test run in the same db.
2022-07-16 23:58:43 +01:00
Rafi Shamim
3c58e96e10 Unskip tests that work on CockroachDB v22.1
CockroachDB supports named cursors in v22.1, so more tests pass.
2022-03-28 20:26:23 +02:00
Daniele Varrazzo
626078388a Use pip-tools to create the requirement file to build the docs
Docs building just broke. The requirement file had some version upper
boundary that caused problems between Sphinx and jinja2.
2022-03-26 02:45:40 +01:00
Daniele Varrazzo
c34bf2f2f9 Bump to release 2.9.3 2021-12-29 13:48:23 +01:00
Daniele Varrazzo
94ba06748f Merge branch 'musllinux' 2021-12-29 13:36:25 +01:00
Peter Lithammer
c5528da2dc
Mention Alpine/musl wheels in news file 2021-12-10 17:21:34 +01:00
Peter Lithammer
2dc137975a
Build musllinux wheels 2021-12-10 17:21:34 +01:00
Daniele Varrazzo
bc79abace1 Bump to next dev release 2021-12-10 14:28:04 +01:00
Daniele Varrazzo
846ae52ab2 Create parent directories too in artifacts download 2021-12-10 14:26:06 +01:00
Daniele Varrazzo
217f4120ca Strip debug symbols from binary packages
The _psycopg.so library goes down from 1.6mb to 300k in Linux packages.
2021-12-10 14:26:06 +01:00
John Vandenberg
4d4d2bc444 Include sys/time.h for gettimeofday
Fixes https://github.com/psycopg/psycopg2/issues/1397
2021-12-03 11:29:39 +01:00
John Vandenberg
4b637ec34a PyPy does not have PyDateTime_TimeZone_UTC
Fixes https://github.com/psycopg/psycopg2/issues/1398
2021-12-03 11:29:21 +01:00
Will Thompson
53bda13afa Fix typo in large object usage documentation 2021-11-21 16:10:42 +01:00
Daniele Varrazzo
8ef195f2ff Bump version number to release 2.9.2 2021-11-11 21:16:12 +01:00
Daniele Varrazzo
1b013b529b Merge branch 'py311' 2021-11-11 21:14:28 +01:00
Daniele Varrazzo
0a4a469669 Mention Python 3.11 preliminary support in the newsfile. 2021-11-11 21:13:38 +01:00
Cyril Jouve
5fb1305a14 support for python 3.11 2021-11-11 21:13:38 +01:00
Daniele Varrazzo
898cbff5a6 Build binary packages against PosgtgreSQL 14.1 lipq
Close #1388.
2021-11-11 21:11:59 +01:00
Daniele Varrazzo
7dd193a7f7 errorcodes map and errors classes updated to PostgreSQL 14. 2021-11-11 20:08:39 +01:00
Daniele Varrazzo
1a0c02a6f4 Raise an error for dates > 10K instead of returning Y9999
Close #1307.
2021-11-11 20:01:14 +01:00
Daniele Varrazzo
1454b14ae0 Fix Python 3.10 and PostgreSQL 14 compatibility notes 2021-11-05 18:37:58 +01:00
Daniele Varrazzo
8e186dd7e9 Merge branch 'py310' 2021-11-03 14:18:09 +01:00
Daniele Varrazzo
7236a1f851 Fix f-string in Appveyor package download script 2021-11-03 14:16:38 +01:00
Daniele Varrazzo
63d30aa397 Add Python 3.10 to Appveyor test grid 2021-11-03 14:16:38 +01:00
Daniele Varrazzo
6b80bd0648 Drop Windows exe package build 2021-11-03 14:16:38 +01:00
Daniele Varrazzo
5a96021612 Fix issue template markup 2021-10-30 22:57:12 +02:00
Daniele Varrazzo
4a46aa39a5 Build Python 3.10 packages of relase 2.9.1 2021-10-11 23:32:30 +02:00
Daniel Saxton
3430dcdee6 Fix doc typo 2021-09-22 12:56:08 +01:00
Daniele Varrazzo
1b255b7dc3 Fix up-date-date typo
Close #1336
2021-08-07 20:53:54 +01:00
Daniele Varrazzo
52c4d6fad4 Add psycopg version to issue templates 2021-07-17 14:26:54 +02:00
Daniele Varrazzo
ee3a069f1d Maintainer email fixed
gmail.org!
2021-07-16 14:50:08 +02:00
Daniele Varrazzo
9cfe80ea55 Drop unwanted issue template 2021-07-14 12:22:58 +02:00
Daniele Varrazzo
64b159676f Add issue templates 2021-07-14 12:22:00 +02:00
Daniele Varrazzo
8fe9861df5 Add docs anchor to reach the 'with' statement from psycopg3 docs 2021-07-14 02:32:22 +02:00
Daniele Varrazzo
39f12bbfc5 Don't build .exe packages anymore 2021-06-30 14:52:27 +01:00
Daniele Varrazzo
47b93efcf8 Note in the docs that now the table and fields names are escaped. 2021-06-17 16:52:44 +01:00
Daniele Varrazzo
7749898a94 Drop script to update docs on travis 2021-06-17 13:37:20 +01:00
Daniele Varrazzo
46bc175cc7 Trigger docs update to the website build workflow on GitHub Action 2021-06-17 12:54:36 +01:00
Daniele Varrazzo
dd9c6659bc Fix building docs for the website 2021-06-17 03:54:14 +01:00
Daniele Varrazzo
62490a6bcc Allow to specify the build to download from Appveyor 2021-06-17 03:54:14 +01:00
Daniele Varrazzo
c59ff6a4b7 Don't require the virtualenv binary to build the docs 2021-06-17 01:42:42 +01:00
Daniele Varrazzo
b241def64b Fix representation of sql.Placeholder
Fix also Placeholder tests, including an error which made an assert
always true, which made us miss the regression in #1291.
2021-06-17 00:28:14 +01:00
Daniele Varrazzo
2df79c5a5f Bump version number to 2.9.1 2021-06-17 00:06:04 +01:00
Daniele Varrazzo
dd2ff2af56 Fix regression with named sql.Placeholder
Close #1291.
2021-06-16 23:56:05 +01:00
Daniele Varrazzo
b46424447f Bump to next dev release 2021-06-16 23:56:05 +01:00
Daniele Varrazzo
bab166e2c1 Fix spelling in news file 2021-06-16 17:08:06 +01:00
Daniele Varrazzo
c5aa98d8bc Add note about cursor.callproc() and PostgreSQL procedures
Close #1155
2021-06-16 16:51:13 +01:00
Daniele Varrazzo
cbbf195a23 Tweak package paths in release docs 2021-06-16 16:38:12 +01:00
Daniele Varrazzo
2b7383c9f9 Build docs from the master branch 2021-06-16 16:37:59 +01:00
Daniele Varrazzo
50145014e8 Bump to versio 2.9 2021-06-16 13:28:31 +01:00
Daniele Varrazzo
9ac54b3615 Move appveyor build support to the scripts/build dir 2021-06-15 18:57:22 +01:00
Daniele Varrazzo
f5d6366287 Rename the github package download script for consistency 2021-06-15 18:54:45 +01:00
Daniele Varrazzo
bbc5fd3180 Drop obsolete file to build Windows packages 2021-06-15 18:42:25 +01:00
Daniele Varrazzo
9e5847222d Upgrade libpq to 13.3 and libssl to 1.1.1k on windows too 2021-06-15 18:42:25 +01:00
Daniele Varrazzo
cefb818105 Build manylinux2014 packages for i686/x86_64 platforms
The manylinux_2_24 tag leaves too many users without usable packages.
Using this tag requires to build libraries too or a libssh too old will
be used, with the segfault risks seen in the past.

OTOH building all the libraries on arm/ppc platforms proves very time
consuming and requires further tooling than what available in the image.
Because these packages are new it seems ok to use the manylinux_2_24
tag and use the package versions of libpq/libssl.
2021-06-15 18:42:25 +01:00
Daniele Varrazzo
37ab1d8877 Bump to a new dev version number to try to release new packages 2021-06-15 18:28:13 +01:00
Daniele Varrazzo
1d3a89a0bb Copyright year updated to 2021
ag -l Copyright | xargs sed -i \
    "s/\(.*copyright (C) [0-9]\+\)\(-[0-9]\+\)\?\(.*Psycopg Team.*\)/\1-$(date +%Y)\3/I"
2021-06-15 00:37:22 +01:00
Daniele Varrazzo
af05c3a1ec Merge branch 'timezone-seconds' 2021-06-15 00:25:55 +01:00
Daniele Varrazzo
1d3d5e905f Deprecate the psycopg2.tz module
Don't use its objects anymore in the tests (except for the tests for the
objects themselves).
2021-06-15 00:22:54 +01:00
Daniele Varrazzo
f28502663f Use datetime.timezone as default tzinfo_factory. 2021-06-15 00:17:14 +01:00
Daniele Varrazzo
2eac70786e Drop support for mx.DateTime objects
They are Python 2 only.
2021-06-14 23:05:48 +01:00
Daniele Varrazzo
476a969bd8 Handle correctly timestamps with fractions of minute in the timezone offset
Close #1272.
2021-06-14 22:25:02 +01:00
Daniele Varrazzo
5667026883 Use a stdlib timezone in TimestampFromTicks
This is the only use of `LocalTimezone` in psycopg2 code.
2021-06-14 19:22:59 +01:00
Daniele Varrazzo
521981584d Clean up the packaging procedure 2021-05-29 21:57:26 +01:00
Daniele Varrazzo
06c3c3a557 Merge branch 'packages' 2021-05-26 17:29:03 +01:00
Daniele Varrazzo
808007456d Document the new way of building packages 2021-05-26 17:28:14 +01:00
Daniele Varrazzo
a9db3228d3 One line about the new packages in the news file 2021-05-26 17:28:14 +01:00
Daniele Varrazzo
52cd94442c Add include and lib dirs from libpq --cppflags, --ldflags
They seem the right thing to fix MacOS build woes.

Inspired to #935, might close #1200.
2021-05-26 17:28:14 +01:00
Daniele Varrazzo
d116b80c5f Add script to download packages from appveyor 2021-05-26 17:28:14 +01:00
Daniele Varrazzo
e7ce6761e1 Use Appveyor to build Windows packages
The script was executed both by this repos' appveyor config (to run the
tests) and by the psycopg2-wheels config (to build the packages). Now
there are two different workflows to execute for tests and to build packages.

The only way to swap them is to change the project config it seems, in
<https://ci.appveyor.com/project/psycopg/psycopg2/settings>.
2021-05-26 17:26:00 +01:00
Daniele Varrazzo
efae570a07 Build MacOS packages on GitHub Actions 2021-05-26 17:23:40 +01:00
Daniele Varrazzo
d1c7e6a094 Add script to download packages from GitHub 2021-05-26 17:23:40 +01:00
Daniele Varrazzo
9b91b09f9c Enable qemu to build arm/ppc packages on github 2021-05-26 17:23:40 +01:00
Daniele Varrazzo
b5dd3aae86 Build packages for Python >= 3.6 2021-05-26 17:23:40 +01:00
Daniele Varrazzo
367ea40b1e Allow libpq tests to fail
They fail on image build when we delete the system library.
2021-05-26 17:23:40 +01:00
Daniele Varrazzo
ec531bee31 Create sdist packages
Adapted from the psycopg2-wheels project
2021-05-25 23:23:27 +01:00
Daniele Varrazzo
8a2deb39ed Escape table and column names in cursor.copy_from() and .copy_to() 2021-05-25 11:50:23 +01:00
Daniele Varrazzo
e5ad0ab2d9 'with' starts a transaction even on autocommit connections
Close #941
2021-05-24 14:13:19 +02:00
Daniele Varrazzo
d8e6426433 Fix formatting of last entries in the NEWS file 2021-05-24 14:11:06 +02:00
Daniele Varrazzo
506a10026a Remove configuration for unused VS versions in appveyor build 2021-05-24 11:17:01 +02:00
Daniele Varrazzo
cb12317d21 Drop use of obsolete alias PyMem_Del 2021-05-24 11:15:24 +02:00
Daniele Varrazzo
e7c5f95bf6 Merge branch 'github-actions' 2021-05-22 17:21:06 +02:00
Daniele Varrazzo
09d6e3cf64 Use GitHub Actions badge in the readme 2021-05-22 17:20:54 +02:00
Daniele Varrazzo
5d19c6ef7e Update GitHub Actions as on branch main_2_8
Drop Python version not supported on master.
Drop Travis workflow on master branch too.
2021-05-22 17:20:12 +02:00
Riccardo Magliocchetti
9dbe8c6757 ci: first stab at running CI as github actions
Props to Adam Chainz for sharing its setup.
2021-05-22 16:51:53 +02:00
Yusuke Hayashi
fed22d39e9 Fix typo 2021-05-22 14:30:11 +02:00
Daniele Varrazzo
19ddbc47ca Merge branch 'rm-2.7' 2021-05-20 16:59:43 +02:00
Daniele Varrazzo
cdc83d64db Add Python 3.9 to travis test grid, drop 2.7 2021-05-20 16:58:46 +02:00
Daniele Varrazzo
3db4abcfa4 Unbreak f-string wrong replacements 2021-05-20 16:49:05 +02:00
Daniele Varrazzo
8f40c648af Merge branch 'master' into rm-2.7 2021-05-20 16:36:55 +02:00
Chris Wilson
45599b2716 Add warning about send_feedback and cursor choice 2021-05-20 16:33:00 +02:00
Hans Ginzel
787a7b90ae cursor.rst typo: was creates
name attribute: “cursor was creates” → “was created”
2021-05-20 16:26:08 +02:00
Daniele Varrazzo
55aef83fa1 Merge branch 'sqlstate_errors' 2021-05-20 16:17:47 +02:00
Daniele Varrazzo
3487f627e2 Mention sqlstate reinit in NEWS file 2021-05-20 16:16:51 +02:00
Sandro Mani
f59d626fe3 Don't re-initialize psycoEncodings if already initialized 2021-05-20 16:14:24 +02:00
Sandro Mani
22575528be Don't abort if sqlstate_errors already initialized 2021-05-20 16:14:24 +02:00
Daniele Varrazzo
0f457a01d9 Fix NEWS typo 2021-05-20 13:12:46 +02:00
Daniele Varrazzo
8ea5d0c0b8 Fix segfault initialising Column object manually
Close #1252
2021-05-20 13:10:59 +02:00
Daniele Varrazzo
391386cfb9 Accept no param in connect()
More friendly towards ``connect(**parse_dsn())``, and what psycopg3 does.

Close #1250
2021-05-20 13:10:53 +02:00
Tim Gates
0d7953a521 docs: fix a few simple typos
There are small typos in:
- doc/src/faq.rst
- psycopg/cursor_type.c
- psycopg/xid_type.c
- scripts/make_errorcodes.py
- scripts/make_errors.py
- tests/dbapi20.py
- tests/test_connection.py

Fixes:
- Should read `publicly` rather than `publically`.
- Should read `unicode` rather than `uniconde`.
- Should read `supposed` rather than `suppsed`.
- Should read `something` rather than `somenthing`.
- Should read `portable` rather than `portible`.
- Should read `exhausted` rather than `exausted`.
- Should read `compliance` rather than `compiliance`.

Closes #1275
2021-05-20 12:22:47 +02:00
Rafi Shamim
73969ba3e7 Skip test_encrypt_server for CockroachDB 2021-04-21 12:56:54 +01:00
arulajmani
f469331af5 Skip test_9_6_diagnostics test for CRDB
Previously, the CRDB's pg server version was 9.5, which meant this test
wasn't run as it is skipped for versions 9.6 and before. Now that the
server version of CRDB is 13, this check no longer applies.

This patch explicitly skips test_9_6_diagnostics for CRDB. The reason
for this is the same as test_9_3_diagnostics, which is currently
skipped for CRDB.
2020-12-16 23:41:45 +00:00
Hugo van Kemenade
8830e30f73
Merge branch 'master' into rm-2.7 2020-11-18 18:10:16 +02:00
Hugo van Kemenade
c3b65d63b6 Upgrade f-strings with flynt -a and remove int() 2020-11-18 18:09:08 +02:00
Daniele Varrazzo
e85ef2298b Merge branch 'connection_exception' 2020-11-17 22:45:52 +00:00
Hugo van Kemenade
8d7f660309 Upgrade f-strings with flynt 2020-11-17 23:52:11 +02:00
Daniele Varrazzo
8449844af3 Merge branch 'pg13-win' 2020-11-17 21:07:52 +00:00
Hugo van Kemenade
d956eaa3b1 Drop support for EOL Python 2.7 2020-11-17 22:53:44 +02:00
Hugo van Kemenade
7babeccbec Upgrade Python syntax with pyupgrade --py36-plus 2020-11-17 22:22:11 +02:00
Hugo van Kemenade
6c48b63ae4 Drop support for EOL Python 2.7 2020-11-17 22:22:11 +02:00
Sergey Golitsynskiy
b05a581931 Fix typo in sample code: psycopg >> psycopg2 2020-11-17 20:19:26 +00:00
Hugo van Kemenade
694a20fb95
Drop support for EOL Python 3.5 (#1197) 2020-11-17 20:17:12 +00:00
Daniele Varrazzo
490c53bace
Merge pull request #1000 from hugovk/rm-3.4
Drop support for EOL Python 3.4
2020-11-17 16:28:47 +00:00
Justas Sadzevicius
cdca0a20e0 Classify connection exceptions as operational errors to better conform with PEP 249 2020-11-17 18:02:06 +02:00
Hugo van Kemenade
60ed2770f3
Merge branch 'master' into rm-3.4 2020-11-17 18:01:04 +02:00
Daniele Varrazzo
8764a85320 Mention Python 3.9 supported
See #1183
2020-11-16 11:53:30 +00:00
Jason Erickson
f1dfbd59af Build against PostgreSQL 13.0 and removed Py27/34
PostgreSQL 12 and 13 do not support older Microsoft Visual Studio compilers
and therefore we can not build against Python 2.7 and Python 3.4
2020-11-13 12:24:12 -07:00
Jason Erickson
e3f8cf0702 Remove old patch for Postgres 9.6 and OpenSSL 1.1 2020-11-13 12:22:38 -07:00
Hugo van Kemenade
d8aa60221d
Merge branch 'master' into rm-3.4 2020-11-13 21:22:26 +02:00
Jason Erickson
12b1432fe1 Build more OpenSSL binaries and add to path
More recent verions of the PostgreSQL source code requires some OpenSSL
binaries to be on the PATH.
2020-11-13 12:17:48 -07:00
Jason Erickson
f5e870dcc0 Combine included libraries into one parameter
build_ext only grabs one '-l' parameter, not multiple, which is weird as
one time I thought it did.
2020-11-13 12:05:20 -07:00
Daniele Varrazzo
87dc783bc6
Merge pull request #1190 from martinfrancois/master
Add support for PostgreSQL 13 (final)
2020-11-13 01:00:57 +00:00
martinfrancois
8c50af551d update supported postgresql versions to include 13 2020-11-13 00:40:14 +01:00
martinfrancois
b125d9dd66 add postgresql 13 to the build matrix 2020-11-13 00:40:14 +01:00
Hugo
d04a420bce Drop support for EOL Python 3.4 2020-11-10 08:44:42 +02:00
Daniele Varrazzo
f900fa4960 Bump to new major release development line on master 2020-11-09 23:17:56 +00:00
Daniele Varrazzo
7ad357599f Merge branch 'py39-appveyor' 2020-11-04 21:22:45 +01:00
Jason Erickson
31b37685b7 Settings for Py39/VS2019 builds + OpenSSL update 2020-11-04 21:21:58 +01:00
Jason Erickson
163dadb6c6 Add Strawberry Perl to the path 2020-11-04 21:21:58 +01:00
Jason Erickson
ec39e1e406 Add VC 2019 path location 2020-11-04 21:21:58 +01:00
Daniele Varrazzo
7cd7b97d5d First batch of changes to build on appveyor with Python 3.9 2020-11-04 21:20:27 +01:00
Jannis Vamvas
616dab7064 Remove semicolon from code example 2020-10-20 18:07:51 +02:00
Daniele Varrazzo
f54cf3b87b Bump to next dev release 2020-09-06 17:24:33 +01:00
Daniele Varrazzo
dd97344149 Suggest how to auto-generate tag name in release doc 2020-09-06 17:24:04 +01:00
Daniel Fortunov
171371da5a Minor spelling and grammar corrections for 195b254 2020-09-06 17:23:37 +01:00
Daniele Varrazzo
b203be11a6 Bump version to 2.8.6 2020-09-05 23:29:47 +01:00
Daniele Varrazzo
dc007e790a Metion ARM packages in news file 2020-09-05 22:07:26 +01:00
Daniele Varrazzo
dec28a21ac 'cursor.query' reports the query of the last COPY opearation too
Close #1141.
2020-09-05 21:47:35 +01:00
Daniele Varrazzo
dd1724c447 Errors mapping updated to PostgreSQL 13 2020-09-05 20:26:19 +01:00
Daniele Varrazzo
c203d681c4 Added duplicate values to errcodes module
Close #1133
2020-09-05 20:26:19 +01:00
Daniele Varrazzo
58c6a07e43 Errors fetch scripts ported to Python 3 2020-09-05 20:26:19 +01:00
Daniele Varrazzo
195b254937 Improve wording around transactions behaviour closing connections
The transaction is not rolled back by the connection, rather discarded
by the server.

Close #1135.
2020-09-05 19:16:50 +01:00
Daniele Varrazzo
0ee9d840a1 Document context manager usage in connection and cursor docs
Close #1143
2020-09-05 18:51:33 +01:00
Daniele Varrazzo
9387bd3c09 Mention building wheels package with OpenSSL 1.1.1g in news file 2020-09-05 18:04:45 +01:00
odidev
6de8c0c6d2 Add ARM64 jobs in Travis-CI
Signed-off-by: odidev <odidev@puresoftware.com>
2020-08-25 06:37:53 +00:00
Daniele Varrazzo
f7618f8bf5
Merge pull request #1120 from bashtanov/dictcursor-docs-improvement
DictCursor docs improvement
2020-08-24 01:56:17 +01:00
Daniele Varrazzo
3aadecebaa
Merge pull request #1131 from jouve/py3.10compat
use Py_SET_TYPE for compat with python 3.10
2020-08-24 01:54:57 +01:00
Daniele Varrazzo
90e8c80ed1 Merge branch 'docs/quick-start' 2020-08-24 01:48:50 +01:00
Daniele Varrazzo
82d679cdb3 A few corrections to the install page
Spacing, lines length, a spurious link targed, reST formatting.
2020-08-24 01:48:31 +01:00
Daniele Varrazzo
b0ddf6ea90 Merge branch 'cockroachdb-tests' 2020-08-18 20:55:13 +01:00
Daniele Varrazzo
423a663306 Python 2 compatibility 2020-08-17 23:50:04 +01:00
Daniele Varrazzo
f339bb30fb Added possibility to skip a test only on certain crdb versions 2020-08-17 23:08:05 +01:00
Daniele Varrazzo
5d2e51e76e Added ticket numbers for the tests skipped on crdb 2020-08-17 22:31:48 +01:00
Daniele Varrazzo
6d8382b7ed Added missing reasons for crdb skip
Added check to make sure a reason must be passed.
2020-08-17 21:27:25 +01:00
Edan Schwartz
9c30fdbc63 minor typo in docs 2020-08-10 09:18:45 -05:00
Edan Schwartz
ed3d44562d Move pyscopg-binary install docs to "quick start" section
This is the fastest way for most folks to get up-and-running
with psycopg. We've seen a lot of noise in the GH issues with people
failng to install the non-binary version. Hopefully this will
make life easier for people new to psycopg/python.

See https://github.com/psycopg/psycopg2/issues/1085#issuecomment-659028139
2020-08-07 15:05:45 -05:00
Daniele Varrazzo
513b0019b1 TeamCity commit hook test 2020-08-04 22:29:24 +01:00
Daniele Varrazzo
6eb4fab1db Added reason for skipping on CockroachDB 2020-07-27 23:03:26 +01:00
Cyril Jouve
442f300e91
use Py_SET_TYPE for compat with python 3.10 2020-07-26 15:41:53 +02:00
Daniele Varrazzo
5e957daa82 Types tests adapted to CockroachDB 2020-07-23 01:56:58 +01:00
Daniele Varrazzo
c8697e6c67 Several other tests skipped for CockroachDB
The only remaining test modules in this branch are test_types_basic/extra.
2020-07-22 02:43:19 +01:00
Daniele Varrazzo
a9153ac373 Some extra cursors test skipped on CockroachDB
Skip named cursor tests
2020-07-22 02:14:18 +01:00
Daniele Varrazzo
701637b5fa Skip a few date tests on CockroachDB
- Infinity gets converted to large dates in the past/future out of
  Python range
- Timestamps get an UTC timezone attached
2020-07-22 02:05:05 +01:00
Daniele Varrazzo
5ccd977e2b Cursor tests adapted to CockroachDB
Named cursor tests separated to skip all in one go
2020-07-21 22:23:27 +01:00
Daniele Varrazzo
9380f2a721 Get CockroachDB version from the connection info 2020-07-21 22:22:58 +01:00
Daniele Varrazzo
7e1e801899 Skip copy tests on CockroachDB 2020-07-21 22:22:55 +01:00
Daniele Varrazzo
e154cbe5aa Skip connection tests which cannot pass on CockroachDB
Features not supported seem:

- isolation level (always serializable)
- client encodings
- notices (maybe there is a way to generate them)
- 2 phase commit
- reset (because of the lack of transaction deferrable)
- backend pid
2020-07-21 22:22:23 +01:00
Daniele Varrazzo
bca72937d8 Expose libpq PG* vars as testconfig content 2020-07-21 22:21:44 +01:00
Daniele Varrazzo
f8c1cff6a3 Skip cancel tests on CockroachDB
One test moved to the async tests module, as it really belongs there.
2020-07-21 22:21:32 +01:00
Daniele Varrazzo
ee34198bf6 All the sync tests pass on CockroachDB
Added decorator to skip tests on crdb
2020-07-21 22:21:24 +01:00
Daniele Varrazzo
659910ee81 Allow most of the async tests to pass on CockroachDB
Added function to get crdb version from a connection
2020-07-21 01:43:57 +01:00
Daniele Varrazzo
cecff195fc
Merge pull request #1127 from rafiss/iso-level-finally-block
Handle failure in setup of IsolationLevelsTestCase
2020-07-08 20:35:01 +01:00
Rafi Shamim
a61f30b2d2 Handle failure in setup of IsolationLevelsTestCase
If the CREATE TABLE statement fails, the setup would fail
without committing or rolling back the active transaction, so the
transaction would hold onto its resources indefinitely.

Normally, the transaction would be closed when the connection is closed
in the `tearDown` function. However, `tearDown` is not called if there
was an error during `setUp` ([as specified by the `unittest` docs](https://docs.python.org/3/library/unittest.html#unittest.TestCase.tearDown)), so
we need to handle this case specially.
2020-07-07 18:48:44 -04:00
Alexey Bashtanov
96f0f63de2 dictcursor-docs-improvement 2020-06-18 15:40:45 +01:00
Daniele Varrazzo
779a1370ce
Merge pull request #1105 from rafiss/with-block-connection-test
Handle failure in setup of ConnectionTwoPhaseTest
2020-05-30 04:43:26 +12:00
Daniele Varrazzo
1092d437c0
Merge pull request #1111 from cjolif/master
use new URL for psycogreen
2020-05-29 01:37:06 +12:00
Christophe Jolif
1afbaf495e use new URL for psycogreen 2020-05-28 14:11:34 +02:00
Daniele Varrazzo
a9b814cb53
Merge pull request #1110 from UpGado/patch-1
Fix ctypes doc example AttributeError
2020-05-27 22:25:15 +12:00
Dio Gado
ac488acee3 Fix ctypes example AttributeError 2020-05-27 05:39:53 -04:00
Rafi Shamim
f935476b3f Handle failure in setup of ConnectionTwoPhaseTest
Previously, this test had a bug, because if the CREATE TABLE statement
failed, the setup would fail without committing or rolling back the
active transaction.
2020-05-12 12:48:35 -04:00
Daniele Varrazzo
14355e9c69
Merge pull request #1103 from franciscouzo/patch-1
Fix typo
2020-05-07 19:39:48 +12:00
Francisco Couzo
7fdf77065d
Fix typo 2020-05-07 04:11:50 -03:00
Daniele Varrazzo
690772f093 Merge branch 'mx-search' 2020-05-06 16:02:00 +12:00
Daniele Varrazzo
a75afe4d83 Mention fixing mx search in news file
Close #996.
2020-05-06 14:46:58 +12:00
Colin 't Hart
f9442744af Fixed search of mxDateTime headers
- Find mxDateTime.h automatically on path directories.
- Prefer mxDateTime.h found in venv over one found in /usr/include.
2020-05-06 14:42:10 +12:00
Daniele Varrazzo
1ec0bb5633 Mention python3-dev as possibly required dev package name
Close #1092.
2020-05-05 00:23:57 +12:00
Daniele Varrazzo
87279d5d03 Mention CALL on stored procedures using transaction in autocommit
Close #1072 - I prefer to mention them where there is a discussion of
the feature rather than in the method or const values section.
2020-05-05 00:19:38 +12:00
Daniele Varrazzo
accd1965bb Merge remote-tracking branch 'pombredanne/patch-1' 2020-05-04 23:55:29 +12:00
Daniele Varrazzo
d0216ce68d Merge branch 'client-encoding-leak' 2020-05-04 23:53:08 +12:00
Daniele Varrazzo
a35549d0ad Mention ticket #1101 closed in news file 2020-05-04 23:52:58 +12:00
Daniele Varrazzo
6043dac0ea Bump to next dev release 2020-05-04 23:50:05 +12:00
Kevin Michel
364b0e0563 Fix memory leak in conn_set_client_encoding
If the specified encoding is the same as the current one,
the early exit did not release the clean_enc string allocated
by clear_encoding_name.
2020-05-04 09:40:36 +02:00
Philippe Ombredanne
4c3e0e5f1d
Improve doc wording
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
2020-04-28 22:37:59 +02:00
Philippe Ombredanne
75c659a5e7
Fix typo and improve grammar in doc
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
2020-04-28 22:27:29 +02:00
Federico Di Gregorio
8b2450287e
Removed ZPL license (closes: #1087) 2020-04-28 18:53:14 +02:00
Daniele Varrazzo
cb3353be1f Releasing psycopg 2.8.5 2020-04-06 17:00:57 +12:00
Daniele Varrazzo
f2852a520a Merge branch 'add-aix-support' 2020-04-06 16:49:42 +12:00
Daniele Varrazzo
012a20b010 Mention AIX support in NEWS file 2020-04-06 16:46:44 +12:00
Jon Dufresne
fbba461052 Fix typo: occured → occurred 2020-04-06 16:40:45 +12:00
Daniele Varrazzo
62743c3be1 Fixed copy() on DictRow
Close #1073.
2020-04-06 14:10:02 +12:00
Abdirahim Musse
6de23eb793
fixup! feat: Add AIX support 2020-03-12 13:21:02 -05:00
Daniele Varrazzo
2bee47efac Merge branch 'column-slice' 2020-03-13 00:17:57 +13:00
Daniele Varrazzo
054123254e Column objects can be sliced
Close #1034.
2020-03-11 10:50:56 +13:00
Daniele Varrazzo
5d96b0c024 Merge branch 'cffi-in-docs' 2020-03-08 11:34:20 +00:00
Daniele Varrazzo
34615b7629 Better descriptions of the non-C porting in install docs 2020-03-08 11:33:31 +00:00
Daniele Varrazzo
34c54f3fc3 Merge branch 'logging-adapter' 2020-03-08 11:23:32 +00:00
Daniele Varrazzo
497ad5c7c0 Mention LoggingAdapter in news 2020-03-08 11:22:43 +00:00
Abdirahim Musse
de58332bdd
feat: Add AIX support 2020-03-05 12:34:25 -06:00
Daniele Varrazzo
12bc9d68c4 Added funding file 2020-02-22 18:54:05 +00:00
Daniele Varrazzo
9bcca1a7b0 Dropped customized doc template
It was meant to be used only by the website, not for the doc shipped
with the package.

[skip ci]
2020-01-27 04:32:31 +00:00
Daniele Varrazzo
f2d13ec809 Upload on https now 2020-01-27 02:58:58 +00:00
Daniele Varrazzo
e14e3385b4 Merge branch 'goodbye-initd' 2020-01-25 19:54:30 +00:00
Daniele Varrazzo
1c80c9d8d5 Trigger docs rebuild on push 2020-01-25 19:51:21 +00:00
Daniele Varrazzo
e9dc1df889 Added sql module basic usage section and classes hierarchy 2020-01-20 21:00:58 +00:00
Daniele Varrazzo
dbd6577d91 Fixed dependencies in docs build
Building without having built the library failed
2020-01-19 00:43:42 +00:00
Daniele Varrazzo
94a660aa6f Use a responsive theme for docs
With a pleasant ottanio background.
2020-01-18 23:56:44 +00:00
Daniele Varrazzo
584197f57d Hide the "made with sphinx" doc footer 2020-01-18 19:37:13 +00:00
Daniele Varrazzo
5e0b02afb2 Copyright bumped to 2020 2020-01-17 21:21:11 +00:00
Bjoern Boschman
93aa469f16 #1026 added support for logging.LoggerAdapter 2020-01-07 13:46:21 +00:00
Daniele Varrazzo
8a6b280d86 Use an ssh config file to configure package uploading
[skip ci]
2020-01-04 16:59:52 +01:00
Daniele Varrazzo
9bfde497e5 Copyright 2020 in the docs 2020-01-04 01:39:29 +01:00
Daniele Varrazzo
c3c24cd67b Website on https 2019-12-31 13:09:13 +01:00
Daniele Varrazzo
501b0412f6 CI resources moved to upload.psycopg.org 2019-12-31 09:59:32 +01:00
Daniele Varrazzo
9154d0920c Changed docs to point to psycopg.org 2019-12-30 18:12:46 +01:00
Daniele Varrazzo
3d29ace058 Document a release procedure not using initd server 2019-12-30 17:13:37 +01:00
Daniele Varrazzo
46022cb162 Merge branch 'py38-win' 2019-12-30 17:11:21 +01:00
Daniele Varrazzo
f4144615f7 Blacklist docutils 0.15 to build docs
It crashes because of https://sourceforge.net/p/docutils/bugs/353/
2019-12-29 23:54:18 +01:00
Daniele Varrazzo
c3b35ba510 Merge branch 'fix-1019' 2019-12-10 11:09:27 +00:00
Daniele Varrazzo
c20c13c493 Fixed use of cursor_factory attribute in connecion subclasses
Close #1019
2019-12-09 11:11:39 +00:00
Daniele Varrazzo
5c02fdaa0d Bump to next dev version 2019-12-09 11:10:58 +00:00
Daniele Varrazzo
9c32457c28 Added Python 3.8 build on Appveyor 2019-11-10 20:58:44 +00:00
Omer Katz
a1fd2da1dc
Mention the CFFI port to Psycopg2 in documentation.
The CFFI port works much better on PyPy and has been used in production before.
The documentation mentioned the Ctypes port but not the CFFI port.
I added it to the documentation.
2019-10-23 12:05:33 +03:00
Daniele Varrazzo
d70d3ee482 Bump to version 2.8.4 2019-10-20 01:25:21 +01:00
Daniele Varrazzo
16c07ba9c4 Mention the library versions packaged in the 2.8.4 wheel in the NEWS file 2019-10-20 01:19:47 +01:00
Daniele Varrazzo
cb7109dfa9 Merge branch 'fix-951' 2019-10-19 18:38:56 +01:00
Daniele Varrazzo
eb893e65f0 Mention fixing time.h include in NEWS
Mostly to remember why we did it.
2019-10-19 18:11:10 +01:00
Daniele Varrazzo
b0b09cbb24 Merge branch 'bugfix/940' 2019-10-19 18:04:02 +01:00
Daniele Varrazzo
63352d7da0 Mention bug 940 fixed in NEWS file 2019-10-19 18:02:32 +01:00
Jann Kleen
4097b4f2a0 Fix typo 'againts' 2019-10-19 17:58:37 +01:00
Daniele Varrazzo
8a18ff7699 Mention that with PgBouncer get_backend_pid() is not updated
Close #956
2019-10-19 17:57:31 +01:00
Daniele Varrazzo
850c585501 Added UltraJSON example
Close #972
2019-10-19 17:47:01 +01:00
Daniele Varrazzo
2f094841b2 Slow test is slow 2019-10-19 16:29:16 +01:00
Daniele Varrazzo
96156727c0 Allow parsing boolean both upper and lowercase
Reportedly useful on H2 databases.

Close #965
2019-10-19 16:28:10 +01:00
Daniele Varrazzo
5e9572aff8 Revert testing on Windows to libpq 11.4
Build broken by:

    d993e0fb82

Error at:

    https://ci.appveyor.com/project/psycopg/psycopg2/builds/28228647/job/490uo4qko6cguldl
2019-10-19 16:17:01 +01:00
Daniele Varrazzo
24a8d600bf Test on appveyior with libpq 11.5 and openssl 1.1.1d
Will mention the new libraries' support after testing with wheels
2019-10-19 16:10:15 +02:00
Daniele Varrazzo
b2a09fb404 Merge branch 'pg12' 2019-10-19 16:09:41 +02:00
Daniele Varrazzo
b029bd80d4 Merge branch 'py38' 2019-10-19 16:08:06 +02:00
Daniele Varrazzo
500f438033 Support for Python 3.8 mentioned in news file 2019-10-19 16:07:35 +02:00
Daniele Varrazzo
ade98c1359 Added Py 3.8 support to appveyor build
VS 14 is the one to use: https://wiki.python.org/moin/WindowsCompilers

Note that appveyor doesn't have Py 3.8 yet though.
2019-10-19 16:01:13 +02:00
Daniele Varrazzo
38a411dc07 Test Python 3.4 on xenial
Trusty is no more required, and PG 12 is not available there.
2019-10-19 15:50:57 +02:00
Daniele Varrazzo
214a8efe64 Test PG 11 and 12 on travis 2019-10-19 15:26:20 +02:00
Daniele Varrazzo
d5c7ec7ae8 Added Postgres 12 errors 2019-10-19 15:22:48 +02:00
Daniele Varrazzo
8f11821c17 Use travis test config variable 0/1 instead of blank strings
Travis web interface doesn't allow anymore to set an empty string as
variable value.
2019-10-19 15:18:38 +02:00
Daniele Varrazzo
58654990d6 Install postgres from pgdg on travis if available there 2019-10-19 14:38:49 +02:00
Daniele Varrazzo
0dec435856 Dropped download url from package metadata
Not really useful anymore as PyPI is the official download place.
2019-10-19 14:09:44 +02:00
Jon Dufresne
4e13acdc88 Add Python 3.8 to the test matrix
Python 3.8 was released on October 14th, 2019.

- Added 'Programming Language :: Python :: 3.8' trove classifier.
- Added 'py38' to the tox test matrix.
- Added 'python: 3.8' to the Travis test matrix.
- Removed 'dist: xenial' from Travis configuration; it is now the
  default.
- Removed 'dist: trusty' from Travis configuration; it is not longer
  necessary.
- Removed 'sudo' from Travis configuration; it is deprecated.

https://docs.python.org/3.8/whatsnew/3.8.html
2019-10-18 18:29:59 -07:00
Daniele Varrazzo
f08019e356 Added decorator to clean up the adaptation mappings after tests
Many tests were doing it manually, some weren't doing it and resulted in
failure if run in different order.

Close #948
2019-09-04 18:17:51 +01:00
Daniele Varrazzo
33d3c074fa Merge branch 'fix-961' 2019-09-04 13:22:16 +01:00
Daniele Varrazzo
80df0553a6 Fixed handling large Oid values
Oid is defined as unsigned 32. On some Python implementations (probably
the ones where maxint = 2 ** 31) this can cause int overflow for large
values (see #961). On my 64 box it doesn't seem the case.

Oid handling was sloppy here and there (messages, casts...): trying to
use uint everywhere, and added a couple of helper macros to treat Oid
consistently.

Close #961.
2019-09-04 12:30:18 +01:00
Samuel Marks
a47fcdd508
[psycopg/pqpath.c] sys/time.h include for non mac & Windows
Signed-off-by: Samuel Marks <807580+SamuelMarks@users.noreply.github.com>
2019-08-05 15:07:43 +10:00
Alexander Kukushkin
9097a5b989 Don't advance replication cursor when the message wasn't confirmed
Fixes https://github.com/psycopg/psycopg2/issues/940
2019-07-05 08:37:24 +02:00
Daniele Varrazzo
4d10f1235f Merge branch 'obscure-password-before-connect' 2019-06-24 12:14:29 +01:00
Daniele Varrazzo
6e972200a3 Mention ctrl-c swallowing fixed in news file 2019-06-24 12:13:47 +01:00
Daniele Varrazzo
3465ce282e Function to obscure password moved to connection_int 2019-06-24 12:11:12 +01:00
Daniele Varrazzo
f40ad0f3ae Obscure the dsn password before storing it into the connection
This avoids the need to juggle with exceptions in order to scrub the
password after a connection error, which may also swallow signals
(see #898).
2019-06-22 19:22:27 +01:00
Jon Dufresne
491296e0f5 Fix typo: "the the" 2019-06-21 11:26:47 +01:00
Daniele Varrazzo
ee056bc6e8 Bump to next dev version number 2019-06-21 11:26:29 +01:00
Kunal Marwaha
c32dbf357c typo: remove 'a' 2019-06-19 00:32:54 +01:00
Daniele Varrazzo
bc65c636ae Bump to version 2.8.3 2019-06-10 23:21:50 +01:00
Daniele Varrazzo
91a8962770 Added entry about how to ask questions
Also fixed mailing list link (although it doesn't seem there's a link to
a subscription page anymore, you have to go through the community
portal).

Close #930.
2019-06-10 23:18:11 +01:00
Daniele Varrazzo
be8e1a2632 Making my linter happy 2019-06-07 18:20:36 +01:00
Daniele Varrazzo
2635f43788 Merge branch 'fix-namedtuple-cache' 2019-06-07 18:19:47 +01:00
Daniele Varrazzo
0578c1ab92 Mention #928 fixed 2019-06-07 18:18:48 +01:00
Changaco
842e383c0c fix NamedTupleCursor._cached_make_nt 2019-06-04 14:30:30 +02:00
Changaco
527592a0a5 improve the NamedTupleCursor cache test 2019-06-04 13:45:37 +02:00
Daniele Varrazzo
668d507c34 Merge branch 'feature/smart-feedback' 2019-05-12 23:55:11 +09:00
Daniele Varrazzo
b79895186c Added news entry about smart replication feedback 2019-05-12 23:48:51 +09:00
Alexander Kukushkin
90755e6f13 Address code-review 2019-05-07 14:18:09 +02:00
Alexander Kukushkin
5eec11f232 Improve docs 2019-05-06 15:42:37 +02:00
Alexander Kukushkin
f827e49f55 Change the default value of keepalive_interval parameter to None
The previous default value was 10 seconds, what might cause silent
overwrite of the *status_interval* specified in the `start_replication()`
2019-05-06 15:26:21 +02:00
Alexander Kukushkin
6cff5a3e08 Smart replication feedback
This commit makes psycopg2 responsible for sending the status update
(feedback) messages to the server regardless of whether a synchronous or
asynchronous connection is used.

Feedback is sent every *status_update* (default value is 10) seconds,
which could be configured by passing a corresponding parameter to the
`start_replication()` or `start_replication_expert()` methods.
The actual feedback message is sent by the
`pq_read_replication_message()` when the *status_update* timeout is
reached.

The default behavior of the `send_feedback()` method is changed.
It doesn't send a feedback message on every call anymore but just
updates internal structures. There is still a way to *force* sending
a message if *force* or *reply* parameters are set.

The new approach has certain advantages:
1. The client can simply call the `send_feedback()` for every
   processed message and the library will take care of not overwhelming
   the server. Actually, in the synchronous mode it is even mandatory
   to confirm every processed message.
2. The library tracks internally the pointer of the last received
   message which is not keepalive. If the client confirmed the last
   message and after that server sends only keepalives with increasing
   *wal_end*, the library can safely move forward *flush* position to
   the *wal_end* and later automatically report it to the server.

Reporting of the *wal_end* received from keepalive messages is very
important. Not doing so casing:
1. Excessive disk usage, because the replication slot prevents from
   WAL being cleaned up.
2. The smart and fast shutdown of the server could last indefinitely
   because walsender waits until the client report *flush* position
   equal to the *wal_end*.

This implementation is only extending the existing API and therefore
should not break any of the existing code.
2019-05-06 10:27:44 +02:00
Daniele Varrazzo
f96982bdfd Merge remote-tracking branch 'origin/appveyor-py' 2019-05-01 16:30:09 +01:00
Daniele Varrazzo
ed7d8ea28c Appveyor: added package_name to options 2019-04-22 22:39:59 +01:00
Daniele Varrazzo
014097c1af Dropped command line config from appveyor scrips
Only use env vars, they were unused.

Use consistently a config object with properties instead of functions
(the one returning a binary are especially dangerous if parens are
forgotten).

Also add helpers to call the target python more succinctly.
2019-04-22 12:41:44 +01:00
Daniele Varrazzo
1b2c1d620f Run tests more quiet/faster building wheels
We are mostly interested it installed alright.
2019-04-22 11:24:29 +01:00
Daniele Varrazzo
285c64d101 Better dir names in appveyor build 2019-04-22 11:24:29 +01:00
Daniele Varrazzo
637a990e09 Added support for wheel building and uploading
To be used by the psycopg/psycopg2-wheels project.
2019-04-22 11:24:29 +01:00
Daniele Varrazzo
9eec303cf7 Configure postgres to run appveyor tests on ssl 2019-04-22 11:24:29 +01:00
Daniele Varrazzo
b1078b1b92 Setup build environment only before building 2019-04-22 11:24:29 +01:00
Daniele Varrazzo
1178501aaf appveyor: added logging level configuration 2019-04-22 11:24:29 +01:00
Daniele Varrazzo
5c72203180 Using pathlib to manipulate paths 2019-04-22 11:24:29 +01:00
Daniele Varrazzo
591476621c Dropped problematic init step
It was performed before repos cloned so no resource available (including
the script!)
2019-04-22 11:24:29 +01:00
Daniele Varrazzo
fda738c90d All together now, let's make this real 2019-04-22 02:54:56 +01:00
Daniele Varrazzo
5858b0b9b4 Test packages from Python 2019-04-22 02:54:56 +01:00
Daniele Varrazzo
169ce22228 Build psycopg from Python 2019-04-22 02:54:56 +01:00
Daniele Varrazzo
c875197432 Build libpq from Python 2019-04-22 02:54:56 +01:00
Daniele Varrazzo
73f6a0cd95 Build openssl from Python 2019-04-22 02:54:56 +01:00
Daniele Varrazzo
37ce131d2c Added setenv to log env vars changes 2019-04-22 02:54:56 +01:00
Daniele Varrazzo
00fc2820a0 Added script to implement appveyor functionality in Python
Only the init step for the moment.
2019-04-22 02:54:56 +01:00
Daniele Varrazzo
325aadbf2c Check return code of pthread_mutex_init
Close #901
2019-04-21 11:53:34 +01:00
Daniele Varrazzo
39b1994c26 Bump to next dev version number 2019-04-21 11:53:13 +01:00
Daniele Varrazzo
324cded166 Bumping to version 2.8.2 2019-04-14 15:11:31 +01:00
Daniele Varrazzo
6b740df704 Added FAQ entry about the change in binary packages in 2.8 2019-04-14 15:08:07 +01:00
Daniele Varrazzo
4821a6294e Merge branch 'openssl-1.1-windows' 2019-04-14 14:49:41 +01:00
Daniele Varrazzo
26b61e809f Mention building openssl 1.1 on windows in news file
Close #836.
2019-04-11 01:42:54 +01:00
Daniele Varrazzo
14bfc54344 Mention fix to repeated fields in RealDictCursor in news file 2019-04-11 00:54:55 +01:00
Daniele Varrazzo
72fe91c02e Build and test with openssl 1.1 on windows
Porting to openssl 1.1 by Matthew Brett, from the psycopg2-wheel repos.
2019-04-11 00:27:49 +01:00
Daniele Varrazzo
5e01c47818 Highlight in docs that the context manager doesn't close the connection
Code as in #889 is not robust, but the behaviour is actually
counter-intuitive.
2019-04-07 11:19:56 +01:00
Daniele Varrazzo
4058f363d6 More robust RealDictRow population
In the presence of repeated columns the mapping would have remained into
into the dictionary. Now it is removed.

Fix #884
2019-04-06 21:17:28 +01:00
Daniele Varrazzo
63e4bc961e Version bumped to next dev release 2019-04-06 21:16:42 +01:00
Daniele Varrazzo
3357477fde Fixed debug title level in news 2019-04-06 20:49:00 +01:00
Daniele Varrazzo
d2dce4dd17 Fixed link to RealDictRow from last news 2019-04-06 20:22:03 +01:00
Daniele Varrazzo
15d684134f Bumping to version 2.8.1 2019-04-06 20:12:10 +01:00
Daniele Varrazzo
5c4b8a3d1f Merge branch 'fix-886' 2019-04-06 20:09:47 +01:00
Daniele Varrazzo
cc815e8e8d RealDictRow inherits from OrderedDict
Now its state is unmodified, so apart from special-casing creation
and initial population can work unmodified, and all the desired
properties just work (modifiability, picklability...)

Close #886.
2019-04-06 19:43:31 +01:00
Daniele Varrazzo
21d16b6f67 Fixed RealDictCursor.pop()
Addresses #886, but there might be something else broken there.
2019-04-06 19:43:09 +01:00
Daniele Varrazzo
7b31b39fed Merge branch 'fix-887' 2019-04-06 10:51:03 +01:00
Daniele Varrazzo
46106e1b78 Test notifies are received ok polling an async cur 2019-04-05 19:04:48 +01:00
Daniele Varrazzo
755a128ffb Handle ok poll() without a cursor having executed queries
Close #887
2019-04-05 18:04:55 +01:00
Daniele Varrazzo
34d45aea87 Bump to next dev release 2019-04-05 18:02:30 +01:00
Daniele Varrazzo
c64d2448e8 Bumping to 2.8 for release 2019-04-03 10:44:07 +01:00
Daniele Varrazzo
544e157649 Fixed replication cursor docs warning indentation level 2019-04-01 10:54:01 +01:00
Daniele Varrazzo
ed74189acd Replication objects docs header level bumped up
Now it appears in the ToCs.
2019-04-01 10:40:44 +01:00
Daniele Varrazzo
813ca30953 Fixed notice about new wal_end attribute being on the cursor 2019-04-01 10:40:06 +01:00
Daniele Varrazzo
b76ff2fc33 Merge branch 'keepalive-save-wal-end'
Close #800
2019-03-30 21:29:39 +00:00
Daniele Varrazzo
b8bf6d9917 Added news entry about ReplicationMessage.wal_end 2019-03-30 21:23:20 +00:00
grunskis-bonial
ff91ad5186 Address code review feedback 2019-03-30 21:23:13 +00:00
Martins Grunskis
f946042a79 Store WAL end pointer in the replication cursor 2019-03-30 21:23:11 +00:00
Andrew Rabert
3eecf34bea Add time type conversion info to docs 2019-03-24 23:09:36 +00:00
Daniele Varrazzo
953bc66ca6 Allow tests to be ignored if dynamic binding failed 2019-03-18 19:49:16 +00:00
Daniele Varrazzo
5b4caadd23 Version number changed to release version 2.8 beta 2 packages 2019-03-18 14:59:04 +00:00
Daniele Varrazzo
8b7506f80d Merge branch 'naming' 2019-03-18 01:54:44 +00:00
Daniele Varrazzo
e569e49b8b Merge branch 'fix-829' 2019-03-18 01:53:59 +00:00
Daniele Varrazzo
f8f5a77838 Mention closed #829 in NEWS file 2019-03-18 01:51:29 +00:00
Daniele Varrazzo
0c581380c7 Allow incorrect result for pgconn_ptr test on OSX
I don't know why it returns 0 instead of the right value. At least it
doesn't segfault, so don't skip the test altogether.

The test is unrelated to this branch: will cherry-pick elsewhere (if I
remember it...)
2019-03-18 01:41:56 +00:00
Daniele Varrazzo
7571ec9368 Run tests on windows using the same library versions of the packages 2019-03-18 01:41:56 +00:00
Daniele Varrazzo
eedbb33226 Appveyor tests in order of sort what I care 2019-03-18 00:33:31 +00:00
Daniele Varrazzo
17b0c61338 Don't close connections from forked processes
On Py3 subprocessing will actually GC the objects and the FD is open,
resulting in connections closed in different processes.

The behaviour is verified in py 3.4 to 3.7 at least,
2019-03-18 00:32:40 +00:00
Daniele Varrazzo
62a078fe0c subprocess test function moved into a module
It won't work on windows if it's in the script: failing with errors
such as:

    AttributeError: 'module' object has no attribute 'process'

or:

    Can't get attribute 'process' on <module '__main__' (built-in)>
2019-03-17 23:55:04 +00:00
Daniele Varrazzo
7c5afd6977 Added test to reproduce ticket #829
Unrelated processes close the FD of the connection. This happens in
Python 3.6 but not 2.7. Let's see if travis shows where else it fails...
2019-03-17 23:06:55 +00:00
Daniele Varrazzo
458254c49e Windows doesn't like the name "connect" for a function 2019-03-17 22:26:02 +00:00
Daniele Varrazzo
dc5dd30526 Prefix 'psycopg_' changed to 'psyco_' 2019-03-17 18:45:25 +00:00
Daniele Varrazzo
e4d365705a Several function names shortened
There's not so much need for a strict convention for static functions.
Leaving some 'psyco_' prefix when the internal function and the
python-exposed function clashed.
2019-03-17 18:33:15 +00:00
Daniele Varrazzo
b4b470c29a Allow 0 as key in the pool
Close #848
2019-03-17 18:24:50 +00:00
Daniele Varrazzo
155c739863 Merge branch 'use-conn-pgres' 2019-03-17 04:43:58 +00:00
Daniele Varrazzo
a5c0a2215e Dropped whole "critical" story
It doesn't seem "critical" errors are used anymore. pq_set_critical()
wasn't called anywhere.
2019-03-17 03:49:34 +00:00
Daniele Varrazzo
17a074b30a Use the error on the connection instead of passing it explicitly around 2019-03-17 03:49:34 +00:00
Daniele Varrazzo
97220eadc6 Added helper methods to set a result into a connection/cursor 2019-03-17 03:49:34 +00:00
Daniele Varrazzo
e740c21ee6 Dropped pgconn argument from conn_setup() 2019-03-17 03:49:34 +00:00
Daniele Varrazzo
c15e4c1a85 Use the connection's PGresult to pass results through calls 2019-03-17 03:49:34 +00:00
Daniele Varrazzo
5957a7ee45 Fixed handling of internal query too large 2019-03-17 03:49:34 +00:00
Daniele Varrazzo
917335eacb Merge branch 'fix-856' 2019-03-17 03:48:40 +00:00
Daniele Varrazzo
963123812d Make sure to free the connection's pgres on delete 2019-03-17 02:25:45 +00:00
Daniele Varrazzo
734845b79a Added pq_get_result_async() replaced pg_get_last_result()
The new function keeps together PQconsumeInput() with PQisBusy(), in
order to handle the condition in which not all the results of a sequence
of statements arrive in the same roundtrip.

Added pointer to a PGresult to the connection to keep the state across
async communication: it can probably be used to simplify other code
paths where a result is brought forward manually.

Close #802
Close #855
Close #856
2019-03-17 01:20:06 +00:00
Daniele Varrazzo
761c3784c4 Retrieving the async cursor moved out of conn_poll() body 2019-03-16 20:05:40 +00:00
Daniele Varrazzo
e864050d07 Simplified interactions between asyc functions
Have advance_write calling flush itself, advance_read calling is_busy
itself, rather than calling them in the caller and passing the result.

Why we were doing the former on write I don't know. On read the paths
between async and green function was different but they got unified in
the previous commit.
2019-03-16 20:05:40 +00:00
Daniele Varrazzo
2a8fa4bef7 Dropped locking version of pq_is_busy()
The locking version was used for sync connections, the non-locking one
for green ones. However it only calls non-blocking functions, so it
doesn't really matter releasing the gil. So have only the non-locking
one.

Note that the name are sort of swapped: pq_is_busy() does now what
pq_is_busy_locked() used to do.
2019-03-16 20:05:40 +00:00
Daniele Varrazzo
5467f65122 Dropped no_begin handling in async execute
no_begin is only used with withhold named cursors, and it's not possible
to create named cursors on async connections.
2019-03-16 20:05:40 +00:00
Daniele Varrazzo
0935c9d8ca Dropped debug info for microprotocols/adapters initialization
Not useful anymore (guess they were when those layers were created).
Much shorter stream of messages on module init now.
2019-03-16 20:05:40 +00:00
Daniele Varrazzo
d61c902230 Shorter timeout in the async tests select 2019-03-16 20:05:40 +00:00
Daniele Varrazzo
b5c7c93092 Merge branch 'version-check-cleanup' 2019-03-16 19:55:17 +00:00
Daniele Varrazzo
e922e2a96e Py2/3 compatibility macro definitions rationalized 2019-03-16 19:54:40 +00:00
Daniele Varrazzo
fec0a5587d Fixed check for type == int on Py2 2019-03-16 19:54:40 +00:00
Daniele Varrazzo
b9d0808f95 Added PY_2, PY_3 macros and used uniformly 2019-03-16 19:54:40 +00:00
Daniele Varrazzo
8448b3b840 Dropped conditional compiling dealing with unsupported versions
Also dropped shameful use of PY_MINOR_VERSION.
2019-03-16 19:54:40 +00:00
Daniele Varrazzo
dfb301b42b Use PY2, PY3 for conditional code instead of sys.version_info 2019-03-16 19:54:40 +00:00
Daniele Varrazzo
f4a2630f1a Added PY2, PY3 to compat module 2019-03-16 19:54:40 +00:00
Daniele Varrazzo
4ace9544ff Merge branch 'fix-imports' 2019-03-16 19:53:45 +00:00
Daniele Varrazzo
e8135ee2cf Use errors module to catch a specific postgres error 2019-03-16 19:13:58 +00:00
Daniele Varrazzo
b0119fef81 Other import moved to top level in tests 2019-03-16 19:13:58 +00:00
Daniele Varrazzo
8cfe176a85 Dropped repeated conditional import of reload in test 2019-03-16 19:04:40 +00:00
Daniele Varrazzo
aaba4dcf87 TextIOBase moved to tests compat imports 2019-03-16 18:41:59 +00:00
Jon Dufresne
d90ad8627d Move imports to the top of the module across tests
Allows removing many duplicate imports and better follows PEP8
guidelines:

https://www.python.org/dev/peps/pep-0008/#imports

> Imports are always put at the top of the file, just after any module
> comments and docstrings, and before module globals and constants.
2019-03-16 18:03:41 +00:00
Jon Dufresne
194efc4375 Fix invalid exception handler: except e:
Fixes flake8 warning:

    ./tests/test_connection.py:390:16: F821 undefined name 'e'
    ./tests/test_connection.py:391:61: F821 undefined name 'e'
    ./tests/test_connection.py:408:16: F821 undefined name 'e'
    ./tests/test_connection.py:409:61: F821 undefined name 'e'

In the event of an unexpected error, let the exception bubble up the
stack for a more informative test failure message.
2019-03-16 17:59:18 +00:00
Jon Dufresne
432fdd7d32 Removed support for mxDateTime as the default date and time adapter
The use_pydatetime configuration option has been removed. Now, always
default to Python's builtin datetime. mxDatetime support continues to be
available as an alternative to Python's builtin datetime.
2019-03-16 16:36:49 +00:00
Jon Dufresne
8685120485 Remove unnecessary except ImportError for Python datetime types
The Python datetime module is available on all supported platforms. The
types are always available and never raise an ImportError.
2019-03-16 16:35:51 +00:00
Jon Dufresne
ad4c6a4673 Use unittest 'skip' feature to skip mxDateTimeTests
Rather than deleting, the class, use the skip feature. Provides a more
informative message during test output.

Never skip DatetimeTests as all supported Python environments have the
datetime module builtin.
2019-03-13 15:01:34 +00:00
Jon Dufresne
d411dc3a73 Remove unused use_pydatetime from setup.py
Looks to have been mistakenly reintroduced in
b537404487.
2019-03-13 15:00:25 +00:00
Jon Dufresne
6db347b5d7 Remove unused use_pg_dll from setup.py
Unused since 3076046b3f.
2019-03-13 11:20:27 +00:00
Jon Dufresne
3f890f8bbe Use True/False instead of 1/0 to represent bool values
Slightly more modern, readable, and Pythonic.
2019-03-13 11:13:36 +00:00
Jon Dufresne
afbbdd18b6 Remove unused variable
The variable i is immediately overwritten by the next line.
2019-03-13 11:13:24 +00:00
Jon Dufresne
03bb44dd2c Convert while 1: statements to while True:
A slightly more readable and modern syntax.
2019-03-13 11:13:05 +00:00
Jon Dufresne
18f5d5ad05 Remove unused imports from tests/test_ipaddress.py 2019-03-13 11:12:48 +00:00
Daniele Varrazzo
f2654d3573 Advertise openssl 1.0.2r and libpq 11.2 in wheels 2019-03-13 11:12:17 +00:00
Daniele Varrazzo
92ac3ba4fc Bumped to version 2.8 2019-03-05 17:33:16 +00:00
Daniele Varrazzo
3ae9dfd545 Better link from docs to "json and jsonb" data types 2019-03-05 17:31:45 +00:00
Daniele Varrazzo
c929f20048 Fixed building with Python 3.8
Not released yet, and using an internal API, so for the moment better
not declare it supported.

Close #854
2019-03-05 17:30:52 +00:00
Daniele Varrazzo
be7e1916d7 Dropped outdated setup.py comment 2019-02-26 23:48:20 +00:00
Grey Baker
7fadb75097 Add project_urls to setup.py, with links to source and documentation 2019-02-26 23:44:32 +00:00
David Fischer
147ff65e4a Fix typo 2019-02-26 11:33:48 +01:00
Daniele Varrazzo
b17670a27e Merge branch 'info-dsn-params' 2019-02-17 10:55:12 +00:00
Daniele Varrazzo
a68df50c7b Added ConnectionInfo.dsn_parameters attribute 2019-02-17 02:37:09 +00:00
Daniele Varrazzo
0eb4560771 Don't use versions such as 2.8.0 in docs
Use 2.8.
2019-02-17 01:51:06 +00:00
Daniele Varrazzo
599432552a Copyright year updated
ag -l Copyright | xargs sed -i \
        "s/\(.*copyright (C) [0-9]\+\)\(-[0-9]\+\)\?\(.*\)/\1-$(date +%Y)\3/I"
2019-02-17 01:36:36 +00:00
Daniele Varrazzo
d177fa9bd0 Allow building docs with Python 3
Use a .pth file to simplify finding the just-built psycopg package into the
docs building env.
2019-02-17 01:36:36 +00:00
Daniele Varrazzo
63ce5ca94f Fixed title level of sqlsate errors table in docs 2019-02-17 01:07:47 +00:00
Daniele Varrazzo
f70d6fd0ed Dropped text docs generation 2019-02-17 00:58:27 +00:00
Daniele Varrazzo
e5e8cec350 Added table of sqlstate exceptions in the docs
Note that the column-spanning cells break text docs. I don't think
anybody cares about them, so going to drop them.
2019-02-17 01:55:14 +01:00
Daniele Varrazzo
d08be18671 Merge branch 'libpq-ptrs' 2019-02-17 00:17:43 +01:00
Daniele Varrazzo
6bbfce7b89 Skip password encryption test if libpq < 10 2019-02-16 22:57:16 +01:00
Daniele Varrazzo
80b7b845d2 Added docs about pgconn_ptr, pgresult_ptr 2019-02-16 18:12:52 +01:00
Daniele Varrazzo
3b7c083c3d Skip tests involving ctypes on Windows
No idea about how to import libpq.
2019-02-16 18:12:52 +01:00
Daniele Varrazzo
7c7bbb9742 Added connection.pgconn_ptr and cursor.pgresult_ptr
Allow interacting with libpq in Python via ctypes.

See #782.
2019-02-16 18:12:52 +01:00
Daniele Varrazzo
1dd8c7435f Mention binary packages no longer installed by default in NEWS
Also fixed an unrelated typo.

[skip ci]
2019-02-16 16:10:03 +01:00
Daniele Varrazzo
495ff79f23 Preparing 2.8 beta release 2019-02-16 14:06:18 +01:00
Daniele Varrazzo
16b35ac77b Merge remote-tracking branch 'origin/errors-module-c' 2019-02-16 13:05:20 +01:00
Daniele Varrazzo
7c148ecee4 Improvements to errors module docs 2019-02-11 01:20:21 +00:00
Daniele Varrazzo
3de4d17519 Fixed use of StandardError in test
In Py3 it's gone.
2019-02-11 00:26:01 +00:00
Daniele Varrazzo
99f680b6fe Allow importing _psycopg even if the 'errors' module is not available 2019-02-10 04:25:06 +00:00
Daniele Varrazzo
30c1befa64 SQLSTATE error classes implemented in C
The module is only used to export them to Python.
2019-02-10 03:45:14 +00:00
Daniele Varrazzo
f1e73507d0 Merge remote-tracking branch 'origin/fast-namedtuple'
Close #838
2019-02-06 02:42:10 +00:00
Daniele Varrazzo
35ec7ad9c1 Use a proper LRU cache for namedtuples
Previous one didn't refresh by last use. Use the stdlib version for py3
and one of our own for py2.

Max size set to 512, which should be fine for everyone (tweaking is
still possible by monkeypatching, as the tests do, but I don't want to
make an interface of it).
2019-02-02 19:29:20 +00:00
Daniele Varrazzo
805527fcd6 Added caching of types generated by NamedTupleCursor
see #838
2019-02-02 14:22:25 +00:00
Daniele Varrazzo
3f20f7934a Merge branch 'drop-display-size' 2019-01-25 17:31:55 +00:00
Daniele Varrazzo
4298718978 Dropped PSYCOPG_DISPLAY_SIZE build parameter
Big and complex _pq_fetch_tuples simplified by moving per-column
calculation to a separate function.
2019-01-25 17:31:39 +00:00
Daniele Varrazzo
00cb2636f5 Merge branch 'module-init-cleanup' 2019-01-23 14:17:07 +00:00
Daniele Varrazzo
65a2a18a1b General cleanup of module init shenanigans
Pass around the module instead of its dict (getting the latter is fast
if needed), mark function raising with negative results, check all errors,
consistent names...
2019-01-23 09:46:18 +00:00
Daniele Varrazzo
66d5c6da07 Incref an object which will be held forever in a static var 2019-01-23 09:46:18 +00:00
Daniele Varrazzo
e9c476266c Decrement the refcount of temporary objects in module init failed
We are going to die anyway, but let's do it in style.
2019-01-22 19:40:42 +00:00
Daniele Varrazzo
63040e5134 Mention new OpenSSL version in wheel package 2019-01-22 12:25:03 +00:00
Daniele Varrazzo
1e6d5fb32d Merge branch 'execute-locks' 2019-01-22 12:24:41 +00:00
Daniele Varrazzo
c34c99aa7f Mention cursor locks cleanup in news file 2019-01-22 11:20:36 +00:00
Daniele Varrazzo
92e615a1a4 Assign the PGresult to the cursor in the execute critical section
Possible cause of the issue reported in #346 (in concurrent
environments).
2019-01-22 11:02:09 +00:00
Daniele Varrazzo
37891500d9 Split pq_execute into sync/async parts 2019-01-22 10:51:27 +00:00
Daniele Varrazzo
eab5d5d93f Date/time modules initialized in separate functions 2019-01-22 09:09:07 +00:00
Daniele Varrazzo
111a71ccee Dropped psyco_errors_fill()
Just use psyco_errors_init() for complete errors initialization
2019-01-21 20:18:53 +00:00
Daniele Varrazzo
1839806c3c Dropped project wide type to define encodings table 2019-01-21 20:18:53 +00:00
Daniele Varrazzo
8f17ccf784 Dropped C API interface
I guess it was unused as it only contained two init functions. The
Capsule should do things better now I guess.
2019-01-21 20:18:53 +00:00
Daniele Varrazzo
7b2e8f0aa4 Respect refcount with PyModule_AddObject()
The function steals a ref. The module is never destroyed so things work
fine but the refcount is wrong.
2019-01-21 20:18:53 +00:00
Daniele Varrazzo
549beeea84 Module constants definition moved in a separate function for clarity 2019-01-21 20:18:53 +00:00
Daniele Varrazzo
4246fdf809 Merge remote-tracking branch 'origin/code-cleanup' 2019-01-21 12:49:05 +00:00
Daniele Varrazzo
e67028f4bc Handle failed allocation in list adaptation 2019-01-21 02:49:38 +00:00
Daniele Varrazzo
7a3bce8fc3 Dropped funny handling of REPLICATION_* constants 2019-01-21 02:49:38 +00:00
Daniele Varrazzo
c77615adc9 _psyco_curs_execute() simplified
Dropped code duplications, more regular increc/decref pattern.

Check the return value of formatting named cursor: would have segfaulted
in case of error.
2019-01-21 02:49:38 +00:00
Daniele Varrazzo
594df09a63 More straightforward semantics for psyco_GetDecimalType
Raise an exception when returning NULL, leave the caller cleaning it.
2019-01-21 02:41:58 +00:00
Daniele Varrazzo
2ad2b27065 Dropped use of converter function to verify copy argument
They weren't really converters, and they confused the static checker
2019-01-21 02:41:58 +00:00
Daniele Varrazzo
3768d9047d Mark psyco_set_error as returning a borrowed object 2019-01-21 02:41:58 +00:00
Daniele Varrazzo
7a1fb9a2e4 Added utils.h file
utils.c functions definition moved out of psycopg.h

Some utility functions defined into psycopgmodule.c moved into utils.c.
2019-01-21 02:41:58 +00:00
Daniele Varrazzo
daff2ea1be Mark setter as raising on negative results
Fixed static check of psyco_conn_cursor().
2019-01-21 02:41:58 +00:00
Daniele Varrazzo
4644715164 Consider the case dereferencing weakref in conn_poll returns NULL
It shouldn't but handle the case to avoid a possible null pointer
dereferencing.
2019-01-21 02:41:58 +00:00
Daniele Varrazzo
5b28d7b9c9 Dropped possible wrong code path in conn_decode
It shouldn't happen for both cdecoder and pydecoder to be null,
but just in case...
2019-01-21 02:41:58 +00:00
Daniele Varrazzo
117f7d33f8 Wrap _Bytes_Resize into a function with clearer semantic
Limit the static checker hacking to a simpler function.
2019-01-21 02:00:04 +00:00
Daniele Varrazzo
f9b798aca9 Avoid unlikely leaks in case of memory errors in Bytes_Format 2019-01-21 02:00:04 +00:00
Daniele Varrazzo
2a05aa2c43 Move var setting into the only case using it
The original function was more complex than this. This refactoring
avoids a false positive in the static checker
2019-01-21 02:00:04 +00:00
Daniele Varrazzo
43d779966b Avoid using PyErr_BadInternalCall as the static checker doesn't get it 2019-01-21 02:00:04 +00:00
Daniele Varrazzo
003fc6dde1 Use the real definition of Py_LOCAL_INLINE 2019-01-21 02:00:04 +00:00
Daniele Varrazzo
fe915ac461 Bytes_Format: use a couple of macros instead of functions
The type was already checked upstream in the func body.
2019-01-21 02:00:04 +00:00
Daniele Varrazzo
15cba69a20 psycopg_escape_string: don't make me cringe
Just reformatted.
2019-01-21 02:00:04 +00:00
Daniele Varrazzo
79de02d7d5 Stricter use of PyArg_ParseTuple typed objects
The function expect PyObject *, not subclasses.
2019-01-21 02:00:04 +00:00
Daniele Varrazzo
3e66022912 Respect PyCFunction signature in METH_NOARGS functions
A second parameter does exist, although it's always NULL.
2019-01-21 02:00:04 +00:00
Daniele Varrazzo
5b08dc45b1 Merge remote-tracking branch 'origin/register-bytes'
Close #835
2019-01-19 15:32:46 +00:00
Daniele Varrazzo
49777de74c Added documentation for BYTES caster 2019-01-18 16:15:15 +00:00
Daniele Varrazzo
ddbe495d70 Added BYTESARRAY typecaster 2019-01-18 15:47:01 +00:00
Daniele Varrazzo
4ab4247189 Added test for BYTES typecaster 2019-01-18 15:10:17 +00:00
Daniele Varrazzo
fd31a7d41b Fixed typecast definition order
Didn't notice that the order matter: the last typecaster registered is
the effective one so let STRING win over UNICODE and BYTES.
2019-01-18 15:09:20 +00:00
Daniele Varrazzo
f713dc9fc1 Preliminary test for a BYTES adapter.
Allow returning unparsed bytes from databases with mixed encodings. See
issue #519.
2019-01-18 13:17:02 +00:00
Daniele Varrazzo
4a41c9a8cc
Merge pull request #828 from wbolster/patch-1
mention postgresql 11 in install docs
2019-01-08 12:21:18 +00:00
Daniele Varrazzo
07d9fb8718 Don't call CLEARPGRES on the cursor state without holding the gil
There is a chance it is executed by two different threads resulting in
issue #384.

I havent't found any other case that may lead to double free.
2019-01-02 13:15:00 +01:00
Daniele Varrazzo
ddcf808d56 Couple of objects into NEWS entries converted into links 2018-12-27 15:04:43 +01:00
Daniele Varrazzo
b26a0b149d Added # char to a few issues in news
Just a formatting thing #ocd #youdontcare #really.
2018-12-27 15:01:45 +01:00
Daniele Varrazzo
f3695e36c7 Merge remote-tracking branch 'eternalflow/execute-values-returning-clause-support' 2018-12-27 14:53:12 +01:00
Daniele Varrazzo
7c8d2f484e Mention execute_values() fetch in news 2018-12-27 14:51:18 +01:00
Daniele Varrazzo
bde9fc6dea Docs wordsmith for execute_values() fetch param 2018-12-27 14:42:58 +01:00
Daniele Varrazzo
6fdac46137 Some harmless adjustments in execute_values() code
No optional result, and create the list only if requred.
2018-12-27 14:39:13 +01:00
wouter bolsterlee
107f779061
mention postgresql 11 in install docs 2018-12-07 15:10:18 +01:00
Daniele Varrazzo
25fc044d13
Merge pull request #823 from jdufresne/dep-pool
Dropped deprecated PersistentConnectionPool
2018-12-05 11:32:20 +00:00
Daniele Varrazzo
de79aba66d
Merge pull request #819 from jdufresne/ctypes
Remove unnecessary test decorator 'skip_if_cant_cast'
2018-12-05 11:30:48 +00:00
Jon Dufresne
eb2d1766c6 Remove unnecessary test decorator 'skip_if_cant_cast'
ctypes is available and works on all supported Pythons. It has been
available since Python 2.5. The tests were written when Python 2.4 was
still supported.
2018-12-04 18:20:17 -08:00
Jon Dufresne
a1fdaebc30 Dropped deprecated PersistentConnectionPool
This class was deprecated in
27cd6c4880 (Dec 2, 2012), which was first
included in release 2.5. Enough time has passed for library uses to find
an alternative solution.

This class was untested.
2018-12-04 06:32:00 -08:00
Daniele Varrazzo
68bacbb194
Merge pull request #822 from jdufresne/decorate-all
Simplify 'decorate_all_tests' usage by decorating the test class
2018-12-04 14:22:02 +00:00
Daniele Varrazzo
672bdba679
Merge pull request #821 from jdufresne/skip-libpq
Remove workarounds for unsupported libpq < 9.1
2018-12-04 14:13:18 +00:00
Daniele Varrazzo
dc5298a919
Merge pull request #820 from jdufresne/appveyor
Remove Python 3.3 references from appveyor.yml
2018-12-04 14:11:53 +00:00
Daniele Varrazzo
b233778acd
Merge pull request #818 from jdufresne/bool-simplify
Simplify PyBool usage with Python convenience macros/functions
2018-12-04 14:07:48 +00:00
Jon Dufresne
a739c09f67 Simplify 'decorate_all_tests' usage by decorating the test class
Skip tests as early as possible by decorating the whole class with
unittest.skipIf instead of every test method individually.
2018-12-01 19:40:27 -08:00
Jon Dufresne
8b543eaa92 Remove Python 3.3 references from appveyor.yml
Python 3.3 has been unsupported since
c2d082e896.
2018-12-01 09:11:35 -08:00
Jon Dufresne
17dc5a85a3 Remove workarounds for unsupported libpq < 9.1
Per http://initd.org/psycopg/docs/install.html#prerequisites:

> PostgreSQL client library version from 9.1
2018-12-01 08:58:39 -08:00
Jon Dufresne
b796ca0c0a Simplify PyBool usage with Python convenience macros/functions
https://docs.python.org/3/c-api/bool.html
2018-11-30 17:09:30 -08:00
Ivan Kotelnikov
2e591e27f2 add versionchanged to docs 2018-11-24 20:51:18 +02:00
Ivan Kotelnikov
b40ac15efc rename param name to fetch 2018-11-24 20:51:18 +02:00
Ivan Kotelnikov
e2b99d3a8e write test for fetch_result flag 2018-11-22 12:30:37 +02:00
Ivan Kotelnikov
9a8d7d5a6a add RETURNING clause support in execute_values function 2018-11-21 16:38:13 +02:00
Daniele Varrazzo
483901ea7b Merge branch 'fix-591' 2018-11-16 19:17:24 +00:00
Daniele Varrazzo
73a680f45d Convert int subclasses to long before adapting
Fixes adaptation of int/long subclasses whose str() is not the number,
such IntEnum

Close #591

Note that I thought it would have needed a new adapter, so I considered
it a new feature. But it is more a shortcoming of the int adapter
failing to do something reasonable (poor Liskov, always mistreated) so I
may actually backport it if there is a new 2.7 release.
2018-11-16 18:16:03 +00:00
Daniele Varrazzo
654be4784c Dropped examples dir (and some leftover reference to the sandbox dir)
Close #645.
2018-11-16 17:06:06 +00:00
Daniele Varrazzo
f9d6430ae4 Mentioning binary packages fixes in news file 2018-11-10 23:48:47 +00:00
Daniele Varrazzo
3279ff7507 Mention get_native_connection() in the news file 2018-11-09 11:40:17 +00:00
Daniele Varrazzo
991b0e02c5 Fixed NEWS file after I actually re-read it for release. 2018-11-09 11:33:03 +00:00
Federico Di Gregorio
aee6f9352b
Merge pull request #805 from fogzot/feature-expose-pgconn
Feature expose pgconn
2018-11-08 15:57:23 +01:00
Federico Di Gregorio
01f8475f53
Merge branch 'master' into feature-expose-pgconn 2018-11-07 14:15:29 +01:00
Daniele Varrazzo
d1aa1585a1 Merge branch 'fix-788' 2018-10-30 10:50:25 +00:00
Daniele Varrazzo
a83696fc50 Fixed adaptation of lists of empty lists
...somehow. Postgres doesn't support them and converts them into a
simple empty array. However this is not really our concern: the syntax
we return is valid.

Close #788
2018-10-30 01:48:51 +00:00
Daniele Varrazzo
2f24a2e22d Use class decorators to decorate all tests
Test decorators changed so that they can be applied either to a method
or to a class. Of course their double nature is implemented by a
decorator.
2018-10-30 00:23:56 +00:00
Daniele Varrazzo
60935b9b3d Merge remote-tracking branch 'origin/fix-794' 2018-10-23 12:09:32 +01:00
Daniele Varrazzo
8fb0f694f7 Don't barf on Composite passed to execute_values()
Close #794
2018-10-23 01:57:48 +01:00
Daniele Varrazzo
05f9e231a0 Full flake8 3.5 cleanup 2018-10-23 00:39:14 +01:00
Daniele Varrazzo
1bb3d5cfe2 Dropped duplicate classes in errors module
Also using a more compact class registration using a decorator
2018-10-23 00:31:57 +01:00
Daniele Varrazzo
fae4284a64 Minimal formatting tweak to last news 2018-10-15 01:36:55 +01:00
Daniele Varrazzo
0236c68da9 Merge branch 'connection-info' 2018-10-15 01:24:00 +01:00
Daniele Varrazzo
c567556d71 Fixed NEWS file to mention the connection.info object 2018-10-15 01:23:51 +01:00
Daniele Varrazzo
b205764fdd Merge branch 'master' into errors-module 2018-10-15 00:58:32 +01:00
Daniele Varrazzo
e7227ce87b Added errors.lookup() function 2018-10-15 00:56:51 +01:00
Daniele Varrazzo
5da968d6f6 Added documentation for the errors module 2018-10-15 00:48:44 +01:00
Daniele Varrazzo
61df7bdd8d Errors module content updated to Postgres 11 2018-10-14 23:07:11 +01:00
Daniele Varrazzo
7a5edff6c6 errorcodes map update to PostgreSQL 11 2018-10-14 22:57:48 +01:00
Daniele Varrazzo
44bd2927c5 Use the connection.info properties instead of the legacy methods 2018-10-13 03:28:42 +01:00
Daniele Varrazzo
704e6797e7 Guard from some info functions not available in some libpq versions 2018-10-13 03:09:39 +01:00
Daniele Varrazzo
d138e42ee5 Added ConnectionInfo.parameter_status() 2018-10-13 02:40:17 +01:00
Daniele Varrazzo
9f6a3a5e96 Added ConnectionInfo.ssl_attribute() 2018-10-13 02:21:38 +01:00
Daniele Varrazzo
cb3d5f9d92 Added all the missing ConnectionInfo attributes 2018-10-13 01:36:07 +01:00
Daniele Varrazzo
4f7bbdca26 Added missing class signatures in the docs 2018-10-13 00:55:20 +01:00
Daniele Varrazzo
795522ff2b Merge branch 'fix-790' 2018-10-13 00:47:25 +01:00
Daniele Varrazzo
439dff974d Added ConnectionInfo.error_message 2018-10-13 00:47:04 +01:00
Daniele Varrazzo
d29aa1c437 Fixed refcount in connection's readonly and deferrable getters
Close #790
2018-10-12 23:32:13 +01:00
Daniele Varrazzo
1ac6359fef Added other members to the ConnectionInfo class
Starting deprecating softly some of the methods bloating the connection
class.
2018-10-12 04:18:59 +01:00
Daniele Varrazzo
0a04c8892d Added several ConnectionInfo attributes 2018-10-12 04:18:59 +01:00
Daniele Varrazzo
9ddf59959f Adding ConnectionInfo object documentation
I'm still fought whether docs should be in the C module or in the .rst.
I'd prefer the first because DRY, but writing multiline strings in C
really sucks.
2018-10-12 03:25:06 +01:00
Daniele Varrazzo
0e2b516a3c Moving host attribute to a connection.info object 2018-10-11 22:42:52 +01:00
Daniele Varrazzo
7619c91d62 Merge branch 'description-extra-attrs' 2018-10-11 04:39:14 +01:00
Daniele Varrazzo
6b3d3604bf Added docs for the Column object 2018-10-11 04:27:42 +01:00
Daniele Varrazzo
f99a8de6d0 Added table_oid, table_column on cursor.description items
Close #661
2018-10-11 03:37:09 +01:00
Daniele Varrazzo
b3b225a9da Added C implementation for a Column type
Currently behaving exactly like the previous (named)tuple.
2018-10-11 02:59:45 +01:00
Daniele Varrazzo
e00c4e2a7f Merge branch 'fix-copy-async-hangs' 2018-10-10 23:58:24 +01:00
Daniele Varrazzo
c314512115 Fixed infinite loop in pq_get_last_result after COPY
There will be an error downstream but we have to get out of this
function first.

Close #781
2018-10-10 23:57:34 +01:00
Daniele Varrazzo
c442b3ec46
Merge pull request #771 from jdufresne/distutils
Drop legacy distutils fallback in setup.py
2018-10-10 22:18:22 +01:00
Daniele Varrazzo
9c905741da Merge branch 'https' 2018-10-10 22:16:23 +01:00
Daniele Varrazzo
5010a65d77 Another url changed to https
Added after this MR.
2018-10-10 22:15:45 +01:00
Daniele Varrazzo
9148157697 Merge branch 'master' into https 2018-10-10 22:07:33 +01:00
Daniele Varrazzo
2e823273d6
Merge pull request #789 from jdufresne/argparse
Replace deprecated optparse usage with argparse
2018-10-10 22:05:16 +01:00
Daniele Varrazzo
cd9d74c462 Merge branch 'conn-get-host' 2018-10-10 22:03:36 +01:00
Daniele Varrazzo
382eeccab8 Small tweaks to connection.host docs 2018-10-10 22:02:20 +01:00
Daniele Varrazzo
f5f6b420b2 Merge remote-tracking branch 'origin/diag-schema-name-nonloc' 2018-10-10 21:46:51 +01:00
Jon Dufresne
488818eeb6 Replace deprecated optparse usage with argparse
Per https://docs.python.org/3/library/optparse.html

> Deprecated since version 3.2: The optparse module is deprecated and
> will not be developed further; development will continue with the
> argparse module.
2018-10-10 05:15:57 -07:00
Federico Di Gregorio
296c80d1f2 Commented out test to avoid beaking master 2018-10-10 11:05:02 +02:00
Federico Di Gregorio
1fe9f1ac5b Fixed test for issue #788 2018-10-10 09:35:18 +02:00
Federico Di Gregorio
ebcfbe03f9 Added test for issue #788 2018-10-10 09:14:56 +02:00
Federico Di Gregorio
7806fc736a Sandbox removed
The sandbox directory was there to test issues before we had full test
coverage and to try quick and dirty Python snippets before moving them to
the examples directory, sending them to mailing list or copying them to
the docs. Almost anything that was in sandbox is now in the examples
directory or has been refactored into a full test, or is so old that is
of no use anymore. So, adieu sandbox.
2018-10-09 00:00:12 +02:00
Federico Di Gregorio
e3c791cf60
Merge pull request #786 from alandmoore/master
Add documentation about the use of backslashes with LIKE
2018-10-08 23:50:33 +02:00
Alan D Moore
20647b7bcc Fix RST markup 2018-10-08 09:40:51 -05:00
Alan D Moore
67b94d0797 Added note about backslashes and LIKE
Added note about the use of LIKE with strings containing
backslashes.  Addresses concern in issue #785.
2018-10-08 09:36:16 -05:00
Federico Di Gregorio
f56392a245 Allow SPHINXBUILD on command line 2018-10-07 13:55:11 +02:00
Federico Di Gregorio
81addddaee Added connection.get_native_connection() 2018-10-07 13:54:24 +02:00
Marco De Paoli
1c553bb703 Added connection.host
Return the server host name of the current connect.
2018-10-06 15:19:01 +02:00
Daniele Varrazzo
4e0b2ec9c9 Added Diagnostics.severity_nonlocalized attribute
Close #783.
2018-10-04 16:13:46 +01:00
Daniele Varrazzo
9d83b03605 Merge branch 'identifier-sequence' 2018-10-04 13:22:46 +01:00
Daniele Varrazzo
4aa02b7855 sql.Identifier can wrap a sequence of strings to represent qualified names
Close #732.
2018-10-04 12:46:10 +01:00
Daniele Varrazzo
695c757dc3 Merge branch 'stringification-of-ranges' 2018-10-04 12:24:27 +01:00
Daniele Varrazzo
81d6f7a7ca Mention the better str(Range) in the docs. 2018-10-04 11:57:31 +01:00
Daniele Varrazzo
8bd7ad7bb5 Faster check for empty range in str() 2018-10-04 11:46:07 +01:00
Michel Albert
d317977205 Implement __str__ for range types 2018-09-30 10:15:55 +02:00
Federico Di Gregorio
ccae5cae34 Expose PGconn* raw pointer on the connection as a PyCapsule 2018-09-27 10:15:40 +02:00
Jon Dufresne
b07e34e0b8 Prefer https:// URLs when available 2018-09-22 19:02:33 -07:00
Jon Dufresne
9405d8cbc5 Drop legacy distutils in setup.py
distutils is not recommended for use and unnecessary for modern Python
environments. Use only setuptools instead. From
https://docs.python.org/3/library/distutils.html:

> Most Python users will not want to use this module directly, but
> instead use the cross-version tools maintained by the Python Packaging
> Authority. In particular, setuptools is an enhanced alternative to
> distutils ...
>
> The recommended pip installer runs all setup.py scripts with
> setuptools, even if the script itself only imports distutils. Refer to
> the Python Packaging User Guide for more information.
2018-09-15 16:05:05 -07:00
Daniele Varrazzo
6b6b1a6e8d Merge branch 'fix-bsd' 2018-09-07 23:58:19 +01:00
Daniele Varrazzo
0eaa0c9d4e Mention FreeBSD build fixed in news file 2018-09-07 23:57:34 +01:00
Dmitry Marakasov
5ec573c83b Remove obsolete and incorrect FreeBSD version condition
The FreeBSD-related condition which enables custom round() implementation is incorrect: one must include <sys/param.h> to get __FreeBSD_version value, and since it's not included here, the check succeeds while it shouldn't. Before it worked somehow, but since python 3.7 it results in conflicting declarations of round(). The condition is also no longer needed since FreeBSD 5.3 is unsupported for 12 years.
2018-09-07 23:57:33 +01:00
Daniel Hahler
6af55ee51c Improve doc for extras.wait_select 2018-09-05 16:45:33 +01:00
Andrew King
03fc3f9a2a Fix typo in install.rst 2018-09-05 16:42:59 +01:00
Jon Dufresne
c57fee2c92 Update intersphinx URLs to point to Python 3 docs
Python 3 docs are more up to date and reflect the future of Python.

Removed unused py3 marker.
2018-09-05 16:21:14 +01:00
Benjamin Peterson
f86229d98b Remove setup.py fallback that assumes postgres 7.4.0.
pyscopg2 only supports postgres >= 9.1 these days. Thus, taking this fallback will only lead to failure later down the line.
2018-09-05 16:18:18 +01:00
Daniele Varrazzo
344ce15261 Better testing of encryption function with libpq < 10 2018-08-17 02:09:22 +01:00
Daniele Varrazzo
782fa39647 Generating the whole errors file from script 2018-08-17 02:00:40 +01:00
Daniele Varrazzo
0bce58d0cd Dropped parsing sgml files for error codes
The errcodes.txt file contains all the errors for the currently
maintained server versions. There is only one error code missing,
probably unused, but adding it back anyway to keep the errcode module
unchanged.
2018-08-17 02:00:40 +01:00
Daniele Varrazzo
ce1ac3aea9 Read exceptions to raise from a Python module 2018-08-17 02:00:01 +01:00
Daniele Varrazzo
153b0983c1 Merge branch 'fix-746' 2018-07-25 16:29:57 +01:00
Daniele Varrazzo
97a4fb92c6 Fixed compile error on windows
Because const int + 1 is not const, right???

Also fixed other occurrences of magic numbers and failed DRY around
PyOS_snprintf() calls.
2018-07-24 21:16:36 +01:00
Daniele Varrazzo
466efe4461 Bump tests for selective closure of named cursor to pg 8.2
Previous versions don't support the features as they don't have the
pg_cursors view. But they are too old to care.
2018-07-24 21:16:36 +01:00
Daniele Varrazzo
6d8f4f9f0d Close named cursor if exist, even if we didn't run execute
Close #746
2018-07-24 21:16:36 +01:00
Daniele Varrazzo
0e89b9de2c Merge branch 'py37' 2018-07-13 19:12:23 +01:00
Daniele Varrazzo
a8b9c9971e Consider PG 9.3 a thing of the past.
Wow, it seems yesterday...

Previosly archived as a "past" version only in the prepare script. Test
script consistent now.

[skip ci]
2018-07-13 19:11:56 +01:00
Daniele Varrazzo
82f52db9b3 Fetch the correct testing postgres packages on xenial 2018-07-13 18:25:07 +01:00
Jon Dufresne
61e644049f Add testing and document support for Python 3.7
Python 3.7 was released on June 27, 2018.

https://docs.python.org/3/whatsnew/3.7.html
2018-07-12 18:07:25 -07:00
Daniele Varrazzo
6becf0ef55 Note the upgrade in wheel dependencies in NEWS file 2018-05-23 21:51:49 +01:00
Daniele Varrazzo
0aa7e21f91 Added note adivising against depending on the -wheels package 2018-05-23 21:43:48 +01:00
Daniele Varrazzo
a339ec3d8f Dropped license paragraph applying to removed files 2018-05-23 21:20:38 +01:00
Daniele Varrazzo
166ad21e5c Merge branch 'drop-2to3' 2018-05-21 03:36:32 +01:00
Daniele Varrazzo
0bb7d0db48 DictCursor and RealDictCursor rows maintain columns order
Close #177.
2018-05-21 03:14:08 +01:00
Daniele Varrazzo
7bdaf0affd Restored methods iter*() on dict cursors rows 2018-05-21 02:51:37 +01:00
Daniele Varrazzo
e8a831dda2 Merge branch 'master' into drop-2to3 2018-05-20 23:56:29 +01:00
Daniele Varrazzo
a0f7027ad5 Added tests to verify iter methods on dict cursors
ISTM the refactoring in #648 broke something
2018-05-20 23:55:18 +01:00
Daniele Varrazzo
82ae44ac3a DictCursor/RealDictCursor tests split 2018-05-20 23:35:26 +01:00
Daniele Varrazzo
f947c0e6be Merge branch 'encrypt-pass' 2018-05-20 22:33:07 +01:00
Daniele Varrazzo
9eb3e0cb79 encrypt_password() reported in the news file 2018-05-20 22:31:22 +01:00
Daniele Varrazzo
9cf658ec6e Fixed refcount handling in encrypt_password
Added tests to check bad types, which discovered the above problem: on
type error we would have decref'd on exit something that was only
borrowed (because we wouldn't have performed matching increfs).
2018-05-20 21:18:36 +01:00
Daniele Varrazzo
abca14d601 Fixed keywords support for encrypt_password and tests completed 2018-05-20 20:50:04 +01:00
Daniele Varrazzo
9e4f89a2a1 encrypt_password docs moved to extension module and updated 2018-05-20 20:13:04 +01:00
Daniele Varrazzo
a3063900ee Fixed code flow in encrypt_password()
Fixed several shortcomings highlighted in #576 and not fixed as
requested.

Also fixed broken behaviour of ignoring the algorithm if the connection
is missing.
2018-05-20 19:18:42 +01:00
Daniele Varrazzo
0161d54dbb Merge branch 'master' into encrypt-pass 2018-05-20 17:57:34 +01:00
Jon Dufresne
a8d4f37b19 Complete tox testing matrix
Now tests all supported Python environments as well. Allows testing the
full matrix of Python version with a single command.

Include the command make in the whitelist_externals configuration to
avoid the runtime warning:

  WARNING:test command found but not installed in testenv
    cmd: /usr/bin/make
    env: .../psycopg2/.tox/flake8
  Maybe you forgot to specify a dependency? See also the whitelist_externals envconfig setting.
2018-05-20 17:53:49 +01:00
Jon Dufresne
9ceffa1cc6 Update all pypi.python.org URLs to pypi.org
For details on the new PyPI, see the blog post:

https://pythoninsider.blogspot.ca/2018/04/new-pypi-launched-legacy-pypi-shutting.html
2018-05-20 17:22:37 +01:00
Daniele Varrazzo
10caf1bd74 Command to upload docs on pythonhosted dropped altogether 2018-05-20 17:21:26 +01:00
Daniele Varrazzo
a110d7dd70 Intersphinx urls to generate Python links updated
Previous urls warn about a redirect, so they are probably to go.
2018-05-20 17:21:26 +01:00
Daniele Varrazzo
3f0a7f9af4 Added license to the docs
Includes other docs improvements, such as the ones proposed in #711.
2018-05-20 17:03:08 +01:00
Daniele Varrazzo
068b15c57f Merge branch 'fix-716' 2018-05-20 17:00:13 +01:00
Daniele Varrazzo
aac8a20fc1 Merge branch 'fix-707' 2018-05-20 14:07:10 +01:00
Daniele Varrazzo
c4da939909 Don't raise an exception closing an unused named cursor
Close #716
2018-05-20 14:00:09 +01:00
Daniele Varrazzo
49d9edce01 Set minimal postgres version for intervalstyle test 2018-05-20 13:40:57 +01:00
Daniele Varrazzo
3f389593f5 Raise NotSupportedError fetching iso_8601 intervals
Previously it would have failed parsing and resulted in ValueError

Close #707
2018-05-20 13:22:38 +01:00
Daniele Varrazzo
098c00d73e Merge remote-tracking branch 'nested-array-nulls' 2018-05-20 12:51:13 +01:00
Daniele Varrazzo
8c969304fd Merge remote-tracking branch 'fix-211' 2018-05-20 12:50:22 +01:00
Daniele Varrazzo
dd7e5c906f Skipped test on db version not supporting unicode identifiers 2018-05-18 12:16:43 +01:00
Daniele Varrazzo
eb570488a4 Test databases from newest to oldest
This way we can spot when a feature was not supported yet by the first
test failing.
2018-05-18 12:16:03 +01:00
Daniele Varrazzo
bc84b6233e Allow non-ascii chars in namedtuple fields
They can be valid chars in Python 3. Or maybe not? In which case Python
will throw an exception, but that's fine.

Fix regression introduced fixing #211
2018-05-18 12:15:50 +01:00
Daniele Varrazzo
8dd00ee874 Hstore test fixed after adapting arrays dropped space after commas 2018-05-18 12:11:02 +01:00
Daniele Varrazzo
b5e4a040f8 Fixed adaptation of arrays of arrays of nulls
Close #325, close #706.
2018-05-18 12:10:20 +01:00
Daniele Varrazzo
548e281350
Merge pull request #715 from hroncok/py37
Travis CI: Run tests on Python 3.7
2018-05-18 12:07:03 +01:00
Miro Hrončok
b52ff10153 Travis CI: Run tests on Python 3.7
Also, switch to wheel, because eggs caused problems on 3.7:

    ValueError: bad marshal data (unknown type code)
2018-05-18 12:12:09 +02:00
Ashesh Vashi
36f0db81d2 Fixed the string format error reported by Travis-CI.
Reference: https://travis-ci.org/psycopg/psycopg2/jobs/376288585
2018-05-08 15:29:16 +05:30
Ashesh Vashi
1bec2bdc43
Merge branch 'master' into master 2018-05-08 15:17:59 +05:30
Daniele Varrazzo
90b26c3e23 Merge branch 'fix-679' 2018-02-21 12:05:06 +00:00
Daniele Varrazzo
ea923b63a4 Allow strings subclasses in ensure_bytes
Fix #679
2018-02-21 10:27:28 +00:00
Daniele Varrazzo
0a5db6ecf5 Merge branch 'expand-version' 2018-02-19 13:54:11 +00:00
Daniele Varrazzo
ede418a009 Report MSYS2 build probably fixed 2018-02-19 13:53:50 +00:00
Daniele Varrazzo
32f5a9fc1d Avoid quoting the string in the psycopg version macro
Use a macro trick to add the quotes. This seems more portable than
passing the quotes to the command line (see #658).

https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html
2018-02-19 13:53:50 +00:00
Daniele Varrazzo
750ececf08 Merge branch 'fix-solaris-11' 2018-02-19 11:43:59 +00:00
Daniele Varrazzo
8670287928 Added Solaris 11 fix to news file 2018-02-19 11:43:37 +00:00
Mike Gerdts
f766d90704 Fixed building on SmartOS
timeradd is missing on Solaris 10, but is present as a macro in
<sys/time.h> on SmartOS, illumos, and likely Solaris 11.
2018-02-19 11:40:05 +00:00
Daniele Varrazzo
df952c149d Fixed pip invocation example to skip binary packages
Close #673
2018-02-09 16:12:29 +00:00
Daniele Varrazzo
5309da117d Autocommit shouldn't change deferrable on servers not supporting it
Regression on unsupported Postgres versions after fixing bug #580
2018-02-08 15:00:38 +00:00
Daniele Varrazzo
c52e49a9da Report Python 2.6 wheels no more available
[skip ci]
2018-01-29 12:58:28 +00:00
Daniele Varrazzo
1436ee308c Link psycopg2-binary package to PyPI in readme
Note: the package doesn't exist yet...
2018-01-29 03:31:49 +00:00
Daniele Varrazzo
9e6b22cc3b Merge branch 'namedtuple-invalid-identifiers' 2018-01-29 03:31:10 +00:00
Daniele Varrazzo
ddb87b7727 Convert fields names into valid Python identifiers in NamedTupleCursor
Close #211.
2018-01-29 03:30:46 +00:00
Daniele Varrazzo
3354bbd1b6 Merge branch 'openssl-1.0.2n' 2018-01-29 03:27:31 +00:00
Daniele Varrazzo
957fd79a27 Build using OpenSSL 1.0.2n 2018-01-29 03:27:08 +00:00
Daniele Varrazzo
8cc0d06e65 Define openssl and libpq versions in vars in appveyor build 2018-01-29 03:27:08 +00:00
Daniele Varrazzo
4845393c15 Build env vars on windows less verbose
Copied from psycopg2-wheels
2018-01-29 03:27:08 +00:00
Daniele Varrazzo
f85e405605 Merge branch 'separate-binary' 2018-01-29 03:24:45 +00:00
Daniele Varrazzo
f976c428d2 Mention new wheel packages in news file
Close #543.
2018-01-29 03:23:59 +00:00
Daniele Varrazzo
76f3e196d3 Silence warning on import failing a test 2018-01-29 03:23:59 +00:00
Daniele Varrazzo
5b69adf797 Document the psycopg2-binary package 2018-01-29 03:23:59 +00:00
Daniele Varrazzo
aa2c172706 Print info about the binary package on build failed
The idea is to release a package 'psycopg2-binary' to allow installing
binary, and leave the psycopg2 package to be source only, to avoid
pushing the unreliability of the wheel pacakge by default (see issue #543).

Version number bumped to test with new packages.
2018-01-29 03:22:59 +00:00
Daniele Varrazzo
8decf34ad7 Dropped warning about unsafe cursor names
It was long made secure
2018-01-25 22:00:40 +00:00
Daniele Varrazzo
da2aba1595 Merge branch 'fix-idempotence-check' 2018-01-11 02:41:38 +00:00
Daniele Varrazzo
74d2c4bef9 Fixed idempotence check changing connection characteristics 2018-01-11 02:23:27 +00:00
Daniele Varrazzo
6da3e7ee69 Merge branch 'mogrify-on-closed-cursor' 2018-01-11 00:16:01 +00:00
Daniele Varrazzo
ddef2e30cd 'key' docs in getconn() improved
Fix #569.
2018-01-11 00:14:36 +00:00
Daniele Varrazzo
a78ac3c125 Fixed test in asian time zones
Fix #652
2018-01-10 23:58:28 +00:00
Daniele Varrazzo
e0226fc46a 'cursor.mogrify()' can be called on closed cursors
Fix #579.
2018-01-11 08:55:31 +09:00
Daniele Varrazzo
04f1f06b9f Fixed stitch_text on Python 2 2018-01-10 22:49:00 +00:00
Daniele Varrazzo
bad9b8b383 Merge branch 'macro-accessors' 2018-01-10 22:47:59 +00:00
Daniele Varrazzo
b3a70e09e9 pypi3 fix noted in the news file 2018-01-10 22:44:37 +00:00
Daniele Varrazzo
77c703395b Moved datatime compatibility macros with others 2018-01-10 22:29:16 +00:00
Daniele Varrazzo
e50f3129c2
Merge pull request #651 from ronnix/patch-1
Fix typo in comment in utils.c
2017-12-14 13:45:09 +00:00
Ronan Amicel
b8f2f71819
Fix typo in comment in utils.c 2017-12-14 14:00:36 +01:00
Glyph
3fcb035126 define a "polyfill" inline for python 2 compatibility 2017-12-12 03:15:21 -08:00
Glyph
852884e086 use accessor macros for pypy3 compatibility 2017-12-12 03:06:18 -08:00
Jon Dufresne
be3b1ba1eb In tests, use compat.py where there is overlap 2017-12-11 20:27:52 -08:00
Jon Dufresne
8ad2098b74 Drop 2to3 build step; make all code compatible with all Pythons
Make all library code compatible with both Python 2 and Python 3. Helps
move to modern Python idioms. Can now write for Python 3 (with
workarounds for Python 2) instead of the other way around.

In the future, when it is eventually time to drop Python 2, the library
will be in a better position to remove workarounds

Added a very small comparability module compat.py where required. It
includes definitions for:

- text_type -- A type. str on Python 3. unicode on Python 2.
- string_types -- A tuple. Contains only str on Python 3. Contains str &
                  unicode on Python 2.
2017-12-11 20:26:58 -08:00
Jon Dufresne
f35465231f Drop the Python 2 style interface from DictRow
Now standardizes on the Python 3 interface for all uses. Makes behavior
of DictRow between Pythons more consistent and predictable.
2017-12-11 20:02:16 -08:00
Jon Dufresne
3a6a8e96fb User super() throughout DictRow class
Avoid calling parent method directly.
2017-12-11 19:01:38 -08:00
Daniele Varrazzo
2cd9a78a97 Gitignore env2/env3 envs too 2017-12-11 02:25:13 +00:00
Daniele Varrazzo
4be2b75816 Dropped PYTHONPATH propagation in 'make check'
Psycopg doesn't have other dependencies outside the stdlib so what's
there is probably just noise.
2017-12-11 02:22:02 +00:00
Daniele Varrazzo
f3d21c24fc
Merge pull request #644 from jdufresne/noinstall-tests
Avoid installing tests to site-packages
2017-12-11 02:20:56 +00:00
Jon Dufresne
389f6c08d9 Avoid installing tests to site-packages
For library end users, there is no need to install tests alongside the
package itself. This keeps the tests available for development without
adding extra packages to user's site-packages directory. Reduces the
size of the installed package. Avoids accidental execution of test code
by an installed package.
2017-12-10 10:55:58 -08:00
Jon Dufresne
c86e682153 Skip register_hstore(..., unicode=True) tests on Python 3
Per the functions documentation, this argument is not supported on
Python 3. Skip it during tests.

> :param unicode: if `!True`, keys and values returned from the database
> will be `!unicode` instead of `!str`. The option is not available on
> Python 3

Work towards moving tests outside of the installed package.
2017-12-10 10:51:07 -08:00
Jon Dufresne
1a8e992fcc Use relative imports throughout tests
The tests relied on Python2 relative import semantics. Python3 changed
import semantics to always search sys.path by default. To import using a
relative path it must have a leading dot.

Forward compatible with newer Pythons.

Works towards the goal of moving tests outside of the installed package.

For more information, see PEP-328:

https://www.python.org/dev/peps/pep-0328/
2017-12-10 10:51:07 -08:00
Jon Dufresne
9de46e416e Use print() function instead of print statement throughout project
Forward compatible with newer Pythons.
2017-12-10 10:51:07 -08:00
Jon Dufresne
ef64493b89 Fix use of "async" in test_cursor.py
"async" will be a keyword starting with Python 3.7. On Python 3.6, use
of "async" causes a deprecation warning. Use the alias "async_" instead.
2017-12-10 10:49:04 -08:00
Daniele Varrazzo
b42c35849b
Merge pull request #647 from jdufresne/drop-unused-scripts
Remove unused scripts maketypes.sh & buildtypes.py
2017-12-10 18:26:29 +00:00
Jon Dufresne
1047af03da Remove unused scripts maketypes.sh & buildtypes.py
Refs #645
2017-12-10 09:57:43 -08:00
Daniele Varrazzo
afd7c6c284
Merge pull request #646 from jdufresne/drop-deprecated
Drop long deprecated function register_tstz_w_secs()
2017-12-10 17:43:01 +00:00
Jon Dufresne
19b1efd629 Drop long deprecated function register_tstz_w_secs()
Deprecated in commit b263fbf274 on
2010-01-13. The deprecation warning was first released in version 2.2.2.

The function used to register an alternate type caster for TIMESTAMP
WITH TIME ZONE to deal with historical time zones with seconds in the
UTC offset. These are now correctly handled by the default type caster,
so currently the function doesn't do anything.
2017-12-10 07:57:11 -08:00
Daniele Varrazzo
ec0a3d59a8 Merge branch 'goodbye-psycopg1' 2017-12-04 12:12:37 +00:00
Daniele Varrazzo
861e389fcf Dropped psycopg1 module 2017-12-04 11:56:27 +00:00
Daniele Varrazzo
2218e73c28 Merge branch 'master' into ws 2017-12-02 14:47:29 +00:00
Daniele Varrazzo
7617e1dbf5 Dropped .sln file 2017-12-02 14:46:03 +00:00
Daniele Varrazzo
df646831d7 Merge remote-tracking branch 'jdufresne/egg-info' 2017-12-02 12:11:10 +00:00
Daniele Varrazzo
06396e5162 Merge remote-tracking branch 'jdufresne/import-unittest' 2017-12-02 12:10:26 +00:00
Daniele Varrazzo
aae5d6364f Merge remote-tracking branch 'jdufresne/leading0' 2017-12-02 12:07:57 +00:00
Daniele Varrazzo
5a3cf32fe5 Merge remote-tracking branch 'jdufresne/next-func' 2017-12-02 12:07:47 +00:00
Daniele Varrazzo
2c5cad1525 Merge remote-tracking branch 'jdufresne/more-json' 2017-12-02 12:07:06 +00:00
Daniele Varrazzo
8f6d744b5d Merge remote-tracking branch 'jdufresne/sorted' 2017-12-02 12:06:05 +00:00
Daniele Varrazzo
ccc3820f8e Merge remote-tracking branch 'jdufresne/script-to-py3' 2017-12-02 12:05:53 +00:00
Jon Dufresne
699be52e8b Remove unnecessary script_to_py3; make scripts compatible instead
Part of the work towards moving tests out of the installed package.
2017-12-01 22:50:16 -08:00
Jon Dufresne
94bb238b70 Remove sorted() workaround; available on all supported Pythons
Introduced in Python 2.4 and the oldest supported Python is 2.7.

https://docs.python.org/2/library/functions.html#sorted
2017-12-01 22:03:38 -08:00
Jon Dufresne
e335d6d223 Trim trailing whitespace from all files throughout project
Many editors automatically trim whitespace on save. By trimming all
 files in one go, makes future diffs cleaner without extraneous
 whitespace changes.
2017-12-01 21:42:14 -08:00
Jon Dufresne
d0c7126aa8 Remove test decorators for json module
The json module is available in all Python versions supported by
psycopg2. No need to check for its presence when executing tests.

Should have been included with d58844e548
but was missed.
2017-12-01 21:06:10 -08:00
Jon Dufresne
f5703dc3e5 Use builtin function next() throughout project
Available since Python 2.6. Use of .next() is deprecated and not
supported in Python 3. Forward compatible with modern Python.

https://docs.python.org/2/library/functions.html#next
2017-12-01 19:57:37 -08:00
Jon Dufresne
56ec575351 Drop leading 0's from numeric literals
Not compatible with Python3. Makes the code more forward compatible with
modern Pythons.

In Python2, it was an alternative syntax for octal.

$ python3
>>> 01
  File "<stdin>", line 1
    01
     ^
SyntaxError: invalid token
2017-12-01 19:00:53 -08:00
Jon Dufresne
fcc083dc12 Always import the system unittest
There is no need to import testutils.unittest instead of simply
unittest. They are simple aliases. Use system unittest to be more
regular, consistent as well as idiomatic with the wider Python
community.
2017-12-01 18:35:30 -08:00
Jon Dufresne
6a1546adde Add *.egg-info directories to .gitignore 2017-12-01 18:21:50 -08:00
Daniele Varrazzo
a51160317c Fixed NEWS file entries
- 2.6.3 has not been released (yet). Fixes for bug #420, bug #462 were
  relased in 2.7.
- Added missing report for bug #489 fixed in 2.7.
2017-12-01 16:29:29 +00:00
Daniele Varrazzo
f4aa40da09 Merge branch 'bug-633' 2017-11-29 15:42:29 +00:00
Daniele Varrazzo
65ed5478d1 Collect rowcount in executemany even when discarding results
Closes #633.
2017-11-29 15:42:04 +00:00
Daniele Varrazzo
727b952a32 Build and test packages with libpq 10.1 and OpenSSL 1.0.2m 2017-11-28 17:19:55 +00:00
Daniele Varrazzo
0d5b0f0287 Merge branch 'fix-libpq-version' 2017-11-28 17:19:30 +00:00
Daniele Varrazzo
87da2f898d Fixed __libpq_version__ for Postgres >= 10.1
The version should be considered as 10.0.1; the number was generated as
10.1.0 instead.

Version number bumped to test building new wheels packages.

Fix #632.
2017-11-28 17:19:01 +00:00
Daniele Varrazzo
3e52b5445b Merge branch 'rm-eol'
Fix #626, close #628.
2017-11-28 16:27:41 +00:00
Daniele Varrazzo
f939f39580 Use dict comprehensions 2017-11-28 16:11:06 +00:00
Daniele Varrazzo
c3ee9cac41 Dropped unused test functions 2017-11-28 16:11:06 +00:00
Daniele Varrazzo
a0229cff82 Documentation tweaked to omit Python 2.6 distinctions 2017-11-28 16:11:06 +00:00
Hugo
60b1517c55 Add news and update version check 2017-11-28 16:11:02 +00:00
Hugo
c2d082e896 Drop support for EOL Python 3.0-3.3 2017-11-28 16:06:55 +00:00
Hugo
ea76504cd1 Remove trailing semicolons 2017-11-28 16:06:55 +00:00
Hugo
283de27098 Remove redundant parentheses 2017-11-28 16:06:52 +00:00
Hugo
08b479bc10 __slots__ should be a tuple 2017-11-28 16:05:59 +00:00
Hugo
7282ef0d14 Rewrite list creation as list literal 2017-11-28 16:03:23 +00:00
Hugo
955526b200 Replace comparison with None with equality operator 2017-11-28 16:03:23 +00:00
Hugo
b69457ccdf Update to Exception as e, print() 2017-11-28 16:03:23 +00:00
Hugo
2f3c233f38 Simplify Boolean 2017-11-28 16:03:23 +00:00
Hugo
53c1c5dcc1 Remove redundant hasattr checks 2017-11-28 16:03:23 +00:00
Hugo
ffcc65d4f0 Drop support for EOL Python 2.6 2017-11-28 16:02:12 +00:00
Daniele Varrazzo
e7529e4823 Merge remote-tracking branch 'jdufresne/json-docs' 2017-11-28 15:22:09 +00:00
Daniele Varrazzo
f77057dd43 Merge remote-tracking branch 'jdufresne/with-statement' 2017-11-28 15:20:24 +00:00
Jon Dufresne
c1d3948be9 Update documentation to reflect JSON import behavior
The docs don't need to describe what will happen on Python versions
before 2.6 as they are unsupported by psycopg2.

Should have been included in commit
d58844e548, but was missed.
2017-11-28 06:38:44 -08:00
Jon Dufresne
4c95668c72 Remove "from __future__ import with_statement"
All versions of Python supported by psycopg2 have builtin support for
the with statement. The import is unnecessary noise.
2017-11-28 06:03:46 -08:00
Daniele Varrazzo
914ccbacb5 Merge branch 'python3_mintimeloggingconnection' 2017-11-28 03:23:42 +00:00
Daniele Varrazzo
b4f066bd43 Mention MinTimeLoggingCursor fix in NEWS file 2017-11-28 03:22:53 +00:00
Daniele Varrazzo
1959d2403f Merge branch 'solaris-support' 2017-11-28 03:16:04 +00:00
Daniele Varrazzo
a1831ef498 Mention solaris support in NEWS
Close #532.
2017-11-28 03:13:25 +00:00
Daniele Varrazzo
fc8574fdd8 Merge remote-tracking branch 'jdufresne/decimal' 2017-11-28 03:05:06 +00:00
Daniele Varrazzo
06d4788811 Merge remote-tracking branch 'jdufresne/json' 2017-11-28 03:04:59 +00:00
Daniele Varrazzo
e0ce35ef72 Merge remote-tracking branch 'jdufresne/skip-before' 2017-11-28 03:04:44 +00:00
Daniele Varrazzo
db0c081d03 Merge remote-tracking branch 'jdufresne/uuid' 2017-11-28 03:04:26 +00:00
Daniele Varrazzo
a39d794308 Merge remote-tracking branch 'jdufresne/iobase' 2017-11-28 03:04:03 +00:00
Daniele Varrazzo
7855f28785 Merge remote-tracking branch 'jdufresne/namedtuple' 2017-11-28 03:02:56 +00:00
Daniele Varrazzo
dda55dbf36 Moving to next major version on master
Opened maintenance branch `maint_2_7`
2017-11-28 03:02:03 +00:00
Daniele Varrazzo
afb42e7625 Merge remote-tracking branch 'jdufresne/py2' 2017-11-28 02:59:17 +00:00
Daniele Varrazzo
b4e658d29b Merge remote-tracking branch 'jdufresne/license' 2017-11-28 02:39:54 +00:00
Jon Dufresne
296abf735e Add some missing trove classifiers for general Python support 2017-11-27 07:30:50 -08:00
Jon Dufresne
048f1bb95a Remove workaround for decimal module
The decimal module is available on all Python versions supported by
psycopg2. It has been available since Python 2.4. No need to catch an
ImportError.

https://docs.python.org/2/library/decimal.html
2017-11-26 17:55:24 -08:00
Jon Dufresne
d58844e548 Clean up JSON workarounds for unsupported Python versions
All Python versions supported by psycopg2 have the json module. It was
added in Python 2.6. Can remove checks for availability, slightly
simplifying the code.
2017-11-26 17:11:27 -08:00
Jon Dufresne
dfc9932f27 Remove use of skip_before_python for unsupported Python versions
psycopg2 does not support Python < 2.6, remove all test guards for these
versions.
2017-11-26 16:43:18 -08:00
Jon Dufresne
582ec189cc Remove uuid workaround for older Pythons
uuid is available on all Python versions supported by psycopg2.
2017-11-26 14:46:53 -08:00
Jon Dufresne
f7d5d25651 Remove io.TextIOBase workaround for Python <= 2.5
io.TextIOBase is available on all Python versions supported by psycopg2.
Can remove all workarounds.
2017-11-26 14:32:35 -08:00
Jon Dufresne
05c28cce78 Remove workarounds for namedtuple on Python <= 2.5
namedtuple is available on all Python versions supported by psycopg2. It
was first introduced in Python 2.6. Can remove all workarounds and
special documentation.
2017-11-26 13:55:30 -08:00
Jon Dufresne
5ddac80cec Include license file in the generated wheel package
The wheel package format supports including the license file. This is
done using the [metadata] section in the setup.cfg file. For additional
information on this feature, see:

https://wheel.readthedocs.io/en/stable/index.html#including-the-license-in-the-generated-wheel-file
2017-11-26 10:42:30 -08:00
Daniele Varrazzo
858bc3d42a
Merge pull request #616 from jdufresne/modern-exceptions
Use modern except syntax throughout project
2017-11-21 11:45:34 +00:00
Jon Dufresne
390e43fcb1 Use modern except syntax throughout project
The syntax "except Exception, exc:" is deprecated. All Python versions
supported by psycopg2 support the newer, modern syntax. Forward
compatible with future Python versions.
2017-11-20 20:00:35 -08:00
Daniele Varrazzo
7a2dd85caa NEWS updated after last bugfix. 2017-11-16 16:07:34 +00:00
Federico Di Gregorio
13b0b9d3e3
Merge pull request #614 from fogzot/fix-613
Don't cast point arrays to float arrays (fixes: #613)
2017-11-16 10:09:28 +01:00
Federico Di Gregorio
5983b96c55 Don't cast point arrays to float arrays (fixes: #613) 2017-11-16 10:07:27 +01:00
Daniele Varrazzo
d88d8f9619 Added PostgreSQL 10 in the list of supported servers 2017-11-06 18:38:22 +00:00
Daniele Varrazzo
9614e7241b Further docs cleanup
Recent Sphinx versions seem overly aggressive in autodetecting python,
or I just didn't notice the errors, so be explicit in what language to
use with code examples.
2017-11-06 18:34:23 +00:00
Daniele Varrazzo
4f1505857b Parameters passing docs improved
Every point has an example and all the example show wrong/correct. Nice
rhythm.

Among the improvements, added point saying explicitly "thou shall not
quote placeholders".  Quoted placeholders will just fail except in the
most contrived cases (a statement raising an exception with all the
strings except with the attack ones...), and an example in the following
section explicitly notes "no quotes", but apparenty someone still thinks
this is not documented enough? (see issue #611) so let's just write it
plain and clear into the list of commandments.
2017-11-06 17:31:35 +00:00
Kevin Campbell
b804c092ac Patch for issue #609 for MinTimeLoggingConnection
On Python3 MinTimeLoggingConnection raises an exception as it tries to
mix strings and bytes
2017-11-03 17:30:06 +08:00
Daniele Varrazzo
dfee199351 Dropped suggestion for --no-binary :all: to skip wheels
:all: applies to the entire file. --no-binary psycopg2 is the solution.

See issue #543
2017-10-27 12:34:00 +01:00
My Karlsson
f54783ae6e Emulate timeradd and timersub on Solaris
Solaris does not have timeradd and timersub. Add solaris_support.c which
provides emulated versions of them on Solaris.
2017-10-26 20:21:30 +02:00
Daniele Varrazzo
46d8529dde Merge branch 'libpq-10-wheels' 2017-10-24 11:52:02 +01:00
Daniele Varrazzo
980145eaee Preparing release 2.7.3.2
Close #601, close #602.
2017-10-24 11:43:26 +01:00
Daniele Varrazzo
c6e90766e1 Merge branch 'libpq-10'
Fix #604
2017-10-24 11:31:26 +01:00
Daniele Varrazzo
f3f394ced9 Import recipe to build PG 10 libpq on win from wheel repos
Also build pg_config so the libpq version is correct at compile time
too.
2017-10-24 11:26:14 +01:00
Daniele Varrazzo
552e49a11d Test building PG 10 using the solution provided by Jason Erickson
https://github.com/psycopg/psycopg2-wheels/pull/3/
2017-10-24 11:26:14 +01:00
Daniele Varrazzo
0d90c173fb Test against PG 10.0 on Travis 2017-10-24 11:26:14 +01:00
Daniele Varrazzo
f1461d2d7e Parse PG 10 error codes from final version 2017-10-19 02:28:52 +01:00
Daniele Varrazzo
6ee8b4c9aa Bumping version to test libpq 10 wheel package 2017-10-18 22:25:42 +01:00
Daniele Varrazzo
582fd95986 Merge branch 'sphinx-1.6' 2017-10-18 21:58:08 +01:00
Daniele Varrazzo
e7587caee3 Dropped doc building warning
doctests have sure completely rotten however.
2017-10-18 21:57:17 +01:00
Daniele Varrazzo
4d68f6e414 Sphinx version do build docs updated to 1.6 2017-10-18 21:56:48 +01:00
Dmitry Shachnev
1ccb61fe18 Make dbapi_extension.py compatible with Sphinx 1.6
In Sphinx commit 1a821b89e9952fc2, the deprecated make_admonition()
function was removed. This commit updates the code to use the modern
API instead.
2017-10-12 13:10:41 +03:00
Ashesh Vashi
84d405894c Moving the encrypt_password method from the connection class to the
psycopgmodule, and exported it from psycopg2.extensions as per review
comments.
2017-09-14 23:42:54 +05:30
Ashesh Vashi
6e0edf7779 Merge remote-tracking branch 'psycopg2/master' 2017-09-11 18:26:34 +05:30
Daniele Varrazzo
3ec06b88f0 Construct proper human sentences to describe execute_values()
With bonus typos dropped.
2017-08-31 16:34:04 +01:00
Daniele Varrazzo
75198a46d4 Merge branch 'fix-wheel-libresolv' 2017-08-25 15:13:36 +01:00
Daniele Varrazzo
c45e219387 Preparing release 2.7.3.1 to fix wheel packages 2017-08-25 15:12:12 +01:00
Daniele Varrazzo
302b2f962f Bump version number to try fixing libc 2.26 libresolv problem
https://github.com/psycopg/psycopg2-wheels/issues/2

[skip-ci]
2017-08-25 12:24:37 +01:00
Daniele Varrazzo
22c7114168 Disable uploading docs on pythonhosted
The service is deprecated in favour of RTD. There is also no more way to
upload redirects there, so #581 cannot be fixed.

Official docs are on http://initd.org/psycopg/docs/
2017-08-23 13:42:49 +01:00
Daniele Varrazzo
2c836a2935 Fixed typo (found on stackoverflow... gh) 2017-07-27 12:10:11 +01:00
Daniele Varrazzo
df688d6b87 Bump to next development release 2017-07-24 16:25:16 +01:00
Daniele Varrazzo
cd3393b21c Bumped version number to 2.7.3 2017-07-24 15:06:09 +01:00
Daniele Varrazzo
9358725963 Merge branch 'fix-578' 2017-07-24 15:04:26 +01:00
Daniele Varrazzo
775de754cf Added back timestamptz[] default cast
It was registered as side effect of an excessive definition that got
cleaned up in 338dbe70a6.

Looking at other removed redundant type oids, this was the only one
missing from the `string_types` map.

Close #578.
2017-07-24 14:23:36 +01:00
Daniele Varrazzo
b7bd5eceed Bump to next development release 2017-07-22 16:13:10 +01:00
Daniele Varrazzo
cfa0509d7e Deal with E'' strings comparisons in a few other tests 2017-07-22 03:15:06 +01:00
Daniele Varrazzo
d619baf000 Skipped a couple of test with unsupported postgres features 2017-07-22 02:09:24 +01:00
Daniele Varrazzo
791f5fe969 Bump to version 2.7.2 2017-07-22 01:32:25 +01:00
Ashesh Vashi
e089d94c88 'encrypt_password' raises 'psycopg2.NotSupportedErorr' exception for
server version >= 10, when compiled using libpq version < 10, when no
algorithm is specified.
2017-07-17 11:46:50 +05:30
Ashesh Vashi
2c1966a7f6 When compiled with libpq version < 10, it raises 'psycopg2.NotSupportedError' (not, psycopg2.ProgrammingError). 2017-07-17 11:06:55 +05:30
Ashesh Vashi
78eb80d0cf Using 'Text_FromUTF8' macro for transforming the encrypted C string to
Python string to make it Python 3 compatible.
2017-07-17 10:54:52 +05:30
Ashesh Vashi
cfb0937605 Added support for preparing the encrypted password of a PostgreSQL
password using the libpq functions - 'PQencryptPasswordConn', and
'PQencryptPassword'.
2017-07-17 10:32:59 +05:30
Daniele Varrazzo
d2e86db8fb Merge branch 'fix-554' 2017-06-17 03:34:01 +01:00
Daniele Varrazzo
1a97445471 Accept Composable in start_replication_expert()
Close #554
2017-06-17 03:30:44 +01:00
Daniele Varrazzo
30d89da4fa Ignore spurious output in test with Python debug build 2017-06-17 03:20:09 +01:00
Daniele Varrazzo
d72efd2fa8 Merge branch 'fix-550' 2017-06-17 01:58:11 +01:00
Daniele Varrazzo
991f0988ee Use an import style reported not broken on Python 3.6
Couldn't reproduce the issue but it has been documented in #550.
2017-06-17 01:51:37 +01:00
Daniele Varrazzo
8ab16807c6 Merge branch 'fix-558' 2017-06-17 01:38:25 +01:00
Daniele Varrazzo
49ce622a86 Fixed parsing interval from micros on 32 bit
Using integers the wrong size. Faithfully segfaulting since 1970.
2017-06-17 01:36:39 +01:00
Daniele Varrazzo
2b5e131831 Merge branch 'fix-558' 2017-06-16 19:41:52 +01:00
Daniele Varrazzo
70a2d2238e Consider redshift interval supported after further tests 2017-06-16 19:39:18 +01:00
Daniele Varrazzo
324e56cfa3 Merge branch 'fix-562' 2017-06-16 02:32:31 +01:00
Daniele Varrazzo
789eb64f3a Added Json.prepare()
Close #562
2017-06-16 01:37:49 +01:00
Daniele Varrazzo
21ee8b62ef Merge branch 'mr-566' 2017-06-16 01:04:27 +01:00
Daniele Varrazzo
315f72862c Parse a number as microseconds when casting interval
Should close #558, but I'm curious to know if a number is returned
for interval < 1 day too (which wouldn't trigger the overflow, but will
finish parsing with part=0).
2017-06-16 00:54:38 +01:00
Sebastian Bank
30af82ef2f Document that executemany() is not logged with LoggingConnection 2017-06-15 23:27:28 +01:00
Daniele Varrazzo
eef198ac5e Report issue #541 fixed in the NEWS file 2017-06-15 23:25:19 +01:00
Daniele Varrazzo
8576d43006 Bump version number to test a new build 2017-06-15 23:07:43 +01:00
Daniele Varrazzo
9b4de93bdc Document incompatibility between wheel package and ssl module
Close #543.
2017-06-15 22:46:53 +01:00
Daniele Varrazzo
338dbe70a6 Dropped wrong associations of PG types to datetime object
The wrong associations are overwritten in the typecaster map by the
right ones, so they have been harmless to date, but only because of the
order of creation of the adapters.
2017-06-15 18:24:25 +01:00
Daniele Varrazzo
496cef80c4 Merge branch 'bug-551' 2017-06-15 17:46:04 +01:00
Daniele Varrazzo
7ae2cb5cd0 Don't force a valid return code for the test
Windows returns 22, Linux returns 1
2017-06-15 17:39:00 +01:00
Daniele Varrazzo
602c74faa6 Check return code from decoding the connection status
It fails on Py3 after receiving a SIGABRT. Because we don't handle it
here it will resurface later with nonsense such as:

    SystemError: <some function> returned a result with an error set

Close #551
2017-06-15 17:33:05 +01:00
Daniele Varrazzo
de843ef756 Added test to reproduce bug #551 2017-06-15 17:22:32 +01:00
山楂片
799c5aaf43 typo
s/fromat/format/g
2017-06-12 11:25:22 +01:00
Jason Erickson
9ac2b8c3a9 Force rebuild of cache for new OpenSSL/PostgreSQL
OpenSSL updated to 1.0.2l
PostgreSQL updated to 9.6.3
2017-06-08 20:11:20 -06:00
Jason Erickson
63cc9ea24b Build/Test against newer PostgreSQL/OpenSSL
Test against PostgreSQL 9.6 and build against newer libraries:
	OpenSSL: 1.0.2l
	PostgreSQL: 9.6.3
2017-06-08 20:11:17 -06:00
Jason Erickson
c837261ac1 Remove VC9 runtime dependency
Changed check in setup.py to only use vc9 manifest when built against
versions that use the MSVC 2008 compiler.  Resolves #541.

Note that as of VS 2010, a manifest is no longer needed according to this
comment, "...we are no longer deploying the VC dlls as Win32 assemblies.
They are regular dlls that can be loaded without a manifest."

https://connect.microsoft.com/VisualStudio/feedback/details/522121/crtassem-h-missing
2017-06-08 20:11:02 -06:00
Daniele Varrazzo
3d13a2cf25 Link the appveyor badge in the readme to the master branch builds
[skip-ci]
2017-06-08 20:07:11 +01:00
Daniele Varrazzo
7d9ef5f952 Run tests against PostgreSQL 10 beta1
Use the new Postgres verisoning schema: 10 is a major version, 10.0 a
patch release. See
https://wiki.postgresql.org/wiki/New_in_postgres_10#Change_in_Version_Numbering
2017-06-08 18:45:07 +01:00
Daniele Varrazzo
767118467f Merge branch 'errcodes-update' 2017-06-05 12:49:42 +01:00
Daniele Varrazzo
256910f8ff Updated docs about versions supported in errcodes 2017-06-05 12:34:17 +01:00
Daniele Varrazzo
89169e6e53 Error codes updated to PG 10 beta 1 2017-06-05 12:34:17 +01:00
Daniele Varrazzo
75d84f0b25 errcodes updated to PG 9.6 2017-06-05 12:18:21 +01:00
Daniele Varrazzo
165449c724 Added doc link to replication commands 2017-05-10 01:55:01 +01:00
Daniele Varrazzo
6e5abf33f2 Merge branch 'fix-547' 2017-04-19 01:34:39 +01:00
Daniele Varrazzo
9d7ff405ee Added news entries for the previous 2 merge requests 2017-04-19 01:16:08 +01:00
Daniele Varrazzo
a7e3f46431 Merge remote-tracking branch 'fix_lobject_factory' 2017-04-19 01:06:24 +01:00
Daniele Varrazzo
bd34c86aba Merge remote-tracking branch 'fix_lobject_mode' 2017-04-19 01:06:08 +01:00
Daniele Varrazzo
248e653c9e Fixed args parsing in ReplicationCursor.consume_stream()
Close #547.
2017-04-19 01:01:59 +01:00
Frazer McLean
9e5621698f Python < 3.2 doesn’t have assertIsInstance 2017-04-16 03:44:21 +02:00
Frazer McLean
7b3ea43e92 Handle lobject mode=None correctly 2017-04-16 03:20:31 +02:00
Frazer McLean
38cd720369 Fix name of lobject keyword argument 2017-04-16 03:12:18 +02:00
Daniele Varrazzo
4b4d2796b7 Merge branch 'fix-410' 2017-04-05 15:16:01 +01:00
Daniele Varrazzo
cd095ef0ee Added test to verify callback errors in named cursors
They work fine.
2017-04-05 14:54:07 +01:00
Daniele Varrazzo
a66c34a6d0 Don't clobber a Python exception with an unknown error
Close #410
2017-04-05 14:54:07 +01:00
Daniele Varrazzo
47f5e97759 Added test to verify #410
The 'unknown error' happens on query.
2017-04-05 14:54:07 +01:00
Daniele Varrazzo
3b48918bef Note that the fast executemany functions don't respect rowcount
See issue #540
2017-03-28 10:37:04 +01:00
Daniele Varrazzo
adf55babe8 Merge remote-tracking branch 'origin/fix-536' 2017-03-22 12:19:31 +00:00
Daniele Varrazzo
b94548f5a3 Fix curl not found on AppVeyor
http://help.appveyor.com/discussions/problems/6312-curl-command-not-found
2017-03-22 03:54:23 +00:00
Daniele Varrazzo
ee9948fa86 Expose *DATETIMETZ* objects in the extensions module 2017-03-22 03:42:12 +00:00
Daniele Varrazzo
57b1093b31 Find again mxDateTime includes in default locations 2017-03-22 03:36:08 +00:00
Daniele Varrazzo
7214c6652e Return objects with timezone parsing infinity timestamptz
Close #536.
2017-03-22 03:03:02 +00:00
Daniele Varrazzo
31f91e033f Dropped info that the features requires libpq >= 9.0
We are currently requiring libpq 9.1 at least, and the feature was
released in 2.7, which could have never been compiled with previos
libpq versions.
2017-03-20 19:08:18 +00:00
Daniele Varrazzo
1e0aef032f Dropped repeated doc links in the same paragraph
And some more sql docs cleanup.
2017-03-16 04:40:22 +00:00
Daniele Varrazzo
f9b36433fb Merge branch 'fix-528' 2017-03-16 04:24:17 +00:00
Daniele Varrazzo
ba0329fb40 replication connection init refactored to use psyco_make_dsn
Some extra bonus refactoring to improve the function readability (don't
reuse names for variables with different refcount rules, don't pass
separate obj/self, async pass-through...)
2017-03-16 03:55:22 +00:00
Daniele Varrazzo
9f160fd820 Obscure the password on url dsn too
Note that we don't leak anymore the password length.

Fix #528
2017-03-16 03:53:40 +00:00
Daniele Varrazzo
c7f5690426 Added docs about the usability of sql objects with copy_expert()
See issue #529.
2017-03-16 00:55:20 +00:00
Daniele Varrazzo
3bfbd3a0a5 Added test to verify sql objects work with copy_expert()
I'll be honest: I lucked out, I didn't think about this combination. But
maybe sheer luck, maybe using common code paths, it just works. Let's
make it stays so.
2017-03-16 00:55:20 +00:00
Daniele Varrazzo
103655d670 Password scrubbing refactored in a separate function 2017-03-15 16:04:45 +00:00
Daniele Varrazzo
cc047a445a Added tests to verify the password is obscured
The url test fails: see issue #528
2017-03-15 16:00:40 +00:00
Daniele Varrazzo
7187d6408a Merge branch 'fix-443' 2017-03-14 14:41:48 +00:00
Daniele Varrazzo
3626e961f8 Reported bug #443 fixed *again*
Also see ticket #527.
2017-03-14 14:16:02 +00:00
Daniele Varrazzo
8e28444897 Bunch of test tweaks to make the test grid green 2017-03-14 14:15:52 +00:00
Daniele Varrazzo
7c2333dd81 Connection state fixed noted in the news 2017-03-14 14:15:52 +00:00
Greg Ward
12317557da Always raise OperationalError when connection was closed externally.
From the DB-API (https://www.python.org/dev/peps/pep-0249/):

  OperationalError

  Exception raised for errors that are related to the database's
  operation and not necessarily under the control of the programmer,
  e.g. an unexpected disconnect occurs, [...]

Additionally, psycopg2 was inconsistent, at least in the async case:
depending on how the "connection closed" error was reported from the
kernel to libpq, it would sometimes raise OperationalError and
sometimes DatabaseError. Now it always raises OperationalError.
2017-03-14 12:14:00 +00:00
Greg Ward
b203a7c775 Always detect when a connection is closed behind psycopg2's back.
There's a race condition that only seems to happen over Unix-domain
sockets. Sometimes, the closed socket is reported by the kernel to
libpq like this (captured with strace):

  sendto(3, "Q\0\0\0\34select pg_backend_pid()\0", 29, MSG_NOSIGNAL, NULL, 0) = 29
  recvfrom(3, "E\0\0\0mSFATAL\0C57P01\0Mterminating "..., 16384, 0, NULL, NULL) = 110
  recvfrom(3, 0x12d0330, 16384, 0, 0, 0)  = -1 ECONNRESET (Connection reset by peer)

That is, psycopg2/libpq sees no error when sending the first query
after the connection is closed, but gets an error reading the result.
In that case, everything worked fine.

But sometimes, the error manifests like this:

  sendto(3, "Q\0\0\0\34select pg_backend_pid()\0", 29, MSG_NOSIGNAL, NULL, 0) = -1 EPIPE (Broken pipe)
  recvfrom(3, "E\0\0\0mSFATAL\0C57P01\0Mterminating "..., 16384, 0, NULL, NULL) = 110
  recvfrom(3, "", 16274, 0, NULL, NULL)   = 0
  recvfrom(3, "", 16274, 0, NULL, NULL)   = 0

i.e. libpq received an error when sending the query. This manifests as
a slightly different exception from a slightly different place. More
importantly, in this case connection.closed is left at 0 rather than
being set to 2, and that is the bug I'm fixing here.

Note that we see almost identical behaviour for sync and async
connections, and the fixes are the same. So I added extremely similar
test cases.

Finally, there is still a bug here: for async connections, we
sometimes raise DatabaseError (incorrect) and sometimes raise
OperationalError (correct). Will fix that next.
2017-03-14 12:08:03 +00:00
Daniele Varrazzo
3c124a0b87 Flake8 complaints 2017-03-14 12:06:46 +00:00
Daniele Varrazzo
ef9f9f5fff Improved notes to release psycopg packages 2017-03-13 16:50:57 +00:00
Daniele Varrazzo
5730aa9a40 Less stuff in the readme, more in the docs 2017-03-13 12:13:47 +00:00
Daniele Varrazzo
8ed0196d02 Bump to next dev release 2017-03-13 11:50:34 +00:00
Daniele Varrazzo
09c48c76c3 Bump to version 2.7.1 2017-03-11 17:03:22 +00:00
Daniele Varrazzo
b075c7169c Report ticket 518 fixed
The fix is actually implemented in the openssl1 branch of
https://github.com/psycopg/psycopg2-wheels
2017-03-11 17:00:58 +00:00
Jon Nelson
c661695b28 correct minor grammatical issue with deprecation warning 2017-03-03 13:54:22 +00:00
Daniele Varrazzo
06fbd0ee02 Dropped "what's new in 2.7.1" from docs index 2017-03-03 13:50:57 +00:00
Daniele Varrazzo
e3f56718d2 Added install section to specify how to skip wheels 2017-03-03 13:49:19 +00:00
Daniele Varrazzo
d007dc3249 Merge branch 'fix-520' 2017-03-02 19:36:45 +00:00
Daniele Varrazzo
a5382d7b72 Skip the tests according to the earliest of libpq built/linked. 2017-03-02 19:32:44 +00:00
Daniele Varrazzo
26bd5df048 Don't use PG_INT64_TYPE
Only defined in Postgres 9.3

Should close #520, but let's wait for the CI response (build on
Windows etc.)
2017-03-02 19:32:39 +00:00
Daniele Varrazzo
3a441467c0 Merge branch 'no-unittest2'
Close #516
2017-03-02 12:41:33 +00:00
Daniele Varrazzo
6be94f1927 Merge branch 'fix-517' 2017-03-02 12:22:27 +00:00
Daniele Varrazzo
5a65ff5cf4 Don't try to use unittest2
Modules importing unittest directly would miss the monkeypatch: see
ticket #516.
2017-03-01 20:44:04 +00:00
Daniele Varrazzo
44d8edfd8c Ignore None arguments passed to make_dsn()
Close #517.
2017-03-01 20:12:13 +00:00
Daniele Varrazzo
455f51c36c Added docs about making a release
Drop previous script which didn't include the CI-generated packages.

[skip ci]
2017-03-01 15:59:15 +00:00
Daniele Varrazzo
6f7e570a0a Bump away from 2.7
[skip ci]
2017-03-01 15:56:54 +00:00
Daniele Varrazzo
51591e2c23 Merge branch 'fix-512' 2017-03-01 02:14:40 +00:00
Daniele Varrazzo
3638d349ba Skip test on PG version with bad interval rounding
On these ancient versions:

    =# select '999999:00:00.1'::interval;
                interval
    --------------------------------
     41666 days 15:00:00.0999999046
2017-03-01 02:14:35 +00:00
Daniele Varrazzo
b0e6045b63 Bump to version 2.7
Refer to pep 440 for version numbering, which superseded pep 386. We are
not changing numbering scheme: the version numbers we have used (when we
have been consistent) would have been valid in both schemes.
2017-02-28 11:57:08 +00:00
Daniele Varrazzo
a2bc3c7bcb Fixed doc typo
Close #515
2017-02-28 11:28:11 +00:00
Daniele Varrazzo
c871c49f55 Dropped reference to "isolation level autocommit" in docs 2017-02-24 16:53:32 +00:00
Daniele Varrazzo
72f74d1f41 Dropped compiler warning on Windows 2017-02-24 13:33:42 +00:00
Daniele Varrazzo
451e1e2e73 Merge branch 'fix-512' 2017-02-24 13:33:36 +00:00
Daniele Varrazzo
691df4952b Handle overflow in interval parsing 2017-02-24 13:23:56 +00:00
Daniele Varrazzo
3b665d35d5 Make sure to use 64 bits in interval parsing accumulators 2017-02-24 12:10:54 +00:00
Daniele Varrazzo
834e9996da Parse interval only using integers
(almost... except for micros rounding)

While this is probably an improvement on the previous implementation,
I am largely waving a dead chicken at windows, which keeps failing to
pass the seconds overflow test. If it doesn't pass now either I'll start
blaming Python's timedelta.
2017-02-24 03:48:41 +01:00
Daniele Varrazzo
e351606b69 Display Appveyor build status of master branch 2017-02-24 02:49:45 +01:00
Daniele Varrazzo
a15dfbbd4f Try to fix the same problem in windows
Previous commit doesn't pass on Windows: it looks like window's floor()
has an integer overflow.
2017-02-24 02:41:34 +01:00
Daniele Varrazzo
14fe3ad8c9 Fixed integer overflow in interval typecaster
Close #512.
2017-02-24 02:10:27 +01:00
Daniele Varrazzo
f5bd6063fc Fixed link to attribute in news 2017-02-16 20:25:58 +00:00
Daniele Varrazzo
a3193aca2a Bump version number 2017-02-16 20:25:58 +00:00
Daniele Varrazzo
355d62f084 Url to download VC fix file moved to this repos 2017-02-16 18:31:49 +00:00
Daniele Varrazzo
1cb2721a67 Bumping to 2.7 beta 2 2017-02-16 18:26:37 +00:00
Daniele Varrazzo
559dbe7b53 Merge branch 'test-windows' 2017-02-16 18:23:23 +00:00
Daniele Varrazzo
30efe59af7 Document installation from wheel packages 2017-02-16 18:22:41 +00:00
Daniele Varrazzo
afcae0a61b Download external packages in .zip instead of .tar.gz
7z barfs every now and then with tar files
(https://ci.appveyor.com/project/psycopg/psycopg2/build/job/oh1ux3ih7baia0uu)
2017-02-16 17:35:16 +00:00
Daniele Varrazzo
089ceb96a8 Download postgres from github instead of ftp.postgresql.org
There may be some misconfigured mirror, download fails randomly, e.g.
https://ci.appveyor.com/project/psycopg/psycopg2/build/job/9j792s03tghrb7sr
2017-02-16 16:32:17 +00:00
Daniele Varrazzo
7819d0fc6c Windows testing tweaks, badge on README 2017-02-16 16:16:16 +00:00
Daniele Varrazzo
535ff672c0 Added AppVeyor configuration to test building on Windows 2017-02-16 15:43:11 +00:00
Daniele Varrazzo
82adf8a162 Merge branch 'session-attributes' 2017-02-16 14:50:21 +00:00
Daniele Varrazzo
61101888e4 Revert default_transaction_* to default only if set
When moving from autocommit True -> False reset only the server
parameters that were actually specified by psycopg to honour the
serssion characteristics.
2017-02-16 13:15:14 +00:00
Daniele Varrazzo
d7bba865f3 Check for deferrable unsupported applied to attribute too 2017-02-16 13:14:45 +00:00
Daniele Varrazzo
d50ed48807 Added readonly and deferrable attributes 2017-02-16 12:46:35 +00:00
Daniele Varrazzo
b5d80b609d Revert pre-2.7b1 behaviour of silent rollback on conn.set_isolation_level()
Legacy method is legacy.
2017-02-16 12:46:35 +00:00
Daniele Varrazzo
20c9c17457 connection.isolation_level is now writable 2017-02-16 12:46:35 +00:00
Daniele Varrazzo
fb1a47c064 Link COPY from docs index to our docs instead of postgres ones 2017-02-16 12:46:12 +00:00
Daniele Varrazzo
6c79f936bd SQL links not bold in the docs
Consistent with the SQL representation not linked.
2017-02-16 12:38:04 +00:00
Daniele Varrazzo
75747606d3 Merge branch 'pull-507' 2017-02-11 20:34:37 +00:00
Jason Erickson
32e81a27b5 Allowed inittype.h's defs all versions of MSVC
Apparently only MSVC 2015 x64 had defined these types.  Changed check to
work for all versions of MSVC.  Does not affect 2015x64.
2017-02-10 10:14:17 -07:00
Jason Erickson
7493ea24f2 Defined inttypes.h for older MSVC compilers
Older MSVC compilers do not support the C99 standard
2017-02-09 22:27:18 -07:00
Jason Erickson
d52e9100d2 Added support for MSVC compiler
Added function 'timeradd'.
Changed second parameter of 'gettimeofday' to void since not used in
function and MSVC timezone definition is not a struct).
2017-02-09 20:57:54 -07:00
Jason Erickson
83cf908c88 Fixed MSVC compiler error and warning
MSVC doesn't like referencing new initialized variables in the variable
declaration section.
2017-02-09 20:54:29 -07:00
Daniele Varrazzo
ee4887b4c5 Download testing servers from upload instead of tarballs 2017-02-08 18:37:40 +00:00
Daniele Varrazzo
4b78ca4405 Fixed generation of download url from beta version 2017-02-08 18:09:15 +00:00
Daniele Varrazzo
21fbe2bd2a Fixed argument name in executemany docs 2017-02-08 14:01:57 +00:00
Daniele Varrazzo
b4b8b5f164 Bump version number 2017-02-08 13:56:50 +00:00
Daniele Varrazzo
6f83c9c87a Bump version to 2.7 beta 1 2017-02-08 10:31:27 +00:00
Daniele Varrazzo
d2cafe2684 Dropped references to prepare in cur.execute[many] docs
They were copied from the DBAPI spec but that's not how psycopg works.
2017-02-08 10:31:19 +00:00
Daniele Varrazzo
d2cd1236a8 Dropped compiler warning about signed/unsigned comparisons 2017-02-08 08:44:08 +00:00
Daniele Varrazzo
3e12522bc9 Don't convert '{}'::unknown into an empty list
Close #506.
2017-02-08 08:43:53 +00:00
Daniele Varrazzo
791befca18 Use pydll to poke into extension library
Causes an error in Py 3.6 in debug mode.

Close #505
2017-02-07 12:29:06 +00:00
Daniele Varrazzo
7210287e76 Stop a docstring generating a warning
Valid reST, slightly less valid Python.
2017-02-07 12:29:05 +00:00
Daniele Varrazzo
28c489f17e Merge branch 'no-set-default-session' 2017-02-07 00:58:54 +00:00
Daniele Varrazzo
3ff350cd24 Merge branch 'test-dinosaurs' 2017-02-07 00:58:48 +00:00
Daniele Varrazzo
7485fabe4f Fixed BEGIN; SET TRANSACTION with PG 7.4 2017-02-07 00:58:29 +00:00
Daniele Varrazzo
705dda2cba Dropped support for Python 3.1 2017-02-06 23:03:48 +00:00
Daniele Varrazzo
7b11b95908 Skipped a couple of tests failing on old dbs
I don't even know why - worth investigating.
2017-02-06 21:40:05 +00:00
Daniele Varrazzo
7f593d5eb0 Skip tests with server not supporting NULL in array 2017-02-06 21:40:05 +00:00
Daniele Varrazzo
2e18b42db0 Don't test with server not implementing INSERT with VALUES list 2017-02-06 21:40:05 +00:00
Daniele Varrazzo
3873c6c09f Deal consistently with E'' quotes in tests 2017-02-06 21:40:05 +00:00
Daniele Varrazzo
d23fe42873 Work around a race condition in async cancel test 2017-02-06 21:40:05 +00:00
Daniele Varrazzo
e599da6308 assertDsnEqual moved as TestSuite method 2017-02-06 21:40:05 +00:00
Daniele Varrazzo
f5cad47909 Run the test suite with postgres versions not available on travis 2017-02-06 21:40:05 +00:00
Daniele Varrazzo
e9c5f66450 build-manylinux script moved to build-wheels project 2017-02-06 19:12:17 +00:00
Daniele Varrazzo
9f467231d9 Merge branch 'conform-subclass-adapter' 2017-02-05 12:13:52 +01:00
Daniele Varrazzo
c6af16c3ae Slower timeout for a test that sometimes fail
At least it should fail with an error after 2 seconds, not waiting for
Travis timeout of 10 minutes.
2017-02-05 12:06:55 +01:00
Daniele Varrazzo
30a833f57a Dropped compiler warning in debug mode 2017-02-05 12:06:55 +01:00
Daniele Varrazzo
3fbff5d848 Give precedence to '__conform__()' over superclasses choosing adapter
Close #456
2017-02-05 11:54:50 +01:00
Daniele Varrazzo
c54a614c6e Added documentation about the changes in transaction control 2017-02-04 15:55:59 +00:00
Daniele Varrazzo
9054eeccc0 Set default_transaction_* GUC if session state is changed in autocomit 2017-02-04 15:19:41 +00:00
Daniele Varrazzo
665e9dc665 Exposing ISOLATION_LEVEL_DEFAULT to Python
This is now the state that is returned to Python if nothing has been
explicitly set.
2017-02-04 14:43:54 +00:00
Federico Di Gregorio
9448576ba6 Merge pull request #504 from fogzot/pgversion-fix
Fixed version regexp to match "10devel"
2017-02-04 14:32:06 +01:00
Daniele Varrazzo
c60682c230 Reuse set_session to implement autocommit, set_isolation_level 2017-02-04 13:26:43 +00:00
Federico Di Gregorio
8b96bcddff Fixed version regexp to match "10devel"
Also normalized the result and made sure that if PostgreSQL ever starts
using just integer version numbers (as in "10") everything still works.
2017-02-04 14:21:07 +01:00
Daniele Varrazzo
8527144173 Better separation between interface and state change code
The state change function has a C callable signature.
2017-02-04 13:01:11 +00:00
Daniele Varrazzo
ca59fd8b3f Test looking the transactions characteristics instead of the default
So we test the effect, not the implementation. Tests pass on master too
this way, three tests fail in this branch, related to autocommit
(sort-of-obviously).
2017-02-04 10:57:30 +00:00
Daniele Varrazzo
c1e016e597 Don't use default_transaction_* for session characteristics
Store the state in the connection object and set the params on BEGIN

Some tests fail: a few can be fixed reading transaction_* instead of
default_transaction_*; but the behaviour of tx characteristics with
autocommit is effectively changed. It may be addressed by setting
default_transaction_* if autocommit is set.
2017-02-04 02:38:56 +00:00
Daniele Varrazzo
9863637f30 Dropped compiler warning in debug mode 2017-02-04 02:32:26 +00:00
Daniele Varrazzo
de8b335d80 Merge branch 'master' into sql-compose 2017-02-03 04:56:02 +00:00
Daniele Varrazzo
ca42306d79 Misplaced NEWS entry fixed. 2017-02-03 04:52:49 +00:00
Daniele Varrazzo
1911b250e3 Merge branch 'async-keyword'
Close #495
2017-02-03 04:45:17 +00:00
Daniele Varrazzo
44c3b77691 Added docs for async_ alias 2017-02-03 04:43:49 +00:00
Daniele Varrazzo
ce9be69615 Added async_ as an alias for async
Added in argument for psycopg2.connect() and connection.__init__, and
for the connection.async attribute.
2017-02-03 04:43:49 +00:00
Daniele Varrazzo
8baf6aa372 Convert warnings into errors on test 2017-02-03 04:41:32 +00:00
Daniele Varrazzo
6e89db020c Merge branch 'fast-executemany' 2017-02-03 04:40:34 +00:00
Daniele Varrazzo
95226baa9b Further minimal performance tweaks to execute_values 2017-02-02 17:44:25 +00:00
Daniele Varrazzo
dc1b4fff90 Avoid an useless encode/decode roundtrip in execute_values()
Tests moved into a separate module.
2017-02-02 17:29:17 +00:00
Daniele Varrazzo
d2fdc5ca9f Better docs for fast executemany functions.
Issue #502.
2017-02-02 16:02:33 +00:00
Daniele Varrazzo
d8b1fbd905 Further skipping of slow tests 2017-02-02 03:02:29 +00:00
Daniele Varrazzo
626e57acda Merge branch 'fast-executemany' 2017-02-02 02:40:28 +00:00
Daniele Varrazzo
27652ed3b0 Added notes about using execute_batch with prepared statements 2017-02-02 02:40:03 +00:00
Daniele Varrazzo
ad6506ff69 Merge branch 'manylinux' 2017-02-02 02:15:15 +00:00
Daniele Varrazzo
88a21689ce Added note about finding slow tests 2017-02-02 02:09:59 +00:00
Daniele Varrazzo
f24de0357f Allow skipping the slow test
It's not so much about tests being slow: some just get stuck and timeout
travis.

Skipped all tests taking about more than 0.2s to run on my laptop.
Fast testing takes about 8s instead of 24.
2017-02-02 01:53:50 +00:00
Daniele Varrazzo
9ca51e0ed9 Use the server on the host to test 2017-02-01 17:33:12 +00:00
Daniele Varrazzo
815869375b Merge back manylinux build script from the psycopg2-wheels project 2017-02-01 17:05:47 +00:00
Daniele Varrazzo
9bac37baf7 Fixed execute_values with unicode
Also added unicode tests.
2017-02-01 02:47:59 +00:00
Daniele Varrazzo
2e2dcd536b Fixed fast execute functions with Python 3 2017-02-01 02:36:54 +00:00
Daniele Varrazzo
26952ecee4 Fixed sql docs style with newer Docutils versions 2017-02-01 02:00:20 +00:00
Daniele Varrazzo
a95fd3df1a Added execute_batch and execute_values functions 2017-02-01 01:59:47 +00:00
Daniele Varrazzo
8ac839ce95 Merge branch 'fix-iter-warning' 2017-01-05 15:27:26 +00:00
NotSqrt
9ffb61214c Fix DeprecationWarning: generator '__iter__' raised StopIteration
Closes #498
2017-01-04 09:45:53 +01:00
Daniele Varrazzo
8341792c5b Added script to create manylinux1 wheels
See issue #425
2017-01-04 04:43:54 +01:00
Daniele Varrazzo
651f1b6c97 Consider Python 3.6 and Postgres 9.6 supported 2017-01-03 19:12:44 +01:00
Daniele Varrazzo
a8a3a298f8 Autonumbered args not available in Python 2.6 2017-01-03 17:53:02 +01:00
Daniele Varrazzo
71a168797c Several improvements to the sql objects
Comparable, iterable, content accessible
2017-01-03 17:27:01 +01:00
Daniele Varrazzo
a76e665567 Use {} instead of %s placeholders in SQL composition 2017-01-03 15:02:34 +01:00
Daniele Varrazzo
49461c2c39 More doc love for the sql module 2017-01-01 18:15:01 +01:00
Daniele Varrazzo
9926942260 Added missing doc file 2017-01-01 16:01:55 +01:00
Daniele Varrazzo
077328c1a2 Using the new name of the old doc template 2017-01-01 16:01:09 +01:00
Daniele Varrazzo
d97399daa5 sql module docs wordsmithing 2017-01-01 09:23:26 +01:00
Daniele Varrazzo
cf40bff2e2 Dropped sql.compose
Use a SQL % operator instead.
2017-01-01 08:39:02 +01:00
Daniele Varrazzo
4a55b8018a Adding sql module documentation 2017-01-01 08:12:05 +01:00
Daniele Varrazzo
41b9bfe401 Added test for sql percents treatment 2017-01-01 06:37:09 +01:00
Daniele Varrazzo
828415d476 Typo: composible -> composable 2017-01-01 06:32:18 +01:00
Daniele Varrazzo
ad2643266f Fixed sql.compose with no args and added tests 2017-01-01 06:26:54 +01:00
Daniele Varrazzo
8c020ca47a Fixed sql.Composed representation 2017-01-01 06:26:42 +01:00
Daniele Varrazzo
600416aafc Fixed sql stuff in Py3 2017-01-01 05:59:21 +01:00
Daniele Varrazzo
c4a67fc1c1 Added sql.compose() implementation 2017-01-01 05:23:42 +01:00
Daniele Varrazzo
f11e6d82b0 Added basic sql module implementation 2017-01-01 05:23:15 +01:00
Daniele Varrazzo
fad5100079 Adding some boilerplate for the new module 2017-01-01 03:53:08 +01:00
Daniele Varrazzo
21f38a4c07 Don't try to write bytes in the LoggingConnection file
Close #483
2016-12-29 22:42:25 +01:00
Daniele Varrazzo
449bd4485f Merge branch 'fast-codecs' 2016-12-29 22:15:46 +01:00
Daniele Varrazzo
f3e47a72ed Brag about encoding/decoding speedup 2016-12-29 22:11:58 +01:00
Daniele Varrazzo
cb5293be1f Use the proper API functions to look up codec functions 2016-12-29 22:11:58 +01:00
Daniele Varrazzo
3295beb777 Don't look up for Python encoding
Store the encode/decode functions for the right codec in the connection.
The Python encoding name has been dropped of the connection to avoid the
temptation to use it...
2016-12-29 22:11:58 +01:00
Daniele Varrazzo
a81f12f9bd Don't set tp_compare on Python 3
The slot is unused in Py < 3.5, and replaced by pg_as_async in Py 3.5.
2016-12-29 21:43:04 +01:00
Daniele Varrazzo
dfe547856e Use -1 instead of 0 to say "calculate the length" in many funcs
0 is a valid length, isn't it?
2016-12-27 00:29:01 +01:00
Daniele Varrazzo
a255e4e1c6 Store python encoding and decoding functions in the connection
Unused for now: will be used instead of 'pyenc', which is to be dropped.
2016-12-27 00:29:01 +01:00
Daniele Varrazzo
17a74cc771 Setting connection encoding refactored
Code paths to read encoding on connection and to store the new
connection in the structure after changing it in the backend unified
into a single function.
2016-12-26 16:51:22 +01:00
Daniele Varrazzo
f439ca61d6 conn->codec rename to pyenc 2016-12-26 12:25:13 +01:00
Daniele Varrazzo
7caba160b7 Merge branch 'master' into fast-codecs 2016-12-26 12:06:21 +01:00
Daniele Varrazzo
e9577e9b89 Merge branch 'named-callproc' 2016-12-26 04:57:07 +01:00
Daniele Varrazzo
c46b6ea719 Fixed travis test: unset green mode 2016-12-26 04:31:18 +01:00
Daniele Varrazzo
64342fcff0 Less verbose travis tests 2016-12-26 04:13:41 +01:00
Daniele Varrazzo
ffeb7001eb Fixed refcount problems in named callproc 2016-12-26 04:12:18 +01:00
Daniele Varrazzo
d13521a6ce Mention named callproc in news, fixed docs. 2016-12-26 03:39:28 +01:00
Daniele Varrazzo
1957389bea Merge branch 'master' into named-callproc 2016-12-26 03:19:02 +01:00
Daniele Varrazzo
a53b39efe8 Dropped internal escape identifier function
Using libpq one as now it's guaranteed to be present.
2016-12-26 03:11:36 +01:00
Daniele Varrazzo
faaef61c27 Merge branch 'master' into named-callproc 2016-12-26 01:49:42 +01:00
Daniele Varrazzo
17698c4815 Fixed REst error in newsfile 2016-12-25 21:17:24 +01:00
Daniele Varrazzo
4c99cadabe Fixed intersphinx links to Pyton docs 2016-12-25 21:17:14 +01:00
Luke Nezda
dcb198e8b7 fix wait_select sample to be extras not extensions 2016-12-25 20:49:24 +01:00
Tim Graham
35b4a01b6d Fix "invalid escape sequence" warning in Python 3.6
http://bugs.python.org/issue27364
2016-12-25 20:43:29 +01:00
Daniele Varrazzo
1c3e2be224 Merge branch 'fix-453' 2016-12-25 19:56:40 +01:00
Daniele Varrazzo
d48d4bab05 Added empty options in setup.cfg
Setuptools removes them from the sdist, see #453
2016-12-25 19:46:09 +01:00
Daniele Varrazzo
c9798ecb15 Merge branch 'dont_set_datestyle_in_replication_mode' 2016-12-25 19:28:23 +01:00
Daniele Varrazzo
c22093ddd4 Skip replication tests in green mode 2016-12-25 19:00:30 +01:00
Daniele Varrazzo
874705db42 Configure Travis to test replication 2016-12-25 18:37:26 +01:00
Daniele Varrazzo
b73115ac41 Added test to verify bug #482 2016-12-25 18:30:27 +01:00
Daniele Varrazzo
e27579292a Avoid deadlock on close if set datestyle failed 2016-12-25 17:45:01 +01:00
Daniele Varrazzo
c2d405116b Dropped testing print 2016-12-25 17:44:25 +01:00
Daniele Varrazzo
b77de74f72 Merge branch 'master' into dont_set_datestyle_in_replication_mode 2016-12-25 16:31:33 +01:00
Daniele Varrazzo
f451d35aae Merge branch 'travis' 2016-12-24 04:51:30 +01:00
Daniele Varrazzo
feebc8f689 Don't use separate databases for tests
I got this wrong: I thought parallel test ran in the same VM; they are
isolated instead.
2016-12-24 04:42:55 +01:00
Daniele Varrazzo
1463bdb86d Added build badge to readme 2016-12-24 04:28:34 +01:00
Daniele Varrazzo
6758ce5eef Test Python versions in a more relevant order 2016-12-24 04:27:51 +01:00
Daniele Varrazzo
def22982fb Run the tests against all the available server versions 2016-12-24 04:12:03 +01:00
Daniele Varrazzo
11ad1005e0 Added python3 supported versions 2016-12-24 01:09:57 +01:00
Daniele Varrazzo
a478ba9a47 Fixed tests failing on Python 2.6 2016-12-24 01:03:57 +01:00
Daniele Varrazzo
b3cd125d27 Create the hstore extension in the trevis db 2016-12-24 00:18:09 +01:00
Daniele Varrazzo
0be783c454 Disable email notification
Mmm... it seems it's going to be a long night...
2016-12-24 00:12:32 +01:00
Daniele Varrazzo
3971ee6d1f Testing CI with Travis 2016-12-24 00:07:23 +01:00
Christoph Moench-Tegeder
fb1dbc2a9b do not "SET datestyle" on replication connections
A replication connection - marked by the use of the keyword "replication"
in the DSN - does not support SET commands. Trying to sent "SET datestyle"
will result in an exception.
2016-10-21 15:32:11 +02:00
Daniele Varrazzo
121cf3b8f8 Optimize UTF8 and Latin1 decoding
Cache a pointer to a fast decoding function when the connection encoding
is set so skip a repeated codec lookup for every string.
2016-10-12 01:10:31 +01:00
Daniele Varrazzo
584c7e6890 Dropped compiler warning in debug mode 2016-10-12 00:28:25 +01:00
Daniele Varrazzo
51aa166d52 Merge branch 'networking-improvement' 2016-10-11 04:55:09 +01:00
Daniele Varrazzo
643ba70bad Added ipaddress objects conversion
Close #387
2016-10-11 04:54:41 +01:00
Daniele Varrazzo
706ad2f177 Conver network array types into array of strings by default 2016-10-11 02:31:45 +01:00
Daniele Varrazzo
86198c1c21 inet adapters deprecated
Close #343
2016-10-11 02:17:56 +01:00
Daniele Varrazzo
05627ac0f9 Fix unicode mogrify test on python 2 2016-10-11 00:22:23 +01:00
Daniele Varrazzo
91d2158de7 Python source cleanup using flake8 2016-10-11 00:11:55 +01:00
Daniele Varrazzo
4458c9b4c9 Merge branch 'drop-libpq-pre-91' 2016-08-15 02:58:36 +01:00
Daniele Varrazzo
b3792c7f02 Mention dropping Pre 9.1 libpq support in NEWS file 2016-08-15 02:57:49 +01:00
Daniele Varrazzo
5ddc952dbb Dropped ifdef guards against obsolete libpq versions
One of them was actually wrong: lobject_type.c wouldn't have compiled
pre 8.3 (broken in 6e841a41, 2 years ago).
2016-08-15 02:55:44 +01:00
Daniele Varrazzo
3d4f6df0de Enforce dependency on libpq version >= 9.1
PGRES_COPY_BOTH was introduced in 9.1: we can ifdef the hell out of
pgpath, but we may as well bury the dead horses instead of beating
them.

They smell funny, too.
2016-08-15 02:55:43 +01:00
Daniele Varrazzo
b006190312 Merge branch 'drop-py25' 2016-08-15 02:51:10 +01:00
Daniele Varrazzo
47a312cf83 Mention dropping Py 2.5 support in NEWS file 2016-08-15 02:39:26 +01:00
Daniele Varrazzo
78649f8e90 Dropped use of b() "macro" and 2to3 fixer
Just use the b"" strings syntax supported from python 2.6.
2016-08-15 01:56:36 +01:00
Daniele Varrazzo
3b41c3a6f3 Stop compiling with Python 2.5 2016-08-15 01:06:42 +01:00
Daniele Varrazzo
1d950748af Merge branch 'replication-protocol' 2016-08-14 21:09:54 +01:00
Daniele Varrazzo
01c552baa3 Mention replication support in the NEWS file 2016-08-14 21:09:00 +01:00
Daniele Varrazzo
e0883f1967 Name the db in the replication test like the unit test one 2016-08-14 19:57:29 +01:00
Daniele Varrazzo
e5390fed98 Use inttypes.h definitions 2016-08-14 19:48:31 +01:00
Daniele Varrazzo
12ecb4b2ce Dropped import of postgres internal/c.h
Stops warning (caused by command line definition of PG_VERSION, so it
could have been avoided otherwise), but the file comment says:

    Note that the definitions here are not intended to be exposed to clients
    of the frontend interface libraries --- so we don't worry much about
    polluting the namespace with lots of stuff...

so it doesn't seem a good idea gulping it.
2016-08-14 19:36:48 +01:00
Daniele Varrazzo
e779fec5f9 Merge branch 'nul-terminator' 2016-08-07 02:51:27 +01:00
Daniele Varrazzo
478f43f0c8 Mention NULL characters guard in NEWS file
Fix #420.
2016-08-07 02:51:06 +01:00
Daniele Varrazzo
bd95269c69 Merge branch 'master' into nul-terminator 2016-08-07 02:49:13 +01:00
SpootDev
edd51aac25 spelling fix 2016-08-07 02:44:08 +01:00
Daniele Varrazzo
ab671146de Merge branch 'range-picklable' 2016-08-07 02:40:05 +01:00
Daniele Varrazzo
ec1e578e4b Report range picklable in NEWS file
Fix #462

Conflicts:
	NEWS
2016-08-07 02:39:26 +01:00
Jonathan Ross Rogers
cde19c4d59 Make Range pickleable 2016-08-07 02:38:52 +01:00
Daniele Varrazzo
86434548a7 Replication docs massaging, mostly formatting 2016-08-07 02:23:02 +01:00
Daniele Varrazzo
9a4f8f915f Reshuffling and indexing of replication docs 2016-08-07 02:07:16 +01:00
Daniele Varrazzo
2a4d6027a4 Merge branch 'master' into replication-protocol
Conflicts:
	tests/testconfig.py
2016-08-07 01:53:21 +01:00
Alexander Schrijver
03824a1dba Throw an exception when a NUL character is used as a parameter. 2016-07-18 22:56:55 +02:00
Daniele Varrazzo
90ee1ebba5 errorcodes map updated to PostgreSQL 9.5. 2016-07-01 20:14:30 +01:00
Daniele Varrazzo
7566af145b Merge branch 'conn-get-parameters' 2016-07-01 20:12:01 +01:00
Daniele Varrazzo
00de4052d1 Mention get_dsn_parameters() in news, improved docs metadata 2016-07-01 20:10:56 +01:00
Daniele Varrazzo
e41bff8ca4 Merge branch 'bug-424' 2016-07-01 19:28:02 +01:00
Daniele Varrazzo
80fd14463b Mention closing bug #424 in the news 2016-07-01 19:27:31 +01:00
Daniele Varrazzo
5bcaf11f9d Allow adapting bytes using QuotedString on Python 3 too
Close #365.
2016-07-01 19:14:00 +01:00
Daniele Varrazzo
70af49c0a2 Fixed encoding tests on Py3 2016-07-01 18:50:24 +01:00
Daniele Varrazzo
9c156d41bb Docs wrapping 2016-07-01 18:03:49 +01:00
Daniele Varrazzo
1442655d3c Merge branch 'qstring-writable-encoding' 2016-07-01 18:03:12 +01:00
Daniele Varrazzo
4a450b63c4 Don't hope to encode stuff in an arbitrary encoding
libpq's PQescapeString will use the same encoding it has seen before in
a connection (static_client_encoding).

So I think I'll leave this feature here for people who know what is
doing, but won't really document it as a feature: it can't really work
in a generic way (unless adding some disgusting hack like creating a
fake connection with the encoding we want to call PQescapeStringConn
instead of PQescapeString).
2016-07-01 18:02:20 +01:00
Daniele Varrazzo
2e8e61b8d4 Test moved to the right module, cleanup, but same problem 2016-07-01 18:01:16 +01:00
Daniele Varrazzo
bada1f1f8e Work in progress on writable encoding
Would help using adapt(unicode) to quote strings without a connection,
see ticket #331.

Currently in heisenbug state: if test_connection_wins_anyway and
test_encoding_default run (in this order), the latter fail because the
returned value is "'\xe8 '", with an extra space. Skipping the first
test, the second succeed.

The bad value is returned by the libpq:

    ql = PQescapeString(to+eq+1, from, len);

just returns len = 2 and an extra space in the string... meh.
2016-07-01 18:00:05 +01:00
Daniele Varrazzo
c29b5cd46a Fixed build on win32
Fix #422.
2016-07-01 02:24:49 +01:00
Daniele Varrazzo
7aedc61d41 Fixed segfault on repr() for uninitialized connections
Close #361.
2016-07-01 02:11:21 +01:00
Daniele Varrazzo
b7330283bc Wordsmithing on COPY commands
Address somehow issue #397.
2016-07-01 01:40:25 +01:00
Daniele Varrazzo
52753b23e8 Document that the libpq must be available at runtime
Fix issue #408.
2016-07-01 01:19:28 +01:00
Greg Ward
3ed2c54790 Fix scattered grammar/spelling errors in comments, debug output, etc. 2016-06-30 21:09:15 +01:00
Oleksandr Shulgin
d5443c65fd Fix TODOs in ReplicationMessage inline docs 2016-04-21 15:32:05 +02:00
Gabriel Kihlman
5ce00f8e5b Avoid a possible null deref, tz might be NULL.
Found by clang static analyzer.
2016-04-18 17:28:50 +02:00
Daniele Varrazzo
732ea90a4f Merge pull request #373 from nonZero/patch-1
Suggest installing psycopg2 in windows using pip
2016-03-10 12:25:23 +00:00
Daniele Varrazzo
4fa1b983e7 Merge pull request #415 from bmwiedemann/master
dont claim copyright for future years
2016-03-10 12:22:59 +00:00
Daniele Varrazzo
caa3e491f2 Merge pull request #416 from dargor/doc_typos
Typo.
2016-03-10 12:22:01 +00:00
Daniele Varrazzo
3033361883 Merge branch 'py35' 2016-03-10 12:14:11 +00:00
Daniele Varrazzo
4fb236e688 Start advertising Py 3.5 support 2016-03-10 12:13:57 +00:00
Daniele Varrazzo
65ec7e8bcb Fixed read() exception propagation in copy_from
Close issue #412.
2016-03-10 12:13:52 +00:00
Daniele Varrazzo
82ef9cfadd Merge branch 'msvc-2015-fix' 2016-03-10 12:12:40 +00:00
Daniele Varrazzo
48260c6406 Py 3.5 MSVC 2015 build fixed noted in news
Close issue #380.
2016-03-10 12:12:24 +00:00
Christian Ullrich
654eeec24c Work around late initialization in distutils._msvccompiler. 2016-03-10 12:12:19 +00:00
Daniele Varrazzo
1b7cebc41e Merge branch 'setuptools' 2016-03-10 12:11:29 +00:00
Daniele Varrazzo
006693421d Fixed 'make sdist' to work with setuptools 2016-03-10 12:10:51 +00:00
Daniele Varrazzo
2d91864977 setuptools in the news 2016-03-10 12:09:20 +00:00
Jason Erickson
22fe6e7aad Modify setup.py to support setuptools/wheel
To support creation of whl files for PyPI, setuptools need to be imported
instead of distutils.  Created try/except case to fall back to integrated
distutils if setuptools is not installed.
2016-03-10 12:09:15 +00:00
Daniele Varrazzo
8611d91b35 Fixed build on Python 2.5 2016-03-10 12:06:28 +00:00
Daniele Varrazzo
244f233e1c Fixed manifest trying to include Makefiles from build env 2016-03-10 12:05:57 +00:00
Daniele Varrazzo
eb687103b4 Skip null array test on Postgres versions not supporting it 2016-03-10 12:04:41 +00:00
Daniele Varrazzo
499366ba2d Merge branch 'patch-328' 2016-03-10 12:02:39 +00:00
Daniele Varrazzo
c13956dc10 Fixed compiler warnings about Py_ssize_t printf format 2016-03-10 12:02:23 +00:00
Jason Erickson
d0309333b7 Removed added Dprintf statements
Removed extra Dprintf statements added to trouble large objects
2016-03-10 12:02:06 +00:00
Jason Erickson
2cdc8d61a2 Fix Windows 64bit lobject support for very (>2GB) large objects
The type 'long' with Windows Visual C is 32bits in size for both 32bit and 64bit platforms.  Changed type of variables that could be > 2GB from long to Py_ssize_t.
2016-03-10 12:02:00 +00:00
Gabriel Linder
88d3d7fc7e Typo. 2016-03-09 21:51:02 +01:00
Bernhard M. Wiedemann
d829a75f2e dont claim copyright for future years
otherwise, when building from unchanged source in 2018,
it would claim Copyright 2018
which is not true

Being able to reproduce identical output from identical input
is important to Linux distributions
2016-03-09 16:33:54 +01:00
Oleksandr Shulgin
a7887fab07 Merge remote-tracking branch 'zalando/feature/replication-protocol' into feature/replication-protocol-c-connection-object 2016-03-08 18:56:58 +01:00
Oleksandr Shulgin
3f10b4dd31 Remove duplicated doc for make_dsn() 2016-03-08 18:52:29 +01:00
Oleksandr Shulgin
b21c8f7a4e Move replication-related imports to extras.py 2016-03-08 18:52:29 +01:00
Oleksandr Shulgin
2de2ed7c63 Remove some dead code 2016-03-08 18:52:29 +01:00
Oleksandr Shulgin
1d52f34e60 We don't need to expose cursor_init(), call tp_init() on the type instead. 2016-03-08 18:52:21 +01:00
Oleksandr Shulgin
da6e061ee8 Use python-defined make_dsn() for ReplicationConnection class 2016-03-08 18:52:21 +01:00
Oleksandr Shulgin
cb7032554e Merge branch 'master' into feature/replication-protocol-c-connection-object 2016-03-04 10:52:10 +01:00
Daniele Varrazzo
ab5d8f4190 Style the dsn arg in connect() as a normal optional parameter
Plus some more connect() docs wordsmithing.
2016-03-03 17:28:56 +00:00
Daniele Varrazzo
d43b74681f Merge branch 'make_dsn'
Close issue #363 instead of the proposed merge request.
2016-03-03 17:10:39 +00:00
Daniele Varrazzo
e33073576c Brag about make_dsn in the NEWS file 2016-03-03 17:09:15 +00:00
Daniele Varrazzo
c9fd828f8a Allow make_dsn to take no parameter
The behaviour of connect() is unchanged: either dsn or params must be
specified.
2016-03-03 17:09:15 +00:00
Daniele Varrazzo
7aab934ae5 Validate output result from make_dsn()
The output is not necessarily munged anyway: if no keyword is passed,
validate the input but return it untouched.
2016-03-03 17:09:15 +00:00
Daniele Varrazzo
7155d06cdc Test that the empty dsn is a valid make_dsn input 2016-03-03 17:09:15 +00:00
Daniele Varrazzo
6893295a87 Added docs about make_dsn
connect() docs updated to document the arguments merging.
2016-03-03 17:09:15 +00:00
Daniele Varrazzo
52087a79d9 Added test suite specific for make_dsn 2016-03-03 15:31:37 +00:00
Daniele Varrazzo
2c55a1bd53 Verify that the dsn is not manipulated by make_dsn if not necessary 2016-03-03 15:07:38 +00:00
Daniele Varrazzo
1c4523f0ac Implementation of make_dsn in Python
This is equivalent to what proposed in #363, but with a much simpler
implementation.
2016-03-03 04:33:59 +00:00
Daniele Varrazzo
d40f81865f Added parse_dsn() docstring 2016-03-03 03:25:47 +00:00
Daniele Varrazzo
01856333c4 Some order in the extensions doc
Classes, coroutine functions and extra functions grouped under separate
headings.
2016-03-03 03:21:59 +00:00
Federico Di Gregorio
3df2c6a2b7 Merge pull request #403 from kpinc/fix
Improve sentence.
2016-02-03 09:51:09 +01:00
Karl O. Pinc
3a54e83737 Improve sentence. 2016-02-02 12:48:16 -06:00
Federico Di Gregorio
b737757eac Merge pull request #375 from kwotuveang3k4bk/patch-1
Update psycopg1.py
2016-01-31 12:55:52 +01:00
Oleksandr Shulgin
5d33b39829 Fix error test for invalid START_REPLICATION command. 2016-01-21 15:56:27 +01:00
Oleksandr Shulgin
09a4bb70a1 Allow retrying start_replication after syntax or data error. 2016-01-05 12:31:57 +01:00
Daniele Varrazzo
452fd56e04 Merge branch 'bug-382' 2015-12-16 12:04:14 +00:00
Daniele Varrazzo
5fd0f6c4ee Fixed race condition on import in errorcodes.lookup
Fixes #382.
2015-12-16 12:03:10 +00:00
mrmilosz
0772d187e9 Return input tuple in cur.callproc, factor code to use PQescapeIdentifier in single place 2015-12-13 01:10:03 -05:00
Daniele Varrazzo
92109e4bba Correctly handle an empty error message from PQescapeIdentifier 2015-12-12 17:52:56 -05:00
Daniele Varrazzo
54e5349f53 Set an exception in case of PQescapeIdentifier error
Ifdeffed surface reduced.
2015-12-12 17:52:56 -05:00
Daniele Varrazzo
4003b7c977 Fixed callproc return value refcount
Temporary anyway: I want to go back returning a list (or dict).
2015-12-12 17:51:45 -05:00
Daniele Varrazzo
021f6d22ad More straightforward param refcount handling in callproc 2015-12-12 17:51:45 -05:00
Daniele Varrazzo
7302f348bc Added test with objects without length as callproc param 2015-12-12 17:51:08 -05:00
Daniele Varrazzo
d297976d6d Raise TypeError if the dict in callproc param contains non-strings
Check-and-conversion chain fixed and simplified. 'spname' was a
reference leak.
2015-12-12 17:51:08 -05:00
Daniele Varrazzo
a3eed9c9f5 Added guard on params with no length on callproc 2015-12-12 17:51:08 -05:00
Daniele Varrazzo
04ce14b251 Avoid clobbering the exceptions raised by other calls 2015-12-12 17:49:59 -05:00
mrmilosz
c205f140a0 callproc: tests, docs, and comment/error-reporting touchups. 2015-12-12 17:49:59 -05:00
mrmilosz
37a80e9de8 callproc: checking for libpq 9.0+ on compile. yes: use PQescapeIdentifier. no: error 2015-12-12 17:49:44 -05:00
mrmilosz
3948e909e4 callproc: now more compliant with local coding standards. 2015-12-12 17:49:44 -05:00
mrmilosz
e9bb4a86f9 cursor.callproc: added a missing memory check 2015-12-12 17:49:25 -05:00
mrmilosz
31c95c0922 callproc using a dict now uses connection encoding and sanitizes parameter names 2015-12-12 17:49:25 -05:00
mrmilosz
1205bf9c2b callproc using a dict now has a type check to make sure the keys are strings. 2015-12-12 17:49:25 -05:00
mrmilosz
23d279945f cursor.callproc now also accepts dict for PostgreSQL 9+ "named notation" 2015-12-12 17:49:25 -05:00
Jan Janßen
b3def74002 Update psycopg1.py 2015-11-10 17:02:59 +01:00
Udi Oron
cf83470891 Suggest installing psycopg2 in windows using pip
pip is becoming the standard method for installing python packages, and now binary wheels are a better and easier option for users:
https://github.com/psycopg/psycopg2/issues/368
2015-11-10 00:35:02 +02:00
Oleksandr Shulgin
051e6d1364 Add skip_before_libpq for test_get_dsn_parameters 2015-10-30 13:02:45 +01:00
Oleksandr Shulgin
e61db578cf Add dbname=replication for physical replication type. 2015-10-30 13:00:55 +01:00
Oleksandr Shulgin
602fefcae3 Fix typo in a new test name 2015-10-30 11:38:28 +01:00
Oleksandr Shulgin
a4cbb088fe Add connection.get_dsn_parameters() 2015-10-30 11:10:41 +01:00
Oleksandr Shulgin
fbcf99ad07 Move replication connection to C level. 2015-10-27 18:21:24 +01:00
Oleksandr Shulgin
433fb957cb Merge branch 'feature/connect2' into feature/replication-protocol 2015-10-27 17:37:18 +01:00
Oleksandr Shulgin
7aba8b3ed0 Rework psycopg2.connect() interface. 2015-10-27 17:35:57 +01:00
Oleksandr Shulgin
4b9a6f48f3 Merge branch 'master' into feature/replication-protocol 2015-10-27 12:16:41 +01:00
Oleksandr Shulgin
fe4cb0d493 Fix stale Dprintfs in pqpath.c referring to 'status' 2015-10-26 17:40:39 +01:00
Oleksandr Shulgin
8b79bf43ac Drop ReplicationCursor.flush_feedback(), rectify pq_*_replication_*() interface. 2015-10-23 18:30:18 +02:00
Oleksandr Shulgin
dd6bcbd04f Improve async replication example. 2015-10-23 17:51:03 +02:00
Oleksandr Shulgin
e69dafbecc Move the decode parameter to start_replication().
It makes more sense this way, because otherwise it must be passed to every call
of `read_message()`.
2015-10-23 11:31:55 +02:00
Oleksandr Shulgin
76c7f4a0b5 Use direct call to consume() callable in pq_copy_both() 2015-10-22 16:17:08 +02:00
Oleksandr Shulgin
22cbfb26d6 Actually add replication tests to the test suite. 2015-10-20 13:05:43 +02:00
Oleksandr Shulgin
089e745af6 Fix cursor_init() declaration for use in replication_cursor_type.c 2015-10-20 12:55:43 +02:00
Oleksandr Shulgin
b3f8e9adb5 Fix send_time printf format in replmsg_repr(). 2015-10-20 12:54:22 +02:00
Oleksandr Shulgin
23abe4f501 Add quick start to the replication doc, minor doc fixes. 2015-10-20 12:36:13 +02:00
Oleksandr Shulgin
0bb81fc848 Properly subclass ReplicationCursor on C level. 2015-10-19 20:00:39 +02:00
Oleksandr Shulgin
7aea2cef6e Improve async replication test. 2015-10-19 17:02:18 +02:00
Oleksandr Shulgin
4ab7cf0157 Replace stop_replication with requirement for an exception. 2015-10-19 15:42:42 +02:00
Oleksandr Shulgin
0435320f34 Fix PSYCOPG2_TEST_REPL_DSN handling. 2015-10-16 16:36:03 +02:00
Oleksandr Shulgin
cf4f2411bf Fix async replication and test. 2015-10-15 18:01:43 +02:00
Oleksandr Shulgin
d14fea31a3 Use quote_ident from psycopg2.extensions 2015-10-15 12:56:21 +02:00
Oleksandr Shulgin
8e518d4954 Merge branch 'master' into feature/replication-protocol 2015-10-15 12:27:43 +02:00
Daniele Varrazzo
6763578cc0 Merge branch 'extensions-quote-ident' 2015-10-15 11:08:34 +01:00
Daniele Varrazzo
109409bc95 Mention quote_ident() in NEWS file 2015-10-15 11:06:44 +01:00
Oleksandr Shulgin
89bb6b0711 Proper unicode handling in quote_ident. 2015-10-15 11:52:18 +02:00
Oleksandr Shulgin
9ab38ee8c5 Add psyco_curs_datetime_init 2015-10-14 18:39:48 +02:00
Oleksandr Shulgin
28a1a00d1c Remove commented copy_both code in pqfetch. 2015-10-14 18:39:20 +02:00
Oleksandr Shulgin
e3097ec956 Fix select/timeout indication in async replication example 2015-10-14 17:42:53 +02:00
Oleksandr Shulgin
822d671e8b Clear repl_stop flag after the consume loop. 2015-10-14 17:40:39 +02:00
Oleksandr Shulgin
e05b4fd267 Add checks on replication state, have to have a separate check for consume loop. 2015-10-14 17:36:50 +02:00
Oleksandr Shulgin
9295bce154 Add psycopg2.extensions.quote_ident. 2015-10-14 17:00:25 +02:00
Oleksandr Shulgin
a0b42a12ff Update stop_repl, require replication consumer to be a callable. 2015-10-14 15:15:07 +02:00
Oleksandr Shulgin
fea2260fc5 Fix stop_replication: always raise outside the loop. 2015-10-14 12:50:08 +02:00
Oleksandr Shulgin
54079072db Fix ReplicationTest: no NotSupportedError now. 2015-10-14 12:43:26 +02:00
Oleksandr Shulgin
6ad299945f Remove IDENTIFY_SYSTEM wrapper method (it can't work with async anyway). 2015-10-13 18:05:33 +02:00
Oleksandr Shulgin
ea2b87eade Fix create_replication_slot doc signature 2015-10-13 11:01:13 +02:00
Oleksandr Shulgin
0233620c26 Rework replication connection/cursor classes 2015-10-01 19:33:27 +02:00
Oleksandr Shulgin
cac83da5db Use parse_dsn in ReplicationConnectionBase 2015-10-01 19:33:24 +02:00
Oleksandr Shulgin
95ee218c6d Update replication connection/cursor interface and docs. 2015-10-01 19:33:20 +02:00
Oleksandr Shulgin
937a7a9024 Cleanup start replication wrt. slot type a bit. 2015-10-01 19:33:16 +02:00
Oleksandr Shulgin
f872a2aabb Remove typedef for uint32, include internal/c.h 2015-10-01 19:33:12 +02:00
Oleksandr Shulgin
862eda10c2 Merge remote-tracking branch 'origin/master' into repl 2015-10-01 19:29:17 +02:00
Daniele Varrazzo
c73c1c5771 Decref the ssl module after importing 2015-10-01 17:04:29 +01:00
Daniele Varrazzo
f635547ec6 The wait_select callback can cancel a query using Ctrl-C
Fixes #333.
2015-10-01 15:26:13 +01:00
Daniele Varrazzo
9e6c3322d8 Fixed PersistentConnectionPool on Python 3
Fixes ticket #348.
2015-10-01 14:44:14 +01:00
ClodoaldoPinto
98f2aad4ba Typo correction 2015-10-01 14:31:31 +01:00
Daniele Varrazzo
ade7dba27c MSVC 2015 compiler support added to news file 2015-10-01 14:30:17 +01:00
Daniele Varrazzo
7e94ce1f14 Drop spurious notices in test
Getting some "rehashing catalog" debug messages in PG 9.4
2015-10-01 13:31:13 +01:00
Daniele Varrazzo
14246a5689 Merge branch 'parse-dsn' 2015-10-01 13:29:10 +01:00
Daniele Varrazzo
58918801d6 Added parse_dsn() to news file 2015-10-01 13:26:11 +01:00
Daniele Varrazzo
5afeee3613 Added unicode support to parse_dsn
Also added support for the argument as a keyword.
2015-10-01 13:20:11 +01:00
Daniele Varrazzo
71d96293ab Fixed parse_dsn tests on Python 3
On Python 3 there is no Exception.message attribute.
2015-10-01 12:03:00 +01:00
Daniele Varrazzo
d3bbd19ccb Separate parse_dsn test in a test case of their own 2015-10-01 11:52:42 +01:00
Daniele Varrazzo
d1af12187c Merge branch 'master' into parse-dsn 2015-10-01 11:39:51 +01:00
Daniele Varrazzo
6803341f21 Report NotSupportedError for PGRES_COPY_BOTH and PGRES_SINGLE_TUPLE
Fixes #352.
2015-09-30 12:28:07 +01:00
Daniele Varrazzo
0e3f5214c5 Report the server response status on errors with no message
Suggested by Craig Ringer in pull request #353, should also give more
information for other cases we were reported on flaky servers (AWS,
digital ocean...), see bug #281.
2015-09-30 12:28:07 +01:00
Federico Di Gregorio
4e92322d74 Merge pull request #350 from Photonios/master
Fixes for MSVC 2015 (Python 3.5)
2015-09-23 11:50:25 +02:00
Photonios
71925fcc00 Fix for MSVC 2015: round has been added to this version 2015-09-22 18:26:14 +02:00
Photonios
ac25ba0a3f Fix for MSVC 2015: isnan is supported in this version 2015-09-22 18:25:53 +02:00
Oleksandr Shulgin
26fe1f230f Fix use of PQconsumeInput() in pq_read_replication_message()
The libpq's PQconsumeInput() returns 0 in case of an error only, but
we need to know if it was able to actually read something.  Work
around this by setting an internal flag before retry.
2015-07-07 19:04:32 +02:00
Oleksandr Shulgin
eac16d048a Fix missing GC flag in ReplicationMessage type 2015-07-03 15:44:45 +02:00
Oleksandr Shulgin
06f18237f7 Fix missing free in replmsg_dealloc 2015-07-03 11:40:00 +02:00
Oleksandr Shulgin
9c1f2acf3e Check return value of PQsocket
When connection is closed by the server, we might get -1 there.
2015-07-02 14:39:51 +02:00
Oleksandr Shulgin
dab41c699a Fix PQconsumeInput usage.
Only call when no data is available in the internal buffer.
2015-07-02 14:34:09 +02:00
Oleksandr Shulgin
9386653d72 Update docs on ReplicationCursor 2015-07-01 14:08:32 +02:00
Oleksandr Shulgin
0d731aa12e Comment on special handling of PGRES_COPY_BOTH 2015-06-30 16:34:17 +02:00
Oleksandr Shulgin
318706f28c Update docs for Replication protocol 2015-06-30 16:17:31 +02:00
Oleksandr Shulgin
058db56430 Merge remote-tracking branch 'zalando/feature/replication-protocol' into feature/replication-protocol 2015-06-30 10:40:52 +02:00
Oleksandr Shulgin
61e52ce879 Rework replication protocol
This change exposes lower level functions for operating the
(logical) replication protocol, while keeping the high-level
start_replication function that does all the job for you in
case of a synchronous connection.

A number of other changes and fixes are put into this commit.
2015-06-30 10:38:18 +02:00
Oleksandr Shulgin
e3c3a2c19e Merge branch 'master' into feature/replication-message-object
Conflicts:
	lib/extensions.py
2015-06-30 10:30:32 +02:00
Oleksandr Shulgin
9ed90b1216 Refer cursor from ReplicationMessage object. At the same time, for the sync use LSN instead of msg reference in cursor. 2015-06-11 14:52:01 +02:00
Oleksandr Shulgin
35a3262fe3 Expose ReplicationMessage type in extras 2015-06-11 12:20:52 +02:00
Oleksandr Shulgin
9fc5bf4436 Add handling of send_time field in replmsg 2015-06-10 18:21:06 +02:00
Oleksandr Shulgin
1ac385d1fb Fix logical decoding plugin options adaptation on python3 2015-06-10 13:39:35 +02:00
Oleksandr Shulgin
453830f80c Add ReplicationMessage object 2015-06-05 17:44:09 +02:00
Oleksandr Shulgin
f7b84ce843 Add {libpq,win32}_support.* to the .cproj file 2015-06-04 11:01:09 +02:00
Oleksandr Shulgin
50df864f8c Add timersub for Win32. Fix gettimeofday on MinGW. 2015-06-04 11:00:08 +02:00
Oleksandr Shulgin
f14521f8cb Add libpq_support.c and win32_support.c
Move libpq-specific code for streaming replication support into a
separate file.  Also provide gettimeofday() on Win32, implementation
copied from Postgres core.
2015-06-03 14:10:20 +02:00
Daniele Varrazzo
925fdf5731 Fixed doc about libpq version availability 2015-06-02 17:11:09 +01:00
btubbs
06b4b1de94 Notify example should pop the oldest message in conn.notifies, not the newest. 2015-06-02 17:07:10 +01:00
Daniele Varrazzo
6002c524d6 Merge branch 'notice-lists-replaceable' 2015-06-02 17:04:25 +01:00
Daniele Varrazzo
1f330e9cac Allow connection.notices and notifies to be replaced.
Close #326
2015-06-02 17:02:04 +01:00
Oleksandr Shulgin
44b705f88f Improve identify_system: don't hardcode column names 2015-06-02 16:52:48 +02:00
Daniele Varrazzo
2ad82b973b Pending notice list converted into a forward list
This allows inserting the elements in order without using list.insert().
2015-06-02 14:25:46 +01:00
Daniele Varrazzo
b326a27774 Dropped unneeded constness on the notice message
That's a strdup result, we 0wn it.
2015-06-02 14:24:48 +01:00
Daniele Varrazzo
0a7261268b Dropped unused notice_filter connection member 2015-06-02 13:11:46 +01:00
Oleksandr Shulgin
d6041271bc Separate parse_dsn test on URI, for libpq >= 9.2 2015-06-02 14:02:29 +02:00
Pete Hollobon
5712f30169 Change "non desiderable" to "undesirable" in docs
"desiderable" is considered obsolete
2015-06-02 13:00:25 +01:00
Daniele Varrazzo
7e5715617e Merge branch 'adapt-list-of-none' 2015-06-02 12:49:15 +01:00
Daniele Varrazzo
b0058c0cc8 Fixed adaptation of lists of None
Note: lists of lists of None are not supported yet.
2015-06-02 12:48:24 +01:00
Oleksandr Shulgin
cc08e14162 Merge branch 'master' into feature/parse-dsn
Conflicts:
	lib/extensions.py
2015-06-02 12:42:03 +02:00
Daniele Varrazzo
8d4ac25b56 Merge branch 'libpq-version' 2015-06-02 11:20:28 +01:00
Daniele Varrazzo
c2955fb8fc Version function/constant docs improved 2015-06-02 11:20:02 +01:00
Daniele Varrazzo
5a21da43ee Mention libpq version inspection in news file 2015-06-02 11:19:55 +01:00
Daniele Varrazzo
73d17e3c5e Dropped PG_VERSION_HEX constant
At PostgreSQL 10.0 it would have become awkward.
2015-06-02 10:54:08 +01:00
Oleksandr Shulgin
80da76d43f Get rid of postgres internal includes; check for Win32 for htonl() 2015-06-02 11:42:56 +02:00
Oleksandr Shulgin
ffd98a82c0 Add test for libpq_version 2015-06-02 11:12:16 +02:00
Oleksandr Shulgin
4bb6f9cef2 Add libpq version discovery 2015-06-01 18:05:11 +02:00
Oleksandr Shulgin
3200cd77bf One more parse_dsn test for unquoted space 2015-06-01 15:18:03 +02:00
Oleksandr Shulgin
6a2f21aa14 Move parse_dsn to extensions, add tests 2015-06-01 15:11:12 +02:00
Oleksandr Shulgin
e32e1b834e Add support for streaming replication protocol
Introduce ReplicationConnection and ReplicationCursor classes, that
incapsulate initiation of special type of PostgreSQL connection and
handling of special replication commands only available in this special
connection mode.

The handling of stream of replication data from the server is modelled
largely after the existing support for "COPY table TO file" command and
pg_recvlogical tool supplied with PostgreSQL (though, it can also be
used for physical replication.)
2015-06-01 11:45:04 +02:00
Oleksandr Shulgin
6c57e4a648 Add parse_dsn module function
Calls PQconninfoParse to parse the dsn into a list of keyword and value
structs, then constructs a dictionary from that.  Can be useful when one
needs to alter some part of the the connection string reliably, but
doesn't want to get into all the details of parsing a dsn string:
quoting, URL format, etc.
2015-06-01 10:16:07 +02:00
Daniele Varrazzo
d66165232e OpenSSL deadlock fix noted in NEWSfile 2015-05-03 12:27:37 +01:00
Jan Urbański
a59704cf93 Make sure libcrypto threadsafety callbacks are properly set up
Multithreaded programs using libcrypto (part of OpenSSL) need to set up
callbacks to ensure safe execution. Both Python and libpq set up those
callbacks, which might lead to a conflict.

To avoid leaving dangling function pointers when being unloaded, libpq sets up
and removes the callbacks every time a SSL connection it opened and closed. If
another Python thread is performing unrelated SSL operations (like connecting
to a HTTPS server), this might lead to deadlocks, as described in
http://www.postgresql.org/message-id/871tlzrlkq.fsf@wulczer.org

Even if the problem will be remediated in libpq, it's still useful to have it
fixed in psycopg2. The solution is to use Python's own libcrypto callbacks and
completely disable handling them in libpq.
2015-05-03 12:27:36 +01:00
Daniele Varrazzo
1b7e3c6da4 Improve docs about connection's with only closing the transaction 2015-05-03 12:01:06 +01:00
Daniele Varrazzo
ad3e91a56f Unlock the connection after PQflush error
Apparently this has never happened... anyway the code path was wrong.

Fixes #294.
2015-05-03 12:01:05 +01:00
Daniele Varrazzo
4078b89521 Added makefile target to upload docs 2015-05-03 10:30:33 +01:00
Daniele Varrazzo
1d006ccbe9 Added note about table names to be escaped in copy_*() methods. 2015-05-03 10:30:28 +01:00
Hyunjun Kim
4eee1207f9 Fix several typos 2015-05-03 10:30:21 +01:00
Daniele Varrazzo
2cab752443 Fix to MinTimeLoggingCursor.callproc() noted in NEWSfile 2015-05-03 10:30:16 +01:00
andrew deryabin
41639c7610 Fixed MinTimeLoggingCursor.callproc() 2015-05-03 10:30:11 +01:00
Daniele Varrazzo
f27ca25d2e Wordsmith on connection.set_session()
Fixes #310.
2015-05-03 10:30:05 +01:00
Daniele Varrazzo
70fbc8bf1f Fixed connection.poll() docstring
Fixes #312
2015-05-03 10:29:57 +01:00
Daniele Varrazzo
0b523927bc Docs build process and docs cleaned up 2015-04-28 09:32:58 +01:00
Daniele Varrazzo
1e8be5bd09 Added missing files needed to build the docs
Fixes #291
2015-04-28 08:38:57 +01:00
Daniele Varrazzo
c62c292053 Bump to next dev version number for the master branch 2015-04-28 08:38:41 +01:00
Daniele Varrazzo
5efe7131ff Version bumped for release 2.6 2015-02-09 09:43:55 +00:00
Daniele Varrazzo
6d63973e08 More portable way to establish Python 32/64 build 2015-02-08 22:52:50 +00:00
Daniele Varrazzo
569fd0975b Python 3.1 bytes.decode() doesn't support keyword arguments
Sucker.
2015-02-08 19:43:09 +00:00
Daniele Varrazzo
296caa4556 More tests tweaks
Named cursors on old server versions have a different prefetch behaviour.
This has hidden me the supported range of the 24:00 time format.
Let's have another go at full testing...
2015-02-08 12:51:36 +00:00
Daniele Varrazzo
7ea56b112e Make Column picklable on Python >= 3.3
Also expose the type from the extensions module, not from the main
module.
2015-02-08 11:27:10 +00:00
Daniele Varrazzo
6177823811 Don't test date 24:00 before PG 8.4 2015-02-08 10:30:48 +00:00
Daniele Varrazzo
2a2f306f7b Added NEWS note about picklable cursor.desciption 2015-02-08 02:32:47 +00:00
Owen Raccuglia
5af5fb4cc6 Allow pickling of cursor.description
This is for people using dtuple.py; a dtuple.DatabaseTuple instance
keeps a reference to cursor.description, which is not picklable because
psycopg2 doesn't export the Column namedtuple it uses.

This commit exports the Column namedtuple, and includes a test to verify
the pickle/unpickle works after exporting Column.
2015-02-08 02:31:33 +00:00
Daniele Varrazzo
54ebf90fc6 Document that LO64 is only available on Py 64 builds 2015-02-08 02:21:22 +00:00
Daniele Varrazzo
f15e9d0cc8 Fixed link in NEWS entry 2015-02-08 02:14:00 +00:00
Daniele Varrazzo
e490e3bfa3 Accept overflow errors testing for LO64 funcs
It is raised on 32 bits by PyArg_ParseTuple. We may work around on
truncate (maybe parsing a py_ssize_t) but we would have the same problem
on seek as the offset is signed.
2015-02-08 02:04:41 +00:00
Daniele Varrazzo
7ce7fef322 Propagate read error messages in COPY FROM
Fix ticket #270.
2015-02-08 01:42:21 +00:00
Daniele Varrazzo
d3c1ad5945 Convert Postgres time 24:00 into 00:00
Fix ticket #278.
2015-02-08 00:41:50 +00:00
Daniele Varrazzo
2332f2c99e Merge branch 'timetz' 2014-12-25 15:09:15 +01:00
Daniele Varrazzo
b5ac992944 Merge branch 'lo64' 2014-12-25 15:08:02 +01:00
Daniele Varrazzo
7139187381 Large object 64 bit API quoted in news file 2014-12-25 15:07:34 +01:00
Daniele Varrazzo
a338da9c19 Fixed typo in tests 2014-12-25 15:06:18 +01:00
Daniele Varrazzo
c008f9d1ce Added documentation about the lo64 support 2014-12-25 15:06:18 +01:00
Daniele Varrazzo
bc5e2aeead Keep into account psycopg build in lo64 tests 2014-12-25 15:06:18 +01:00
Daniele Varrazzo
2f862972c9 Guard against overflows when using the lo32 api
If psycopg supports lo64 but the server doesn't the user may pass values
that would overflow the api range, resulting in:

    lo.seek((2<<30))
    *** OperationalError: ERROR:  invalid seek offset: -2147483648

Also improved the error messages and guard against INT_MIN for negative
seek offsets.
2014-12-25 15:06:18 +01:00
Daniele Varrazzo
79df47a146 Fixed mismatched types in debug print 2014-12-25 15:06:18 +01:00
Daniele Varrazzo
44219bf366 Don't try and compile lo64 support on 32 bits Python
We can't fit more than 31 bits in a long anyway.
2014-12-25 15:06:18 +01:00
Daniele Varrazzo
b2327b0fc7 Add the flag 'lo64' to the version if psycopg supports the lo_*64 api 2014-12-25 15:06:18 +01:00
Daniele Varrazzo
0205d6ca2e Use ifdef instead of if to check LO64 2014-12-25 15:06:18 +01:00
Daniele Varrazzo
91eabf5fcb Fixed check for PG version
It would have failed in PostgreSQL 10.0.
2014-12-25 15:06:18 +01:00
Blake Rouse
e5bbde9554 Check server_version before using lo_*64 functions. If less tahn 9.3 old none 64bit functions will be use. 2014-12-25 15:06:18 +01:00
Blake Rouse
cd67d3d2fe Modify truncate to use lo_truncate64. Use HAVE_LO64 define to use new lo_*64 methods. Check size of offset and length for versions without LO64. 2014-12-25 15:06:18 +01:00
Blake Rouse
e13ec67da3 Use lseek64 and ltell64 to support large object greater than 2gb in size. 2014-12-25 15:06:18 +01:00
Daniele Varrazzo
6bccb05c90 timetz adaptation documented 2014-12-25 14:57:31 +01:00
Federico Di Gregorio
85ba098cd8 Merge pull request #273 from eriklee/master
Correct exausted -> exhausted typo in exception
2014-11-17 22:36:47 +01:00
Erik Lee
e9f54a2d6e Correct exausted -> exhausted typo 2014-11-17 17:01:00 +00:00
Federico Di Gregorio
096e0729d5 Merge pull request #272 from yoloseem/timetz
Cast time into timetz when the tzinfo field is set.
2014-11-13 10:07:02 +01:00
Hyunjun Kim
4dbda02145 Cast time into timetz when the tzinfo field is set. 2014-11-13 17:32:06 +09:00
Federico Di Gregorio
0d553269d5 Merge pull request #271 from tokheim/master
Correction to type adaption example

It is OK for an adapted object to return the escaped string on 
__str__ calls but getquoted() is the canonical method.
2014-11-03 21:21:10 +01:00
Asmund Tokheim
ab4afd0e2f Correction to type adaption example, making it more transparent 2014-11-02 14:15:51 +01:00
Daniele Varrazzo
1b48033345 Don't try to close the server cursor in error state
`close()` is implicitly called by `__exit__()`, so an exit on error
would run a query on a inerr connection, causing another exception
hiding the original one. The fix is on `close()`, not on `__exit__()`,
because the semantic of the latter is simply to call the former.

Closes #262.
2014-09-16 06:57:34 +01:00
Daniele Varrazzo
48a32b766b In 2010 I couldn't speak English 2014-09-16 06:57:34 +01:00
Tomer Chachamu
6de7315210 Fix typo in docs 2014-09-01 16:29:38 +01:00
Daniele Varrazzo
b4d38c455c Don't need to build the env for a sdist
After 2.5 we are not releasing the html docs in the sdist anymore.
2014-09-01 16:29:38 +01:00
Daniele Varrazzo
7faa06ce0b Added scripts to release and upload docs 2014-09-01 16:29:38 +01:00
Daniele Varrazzo
9fdfa86200 Release notes cleanup before releasing 2.4.5 2014-08-31 03:06:50 +01:00
Daniele Varrazzo
6210af2763 Fixed excessively strict notices test
Failing with PG 9.4 because it generates other debug messages during the
test run (rehashing catalog cache).
2014-08-31 03:06:33 +01:00
Daniele Varrazzo
8e06a51884 Added plural version of the tickets role 2014-08-31 03:05:03 +01:00
Daniele Varrazzo
7d81c48849 Point tickets to GitHub instead of Lighthouse
Keep into account the numbers reshuffling: Lighthouse bugs with a number
matching a GitHub merge request are shifted ahead.
2014-08-31 03:05:03 +01:00
Daniele Varrazzo
37d80f2c03 Use the readme as PyPI desctiption 2014-08-31 02:59:49 +01:00
Daniele Varrazzo
6705e4051d Dropped creation of errcodes with missing spec field
On further inspection these names are just aliases for values already
defined: we don't need the duplication.
2014-08-28 02:17:57 +01:00
Daniele Varrazzo
ccc30e1877 Clear adapters in test to maintain reference count 2014-08-28 02:17:54 +01:00
Daniele Varrazzo
2d601ef157 Fixed memory leak with large objects
Deallocating closed large objects failed to decrement the connection
refcount. The fact the lobject is closed doesn't matter for refcount.
Issue detected by the always useful scripts/refcounter.py

With an extra bit of unrequested whitespace love.
2014-08-28 02:17:52 +01:00
Daniele Varrazzo
ea54aa77ed Added test to verify _psycopg can be imported 2014-08-28 02:17:49 +01:00
Daniele Varrazzo
54d904138d Don't import psycopg2.tz into the C extension
This makes possible to import _psycopg directly, after adding the
package directory to the pythonpath. This enables hacks such as:

    sys.path.insert(0, '/path/to/psycopg2')
    import _psycopg
    sys.modules['psycopg2._psycopg'] = _psycopg
    sys.path.pop(0)

which can work around e.g. the problem of #201, freeze that cannot
freeze psycopg2. Well, freeze cannot freeze it because it's just not
designed to deal with C extensions. At least now the frozen application
can hack the pythonpath and work around the limitation by importing
_psycopg as above and then doing the rest of the imports normally.

Keeping long-lived references to python objects is bad anyway: the
tz module couldn't be reloaded before.
2014-08-28 02:17:46 +01:00
Daniele Varrazzo
df9fbc515d Direct link to the install docs in the readme 2014-08-24 23:33:14 +01:00
Daniele Varrazzo
f7ee006bef Use virtualenv as build environment for the docs 2014-08-24 23:11:07 +01:00
Daniele Varrazzo
4a4e0d8f9a Self-updating copyright year in docs 2014-08-24 23:07:22 +01:00
Daniele Varrazzo
c1da93a7b2 Document we known 9.4 errorcodes 2014-08-24 22:11:21 +01:00
Daniele Varrazzo
b8b15637aa Take the PYTHONPATH into account when building the docs 2014-08-24 22:11:02 +01:00
Daniele Varrazzo
2ad67ee56e Move the extras module up in the docs
It is more interesting than `tz` and `pool`.
2014-08-24 22:10:24 +01:00
Daniele Varrazzo
843de765a1 Fixed doc example about Error attributes
Catch the Error, not everything!

Also, whitespaces.
2014-08-24 22:08:33 +01:00
Daniele Varrazzo
afdb7422fb Merge branch 'clean-text-files' 2014-08-24 02:06:27 +01:00
Daniele Varrazzo
c0e94ad01f Dropped outdated HACKING file 2014-08-24 02:06:09 +01:00
Daniele Varrazzo
2be26804d3 Dropped content from the INSTALL file
The docs have it right.
2014-08-24 02:06:09 +01:00
Daniele Varrazzo
d8bbaf0481 Added info about running the test suite in the docs
They were in the INSTALL file, which is quite out-of-date now.
Also fixed a couple of other things.
2014-08-24 02:06:09 +01:00
Daniele Varrazzo
353b36c657 Readme cleaned up and converted to reST
Dropped outdated info and references to the INSTALL, which is less
up-to-date than the docs.

Converted to reST to have it prettier on GitHub.
2014-08-24 02:06:09 +01:00
Daniele Varrazzo
0ea7798122 Merge branch 'drop-flags' 2014-08-24 02:05:23 +01:00
Daniele Varrazzo
1d729ab40e Dropped HAVE_PQFREEMEM flag
It was necessary before PG 7.4, in versions which have long been unsupported.
2014-08-24 01:43:12 +01:00
Daniele Varrazzo
68a4308c3d Dropped PSYCOPG_NEW_BOOLEAN flag
Introduced in 2.0 beta 8, 2006 A.D. Went absolutely untouched in 8 years
of refactoring, when Python 2.5 and PostgreSQL 8.1 roamed the earth.

I would say it has stood the test of the time.
2014-08-24 01:25:02 +01:00
Daniele Varrazzo
6e841a41e6 Dropped PSYCOPG_EXTENSIONS flag
Building without extensions has been long broken and nobody really cares
about a pure-DBAPI implementation (which could be created using a wrapper
instead).
2014-08-23 19:30:48 +01:00
Daniele Varrazzo
6a5f778361 Merge branch 'withhold-transactions' 2014-08-21 05:55:11 +01:00
Daniele Varrazzo
d20c03310d Document WITH HOLD corrections. 2014-08-21 05:53:07 +01:00
Alexey Borzenkov
13b0852619 Allow using named with hold cursors in autocommit 2014-08-21 05:35:11 +01:00
Daniele Varrazzo
c81522079e Added test to verify withhold cursors work in autocommit 2014-08-21 05:35:11 +01:00
Alexey Borzenkov
478e66f761 No implicit transaction on named cursor close
Also, don't start an implicit transaction when fetching with
named with hold cursor, since it already returns results
from a previously committed transaction.
2014-08-21 05:35:10 +01:00
Daniele Varrazzo
283a422b4d Added test to verify withhold transaction behaviour
A withhold cursor can read its data when the transaction is closed, so
it shouldn't start a new one upon movement/close.
2014-08-21 05:35:10 +01:00
Daniele Varrazzo
a2b01cdf42 Dropped simple type wrapper functions
These functions don't need to exist: exposing the type in the module is
enough. It is actually better as one may use isinstance and such.
2014-08-15 02:54:31 +01:00
Daniele Varrazzo
1b322a9b19 Fixed segfault in List function
This function is never called: it segfaults 100%. To be removed.
2014-08-15 02:54:25 +01:00
Daniele Varrazzo
95165cef7d Dropped almost-no-op customized objects repr()
The default repr is enough: it prints <TypeName at 0xADDR> instead of
<TypeName object at 0xADDR>.

The only people being hurt by this change are the ones using doctests:
they deserve it.
2014-08-15 02:54:10 +01:00
Daniele Varrazzo
669e787919 Name the types after the module they are exposed from 2014-08-15 01:47:19 +01:00
Daniele Varrazzo
31d07e5029 Scrape PostgreSQL 9.4 error codes table too
No new error code found as of 9.4 beta2.
2014-08-13 02:44:59 +01:00
Daniele Varrazzo
41a083cec3 Convert pool arguments to int
Failing to do so may cause dangerous misbehaviours such as an unbounded
pool (because of lame comparison operators in Python 2).

Fix ticket #220.
2014-08-13 02:39:16 +01:00
Daniele Varrazzo
c475a0db95 Document PostgreSQL 9.4 as supported
Actually there is a test failing in the test suite in PG 9.4beta2, but
it's probably because the default logging level is to DEBUG. Will wait
for the final release to check if the test is to be fixed. All other
tests pass no problem.
2014-08-13 02:09:04 +01:00
Daniele Varrazzo
0b95194f74 Merge branch 'jsonb' 2014-08-13 02:03:11 +01:00
Daniele Varrazzo
e225aad042 Habemus jsonb 2014-08-13 02:02:06 +01:00
Daniele Varrazzo
f40ad93a37 Added jsonb docs 2014-08-13 02:02:04 +01:00
Daniele Varrazzo
9d547469b8 Add register_default_jsonb() and register the type 2014-08-13 02:02:01 +01:00
Daniele Varrazzo
6bca443e37 Added name param to register_json() 2014-08-13 02:01:55 +01:00
Daniele Varrazzo
634fc004fb Added wishful test suite for jsonb type 2014-08-13 02:01:51 +01:00
Daniele Varrazzo
44281d6692 Fix supported Py/PG versions in docs 2014-08-04 22:39:52 +01:00
Daniele Varrazzo
6d6fd9acf7 Parse errocodes for PG 9.3 too
There is no new errcode defined so no need to release this as a change,
only change the docs.
2014-07-31 13:35:04 +01:00
Daniele Varrazzo
40dca9924d Add a few missing errcodes
They are used in the code but not defined in the SGML docs so the script
failed to parse them.
2014-07-31 13:34:53 +01:00
Daniele Varrazzo
081bf843d2 Parse the error codes from the text file if available
The text file was added in PG 9.1. It contains a few errors not available
in the SGML.
2014-07-31 13:33:36 +01:00
Daniele Varrazzo
56adc590ff Fixed segfault if COPY statements are executed
Close ticket #219
2014-06-06 21:42:21 +02:00
Daniele Varrazzo
115ceea1eb Don't ignore silently the cursor.callproc argument without a length 2014-06-06 21:42:21 +02:00
Daniele Varrazzo
e076e935b9 Added test with objects without length as callproc param 2014-06-06 21:42:20 +02:00
Chris Mildebrandt
693dedf4da cleanup remaining GPL license text 2014-05-20 09:50:53 -07:00
Chris Mildebrandt
67354ed14f cleanup remaining GPL license text 2014-05-20 09:42:41 -07:00
Jason Erickson
8746b0c6b7 Skip test_cleanup_on_badconn_close on Windows
The Windows server version of PostgreSQL uses a function called pgkill in the
file kill.c in place of the UNIX kill function.  This pgkill function
simulates some of the SIGHUP like commands by passing signals through a named
pipe.  Because it is passing the signal through a pipe, the server doesn't get
the kill signal immediately and therefore fails the test on
test_connection.ConnectionTests.test_cleanup_on_badconn_close.
Ideally, the test should check to see if the server is running on Windows, not
the psycopg.
2014-05-19 12:15:53 +01:00
Jason Erickson
c5f2e29dde Added select.select timeout on AsyncTests.wait
On Windows, the select.select() hangs/waits forever on the
test_async_connection_error_message() test.  Adding a 10 second timeout
allows the tests to continue.
2014-05-19 12:15:52 +01:00
Daniele Varrazzo
97290955f6 Python 3.4 declared supported 2014-05-13 14:36:28 +01:00
Daniele Varrazzo
d0b35adeb6 Parse the rowcount as long 2014-05-13 14:34:10 +01:00
Daniele Varrazzo
35545e7374 Skip rowcount on copy test on postgres < 8.2
It looks like the server doesn't send the message.
2014-05-13 14:34:09 +01:00
Daniele Varrazzo
81b5f1fb26 Copy operations correctly set the cursor.rowcount attribute
Fixes ticket #180.
2014-05-05 23:53:50 +01:00
Daniele Varrazzo
abd975ae40 set_session() params documented in a more Python-friendly way 2014-05-05 23:06:23 +01:00
Daniele Varrazzo
69605e54ec Fixed explicit connection.cursor(cursor_factory=None)
Fixes issue #210.
2014-04-30 17:57:55 +01:00
Daniele Varrazzo
03b8b1e97a Merge branch 'connection-closed'
NEWS for released 2.5.3 reordered.
2014-04-05 16:11:19 +01:00
Daniele Varrazzo
09fb131f1a Don't specify 0 or 1 in closed docs
There's also 2 which means broken. But I prefer to leave that as
implementation detail.
2014-04-05 16:03:19 +01:00
Daniele Varrazzo
489658cfc5 Close the connection if discovered bad on poll() 2014-04-05 16:03:19 +01:00
Daniele Varrazzo
1654687d1b Check the connection is really bad on exception before closing it
We end up here without a pgres sometimes (e.g. from lobject errors)
2014-04-05 16:03:06 +01:00
Daniele Varrazzo
3752880b7b Fixed attempt of closing an already closed lobject on dealloc
This results in a "null without exception set" in the corrent state, which
is caused by the connection being unexpectedly closed anyway.
2014-04-05 16:03:06 +01:00
Daniele Varrazzo
2e55b35d5d Don't set an exception witout GIL closing lobjects with a bad conn
We ended up in this branch only for an excessively aggressive closing
of the transaction that now I'm going to fix.
2014-04-05 16:03:06 +01:00
Daniele Varrazzo
696d123550 Close a connection if PQexec returned NULL
This happens for Socket connections, not for TCP ones, where a result
containing an error is returned and correctly handled by pq_raise()

Closes ticket #196 but not #192: poll() still doesn't change the
connection closed.
2014-04-05 16:03:06 +01:00
Daniele Varrazzo
a31c1a1722 Allow get_transaction_status on closed connections
It's a local operation and the libpq functions has a NULL guard.
2014-04-05 16:02:43 +01:00
Daniele Varrazzo
9036299d54 Avoid printing the typecast name in debug statement
The way we were doing it is unsafe and causes assertion failures on Py3.

Fixes ticket #188
2014-04-04 19:25:09 +01:00
Daniele Varrazzo
ca98167ae4 Fixed use of Python object with refcount 0 in cursor_init
Caused segfault running test_cursor.CursorTests.test_invalid_name under
Python 3.4 built in debug mode.
2014-04-04 19:20:08 +01:00
Daniele Varrazzo
81443c3a65 Work around pip issue #1630 breaking 'pip -e git+url'
https://github.com/pypa/pip/issues/1630

Fixes ticket #18 (opened in 2010!)
2014-04-04 18:07:05 +01:00
Daniele Varrazzo
33f2301772 Clarify in the docs that mogrify() and query always return bytes 2014-04-03 02:46:54 +01:00
Daniele Varrazzo
e9661bcde5 Fixed bug number typo in NEWS file 2014-04-03 02:45:57 +01:00
Daniele Varrazzo
a8fdc74090 Fixed overflow opening a lobject with an oid not fitting in a signed int
Fixes 🎫`203`.
2014-04-03 02:35:56 +01:00
Daniele Varrazzo
dfacc483b5 Dropped unneeded pass in test 2014-04-03 02:32:05 +01:00
Daniele Varrazzo
25e3a5f744 Explicit the fact that closed connections have undefined status 2014-04-03 02:07:38 +01:00
Daniele Varrazzo
e7fc7f31b9 Fixed dsn and closed attributes in failing connection subclasses.
From ticket #192 discussion.
2014-04-03 01:42:35 +01:00
Erwin de Keijzer
0258e90ef0 Fixed DNS typo in examples 2014-03-24 18:36:33 +01:00
Daniele Varrazzo
7b82be936d Don't segfault on uninitialized cursor
It can happen with bad cursor subclasses not calling super's init. Raise
an exception instead of segfaulting.

Closes #195
2014-02-26 19:41:59 +00:00
Daniele Varrazzo
618f7e41de Use the do-while 0 idiom for cursor guards macro 2014-02-26 19:31:27 +00:00
Daniele Varrazzo
3c893606f5 Merge branch 'ticket-194' 2014-02-24 15:20:13 +00:00
Daniele Varrazzo
79e84e432a Bug #194 confirmed fixed: newsfile updated. 2014-02-24 15:20:01 +00:00
Daniele Varrazzo
63e36e22d2 Set the connection async before polling for connection
It should fix ticket #194
2014-02-24 15:20:01 +00:00
Daniele Varrazzo
ca99579b76 Set the connection async earlier in green mode
The moment it is called shouldn't have really changed, but it's more
explicit when it happens. Previously it was sort of obfuscated behind a
roundtrip through the green callback and poll.
2014-02-24 15:20:01 +00:00
Daniele Varrazzo
283dbccf56 Merge branch 'range_sort' 2014-02-22 23:02:19 +00:00
Daniele Varrazzo
dd9e476353 Fixed error message on range parsing failed 2014-02-22 23:02:07 +00:00
Daniele Varrazzo
8d2744c550 Mention Range order in the news file 2014-02-22 23:01:22 +00:00
Daniele Varrazzo
212f4e3538 Docs wordsmithing about Range order 2014-02-22 23:01:02 +00:00
Daniele Varrazzo
8937c635df Hardcode the list of attributes to be used in comparison
Comparing Range subclasses may lead to surprises.
2014-02-22 21:52:44 +00:00
Daniele Varrazzo
4545d1636c Added implementation for Range gt and ge operators
Using a common implementation for all the operators. Note that lt is the
one used by sort so it's nice it's the fastest.
2014-02-22 21:51:28 +00:00
Daniele Varrazzo
6192a4fb17 Added str() for the Json adapter
Fixes ticket #191.
2014-02-22 20:45:35 +00:00
Chris Withers
6cd0647da9 documentation changes now that Range objects can be ordered 2014-02-18 21:24:59 +00:00
Chris Withers
e60266c4c5 New implementation of Range sorting that works for Python 2.5 to 3.3, at least. 2014-02-18 20:55:00 +00:00
Chris Withers
bae508ffa6 Coding style changes. 2014-02-14 07:46:32 +00:00
Chris Withers
d469c32503 Provide a stable and consistent sort order for Range objects.
This matches postgres server-side behaviour and helps client applications that need to sort based on the primary key of tables where the primary key is or contains a range.
2014-02-12 08:11:59 +00:00
Daniele Varrazzo
66f85b5832 Merge branch 'outputres' 2014-01-14 21:54:28 +00:00
Daniele Varrazzo
a35b743af7 Mention outputres fix in NEWS file 2014-01-14 21:52:42 +00:00
Daniele Varrazzo
4ed9dc1435 Added doc notes about how to avoid JSON parsing
Added FAQ too as it has bitten more than one user
(see tickets #172, #190).
2014-01-14 18:33:05 +00:00
James Emerton
58c98deebb Fallback when get_ext_fullpath() is unavailable 2014-01-10 13:41:16 -08:00
James Emerton
9100ad3e8f Use get_ext_fullpath() for -outputresource
The manifest fixup was relying on the extension name being "_psycopg.pyd" which effectively prevents building with --debug as the extension name becomes "_psycopg_d.pyd" in this instance.
2014-01-10 11:56:14 -08:00
Daniele Varrazzo
85b1914ad6 Fixed dealloc of lobject->smode
I put it by mistake into the in the self->conn checked block in the
previous commit.
2013-11-27 13:00:16 +00:00
Daniele Varrazzo
e11d0d39ec Check connection type in lobject init
Fixes ticket #187.
2013-11-27 12:44:28 +00:00
Daniele Varrazzo
6ab1ec1c37 Typo fixes and improvements to new_array_type() docs 2013-10-21 15:27:31 +01:00
Daniele Varrazzo
bc70902ea5 Use bytestrings in infinite dates adapter example
Returning strings would result in unclear tracebacks on Py3 (see ticket #163).
2013-10-21 14:30:25 +01:00
Daniele Varrazzo
2e3833f7fb Really test named cursors in test_scroll_named() 2013-10-16 19:10:21 +01:00
Daniele Varrazzo
5c99d2a456 Document that named cursors don't raise an exception going out-of-bound
See issue #174 for the details.
2013-10-16 19:10:20 +01:00
Daniele Varrazzo
a0a63e3ac7 Document that using %, (, ) in the placeholder name is not supported 2013-10-16 17:50:11 +01:00
Daniele Varrazzo
1e623a951c Meaningful connection errors report a meaningful message
Fixes issue #173.
2013-10-16 17:50:10 +01:00
Daniele Varrazzo
345077d5f7 Fixed pickling of exceptions with no pgerror/pgcode set
Fixes ticket #170.
2013-07-19 16:05:59 +01:00
Daniele Varrazzo
81e8b869d0 Fixed titles in newsfile
The first title at the same level of the main releases helps getting a
more regular ToC in the docs main page.
2013-07-19 16:02:31 +01:00
Daniele Varrazzo
497247a528 Fixed doc index entry for infinite dates 2013-06-23 02:14:01 +01:00
Daniele Varrazzo
921b676471 Untrack the connection before closing to avoid possible double-free
From Gangadharan S.A. Fixes issue #166.
2013-06-20 16:35:43 +01:00
Daniele Varrazzo
83c5d12cf1 Added doc example to convert date.max to infinity
See issue #163.
2013-06-18 15:00:30 +01:00
Daniele Varrazzo
ea08f7e7c7 Merge branch 'range_eq_typerror' 2013-06-18 14:14:01 +01:00
Daniele Varrazzo
1361189b99 Mention the Range eq fix in the NEWS file 2013-06-18 14:13:00 +01:00
Daniele Varrazzo
d50ea3d82b Uniform Range eq tests style 2013-06-18 14:10:49 +01:00
Chris Withers
28276e3eb1 cater for comparison of subclasses 2013-05-26 22:20:07 +01:00
Chris Withers
b6a9e0ffaf raising an exception here rather than returning False causes problems with SQLAlchemy's internal state tracking 2013-05-26 21:58:39 +01:00
Chris Withers
8bb44f3444 more useful error message when comparing ranges with non-ranges 2013-05-26 21:20:40 +01:00
Daniele Varrazzo
1ef234ebfc Added regression test for infinity parsing in dates
...and a couple of typos.
2013-05-11 02:19:59 +01:00
Daniele Varrazzo
c796bc2cbd Added test to verify copysize handling in copy_expert
Not an original psycopg2 bug but present in pure python implementation,
e.g. ctypes issue #25 and cffi issue #5.

https://github.com/mvantellingen/psycopg2-ctypes/issues/25
https://github.com/chtd/psycopg2cffi/pull/5
2013-05-06 10:48:10 +01:00
Daniele Varrazzo
a44db81d9b Skip tests on python implementations without getrefcount()
PyPy is one of these.
2013-05-06 10:39:24 +01:00
Daniele Varrazzo
bbe0bf955c A few docs fixes to the usage page 2013-05-01 22:40:19 +01:00
Daniele Varrazzo
1ff3ea0745 Dropped a lot of words from the front matter
Replaced with links to the types adaptation table and the extension docs.
2013-04-26 10:06:26 +01:00
Piotr Kasprzyk
31b6ec63f8 Fix multiple misspellings 2013-04-26 09:59:40 +01:00
Daniele Varrazzo
2eba97de70 Merge branch 'classifiers' 2013-04-21 21:44:57 +01:00
Daniele Varrazzo
4547753df0 Added explicit Python 2 and Python 3 classifiers
Not sure, but I suspect the "python3" page on PyPy in only based
on the Language :: Python :: 3 classifier, not the more specific ones
2013-04-21 21:43:55 +01:00
Saul Shanabrook
4de8b9577e Explicit Python Version Support
Used supported versions from http://initd.org/psycopg/docs/install.html
2013-04-21 21:35:58 +01:00
Daniele Varrazzo
fc2ca0d2e9 Make sure to return a bytes string from numeric range adapter 2013-04-21 20:30:50 +01:00
Daniele Varrazzo
d159dfea9d Merge branch 'solaris-round' 2013-04-21 18:39:30 +01:00
Daniele Varrazzo
fdc5dc750c Mention Solaris round fix in NEWS file 2013-04-21 18:37:19 +01:00
Daniele Varrazzo
e335eb98ce Long ifdef reformatted for readibility 2013-04-20 02:21:58 +01:00
Daniele Varrazzo
5d86d07618 Testing external script independent from psycopg implementation
Patch needed to run the test suite on psycopg2cffi or psycopg2ct.
2013-04-19 23:01:28 +01:00
Daniel Enman
558f7ad929 Remove extra || 2013-04-18 17:12:14 -03:00
Daniel Enman
cda0b6a8eb Solaris 10+, and illumos distros have round() 2013-04-18 16:59:26 -03:00
Daniele Varrazzo
711c092a79 The UUID adapter returns bytes instead of str in Python 3
Also added __conform__ method to the adapter.
2013-04-07 22:19:04 +01:00
Daniele Varrazzo
61d496b2ed Script to test ticket #58 moved into sandbox
We don't need it distributed in the sdist
2013-04-07 22:02:52 +01:00
Daniele Varrazzo
04c09b7b38 Dropped GPL license from source
It doesn't apply: leaving the LGPL only.
2013-04-07 22:02:45 +01:00
Daniele Varrazzo
1af4bd83c4 Stop distributing the compiled documentation with the source 2013-04-07 22:02:38 +01:00
Daniele Varrazzo
af7347473e Dropped stale entries from MANIFEST.in 2013-04-07 22:02:32 +01:00
Daniele Varrazzo
f2fbf18a05 Dropped psycopg 1 changelog
Also MANIFEST.in cleaned up from stale entries
2013-04-07 22:01:38 +01:00
Daniele Varrazzo
6d2f2676ad Bump to next dev version 2013-04-07 19:43:52 +01:00
Daniele Varrazzo
80e105c74d Merge branch 'devel' 2013-04-07 17:43:35 +01:00
Daniele Varrazzo
b448f822f4 Bump to release 2.5 2013-04-07 17:26:57 +01:00
Daniele Varrazzo
b214d10fff Use NULL instead of an empty string as PyObject_CallMethod format 2013-04-07 17:26:57 +01:00
Daniele Varrazzo
884a7f7db6 A couple of typos fixed 2013-04-07 16:05:36 +01:00
Daniele Varrazzo
2b554937f2 Dropped __all__ from modules
They were only used to generate docs with Epydoc, now largely forgotten.

Imports in extras cleaned up to expose the API only.
2013-04-07 02:59:30 +01:00
Daniele Varrazzo
d5d6a1f4c7 Enable by default the range typecasters
Otherwise it would have been enabled importing psycopg2.extras,
which is a surprising behaviour.
2013-04-07 02:37:55 +01:00
Daniele Varrazzo
9e15f54fe8 Added cursor_factory connection attribute and connect() parameter 2013-04-07 02:30:12 +01:00
Daniele Varrazzo
0e06addc9f Testing boilerplate unified in a single base class
The class makes a connection always available, allows creating
new connection and closes everything on tear down.
2013-04-07 00:23:30 +01:00
Daniele Varrazzo
408c76fdb6 Fixed build on windows
Will fail with error: initializer element is not constant
2013-04-06 01:34:12 +01:00
Daniele Varrazzo
d36024dc1f Use the Python heap for conn->dsn 2013-04-06 00:42:25 +01:00
Daniele Varrazzo
c63d623f65 Merge branch 'drop-py24' into devel 2013-04-05 01:29:25 +01:00
Daniele Varrazzo
beea32ef03 Use the Py_RETURN_NONE macro 2013-04-05 01:25:05 +01:00
Daniele Varrazzo
67c8250081 Added tp_clear method for objects with GC support 2013-04-05 01:05:12 +01:00
Daniele Varrazzo
1a93279fe7 Dropped bogus return in void function 2013-04-05 01:03:05 +01:00
Daniele Varrazzo
e14440d96d Dropped GC support for several objects
Non-containers don't need GC. It was half-baked anyway
as the tp_clear was often not set. Dropped tp_traverse too
for these objects as unused.
2013-04-05 01:02:47 +01:00
Daniele Varrazzo
95ff64d739 Dropped encoding attribute from list adapter 2013-04-05 00:35:02 +01:00
Daniele Varrazzo
6bc4b23af5 Static-type psycopg_escape_string connection parameter 2013-04-05 00:07:36 +01:00
Daniele Varrazzo
736a78f3f6 Avoid encoding strdup in qstring adapter
Dropped encoding parameter in the constructor: it is used
nowhere and not documented. Use directly the connection
encoding if available, else the previous latin1 fallback.
2013-04-05 00:00:42 +01:00
Daniele Varrazzo
7a5a226b49 Set a memory exception in psycopg_escape_string
...otherwise all the callers should set it.
2013-04-04 22:48:53 +01:00
Daniele Varrazzo
7328aaf0fb Dropped GC support from Xid and Notify types
These types are immutable and have only atomic types attributes, so it's
impossible to build loops out of them.
2013-04-02 01:50:31 +01:00
Daniele Varrazzo
5aafe38fd7 Some improvements to connection/cursor GC
Provide a tp_clear, make sure that GC_UnTrack is called before clearing.
2013-03-21 12:55:17 +00:00
Daniele Varrazzo
3b8abf3fc4 Clean the C members of Error in tp_dealloc instead of tp_clear
tp_clear should only be used to break the reference cycles. tp_clear was
causing a segfault because it was called twice (by the gc and by _dealloc) so
self->codec was freed twice.

Amazingly the double free was only causing a segfault on Python 3.3 (released
in late 2012) talking to Postgres 8.1 (released in 2005) in async mode... no
other combination crashed. Thank you buildbot.
2013-03-21 12:34:53 +00:00
Daniele Varrazzo
d5316d7eb2 PyType_GenericAlloc is the default allocator: no need to specify 2013-03-20 23:53:20 +00:00
Daniele Varrazzo
eb280c1da4 Better use of Py_CLEAR and implicit zeroed-out structures 2013-03-20 23:53:20 +00:00
Daniele Varrazzo
546927d44a Use wrap to fix names of decorated test methods
Decorators not using wrap() prevent running the test from command line, e.g.
with:

    python tests/__init__.py test_module.TestSuite.test_method
2013-03-20 23:53:20 +00:00
Daniele Varrazzo
31265e3439 Fixed broken test decorator preventing 3 tests to run 2013-03-20 23:53:19 +00:00
Daniele Varrazzo
b6873ee1ab Dropped support for Python 2.4 2013-03-20 23:40:13 +00:00
Daniele Varrazzo
e65392e0d8 PyType_GenericAlloc is the default allocator: no need to specify 2013-03-20 22:59:50 +00:00
Daniele Varrazzo
8a59e75d62 Better use of Py_CLEAR and implicit zeroed-out structures 2013-03-20 22:59:50 +00:00
Daniele Varrazzo
09629a6dbc Use wrap to fix names of decorated test methods
Decorators not using wrap() prevent running the test from command line, e.g.
with:

    python tests/__init__.py test_module.TestSuite.test_method
2013-03-20 17:26:10 +00:00
Daniele Varrazzo
0c0e2a2455 Fixed broken test decorator preventing 3 tests to run 2013-03-20 17:13:33 +00:00
Daniele Varrazzo
3410fee8d1 Fixed leak of cancel key on connection.reset()
Moving the final free into the destructor is not necessary but looks
appropriate.
2013-03-20 16:43:16 +00:00
Daniele Varrazzo
9813bac4fe Added forgotten attributes to visit in error 2013-03-20 15:06:06 +00:00
Daniele Varrazzo
75811f5bb1 Note than Python 3.3 is supported in install docs 2013-03-20 13:08:01 +00:00
Daniele Varrazzo
87962728ee Fixed ticket number in NEWS file 2013-03-20 11:42:15 +00:00
Daniele Varrazzo
5dfba462da Dropped "customized" pg_free functions
The defaut is already to call PyObject_GC_Del.
2013-03-20 01:48:21 +00:00
Daniele Varrazzo
0830deb790 Dropped IFCLEARPGRES macro
PQclear already guards against NULL, so the extra check is redundant
2013-03-20 01:48:17 +00:00
Daniele Varrazzo
16021dae6d Use Py_CLEAR on self->query instead of if and decref 2013-03-20 01:48:11 +00:00
Daniele Varrazzo
a210859326 Notify and Xid objects and types renamed for consistency
They were the only objects starting with uppercase. My fault.
2013-03-20 01:48:05 +00:00
Daniele Varrazzo
73949cd1b8 Merge branch 'diagnostics' into devel 2013-03-20 01:47:14 +00:00
Daniele Varrazzo
b503db9ce6 psycopg2.Error object and type renamed more consistently 2013-03-20 00:03:58 +00:00
Daniele Varrazzo
114c62fac8 Added tests to verify the new Diagnostics properties
diag can be used on exceptions raised without cursor and is independent from
the cursor.

Docs updated to reflect the changes.
2013-03-20 00:03:58 +00:00
Daniele Varrazzo
7177f815a6 Store a PGresult in the Exception error
This makes the Diagnostics independent from further operations on the cursor
and allows using it with exceptions not generated by a cursor.
2013-03-19 23:42:54 +00:00
Daniele Varrazzo
394312939e Added a C structure to psycopg.Error
This will allow to store a PGresult in it.
2013-03-19 12:15:49 +00:00
Daniele Varrazzo
e86efa7e30 Added summary data types conversion table to the docs
It allows looking at a glance both basic and extended type casters,
with plenty of links to the detailed explanations.
2013-03-18 19:22:31 +00:00
Daniele Varrazzo
abb3027aa3 NEWS file reformatted to reST and included in the docs 2013-03-18 15:42:10 +00:00
Daniele Varrazzo
93928a7141 Document that errorcodes is updated to 9.2 2013-03-18 15:10:24 +00:00
Daniele Varrazzo
ae918c34b8 Copyright year bumped to 2013 in docs footer 2013-03-18 15:10:06 +00:00
Daniele Varrazzo
294e7ae080 Tests tweaked to run on all the supported versions 2013-03-18 10:06:07 +00:00
Daniele Varrazzo
97311967e8 Merge branch 'diagnostics' into devel 2013-03-18 02:21:09 +00:00
Daniele Varrazzo
fe6eb127fc Fixed bad interaction of setup.py with other dependencies
The problem is in Distribute dependencies on Python 3. Create a new command
class instead of changing inplace the one other projects may use.

Close ticket #153.
2013-03-18 02:18:50 +00:00
Daniele Varrazzo
49c3569919 Diagnostics added to the NEWS file 2013-03-18 02:11:45 +00:00
Daniele Varrazzo
1cf9825035 Diagnostics is more GC friendly 2013-03-18 02:11:45 +00:00
Daniele Varrazzo
678f0dc949 Added documentation about the Diagnostics object 2013-03-18 02:11:45 +00:00
Daniele Varrazzo
819a551d01 Decode Diagnostics result on Python 3 2013-03-18 00:38:28 +00:00
Daniele Varrazzo
70b756b8c7 Added test to verify Diagnostics works after copy errors 2013-03-18 00:31:25 +00:00
Daniele Varrazzo
660386929f Added test to verify Diagnostics reference disposal 2013-03-18 00:24:46 +00:00
Daniele Varrazzo
42b063b562 Added all supported properties to the Diagnostic object 2013-03-17 23:58:10 +00:00
Daniele Varrazzo
9e79112e25 Expose the Diagnostics object in the extensions module 2013-03-17 23:58:10 +00:00
Matthew Woodcraft
c75a3bbab4 Work-in-progress support for retrieving PG_DIAG result error fields. 2013-03-17 16:41:15 +00:00
Daniele Varrazzo
06bfa801f4 Fixed range adaptation on Python 3 2013-03-16 22:12:41 +00:00
Daniele Varrazzo
af18c29f0b Fixed exception handling in disconnection test
OperationalError is DatabaseError's subclass.
2013-03-16 21:43:11 +00:00
Daniele Varrazzo
c5de7b5ac6 Fixed Decimal range tests 2013-03-16 17:58:58 +00:00
Daniele Varrazzo
594a4d79ec Fixed handling of database disconnection in tests in green mode 2013-03-16 17:41:59 +00:00
Daniele Varrazzo
e1ff432f4c Merge branch 'dead-bytes' into devel 2013-03-16 16:25:17 +00:00
Daniele Varrazzo
4883ce7d91 Added ZPsycopgDA URL to the NEWS file 2013-03-16 16:23:02 +00:00
Daniele Varrazzo
66d6c68dcc Properly cleanup memory of broken connections
Fixed ticket #148.
2013-03-16 11:56:38 +00:00
Catalin Iacob
7abe1775d0 Fix tests for Postgres 9.3
Postgres 9.3 turns messages about implicit indexes and sequences from NOTICE
to DEBUG1 so the tests fail with a default 9.3 server configuration because
the client doesn't get any NOTICE. Fix it by also asking for DEBUG1 messages
from the server when testing against Postgres >= 9.3.
2013-03-16 00:54:11 +00:00
Idan Kamara
7f86529183 docs: grammar fix in extras.rst 2013-03-06 11:36:32 +02:00
Daniele Varrazzo
7a1d1791d3 Merge commit '2_4_6' 2013-01-21 11:18:27 +00:00
Daniele Varrazzo
e8db9954d1 Improvements to the connect() docs
- links updated to the current PG docs, which include the syntax as url
  and lists the parameters in a separate chapter
- more evident links to the PG docs
- mutually exclusive use of dsn and **kwargs specified

See ticket #143
2013-01-09 12:56:06 +00:00
Daniele Varrazzo
49af4fe539 Fixed interactive sessions docs examples 2013-01-09 03:10:32 +00:00
Daniele Varrazzo
16d96fd43c Merge branch 'py33' into devel 2012-12-22 00:58:17 +01:00
Daniele Varrazzo
cedd15cb49 Python 3.3 is now supported 2012-12-22 00:56:48 +01:00
Daniele Varrazzo
a04379210b Doubt about 'c' buffer solved by Stefan Krah 2012-12-22 00:51:47 +01:00
Daniele Varrazzo
4e65ca1d8d Version bumped to 2.4.6 2012-12-11 01:40:02 +00:00
Daniele Varrazzo
67445dfbea Fixed pickling of DictRow objects too 2012-12-11 01:40:02 +00:00
Daniele Varrazzo
5bee4d3379 Fixed pickling of RealDictRow objects 2012-12-11 01:40:02 +00:00
Daniele Varrazzo
6df6e6adfe Fixed pickling of DictRow objects too 2012-12-11 01:10:45 +00:00
Daniele Varrazzo
99bedd1bb2 Fixed pickling of RealDictRow objects 2012-12-10 23:54:25 +00:00
Daniele Varrazzo
e6fbf47c46 Merge branch 'contextmanager' into devel 2012-12-04 00:38:01 +00:00
Daniele Varrazzo
ec34b9bed6 Mention context managers in NEWS file 2012-12-04 00:37:49 +00:00
Daniele Varrazzo
170636d46d Merge branch 'zope-fixes' into devel 2012-12-04 00:34:48 +00:00
Daniele Varrazzo
bb72f121fb Fixed connections re-init across ZSQL methods
Fixes issue #142, probably #123 and #125 too.
2012-12-04 00:31:22 +00:00
Daniele Varrazzo
27cd6c4880 Added specific pool implementation for ZPsycopgDA
The implementation is based on psycopg 2.4, which should be less broken
(zope-wise) of the current one.

Instantiating psycopg2.pool.PersistentConnectionPool now raises a warning.

This should fix ticket #123, #125. The issue of the reset on
set_client_encoding() is still present but that's always been there and I'm no
good at fixing it.
2012-12-04 00:30:58 +00:00
Daniele Varrazzo
57e1631181 Use set_session instead of set_isolation_level where available
Avoid spurious queries as reported in psycopg2 ticket #125.
2012-12-04 00:30:52 +00:00
Daniele Varrazzo
f1a8c075ab Show all the available isolation levels in ZPsycopgDA menu 2012-12-04 00:30:48 +00:00
Daniele Varrazzo
6e57f32f8d Added 2.4.6 to the allowed versions for ZPsycopgDA
Dropped beta versions and the versions with the messed up isolation level
constants.
2012-12-04 00:30:43 +00:00
Daniele Varrazzo
a64fd31fd1 Fixed connections re-init across ZSQL methods
Fixes issue #142, probably #123 and #125 too.
2012-12-03 16:49:55 +00:00
Daniele Varrazzo
5053a7c2b6 Fixed version number in NEWS file 2012-12-03 14:22:04 +00:00
Daniele Varrazzo
0653861bc4 Fixed empty strings handling in composite caster
Closes ticket #141.
2012-12-03 14:20:08 +00:00
Daniele Varrazzo
9a031db8b9 Fixed empty strings handling in composite caster
Closes ticket #141.
2012-12-03 14:19:09 +00:00
Daniele Varrazzo
12645db754 Make sure to call subclasses methods on context exit 2012-12-03 03:37:47 +00:00
Daniele Varrazzo
c2f284cd3b Added documentation for the with statement 2012-12-03 03:18:51 +00:00
Daniele Varrazzo
8e08aeb690 Dropped Zope support 2012-12-03 02:53:20 +00:00
Daniele Varrazzo
cc605032f5 Added support for with statement for connection and cursor
The implementation should be conform to the DBAPI, although the "with"
extension has not been released yet.
2012-12-03 02:50:24 +00:00
Daniele Varrazzo
9f06df1820 Fixed signature for METH_NOARGS functions 2012-12-03 02:49:06 +00:00
Daniele Varrazzo
dcbbaa76d6 Dropped unmaintained changelog
Welcome to the worderful world of SCM.
2012-12-03 00:39:47 +00:00
Daniele Varrazzo
2a9e5c7203 Dropped configuration of unused logger inside the pool module 2012-12-03 00:39:47 +00:00
Daniele Varrazzo
d74aea209b Dropped debian package metadata
This is being maintained ouside psycopg2 source tree:
http://anonscm.debian.org/viewvc/python-modules/packages/psycopg2/trunk/
and the copy in our tree is out of date.
2012-12-03 00:39:47 +00:00
Daniele Varrazzo
02ffb7423a Splitting the release of new features in version 2.5 2012-12-03 00:39:19 +00:00
Daniele Varrazzo
bf45539585 Added specific pool implementation for ZPsycopgDA
The implementation is based on psycopg 2.4, which should be less broken
(zope-wise) of the current one.

Instantiating psycopg2.pool.PersistentConnectionPool now raises a warning.

This should fix ticket #123, #125. The issue of the reset on
set_client_encoding() is still present but that's always been there and I'm no
good at fixing it.
2012-12-03 00:37:02 +00:00
Daniele Varrazzo
fb24777200 Use set_session instead of set_isolation_level where available
Avoid spurious queries as reported in psycopg2 ticket #125.
2012-12-02 23:51:26 +00:00
Daniele Varrazzo
f9bcbc213e Show all the available isolation levels in ZPsycopgDA menu 2012-12-02 23:27:21 +00:00
Daniele Varrazzo
6fb0b001b2 Added 2.4.6 to the allowed versions for ZPsycopgDA
Dropped beta versions and the versions with the messed up isolation level
constants.
2012-12-02 22:46:55 +00:00
Daniele Varrazzo
f6054c28d8 Release the GIL around PQgetResult calls after COPY
It should fix ticket #140.
2012-11-24 22:51:23 +00:00
Daniele Varrazzo
362c2ae597 Release the GIL around PQgetResult calls after COPY
It should fix ticket #140.
2012-11-24 22:49:36 +00:00
Daniele Varrazzo
896ad7c827 Fixed a couple of terms in the docs
After Pierre-Louis Bonicoli's suggestions in ticket #138.
2012-11-12 01:32:38 +00:00
Daniele Varrazzo
10476200fd Added note about the adapted attribute in the module-level wrappers
Specifying it otherwise people expects the wrappers to have full datetime
semantics: see ticket #136.
2012-10-27 22:24:48 +01:00
Daniele Varrazzo
0837fc958e Merge branch 'fix-135' into maint_2_4 2012-10-21 22:02:39 +01:00
Daniele Varrazzo
e109024d39 Merge branch 'fix-135' into devel 2012-10-21 21:49:30 +01:00
Daniele Varrazzo
5e6eabd9f8 Fixed pickling of FixedOffsetTimezone objects
I have also verified that the fixed class can unpickle instance pickled with
the buggy one and viceversa.

Fixes ticket #135.
2012-10-21 21:47:32 +01:00
Daniele Varrazzo
1feb179fba Fixed pickling of FixedOffsetTimezone objects
I have also verified that the fixed class can unpickle instance pickled with
the buggy one and viceversa.

Fixes ticket #135.
2012-10-21 21:47:32 +01:00
Daniele Varrazzo
790843a48a More idiomatic way to call FixedOffsetTimezone.__new__ superclass 2012-10-21 21:16:52 +01:00
Daniele Varrazzo
a33c0670fd More idiomatic way to call FixedOffsetTimezone.__new__ superclass 2012-10-21 21:16:52 +01:00
Daniele Varrazzo
e4a07c3a30 Dropped redundant call to FixedOffsetTimezone.__init__ 2012-10-21 21:12:02 +01:00
Daniele Varrazzo
f5f2e2c092 Dropped redundant call to FixedOffsetTimezone.__init__ 2012-10-21 21:12:02 +01:00
Daniele Varrazzo
6b8861d2d5 Clarification in copy_expert docs
Closes ticket #134.
2012-10-15 00:47:22 +01:00
Daniele Varrazzo
71393b9ae9 Discard any result produced by cursor.executemany() 2012-10-11 22:29:03 +01:00
Daniele Varrazzo
4ddad45feb Discard any result produced by cursor.executemany() 2012-10-11 22:27:35 +01:00
Daniele Varrazzo
5fbf3ef147 Merge branch 'fix-113' into devel 2012-10-11 22:26:51 +01:00
Daniele Varrazzo
20d3344972 Merge branch 'fix-113' into maint_2_4 2012-10-09 02:02:28 +01:00
Daniele Varrazzo
58d048198f Close the connection on error in callback
Unfortunately PQcancel blocks, so it's not better than PQgetResult.
It has been suggested to use PQreset in non-blocking way but this would give
the Python program the burden of handling a connection done but not configured
in an unexpected place.
2012-10-09 02:01:29 +01:00
Daniele Varrazzo
7632e1ae46 Get the result from the connection after the green panic
Otherwise the connection won't be usable in case we manage
to put it back on track (libpq reports "another command is
already in progress")
2012-10-09 02:01:29 +01:00
Daniele Varrazzo
6b6aded90b Added compatibility PyErr_WarnEx macro for Python 2.4 2012-10-09 02:01:29 +01:00
Daniele Varrazzo
fa032f09fb Attempt to fix issue #113.
If the network is down, trying to read blocking will hang the process hard
(ctrl-c not working). Send a cancel signal instead (as suggested in
http://archives.postgresql.org/pgsql-hackers/2012-07/msg00903.php) and go
back into a green polling: this should allow a further error (e.g. another
ctrl-c) to break the loop. In this case we cannot assume anything about
the state of the connection, so we close it.
2012-10-09 02:01:29 +01:00
Daniele Varrazzo
6d1b3b21e6 Added function conn_close_locked() 2012-10-09 02:01:29 +01:00
Daniele Varrazzo
ee763e0f47 Copyright bumped to 2012 in docs pages 2012-10-07 13:14:31 +01:00
Daniele Varrazzo
a666432329 Docs front page adjustments 2012-10-07 02:07:47 +01:00
Daniele Varrazzo
82dc32cebd Added install section to the manual 2012-10-07 02:04:39 +01:00
Daniele Varrazzo
b61a2a34c4 Close the connection on error in callback
Unfortunately PQcancel blocks, so it's not better than PQgetResult.
It has been suggested to use PQreset in non-blocking way but this would give
the Python program the burden of handling a connection done but not configured
in an unexpected place.
2012-10-06 11:58:52 +01:00
Daniele Varrazzo
2611d62283 Get the result from the connection after the green panic
Otherwise the connection won't be usable in case we manage
to put it back on track (libpq reports "another command is
already in progress")
2012-10-06 01:45:24 +01:00
Daniele Varrazzo
f4f67ad985 Dropped compiler warning on Py 2.4 2012-10-06 01:22:05 +01:00
Daniele Varrazzo
644b18a2c9 Dropped compiler warning on Py 2.4 2012-10-06 01:22:05 +01:00
Daniele Varrazzo
76815f1e92 Added compatibility PyErr_WarnEx macro for Python 2.4 2012-10-06 01:16:57 +01:00
Daniele Varrazzo
53b1c70f3a Attempt to fix issue #113.
If the network is down, trying to read blocking will hang the process hard
(ctrl-c not working). Send a cancel signal instead (as suggested in
http://archives.postgresql.org/pgsql-hackers/2012-07/msg00903.php) and go
back into a green polling: this should allow a further error (e.g. another
ctrl-c) to break the loop. In this case we cannot assume anything about
the state of the connection, so we close it.
2012-10-06 01:10:41 +01:00
Daniele Varrazzo
2137db89d4 Added function conn_close_locked() 2012-10-06 01:03:12 +01:00
Daniele Varrazzo
387b7b6b36 Using super() in the connection/cursor subclasses
This opens to collaborative subclassing (e.g. you may want to have a
logging namedtuple cursor...)
2012-09-28 02:51:58 +01:00
Daniele Varrazzo
9f9da182f1 Using super() in the connection/cursor subclasses
This opens to collaborative subclassing (e.g. you may want to have a
logging namedtuple cursor...)
2012-09-28 02:51:58 +01:00
Daniele Varrazzo
4244d5953a Merge branch 'range-type' into devel 2012-09-27 00:48:05 +01:00
Daniele Varrazzo
dda24f082f Merge branch 'json' into devel 2012-09-27 00:41:04 +01:00
Daniele Varrazzo
465b5cf280 Mention JSON adaptation in the NEWS file 2012-09-27 00:40:35 +01:00
Daniele Varrazzo
33043cd038 Merge branch 'composite-custom' into devel 2012-09-27 00:38:00 +01:00
Daniele Varrazzo
bc1d2f5d3a Merge remote-tracking branch 'github/connect-keywords' into devel 2012-09-26 13:15:33 +01:00
Daniele Varrazzo
74e6efd717 Raise TypeError instead of InterfaceError on bad params on connect()
TypeError is the standard Python error raised in this case:

    $ python -c "(lambda a: None)(b=10)"
    TypeError: <lambda>() got an unexpected keyword argument 'b'

We only used to raise InterfaceError when connect was used without
any parameter at all, so it's hard to think a program depending on
that design. Furthermore the function has always raised (and still
does) OperationalError too, if the bad argument is detected by the
libpq, and that cannot be changed because we can't tell the
difference from a normal connection error.
2012-09-26 11:55:21 +01:00
Daniele Varrazzo
20d3d0f66d Raise TypeError instead of InterfaceError on bad params on connect()
TypeError is the standard Python error raised in this case:

    $ python -c "(lambda a: None)(b=10)"
    TypeError: <lambda>() got an unexpected keyword argument 'b'

We only used to raise InterfaceError when connect was used without
any parameter at all, so it's hard to think a program depending on
that design. Furthermore the function has always raised (and still
does) OperationalError too, if the bad argument is detected by the
libpq, and that cannot be changed because we can't tell the
difference from a normal connection error.
2012-09-26 11:55:21 +01:00
Daniele Varrazzo
bc68b2ff1e Improved error message on connect when kwargs are passed together with dns 2012-09-26 11:47:06 +01:00
Daniele Varrazzo
cf3c6f86ff Improved error message on connect when kwargs are passed together with dns 2012-09-26 11:47:06 +01:00
Daniele Varrazzo
32fae728b3 Dropped quirks in connection arguments handling
Now connect() raises an exception instead of swallowing keyword arguments
when a connection string is specified as well

Closes ticket #131.
2012-09-25 23:46:46 +01:00
Daniele Varrazzo
cd316a94f1 Dropped quirks in connection arguments handling
Now connect() raises an exception instead of swallowing keyword arguments
when a connection string is specified as well

Closes ticket #131.
2012-09-25 23:46:46 +01:00
Daniele Varrazzo
b894539007 Fixed json doc error 2012-09-25 00:12:57 +01:00
Daniele Varrazzo
b8b669611e More helpful error messasge on Range order attempts 2012-09-25 00:07:08 +01:00
Daniele Varrazzo
7b1973354f Fixed SQL_IN when getquoted() is called without prepare() 2012-09-24 16:55:01 +01:00
Daniele Varrazzo
a733416241 Fixed SQL_IN when getquoted() is called without prepare() 2012-09-24 16:55:01 +01:00
Daniele Varrazzo
f70e6a1519 Grammar correction for RangeCaster.array_typecaster 2012-09-24 12:13:46 +01:00
Daniele Varrazzo
71e2f190c2 Json documentation improved 2012-09-24 11:51:35 +01:00
Daniele Varrazzo
a3418052e9 Don't create/register a json array typecaster if no oid provided 2012-09-24 11:23:09 +01:00
Daniele Varrazzo
c756d580f2 Added documentation for range types and adaptation 2012-09-24 00:49:44 +01:00
Daniele Varrazzo
b1953640d2 Don't need to implement __new__ to make an immutable class 2012-09-24 00:49:02 +01:00
Daniele Varrazzo
a858987844 Fixed search of types into schemas.
We don't need to look for stuff implicitly into pg_catalog as all
the builtin ranges are already registered. So just search into
'public' if the schema is not specified.
2012-09-24 00:49:02 +01:00
Daniele Varrazzo
a1a2772a79 Added test for range not found 2012-09-24 00:48:56 +01:00
Daniele Varrazzo
a701e36d16 Added containment tests for unbounded intervals 2012-09-23 22:59:49 +01:00
Daniele Varrazzo
841ddaba87 Range objects cannot be ordered 2012-09-23 22:54:50 +01:00
Daniele Varrazzo
25ef540aa3 Range objects are nonzero when not empty 2012-09-23 22:43:23 +01:00
Daniele Varrazzo
a96a4349ed Range objects are immutable and hashable 2012-09-23 22:40:13 +01:00
Daniele Varrazzo
e002ea5937 Dropped Range._empty attribute
We can do with just _bounds: it will make eq and hash easier to
implement in a consistent way
2012-09-23 22:10:33 +01:00
Daniele Varrazzo
d2cee6f9ad Added in operator for ranges 2012-09-23 22:01:39 +01:00
Daniele Varrazzo
94c6353d55 NumberRange renamed to NumericRange
I was avoiding Numeric to avoid conflicting with the 'numeric'
Postgres type, which is an alias for 'decimal'. But now that there
is a single numeric range I can use the preferred name
2012-09-23 21:11:06 +01:00
Daniele Varrazzo
45cbcc0713 Dropped Range classes for specific numeric types 2012-09-23 21:08:18 +01:00
Daniele Varrazzo
5e7c1d0b51 Added first implementation of Range type, adapter, typecaster 2012-09-23 21:03:36 +01:00
Daniele Varrazzo
9949e04c70 Added schema attribute to CompositeCaster 2012-09-22 15:10:40 +01:00
Daniele Varrazzo
59151886a0 Info about hstore versions history moved from code to docs 2012-09-22 02:10:58 +01:00
Daniele Varrazzo
d183657c11 Info about hstore versions history moved from code to docs 2012-09-22 02:10:58 +01:00
Daniele Varrazzo
26cfdc1234 Info about versions history moved from code to docs 2012-09-22 02:08:21 +01:00
Daniele Varrazzo
fa9393b587 Added documentation about CompositeCaster subclassing 2012-09-22 02:01:04 +01:00
Daniele Varrazzo
1b2c2c34b6 Make CompositeCaster easier to subclass 2012-09-22 01:46:53 +01:00
Daniele Varrazzo
6d9a25e63a Deal with sys.platform = "linux"
Changed in Python 3.3.
2012-09-21 02:28:52 +01:00
Daniele Varrazzo
7de8611607 errorcodes map updated to PostgreSQL 9.2 2012-09-21 01:59:02 +01:00
Daniele Varrazzo
469b6f8aff Return memoryview object of type "c" instead of "B" from bytea
In Python 3.3 items are returned as int instead of chars.
I'm not sure the way I did it is correct: worth asking some
hardcore Python dev.

Fixed tests after the stricter memview comparison rules in Py 3.3.
2012-09-21 00:54:37 +01:00
Daniele Varrazzo
526e270934 Use namedtuple._make in NamedTupleCursor and CompositeCaster
Makes things more natural as _make has the same signature of the tuple (see
_ctor in CompositeCaster) and is probably more efficient with less
intermediate sequences to build.
2012-09-20 16:27:50 +01:00
Daniele Varrazzo
5645e7adef Pasto fixed 2012-09-20 03:44:50 +01:00
Daniele Varrazzo
abe2df5f57 Merge branch 'fix-array-parsing' into devel 2012-09-20 03:26:07 +01:00
Daniele Varrazzo
62a54f64f7 Fixed infinite loop when parsing '{' as array 2012-09-20 03:24:47 +01:00
Daniele Varrazzo
0e644f6d95 Fixed return value after malformed arrays 2012-09-20 03:24:26 +01:00
Daniele Varrazzo
c7bee92160 Fixed infinite loop when parsing '{' as array 2012-09-20 03:19:24 +01:00
Daniele Varrazzo
9b2ad7abb5 Fixed json typecaster with NULL input 2012-09-20 00:39:34 +01:00
Daniele Varrazzo
7386b8327c Dropped keywords passthrough in Json adapter
Pass a dumps function instead. Allow customizing by either arg passing or
subclassing.

The basic Json class now raises ImportError on getquoted() if json is not
available, thus allowing using a customized Json subclass even when the json
module is not available.
2012-09-19 16:32:57 +01:00
Daniele Varrazzo
d963b478e2 Added register_default_json() function
Register a typecaster for PostgreSQL 9.2 json.
2012-09-19 15:49:00 +01:00
Daniele Varrazzo
26d71b4cba First parameter of register_json defaults to None 2012-09-19 15:31:28 +01:00
Daniele Varrazzo
024f0dbada Added json typecaster 2012-09-19 04:26:35 +01:00
Daniele Varrazzo
b8e7f02256 Added Json adapter 2012-09-19 04:12:20 +01:00
Daniele Varrazzo
64e3e1199e Fixed note on rollback on close in the doc
It's not like we call "rollback()": we close the connection and the
backend rolls back on its own. It may have differences, e.g. conn poolers.
2012-09-18 12:54:41 +01:00
Daniele Varrazzo
9ae4bbd195 Fixed smell of pizza in the docs 2012-09-18 12:54:41 +01:00
Daniele Varrazzo
72e9cf7b6d Fixed return value after malformed arrays 2012-09-10 04:20:39 +01:00
Daniele Varrazzo
5fedaa5474 Fixed tests to run with PG 8.3 2012-09-04 21:23:19 +01:00
Federico Di Gregorio
40a512fe46 Fixed always true comparaison 2012-08-17 14:52:59 +02:00
Daniele Varrazzo
fc5cc1df01 Fixed note on rollback on close in the doc
It's not like we call "rollback()": we close the connection and the
backend rolls back on its own. It may have differences, e.g. conn poolers.
2012-08-15 12:28:13 +01:00
Daniele Varrazzo
7cb754fbc9 Fixed smell of pizza in the docs 2012-08-15 12:25:35 +01:00
Daniele Varrazzo
bc400f6961 Fixed tests to run with PG 8.3 2012-09-04 21:23:19 +01:00
Federico Di Gregorio
64674787fd Fixed always true comparaison 2012-08-17 14:52:59 +02:00
Daniele Varrazzo
07e2c6a62f Merge branch 'scrollable' into devel 2012-08-15 11:27:43 +01:00
Daniele Varrazzo
99b7683338 Added documentation for scrollable cursors 2012-08-15 11:26:45 +01:00
Daniele Varrazzo
a79a5292e7 Added support with cursors without scroll clause
Using nothing is different from NO SCROLL, see DECLARE notes
in PG docs.
2012-08-15 09:44:44 +01:00
Daniele Varrazzo
d074b096be Added test for scrollable cursor 2012-08-15 01:11:26 +01:00
Daniele Varrazzo
fa4994e471 Added scrollable cursor implementation
Patch provided by Jon Nelson (ticket #108).
2012-08-15 00:30:54 +01:00
Daniele Varrazzo
cc951b5fbe Fixed tpc_recover() with RealDictStuff
Same problem and correction of ticket #114.
2012-08-14 23:29:19 +01:00
Daniele Varrazzo
91c2ff9296 Fixed tpc_recover() with RealDictStuff
Same problem and correction of ticket #114.
2012-08-14 23:29:19 +01:00
Daniele Varrazzo
fd4153d632 Fixed register_hstore and register_composite with non-dbapi objects
Closed ticket #114.
2012-08-14 23:26:17 +01:00
Daniele Varrazzo
21d323d2c8 Fixed register_hstore and register_composite with non-dbapi objects
Closed ticket #114.
2012-08-14 23:26:17 +01:00
Daniele Varrazzo
e369fb5f0d Fixed incorrect and outdated connection.commit() doc 2012-07-27 17:44:28 +01:00
Daniele Varrazzo
8666693512 Fixed incorrect and outdated connection.commit() doc 2012-07-27 17:44:28 +01:00
Brian Sutherland
2371166383 grammar 2012-07-27 12:48:28 +03:00
Daniele Varrazzo
ee7890d700 Fixed typo in docs
Ticket #115 closed.
2012-07-08 22:52:24 +01:00
Daniele Varrazzo
3559ea0d10 Fixed typo in docs
Ticket #115 closed.
2012-07-08 22:52:24 +01:00
Daniele Varrazzo
f9a13eb563 connection.reset() implemented using DISCARD ALL 2012-06-25 16:37:11 +01:00
Federico Di Gregorio
7a33ebd580 Merge remote-tracking branch 'msabramo/travis' into devel
Travis CI (http://travis-ci.org/) is a hosted CI system
"in the cloud".
2012-06-18 12:24:21 +02:00
Federico Di Gregorio
79165dab78 Merge remote-tracking branch 'msabramo/tox' into devel
Tox (http://tox.testrun.org/) is a nice tool for
testing a package against multiple Python distributions.
2012-06-18 12:23:44 +02:00
Marc Abramowitz
6bf2b1b465 Add .travis.yml for Travis CI (http://travis-ci.org/) 2012-06-15 08:07:19 -07:00
Marc Abramowitz
3c510cf768 Add .tox to .gitignore 2012-06-15 02:57:11 -07:00
Marc Abramowitz
9e1e69003b Add tox.ini for tox (http://tox.testrun.org/) 2012-06-15 02:56:44 -07:00
Daniele Varrazzo
ea203f0587 Added %% use to the docs 2012-05-29 23:53:02 +01:00
Daniele Varrazzo
08c8b62e1b Added %% use to the docs 2012-05-29 23:53:02 +01:00
Daniele Varrazzo
c7d1271ab4 Fixed cursor name as unicode string on Python 3 2012-05-27 08:58:55 +01:00
Daniele Varrazzo
e8fb84306d Fixed cursor name as unicode string on Python 3 2012-05-27 08:58:55 +01:00
Daniele Varrazzo
cb6baff8e0 Dropped build dirs entries from setup.cfg
They were not used anymore after pg_config had become mandatory to build the
module.  Thanks to Steven Winfield for the report (ticket #109).
2012-05-23 11:02:05 +01:00
Daniele Varrazzo
874a74fe94 Dropped GIL release around function calling PyMem_Malloc
Closes ticket #110.
2012-05-22 17:22:57 +01:00
Daniele Varrazzo
7982a6ac0b Dropped GIL release around function calling PyMem_Malloc
Closes ticket #110.
2012-05-22 17:22:57 +01:00
Daniele Varrazzo
ba1fe6fff6 Fixed superclass methods call.
Methods execute() and callproc() in DictCursor and RealDictCursor should
call DictCursorBase methods, not _cursor's ones.

Reported by Alexey Luchko on the ML.
2012-05-08 15:48:07 +01:00
Daniele Varrazzo
55828c2ea3 Fixed superclass methods call.
Methods execute() and callproc() in DictCursor and RealDictCursor should
call DictCursorBase methods, not _cursor's ones.

Reported by Alexey Luchko on the ML.
2012-05-08 15:48:07 +01:00
Daniele Varrazzo
291b4ce81f Fixed text docs build on Python 3
Thanks to Arfrever for the patch (ticket #107).
2012-04-11 18:18:40 +01:00
Daniele Varrazzo
667387e746 Fixed text docs build on Python 3
Thanks to Arfrever for the patch (ticket #107).
2012-04-11 18:18:40 +01:00
Daniele Varrazzo
4436fce4c6 Merge branch 'cursor-args-fix' into devel 2012-04-11 18:12:27 +01:00
Daniele Varrazzo
47336c7428 Merge branch 'cursor-args-fix' into MAINT_2_4 2012-04-11 18:12:27 +01:00
Daniele Varrazzo
241403e7ba Bump to next dev release 2012-04-11 18:11:59 +01:00
Daniele Varrazzo
210eeb875d Bump to next dev release 2012-04-11 18:11:59 +01:00
Daniele Varrazzo
73df259f7b Added news entry about cursor() cleanup 2012-04-11 18:11:04 +01:00
Daniele Varrazzo
365a1b20a7 Added tests to verify cursor() arguments propagation 2012-04-11 18:00:18 +01:00
Daniele Varrazzo
c86ca7687f Fixed cursor() arguments propagation to other connection classes 2012-04-11 17:59:16 +01:00
Corry Haines
095cce5605 Allow user to override connection factory cursors
Prior to this change, using a extras.connection_factory would not allow
any other cursor to be used on that connection. It was set in stone.

This change allows all cursor options to pass through and override the
connection factory behaviors. This allows a connection_factory to be
dropped into existing code with no disruption.

This change also standardizes the extras.connection_factories to have
the same behavior and all pass through *args and **kwargs.
2012-04-11 17:36:04 +01:00
Daniele Varrazzo
27421f1e41 Name can be passed as None to cursor()
Makes invocation from subclasses and generic code easier.

Code simplified by using default values for keyword arguments
and avoiding needless conversions back and forth between Python and C
strings. Also added connection type check to cursor's init.
2012-04-11 17:32:10 +01:00
Daniele Varrazzo
c63891af8d Fixed bad error return code from cursor's init 2012-04-11 17:26:11 +01:00
Federico Di Gregorio
d7c8c1c49a Merge branch 'devel' 2012-03-28 23:09:15 +02:00
Federico Di Gregorio
037b704e9a Bumping up versions to prepare 2.4.5 2012-03-28 23:08:59 +02:00
Daniele Varrazzo
67064f8e03 All the FAQ have they own id that can be used in URLs to refer to 2012-03-09 16:55:02 +00:00
Daniele Varrazzo
5473d50a09 Added more information about the case of the missing lo_truncate
After some ML message and ticket #104.
2012-03-09 16:55:02 +00:00
Federico Di Gregorio
550130b19e Merge remote-tracking branch 'piro/devel' into devel
Conflicts:
	psycopg/lobject_int.c
2012-03-08 12:28:52 +01:00
Daniele Varrazzo
b8c75d9de0 Merge branch 'gcc-python-plugin' into devel 2012-03-05 02:48:11 +00:00
Daniele Varrazzo
37aa62ca52 Merge branch 'close-idempotent' into devel 2012-03-05 02:47:52 +00:00
Daniele Varrazzo
2c309dfdb4 Mention the static analysis cleanup in the news 2012-03-05 02:38:21 +00:00
Daniele Varrazzo
8707d8c399 Fixed iterator refcount in case of memory error during COPY 2012-03-05 02:09:20 +00:00
Daniele Varrazzo
735d50c782 Check if the object wrapped in binary is not None before trying the other types
Otherwise it seems we clobber some result with NULL.
2012-03-05 02:08:45 +00:00
Daniele Varrazzo
a9dc1b83ad Methods callbacks signatures match the flags they are exported with 2012-03-05 01:26:28 +00:00
Daniele Varrazzo
531084d561 Stricter types usage in several PyArg_ParseTuple calls 2012-03-04 18:01:08 +00:00
Daniele Varrazzo
0e832b97ea Proper type check in prepare() methods for list, binary, qstring 2012-03-04 17:59:51 +00:00
Daniele Varrazzo
84f2a370f6 close() methods don't raise errors if called on closed objects 2012-03-04 05:10:07 +00:00
Daniele Varrazzo
2cbedbee45 Dropped test about close() on closed connection raising an exception
This seems unnecessary and has caused problems to a few. The DB-SIG seems
agreeing on the change:
http://mail.python.org/pipermail/db-sig/2011-October/005811.html
2012-03-04 05:10:06 +00:00
Daniele Varrazzo
76cc838a93 Expressions rewritten in a more normal way
(double)'0'? :)
2012-03-04 04:47:21 +00:00
Daniele Varrazzo
5bbfd38dfb Check for errors in float adaptation 2012-03-04 04:43:14 +00:00
Daniele Varrazzo
6cece00958 Check failed list creation in array adaptation 2012-03-04 04:42:44 +00:00
Daniele Varrazzo
be35df3818 Fixed typecasters refcount 2012-03-04 04:41:36 +00:00
Daniele Varrazzo
dc4c3d3143 Guard from failed keys creation during adaptation 2012-03-04 04:40:44 +00:00
Daniele Varrazzo
18085201c8 Guard from NULL dereference if Xid allocation fails 2012-03-04 04:39:41 +00:00
Daniele Varrazzo
31812c01e6 Further modeling of exception raising 2012-03-04 04:38:44 +00:00
Daniele Varrazzo
d93732558d Raise an exception in case of failed localtime_r call 2012-03-04 04:17:03 +00:00
Daniele Varrazzo
4d15b973b0 Attempt to enforce signature for the "O&" converter functions
It seems causing a traceback in the static checker. Enforcing it simplifies
the code, but doesn't help the checker.
2012-03-01 02:53:29 +00:00
Daniele Varrazzo
e1266d52cd More functions annotated for static analysis
Also more return values checked for values < 0 for errors, instead of
checking == 0 and leaving the positive side unchecked
2012-03-01 02:53:28 +00:00
Daniele Varrazzo
5bfb6cdefe Use more compact macros to annotate functions for the static checker 2012-03-01 02:53:28 +00:00
Daniele Varrazzo
f2e4a8ed78 Functions setting exception return a negative value on error
This works around another shortcoming of the static checker; also to be
discussed with the author.
2012-03-01 02:53:28 +00:00
Daniele Varrazzo
9432787279 Work around a false positive returned by the static checker
To be submitted to the author.
2012-03-01 02:53:28 +00:00
Daniele Varrazzo
a167822e26 Use the newly provided attributes to validate exceptions raising
Be more consistent in using 0 for success, <0 for failure, and to check
for values < 0 instead of specific -1.
2012-03-01 02:53:28 +00:00
Marti Raudsepp
b97599166e Update all links to PostgreSQL docs to the current version.
I also checked all links and anchors to make sure they're still valid.
2012-02-28 18:28:07 +02:00
Daniele Varrazzo
67712e4226 Fixed possible NULL dereferencing in fetchmany()/fetchall() 2012-02-24 22:26:02 +00:00
Daniele Varrazzo
6d76e81166 Fixed possible NULL dereferencing in callproc() 2012-02-24 22:26:02 +00:00
Daniele Varrazzo
94a53b48df Building rows simplified
Dropped repeated checks for tuple_factory.
Internal functions refactored a bit.
2012-02-24 22:26:02 +00:00
Daniele Varrazzo
efee049338 Added error check in _mogrify for failed tuple creation 2012-02-24 22:26:02 +00:00
Daniele Varrazzo
0ee641361b Flag a few other functions returning borrowed refs 2012-02-24 22:26:01 +00:00
Daniele Varrazzo
4ecfd48671 Fixed possible NULL dereferencing in notice process 2012-02-24 22:25:56 +00:00
Daniele Varrazzo
a6df55f4e3 Flag the psycopg_ensure_*() functions as stealing a ref 2012-02-24 10:41:02 +00:00
Daniele Varrazzo
5f3f35a2c2 Mark getnextarg function as returning a borrowed reference 2012-02-24 04:25:08 +00:00
Daniele Varrazzo
fc78fb09c0 Dropped unused pq_resolve_critical() return value 2012-02-24 04:00:12 +00:00
Daniele Varrazzo
4eea8bc912 Dropped redundant check on the status before rollback
The check is better done inside the critical section.
2012-02-24 03:28:20 +00:00
Daniele Varrazzo
5fcbe7bd0f Check/set connection status at commit inside the critical section
Failing to do so was causing the issue reported in ticket #103. The issue
as reported was fixed when SET ISOLATION LEVEL was dropped, but the real
problem wasn't fixed.
2012-02-24 03:28:20 +00:00
Daniele Varrazzo
b2c61eaa18 Merge branch 'types-arrays' into devel 2012-02-24 00:35:21 +00:00
Daniele Varrazzo
a165f86127 Added docs about how to create a generic array typecaster 2012-02-24 00:33:28 +00:00
Daniele Varrazzo
0c337a2029 Added support for inet array 2012-02-23 23:56:55 +00:00
Daniele Varrazzo
36b6c80ed1 register_uuid takes more iterables types as oids argument
Also added docs for the function parameters.
2012-02-23 23:51:28 +00:00
Daniele Varrazzo
9ffa1f4b59 Fixed inet test that wasn't testing anything 2012-02-23 23:35:05 +00:00
Daniele Varrazzo
98d6d96ee3 Fixed exception testing on Python 3
...and so caught exceptions are local to the except suite in Py3.
(Lo sapevate? Sapevatelo!)
2012-02-23 23:15:42 +00:00
Daniele Varrazzo
e57f3284eb Merge branch 'cursors-rownumber' into devel 2012-02-23 23:05:40 +00:00
Daniele Varrazzo
1d7e6afcf0 Ticket #100 closed
Note that rownumber is still broken for named cursors: it is reset to zero
when each itersize block is fetched.
2012-02-23 23:04:54 +00:00
Daniele Varrazzo
b8597dc1d3 Fixed NamedTupleCursor rownumber during iteration.
The correction is similar to the other one for the other subclasses.

Also added tests for rowcount and rownumber during different fetch styles.
Just in case.
2012-02-23 22:58:58 +00:00
Daniele Varrazzo
ebec522a07 Fixed rownumber for cursor subclasses during iterations
Regression introduced to fix ticket #80. Don't use fetchmany to get the
chunks of values. I did it that way because I was ending up into infinite
recursion calling __iter__ from __iter__: the solution has been the
"while 1: yield next()" idiom.
2012-02-23 22:55:13 +00:00
Daniele Varrazzo
7221ea9ec5 Added test to check rowcount behaves fine during named cursor iteration
Actually *it doesn't*: once we iterate the first itersize records, rowcount
is reset to zero. If we want to fix it we need an extra member in the
cursor.
2012-02-23 22:04:22 +00:00
Daniele Varrazzo
71d1690870 Test methods reordered to improve readability 2012-02-23 21:27:45 +00:00
Daniele Varrazzo
3b36100ec1 Dropped hardcoded list of exceptions in init functions
Use the already available exctable array.

This stops the gcc-python-plugin complaining about access to potentially
uninitialized memory.
2012-02-23 20:09:28 +00:00
Daniele Varrazzo
09be4dc5d1 Fixed potential failures while setting exceptions attributes 2012-02-23 19:48:46 +00:00
Daniele Varrazzo
7d67ecbed3 Fixed potential NULL incref 2012-02-23 19:47:36 +00:00
Daniele Varrazzo
1b27820389 Fixed refcount of exceptions dicts 2012-02-23 19:36:30 +00:00
Daniele Varrazzo
08fbd86495 Check errors in module typecasters init 2012-02-23 19:20:51 +00:00
Daniele Varrazzo
ff61cf25b6 Fixed refcount of None if namedtuples are not available 2012-02-23 18:50:06 +00:00
Daniele Varrazzo
026899e0c1 Check errors when populating encodings map 2012-02-23 18:50:06 +00:00
Daniele Varrazzo
dca6cffd6e Dropped custom array parsing for UUID[]
Use the C generic array parsing exposed by new_array_type().
2012-02-23 14:41:55 +00:00
Daniele Varrazzo
f782470d71 Parens don't need escaping in regexp char classes 2012-02-23 14:41:51 +00:00
Daniele Varrazzo
1332d4a0d8 Fixed never raised exception in composite parsing 2012-02-23 14:41:46 +00:00
Daniele Varrazzo
4e1d96082a Typos fixed in copy methods 2012-02-23 14:41:41 +00:00
Nate Eagleson
1bc73896dc Clean up comments in setup.cfg 2012-02-22 11:59:48 +00:00
Nate Eagleson
f3f3dbbca9 Fix typos in the INSTALL document
Also remove a bit of extraneous whitespace.
2012-02-22 11:59:48 +00:00
Daniele Varrazzo
91388d2c51 Cite Menno's TZ improvements into news file 2012-01-30 13:32:58 +00:00
Menno Smits
bca7200b3f Cache FixedOffsetTimezone instances
Avoid creating new a new FixedOffsetTimezone instance if one with the
same offset and name has been created before. This will save memory
when returning many rows containing "timestamp with timezone" columns,
and also improves comparability.
2012-01-30 13:27:40 +00:00
Menno Smits
1469a56512 Fixed repr for FixedOffsetTimezone for offsets west of UTC (negative)
The offset displayed was always positive and somewhat confusing. The
offset displayed now is the offset that the instance was created
with.

Also added some tests for initialisation.
2012-01-30 13:27:01 +00:00
Menno Smits
35ff2def34 Renamed shadowed test method 2012-01-29 19:35:38 +00:00
Daniele Varrazzo
78895e6943 Added doc for Error.cursor 2012-01-19 01:30:46 +00:00
Daniele Varrazzo
db987250c8 Avoid installing Error.__reduce_ex__ on Python 2.4
It is not used by the pickle protocol, and if called manually fails in an
unsettling way, probably because the exceptions were old-style classes.
2012-01-14 18:01:15 +00:00
Daniele Varrazzo
43daba38e7 Make Error and subclasses picklable
Useful for multiprocessing interaction.
Closes ticket #90.
2012-01-14 17:34:09 +00:00
Daniele Varrazzo
28f1013c2a Dropped duplicate import 2012-01-14 17:28:37 +00:00
Daniele Varrazzo
6f21111a92 Docs/cleanup for the lo_creat patch 2012-01-10 21:51:34 +00:00
Giovanni Mascellani
e1700fe28b Use lo_creat() instead of lo_create() when creating large objects without new_oid.
This enhances the compatibility with the pgpool-II replication middleware,
that doesn't support lo_create() calls.
2012-01-10 20:49:58 +00:00
Giovanni Mascellani
8ec9b0f3d9 Use lo_creat() instead of lo_create() when creating large objects without new_oid.
This enhances the compatibility with the pgpool-II replication middleware,
that doesn't support lo_create() calls.
2012-01-10 11:12:06 +01:00
Daniele Varrazzo
dcc60131a9 fetchmany accepts None as size, meaning the default arraysize
without this care, extending fetchmany in subclasses becomes tricky.

Closes ticket #84.
2012-01-10 01:32:45 +00:00
Daniele Varrazzo
09a8e7bf1f Fixed cursor.fetchmany docstring 2012-01-10 01:28:14 +00:00
Daniele Varrazzo
05fb0e2fbf Added tests to verify ticket #84
fetchmany() with no arg is broken in cursor subclasses.
2012-01-10 01:27:43 +00:00
Daniele Varrazzo
702ae0a904 Force GC during weakref tests
Required to run the tests under PyPy with no refcount. See
https://github.com/mvantellingen/psycopg2-ctypes/pull/15#issuecomment-3274618
2011-12-26 22:35:33 +01:00
Daniele Varrazzo
ede0e145dd Added tests for cursor scroll 2011-12-26 22:00:25 +01:00
Daniele Varrazzo
7990425801 Bump to next dev version 2011-12-26 20:06:10 +01:00
Federico Di Gregorio
0bc49147d1 Merge branch 'devel' 2011-12-19 11:30:20 +01:00
Federico Di Gregorio
c22e8ef808 Preparing release 2.4.4 2011-12-19 10:57:38 +01:00
Federico Di Gregorio
56482d3300 Merge remote-tracking branch 'piro/devel' into devel
Conflicts:
	NEWS
2011-12-19 10:55:55 +01:00
Daniele Varrazzo
2af563227a make_errorcodes updated to the current page style 2011-12-16 14:49:49 +00:00
Daniele Varrazzo
3094371621 Fixed doc for supported PG versions in errorcodes table 2011-12-16 12:37:38 +00:00
Daniele Varrazzo
d6e0b284e7 Map error classes 20 and HV to more specific exceptions 2011-12-16 12:26:27 +00:00
Daniele Varrazzo
08fa6550ab Docs typo fixed 2011-12-16 11:09:20 +00:00
Federico Di Gregorio
71a4c2bac9 Fixed rollback on error on Zope (ticket #73) 2011-12-16 10:37:01 +01:00
Daniele Varrazzo
b721421633 A bunch of typos fixed in the examples by Josh Kupershmidt 2011-12-15 23:58:22 +00:00
Daniele Varrazzo
c3914b8aa2 Improvements to the docs homepage after Bucko's proofreading 2011-12-15 22:13:20 +00:00
Daniele Varrazzo
9e8fc349b9 Docs homepage refreshed with new bragging and links 2011-12-15 21:42:08 +00:00
Daniele Varrazzo
5f098de7e8 A bunch of changes registered in the NEWS file 2011-12-15 20:17:36 +00:00
Daniele Varrazzo
2cf35b69de 'register_composite()' also works with tables
Skip dropped and hidden columns when inspecting the schema.
2011-12-15 20:11:17 +00:00
Daniele Varrazzo
a4485022b5 Use 'autocommit' to check if to rollback after extra types registration
isolation_level currently requires an extra query, autocommit doesn't.
2011-12-15 19:56:52 +00:00
Daniele Varrazzo
bb8e1e9455 Fixed error in schema mismatch in composite caster 2011-12-15 19:56:52 +00:00
Daniele Varrazzo
ba7a0a3008 Raise DatabaseError instead of error with bad exception informations
We can actually raise these exceptions in weird situations,
e.g. see ticket #82.
2011-12-15 17:50:31 +00:00
Daniele Varrazzo
424bc310a6 Use isolation level symbolic constants in examples 2011-12-15 13:10:36 +00:00
Daniele Varrazzo
5a6a303d43 A couple of fixes to psycopg1
_psycopg.connect is no more. Also use symbolic consts instead of values
for the isolation level.
2011-12-15 13:06:32 +00:00
Daniele Varrazzo
b5de04d2ff Put back a distinct ISOLATION_LEVEL_READ_UNCOMMITTED value 2011-12-15 12:53:48 +00:00
Federico Di Gregorio
d2d94e203f Reverted isolation level values to backward compatible values
This basically removes the READ UNCOMMITED level (that internally
PostgreSQL maps to READ COMMITED anyway) to keep the numeric values
compattible with old psycopg versions. For full details and discussion
see this thread:
http://archives.postgresql.org/psycopg/2011-12/msg00008.php
2011-12-15 12:25:19 +01:00
Daniele Varrazzo
8473209d24 Named DictCursor/RealDictCursor honour itersize
Closes ticket #80.
2011-12-11 22:06:15 +00:00
Daniele Varrazzo
8606d83507 Bump to next development version 2011-12-11 22:06:15 +00:00
Federico Di Gregorio
ba34b6942f Merge branch 'devel' 2011-12-11 22:18:11 +01:00
Federico Di Gregorio
2efe3efdfa Preparing release 2.4.3 2011-12-11 22:17:54 +01:00
Daniele Varrazzo
088978e7b1 Typo fixed writeable -> writable
Closes ticket #79.
2011-12-11 02:55:29 +00:00
Daniele Varrazzo
ad3a198919 Fixed reference leak with arguments referenced more than once in queries
Plus, some more care in objects life cycle, mostly in exceptions handling.

Closes ticket #81.
2011-12-11 02:52:06 +00:00
Daniele Varrazzo
cdb19a2329 Prepare for Linux 3 2011-11-26 19:08:20 +00:00
Daniele Varrazzo
0fccc10777 Tests in order
Just to know where to put the next one
2011-11-18 00:10:53 +00:00
Daniele Varrazzo
2cf44fdddd Merge branch 'connect-keywords' into devel 2011-11-18 00:05:44 +00:00
Daniele Varrazzo
a6aea38540 Added keywords on connect to news file 2011-11-17 21:51:24 +00:00
Daniele Varrazzo
417203f68e Added test to check connect() with no parameters 2011-11-17 21:51:24 +00:00
Daniele Varrazzo
e18d27c475 Reproducing/documenting odd behaviours of connect() 2011-11-17 21:51:24 +00:00
Daniele Varrazzo
625cc1b402 Escape parameters to the connection strings as required by PQconnectdb 2011-11-17 21:51:24 +00:00
Daniele Varrazzo
99ac79511c Added test module to verify the dsn manipulation 2011-11-17 21:51:24 +00:00
Daniele Varrazzo
d2b67364fd connect() supports generic keyword arguments passed to the dsn 2011-11-17 01:51:25 +00:00
Daniele Varrazzo
4254fb8566 Documentation for the isolation level constants updated
REPEATABLE READ and SERIALIZABLE are no more synonyms since PostgreSQL 9.1,
and in Psycopg values are different since 2.4.2.
2011-11-17 00:41:44 +00:00
Daniele Varrazzo
dc94a3cb2d Check for connection closed before getting the isolation level
Closes ticket #74

Also added test to check regressions in isolation_level,
set_isolation_level, set_session, autocommit.
2011-11-16 23:51:05 +00:00
Daniele Varrazzo
a76d0525d1 Dropped unused variable 2011-11-01 07:42:22 +00:00
Daniele Varrazzo
865fb2d792 Work around mxDateTime 3.2.0 segfault in tests 2011-11-01 07:42:08 +00:00
Daniele Varrazzo
00b52c78b3 Docs cleanup by Josh Kupershmidt 2011-11-01 07:09:51 +00:00
Daniele Varrazzo
5728649944 Merge branch 'fix-copy-on-win' into devel 2011-10-20 11:12:43 +01:00
Daniele Varrazzo
83d457361e Fixed docs for the copy null parameter 2011-10-20 11:12:05 +01:00
Daniele Varrazzo
2671472de8 Dropped leftover extra char, already accounted for before 2011-10-20 11:11:57 +01:00
Federico Di Gregorio
512b41cc9c Fix encoding when Zope explicitly pass empty "enc" argument 2011-10-20 09:52:22 +02:00
Daniele Varrazzo
6fc167a7b1 Unregister the composite array caster after the test
Otherwise the refcount script will report a leak.
2011-10-19 22:00:59 +01:00
Daniele Varrazzo
60b49f5c45 Avoid PyOS_snprintf to calculate the copy command buffer size
On windows it returns -1 instead of sometihing portable. So just ditch
the static buffer and just use a dynamic one to compose the command.

Also squashed a couple of buglets in copy_to: copyfile was decremented
before being set to null, size_t was used instead of Py_ssize_t.
2011-10-19 21:01:53 +01:00
Daniele Varrazzo
ff8158d7c0 Simplification in the COPY command composition
Dropped the branch if NULL is specified or not: just use the default \N.

Also fixed copy_from/copy_to docstrings.
2011-10-19 20:31:09 +01:00
Daniele Varrazzo
0f4fd0d828 Test suite fixed to make it compatible with the ctypes implementation 2011-10-19 02:25:53 +01:00
Daniele Varrazzo
d79661c87f All unit test modules have a test_ prefix
Both for consistency and for test discovery.
2011-10-19 02:20:43 +01:00
Daniele Varrazzo
3e39b23835 Notice -> Note in the docs, and a handful of other typo fixed 2011-10-14 23:59:49 +01:00
Daniele Varrazzo
37a9eb3615 Test and document the named cursor stealing technique 2011-10-14 23:17:24 +01:00
Daniele Varrazzo
dde4c0de3d Decimal adapter registration moved from C to Python
Fixes Decimal adaptation in sub-interpreter, where the Decimal class has
a different identity from the one in the main interpreter.

Closes ticket #52.
2011-10-14 22:35:56 +01:00
Daniele Varrazzo
6da39e3a37 Fixed pasto in docs 2011-10-06 18:38:30 +01:00
Daniele Varrazzo
5fa1729000 Skip test on array of records on PG 8.3 2011-10-05 00:44:44 +01:00
Daniele Varrazzo
e4424bdfdc Fixed tests to run with antebellum Postgres versions 2011-10-05 00:12:35 +01:00
Daniele Varrazzo
50b445fa12 Merge branch 'array-typecast' into devel 2011-09-22 20:00:08 +02:00
Daniele Varrazzo
8963b8adcb Added support for arrays of composite types 2011-09-22 19:57:42 +02:00
Daniele Varrazzo
2f9ceeac64 Added support for arrays of hstores 2011-09-22 19:56:58 +02:00
Daniele Varrazzo
c4e6d7d982 Fixed typecasting of arrays containing consecutive backslashes 2011-09-22 18:14:16 +01:00
Daniele Varrazzo
e3054ac9f3 Added new_array_type() function
Allows the creation of a generic array typecaster from Python.
2011-09-22 15:51:21 +01:00
Daniele Varrazzo
6c8051907c Fixed doc blocks
Raise error with docutils 0.8.1. Probably docutils 0.7 was more lenient.
2011-09-22 15:50:50 +01:00
Daniele Varrazzo
cd6e2cd8f2 Don't leak private variables into the psycopg2.extensions interface 2011-09-22 14:34:14 +01:00
Daniele Varrazzo
8fb08efae7 Allocate dynamically memory for the list of columns in COPY
Some bloke finds the limit of 8K too restrictive... ticket #68.
2011-09-12 02:21:59 +01:00
Daniele Varrazzo
d67d50b434 Fixed interaction between RealDictCursor and named cursors
Closes ticket #67.
2011-09-12 02:20:53 +01:00
Daniele Varrazzo
29932c488f errorcodes map updated to PostgreSQL 9.1 2011-08-22 17:29:14 +01:00
Federico Di Gregorio
880aa07a58 WITH HOLD documentation a argument parsing changes
Now any true value will do for the withhold parameter.
2011-08-10 19:21:12 +02:00
Federico Di Gregorio
a59d88c703 Merge remote-tracking branch 'piro/devel' into devel 2011-08-10 18:36:24 +02:00
Federico Di Gregorio
479bdf7458 New 'withhold' parameter for connection.cursor() 2011-08-10 18:25:46 +02:00
Daniele Varrazzo
1861e0010d Fixed --static-libpq setup option (ticket #64) 2011-08-09 11:44:30 +01:00
Daniele Varrazzo
9870ca4dce Fixed NamedTupleCursor.executemany() (ticket #65) 2011-08-09 11:44:30 +01:00
Daniele Varrazzo
a2ee25ecfe Check the connection status before putting back into the pool
Rollback connections in transaction or in error.
Discard broken connections.
Closes ticket #62.
2011-08-09 11:44:30 +01:00
Daniele Varrazzo
11ff27b5af Added documentation for putconn's close parameter 2011-08-09 11:44:30 +01:00
Daniele Varrazzo
4fd5f3267b Raise PoolError when putting a connection not belonging to the pool
A KeyError was raised instead.
2011-08-09 11:44:30 +01:00
Daniele Varrazzo
de6f2ac387 Grab the GIL when checking for errors occurred
The problem was causing a segfault on BEGIN if the server is disconnected
after the connection is created.
2011-08-09 11:44:30 +01:00
Daniele Varrazzo
d9fce1f837 Mention the lazy uuid import in the news file 2011-08-09 11:44:30 +01:00
Daniele Varrazzo
e3b32dcee1 Bump to next dev version 2011-08-09 11:44:30 +01:00
Daniele Varrazzo
30a046c602 Fixed adaptation doc example
Close ticket #63
2011-07-24 20:42:23 +01:00
Federico Di Gregorio
2f6336ea78 First try at curs.withhold implementation 2011-07-05 10:28:34 +02:00
Marko Kreen
cb1d163f4f lazy import for uuid module
Attached patch moves uuid import from inside try-except
to register_uuid function.  Reason: uuid module import is *very*
heavy.  It goes into OS searching for various .dll/.so libraries,
lauches 'ldconfig' and so on...

With this patch, 200x python -c 'import psycopg2.extras'
goes from 22s to 7s.  (plain 'import psycopg2' is 6s)

--
marko
2011-06-28 17:28:43 +02:00
Federico Di Gregorio
f8ff2ccc49 Merge branch 'devel' 2011-06-13 18:53:48 +02:00
Federico Di Gregorio
f8a5dabdc1 Preparing release 2.4.2 2011-06-12 21:40:44 +02:00
Federico Di Gregorio
3ec9677978 Aligned casing of isolation levels with PostgreSQL documentation 2011-06-12 21:40:31 +02:00
Daniele Varrazzo
d76d136b4f Introductory docs section on transaction control improved
Added big fat warning about idle in transaction and reference to
set_session().
2011-06-08 14:38:57 +01:00
Daniele Varrazzo
d2b28abced Method set_transaction() renamed to set_session()
In fact it doesn't change "the transaction", as there has to be no
transaction when invoked. The effect instead is to execute SET SESSION
CHARACTERISTICS.
2011-06-08 14:22:11 +01:00
Daniele Varrazzo
1a51cfe274 Better error message if deferrable is used in PG < 9.1 2011-06-08 10:59:27 +01:00
Daniele Varrazzo
0a1bbb56cd Dropped redundant semicolons at the end of internal queries
For consistency with other queries, and probably we give less work to do
to the server parser (a ridiculously tiny amount).
2011-06-08 09:22:35 +01:00
Daniele Varrazzo
5c13dac5ff Merge branch 'setup-cleanup' into devel 2011-06-08 08:22:03 +01:00
Jason Erickson
5ee7bac66b No manifest reinsertion into 2.4/2.5 with MSVC
Python versions 2.4 and 2.5 for MSVC on Windows do not need to manifest file
reinserted into the DLL.  The VC compiler for these versions does not have the
mt.exe executable to insert the manifest file.
2011-06-08 08:21:32 +01:00
Daniele Varrazzo
178698f9e8 Merge branch 'setup-cleanup' into devel 2011-06-07 23:58:58 +01:00
Daniele Varrazzo
7b017e7944 Mention Steve and his work in the NEWS file
That's Steve's Job! :D
2011-06-07 23:58:37 +01:00
Daniele Varrazzo
dc92161dda Delay detection of the compiler in setup.py
At init time, build_ext is not configured, so neither the --compiler option
nor settings in setup.cfg/distutil.cfg is effective.

Steve, I told you distutils was a mess :)
2011-06-07 23:28:17 +01:00
Daniele Varrazzo
d0b97feab3 More cleanup in pg_config detection from Windows registry 2011-06-07 22:35:22 +01:00
Steve Lacy
575afa2e0e Properly detect pg_config.exe on Windows.
I'm fairly certain this is correct, submitting so I can pull on my Windows
box and do some testing there.
2011-06-07 22:35:22 +01:00
Steve Lacy
46dc7e66f8 Fix pg_config commandline option broken in a previous change
- Make sure to declare self.pg_config in initialize_options.
- Don't declare PostgresConfig in __init__, as its scope is limited.
- Pass build_ext instance to PostgresConfig to avoid having to
  call the option parser directly.
2011-06-07 22:22:08 +01:00
Steve Lacy
57a6cf3144 Code to find an executable on the current PATH refactored 2011-06-07 22:18:56 +01:00
Daniele Varrazzo
6d907df14d Fixed documentation for COPY methods
The size parameter in copy_from was undocumented (ticket #59).
2011-06-07 11:16:10 +01:00
Daniele Varrazzo
9b5ac79513 Fixed default size for read copy buffer
The original commit stated it should have been 8192.
2011-06-07 11:16:06 +01:00
Daniele Varrazzo
9a7aee3d05 Fixed compatibility problem in setup for Python 2.4 2011-06-07 08:58:54 +01:00
Steve Lacy
ef18915396 Unify the way the MSVC compiler is detected
And do it only once in __init__ instead of different ways
and in different places.
2011-06-07 08:41:57 +01:00
Steve Lacy
c826446ff8 Clean up a bunch of lint from pylint/pyflakes/pep8 checking
- Don't override global variable name "ext" (use "extension" as function
  argument names)
- Improve function naming (get_compiler -> get_compiler_name)
- Other misc operator spacing and 80-column violation cleanup.
- Remove unneeded import (DistUtilsFileError)
2011-06-07 08:40:40 +01:00
Steve Lacy
f3526d0630 Refactoring of the pg_config detection code in setup.py
Pull all state and path searching into it's own class.
2011-06-07 08:40:19 +01:00
Daniele Varrazzo
816b5dda33 Merge branch 'copy-refcount-bug' into devel 2011-06-07 01:20:37 +01:00
Daniele Varrazzo
679af4a975 Fixed copyfile refcount in copy_expert
In case of early error, jumping to exit would have decref'd the borrowed
reference to file.

Issue spotted by Dave Malcolm, thanks!
2011-06-07 01:20:25 +01:00
Daniele Varrazzo
e9a485e30b Merge branch 'copy-refcount-bug' into devel 2011-06-07 00:14:11 +01:00
Daniele Varrazzo
b6e710b0fc Fixed refcount bug in copy_to() and copy_expert() methods too 2011-06-07 00:08:29 +01:00
Daniele Varrazzo
1888bf41c0 Added patch for refcount bug in copy_from
By Dave Malcolm. https://bugzilla.redhat.com/show_bug.cgi?id=711095
(slightly edited to increment the refcount before storing the pointer
in the cursor).
2011-06-07 00:08:29 +01:00
Daniele Varrazzo
2a1b2b5713 Added script to demonstrate the refcount bug during copy
from https://bugzilla.redhat.com/show_bug.cgi?id=711095
2011-06-07 00:08:29 +01:00
Jason Erickson
dd7ee7093a No strcasecmp function with MSVC
The MSVC compiler does not have the strcasecmp(x, y) function, which is a
case insensitve string compare function.  Instead, MSVC has a similar function,
lstrcmpi(x, y).  Modified config.h to use this function when building with
MSVC.
2011-06-05 23:33:28 +01:00
Daniele Varrazzo
442a0606fe Merge branch 'guc-cleanup' into devel 2011-06-05 16:31:25 +01:00
Daniele Varrazzo
709df38d79 Don't clobber an eventual Python exception set by a green thread 2011-06-05 16:30:37 +01:00
Daniele Varrazzo
869d48b6f0 Use the pqpath functions to get/set GUC parameters
Functions conn_setup(), conn_get_isolation_level(), conn_set_transaction(),
conn_switch_isolation_level(), conn_set_client_encoding() reimplemented
using the pqpath funtitons.

Dropped analogous function in the connection, as it had to take the lock,
thus it was hard to build consistent pieces of functionality with it.
2011-06-05 16:26:01 +01:00
Daniele Varrazzo
8f876d4b5d Avoid a deadlock using concurrent green threads on the same connection
Use the async_cursor property to store an indication that something is
running (even if it is not necessarily a cursor running the query).
2011-06-05 16:22:54 +01:00
Daniele Varrazzo
cf6a4ec062 Added pqpath functions to get/set the value for GUC parameters
The aim of these function is to allow the connection to make a better use
of the pqpath functions instead of using PQexec for these small things.
Also, the functions are to be called with the connection lock: this makes
composing higher level functions using them easier.
2011-06-05 15:36:02 +01:00
Daniele Varrazzo
dcc9e84a68 Don't encode the pg_config path on Python 3 on Windows
It can deal with unicode ok, and fails if it gets bytes.
2011-06-04 22:26:21 +01:00
Daniele Varrazzo
a0d16fcfb2 Avoid a ton of warnings when building on mingw
mingw doesn't support visibility hidden even if gcc can.
2011-06-04 22:19:56 +01:00
Daniele Varrazzo
62a8ef308a Fixed version check 2011-06-04 14:21:18 +01:00
Daniele Varrazzo
c8ec747903 Don't fail import if mx.DateTime module is not found at import time
A better fix for ticket #53.
2011-06-04 14:16:24 +01:00
Daniele Varrazzo
05659c0d16 Cleanup of notice processing
The function is always called in the context of functions grabbing the
connection lock, so just use the same critical section instead of releasing
and re-acquiring it. It is not a problem as serious as the notifies process
(ticket #55) as the notices are a psycopg structure, not libpq. However the
change allows again processing notices/notifies in the same place,
which makes sense conceptually, plus we save some lock dance.
2011-06-04 01:49:03 +01:00
Daniele Varrazzo
d9c0b8166f Process notifies when data is received, not when the result is parsed
Notifies process access the connection, is not limited to the result, so
There is the possibility of loss of protocol sync in multithread programs.

Closes ticket #55.
2011-06-04 01:31:36 +01:00
Daniele Varrazzo
3aad3d3143 Fixed test to run on Python <= 2.5
tuple.index() is not available on these versions.
2011-06-03 09:31:06 +01:00
Daniele Varrazzo
0eb5e0430e Merge branch 'transaction-control' into devel 2011-06-03 01:48:24 +01:00
Daniele Varrazzo
530ba78881 Documentation for set_transaction() and autocommit improved 2011-06-03 01:46:56 +01:00
Daniele Varrazzo
5748ae14bf Test tweaked to deal with missing usecs in BC timestamps
Probably depending on compile time options. On my test db usecs
are available from PG 8.4.
2011-06-03 00:54:33 +01:00
Daniele Varrazzo
4d3c6865ee Use only the isolation levels available on old PG versions 2011-06-03 00:40:54 +01:00
Daniele Varrazzo
c2d1f1f2e6 Dropped isolation level from the connection object
Don't issue a SET TRANSACTION ISOLATION LEVEL at every begin: use PG's
GUC default, eventually set by set_transaction.

Dropped the last query at connection, yay!

Method set_isolation_level() and property isolation_level refactored using
the new structures, keeping the previous semantic.
2011-06-03 00:10:24 +01:00
Daniele Varrazzo
389f2cf1d0 Added autocommit property on connection 2011-06-02 01:16:22 +01:00
Daniele Varrazzo
ea03ffbf76 Added partial implementation for set_transaction
autocommit to be implemented yet.
2011-06-01 09:07:02 +01:00
Daniele Varrazzo
a69facc7f0 Adding docs for the planned set_transaction/autocommit features 2011-05-31 00:05:50 +01:00
Daniele Varrazzo
531292bca5 Merge branch 'neg-escape' into devel 2011-05-30 22:09:23 +01:00
Daniele Varrazzo
281427f450 Fixed escape for negative numbers prefixed by minus operator
Closes ticket #57.
2011-05-30 22:00:20 +01:00
Daniele Varrazzo
19ec8809fd Use all the isolation levels accepted by PostgreSQL
In PG 9.1 repeatable read and serializable are distinct levels.
2011-05-11 13:01:20 +01:00
Daniele Varrazzo
834c7d1288 Fixed a few docstrings mixed up 2011-05-11 12:59:31 +01:00
Daniele Varrazzo
af424821b7 Don't build mx.DateTime support if the module can't be imported
Previously we only checked for the existence of the include files, but this
doesn't imply the presence of the module. Particularly true in restricted
environments such as virtualenv.

Closes ticket #53.
2011-05-11 12:59:31 +01:00
Daniele Varrazzo
c687f1d816 Bump to next development release 2011-05-11 12:59:31 +01:00
Federico Di Gregorio
ab685c2fc0 Merge branch 'devel' 2011-05-11 09:58:49 +02:00
Federico Di Gregorio
9080b30741 Preparing release 2.4.1 2011-05-11 09:58:34 +02:00
Daniele Varrazzo
de6aff31b8 Skip a test on the proper PG function 2011-04-27 12:18:50 +01:00
Daniele Varrazzo
c61ec094a3 Don't fetch all the records iterating a NamedTuple cursor on a named cursor 2011-04-26 19:26:19 +01:00
Daniele Varrazzo
ffa7a62b93 Fixed interaction between NamedTuple and named cursor
Build the nametuple after fetching the first resutl, or else
cursor.description will be empty.
2011-04-26 19:18:39 +01:00
Daniele Varrazzo
80891e64b3 Dropped unused import 2011-04-26 19:16:10 +01:00
Daniele Varrazzo
c08799b0b0 Fixed SystemError clobbering libpq errors raised without SQLSTATE
Bug vivisectioned by Eric Snow
<http://archives.postgresql.org/psycopg/2011-04/msg00019.php>.
2011-04-24 02:59:28 +01:00
Daniele Varrazzo
746afdf69f Added missing vertical spaces in NEWS 2011-04-15 01:11:22 +01:00
Daniele Varrazzo
e316d7bcd4 Merge branch 'fix-encoding' into devel 2011-04-09 14:47:07 +01:00
Daniele Varrazzo
e3605b33c1 Updated NEWS with the connection encoding fix 2011-04-08 14:36:49 +01:00
Daniele Varrazzo
19653a88ec Store a normalized version of the PG encoding in the connection
This way looking up into extensions.encodings will not break.
2011-04-08 13:48:11 +01:00
Daniele Varrazzo
88803695ac Normalize the encoding name at connection
The encoding can be set by PGCLIENTENCODING, which may be an alternative
spelling. Bug reported by Peter Eisentraut.

At this point the idea of considering one of the random spellings such as
EUC_CN as somewhat "blessed" is debunked. So just store the cleaned-up
version of the encoding in the mapping table. Note that the cleaned-up
version was needed by the unicode adapter: this requirement has been
surpassed as the connection now contains a copy of the Python codec name
set whenever the client encoding is set.
2011-04-08 13:48:11 +01:00
Daniele Varrazzo
bf48706868 Don't check the test db exists at psycopg2.tests import time 2011-03-30 15:52:49 +01:00
Daniele Varrazzo
2dab7d52f2 Fixed bytea encoding tests skipping when ctypes is not available 2011-03-26 14:27:58 +00:00
Daniele Varrazzo
7716cc6a0c Allow to specify --static-libpq on setup.py command line
Patch provided by Matthew Ryan (ticket #48).
2011-03-26 13:48:37 +00:00
Daniele Varrazzo
90536a187d Merge branch 'bytea-parser' into devel 2011-03-26 13:02:57 +00:00
Daniele Varrazzo
da58bee70a Added documentation for the bytea parser 2011-03-26 12:59:15 +00:00
Daniele Varrazzo
e0cd6f0f00 Added tests for our own bytea parser
Because the parse function is not supposed to be exposed in Python,
use ctypes to directly inspect the C function.
2011-03-26 12:59:14 +00:00
Daniele Varrazzo
66c543b16c Parse bytea output format ourselves instead of using the libpq
PG 9.0 uses the hex format by default, and clients < 9.0 can't parse that
format, requiring client update and great care in what is linked at runtime,
and generally giving headache to users and transitively us.
2011-03-26 12:59:14 +00:00
Daniele Varrazzo
f34e44b3f4 Merge branch 'empty-query' into devel 2011-03-04 20:33:51 +00:00
Daniele Varrazzo
fcbe0466a6 Correctly detect an empty query sent to the backend
Closes ticket #46.
2011-03-04 20:30:43 +00:00
Daniele Varrazzo
f1d69f6dec Fixed detection of empty error from pq_raise
Avoid a system error in case err is set to an empty string.
2011-03-04 20:20:56 +00:00
Daniele Varrazzo
4a8b5f98f3 Bump to work on 2.4.1 2011-03-04 20:18:22 +00:00
Federico Di Gregorio
29f83f05c4 Merge branch 'devel' 2011-02-27 13:03:48 +01:00
Federico Di Gregorio
2212ea96a6 Preparing release 2.4
* NEWS file now uses 72 columns (better in emails and posts)
* Bumped versions
* Updated MonoDevelop file
2011-02-27 12:52:00 +01:00
Daniele Varrazzo
194447fbbf Merge branch 'msvc-cleanup' into devel
Merged Jason Erickson devel branch after collapsing a few commits together
where it made sense.
2011-02-25 10:29:19 +00:00
Jason Erickson
2997c0eb6c Windows MSVC: 64bit compiler sees 2 export symbols
The MSVC compiler sees a request for the main symbol (init__pyscopg) to be
exported twice during the build process and issues a warning in 64bit mode.
One symbol is from distutils exporting the library with the
build_ext.get_export_symbols() function, the other is from the #define
PyMODINIT_FUNC (define in pyport.h) that begins the main _psycopg module.
This patch overrides the get_export_symbols function and returns an empty
array of symbols to export if the compiler is MSVC.
2011-02-25 10:25:12 +00:00
Jason Erickson
7c2fa77c4b Windows MSVC: Fixed warning of incompatible types
Fixed incompatible type warning from XidObject * to PyObject * by
casting.
2011-02-25 10:25:12 +00:00
Jason Erickson
961e855bbd Windows MSVC: Fix Compiler Warning: getpid
Fix a compiler warning when using PSYCOPG_DEBUG on MSVC where getpid is
undefined.
2011-02-25 10:25:12 +00:00
Jason Erickson
631883f62f Windows MSVC: Fix data loss compiler warnings
Fixed MSVC compiler warnings where it was indicating a conversion
from a larger data type to smaller data type might have data loss.
2011-02-25 10:25:12 +00:00
Daniele Varrazzo
9e00196165 Fixed use of the new return value of HstoreAdapter.get_oids() 2011-02-25 01:37:02 +00:00
Daniele Varrazzo
5211e1474b Don't limit the hstore search to the public schema only
Looks like there is a case for installing hstore somewhere else (see
ticket #45). And after all the typecaster can be registered on a list of
OIDs, so let's grab them all.
2011-02-25 00:19:49 +00:00
Daniele Varrazzo
29ac03ef04 Check for failed allocation in the notice callback 2011-02-24 10:14:06 +00:00
Daniele Varrazzo
343687ebc8 Fixed runtests -> check in INSTALL file 2011-02-24 10:10:27 +00:00
Jason Erickson
6f0dfe6d2d Windows MSVC: Remove /Wp64 compiler flag
Remove the /Wp64 flag since it is deprecated starting in Visual Studio 2008.
2011-02-23 14:29:44 -07:00
Daniele Varrazzo
f9862211b1 NEWS for release 2.4 ordered in groups 2011-02-23 14:23:34 +00:00
Daniele Varrazzo
894d3f653c Raise an exception if the libpq fails to decode bytea in hex format 2011-02-23 14:04:27 +00:00
Daniele Varrazzo
c01a7edbf4 Fixed test for execution with older PostgreSQL versions 2011-02-23 08:43:01 +00:00
Daniele Varrazzo
f96b68d8c6 Fixed docstring for connection.lobject() 2011-02-23 01:53:56 +00:00
Daniele Varrazzo
1db9c9b8ce The cursor name can be a non-valid PostgreSQL identifier 2011-02-23 01:53:25 +00:00
Daniele Varrazzo
66555c5f11 Fixed call of memory functions without the GIL 2011-02-23 00:48:10 +00:00
Daniele Varrazzo
20f714f17c Added error checking to _pq_fetch_tuples() 2011-02-23 00:32:23 +00:00
Daniele Varrazzo
c1715f66fe More careful memory management
- Check return value of PyErr_Malloc and set an exception in case of error
- Avoid exposing variables with refcount 0 as connection attributes.
- PyErr_Free guards itself for NULL input
2011-02-23 00:32:23 +00:00
Daniele Varrazzo
143dc2e911 Added oid parameter to register_hstore()
The parameter is mostly useful with async connections that would need a
different protocol to be queried.

Issue reported by Jan "the Asynchronous".
2011-02-21 01:29:53 +00:00
Daniele Varrazzo
beffb02d56 Stricter declaration and correct use of psyco_set_error
It has long been used in wrong ways, with the function receiving a
connection or lobject instead of a cursor. It has always been unnoticed
(nobody has noticed the wrong object attached to the exception in the
wrong cases) but it started crashing the interpreter with Python 3.2 on
Windows.

Thanks to Jason Erickson for finding the problem and helping fixing it.
2011-02-21 00:31:09 +00:00
Daniele Varrazzo
a97e2a842d Tweaks to test timing to avoid errors on test VMs 2011-02-20 19:33:22 +00:00
Daniele Varrazzo
d74f777339 Check for memory errors in the connection init 2011-02-20 18:57:04 +00:00
Daniele Varrazzo
7996333ee7 Added regression test to check {} is also a valid string 2011-02-20 12:28:50 +00:00
Benjamin Poulain
5ee60571a5 Add a type converter to handle untyped empty arrays.
Empty array can be returned untyped by postgres. To handle
this case, a special handler is added for the type UNKNOWNOID.
If the value return by the database is strictly equal to "{}",
the value is converted. Otherwise, the conversion fallback on
the default handler.
2011-02-20 12:28:10 +00:00
Daniele Varrazzo
4bc4f85229 Merge remote branch 'jason/devel' into devel
Conflicts:
	psycopg/notify_type.c
2011-02-19 16:25:31 +00:00
Daniele Varrazzo
556b4d461e Documentation cleanup
Added several links to the Python documentation using the 'intersphinx'
extension.
2011-02-19 16:16:28 +00:00
Daniele Varrazzo
75c61c2e80 Added complete roundtrip test with copy_expert and Unicode 2011-02-19 14:35:56 +00:00
Daniele Varrazzo
6098ced761 Assume there may be files returning Unicode in Python 2 too
This is the case in Python 2.7 with files implementing io.TextIOBase.
2011-02-19 14:24:15 +00:00
Daniele Varrazzo
8a08114314 Correctly handle exceptions with non-ascii chars in the message
Previous implementation would have barfed in canse of non-utf-8 data in
the message.
2011-02-19 14:16:53 +00:00
Jason Erickson
4bc47d47a5 Python 3.2 hash() return value is arch dependant
Python 3.2 hash() function will now return a 64bit value when run on a 64bit
architecture, where as previously, it would always return a 32bit value.
Modified the code to use the now Py_hash_t typedef and for Python versions
less than 3.2, hard code Py_hash_t to long and Py_uhash_t to unsigned long.
2011-02-18 23:57:25 -07:00
Daniele Varrazzo
d263ecfee7 Display a note as a note in the cursor.lastrowid docs 2011-02-19 00:52:26 +00:00
Daniele Varrazzo
1f7774bd4e Cursor docs reordered
'cast()' moved in the retrieval functions. Methods only defined for
DBAPI compliance moved to the bottom.
2011-02-19 00:44:24 +00:00
Daniele Varrazzo
837f1e5e4f Set hidden visibility to a few functions not public 2011-02-19 00:25:23 +00:00
Daniele Varrazzo
c620f18be1 Provide cursor.description as named tuple if possible
If namedtuple() is not available, use regular tuples.
2011-02-19 00:05:43 +00:00
Daniele Varrazzo
e2cbc3411d Duplicate item in NEWS dropped, quotes cleanup 2011-02-19 00:00:34 +00:00
Jason Erickson
4fdc22451e Merge branch 'devel' of github.com:jerickso/psycopg into devel 2011-02-18 13:08:33 -07:00
Jason Erickson
9dc6811135 Again, increase timeout on concurrent_exec tests
Truly increase the sleep timeout to 4 seconds and the check to 7.  Previous
commit message indicated that, but reality was different.
2011-02-18 11:52:17 -07:00
Daniele Varrazzo
836f8a1aa1 Make Binary(None) work as expected, adapting to NULL
Issue reported by Stefano Dal Pra.
2011-02-18 14:19:57 +00:00
Daniele Varrazzo
8530ef1793 Download url set to the sdist location. 2011-02-18 13:53:57 +00:00
Daniele Varrazzo
99b3c72312 Some cleanup in mogrify
- Raise an exception on incomplete placeholders.
- Minor speedups.
- Don't change the string in place (??!!) if the placeholder is not s
  and the value is null.

The latter point can be done because downstream we don't accept anything
different from s anyway (in the Bytes_Format function).

Notice that now the format string is constant whatever the arguments.
This means that executemany is still more inefficient than it should be
as mogrify may work only on the parameters. However this is an
implementation only worthwhile if we start supporting real parameters.

Let's talk about that for the next release.
2011-02-18 02:33:42 +00:00
Daniele Varrazzo
b6d6fbbe8c Use a global object for NULL
Small optimization as NULL is a frequent value to build.
2011-02-17 20:09:52 +00:00
Daniele Varrazzo
c51165e2aa Indentation fixed 2011-02-17 19:53:04 +00:00
Daniele Varrazzo
c76cace2ef Improved documentation for cursor.description
Describe what actually happens between Psycopg and PostgreSQL, not the
basic template copied from the DBAPI.
2011-02-17 13:38:18 +00:00
Daniele Varrazzo
63ac6cdde5 Added cursor.itersize
The value is used to control the number of records to fetch per network
roundtrip in named cursors iteration. Used to avoid the inefficient
arraysize default of 1 without giving this value the magic meaning of
2000.
2011-02-17 12:36:02 +00:00
Daniele Varrazzo
7756eae573 Merge remote branch 'jason/devel' into devel 2011-02-17 11:50:14 +00:00
Daniele Varrazzo
1ba5f104c9 Import _psycopg as the first module in the package
Failing to do so, the real cause of the _psycopg import failed may get
hidden and people may get a misleading error such as "cannot import name
tz" instead.
2011-02-17 10:45:18 +00:00
Daniele Varrazzo
3b10ef8998 Documentation about new support for binary objects improved 2011-02-16 02:54:30 +00:00
Daniele Varrazzo
bccbcf42d0 Added adaptation for objects supporting the new-style buffer interface
Supporting this interface is required to adapt memoryview on Python 2.7 as they
don't support the old style. But because the old style is long deprecated it
makes sense to start supporting the new one.
2011-02-16 01:30:25 +00:00
Daniele Varrazzo
3ae2f221b3 Adapt bytearray and memoryview to bytes if available 2011-02-15 17:30:43 +00:00
Daniele Varrazzo
c96ba553da Cleanup of skipping of testing methods on certain Py/PG versions 2011-02-15 17:11:07 +00:00
Daniele Varrazzo
e4a84b9ce9 Fixed error message on Binary(str) in Python 3 2011-02-15 15:53:07 +00:00
Daniele Varrazzo
be22dfb765 Skip test if clock_timestamp function is not available 2011-02-15 15:25:14 +00:00
Daniele Varrazzo
522af403c6 Added FAQ entry about the PYTHON_EGG_CACHE problem 2011-02-15 12:50:37 +00:00
Daniele Varrazzo
5b2d54669f Fixed reference to NEWS file in the manifest 2011-02-15 12:29:14 +00:00
Daniele Varrazzo
d4eb28aed5 Dropped reference to release 2.3.3 in the docs 2011-02-15 11:00:08 +00:00
Daniele Varrazzo
c1fe0b675a Dropped correct roundtrip of empty array
The feature in itself is not extremely useful and instead PostgreSQL is
not always able to cast away from text[], which is a regression see
(ticket #42).
2011-02-15 10:27:47 +00:00
Daniele Varrazzo
84352e8cfb Bump version number 2011-02-15 10:26:48 +00:00
Federico Di Gregorio
93c19d18f1 Added to manifest "*.manifest" files needed by win32/VC 2011-02-15 09:25:05 +01:00
Jason Erickson
7c9d8192a3 Increase timeout on concurrent_execution test
With test_concurrent_execution test, checking two threads issuing a pg_sleep
of 2 seconds and and check if they complete in under 3 seconds occasionally
fails when the test is run in a virtual machine on a VM Server with other
virtual machines running.  Increased the sleep to 4, and the check to 7,
giving 3 seconds buffer instead of 1 second.
2011-02-14 16:31:31 -07:00
Jason Erickson
7dfb40ce43 Windows manifest check now checks compiler type
Initial compiler check was only checking two python versions.  Changed the
check not to check python version, but compiler version, to be compatible
with more versions of python.
2011-02-14 16:03:38 -07:00
Federico Di Gregorio
3762c67cd4 Merge branch 'devel' 2011-02-13 12:28:18 +01:00
Daniele Varrazzo
3842026bed Bumped to 2.4 beta2
We may release a Windows package to let people test if ticket #20 is
fixed.
2011-02-12 20:19:14 +00:00
Daniele Varrazzo
8ab7fa596c Merge remote branch 'jason/devel' into devel 2011-02-12 20:19:07 +00:00
Daniele Varrazzo
4c336a51bc Added test to check issue #40 2011-02-12 20:19:02 +00:00
Marti Raudsepp
9cb72a38da Add negative infinity support for Python->pg conversion 2011-02-12 20:19:02 +00:00
Jason Erickson
e3095edad3 Python 3 conversion failure on Windows
Windows is not able to create a tempfile with NamedTemporaryFile and then
open it with a second file handle without closing the first one.  Added
code to close the handle, and keep the file around a little longer so it
can be reopened and rewritten to again.
2011-02-11 17:40:23 -07:00
Jason Erickson
ed42746027 Merge branch 'devel' of git://github.com/dvarrazzo/psycopg into devel 2011-02-11 13:37:19 -07:00
Daniele Varrazzo
9e9c221637 Work around a 2to3 next fixer bug in a test 2011-02-11 17:54:41 +00:00
Jason Erickson
560f52106c Windows manifest changes based upon architecture
Apparently, using * for the architecture has the potential to not work on
on some amd64 systems.  Added checks and split the manifest based upon
architecture.
2011-02-11 10:01:38 -07:00
Jason Erickson
da68119f7c MSVC manifest change to work with buildbot
The buildbot does not seem to like the checks for if the source has
changed, forced build, etc.  Removed to work with buildbot.
2011-02-10 22:55:33 -07:00
Jason Erickson
502d8e120e Fix manifest insertion checks for MSVC py2.6/2.7
The manifest was never inserted because the checks were failing.  Assuming
build_extension was clearing out some of the checked values.
2011-02-10 22:28:27 -07:00
Jason Erickson
f2c0a01db1 Modified code to conform to python coding standard
Change indention from 2 spaces to 4 spaces with recent changes.
2011-02-10 21:50:33 -07:00
Jason Erickson
68ccac1766 Fixed linefeeds on merged files to unix linefeeds
Merge utility changed the linefeeds from unix to windows.  Changed the
linefeeds back to unix linefeeds.
2011-02-10 17:16:10 -07:00
Jason Erickson
3fc4dcec06 Merge remote branch 'upstream/devel' into devel
Conflicts:
	setup.py
	tests/__init__.py
	tests/testconfig.py
2011-02-10 16:07:38 -07:00
Jason Erickson
b075017ad9 Pulled down changes from dvarrazzo branch on gh
Pulled the master branch from of Daniele's psycopg branch on github and
merged the changes.
2011-02-10 15:59:31 -07:00
Jason Erickson
8d28509f49 Change win32 build to reinsert VC Library Manifest
Added a change at the end of the build process that would reinsert the VC library manifest.  This patch will fix issues when an embedded program does not have a manifest pointing to the VC 2008 runtime library, such as in an apache/mod_python situation.

Signed-off-by: Jason Erickson <jerickso@stickpeople.com>
2011-02-10 13:17:14 -07:00
Daniele Varrazzo
1a0c494417 Document difference of string handling in Python 2/3 2011-02-10 02:16:55 +00:00
Daniele Varrazzo
713b86acdf Added FAQ point about bytea_output in PostgreSQL 9.0 2011-02-10 02:16:55 +00:00
Daniele Varrazzo
9c81f6c186 Improved adaptation documentation
Documented __conform__() and prepare().
2011-02-10 02:16:24 +00:00
Daniele Varrazzo
7a058403ca Fixed mapping for composite types defined in a schema 2011-02-09 02:22:03 +01:00
Daniele Varrazzo
8ac5f0070a Fields order enforced in composite types adapter 2011-02-09 02:21:55 +01:00
Federico Di Gregorio
352d0d1f07 Preparing 2.4 beta 1
* Unified NEWS (we don 't support 2.0 anymore)
* Bumped up version in setup.py and ZPsycopgDA/DA.py
2011-02-06 16:54:35 +01:00
Federico Di Gregorio
da27142882 Merge branch 'python3' into python2 2011-02-06 16:47:05 +01:00
Daniele Varrazzo
c97fa1c476 Merge branch 'iter-named-cursor' into python2 2011-02-05 15:28:30 +01:00
Daniele Varrazzo
fab31e9441 Fetch 'arraysize' records per roundtrip in named cursors iteration
Closes ticket #33.
2011-02-05 15:24:00 +01:00
Daniele Varrazzo
b544354db2 COPY sends unicode to a file if it derives from io.TextIoBase
Fixes ticket #36.
2011-02-05 15:12:37 +01:00
Daniele Varrazzo
b358c54f02 More efficient cursor.iter: fetch many records at time. 2011-02-04 12:22:07 +00:00
Jason Erickson
88cc5a986d Use tests.dsn for the dsn connection string
Using self.conn.dsn as the dsn connection string actually has the password
'x'ed out.  The initial connection replaces the password with 'x' to
obfuscate it.  Using tests.dsn instead of self.conn.dsn ensures that the
correct connection string is used.
2011-02-02 17:14:29 -07:00
Jason Erickson
dcd2e19bde Add PSYCOPG2_TESTDB_PASSWORD variable for tests
Add a check for the PSYCOPG2_TESTDB_PASSWORD environment variable if the
database user (or database settings) requires a password.
2011-02-02 17:14:12 -07:00
Daniele Varrazzo
8a1de1ec4e Added test to verify named cursor efficiency.
Iter shouldn't fetch one record at time.
2011-02-01 03:01:47 +00:00
Daniele Varrazzo
d40b394c50 Merge branch 'python2' into python3 2011-02-01 02:27:45 +00:00
Daniele Varrazzo
9433a6879f Merge remote branch 'origin/python2' into python2
Conflicts:
	NEWS-2.3
2011-02-01 02:24:33 +00:00
Daniele Varrazzo
a2dcf504b5 Hopefully really fixed crash in datetime adapter.
Verified with gcc 4.3. Notice that on gcc 4.4 the bug was not present.
2011-02-01 02:00:47 +00:00
Daniele Varrazzo
bde443a902 Fixed standard_conforming_strings filtering in Python 3 tests 2011-01-18 02:45:31 +00:00
Daniele Varrazzo
9f90f049ab Merge branch 'python2' into python3
Conflicts:
	tests/bug_gc.py
	tests/types_extras.py
2011-01-18 02:11:58 +00:00
Daniele Varrazzo
153c30f24b Skip composite type tests if the server doesn't support them 2011-01-18 02:09:49 +00:00
Daniele Varrazzo
ca3d9da83b Skip GC bug test if uuid is not available 2011-01-18 02:09:49 +00:00
Daniele Varrazzo
06059a216f Fixed hstore test in PG 9.x with standard_conforming_strings off 2011-01-18 00:58:33 +00:00
Daniele Varrazzo
8e1257d7d0 Fixed check for pg_sleep availability in tests
The function is available since PG 8.2.
2011-01-18 00:57:27 +00:00
Daniele Varrazzo
d0e36d194c Added icon removed from Zope 2.12.9 to the ZPsycopgDA package
Closes ticket #30. Bug report and patch by Pumukel.
2011-01-14 16:31:57 +01:00
Daniele Varrazzo
332acccc6e Replace b('str') with b'str' in Python 3
This avoids an encode() call for each of these constants.

Use a custom 2to3 fixer in setup.py to perform the conversion.
2011-01-13 11:37:40 +00:00
Daniele Varrazzo
3ba0631dbb A few large objects tests fixed
The behavior changed in Python 3 after the lobject-decode merge.
2011-01-10 22:05:47 +00:00
Daniele Varrazzo
36d9ffea32 Merge branch 'lobject-decode' into python3 2011-01-10 00:49:04 +00:00
Daniele Varrazzo
789dda1173 lobject read and write can deal with both bytes and unicode
On write, unicode is encoded in connection encoding.
On read, respect the lobject mode 't' or 'b'.
2011-01-10 00:46:51 +00:00
Daniele Varrazzo
ba1d77a297 Large object mode parsing refactored
Added parsing of text/binary mode.
2011-01-10 00:46:51 +00:00
Daniele Varrazzo
f63167a92c Added tests to check large objects decoding 2011-01-10 00:46:51 +00:00
Daniele Varrazzo
2cde9033ac Added documentation for Unicode support in large object
Not implemented yet!
2011-01-10 00:46:51 +00:00
Daniele Varrazzo
79048ff19a Merge branch 'python2' into python3
Conflicts:
	NEWS-2.3
	tests/__init__.py
	tests/test_lobject.py
	tests/test_quote.py
	tests/testutils.py
2011-01-10 00:46:02 +00:00
Daniele Varrazzo
f345e7daeb Merge branch 'python32' into python3 2011-01-10 00:25:09 +00:00
Daniele Varrazzo
48588e5f69 Invalidate large objects after a two-phase commit operation 2011-01-10 00:20:55 +00:00
Daniele Varrazzo
935c25730a Fixed segfault in large object close.
Check that the connection is not closed/faulty before attempting lo_close.
2011-01-10 00:11:14 +00:00
Daniele Varrazzo
38641b93ea Test decorator moved into the test utilities module 2011-01-09 23:44:58 +00:00
Daniele Varrazzo
15a09da96d Added license to unit tests
As the test suite is now part of the source distribution.
2011-01-09 23:44:35 +00:00
Daniele Varrazzo
f8c4335f35 Avoid ResourceWarning in tests in Python 3.2 2011-01-08 23:54:48 +00:00
Daniele Varrazzo
43c8fce45c Silence warnings due to deprecated TestCase methods
With a veiled criticism.
2011-01-08 23:54:17 +00:00
Daniele Varrazzo
ac5cde8834 Only use absolute imports in the package
In Python 3.2b2 the relative imports are not converted into explicit
ones (with .).
2011-01-08 01:24:28 +00:00
Daniele Varrazzo
9deb16484d Don't define a CObject API in Python 3.2
The API is not available: a PyCapsule should be used. Nobody seems
needing it for now.
2011-01-08 01:24:16 +00:00
Daniele Varrazzo
7c1b03bd45 All tests made executable. 2011-01-07 00:58:29 +00:00
Daniele Varrazzo
b8c8cddc2d Fixed argument parsing in lobject.read
Using an int instead of a Py_ssize_t randomly crashed Python 3.1 64 bit.
2011-01-04 02:27:02 +01:00
Daniele Varrazzo
80bd6e2794 Merge branch 'python2' into python3
Conflicts:
	NEWS-2.3
	psycopg/connection_type.c
	tests/test_connection.py
	tests/types_basic.py
2011-01-03 21:43:02 +01:00
Daniele Varrazzo
627df15995 Merge branch 'noleak' into python2 2011-01-03 21:39:35 +01:00
Daniele Varrazzo
8d44d0f1c7 Mention refcount fixes in NEWS files 2011-01-03 21:34:49 +01:00
Daniele Varrazzo
abd7991968 Fixed refcount bug with connection destroyed in a 2PC transaction 2011-01-03 21:34:49 +01:00
Daniele Varrazzo
5f6e773575 Broken circular reference in async execution
If a connection is destroyed before an async operation is completed, the
`async_cursor` member creates a reference loop, leaving the connection and
the cursor alive. `async_cursor` is now a weak reference.
2011-01-03 21:34:49 +01:00
Daniele Varrazzo
19ff51ae75 The cursor is weakly referenceable 2011-01-03 21:34:49 +01:00
Daniele Varrazzo
04cf90cc21 The connection is weakly referenceable 2011-01-03 21:34:49 +01:00
Daniele Varrazzo
5888b03608 Fixed "historical" reference leak in TimestampFromTicks
Added an internal function with C signature to avoid the creation of a
tuple to be later unpacked. When the tuple was decref'd, Python 2.4 64
bits regularly segfaulted; Python 2.5 less regularly; don't know about
other versions.
2011-01-03 21:34:49 +01:00
Daniele Varrazzo
8b0af283f6 Don't register the unicode typecaster globally during tests
It can invalidate the results in further runs in the same process.
2011-01-03 21:34:49 +01:00
Daniele Varrazzo
131c6a25e9 Unregister test adapters to keep a more precise references count 2011-01-03 21:34:46 +01:00
Daniele Varrazzo
a44441f5e5 Added script to look for refcounting bugs 2011-01-03 21:34:46 +01:00
Daniele Varrazzo
a01700d478 Fixed test suite execution as a script
Don't know why I changed the defaultTest argument into a function when I
converted the test suite into a package: that argument should be really
a string.
2011-01-03 20:45:03 +01:00
Daniele Varrazzo
39dd577c90 Use the proper printf placeholders to avoid warnings on 64 bit builds 2011-01-03 20:44:57 +01:00
Daniele Varrazzo
68305a0eb6 Fixed TYPE adaptation to basic tuples
Tuples and namedtuples have different constructors.
2011-01-03 19:27:26 +01:00
Daniele Varrazzo
b276e3b05d Fixed compiling on Python versions before 2.6
Added a few macros not defined in Py 2.4. Don't know about 2.5.
2011-01-03 19:18:50 +01:00
Daniele Varrazzo
9eae66e8cf Added Py3 compatibility macro for Py_TPFLAGS_HAVE_WEAKREFS 2011-01-03 16:56:26 +01:00
Daniele Varrazzo
929d62053a Merge branch 'python2' into python3
Conflicts:
	NEWS-2.3
	setup.py
2011-01-02 03:28:00 +01:00
Daniele Varrazzo
7e9be4c133 Added Python 3 trove classifier. 2011-01-02 03:26:31 +01:00
Daniele Varrazzo
3cc8719998 Added missing test to the test suite. 2011-01-02 03:00:44 +01:00
Daniele Varrazzo
17f69ba735 Fixed Makefile dependencies of the test suite. 2011-01-02 03:00:32 +01:00
Daniele Varrazzo
afb87bb10a Fixed "building" of purelib files with make.
Using build instead of build_py forced build_ext to run too, which may
fail to run as the option PG_CONFIG is not passed (or, worse, we may end
up building against the wrong pg_config).

Also touching the target file as make seems considering the source file
newer than the destination when the timestamp is the same (as it is
because the file is usually just copied).
2011-01-02 02:44:56 +01:00
Daniele Varrazzo
d08bfcbee5 Refuse to build if pg_config is not found.
I think half of the problems in OS X setup are due to setup going ahead
even when the pg_config is not found. We are now only building with PG
version that make the tool available.
2011-01-02 02:01:53 +01:00
Daniele Varrazzo
88bb8eda3e None/IN adaptation ported to Python 3. 2011-01-02 00:44:14 +01:00
Daniele Varrazzo
45c6dfb69d Merge branch 'adapt-type' into python2 2011-01-02 00:35:59 +01:00
Daniele Varrazzo
7ac0bdd661 Added PostgreSQL composite types typecaster to Python tuples. 2011-01-02 00:34:13 +01:00
Daniele Varrazzo
159cda3688 Added cursor.cast() method
The method exposes the typecasters lookup algorithm. Useful to create
recursive typecasters.
2011-01-01 22:55:10 +01:00
Daniele Varrazzo
3e94375cf7 Merge branch 'python2' into python3
Conflicts:
	ChangeLog
	NEWS-2.3
	lib/extensions.py
	psycopg/microprotocols.c
	setup.py
2011-01-01 17:14:54 +01:00
Daniele Varrazzo
f9be48d89e Merge branch 'none-in-composite' into python2 2011-01-01 17:09:37 +01:00
Daniele Varrazzo
fdfa2de1a1 Fixed adaptation of None in composite types (ticket #26).
Added an adapter for None: it is usually not invoked as adaptation to
NULL is a fast path in mogrify, but can be invoked by composite types.
Notice that composite types still have the option to fast-path None
(e.g. list adapter does).
2011-01-01 17:07:54 +01:00
Daniele Varrazzo
506ce93a5b Bump to the next dev version. 2011-01-01 12:55:41 +01:00
Daniele Varrazzo
30921b58a8 Dropped conversion from None to NULL in adapter.
It was an error as the string is not conform to the protocol. The error
is masked by the None fast path in _mogrify, but surfaces when adapting
a tuple contains a None.
2010-12-31 18:55:33 +01:00
Daniele Varrazzo
b5a8facb9c Added test to show failed adaptation of None in records. 2010-12-31 18:54:50 +01:00
Daniele Varrazzo
ac25816962 Use the same Bytes_Format function for both Python 2 and 3.
This makes the behaviour between the two versions similar. It also have
the effect of a more specific error message in case an user specifies a
placeholder different from 's'.
2010-12-31 03:22:19 +01:00
Daniele Varrazzo
2930ed3d59 Dropped support for all format specifiers except s in PyBytes_Format. 2010-12-31 03:18:27 +01:00
Daniele Varrazzo
6882ac31d4 Dropped warnings in PyBytes_Format function. 2010-12-31 03:18:27 +01:00
Daniele Varrazzo
96a950d3eb Fixed 2-phase commit support in Python 3. 2010-12-31 03:18:27 +01:00
Daniele Varrazzo
89fb60de4b Column names in copy methods can be unicode. 2010-12-31 03:18:27 +01:00
Daniele Varrazzo
73917c15e1 Fixed COPY FROM to deal with decoded files. 2010-12-31 03:18:27 +01:00
Daniele Varrazzo
bc28cc8b00 Use unicode keys as strings in Py3.
This fixes pyformat style argument passing. Unicode and bytes don't
compare equal (even if they hash the same).
2010-12-31 03:18:27 +01:00
Daniele Varrazzo
0a4eeb4e13 Fixed notification tests to run on Py3.
Call 2to3 on the dynamically generated scripts.
2010-12-31 03:18:27 +01:00
Daniele Varrazzo
b78ff4a273 Several tests ported to Python 3. 2010-12-31 03:18:27 +01:00
Daniele Varrazzo
2fa9117835 Inet adapter compatible with Python 3. 2010-12-31 03:18:27 +01:00
Daniele Varrazzo
c176de4bf8 Hstore adapter compatible with Python 3. 2010-12-31 03:18:27 +01:00
Daniele Varrazzo
89c492d3a4 Added b() function to return bytes in both Py2 and Py3. 2010-12-31 03:18:27 +01:00
Daniele Varrazzo
061079c918 In Py3, decode the tuple values before passing to the typecaster.
Not sure this is the best way to go: it is now impossible to write a
binary typecaster in Python; furthermore it is the opposite approach of
the codecs, which should return bytes.
2010-12-31 03:18:27 +01:00
Daniele Varrazzo
ab5934dc35 Use ascii_letters instead of letters.
The latter is locale-dependent and not available on Py3.
2010-12-31 03:18:27 +01:00
Daniele Varrazzo
01565fa6c5 Added tests to verify a couple of incomplete encodings. 2010-12-31 03:18:27 +01:00
Daniele Varrazzo
f6fefbea64 Function psycopg_ensure_bytes converted in a "filter" stealing a ref. 2010-12-31 03:18:27 +01:00
Daniele Varrazzo
3214c23f51 Fixed adaptation in several adapters.
The getquoted methods always return bytes. The str() convert this
representation to string on the fly.
2010-12-31 03:18:27 +01:00
Daniele Varrazzo
2e22eef727 Added utility function to convert bytes to string in Python 3. 2010-12-31 03:18:27 +01:00
Daniele Varrazzo
d3f3f1caf0 Added utility method to return a string in the connection encoding.
In Py2 the result is plain string, in Py3 an unicode decoded in the
connection encoding.
2010-12-31 03:18:27 +01:00
Daniele Varrazzo
60841c6567 Added regression test on bool adaptation. 2010-12-31 03:18:27 +01:00
Daniele Varrazzo
beba064983 Test on basic adapters pass on Python 3. 2010-12-31 03:18:26 +01:00
Daniele Varrazzo
56e4c2bd55 Redefining the microprotocol on Py3 as returning bytes. 2010-12-31 03:18:26 +01:00
Daniele Varrazzo
014b6a6d5b Use psycopg_ensure_bytes() to unify Py2/3 code paths. 2010-12-31 03:18:26 +01:00
Daniele Varrazzo
89e4d4c7bb Empty lists correctly roundtrip. 2010-12-31 03:18:26 +01:00
Daniele Varrazzo
b5ef5ef21d Added typecasters repr(). 2010-12-31 03:18:26 +01:00
Daniele Varrazzo
b4685bba4a Added utility function to get bytes from a str/unicode. 2010-12-31 03:18:26 +01:00
Daniele Varrazzo
03dde732f6 Datetime adaptation in bytes. 2010-12-31 03:18:26 +01:00
Daniele Varrazzo
87a7ebac10 Query mogrification in bytes. 2010-12-31 03:18:26 +01:00
Daniele Varrazzo
c3196ebd9d Added PyBytes_Format function. 2010-12-31 03:18:26 +01:00
Daniele Varrazzo
e18f1c63ea Deal with slices passed to __*item__ in Python 3. 2010-12-23 03:28:19 +01:00
Daniele Varrazzo
ade1b2cc7b Test suite converted into a proper package.
Dropped cyclic import from modules to tests: they were only working
because a second copy of the package was found in the project dir.
Use relative import so that 2to3 can do a good conversion.
2010-12-21 05:02:19 +00:00
Daniele Varrazzo
f697410ab4 The tests are run from the external of the package.
If __init__ is treated as a script, relative import fail.
2010-12-21 04:49:16 +00:00
Daniele Varrazzo
cb6b52945b The library can be compiled with Python 3.
Just compiled! No test run yet and many points to review, marked in the
code.

The patch is largely Martin von Löwis work, simplified after refactoring
in the previous commits and adapted to the new code (as the patch was
originally for Psycopg 2.0.9)
2010-12-21 04:24:36 +00:00
Daniele Varrazzo
e182201e6e Added Python codec name to the connection.
This allows dropping repeated dictionary lookups with unicode
query/parameters.
2010-12-21 04:02:14 +00:00
Daniele Varrazzo
ae06fb03e7 Added psycopg_strdup utility function. 2010-12-21 04:02:14 +00:00
Daniele Varrazzo
a50a91fc7b No need to put connection fields to zero: tp_alloc already did. 2010-12-21 04:02:14 +00:00
Daniele Varrazzo
7b5d80d36d Added a few missing encodings.
EUC_CN, EUC_JIS_2004, ISO885910, ISO885916, LATIN10, SHIFT_JIS_2004.
2010-12-21 04:02:14 +00:00
Daniele Varrazzo
657bcb4828 Encodings mapping reordered in a more maintainable order. 2010-12-21 04:02:14 +00:00
Daniele Varrazzo
b96dcef8a2 Fixed PG -> Py encodings mapping with non-alnum chars.
We mangle the encoding names a little bit before asking it to the
backend: be sure to be able to find the equivalent Python code back or
decoding (unicode cast or Py3) will barf.
2010-12-21 04:02:14 +00:00
Daniele Varrazzo
4635c2aa4f Import structmember/stringobject headers from python.h.
stringobject is not to be imported with Python 3.
2010-12-21 04:02:13 +00:00
Daniele Varrazzo
9b30147341 Using PyVarObject_HEAD_INIT macro. 2010-12-21 04:02:13 +00:00
Daniele Varrazzo
8dfa9915eb Using Py_TYPE and Py_REFCNT macros. 2010-12-21 04:02:13 +00:00
Daniele Varrazzo
2196ff5488 Added a few compatibility macros defined in Py 2.6. 2010-12-21 04:02:13 +00:00
Daniele Varrazzo
9b29282ee4 'make check' runs the test in the build directory.
This way tests can be run win Py3 too, as the setup 2to3s them.
2010-12-21 04:02:13 +00:00
Daniele Varrazzo
31093a7a58 Some light cleanup for Py3 conversion.
Either flagged as warning by python2.6 -3 or converted by 2to3.
2010-12-21 04:02:13 +00:00
Federico Di Gregorio
69c66a3a3f Preparing release 2.3.2 2010-12-20 13:33:21 +01:00
Daniele Varrazzo
ddd2de0410 Updated ChangeLog/NEWS after ticket #24 patch commit. 2010-12-18 15:38:56 +00:00
Marti Raudsepp
a08419406c Don't segfault when PQparameterStatus(DateStyle) returns NULL
pgbouncer for example does not pass on DateStyle.
2010-12-18 15:27:15 +00:00
Daniele Varrazzo
5a0cfad95f Bump to next dev version. 2010-12-18 15:25:53 +00:00
Daniele Varrazzo
a30e461038 The Makefile can run with both Python 2 and 3. 2010-12-12 16:20:02 +00:00
Daniele Varrazzo
8a1fa9d3a0 setup.py compatible with both python 2 and 3. 2010-12-12 15:08:28 +00:00
Daniele Varrazzo
ec182e818e Added list of files the extension depends on. 2010-12-12 14:38:25 +00:00
Daniele Varrazzo
89f70bdb3c Changed Python const RO -> READONLY. 2010-12-12 13:39:32 +00:00
Daniele Varrazzo
6d7916cfe1 Internal imports simplified.
.c files only need to import psycopg.h: it will in turn import
dependencies from Python and libpq and configure.h. psycopg.h should be
the first to be imported, so the basic imports are not required in
the .h's

As a guideline I'm trying to import from the most specific to the most
generic to detect missing imports in the .h's.
2010-12-12 13:39:32 +00:00
Daniele Varrazzo
9fa1eac2b4 Dropped unused include file. 2010-12-12 13:39:32 +00:00
Daniele Varrazzo
0fbbd1cc91 Bump to next dev version. 2010-12-12 13:39:32 +00:00
Daniele Varrazzo
cf243ccf37 Shorter "never ending query" to test query canceling.
If the cancel signal misses the race, this query will stay in the
backend until the sleep expires.
2010-12-04 23:21:16 +00:00
Daniele Varrazzo
13c2f5a78b Added target to package the docs for PyPI documentation. 2010-12-04 23:14:03 +00:00
Daniele Varrazzo
9e9933faed Update classifier URLs for PyPI. 2010-12-04 23:14:03 +00:00
Federico Di Gregorio
ee5015a30b Preparing release 2.3.1 2010-12-04 21:24:02 +01:00
Daniele Varrazzo
557e28d744 Dropped interface for two private functions.
Note: the functions are private because typecast.c imports the .c's of
typecast_[mx]datetime, not the .h's.

Work around the warning for 'skip_until_space' not used with an #ifdef.
Furthermore, those functions are now static.
2010-12-04 13:51:21 +00:00
Daniele Varrazzo
288f9ee809 Work around CentOS 5.5 x86_64 buld problem.
Closes ticket #23
2010-12-04 13:51:21 +00:00
Daniele Varrazzo
ebd73c14a8 Going to dev version for 2.3.1. 2010-12-04 13:43:28 +00:00
Daniele Varrazzo
9c71a9c6e5 Added link to psycogreen. 2010-12-02 17:13:13 +00:00
Daniele Varrazzo
bde523695a Fixed index entries of green-related terms. 2010-12-02 15:15:31 +00:00
Daniele Varrazzo
4bd8f8c76b Typo/tenso fixed. 2010-12-02 15:07:17 +00:00
Daniele Varrazzo
593cd20b4a Added index entries under Adaptation for different objects. 2010-12-02 15:06:27 +00:00
Federico Di Gregorio
2dae07a796 Preparing release 2.3.0 2010-12-02 14:41:58 +01:00
Daniele Varrazzo
46a5f140c7 Bail out early from tests if connection to the test db fails. 2010-12-01 20:56:25 +00:00
Federico Di Gregorio
5f80dd38c4 Removed runtests target; checks is the default for Makefiles 2010-12-01 21:55:42 +01:00
Federico Di Gregorio
a411f85354 Removed default test database from Makefile
The default is already in test/__init__.py and the Makefile was
overwriting the PSYCOPG2_TESTDB env variable.
2010-12-01 21:29:33 +01:00
Federico Di Gregorio
f981e81813 Merge remote branch 'piro/python2' into python2 2010-12-01 19:47:44 +01:00
Daniele Varrazzo
6688e7011c Typos fixed in the news. 2010-12-01 13:21:16 +00:00
Daniele Varrazzo
0ad7483a2b DictRow items can be updated. Patch by Alex Aster. 2010-12-01 13:17:12 +00:00
Daniele Varrazzo
6f2d40405e Added documentation for ISQLQuote.prepare(). 2010-11-28 18:26:30 +00:00
Daniele Varrazzo
361786f4a8 More careful connections handling during tests. 2010-11-28 17:29:37 +00:00
Daniele Varrazzo
598b9424d2 Deal uniformly with test servers without pg_sleep. 2010-11-28 17:29:36 +00:00
Daniele Varrazzo
2b6d2017ed Added paranoia test to check we haven't broken gil release.
Got scared testing cancel with a signal as it doesn't work. But probably
signals are not deliveded to Python in the middle of an opcode.
2010-11-28 17:29:35 +00:00
Daniele Varrazzo
0c7b0a943b A prepared connection can't be canceled. 2010-11-28 12:15:26 +00:00
Daniele Varrazzo
4dbd4344a3 Mention query cancelling in the release notes. 2010-11-28 12:14:04 +00:00
Jan Urbański
751bfa1ea6 Support query cancellation.
Add a cancel() method do the connection object that will interrupt
the current query using the libpq PQcancel() function.
2010-11-28 11:50:02 +00:00
Daniele Varrazzo
9f78141532 Don't consider the kernel not blocking us on write as an error. 2010-11-25 03:13:49 +00:00
Daniele Varrazzo
5a025825cc Skip test if uuid not available on Python. 2010-11-24 11:04:18 +00:00
Daniele Varrazzo
bb44bcd5b5 Skipped inf test on the platform not supporting it (win32). 2010-11-24 10:50:28 +00:00
Daniele Varrazzo
1fd6b84068 Added test suite to the distributed package. 2010-11-24 03:36:57 +00:00
Daniele Varrazzo
fdf1ba1aac Dropped notices hack to get COPY errors from V2 protocol. 2010-11-22 00:49:07 +00:00
Daniele Varrazzo
7fe7b669aa Added instructions about running tests and building docs. 2010-11-20 01:14:41 +00:00
Daniele Varrazzo
6f51eefac3 Dropped references to psycopg 1 from readme and install.
Nowaday not many remember it: I think it's useless to make comparisons.
2010-11-20 01:14:05 +00:00
Daniele Varrazzo
ed3b2188fe Fixed import of test functions from Python 2.7 unittest. 2010-11-19 18:01:29 +00:00
Daniele Varrazzo
bbe28ba75f Add a small delay to receive notification when testing on busy network. 2010-11-19 14:44:47 +00:00
Daniele Varrazzo
f2c5d04f39 Fixed docs: the execute argument must be a sequence, not a tuple. 2010-11-19 13:13:14 +00:00
Daniele Varrazzo
21dfc2c592 Float test skipped where the server doesn't support inf. 2010-11-19 10:44:39 +00:00
Daniele Varrazzo
a55e50b991 hstore test passes against non-utf8 databases. 2010-11-19 10:29:07 +00:00
Daniele Varrazzo
19ead4a5cb Test cleanup.
Tests pass or fail gracefully on older PostgreSQL versions.

If unittest2 is available, skip tests instead of printing warnings.
2010-11-19 03:55:37 +00:00
Daniele Varrazzo
94348bfb78 hstore registration doesn't fail if typarray column not available. 2010-11-19 03:51:53 +00:00
Daniele Varrazzo
163cf5bfb4 mx.DateTime module initialized as it is supposed to be.
No need to pass the api pointer around. Dropped compiler warnings.
2010-11-19 00:28:49 +00:00
Daniele Varrazzo
3e3aa676a9 datetime module initialized as it is supposed to be.
Dropped compiler warnings. It wouldn't blow up if any api was called.
No need to pass type pointers around.
2010-11-19 00:28:39 +00:00
Daniele Varrazzo
576b01f6a3 Functions exported to drop warnings. 2010-11-19 00:20:49 +00:00
Daniele Varrazzo
67793ed989 Compiler warning dropped. 2010-11-18 23:13:16 +00:00
Daniele Varrazzo
bcacdc8461 Added enum with possilbe isolation level states.
Also, general isolation levels cleanup and tests added.
2010-11-18 00:31:51 +00:00
Daniele Varrazzo
4074635629 Moved links to PG docs from 8.4 to 9.0. 2010-11-17 23:05:10 +00:00
Daniele Varrazzo
454c6b8915 Moved links to PG docs from 8.4 to 9.0. 2010-11-17 02:59:03 +00:00
Daniele Varrazzo
c3c54aab38 Don't clobber exception if conn_switch_isolation_level fails.
Which shouldn't.
2010-11-17 01:43:50 +00:00
Daniele Varrazzo
9849083628 Added tests to check the effective isolation level. 2010-11-17 01:04:34 +00:00
Daniele Varrazzo
e1a04bec0e Don't inconditionately run a query at connection to set datestyle to ISO.
Run it only if PQparameterStatus() reports the datestyle is set to
something different.
2010-11-16 18:15:00 +00:00
Daniele Varrazzo
15bba2966f Don't run a query at connection to detect client encoding.
Use PQparameterStatus() instead. This is only guaranteed in protocol 3.
2010-11-16 10:16:52 +00:00
Daniele Varrazzo
a88d7ab424 Dropped support for protocol 2.
Dropped both the setup constant allowing conditional compiling and the
code specific to V2 protocol (mostly COPY and error handling).
2010-11-16 01:08:50 +00:00
Daniele Varrazzo
73265e7ece Refuse connection with server with protocol version 2.
This cuts off server whose version is older than 7.4. But enables us to
remove large portions of code rarely used and tested (e.g. p2 copy) and
will allow us to drop the query we do at each connection to establish
the client encoding and the datestyle.
2010-11-16 01:01:32 +00:00
Daniele Varrazzo
58079c6c91 Fixed dependencies of the sdist target 2010-11-15 09:35:28 +00:00
Daniele Varrazzo
0a2856477c The Makefile can receive the pg_config location. 2010-11-14 18:23:09 +00:00
Daniele Varrazzo
b25af6311c Makefile included in sdist. 2010-11-14 02:18:57 +00:00
Daniele Varrazzo
78dfbfb94a Fixed dependencies to build the docs. 2010-11-13 20:31:53 +00:00
Daniele Varrazzo
d07791cfe9 Fixed setuptools installation from scratch. 2010-11-13 20:01:48 +00:00
Daniele Varrazzo
988861a2d8 runtests.py script dropped.
It was broken as the distutils changed the name of the build dir
somewhere along the way. Use ``make runtests`` instead.
2010-11-13 19:50:25 +00:00
Daniele Varrazzo
9ffcb90038 Added flesh to the Makefile.
Now it can be used to build, make the docs (including installing
dependencies), run the tests, build the sdist.
2010-11-13 19:45:45 +00:00
Jean-Baptiste Quenot
b8ce51d9c2 Mention connection object in debug logs 2010-11-13 03:56:23 +00:00
Daniele Varrazzo
cd19f9115d Fixed notices order (ticket #9). 2010-11-11 11:54:43 +00:00
Daniele Varrazzo
3cae0f3f5d NamedTupleCursor doesn't change exception when fetching with no result. 2010-11-11 10:39:42 +00:00
Daniele Varrazzo
ef7a5ee8a9 Build the namedtuple only once per execution, not once per fetch. 2010-11-11 10:39:42 +00:00
Daniele Varrazzo
11c021cb21 Fixed tests to run on Windows. 2010-11-11 10:39:35 +00:00
Daniele Varrazzo
92ee893f0f Functions unused outside the module marked static. 2010-11-10 15:50:05 +00:00
Federico Di Gregorio
cf07af5ff5 Version bump to 2.3.0-beta2 2010-11-09 18:51:46 +01:00
Daniele Varrazzo
a39e98f9e5 Check the presence of a mro.
The mere presence of the Py_TPFLAGS_HAVE_CLASS doesn't ensure it is
there.
2010-11-09 14:28:00 +00:00
Daniele Varrazzo
f0773d5682 Avoid pointless string manipulation in NamedTupleCursor.
Closes ticket #10. Reported by Marko Kreen.
2010-11-09 11:17:02 +00:00
Daniele Varrazzo
ed6a4c8b1a Dropped PyArg_ParseTuple() calls in functions taking no arguments. 2010-11-09 03:18:54 +00:00
Daniele Varrazzo
2dc28ee7d8 Less lookups and more efficient calls in microprotocols_adapt().
Also more explicit handling of the exception indicator.
2010-11-09 02:41:43 +00:00
Daniele Varrazzo
753b580d72 Less lookups and more efficient calls in microprotocols_getquoted(). 2010-11-09 02:21:21 +00:00
Daniele Varrazzo
422fede38e Replaced PyObject_CallFunction() with *ObjArgs() where more efficient. 2010-11-09 01:49:22 +00:00
Daniele Varrazzo
9fe0511711 Silencing other 2 tests failures due to 2pc disabled in the server. 2010-11-09 01:44:42 +00:00
Jason Erickson
c79d20855a Win32 *time_r fix
Fixed the thread safetyness of the Windows *time_r functions.
2010-11-09 00:20:58 +00:00
Daniele Varrazzo
d601ab8239 fixed crash in pdecimal_str with a few Python 2.5.x releases.
is_finite() is not available in 2.5.1, it is in 2.5.5 but is officially
supported only since 2.6.
2010-11-09 00:14:22 +00:00
Daniele Varrazzo
0d318179a9 Fixed test syntax for py 2.4. 2010-11-09 00:09:32 +00:00
Daniele Varrazzo
af3681cc1c Fixed repr for Decimal wrapper. 2010-11-09 00:09:19 +00:00
Daniele Varrazzo
916c172cf7 Dropped file imported by mistake. 2010-11-09 00:09:09 +00:00
Daniele Varrazzo
62d3a1533b Use the adapter of an object superclass if available. 2010-11-08 01:35:06 +00:00
Daniele Varrazzo
225b276de5 Use faster function to build tuples in adaptation.
Fixed a refcount bug too.
2010-11-08 01:28:01 +00:00
Daniele Varrazzo
df05ea7a33 Py_TYPE defined as it is in Python 2.6. 2010-11-08 01:28:01 +00:00
Daniele Varrazzo
b9e96dbbd2 Added version info to Xid object docs. 2010-11-08 01:28:01 +00:00
Daniele Varrazzo
2f582da1f0 Notifcation example improved. 2010-11-08 01:28:00 +00:00
Daniele Varrazzo
7276c4a6b1 Tests fail gracefully if tpc is supported but disabled by the server. 2010-11-08 01:28:00 +00:00
Federico Di Gregorio
645ab521f3 Preparing release 2.3.0-beta1
* Merged NEWS-2.3 and NEWS-2.2: 2.0 (pre-async) still makes sense in case
  someone has horrible problems with the new code but 2.3 will just
  substitute 2.2 so having a separated NEWS file doesn't make sense.

* Moved authors and contributors to AUHTORS file.

* README now has pointers to web site and bug tracker.

* Updated MonoDevelop project.
2010-11-06 15:50:39 +01:00
Daniele Varrazzo
4ea9dbdcf0 Typo fixed 2010-11-06 04:40:47 +00:00
Daniele Varrazzo
abad3127ca Added NamedTupleCursor. 2010-11-06 04:33:44 +00:00
Daniele Varrazzo
985425fb38 Added test to verify the ticket #7 is fixed. 2010-11-06 02:24:28 +00:00
Daniele Varrazzo
5b65e75122 Docs expansions about thread/processes safety. 2010-11-05 23:58:10 +00:00
Daniele Varrazzo
4125b3fce0 Added compatibility macro for pre 2.6 2010-11-05 12:59:32 +00:00
Daniele Varrazzo
04b4649d03 Updated version 2.2.3 -> 2.3 in the docs. 2010-11-05 12:38:49 +00:00
Daniele Varrazzo
ee71e52269 Added news file for new release. 2010-11-05 10:07:25 +00:00
Daniele Varrazzo
40377a18af Updated classifier to make the upload work. 2010-11-05 10:06:54 +00:00
Daniele Varrazzo
274ff8bb1d Dropped reference to removed TODO file: it breaks 'pip'. 2010-11-05 09:40:02 +00:00
Daniele Varrazzo
d6cdc1c7b6 Bump to 2.3.dev0 2010-11-05 09:34:53 +00:00
Daniele Varrazzo
2480f587e1 Added warning note about equivalence inconsistence between Notify and tuples. 2010-11-05 09:34:52 +00:00
Daniele Varrazzo
77c0ab02d8 The Notify type is hashable.
If there is no payload, hash the same way the equivalent 2-tuple does.
Otherwise hash on the payload too.
2010-11-05 09:34:52 +00:00
Daniele Varrazzo
56ae1fe4bf Payload default is the empty string. 2010-11-05 09:34:52 +00:00
Daniele Varrazzo
9c58c01e0f Added comparison between Notify objects and Notify or tuple.
Explicit comparison with the tuple is required if we want to make
Notify() == (pid, channel) work: item access is not enough (and a test
in the suite fails if we get this wrong).
2010-11-05 09:34:52 +00:00
Daniele Varrazzo
6cb949d371 Try to install the hstore type in the test database. 2010-11-05 09:34:52 +00:00
Daniele Varrazzo
1b100b5cbf Skip tests if the hstore type is not in the test database. 2010-11-05 09:34:52 +00:00
Daniele Varrazzo
01ec120aa8 Hstore documentation improved. 2010-11-05 09:34:52 +00:00
Daniele Varrazzo
4b98e8941f Added some documentation for the hstore adaptation. 2010-11-05 09:34:52 +00:00
Daniele Varrazzo
d5bf400cb4 The hstore typecast can be registered globally. 2010-11-05 09:34:52 +00:00
Daniele Varrazzo
bb41acd1da Favour the PG9 implementation of the hstore adapter. 2010-11-05 09:34:51 +00:00
Daniele Varrazzo
ed623776f3 Hstore can return unicode keys and values. 2010-11-05 09:34:51 +00:00
Daniele Varrazzo
00e005b77d Added test to verify dict roundtrip with hstore. 2010-11-05 09:34:50 +00:00
Daniele Varrazzo
af835f8857 Correctly parse escaped quotes from hstore.
Parse regexp simplified.
2010-11-05 09:34:50 +00:00
Daniele Varrazzo
70880dde79 Added special cases to store empty dicts. 2010-11-05 09:34:50 +00:00
Daniele Varrazzo
6d441b6e03 Added hstore typecaster registration. 2010-11-05 09:34:50 +00:00
Daniele Varrazzo
fef9727cce parse_hstore converted in class method. 2010-11-05 09:34:50 +00:00
Daniele Varrazzo
5844e989c4 Added function to parse an hstore into a dict. 2010-11-05 09:34:50 +00:00
Daniele Varrazzo
5693c9cab1 Added implementation of python dict adapter to hstore. 2010-11-05 09:34:50 +00:00
Daniele Varrazzo
90e0e2f47d Added documentation for the Xid object. 2010-11-05 09:34:50 +00:00
Daniele Varrazzo
3e658c33b5 Ensure unicode is accepted as type for transaction ids.
We don't do somersaults to ensure people can use snowmen as transaction
ids anyway: it would require passing the connection to xid_ensure and
down below to use the correct encoding.
2010-11-05 09:34:50 +00:00
Daniele Varrazzo
4f3976681a Added Xid.from_string() constructor.
It exposes the parsing rules used in restore.
2010-11-05 09:34:49 +00:00
Daniele Varrazzo
2f29429e88 Expose the Xid object in the extension module. 2010-11-05 09:34:49 +00:00
Daniele Varrazzo
f0f5f095c7 Fixed handling of commit/rollback prepared in green mode 2010-11-05 09:34:49 +00:00
Daniele Varrazzo
a923a16ae8 Added two-phase commit docunetation. 2010-11-05 09:34:49 +00:00
Daniele Varrazzo
5dbeeba0f2 Raise NotSuppoertdError if tpc is used with PostgreSQL < 8.1 2010-11-05 09:34:49 +00:00
Daniele Varrazzo
ab8e145063 Encoding/decoding in base64 refactored. 2010-11-05 09:34:49 +00:00
Daniele Varrazzo
3312897e5d Added str() and repr() for Xid objects. 2010-11-05 09:34:49 +00:00
Daniele Varrazzo
4fdcfe365c xid_get_tid returns a Python string, not a buffer. 2010-11-05 09:34:49 +00:00
Daniele Varrazzo
774be1d616 Dropped XID_UNPARSED: we use format_id = None for PG xact ids. 2010-11-05 09:34:49 +00:00
Daniele Varrazzo
978cac3a1b XA transaction ids can be decoded from PostgreSQL transaction ids. 2010-11-05 09:34:48 +00:00
Daniele Varrazzo
6309e038e5 Dropped pg_xact_id from XidObject 2010-11-05 09:34:48 +00:00
Daniele Varrazzo
c0c116dcc4 Use pgjdbc algorithm to convert XA xids into strings. 2010-11-05 09:34:48 +00:00
Daniele Varrazzo
17d70babb1 Keep the GIL while converting the xid into the PostgreSQL transaction id. 2010-11-05 09:34:48 +00:00
Daniele Varrazzo
397eace051 Added tests for two-phase commit/rollback. 2010-11-05 09:34:48 +00:00
Daniele Varrazzo
56c02b0f94 Added tpc_recover method. 2010-11-05 09:34:48 +00:00
Daniele Varrazzo
09983db6ed Added tpc_commit and tpc_rollback methods. 2010-11-05 09:34:48 +00:00
Daniele Varrazzo
4f66de494b Added tpc_prepare and CONN_STATUS_PREPARED. 2010-11-05 09:34:48 +00:00
Daniele Varrazzo
4588fa50f2 begin and commit can't be called during a two-phase transaction. 2010-11-05 09:34:48 +00:00
Daniele Varrazzo
98c5b1d374 Added tpc_begin() and current xid on connection. 2010-11-05 09:34:48 +00:00
Daniele Varrazzo
60ee39fa3d Copyright of TPC files moved to LGPL V3.
With the permission of James Henstridge.
2010-11-05 09:34:47 +00:00
Daniele Varrazzo
8bfd34faf2 hook up two phase commit tests.
By James Henstridge on 2008-07-24.

Merged from lp:~jamesh/psycopg/two-phase-commit/revision/359
2010-11-05 09:34:47 +00:00
Daniele Varrazzo
7a9d678050 There is no point in allowing subclasses of Xid.
By James Henstridge on 2008-07-24.

Merged from lp:~jamesh/psycopg/two-phase-commit/revision/358
2010-11-05 09:34:47 +00:00
Daniele Varrazzo
22aea9114b implement sequence behaviour, as required for transaction IDs.
By James Henstridge on 2008-07-24.

Merged from lp:~jamesh/psycopg/two-phase-commit/revision/357
2010-11-05 09:34:47 +00:00
Daniele Varrazzo
0021e56d80 Added connection.xid() and related objects.
By James Henstridge on 2008-07-23.

Merged from lp:~jamesh/psycopg/two-phase-commit/revision/356

* psycopg/connection_type.c (psyco_conn_xid): add a
Connection.xid() method that instantiates Xid objects.

* psycopg/psycopgmodule.c (init_psycopg): initialise the Xid
object type.

* psycopg/xid.h:
* psycopg/xid_type.c: Implement a basic transaction ID object for
use in two phase commit.
2010-11-05 09:34:47 +00:00
Daniele Varrazzo
e863222b5c beginnings of a TPC test harness
By James Henstridge on 2008-05-12.

Merged from lp:~jamesh/psycopg/two-phase-commit/revision/354
2010-11-05 09:34:47 +00:00
Daniele Varrazzo
1a0fca09d9 Added documentation for the Notify object. 2010-11-05 09:34:47 +00:00
Daniele Varrazzo
4ec298e112 Notify object exposed in the extensions module. 2010-11-05 09:34:47 +00:00
Daniele Varrazzo
8db9c7085d Added repr method for Notify object. 2010-11-05 09:34:47 +00:00
Daniele Varrazzo
f435d15c95 Adding Notify object with payload. 2010-11-05 09:34:46 +00:00
Daniele Varrazzo
e651308287 Check the correctness of the PID in the notify tests. 2010-11-05 09:34:46 +00:00
Daniele Varrazzo
d9e49e940a Fixed versionchanged note on fractional time zone. 2010-10-31 23:57:40 +00:00
Daniele Varrazzo
7e482756c5 Use PQfreemem to free memory allocated by the libpq.
Bug reported by Anton Kovalev.
2010-10-08 14:26:40 +01:00
Daniele Varrazzo
6e71b3db05 Dropped PSYCOPG_OWN_QUOTING.
It was deprecated for version 2.1. There are bugs to be fixed made more
complex by its presence and it doesn't keep into account PostgreSQL 9.0
new binary format.

Time to go!
2010-10-08 12:27:47 +01:00
Daniele Varrazzo
baf65a0dda Fixed access to freed memory in conn_get_isolation_level().
Bug reported by Anton Kovalev.
2010-10-08 12:02:53 +01:00
Daniele Varrazzo
850cd97ab3 A few doc fixes. 2010-10-08 10:16:59 +01:00
Daniele Varrazzo
bc2aefeacf cursor.mogrify() accepts unicode queries. 2010-10-05 03:13:44 +01:00
Daniele Varrazzo
5b4d366f4e Common code in execute() and mogrify() merged. 2010-10-05 01:43:23 +01:00
Daniele Varrazzo
575b2b5f77 The Inet type knows how to adapt itself.
Implemented __conform__ as the Adaptation PEP suggests. It is not
required for the type to be registered as adapter.
2010-09-25 23:55:55 +01:00
Daniele Varrazzo
75a6f783c5 Added PostgreSQL 9.0 error codes. 2010-09-23 23:43:23 +01:00
Daniele Varrazzo
b072a04c9c DBAPI compatibility test updated to 1.12.
Nothing major: Python 3.0 compatibility fixes.
2010-09-23 23:36:58 +01:00
Daniele Varrazzo
2081ceffde Don't execute a ROLLBACK on close()/GC.
The command wasn't sent since 2.2.0 due to a bug, but after a ML
discussion this behaviour proved more correct so the bug has become a
feature.
2010-09-23 23:28:30 +01:00
Daniele Varrazzo
cb1ef242a0 Bump to version 2.2.3-devel. 2010-09-23 23:27:55 +01:00
Daniele Varrazzo
bf9e557a71 Fixed typo in docs. 2010-09-23 23:17:32 +01:00
Daniele Varrazzo
19ae49e79e Refer to PostgreSQL 9.0 documentation. 2010-09-23 23:14:39 +01:00
Daniele Varrazzo
80ebb14df4 Use stable anchors to reference PostgreSQL docs. 2010-09-23 23:13:59 +01:00
Daniele Varrazzo
9b3aa290d2 Added missing import required by Sphinx 1.0. 2010-08-05 01:08:21 +01:00
Daniele Varrazzo
660b75c2f4 Typo fixed. 2010-08-04 23:26:52 +01:00
Federico Di Gregorio
c3b835929b Preparing release 2.2.2 2010-07-18 12:32:45 +02:00
Federico Di Gregorio
557608f715 Applied spelling fixes patch from Peter Eisentraut 2010-07-18 12:14:46 +02:00
Federico Di Gregorio
b263fbf274 Added deprecation warning to register_tstz_w_secs 2010-07-13 14:26:52 +02:00
Daniele Varrazzo
deb2d9050f Exceptions raised by the columns iterator propagated. 2010-07-10 00:12:50 +01:00
Daniele Varrazzo
cb8128c6d4 Added test to verify copy_from() with columns. 2010-07-10 00:04:54 +01:00
Daniele Varrazzo
927f2bb1f1 Dropped logging.basicConfig() call.
It messes up with projects using logging but where no handler is
installed on the root logger.  Bug reported by Joe Abbate.
2010-07-09 23:23:10 +01:00
Daniele Varrazzo
3773b50bb3 Propagate iterable exceptions to the executemany caller. 2010-07-09 23:22:35 +01:00
Daniele Varrazzo
bd6a4139da Added test to verify executemany doesn't propagate exceptions. 2010-07-09 15:23:02 +01:00
Daniele Varrazzo
4a78e4068b Dropped register_tstz_w_secs() implementation.
The function is no-op now that the default type caster can deal with
seconds in the tz offset.
2010-05-20 02:18:04 +01:00
Daniele Varrazzo
305d86f38a Handle time zones with seconds in the UTC offset.
The offset is rounded to the nearest minute.
2010-05-20 02:16:04 +01:00
Daniele Varrazzo
e3d489f701 Bump to version 2.2.2-devel.
The -devel suffix appears in the docs we publish on the website, so it's
clear that they refer to the upcoming version.
2010-05-20 02:03:07 +01:00
Daniele Varrazzo
eacf6febfe Warn on declarations not at beginning of the block.
They are accepted by gcc but not by MS compilers.
2010-05-19 11:40:38 +01:00
Daniele Varrazzo
b597ccf917 Tests can be run again different coroutine libraries.
Use PSYCOPG2_TEST_GREEN=<something>, where <something> is 1 or a library
name. Currently eventlet is supported.
2010-05-19 11:40:13 +01:00
Federico Di Gregorio
23391a3c55 Preparing release 2.2.1 2010-05-17 21:51:25 +02:00
Jason Erickson
069695b4ae Additional Library for Windows linking and OpenSSL 1.0.0
Added the linking of crypt32.lib to the windows SSL build, as it seems that the current version of OpenSSL is looking for crypt32.lib as well.
2010-05-17 09:06:29 +02:00
Jason Erickson
1f1133b871 Micrsoft Visual C Compile Fix
Moved the declarations of variables/pointers to the beginning of the block, where MSVC wants them.
2010-05-17 09:06:14 +02:00
Federico Di Gregorio
e286970b62 Preparing release 2.2.0 2010-05-16 12:55:59 +02:00
Federico Di Gregorio
6521fb5a44 Fixed error related to calling C typecasters from Python ones 2010-05-15 19:34:56 +02:00
Federico Di Gregorio
36cbefdee1 Updated project and version for release 2.2.0 2010-05-15 17:51:54 +02:00
Daniele Varrazzo
a35498532a Fixed time test to be independent from the TZ it runs. 2010-05-15 14:27:24 +01:00
Daniele Varrazzo
c46a1dad63 Fixed TimeFromTicks for second values > 59.5. 2010-05-15 14:27:24 +01:00
Daniele Varrazzo
afea19651c Fixed TimestampFromTicks for second values > 59.5.
Bug reported and fixed by Jozsef Szalay on 2010-05-06 at 14:11:59.999920.
2010-05-15 14:27:24 +01:00
Daniele Varrazzo
b04bf41f99 Fixed decimal to float recipe to avoid using FLOAT.
FLOAT seems not working with NULLs.
2010-05-15 14:27:24 +01:00
Daniele Varrazzo
5e3f240ac9 Cast datetime into timestamptz when the tzinfo field is set. 2010-05-15 14:27:23 +01:00
Daniele Varrazzo
60e7522e47 Added evaluable representation for the FixedOffsetTimezone object. 2010-05-15 14:27:23 +01:00
Daniele Varrazzo
d30daac782 Fixed typo in LocalTimezone doc. 2010-05-15 14:27:23 +01:00
Daniele Varrazzo
bf1c76b792 Explicit cast of the SQL representation of time-related objects.
Allow the objects to be recognized as the proper type by Postgres in not
strong contexts: problem reported by Peter Eisentraut.

Added tests to check the types are respected in a complete Py -> PG ->
Py roundtrip without context.
2010-05-15 14:27:23 +01:00
Daniele Varrazzo
e8c2a14362 Added typecasters for arrays of specific MX/Py time-related types. 2010-05-15 14:27:23 +01:00
Daniele Varrazzo
c8aef26e15 Adapt buffer objects using an explicit cast on the string literal.
Don't rely on Postgres casting the literal according to the context:
this doesn't work e.g. passing the object as function argument where a
function with the same name but taking a text exists. It doesn't work
either when the object is in an ARRAY construct.

Added test to check the type is respected in a complete Py -> PG -> Py
roundtrip without context.

Bug and solution reported by Peter Eisentraut.
2010-05-15 14:27:23 +01:00
Daniele Varrazzo
2020790ba1 Typo fixed. 2010-05-15 14:27:02 +01:00
Daniele Varrazzo
73db6bee01 Keep the connection in blocking mode unless it is not async.
Dropped set/unset nonblocking mode for copy and lobject operations:
lobjects don't work in nonblocking mode so they will hardly be supported
in green/async branches.  Support for copy is still feasible, but it
will be done in other code paths (called by poll).
2010-05-09 20:37:48 +01:00
Daniele Varrazzo
e29424a230 Dropped large object support when psycopg is in green mode.
Async mode and large object are not compatible, albeit I haven't found
an authoritative source yet.
2010-05-09 20:34:02 +01:00
Daniele Varrazzo
2596cf7125 Simplified psyco_wait() function interface. 2010-04-25 23:08:08 +01:00
Daniele Varrazzo
8efa1fa6af Dropped compiling warning. 2010-04-25 23:08:08 +01:00
Daniele Varrazzo
dab098c1cb Cleaned up documentation for connection status constants.
Dropped reference to unused/internal states.
2010-04-23 13:28:49 +01:00
Daniele Varrazzo
cb40342afa poll implementation for async, sync and green connection unified. 2010-04-23 13:28:49 +01:00
Daniele Varrazzo
0da4befe78 Added function to advance the state after flush attempt. 2010-04-23 13:28:38 +01:00
Daniele Varrazzo
f3b3483df3 Added a function to advance the state after a read attempt.
Dropped calls to PQisBusy/PQconsumeInput in the connection code.
2010-04-23 13:24:36 +01:00
Daniele Varrazzo
e82d2be64b More lenient test timeout for a slow (or busy) machine. 2010-04-23 13:24:35 +01:00
Daniele Varrazzo
1edbd16577 Dropped curs_get_last_result function.
The result is read from a pqpath function and put on the async_cursor by
a function that also checks for is presence and dismiss it after its
usage.
2010-04-23 13:24:35 +01:00
Daniele Varrazzo
a66de9808f Added 'pq_get_last_result()' function.
The function reads the last result after an asynchronous query.
2010-04-23 13:24:35 +01:00
Daniele Varrazzo
5be0fc52ca Reusable parts of the green polling refactored out.
The functions _conn_poll_connecting() and _conn_poll_query() will be
usable by the async connections too.
2010-04-23 13:24:35 +01:00
Daniele Varrazzo
df959c20be Making sync and async connection setup somewhat more consistent. 2010-04-23 13:24:35 +01:00
Daniele Varrazzo
d915cb12a8 Functions to poll in ready state moved on the connection. 2010-04-23 13:24:35 +01:00
Daniele Varrazzo
9f5d835de6 Functions conn_poll_* renamed to conn_poll_connect_*.
These functions are used only during async connections, not for polling
afterwards.
2010-04-23 13:24:35 +01:00
Daniele Varrazzo
d2d1160260 Documentation about coroutines support reviewed. 2010-04-23 13:20:56 +01:00
Daniele Varrazzo
7af0bf0b54 Set the async_status to ASYNC_DONE after a query with wait callback.
Failing in doing that broke notifications reception.

The responsibility for changing the async_status has been moved to the
poll function: this is consistent with how the async branch is
implemented.

With this commit all the test suite passes in "green" mode.
2010-04-21 16:20:16 +01:00
Daniele Varrazzo
d71520db9a Read the server version only after connection established. 2010-04-21 15:31:07 +01:00
Daniele Varrazzo
8fed0aa57d Forbid COPY-related methods in green mode.
With the current implementation, at best they would silently block. They
actually hang everything.

Implementation posponed after some refactoring of the polling system,
because it will be probably possible to provide an implementation for
'poll()' during COPY which is good for both async and green modes.
2010-04-21 15:21:33 +01:00
Daniele Varrazzo
c1f0d4d46c Read notifications when polling an idle sync connection. 2010-04-21 15:21:33 +01:00
Daniele Varrazzo
4bb0c3bdf6 Use the wait callback in the connection setup queries. 2010-04-21 15:21:33 +01:00
Daniele Varrazzo
0ec73a18b4 'pq_execute_command_locked()' calls the wait callback if set.
The function is called without holding the GIL. Because it is necessary
to execute the Python callback if set, we need to re-acquire the GIL and
tnen release it again. In order to correctly bookkeep the thread state,
the pointer of the _save variable is passed to the function.
2010-04-21 15:21:33 +01:00
Daniele Varrazzo
7a06c0455b Try to restore the connection state after a wait callback error. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
a54932ee9c Added documentation for the green features. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
127f92f9db Changed 'psyco_wait()' to only take the connection. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
0dd5d3f1d9 Correctly flush async queries in 'green' mode. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
8ba0f00d21 Added 'get_wait_callback()' function. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
a7c41a0388 'pq_execute()' uses the user wait callback if provided. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
55270cab9f 'poll()' can raise a Python exception in case of error. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
442b3b2f6c Added 'psyco_exec_green()' to replace 'PQexec' using the user-provided block function. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
6dd6bee217 Added async read support to 'connection.poll()'. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
1108172e4c The test suite can be run against the green path. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
1607f89bb1 Avoid the locks dance when reading the connection socket number.
It is a fast and non critical operation, so the lock is not required.
Furthermore, called from the wait callback creates a deadlock.
2010-04-21 15:21:32 +01:00
Daniele Varrazzo
389ad08965 Use the wait callback during connection if set. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
04d66a6c82 Added poll implementation for sync connection with external wait. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
1446f046e9 Added wait callback and functions to deal with it. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
02a28ff028 Notifications are automatically read after each query.
Added tests for basic notifications process.
2010-04-21 15:09:14 +01:00
Daniele Varrazzo
12ef826d50 Dropped redundant call to conn_notice_process().
If the connection is sync, notices will be processed by pq_fetch()
downstream.

If the connection is async, here we have only sent the query: no result
is ready yet, and neither notices have had a chance to arrive: they will
be retrieved later by pq_is_busy().

Added tests to check the above statement don't break.
2010-04-21 15:09:14 +01:00
Daniele Varrazzo
bcfcea4b49 Fixed reference leak in notify reception. 2010-04-21 15:09:13 +01:00
Daniele Varrazzo
2af29b467d Added missing points to the changelog. 2010-04-21 15:09:13 +01:00
Daniele Varrazzo
d8f4ed1a04 Fixed documentation and example for asynchronous notifications. 2010-04-21 15:09:13 +01:00
Daniele Varrazzo
6fecc36b7f Connection method 'executing()' renamed to 'isexecuting()'. 2010-04-21 15:09:13 +01:00
Daniele Varrazzo
7ee09353ec Connection method 'issync()' changed into the attribute 'async'. 2010-04-21 15:09:13 +01:00
Daniele Varrazzo
7cf52da969 Ensure to close the connections in the doctests to avoid deadlocks. 2010-04-21 15:09:13 +01:00
Daniele Varrazzo
ac6938a26a Fixed async documentation after cursor.poll() dropped. 2010-04-21 15:09:13 +01:00
Jan Urbański
a57a9976b4 Fix the NOTIFY example to use the correct APIs 2010-04-21 15:09:13 +01:00
Jan Urbański
067161d5f3 Remove fileno() and poll() from cursors
Instead, the code should be using the fileno() and poll() methods of
the cursor's connection. Handle the case when poll() is called on an
already built connection as a request to poll the asynchronous query
(if there is one) and get NOTIFY events.
Update the tests to reflect that change, add a test for NOTIFY.
2010-04-21 15:09:13 +01:00
Daniele Varrazzo
b7327a349d FAQs grouped in themes. 2010-04-21 15:09:13 +01:00
Jan Urbański
f06f557111 Add one more test for errors involving two cursors 2010-04-20 23:01:10 +01:00
Jan Urbański
c4ebc0f702 Handle errors in asynchronous queries.
Do it by keeping the reference to the last PGresult in the cursor and
calling pq_fetch() before ending the asynchronous execution. This
takes care of handling the possible error state of the PGresult and
also allows the removal of the needsfetch flag, since now after
execution ends the results are already fetched and parsed.
2010-04-20 23:01:01 +01:00
Federico Di Gregorio
249b3ef88f Merged tests from piro and jan async fixes branches 2010-04-14 10:01:37 +02:00
Jan Urbański
5f4ef5da13 Make connection.executing() be True during an async connection attempt. 2010-04-14 10:00:37 +02:00
Jan Urbański
463724690c Set the execution status to ASYNC_READ after flushing all output.
Without this a query that did not get flushed completely to the server
would cause cursor.poll() to always go into the curs_poll_send()
branch even if it was retuning ASYNC_READ.

Bug report by Daniele Varrazzo.
2010-04-14 09:56:44 +02:00
Jan Urbański
4574bde3a2 Check for possible errors from PQflush.
Noticed by Daniele Varrazzo.
2010-04-14 09:56:44 +02:00
Jan Urbański
61f890c317 Set the initial connection status to CONN_STATUS_SETUP.
Without it the changes in e79528f9aa1f7457573720fce5548302fefffd37 are
never used.
2010-04-14 09:56:44 +02:00
Jan Urbański
6108e4dc92 Make the first poll() of an asynchronous connection return POLL_WRITE.
This hides from the user the libpq's implementation detail of
requiring the first select() to wait for the connection socket to
become writable and makes it possible to have a uniform select loop
for both cursors and connections, in which you always start by polling
the object and then acting according to the result from poll().

Idea and implementation by Daniele Varrazzo.
2010-04-14 09:56:44 +02:00
Jan Urbański
4afc1baf35 Make polling a cursor that's not in an async query raise an exception.
If there is an asynchronous query, polling a cursor that did not
initiate it will raise an exception. Polling while there is no
asynchronous query underway still works, because the user needs to
have a way to get asynchronous NOTIFYs.
2010-04-14 09:56:44 +02:00
Federico Di Gregorio
a90935930b Merge remote branch 'piro/fix22' into python2 2010-04-14 08:57:30 +02:00
Federico Di Gregorio
eaa97def73 Applied GC patch from Michael Tharp 2010-04-14 08:50:16 +02:00
Daniele Varrazzo
431920b367 Added recipe to get Python floats from Postgres decimals in the FAQ. 2010-04-14 01:05:36 +01:00
Daniele Varrazzo
0ac4c8ac17 Typecasters section in the extensions doc reordered. 2010-04-14 00:41:03 +01:00
Daniele Varrazzo
d162c08cfa PY* and MX* typecasters imported into the extensions module. 2010-04-14 00:27:28 +01:00
Daniele Varrazzo
54e9c89ea4 DECIMAL typecaster imported into the extensions module. 2010-04-14 00:20:16 +01:00
Daniele Varrazzo
595dc7effa Added a test to check poll() correctly calls PQflush.
When a large query is sent to the backend (and probably in high
concurrency situations), writing the query could block. In
this case PQflush() should be called until it returns 0. The test checks
this is done correctly.
2010-04-11 01:05:31 +01:00
Daniele Varrazzo
88fe5f91d2 Fixed parameters parsing in the connection constructor.
Keyword arguments were silently discarded.
2010-04-11 00:30:54 +01:00
Daniele Varrazzo
47ff5a6b01 test_async made properly executable. 2010-04-11 00:06:54 +01:00
Federico Di Gregorio
b8953cb345 Fixed Python 2.4 compatibility breakage 2010-04-09 12:53:38 +02:00
Federico Di Gregorio
0a33ed01f5 Added test for refcounting/gc bug reported by Michael Tharp 2010-04-08 18:42:20 +02:00
Daniele Varrazzo
6aaa50703e Added documentation for the new asynchronous support. 2010-04-08 13:25:17 +01:00
Daniele Varrazzo
d197346ce3 Added test to check that connections subclasses can be asynchronous. 2010-04-08 12:51:33 +01:00
Daniele Varrazzo
236b97045e Dropped README.async files referring to pre-2.2. 2010-04-08 10:51:30 +01:00
Daniele Varrazzo
e8286084e9 Free the GIL in blocking operations in V2 COPY FROM. 2010-04-07 23:52:53 +01:00
Daniele Varrazzo
aeec583ff1 Ensure running COPY in blocking mode. 2010-04-07 23:41:32 +01:00
Daniele Varrazzo
b114e25c31 Added some COPY tests. 2010-04-07 23:41:32 +01:00
Daniele Varrazzo
7e0dcfdda5 Added pq_set_non_blocking utility function. 2010-04-07 23:41:18 +01:00
Daniele Varrazzo
d339466c6a Speedup of the copy functions.
Python objects are evaluated only once outside the I/O loops.
2010-04-07 18:22:31 +01:00
Daniele Varrazzo
5a75d693a3 Dropped warnings when compiling on Python 2.5 2010-04-07 18:12:24 +01:00
Daniele Varrazzo
c75ddea895 Pass the async parameter to the connection only if nonzero.
This avoids breaking connection subclasses redefining '__init__' (at
least when used sync, which is good for most of the people).
2010-04-05 18:31:09 +01:00
Daniele Varrazzo
c486136df7 Delegate the destruction of the PGconn to the connection finalization.
This way we can have an usable connection before complete
initialization: this will be required to allow a Python callback to
interact with connect().
2010-04-05 18:19:37 +01:00
Federico Di Gregorio
012e2e3c72 Preparing 2.2.0 release candidate 1 2010-04-05 17:06:35 +02:00
Federico Di Gregorio
c1a24f4ca2 NOTIFYs fix and poll status changes
POLL_OK has been changed from 3 to 0 to let the user specify a short loop
just as "if not curs.poll()" instead of having to check for write and read
separately. For an example of this, see examples/notify.py.
2010-04-05 16:52:25 +02:00
Jan Urbański
e15bc9da05 Adapt the tests to recent changes
Some methods were forbidden in asynchronous mode, the isolation level
of an asynchronous connection is not always 0 and these changes
influenced expected test results.
2010-04-05 16:28:39 +02:00
Jan Urbański
31f60be000 Be a bit more explicit 2010-04-05 16:27:59 +02:00
Jan Urbański
58eb868db6 Avoid the possibility when curs_get_last_result would block
It was trying to get all pending results from the connection and if
the client sent many and anyone except the first one would not be
immediately available the loop in curs_get_last_result would call
PQgetResult blockingly.
Avoid that by calling PQisBusy every time and telling the client to
wait for more data if it returns 1.
2010-04-05 16:27:39 +02:00
Jan Urbański
25a609c9a7 Handle initial connection queries being sent partly
The CONN_STATUS_SENT_* statuses were not being handled at all, and
they indicate that a query has been sent, but not fully, so the client
should wait for the socket to become writable again and flush the output.
2010-04-05 16:25:17 +02:00
Jan Urbański
b99eac18f8 Make cursor.scroll() raise an exception in asynchronous mode
The exception is raised if an asynchronous query is in progress,
otherwise it will behave normally (since the data is already on the
client side).
2010-04-05 16:24:45 +02:00
Jan Urbański
727670c269 Make some methods raise an exception in asynchronous mode
The methods changed are connection.commit(), rollback(), reset(),
set_isolation_level(), set_client_encoding(), lobject(), cursor(str)
as well as cursor.execute() and cursor.callproc() if another query is
in progress and cursor.executemany(), cursor.copy_{from,to,expert)().
2010-04-05 16:23:44 +02:00
Jan Urbański
01799e9137 Make asynchronous connections produce asynchronous cursors by default
Drop the async kwarg from cursor.execute(), cursors created by
asynchronous connections will be asynchronous by default, ones created
by synchronous connections will be synchronous.

Mind that this might break third party subclasses of
psycopg2.extensions.cursor, if they try to chain to the superclass in
their execute() implementation and are passing the async kwarg. The
example cursors in psycopg2.extras have been fixed no to do that.
2010-04-05 11:41:32 +02:00
Jan Urbański
d8ab5ac8a1 Make asynchronous connections always use autocommit
Clients using async connections are expected to do their own
transaction management by sending (asynchronously) BEGIN and COMMIT
statements.
As a bonus, it allows to drop one step from the async connection
building, namely getting the default isolation level from the server.
2010-04-05 11:37:06 +02:00
Jan Urbański
062a9602ae Ref the async cursor before storing it in the connection 2010-04-05 11:36:09 +02:00
Jan Urbański
eb646f71fa Add tests for the asynchronous API 2010-04-05 11:32:03 +02:00
Jan Urbański
91ef0e09ed Change the API for asynchronous queries to use cursor.poll()
The isread() API was not safe, because the query might have not been
sent fully to the server after calling execute(). To make the async
API complete, a similar mechanism to async connections must be used.

The cursor now has a poll() method that you would use identically to
the poll() method of the connection class.
2010-04-05 11:31:50 +02:00
Jan Urbański
9b259a8a54 Disallow some methods depending on the connection's sync/async mode 2010-04-05 11:31:37 +02:00
Federico Di Gregorio
34317dc4c3 Support asynchronous connection building
After calling psycopg2.connect(dsn, async=True) you can poll the
connection that will tell you whether its file descriptor should be
waited on to become writable or readable or that the connection
attempt has succeeded.

Edited commit by Jan to not expose internal state in extensions.py.
2010-04-05 11:30:03 +02:00
Jan Urbański
1f6ffbba0f Block and clear the result of asynchronous queries where necessary
Remove the big loop in pq_fetch with the select() call, among
others. Code paths that don't support asynchronous queries should now
be adequately guarded.
2010-04-05 11:28:20 +02:00
Federico Di Gregorio
3d2c315049 Checks for pointers should be explicit, i.e., (ptr != NULL) 2010-04-05 11:27:34 +02:00
Jan Urbański
cc37fd1ea9 Add curs_get_last_result, a function to get the last result from a connection 2010-04-05 11:24:57 +02:00
Jan Urbański
75a0299a48 Add pq_flush, a function to flush the output buffer 2010-04-05 11:07:53 +02:00
Federico Di Gregorio
3f2c1f6489 /me does not like empty for loops 2010-04-05 11:07:19 +02:00
Jan Urbański
53748443d8 Make pq_clear_async clear the whole pending result and export it 2010-04-05 11:01:44 +02:00
Jan Urbański
e0d789466a Support large objects truncating.
The lobject.truncate(len=0) method will be available if psycopg2 has
been built against libpq from 8.3 or later (which is when the lobject
truncating support has been introduced).
2010-03-29 09:19:35 +02:00
Federico Di Gregorio
0edd520593 Preparing release 2.0.14 (final) 2010-03-13 21:15:50 +01:00
Federico Di Gregorio
b5373bd90a Merge remote branch 'piro/python2' into python2 2010-03-12 17:37:04 +01:00
Federico Di Gregorio
21a6a64fd1 Changed setup.py to detect PostgreSQL "alpha" versions 2010-03-11 22:42:00 +01:00
Daniele Varrazzo
99620c1454 A bunch of typo fixed in the docs 2010-03-03 18:43:24 +01:00
Federico Di Gregorio
855674faf1 Fixed Python 2.4 segfault related to decimal implementation 2010-02-28 20:52:03 +01:00
Daniele Varrazzo
17a4cc9f67 All the docs todo points dropped: todo list removed. 2010-02-26 01:10:15 +00:00
Daniele Varrazzo
140e6ad4f2 Added notes about stuff changed in ver. 2.0.14. 2010-02-26 01:09:08 +00:00
Daniele Varrazzo
97ced0d4f1 Use the default role for cross referencing Python objects. 2010-02-26 00:49:19 +00:00
Daniele Varrazzo
4412826556 Added documentation for the 'pool' module. 2010-02-26 00:46:23 +00:00
Federico Di Gregorio
3636bc4201 Release candidate 1 2010-02-22 19:45:48 +01:00
Federico Di Gregorio
b99f2d5f8e Added a couple more questions to the FAQ 2010-02-22 19:38:47 +01:00
Federico Di Gregorio
6733c64412 Varrazzo has two "r"! 2010-02-22 09:09:44 +01:00
Federico Di Gregorio
1b3e16e6fe MANIFEST.in does not prune docs/html/_sources anymore 2010-02-22 09:06:28 +01:00
Federico Di Gregorio
b46035c222 Merge remote branch 'remotes/piro/python2' into python2 2010-02-22 09:05:40 +01:00
Federico Di Gregorio
fd6d3185b4 Preparing release 2.0.14 2010-02-21 01:26:43 +01:00
Federico Di Gregorio
4712ad1550 Added documentation to project 2010-02-21 01:09:40 +01:00
Federico Di Gregorio
192034dc38 Fixed problem with decimal.Decimal conversions 2010-02-21 01:04:00 +01:00
Daniele Varrazzo
50f5daef8b Added FAQ section to the documentation. 2010-02-18 04:12:49 +00:00
Daniele Varrazzo
29feed31b6 Cleaned up parameters style from the docs. 2010-02-18 04:12:46 +00:00
Daniele Varrazzo
a320f25a2a Completed documentation for errorcodes module. 2010-02-16 00:38:44 +00:00
Daniele Varrazzo
96b7912bcf Typo fixed in DictRow doc. 2010-02-16 00:38:15 +00:00
Daniele Varrazzo
8001795b95 More uniform titles style in docs index. 2010-02-16 00:37:47 +00:00
Daniele Varrazzo
491bbb111c Fixed code block. 2010-02-16 00:37:17 +00:00
Daniele Varrazzo
289ab1cd8d Binary adapter imported from the correct module. 2010-02-16 00:36:59 +00:00
Daniele Varrazzo
c72fbf0b0f Fixed example (with doctest) for Inet 2010-02-16 00:36:48 +00:00
Daniele Varrazzo
9ba6102f66 Added documentation for database large objects. 2010-02-16 00:36:32 +00:00
Daniele Varrazzo
d08d9ab199 Added errorcodes.lookup() function. 2010-02-15 01:38:49 +00:00
Daniele Varrazzo
3da7a33ffb Added script to update the errorcodes module. 2010-02-15 01:12:13 +00:00
Daniele Varrazzo
bcfdbd1903 Error codes updated to include all errors between PostgreSQL 8.1 and 8.4. 2010-02-15 01:07:28 +00:00
Daniele Varrazzo
be30f43181 Inet adapter fixed. 2010-02-14 20:14:17 +00:00
Daniele Varrazzo
cf3b7e7e50 Whitespace fixed 2010-02-14 19:45:22 +00:00
Daniele Varrazzo
c167a6f07f Manifest contains both rendered and source documentation. 2010-02-14 16:45:36 +00:00
Daniele Varrazzo
b744c92f58 Documentation dir reordered. 2010-02-14 16:45:36 +00:00
Daniele Varrazzo
620f77cb77 Generate text documentation in a single file. 2010-02-14 16:45:31 +00:00
Daniele Varrazzo
a1fa06e6d8 Drop table moved off the example. 2010-02-14 13:23:05 +00:00
Daniele Varrazzo
f134bceb00 Added function to drop a test table in the doctest. 2010-02-14 13:23:05 +00:00
Daniele Varrazzo
a54336f7b4 Docs cleaned up while still being testable. 2010-02-14 13:23:05 +00:00
Daniele Varrazzo
47809c338f Added 'make check' target to docs. 2010-02-14 13:23:05 +00:00
Daniele Varrazzo
edc690e60a Index and targets for subclassing work again. 2010-02-14 13:23:04 +00:00
Jonathan Ballet
323340abc6 The documentation is now mostly doctest-able 2010-02-14 13:23:04 +00:00
Federico Di Gregorio
67de65040c Fixed license in trove categories 2010-02-14 13:35:49 +01:00
Daniele Varrazzo
12bd7bf7cc Documentation generated in 'doc/html/' instead of 'doc/_build/html/' 2010-02-14 01:10:37 +00:00
Federico Di Gregorio
1a3e231e51 License change for psycopg2da
LGPL3+ZPL is fine for me, thanks.

Fabio
2010-02-14 01:23:57 +01:00
Federico Di Gregorio
4b58fc640e License change for lib/errorcodes.py
You hereby have my blessing to go ahead and license all my contributions to
the psycopg2 project, including lib/errorcodes.py to LGPL3(+).

-- Johan Dahlin
2010-02-14 01:19:17 +01:00
Daniele Varrazzo
00805633b2 Added README to explain how to build the documentation. 2010-02-14 00:39:49 +01:00
Daniele Varrazzo
a313011a57 Added a bunch of versions update informations. 2010-02-14 00:39:49 +01:00
Daniele Varrazzo
e4d427aae6 Added documentation for 'Error.pgerror' and 'Error.pgcode' attributes. 2010-02-14 00:39:49 +01:00
Daniele Varrazzo
c72dc3af00 Added documentation for 'connection.reset()' method. 2010-02-14 00:39:49 +01:00
Daniele Varrazzo
a856f0724e Use the module version as documentation version. 2010-02-14 00:39:49 +01:00
Daniele Varrazzo
ba1354502e Added documentation for the errorcodes module. 2010-02-14 00:39:49 +01:00
Daniele Varrazzo
8246b28563 Removed files used by the Epydoc documentation. 2010-02-14 00:39:49 +01:00
Daniele Varrazzo
e11199c420 Dropped fixed point. 2010-02-14 00:39:49 +01:00
Daniele Varrazzo
b90f2925d0 Removed modules index from the doc front page. 2010-02-14 00:39:48 +01:00
Daniele Varrazzo
3789f8fb17 Added other info about tz module. 2010-02-14 00:39:48 +01:00
Daniele Varrazzo
6a4ff65b49 Added documentation for the extras module. 2010-02-14 00:39:48 +01:00
Daniele Varrazzo
ec68569e58 Dropped implementation details from the cursor documentation. 2010-02-14 00:39:48 +01:00
Daniele Varrazzo
e7d1d7ae1e Just discovered how to put many objects in the same directive. 2010-02-14 00:39:48 +01:00
Daniele Varrazzo
53f3248976 Added example about how to deal with the cursor bad exception. 2010-02-14 00:39:48 +01:00
Daniele Varrazzo
885dbf6428 Cleanup in the usage file. 2010-02-14 00:39:48 +01:00
Daniele Varrazzo
0694b85e59 Added documentation about Unicode handling. 2010-02-14 00:39:48 +01:00
Daniele Varrazzo
9a6c4c4c93 Fixed repetition in exceptions docs. 2010-02-14 00:39:48 +01:00
Daniele Varrazzo
c8010cfd47 Big documentation cleanup. 2010-02-14 00:39:48 +01:00
Daniele Varrazzo
6ea6d48f5d Added docutils SQL role. 2010-02-14 00:39:48 +01:00
Daniele Varrazzo
5491dd8db0 Added documentation to type casting objects. 2010-02-14 00:39:48 +01:00
Daniele Varrazzo
74403ff5a8 Fixed newline in docstring. 2010-02-14 00:39:48 +01:00
Daniele Varrazzo
c176a9d075 Fixed jumbled COPY methods. 2010-02-14 00:39:48 +01:00
Daniele Varrazzo
6199ce5127 Fixed typo in example. 2010-02-14 00:39:48 +01:00
Daniele Varrazzo
5431890938 Added introductive section about sessions. 2010-02-14 00:39:48 +01:00
Daniele Varrazzo
10f1a5b57a Added CSS style for TODO admonitions. 2010-02-14 00:39:47 +01:00
Daniele Varrazzo
5cb07685ca Showing the points where Psycopg diverges from the DB API. 2010-02-14 00:39:47 +01:00
Daniele Varrazzo
5417d7153d Added `extension` directive to mark Psycopg extensions to the DB API. 2010-02-14 00:39:47 +01:00
Daniele Varrazzo
3e66529864 Uniform usage of DB API spelling. 2010-02-14 00:39:47 +01:00
Daniele Varrazzo
9955b2f32f Using uppercase P when dealing with Psycopg - not the module. 2010-02-14 00:39:47 +01:00
Daniele Varrazzo
5c732ac2a3 Asynchronous queries marked as experimental. 2010-02-14 00:39:47 +01:00
Daniele Varrazzo
4708704f16 Added documentation about asynchronous notifications. 2010-02-14 00:39:47 +01:00
Daniele Varrazzo
ac6640fd9e Completed documentation for the COPY-related methods. 2010-02-14 00:39:47 +01:00
Daniele Varrazzo
d081d533b9 A few index entries fixed. 2010-02-14 00:39:47 +01:00
Daniele Varrazzo
e0065bfbef Added a bunch of index entries for the connection class. 2010-02-14 00:39:47 +01:00
Daniele Varrazzo
a9b793a371 Added documentation for `connection.notices` 2010-02-14 00:39:47 +01:00
Jonathan Ballet
1a7a12c833 Fixed some typos 2010-02-14 00:39:47 +01:00
Daniele Varrazzo
961b4eedc5 First iteration with the Sphinx module documentation. 2010-02-14 00:39:47 +01:00
Daniele Varrazzo
442d8693cd Ignore vim temporary files. 2010-02-14 00:39:47 +01:00
Daniele Varrazzo
04db8e7428 Fixed docstring for 'QueryCanceledError' exception. 2010-02-14 00:35:48 +01:00
Daniele Varrazzo
f6e87fbb30 Moved status from beta to stable in trove classifier. 2010-02-14 00:35:48 +01:00
Daniele Varrazzo
08e14e1049 Restored meaning of the word "respectively". 2010-02-14 00:35:48 +01:00
Daniele Varrazzo
e1b3c7b940 Fixed Inet constructor. 2010-02-14 00:35:48 +01:00
Daniele Varrazzo
0dbe068df4 Stop the loop variable used to create __all__ leaking in the module. 2010-02-14 00:35:47 +01:00
Federico Di Gregorio
0089201ba2 Binary was not imported from _psycopg; now it is 2010-02-13 00:52:36 +01:00
Federico Di Gregorio
a9673f31d6 SQL_IN adapter is now automatically registered 2010-02-13 00:40:29 +01:00
Federico Di Gregorio
3b4c0443e4 Removed debug logging calls 2010-02-13 00:15:39 +01:00
Federico Di Gregorio
611606d532 Changes license to LGPL3 + OpenSSL exception on all source files 2010-02-12 23:34:53 +01:00
Federico Di Gregorio
e5bed4993b Fixed register_tstz_w_secs() error 2010-02-10 18:16:00 +01:00
Federico Di Gregorio
bcc836c661 Now adapt() errors include the type name 2009-11-25 11:51:54 +01:00
Federico Di Gregorio
d40a5321f2 Fixed test broken by float precision fix 2009-11-25 10:38:31 +01:00
Federico Di Gregorio
7b730f3935 Fixed float loss of precision 2009-11-09 09:17:05 +01:00
Jason Erickson
b537404487 Fixed --have_ssl command line parameter
Added initialization of have_ssl variable so passing --have_ssl on the
command line works.
2009-10-08 13:18:55 +02:00
Jason Erickson
ac1b5ce68a Unclear error message when no pg_config found
If unable to find pg_config, a warning will be printed instead of stopping
the build process and displaying a generic error message.
2009-10-08 13:17:26 +02:00
Jason Erickson
5a3e07a610 Rearranged code to fix recent MSVC errors
Rearranged code to fix recent MSVC errors, such as mutex locking in conn_setup
to after the delcarations of variables.
2009-10-04 23:38:16 +02:00
Jason Erickson
69a8400e60 Added additional library required for PostgreSQL 8.4.x
For MSVC, added an additional library to include that is required for
PostgreSQL 8.4.x.
2009-10-04 23:37:14 +02:00
Jason Erickson
0f00ee129d Moved declarations of varaibles/pointers to the beginning of functions
Moved the declarations of varaibles/pointers to the beginning of the functions,
where MSVC requires them to be defined.
2009-10-04 23:35:29 +02:00
Federico Di Gregorio
69224032ce Fixed missing entry in NEWS file 2009-10-04 12:55:28 +02:00
Federico Di Gregorio
9bd771cda0 Preparing release 2.0.13 2009-10-04 12:53:42 +02:00
Federico Di Gregorio
8bb617ee76 Added very large lobject creation to the lobject.py example 2009-10-04 12:50:16 +02:00
Federico Di Gregorio
9670c9eddc Enabled linking to static libpq 2009-10-04 12:43:30 +02:00
Federico Di Gregorio
390a9c2451 Added support for UUID arrays 2009-10-04 12:34:02 +02:00
Federico Di Gregorio
7022269b3d Fixed a deadlock when using the same connection from multiple threads 2009-10-04 12:02:02 +02:00
Federico Di Gregorio
1c9fa1355d Added README file about async support. 2009-10-04 11:33:35 +02:00
Federico Di Gregorio
0fc94be496 Preparing release 2.0.12 2009-08-09 17:22:18 +02:00
Federico Di Gregorio
3a6911216b Fixed problem with large writes in large objects code 2009-08-09 17:05:16 +02:00
Federico Di Gregorio
a2af059e6c Fixed PostgreSQL version detection 2009-08-09 16:28:27 +02:00
Federico Di Gregorio
29d00f56f6 Fix for retry on serialization errors for ZPsycopgDA 2009-08-09 16:22:43 +02:00
Federico Di Gregorio
36aff2f73d Implemented connection.reset() 2009-08-09 16:19:08 +02:00
Federico Di Gregorio
4c3e2ad94b Fixed problem with lots of columns in COPY operations 2009-08-09 15:13:42 +02:00
Federico Di Gregorio
e5a696ad58 Fixed version check in ZPsycopgDA 2009-08-09 14:53:41 +02:00
Federico Di Gregorio
091102a919 Preparing release 2.0.11 2009-05-09 14:52:16 +02:00
Federico Di Gregorio
e1fae0fcac Fixed bug in RealDictCursor when prefetching 2009-05-09 14:44:59 +02:00
Federico Di Gregorio
3935c019fe Fixed error in fetchXXX methods 2009-05-09 14:28:40 +02:00
Federico Di Gregorio
06eb574cec Applied DictRow "diet" patch 2009-05-09 10:19:15 +02:00
Federico Di Gregorio
aecdf33b17 Removed old project files 2009-04-26 14:39:19 +02:00
Federico Di Gregorio
b0741721c3 Migrated project to MS Visual Studio 2008 format and repo to Git 2009-04-26 14:38:41 +02:00
Federico Di Gregorio
5e3fa15091 Better detection of PostgreSQL version 2009-04-21 00:38:09 +02:00
Federico Di Gregorio
f68d828f6b Release 2.0.10 2009-04-20 20:37:59 +02:00
Federico Di Gregorio
d621c02e58 Preparing release 2.0.10 2009-04-20 20:34:06 +02:00
Federico Di Gregorio
85fdc828e7 Fix to double free segfault in cursor 2009-04-20 20:19:55 +02:00
Federico Di Gregorio
5db66038fe Fix to double free segfault in connection 2009-04-19 16:51:31 +02:00
Federico Di Gregorio
5dab867db4 Added get_parameter_status() implementation 2009-04-19 16:42:06 +02:00
Federico Di Gregorio
39d6d8ad11 Exposed protocol_version and server_version 2009-04-19 16:36:10 +02:00
Federico Di Gregorio
e3a5ae8e20 Added a couple of test scripts to sandbox 2009-04-19 16:25:49 +02:00
Federico Di Gregorio
bb77a6912f Added missing dict methods in DictRow 2009-04-19 16:25:12 +02:00
Federico Di Gregorio
bd19e3148c Removed calls to PyMem_XXX when not holding the GIL 2009-04-07 09:25:05 +02:00
Federico Di Gregorio
16c2a8fc81 Cleaned conn_notice_callback() to run without the GIL 2009-04-04 19:17:40 +02:00
Federico Di Gregorio
f1e532151f Removed unecessary import 2009-04-04 19:14:53 +02:00
Federico Di Gregorio
8e54f7dcce Fixed test_dates failures in older version of Python 2009-04-01 20:52:58 +02:00
Federico Di Gregorio
e8ef973ddf Fixed lobject test failures 2009-04-01 20:49:00 +02:00
Federico Di Gregorio
850423d8fc Fixed setup script to handle PostgreSQL devel version strings 2009-03-21 12:54:44 +01:00
Federico Di Gregorio
825a60eec5 Removed spurious print 2009-03-16 22:15:20 +01:00
Federico Di Gregorio
0b0639dae5 Fixed error when adapt()ing None 2009-03-09 21:45:49 +01:00
Federico Di Gregorio
a574321fcd NEWS for 2.0.10 2009-03-02 11:07:36 +01:00
Federico Di Gregorio
1daf300ca3 Support for seconds in time zone offsets 2009-03-02 11:07:17 +01:00
Federico Di Gregorio
5b04203c9f Fixed error in register_type() 2009-03-02 10:59:52 +01:00
Federico Di Gregorio
a3ce636be0 Fixed error in register_type() 2009-03-02 10:56:53 +01:00
Federico Di Gregorio
4077711050 More cross-platform build fixes 2009-03-02 09:19:23 +01:00
Federico Di Gregorio
5c0cfa86bf isinf() for Solaris 2009-02-27 11:02:45 +01:00
Federico Di Gregorio
71c7825b9c Release 2.0.9 2009-02-23 21:39:47 +01:00
Federico Di Gregorio
9b259bba86 Removed some spurious tabs 2009-02-23 21:39:25 +01:00
Federico Di Gregorio
49bdaf92f6 Merge from trunk 2009-02-22 23:39:13 +01:00
Federico Di Gregorio
a6dff6c82a Preparing release 2.0.9 2009-02-22 23:37:34 +01:00
James Henstridge
9067bde803 * psycopg/utils.c (psycopg_escape_string): same here.
* psycopg/adapter_binary.c (binary_escape): simplify PostgreSQL
	version check.

	* setup.py (psycopg_build_ext.finalize_options): use a single
	define of the PostgreSQL version in a form that can easily be used
	by #ifdefs.
2009-02-17 16:00:52 +09:00
James Henstridge
2a94dfae47 * tests/test_dates.py (DatetimeTests, mxDateTimeTests): full test
coverage for datetime and time strings with and without time zone
	information.

	* psycopg/typecast_datetime.c (typecast_PYDATETIME_cast): adjust
	to handle the changes in typecast_parse_time.
	(typecast_PYTIME_cast): add support for time zone aware time
	values.

	* psycopg/typecast_mxdatetime.c (typecast_MXDATE_cast): make sure
	that values with time zones are correctly processed (even though
	that means ignoring the time zone value).
	(typecast_MXTIME_cast): same here.

	* psycopg/typecast.c (typecast_parse_time): Update method to parse
	second resolution timezone offsets.
2009-02-17 15:03:33 +09:00
James Henstridge
ba8be438bb * psycopg/typecast.c (typecast_parse_time): Fix up handling of
negative timezone offsets with a non-zero minutes field.

	* tests/test_dates.py (DatetimeTests): Add tests for time zone
	parsing.  The test for HH:MM:SS time zones is disabled because we
	don't currently support it.
2009-02-17 12:58:45 +09:00
James Henstridge
3466b3b72d Add tests for time zone parsing, for "HH", "HH:MM" and "HH:MM:SS" forms.
Currently the second fails for negative offsets due to bugs in the 
parser, and the third fails because it doesn't even try to parse second 
offset values (as Python doesn't either).
2009-02-17 12:39:57 +09:00
Federico Di Gregorio
41dd7a1095 Compile again on modern FreeBSD 2009-02-16 10:00:34 +01:00
Federico Di Gregorio
f9fa711f03 Modified executemany() to return modified rows count 2009-02-07 18:02:14 +01:00
Federico Di Gregorio
eb25f9f154 Added adapter to handle float('inf') and float('nan') 2009-01-23 00:09:20 +01:00
Federico Di Gregorio
e22451736a register_type() now works on connection and cursor subclasses 2009-01-22 11:02:38 +01:00
Federico Di Gregorio
78c0765367 Merge from public trunk 2009-01-10 18:51:45 +01:00
Federico Di Gregorio
f5ec676566 Added isready() error test to sandbox 2009-01-10 18:48:31 +01:00
Federico Di Gregorio
aeb5080208 Fixed isready() not throwing exception on error 2009-01-10 18:48:08 +01:00
James Henstridge
83b03e5e36 If we are depending on Python 2.4, we don't need to make decimal module
support conditional.
2008-12-27 00:03:11 +09:00
James Henstridge
345a254ca0 Remove conditionals on support for booleans and datetimes, since they
are guaranteed to be available in Python 2.4.
2008-12-26 23:46:35 +09:00
James Henstridge
e7b8d6505e Remove backward compatibility support for Python versions older than
2.4, since we don't really support them any way.
2008-12-26 09:37:44 +09:00
Federico Di Gregorio
5480cf5332 Fixed memory leak in lobject 2008-12-04 16:58:05 +01:00
Federico Di Gregorio
4eb295a8ca Patch from Jason Erickson to build on MSVC 2008-11-26 09:51:53 +01:00
Federico Di Gregorio
5c982d90f0 Unified string quoting 2008-11-25 19:18:17 +01:00
Federico Di Gregorio
4810789194 Removed non-existing files from project 2008-11-25 17:53:48 +01:00
Federico Di Gregorio
4e359f6f05 Applied COPY patch from Alejandro Dubrovsky (missing files and project) 2008-11-25 17:46:15 +01:00
Federico Di Gregorio
c1d6073531 Applied COPY patch from Alejandro Dubrovsky 2008-11-25 17:45:22 +01:00
Federico Di Gregorio
b9157c8ba1 Merged changed by JH from head 2008-09-24 01:29:20 +02:00
Federico Di Gregorio
4c8e80038e Added inet support 2008-09-24 01:27:52 +02:00
James Henstridge
cc2aa0a9ca * psycopg/psycopg.h (NotSupportedError_doc): clean up
spelling/grammar a bit, using exception description from the PEP.
2008-09-23 17:22:37 +08:00
Federico Di Gregorio
56f6001d6d Support for NULLs in UUID 2008-09-23 09:11:11 +02:00
Federico Di Gregorio
b92601306e Added suppport for UUID and related test. 2008-09-19 21:25:16 +02:00
Federico Di Gregorio
758eaf23d1 Preparing release 2.0.8 2008-09-16 09:58:44 +02:00
James Henstridge
bc662db1cc Fill in a few more items in the NEWS file for 2.0.8. 2008-08-26 14:47:47 +08:00
Federico Di Gregorio
f6a25ccdf0 Build fix from Jorgen Austvik 2008-08-02 10:30:36 +02:00
Federico Di Gregorio
ceee4c816f Merge from jh 2008-07-26 15:10:02 +02:00
Federico Di Gregorio
e95a4d9d2e get_backend_pid() patch and fixes 2008-07-26 15:09:20 +02:00
James Henstridge
a2f3e4a3ac * psycopg/lobject_type.c (lobject_setup): use
FORMAT_CODE_PY_SSIZE_T in Dprintf() call for 64-bit compatibility
when using Python 2.5 or later.
(lobject_dealloc): same here.
2008-07-23 16:57:10 +08:00
James Henstridge
0aec2840d8 Merge support for cyclic GC in relevant types that psycopg defines. 2008-07-23 16:50:24 +08:00
James Henstridge
2273b79be9 Use Py_CLEAR() in a few more places, and do INCREF's before setting
struct members rather than afterwards.
2008-07-21 13:41:54 +08:00
James Henstridge
e0287c0db4 * psycopg/adapter_qstring.c (qstring_traverse): add cyclic GC
traversal for quoted string adapters.

	* psycopg/adapter_pboolean.c (pboolean_traverse): add cyclic GC
	traversal for boolean adapters.

	* psycopg/adapter_mxdatetime.c (mxdatetime_traverse): add cyclic
	GC traversal for mxdatetime adapters.

	* psycopg/adapter_datetime.c (pydatetime_traverse): add cyclic GC
	traversal for datetime adapters.
2008-07-18 17:42:31 +08:00
James Henstridge
590542e973 * psycopg/adapter_binary.c (binary_traverse): add cyclic GC
traversal for binary adapters.
2008-07-01 11:59:25 +08:00
James Henstridge
47d2414e32 * psycopg/adapter_asis.c (asis_traverse): add cyclic GC traversal
for AsIs adapters.
2008-07-01 09:57:16 +08:00
James Henstridge
fd538a8b17 * psycopg/adapter_list.c (list_traverse): add cyclic GC traversal
for list adapters.
2008-07-01 09:34:51 +08:00
Federico Di Gregorio
a5e01ef0df Fixed spaces in pg_config path 2008-06-28 18:34:57 +02:00
Federico Di Gregorio
e664abb248 Added XXXARRAY imports to psycopg2.extenions 2008-05-30 00:39:50 +02:00
James Henstridge
26693621ef * psycopg/cursor_type.c (cursor_setup): incref before setting
attributes, to make things GC-safe.

	* psycopg/cursor_int.c (curs_reset): make clearing of description
	and casts attributes GC-safe.
2008-05-28 17:45:37 +08:00
James Henstridge
bbd101bb7e * psycopg/typecast.c (typecast_traverse): implement cyclic GC
traversal for typecasters.
2008-05-28 17:22:40 +08:00
James Henstridge
a39fb19eb9 * psycopg/connection_type.c:
* psycopg/cursor_type.c: add support for cyclic GC.

	* psycopg/python.h: add definitions for Py_CLEAR() and Py_VISIT()
	for compatibility with old versions of Python.
2008-05-28 09:00:36 +08:00
Federico Di Gregorio
5a428642f8 COPY problem tests and partial fix 2008-05-27 17:40:19 +02:00
Federico Di Gregorio
6073193314 Fixed memory leak in executemany 2008-05-19 10:14:17 +02:00
Fabio Tranchitella
f1fab54b97 Update debian packaging files. 2008-05-12 15:33:10 +08:00
James Henstridge
ee235478bd * psycopg/lobject.h (lobjectObject): remove "mode" struct member,
since it was unused.
2008-05-06 18:12:50 +08:00
James Henstridge
9d20f5c09c * psycopg/lobject_*.c: replace uses of the closed struct member,
and change the Python level attribute to a getset.

	* psycopg/lobject.h (lobjectObject): remove the closed member,
	since "fd < 0" gives us the same information.  Reorder the struct
	members for better packing.
2008-05-06 18:07:54 +08:00
James Henstridge
2046ae34fb * psycopg/lobject*: const'ify the code. 2008-05-06 17:09:43 +08:00
James Henstridge
7d66c20edb * tests/test_lobject.py (LargeObjectTests): add more tests,
including behaviour on closed lobjects and stale lobjects.

	* psycopg/lobject_type.c (psyco_lobj_close): don't mark the
	connection closed here because it is done by
	lobject_close_locked().

	* psycopg/lobject_int.c (lobject_open): mark objects as not closed
	if we successfully open them.
	(lobject_close_locked): mark the lobject closed here.
	(lobject_export): ensure we are in a transaction, since
	lo_export() issues multiple queries.

	* psycopg/lobject_type.c (lobject_setup): make lobjects start closed.
2008-05-06 17:04:26 +08:00
James Henstridge
e627948a6b * psycopg/lobject.h: don't export the lobjectType symbol. 2008-05-05 22:51:15 +08:00
Federico Di Gregorio
0319bc8cc4 Fixed build error on SUN 2008-05-05 15:55:51 +02:00
James Henstridge
975d2286e8 Merge lobject work from trunk, plus fixes to make it work with current
psycopg2.
2008-05-05 19:23:33 +08:00
James Henstridge
9a48c261be Add basic tests for large object code. Fix lobject.seek() to actually
work.
2008-05-05 15:33:44 +08:00
James Henstridge
e192c603fa Fix up structmember definitions to match real types. T_LONG is not the
same as T_INT/T_UINT on AMD64 ...
2008-05-05 15:00:50 +08:00
James Henstridge
82557e65a2 Fix up pq_complete_error() calls. 2008-05-05 15:00:34 +08:00
James Henstridge
5beef38bfc Fix double free in case where PGresult is NULL. 2008-05-05 14:16:57 +08:00
James Henstridge
ec20fa8912 Some changes to the lobject code to match changes in pqpath.[ch]. 2008-05-05 12:07:24 +08:00
James Henstridge
3cfe438b74 Add an #endif I accidentally removed 2008-05-05 10:43:38 +08:00
James Henstridge
e01da0a540 add ignores 2008-05-05 10:39:13 +08:00
James Henstridge
938c456cee Merge changes from psycopg2/trunk via psycopg2.r243. 2008-05-05 10:37:24 +08:00
James Henstridge
31ef9355c2 Merge psycopg2/trunk into psycopg2/branches/2_0_x r243 (which is the
last revision merged into trunk).  Where file ID conflicts exist, but 
the content was equivalent, I've picked the 2_0_x version.
2008-05-05 10:22:22 +08:00
Fabio Tranchitella
fedfd53d54 Added encoding. 2008-04-09 09:49:55 +00:00
Fabio Tranchitella
5930078ec7 Add the encoding property into the ZMI add form (debian bug #475123). 2008-04-09 09:47:45 +00:00
Federico Di Gregorio
3b1c2b24de Signed all commits 2008-04-25 23:09:04 +02:00
James Henstridge
331c942800 2008-04-21 James Henstridge <james@jamesh.id.au>
* tests/test_quote.py (QuotingTestCase.test_unicode): If the
	server encoding is not UTF8, skip the unicode test and emit a
	warning.
2008-04-20 23:19:42 +00:00
James Henstridge
2f3f4c1258 2008-04-21 Jorgen Austvik <Jorgen.Austvik@sun.com>
* tests/*.py: use the DSN constructed in tests/__init__.py.

	* tests/__init__.py: allow setting the host, port and user for the
	DSN used by the tests through the environment.
2008-04-20 23:12:21 +00:00
Federico Di Gregorio
962c5a9a5f Preparing release 2.0.7. 2008-04-14 05:23:15 +00:00
Federico Di Gregorio
f3438f2961 Preparing release 2.0.7. 2008-04-14 04:27:22 +00:00
Federico Di Gregorio
1fddaa8562 Added a couple of files used for tests. 2008-04-14 04:13:07 +00:00
James Henstridge
23866bc35d * psycopg/connection_type.c (connection_dealloc): free
connection->encoding with free() instead of PyMem_Free().

	* psycopg/connection_int.c (conn_connect): use malloc() to
	allocate connection->encoding instead of PyMem_Malloc(), since it
	is freed in other places with free() and assigned to with
	strdup().
2008-03-30 22:15:21 +00:00
James Henstridge
e848585b90 * psycopg/typecast.c (typecast_from_c): fix up some reference
leaks.  This leak affected a bounded set of objects, so doesn't
	account for any gradual leaks.
2008-03-25 23:21:00 +00:00
James Henstridge
af1478feb9 * psycopg/connection_int.c (conn_notice_callback): don't leak
notice messages.
2008-03-19 01:01:26 +00:00
Federico Di Gregorio
8103f44a12 Fixed test segfault due to double decref. 2008-03-17 08:13:16 +00:00
James Henstridge
cceaa7331b * psycopg/typecast.c (typecast_parse_time): give the correct
return value for partially parsed time values.

	* psycopg/typecast_mxdatetime.c (typecast_MXDATE_cast): return
	NULL after setting DataError.  Also, don't treat it as an error if
	typecast_parse_time() returns 0 (as might happen if the remainder
	of the string is " BC").

	* psycopg/typecast_datetime.c (typecast_PYDATE_cast): return NULL
	after setting DataError.
	(typecast_PYDATETIME_cast): same here.
	(typecast_PYTIME_cast): same here.

	* tests/test_dates.py
	(CommonDatetimeTestsMixin.test_parse_incomplete_date): test that
	parsing incomplete date values results in DataError.
	(CommonDatetimeTestsMixin.test_parse_incomplete_time): same for
	times.
	(CommonDatetimeTestsMixin.test_parse_incomplete_time): same for
	datetimes.
2008-03-17 04:06:44 +00:00
James Henstridge
1ea0cd4980 Missed the last bit of the commit message. 2008-03-06 19:35:47 +00:00
James Henstridge
475df5ebd6 2008-03-07 Jason Erickson <jerickso@stickpeople.com>
* psycopg/pqpath.c (pq_raise): if PSYCOPG_EXTENSIONS is not
	defined, raise OperationalError rather than
	TransactionRollbackError for deadlock or serialisation errors for
	protocol versions less than 3.
2008-03-06 18:41:07 +00:00
James Henstridge
89cadcb553 2008-03-07 Jason Erickson <jerickso@stickpeople.com>
* psycopg/psycopgmodule.c (psyco_connect): fix off by one error in
	calculating the length of the DSN.
2008-03-06 16:15:41 +00:00
James Henstridge
e55e2683cf * psycopg/pqpath.c (_pq_fetch_tuples): Don't call Python APIs
without holding the GIL.
2008-03-06 15:12:40 +00:00
James Henstridge
14135c1d7e * NEWS: add some draft NEWS items for a 2.0.7 release. 2008-02-27 04:42:56 +00:00
James Henstridge
fc2b684843 * runtests.py: add a harness to run all the psycopg tests against
the version built by distutils.
2008-02-27 02:29:55 +00:00
James Henstridge
b5f4a5f6c2 Fix off-by-one error in PyMem_Malloc() call in
psyco_conn_set_client_encoding().  Fixes #211
2008-02-13 16:01:10 +00:00
James Henstridge
6c2e3ab49b * Add HIDDEN attribute to datetime related global variables.
* Make const strings static, which essentially makes them labels for the 
  strings.
2008-01-22 00:13:42 +00:00
James Henstridge
fe853d0261 * psycopg/typecast.c (typecast_pydatetime): make array static.
(typecast_mxdatetime): same here.

	* psycopg/typecast_builtins.c (typecast_builtins): make array
	static.

	* psycopg/psycopgmodule.c: add hidden visibility to a bunch of
	global variables here.

	* psycopg/psycopg.h: add set QueryCanceledError and
	TransactionRollbackError to hidden visibility.
2008-01-21 21:41:17 +00:00
James Henstridge
e054004e8f Add more const qualifiers. 2008-01-21 21:01:08 +00:00
James Henstridge
eae563ac96 * psycopg/*.[ch]: add const qualifier to various string arguments
to functions (typecast functions and conn_switch_isolation_level).
2008-01-21 17:34:08 +00:00
James Henstridge
9fa039326c * setup.cfg (define): remove PSYCOPG_DISPLAY_SIZE from default
list of defines, as discussed on mailing list.  It slows down
	queries with very little benefit.
2008-01-21 05:59:03 +00:00
James Henstridge
864d107325 * psycypg/*.h: apply HIDDEN to all global variables and functions
that should not be exported from the module.  This results in a 5%
	reduction in code size and shortens the dynamic symbol table.

	* psycopg/config.h: If GCC >= 4.0 is installed, define the HIDDEN
	symbol to apply the "hidden" visibility attribute.
2008-01-21 05:54:01 +00:00
James Henstridge
3265dd172d * tests/test_connection.py (ConnectionTests): add simple tests for
the Connection and Cursor "closed" attributes.

	* psycopg/cursor_type.c (psyco_curs_get_closed): add a "closed"
	attribute to cursors.  It will be True if either the cursor or its
	associated connection are closed.  This fixes bug #164.
2008-01-19 03:32:42 +00:00
James Henstridge
11b017fcbe * psycopg/pqpath.c (pq_raise): remove unused arguments to
function, and simplify.
	(pq_resolve_critical): make function static, since it isn't being
	used outside of pqpath.c any more.
2008-01-19 02:16:57 +00:00
James Henstridge
e744242fe1 Update the debian directory (debian release 2.0.6-3). 2008-01-17 23:59:42 +00:00
James Henstridge
abb0a6f52c (App.ImageFile): simplify ImageFile import using patch from
chrism, fixing bug #198.
2008-01-16 23:16:59 +00:00
James Henstridge
6d9b6a977c * ZPsycopgDA/DA.py (Connection.__init__): Default the encoding to
UTF-8, fixing bug #190.
2008-01-16 18:56:13 +00:00
James Henstridge
bc663111b6 Split the binary tests out a bit. 2008-01-16 18:08:12 +00:00
James Henstridge
f64cbeda46 * tests/test_transaction.py (DeadlockSerializationTestCase): port
over some tests for serialisation and deadlock errors,
	demonstrating that TransactionRollbackError is generated.
	(QueryCancelationTests): add a test to show that
	QueryCanceledError is raised on statement timeouts.

	* psycopg2da/adapter.py (_handle_psycopg_exception): rather than
	checking exception messages, check for TransactionRollbackError.

	* psycopg/pqpath.c (exception_from_sqlstate): return
	TransactionRollbackError for 40xxx errors, and QueryCanceledError
	for 57014 errors.
	(pq_raise): If we are using an old server, use
	TransactionRollbackError if the error message contains "could not
	serialize" or "deadlock detected".

	* psycopg/psycopgmodule.c (_psyco_connect_fill_exc): remove
	function, since we no longer need to store pointers to the
	exceptions in the connection.  This also fixes a reference leak.
	(psyco_connect): remove _psyco_connect_fill_exc() function call.

	* psycopg/connection.h (connectionObject): remove exception
	members from struct.

	* psycopg/connection_type.c (connectionObject_getsets): modify the
	exception attributes on the connection object from members to
	getsets.  This reduces the size of the struct.

	* lib/extensions.py: import the two new extensions.

	* psycopg/psycopgmodule.c (exctable): add new QueryCanceledError
	and TransactionRollbackError exceptions.
2008-01-16 05:14:24 +00:00
James Henstridge
46bf23caf4 * tests/__init__.py (test_suite): add date tests to test suite.
* tests/test_dates.py: add tests for date/time typecasting and
	adaption.

	* psycopg/adapter_mxdatetime.c (mxdatetime_str): add support for
	outputting BC dates (which involves switching them to one-based
	dates).  Also remove broken handling of microseconds.

	* psycopg/typecast.c (typecast_parse_date): if the string ends
	with "BC" adjust the year value to be a zero-based BC value as
	used by mx.DateTime (datetime doesn't support BC dates).
	(typecast_parse_time): ignore ' ', 'B' and 'C' in time strings
	rather than treating them as part of the seconds part of the time.
2008-01-16 01:43:50 +00:00
James Henstridge
f18881983b * psycopg/typecast_array.c (typecast_array_scan): set an initial
value for quotes to keep gcc happy.

	* psycopg/*.c: add missing static modifier on many functions.
2008-01-13 16:05:59 +00:00
James Henstridge
7d80c05748 * tests/test_transaction.py
(TransactionTestCase.test_failed_commit): Expect IntegrityError
	instead of OperationalError.

	* psycopg/pqpath.c (exception_from_sqlstate): new function that
	converts an SQLSTATE error code to the corresponding exception
	class.
	(pq_raise): use exception_from_sqlstate() to pick which exception
	to use when working with protocol version 3.
	(pq_complete_error): Let pq_raise() pick an appropriate exception
	rather than forcing OperationalError.
2008-01-11 15:10:21 +00:00
James Henstridge
86597f6939 * psycopg/adapter_binary.c (binary_quote): apply Brandon Rhodes'
patch from ticket #209 to check return value from
	PyObject_AsCharBuffer().  This fixes the segfault.
	(binary_quote): switch from PyObject_AsCharBuffer() to
	PyObject_AsReadBuffer() to support buffer objects that don't
	implement the bf_getcharbuf protocol.

	* tests/types_basic.py (TypesBasicTests.testBinary): Test round
	tripping of bytea buffers.  Currently segfaults.
2008-01-10 22:19:23 +00:00
James Henstridge
729117af8b * psycopg/connection_int.c (conn_close): fix for new
pq_abort_locked() prototype.
	(conn_switch_isolation_level): fix for new pq_abort_locked()
	prototype, and use pq_complete_error() to show error message.
	(conn_set_client_encoding): same here.

	* psycopg/pqpath.c (pq_execute_command_locked): remove static
	modifier.
	(pq_complete_error): same here.
	(pq_abort_locked): add pgres and error arguments.
	(pq_abort): call pq_abort_locked() to reduce code duplication.
2008-01-10 18:14:44 +00:00
James Henstridge
d190d5918a 2007-12-23 James Henstridge <james@jamesh.id.au>
* psycopg/pqpath.c (pq_execute_command_locked): add an error
	argument to hold an error when no PGresult is returned by PQexec,
	rather than using pq_set_critical().
	(pq_complete_error): new function that converts the error returned
	by pq_execute_command_locked() to a Python exception.
	(pq_begin_locked): add error argument.
	(pq_commit): use pq_complete_error().
	(pq_abort): use pq_complete_error().
	(pq_abort_locked): always call pq_set_critical() on error, and
	clear the error message from pq_execute_command_locked().
	(pq_execute): use pq_complete_error() to handle the error from
	pq_begin_locked().

	* psycopg/pqpath.c (pq_begin): remove unused function.

	* psycopg/connection_type.c (psyco_conn_commit): if conn_commit()
	raises an error, just return NULL, since it is now setting an
	exception itself.
	(psyco_conn_rollback): same here.

	* psycopg/connection_int.c (conn_commit): don't drop GIL and lock
	connection before calling pq_commit().
	(conn_rollback): same here.
	(conn_close): use pq_abort_locked().
	(conn_switch_isolation_level): same here.
	(conn_set_client_encoding): same here.

	* psycopg/pqpath.h: add prototype for pq_abort_locked().

	* psycopg/pqpath.c (pq_commit): convert function to run with GIL
	held, and handle errors appropriately.
	(pq_abort): same here.
	(pq_abort_locked): new function to abort a locked connection.

2007-12-22  James Henstridge  <james@jamesh.id.au>

	* psycopg/pqpath.c (pq_raise): add a "pgres" argument so we can
	generate nice errors not related to a particular cursor.
	(pq_execute): use pq_begin_locked() rather than pq_begin().  Use
	pq_raise() to handle any errors from it.

	* psycopg/pqpath.c (pq_execute_command_locked): helper function
	used to execute a command-style query on a locked connection.
	(pq_begin_locked): a variant of pq_begin() that uses
	pq_execute_command_locked().
	(pq_begin): rewrite to use pq_begin_locked().
2008-01-10 06:14:20 +00:00
James Henstridge
5fe08ae83e 2007-12-22 James Henstridge <james@jamesh.id.au>
* psycopg/config.h: only print debug messages if
        psycopg_debug_enabled is true.

        * psycopg/psycopgmodule.c (init_psycopg): set
        psycopg_debug_enabled to true if the $PSYCOPG_DEBUG environment
        variable is set.
2007-12-22 13:03:41 +00:00
Federico Di Gregorio
f3e74d2c48 DA version patch. 2007-12-21 00:45:01 +00:00
Federico Di Gregorio
d31b4add22 Applied win32 patch from Jason Erickson. 2007-12-21 00:18:55 +00:00
James Henstridge
4910f53b7e * psycopg/pqpath.c (pq_execute): uncomment the "curs->pgres ==
NULL" error handler after the PQexec() call.  This is needed to
	catch database disconnects (and probably other errors).  According
	to Federico, it was commented out to avoid a spurious error, so we
	should watch for problems.
2007-12-19 14:33:44 +00:00
James Henstridge
fd5d2d5238 * psycopg/pqpath.c (pq_raise): only remove the first 8 characters
of the exception message if it actually gives the severity.

	* psycopg/pqpath.h (pq_resolve_critical): add prototype, since
	this function is being used from connection_int.c.

	* psycopg/psycopg.h: update psyco_set_error() prototype.

	* psycopg/psycopgmodule.c (psyco_errors_init): set pgerror, pgcode
	and cursor class attributes to None on psycopg2.Error so that the
	attributes will always be available (simplifies error handling).
	(psyco_set_error): add const qualifiers to msg, pgerror and pgcode
	arguments.
	Don't bother setting pgerror, pgcode or cursor to None if they are
	not provided -- the class defaults take care of this.
2007-12-19 14:29:03 +00:00
Daniele Varrazzo
67afd678b0 Added 'make check' target, running all the available tests.
Most of the updates have been provided by James Henstridge.

Closes ticket #195.
2007-11-11 10:40:12 +00:00
Daniele Varrazzo
fd1ee6fffc Fixes to let the dbapi20 test suite pass.
Submitted by James Henstridge in ticket #195.
2007-11-11 10:18:43 +00:00
Daniele Varrazzo
75cb5d75d7 Use escape string syntax for string escape if connected to a server
requiring it.

Added a connection flag to store whether E''-style quoting is required: this
avoids repeated PQparameterStatus() calls.

Added a test case to verify correct behavior on strings, unicode and binary 
data. Tested with PG versions from 7.4 to 8.3b2, with any server
'standard_conforming_strings' setting and with 'PSYCOPG_OWN_QUOTING' too.
2007-11-11 08:53:44 +00:00
Daniele Varrazzo
a6ea092acc - Tabs fixed. 2007-11-11 03:58:45 +00:00
Daniele Varrazzo
70e555585e Fixed selection of the proper binary string quoting. 2007-11-09 13:00:37 +00:00
Daniele Varrazzo
272140f5c1 Use escape string syntax for binary escape if connected with a
server with ver >= 8.2.

The feature is only enabled when compiling psycopg with libpq
ver >= 8.0.
2007-11-09 05:51:12 +00:00
Daniele Varrazzo
7d408b47d7 ChangeLog updated after r903. 2007-11-09 05:49:13 +00:00
Daniele Varrazzo
277f57ffb0 - Hard limit on the connection.notices list to avoid them
growing indefinitely.
  Notices are treated as a queue: when the queue is full 
  drop the oldest notice.
2007-11-09 02:28:47 +00:00
Daniele Varrazzo
e1dd9ca843 Fixed bug #192 (Decimal support not safe for use with multiple sub
interpreters) as proposed by Graham Dumpleton.

If running in the main interpreter, use a cached version of the Decimal
object. Else repeat the object lookup.
2007-10-21 03:22:55 +00:00
Daniele Varrazzo
63773ad1e0 Added missing DECREF. 2007-10-18 17:29:15 +00:00
Daniele Varrazzo
c71b7a03d0 Added missing return in case out of memory. 2007-10-18 17:19:16 +00:00
Federico Di Gregorio
1ed16c8265 Added test for DateTime object allocation bug. 2007-09-19 13:40:18 +00:00
Federico Di Gregorio
07892b29a6 Aggressive threading on fetch (and a new bug!) 2007-09-19 13:39:48 +00:00
Federico Di Gregorio
c9e701baa9 Fixed bug #194 (and added nice MD project not that C/C++ is supported.) 2007-09-08 08:54:30 +00:00
Federico Di Gregorio
0422506404 Added name parameters to .cursor() calls in extras. 2007-09-01 09:32:42 +00:00
Federico Di Gregorio
dfda372fae Preparing release 2.0.6. 2007-06-08 00:39:06 +00:00
Federico Di Gregorio
98c0992b6e Fix for #182. 2007-05-29 08:56:25 +00:00
Federico Di Gregorio
dbbdcfb0c0 Fix for #182. 2007-05-29 08:56:17 +00:00
Federico Di Gregorio
46668d214b conn_commit/conn_rollback error handling (closes: #187). 2007-05-29 08:43:34 +00:00
Federico Di Gregorio
a07987cd90 Patchset copy_expert 5/5. 2007-05-29 08:30:24 +00:00
Federico Di Gregorio
b82c2f5cd9 Patchset copy_expert 4/5. 2007-05-29 08:23:35 +00:00
Federico Di Gregorio
c54e9142f4 Patchset copy_expert 3/5. 2007-05-29 08:16:44 +00:00
Federico Di Gregorio
3b2908b51e Patchset copy_expert 2/5. 2007-05-29 08:14:58 +00:00
Federico Di Gregorio
a23de80c6b Patchset copy_expert 1/5. 2007-05-29 08:13:40 +00:00
Federico Di Gregorio
a779c8ef99 .get_transaction_status() implementation. 2007-04-25 22:42:36 +00:00
Federico Di Gregorio
d6e232e2b9 Various fixes, now all examples work. 2007-04-13 14:07:11 +00:00
Federico Di Gregorio
8274a032b1 typecast_binary.c cleanup. 2007-04-13 01:17:54 +00:00
Federico Di Gregorio
967ec370ed int->size_t transition. 2007-04-13 01:16:22 +00:00
Federico Di Gregorio
ee44315ff2 Appliet Jasons patch to fix win32 build glitches. 2007-04-13 01:14:01 +00:00
Federico Di Gregorio
f57920b0dd Release 2.0.6b2. 2007-04-11 07:12:16 +00:00
Federico Di Gregorio
2a6b523506 Fixed crash and win32 patches. 2007-04-11 04:16:00 +00:00
Federico Di Gregorio
d6f2aa27b7 Fixed mem and ref leak in connect(). 2007-04-10 06:51:35 +00:00
Federico Di Gregorio
e5829292cd Fixed both Python 2.5 and 64 bit problems. 2007-04-10 06:36:18 +00:00
Fabio Tranchitella
fadd1a6938 psycopg2da: better pattern matching for Retry exceptions; it is now compatible with postgresql 8.0, 8.1 and 8.2 exception messages. 2007-03-25 03:39:23 +00:00
Federico Di Gregorio
2ae0c32031 ZPsycopgDA now uses connection-level type-casters. 2007-02-23 15:23:06 +00:00
Federico Di Gregorio
6598a279e2 Added support for per-cursor and per-connection typecasters. 2007-02-22 15:16:54 +00:00
Federico Di Gregorio
c2e16b8901 Applied patch from #135. 2007-02-11 08:25:33 +00:00
Federico Di Gregorio
09c866221c Password obfuscation done right (closes: #147) 2007-02-11 08:11:22 +00:00
Federico Di Gregorio
3a94e747d7 Encodings from Karsten (part 2.) 2007-01-19 14:47:21 +00:00
Federico Di Gregorio
5642a68adb Encodings from Karsten. 2007-01-19 14:38:01 +00:00
Federico Di Gregorio
1c16009985 Added support for NULL in arrays (closes: #154) 2007-01-19 14:08:06 +00:00
Federico Di Gregorio
2883428791 Lets do a beta release. 2007-01-19 03:40:27 +00:00
Federico Di Gregorio
b074dd4d8b Encoding fixes. 2007-01-16 23:39:08 +00:00
Federico Di Gregorio
f43a52f781 Added RealDictCursor from #143. 2007-01-16 13:45:41 +00:00
Federico Di Gregorio
5c425f5294 Check for Python errors during copy (closes: #134). 2007-01-16 12:03:29 +00:00
Federico Di Gregorio
8c2c72a48a Applied patch from #148. 2007-01-16 11:32:01 +00:00
Federico Di Gregorio
e02f569dd3 Password obfuscation to close: #147. 2007-01-16 11:29:07 +00:00
Federico Di Gregorio
bee60c203a Fixed conversion of date to Zope DateTime (closes: #145) 2007-01-16 11:15:52 +00:00
Federico Di Gregorio
e59ef4de4b Moved SQL_IN to extensions and away from extras. 2007-01-16 10:58:05 +00:00
Federico Di Gregorio
d342d37e27 Fixed problem with locales in mx.DateTime adaptation. 2007-01-16 10:47:28 +00:00
Federico Di Gregorio
b651781f63 Added note about missign pg headers to INSTALL. 2007-01-16 10:11:28 +00:00
Federico Di Gregorio
d061b384d9 Fixed problem with year > 9999. 2007-01-16 07:57:22 +00:00
Fabio Tranchitella
401af084ab Renamed psycopgda-configure.zcml as psycopg2da-configure.zcml. 2006-11-06 00:37:45 +00:00
Federico Di Gregorio
f4dc6936a2 Builds again on win32 (closes: #132). 2006-10-29 03:12:51 +00:00
Federico Di Gregorio
0f5e4e7340 Fixed #136. 2006-10-21 07:39:16 +00:00
Federico Di Gregorio
ac5a747e95 Fixed precision and scale. 2006-10-21 07:33:44 +00:00
Federico Di Gregorio
bfe5b8fe6b Added iteritem method to DictRow. 2006-10-06 05:22:54 +00:00
Federico Di Gregorio
d189203f9f .callproc() patch from Moshe (support for result sets.) 2006-10-03 05:54:22 +00:00
Fabio Tranchitella
3381b0362b Debian release 2.0.5.1-2. 2006-10-03 00:23:57 +00:00
Federico Di Gregorio
96f631d41e Merge from 2.0 branch up to r839. 2006-09-30 06:57:35 +00:00
Federico Di Gregorio
5689f07de4 Infinity ok in Zope (closes: #122) 2006-09-30 06:39:51 +00:00
Federico Di Gregorio
4820213b7f Fixed fractionary seconds >59 problem (closes: #131) 2006-09-30 06:35:12 +00:00
Federico Di Gregorio
bc580e3383 Fixed #129. 2006-09-30 06:24:24 +00:00
Federico Di Gregorio
168d9c36af Fractionary seconds fix (closes: #130) 2006-09-30 06:16:24 +00:00
Federico Di Gregorio
ca860424e6 Fixed lib/errorcodes.py. 2006-09-23 05:36:18 +00:00
Federico Di Gregorio
43518d067e Added lib/errorcodes.py. 2006-09-23 05:35:03 +00:00
Federico Di Gregorio
1fe6269904 Piet Delport patches: final cleanup and PEP 353 macros. 2006-09-23 05:19:30 +00:00
Federico Di Gregorio
1d8af808bf Piet Delport patches: 3 of 3. 2006-09-23 05:15:36 +00:00
Federico Di Gregorio
474d8b9d51 Piet Delport patches: 2 of 3. 2006-09-23 05:14:24 +00:00
Federico Di Gregorio
3009a29b11 Piet Delport patches: 1 of 3. 2006-09-23 05:10:58 +00:00
Fabio Tranchitella
49aa00d783 Updated the debian directory (debian release 2.0.5.1-1). 2006-09-19 03:53:10 +00:00
Fabio Tranchitella
146f64e71d Added psycopg2da, the zope3 database adapter for psycopg2. 2006-09-19 03:50:35 +00:00
Federico Di Gregorio
52666ef5bd Fixed syntax error in lib/extras.py. 2006-09-10 14:51:43 +00:00
Federico Di Gregorio
31189ef0df Fixed syntax error in extras module (closes: #123). 2006-09-10 14:50:03 +00:00
Federico Di Gregorio
a9d307140e mx fix to build on win32. 2006-09-02 09:00:47 +00:00
Federico Di Gregorio
2007652589 mx fix to build on win32. 2006-09-02 09:00:39 +00:00
Federico Di Gregorio
dbd976bc03 Double mutex destroy fix. 2006-09-02 08:50:58 +00:00
Federico Di Gregorio
afaca71aa9 Double mutex destroy fix. 2006-09-02 08:50:30 +00:00
Federico Di Gregorio
269156d9bf Added some file-like attributes to lobject. 2006-09-02 05:33:03 +00:00
Federico Di Gregorio
64bd7ae61c Large objects landing.. 2006-09-02 04:57:50 +00:00
Federico Di Gregorio
36785f753b Work on large objects continue. 2006-09-01 17:15:27 +00:00
Federico Di Gregorio
0b9d13455d Missing file. 2006-09-01 16:44:07 +00:00
Federico Di Gregorio
b8f3cef62f psycopg is enlarging.. 2006-09-01 16:27:02 +00:00
Federico Di Gregorio
64933f2004 Merge from 2_0_x branch up to r814. 2006-09-01 13:46:57 +00:00
267 changed files with 44738 additions and 14105 deletions

4
.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1,4 @@
github:
- dvarrazzo
custom:
- "https://www.paypal.me/dvarrazzo"

View File

@ -0,0 +1,23 @@
---
name: Problem installing psycopg2
about: Report a case in which psycopg2 failed to install on your platform
title: ''
labels: ''
assignees: ''
---
**This is a bug tracker**
If you have a question, such has "how do you do X with Python/PostgreSQL/psycopg2" please [write to the mailing list](https://lists.postgresql.org/manage/) or [open a question](https://github.com/psycopg/psycopg2/discussions) instead.
**Before opening this ticket, please confirm that:**
- [ ] I am running the latest version of pip, i.e. typing ``pip --version`` you get [this version](https://pypi.org/project/pip/).
- [ ] I have read the [installation documentation](https://www.psycopg.org/docs/install.html) and the [frequently asked questions](https://www.psycopg.org/docs/faq.html)
- [ ] If install failed, I typed `pg_config` on the command line and I obtained an output instead of an error.
**Please complete the following information:**
- OS:
- Psycopg version:
- Python version:
- PostgreSQL version:
- pip version

View File

@ -0,0 +1,27 @@
---
name: Problem using psycopg2
about: Report a case in which psycopg2 is not working as expected
title: ''
labels: ''
assignees: ''
---
**This is a bug tracker**
If you have a question, such has "how do you do X with Python/PostgreSQL/psycopg2" please [write to the mailing list](https://lists.postgresql.org/manage/) or [open a question](https://github.com/psycopg/psycopg2/discussions) instead.
**Please complete the following information:**
- OS:
- Psycopg version:
- Python version:
- PostgreSQL version:
- pip version
**Describe the bug**
Please let us know:
1: what you did
2: what you expected to happen
3: what happened instead
If possible, provide a script reproducing the issue.

6
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"

18
.github/workflows/docs.yml vendored Normal file
View File

@ -0,0 +1,18 @@
name: Build documentation
on:
push:
branches:
# This should match the DOC_BRANCH value in the psycopg-website Makefile
- master
jobs:
docs:
runs-on: ubuntu-latest
steps:
- name: Trigger docs build
uses: peter-evans/repository-dispatch@v3
with:
repository: psycopg/psycopg-website
event-type: psycopg2-commit
token: ${{ secrets.ACCESS_TOKEN }}

266
.github/workflows/packages.yml vendored Normal file
View File

@ -0,0 +1,266 @@
---
name: Build packages
on:
- workflow_dispatch
env:
PIP_BREAK_SYSTEM_PACKAGES: "1"
LIBPQ_VERSION: "16.0"
OPENSSL_VERSION: "1.1.1w"
jobs:
sdist: # {{{
if: true
strategy:
fail-fast: false
matrix:
include:
- package_name: psycopg2
- package_name: psycopg2-binary
runs-on: ubuntu-latest
steps:
- name: Checkout repos
uses: actions/checkout@v4
- name: Build sdist
run: ./scripts/build/build_sdist.sh
env:
PACKAGE_NAME: ${{ matrix.package_name }}
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: sdist-${{ matrix.package_name }}
path: |
dist/*.tar.gz
env:
PSYCOPG2_TESTDB: postgres
PSYCOPG2_TESTDB_HOST: 172.17.0.1
PSYCOPG2_TESTDB_USER: postgres
PSYCOPG2_TESTDB_PASSWORD: password
PSYCOPG2_TEST_FAST: 1
services:
postgresql:
image: postgres:16
env:
POSTGRES_PASSWORD: password
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
# }}}
linux: # {{{
if: true
strategy:
fail-fast: false
matrix:
platform: [manylinux, musllinux]
arch: [x86_64, i686, aarch64, ppc64le]
pyver: [cp38, cp39, cp310, cp311, cp312, cp313]
runs-on: ubuntu-latest
steps:
- name: Checkout repos
uses: actions/checkout@v4
- name: Set up QEMU for multi-arch build
uses: docker/setup-qemu-action@v3
- name: Cache libpq build
uses: actions/cache@v4
with:
path: /tmp/libpq.build
key: libpq-${{ env.LIBPQ_VERSION }}-${{ matrix.platform }}-${{ matrix.arch }}
- name: Build wheels
uses: pypa/cibuildwheel@v2.23.2
env:
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
CIBW_MANYLINUX_I686_IMAGE: manylinux2014
CIBW_MANYLINUX_AARCH64_IMAGE: manylinux2014
CIBW_MANYLINUX_PPC64LE_IMAGE: manylinux2014
CIBW_BUILD: ${{matrix.pyver}}-${{matrix.platform}}_${{matrix.arch}}
CIBW_ARCHS_LINUX: auto aarch64 ppc64le
CIBW_BEFORE_ALL_LINUX: ./scripts/build/wheel_linux_before_all.sh
CIBW_REPAIR_WHEEL_COMMAND: >-
./scripts/build/strip_wheel.sh {wheel}
&& auditwheel repair -w {dest_dir} {wheel}
CIBW_TEST_COMMAND: >-
export PYTHONPATH={project} &&
python -c "import tests; tests.unittest.main(defaultTest='tests.test_suite')"
CIBW_ENVIRONMENT_PASS_LINUX: LIBPQ_VERSION OPENSSL_VERSION
CIBW_ENVIRONMENT: >-
PACKAGE_NAME=psycopg2-binary
LIBPQ_BUILD_PREFIX=/host/tmp/libpq.build
PATH="$LIBPQ_BUILD_PREFIX/bin:$PATH"
LD_LIBRARY_PATH="$LIBPQ_BUILD_PREFIX/lib:$LIBPQ_BUILD_PREFIX/lib64"
PSYCOPG2_TESTDB=postgres
PSYCOPG2_TESTDB_HOST=172.17.0.1
PSYCOPG2_TESTDB_USER=postgres
PSYCOPG2_TESTDB_PASSWORD=password
PSYCOPG2_TEST_FAST=1
- uses: actions/upload-artifact@v4
with:
name: linux-${{matrix.pyver}}-${{matrix.platform}}_${{matrix.arch}}
path: ./wheelhouse/*.whl
services:
postgresql:
image: postgres:16
env:
POSTGRES_PASSWORD: password
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
# }}}
macos: # {{{
runs-on: macos-latest
if: true
strategy:
fail-fast: false
matrix:
# These archs require an Apple M1 runner: [arm64, universal2]
arch: [x86_64, arm64]
pyver: [cp39, cp310, cp311, cp312, cp313]
steps:
- name: Checkout repos
uses: actions/checkout@v4
- name: Cache libpq build
uses: actions/cache@v4
with:
path: /tmp/libpq.build
key: libpq-${{ env.LIBPQ_VERSION }}-macos-${{ matrix.arch }}
- name: Build wheels
uses: pypa/cibuildwheel@v2.23.2
env:
CIBW_BUILD: ${{matrix.pyver}}-macosx_${{matrix.arch}}
CIBW_ARCHS_MACOS: ${{matrix.arch}}
MACOSX_ARCHITECTURE: ${{matrix.arch}}
CIBW_BEFORE_ALL_MACOS: ./scripts/build/wheel_macos_before_all.sh
CIBW_TEST_COMMAND: >-
export PYTHONPATH={project} &&
python -c "import tests; tests.unittest.main(defaultTest='tests.test_suite')"
CIBW_ENVIRONMENT: >-
PG_VERSION=16
PACKAGE_NAME=psycopg2-binary
PSYCOPG2_TESTDB=postgres
PATH="/tmp/libpq.build/bin:$PATH"
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: macos-${{matrix.pyver}}-macos-${{matrix.arch}}
path: ./wheelhouse/*.whl
# }}}
windows: # {{{
runs-on: windows-latest
if: true
strategy:
fail-fast: false
matrix:
arch: [win_amd64]
pyver: [cp38, cp39, cp310, cp311, cp312, cp313]
package_name: [psycopg2, psycopg2-binary]
defaults:
run:
shell: bash
steps:
# there are some other libpq in PATH
- name: Drop spurious libpq in the path
run: rm -rf c:/tools/php C:/Strawberry/c/bin
- name: Checkout repo
uses: actions/checkout@v4
- name: Start PostgreSQL service for test
run: |
$PgSvc = Get-Service "postgresql*"
Set-Service $PgSvc.Name -StartupType manual
$PgSvc.Start()
shell: powershell
- name: Export GitHub Actions cache environment variables
uses: actions/github-script@v7
with:
script: |
const path = require('path')
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
core.addPath(path.join(process.env.VCPKG_INSTALLATION_ROOT, 'installed/x64-windows-release/lib'));
core.addPath(path.join(process.env.VCPKG_INSTALLATION_ROOT, 'installed/x64-windows-release/bin'));
- name: Create the binary package source tree
run: >-
sed -i 's/^setup(name="psycopg2"/setup(name="${{matrix.package_name}}"/'
setup.py
if: ${{ matrix.package_name != 'psycopg2' }}
- name: Build wheels
uses: pypa/cibuildwheel@v2.23.2
env:
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite" # cache vcpkg
CIBW_BUILD: ${{matrix.pyver}}-${{matrix.arch}}
CIBW_ARCHS_WINDOWS: AMD64 x86
CIBW_BEFORE_BUILD_WINDOWS: '.\scripts\build\wheel_win32_before_build.bat'
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: >-
delvewheel repair -w {dest_dir}
--no-mangle "libiconv-2.dll;libwinpthread-1.dll" {wheel}
CIBW_TEST_COMMAND: >-
set PYTHONPATH={project} &&
python -c "import tests; tests.unittest.main(defaultTest='tests.test_suite')"
# Note: no fast test because we don't run Windows tests
CIBW_ENVIRONMENT_WINDOWS: >-
PSYCOPG2_TESTDB=postgres
PSYCOPG2_TESTDB_USER=postgres
PSYCOPG2_TESTDB_HOST=localhost
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: windows-${{ matrix.package_name }}-${{matrix.pyver}}-${{matrix.arch}}
path: ./wheelhouse/*.whl
# }}}
merge: # {{{
runs-on: ubuntu-latest
needs:
- sdist
- linux
- macos
- windows
steps:
- name: Merge Artifacts
uses: actions/upload-artifact/merge@v4
with:
name: psycopg2-artifacts
delete-merged: true
# }}}

79
.github/workflows/tests.yml vendored Normal file
View File

@ -0,0 +1,79 @@
name: Tests
env:
PIP_BREAK_SYSTEM_PACKAGES: "1"
on:
push:
pull_request:
jobs:
linux:
runs-on: ubuntu-latest
if: true
strategy:
fail-fast: false
matrix:
include:
- {python: "3.8", postgres: "12"}
- {python: "3.9", postgres: "13"}
- {python: "3.10", postgres: "14"}
- {python: "3.11", postgres: "15"}
- {python: "3.12", postgres: "16"}
- {python: "3.13", postgres: "17"}
# Opposite extremes of the supported Py/PG range, other architecture
- {python: "3.8", postgres: "17", architecture: "x86"}
- {python: "3.9", postgres: "16", architecture: "x86"}
- {python: "3.10", postgres: "15", architecture: "x86"}
- {python: "3.11", postgres: "14", architecture: "x86"}
- {python: "3.12", postgres: "13", architecture: "x86"}
- {python: "3.13", postgres: "12", architecture: "x86"}
env:
PSYCOPG2_TESTDB: postgres
PSYCOPG2_TESTDB_HOST: 127.0.0.1
PSYCOPG2_TESTDB_USER: postgres
PSYCOPG2_TESTDB_PASSWORD: password
services:
postgresql:
image: postgres:${{ matrix.postgres }}
env:
POSTGRES_PASSWORD: password
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
# Can enable to test an unreleased libpq version.
- name: install libpq 16
if: false
run: |
set -x
rel=$(lsb_release -c -s)
echo "deb http://apt.postgresql.org/pub/repos/apt ${rel}-pgdg main 16" \
| sudo tee -a /etc/apt/sources.list.d/pgdg.list
sudo apt-get -qq update
pqver=$(apt-cache show libpq5 | grep ^Version: | head -1 \
| awk '{print $2}')
sudo apt-get -qq -y install "libpq-dev=${pqver}" "libpq5=${pqver}"
- name: Install tox
run: pip install "tox < 4"
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Run tests
env:
MATRIX_PYTHON: ${{ matrix.python }}
run: tox -e ${MATRIX_PYTHON%-dev}
timeout-minutes: 5

18
.gitignore vendored Normal file
View File

@ -0,0 +1,18 @@
MANIFEST
*~
*.userprefs
*.pidb
*.pyc
*.sw[po]
*.egg-info/
dist/*
/build
env
env?
.idea
.tox
.vscode/
/rel
/wheels
/packages
/wheelhouse

11
AUTHORS
View File

@ -1,8 +1,15 @@
Main authors: Main authors:
Federico Di Gregorio <fog@debian.org> Federico Di Gregorio <fog@debian.org>
Daniele Varrazzo <daniele.varrazzo@gmail.com>
For the win32 port: For the win32 port:
Jason Erickson <jerickso@indian.com> (most of his changes are still in 2.0) Jason Erickson <jerickso@indian.com>
Additional Help: Additional Help:
Peter Fein contributed a logging connection/cursor class that even if it
was not used directly heavily influenced the implementation currently in
psycopg2.extras.
Jan Urbański (re)started the work on asynchronous queries and contributed
both on that and on other parts of psycopg2.

1219
ChangeLog

File diff suppressed because it is too large Load Diff

50
INSTALL
View File

@ -1,48 +1,4 @@
Compiling and installing psycopg Installation instructions are included in the docs.
********************************
** Important note: if you plan to use psyopg2 in a multithreaed application Please check the 'doc/src/install.rst' file or online at
make sure that your libpq has been compiled with the --with-thread-safety <https://www.psycopg.org/docs/install.html>.
option. psycopg2 will work correctly even with a non-thread-safe libpq but
libpq will leak memory.
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 setup.cfg file
and change any settings to follow your system (or taste); then:
python setup.py build
to build in the local directory; and:
python setup.py install
to install system-wide.
Using setuptools and EasyInstall
================================
If setuptools are installed on your system you can easily create an egg for
psycopg and install it. Download the source distribution (if you're reading
this file you probably already have) and then edit setup.cfg to your taste
and build from the source distribution top-level directory using:
easy_install .
Compiling under Windows with mingw32
====================================
You can compile psycopg under Windows platform with mingw32
(http://www.mingw.org/) compiler. MinGW is also shipped with IDEs such as
Dev-C++ (http://www.bloodshed.net/devcpp.html) and Code::Blocks
(http://www.codeblocks.org). gcc binaries should be in your PATH.
You need a PostgreSQL with include and libary files installed. At least v8.0 is required.
First you need to create a libpython2X.a as described in
http://starship.python.net/crew/kernr/mingw32/Notes.html. Then run:
python setup.py build_ext --compiler=mingw32 install

69
LICENSE
View File

@ -1,35 +1,38 @@
psycopg and the GPL psycopg2 and the LGPL
=================== ---------------------
psycopg is free software; you can redistribute it and/or modify psycopg2 is free software: you can redistribute it and/or modify it
it under the terms of the GNU General Public License as published by under the terms of the GNU Lesser General Public License as published
the Free Software Foundation; either version 2 of the License, or by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. See file COPYING for details. (at your option) any later version.
As a special exception, specific permission is granted for the GPLed psycopg2 is distributed in the hope that it will be useful, but WITHOUT
code in this distribition to be linked to OpenSSL and PostgreSQL libpq ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
without invoking GPL clause 2(b). FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
Note that the GPL was chosen to avoid proprietary adapters based on In addition, as a special exception, the copyright holders give
psycopg code. Using psycopg in a proprietary product (even bundling permission to link this program with the OpenSSL library (or with
psycopg with the proprietary product) is fine as long as: modified versions of OpenSSL that use the same license as OpenSSL),
and distribute linked combinations including the two.
1. psycopg is called from Python only using only the provided API You must obey the GNU Lesser General Public License in all respects for
(i.e., no linking with C code and no C modules based on it); and all of the code used other than OpenSSL. If you modify file(s) with this
exception, you may extend this exception to your version of the file(s),
but you are not obligated to do so. If you do not wish to do so, delete
this exception statement from your version. If you delete this exception
statement from all source files in the program, then also delete it here.
You should have received a copy of the GNU Lesser General Public License
along with psycopg2 (see the doc/ directory.)
If not, see <https://www.gnu.org/licenses/>.
2. all the other points of the GPL are respected (you offer a copy
of psycopg's source code, and so on.)
Alternative licenses Alternative licenses
==================== --------------------
If you prefer you can use the Zope Database Adapter ZPsycopgDA (i.e., The following BSD-like license applies (at your option) to the files following
every file inside the ZPsycopgDA directory) user the ZPL license as the pattern ``psycopg/adapter*.{h,c}`` and ``psycopg/microprotocol*.{h,c}``:
published on the Zope web site, http://www.zope.org/Resources/ZPL.
Also, the following BSD-like license applies (at your option) to the
files following the pattern psycopg/adapter*.{h,c} and
psycopg/microprotocol*.{h,c}:
Permission is granted to anyone to use this software for any purpose, Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it including commercial applications, and to alter it and redistribute it
@ -39,22 +42,8 @@ psycopg/microprotocol*.{h,c}:
claim that you wrote the original software. If you use this claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation software in a product, an acknowledgment in the product documentation
would be appreciated but is not required. would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not 2. Altered source versions must be plainly marked as such, and must not
be misrepresented as being the original software. be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
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.
Proprietary licenses
====================
A non-exclusive license is available for companies that want to include
psycopg in their proprietary products without respecting the spirit of the
GPL. The price of the license is one day of development done by the author,
at the consulting fee he applies to his usual customers at the day of the
request.

View File

@ -1,12 +1,9 @@
recursive-include psycopg *.c *.h recursive-include psycopg *.c *.h *.manifest
recursive-include lib *.py recursive-include lib *.py
recursive-include tests *.py recursive-include tests *.py
recursive-include ZPsycopgDA *.py *.gif *.dtml include doc/README.rst doc/SUCCESS doc/COPYING.LESSER doc/pep-0249.txt
recursive-include examples *.py somehackers.jpg whereareyou.jpg include doc/Makefile doc/requirements.txt
recursive-include debian * recursive-include doc/src *.rst *.py *.css Makefile
recursive-include doc TODO HACKING SUCCESS ChangeLog-1.x async.txt
recursive-include scripts *.py *.sh recursive-include scripts *.py *.sh
include scripts/maketypes.sh scripts/buildtypes.py include AUTHORS README.rst INSTALL LICENSE NEWS
include AUTHORS README INSTALL LICENSE ChangeLog include MANIFEST.in setup.py setup.cfg Makefile
include PKG-INFO MANIFEST.in MANIFEST setup.py setup.cfg
recursive-include doc *.rst *.css *.html

104
Makefile Normal file
View File

@ -0,0 +1,104 @@
# Makefile for psycopg2. Do you want to...
#
# Build the library::
#
# make
#
# Build the documentation::
#
# make env (once)
# make docs
#
# Create a source package::
#
# make sdist
#
# Run the test::
#
# make check # this requires setting up a test database with the correct user
PYTHON := python$(PYTHON_VERSION)
PYTHON_VERSION ?= $(shell $(PYTHON) -c 'import sys; print ("%d.%d" % sys.version_info[:2])')
BUILD_DIR = $(shell pwd)/build/lib.$(PYTHON_VERSION)
SOURCE_C := $(wildcard psycopg/*.c psycopg/*.h)
SOURCE_PY := $(wildcard lib/*.py)
SOURCE_TESTS := $(wildcard tests/*.py)
SOURCE_DOC := $(wildcard doc/src/*.rst)
SOURCE := $(SOURCE_C) $(SOURCE_PY) $(SOURCE_TESTS) $(SOURCE_DOC)
PACKAGE := $(BUILD_DIR)/psycopg2
PLATLIB := $(PACKAGE)/_psycopg.so
PURELIB := $(patsubst lib/%,$(PACKAGE)/%,$(SOURCE_PY))
BUILD_OPT := --build-lib=$(BUILD_DIR)
BUILD_EXT_OPT := --build-lib=$(BUILD_DIR)
SDIST_OPT := --formats=gztar
ifdef PG_CONFIG
BUILD_EXT_OPT += --pg-config=$(PG_CONFIG)
endif
VERSION := $(shell grep PSYCOPG_VERSION setup.py | head -1 | sed -e "s/.*'\(.*\)'/\1/")
SDIST := dist/psycopg2-$(VERSION).tar.gz
.PHONY: check clean
default: package
all: package sdist
package: $(PLATLIB) $(PURELIB)
docs: docs-html
docs-html: doc/html/genindex.html
# for PyPI documentation
docs-zip: doc/docs.zip
sdist: $(SDIST)
env:
$(MAKE) -C doc $@
check:
PYTHONPATH=$(BUILD_DIR) $(PYTHON) -c "import tests; tests.unittest.main(defaultTest='tests.test_suite')" --verbose
testdb:
@echo "* Creating $(TESTDB)"
@if psql -l | grep -q " $(TESTDB) "; then \
dropdb $(TESTDB) >/dev/null; \
fi
createdb $(TESTDB)
# Note to packagers: this requires the postgres user running the test
# to be a superuser. You may change this line to use the superuser only
# to install the contrib. Feel free to suggest a better way to set up the
# testing environment (as the current is enough for development).
psql -f `pg_config --sharedir`/contrib/hstore.sql $(TESTDB)
$(PLATLIB): $(SOURCE_C)
$(PYTHON) setup.py build_ext $(BUILD_EXT_OPT)
$(PACKAGE)/%.py: lib/%.py
$(PYTHON) setup.py build_py $(BUILD_OPT)
touch $@
$(PACKAGE)/tests/%.py: tests/%.py
$(PYTHON) setup.py build_py $(BUILD_OPT)
touch $@
$(SDIST): $(SOURCE)
$(PYTHON) setup.py sdist $(SDIST_OPT)
# docs depend on the build as it partly use introspection.
doc/html/genindex.html: $(PLATLIB) $(PURELIB) $(SOURCE_DOC)
$(MAKE) -C doc html
doc/docs.zip: doc/html/genindex.html
(cd doc/html && zip -r ../docs.zip *)
clean:
rm -rf build
$(MAKE) -C doc clean

1281
NEWS

File diff suppressed because it is too large Load Diff

39
README
View File

@ -1,39 +0,0 @@
psycopg - Python-PostgreSQL Database Adapter
********************************************
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. psycopg 2 also provide full asycronous operations for the really
brave programmer.
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.
psycopg is free software ("free as in freedom" but I like beer too.)
Licensing information is available in the LICENSE file.
Contributors
------------
A short list of contributors to psycopg2 follows (if you feel you belong
to this list and you can't find yourself here just drop me a mail):
* Kudos to piro for all the documentation work.
* Peter Fein contributed a logging connection/cursor class that even if it
was not used directly heavily influenced the implementation currently in
psycopg2.extras.

80
README.rst Normal file
View File

@ -0,0 +1,80 @@
psycopg2 - Python-PostgreSQL Database Adapter
=============================================
Psycopg is the most popular PostgreSQL database adapter for the Python
programming language. Its main features are the complete implementation of
the Python DB API 2.0 specification and the thread safety (several threads can
share the same connection). It was designed for heavily multi-threaded
applications that create and destroy lots of cursors and make a large number
of concurrent "INSERT"s or "UPDATE"s.
Psycopg 2 is mostly implemented in C as a libpq wrapper, resulting in being
both efficient and secure. It features client-side and server-side cursors,
asynchronous communication and notifications, "COPY TO/COPY FROM" support.
Many Python types are supported out-of-the-box and adapted to matching
PostgreSQL data types; adaptation can be extended and customized thanks to a
flexible objects adaptation system.
Psycopg 2 is both Unicode and Python 3 friendly.
.. Note::
The psycopg2 package is still widely used and actively maintained, but it
is not expected to receive new features.
`Psycopg 3`__ is the evolution of psycopg2 and is where `new features are
being developed`__: if you are starting a new project you should probably
start from 3!
.. __: https://pypi.org/project/psycopg/
.. __: https://www.psycopg.org/psycopg3/docs/index.html
Documentation
-------------
Documentation is included in the ``doc`` directory and is `available online`__.
.. __: https://www.psycopg.org/docs/
For any other resource (source code repository, bug tracker, mailing list)
please check the `project homepage`__.
.. __: https://psycopg.org/
Installation
------------
Building Psycopg requires a few prerequisites (a C compiler, some development
packages): please check the install_ and the faq_ documents in the ``doc`` dir
or online for the details.
If prerequisites are met, you can install psycopg like any other Python
package, using ``pip`` to download it from PyPI_::
$ pip install psycopg2
or using ``setup.py`` if you have downloaded the source package locally::
$ python setup.py build
$ sudo python setup.py install
You can also obtain a stand-alone package, not requiring a compiler or
external libraries, by installing the `psycopg2-binary`_ package from PyPI::
$ pip install psycopg2-binary
The binary package is a practical choice for development and testing but in
production it is advised to use the package built from sources.
.. _PyPI: https://pypi.org/project/psycopg2/
.. _psycopg2-binary: https://pypi.org/project/psycopg2-binary/
.. _install: https://www.psycopg.org/docs/install.html#install-from-source
.. _faq: https://www.psycopg.org/docs/faq.html#faq-compile
:Build status: |gh-actions|
.. |gh-actions| image:: https://github.com/psycopg/psycopg2/actions/workflows/tests.yml/badge.svg
:target: https://github.com/psycopg/psycopg2/actions/workflows/tests.yml
:alt: Build status

View File

@ -1,375 +0,0 @@
# 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 = ('2.0.1', '2.0.2', '2.0.3', '2.0.4', '2.0.5')
import sys
import time
import db
import re
import Acquisition
import Shared.DC.ZRDB.Connection
from db import DB
from Globals import HTMLFile
from ExtensionClass import Base
from App.Dialogs import MessageDialog
from DateTime import DateTime
# Build Zope version in a float for later cheks
import App
zope_version = App.version_txt.getZopeVersion()
zope_version = float("%s.%s" %(zope_version[:2]))
# ImageFile is deprecated in Zope >= 2.9
if zope_version < 2.9:
from ImageFile import ImageFile
else:
from App.ImageFile import ImageFile
# import psycopg and functions/singletons needed for date/time conversions
import psycopg2
from psycopg2 import NUMBER, STRING, ROWID, DATETIME
from psycopg2.extensions import INTEGER, LONGINTEGER, FLOAT, BOOLEAN, DATE
from psycopg2.extensions import TIME, INTERVAL
from psycopg2.extensions import new_type, register_type
# add a new connection to a folder
manage_addZPsycopgConnectionForm = HTMLFile('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(Shared.DC.ZRDB.Connection.Connection):
"""ZPsycopg Connection."""
_isAnSQLConnection = 1
id = 'Psycopg2_database_connection'
database_type = 'Psycopg2'
meta_type = title = 'Z Psycopg 2 Database Connection'
icon = 'misc_/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
## connection parameters editing ##
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
self.set_type_casts()
if check: self.connect(self.connection_string)
manage_properties = HTMLFile('dtml/edit', globals())
def manage_edit(self, title, connection_string,
zdatetime=None, check=None, tilevel=2, encoding='UTF-8',
REQUEST=None):
"""Edit the DB connection."""
self.edit(title, connection_string, zdatetime,
check=check, tilevel=tilevel, encoding=encoding)
if REQUEST is not None:
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 psycopg2.__version__[:5] not in ALLOWED_PSYCOPG_VERSIONS:
raise ImportError("psycopg version mismatch (imported %s)" %
psycopg2.__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):
# note that in both cases order *is* important
if self.zdatetime:
# use zope internal datetime routines
register_type(ZDATETIME)
register_type(ZDATE)
register_type(ZTIME)
else:
# use the standard
register_type(DATETIME)
register_type(DATE)
register_type(TIME)
## browsing and table/column management ##
manage_options = Shared.DC.ZRDB.Connection.Connection.manage_options
# + (
# {'label': 'Browse', 'action':'manage_browse'},)
#manage_tables = HTMLFile('dtml/tables', globals())
#manage_browse = HTMLFile('dtml/browse', globals())
info = None
def table_info(self):
return self._v_database_connection.table_info()
def __getitem__(self, name):
if name == 'tableNamed':
if not hasattr(self, '_v_tables'): self.tpValues()
return self._v_tables.__of__(self)
raise KeyError, name
def tpValues(self):
res = []
conn = self._v_database_connection
for d in conn.tables(rdb=0):
try:
name = d['TABLE_NAME']
b = TableBrowser()
b.__name__ = name
b._d = d
b._c = c
try:
b.icon = table_icons[d['TABLE_TYPE']]
except:
pass
r.append(b)
except:
pass
return res
## database connection registration data ##
classes = (Connection,)
meta_types = ({'name':'Z Psycopg 2 Database Connection',
'action':'manage_addZPsycopgConnectionForm'},)
folder_methods = {
'manage_addZPsycopgConnection': manage_addZPsycopgConnection,
'manage_addZPsycopgConnectionForm': manage_addZPsycopgConnectionForm}
__ac_permissions__ = (
('Add Z Psycopg Database Connections',
('manage_addZPsycopgConnectionForm', 'manage_addZPsycopgConnection')),)
# add icons
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())
## zope-specific psycopg typecasters ##
# convert an ISO timestamp string from postgres to a Zope DateTime object
def _cast_DateTime(iso, curs):
if iso:
return DateTime(re.split("GMT\+?|GMT-?", iso)[0])
# this will split us into [date, time, GMT/AM/PM(if there)]
# dt = str.split(' ')
# if len(dt) > 1:
# # we now should split out any timezone info
# dt[1] = dt[1].split('-')[0]
# dt[1] = dt[1].split('+')[0]
# return DateTime(' '.join(dt[:2]))
# else:
# return DateTime(dt[0])
# convert an ISO date string from postgres to a Zope DateTime object
def _cast_Date(iso, curs):
if iso:
return DateTime(iso)
# 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(iso, curs):
if iso:
return DateTime(time.strftime('%Y-%m-%d %H:%M:%S',
time.localtime(time.time())[:3]+
time.strptime(iso[:8], "%H:%M:%S")[3:]))
# NOTE: we don't cast intervals anymore because they are passed
# untouched to Zope.
def _cast_Interval(iso, curs):
return iso
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)
## table browsing helpers ##
class TableBrowserCollection(Acquisition.Implicit):
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: 'i',
STRING.name: 'text',
DATETIME.name: 'date',
INTEGER.name: 'int',
FLOAT.name: 'float',
BOOLEAN.name: 'bin',
ROWID.name: 'int'
}

View File

@ -1,31 +0,0 @@
# 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.
__doc__ = "ZPsycopg Database Adapter Registration."
__version__ = '2.0'
import DA
def initialize(context):
context.registerClass(
DA.Connection,
permission = 'Add Z Psycopg 2 Database Connections',
constructors = (DA.manage_addZPsycopgConnectionForm,
DA.manage_addZPsycopgConnection),
icon = SOFTWARE_HOME + '/Shared/DC/ZRDB/www/DBAdapterFolder_icon.gif')

View File

@ -1,206 +0,0 @@
# 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
from ZODB.POSException import ConflictError
import site
import pool
import psycopg2
from psycopg2.extensions import INTEGER, LONGINTEGER, FLOAT, BOOLEAN, DATE, TIME
from psycopg2 import NUMBER, STRING, ROWID, DATETIME
# the DB object, managing all the real query work
class DB(TM, dbi_db.DB):
_p_oid = _p_changed = _registered = None
def __init__(self, dsn, tilevel, enc='utf-8'):
self.dsn = dsn
self.tilevel = tilevel
self.encoding = enc
self.failures = 0
self.calls = 0
self.make_mappings()
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):
try:
conn = self.getconn(False)
conn.commit()
self.putconn()
except AttributeError:
pass
def _abort(self, *ignored):
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
def make_mappings(self):
"""Generate the mappings used later by self.convert_description()."""
self.type_mappings = {}
for t, s in [(INTEGER,'i'), (LONGINTEGER, 'i'), (NUMBER, 'n'),
(BOOLEAN,'n'), (ROWID, 'i'),
(DATETIME, 'd'), (DATE, 'd'), (TIME, 'd')]:
for v in t.values:
self.type_mappings[v] = (t, s)
def convert_description(self, desc, use_psycopg_types=False):
"""Convert DBAPI-2.0 description field to Zope format."""
items = []
for name, typ, width, ds, p, scale, null_ok in desc:
m = self.type_mappings.get(typ, (STRING, 's'))
items.append({
'name': name,
'type': use_psycopg_types and m[0] or m[1],
'width': width,
'precision': p,
'scale': scale,
'null': null_ok,
})
return items
## tables and rows ##
def tables(self, rdb=0, _care=('TABLE', 'VIEW')):
self._register()
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:
res.append({'TABLE_NAME': name, 'TABLE_TYPE': typ})
self.putconn()
return res
def columns(self, table_name):
self._register()
c = self.getcursor()
try:
r = c.execute('SELECT * FROM "%s" WHERE 1=0' % table_name)
except:
return ()
self.putconn()
return self.convert_description(c.description, True)
## query execution ##
def query(self, query_string, max_rows=None, query_data=None):
self._register()
self.calls = self.calls+1
desc = ()
res = []
nselects = 0
c = self.getcursor()
try:
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:
c.execute(qs, query_data)
else:
c.execute(qs)
except psycopg2.OperationalError, e:
try:
self.close()
except:
pass
self.open()
try:
if query_data:
c.execute(qs, query_data)
else:
c.execute(qs)
except (psycopg2.ProgrammingError,
psycopg2.IntegrityError), e:
if e.args[0].find("concurrent update") > -1:
raise ConflictError
raise e
except (psycopg2.ProgrammingError, psycopg2.IntegrityError), e:
if e.args[0].find("concurrent update") > -1:
raise ConflictError
raise e
if c.description is not None:
nselects += 1
if c.description != desc and nselects > 1:
raise psycopg2.ProgrammingError(
'multiple selects in single query not allowed')
if max_rows:
res = c.fetchmany(max_rows)
else:
res = c.fetchall()
desc = c.description
self.failures = 0
except StandardError, err:
self._abort()
raise err
return self.convert_description(desc), res

View File

@ -1,96 +0,0 @@
<dtml-var manage_page_header>
<dtml-var "manage_form_title(this(), _,
form_title='Add Z Psycopg 2 Database Connection',
help_product='ZPsycopgDA',
help_topic='ZPsycopgDA-Method-Add.stx'
)">
<p class="form-help">
A Zope Psycopg 2 Database Connection is used to connect and execute
queries on a PostgreSQL database.
</p>
<p class="form-help">
In the form below <em>Connection String</em> (also called the Data Source Name
or DSN for short) is a string... (TODO: finish docs)
</p>
<form action="manage_addZPsycopgConnection" method="POST">
<table cellspacing="0" cellpadding="2" border="0">
<tr>
<td align="left" valign="top">
<div class="form-label">
Id
</div>
</td>
<td align="left" valign="top">
<input type="text" name="id" size="40"
value="Psycopg2_database_connection" />
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-optional">
Title
</div>
</td>
<td align="left" valign="top">
<input type="text" name="title" size="40"
value="Z Psycopg 2 Database Connection"/>
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Connection string
</div>
</td>
<td align="left" valign="top">
<input type="text" name="connection_string" size="40" value="" />
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Connect immediately
</div>
</td>
<td align="left" valign="top">
<input type="checkbox" name="check" value="YES" checked="YES" />
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Use Zope's internal DateTime
</div>
</td>
<td align="left" valign="top">
<input type="checkbox" name="zdatetime" value="YES" checked="YES" />
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Transaction isolation level
</div>
</td>
<td align="left" valign="top">
<select name="tilevel:int">
<option value="1">Read committed</option>
<option value="2" selected="YES">Serializable</option>
</select>
</td>
</tr>
<tr>
<td align="left" valign="top" colspan="2">
<div class="form-element">
<input class="form-element" type="submit" name="submit" value=" Add " />
</div>
</td>
</tr>
</table>
</form>
<dtml-var manage_page_footer>

View File

@ -1,11 +0,0 @@
<html>
<head><title><dtml-var title_or_id >tables</title></head>
<body bgcolor="#FFFFFF" link="#000099" vlink="#555555" alink="#77003B">
<dtml-var manage_tabs>
<dtml-tree header="info">
<IMG SRC="<dtml-var SCRIPT_NAME >/misc_/ZPsycopgDA/<dtml-var icon>"
ALT="<dtml-var Type>" BORDER="0">
<dtml-var Name><dtml-var Description>
</dtml-tree>
</body>
</html>

View File

@ -1,67 +0,0 @@
<dtml-var manage_page_header>
<dtml-var manage_tabs>
<form action="manage_edit" method="POST">
<table cellspacing="0" cellpadding="2" border="0">
<tr>
<td align="left" valign="top">
<div class="form-optional">
Title
</div>
</td>
<td align="left" valign="top">
<input type="text" name="title" size="40"
value="&dtml-title;"/>
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Connection string
</div>
</td>
<td align="left" valign="top">
<input type="text" name="connection_string" size="40"
value="&dtml-connection_string;" />
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Use Zope's internal DateTime
</div>
</td>
<td align="left" valign="top">
<input type="checkbox" name="zdatetime" value="YES"
<dtml-if expr="zdatetime">checked="YES"</dtml-if> />
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Transaction isolation level
</div>
</td>
<td align="left" valign="top">
<select name="tilevel:int">
<option value="1"
<dtml-if expr="tilevel==1">selected="YES"</dtml-if>>
Read committed</option>
<option value="2"
<dtml-if expr="tilevel==2">selected="YES"</dtml-if>>
Serializable</option>
</select>
</td>
</tr>
<tr>
<td align="left" valign="top" colspan="2">
<div class="form-element">
<input class="form-element" type="submit" name="submit"
value=" Save Changes " />
</div>
</td>
</tr>
</table>
</form>
<dtml-var manage_page_footer>

View File

@ -1,7 +0,0 @@
<dtml-var standard_html_header>
<dtml-var TABLE_TYPE><dtml-if TABLE_OWNER>
owned by <dtml-var TABLE_OWNER></dtml-if>
<dtml-if REMARKS><br><dtml-var REMARKS></dtml-if>
<dtml-var standard_html_footer>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 924 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 930 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 925 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 915 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 929 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 918 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 884 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 878 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 918 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 926 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 893 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 894 B

View File

@ -1,51 +0,0 @@
# ZPsycopgDA/pool.py - ZPsycopgDA Zope product: connection pooling
#
# 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.
# all the connections are held in a pool of pools, directly accessible by the
# ZPsycopgDA code in db.py
import threading
import psycopg2.pool
_connections_pool = {}
_connections_lock = threading.Lock()
def getpool(dsn, create=True):
_connections_lock.acquire()
try:
if not _connections_pool.has_key(dsn) and create:
_connections_pool[dsn] = \
psycopg2.pool.PersistentConnectionPool(4, 200, dsn)
finally:
_connections_lock.release()
return _connections_pool[dsn]
def flushpool(dsn):
_connections_lock.acquire()
try:
_connections_pool[dsn].closeall()
del _connections_pool[dsn]
finally:
_connections_lock.release()
def getconn(dsn, create=True):
return getpool(dsn, create=create).getconn()
def putconn(dsn, conn, close=False):
getpool(dsn).putconn(conn, close=close)

12
debian/changelog vendored
View File

@ -1,12 +0,0 @@
psycopg2 (1.99.12.1-1) experimental; urgency=low
* Adapted from patches sent by W. Borgert.
* Renamed source package to psycopg2.
-- Federico Di Gregorio <fog@debian.org> Fri, 4 Mar 2005 13:11:43 +0100
psycopg2 (1.99.11-0.1) unstable; urgency=low
* Experimental package.
-- W. Borgert <debacle@debian.org> Sun, 09 Jan 2005 10:14:09 +0000

51
debian/control vendored
View File

@ -1,51 +0,0 @@
Source: psycopg2
Section: python
Priority: optional
Build-depends: postgresql-dev, debhelper (>> 3), python2.3-dev, cdbs
Maintainer: Federico Di Gregorio <fog@debian.org>
Standards-Version: 3.6.1.1
Package: python-psycopg2
Architecture: any
Section: python
Depends: python (>= 2.3), python (<< 2.4), python2.3-psycopg2
Description: Python module for PostgreSQL [dummy package]
psycopg is a PostgreSQL database adapter for the Python programming
language. 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 the full Python DBAPI-2.0 and being thread safe at level 2.
.
psycopg 2 is the next generation psycopg, implementing a much better
type system and even more DBAPI extensions:
.
* support for Python datetime and Decimal types;
* complete implementation of adapt() from PEP 246 to convert Python
types to PostgreSQL ones;
* COPY FROM/COPY TO support;
* inehritable connection and cursor objects and support for connection
and cursor factories;
* automatic encoding conversion and support for unicode queries.
.
This dummy package just depends on the right, default version of Python
and psycopg 2.
Package: python2.3-psycopg2
Architecture: any
Section: python
Depends: ${shlibs:Depends}, python2.3
Description: Python 2.3 module for PostgreSQL
psycopg is a PostgreSQL database adapter for the Python programming
language. 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 the full Python DBAPI-2.0 and being thread safe at level 2.
.
psycopg 2 is the next generation psycopg, implementing a much better
type system and even more DBAPI extensions:
.
* support for Python datetime and Decimal types;
* complete implementation of adapt() from PEP 246 to convert Python
types to PostgreSQL ones;
* COPY FROM/COPY TO support;
* inehritable connection and cursor objects and support for connection
and cursor factories;
* automatic encoding conversion and support for unicode queries.

10
debian/copyright vendored
View File

@ -1,10 +0,0 @@
psycopg 2 can be downloaded from:
http://initd.org/pub/software/psycopg/ALPHA/
Copyright (c) 2001-2005 Federico Di Gregorio <fog@debian.org>
This program is distributed under the GNU GPL.
On Debian GNU/Linux systems, the complete text of the GNU General
Public License can be found in '/usr/share/common-licenses/GPL'.

4
debian/rules vendored
View File

@ -1,4 +0,0 @@
#!/usr/bin/make -f
include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/python-distutils.mk

8
doc/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
env
src/_build/*
html/*
psycopg2.txt
src/sqlstate_errors.rst
# Added by psycopg-website to customize published docs
src/_templates/layout.html

165
doc/COPYING.LESSER Normal file
View File

@ -0,0 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

File diff suppressed because it is too large Load Diff

View File

@ -1,43 +0,0 @@
General information
*******************
Some help to people wanting to hack on psycopg. First of all, note that
*every* function in the psycopg module source code is prefixed by one of the
following words:
psyco is used for function directly callable from python (i.e., functions
in the psycopg module itself.) the only notable exception is the
source code for the module itself, that uses "psyco" even for C-only
functions.
conn is used for functions related to connection objects.
curs is used for functions related to cursor objects.
typecast is used for typecasters and utility function related to
typecaster creation and registration.
Pythonic definition of types and functions available from python are defined
in *_type.c files. Internal functions, callable only from C are located in
*_int.c files and extensions to the DBAPI can be found in the *_ext.c files.
Patches
*******
If you submit a patch, please send a diff generated with the "-u" switch.
Also note that I don't like that much cosmetic changes (like renaming
already existing variables) and I will rewrap the patch to 78 columns
anyway, so it is much better if you do that beforehand.
The type system
***************
Simple types, like integers and strings, are converted to python base types
(the conversion functions are in typecast_base.c). Complex types are
converted to ad-hoc types, defined in the typeobj_*.{c,h} files. The
conversion function are in the other typecast_*.c files. typecast.c defines
the basic utility functions (available through the psycopg module) used when
defining new typecasters from C and python.

39
doc/Makefile Normal file
View File

@ -0,0 +1,39 @@
.PHONY: env help clean html package doctest
docs: html
check: doctest
# The environment is currently required to build the documentation.
# It is not clean by 'make clean'
PYTHON := python$(PYTHON_VERSION)
PYTHON_VERSION ?= $(shell $(PYTHON) -c 'import sys; print("%d.%d" % sys.version_info[:2])')
BUILD_DIR = $(shell pwd)/../build/lib.$(PYTHON_VERSION)
SPHINXBUILD ?= $$(pwd)/env/bin/sphinx-build
SPHOPTS = SPHINXBUILD=$(SPHINXBUILD)
html: package src/sqlstate_errors.rst
$(MAKE) $(SPHOPTS) -C src $@
cp -r src/_build/html .
src/sqlstate_errors.rst: ../psycopg/sqlstate_errors.h $(BUILD_DIR)
./env/bin/python src/tools/make_sqlstate_docs.py $< > $@
$(BUILD_DIR):
$(MAKE) PYTHON=$(PYTHON) -C .. package
doctest:
$(MAKE) PYTHON=$(PYTHON) -C .. package
$(MAKE) $(SPHOPTS) -C src $@
clean:
$(MAKE) $(SPHOPTS) -C src $@
rm -rf html src/sqlstate_errors.rst
env: requirements.txt
$(PYTHON) -m venv env
./env/bin/pip install -r requirements.txt
echo "$$(pwd)/../build/lib.$(PYTHON_VERSION)" \
> env/lib/python$(PYTHON_VERSION)/site-packages/psycopg.pth

20
doc/README.rst Normal file
View File

@ -0,0 +1,20 @@
How to build psycopg documentation
----------------------------------
Building the documentation usually requires building the library too for
introspection, so you will need the same prerequisites_. The only extra
prerequisite is virtualenv_: the packages needed to build the docs will be
installed when building the env.
.. _prerequisites: https://www.psycopg.org/docs/install.html#install-from-source
.. _virtualenv: https://virtualenv.pypa.io/en/latest/
Build the env once with::
make env
Then you can build the documentation with::
make
You should find the rendered documentation in the ``html`` directory.

View File

@ -1,10 +1,10 @@
From: Jack Moffitt <jack@xiph.org> From: Jack Moffitt <jack@xiph.org>
To: Psycopg Mailing List <psycopg@lists.initd.org> To: Psycopg Mailing List <psycopg@lists.initd.org>
Subject: Re: [Psycopg] preparing for 1.0 Subject: Re: [Psycopg] preparing for 1.0
Date: 22 Oct 2001 11:16:21 -0600 Date: 22 Oct 2001 11:16:21 -0600
www.vorbis.com is serving from 5-10k pages per day with psycopg serving www.vorbis.com is serving from 5-10k pages per day with psycopg serving
data for most of that. data for most of that.
I plan to use it for several of our other sites, so that number will I plan to use it for several of our other sites, so that number will
increase. increase.
@ -19,11 +19,11 @@ jack.
From: Yury Don <gercon@vpcit.ru> From: Yury Don <gercon@vpcit.ru>
To: Psycopg Mailing List <psycopg@lists.initd.org> To: Psycopg Mailing List <psycopg@lists.initd.org>
Subject: Re: [Psycopg] preparing for 1.0 Subject: Re: [Psycopg] preparing for 1.0
Date: 23 Oct 2001 09:53:11 +0600 Date: 23 Oct 2001 09:53:11 +0600
We use psycopg and psycopg zope adapter since fisrt public We use psycopg and psycopg zope adapter since fisrt public
release (it seems version 0.4). Now it works on 3 our sites and in intranet release (it seems version 0.4). Now it works on 3 our sites and in intranet
applications. We had few problems, but all problems were quckly applications. We had few problems, but all problems were quickly
solved. The strong side of psycopg is that it's code is well organized solved. The strong side of psycopg is that it's code is well organized
and easy to understand. When I found a problem with non-ISO datestyle in first and easy to understand. When I found a problem with non-ISO datestyle in first
version of psycopg, it took for me 15 or 20 minutes to learn code and version of psycopg, it took for me 15 or 20 minutes to learn code and
@ -32,7 +32,7 @@ to solve the problem, even thouth my knowledge of c were poor.
BTW, segfault with dictfetchall on particular data set (see [Psycopg] BTW, segfault with dictfetchall on particular data set (see [Psycopg]
dictfetchXXX() problems) disappeared in 0.99.8pre2. dictfetchXXX() problems) disappeared in 0.99.8pre2.
-- --
Best regards, Best regards,
Yury Don Yury Don
@ -42,7 +42,7 @@ To: Federico Di Gregorio <fog@debian.org>
Cc: Psycopg Mailing List <psycopg@lists.initd.org> Cc: Psycopg Mailing List <psycopg@lists.initd.org>
Subject: Re: [Psycopg] preparing for 1.0 Subject: Re: [Psycopg] preparing for 1.0
Date: 23 Oct 2001 08:25:52 -0400 Date: 23 Oct 2001 08:25:52 -0400
The US Govt Department of Labor's Office of Disability Employment The US Govt Department of Labor's Office of Disability Employment
Policy's DisabilityDirect website is run on zope and zpsycopg. Policy's DisabilityDirect website is run on zope and zpsycopg.
@ -50,7 +50,7 @@ Policy's DisabilityDirect website is run on zope and zpsycopg.
From: Scott Leerssen <sleerssen@racemi.com> From: Scott Leerssen <sleerssen@racemi.com>
To: Federico Di Gregorio <fog@debian.org> To: Federico Di Gregorio <fog@debian.org>
Subject: Re: [Psycopg] preparing for 1.0 Subject: Re: [Psycopg] preparing for 1.0
Date: 23 Oct 2001 09:56:10 -0400 Date: 23 Oct 2001 09:56:10 -0400
Racemi's load management software infrastructure uses psycopg to handle Racemi's load management software infrastructure uses psycopg to handle
complex server allocation decisions, plus storage and access of complex server allocation decisions, plus storage and access of
@ -66,10 +66,10 @@ From: Andre Schubert <andre.schubert@geyer.kabeljournal.de>
To: Federico Di Gregorio <fog@debian.org> To: Federico Di Gregorio <fog@debian.org>
Cc: Psycopg Mailing List <psycopg@lists.initd.org> Cc: Psycopg Mailing List <psycopg@lists.initd.org>
Subject: Re: [Psycopg] preparing for 1.0 Subject: Re: [Psycopg] preparing for 1.0
Date: 23 Oct 2001 11:46:07 +0200 Date: 23 Oct 2001 11:46:07 +0200
i have changed the psycopg version to 0.99.8pre2 on all devel-machines i have changed the psycopg version to 0.99.8pre2 on all devel-machines
and all segfaults are gone. after my holiday i wil change to 0.99.8pre2 and all segfaults are gone. after my holiday i wil change to 0.99.8pre2
or 1.0 on our production-server. or 1.0 on our production-server.
this server contains several web-sites which are all connected to this server contains several web-sites which are all connected to
postgres over ZPsycopgDA. postgres over ZPsycopgDA.
@ -81,7 +81,7 @@ From: Fred Wilson Horch <fhorch@ecoaccess.org>
To: <psycopg@lists.initd.org> To: <psycopg@lists.initd.org>
Subject: [Psycopg] Success story for psycopg Subject: [Psycopg] Success story for psycopg
Date: 23 Oct 2001 10:59:17 -0400 Date: 23 Oct 2001 10:59:17 -0400
Due to various quirks of PyGreSQL and PoPy, EcoAccess has been looking for Due to various quirks of PyGreSQL and PoPy, EcoAccess has been looking for
a reliable, fast and relatively bug-free Python-PostgreSQL interface for a reliable, fast and relatively bug-free Python-PostgreSQL interface for
our project. our project.
@ -98,7 +98,7 @@ reports and feature requests, and we're looking forward to using psycopg
as the Python interface for additional database-backed web applications. as the Python interface for additional database-backed web applications.
Keep up the good work! Keep up the good work!
-- --
Fred Wilson Horch mailto:fhorch@ecoaccess.org Fred Wilson Horch mailto:fhorch@ecoaccess.org
Executive Director, EcoAccess http://ecoaccess.org/ Executive Director, EcoAccess http://ecoaccess.org/

View File

@ -1,33 +0,0 @@
TODO list for psycopg 2 or later
********************************
Move items to the DONE section only after writing a test for the
implementation. Also add a note on how the item was resolved.
(Obviously I was joking about the test..)
* Find a better way to compile the type-casting code instead of including it
in typecast.c directy. (Including is not that bad, but the need to touch
psycopg/typecast.c every time is bad bad bad.)
* executemany() should _not_ take the async flag, remove it and force multiple
queries to be synchronous.
* Fix all the docstrings.
* Support the protocols API fully.
* Unify the common code in typecast_datetime.c and typecast_mxdatetime.c.
* Port typecasters to new-style classes.
* Write a complete postgresql<->python encodings table.
* Implement binary typecasters (should be easy, but it will take time.)
DONE
====
* Convert type-casters to new-style types in Python 2.2+.
* callproc() never worked, fix it or remove it and raise right exception.
[Removed callproc code, now an exception is raised.]

View File

@ -1,138 +0,0 @@
/* Based on the Epydoc "default.css"
** with some missing reST-related classes
** and Python syntax support (from SilverCity)
*/
/* Body color */
body { background: #ffffff; color: #000000; }
/* Tables */
table.summary, table.details, table.index
{ background: #e8f0f8; color: #000000; }
tr.summary, tr.details, tr.index
{ background: #70b0f0; color: #000000;
text-align: left; font-size: 120%; }
tr.group { background: #c0e0f8; color: #000000;
text-align: left; font-size: 120%;
font-style: italic; }
/* Documentation page titles */
h2.module { margin-top: 0.2em; }
h2.class { margin-top: 0.2em; }
/* Headings */
h1.heading { font-size: +140%; font-style: italic;
font-weight: bold; }
h2.heading { font-size: +125%; font-style: italic;
font-weight: bold; }
h3.heading { font-size: +110%; font-style: italic;
font-weight: normal; }
/* Base tree */
pre.base-tree { font-size: 80%; margin: 0; }
/* TOC */
p.toc { margin: 0; }
/* Details Sections */
table.func-details { background: #e8f0f8; color: #000000;
border: 2px groove #c0d0d0;
padding: 0 1em 0 1em; margin: 0.4em 0 0 0; }
h3.func-detail { background: transparent; color: #000000;
margin: 0 0 1em 0; }
table.var-details { background: #e8f0f8; color: #000000;
border: 2px groove #c0d0d0;
padding: 0 1em 0 1em; margin: 0.4em 0 0 0; }
h3.var-details { background: transparent; color: #000000;
margin: 0 0 1em 0; }
/* Function signatures */
.sig { background: transparent; color: #000000;
font-weight: bold; }
.sig-name { background: transparent; color: #006080; }
.sig-arg, .sig-kwarg, .sig-vararg
{ background: transparent; color: #008060; }
.sig-default { background: transparent; color: #602000; }
.summary-sig { background: transparent; color: #000000; }
.summary-sig-name { background: transparent; color: #204080; }
.summary-sig-arg, .summary-sig-kwarg, .summary-sig-vararg
{ background: transparent; color: #008060; }
/* Doctest blocks */
.py-src { background: transparent; color: #000000; }
.py-prompt { background: transparent; color: #005050;
font-weight: bold;}
.py-string { background: transparent; color: #006030; }
.py-comment { background: transparent; color: #003060; }
.py-keyword { background: transparent; color: #600000; }
.py-output { background: transparent; color: #404040; }
div.code-block,
pre.literal-block,
pre.doctestblock { background: #f4faff; color: #000000;
padding: .5em; margin: 1em;
border: 1px solid #708890; }
table pre.doctestblock
{ background: #dce4ec; color: #000000;
padding: .5em; margin: 1em;
border: 1px solid #708890; }
div.code-block { font-family: monospace; }
/* Variable values */
pre.variable { background: #dce4ec; color: #000000;
padding: .5em; margin: 0;
border: 1px solid #708890; }
.variable-linewrap { background: transparent; color: #604000; }
.variable-ellipsis { background: transparent; color: #604000; }
.variable-quote { background: transparent; color: #604000; }
.re { background: transparent; color: #000000; }
.re-char { background: transparent; color: #006030; }
.re-op { background: transparent; color: #600000; }
.re-group { background: transparent; color: #003060; }
.re-ref { background: transparent; color: #404040; }
/* Navigation bar */
table.navbar { background: #a0c0ff; color: #0000ff;
border: 2px groove #c0d0d0; }
th.navbar { background: #a0c0ff; color: #0000ff; }
th.navselect { background: #70b0ff; color: #000000; }
.nomargin { margin: 0; }
/* Links */
a:link { background: transparent; color: #0000ff; }
a:visited { background: transparent; color: #204080; }
a.navbar:link { background: transparent; color: #0000ff;
text-decoration: none; }
a.navbar:visited { background: transparent; color: #204080;
text-decoration: none; }
/* Admonitions */
div.warning,
div.note { background-color: #c0e0f8;
border: thin solid black;
padding: 1em;
margin-left: 1em;
margin-right: 1em; }
div.warning .first,
div.note .first { font-family: sans-serif;
font-size: 110%;
margin-right: 0.5em; }
/* Lists */
ul { margin-top: 0; }
/* Python syntax */
.p_character { color: olive; }
.p_classname { color: blue; font-weight: bold; }
.p_commentblock {color: gray; font-style: italic; }
.p_commentline { color: green; font-style: italic; }
.p_default {}
.p_defname { color: #009999; font-weight: bold; }
.p_identifier { color: black; }
.p_number { color: #009999; }
.p_operator { color: black; }
.p_string { color: #7F007F; }
.p_stringeol { color: #7F007F; }
.p_triple { color: #7F0000; }
.p_tripledouble { color: #7F0000; }
.p_word { color: navy; font-weight: bold; }

View File

@ -1,67 +0,0 @@
psycopg asynchronous API
************************
** Important: async quaeries are not enabled for 2.0 **
Program code can initiate an asynchronous query by passing an 'async=1' flag
to the .execute() method. A very simple example, from the connection to the
query:
conn = psycopg.connect(database='test')
curs = conn.cursor()
curs.execute("SEECT * from test WHERE fielda > %s", (1971,), async=1)
From then on any query on other cursors derived from the same connection is
doomed to fail (and raise an exception) until the original cursor (the one
executing the query) complete the asynchronous operation. This can happen in
a number of different ways:
1) one of the .fetchXXX() methods is called, effectively blocking untill
data has been sent from the backend to the client, terminating the
query.
2) .cancel() is called. This method tries to abort the current query and
will block until the query is aborted or fully executed. The return
value is True if the query was successfully aborted or False if it
was executed. Query result are discarded in both cases.
3) .execute() is called again on the same cursor (.execute() on a
different cursor will simply raise an exception.) This waits for the
complete execution of the current query, discard any data and execute
the new one.
Note that calling .execute() two times in a row will not abort the former
query and will temporarily go to synchronous mode until the first of the two
queries is executed.
Cursors now have some extra methods that make them usefull during
asynchronous queries:
.fileno()
Returns the file descriptor associated with the current connection and
make possible to use a cursor in a context where a file object would be
expected (like in a select() call.)
.isbusy()
Returns True if the backend is still processing the query or false if
data is ready to be fetched (by one of the .fetchXXX() methods.)
A code snippet that shows how to use the cursor object in a select() call:
import psycopg
import select
conn = psycopg.connect(database='test')
curs = conn.cursor()
curs.execute("SEECT * from test WHERE fielda > %s", (1971,), async=1)
# wait for input with a maximum timeout of 5 seconds
query_ended = False
while not query_ended:
rread, rwrite, rspec = select([cursor, another_file], [], [], 5)
if not cursor.isbusy():
query_ended = True
# manage input from other sources like other_file, etc.
print "Query Results:"
for row in cursor:
print row

View File

@ -1,260 +0,0 @@
=======================================
psycopg 2 extensions to the DBAPI 2.0
=======================================
This document is a short summary of the extensions built in psycopg 2.0.x over
the standard `Python Database API Specification 2.0`__, usually called simply
DBAPI-2.0 or even PEP-249. Before reading on this document please make sure
you already know how to program in Python using a DBAPI-2.0 compliant driver:
basic concepts like opening a connection, executing queries and commiting or
rolling back a transaction will not be explained but just used.
.. __: http://www.python.org/peps/pep-0249.html
Many objects and extension functions are defined in the `psycopg2.extensions`
module.
Connection and cursor factories
===============================
psycopg 2 exposes two new-style classes that can be sub-classed and expanded to
adapt them to the needs of the programmer: `cursor` and `connection`. The
`connection` class is usually sub-classed only to provide an easy way to create
customized cursors but other uses are possible. `cursor` is much more
interesting, because it is the class where query building, execution and result
type-casting into Python variables happens.
An example of cursor subclass performing logging is::
import psycopg2
import psycopg2.extensions
import logging
class LoggingCursor(psycopg2.extensions.cursor):
def execute(self, sql, args=None):
logger = logging.getLogger('sql_debug')
logger.info(self.mogrify(sql, args))
try:
psycopg2.extensions.cursor.execute(self, sql, args)
except Exception, exc:
logger.error("%s: %s" % (exc.__class__.__name__, exc))
raise
conn = psycopg2.connect(DSN)
curs = conn.cursor(cursor_factory=LoggingCursor)
curs.execute("INSERT INTO mytable VALUES (%s, %s, %s);",
(10, 20, 30))
Row factories
-------------
tzinfo factories
----------------
Setting transaction isolation levels
====================================
psycopg2 connection objects hold informations about the PostgreSQL `transaction
isolation level`_. The current transaction level can be read from the
`.isolation_level` attribute. The default isolation level is ``READ
COMMITTED``. A different isolation level con be set through the
`.set_isolation_level()` method. The level can be set to one of the following
constants, defined in `psycopg2.extensions`:
`ISOLATION_LEVEL_AUTOCOMMIT`
No transaction is started when command are issued and no
`.commit()`/`.rollback()` is required. Some PostgreSQL command such as
``CREATE DATABASE`` can't run into a transaction: to run such command use
`.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)`.
`ISOLATION_LEVEL_READ_COMMITTED`
This is the default value. A new transaction is started at the first
`.execute()` command on a cursor and at each new `.execute()` after a
`.commit()` or a `.rollback()`. The transaction runs in the PostgreSQL
``READ COMMITTED`` isolation level.
`ISOLATION_LEVEL_SERIALIZABLE`
Transactions are run at a ``SERIALIZABLE`` isolation level.
.. _transaction isolation level:
http://www.postgresql.org/docs/8.1/static/transaction-iso.html
Adaptation of Python values to SQL types
========================================
psycopg2 casts Python variables to SQL literals by type. Standard Python types
are already adapted to the proper SQL literal.
Example: the Python function::
curs.execute("""INSERT INTO atable (anint, adate, astring)
VALUES (%s, %s, %s)""",
(10, datetime.date(2005, 11, 18), "O'Reilly"))
is converted into the SQL command::
INSERT INTO atable (anint, adate, astring)
VALUES (10, '2005-11-18', 'O''Reilly');
Named arguments are supported too with ``%(name)s`` placeholders. Notice that:
- The Python string operator ``%`` is not used: the `.execute()` function
accepts the values tuple or dictionary as second parameter.
- The variables placeholder must always be a ``%s``, even if a different
placeholder (such as a ``%d`` for an integer) may look more appropriate.
- For positional variables binding, the second argument must always be a
tuple, even if it contains a single variable.
- Only variable values should be bound via this method: it shouldn't be used
to set table or field names. For these elements, ordinary string formatting
should be used before running `.execute()`.
Adapting new types
------------------
Any Python class or type can be adapted to an SQL string. Adaptation mechanism
is similar to the Object Adaptation proposed in the `PEP-246`_ and is exposed
by the `adapt()` function.
psycopg2 `.execute()` method adapts its ``vars`` arguments to the `ISQLQuote`
protocol. Objects that conform to this protocol expose a ``getquoted()`` method
returning the SQL representation of the object as a string.
The easiest way to adapt an object to an SQL string is to register an adapter
function via the `register_adapter()` function. The adapter function must take
the value to be adapted as argument and return a conform object. A convenient
object is the `AsIs` wrapper, whose ``getquoted()`` result is simply the
``str()``\ ingification of the wrapped object.
Example: mapping of a ``Point`` class into the ``point`` PostgreSQL geometric
type::
from psycopg2.extensions import adapt, register_adapter, AsIs
class Point(object):
def __init__(self, x=0.0, y=0.0):
self.x = x
self.y = y
def adapt_point(point):
return AsIs("'(%s,%s)'" % (adapt(point.x), adapt(point.y)))
register_adapter(Point, adapt_point)
curs.execute("INSERT INTO atable (apoint) VALUES (%s)",
(Point(1.23, 4.56),))
The above function call results in the SQL command::
INSERT INTO atable (apoint) VALUES ((1.23, 4.56));
.. _PEP-246: http://www.python.org/peps/pep-0246.html
Type casting of SQL types into Python values
============================================
PostgreSQL objects read from the database can be adapted to Python objects
through an user-defined adapting function. An adapter function takes two
argments: the object string representation as returned by PostgreSQL and the
cursor currently being read, and should return a new Python object. For
example, the following function parses a PostgreSQL ``point`` into the
previously defined ``Point`` class::
def cast_point(value, curs):
if value is not None:
# Convert from (f1, f2) syntax using a regular expression.
m = re.match("\((.*),(.*)\)", value)
if m:
return Point(float(m.group(1)), float(m.group(2)))
To create a mapping from the PostgreSQL type (either standard or user-defined),
its ``oid`` must be known. It can be retrieved either by the second column of
the cursor description::
curs.execute("SELECT NULL::point")
point_oid = curs.description[0][1] # usually returns 600
or by querying the system catalogs for the type name and namespace (the
namespace for system objects is ``pg_catalog``)::
curs.execute("""
SELECT pg_type.oid
FROM pg_type JOIN pg_namespace
ON typnamespace = pg_namespace.oid
WHERE typname = %(typename)s
AND nspname = %(namespace)s""",
{'typename': 'point', 'namespace': 'pg_catalog'})
point_oid = curs.fetchone()[0]
After you know the object ``oid``, you must can and register the new type::
POINT = psycopg2.extensions.new_type((point_oid,), "POINT", cast_point)
psycopg2.extensions.register_type(POINT)
The `new_type()` function binds the object oids (more than one can be
specified) to the adapter function. `register_type()` completes the spell.
Conversion is automatically performed when a column whose type is a registered
``oid`` is read::
curs.execute("SELECT '(10.2,20.3)'::point")
point = curs.fetchone()[0]
print type(point), point.x, point.y
# Prints: "<class '__main__.Point'> 10.2 20.3"
Working with times and dates
============================
Receiving NOTIFYs
=================
Using COPY TO and COPY FROM
===========================
psycopg2 `cursor` object provides an interface to the efficient `PostgreSQL
COPY command`__ to move data from files to tables and back.
The `.copy_to(file, table)` method writes the content of the table
named ``table`` *to* the file-like object ``file``. ``file`` must have a
``write()`` method.
The `.copy_from(file, table)` reads data *from* the file-like object
``file`` appending them to the table named ``table``. ``file`` must have both
``read()`` and ``readline()`` method.
Both methods accept two optional arguments: ``sep`` (defaulting to a tab) is
the columns separator and ``null`` (defaulting to ``\N``) represents ``NULL``
values in the file.
.. __: http://www.postgresql.org/docs/8.1/static/sql-copy.html
PostgreSQL status message and executed query
============================================
`cursor` objects have two special fields related to the last executed query:
- `.query` is the textual representation (str or unicode, depending on what
was passed to `.execute()` as first argument) of the query *after* argument
binding and mogrification has been applied. To put it another way, `.query`
is the *exact* query that was sent to the PostgreSQL backend.
- `.statusmessage` is the status message that the backend sent upon query
execution. It usually contains the basic type of the query (SELECT,
INSERT, UPDATE, ...) and some additional information like the number of
rows updated and so on. Refer to the PostgreSQL manual for more
information.

View File

@ -9,15 +9,15 @@ Replaces: 248
Release-Date: 07 Apr 1999 Release-Date: 07 Apr 1999
Introduction Introduction
This API has been defined to encourage similarity between the This API has been defined to encourage similarity between the
Python modules that are used to access databases. By doing this, Python modules that are used to access databases. By doing this,
we hope to achieve a consistency leading to more easily understood we hope to achieve a consistency leading to more easily understood
modules, code that is generally more portable across databases, modules, code that is generally more portable across databases,
and a broader reach of database connectivity from Python. and a broader reach of database connectivity from Python.
The interface specification consists of several sections: The interface specification consists of several sections:
* Module Interface * Module Interface
* Connection Objects * Connection Objects
* Cursor Objects * Cursor Objects
@ -25,7 +25,7 @@ Introduction
* Type Objects and Constructors * Type Objects and Constructors
* Implementation Hints * Implementation Hints
* Major Changes from 1.0 to 2.0 * Major Changes from 1.0 to 2.0
Comments and questions about this specification may be directed Comments and questions about this specification may be directed
to the SIG for Database Interfacing with Python to the SIG for Database Interfacing with Python
(db-sig@python.org). (db-sig@python.org).
@ -41,7 +41,7 @@ Introduction
basis for new interfaces. basis for new interfaces.
Module Interface Module Interface
Access to the database is made available through connection Access to the database is made available through connection
objects. The module must provide the following constructor for objects. The module must provide the following constructor for
these: these:
@ -51,17 +51,17 @@ Module Interface
Constructor for creating a connection to the database. Constructor for creating a connection to the database.
Returns a Connection Object. It takes a number of Returns a Connection Object. It takes a number of
parameters which are database dependent. [1] parameters which are database dependent. [1]
These module globals must be defined: These module globals must be defined:
apilevel apilevel
String constant stating the supported DB API level. String constant stating the supported DB API level.
Currently only the strings '1.0' and '2.0' are allowed. Currently only the strings '1.0' and '2.0' are allowed.
If not given, a DB-API 1.0 level interface should be If not given, a DB-API 1.0 level interface should be
assumed. assumed.
threadsafety threadsafety
Integer constant stating the level of thread safety the Integer constant stating the level of thread safety the
@ -81,33 +81,33 @@ Module Interface
or other external sources that are beyond your control. or other external sources that are beyond your control.
paramstyle paramstyle
String constant stating the type of parameter marker String constant stating the type of parameter marker
formatting expected by the interface. Possible values are formatting expected by the interface. Possible values are
[2]: [2]:
'qmark' Question mark style, 'qmark' Question mark style,
e.g. '...WHERE name=?' e.g. '...WHERE name=?'
'numeric' Numeric, positional style, 'numeric' Numeric, positional style,
e.g. '...WHERE name=:1' e.g. '...WHERE name=:1'
'named' Named style, 'named' Named style,
e.g. '...WHERE name=:name' e.g. '...WHERE name=:name'
'format' ANSI C printf format codes, 'format' ANSI C printf format codes,
e.g. '...WHERE name=%s' e.g. '...WHERE name=%s'
'pyformat' Python extended format codes, 'pyformat' Python extended format codes,
e.g. '...WHERE name=%(name)s' e.g. '...WHERE name=%(name)s'
The module should make all error information available through The module should make all error information available through
these exceptions or subclasses thereof: these exceptions or subclasses thereof:
Warning Warning
Exception raised for important warnings like data Exception raised for important warnings like data
truncations while inserting, etc. It must be a subclass of truncations while inserting, etc. It must be a subclass of
the Python StandardError (defined in the module the Python StandardError (defined in the module
exceptions). exceptions).
Error Error
Exception that is the base class of all other error Exception that is the base class of all other error
exceptions. You can use this to catch all errors with one exceptions. You can use this to catch all errors with one
@ -115,7 +115,7 @@ Module Interface
errors and thus should not use this class as base. It must errors and thus should not use this class as base. It must
be a subclass of the Python StandardError (defined in the be a subclass of the Python StandardError (defined in the
module exceptions). module exceptions).
InterfaceError InterfaceError
Exception raised for errors that are related to the Exception raised for errors that are related to the
@ -126,50 +126,50 @@ Module Interface
Exception raised for errors that are related to the Exception raised for errors that are related to the
database. It must be a subclass of Error. database. It must be a subclass of Error.
DataError DataError
Exception raised for errors that are due to problems with Exception raised for errors that are due to problems with
the processed data like division by zero, numeric value the processed data like division by zero, numeric value
out of range, etc. It must be a subclass of DatabaseError. out of range, etc. It must be a subclass of DatabaseError.
OperationalError OperationalError
Exception raised for errors that are related to the Exception raised for errors that are related to the
database's operation and not necessarily under the control database's operation and not necessarily under the control
of the programmer, e.g. an unexpected disconnect occurs, of the programmer, e.g. an unexpected disconnect occurs,
the data source name is not found, a transaction could not the data source name is not found, a transaction could not
be processed, a memory allocation error occurred during be processed, a memory allocation error occurred during
processing, etc. It must be a subclass of DatabaseError. processing, etc. It must be a subclass of DatabaseError.
IntegrityError IntegrityError
Exception raised when the relational integrity of the Exception raised when the relational integrity of the
database is affected, e.g. a foreign key check fails. It database is affected, e.g. a foreign key check fails. It
must be a subclass of DatabaseError. must be a subclass of DatabaseError.
InternalError InternalError
Exception raised when the database encounters an internal Exception raised when the database encounters an internal
error, e.g. the cursor is not valid anymore, the error, e.g. the cursor is not valid anymore, the
transaction is out of sync, etc. It must be a subclass of transaction is out of sync, etc. It must be a subclass of
DatabaseError. DatabaseError.
ProgrammingError ProgrammingError
Exception raised for programming errors, e.g. table not Exception raised for programming errors, e.g. table not
found or already exists, syntax error in the SQL found or already exists, syntax error in the SQL
statement, wrong number of parameters specified, etc. It statement, wrong number of parameters specified, etc. It
must be a subclass of DatabaseError. must be a subclass of DatabaseError.
NotSupportedError NotSupportedError
Exception raised in case a method or database API was used Exception raised in case a method or database API was used
which is not supported by the database, e.g. requesting a which is not supported by the database, e.g. requesting a
.rollback() on a connection that does not support .rollback() on a connection that does not support
transaction or has transactions turned off. It must be a transaction or has transactions turned off. It must be a
subclass of DatabaseError. subclass of DatabaseError.
This is the exception inheritance layout: This is the exception inheritance layout:
StandardError StandardError
@ -183,17 +183,17 @@ Module Interface
|__InternalError |__InternalError
|__ProgrammingError |__ProgrammingError
|__NotSupportedError |__NotSupportedError
Note: The values of these exceptions are not defined. They should Note: The values of these exceptions are not defined. They should
give the user a fairly good idea of what went wrong, though. give the user a fairly good idea of what went wrong, though.
Connection Objects Connection Objects
Connection Objects should respond to the following methods: Connection Objects should respond to the following methods:
.close() .close()
Close the connection now (rather than whenever __del__ is Close the connection now (rather than whenever __del__ is
called). The connection will be unusable from this point called). The connection will be unusable from this point
forward; an Error (or subclass) exception will be raised forward; an Error (or subclass) exception will be raised
@ -203,74 +203,74 @@ Connection Objects
committing the changes first will cause an implicit committing the changes first will cause an implicit
rollback to be performed. rollback to be performed.
.commit() .commit()
Commit any pending transaction to the database. Note that Commit any pending transaction to the database. Note that
if the database supports an auto-commit feature, this must if the database supports an auto-commit feature, this must
be initially off. An interface method may be provided to be initially off. An interface method may be provided to
turn it back on. turn it back on.
Database modules that do not support transactions should Database modules that do not support transactions should
implement this method with void functionality. implement this method with void functionality.
.rollback() .rollback()
This method is optional since not all databases provide This method is optional since not all databases provide
transaction support. [3] transaction support. [3]
In case a database does provide transactions this method In case a database does provide transactions this method
causes the the database to roll back to the start of any causes the the database to roll back to the start of any
pending transaction. Closing a connection without pending transaction. Closing a connection without
committing the changes first will cause an implicit committing the changes first will cause an implicit
rollback to be performed. rollback to be performed.
.cursor() .cursor()
Return a new Cursor Object using the connection. If the Return a new Cursor Object using the connection. If the
database does not provide a direct cursor concept, the database does not provide a direct cursor concept, the
module will have to emulate cursors using other means to module will have to emulate cursors using other means to
the extent needed by this specification. [4] the extent needed by this specification. [4]
Cursor Objects Cursor Objects
These objects represent a database cursor, which is used to These objects represent a database cursor, which is used to
manage the context of a fetch operation. Cursors created from manage the context of a fetch operation. Cursors created from
the same connection are not isolated, i.e., any changes the same connection are not isolated, i.e., any changes
done to the database by a cursor are immediately visible by the done to the database by a cursor are immediately visible by the
other cursors. Cursors created from different connections can other cursors. Cursors created from different connections can
or can not be isolated, depending on how the transaction support or can not be isolated, depending on how the transaction support
is implemented (see also the connection's rollback() and commit() is implemented (see also the connection's rollback() and commit()
methods.) methods.)
Cursor Objects should respond to the following methods and Cursor Objects should respond to the following methods and
attributes: attributes:
.description .description
This read-only attribute is a sequence of 7-item This read-only attribute is a sequence of 7-item
sequences. Each of these sequences contains information sequences. Each of these sequences contains information
describing one result column: (name, type_code, describing one result column: (name, type_code,
display_size, internal_size, precision, scale, display_size, internal_size, precision, scale,
null_ok). The first two items (name and type_code) are null_ok). The first two items (name and type_code) are
mandatory, the other five are optional and must be set to mandatory, the other five are optional and must be set to
None if meaningfull values are not provided. None if meaningful values are not provided.
This attribute will be None for operations that This attribute will be None for operations that
do not return rows or if the cursor has not had an do not return rows or if the cursor has not had an
operation invoked via the executeXXX() method yet. operation invoked via the executeXXX() method yet.
The type_code can be interpreted by comparing it to the The type_code can be interpreted by comparing it to the
Type Objects specified in the section below. Type Objects specified in the section below.
.rowcount .rowcount
This read-only attribute specifies the number of rows that This read-only attribute specifies the number of rows that
the last executeXXX() produced (for DQL statements like the last executeXXX() produced (for DQL statements like
'select') or affected (for DML statements like 'update' or 'select') or affected (for DML statements like 'update' or
'insert'). 'insert').
The attribute is -1 in case no executeXXX() has been The attribute is -1 in case no executeXXX() has been
performed on the cursor or the rowcount of the last performed on the cursor or the rowcount of the last
operation is not determinable by the interface. [7] operation is not determinable by the interface. [7]
@ -278,96 +278,96 @@ Cursor Objects
Note: Future versions of the DB API specification could Note: Future versions of the DB API specification could
redefine the latter case to have the object return None redefine the latter case to have the object return None
instead of -1. instead of -1.
.callproc(procname[,parameters]) .callproc(procname[,parameters])
(This method is optional since not all databases provide (This method is optional since not all databases provide
stored procedures. [3]) stored procedures. [3])
Call a stored database procedure with the given name. The Call a stored database procedure with the given name. The
sequence of parameters must contain one entry for each sequence of parameters must contain one entry for each
argument that the procedure expects. The result of the argument that the procedure expects. The result of the
call is returned as modified copy of the input call is returned as modified copy of the input
sequence. Input parameters are left untouched, output and sequence. Input parameters are left untouched, output and
input/output parameters replaced with possibly new values. input/output parameters replaced with possibly new values.
The procedure may also provide a result set as The procedure may also provide a result set as
output. This must then be made available through the output. This must then be made available through the
standard fetchXXX() methods. standard fetchXXX() methods.
.close() .close()
Close the cursor now (rather than whenever __del__ is Close the cursor now (rather than whenever __del__ is
called). The cursor will be unusable from this point called). The cursor will be unusable from this point
forward; an Error (or subclass) exception will be raised forward; an Error (or subclass) exception will be raised
if any operation is attempted with the cursor. if any operation is attempted with the cursor.
.execute(operation[,parameters]) .execute(operation[,parameters])
Prepare and execute a database operation (query or Prepare and execute a database operation (query or
command). Parameters may be provided as sequence or command). Parameters may be provided as sequence or
mapping and will be bound to variables in the operation. mapping and will be bound to variables in the operation.
Variables are specified in a database-specific notation Variables are specified in a database-specific notation
(see the module's paramstyle attribute for details). [5] (see the module's paramstyle attribute for details). [5]
A reference to the operation will be retained by the A reference to the operation will be retained by the
cursor. If the same operation object is passed in again, cursor. If the same operation object is passed in again,
then the cursor can optimize its behavior. This is most then the cursor can optimize its behavior. This is most
effective for algorithms where the same operation is used, effective for algorithms where the same operation is used,
but different parameters are bound to it (many times). but different parameters are bound to it (many times).
For maximum efficiency when reusing an operation, it is For maximum efficiency when reusing an operation, it is
best to use the setinputsizes() method to specify the best to use the setinputsizes() method to specify the
parameter types and sizes ahead of time. It is legal for parameter types and sizes ahead of time. It is legal for
a parameter to not match the predefined information; the a parameter to not match the predefined information; the
implementation should compensate, possibly with a loss of implementation should compensate, possibly with a loss of
efficiency. efficiency.
The parameters may also be specified as list of tuples to The parameters may also be specified as list of tuples to
e.g. insert multiple rows in a single operation, but this e.g. insert multiple rows in a single operation, but this
kind of usage is depreciated: executemany() should be used kind of usage is depreciated: executemany() should be used
instead. instead.
Return values are not defined. Return values are not defined.
.executemany(operation,seq_of_parameters) .executemany(operation,seq_of_parameters)
Prepare a database operation (query or command) and then Prepare a database operation (query or command) and then
execute it against all parameter sequences or mappings execute it against all parameter sequences or mappings
found in the sequence seq_of_parameters. found in the sequence seq_of_parameters.
Modules are free to implement this method using multiple Modules are free to implement this method using multiple
calls to the execute() method or by using array operations calls to the execute() method or by using array operations
to have the database process the sequence as a whole in to have the database process the sequence as a whole in
one call. one call.
Use of this method for an operation which produces one or Use of this method for an operation which produces one or
more result sets constitutes undefined behavior, and the more result sets constitutes undefined behavior, and the
implementation is permitted (but not required) to raise implementation is permitted (but not required) to raise
an exception when it detects that a result set has been an exception when it detects that a result set has been
created by an invocation of the operation. created by an invocation of the operation.
The same comments as for execute() also apply accordingly The same comments as for execute() also apply accordingly
to this method. to this method.
Return values are not defined. Return values are not defined.
.fetchone() .fetchone()
Fetch the next row of a query result set, returning a Fetch the next row of a query result set, returning a
single sequence, or None when no more data is single sequence, or None when no more data is
available. [6] available. [6]
An Error (or subclass) exception is raised if the previous An Error (or subclass) exception is raised if the previous
call to executeXXX() did not produce any result set or no call to executeXXX() did not produce any result set or no
call was issued yet. call was issued yet.
fetchmany([size=cursor.arraysize]) fetchmany([size=cursor.arraysize])
Fetch the next set of rows of a query result, returning a Fetch the next set of rows of a query result, returning a
sequence of sequences (e.g. a list of tuples). An empty sequence of sequences (e.g. a list of tuples). An empty
sequence is returned when no more rows are available. sequence is returned when no more rows are available.
The number of rows to fetch per call is specified by the The number of rows to fetch per call is specified by the
parameter. If it is not given, the cursor's arraysize parameter. If it is not given, the cursor's arraysize
determines the number of rows to be fetched. The method determines the number of rows to be fetched. The method
@ -375,62 +375,62 @@ Cursor Objects
parameter. If this is not possible due to the specified parameter. If this is not possible due to the specified
number of rows not being available, fewer rows may be number of rows not being available, fewer rows may be
returned. returned.
An Error (or subclass) exception is raised if the previous An Error (or subclass) exception is raised if the previous
call to executeXXX() did not produce any result set or no call to executeXXX() did not produce any result set or no
call was issued yet. call was issued yet.
Note there are performance considerations involved with Note there are performance considerations involved with
the size parameter. For optimal performance, it is the size parameter. For optimal performance, it is
usually best to use the arraysize attribute. If the size usually best to use the arraysize attribute. If the size
parameter is used, then it is best for it to retain the parameter is used, then it is best for it to retain the
same value from one fetchmany() call to the next. same value from one fetchmany() call to the next.
.fetchall() .fetchall()
Fetch all (remaining) rows of a query result, returning Fetch all (remaining) rows of a query result, returning
them as a sequence of sequences (e.g. a list of tuples). them as a sequence of sequences (e.g. a list of tuples).
Note that the cursor's arraysize attribute can affect the Note that the cursor's arraysize attribute can affect the
performance of this operation. performance of this operation.
An Error (or subclass) exception is raised if the previous An Error (or subclass) exception is raised if the previous
call to executeXXX() did not produce any result set or no call to executeXXX() did not produce any result set or no
call was issued yet. call was issued yet.
.nextset() .nextset()
(This method is optional since not all databases support (This method is optional since not all databases support
multiple result sets. [3]) multiple result sets. [3])
This method will make the cursor skip to the next This method will make the cursor skip to the next
available set, discarding any remaining rows from the available set, discarding any remaining rows from the
current set. current set.
If there are no more sets, the method returns If there are no more sets, the method returns
None. Otherwise, it returns a true value and subsequent None. Otherwise, it returns a true value and subsequent
calls to the fetch methods will return rows from the next calls to the fetch methods will return rows from the next
result set. result set.
An Error (or subclass) exception is raised if the previous An Error (or subclass) exception is raised if the previous
call to executeXXX() did not produce any result set or no call to executeXXX() did not produce any result set or no
call was issued yet. call was issued yet.
.arraysize .arraysize
This read/write attribute specifies the number of rows to This read/write attribute specifies the number of rows to
fetch at a time with fetchmany(). It defaults to 1 meaning fetch at a time with fetchmany(). It defaults to 1 meaning
to fetch a single row at a time. to fetch a single row at a time.
Implementations must observe this value with respect to Implementations must observe this value with respect to
the fetchmany() method, but are free to interact with the the fetchmany() method, but are free to interact with the
database a single row at a time. It may also be used in database a single row at a time. It may also be used in
the implementation of executemany(). the implementation of executemany().
.setinputsizes(sizes) .setinputsizes(sizes)
This can be used before a call to executeXXX() to This can be used before a call to executeXXX() to
predefine memory areas for the operation's parameters. predefine memory areas for the operation's parameters.
sizes is specified as a sequence -- one item for each sizes is specified as a sequence -- one item for each
input parameter. The item should be a Type Object that input parameter. The item should be a Type Object that
corresponds to the input that will be used, or it should corresponds to the input that will be used, or it should
@ -438,27 +438,27 @@ Cursor Objects
parameter. If the item is None, then no predefined memory parameter. If the item is None, then no predefined memory
area will be reserved for that column (this is useful to area will be reserved for that column (this is useful to
avoid predefined areas for large inputs). avoid predefined areas for large inputs).
This method would be used before the executeXXX() method This method would be used before the executeXXX() method
is invoked. is invoked.
Implementations are free to have this method do nothing Implementations are free to have this method do nothing
and users are free to not use it. and users are free to not use it.
.setoutputsize(size[,column]) .setoutputsize(size[,column])
Set a column buffer size for fetches of large columns Set a column buffer size for fetches of large columns
(e.g. LONGs, BLOBs, etc.). The column is specified as an (e.g. LONGs, BLOBs, etc.). The column is specified as an
index into the result sequence. Not specifying the column index into the result sequence. Not specifying the column
will set the default size for all large columns in the will set the default size for all large columns in the
cursor. cursor.
This method would be used before the executeXXX() method This method would be used before the executeXXX() method
is invoked. is invoked.
Implementations are free to have this method do nothing Implementations are free to have this method do nothing
and users are free to not use it. and users are free to not use it.
Type Objects and Constructors Type Objects and Constructors
@ -485,15 +485,15 @@ Type Objects and Constructors
Implementation Hints below for details). Implementation Hints below for details).
The module exports the following constructors and singletons: The module exports the following constructors and singletons:
Date(year,month,day) Date(year,month,day)
This function constructs an object holding a date value. This function constructs an object holding a date value.
Time(hour,minute,second) Time(hour,minute,second)
This function constructs an object holding a time value. This function constructs an object holding a time value.
Timestamp(year,month,day,hour,minute,second) Timestamp(year,month,day,hour,minute,second)
This function constructs an object holding a time stamp This function constructs an object holding a time stamp
@ -507,12 +507,12 @@ Type Objects and Constructors
module for details). module for details).
TimeFromTicks(ticks) TimeFromTicks(ticks)
This function constructs an object holding a time value This function constructs an object holding a time value
from the given ticks value (number of seconds since the from the given ticks value (number of seconds since the
epoch; see the documentation of the standard Python time epoch; see the documentation of the standard Python time
module for details). module for details).
TimestampFromTicks(ticks) TimestampFromTicks(ticks)
This function constructs an object holding a time stamp This function constructs an object holding a time stamp
@ -521,10 +521,10 @@ Type Objects and Constructors
time module for details). time module for details).
Binary(string) Binary(string)
This function constructs an object capable of holding a This function constructs an object capable of holding a
binary (long) string value. binary (long) string value.
STRING STRING
@ -535,22 +535,22 @@ Type Objects and Constructors
This type object is used to describe (long) binary columns This type object is used to describe (long) binary columns
in a database (e.g. LONG, RAW, BLOBs). in a database (e.g. LONG, RAW, BLOBs).
NUMBER NUMBER
This type object is used to describe numeric columns in a This type object is used to describe numeric columns in a
database. database.
DATETIME DATETIME
This type object is used to describe date/time columns in This type object is used to describe date/time columns in
a database. a database.
ROWID ROWID
This type object is used to describe the "Row ID" column This type object is used to describe the "Row ID" column
in a database. in a database.
SQL NULL values are represented by the Python None singleton on SQL NULL values are represented by the Python None singleton on
input and output. input and output.
@ -563,7 +563,7 @@ Implementation Hints for Module Authors
* The preferred object types for the date/time objects are those * The preferred object types for the date/time objects are those
defined in the mxDateTime package. It provides all necessary defined in the mxDateTime package. It provides all necessary
constructors and methods both at Python and C level. constructors and methods both at Python and C level.
* The preferred object type for Binary objects are the * The preferred object type for Binary objects are the
buffer types available in standard Python starting with buffer types available in standard Python starting with
version 1.5.2. Please see the Python documentation for version 1.5.2. Please see the Python documentation for
@ -577,7 +577,7 @@ Implementation Hints for Module Authors
processing. However, it should be noted that this does not processing. However, it should be noted that this does not
expose a C API like mxDateTime does which means that integration expose a C API like mxDateTime does which means that integration
with C based database modules is more difficult. with C based database modules is more difficult.
* Here is a sample implementation of the Unix ticks based * Here is a sample implementation of the Unix ticks based
constructors for date/time delegating work to the generic constructors for date/time delegating work to the generic
constructors: constructors:
@ -645,7 +645,7 @@ Implementation Hints for Module Authors
class NotSupportedError(DatabaseError): class NotSupportedError(DatabaseError):
pass pass
In C you can use the PyErr_NewException(fullname, In C you can use the PyErr_NewException(fullname,
base, NULL) API to create the exception objects. base, NULL) API to create the exception objects.
@ -760,7 +760,7 @@ Optional DB API Extensions
Warning Message: "DB-API extension connection.messages used" Warning Message: "DB-API extension connection.messages used"
Cursor Method .next() Cursor Method .next()
Return the next row from the currently executing SQL statement Return the next row from the currently executing SQL statement
using the same semantics as .fetchone(). A StopIteration using the same semantics as .fetchone(). A StopIteration
exception is raised when the result set is exhausted for Python exception is raised when the result set is exhausted for Python
@ -790,13 +790,13 @@ Optional DB API Extensions
Warning Message: "DB-API extension cursor.lastrowid used" Warning Message: "DB-API extension cursor.lastrowid used"
Optional Error Handling Extension Optional Error Handling Extension
The core DB API specification only introduces a set of exceptions The core DB API specification only introduces a set of exceptions
which can be raised to report errors to the user. In some cases, which can be raised to report errors to the user. In some cases,
exceptions may be too disruptive for the flow of a program or even exceptions may be too disruptive for the flow of a program or even
render execution impossible. render execution impossible.
For these cases and in order to simplify error handling when For these cases and in order to simplify error handling when
dealing with databases, database module authors may choose to dealing with databases, database module authors may choose to
@ -806,7 +806,7 @@ Optional Error Handling Extension
Cursor/Connection Attribute .errorhandler Cursor/Connection Attribute .errorhandler
Read/write attribute which references an error handler to call Read/write attribute which references an error handler to call
in case an error condition is met. in case an error condition is met.
The handler must be a Python callable taking the following The handler must be a Python callable taking the following
arguments: errorhandler(connection, cursor, errorclass, arguments: errorhandler(connection, cursor, errorclass,
@ -836,7 +836,7 @@ Frequently Asked Questions
specification. This section covers some of the issues people specification. This section covers some of the issues people
sometimes have with the specification. sometimes have with the specification.
Question: Question:
How can I construct a dictionary out of the tuples returned by How can I construct a dictionary out of the tuples returned by
.fetchxxx(): .fetchxxx():
@ -855,7 +855,7 @@ Frequently Asked Questions
* Some databases don't support case-sensitive column names or * Some databases don't support case-sensitive column names or
auto-convert them to all lowercase or all uppercase auto-convert them to all lowercase or all uppercase
characters. characters.
* Columns in the result set which are generated by the query * Columns in the result set which are generated by the query
(e.g. using SQL functions) don't map to table column names (e.g. using SQL functions) don't map to table column names
and databases usually generate names for these columns in a and databases usually generate names for these columns in a
@ -872,9 +872,9 @@ Major Changes from Version 1.0 to Version 2.0
compared to the 1.0 version. Because some of these changes will compared to the 1.0 version. Because some of these changes will
cause existing DB API 1.0 based scripts to break, the major cause existing DB API 1.0 based scripts to break, the major
version number was adjusted to reflect this change. version number was adjusted to reflect this change.
These are the most important changes from 1.0 to 2.0: These are the most important changes from 1.0 to 2.0:
* The need for a separate dbi module was dropped and the * The need for a separate dbi module was dropped and the
functionality merged into the module interface itself. functionality merged into the module interface itself.
@ -886,10 +886,10 @@ Major Changes from Version 1.0 to Version 2.0
* New constants (apilevel, threadlevel, paramstyle) and * New constants (apilevel, threadlevel, paramstyle) and
methods (executemany, nextset) were added to provide better methods (executemany, nextset) were added to provide better
database bindings. database bindings.
* The semantics of .callproc() needed to call stored * The semantics of .callproc() needed to call stored
procedures are now clearly defined. procedures are now clearly defined.
* The definition of the .execute() return value changed. * The definition of the .execute() return value changed.
Previously, the return value was based on the SQL statement Previously, the return value was based on the SQL statement
type (which was hard to implement right) -- it is undefined type (which was hard to implement right) -- it is undefined
@ -898,7 +898,7 @@ Major Changes from Version 1.0 to Version 2.0
values, but these are no longer mandated by the values, but these are no longer mandated by the
specification and should be considered database interface specification and should be considered database interface
dependent. dependent.
* Class based exceptions were incorporated into the * Class based exceptions were incorporated into the
specification. Module implementors are free to extend the specification. Module implementors are free to extend the
exception layout defined in this specification by exception layout defined in this specification by
@ -916,10 +916,10 @@ Open Issues
questions that were left open in the 1.0 version, there are still questions that were left open in the 1.0 version, there are still
some remaining issues which should be addressed in future some remaining issues which should be addressed in future
versions: versions:
* Define a useful return value for .nextset() for the case where * Define a useful return value for .nextset() for the case where
a new result set is available. a new result set is available.
* Create a fixed point numeric type for use as loss-less * Create a fixed point numeric type for use as loss-less
monetary and decimal interchange format. monetary and decimal interchange format.
@ -929,17 +929,17 @@ Footnotes
[1] As a guideline the connection constructor parameters should be [1] As a guideline the connection constructor parameters should be
implemented as keyword parameters for more intuitive use and implemented as keyword parameters for more intuitive use and
follow this order of parameters: follow this order of parameters:
dsn Data source name as string dsn Data source name as string
user User name as string (optional) user User name as string (optional)
password Password as string (optional) password Password as string (optional)
host Hostname (optional) host Hostname (optional)
database Database name (optional) database Database name (optional)
E.g. a connect could look like this: E.g. a connect could look like this:
connect(dsn='myhost:MYDB',user='guido',password='234$') connect(dsn='myhost:MYDB',user='guido',password='234$')
[2] Module implementors should prefer 'numeric', 'named' or [2] Module implementors should prefer 'numeric', 'named' or
'pyformat' over the other formats because these offer more 'pyformat' over the other formats because these offer more
clarity and flexibility. clarity and flexibility.
@ -947,41 +947,41 @@ Footnotes
[3] If the database does not support the functionality required [3] If the database does not support the functionality required
by the method, the interface should throw an exception in by the method, the interface should throw an exception in
case the method is used. case the method is used.
The preferred approach is to not implement the method and The preferred approach is to not implement the method and
thus have Python generate an AttributeError in thus have Python generate an AttributeError in
case the method is requested. This allows the programmer to case the method is requested. This allows the programmer to
check for database capabilities using the standard check for database capabilities using the standard
hasattr() function. hasattr() function.
For some dynamically configured interfaces it may not be For some dynamically configured interfaces it may not be
appropriate to require dynamically making the method appropriate to require dynamically making the method
available. These interfaces should then raise a available. These interfaces should then raise a
NotSupportedError to indicate the non-ability NotSupportedError to indicate the non-ability
to perform the roll back when the method is invoked. to perform the roll back when the method is invoked.
[4] a database interface may choose to support named cursors by [4] a database interface may choose to support named cursors by
allowing a string argument to the method. This feature is allowing a string argument to the method. This feature is
not part of the specification, since it complicates not part of the specification, since it complicates
semantics of the .fetchXXX() methods. semantics of the .fetchXXX() methods.
[5] The module will use the __getitem__ method of the parameters [5] The module will use the __getitem__ method of the parameters
object to map either positions (integers) or names (strings) object to map either positions (integers) or names (strings)
to parameter values. This allows for both sequences and to parameter values. This allows for both sequences and
mappings to be used as input. mappings to be used as input.
The term "bound" refers to the process of binding an input The term "bound" refers to the process of binding an input
value to a database execution buffer. In practical terms, value to a database execution buffer. In practical terms,
this means that the input value is directly used as a value this means that the input value is directly used as a value
in the operation. The client should not be required to in the operation. The client should not be required to
"escape" the value so that it can be used -- the value "escape" the value so that it can be used -- the value
should be equal to the actual database value. should be equal to the actual database value.
[6] Note that the interface may implement row fetching using [6] Note that the interface may implement row fetching using
arrays and other optimizations. It is not arrays and other optimizations. It is not
guaranteed that a call to this method will only move the guaranteed that a call to this method will only move the
associated cursor forward by one row. associated cursor forward by one row.
[7] The rowcount attribute may be coded in a way that updates [7] The rowcount attribute may be coded in a way that updates
its value dynamically. This can be useful for databases that its value dynamically. This can be useful for databases that
return usable rowcount values only after the first call to return usable rowcount values only after the first call to

68
doc/release.rst Normal file
View File

@ -0,0 +1,68 @@
How to make a psycopg2 release
==============================
- Edit ``setup.py`` and set a stable version release. Use PEP 440 to choose
version numbers, e.g.
- ``2.7``: a new major release, new features
- ``2.7.1``: a bugfix release
- ``2.7.1.1``: a release to fix packaging problems
- ``2.7.2.dev0``: version held during development, non-public test packages...
- ``2.8b1``: a beta for public tests
In the rest of this document we assume you have exported the version number
into an environment variable, e.g.::
$ export VERSION=2.8.4
- Push psycopg2 to master or to the maint branch. Make sure tests on `GitHub
Actions`__.
.. __: https://github.com/psycopg/psycopg2/actions/workflows/tests.yml
- Create a signed tag with the content of the relevant NEWS bit and push it.
E.g.::
# Tag name will be 2_8_4
$ git tag -a -s ${VERSION//\./_}
Psycopg 2.8.4 released
What's new in psycopg 2.8.4
---------------------------
New features:
- Fixed bug blah (:ticket:`#42`).
...
- Create the packages:
- On GitHub Actions run manually a `package build workflow`__.
.. __: https://github.com/psycopg/psycopg2/actions/workflows/packages.yml
- When the workflows have finished download the packages from the job
artifacts.
- Only for stable packages: upload the signed packages on PyPI::
$ twine upload -s wheelhouse/psycopg2-${VERSION}/*
- Create a release and release notes in the psycopg website, announce to
psycopg and pgsql-announce mailing lists.
- Edit ``setup.py`` changing the version again (e.g. go to ``2.8.5.dev0``).
Releasing test packages
-----------------------
Test packages may be uploaded on the `PyPI testing site`__ using::
$ twine upload -s -r testpypi wheelhouse/psycopg2-${VERSION}/*
assuming `proper configuration`__ of ``~/.pypirc``.
.. __: https://test.pypi.org/project/psycopg2/
.. __: https://wiki.python.org/moin/TestPyPI

2
doc/requirements.in Normal file
View File

@ -0,0 +1,2 @@
Sphinx
sphinx-better-theme

50
doc/requirements.txt Normal file
View File

@ -0,0 +1,50 @@
#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile requirements.in
#
alabaster==0.7.13
# via sphinx
babel==2.12.1
# via sphinx
certifi>=2023.7.22
# via requests
charset-normalizer==3.1.0
# via requests
docutils==0.19
# via sphinx
idna==3.4
# via requests
imagesize==1.4.1
# via sphinx
jinja2==3.1.2
# via sphinx
markupsafe==2.1.2
# via jinja2
packaging==23.1
# via sphinx
pygments==2.15.0
# via sphinx
requests==2.31.0
# via sphinx
snowballstemmer==2.2.0
# via sphinx
sphinx==6.1.3
# via -r requirements.in
sphinx-better-theme==0.1.5
# via -r requirements.in
sphinxcontrib-applehelp==1.0.4
# via sphinx
sphinxcontrib-devhelp==1.0.2
# via sphinx
sphinxcontrib-htmlhelp==2.0.1
# via sphinx
sphinxcontrib-jsmath==1.0.1
# via sphinx
sphinxcontrib-qthelp==1.0.3
# via sphinx
sphinxcontrib-serializinghtml==1.1.5
# via sphinx
urllib3==1.26.17
# via requests

99
doc/src/Makefile Normal file
View File

@ -0,0 +1,99 @@
# Makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = _build
# DSN for the doctest database
PSYCOPG2_DSN="user=postgres dbname=test"
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
.PHONY: help clean html dirhtml pickle json htmlhelp qthelp latex changes linkcheck doctest
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " dirhtml to make HTML files named index.html in directories"
@echo " pickle to make pickle files"
@echo " json to make JSON files"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " qthelp to make HTML files and a qthelp project"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
clean:
-rm -rf $(BUILDDIR)/*
-rm -rf ./html/*
html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
text:
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
@echo
@echo "Build finished. The text pages are in $(BUILDDIR)/text."
pickle:
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
@echo
@echo "Build finished; now you can process the pickle files."
json:
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
@echo
@echo "Build finished; now you can process the JSON files."
htmlhelp:
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in $(BUILDDIR)/htmlhelp."
qthelp:
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/psycopg.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/psycopg.qhc"
latex:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
@echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \
"run these through (pdf)latex."
changes:
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
@echo
@echo "The overview file is in $(BUILDDIR)/changes."
linkcheck:
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."
doctest:
PSYCOPG2_DSN=$(PSYCOPG2_DSN) \
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."

136
doc/src/_static/psycopg.css Normal file
View File

@ -0,0 +1,136 @@
blockquote {
font-style: italic;
}
div.admonition-todo {
background-color: #ffa;
border: 1px solid #ee2;
}
div.dbapi-extension {
background-color: #eef;
border: 1px solid #aaf;
}
code.sql,
tt.sql {
font-size: 1em;
background-color: transparent;
}
a > code.sql,
a > tt.sql {
font-weight: normal;
}
a > code.sql:hover,
a > tt.sql:hover {
text-decoration: underline;
}
dl.faq dt {
font-weight: bold;
}
table.data-types div.line-block {
margin-bottom: 0;
}
/* better theme customisation */
body {
background-color: #216464;
}
header, .related, .document, footer {
background-color: white;
}
header h1 {
font-size: 150%;
margin-bottom: 0;
padding: 0.5rem 10px 0.5rem 10px;
}
h1, h2, h3 {
font-weight: normal;
}
.body h1, .body h2, .body h3 {
color: #074848;
}
h1 {
font-size: 200%;
}
h2 {
font-size: 160%;
}
h3 {
font-size: 140%;
}
footer#pagefooter {
margin-bottom: 1rem;
font-size: 85%;
color: #444;
}
#rellinks, #breadcrumbs {
padding-right: 10px;
padding-left: 10px;
}
.sphinxsidebar {
padding-left: 10px;
}
.bodywrapper {
padding-right: 10px;
}
div.body h1, div.body h2, div.body h3 {
background-color: #f2f2f2;
border-bottom: 1px solid #d0d0d0;
}
div.body p.rubric {
border-bottom: 1px solid #d0d0d0;
}
body .sphinxsidebar .search {
margin-top: 0;
}
html pre {
background-color: #efc;
border: 1px solid #ac9;
border-left: none;
border-right: none;
}
a, a:visited {
color: #0b6868;
}
th {
background-color: #ede;
}
code.xref, a code {
font-weight: bold;
}
code.descname {
font-weight: bold;
font-size: 120%;
}
@media (max-width: 820px) {
body {
background-color: white;
}
}

View File

@ -0,0 +1,6 @@
{# Add a title over the search box #}
{%- if pagename != "search" %}
<h3>Quick search</h3>
{%- include "!searchbox.html" %}
{%- endif %}

599
doc/src/advanced.rst Normal file
View File

@ -0,0 +1,599 @@
More advanced topics
====================
.. sectionauthor:: Daniele Varrazzo <daniele.varrazzo@gmail.com>
.. testsetup:: *
import re
import select
cur.execute("CREATE TABLE atable (apoint point)")
conn.commit()
def wait(conn):
while True:
state = conn.poll()
if state == psycopg2.extensions.POLL_OK:
break
elif state == psycopg2.extensions.POLL_WRITE:
select.select([], [conn.fileno()], [])
elif state == psycopg2.extensions.POLL_READ:
select.select([conn.fileno()], [], [])
else:
raise psycopg2.OperationalError("poll() returned %s" % state)
aconn = psycopg2.connect(database='test', async=1)
wait(aconn)
acurs = aconn.cursor()
.. index::
double: Subclassing; Cursor
double: Subclassing; Connection
.. _subclassing-connection:
.. _subclassing-cursor:
Connection and cursor factories
-------------------------------
Psycopg exposes two new-style classes that can be sub-classed and expanded to
adapt them to the needs of the programmer: `psycopg2.extensions.cursor`
and `psycopg2.extensions.connection`. The `connection` class is
usually sub-classed only to provide an easy way to create customized cursors
but other uses are possible. `cursor` is much more interesting, because
it is the class where query building, execution and result type-casting into
Python variables happens.
The `~psycopg2.extras` module contains several examples of :ref:`connection
and cursor subclasses <cursor-subclasses>`.
.. note::
If you only need a customized cursor class, since Psycopg 2.5 you can use
the `~connection.cursor_factory` parameter of a regular connection instead
of creating a new `!connection` subclass.
.. index::
single: Example; Cursor subclass
An example of cursor subclass performing logging is::
import psycopg2
import psycopg2.extensions
import logging
class LoggingCursor(psycopg2.extensions.cursor):
def execute(self, sql, args=None):
logger = logging.getLogger('sql_debug')
logger.info(self.mogrify(sql, args))
try:
psycopg2.extensions.cursor.execute(self, sql, args)
except Exception, exc:
logger.error("%s: %s" % (exc.__class__.__name__, exc))
raise
conn = psycopg2.connect(DSN)
cur = conn.cursor(cursor_factory=LoggingCursor)
cur.execute("INSERT INTO mytable VALUES (%s, %s, %s);",
(10, 20, 30))
.. index::
single: Objects; Creating new adapters
single: Adaptation; Creating new adapters
single: Data types; Creating new adapters
.. _adapting-new-types:
Adapting new Python types to SQL syntax
---------------------------------------
Any Python class or type can be adapted to an SQL string. Adaptation mechanism
is similar to the Object Adaptation proposed in the :pep:`246` and is exposed
by the `psycopg2.extensions.adapt()` function.
The `~cursor.execute()` method adapts its arguments to the
`~psycopg2.extensions.ISQLQuote` protocol. Objects that conform to this
protocol expose a `!getquoted()` method returning the SQL representation
of the object as a string (the method must return `!bytes` in Python 3).
Optionally the conform object may expose a
`~psycopg2.extensions.ISQLQuote.prepare()` method.
There are two basic ways to have a Python object adapted to SQL:
- the object itself is conform, or knows how to make itself conform. Such
object must expose a `__conform__()` method that will be called with the
protocol object as argument. The object can check that the protocol is
`!ISQLQuote`, in which case it can return `!self` (if the object also
implements `!getquoted()`) or a suitable wrapper object. This option is
viable if you are the author of the object and if the object is specifically
designed for the database (i.e. having Psycopg as a dependency and polluting
its interface with the required methods doesn't bother you). For a simple
example you can take a look at the source code for the
`psycopg2.extras.Inet` object.
- If implementing the `!ISQLQuote` interface directly in the object is not an
option (maybe because the object to adapt comes from a third party library),
you can use an *adaptation function*, taking the object to be adapted as
argument and returning a conforming object. The adapter must be
registered via the `~psycopg2.extensions.register_adapter()` function. A
simple example wrapper is `!psycopg2.extras.UUID_adapter` used by the
`~psycopg2.extras.register_uuid()` function.
A convenient object to write adapters is the `~psycopg2.extensions.AsIs`
wrapper, whose `!getquoted()` result is simply the `!str()`\ ing conversion of
the wrapped object.
.. index::
single: Example; Types adaptation
Example: mapping of a `!Point` class into the |point|_ PostgreSQL
geometric type:
.. doctest::
>>> from psycopg2.extensions import adapt, register_adapter, AsIs
>>> class Point(object):
... def __init__(self, x, y):
... self.x = x
... self.y = y
>>> def adapt_point(point):
... x = adapt(point.x).getquoted()
... y = adapt(point.y).getquoted()
... return AsIs("'(%s, %s)'" % (x, y))
>>> register_adapter(Point, adapt_point)
>>> cur.execute("INSERT INTO atable (apoint) VALUES (%s)",
... (Point(1.23, 4.56),))
.. |point| replace:: :sql:`point`
.. _point: https://www.postgresql.org/docs/current/static/datatype-geometric.html#DATATYPE-GEOMETRIC
The above function call results in the SQL command::
INSERT INTO atable (apoint) VALUES ('(1.23, 4.56)');
.. index:: Type casting
.. _type-casting-from-sql-to-python:
Type casting of SQL types into Python objects
---------------------------------------------
PostgreSQL objects read from the database can be adapted to Python objects
through an user-defined adapting function. An adapter function takes two
arguments: the object string representation as returned by PostgreSQL and the
cursor currently being read, and should return a new Python object. For
example, the following function parses the PostgreSQL :sql:`point`
representation into the previously defined `!Point` class:
>>> def cast_point(value, cur):
... if value is None:
... return None
...
... # Convert from (f1, f2) syntax using a regular expression.
... m = re.match(r"\(([^)]+),([^)]+)\)", value)
... if m:
... return Point(float(m.group(1)), float(m.group(2)))
... else:
... raise InterfaceError("bad point representation: %r" % value)
In order to create a mapping from a PostgreSQL type (either standard or
user-defined), its OID must be known. It can be retrieved either by the second
column of the `cursor.description`:
>>> cur.execute("SELECT NULL::point")
>>> point_oid = cur.description[0][1]
>>> point_oid
600
or by querying the system catalog for the type name and namespace (the
namespace for system objects is :sql:`pg_catalog`):
>>> cur.execute("""
... SELECT pg_type.oid
... FROM pg_type JOIN pg_namespace
... ON typnamespace = pg_namespace.oid
... WHERE typname = %(typename)s
... AND nspname = %(namespace)s""",
... {'typename': 'point', 'namespace': 'pg_catalog'})
>>> point_oid = cur.fetchone()[0]
>>> point_oid
600
After you know the object OID, you can create and register the new type:
>>> POINT = psycopg2.extensions.new_type((point_oid,), "POINT", cast_point)
>>> psycopg2.extensions.register_type(POINT)
The `~psycopg2.extensions.new_type()` function binds the object OIDs
(more than one can be specified) to the adapter function.
`~psycopg2.extensions.register_type()` completes the spell. Conversion
is automatically performed when a column whose type is a registered OID is
read:
>>> cur.execute("SELECT '(10.2,20.3)'::point")
>>> point = cur.fetchone()[0]
>>> print(type(point), point.x, point.y)
<class 'Point'> 10.2 20.3
A typecaster created by `!new_type()` can be also used with
`~psycopg2.extensions.new_array_type()` to create a typecaster converting a
PostgreSQL array into a Python list.
.. index::
pair: Asynchronous; Notifications
pair: LISTEN; SQL command
pair: NOTIFY; SQL command
.. _async-notify:
Asynchronous notifications
--------------------------
Psycopg allows asynchronous interaction with other database sessions using the
facilities offered by PostgreSQL commands |LISTEN|_ and |NOTIFY|_. Please
refer to the PostgreSQL documentation for examples about how to use this form of
communication.
Notifications are instances of the `~psycopg2.extensions.Notify` object made
available upon reception in the `connection.notifies` list. Notifications can
be sent from Python code simply executing a :sql:`NOTIFY` command in an
`~cursor.execute()` call.
Because of the way sessions interact with notifications (see |NOTIFY|_
documentation), you should keep the connection in `~connection.autocommit`
mode if you wish to receive or send notifications in a timely manner.
.. |LISTEN| replace:: :sql:`LISTEN`
.. _LISTEN: https://www.postgresql.org/docs/current/static/sql-listen.html
.. |NOTIFY| replace:: :sql:`NOTIFY`
.. _NOTIFY: https://www.postgresql.org/docs/current/static/sql-notify.html
Notifications are received after every query execution. If the user is
interested in receiving notifications but not in performing any query, the
`~connection.poll()` method can be used to check for new messages without
wasting resources.
A simple application could poll the connection from time to time to check if
something new has arrived. A better strategy is to use some I/O completion
function such as :py:func:`~select.select` to sleep until awakened by the kernel when there is
some data to read on the connection, thereby using no CPU unless there is
something to read::
import select
import psycopg2
import psycopg2.extensions
conn = psycopg2.connect(DSN)
conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
curs = conn.cursor()
curs.execute("LISTEN test;")
print("Waiting for notifications on channel 'test'")
while True:
if select.select([conn],[],[],5) == ([],[],[]):
print("Timeout")
else:
conn.poll()
while conn.notifies:
notify = conn.notifies.pop(0)
print("Got NOTIFY:", notify.pid, notify.channel, notify.payload)
Running the script and executing a command such as :sql:`NOTIFY test, 'hello'`
in a separate :program:`psql` shell, the output may look similar to:
.. code-block:: none
Waiting for notifications on channel 'test'
Timeout
Timeout
Got NOTIFY: 6535 test hello
Timeout
...
Note that the payload is only available from PostgreSQL 9.0: notifications
received from a previous version server will have the
`~psycopg2.extensions.Notify.payload` attribute set to the empty string.
.. versionchanged:: 2.3
Added `~psycopg2.extensions.Notify` object and handling notification
payload.
.. versionchanged:: 2.7
The `~connection.notifies` attribute is writable: it is possible to
replace it with any object exposing an `!append()` method. An useful
example would be to use a `~collections.deque` object.
.. index::
double: Asynchronous; Connection
.. _async-support:
Asynchronous support
--------------------
.. versionadded:: 2.2
Psycopg can issue asynchronous queries to a PostgreSQL database. An asynchronous
communication style is established passing the parameter *async*\=1 to the
`~psycopg2.connect()` function: the returned connection will work in
*asynchronous mode*.
In asynchronous mode, a Psycopg connection will rely on the caller to poll the
socket file descriptor, checking if it is ready to accept data or if a query
result has been transferred and is ready to be read on the client. The caller
can use the method `~connection.fileno()` to get the connection file
descriptor and `~connection.poll()` to make communication proceed according to
the current connection state.
The following is an example loop using methods `!fileno()` and `!poll()`
together with the Python :py:func:`~select.select` function in order to carry on
asynchronous operations with Psycopg::
def wait(conn):
while True:
state = conn.poll()
if state == psycopg2.extensions.POLL_OK:
break
elif state == psycopg2.extensions.POLL_WRITE:
select.select([], [conn.fileno()], [])
elif state == psycopg2.extensions.POLL_READ:
select.select([conn.fileno()], [], [])
else:
raise psycopg2.OperationalError("poll() returned %s" % state)
The above loop of course would block an entire application: in a real
asynchronous framework, `!select()` would be called on many file descriptors
waiting for any of them to be ready. Nonetheless the function can be used to
connect to a PostgreSQL server only using nonblocking commands and the
connection obtained can be used to perform further nonblocking queries. After
`!poll()` has returned `~psycopg2.extensions.POLL_OK`, and thus `!wait()` has
returned, the connection can be safely used:
>>> aconn = psycopg2.connect(database='test', async=1)
>>> wait(aconn)
>>> acurs = aconn.cursor()
Note that there are a few other requirements to be met in order to have a
completely non-blocking connection attempt: see the libpq documentation for
|PQconnectStart|_.
.. |PQconnectStart| replace:: `!PQconnectStart()`
.. _PQconnectStart: https://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-PQCONNECTSTARTPARAMS
The same loop should be also used to perform nonblocking queries: after
sending a query via `~cursor.execute()` or `~cursor.callproc()`, call
`!poll()` on the connection available from `cursor.connection` until it
returns `!POLL_OK`, at which point the query has been completely sent to the
server and, if it produced data, the results have been transferred to the
client and available using the regular cursor methods:
>>> acurs.execute("SELECT pg_sleep(5); SELECT 42;")
>>> wait(acurs.connection)
>>> acurs.fetchone()[0]
42
When an asynchronous query is being executed, `connection.isexecuting()` returns
`!True`. Two cursors can't execute concurrent queries on the same asynchronous
connection.
There are several limitations in using asynchronous connections: the
connection is always in `~connection.autocommit` mode and it is not
possible to change it. So a
transaction is not implicitly started at the first query and is not possible
to use methods `~connection.commit()` and `~connection.rollback()`: you can
manually control transactions using `~cursor.execute()` to send database
commands such as :sql:`BEGIN`, :sql:`COMMIT` and :sql:`ROLLBACK`. Similarly
`~connection.set_session()` can't be used but it is still possible to invoke the
:sql:`SET` command with the proper :sql:`default_transaction_...` parameter.
With asynchronous connections it is also not possible to use
`~connection.set_client_encoding()`, `~cursor.executemany()`, :ref:`large
objects <large-objects>`, :ref:`named cursors <server-side-cursors>`.
:ref:`COPY commands <copy>` are not supported either in asynchronous mode, but
this will be probably implemented in a future release.
.. index::
single: Greenlet
single: Coroutine
single: Eventlet
single: gevent
single: Wait callback
.. _green-support:
Support for coroutine libraries
-------------------------------
.. versionadded:: 2.2
Psycopg can be used together with coroutine_\-based libraries and participate
in cooperative multithreading.
Coroutine-based libraries (such as Eventlet_ or gevent_) can usually patch the
Python standard library in order to enable a coroutine switch in the presence of
blocking I/O: the process is usually referred as making the system *green*, in
reference to the `green threads`_.
Because Psycopg is a C extension module, it is not possible for coroutine
libraries to patch it: Psycopg instead enables cooperative multithreading by
allowing the registration of a *wait callback* using the
`psycopg2.extensions.set_wait_callback()` function. When a wait callback is
registered, Psycopg will use `libpq non-blocking calls`__ instead of the regular
blocking ones, and will delegate to the callback the responsibility to wait
for the socket to become readable or writable.
Working this way, the caller does not have the complete freedom to schedule the
socket check whenever they want as with an :ref:`asynchronous connection
<async-support>`, but has the advantage of maintaining a complete |DBAPI|
semantics: from the point of view of the end user, all Psycopg functions and
objects will work transparently in the coroutine environment (blocking the
calling green thread and giving other green threads the possibility to be
scheduled), allowing non modified code and third party libraries (such as
SQLAlchemy_) to be used in coroutine-based programs.
.. warning::
Psycopg connections are not *green thread safe* and can't be used
concurrently by different green threads. Trying to execute more than one
command at time using one cursor per thread will result in an error (or a
deadlock on versions before 2.4.2).
Therefore, programmers are advised to either avoid sharing connections
between coroutines or to use a library-friendly lock to synchronize shared
connections, e.g. for pooling.
Coroutine libraries authors should provide a callback implementation (and
possibly a method to register it) to make Psycopg as green as they want. An
example callback (using `!select()` to block) is provided as
`psycopg2.extras.wait_select()`: it boils down to something similar to::
def wait_select(conn):
while True:
state = conn.poll()
if state == extensions.POLL_OK:
break
elif state == extensions.POLL_READ:
select.select([conn.fileno()], [], [])
elif state == extensions.POLL_WRITE:
select.select([], [conn.fileno()], [])
else:
raise OperationalError("bad state from poll: %s" % state)
Providing callback functions for the single coroutine libraries is out of
psycopg2 scope, as the callback can be tied to the libraries' implementation
details. You can check the `psycogreen`_ project for further informations and
resources about the topic.
.. _coroutine: https://en.wikipedia.org/wiki/Coroutine
.. _greenlet: https://pypi.org/project/greenlet/
.. _green threads: https://en.wikipedia.org/wiki/Green_threads
.. _Eventlet: https://eventlet.net/
.. _gevent: http://www.gevent.org/
.. _SQLAlchemy: https://www.sqlalchemy.org/
.. _psycogreen: https://github.com/psycopg/psycogreen/
.. __: https://www.postgresql.org/docs/current/static/libpq-async.html
.. warning::
:ref:`COPY commands <copy>` are currently not supported when a wait callback
is registered, but they will be probably implemented in a future release.
:ref:`Large objects <large-objects>` are not supported either: they are
not compatible with asynchronous connections.
.. testcode::
:hide:
aconn.close()
conn.rollback()
cur.execute("DROP TABLE atable")
conn.commit()
cur.close()
conn.close()
.. index::
single: Replication
.. _replication-support:
Replication protocol support
----------------------------
.. versionadded:: 2.7
Modern PostgreSQL servers (version 9.0 and above) support replication. The
replication protocol is built on top of the client-server protocol and can be
operated using ``libpq``, as such it can be also operated by ``psycopg2``.
The replication protocol can be operated on both synchronous and
:ref:`asynchronous <async-support>` connections.
Server version 9.4 adds a new feature called *Logical Replication*.
.. seealso::
- PostgreSQL `Streaming Replication Protocol`__
.. __: https://www.postgresql.org/docs/current/static/protocol-replication.html
Logical replication Quick-Start
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You must be using PostgreSQL server version 9.4 or above to run this quick
start.
Make sure that replication connections are permitted for user ``postgres`` in
``pg_hba.conf`` and reload the server configuration. You also need to set
``wal_level=logical`` and ``max_wal_senders``, ``max_replication_slots`` to
value greater than zero in ``postgresql.conf`` (these changes require a server
restart). Create a database ``psycopg2_test``.
Then run the following code to quickly try the replication support out. This
is not production code -- it's only intended as a simple demo of logical
replication::
from __future__ import print_function
import sys
import psycopg2
import psycopg2.extras
conn = psycopg2.connect('dbname=psycopg2_test user=postgres',
connection_factory=psycopg2.extras.LogicalReplicationConnection)
cur = conn.cursor()
try:
# test_decoding produces textual output
cur.start_replication(slot_name='pytest', decode=True)
except psycopg2.ProgrammingError:
cur.create_replication_slot('pytest', output_plugin='test_decoding')
cur.start_replication(slot_name='pytest', decode=True)
class DemoConsumer(object):
def __call__(self, msg):
print(msg.payload)
msg.cursor.send_feedback(flush_lsn=msg.data_start)
democonsumer = DemoConsumer()
print("Starting streaming, press Control-C to end...", file=sys.stderr)
try:
cur.consume_stream(democonsumer)
except KeyboardInterrupt:
cur.close()
conn.close()
print("The slot 'pytest' still exists. Drop it with "
"SELECT pg_drop_replication_slot('pytest'); if no longer needed.",
file=sys.stderr)
print("WARNING: Transaction logs will accumulate in pg_xlog "
"until the slot is dropped.", file=sys.stderr)
You can now make changes to the ``psycopg2_test`` database using a normal
psycopg2 session, ``psql``, etc. and see the logical decoding stream printed
by this demo client.
This will continue running until terminated with ``Control-C``.
For the details see :ref:`replication-objects`.

289
doc/src/conf.py Normal file
View File

@ -0,0 +1,289 @@
#
# Psycopg documentation build configuration file, created by
# sphinx-quickstart on Sun Feb 7 13:48:41 2010.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import os
import sys
from better import better_theme_path
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.append(os.path.abspath('tools/lib'))
# -- General configuration -----------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.todo',
'sphinx.ext.ifconfig',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
]
# Specific extensions for Psycopg documentation.
extensions += ['dbapi_extension', 'sql_role', 'ticket_role']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
# source_encoding = 'utf-8'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = 'Psycopg'
copyright = (
'2001-2021, Federico Di Gregorio, Daniele Varrazzo, The Psycopg Team'
)
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '2.0'
# The full version, including alpha/beta/rc tags.
try:
import psycopg2
except ImportError:
print("WARNING: couldn't import psycopg to read version.")
release = version
else:
release = psycopg2.__version__.split()[0]
version = '.'.join(release.split('.')[:2])
intersphinx_mapping = {'py': ('https://docs.python.org/3', None)}
# Pattern to generate links to the bug tracker
ticket_url = 'https://github.com/psycopg/psycopg2/issues/%s'
ticket_remap_until = 25
ticket_remap_offset = 230
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
# language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
# today = ''
# Else, today_fmt is used as the format for a strftime call.
# today_fmt = '%B %d, %Y'
# List of documents that shouldn't be included in the build.
# unused_docs = []
# List of directories, relative to source directory, that shouldn't be searched
# for source files.
exclude_trees = ['_build', 'html']
# The reST default role (used for this markup: `text`) to use for all documents.
default_role = 'obj'
# If true, '()' will be appended to :func: etc. cross-reference text.
# add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
# add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
# show_authors = False
# Using 'python' instead of the default gives warnings if parsing an example
# fails, instead of defaulting to none
highlight_language = 'python'
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []
# Include TODO items in the documentation
todo_include_todos = False
rst_epilog = """
.. |DBAPI| replace:: DB API 2.0
.. _DBAPI: https://www.python.org/dev/peps/pep-0249/
.. _transaction isolation level:
https://www.postgresql.org/docs/current/static/transaction-iso.html
.. |MVCC| replace:: :abbr:`MVCC (Multiversion concurrency control)`
"""
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. Major themes that come with
# Sphinx are currently 'default' and 'sphinxdoc'.
html_theme = 'better'
# The stylesheet to use with HTML output: this will include the original one
# adding a few classes.
# html_style = 'psycopg.css'
# Hide the sphinx footer
html_show_sphinx = False
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
html_theme_options = {
'linktotheme': False,
'cssfiles': ['_static/psycopg.css'],
}
# Add any paths that contain custom themes here, relative to this directory.
html_theme_path = [better_theme_path]
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
# html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
html_short_title = 'Home'
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
# html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
# html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
# html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
# html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
# no need for the prev/next topic link using better theme: they are on top
html_sidebars = {
'**': ['localtoc.html', 'searchbox.html'],
}
# Additional templates that should be rendered to pages, maps page names to
# template names.
# html_additional_pages = {}
# If false, no module index is generated.
# html_use_modindex = True
# If false, no index is generated.
# html_use_index = True
# If true, the index is split into individual pages for each letter.
# html_split_index = False
# If true, links to the reST sources are added to the pages.
# html_show_sourcelink = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
# html_use_opensearch = ''
# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
# html_file_suffix = ''
# Output file base name for HTML help builder.
htmlhelp_basename = 'psycopgdoc'
# -- Options for LaTeX output --------------------------------------------------
# The paper size ('letter' or 'a4').
# latex_paper_size = 'letter'
# The font size ('10pt', '11pt' or '12pt').
# latex_font_size = '10pt'
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
(
'index',
'psycopg.tex',
'Psycopg Documentation',
'Federico Di Gregorio',
'manual',
)
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
# latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
# latex_use_parts = False
# Additional stuff for the LaTeX preamble.
# latex_preamble = ''
# Documents to append as an appendix to all manuals.
# latex_appendices = []
# If false, no module index is generated.
# latex_use_modindex = True
toc_object_entries = False
doctest_global_setup = """
import os
import psycopg2
def test_connect():
try:
dsn = os.environ['PSYCOPG2_DSN']
except KeyError:
assert False, "You need to set the environment variable PSYCOPG2_DSN" \
" in order to test the documentation!"
return psycopg2.connect(dsn)
conn = test_connect()
cur = conn.cursor()
def drop_test_table(name):
cur.execute("SAVEPOINT drop_test_table;")
try:
cur.execute("DROP TABLE %s;" % name)
except:
cur.execute("ROLLBACK TO SAVEPOINT drop_test_table;")
conn.commit()
def create_test_table():
drop_test_table('test')
cur.execute("CREATE TABLE test (id SERIAL PRIMARY KEY, num INT, data TEXT)")
conn.commit()
"""

916
doc/src/connection.rst Normal file
View File

@ -0,0 +1,916 @@
The ``connection`` class
========================
.. sectionauthor:: Daniele Varrazzo <daniele.varrazzo@gmail.com>
.. testsetup::
from pprint import pprint
import psycopg2.extensions
drop_test_table('foo')
.. class:: connection
Handles the connection to a PostgreSQL database instance. It encapsulates
a database session.
Connections are created using the factory function
`~psycopg2.connect()`.
Connections are thread safe and can be shared among many threads. See
:ref:`thread-safety` for details.
Connections can be used as context managers. Note that a context wraps a
transaction: if the context exits with success the transaction is
committed, if it exits with an exception the transaction is rolled back.
Note that the connection is not closed by the context and it can be used
for several contexts.
.. code:: python
conn = psycopg2.connect(DSN)
with conn:
with conn.cursor() as curs:
curs.execute(SQL1)
with conn:
with conn.cursor() as curs:
curs.execute(SQL2)
# leaving contexts doesn't close the connection
conn.close()
.. method:: cursor(name=None, cursor_factory=None, scrollable=None, withhold=False)
Return a new `cursor` object using the connection.
If *name* is specified, the returned cursor will be a :ref:`server
side cursor <server-side-cursors>` (also known as *named cursor*).
Otherwise it will be a regular *client side* cursor. By default a
named cursor is declared without :sql:`SCROLL` option and
:sql:`WITHOUT HOLD`: set the argument or property `~cursor.scrollable`
to `!True`/`!False` and or `~cursor.withhold` to `!True` to change the
declaration.
The name can be a string not valid as a PostgreSQL identifier: for
example it may start with a digit and contain non-alphanumeric
characters and quotes.
.. versionchanged:: 2.4
previously only valid PostgreSQL identifiers were accepted as
cursor name.
The *cursor_factory* argument can be used to create non-standard
cursors. The class returned must be a subclass of
`psycopg2.extensions.cursor`. See :ref:`subclassing-cursor` for
details. A default factory for the connection can also be specified
using the `~connection.cursor_factory` attribute.
.. versionchanged:: 2.4.3 added the *withhold* argument.
.. versionchanged:: 2.5 added the *scrollable* argument.
.. extension::
All the function arguments are Psycopg extensions to the |DBAPI|.
.. index::
pair: Transaction; Commit
.. method:: commit()
Commit any pending transaction to the database.
By default, Psycopg opens a transaction before executing the first
command: if `!commit()` is not called, the effect of any data
manipulation will be lost.
The connection can be also set in "autocommit" mode: no transaction is
automatically open, commands have immediate effect. See
:ref:`transactions-control` for details.
.. versionchanged:: 2.5 if the connection is used in a ``with``
statement, the method is automatically called if no exception is
raised in the ``with`` block.
.. index::
pair: Transaction; Rollback
.. method:: rollback()
Roll back to the start of any pending transaction. Closing a
connection without committing the changes first will cause an implicit
rollback to be performed.
.. versionchanged:: 2.5 if the connection is used in a ``with``
statement, the method is automatically called if an exception is
raised in the ``with`` block.
.. method:: close()
Close the connection now (rather than whenever `del` is executed).
The connection will be unusable from this point forward; an
`~psycopg2.InterfaceError` will be raised if any operation is
attempted with the connection. The same applies to all cursor objects
trying to use the connection. Note that closing a connection without
committing the changes first will cause any pending change to be
discarded as if a :sql:`ROLLBACK` was performed (unless a different
isolation level has been selected: see
`~connection.set_isolation_level()`).
.. index::
single: PgBouncer; unclean server
.. versionchanged:: 2.2
previously an explicit :sql:`ROLLBACK` was issued by Psycopg on
`!close()`. The command could have been sent to the backend at an
inappropriate time, so Psycopg currently relies on the backend to
implicitly discard uncommitted changes. Some middleware are known
to behave incorrectly though when the connection is closed during
a transaction (when `~connection.status` is
`~psycopg2.extensions.STATUS_IN_TRANSACTION`), e.g. PgBouncer_
reports an ``unclean server`` and discards the connection. To
avoid this problem you can ensure to terminate the transaction
with a `~connection.commit()`/`~connection.rollback()` before
closing.
.. _PgBouncer: http://www.pgbouncer.org/
.. index::
single: Exceptions; In the connection class
.. rubric:: Exceptions as connection class attributes
The `!connection` also exposes as attributes the same exceptions
available in the `psycopg2` module. See :ref:`dbapi-exceptions`.
.. index::
single: Two-phase commit; methods
.. rubric:: Two-phase commit support methods
.. versionadded:: 2.3
.. seealso:: :ref:`tpc` for an introductory explanation of these methods.
Note that PostgreSQL supports two-phase commit since release 8.1: these
methods raise `~psycopg2.NotSupportedError` if used with an older version
server.
.. _tpc_methods:
.. method:: xid(format_id, gtrid, bqual)
Returns a `~psycopg2.extensions.Xid` instance to be passed to the
`!tpc_*()` methods of this connection. The argument types and
constraints are explained in :ref:`tpc`.
The values passed to the method will be available on the returned
object as the members `~psycopg2.extensions.Xid.format_id`,
`~psycopg2.extensions.Xid.gtrid`, `~psycopg2.extensions.Xid.bqual`.
The object also allows accessing to these members and unpacking as a
3-items tuple.
.. method:: tpc_begin(xid)
Begins a TPC transaction with the given transaction ID *xid*.
This method should be called outside of a transaction (i.e. nothing
may have executed since the last `~connection.commit()` or
`~connection.rollback()` and `connection.status` is
`~psycopg2.extensions.STATUS_READY`).
Furthermore, it is an error to call `!commit()` or `!rollback()`
within the TPC transaction: in this case a `~psycopg2.ProgrammingError`
is raised.
The *xid* may be either an object returned by the `~connection.xid()`
method or a plain string: the latter allows to create a transaction
using the provided string as PostgreSQL transaction id. See also
`~connection.tpc_recover()`.
.. index::
pair: Transaction; Prepare
.. method:: tpc_prepare()
Performs the first phase of a transaction started with
`~connection.tpc_begin()`. A `~psycopg2.ProgrammingError` is raised if
this method is used outside of a TPC transaction.
After calling `!tpc_prepare()`, no statements can be executed until
`~connection.tpc_commit()` or `~connection.tpc_rollback()` will be
called. The `~connection.reset()` method can be used to restore the
status of the connection to `~psycopg2.extensions.STATUS_READY`: the
transaction will remain prepared in the database and will be
possible to finish it with `!tpc_commit(xid)` and
`!tpc_rollback(xid)`.
.. seealso:: the |PREPARE TRANSACTION|_ PostgreSQL command.
.. |PREPARE TRANSACTION| replace:: :sql:`PREPARE TRANSACTION`
.. _PREPARE TRANSACTION: https://www.postgresql.org/docs/current/static/sql-prepare-transaction.html
.. index::
pair: Commit; Prepared
.. method:: tpc_commit([xid])
When called with no arguments, `!tpc_commit()` commits a TPC
transaction previously prepared with `~connection.tpc_prepare()`.
If `!tpc_commit()` is called prior to `!tpc_prepare()`, a single phase
commit is performed. A transaction manager may choose to do this if
only a single resource is participating in the global transaction.
When called with a transaction ID *xid*, the database commits
the given transaction. If an invalid transaction ID is
provided, a `~psycopg2.ProgrammingError` will be raised. This form
should be called outside of a transaction, and is intended for use in
recovery.
On return, the TPC transaction is ended.
.. seealso:: the |COMMIT PREPARED|_ PostgreSQL command.
.. |COMMIT PREPARED| replace:: :sql:`COMMIT PREPARED`
.. _COMMIT PREPARED: https://www.postgresql.org/docs/current/static/sql-commit-prepared.html
.. index::
pair: Rollback; Prepared
.. method:: tpc_rollback([xid])
When called with no arguments, `!tpc_rollback()` rolls back a TPC
transaction. It may be called before or after
`~connection.tpc_prepare()`.
When called with a transaction ID *xid*, it rolls back the given
transaction. If an invalid transaction ID is provided, a
`~psycopg2.ProgrammingError` is raised. This form should be called
outside of a transaction, and is intended for use in recovery.
On return, the TPC transaction is ended.
.. seealso:: the |ROLLBACK PREPARED|_ PostgreSQL command.
.. |ROLLBACK PREPARED| replace:: :sql:`ROLLBACK PREPARED`
.. _ROLLBACK PREPARED: https://www.postgresql.org/docs/current/static/sql-rollback-prepared.html
.. index::
pair: Transaction; Recover
.. method:: tpc_recover()
Returns a list of `~psycopg2.extensions.Xid` representing pending
transactions, suitable for use with `tpc_commit()` or
`tpc_rollback()`.
If a transaction was not initiated by Psycopg, the returned Xids will
have attributes `~psycopg2.extensions.Xid.format_id` and
`~psycopg2.extensions.Xid.bqual` set to `!None` and the
`~psycopg2.extensions.Xid.gtrid` set to the PostgreSQL transaction ID: such Xids are still
usable for recovery. Psycopg uses the same algorithm of the
`PostgreSQL JDBC driver`__ to encode a XA triple in a string, so
transactions initiated by a program using such driver should be
unpacked correctly.
.. __: https://jdbc.postgresql.org/
Xids returned by `!tpc_recover()` also have extra attributes
`~psycopg2.extensions.Xid.prepared`, `~psycopg2.extensions.Xid.owner`,
`~psycopg2.extensions.Xid.database` populated with the values read
from the server.
.. seealso:: the |pg_prepared_xacts|_ system view.
.. |pg_prepared_xacts| replace:: `pg_prepared_xacts`
.. _pg_prepared_xacts: https://www.postgresql.org/docs/current/static/view-pg-prepared-xacts.html
.. extension::
The above methods are the only ones defined by the |DBAPI| protocol.
The Psycopg connection objects exports the following additional
methods and attributes.
.. attribute:: closed
Read-only integer attribute: 0 if the connection is open, nonzero if
it is closed or broken.
.. method:: cancel
Cancel the current database operation.
The method interrupts the processing of the current operation. If no
query is being executed, it does nothing. You can call this function
from a different thread than the one currently executing a database
operation, for instance if you want to cancel a long running query if a
button is pushed in the UI. Interrupting query execution will cause the
cancelled method to raise a
`~psycopg2.extensions.QueryCanceledError`. Note that the termination
of the query is not guaranteed to succeed: see the documentation for
|PQcancel|_.
.. |PQcancel| replace:: `!PQcancel()`
.. _PQcancel: https://www.postgresql.org/docs/current/static/libpq-cancel.html#LIBPQ-PQCANCEL
.. versionadded:: 2.3
.. method:: reset
Reset the connection to the default.
The method rolls back an eventual pending transaction and executes the
PostgreSQL |RESET|_ and |SET SESSION AUTHORIZATION|__ to revert the
session to the default values. A two-phase commit transaction prepared
using `~connection.tpc_prepare()` will remain in the database
available for recover.
.. |RESET| replace:: :sql:`RESET`
.. _RESET: https://www.postgresql.org/docs/current/static/sql-reset.html
.. |SET SESSION AUTHORIZATION| replace:: :sql:`SET SESSION AUTHORIZATION`
.. __: https://www.postgresql.org/docs/current/static/sql-set-session-authorization.html
.. versionadded:: 2.0.12
.. attribute:: dsn
Read-only string containing the connection string used by the
connection.
If a password was specified in the connection string it will be
obscured.
.. rubric:: Transaction control methods and attributes.
.. index::
pair: Transaction; Autocommit
pair: Transaction; Isolation level
.. method:: set_session(isolation_level=None, readonly=None, deferrable=None, autocommit=None)
Set one or more parameters for the next transactions or statements in
the current session.
:param isolation_level: set the `isolation level`_ for the next
transactions/statements. The value can be one of the literal
values ``READ UNCOMMITTED``, ``READ COMMITTED``, ``REPEATABLE
READ``, ``SERIALIZABLE`` or the equivalent :ref:`constant
<isolation-level-constants>` defined in the `~psycopg2.extensions`
module.
:param readonly: if `!True`, set the connection to read only;
read/write if `!False`.
:param deferrable: if `!True`, set the connection to deferrable;
non deferrable if `!False`. Only available from PostgreSQL 9.1.
:param autocommit: switch the connection to autocommit mode: not a
PostgreSQL session setting but an alias for setting the
`autocommit` attribute.
.. _isolation level:
https://www.postgresql.org/docs/current/static/transaction-iso.html
Arguments set to `!None` (the default for all) will not be changed.
The parameters *isolation_level*, *readonly* and *deferrable* also
accept the string ``DEFAULT`` as a value: the effect is to reset the
parameter to the server default. Defaults are defined by the server
configuration: see values for |default_transaction_isolation|__,
|default_transaction_read_only|__, |default_transaction_deferrable|__.
.. |default_transaction_isolation| replace:: :sql:`default_transaction_isolation`
.. __: https://www.postgresql.org/docs/current/static/runtime-config-client.html#GUC-DEFAULT-TRANSACTION-ISOLATION
.. |default_transaction_read_only| replace:: :sql:`default_transaction_read_only`
.. __: https://www.postgresql.org/docs/current/static/runtime-config-client.html#GUC-DEFAULT-TRANSACTION-READ-ONLY
.. |default_transaction_deferrable| replace:: :sql:`default_transaction_deferrable`
.. __: https://www.postgresql.org/docs/current/static/runtime-config-client.html#GUC-DEFAULT-TRANSACTION-DEFERRABLE
The function must be invoked with no transaction in progress.
.. seealso:: |SET TRANSACTION|_ for further details about the behaviour
of the transaction parameters in the server.
.. |SET TRANSACTION| replace:: :sql:`SET TRANSACTION`
.. _SET TRANSACTION: https://www.postgresql.org/docs/current/static/sql-set-transaction.html
.. versionadded:: 2.4.2
.. versionchanged:: 2.7
Before this version, the function would have set
:sql:`default_transaction_*` attribute in the current session;
this implementation has the problem of not playing well with
external connection pooling working at transaction level and not
resetting the state of the session: changing the default
transaction would pollute the connections in the pool and create
problems to other applications using the same pool.
Starting from 2.7, if the connection is not autocommit, the
transaction characteristics are issued together with :sql:`BEGIN`
and will leave the :sql:`default_transaction_*` settings untouched.
For example::
conn.set_session(readonly=True)
will not change :sql:`default_transaction_read_only`, but
following transaction will start with a :sql:`BEGIN READ ONLY`.
Conversely, using::
conn.set_session(readonly=True, autocommit=True)
will set :sql:`default_transaction_read_only` to :sql:`on` and
rely on the server to apply the read only state to whatever
transaction, implicit or explicit, is executed in the connection.
.. attribute:: autocommit
Read/write attribute: if `!True`, no transaction is handled by the
driver and every statement sent to the backend has immediate effect;
if `!False` a new transaction is started at the first command
execution: the methods `commit()` or `rollback()` must be manually
invoked to terminate the transaction.
The autocommit mode is useful to execute commands requiring to be run
outside a transaction, such as :sql:`CREATE DATABASE` or
:sql:`VACUUM`.
The default is `!False` (manual commit) as per DBAPI specification.
.. warning::
By default, any query execution, including a simple :sql:`SELECT`
will start a transaction: for long-running programs, if no further
action is taken, the session will remain "idle in transaction", an
undesirable condition for several reasons (locks are held by
the session, tables bloat...). For long lived scripts, either
ensure to terminate a transaction as soon as possible or use an
autocommit connection.
.. versionadded:: 2.4.2
.. attribute:: isolation_level
Return or set the `transaction isolation level`_ for the current
session. The value is one of the :ref:`isolation-level-constants`
defined in the `psycopg2.extensions` module. On set it is also
possible to use one of the literal values ``READ UNCOMMITTED``, ``READ
COMMITTED``, ``REPEATABLE READ``, ``SERIALIZABLE``, ``DEFAULT``.
.. versionchanged:: 2.7
the property is writable.
.. versionchanged:: 2.7
the default value for `!isolation_level` is
`~psycopg2.extensions.ISOLATION_LEVEL_DEFAULT`; previously the
property would have queried the server and returned the real value
applied. To know this value you can run a query such as :sql:`show
transaction_isolation`. Usually the default value is `READ
COMMITTED`, but this may be changed in the server configuration.
This value is now entirely separate from the `autocommit`
property: in previous version, if `!autocommit` was set to `!True`
this property would have returned
`~psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT`; it will now
return the server isolation level.
.. attribute:: readonly
Return or set the read-only status for the current session. Available
values are `!True` (new transactions will be in read-only mode),
`!False` (new transactions will be writable), `!None` (use the default
configured for the server by :sql:`default_transaction_read_only`).
.. versionadded:: 2.7
.. attribute:: deferrable
Return or set the `deferrable status`__ for the current session.
Available values are `!True` (new transactions will be in deferrable
mode), `!False` (new transactions will be in non deferrable mode),
`!None` (use the default configured for the server by
:sql:`default_transaction_deferrable`).
.. __: `SET TRANSACTION`_
.. versionadded:: 2.7
.. method:: set_isolation_level(level)
.. note::
This is a legacy method mixing `~conn.isolation_level` and
`~conn.autocommit`. Using the respective properties is a better
option.
Set the `transaction isolation level`_ for the current session.
The level defines the different phenomena that can happen in the
database between concurrent transactions.
The value set is an integer: symbolic constants are defined in
the module `psycopg2.extensions`: see
:ref:`isolation-level-constants` for the available values.
The default level is `~psycopg2.extensions.ISOLATION_LEVEL_DEFAULT`:
at this level a transaction is automatically started the first time a
database command is executed. If you want an *autocommit* mode,
switch to `~psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT` before
executing any command::
>>> conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
See also :ref:`transactions-control`.
.. index::
pair: Client; Encoding
.. attribute:: encoding
.. method:: set_client_encoding(enc)
Read or set the client encoding for the current session. The default
is the encoding defined by the database. It should be one of the
`characters set supported by PostgreSQL`__
.. __: https://www.postgresql.org/docs/current/static/multibyte.html
.. index::
pair: Client; Logging
.. attribute:: notices
A list containing all the database messages sent to the client during
the session.
.. doctest::
:options: +NORMALIZE_WHITESPACE
>>> cur.execute("CREATE TABLE foo (id serial PRIMARY KEY);")
>>> pprint(conn.notices)
['NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "foo_pkey" for table "foo"\n',
'NOTICE: CREATE TABLE will create implicit sequence "foo_id_seq" for serial column "foo.id"\n']
.. versionchanged:: 2.7
The `!notices` attribute is writable: the user may replace it
with any Python object exposing an `!append()` method. If
appending raises an exception the notice is silently
dropped.
To avoid a leak in case excessive notices are generated, only the last
50 messages are kept. This check is only in place if the `!notices`
attribute is a list: if any other object is used it will be up to the
user to guard from leakage.
You can configure what messages to receive using `PostgreSQL logging
configuration parameters`__ such as ``log_statement``,
``client_min_messages``, ``log_min_duration_statement`` etc.
.. __: https://www.postgresql.org/docs/current/static/runtime-config-logging.html
.. attribute:: notifies
List of `~psycopg2.extensions.Notify` objects containing asynchronous
notifications received by the session.
For other details see :ref:`async-notify`.
.. versionchanged:: 2.3
Notifications are instances of the `!Notify` object. Previously the
list was composed by 2 items tuples :samp:`({pid},{channel})` and
the payload was not accessible. To keep backward compatibility,
`!Notify` objects can still be accessed as 2 items tuples.
.. versionchanged:: 2.7
The `!notifies` attribute is writable: the user may replace it
with any Python object exposing an `!append()` method. If
appending raises an exception the notification is silently
dropped.
.. attribute:: cursor_factory
The default cursor factory used by `~connection.cursor()` if the
parameter is not specified.
.. versionadded:: 2.5
.. index::
pair: Connection; Info
.. attribute:: info
A `~psycopg2.extensions.ConnectionInfo` object exposing information
about the native libpq connection.
.. versionadded:: 2.8
.. index::
pair: Connection; Status
.. attribute:: status
A read-only integer representing the status of the connection.
Symbolic constants for the values are defined in the module
`psycopg2.extensions`: see :ref:`connection-status-constants`
for the available values.
The status is undefined for `closed` connections.
.. method:: lobject([oid [, mode [, new_oid [, new_file [, lobject_factory]]]]])
Return a new database large object as a `~psycopg2.extensions.lobject`
instance.
See :ref:`large-objects` for an overview.
:param oid: The OID of the object to read or write. 0 to create
a new large object and and have its OID assigned automatically.
:param mode: Access mode to the object, see below.
:param new_oid: Create a new object using the specified OID. The
function raises `~psycopg2.OperationalError` if the OID is already
in use. Default is 0, meaning assign a new one automatically.
:param new_file: The name of a file to be imported in the database
(using the |lo_import|_ function)
:param lobject_factory: Subclass of
`~psycopg2.extensions.lobject` to be instantiated.
.. |lo_import| replace:: `!lo_import()`
.. _lo_import: https://www.postgresql.org/docs/current/static/lo-interfaces.html#LO-IMPORT
Available values for *mode* are:
======= =========
*mode* meaning
======= =========
``r`` Open for read only
``w`` Open for write only
``rw`` Open for read/write
``n`` Don't open the file
``b`` Don't decode read data (return data as `!str` in Python 2 or `!bytes` in Python 3)
``t`` Decode read data according to `connection.encoding` (return data as `!unicode` in Python 2 or `!str` in Python 3)
======= =========
``b`` and ``t`` can be specified together with a read/write mode. If
neither ``b`` nor ``t`` is specified, the default is ``b`` in Python 2
and ``t`` in Python 3.
.. versionadded:: 2.0.8
.. versionchanged:: 2.4 added ``b`` and ``t`` mode and unicode
support.
.. rubric:: Methods related to asynchronous support
.. versionadded:: 2.2
.. seealso:: :ref:`async-support` and :ref:`green-support`.
.. attribute:: async
async_
Read only attribute: 1 if the connection is asynchronous, 0 otherwise.
.. versionchanged:: 2.7 added the `!async_` alias for Python versions
where `!async` is a keyword.
.. method:: poll()
Used during an asynchronous connection attempt, or when a cursor is
executing a query on an asynchronous connection, make communication
proceed if it wouldn't block.
Return one of the constants defined in :ref:`poll-constants`. If it
returns `~psycopg2.extensions.POLL_OK` then the connection has been
established or the query results are available on the client.
Otherwise wait until the file descriptor returned by `fileno()` is
ready to read or to write, as explained in :ref:`async-support`.
`poll()` should be also used by the function installed by
`~psycopg2.extensions.set_wait_callback()` as explained in
:ref:`green-support`.
`poll()` is also used to receive asynchronous notifications from the
database: see :ref:`async-notify` from further details.
.. method:: fileno()
Return the file descriptor underlying the connection: useful to read
its status during asynchronous communication.
.. method:: isexecuting()
Return `!True` if the connection is executing an asynchronous operation.
.. rubric:: Interoperation with other C API modules
.. attribute:: pgconn_ptr
Return the internal `!PGconn*` as integer. Useful to pass the libpq
raw connection structure to C functions, e.g. via `ctypes`::
>>> import ctypes
>>> import ctypes.util
>>> libpq = ctypes.pydll.LoadLibrary(ctypes.util.find_library('pq'))
>>> libpq.PQserverVersion.argtypes = [ctypes.c_void_p]
>>> libpq.PQserverVersion.restype = ctypes.c_int
>>> libpq.PQserverVersion(conn.pgconn_ptr)
90611
.. versionadded:: 2.8
.. method:: get_native_connection()
Return the internal `!PGconn*` wrapped in a PyCapsule object. This is
only useful for passing the `libpq` raw connection associated to this
connection object to other C-level modules that may have a use for it.
.. seealso:: Python C API `Capsules`__ docs.
.. __: https://docs.python.org/3.1/c-api/capsule.html
.. versionadded:: 2.8
.. rubric:: informative methods of the native connection
.. note::
These methods are better accessed using the `~connection.info`
attributes and may be dropped in future versions.
.. index::
pair: Transaction; Status
.. method:: get_transaction_status()
Also available as `~connection.info`\ `!.`\
`~psycopg2.extensions.ConnectionInfo.transaction_status`.
Return the current session transaction status as an integer. Symbolic
constants for the values are defined in the module
`psycopg2.extensions`: see :ref:`transaction-status-constants`
for the available values.
.. seealso:: libpq docs for `PQtransactionStatus()`__ for details.
.. __: https://www.postgresql.org/docs/current/static/libpq-status.html#LIBPQ-PQTRANSACTIONSTATUS
.. index::
pair: Protocol; Version
.. attribute:: protocol_version
Also available as `~connection.info`\ `!.`\
`~psycopg2.extensions.ConnectionInfo.protocol_version`.
A read-only integer representing frontend/backend protocol being used.
Currently Psycopg supports only protocol 3, which allows connection
to PostgreSQL server from version 7.4. Psycopg versions previous than
2.3 support both protocols 2 and 3.
.. seealso:: libpq docs for `PQprotocolVersion()`__ for details.
.. __: https://www.postgresql.org/docs/current/static/libpq-status.html#LIBPQ-PQPROTOCOLVERSION
.. versionadded:: 2.0.12
.. index::
pair: Server; Version
.. attribute:: server_version
Also available as `~connection.info`\ `!.`\
`~psycopg2.extensions.ConnectionInfo.server_version`.
A read-only integer representing the backend version.
The number is formed by converting the major, minor, and revision
numbers into two-decimal-digit numbers and appending them together.
For example, version 8.1.5 will be returned as ``80105``.
.. seealso:: libpq docs for `PQserverVersion()`__ for details.
.. __: https://www.postgresql.org/docs/current/static/libpq-status.html#LIBPQ-PQSERVERVERSION
.. versionadded:: 2.0.12
.. index::
pair: Backend; PID
.. method:: get_backend_pid()
Also available as `~connection.info`\ `!.`\
`~psycopg2.extensions.ConnectionInfo.backend_pid`.
Returns the process ID (PID) of the backend server process *you
connected to*. Note that if you use a connection pool service such as
PgBouncer_ this value will not be updated if your connection is
switched to a different backend.
Note that the PID belongs to a process executing on the database
server host, not the local host!
.. seealso:: libpq docs for `PQbackendPID()`__ for details.
.. __: https://www.postgresql.org/docs/current/static/libpq-status.html#LIBPQ-PQBACKENDPID
.. versionadded:: 2.0.8
.. index::
pair: Server; Parameters
.. method:: get_parameter_status(parameter)
Also available as `~connection.info`\ `!.`\
`~psycopg2.extensions.ConnectionInfo.parameter_status()`.
Look up a current parameter setting of the server.
Potential values for ``parameter`` are: ``server_version``,
``server_encoding``, ``client_encoding``, ``is_superuser``,
``session_authorization``, ``DateStyle``, ``TimeZone``,
``integer_datetimes``, and ``standard_conforming_strings``.
If server did not report requested parameter, return `!None`.
.. seealso:: libpq docs for `PQparameterStatus()`__ for details.
.. __: https://www.postgresql.org/docs/current/static/libpq-status.html#LIBPQ-PQPARAMETERSTATUS
.. versionadded:: 2.0.12
.. index::
pair: Connection; Parameters
.. method:: get_dsn_parameters()
Also available as `~connection.info`\ `!.`\
`~psycopg2.extensions.ConnectionInfo.dsn_parameters`.
Get the effective dsn parameters for the connection as a dictionary.
The *password* parameter is removed from the result.
Example::
>>> conn.get_dsn_parameters()
{'dbname': 'test', 'user': 'postgres', 'port': '5432', 'sslmode': 'prefer'}
Requires libpq >= 9.3.
.. seealso:: libpq docs for `PQconninfo()`__ for details.
.. __: https://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-PQCONNINFO
.. versionadded:: 2.7
.. testcode::
:hide:
conn.rollback()

682
doc/src/cursor.rst Normal file
View File

@ -0,0 +1,682 @@
The ``cursor`` class
====================
.. sectionauthor:: Daniele Varrazzo <daniele.varrazzo@gmail.com>
.. testsetup:: *
from StringIO import StringIO
import sys
create_test_table()
# initial data
cur.executemany("INSERT INTO test (num, data) VALUES (%s, %s)",
[(100, "abc'def"), (None, 'dada'), (42, 'bar')])
conn.commit()
.. class:: cursor
Allows Python code to execute PostgreSQL command in a database session.
Cursors are created by the `connection.cursor()` method: they are
bound to the connection for the entire lifetime and all the commands are
executed in the context of the database session wrapped by the connection.
Cursors created from the same connection are not isolated, i.e., any
changes done to the database by a cursor are immediately visible by the
other cursors. Cursors created from different connections can or can not
be isolated, depending on the connections' :ref:`isolation level
<transactions-control>`. See also `~connection.rollback()` and
`~connection.commit()` methods.
Cursors are *not* thread safe: a multithread application can create
many cursors from the same connection and should use each cursor from
a single thread. See :ref:`thread-safety` for details.
Cursors can be used as context managers: leaving the context will close
the cursor.
.. code:: python
with conn.cursor() as curs:
curs.execute(SQL)
# the cursor is now closed
.. attribute:: description
Read-only attribute describing the result of a query. It is a
sequence of `~psycopg2.extensions.Column` instances, each one
describing one result column in order. The attribute is `!None` for
operations that do not return rows or if the cursor has not had an
operation invoked via the |execute*|_ methods yet.
For compatibility with the DB-API, every object can be unpacked as a
7-items sequence: the attributes retuned this way are the following.
For further details and other attributes available check the
`~psycopg2.extensions.Column` documentation.
0. `~psycopg2.extensions.Column.name`: the name of the column returned.
1. `~psycopg2.extensions.Column.type_code`: the PostgreSQL OID of the
column.
2. `~psycopg2.extensions.Column.display_size`: the actual length of
the column in bytes.
3. `~psycopg2.extensions.Column.internal_size`: the size in bytes of
the column associated to this column on the server.
4. `~psycopg2.extensions.Column.precision`: total number of
significant digits in columns of type |NUMERIC|. `!None`
for other types.
5. `~psycopg2.extensions.Column.scale`: count of decimal digits in
the fractional part in columns of type |NUMERIC|. `!None`
for other types.
6. `~psycopg2.extensions.Column.null_ok`: always `!None` as not easy
to retrieve from the libpq.
.. versionchanged:: 2.4
if possible, columns descriptions are named tuple instead of
regular tuples.
.. versionchanged:: 2.8
columns descriptions are instances of `!Column`, exposing extra
attributes.
.. |NUMERIC| replace:: :sql:`NUMERIC`
.. method:: close()
Close the cursor now (rather than whenever `del` is executed).
The cursor will be unusable from this point forward; an
`~psycopg2.InterfaceError` will be raised if any operation is
attempted with the cursor.
.. versionchanged:: 2.5 if the cursor is used in a ``with`` statement,
the method is automatically called at the end of the ``with``
block.
.. attribute:: closed
Read-only boolean attribute: specifies if the cursor is closed
(`!True`) or not (`!False`).
.. extension::
The `closed` attribute is a Psycopg extension to the
|DBAPI|.
.. versionadded:: 2.0.7
.. attribute:: connection
Read-only attribute returning a reference to the `connection`
object on which the cursor was created.
.. attribute:: name
Read-only attribute containing the name of the cursor if it was
created as named cursor by `connection.cursor()`, or `!None` if
it is a client side cursor. See :ref:`server-side-cursors`.
.. extension::
The `name` attribute is a Psycopg extension to the |DBAPI|.
.. attribute:: scrollable
Read/write attribute: specifies if a named cursor is declared
:sql:`SCROLL`, hence is capable to scroll backwards (using
`~cursor.scroll()`). If `!True`, the cursor can be scrolled backwards,
if `!False` it is never scrollable. If `!None` (default) the cursor
scroll option is not specified, usually but not always meaning no
backward scroll (see the |declare-notes|__).
.. |declare-notes| replace:: :sql:`DECLARE` notes
.. __: https://www.postgresql.org/docs/current/static/sql-declare.html#SQL-DECLARE-NOTES
.. note::
set the value before calling `~cursor.execute()` or use the
`connection.cursor()` *scrollable* parameter, otherwise the value
will have no effect.
.. versionadded:: 2.5
.. extension::
The `scrollable` attribute is a Psycopg extension to the |DBAPI|.
.. attribute:: withhold
Read/write attribute: specifies if a named cursor lifetime should
extend outside of the current transaction, i.e., it is possible to
fetch from the cursor even after a `connection.commit()` (but not after
a `connection.rollback()`). See :ref:`server-side-cursors`
.. note::
set the value before calling `~cursor.execute()` or use the
`connection.cursor()` *withhold* parameter, otherwise the value
will have no effect.
.. versionadded:: 2.4.3
.. extension::
The `withhold` attribute is a Psycopg extension to the |DBAPI|.
.. |execute*| replace:: `execute*()`
.. _execute*:
.. rubric:: Commands execution methods
.. method:: execute(query, vars=None)
Execute a database operation (query or command).
Parameters may be provided as sequence or mapping and will be bound to
variables in the operation. Variables are specified either with
positional (``%s``) or named (:samp:`%({name})s`) placeholders. See
:ref:`query-parameters`.
The method returns `!None`. If a query was executed, the returned
values can be retrieved using |fetch*|_ methods.
.. method:: executemany(query, vars_list)
Execute a database operation (query or command) against all parameter
tuples or mappings found in the sequence *vars_list*.
The function is mostly useful for commands that update the database:
any result set returned by the query is discarded.
Parameters are bounded to the query using the same rules described in
the `~cursor.execute()` method.
.. code:: python
>>> nums = ((1,), (5,), (10,))
>>> cur.executemany("INSERT INTO test (num) VALUES (%s)", nums)
>>> tuples = ((123, "foo"), (42, "bar"), (23, "baz"))
>>> cur.executemany("INSERT INTO test (num, data) VALUES (%s, %s)", tuples)
.. warning::
In its current implementation this method is not faster than
executing `~cursor.execute()` in a loop. For better performance
you can use the functions described in :ref:`fast-exec`.
.. method:: callproc(procname [, parameters])
Call a stored database procedure with the given name. The sequence of
parameters must contain one entry for each argument that the procedure
expects. Overloaded procedures are supported. Named parameters can be
used by supplying the parameters as a dictionary.
This function is, at present, not DBAPI-compliant. The return value is
supposed to consist of the sequence of parameters with modified output
and input/output parameters. In future versions, the DBAPI-compliant
return value may be implemented, but for now the function returns None.
The procedure may provide a result set as output. This is then made
available through the standard |fetch*|_ methods.
.. versionchanged:: 2.7
added support for named arguments.
.. note::
`!callproc()` can only be used with PostgreSQL functions__, not
with the procedures__ introduced in PostgreSQL 11, which require
the :sql:`CALL` statement to run. Please use a normal
`execute()` to run them.
.. __: https://www.postgresql.org/docs/current/sql-createfunction.html
.. __: https://www.postgresql.org/docs/current/sql-createprocedure.html
.. method:: mogrify(operation [, parameters])
Return a query string after arguments binding. The string returned is
exactly the one that would be sent to the database running the
`~cursor.execute()` method or similar.
The returned string is always a bytes string.
>>> cur.mogrify("INSERT INTO test (num, data) VALUES (%s, %s)", (42, 'bar'))
"INSERT INTO test (num, data) VALUES (42, E'bar')"
.. extension::
The `mogrify()` method is a Psycopg extension to the |DBAPI|.
.. method:: setinputsizes(sizes)
This method is exposed in compliance with the |DBAPI|. It currently
does nothing but it is safe to call it.
.. |fetch*| replace:: `!fetch*()`
.. _fetch*:
.. rubric:: Results retrieval methods
The following methods are used to read data from the database after an
`~cursor.execute()` call.
.. _cursor-iterable:
.. note::
`cursor` objects are iterable, so, instead of calling
explicitly `~cursor.fetchone()` in a loop, the object itself can
be used:
>>> cur.execute("SELECT * FROM test;")
>>> for record in cur:
... print(record)
...
(1, 100, "abc'def")
(2, None, 'dada')
(3, 42, 'bar')
.. versionchanged:: 2.4
iterating over a :ref:`named cursor <server-side-cursors>`
fetches `~cursor.itersize` records at time from the backend.
Previously only one record was fetched per roundtrip, resulting
in a large overhead.
.. method:: fetchone()
Fetch the next row of a query result set, returning a single tuple,
or `!None` when no more data is available:
>>> cur.execute("SELECT * FROM test WHERE id = %s", (3,))
>>> cur.fetchone()
(3, 42, 'bar')
A `~psycopg2.ProgrammingError` is raised if the previous call
to |execute*|_ did not produce any result set or no call was issued
yet.
.. method:: fetchmany([size=cursor.arraysize])
Fetch the next set of rows of a query result, returning a list of
tuples. An empty list is returned when no more rows are available.
The number of rows to fetch per call is specified by the parameter.
If it is not given, the cursor's `~cursor.arraysize` determines
the number of rows to be fetched. The method should try to fetch as
many rows as indicated by the size parameter. If this is not possible
due to the specified number of rows not being available, fewer rows
may be returned:
>>> cur.execute("SELECT * FROM test;")
>>> cur.fetchmany(2)
[(1, 100, "abc'def"), (2, None, 'dada')]
>>> cur.fetchmany(2)
[(3, 42, 'bar')]
>>> cur.fetchmany(2)
[]
A `~psycopg2.ProgrammingError` is raised if the previous call to
|execute*|_ did not produce any result set or no call was issued yet.
Note there are performance considerations involved with the size
parameter. For optimal performance, it is usually best to use the
`~cursor.arraysize` attribute. If the size parameter is used,
then it is best for it to retain the same value from one
`fetchmany()` call to the next.
.. method:: fetchall()
Fetch all (remaining) rows of a query result, returning them as a list
of tuples. An empty list is returned if there is no more record to
fetch.
>>> cur.execute("SELECT * FROM test;")
>>> cur.fetchall()
[(1, 100, "abc'def"), (2, None, 'dada'), (3, 42, 'bar')]
A `~psycopg2.ProgrammingError` is raised if the previous call to
|execute*|_ did not produce any result set or no call was issued yet.
.. method:: scroll(value [, mode='relative'])
Scroll the cursor in the result set to a new position according
to mode.
If `mode` is ``relative`` (default), value is taken as offset to
the current position in the result set, if set to ``absolute``,
value states an absolute target position.
If the scroll operation would leave the result set, a
`~psycopg2.ProgrammingError` is raised and the cursor position is
not changed.
.. note::
According to the |DBAPI|_, the exception raised for a cursor out
of bound should have been `!IndexError`. The best option is
probably to catch both exceptions in your code::
try:
cur.scroll(1000 * 1000)
except (ProgrammingError, IndexError), exc:
deal_with_it(exc)
The method can be used both for client-side cursors and
:ref:`server-side cursors <server-side-cursors>`. Server-side cursors
can usually scroll backwards only if declared `~cursor.scrollable`.
Moving out-of-bound in a server-side cursor doesn't result in an
exception, if the backend doesn't raise any (Postgres doesn't tell us
in a reliable way if we went out of bound).
.. attribute:: arraysize
This read/write attribute specifies the number of rows to fetch at a
time with `~cursor.fetchmany()`. It defaults to 1 meaning to fetch
a single row at a time.
.. attribute:: itersize
Read/write attribute specifying the number of rows to fetch from the
backend at each network roundtrip during :ref:`iteration
<cursor-iterable>` on a :ref:`named cursor <server-side-cursors>`. The
default is 2000.
.. versionadded:: 2.4
.. extension::
The `itersize` attribute is a Psycopg extension to the |DBAPI|.
.. attribute:: rowcount
This read-only attribute specifies the number of rows that the last
|execute*|_ produced (for :abbr:`DQL (Data Query Language)` statements
like :sql:`SELECT`) or affected (for
:abbr:`DML (Data Manipulation Language)` statements like :sql:`UPDATE`
or :sql:`INSERT`).
The attribute is -1 in case no |execute*| has been performed on
the cursor or the row count of the last operation if it can't be
determined by the interface.
.. note::
The |DBAPI|_ interface reserves to redefine the latter case to
have the object return `!None` instead of -1 in future versions
of the specification.
.. attribute:: rownumber
This read-only attribute provides the current 0-based index of the
cursor in the result set or `!None` if the index cannot be
determined.
The index can be seen as index of the cursor in a sequence (the result
set). The next fetch operation will fetch the row indexed by
`rownumber` in that sequence.
.. index:: oid
.. attribute:: lastrowid
This read-only attribute provides the OID of the last row inserted
by the cursor. If the table wasn't created with OID support or the
last operation is not a single record insert, the attribute is set to
`!None`.
.. note::
PostgreSQL currently advices to not create OIDs on the tables and
the default for |CREATE-TABLE|__ is to not support them. The
|INSERT-RETURNING|__ syntax available from PostgreSQL 8.3 allows
more flexibility.
.. |CREATE-TABLE| replace:: :sql:`CREATE TABLE`
.. __: https://www.postgresql.org/docs/current/static/sql-createtable.html
.. |INSERT-RETURNING| replace:: :sql:`INSERT ... RETURNING`
.. __: https://www.postgresql.org/docs/current/static/sql-insert.html
.. attribute:: query
Read-only attribute containing the body of the last query sent to the
backend (including bound arguments) as bytes string. `!None` if no
query has been executed yet:
>>> cur.execute("INSERT INTO test (num, data) VALUES (%s, %s)", (42, 'bar'))
>>> cur.query
"INSERT INTO test (num, data) VALUES (42, E'bar')"
.. extension::
The `query` attribute is a Psycopg extension to the |DBAPI|.
.. attribute:: statusmessage
Read-only attribute containing the message returned by the last
command:
>>> cur.execute("INSERT INTO test (num, data) VALUES (%s, %s)", (42, 'bar'))
>>> cur.statusmessage
'INSERT 0 1'
.. extension::
The `statusmessage` attribute is a Psycopg extension to the
|DBAPI|.
.. method:: cast(oid, s)
Convert a value from the PostgreSQL string representation to a Python
object.
Use the most specific of the typecasters registered by
`~psycopg2.extensions.register_type()`.
.. versionadded:: 2.4
.. extension::
The `cast()` method is a Psycopg extension to the |DBAPI|.
.. attribute:: tzinfo_factory
The time zone factory used to handle data types such as
:sql:`TIMESTAMP WITH TIME ZONE`. It should be a `~datetime.tzinfo`
object. Default is `datetime.timezone`.
.. versionchanged:: 2.9
previosly the default factory was `psycopg2.tz.FixedOffsetTimezone`.
.. method:: nextset()
This method is not supported (PostgreSQL does not have multiple data
sets) and will raise a `~psycopg2.NotSupportedError` exception.
.. method:: setoutputsize(size [, column])
This method is exposed in compliance with the |DBAPI|. It currently
does nothing but it is safe to call it.
.. rubric:: COPY-related methods
Efficiently copy data from file-like objects to the database and back. See
:ref:`copy` for an overview.
.. extension::
The :sql:`COPY` command is a PostgreSQL extension to the SQL standard.
As such, its support is a Psycopg extension to the |DBAPI|.
.. method:: copy_from(file, table, sep='\\t', null='\\\\N', size=8192, columns=None)
Read data *from* the file-like object *file* appending them to
the table named *table*.
:param file: file-like object to read data from. It must have both
`!read()` and `!readline()` methods.
:param table: name of the table to copy data into.
:param sep: columns separator expected in the file. Defaults to a tab.
:param null: textual representation of :sql:`NULL` in the file.
The default is the two characters string ``\N``.
:param size: size of the buffer used to read from the file.
:param columns: iterable with name of the columns to import.
The length and types should match the content of the file to read.
If not specified, it is assumed that the entire table matches the
file structure.
Example::
>>> f = StringIO("42\tfoo\n74\tbar\n")
>>> cur.copy_from(f, 'test', columns=('num', 'data'))
>>> cur.execute("select * from test where id > 5;")
>>> cur.fetchall()
[(6, 42, 'foo'), (7, 74, 'bar')]
.. versionchanged:: 2.0.6
added the *columns* parameter.
.. versionchanged:: 2.4
data read from files implementing the `io.TextIOBase` interface
are encoded in the connection `~connection.encoding` when sent to
the backend.
.. versionchanged:: 2.9
the table and fields names are now quoted. If you need to specify
a schema-qualified table please use `copy_expert()`.
.. method:: copy_to(file, table, sep='\\t', null='\\\\N', columns=None)
Write the content of the table named *table* *to* the file-like
object *file*. See :ref:`copy` for an overview.
:param file: file-like object to write data into. It must have a
`!write()` method.
:param table: name of the table to copy data from.
:param sep: columns separator expected in the file. Defaults to a tab.
:param null: textual representation of :sql:`NULL` in the file.
The default is the two characters string ``\N``.
:param columns: iterable with name of the columns to export.
If not specified, export all the columns.
Example::
>>> cur.copy_to(sys.stdout, 'test', sep="|")
1|100|abc'def
2|\N|dada
...
.. versionchanged:: 2.0.6
added the *columns* parameter.
.. versionchanged:: 2.4
data sent to files implementing the `io.TextIOBase` interface
are decoded in the connection `~connection.encoding` when read
from the backend.
.. versionchanged:: 2.9
the table and fields names are now quoted. If you need to specify
a schema-qualified table please use `copy_expert()`.
.. method:: copy_expert(sql, file, size=8192)
Submit a user-composed :sql:`COPY` statement. The method is useful to
handle all the parameters that PostgreSQL makes available (see
|COPY|__ command documentation).
:param sql: the :sql:`COPY` statement to execute.
:param file: a file-like object to read or write (according to *sql*).
:param size: size of the read buffer to be used in :sql:`COPY FROM`.
The *sql* statement should be in the form :samp:`COPY {table} TO
STDOUT` to export :samp:`{table}` to the *file* object passed as
argument or :samp:`COPY {table} FROM STDIN` to import the content of
the *file* object into :samp:`{table}`. If you need to compose a
:sql:`COPY` statement dynamically (because table, fields, or query
parameters are in Python variables) you may use the objects provided
by the `psycopg2.sql` module.
*file* must be a readable file-like object (as required by
`~cursor.copy_from()`) for *sql* statement :sql:`COPY ... FROM STDIN`
or a writable one (as required by `~cursor.copy_to()`) for :sql:`COPY
... TO STDOUT`.
Example:
>>> cur.copy_expert("COPY test TO STDOUT WITH CSV HEADER", sys.stdout)
id,num,data
1,100,abc'def
2,,dada
...
.. |COPY| replace:: :sql:`COPY`
.. __: https://www.postgresql.org/docs/current/static/sql-copy.html
.. versionadded:: 2.0.6
.. versionchanged:: 2.4
files implementing the `io.TextIOBase` interface are dealt with
using Unicode data instead of bytes.
.. rubric:: Interoperation with other C API modules
.. attribute:: pgresult_ptr
Return the cursor's internal `!PGresult*` as integer. Useful to pass
the libpq raw result structure to C functions, e.g. via `ctypes`::
>>> import ctypes
>>> libpq = ctypes.pydll.LoadLibrary(ctypes.util.find_library('pq'))
>>> libpq.PQcmdStatus.argtypes = [ctypes.c_void_p]
>>> libpq.PQcmdStatus.restype = ctypes.c_char_p
>>> curs.execute("select 'x'")
>>> libpq.PQcmdStatus(curs.pgresult_ptr)
b'SELECT 1'
.. versionadded:: 2.8
.. testcode::
:hide:
conn.rollback()

76
doc/src/errorcodes.rst Normal file
View File

@ -0,0 +1,76 @@
`psycopg2.errorcodes` -- Error codes defined by PostgreSQL
===============================================================
.. sectionauthor:: Daniele Varrazzo <daniele.varrazzo@gmail.com>
.. index::
single: Error; Codes
.. module:: psycopg2.errorcodes
.. testsetup:: *
from psycopg2 import errorcodes
.. versionadded:: 2.0.6
This module contains symbolic names for all PostgreSQL error codes and error
classes codes. Subclasses of `~psycopg2.Error` make the PostgreSQL error
code available in the `~psycopg2.Error.pgcode` attribute.
From PostgreSQL documentation:
All messages emitted by the PostgreSQL server are assigned five-character
error codes that follow the SQL standard's conventions for :sql:`SQLSTATE`
codes. Applications that need to know which error condition has occurred
should usually test the error code, rather than looking at the textual
error message. The error codes are less likely to change across
PostgreSQL releases, and also are not subject to change due to
localization of error messages. Note that some, but not all, of the error
codes produced by PostgreSQL are defined by the SQL standard; some
additional error codes for conditions not defined by the standard have
been invented or borrowed from other databases.
According to the standard, the first two characters of an error code
denote a class of errors, while the last three characters indicate a
specific condition within that class. Thus, an application that does not
recognize the specific error code can still be able to infer what to do
from the error class.
.. seealso:: `PostgreSQL Error Codes table`__
.. __: https://www.postgresql.org/docs/current/static/errcodes-appendix.html#ERRCODES-TABLE
An example of the available constants defined in the module:
>>> errorcodes.CLASS_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION
'42'
>>> errorcodes.UNDEFINED_TABLE
'42P01'
Constants representing all the error values defined by PostgreSQL versions
between 8.1 and 15 are included in the module.
.. autofunction:: lookup(code)
.. doctest::
>>> try:
... cur.execute("SELECT ouch FROM aargh;")
... except Exception as e:
... pass
...
>>> errorcodes.lookup(e.pgcode[:2])
'CLASS_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION'
>>> errorcodes.lookup(e.pgcode)
'UNDEFINED_TABLE'
.. versionadded:: 2.0.14
.. testcode::
:hide:
conn.rollback()

89
doc/src/errors.rst Normal file
View File

@ -0,0 +1,89 @@
`psycopg2.errors` -- Exception classes mapping PostgreSQL errors
================================================================
.. sectionauthor:: Daniele Varrazzo <daniele.varrazzo@gmail.com>
.. index::
single: Error; Class
.. module:: psycopg2.errors
.. versionadded:: 2.8
.. versionchanged:: 2.8.4 added errors introduced in PostgreSQL 12
.. versionchanged:: 2.8.6 added errors introduced in PostgreSQL 13
.. versionchanged:: 2.9.2 added errors introduced in PostgreSQL 14
.. versionchanged:: 2.9.4 added errors introduced in PostgreSQL 15
.. versionchanged:: 2.9.10 added errors introduced in PostgreSQL 17
This module exposes the classes psycopg raises upon receiving an error from
the database with a :sql:`SQLSTATE` value attached (available in the
`~psycopg2.Error.pgcode` attribute). The content of the module is generated
from the PostgreSQL source code and includes classes for every error defined
by PostgreSQL in versions between 9.1 and 15.
Every class in the module is named after what referred as "condition name" `in
the documentation`__, converted to CamelCase: e.g. the error 22012,
``division_by_zero`` is exposed by this module as the class `!DivisionByZero`.
.. __: https://www.postgresql.org/docs/current/static/errcodes-appendix.html#ERRCODES-TABLE
Every exception class is a subclass of one of the :ref:`standard DB-API
exception <dbapi-exceptions>` and expose the `~psycopg2.Error` interface.
Each class' superclass is what used to be raised by psycopg in versions before
the introduction of this module, so everything should be compatible with
previously written code catching one the DB-API class: if your code used to
catch `!IntegrityError` to detect a duplicate entry, it will keep on working
even if a more specialised subclass such as `UniqueViolation` is raised.
The new classes allow a more idiomatic way to check and process a specific
error among the many the database may return. For instance, in order to check
that a table is locked, the following code could have been used previously:
.. code-block:: python
try:
cur.execute("LOCK TABLE mytable IN ACCESS EXCLUSIVE MODE NOWAIT")
except psycopg2.OperationalError as e:
if e.pgcode == psycopg2.errorcodes.LOCK_NOT_AVAILABLE:
locked = True
else:
raise
While this method is still available, the specialised class allows for a more
idiomatic error handler:
.. code-block:: python
try:
cur.execute("LOCK TABLE mytable IN ACCESS EXCLUSIVE MODE NOWAIT")
except psycopg2.errors.LockNotAvailable:
locked = True
.. autofunction:: lookup
.. code-block:: python
try:
cur.execute("LOCK TABLE mytable IN ACCESS EXCLUSIVE MODE NOWAIT")
except psycopg2.errors.lookup("55P03"):
locked = True
SQLSTATE exception classes
--------------------------
The following table contains the list of all the SQLSTATE classes exposed by
the module.
Note that, for completeness, the module also exposes all the
:ref:`DB-API-defined exceptions <dbapi-exceptions>` and :ref:`a few
psycopg-specific ones <extension-exceptions>` exposed by the `!extensions`
module, which are not listed here.
.. include:: sqlstate_errors.rst

1010
doc/src/extensions.rst Normal file

File diff suppressed because it is too large Load Diff

1093
doc/src/extras.rst Normal file

File diff suppressed because it is too large Load Diff

382
doc/src/faq.rst Normal file
View File

@ -0,0 +1,382 @@
Frequently Asked Questions
==========================
.. sectionauthor:: Daniele Varrazzo <daniele.varrazzo@gmail.com>
Here are a few gotchas you may encounter using `psycopg2`. Feel free to
suggest new entries!
Meta
----
.. _faq-question:
.. cssclass:: faq
How do I ask a question?
- Have you first checked if your question is answered already in the
documentation?
- If your question is about installing psycopg, have you checked the
:ref:`install FAQ <faq-compile>` and the :ref:`install docs
<installation>`?
- Have you googled for your error message?
- If you haven't found an answer yet, please write to the `Mailing List`_.
- If you haven't found a bug, DO NOT write to the bug tracker to ask
questions. You will only get piro grumpy.
.. _mailing list: https://www.postgresql.org/list/psycopg/
.. _faq-transactions:
Problems with transactions handling
-----------------------------------
.. _faq-idle-in-transaction:
.. cssclass:: faq
Why does `!psycopg2` leave database sessions "idle in transaction"?
Psycopg normally starts a new transaction the first time a query is
executed, e.g. calling `cursor.execute()`, even if the command is a
:sql:`SELECT`. The transaction is not closed until an explicit
`~connection.commit()` or `~connection.rollback()`.
If you are writing a long-living program, you should probably make sure to
call one of the transaction closing methods before leaving the connection
unused for a long time (which may also be a few seconds, depending on the
concurrency level in your database). Alternatively you can use a
connection in `~connection.autocommit` mode to avoid a new transaction to
be started at the first command.
.. _faq-transaction-aborted:
.. cssclass:: faq
I receive the error *current transaction is aborted, commands ignored until end of transaction block* and can't do anything else!
There was a problem *in the previous* command to the database, which
resulted in an error. The database will not recover automatically from
this condition: you must run a `~connection.rollback()` before sending
new commands to the session (if this seems too harsh, remember that
PostgreSQL supports nested transactions using the |SAVEPOINT|_ command).
.. |SAVEPOINT| replace:: :sql:`SAVEPOINT`
.. _SAVEPOINT: https://www.postgresql.org/docs/current/static/sql-savepoint.html
.. _faq-transaction-aborted-multiprocess:
.. cssclass:: faq
Why do I get the error *current transaction is aborted, commands ignored until end of transaction block* when I use `!multiprocessing` (or any other forking system) and not when use `!threading`?
Psycopg's connections can't be shared across processes (but are thread
safe). If you are forking the Python process make sure to create a new
connection in each forked child. See :ref:`thread-safety` for further
informations.
.. _faq-types:
Problems with type conversions
------------------------------
.. _faq-cant-adapt:
.. cssclass:: faq
Why does `!cursor.execute()` raise the exception *can't adapt*?
Psycopg converts Python objects in a SQL string representation by looking
at the object class. The exception is raised when you are trying to pass
as query parameter an object for which there is no adapter registered for
its class. See :ref:`adapting-new-types` for informations.
.. _faq-number-required:
.. cssclass:: faq
I can't pass an integer or a float parameter to my query: it says *a number is required*, but *it is* a number!
In your query string, you always have to use ``%s`` placeholders,
even when passing a number. All Python objects are converted by Psycopg
in their SQL representation, so they get passed to the query as strings.
See :ref:`query-parameters`. ::
>>> cur.execute("INSERT INTO numbers VALUES (%d)", (42,)) # WRONG
>>> cur.execute("INSERT INTO numbers VALUES (%s)", (42,)) # correct
.. _faq-not-all-arguments-converted:
.. cssclass:: faq
I try to execute a query but it fails with the error *not all arguments converted during string formatting* (or *object does not support indexing*). Why?
Psycopg always require positional arguments to be passed as a sequence, even
when the query takes a single parameter. And remember that to make a
single item tuple in Python you need a comma! See :ref:`query-parameters`.
::
>>> cur.execute("INSERT INTO foo VALUES (%s)", "bar") # WRONG
>>> cur.execute("INSERT INTO foo VALUES (%s)", ("bar")) # WRONG
>>> cur.execute("INSERT INTO foo VALUES (%s)", ("bar",)) # correct
>>> cur.execute("INSERT INTO foo VALUES (%s)", ["bar"]) # correct
.. _faq-unicode:
.. cssclass:: faq
My database is Unicode, but I receive all the strings as UTF-8 `!str`. Can I receive `!unicode` objects instead?
The following magic formula will do the trick::
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
psycopg2.extensions.register_type(psycopg2.extensions.UNICODEARRAY)
See :ref:`unicode-handling` for the gory details.
.. _faq-bytes:
.. cssclass:: faq
My database is in mixed encoding. My program was working on Python 2 but Python 3 fails decoding the strings. How do I avoid decoding?
From psycopg 2.8 you can use the following adapters to always return bytes
from strings::
psycopg2.extensions.register_type(psycopg2.extensions.BYTES)
psycopg2.extensions.register_type(psycopg2.extensions.BYTESARRAY)
See :ref:`unicode-handling` for an example.
.. _faq-float:
.. cssclass:: faq
Psycopg converts :sql:`decimal`\/\ :sql:`numeric` database types into Python `!Decimal` objects. Can I have `!float` instead?
You can register a customized adapter for PostgreSQL decimal type::
DEC2FLOAT = psycopg2.extensions.new_type(
psycopg2.extensions.DECIMAL.values,
'DEC2FLOAT',
lambda value, curs: float(value) if value is not None else None)
psycopg2.extensions.register_type(DEC2FLOAT)
See :ref:`type-casting-from-sql-to-python` to read the relevant
documentation. If you find `!psycopg2.extensions.DECIMAL` not available, use
`!psycopg2._psycopg.DECIMAL` instead.
.. _faq-json-adapt:
.. cssclass:: faq
Psycopg automatically converts PostgreSQL :sql:`json` data into Python objects. How can I receive strings instead?
The easiest way to avoid JSON parsing is to register a no-op function with
`~psycopg2.extras.register_default_json()`::
psycopg2.extras.register_default_json(loads=lambda x: x)
See :ref:`adapt-json` for further details.
.. _faq-jsonb-adapt:
.. cssclass:: faq
Psycopg converts :sql:`json` values into Python objects but :sql:`jsonb` values are returned as strings. Can :sql:`jsonb` be converted automatically?
Automatic conversion of :sql:`jsonb` values is supported from Psycopg
release 2.5.4. For previous versions you can register the :sql:`json`
typecaster on the :sql:`jsonb` oids (which are known and not supposed to
change in future PostgreSQL versions)::
psycopg2.extras.register_json(oid=3802, array_oid=3807, globally=True)
See :ref:`adapt-json` for further details.
.. _faq-identifier:
.. cssclass:: faq
How can I pass field/table names to a query?
The arguments in the `~cursor.execute()` methods can only represent data
to pass to the query: they cannot represent a table or field name::
# This doesn't work
cur.execute("insert into %s values (%s)", ["my_table", 42])
If you want to build a query dynamically you can use the objects exposed
by the `psycopg2.sql` module::
cur.execute(
sql.SQL("insert into %s values (%%s)") % [sql.Identifier("my_table")],
[42])
.. _faq-bytea-9.0:
.. cssclass:: faq
Transferring binary data from PostgreSQL 9.0 doesn't work.
PostgreSQL 9.0 uses by default `the "hex" format`__ to transfer
:sql:`bytea` data: the format can't be parsed by the libpq 8.4 and
earlier. The problem is solved in Psycopg 2.4.1, that uses its own parser
for the :sql:`bytea` format. For previous Psycopg releases, three options
to solve the problem are:
- set the bytea_output__ parameter to ``escape`` in the server;
- execute the database command ``SET bytea_output TO escape;`` in the
session before reading binary data;
- upgrade the libpq library on the client to at least 9.0.
.. __: https://www.postgresql.org/docs/current/static/datatype-binary.html
.. __: https://www.postgresql.org/docs/current/static/runtime-config-client.html#GUC-BYTEA-OUTPUT
.. _faq-array:
.. cssclass:: faq
Arrays of *TYPE* are not casted to list.
Arrays are only casted to list when their oid is known, and an array
typecaster is registered for them. If there is no typecaster, the array is
returned unparsed from PostgreSQL (e.g. ``{a,b,c}``). It is easy to create
a generic arrays typecaster, returning a list of array: an example is
provided in the `~psycopg2.extensions.new_array_type()` documentation.
.. _faq-best-practices:
Best practices
--------------
.. _faq-reuse-cursors:
.. cssclass:: faq
When should I save and re-use a cursor as opposed to creating a new one as needed?
Cursors are lightweight objects and creating lots of them should not pose
any kind of problem. But note that cursors used to fetch result sets will
cache the data and use memory in proportion to the result set size. Our
suggestion is to almost always create a new cursor and dispose old ones as
soon as the data is not required anymore (call `~cursor.close()` on
them.) The only exception are tight loops where one usually use the same
cursor for a whole bunch of :sql:`INSERT`\s or :sql:`UPDATE`\s.
.. _faq-reuse-connections:
.. cssclass:: faq
When should I save and re-use a connection as opposed to creating a new one as needed?
Creating a connection can be slow (think of SSL over TCP) so the best
practice is to create a single connection and keep it open as long as
required. It is also good practice to rollback or commit frequently (even
after a single :sql:`SELECT` statement) to make sure the backend is never
left "idle in transaction". See also `psycopg2.pool` for lightweight
connection pooling.
.. _faq-named-cursors:
.. cssclass:: faq
What are the advantages or disadvantages of using named cursors?
The only disadvantages is that they use up resources on the server and
that there is a little overhead because at least two queries (one to
create the cursor and one to fetch the initial result set) are issued to
the backend. The advantage is that data is fetched one chunk at a time:
using small `~cursor.fetchmany()` values it is possible to use very
little memory on the client and to skip or discard parts of the result set.
.. _faq-interrupt-query:
.. cssclass:: faq
How do I interrupt a long-running query in an interactive shell?
Normally the interactive shell becomes unresponsive to :kbd:`Ctrl-C` when
running a query. Using a connection in green mode allows Python to
receive and handle the interrupt, although it may leave the connection
broken, if the async callback doesn't handle the `!KeyboardInterrupt`
correctly.
Starting from psycopg 2.6.2, the `~psycopg2.extras.wait_select` callback
can handle a :kbd:`Ctrl-C` correctly. For previous versions, you can use
`this implementation`__.
.. __: https://www.psycopg.org/articles/2014/07/20/cancelling-postgresql-statements-python/
.. code-block:: pycon
>>> psycopg2.extensions.set_wait_callback(psycopg2.extras.wait_select)
>>> cnn = psycopg2.connect('')
>>> cur = cnn.cursor()
>>> cur.execute("select pg_sleep(10)")
^C
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
QueryCanceledError: canceling statement due to user request
>>> cnn.rollback()
>>> # You can use the connection and cursor again from here
.. _faq-compile:
Problems compiling and installing psycopg2
------------------------------------------
.. _faq-wheels:
.. cssclass:: faq
Psycopg 2.8 fails to install, Psycopg 2.7 was working fine.
With Psycopg 2.7 you were installing binary packages, but they have proven
unreliable so now you have to install them explicitly using the
``psycopg2-binary`` package. See :ref:`binary-packages` for all the
details.
.. _faq-python-h:
.. cssclass:: faq
I can't compile `!psycopg2`: the compiler says *error: Python.h: No such file or directory*. What am I missing?
You need to install a Python development package: it is usually called
``python-dev`` or ``python3-dev`` according to your Python version.
.. _faq-libpq-fe-h:
.. cssclass:: faq
I can't compile `!psycopg2`: the compiler says *error: libpq-fe.h: No such file or directory*. What am I missing?
You need to install the development version of the libpq: the package is
usually called ``libpq-dev``.
.. _faq-lo_truncate:
.. cssclass:: faq
`!psycopg2` raises `!ImportError` with message *_psycopg.so: undefined symbol: lo_truncate* when imported.
This means that Psycopg was compiled with |lo_truncate|_ support (*i.e.*
the libpq used at compile time was version >= 8.3) but at runtime an older
libpq dynamic library is found.
Fast-forward several years, if the message reports *undefined symbol:
lo_truncate64* it means that Psycopg was built with large objects 64 bits
API support (*i.e.* the libpq used at compile time was at least 9.3) but
at runtime an older libpq dynamic library is found.
You can use:
.. code-block:: shell
$ ldd /path/to/packages/psycopg2/_psycopg.so | grep libpq
to find what is the libpq dynamic library used at runtime.
You can avoid the problem by using the same version of the
:program:`pg_config` at install time and the libpq at runtime.
.. |lo_truncate| replace:: `!lo_truncate()`
.. _lo_truncate: https://www.postgresql.org/docs/current/static/lo-interfaces.html#LO-TRUNCATE
.. _faq-import-mod_wsgi:
.. cssclass:: faq
Psycopg raises *ImportError: cannot import name tz* on import in mod_wsgi / ASP, but it works fine otherwise.
If `!psycopg2` is installed in an egg_ (e.g. because installed by
:program:`easy_install`), the user running the program may be unable to
write in the `eggs cache`__. Set the env variable
:envvar:`PYTHON_EGG_CACHE` to a writable directory. With modwsgi you can
use the WSGIPythonEggs__ directive.
.. _egg: http://peak.telecommunity.com/DevCenter/PythonEggs
.. __: https://stackoverflow.com/questions/2192323/what-is-the-python-egg-cache-python-egg-cache
.. __: https://modwsgi.readthedocs.io/en/develop/configuration-directives/WSGIPythonEggs.html

70
doc/src/index.rst Normal file
View File

@ -0,0 +1,70 @@
=================================================
Psycopg -- PostgreSQL database adapter for Python
=================================================
.. sectionauthor:: Daniele Varrazzo <daniele.varrazzo@gmail.com>
Psycopg_ is the most popular PostgreSQL_ database adapter for the Python_
programming language. Its main features are the complete implementation of
the Python |DBAPI|_ specification and the thread safety (several threads can
share the same connection). It was designed for heavily multi-threaded
applications that create and destroy lots of cursors and make a large number
of concurrent :sql:`INSERT`\s or :sql:`UPDATE`\s.
Psycopg 2 is mostly implemented in C as a libpq_ wrapper, resulting in being
both efficient and secure. It features client-side and :ref:`server-side
<server-side-cursors>` cursors, :ref:`asynchronous communication
<async-support>` and :ref:`notifications <async-notify>`, :ref:`COPY <copy>`
support. Many Python types are supported out-of-the-box and :ref:`adapted to
matching PostgreSQL data types <python-types-adaptation>`; adaptation can be
extended and customized thanks to a flexible :ref:`objects adaptation system
<adapting-new-types>`.
Psycopg 2 is both Unicode and Python 3 friendly.
.. _Psycopg: https://psycopg.org/
.. _PostgreSQL: https://www.postgresql.org/
.. _Python: https://www.python.org/
.. _libpq: https://www.postgresql.org/docs/current/static/libpq.html
.. rubric:: Contents
.. toctree::
:maxdepth: 2
install
usage
module
connection
cursor
advanced
extensions
extras
errors
sql
tz
pool
errorcodes
faq
news
license
.. ifconfig:: builder != 'text'
.. rubric:: Indices and tables
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
.. ifconfig:: todo_include_todos
.. note::
**To Do items in the documentation**
.. todolist::

364
doc/src/install.rst Normal file
View File

@ -0,0 +1,364 @@
.. _installation:
Installation
============
.. sectionauthor:: Daniele Varrazzo <daniele.varrazzo@gmail.com>
Psycopg is a PostgreSQL_ adapter for the Python_ programming language. It is a
wrapper for the libpq_, the official PostgreSQL client library.
.. _PostgreSQL: https://www.postgresql.org/
.. _Python: https://www.python.org/
.. index::
single: Install; from PyPI
single: Install; wheel
single: Wheel
.. _binary-packages:
Quick Install
-------------
For most operating systems, the quickest way to install Psycopg is using the
wheel_ package available on PyPI_:
.. code-block:: console
$ pip install psycopg2-binary
This will install a pre-compiled binary version of the module which does not
require the build or runtime prerequisites described below. Make sure to use
an up-to-date version of :program:`pip` (you can upgrade it using something
like ``pip install -U pip``).
You may then import the ``psycopg2`` package, as usual:
.. code-block:: python
import psycopg2
# Connect to your postgres DB
conn = psycopg2.connect("dbname=test user=postgres")
# Open a cursor to perform database operations
cur = conn.cursor()
# Execute a query
cur.execute("SELECT * FROM my_data")
# Retrieve query results
records = cur.fetchall()
.. _PyPI: https://pypi.org/project/psycopg2-binary/
.. _wheel: https://pythonwheels.com/
psycopg vs psycopg-binary
^^^^^^^^^^^^^^^^^^^^^^^^^
The ``psycopg2-binary`` package is meant for beginners to start playing
with Python and PostgreSQL without the need to meet the build
requirements.
If you are the maintainer of a published package depending on `!psycopg2`
you shouldn't use ``psycopg2-binary`` as a module dependency. **For
production use you are advised to use the source distribution.**
The binary packages come with their own versions of a few C libraries,
among which ``libpq`` and ``libssl``, which will be used regardless of other
libraries available on the client: upgrading the system libraries will not
upgrade the libraries used by `!psycopg2`. Please build `!psycopg2` from
source if you want to maintain binary upgradeability.
.. warning::
The `!psycopg2` wheel package comes packaged, among the others, with its
own ``libssl`` binary. This may create conflicts with other extension
modules binding with ``libssl`` as well, for instance with the Python
`ssl` module: in some cases, under concurrency, the interaction between
the two libraries may result in a segfault. In case of doubts you are
advised to use a package built from source.
.. index::
single: Install; disable wheel
single: Wheel; disable
.. _disable-wheel:
Change in binary packages between Psycopg 2.7 and 2.8
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
In version 2.7.x, :command:`pip install psycopg2` would have tried to install
automatically the binary package of Psycopg. Because of concurrency problems
binary packages have displayed, ``psycopg2-binary`` has become a separate
package, and from 2.8 it has become the only way to install the binary
package.
If you are using Psycopg 2.7 and you want to disable the use of wheel binary
packages, relying on the system libraries available on your client, you
can use the :command:`pip` |--no-binary option|__, e.g.:
.. code-block:: console
$ pip install --no-binary :all: psycopg2
.. |--no-binary option| replace:: ``--no-binary`` option
.. __: https://pip.pypa.io/en/stable/reference/pip_install/#install-no-binary
which can be specified in your :file:`requirements.txt` files too, e.g. use:
.. code-block:: none
psycopg2>=2.7,<2.8 --no-binary psycopg2
to use the last bugfix release of the `!psycopg2` 2.7 package, specifying to
always compile it from source. Of course in this case you will have to meet
the :ref:`build prerequisites <build-prerequisites>`.
.. index::
single: Prerequisites
Prerequisites
-------------
The current `!psycopg2` implementation supports:
..
NOTE: keep consistent with setup.py and the /features/ page.
- Python versions from 3.8 to 3.13
- PostgreSQL server versions from 7.4 to 17
- PostgreSQL client library version from 9.1
.. note::
Not all the psycopg2 versions support all the supported Python versions.
Please see the :ref:`release notes <news>` to verify when the support for
a new Python version was added and when the support for an old Python
version was removed.
.. _build-prerequisites:
Build prerequisites
^^^^^^^^^^^^^^^^^^^
The build prerequisites are to be met in order to install Psycopg from source
code, from a source distribution package, GitHub_ or from PyPI.
.. _GitHub: https://github.com/psycopg/psycopg2
Psycopg is a C wrapper around the libpq_ PostgreSQL client library. To install
it from sources you will need:
- A C compiler.
- The Python header files. They are usually installed in a package such as
**python-dev** or **python3-dev**. A message such as *error: Python.h: No
such file or directory* is an indication that the Python headers are
missing.
- The libpq header files. They are usually installed in a package such as
**libpq-dev**. If you get an *error: libpq-fe.h: No such file or directory*
you are missing them.
- The :program:`pg_config` program: it is usually installed by the
**libpq-dev** package but sometimes it is not in a :envvar:`PATH` directory.
Having it in the :envvar:`PATH` greatly streamlines the installation, so try
running ``pg_config --version``: if it returns an error or an unexpected
version number then locate the directory containing the :program:`pg_config`
shipped with the right libpq version (usually
``/usr/lib/postgresql/X.Y/bin/``) and add it to the :envvar:`PATH`:
.. code-block:: console
$ export PATH=/usr/lib/postgresql/X.Y/bin/:$PATH
You only need :program:`pg_config` to compile `!psycopg2`, not for its
regular usage.
Once everything is in place it's just a matter of running the standard:
.. code-block:: console
$ pip install psycopg2
or, from the directory containing the source code:
.. code-block:: console
$ python setup.py build
$ python setup.py install
Runtime requirements
^^^^^^^^^^^^^^^^^^^^
Unless you compile `!psycopg2` as a static library, or you install it from a
self-contained wheel package, it will need the libpq_ library at runtime
(usually distributed in a ``libpq.so`` or ``libpq.dll`` file). `!psycopg2`
relies on the host OS to find the library if the library is installed in a
standard location there is usually no problem; if the library is in a
non-standard location you will have to tell Psycopg how to find it,
which is OS-dependent (for instance setting a suitable
:envvar:`LD_LIBRARY_PATH` on Linux).
.. note::
The libpq header files used to compile `!psycopg2` should match the
version of the library linked at runtime. If you get errors about missing
or mismatching libraries when importing `!psycopg2` check (e.g. using
:program:`ldd`) if the module ``psycopg2/_psycopg.so`` is linked to the
right ``libpq.so``.
.. note::
Whatever version of libpq `!psycopg2` is compiled with, it will be
possible to connect to PostgreSQL servers of any supported version: just
install the most recent libpq version or the most practical, without
trying to match it to the version of the PostgreSQL server you will have
to connect to.
.. index::
single: setup.py
single: setup.cfg
Non-standard builds
-------------------
If you have less standard requirements such as:
- creating a :ref:`debug build <debug-build>`,
- using :program:`pg_config` not in the :envvar:`PATH`,
then take a look at the ``setup.cfg`` file.
Some of the options available in ``setup.cfg`` are also available as command
line arguments of the ``build_ext`` sub-command. For instance you can specify
an alternate :program:`pg_config` location using:
.. code-block:: console
$ python setup.py build_ext --pg-config /path/to/pg_config build
Use ``python setup.py build_ext --help`` to get a list of the options
supported.
.. index::
single: debug
single: PSYCOPG_DEBUG
.. _debug-build:
Creating a debug build
^^^^^^^^^^^^^^^^^^^^^^
In case of problems, Psycopg can be configured to emit detailed debug
messages, which can be very useful for diagnostics and to report a bug. In
order to create a debug package:
- `Download`__ and unpack the Psycopg *source package* (the ``.tar.gz``
package).
- Edit the ``setup.cfg`` file adding the ``PSYCOPG_DEBUG`` flag to the
``define`` option.
- :ref:`Compile and install <build-prerequisites>` the package.
- Set the :envvar:`PSYCOPG_DEBUG` environment variable:
.. code-block:: console
$ export PSYCOPG_DEBUG=1
- Run your program (making sure that the `!psycopg2` package imported is the
one you just compiled and not e.g. the system one): you will have a copious
stream of informations printed on stderr.
.. __: https://pypi.org/project/psycopg2/#files
Non-standard Python Implementation
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The `psycopg2` package is the current mature implementation of the adapter: it
is a C extension and as such it is only compatible with CPython_. If you want
to use Psycopg on a different Python implementation (PyPy, Jython, IronPython)
there is a couple of alternative:
- a `Ctypes port`__, but it is not as mature as the C implementation yet
and it is not as feature-complete;
- a `CFFI port`__ which is currently more used and reported more efficient on
PyPy, but please be careful of its version numbers because they are not
aligned to the official psycopg2 ones and some features may differ.
.. _PostgreSQL: https://www.postgresql.org/
.. _Python: https://www.python.org/
.. _libpq: https://www.postgresql.org/docs/current/static/libpq.html
.. _CPython: https://en.wikipedia.org/wiki/CPython
.. _Ctypes: https://docs.python.org/library/ctypes.html
.. __: https://github.com/mvantellingen/psycopg2-ctypes
.. __: https://github.com/chtd/psycopg2cffi
.. index::
single: tests
.. _test-suite:
Running the test suite
----------------------
Once `!psycopg2` is installed you can run the test suite to verify it is
working correctly. From the source directory, you can run:
.. code-block:: console
$ python -c "import tests; tests.unittest.main(defaultTest='tests.test_suite')" --verbose
The tests run against a database called ``psycopg2_test`` on UNIX socket and
the standard port. You can configure a different database to run the test by
setting the environment variables:
- :envvar:`PSYCOPG2_TESTDB`
- :envvar:`PSYCOPG2_TESTDB_HOST`
- :envvar:`PSYCOPG2_TESTDB_PORT`
- :envvar:`PSYCOPG2_TESTDB_USER`
The database should already exist before running the tests.
.. _other-problems:
If you still have problems
--------------------------
Try the following. *In order:*
- Read again the :ref:`build-prerequisites`.
- Read the :ref:`FAQ <faq-compile>`.
- Google for `!psycopg2` *your error message*. Especially useful the week
after the release of a new OS X version.
- Write to the `Mailing List`_.
- If you think that you have discovered a bug, test failure or missing feature
please raise a ticket in the `bug tracker`_.
- Complain on your blog or on Twitter that `!psycopg2` is the worst package
ever and about the quality time you have wasted figuring out the correct
:envvar:`ARCHFLAGS`. Especially useful from the Starbucks near you.
.. _mailing list: https://www.postgresql.org/list/psycopg/
.. _bug tracker: https://github.com/psycopg/psycopg2/issues

7
doc/src/license.rst Normal file
View File

@ -0,0 +1,7 @@
.. index::
single: License
License
=======
.. include:: ../../LICENSE

388
doc/src/module.rst Normal file
View File

@ -0,0 +1,388 @@
The `psycopg2` module content
==================================
.. sectionauthor:: Daniele Varrazzo <daniele.varrazzo@gmail.com>
.. module:: psycopg2
The module interface respects the standard defined in the |DBAPI|_.
.. index::
single: Connection string
double: Connection; Parameters
single: Username; Connection
single: Password; Connection
single: Host; Connection
single: Port; Connection
single: DSN (Database Source Name)
.. function::
connect(dsn=None, connection_factory=None, cursor_factory=None, async=False, \*\*kwargs)
Create a new database session and return a new `connection` object.
The connection parameters can be specified as a `libpq connection
string`__ using the *dsn* parameter::
conn = psycopg2.connect("dbname=test user=postgres password=secret")
or using a set of keyword arguments::
conn = psycopg2.connect(dbname="test", user="postgres", password="secret")
or using a mix of both: if the same parameter name is specified in both
sources, the *kwargs* value will have precedence over the *dsn* value.
Note that either the *dsn* or at least one connection-related keyword
argument is required.
The basic connection parameters are:
- `!dbname` -- the database name (`!database` is a deprecated alias)
- `!user` -- user name used to authenticate
- `!password` -- password used to authenticate
- `!host` -- database host address (defaults to UNIX socket if not provided)
- `!port` -- connection port number (defaults to 5432 if not provided)
Any other connection parameter supported by the client library/server can
be passed either in the connection string or as a keyword. The PostgreSQL
documentation contains the complete list of the `supported parameters`__.
Also note that the same parameters can be passed to the client library
using `environment variables`__.
.. __:
.. _connstring: https://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-CONNSTRING
.. __:
.. _connparams: https://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-PARAMKEYWORDS
.. __:
.. _connenvvars: https://www.postgresql.org/docs/current/static/libpq-envars.html
Using the *connection_factory* parameter a different class or
connections factory can be specified. It should be a callable object
taking a *dsn* string argument. See :ref:`subclassing-connection` for
details. If a *cursor_factory* is specified, the connection's
`~connection.cursor_factory` is set to it. If you only need customized
cursors you can use this parameter instead of subclassing a connection.
Using *async*\=\ `!True` an asynchronous connection will be created: see
:ref:`async-support` to know about advantages and limitations. *async_* is
a valid alias for the Python version where ``async`` is a keyword.
.. versionchanged:: 2.4.3
any keyword argument is passed to the connection. Previously only the
basic parameters (plus `!sslmode`) were supported as keywords.
.. versionchanged:: 2.5
added the *cursor_factory* parameter.
.. versionchanged:: 2.7
both *dsn* and keyword arguments can be specified.
.. versionchanged:: 2.7
added *async_* alias.
.. seealso::
- `~psycopg2.extensions.parse_dsn`
- libpq `connection string syntax`__
- libpq supported `connection parameters`__
- libpq supported `environment variables`__
.. __: connstring_
.. __: connparams_
.. __: connenvvars_
.. extension::
The non-connection-related keyword parameters are Psycopg extensions
to the |DBAPI|_.
.. data:: apilevel
String constant stating the supported DB API level. For `psycopg2` is
``2.0``.
.. data:: threadsafety
Integer constant stating the level of thread safety the interface
supports. For `psycopg2` is ``2``, i.e. threads can share the module
and the connection. See :ref:`thread-safety` for details.
.. data:: paramstyle
String constant stating the type of parameter marker formatting expected
by the interface. For `psycopg2` is ``pyformat``. See also
:ref:`query-parameters`.
.. data:: __libpq_version__
Integer constant reporting the version of the ``libpq`` library this
``psycopg2`` module was compiled with (in the same format of
`~psycopg2.extensions.ConnectionInfo.server_version`). If this value is
greater or equal than ``90100`` then you may query the version of the
actually loaded library using the `~psycopg2.extensions.libpq_version()`
function.
.. index::
single: Exceptions; DB API
.. _dbapi-exceptions:
Exceptions
----------
In compliance with the |DBAPI|_, the module makes informations about errors
available through the following exceptions:
.. exception:: Warning
Exception raised for important warnings like data truncations while
inserting, etc. It is a subclass of the Python `StandardError`
(`Exception` on Python 3).
.. exception:: Error
Exception that is the base class of all other error exceptions. You can
use this to catch all errors with one single `!except` statement. Warnings
are not considered errors and thus not use this class as base. It
is a subclass of the Python `StandardError` (`Exception` on Python 3).
.. attribute:: pgerror
String representing the error message returned by the backend,
`!None` if not available.
.. attribute:: pgcode
String representing the error code returned by the backend, `!None`
if not available. The `~psycopg2.errorcodes` module contains
symbolic constants representing PostgreSQL error codes.
.. doctest::
:options: +NORMALIZE_WHITESPACE
>>> try:
... cur.execute("SELECT * FROM barf")
... except psycopg2.Error as e:
... pass
>>> e.pgcode
'42P01'
>>> print(e.pgerror)
ERROR: relation "barf" does not exist
LINE 1: SELECT * FROM barf
^
.. attribute:: cursor
The cursor the exception was raised from; `None` if not applicable.
.. attribute:: diag
A `~psycopg2.extensions.Diagnostics` object containing further
information about the error. ::
>>> try:
... cur.execute("SELECT * FROM barf")
... except psycopg2.Error as e:
... pass
>>> e.diag.severity
'ERROR'
>>> e.diag.message_primary
'relation "barf" does not exist'
.. versionadded:: 2.5
.. extension::
The `~Error.pgerror`, `~Error.pgcode`, `~Error.cursor`, and
`~Error.diag` attributes are Psycopg extensions.
.. exception:: InterfaceError
Exception raised for errors that are related to the database interface
rather than the database itself. It is a subclass of `Error`.
.. exception:: DatabaseError
Exception raised for errors that are related to the database. It is a
subclass of `Error`.
.. exception:: DataError
Exception raised for errors that are due to problems with the processed
data like division by zero, numeric value out of range, etc. It is a
subclass of `DatabaseError`.
.. exception:: OperationalError
Exception raised for errors that are related to the database's operation
and not necessarily under the control of the programmer, e.g. an
unexpected disconnect occurs, the data source name is not found, a
transaction could not be processed, a memory allocation error occurred
during processing, etc. It is a subclass of `DatabaseError`.
.. exception:: IntegrityError
Exception raised when the relational integrity of the database is
affected, e.g. a foreign key check fails. It is a subclass of
`DatabaseError`.
.. exception:: InternalError
Exception raised when the database encounters an internal error, e.g. the
cursor is not valid anymore, the transaction is out of sync, etc. It is a
subclass of `DatabaseError`.
.. exception:: ProgrammingError
Exception raised for programming errors, e.g. table not found or already
exists, syntax error in the SQL statement, wrong number of parameters
specified, etc. It is a subclass of `DatabaseError`.
.. exception:: NotSupportedError
Exception raised in case a method or database API was used which is not
supported by the database, e.g. requesting a `!rollback()` on a
connection that does not support transaction or has transactions turned
off. It is a subclass of `DatabaseError`.
.. extension::
Psycopg actually raises a different exception for each :sql:`SQLSTATE`
error returned by the database: the classes are available in the
`psycopg2.errors` module. Every exception class is a subclass of one of
the exception classes defined here though, so they don't need to be
trapped specifically: trapping `!Error` or `!DatabaseError` is usually
what needed to write a generic error handler; trapping a specific error
such as `!NotNullViolation` can be useful to write specific exception
handlers.
This is the exception inheritance layout:
.. parsed-literal::
`!StandardError`
\|__ `Warning`
\|__ `Error`
\|__ `InterfaceError`
\|__ `DatabaseError`
\|__ `DataError`
\|__ `OperationalError`
\|__ `IntegrityError`
\|__ `InternalError`
\|__ `ProgrammingError`
\|__ `NotSupportedError`
.. _type-objects-and-constructors:
Type Objects and Constructors
-----------------------------
.. note::
This section is mostly copied verbatim from the |DBAPI|_
specification. While these objects are exposed in compliance to the
DB API, Psycopg offers very accurate tools to convert data between Python
and PostgreSQL formats. See :ref:`adapting-new-types` and
:ref:`type-casting-from-sql-to-python`
Many databases need to have the input in a particular format for
binding to an operation's input parameters. For example, if an
input is destined for a DATE column, then it must be bound to the
database in a particular string format. Similar problems exist
for "Row ID" columns or large binary items (e.g. blobs or RAW
columns). This presents problems for Python since the parameters
to the .execute*() method are untyped. When the database module
sees a Python string object, it doesn't know if it should be bound
as a simple CHAR column, as a raw BINARY item, or as a DATE.
To overcome this problem, a module must provide the constructors
defined below to create objects that can hold special values.
When passed to the cursor methods, the module can then detect the
proper type of the input parameter and bind it accordingly.
A Cursor Object's description attribute returns information about
each of the result columns of a query. The type_code must compare
equal to one of Type Objects defined below. Type Objects may be
equal to more than one type code (e.g. DATETIME could be equal to
the type codes for date, time and timestamp columns; see the
Implementation Hints below for details).
The module exports the following constructors and singletons:
.. function:: Date(year,month,day)
This function constructs an object holding a date value.
.. function:: Time(hour,minute,second)
This function constructs an object holding a time value.
.. function:: Timestamp(year,month,day,hour,minute,second)
This function constructs an object holding a time stamp value.
.. function:: DateFromTicks(ticks)
This function constructs an object holding a date value from the given
ticks value (number of seconds since the epoch; see the documentation of
the standard Python time module for details).
.. function:: TimeFromTicks(ticks)
This function constructs an object holding a time value from the given
ticks value (number of seconds since the epoch; see the documentation of
the standard Python time module for details).
.. function:: TimestampFromTicks(ticks)
This function constructs an object holding a time stamp value from the
given ticks value (number of seconds since the epoch; see the
documentation of the standard Python time module for details).
.. function:: Binary(string)
This function constructs an object capable of holding a binary (long)
string value.
.. note::
All the adapters returned by the module level factories (`!Binary`,
`!Date`, `!Time`, `!Timestamp` and the `!*FromTicks` variants) expose the
wrapped object (a regular Python object such as `!datetime`) in an
`!adapted` attribute.
.. data:: STRING
This type object is used to describe columns in a database that are
string-based (e.g. CHAR).
.. data:: BINARY
This type object is used to describe (long) binary columns in a database
(e.g. LONG, RAW, BLOBs).
.. data:: NUMBER
This type object is used to describe numeric columns in a database.
.. data:: DATETIME
This type object is used to describe date/time columns in a database.
.. data:: ROWID
This type object is used to describe the "Row ID" column in a database.
.. testcode::
:hide:
conn.rollback()

10
doc/src/news.rst Normal file
View File

@ -0,0 +1,10 @@
.. index::
single: Release notes
single: News
.. _news:
Release notes
=============
.. include:: ../../NEWS

60
doc/src/pool.rst Normal file
View File

@ -0,0 +1,60 @@
`psycopg2.pool` -- Connections pooling
======================================
.. sectionauthor:: Daniele Varrazzo <daniele.varrazzo@gmail.com>
.. index::
pair: Connection; Pooling
.. module:: psycopg2.pool
Creating new PostgreSQL connections can be an expensive operation. This
module offers a few pure Python classes implementing simple connection pooling
directly in the client application.
.. class:: AbstractConnectionPool(minconn, maxconn, \*args, \*\*kwargs)
Base class implementing generic key-based pooling code.
New *minconn* connections are created automatically. The pool will support
a maximum of about *maxconn* connections. *\*args* and *\*\*kwargs* are
passed to the `~psycopg2.connect()` function.
The following methods are expected to be implemented by subclasses:
.. method:: getconn(key=None)
Get a free connection from the pool.
The *key* parameter is optional: if used, the connection will be
associated to the key and calling `!getconn()` with the same key again
will return the same connection.
.. method:: putconn(conn, key=None, close=False)
Put away a connection.
If *close* is `!True`, discard the connection from the pool.
*key* should be used consistently with `getconn()`.
.. method:: closeall
Close all the connections handled by the pool.
Note that all the connections are closed, including ones
eventually in use by the application.
The following classes are `AbstractConnectionPool` subclasses ready to
be used.
.. autoclass:: SimpleConnectionPool
.. note:: This pool class is useful only for single-threaded applications.
.. index:: Multithread; Connection pooling
.. autoclass:: ThreadedConnectionPool
.. note:: This pool class can be safely used in multi-threaded applications.

147
doc/src/sql.rst Normal file
View File

@ -0,0 +1,147 @@
`psycopg2.sql` -- SQL string composition
========================================
.. sectionauthor:: Daniele Varrazzo <daniele.varrazzo@gmail.com>
.. module:: psycopg2.sql
.. versionadded:: 2.7
The module contains objects and functions useful to generate SQL dynamically,
in a convenient and safe way. SQL identifiers (e.g. names of tables and
fields) cannot be passed to the `~cursor.execute()` method like query
arguments::
# This will not work
table_name = 'my_table'
cur.execute("insert into %s values (%s, %s)", [table_name, 10, 20])
The SQL query should be composed before the arguments are merged, for
instance::
# This works, but it is not optimal
table_name = 'my_table'
cur.execute(
"insert into %s values (%%s, %%s)" % table_name,
[10, 20])
This sort of works, but it is an accident waiting to happen: the table name
may be an invalid SQL literal and need quoting; even more serious is the
security problem in case the table name comes from an untrusted source. The
name should be escaped using `~psycopg2.extensions.quote_ident()`::
# This works, but it is not optimal
table_name = 'my_table'
cur.execute(
"insert into %s values (%%s, %%s)" % ext.quote_ident(table_name, cur),
[10, 20])
This is now safe, but it somewhat ad-hoc. In case, for some reason, it is
necessary to include a value in the query string (as opposite as in a value)
the merging rule is still different (`~psycopg2.extensions.adapt()` should be
used...). It is also still relatively dangerous: if `!quote_ident()` is
forgotten somewhere, the program will usually work, but will eventually crash
in the presence of a table or field name with containing characters to escape,
or will present a potentially exploitable weakness.
The objects exposed by the `!psycopg2.sql` module allow generating SQL
statements on the fly, separating clearly the variable parts of the statement
from the query parameters::
from psycopg2 import sql
cur.execute(
sql.SQL("insert into {} values (%s, %s)")
.format(sql.Identifier('my_table')),
[10, 20])
Module usage
------------
Usually you should express the template of your query as an `SQL` instance
with `{}`\-style placeholders and use `~SQL.format()` to merge the variable
parts into them, all of which must be `Composable` subclasses. You can still
have `%s`\ -style placeholders in your query and pass values to
`~cursor.execute()`: such value placeholders will be untouched by
`!format()`::
query = sql.SQL("select {field} from {table} where {pkey} = %s").format(
field=sql.Identifier('my_name'),
table=sql.Identifier('some_table'),
pkey=sql.Identifier('id'))
The resulting object is meant to be passed directly to cursor methods such as
`~cursor.execute()`, `~cursor.executemany()`, `~cursor.copy_expert()`, but can
also be used to compose a query as a Python string, using the
`~Composable.as_string()` method::
cur.execute(query, (42,))
If part of your query is a variable sequence of arguments, such as a
comma-separated list of field names, you can use the `SQL.join()` method to
pass them to the query::
query = sql.SQL("select {fields} from {table}").format(
fields=sql.SQL(',').join([
sql.Identifier('field1'),
sql.Identifier('field2'),
sql.Identifier('field3'),
]),
table=sql.Identifier('some_table'))
`!sql` objects
--------------
The `!sql` objects are in the following inheritance hierarchy:
| `Composable`: the base class exposing the common interface
| ``|__`` `SQL`: a literal snippet of an SQL query
| ``|__`` `Identifier`: a PostgreSQL identifier or dot-separated sequence of identifiers
| ``|__`` `Literal`: a value hardcoded into a query
| ``|__`` `Placeholder`: a `%s`\ -style placeholder whose value will be added later e.g. by `~cursor.execute()`
| ``|__`` `Composed`: a sequence of `!Composable` instances.
.. autoclass:: Composable
.. automethod:: as_string
.. autoclass:: SQL
.. autoattribute:: string
.. automethod:: format
.. automethod:: join
.. autoclass:: Identifier
.. versionchanged:: 2.8
added support for multiple strings.
.. autoattribute:: strings
.. versionadded:: 2.8
previous verions only had a `!string` attribute. The attribute
still exists but is deprecate and will only work if the
`!Identifier` wraps a single string.
.. autoclass:: Literal
.. autoattribute:: wrapped
.. autoclass:: Placeholder
.. autoattribute:: name
.. autoclass:: Composed
.. autoattribute:: seq
.. automethod:: join

View File

@ -0,0 +1,50 @@
"""
extension
~~~~~~~~~
A directive to create a box warning that a certain bit of Psycopg is an
extension to the DBAPI 2.0.
:copyright: Copyright 2010 by Daniele Varrazzo.
"""
from docutils import nodes
from sphinx.locale import _
from docutils.parsers.rst import Directive
class extension_node(nodes.Admonition, nodes.Element): pass
class Extension(Directive):
"""
An extension entry, displayed as an admonition.
"""
has_content = True
required_arguments = 0
optional_arguments = 0
final_argument_whitespace = False
option_spec = {}
def run(self):
node = extension_node('\n'.join(self.content))
node += nodes.title(_('DB API extension'), _('DB API extension'))
self.state.nested_parse(self.content, self.content_offset, node)
node['classes'].append('dbapi-extension')
return [node]
def visit_extension_node(self, node):
self.visit_admonition(node)
def depart_extension_node(self, node):
self.depart_admonition(node)
def setup(app):
app.add_node(extension_node,
html=(visit_extension_node, depart_extension_node),
latex=(visit_extension_node, depart_extension_node),
text=(visit_extension_node, depart_extension_node))
app.add_directive('extension', Extension)

View File

@ -0,0 +1,19 @@
"""
sql role
~~~~~~~~
An interpreted text role to style SQL syntax in Psycopg documentation.
:copyright: Copyright 2010 by Daniele Varrazzo.
"""
from docutils import nodes, utils
from docutils.parsers.rst import roles
def sql_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
text = utils.unescape(text)
options['classes'] = ['sql']
return [nodes.literal(rawtext, text, **options)], []
def setup(app):
roles.register_local_role('sql', sql_role)

View File

@ -0,0 +1,57 @@
"""
ticket role
~~~~~~~~~~~
An interpreted text role to link docs to tickets issues.
:copyright: Copyright 2013 by Daniele Varrazzo.
"""
import re
from docutils import nodes, utils
from docutils.parsers.rst import roles
def ticket_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
cfg = inliner.document.settings.env.app.config
if cfg.ticket_url is None:
msg = inliner.reporter.warning(
"ticket not configured: please configure ticket_url in conf.py")
prb = inliner.problematic(rawtext, rawtext, msg)
return [prb], [msg]
rv = [nodes.Text(name + ' ')]
tokens = re.findall(r'(#?\d+)|([^\d#]+)', text)
for ticket, noise in tokens:
if ticket:
num = int(ticket.replace('#', ''))
# Push numbers of the oldel tickets ahead.
# We moved the tickets from a different tracker to GitHub and the
# latter already had a few ticket numbers taken (as merge
# requests).
remap_until = cfg.ticket_remap_until
remap_offset = cfg.ticket_remap_offset
if remap_until and remap_offset:
if num <= remap_until:
num += remap_offset
url = cfg.ticket_url % num
roles.set_classes(options)
node = nodes.reference(ticket, utils.unescape(ticket),
refuri=url, **options)
rv.append(node)
else:
assert noise
rv.append(nodes.Text(noise))
return rv, []
def setup(app):
app.add_config_value('ticket_url', None, 'env')
app.add_config_value('ticket_remap_until', None, 'env')
app.add_config_value('ticket_remap_offset', None, 'env')
app.add_role('ticket', ticket_role)
app.add_role('tickets', ticket_role)

View File

@ -0,0 +1,57 @@
#!/usr/bin/env python
"""Create the docs table of the sqlstate errors.
"""
import re
import sys
from collections import namedtuple
from psycopg2._psycopg import sqlstate_errors
def main():
sqlclasses = {}
clsfile = sys.argv[1]
with open(clsfile) as f:
for l in f:
m = re.match(r'/\* Class (..) - (.+) \*/', l)
if m is not None:
sqlclasses[m.group(1)] = m.group(2)
Line = namedtuple('Line', 'colstate colexc colbase sqlstate')
lines = [Line('SQLSTATE', 'Exception', 'Base exception', None)]
for k in sorted(sqlstate_errors):
exc = sqlstate_errors[k]
lines.append(Line(
f"``{k}``", f"`!{exc.__name__}`",
f"`!{get_base_exception(exc).__name__}`", k))
widths = [max(len(l[c]) for l in lines) for c in range(3)]
h = Line(*(['=' * w for w in widths] + [None]))
lines.insert(0, h)
lines.insert(2, h)
lines.append(h)
h1 = '-' * (sum(widths) + len(widths) - 1)
sqlclass = None
for l in lines:
cls = l.sqlstate[:2] if l.sqlstate else None
if cls and cls != sqlclass:
print(f"**Class {cls}**: {sqlclasses[cls]}")
print(h1)
sqlclass = cls
print("%-*s %-*s %-*s" % (
widths[0], l.colstate, widths[1], l.colexc, widths[2], l.colbase))
def get_base_exception(exc):
for cls in exc.__mro__:
if cls.__module__ == 'psycopg2':
return cls
if __name__ == '__main__':
sys.exit(main())

19
doc/src/tz.rst Normal file
View File

@ -0,0 +1,19 @@
`psycopg2.tz` -- ``tzinfo`` implementations for Psycopg 2
===============================================================
.. sectionauthor:: Daniele Varrazzo <daniele.varrazzo@gmail.com>
.. module:: psycopg2.tz
.. deprecated:: 2.9
The module will be dropped in psycopg 2.10. Use `datetime.timezone`
instead.
This module holds two different tzinfo implementations that can be used as the
`tzinfo` argument to `~datetime.datetime` constructors, directly passed to
Psycopg functions or used to set the `cursor.tzinfo_factory` attribute in
cursors.
.. autoclass:: psycopg2.tz.FixedOffsetTimezone
.. autoclass:: psycopg2.tz.LocalTimezone

1108
doc/src/usage.rst Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,89 +0,0 @@
# binary.py - working with binary data
#
# Copyright (C) 2001-2004 Federico Di Gregorio <fog@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
## put in DSN your DSN string
DSN = 'dbname=test'
## don't modify anything below tis line (except for experimenting)
import sys
import psycopg2
if len(sys.argv) > 1:
DSN = sys.argv[1]
print "Opening connection using dns:", DSN
conn = psycopg2.connect(DSN)
print "Encoding for this connection is", conn.encoding
curs = conn.cursor()
try:
curs.execute("CREATE TABLE test_binary (id int4, name text, img bytea)")
except:
conn.rollback()
curs.execute("DROP TABLE test_binary")
curs.execute("CREATE TABLE test_binary (id int4, name text, img bytea)")
conn.commit()
# first we try two inserts, one with an explicit Binary call and the other
# using a buffer on a file object.
data1 = {'id':1, 'name':'somehackers.jpg',
'img':psycopg2.Binary(open('somehackers.jpg').read())}
data2 = {'id':2, 'name':'whereareyou.jpg',
'img':buffer(open('whereareyou.jpg').read())}
curs.execute("""INSERT INTO test_binary
VALUES (%(id)s, %(name)s, %(img)s)""", data1)
curs.execute("""INSERT INTO test_binary
VALUES (%(id)s, %(name)s, %(img)s)""", data2)
# now we try to extract the images as simple text strings
print "Extracting the images as strings..."
curs.execute("SELECT * FROM test_binary")
for row in curs.fetchall():
name, ext = row[1].split('.')
new_name = name + '_S.' + ext
print " writing %s to %s ..." % (name+'.'+ext, new_name),
open(new_name, 'wb').write(row[2])
print "done"
print " python type of image data is", type(row[2])
# extract exactly the same data but using a binary cursor
print "Extracting the images using a binary cursor:"
curs.execute("""DECLARE zot CURSOR FOR
SELECT img, name FROM test_binary FOR READ ONLY""")
curs.execute("""FETCH ALL FROM zot""")
for row in curs.fetchall():
name, ext = row[1].split('.')
new_name = name + '_B.' + ext
print " writing %s to %s ..." % (name+'.'+ext, new_name),
open(new_name, 'wb').write(row[0])
print "done"
print " python type of image data is", type(row[0])
# this rollback is requires because we can't drop a table with a binary cusor
# declared and still open
conn.rollback()
curs.execute("DROP TABLE test_binary")
conn.commit()
print "\nNow try to load the new images, to check it worked!"

View File

@ -1,178 +0,0 @@
# copy_from.py -- example about copy_from
#
# Copyright (C) 2002 Tom Jenkins <tjenkins@devis.com>
# Copyright (C) 2005 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.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
## put in DSN your DSN string
DSN = 'dbname=test'
## don't modify anything below tis line (except for experimenting)
import sys
import os
import StringIO
import psycopg2
if len(sys.argv) > 1:
DSN = sys.argv[1]
print "Opening connection using dns:", DSN
conn = psycopg2.connect(DSN)
print "Encoding for this connection is", conn.encoding
curs = conn.cursor()
try:
curs.execute("CREATE TABLE test_copy (fld1 text, fld2 text, fld3 int4)")
except:
conn.rollback()
curs.execute("DROP TABLE test_copy")
curs.execute("CREATE TABLE test_copy (fld1 text, fld2 text, fld3 int4)")
conn.commit()
# copy_from with default arguments, from open file
io = open('copy_from.txt', 'wr')
data = ['Tom\tJenkins\t37\n',
'Madonna\t\N\t45\n',
'Federico\tDi Gregorio\t\N\n']
io.writelines(data)
io.close()
io = open('copy_from.txt', 'r')
curs.copy_from(io, 'test_copy')
print "1) Copy %d records from file object " % len(data) + \
"using defaults (sep: \\t and null = \\N)"
io.close()
curs.execute("SELECT * FROM test_copy")
rows = curs.fetchall()
print " Select returned %d rows" % len(rows)
for r in rows:
print " %s %s\t%s" % (r[0], r[1], r[2])
curs.execute("delete from test_copy")
conn.commit()
# copy_from using custom separator, from open file
io = open('copy_from.txt', 'wr')
data = ['Tom:Jenkins:37\n',
'Madonna:\N:45\n',
'Federico:Di Gregorio:\N\n']
io.writelines(data)
io.close()
io = open('copy_from.txt', 'r')
curs.copy_from(io, 'test_copy', ':')
print "2) Copy %d records from file object using sep = :" % len(data)
io.close()
curs.execute("SELECT * FROM test_copy")
rows = curs.fetchall()
print " Select returned %d rows" % len(rows)
for r in rows:
print " %s %s\t%s" % (r[0], r[1], r[2])
curs.execute("delete from test_copy")
conn.commit()
# copy_from using custom null identifier, from open file
io = open('copy_from.txt', 'wr')
data = ['Tom\tJenkins\t37\n',
'Madonna\tNULL\t45\n',
'Federico\tDi Gregorio\tNULL\n']
io.writelines(data)
io.close()
io = open('copy_from.txt', 'r')
curs.copy_from(io, 'test_copy', null='NULL')
print "3) Copy %d records from file object using null = NULL" % len(data)
io.close()
curs.execute("SELECT * FROM test_copy")
rows = curs.fetchall()
print " Select using cursor returned %d rows" % len(rows)
for r in rows:
print " %s %s\t%s" % (r[0], r[1], r[2])
curs.execute("delete from test_copy")
conn.commit()
# copy_from using custom separator and null identifier
io = open('copy_from.txt', 'wr')
data = ['Tom:Jenkins:37\n', 'Madonna:NULL:45\n', 'Federico:Di Gregorio:NULL\n']
io.writelines(data)
io.close()
io = open('copy_from.txt', 'r')
curs.copy_from(io, 'test_copy', ':', 'NULL')
print "4) Copy %d records from file object " % len(data) + \
"using sep = : and null = NULL"
io.close()
curs.execute("SELECT * FROM test_copy")
rows = curs.fetchall()
print " Select using cursor returned %d rows" % len(rows)
for r in rows:
print " %s %s\t%s" % (r[0], r[1], r[2])
curs.execute("delete from test_copy")
conn.commit()
# anything can be used as a file if it has .read() and .readline() methods
data = StringIO.StringIO()
data.write('\n'.join(['Tom\tJenkins\t37',
'Madonna\t\N\t45',
'Federico\tDi Gregorio\t\N']))
data.seek(0)
curs.copy_from(data, 'test_copy')
print "5) Copy 3 records from StringIO object using defaults"
curs.execute("SELECT * FROM test_copy")
rows = curs.fetchall()
print " Select using cursor returned %d rows" % len(rows)
for r in rows:
print " %s %s\t%s" % (r[0], r[1], r[2])
curs.execute("delete from test_copy")
conn.commit()
# simple error test
print "6) About to raise an error"
data = StringIO.StringIO()
data.write('\n'.join(['Tom\tJenkins\t37',
'Madonna\t\N\t45',
'Federico\tDi Gregorio\taaa']))
data.seek(0)
try:
curs.copy_from(data, 'test_copy')
except StandardError, err:
conn.rollback()
print " Catched error (as expected):\n", err
conn.rollback()
curs.execute("DROP TABLE test_copy")
os.unlink('copy_from.txt')
conn.commit()

View File

@ -1,104 +0,0 @@
# copy_to.py -- example about copy_to
#
# Copyright (C) 2002 Tom Jenkins <tjenkins@devis.com>
# Copyright (C) 2005 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.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
## put in DSN your DSN string
DSN = 'dbname=test'
## don't modify anything below tis line (except for experimenting)
import sys
import os
import StringIO
import psycopg2
if len(sys.argv) > 1:
DSN = sys.argv[1]
print "Opening connection using dns:", DSN
conn = psycopg2.connect(DSN)
print "Encoding for this connection is", conn.encoding
curs = conn.cursor()
try:
curs.execute("CREATE TABLE test_copy (fld1 text, fld2 text, fld3 int4)")
except:
conn.rollback()
curs.execute("DROP TABLE test_copy")
curs.execute("CREATE TABLE test_copy (fld1 text, fld2 text, fld3 int4)")
conn.commit()
# demostrate copy_to functionality
data = [('Tom', 'Jenkins', '37'),
('Madonna', None, '45'),
('Federico', 'Di Gregorio', None)]
query = "INSERT INTO test_copy VALUES (%s, %s, %s)"
curs.executemany(query, data)
conn.commit()
# copy_to using defaults
io = open('copy_to.txt', 'w')
curs.copy_to(io, 'test_copy')
print "1) Copy %d records into file object using defaults: " % len (data) + \
"sep = \\t and null = \\N"
io.close()
rows = open('copy_to.txt', 'r').readlines()
print " File has %d rows:" % len(rows)
for r in rows:
print " ", r,
# copy_to using custom separator
io = open('copy_to.txt', 'w')
curs.copy_to(io, 'test_copy', ':')
print "2) Copy %d records into file object using sep = :" % len(data)
io.close()
rows = open('copy_to.txt', 'r').readlines()
print " File has %d rows:" % len(rows)
for r in rows:
print " ", r,
# copy_to using custom null identifier
io = open('copy_to.txt', 'w')
curs.copy_to(io, 'test_copy', null='NULL')
print "3) Copy %d records into file object using null = NULL" % len(data)
io.close()
rows = open('copy_to.txt', 'r').readlines()
print " File has %d rows:" % len(rows)
for r in rows:
print " ", r,
# copy_to using custom separator and null identifier
io = open('copy_to.txt', 'w')
curs.copy_to(io, 'test_copy', ':', 'NULL')
print "4) Copy %d records into file object using sep = : and null ) NULL" % \
len(data)
io.close()
rows = open('copy_to.txt', 'r').readlines()
print " File has %d rows:" % len(rows)
for r in rows:
print " ", r,
curs.execute("DROP TABLE test_copy")
os.unlink('copy_to.txt')
conn.commit()

View File

@ -1,63 +0,0 @@
# cursor.py - how to subclass the cursor type
#
# Copyright (C) 2004 Federico Di Gregorio <fog@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
## put in DSN your DSN string
DSN = 'dbname=test'
## don't modify anything below this line (except for experimenting)
import sys
import psycopg2
import psycopg2.extensions
if len(sys.argv) > 1:
DSN = sys.argv[1]
print "Opening connection using dsn:", DSN
conn = psycopg2.connect(DSN)
print "Encoding for this connection is", conn.encoding
class NoDataError(psycopg2.ProgrammingError):
"""Exception that will be raised by our cursor."""
pass
class Cursor(psycopg2.extensions.cursor):
"""A custom cursor."""
def fetchone(self):
"""Like fetchone but raise an exception if no data is available.
Note that to have .fetchmany() and .fetchall() to raise the same
exception we'll have to override them too; even if internally psycopg
uses the same function to fetch rows, the code path from Python is
different.
"""
d = psycopg2.extensions.cursor.fetchone(self)
if d is None:
raise NoDataError("no more data")
return d
curs = conn.cursor(cursor_factory=Cursor)
curs.execute("SELECT 1 AS foo")
print "Result of fetchone():", curs.fetchone()
# now let's raise the exception
try:
curs.fetchone()
except NoDataError, err:
print "Exception caugth:", err
conn.rollback()

View File

@ -1,144 +0,0 @@
"""
This example/recipe has been contributed by Valentino Volonghi (dialtone)
Mapping arbitrary objects to a PostgreSQL database with psycopg2
- Problem
You need to store arbitrary objects in a PostgreSQL database without being
intrusive for your classes (don't want inheritance from an 'Item' or
'Persistent' object).
- Solution
"""
from datetime import datetime
import psycopg2
from psycopg2.extensions import adapt, register_adapter
try:
sorted()
except:
def sorted(seq):
seq.sort()
return seq
# Here is the adapter for every object that we may ever need to
# insert in the database. It receives the original object and does
# its job on that instance
class ObjectMapper(object):
def __init__(self, orig, curs=None):
self.orig = orig
self.tmp = {}
self.items, self.fields = self._gatherState()
def _gatherState(self):
adaptee_name = self.orig.__class__.__name__
fields = sorted([(field, getattr(self.orig, field))
for field in persistent_fields[adaptee_name]])
items = []
for item, value in fields:
items.append(item)
return items, fields
def getTableName(self):
return self.orig.__class__.__name__
def getMappedValues(self):
tmp = []
for i in self.items:
tmp.append("%%(%s)s"%i)
return ", ".join(tmp)
def getValuesDict(self):
return dict(self.fields)
def getFields(self):
return self.items
def generateInsert(self):
qry = "INSERT INTO"
qry += " " + self.getTableName() + " ("
qry += ", ".join(self.getFields()) + ") VALUES ("
qry += self.getMappedValues() + ")"
return qry, self.getValuesDict()
# Here are the objects
class Album(object):
id = 0
def __init__(self):
self.creation_time = datetime.now()
self.album_id = self.id
Album.id = Album.id + 1
self.binary_data = buffer('12312312312121')
class Order(object):
id = 0
def __init__(self):
self.items = ['rice','chocolate']
self.price = 34
self.order_id = self.id
Order.id = Order.id + 1
register_adapter(Album, ObjectMapper)
register_adapter(Order, ObjectMapper)
# Describe what is needed to save on each object
# This is actually just configuration, you can use xml with a parser if you
# like to have plenty of wasted CPU cycles ;P.
persistent_fields = {'Album': ['album_id', 'creation_time', 'binary_data'],
'Order': ['order_id', 'items', 'price']
}
print adapt(Album()).generateInsert()
print adapt(Album()).generateInsert()
print adapt(Album()).generateInsert()
print adapt(Order()).generateInsert()
print adapt(Order()).generateInsert()
print adapt(Order()).generateInsert()
"""
- Discussion
Psycopg 2 has a great new feature: adaptation. The big thing about
adaptation is that it enable the programmer to glue most of the
code out there without many difficulties.
This recipe tries to focus the attention on a way to generate SQL queries to
insert completely new objects inside a database. As you can see objects do
not know anything about the code that is handling them. We specify all the
fields that we need for each object through the persistent_fields dict.
The most important lines of this recipe are:
register_adapter(Album, ObjectMapper)
register_adapter(Order, ObjectMapper)
In these line we notify the system that when we call adapt with an Album instance
as an argument we want it to istantiate ObjectMapper passing the Album instance
as argument (self.orig in the ObjectMapper class).
The output is something like this (for each call to generateInsert):
('INSERT INTO Album (album_id, binary_data, creation_time) VALUES
(%(album_id)s, %(binary_data)s, %(creation_time)s)',
{'binary_data': <read-only buffer for 0x402de070, ...>,
'creation_time': datetime.datetime(2004, 9, 10, 20, 48, 29, 633728),
'album_id': 1}
)
This is a tuple of {SQL_QUERY, FILLING_DICT}, and all the quoting/converting
stuff (from python's datetime to postgres s and from python's buffer to
postgres' blob) is handled with the same adaptation process hunder the hood
by psycopg2.
At last, just notice that ObjectMapper is working for both Album and Order
instances without any glitches at all, and both classes could have easily been
coming from closed source libraries or C coded ones (which are not easily
modified), whereas a common pattern in todays ORMs or OODBs is to provide
a basic 'Persistent' object that already knows how to store itself in the
database.
"""

View File

@ -1,45 +0,0 @@
# dict.py - using DictCUrsor/DictRow
#
# Copyright (C) 2005 Federico Di Gregorio <fog@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
## put in DSN your DSN string
DSN = 'dbname=test'
## don't modify anything below this line (except for experimenting)
import sys
import psycopg2
import psycopg2.extras
if len(sys.argv) > 1:
DSN = sys.argv[1]
print "Opening connection using dsn:", DSN
conn = psycopg2.connect(DSN)
print "Encoding for this connection is", conn.encoding
curs = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
curs.execute("SELECT 1 AS foo, 'cip' AS bar, date(now()) as zot")
data = curs.fetchone()
print "Some data accessed both as tuple and dict:"
print " ", data['foo'], data['bar'], data['zot']
print " ", data[0], data[1], data[2]
# execute another query and demostrate we can still access the row
curs.execute("SELECT 2 AS foo")
print "Some more data accessed both as tuple and dict:"
print " ", data['foo'], data['bar'], data['zot']
print " ", data[0], data[1], data[2]

View File

@ -1,99 +0,0 @@
# datetime.py - example of using date and time types
#
# Copyright (C) 2001-2004 Federico Di Gregorio <fog@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
## put in DSN your DSN string
DSN = 'dbname=test'
## don't modify anything below tis line (except for experimenting)
import sys
import psycopg2
import mx.DateTime
import datetime
from psycopg2.extensions import adapt
if len(sys.argv) > 1:
DSN = sys.argv[1]
print "Opening connection using dns:", DSN
conn = psycopg2.connect(DSN)
curs = conn.cursor()
try:
curs.execute("""CREATE TABLE test_dt (
k int4, d date, t time, dt timestamp, z interval)""")
except:
conn.rollback()
curs.execute("DROP TABLE test_dt")
curs.execute("""CREATE TABLE test_dt (
k int4, d date, t time, dt timestamp, z interval)""")
conn.commit()
# build and insert some data using mx.DateTime
mx1 = (
1,
mx.DateTime.Date(2004, 10, 19),
mx.DateTime.Time(0, 11, 17.015),
mx.DateTime.Timestamp(2004, 10, 19, 0, 11, 17.5),
mx.DateTime.DateTimeDelta(13, 15, 17, 59.9))
from psycopg2.extensions import adapt
import psycopg2.extras
print adapt(mx1)
print "Inserting mx.DateTime values..."
curs.execute("INSERT INTO test_dt VALUES (%s, %s, %s, %s, %s)", mx1)
# build and insert some values using the datetime adapters
dt1 = (
2,
datetime.date(2004, 10, 19),
datetime.time(0, 11, 17, 15000),
datetime.datetime(2004, 10, 19, 0, 11, 17, 500000),
datetime.timedelta(13, 15*3600+17*60+59, 900000))
print "Inserting Python datetime values..."
curs.execute("INSERT INTO test_dt VALUES (%s, %s, %s, %s, %s)", dt1)
# now extract the row from database and print them
print "Extracting values inserted with mx.DateTime wrappers:"
curs.execute("SELECT d, t, dt, z FROM test_dt WHERE k = 1")
for n, x in zip(mx1[1:], curs.fetchone()):
try:
# this will work only is psycopg has been compiled with datetime
# as the default typecaster for date/time values
s = repr(n) + "\n -> " + str(adapt(n)) + \
"\n -> " + repr(x) + "\n -> " + x.isoformat()
except:
s = repr(n) + "\n -> " + str(adapt(n)) + \
"\n -> " + repr(x) + "\n -> " + str(x)
print s
print
print "Extracting values inserted with Python datetime wrappers:"
curs.execute("SELECT d, t, dt, z FROM test_dt WHERE k = 2")
for n, x in zip(dt1[1:], curs.fetchone()):
try:
# this will work only is psycopg has been compiled with datetime
# as the default typecaster for date/time values
s = repr(n) + "\n -> " + repr(x) + "\n -> " + x.isoformat()
except:
s = repr(n) + "\n -> " + repr(x) + "\n -> " + str(x)
print s
print
curs.execute("DROP TABLE test_dt")
conn.commit()

View File

@ -1,105 +0,0 @@
# enkoding.py - show to change client enkoding (and test it works)
# -*- encoding: utf8 -*-
#
# Copyright (C) 2004 Federico Di Gregorio <fog@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
## put in DSN your DSN string
DSN = 'dbname=test'
## don't modify anything below this line (except for experimenting)
import sys
import psycopg2
import psycopg2.extensions
if len(sys.argv) > 1:
DSN = sys.argv[1]
print "Opening connection using dns:", DSN
conn = psycopg2.connect(DSN)
print "Initial encoding for this connection is", conn.encoding
print "\n** This example is supposed to be run in a UNICODE terminal! **\n"
print "Available encodings:"
encs = psycopg2.extensions.encodings.items()
encs.sort()
for a, b in encs:
print " ", a, "<->", b
print "Using STRING typecaster"
print "Setting backend encoding to LATIN1 and executing queries:"
conn.set_client_encoding('LATIN1')
curs = conn.cursor()
curs.execute("SELECT %s::TEXT AS foo", ('àèìòù',))
x = curs.fetchone()[0]
print " ->", unicode(x, 'latin-1').encode('utf-8'), type(x)
curs.execute("SELECT %s::TEXT AS foo", (u'àèìòù',))
x = curs.fetchone()[0]
print " ->", unicode(x, 'latin-1').encode('utf-8'), type(x)
print "Setting backend encoding to UTF8 and executing queries:"
conn.set_client_encoding('UNICODE')
curs = conn.cursor()
curs.execute("SELECT %s::TEXT AS foo", (u'àèìòù'.encode('utf-8'),))
x = curs.fetchone()[0]
print " ->", x, type(x)
curs.execute("SELECT %s::TEXT AS foo", (u'àèìòù',))
x = curs.fetchone()[0]
print " ->", x, type(x)
print "Using UNICODE typecaster"
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
print "Setting backend encoding to LATIN1 and executing queries:"
conn.set_client_encoding('LATIN1')
curs = conn.cursor()
curs.execute("SELECT %s::TEXT AS foo", ('àèìòù',))
x = curs.fetchone()[0]
print " ->", x.encode('utf-8'), ":", type(x)
curs.execute("SELECT %s::TEXT AS foo", (u'àèìòù',))
x = curs.fetchone()[0]
print " ->", x.encode('utf-8'), ":", type(x)
print "Setting backend encoding to UTF8 and executing queries:"
conn.set_client_encoding('UNICODE')
curs = conn.cursor()
curs.execute("SELECT %s::TEXT AS foo", (u'àèìòù'.encode('utf-8'),))
x = curs.fetchone()[0]
print " ->", x.encode('utf-8'), ":", type(x)
curs.execute("SELECT %s::TEXT AS foo", (u'àèìòù',))
x = curs.fetchone()[0]
print " ->", x.encode('utf-8'), ":", type(x)
print "Executing full UNICODE queries"
print "Setting backend encoding to LATIN1 and executing queries:"
conn.set_client_encoding('LATIN1')
curs = conn.cursor()
curs.execute(u"SELECT %s::TEXT AS foo", ('àèìòù',))
x = curs.fetchone()[0]
print " ->", x.encode('utf-8'), ":", type(x)
curs.execute(u"SELECT %s::TEXT AS foo", (u'àèìòù',))
x = curs.fetchone()[0]
print " ->", x.encode('utf-8'), ":", type(x)
print "Setting backend encoding to UTF8 and executing queries:"
conn.set_client_encoding('UNICODE')
curs = conn.cursor()
curs.execute(u"SELECT %s::TEXT AS foo", (u'àèìòù'.encode('utf-8'),))
x = curs.fetchone()[0]
print " ->", x.encode('utf-8'), ":", type(x)
curs.execute(u"SELECT %s::TEXT AS foo", (u'àèìòù',))
x = curs.fetchone()[0]
print " ->", x.encode('utf-8'), ":", type(x)

View File

@ -1,81 +0,0 @@
# fetch.py -- example about declaring cursors
#
# Copyright (C) 2001-2005 Federico Di Gregorio <fog@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
## put in DSN your DSN string
DSN = 'dbname=test'
## don't modify anything below tis line (except for experimenting)
import sys
import psycopg2
if len(sys.argv) > 1:
DSN = sys.argv[1]
print "Opening connection using dns:", DSN
conn = psycopg2.connect(DSN)
print "Encoding for this connection is", conn.encoding
curs = conn.cursor()
try:
curs.execute("CREATE TABLE test_fetch (val int4)")
except:
conn.rollback()
curs.execute("DROP TABLE test_fetch")
curs.execute("CREATE TABLE test_fetch (val int4)")
conn.commit()
# we use this function to format the output
def flatten(l):
"""Flattens list of tuples l."""
return map(lambda x: x[0], l)
# insert 20 rows in the table
for i in range(20):
curs.execute("INSERT INTO test_fetch VALUES(%s)", (i,))
conn.commit()
# does some nice tricks with the transaction and postgres cursors
# (remember to always commit or rollback before a DECLARE)
#
# we don't need to DECLARE ourselves, psycopg now support named
# cursors (but we leave the code here, comments, as an example of
# what psycopg is doing under the hood)
#
#curs.execute("DECLARE crs CURSOR FOR SELECT * FROM test_fetch")
#curs.execute("FETCH 10 FROM crs")
#print "First 10 rows:", flatten(curs.fetchall())
#curs.execute("MOVE -5 FROM crs")
#print "Moved back cursor by 5 rows (to row 5.)"
#curs.execute("FETCH 10 FROM crs")
#print "Another 10 rows:", flatten(curs.fetchall())
#curs.execute("FETCH 10 FROM crs")
#print "The remaining rows:", flatten(curs.fetchall())
ncurs = conn.cursor("crs")
ncurs.execute("SELECT * FROM test_fetch")
print "First 10 rows:", flatten(ncurs.fetchmany(10))
ncurs.scroll(-5)
print "Moved back cursor by 5 rows (to row 5.)"
print "Another 10 rows:", flatten(ncurs.fetchmany(10))
print "Another one:", list(ncurs.fetchone())
print "The remaining rows:", flatten(ncurs.fetchall())
conn.rollback()
curs.execute("DROP TABLE test_fetch")
conn.commit()

View File

@ -1,59 +0,0 @@
# lastrowid.py - example of using .lastrowid attribute
#
# Copyright (C) 2001-2004 Federico Di Gregorio <fog@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
## put in DSN your DSN string
DSN = 'dbname=test'
## don't modify anything below tis line (except for experimenting)
import sys, psycopg2
if len(sys.argv) > 1:
DSN = sys.argv[1]
print "Opening connection using dns:", DSN
conn = psycopg2.connect(DSN)
curs = conn.cursor()
try:
curs.execute("CREATE TABLE test_oid (name text, surname text)")
except:
conn.rollback()
curs.execute("DROP TABLE test_oid")
curs.execute("CREATE TABLE test_oid (name text, surname text)")
conn.commit()
data = ({'name':'Federico', 'surname':'Di Gregorio'},
{'name':'Pierluigi', 'surname':'Di Nunzio'})
curs.execute("""INSERT INTO test_oid
VALUES (%(name)s, %(surname)s)""", data[0])
foid = curs.lastrowid
print "Oid for %(name)s %(surname)s" % data[0], "is", foid
curs.execute("""INSERT INTO test_oid
VALUES (%(name)s, %(surname)s)""", data[1])
moid = curs.lastrowid
print "Oid for %(name)s %(surname)s" % data[1], "is", moid
curs.execute("SELECT * FROM test_oid WHERE oid = %s", (foid,))
print "Oid", foid, "selected %s %s" % curs.fetchone()
curs.execute("SELECT * FROM test_oid WHERE oid = %s", (moid,))
print "Oid", moid, "selected %s %s" % curs.fetchone()
curs.execute("DROP TABLE test_oid")
conn.commit()

View File

@ -1,47 +0,0 @@
# mogrify.py - test all possible simple type mogrifications
# -*- encoding: latin1 -*-
#
# Copyright (C) 2004 Federico Di Gregorio <fog@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
## put in DSN your DSN string
DSN = 'dbname=test'
## don't modify anything below this line (except for experimenting)
import sys, psycopg2
if len(sys.argv) > 1:
DSN = sys.argv[1]
print "Opening connection using dns:", DSN
conn = psycopg2.connect(DSN)
print "Encoding for this connection is", conn.encoding
curs = conn.cursor()
curs.execute("SELECT %(foo)s AS foo", {'foo':'bar'})
curs.execute("SELECT %(foo)s AS foo", {'foo':None})
curs.execute("SELECT %(foo)s AS foo", {'foo':True})
curs.execute("SELECT %(foo)s AS foo", {'foo':42})
curs.execute("SELECT %(foo)s AS foo", {'foo':u'yatt<EFBFBD>!'})
curs.execute("SELECT %(foo)s AS foo", {'foo':u'bar'})
print curs.mogrify("SELECT %(foo)s AS foo", {'foo':'bar'})
print curs.mogrify("SELECT %(foo)s AS foo", {'foo':None})
print curs.mogrify("SELECT %(foo)s AS foo", {'foo':True})
print curs.mogrify("SELECT %(foo)s AS foo", {'foo':42})
print curs.mogrify("SELECT %(foo)s AS foo", {'foo':u'yatt<EFBFBD>!'})
print curs.mogrify("SELECT %(foo)s AS foo", {'foo':u'bar'})
conn.rollback()

View File

@ -1,122 +0,0 @@
"""
Using a tuple as a bound variable in "SELECT ... IN (...)" clauses
in PostgreSQL using psycopg 2
Some time ago someone asked on the psycopg mailing list how to have a
bound variable expand to the right SQL for an SELECT IN clause:
SELECT * FROM atable WHERE afield IN (value1, value2, value3)
with the values to be used in the IN clause to be passed to the cursor
.execute() method in a tuple as a bound variable, i.e.:
in_values = ("value1", "value2", "value3")
curs.execute("SELECT ... IN %s", (in_values,))
psycopg 1 does support typecasting from Python to PostgreSQL (and back)
only for simple types and this problem has no elegant solution (short or
writing a wrapper class returning the pre-quoted text in an __str__
method.
But psycopg 2 offers a simple and elegant solution by partially
implementing the Object Adaptation from PEP 246. psycopg 2 (still in
beta and currently labeled as 1.99.9) moves the type-casting logic into
external adapters and a somehow broken adapt() function.
While the original adapt() takes 3 arguments, psycopg's one only takes
1: the bound variable to be adapted. The result is an object supporting
a not-yet well defined protocol that we can call IPsycopgSQLQuote:
class IPsycopgSQLQuote:
def getquoted(self):
"Returns a quoted string representing the bound variable."
def getbinary(self):
"Returns a binary quoted string representing the bound variable."
def getbuffer(self):
"Returns the wrapped object itself."
__str__ = getquoted
Then one of the functions (usually .getquoted()) is called by psycopg at
the right time to obtain the right, sql-quoted representation for the
corresponding bound variable.
The nice part is that the default, built-in adapters, derived from
psycopg 1 tyecasting code can be overridden by the programmer, simply
replacing them in the psycopg.extensions.adapters dictionary.
Then the solution to the original problem is now obvious: write an
adapter that adapts tuple objects into the right SQL string, by calling
recursively adapt() on each element.
Note: psycopg 2 adapter code is still very young and will probably move
to a more 'standard' (3 arguments) implementation for the adapt()
function; as long as that does not slow down too much query execution.
Psycopg 2 development can be tracked on the psycopg mailing list:
http://lists.initd.org/mailman/listinfo/psycopg
and on the psycopg 2 wiki:
http://wiki.initd.org/Projects/Psycopg2
"""
import psycopg2
import psycopg2.extensions
from psycopg2.extensions import adapt as psycoadapt
from psycopg2.extensions import register_adapter
class AsIs(object):
"""An adapter that just return the object 'as is'.
psycopg 1.99.9 has some optimizations that make impossible to call
adapt() without adding some basic adapters externally. This limitation
will be lifted in a future release.
"""
def __init__(self, obj):
self.__obj = obj
def getquoted(self):
return self.__obj
class SQL_IN(object):
"""Adapt a tuple to an SQL quotable object."""
def __init__(self, seq):
self._seq = seq
def prepare(self, conn):
pass
def getquoted(self):
# this is the important line: note how every object in the
# list is adapted and then how getquoted() is called on it
qobjs = [str(psycoadapt(o).getquoted()) for o in self._seq]
return '(' + ', '.join(qobjs) + ')'
__str__ = getquoted
# add our new adapter class to psycopg list of adapters
register_adapter(tuple, SQL_IN)
register_adapter(float, AsIs)
register_adapter(int, AsIs)
# usually we would call:
#
# conn = psycopg.connect("...")
# curs = conn.cursor()
# curs.execute("SELECT ...", (("this", "is", "the", "tuple"),))
#
# but we have no connection to a database right now, so we just check
# the SQL_IN class by calling psycopg's adapt() directly:
if __name__ == '__main__':
print "Note how the string will be SQL-quoted, but the number will not:"
print psycoadapt(("this is an 'sql quoted' str\\ing", 1, 2.0))

View File

@ -1,43 +0,0 @@
# notify.py - example of getting notifies
#
# Copyright (C) 2001-2005 Federico Di Gregorio <fog@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
## put in DSN your DSN string
DSN = 'dbname=test'
## don't modify anything below tis line (except for experimenting)
import sys
import psycopg2
import select
if len(sys.argv) > 1:
DSN = sys.argv[1]
print "Opening connection using dns:", DSN
conn = psycopg2.connect(DSN)
print "Encoding for this connection is", conn.encoding
conn.set_isolation_level(0)
curs = conn.cursor()
curs.execute("listen test")
print "Waiting for 'NOTIFY test'"
while 1:
if select.select([curs],[],[],5)==([],[],[]):
print "Timeout"
else:
if curs.isready():
print "Got NOTIFY: %s" % str(curs.connection.notifies.pop())

View File

@ -1,53 +0,0 @@
# simple.py - very simple example of plain DBAPI-2.0 usage
# currently used as test-me-stress-me script for psycopg 2.0
#
# Copyright (C) 2001-2003 Federico Di Gregorio <fog@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
## put in DSN your DSN string
DSN = 'dbname=test'
## don't modify anything below this line (except for experimenting)
class SimpleQuoter(object):
def sqlquote(x=None):
return "'bar'"
import sys
import psycopg2
if len(sys.argv) > 1:
DSN = sys.argv[1]
print "Opening connection using dns:", DSN
conn = psycopg2.connect(DSN)
print "Encoding for this connection is", conn.encoding
curs = conn.cursor()
curs.execute("SELECT 1 AS foo")
print curs.fetchone()
curs.execute("SELECT 1 AS foo")
print curs.fetchmany()
curs.execute("SELECT 1 AS foo")
print curs.fetchall()
conn.rollback()
sys.exit(0)
curs.execute("SELECT 1 AS foo", async=1)
curs.execute("SELECT %(foo)s AS foo", {'foo':'bar'})
curs.execute("SELECT %(foo)s AS foo", {'foo':None})
curs.execute("SELECT %(foo)f AS foo", {'foo':42})
curs.execute("SELECT %(foo)s AS foo", {'foo':SimpleQuoter()})

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

View File

@ -1,160 +0,0 @@
# threads.py -- example of multiple threads using psycopg
# -*- encoding: latin1 -*-
#
# Copyright (C) 2001-2004 Federico Di Gregorio <fog@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
## put in DSN your DSN string
DSN = 'dbname=test'
## some others parameters
INSERT_THREADS = ('A', 'B', 'C')
SELECT_THREADS = ('1', '2')
ROWS = 1000
COMMIT_STEP = 20
SELECT_SIZE = 10000
SELECT_STEP = 500
SELECT_DIV = 250
# the available modes are:
# 0 - one connection for all insert and one for all select threads
# 1 - connections generated using the connection pool
MODE = 1
## don't modify anything below tis line (except for experimenting)
import sys, psycopg2, threading
from psycopg2.pool import ThreadedConnectionPool
if len(sys.argv) > 1:
DSN = sys.argv[1]
if len(sys.argv) > 2:
MODE = int(sys.argv[2])
print "Opening connection using dns:", DSN
conn = psycopg2.connect(DSN)
curs = conn.cursor()
try:
curs.execute("""CREATE TABLE test_threads (
name text, value1 int4, value2 float)""")
except:
conn.rollback()
curs.execute("DROP TABLE test_threads")
curs.execute("""CREATE TABLE test_threads (
name text, value1 int4, value2 float)""")
conn.commit()
## this function inserts a big number of rows and creates and destroys
## a large number of cursors
def insert_func(conn_or_pool, rows):
name = threading.currentThread().getName()
if MODE == 0:
conn = conn_or_pool
else:
conn = conn_or_pool.getconn()
for i in range(rows):
if divmod(i, COMMIT_STEP)[1] == 0:
conn.commit()
if MODE == 1:
conn_or_pool.putconn(conn)
s = name + ": COMMIT STEP " + str(i)
print s
if MODE == 1:
conn = conn_or_pool.getconn()
c = conn.cursor()
try:
c.execute("INSERT INTO test_threads VALUES (%s, %s, %s)",
(str(i), i, float(i)))
except psycopg2.ProgrammingError, err:
print name, ": an error occurred; skipping this insert"
print err
conn.commit()
## a nice select function that prints the current number of rows in the
## database (and transefer them, putting some pressure on the network)
def select_func(conn_or_pool, z):
name = threading.currentThread().getName()
if MODE == 0:
conn = conn_or_pool
conn.set_isolation_level(0)
for i in range(SELECT_SIZE):
if divmod(i, SELECT_STEP)[1] == 0:
try:
if MODE == 1:
conn = conn_or_pool.getconn()
conn.set_isolation_level(0)
c = conn.cursor()
c.execute("SELECT * FROM test_threads WHERE value2 < %s",
(int(i/z),))
l = c.fetchall()
if MODE == 1:
conn_or_pool.putconn(conn)
s = name + ": number of rows fetched: " + str(len(l))
print s
except psycopg2.ProgrammingError, err:
print name, ": an error occurred; skipping this select"
print err
## create the connection pool or the connections
if MODE == 0:
conn_insert = psycopg2.connect(DSN)
conn_select = psycopg2.connect(DSN)
else:
m = len(INSERT_THREADS) + len(SELECT_THREADS)
n = m/2
conn_insert = conn_select = ThreadedConnectionPool(n, m, DSN)
## create the threads
threads = []
print "Creating INSERT threads:"
for name in INSERT_THREADS:
t = threading.Thread(None, insert_func, 'Thread-'+name,
(conn_insert, ROWS))
t.setDaemon(0)
threads.append(t)
print "Creating SELECT threads:"
for name in SELECT_THREADS:
t = threading.Thread(None, select_func, 'Thread-'+name,
(conn_select, SELECT_DIV))
t.setDaemon(0)
threads.append(t)
## really start the threads now
for t in threads:
t.start()
# and wait for them to finish
for t in threads:
t.join()
print t.getName(), "exited OK"
conn.commit()
curs.execute("SELECT count(name) FROM test_threads")
print "Inserted", curs.fetchone()[0], "rows."
curs.execute("DROP TABLE test_threads")
conn.commit()

View File

@ -1,69 +0,0 @@
# tz.py - example of datetime objects with time zones
# -*- encoding: utf8 -*-
#
# Copyright (C) 2004 Federico Di Gregorio <fog@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
## put in DSN your DSN string
DSN = 'dbname=test'
## don't modify anything below this line (except for experimenting)
import sys
import psycopg2
import datetime
from psycopg2.tz import ZERO, LOCAL, FixedOffsetTimezone
if len(sys.argv) > 1:
DSN = sys.argv[1]
print "Opening connection using dns:", DSN
conn = psycopg2.connect(DSN)
curs = conn.cursor()
try:
curs.execute("CREATE TABLE test_tz (t timestamp with time zone)")
except:
conn.rollback()
curs.execute("DROP TABLE test_tz")
curs.execute("CREATE TABLE test_tz (t timestamp with time zone)")
conn.commit()
d = datetime.datetime(1971, 10, 19, 22, 30, 0, tzinfo=LOCAL)
curs.execute("INSERT INTO test_tz VALUES (%s)", (d,))
print "Inserted timestamp with timezone:", d
print "Time zone:", d.tzinfo.tzname(d), "offset:", d.tzinfo.utcoffset(d)
tz = FixedOffsetTimezone(-5*60, "EST")
d = datetime.datetime(1971, 10, 19, 22, 30, 0, tzinfo=tz)
curs.execute("INSERT INTO test_tz VALUES (%s)", (d,))
print "Inserted timestamp with timezone:", d
print "Time zone:", d.tzinfo.tzname(d), "offset:", d.tzinfo.utcoffset(d)
curs.execute("SELECT * FROM test_tz")
d = curs.fetchone()[0]
curs.execute("INSERT INTO test_tz VALUES (%s)", (d,))
print "Inserted SELECTed timestamp:", d
print "Time zone:", d.tzinfo.tzname(d), "offset:", d.tzinfo.utcoffset(d)
curs.execute("SELECT * FROM test_tz")
for d in curs:
u = d[0].utcoffset() or ZERO
print "UTC time: ", d[0] - u
print "Local time:", d[0]
print "Time zone:", d[0].tzinfo.tzname(d[0]), d[0].tzinfo.utcoffset(d[0])
curs.execute("DROP TABLE test_tz")
conn.commit()

View File

@ -1,126 +0,0 @@
# usercast.py -- example of user defined typecasters
# -*- encoding: latin-1 -*-
#
# Copyright (C) 2001-2005 Federico Di Gregorio <fog@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
## put in DSN your DSN string
DSN = 'dbname=test'
## don't modify anything below tis line (except for experimenting)
import sys
import psycopg2
import psycopg2.extensions
import whrandom
# importing psycopg.extras will give us a nice tuple adapter: this is wrong
# because the adapter is meant to be used in SQL IN clauses while we use
# tuples to represent points but it works and the example is about Rect, not
# "Point"
import psycopg2.extras
if len(sys.argv) > 1:
DSN = sys.argv[1]
print "Opening connection using dns:", DSN
conn = psycopg2.connect(DSN)
print "Initial encoding for this connection is", conn.encoding
curs = conn.cursor()
try:
curs.execute("CREATE TABLE test_cast (p1 point, p2 point, b box)")
except:
conn.rollback()
curs.execute("DROP TABLE test_cast")
curs.execute("CREATE TABLE test_cast (p1 point, p2 point, b box)")
conn.commit()
# this is the callable object we use as a typecast (the typecast is
# usually a function, but we use a class, just to demonstrate the
# flexibility of the psycopg casting system
class Rect(object):
"""Very simple rectangle.
Note that we use this type as a data holder, as an adapter of itself for
the ISQLQuote protocol used by psycopg's adapt() (see __confrom__ below)
and eventually as a type-caster for the data extracted from the database
(that's why __init__ takes the curs argument.)
"""
def __init__(self, s=None, curs=None):
"""Init the rectangle from the optional string s."""
self.x = self.y = self.width = self.height = 0.0
if s: self.from_string(s)
def __conform__(self, proto):
"""This is a terrible hack, just ignore proto and return self."""
if proto == psycopg2.extensions.ISQLQuote:
return self
def from_points(self, x0, y0, x1, y1):
"""Init the rectangle from points."""
if x0 > x1: (x0, x1) = (x1, x0)
if y0 > y1: (y0, y1) = (y1, y0)
self.x = x0
self.y = y0
self.width = x1 - x0
self.height = y1 - y0
def from_string(self, s):
"""Init the rectangle from a string."""
seq = eval(s)
self.from_points(seq[0][0], seq[0][1], seq[1][0], seq[1][1])
def getquoted(self):
"""Format self as a string usable by the db to represent a box."""
s = "'((%d,%d),(%d,%d))'" % (
self.x, self.y, self.x + self.width, self.y + self.height)
return s
def show(self):
"""Format a description of the box."""
s = "X: %d\tY: %d\tWidth: %d\tHeight: %d" % (
self.x, self.y, self.width, self.height)
return s
# here we select from the empty table, just to grab the description
curs.execute("SELECT b FROM test_cast WHERE 0=1")
boxoid = curs.description[0][1]
print "Oid for the box datatype is", boxoid
# and build the user cast object
BOX = psycopg2.extensions.new_type((boxoid,), "BOX", Rect)
psycopg2.extensions.register_type(BOX)
# now insert 100 random data (2 points and a box in each row)
for i in range(100):
p1 = (whrandom.randint(0,100), whrandom.randint(0,100))
p2 = (whrandom.randint(0,100), whrandom.randint(0,100))
b = Rect()
b.from_points(whrandom.randint(0,100), whrandom.randint(0,100),
whrandom.randint(0,100), whrandom.randint(0,100))
curs.execute("INSERT INTO test_cast VALUES ('%(p1)s', '%(p2)s', %(box)s)",
{'box':b, 'p1':p1, 'p2':p2})
print "Added 100 boxed to the database"
# select and print all boxes with at least one point inside
curs.execute("SELECT b FROM test_cast WHERE p1 @ b OR p2 @ b")
boxes = curs.fetchall()
print "Found %d boxes with at least a point inside:" % len(boxes)
for box in boxes:
print " ", box[0].show()
curs.execute("DROP TABLE test_cast")
conn.commit()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

Some files were not shown because too many files have changed in this diff Show More