File: connection.html

package info (click to toggle)
pygresql 1%3A5.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,340 kB
  • ctags: 2,187
  • sloc: python: 13,239; ansic: 4,975; makefile: 164
file content (299 lines) | stat: -rw-r--r-- 15,329 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Connection – The connection object &mdash; PyGreSQL 5.0 documentation</title>
    
    <link rel="stylesheet" href="../../_static/cloud.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygresql.css" type="text/css" />
    <link rel="stylesheet" href="//fonts.googleapis.com/css?family=Noticia+Text|Open+Sans|Droid+Sans+Mono" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '5.0.3',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../_static/jquery.cookie.js"></script>
    <script type="text/javascript" src="../../_static/cloud.js"></script>
    <link rel="shortcut icon" href="../../_static/favicon.ico"/>
    <link rel="copyright" title="Copyright" href="../../copyright.html" />
    <link rel="top" title="PyGreSQL 5.0 documentation" href="../index.html" />
    <link rel="up" title="pgdb — The DB-API Compliant Interface" href="index.html" />
    <link rel="next" title="Cursor – The cursor object" href="cursor.html" />
    <link rel="prev" title="Module functions and constants" href="module.html" /> 
        <meta name="viewport" content="width=device-width, initial-scale=1">
  </head>
  <body role="document">
<div class="pageheader related" role="navigation" aria-label="related navigation">
  <ul>
    <li><a href="../../index.html">Home</a></li>
    <li><a href="../../download/index.html">Download</a></li>
    <li><a href="../index.html">Documentation</a></li>
    <li><a href="../../community/index.html">Community</a></li>
  </ul>
  <div class="logo">
    <a href="../../index.html">PyGreSQL</a>
  </div>
</div>

</div>

    <div class="relbar-top">
        
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> &nbsp; &nbsp;</li>
        <li class="right" >
          <a href="cursor.html" title="Cursor – The cursor object"
             accesskey="N">next</a> &nbsp; &nbsp;</li>
        <li class="right" >
          <a href="module.html" title="Module functions and constants"
             accesskey="P">previous</a> &nbsp; &nbsp;</li>
    <li><a href="../index.html">PyGreSQL 5.0 documentation</a> &raquo;</li>

          <li class="nav-item nav-item-1"><a href="index.html" accesskey="U"><code class="docutils literal"><span class="pre">pgdb</span></code> &#8212; The DB-API Compliant Interface</a> &raquo;</li> 
      </ul>
    </div>
    </div>

  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="connection-the-connection-object">
<h1>Connection &#8211; The connection object<a class="headerlink" href="#connection-the-connection-object" title="Permalink to this headline">¶</a></h1>
<dl class="class">
<dt id="pgdb.Connection">
<em class="property">class </em><code class="descclassname">pgdb.</code><code class="descname">Connection</code><a class="headerlink" href="#pgdb.Connection" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>These connection objects respond to the following methods.</p>
<p>Note that <code class="docutils literal"><span class="pre">pgdb.Connection</span></code> objects also implement the context manager protocol,
i.e. you can use them in a <code class="docutils literal"><span class="pre">with</span></code> statement.</p>
<div class="section" id="close-close-the-connection">
<h2>close &#8211; close the connection<a class="headerlink" href="#close-close-the-connection" title="Permalink to this headline">¶</a></h2>
<dl class="method">
<dt id="pgdb.Connection.close">
<code class="descclassname">Connection.</code><code class="descname">close</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pgdb.Connection.close" title="Permalink to this definition">¶</a></dt>
<dd><p>Close the connection now (rather than whenever it is deleted)</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">None</td>
</tr>
</tbody>
</table>
</dd></dl>

<p>The connection will be unusable from this point forward; an <a class="reference internal" href="module.html#pgdb.Error" title="pgdb.Error"><code class="xref py py-exc docutils literal"><span class="pre">Error</span></code></a>
(or subclass) exception 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 an implicit rollback to be performed.</p>
</div>
<div class="section" id="commit-commit-the-connection">
<h2>commit &#8211; commit the connection<a class="headerlink" href="#commit-commit-the-connection" title="Permalink to this headline">¶</a></h2>
<dl class="method">
<dt id="pgdb.Connection.commit">
<code class="descclassname">Connection.</code><code class="descname">commit</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pgdb.Connection.commit" title="Permalink to this definition">¶</a></dt>
<dd><p>Commit any pending transaction to the database</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">None</td>
</tr>
</tbody>
</table>
</dd></dl>

<p>Note that connections always use a transaction, there is no auto-commit.</p>
</div>
<div class="section" id="rollback-roll-back-the-connection">
<h2>rollback &#8211; roll back the connection<a class="headerlink" href="#rollback-roll-back-the-connection" title="Permalink to this headline">¶</a></h2>
<dl class="method">
<dt id="pgdb.Connection.rollback">
<code class="descclassname">Connection.</code><code class="descname">rollback</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pgdb.Connection.rollback" title="Permalink to this definition">¶</a></dt>
<dd><p>Roll back any pending transaction to the database</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">None</td>
</tr>
</tbody>
</table>
</dd></dl>

<p>This method causes the database to 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.</p>
</div>
<div class="section" id="cursor-return-a-new-cursor-object">
<h2>cursor &#8211; return a new cursor object<a class="headerlink" href="#cursor-return-a-new-cursor-object" title="Permalink to this headline">¶</a></h2>
<dl class="method">
<dt id="pgdb.Connection.cursor">
<code class="descclassname">Connection.</code><code class="descname">cursor</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pgdb.Connection.cursor" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a new cursor object using the connection</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">a connection object</td>
</tr>
<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body"><a class="reference internal" href="cursor.html#pgdb.Cursor" title="pgdb.Cursor"><code class="xref py py-class docutils literal"><span class="pre">Cursor</span></code></a></td>
</tr>
</tbody>
</table>
</dd></dl>

<p>This method returns a new <a class="reference internal" href="cursor.html#pgdb.Cursor" title="pgdb.Cursor"><code class="xref py py-class docutils literal"><span class="pre">Cursor</span></code></a> object that can be used to
operate on the database in the way described in the next section.</p>
</div>
<div class="section" id="attributes-that-are-not-part-of-the-standard">
<h2>Attributes that are not part of the standard<a class="headerlink" href="#attributes-that-are-not-part-of-the-standard" title="Permalink to this headline">¶</a></h2>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The following attributes are not part of the DB-API 2 standard.</p>
</div>
<dl class="attribute">
<dt id="pgdb.Connection.closed">
<code class="descclassname">Connection.</code><code class="descname">closed</code><a class="headerlink" href="#pgdb.Connection.closed" title="Permalink to this definition">¶</a></dt>
<dd><p>This is <em>True</em> if the connection has been closed or has become invalid</p>
</dd></dl>

<dl class="attribute">
<dt id="pgdb.Connection.cursor_type">
<code class="descclassname">Connection.</code><code class="descname">cursor_type</code><a class="headerlink" href="#pgdb.Connection.cursor_type" title="Permalink to this definition">¶</a></dt>
<dd><p>The default cursor type used by the connection</p>
</dd></dl>

<p>If you want to use your own custom subclass of the <a class="reference internal" href="cursor.html#pgdb.Cursor" title="pgdb.Cursor"><code class="xref py py-class docutils literal"><span class="pre">Cursor</span></code></a> class
with he connection, set this attribute to your custom cursor class. You will
then get your custom cursor whenever you call <a class="reference internal" href="#pgdb.Connection.cursor" title="pgdb.Connection.cursor"><code class="xref py py-meth docutils literal"><span class="pre">Connection.cursor()</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 5.0.</span></p>
</div>
<dl class="attribute">
<dt id="pgdb.Connection.type_cache">
<code class="descclassname">Connection.</code><code class="descname">type_cache</code><a class="headerlink" href="#pgdb.Connection.type_cache" title="Permalink to this definition">¶</a></dt>
<dd><p>A dictionary with the various type codes for the PostgreSQL types</p>
</dd></dl>

<p>This can be used for getting more information on the PostgreSQL database
types or changing the typecast functions used for the connection.  See the
description of the <a class="reference internal" href="typecache.html#pgdb.TypeCache" title="pgdb.TypeCache"><code class="xref py py-class docutils literal"><span class="pre">TypeCache</span></code></a> class for details.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 5.0.</span></p>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
        <p class="logo"><a href="../index.html" title="contents/index">
          <img class="logo" src="../../_static/pygresql.png" alt="Logo"/>
        </a></p><div class="sphinxlocaltoc">
    <h3><a href="../../index.html">Page contents</a></h3>
    <ul>
<li><a class="reference internal" href="#">Connection &#8211; The connection object</a><ul>
<li><a class="reference internal" href="#close-close-the-connection">close &#8211; close the connection</a></li>
<li><a class="reference internal" href="#commit-commit-the-connection">commit &#8211; commit the connection</a></li>
<li><a class="reference internal" href="#rollback-roll-back-the-connection">rollback &#8211; roll back the connection</a></li>
<li><a class="reference internal" href="#cursor-return-a-new-cursor-object">cursor &#8211; return a new cursor object</a></li>
<li><a class="reference internal" href="#attributes-that-are-not-part-of-the-standard">Attributes that are not part of the standard</a></li>
</ul>
</li>
</ul>

  </div>
  <div class="sphinxprev">
    <h4>Previous page</h4>
    <p class="topless"><a href="module.html"
                          title="Previous page">&larr; Module functions and constants</a></p>
  </div>
  <div class="sphinxnext">
    <h4>Next page</h4>
    <p class="topless"><a href="cursor.html"
                          title="Next page">&rarr; Cursor &#8211; The cursor object</a></p>
  </div>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/contents/pgdb/connection.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="relbar-bottom">
        
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> &nbsp; &nbsp;</li>
        <li class="right" >
          <a href="cursor.html" title="Cursor – The cursor object"
             >next</a> &nbsp; &nbsp;</li>
        <li class="right" >
          <a href="module.html" title="Module functions and constants"
             >previous</a> &nbsp; &nbsp;</li>
    <li><a href="../index.html">PyGreSQL 5.0 documentation</a> &raquo;</li>

          <li class="nav-item nav-item-1"><a href="index.html" ><code class="docutils literal"><span class="pre">pgdb</span></code> &#8212; The DB-API Compliant Interface</a> &raquo;</li> 
      </ul>
    </div>
    </div>

    <div class="footer" role="contentinfo">
        &copy; <a href="../../copyright.html">Copyright</a> 2016, The PyGreSQL team.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.1.
    </div>
    <!-- cloud_sptheme 1.4 -->
  </body>
</html>