diff options
| author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2010-02-26 00:17:52 +0000 |
|---|---|---|
| committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2010-02-26 00:49:19 +0000 |
| commit | 97ced0d4f14bc9e2e66e495eebcd2f0ab25adb21 (patch) | |
| tree | 104d6adbc709766e9f2657e28c225e3508b67c64 /doc/src/faq.rst | |
| parent | 4412826556ea5af86ca2be0cf03a691f4e7cdadb (diff) | |
| download | psycopg2-97ced0d4f14bc9e2e66e495eebcd2f0ab25adb21.tar.gz | |
Use the default role for cross referencing Python objects.
Diffstat (limited to 'doc/src/faq.rst')
| -rw-r--r-- | doc/src/faq.rst | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/doc/src/faq.rst b/doc/src/faq.rst index 9041ead..b45d103 100644 --- a/doc/src/faq.rst +++ b/doc/src/faq.rst @@ -3,17 +3,17 @@ Frequently Asked Questions .. sectionauthor:: Daniele Varrazzo <daniele.varrazzo@gmail.com> -Here are a few gotchas you may encounter using :mod:`psycopg2`. Feel free to +Here are a few gotchas you may encounter using `psycopg2`. Feel free to suggest new entries! .. cssclass:: faq -Why does :mod:`!psycopg2` leave database sessions "idle in transaction"? +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 :meth:`cursor.execute`, even if the command is a + executed, e.g. calling `cursor.execute()`, even if the command is a :sql:`SELECT`. The transaction is not closed until an explicit - :meth:`~connection.commit` or :meth:`~connection.rollback`. + `~connection.commit()` or `~connection.rollback()`. If you are writing a long-living program, you should probably ensure to call one of the transaction closing methods before leaving the connection @@ -22,7 +22,7 @@ Why does :mod:`!psycopg2` leave database sessions "idle in transaction"? connection in :ref:`autocommit <autocommit>` mode to avoid a new transaction to be started at the first command. -Why does :meth:`!cursor.execute` raise the exception *can't adapt*? +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 @@ -50,19 +50,19 @@ I try to execute a query but it fails with the error *not all arguments converte 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 :meth:`~connection.rollback` before sending + 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: http://www.postgresql.org/docs/8.4/static/sql-savepoint.html -Why do i get the error *current transaction is aborted, commands ignored until end of transaction block* when I use :mod:`!multiprocessing` (or any other forking system) and not when use :mod:`!threading`? +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 ensure to create a new connection in each forked child. -My database is Unicode, but I receive all the strings as UTF-8 :class:`str`. Can I receive :class:`unicode` objects instead? +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) @@ -70,11 +70,11 @@ My database is Unicode, but I receive all the strings as UTF-8 :class:`str`. Can See :ref:`unicode-handling` for the gory details. -I can't compile :mod:`!psycopg2`: the compiler says *error: Python.h: No such file or directory*. What am I missing? +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``. -I can't compile :mod:`!psycopg2`: the compiler says *error: libpq-fe.h: No such file or directory*. What am I missing? +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``. @@ -83,7 +83,7 @@ When should I save and re-use a cursor as opposed to creating a new one as neede 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 :meth:`~cursor.close` on + 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. @@ -92,7 +92,7 @@ When should I save and re-use a connection as opposed to creating a new one as n 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 :mod:`psycopg2.pool` for lightweight + left "idle in transaction". See also `psycopg2.pool` for lightweight connection pooling. What are the advantages or disadvantages of using named cursors? @@ -100,5 +100,5 @@ What are the advantages or disadvantages of using named cursors? that there is a little overhead because a 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 :meth:`~cursor.fetchmany` values it is possible to use very + 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. |
