source: trunk/docs/contents/pgdb/connection.rst @ 787

Last change on this file since 787 was 787, checked in by cito, 4 years ago

Make the type cache of pgdb available to users

File size: 3.0 KB
Line 
1Connection -- The connection object
2===================================
3
4.. py:currentmodule:: pgdb
5
6.. class:: Connection
7
8These connection objects respond to the following methods.
9
10Note that ``pgdb.Connection`` objects also implement the context manager protocol,
11i.e. you can use them in a ``with`` statement.
12
13close -- close the connection
14-----------------------------
15
16.. method:: Connection.close()
17
18    Close the connection now (rather than whenever it is deleted)
19
20    :rtype: None
21
22The connection will be unusable from this point forward; an :exc:`Error`
23(or subclass) exception will be raised if any operation is attempted with
24the connection. The same applies to all cursor objects trying to use the
25connection. Note that closing a connection without committing the changes
26first will cause an implicit rollback to be performed.
27
28commit -- commit the connection
29-------------------------------
30
31.. method:: Connection.commit()
32
33    Commit any pending transaction to the database
34
35    :rtype: None
36
37Note that connections always use a transaction, there is no auto-commit.
38
39rollback -- roll back the connection
40------------------------------------
41
42.. method:: Connection.rollback()
43
44    Roll back any pending transaction to the database
45
46    :rtype: None
47
48This method causes the database to roll back to the start of any pending
49transaction. Closing a connection without committing the changes first will
50cause an implicit rollback to be performed.
51
52cursor -- return a new cursor object
53------------------------------------
54
55.. method:: Connection.cursor()
56
57    Return a new cursor object using the connection
58
59    :returns: a connection object
60    :rtype: :class:`Cursor`
61
62This method returns a new :class:`Cursor` object that can be used to
63operate on the database in the way described in the next section.
64
65Attributes that are not part of the standard
66--------------------------------------------
67
68.. note::
69
70   The following attributes are not part of the DB-API 2 standard.
71
72.. attribute:: cursor_type
73
74    The default cursor type used by the connection
75
76If you want to use your own custom subclass of the :class:`Cursor` class
77with he connection, set this attribute to your custom cursor class. You will
78then get your custom cursor whenever you call :meth:`Connection.cursor`.
79
80.. versionadded:: 5.0
81
82.. attribute:: type_cache
83
84    A dictionary with type information on the PostgreSQL types
85
86You can request the dictionary either via type names or type OIDs.
87
88The values are named tuples containing the following fields:
89
90        - *oid* -- the OID of the type
91        - *name*  -- the type's name
92        - *len*  -- the internal size
93        - *type*  -- ``'b'`` = base, ``'c'`` = composite, ...
94        - *category*  -- ``'A'`` = Array, ``'B'`` = Boolean, ...
95        - *delim*  -- delimiter to be used when parsing arrays
96        - *relid*  -- the table OID for composite types
97
98For details, see the PostgreSQL documentation on `pg_type
99<http://www.postgresql.org/docs/current/static/catalog-pg-type.html>`_.
100
101.. versionadded:: 5.0
Note: See TracBrowser for help on using the repository browser.