1 <!-- $Header: /cvsroot/pgsql/doc/src/sgml/Attic/pygresql.sgml,v 1.4 2001/11/19 03:58:24 tgl Exp $ -->
3 <chapter id="pygresql">
4 <title><application>PyGreSQL</application> - <application>Python</application> Interface</title>
9 Written by D'Arcy J.M. Cain (<email>darcy@druid.net</email>).
10 Based heavily on code written by Pascal Andre
11 <email>andre@chimay.via.ecp.fr</email>. Copyright © 1995,
12 Pascal Andre. Further modifications Copyright © 1997-2000 by
19 <sect1 id="pygresql-install">
20 <title>Installation</title>
25 If you are on <acronym>NetBSD</acronym>, look in the packages
26 directory under databases. If it isn't there yet, it should be
27 there shortly. You can also pick up the package files from
28 <ulink url="ftp://ftp.druid.net/pub/distrib/pygresql.pkg.tgz"
29 >ftp://ftp.druid.net/pub/distrib/pygresql.pkg.tgz</ulink>. There
30 is also a package in the <acronym>FreeBSD</acronym> ports
31 collection but as I write this it is at version 2.1. I will try
32 to get that updated as well.
38 For Linux installation look at <filename>README.linux</filename>.
39 If you're on an <acronym>x86</acronym> system that uses
40 <acronym>RPMs</acronym>, then you can pick up an
41 <acronym>RPM</acronym> at <ulink
42 url="ftp://ftp.druid.net/pub/distrib/pygresql.i386.rpm"
43 >ftp://ftp.druid.net/pub/distrib/pygresql.i386.rpm</ulink>.
49 Note that if you are using the <acronym>DB-API</acronym> module
50 you must also install <acronym>mxDateTime</acronym> from <ulink
51 url="http://starship.python.net/~lemburg/mxDateTime.html"
52 >http://starship.python.net/~lemburg/mxDateTime.html</ulink>.
58 Also, check out <filename>setup.py</filename> for an alternate
59 method of installing the package using Python's Distutils.
66 You have two options. You can compile
67 <productname>PyGreSQL</productname> as a stand-alone module or you
68 can build it into the <productname>Python</productname>
73 <title>General</title>
78 You must first have installed <productname>Python</productname>
79 and <productname>PostgreSQL</productname> on your system. The
80 header files and developer's libraries for both
81 <productname>Python</productname> and
82 <productname>PostgreSQL</productname> must be installed on your
83 system before you can build <productname>PyGreSQL</productname>.
84 If you built both <productname>Python</productname> and
85 <productname>PostgreSQL</productname> from source, you should be
86 fine. If your system uses some package mechanism (such as
87 <acronym>RPM</acronym> or <acronym>NetBSD</acronym> packages),
88 then you probably need to install packages such as
89 <acronym>Python-devel</acronym> in addition to the
90 <productname>Python</productname> package.
96 <productname>PyGreSQL</productname> is implemented as three
97 parts, a C module labeled <acronym>_pg</acronym> and two
98 <productname>Python</productname> wrappers called
99 <filename>pg.py</filename> and <filename>pgdb.py</filename>.
100 This changed between 2.1 and 2.2 and again in 3.0. These
101 changes should not affect any existing programs but the
102 installation is slightly different.
108 Download and unpack the <productname>PyGreSQL</productname>
109 tarball if you haven't already done so.
116 <title>Stand-alone</title>
121 In the directory containing <filename>pgmodule.c</filename>, run
122 the following command
125 cc -fpic -shared -o _pg.so -I[pyInc] -I[pgInc] -L[pgLib] -lpq pgmodule.c
132 [pyInc] = path of the <productname>Python</productname>
133 include (usually <filename>Python.h</filename>)
139 [pgInc] = path of the <productname>PostgreSQL</productname>
140 include (usually <filename>postgres.h</filename>)
146 [pgLib] = path of the <productname>PostgreSQL</productname>
147 libraries (usually <filename>libpq.so</filename> or
148 <filename>libpq.a</filename>)
153 Some options may be added to this line:
157 <literal>-DNO_DEF_VAR</literal> - no default variables
164 <literal>-DNO_DIRECT</literal> - no direct access methods
170 <literal>-DNO_LARGE</literal> - no large object support
176 <literal>-DNO_SNPRINTF</literal> - if running a system with
183 <literal>-DNO_PQSOCKET</literal> - if running an older
184 <productname>PostgreSQL</productname>
189 On some systems you may need to include
190 <literal>-lcrypt</literal> in the list of libraries to make it
193 Define <literal>DNO_PQSOCKET</literal> if you are using a
194 version of <productname>PostgreSQL</productname> before 6.4 that
195 does not have the <function>PQsocket</function> function. The
196 other options will be described in the next sections.
202 Test the new module. Something like the following should work.
204 <prompt>$</prompt> <userinput>python</userinput>
206 <prompt>>>></prompt> <userinput>import _pg</userinput>
207 <prompt>>>></prompt> <userinput>db = _pg.connect('thilo', 'localhost')</userinput>
208 <prompt>>>></prompt> <userinput>db.query("INSERT INTO test VALUES ('ping', 'pong');")</userinput>
210 <prompt>>>></prompt> <userinput>db.query("SELECT * FROM test;")</userinput>
220 Finally, move the <filename>_pg.so</filename>,
221 <filename>pg.py</filename>, and <filename>pgdb.py</filename>
222 to a directory in your <literal>PYTHONPATH</literal>.
223 A good place would be
224 <filename>/usr/lib/python1.5/site-python</filename>
225 if your <productname>Python</productname> modules are in
226 <filename>/usr/lib/python1.5</filename>.
234 <title>Built-in to python interpreter</title>
239 Find the directory where your <filename>Setup</filename>
240 file lives (usually <filename>??/Modules</filename>) in
241 the <productname>Python</productname> source hierarchy and
242 copy or symlink the <filename>pgmodule.c</filename> file there.
247 Add the following line to your Setup file
249 _pg pgmodule.c -I[pgInc] -L[pgLib] -lpq # -lcrypt # needed on some systems
255 [pgInc] = path of the <productname>PostgreSQL</productname>
256 include (usually <filename>postgres.h</filename>)
261 [pgLib] = path of the <productname>PostgreSQL</productname>
262 libraries (usually <filename>libpq.so</filename>
263 or <filename>libpq.a</filename>)
267 Some options may be added to this line:
271 <literal>-DNO_DEF_VAR</literal> - no default variables
277 <literal>-DNO_DIRECT</literal> - no direct access methods
282 <literal>-DNO_LARGE</literal> - no large object support
287 <literal>-DNO_SNPRINTF</literal> - if running a system with
293 <literal>-DNO_PQSOCKET</literal> - if running an older
294 <productname>PostgreSQL</productname>
299 Define <literal>DNO_PQSOCKET</literal> if you are using a version of
300 <productname>PostgreSQL</productname> before 6.4
301 that does not have the <function>PQsocket</function> function.
302 The other options will be described in the next sections.
307 If you want a shared module, make sure that the
308 <literal>*shared*</literal> keyword is uncommented and
309 add the above line below it. You used to need to install
310 your shared modules with <literal>make sharedinstall</> but this no
311 longer seems to be true.
316 Copy <filename>pg.py</filename> to the lib directory where
317 the rest of your modules are. For example, that's
318 <filename>/usr/local/lib/Python</filename> on my system.
323 Rebuild <productname>Python</productname> from the root
324 directory of the <productname>Python</productname> source
327 make -f Makefile.pre.in boot
334 For more details read the documentation at the top of
335 <filename>Makefile.pre.in</filename>
345 <sect1 id="pygresql-pg">
346 <title>The <literal>pg</literal> Module</title>
349 You may either choose to use the old mature interface provided by
350 the <literal>pg</literal> module or otherwise the newer
351 <literal>pgdb</literal> interface compliant with the <ulink
352 url="http://www.python.org/topics/database/DatabaseAPI-2.0.html"
353 ><acronym>DB-API 2.0</acronym></ulink> specification developed by
354 the <productname>Python</productname> <acronym>DB-SIG</acronym>.
358 Here we describe only the older <literal>pg</literal>
359 <acronym>API</acronym>. As long as
360 <productname>PyGreSQL</productname> does not contain a description
361 of the <acronym>DB-API</acronym> you should read about the
362 <acronym>API</acronym> at <ulink
363 url="http://www.python.org/topics/database/DatabaseAPI-2.0.html"
364 >http://www.python.org/topics/database/DatabaseAPI-2.0.html</ulink>.
368 A tutorial-like introduction to the <acronym>DB-API</acronym> can
370 url="http://www2.linuxjournal.com/lj-issues/issue49/2605.html"
371 >http://www2.linuxjournal.com/lj-issues/issue49/2605.html</ulink>
375 The <literal>pg</literal> module defines three objects:
379 <classname>pgobject</classname>, which handles the connection and all the
380 requests to the database,
386 <classname>pglargeobject</classname>, which handles all the accesses
387 to <productname>Postgres</productname> large objects, and
393 <literal>pgqueryobject</literal> that handles query results.
400 If you want to see a simple example of the use of some of these
401 functions, see <ulink url="http://www.druid.net/rides"
402 >http://www.druid.net/rides</ulink> where I have a link at the
403 bottom to the actual <productname>Python</productname> code for the
408 <title>Constants</title>
411 Some constants are defined in the <literal>pg</literal> module
412 dictionary. They are intended to be used as a parameters for
413 methods calls. You should refer to the <literal>libpq</literal>
414 description (<xref linkend="libpq">) for more information about
415 them. These constants are:
419 <term><varname>INV_READ</varname></term>
420 <term><varname>INV_WRITE</varname></term>
423 large objects access modes, used by
424 <function>(pgobject.)locreate</function> and
425 <function>(pglarge.)open</function>.
431 <term><varname>SEEK_SET</varname></term>
432 <term><varname>SEEK_CUR</varname></term>
433 <term><varname>SEEK_END</varname></term>
436 positional flags, used by <function>(pglarge.)seek</function>.
442 <term><varname>version</varname></term>
443 <term><varname>__version__</varname></term>
446 constants that give the current version
456 <sect1 id="pygresql-pg-functions">
457 <title><literal>pg</literal> Module Functions</title>
460 <literal>pg</literal> module defines only a few methods that allow
461 to connect to a database and to define <quote>default
462 variables</quote> that override the environment variables used by
463 <productname>PostgreSQL</productname>.
467 These <quote>default variables</quote> were designed to allow you
468 to handle general connection parameters without heavy code in your
469 programs. You can prompt the user for a value, put it in the
470 default variable, and forget it, without having to modify your
471 environment. The support for default variables can be disabled by
472 setting the <acronym>-DNO_DEF_VAR</acronym> option in the Python
473 Setup file. Methods relative to this are specified by te tag [DV].
477 All variables are set to <symbol>None</symbol> at module
478 initialization, specifying that standard environment variables
482 <refentry id="pygresql-connect">
484 <refentrytitle>connect</refentrytitle>
485 <refmiscinfo>PYGRESQL - Connection Management</refmiscinfo>
489 <refname>connect</refname>
490 <refpurpose>opens a connection to the database server</refpurpose>
495 connect(<optional><replaceable>dbname</replaceable></optional>, <optional><replaceable>host</replaceable></optional>, <optional><replaceable>port</replaceable></optional>, <optional><replaceable>opt</replaceable></optional>, <optional><replaceable>tty</replaceable></optional>, <optional><replaceable>user</replaceable></optional>, <optional><replaceable>passwd</replaceable></optional>)
498 <refsect2 id="pygresql-connect-parameters">
499 <title>Parameters</title>
503 <term><replaceable>dbname</replaceable></term>
506 <para>Name of connected database (string/None).</para>
511 <term><replaceable>host</replaceable></term>
514 <para>Name of the server host (string/None).</para>
519 <term><replaceable>port</replaceable></term>
522 <para>Port used by the database server (integer/-1).</para>
527 <term><replaceable>opt</replaceable></term>
531 Options for the server (string/None).
537 <term><replaceable>tty</replaceable></term>
541 File or tty for optional debug output from backend
548 <term><replaceable>user</replaceable></term>
552 <productname>PostgreSQL</productname> user (string/None).
558 <term><replaceable>passwd</replaceable></term>
561 <para>Password for user (string/None).</para>
567 <refsect2 id="pygresql-connect-return">
568 <title>Return Type</title>
572 <term><replaceable>pgobject</replaceable></term>
576 If successful, an object handling a database connection is returned.
583 <refsect2 id="pygresql-connect-exceptions">
584 <title>Exceptions</title>
588 <term><errorname>TypeError</errorname></term>
592 Bad argument type, or too many arguments.
598 <term><errorname>SyntaxError</errorname></term>
602 Duplicate argument definition.
608 <term><errorname>pg.error</errorname></term>
612 Some error occurred during pg connection definition.
619 (+ all exceptions relative to object allocation)
624 <refsect1 id="pygresql-connect-description">
625 <title>Description</title>
628 This method opens a connection to a specified database on a given
629 <productname>PostgreSQL</productname> server. You can use
630 keywords here, as described in the
631 <productname>Python</productname> tutorial. The names of the
632 keywords are the name of the parameters given in the syntax
633 line. For a precise description of the parameters, please refer
634 to the <productname>PostgreSQL</productname> user manual.
638 <refsect1 id="pygresql-connect-examples">
639 <title>Examples</title>
645 con1 = pg.connect('testdb', 'myhost', 5432, None, None, 'bob', None)
646 con2 = pg.connect(dbname='testdb', host='localhost', user='bob')
654 <refentry id="pygresql-get-defhost">
656 <refentrytitle>get_defhost</refentrytitle>
657 <refmiscinfo>PYGRESQL - Connection Management</refmiscinfo>
661 <refname>get_defhost</refname>
662 <refpurpose>get default host name [DV]</refpurpose>
670 <refsect2 id="pygresql-get-defhost-parameters">
671 <title>Parameters</title>
678 <refsect2 id="pygresql-get-defhost-return">
679 <title>Return Type</title>
683 <term>string or None</term>
687 Default host specification
694 <refsect2 id="pygresql-get-defhost-exceptions">
695 <title>Exceptions</title>
699 <term><errorname>SyntaxError</errorname></term>
712 <refsect1 id="pygresql-get-defhost-description">
713 <title>Description</title>
716 <function>get_defhost()</function> returns the current default
717 host specification, or None if the environment variables should
718 be used. Environment variables will not be looked up.
725 <refentry id="pygresql-set-defhost">
727 <refentrytitle>set_defhost</refentrytitle>
728 <refmiscinfo>PYGRESQL - Connection Management</refmiscinfo>
731 <refname>set_defhost</refname>
732 <refpurpose>set default host name [DV]</refpurpose>
737 set_defhost(<replaceable>host</replaceable>)
740 <refsect2 id="pygresql-set-defhost-parameters">
741 <title>Parameters</title>
745 <replaceable>host</replaceable>
748 <para>New default host (string/None).</para>
754 <refsect2 id="pygresql-set-defhost-return">
755 <title>Return Type</title>
763 Previous default host specification.
770 <refsect2 id="pygresql-set-defhost-exceptions">
771 <title>Exceptions</title>
775 <errorname>TypeError</errorname>
779 Bad argument type, or too many arguments.
788 <refsect1 id="pygresql-set-defhost-description">
789 <title>Description</title>
791 <function>set_defhost()</function> sets the default host value
792 for new connections. If None is supplied as parameter, environment
793 variables will be used in future connections. It returns the
794 previous setting for default host.
800 <!-- ********************************************************** -->
802 <refentry id="pygresql-get-defport">
804 <refentrytitle>get_defport</refentrytitle>
805 <refmiscinfo>PYGRESQL - Connection Management</refmiscinfo>
808 <refname>get_defport</refname>
809 <refpurpose>get default port [DV]</refpurpose>
817 <refsect2 id="R2-PYGRESQL-GET-DEFPORT-1">
818 <title>Parameters</title>
824 <refsect2 id="R2-PYGRESQL-GET-DEFPORT-2">
825 <title>Return Type</title>
833 Default port specification
840 <refsect2 id="R2-PYGRESQL-GET-DEFPORT-3">
841 <title>Exceptions</title>
845 <errorname>SyntaxError</errorname>
858 <refsect1 id="R1-PYGRESQL-GET-DEFPORT-1">
859 <title>Description</title>
861 <function>get_defport()</function> returns the current default
862 port specification, or None if the environment variables should
863 be used. Environment variables will not be looked up.
869 <!-- ********************************************************** -->
871 <refentry id="PYGRESQL-SET-DEFPORT">
873 <refentrytitle>set_defport</refentrytitle>
874 <refmiscinfo>PYGRESQL - Connection Management</refmiscinfo>
877 <refname>set_defport</refname>
878 <refpurpose>set default port [DV]</refpurpose>
883 set_defport(<replaceable>port</replaceable>)
886 <refsect2 id="R2-PYGRESQL-SET-DEFPORT-1">
887 <title>Parameters</title>
891 <replaceable>port</replaceable>
894 <para>New default host (integer/-1).</para>
900 <refsect2 id="R2-PYGRESQL-SET-DEFPORT-2">
901 <title>Return Type</title>
909 Previous default port specification.
916 <refsect2 id="R2-PYGRESQL-SET-DEFPORT-3">
917 <title>Exceptions</title>
921 <errorname>TypeError</errorname>
925 Bad argument type, or too many arguments.
934 <refsect1 id="R1-PYGRESQL-SET-DEFPORT-1">
935 <title>Description</title>
937 <function>set_defport()</function> sets the default port value
938 for new connections. If -1 is supplied as parameter, environment
939 variables will be used in future connections. It returns the
940 previous setting for default port.
946 <!-- ********************************************************** -->
948 <refentry id="PYGRESQL-GET-DEFOPT">
950 <refentrytitle>get_defopt</refentrytitle>
951 <refmiscinfo>PYGRESQL - Connection Management</refmiscinfo>
954 <refname>get_defopt</refname>
955 <refpurpose>get default options specification [DV]</refpurpose>
963 <refsect2 id="R2-PYGRESQL-GET-DEFOPT-1">
964 <title>Parameters</title>
970 <refsect2 id="R2-PYGRESQL-GET-DEFOPT-2">
971 <title>Return Type</title>
979 Default options specification
986 <refsect2 id="R2-PYGRESQL-GET-DEFOPT-3">
987 <title>Exceptions</title>
991 <errorname>SyntaxError</errorname>
1004 <refsect1 id="R1-PYGRESQL-GET-DEFOPT-1">
1005 <title>Description</title>
1007 <function>get_defopt()</function> returns the current default
1008 connection options specification, or None if the environment variables should
1009 be used. Environment variables will not be looked up.
1015 <!-- ********************************************************** -->
1017 <refentry id="PYGRESQL-SET-DEFOPT">
1019 <refentrytitle>set_defopt</refentrytitle>
1020 <refmiscinfo>PYGRESQL - Connection Management</refmiscinfo>
1023 <refname>set_defopt</refname>
1024 <refpurpose>set options specification [DV]</refpurpose>
1029 set_defopt(<replaceable>options</replaceable>)
1032 <refsect2 id="R2-PYGRESQL-SET-DEFOPT-1">
1033 <title>Parameters</title>
1037 <replaceable>options</replaceable>
1040 <para>New default connection options (string/None).</para>
1046 <refsect2 id="R2-PYGRESQL-SET-DEFOPT-2">
1047 <title>Return Type</title>
1055 Previous default opt specification.
1062 <refsect2 id="R2-PYGRESQL-SET-DEFOPT-3">
1063 <title>Exceptions</title>
1067 <errorname>TypeError</errorname>
1071 Bad argument type, or too many arguments.
1080 <refsect1 id="R1-PYGRESQL-SET-DEFOPT-1">
1081 <title>Description</title>
1083 <function>set_defopt()</function> sets the default connection options value
1084 for new connections. If None is supplied as parameter, environment
1085 variables will be used in future connections. It returns the
1086 previous setting for default options.
1092 <!-- ********************************************************** -->
1094 <refentry id="PYGRESQL-GET-DEFTTY">
1096 <refentrytitle>get_deftty</refentrytitle>
1097 <refmiscinfo>PYGRESQL - Connection Management</refmiscinfo>
1100 <refname>get_deftty</refname>
1101 <refpurpose>get default connection debug terminal specification [DV]</refpurpose>
1109 <refsect2 id="R2-PYGRESQL-GET-DEFTTY-1">
1110 <title>Parameters</title>
1116 <refsect2 id="R2-PYGRESQL-GET-DEFTTY-2">
1117 <title>Return Type</title>
1125 Default debug terminal specification
1132 <refsect2 id="R2-PYGRESQL-GET-DEFTTY-3">
1133 <title>Exceptions</title>
1137 <errorname>SyntaxError</errorname>
1150 <refsect1 id="R1-PYGRESQL-GET-DEFTTY-1">
1151 <title>Description</title>
1153 <function>get_deftty()</function> returns the current default
1154 debug terminal specification, or None if the environment variables should
1155 be used. Environment variables will not be looked up.
1161 <!-- ********************************************************** -->
1163 <refentry id="PYGRESQL-SET-DEFTTY">
1165 <refentrytitle>set_deftty</refentrytitle>
1166 <refmiscinfo>PYGRESQL - Connection Management</refmiscinfo>
1169 <refname>set_deftty</refname>
1170 <refpurpose>set default debug terminal specification [DV]</refpurpose>
1175 set_deftty(<replaceable>terminal</replaceable>)
1178 <refsect2 id="R2-PYGRESQL-SET-DEFTTY-1">
1179 <title>Parameters</title>
1183 <replaceable>terminal</replaceable>
1186 <para>New default debug terminal (string/None).</para>
1192 <refsect2 id="R2-PYGRESQL-SET-DEFTTY-2">
1193 <title>Return Type</title>
1201 Previous default debug terminal specification.
1208 <refsect2 id="R2-PYGRESQL-SET-DEFTTY-3">
1209 <title>Exceptions</title>
1213 <errorname>TypeError</errorname>
1217 Bad argument type, or too many arguments.
1226 <refsect1 id="R1-PYGRESQL-SET-DEFTTY-1">
1227 <title>Description</title>
1229 <function>set_deftty()</function> sets the default terminal value
1230 for new connections. If None is supplied as parameter, environment
1231 variables will be used in future connections. It returns the
1232 previous setting for default terminal.
1238 <!-- ********************************************************** -->
1240 <refentry id="PYGRESQL-GET-DEFBASE">
1242 <refentrytitle>get_defbase</refentrytitle>
1243 <refmiscinfo>PYGRESQL - Connection Management</refmiscinfo>
1246 <refname>get_defbase</refname>
1247 <refpurpose>get default database name specification [DV]</refpurpose>
1255 <refsect2 id="R2-PYGRESQL-GET-DEFBASE-1">
1256 <title>Parameters</title>
1262 <refsect2 id="R2-PYGRESQL-GET-DEFBASE-2">
1263 <title>Return Type</title>
1271 Default debug database name specification
1278 <refsect2 id="R2-PYGRESQL-GET-DEFBASE-3">
1279 <title>Exceptions</title>
1283 <errorname>SyntaxError</errorname>
1296 <refsect1 id="R1-PYGRESQL-GET-DEFBASE-1">
1297 <title>Description</title>
1299 <function>get_defbase()</function> returns the current default
1300 database name specification, or None if the environment variables should
1301 be used. Environment variables will not be looked up.
1307 <!-- ********************************************************** -->
1309 <refentry id="PYGRESQL-SET-DEFBASE">
1311 <refentrytitle>set_defbase</refentrytitle>
1312 <refmiscinfo>PYGRESQL - Connection Management</refmiscinfo>
1315 <refname>set_defbase</refname>
1316 <refpurpose>set default database name specification [DV]</refpurpose>
1321 set_defbase(<replaceable>database</replaceable>)
1324 <refsect2 id="R2-PYGRESQL-SET-DEFBASE-1">
1325 <title>Parameters</title>
1329 <replaceable>database</replaceable>
1332 <para>New default database name (string/None).</para>
1338 <refsect2 id="R2-PYGRESQL-SET-DEFBASE-2">
1339 <title>Return Type</title>
1347 Previous default database name specification.
1354 <refsect2 id="R2-PYGRESQL-SET-DEFBASE-3">
1355 <title>Exceptions</title>
1359 <errorname>TypeError</errorname>
1363 Bad argument type, or too many arguments.
1372 <refsect1 id="R1-PYGRESQL-SET-DEFBASE-1">
1373 <title>Description</title>
1375 <function>set_defbase()</function> sets the default database name
1376 for new connections. If None is supplied as parameter, environment
1377 variables will be used in future connections. It returns the
1378 previous setting for default database name.
1387 <sect1 id="pygresql-pg-pgobject">
1388 <title>Connection object: <classname>pgobject</classname></title>
1391 This object handles a connection to the
1392 <productname>PostgreSQL</productname> database. It embeds and
1393 hides all the parameters that define this connection, leaving just
1394 really significant parameters in function calls.
1398 Some methods give direct access to the connection socket. They are
1399 specified by the tag [DA]. <emphasis>Do not use them unless you
1400 really know what you are doing.</emphasis> If you prefer disabling
1401 them, set the <literal>-DNO_DIRECT</literal> option in the
1402 <productname>Python</productname> <filename>Setup</filename> file.
1406 Some other methods give access to large objects. if you want to
1407 forbid access to these from the module, set the
1408 <literal>-DNO_LARGE</literal> option in the
1409 <productname>Python</productname> <filename>Setup</filename> file.
1410 These methods are specified by the tag [LO].
1414 Every <literal>pgobject</literal> defines a set of read-only
1415 attributes that describe the connection and its status. These
1423 the host name of the server (string)
1432 the port of the server (integer)
1441 the selected database (string)
1447 <term>options</term>
1450 the connection options (string)
1459 the connection debug terminal (string)
1468 user name on the database system (string)
1477 the status of the connection (integer: 1 - OK, 0 - BAD)
1486 the last warning/error message from the server (string)
1494 <refentry id="PYGRESQL-QUERY">
1496 <refentrytitle>query</refentrytitle>
1497 <refmiscinfo>PYGRESQL - Query</refmiscinfo>
1500 <refname>query</refname>
1501 <refpurpose>executes a SQL command</refpurpose>
1506 query(<replaceable>command</replaceable>)
1509 <refsect2 id="R2-PYGRESQL-QUERY-1">
1510 <title>Parameters</title>
1514 <replaceable>command</replaceable>
1517 <para>SQL command (string).</para>
1523 <refsect2 id="R2-PYGRESQL-QUERY-2">
1524 <title>Return Type</title>
1528 pgqueryobject or None
1539 <refsect2 id="R2-PYGRESQL-QUERY-3">
1540 <title>Exceptions</title>
1544 <errorname>TypeError</errorname>
1548 Bad argument type, or too many arguments.
1554 <errorname>ValueError</errorname>
1564 <errorname>pg.error</errorname>
1568 Error during query processing, or invalid connection.
1577 <refsect1 id="R1-PYGRESQL-QUERY-1">
1578 <title>Description</title>
1580 <function>query()</function> method sends a <acronym>SQL</acronym>
1581 query to the database. If the query is an insert statement, the return
1582 value is the <acronym>OID</acronym> of the newly inserted row.
1583 If it is otherwise a query that does not return a result
1584 (i.e., is not a some kind of <literal>SELECT</literal> statement), it returns None.
1585 Otherwise, it returns a <literal>pgqueryobject</literal> that can be accessed via the
1586 <function>getresult()</function> or <function>dictresult()</function>
1587 methods or simply printed.
1593 <!-- ********************************************************** -->
1595 <refentry id="PYGRESQL-RESET">
1597 <refentrytitle>reset</refentrytitle>
1598 <refmiscinfo>PYGRESQL - Reset</refmiscinfo>
1601 <refname>reset</refname>
1602 <refpurpose>resets the connection</refpurpose>
1610 <refsect2 id="R2-PYGRESQL-RESET-1">
1611 <title>Parameters</title>
1617 <refsect2 id="R2-PYGRESQL-RESET-2">
1618 <title>Return Type</title>
1624 <refsect2 id="R2-PYGRESQL-RESET-3">
1625 <title>Exceptions</title>
1629 <errorname>TypeError</errorname>
1633 Too many (any) arguments.
1642 <refsect1 id="R1-PYGRESQL-RESET-1">
1643 <title>Description</title>
1645 <function>reset()</function> method resets the current database.
1651 <!-- ********************************************************** -->
1653 <refentry id="PYGRESQL-CLOSE">
1655 <refentrytitle>close</refentrytitle>
1656 <refmiscinfo>PYGRESQL - Close</refmiscinfo>
1659 <refname>close</refname>
1660 <refpurpose>close the database connection</refpurpose>
1668 <refsect2 id="R2-PYGRESQL-CLOSE-1">
1669 <title>Parameters</title>
1675 <refsect2 id="R2-PYGRESQL-CLOSE-2">
1676 <title>Return Type</title>
1682 <refsect2 id="R2-PYGRESQL-CLOSE-3">
1683 <title>Exceptions</title>
1687 <errorname>TypeError</errorname>
1691 Too many (any) arguments.
1700 <refsect1 id="R1-PYGRESQL-CLOSE-1">
1701 <title>Description</title>
1703 <function>close()</function> method closes the database connection.
1704 The connection will be closed in any case when the connection is deleted but this
1705 allows you to explicitly close it. It is mainly here to allow
1706 the DB-SIG API wrapper to implement a close function.
1712 <!-- ********************************************************** -->
1714 <refentry id="PYGRESQL-FILENO">
1716 <refentrytitle>fileno</refentrytitle>
1717 <refmiscinfo>PYGRESQL - Fileno</refmiscinfo>
1720 <refname>fileno</refname>
1721 <refpurpose>returns the socket used to connect to the database</refpurpose>
1729 <refsect2 id="R2-PYGRESQL-FILENO-1">
1730 <title>Parameters</title>
1736 <refsect2 id="R2-PYGRESQL-FILENO-2">
1737 <title>Return Type</title>
1745 The underlying socket id used to connect to the database.
1752 <refsect2 id="R2-PYGRESQL-FILENO-3">
1753 <title>Exceptions</title>
1757 <errorname>TypeError</errorname>
1761 Too many (any) arguments.
1770 <refsect1 id="R1-PYGRESQL-FILENO-1">
1771 <title>Description</title>
1773 <function>fileno()</function> method returns the underlying socket id used to connect
1774 to the database. This is useful for use in <function>select</function> calls, etc.
1780 <!-- ********************************************************** -->
1782 <refentry id="PYGRESQL-GETNOTIFY">
1784 <refentrytitle>getnotify</refentrytitle>
1785 <refmiscinfo>PYGRESQL - Getnotify</refmiscinfo>
1788 <refname>getnotify</refname>
1789 <refpurpose>gets the last notify from the server</refpurpose>
1797 <refsect2 id="R2-PYGRESQL-GETNOTIFY-1">
1798 <title>Parameters</title>
1804 <refsect2 id="R2-PYGRESQL-GETNOTIFY-2">
1805 <title>Return Type</title>
1813 Last notify from server
1820 <refsect2 id="R2-PYGRESQL-GETNOTIFY-3">
1821 <title>Exceptions</title>
1825 <errorname>TypeError</errorname>
1829 Too many (any) arguments.
1835 <errorname>pg.error</errorname>
1848 <refsect1 id="R1-PYGRESQL-GETNOTIFY-1">
1849 <title>Description</title>
1851 <function>getnotify()</function> method tries to get a notify from
1852 the server (from the <literal>SQL</literal> statement <literal>NOTIFY</literal>).
1853 If the server returns no notify, the methods returns None.
1854 Otherwise, it returns a tuple (couple) <literal>(relname, pid)</literal>,
1855 where <literal>relname</literal> is the name of the notify and <literal>pid</literal>
1856 the process id of the connection that triggered the notify.
1857 Remember to do a listen query first otherwise getnotify will always return None.
1863 <!-- ********************************************************** -->
1865 <refentry id="PYGRESQL-INSERTTABLE">
1867 <refentrytitle>inserttable</refentrytitle>
1868 <refmiscinfo>PYGRESQL - Inserttable</refmiscinfo>
1871 <refname>inserttable</refname>
1872 <refpurpose>inserts a list into a table</refpurpose>
1877 inserttable(<replaceable>table</replaceable>, <replaceable>values</replaceable>)
1880 <refsect2 id="R2-PYGRESQL-INSERTTABLE-1">
1881 <title>Parameters</title>
1885 <replaceable>table</replaceable>
1888 <para>The table name (string).</para>
1893 <replaceable>values</replaceable>
1896 <para>The list of rows values to insert (list).</para>
1902 <refsect2 id="R2-PYGRESQL-INSERTTABLE-2">
1903 <title>Return Type</title>
1909 <refsect2 id="R2-PYGRESQL-INSERTTABLE-3">
1910 <title>Exceptions</title>
1914 <errorname>TypeError</errorname>
1918 Bad argument type or too many (any) arguments.
1924 <errorname>pg.error</errorname>
1937 <refsect1 id="R1-PYGRESQL-INSERTTABLE-1">
1938 <title>Description</title>
1940 <function>inserttable()</function> method allows to quickly
1941 insert large blocks of data in a table: it inserts the whole
1942 values list into the given table. The list is a list of
1943 tuples/lists that define the values for each inserted row. The
1944 rows values may contain string, integer, long or double (real)
1945 values. <emphasis>Be very careful:</emphasis> this method
1946 does not typecheck the fields according to the table
1947 definition; it just look whether or not it knows how to handle
1954 <!-- ********************************************************** -->
1956 <refentry id="PYGRESQL-PUTLINE">
1958 <refentrytitle>putline</refentrytitle>
1959 <refmiscinfo>PYGRESQL - Putline</refmiscinfo>
1962 <refname>putline</refname>
1963 <refpurpose>writes a line to the server socket [DA]</refpurpose>
1968 putline(<replaceable>line</replaceable>)
1971 <refsect2 id="R2-PYGRESQL-PUTLINE-1">
1972 <title>Parameters</title>
1976 <replaceable>line</replaceable>
1979 <para>Line to be written (string).</para>
1985 <refsect2 id="R2-PYGRESQL-PUTLINE-2">
1986 <title>Return Type</title>
1992 <refsect2 id="R2-PYGRESQL-PUTLINE-3">
1993 <title>Exceptions</title>
1997 <errorname>TypeError</errorname>
2001 Bad argument type or too many (any) arguments.
2007 <errorname>pg.error</errorname>
2020 <refsect1 id="R1-PYGRESQL-PUTLINE-1">
2021 <title>Description</title>
2023 <function>putline()</function> method allows to directly write a string to the server socket.
2029 <!-- ********************************************************** -->
2031 <refentry id="PYGRESQL-GETLINE">
2033 <refentrytitle>getline</refentrytitle>
2034 <refmiscinfo>PYGRESQL - Getline</refmiscinfo>
2037 <refname>getline</refname>
2038 <refpurpose>gets a line from server socket [DA]</refpurpose>
2046 <refsect2 id="R2-PYGRESQL-GETLINE-1">
2047 <title>Parameters</title>
2053 <refsect2 id="R2-PYGRESQL-GETLINE-2">
2054 <title>Return Type</title>
2069 <refsect2 id="R2-PYGRESQL-GETLINE-3">
2070 <title>Exceptions</title>
2074 <errorname>TypeError</errorname>
2078 Bad argument type or too many (any) arguments.
2084 <errorname>pg.error</errorname>
2097 <refsect1 id="R1-PYGRESQL-GETLINE-1">
2098 <title>Description</title>
2100 <function>getline()</function> method allows to directly read a string from the server socket.
2106 <!-- ********************************************************** -->
2108 <refentry id="PYGRESQL-ENDCOPY">
2110 <refentrytitle>endcopy</refentrytitle>
2111 <refmiscinfo>PYGRESQL - Endcopy</refmiscinfo>
2114 <refname>endcopy</refname>
2115 <refpurpose>synchronizes client and server [DA]</refpurpose>
2123 <refsect2 id="R2-PYGRESQL-ENDCOPY-1">
2124 <title>Parameters</title>
2130 <refsect2 id="R2-PYGRESQL-ENDCOPY-2">
2131 <title>Return Type</title>
2137 <refsect2 id="R2-PYGRESQL-ENDCOPY-3">
2138 <title>Exceptions</title>
2142 <errorname>TypeError</errorname>
2146 Bad argument type or too many (any) arguments.
2152 <errorname>pg.error</errorname>
2165 <refsect1 id="R1-PYGRESQL-ENDCOPY-1">
2166 <title>Description</title>
2168 The use of direct access methods may desynchronize client and server. This
2169 method ensure that client and server will be synchronized.
2175 <!-- ********************************************************** -->
2177 <refentry id="PYGRESQL-LOCREATE">
2179 <refentrytitle>locreate</refentrytitle>
2180 <refmiscinfo>PYGRESQL - Locreate</refmiscinfo>
2183 <refname>locreate</refname>
2184 <refpurpose>creates of large object in the database [LO]</refpurpose>
2189 locreate(<replaceable>mode</replaceable>)
2192 <refsect2 id="R2-PYGRESQL-LOCREATE-1">
2193 <title>Parameters</title>
2197 <replaceable>mode</replaceable>
2200 <para>Large object create mode.</para>
2206 <refsect2 id="R2-PYGRESQL-LOCREATE-2">
2207 <title>Return Type</title>
2215 Object handling the <productname>PostgreSQL</productname> large object.
2222 <refsect2 id="R2-PYGRESQL-LOCREATE-3">
2223 <title>Exceptions</title>
2227 <errorname>TypeError</errorname>
2231 Bad argument type or too many arguments.
2237 <errorname>pg.error</errorname>
2241 Invalid connection, or creation error.
2250 <refsect1 id="R1-PYGRESQL-LOCREATE-1">
2251 <title>Description</title>
2253 <function>locreate()</function> method creates a large object in the database.
2254 The mode can be defined by OR-ing the constants defined in the pg module
2255 (<literal>INV_READ and INV_WRITE</literal>).
2261 <!-- ********************************************************** -->
2263 <refentry id="PYGRESQL-GETLO">
2265 <refentrytitle>getlo</refentrytitle>
2266 <refmiscinfo>PYGRESQL - Getlo</refmiscinfo>
2269 <refname>getlo</refname>
2270 <refpurpose>builds a large object from given <literal>oid</literal> [LO]</refpurpose>
2275 getlo(<replaceable>oid</replaceable>)
2278 <refsect2 id="R2-PYGRESQL-GETLO-1">
2279 <title>Parameters</title>
2283 <replaceable>oid</replaceable>
2286 <para><literal>OID</literal> of the existing large object (integer).</para>
2292 <refsect2 id="R2-PYGRESQL-GETLO-2">
2293 <title>Return Type</title>
2301 Object handling the <productname>PostgreSQL</productname> large object.
2308 <refsect2 id="R2-PYGRESQL-GETLO-3">
2309 <title>Exceptions</title>
2313 <errorname>TypeError</errorname>
2317 Bad argument type or too many arguments.
2323 <errorname>pg.error</errorname>
2336 <refsect1 id="R1-PYGRESQL-GETLO-1">
2337 <title>Description</title>
2339 <function>getlo()</function> method allows to reuse a formerly
2340 created large object through the <classname>pglarge</classname> interface, providing
2341 the user have its <literal>oid</literal>.
2347 <!-- ********************************************************** -->
2349 <refentry id="PYGRESQL-LOIMPORT">
2351 <refentrytitle>loimport</refentrytitle>
2352 <refmiscinfo>PYGRESQL - Loimport</refmiscinfo>
2355 <refname>loimport</refname>
2356 <refpurpose>imports a file to a <productname>PostgreSQL</productname> large object [LO]</refpurpose>
2361 loimport(<replaceable>filename</replaceable>)
2364 <refsect2 id="R2-PYGRESQL-LOIMPORT-1">
2365 <title>Parameters</title>
2369 <replaceable>filename</replaceable>
2372 <para>The name of the file to be imported (string).</para>
2378 <refsect2 id="R2-PYGRESQL-LOIMPORT-2">
2379 <title>Return Type</title>
2387 Object handling the <productname>PostgreSQL</productname> large object.
2394 <refsect2 id="R2-PYGRESQL-LOIMPORT-3">
2395 <title>Exceptions</title>
2399 <errorname>TypeError</errorname>
2403 Bad argument type or too many arguments.
2409 <errorname>pg.error</errorname>
2413 Invalid connection, or error during file import.
2422 <refsect1 id="R1-PYGRESQL-LOIMPORT-1">
2423 <title>Description</title>
2425 <function>loimport()</function> method allows to create large objects
2426 in a very simple way. You just give the name of a file containing the
2436 <sect1 id="pygresql-pg-DB">
2437 <title>Database wrapper class: <classname>DB</classname></title>
2440 <classname>pg</classname> module contains a class called
2441 <classname>DB</classname>. All <classname>pgobject</classname>
2442 methods are included in this class also. A number of additional
2443 <classname>DB</classname> class methods are described below. The
2444 preferred way to use this module is as follows (See description of
2445 the initialization method below.):
2458 print '%(foo)s %(bar)s' % r
2461 The following describes the methods and variables of this class.
2465 The <classname>DB</classname> class is initialized with the same
2466 arguments as the <function>pg.connect</function> method. It also
2467 initializes a few internal variables. The statement <literal>db =
2468 DB()</literal> will open the local database with the name of the
2469 user just like <function>pg.connect()</function> does.
2472 <refentry id="PYGRESQL-DB-PKEY">
2474 <refentrytitle>pkey</refentrytitle>
2475 <refmiscinfo>PYGRESQL - Pkey</refmiscinfo>
2478 <refname>pkey</refname>
2479 <refpurpose>returns the primary key of a table</refpurpose>
2484 pkey(<replaceable>table</replaceable>)
2487 <refsect2 id="R2-PYGRESQL-DB-PKEY-1">
2488 <title>Parameters</title>
2492 <replaceable>table</replaceable>
2503 <refsect2 id="R2-PYGRESQL-DB-PKEY-2">
2504 <title>Return Type</title>
2512 Name of field which is the primary key of the table.
2521 <refsect1 id="R1-PYGRESQL-DB-PKEY-1">
2522 <title>Description</title>
2524 <function>pkey()</function> method returns the primary key
2525 of a table. Note that this raises an exception if the table
2526 does not have a primary key.
2532 <!-- ********************************************************** -->
2534 <refentry id="PYGRESQL-DB-GET-DATABASES">
2536 <refentrytitle>get_databases</refentrytitle>
2537 <refmiscinfo>PYGRESQL - Get_databases</refmiscinfo>
2540 <refname>get_databases</refname>
2541 <refpurpose>get list of databases in the system</refpurpose>
2549 <refsect2 id="R2-PYGRESQL-DB-GET-DATABASES-1">
2550 <title>Parameters</title>
2556 <refsect2 id="R2-PYGRESQL-DB-GET-DATABASES-2">
2557 <title>Return Type</title>
2565 List of databases in the system.
2574 <refsect1 id="R1-PYGRESQL-DB-GET-DATABASES-1">
2575 <title>Description</title>
2577 Although you can do this with a simple select,
2578 it is added here for convenience
2584 <!-- ********************************************************** -->
2586 <refentry id="PYGRESQL-DB-GET-TABLES">
2588 <refentrytitle>get_tables</refentrytitle>
2589 <refmiscinfo>PYGRESQL - get_tables</refmiscinfo>
2592 <refname>get_tables</refname>
2593 <refpurpose>get list of tables in connected database</refpurpose>
2601 <refsect2 id="R2-PYGRESQL-DB-GET-TABLES-1">
2602 <title>Parameters</title>
2608 <refsect2 id="R2-PYGRESQL-DB-GET-TABLES-2">
2609 <title>Return Type</title>
2617 List of tables in connected database.
2626 <refsect1 id="R1-PYGRESQL-DB-GET-TABLES-1">
2627 <title>Description</title>
2629 Although you can do this with a simple select,
2630 it is added here for convenience
2636 <!-- ********************************************************** -->
2638 <refentry id="PYGRESQL-DB-GET-ATTNAMES">
2640 <refentrytitle>get_attnames</refentrytitle>
2641 <refmiscinfo>PYGRESQL - Get_Attnames</refmiscinfo>
2644 <refname>get_attnames</refname>
2645 <refpurpose>returns the attribute names of a table</refpurpose>
2650 get_attnames(<replaceable>table</replaceable>)
2653 <refsect2 id="R2-PYGRESQL-DB-GET-ATTNAMES-1">
2654 <title>Parameters</title>
2658 <replaceable>table</replaceable>
2669 <refsect2 id="R2-PYGRESQL-DB-GET-ATTNAMES-2">
2670 <title>Return Type</title>
2678 The dictionary's keys are
2679 the attribute names, the values are the type names of
2689 <refsect1 id="R1-PYGRESQL-DB-GET-ATTNAMES-1">
2690 <title>Description</title>
2692 Given the name of a table, digs out the set of attribute names
2699 <!-- ********************************************************** -->
2701 <refentry id="PYGRESQL-DB-GET">
2703 <refentrytitle>get</refentrytitle>
2704 <refmiscinfo>PYGRESQL - Get</refmiscinfo>
2707 <refname>get</refname>
2708 <refpurpose>get a tuple from a database table</refpurpose>
2713 get(<replaceable>table</replaceable>, <replaceable>arg</replaceable>, <optional><replaceable>keyname</replaceable></optional>)
2716 <refsect2 id="R2-PYGRESQL-DB-GET-1">
2717 <title>Parameters</title>
2721 <replaceable>table</replaceable>
2731 <replaceable>arg</replaceable>
2735 Either a dictionary or the value to be looked up.
2741 <optional><replaceable>keyname</replaceable></optional>
2745 Name of field to use as key (optional).
2752 <refsect2 id="R2-PYGRESQL-DB-GET-2">
2753 <title>Return Type</title>
2761 A dictionary mapping attribute names to row values.
2770 <refsect1 id="R1-PYGRESQL-DB-GET-1">
2771 <title>Description</title>
2773 This method is the basic mechanism to get a single row. It assumes
2774 that the key specifies a unique row. If keyname is not specified
2775 then the primary key for the table is used. If arg is a dictionary
2776 then the value for the key is taken from it and it is modified to
2777 include the new values, replacing existing values where necessary.
2778 The oid is also put into the dictionary but in order to allow the
2779 caller to work with multiple tables, the attribute name is munged
2780 to make it unique. It consists of the string <literal>oid_</literal> followed by
2781 the name of the table.
2787 <!-- ********************************************************** -->
2789 <refentry id="PYGRESQL-DB-INSERT">
2791 <refentrytitle>insert</refentrytitle>
2792 <refmiscinfo>PYGRESQL - Insert</refmiscinfo>
2795 <refname>insert</refname>
2796 <refpurpose>insert a tuple into a database table</refpurpose>
2801 insert(<replaceable>table</replaceable>, <replaceable>a</replaceable>)
2804 <refsect2 id="R2-PYGRESQL-DB-INSERT-1">
2805 <title>Parameters</title>
2809 <replaceable>table</replaceable>
2819 <replaceable>a</replaceable>
2823 A dictionary of values.
2830 <refsect2 id="R2-PYGRESQL-DB-INSERT-2">
2831 <title>Return Type</title>
2839 The OID of the newly inserted row.
2848 <refsect1 id="R1-PYGRESQL-DB-INSERT-1">
2849 <title>Description</title>
2851 This method inserts values into the table specified filling in the
2852 values from the dictionary. It then reloads the dictionary with the
2853 values from the database. This causes the dictionary to be updated
2854 with values that are modified by rules, triggers, etc.
2860 <!-- ********************************************************** -->
2862 <refentry id="PYGRESQL-DB-UPDATE">
2864 <refentrytitle>update</refentrytitle>
2865 <refmiscinfo>PYGRESQL - Update</refmiscinfo>
2868 <refname>update</refname>
2869 <refpurpose>update a database table</refpurpose>
2874 update(<replaceable>table</replaceable>, <replaceable>a</replaceable>)
2877 <refsect2 id="R2-PYGRESQL-DB-UPDATE-1">
2878 <title>Parameters</title>
2882 <replaceable>table</replaceable>
2892 <replaceable>a</replaceable>
2896 A dictionary of values.
2903 <refsect2 id="R2-PYGRESQL-DB-UPDATE-2">
2904 <title>Return Type</title>
2912 The OID of the newly updated row.
2921 <refsect1 id="R1-PYGRESQL-DB-UPDATE-1">
2922 <title>Description</title>
2924 Similar to insert but updates an existing row. The update is based
2925 on the OID value as munged by get. The array returned is the
2926 one sent modified to reflect any changes caused by the update due
2927 to triggers, rules, defaults, etc.
2933 <!-- ********************************************************** -->
2935 <refentry id="PYGRESQL-DB-CLEAR">
2937 <refentrytitle>clear</refentrytitle>
2938 <refmiscinfo>PYGRESQL - Clear</refmiscinfo>
2941 <refname>clear</refname>
2942 <refpurpose>clear a database table</refpurpose>
2947 clear(<replaceable>table</replaceable>, <optional><replaceable>a</replaceable></optional>)
2950 <refsect2 id="R2-PYGRESQL-DB-CLEAR-1">
2951 <title>Parameters</title>
2955 <replaceable>table</replaceable>
2965 <optional><replaceable>a</replaceable></optional>
2969 A dictionary of values.
2976 <refsect2 id="R2-PYGRESQL-DB-CLEAR-2">
2977 <title>Return Type</title>
2985 A dictionary with an empty row.
2994 <refsect1 id="R1-PYGRESQL-DB-CLEAR-1">
2995 <title>Description</title>
2997 This method clears all the attributes to values determined by the types.
2998 Numeric types are set to 0, dates are set to <literal>'today'</literal> and everything
2999 else is set to the empty string. If the array argument is present,
3000 it is used as the array and any entries matching attribute names
3001 are cleared with everything else left unchanged.
3007 <!-- ********************************************************** -->
3009 <refentry id="PYGRESQL-DB-DELETE">
3011 <refentrytitle>delete</refentrytitle>
3012 <refmiscinfo>PYGRESQL - Delete</refmiscinfo>
3015 <refname>delete</refname>
3016 <refpurpose>deletes the row from a table</refpurpose>
3021 delete(<replaceable>table</replaceable>, <optional><replaceable>a</replaceable></optional>)
3024 <refsect2 id="R2-PYGRESQL-DB-DELETE-1">
3025 <title>Parameters</title>
3029 <replaceable>table</replaceable>
3039 <optional><replaceable>a</replaceable></optional>
3043 A dictionary of values.
3050 <refsect2 id="R2-PYGRESQL-DB-DELETE-2">
3051 <title>Return Type</title>
3059 <refsect1 id="R1-PYGRESQL-DB-DELETE-1">
3060 <title>Description</title>
3062 This method deletes the row from a table. It deletes based on the OID
3063 as munged as described above.
3069 <!-- ********************************************************** -->
3073 <!-- ********************************************************** -->
3074 <!-- ********************************************************** -->
3076 <sect1 id="pygresql-pg-pgqueryobject">
3077 <title>Query result object: <literal>pgqueryobject</literal></title>
3079 <!-- ********************************************************** -->
3081 <refentry id="PYGRESQL-PGQUERYOBJECT-GETRESULT">
3083 <refentrytitle>getresult</refentrytitle>
3084 <refmiscinfo>PYGRESQL - Getresult</refmiscinfo>
3087 <refname>getresult</refname>
3088 <refpurpose>gets the values returned by the query</refpurpose>
3096 <refsect2 id="R2-PYGRESQL-PGQUERYOBJECT-GETRESULT-1">
3097 <title>Parameters</title>
3103 <refsect2 id="R2-PYGRESQL-PGQUERYOBJECT-GETRESULT-2">
3104 <title>Return Type</title>
3119 <refsect2 id="R2-PYGRESQL-PGQUERYOBJECT-GETRESULT-3">
3120 <title>Exceptions</title>
3124 <errorname>SyntaxError</errorname>
3134 <errorname>pg.error</errorname>
3138 Invalid previous result.
3147 <refsect1 id="R1-PYGRESQL-PGQUERYOBJECT-GETRESULT-1">
3148 <title>Description</title>
3150 <function>getresult()</function> method returns the list of the values returned by the query.
3151 More information about this result may be accessed using <function>listfields</function>,
3152 <function>fieldname</function> and <function>fieldnum</function> methods.
3158 <!-- ********************************************************** -->
3160 <refentry id="PYGRESQL-PGQUERYOBJECT-DICTRESULT">
3162 <refentrytitle>dictresult</refentrytitle>
3163 <refmiscinfo>PYGRESQL - Dictresult</refmiscinfo>
3166 <refname>dictresult</refname>
3167 <refpurpose>like getresult but returns a list of dictionaries</refpurpose>
3175 <refsect2 id="R2-PYGRESQL-PGQUERYOBJECT-DICTRESULT-1">
3176 <title>Parameters</title>
3182 <refsect2 id="R2-PYGRESQL-PGQUERYOBJECT-DICTRESULT-2">
3183 <title>Return Type</title>
3191 List of dictionaries.
3198 <refsect2 id="R2-PYGRESQL-PGQUERYOBJECT-DICTRESULT-3">
3199 <title>Exceptions</title>
3203 <errorname>SyntaxError</errorname>
3213 <errorname>pg.error</errorname>
3217 Invalid previous result.
3226 <refsect1 id="R1-PYGRESQL-PGQUERYOBJECT-DICTRESULT-1">
3227 <title>Description</title>
3229 <function>dictresult()</function> method returns the list of the values returned by the query
3230 with each tuple returned as a dictionary with the field names
3231 used as the dictionary index.
3237 <!-- ********************************************************** -->
3239 <refentry id="PYGRESQL-PGQUERYOBJECT-LISTFIELDS">
3241 <refentrytitle>listfields</refentrytitle>
3242 <refmiscinfo>PYGRESQL - Listfields</refmiscinfo>
3245 <refname>listfields</refname>
3246 <refpurpose>lists the fields names of the query result</refpurpose>
3254 <refsect2 id="R2-PYGRESQL-PGQUERYOBJECT-LISTFIELDS-1">
3255 <title>Parameters</title>
3261 <refsect2 id="R2-PYGRESQL-PGQUERYOBJECT-LISTFIELDS-2">
3262 <title>Return Type</title>
3277 <refsect2 id="R2-PYGRESQL-PGQUERYOBJECT-LISTFIELDS-3">
3278 <title>Exceptions</title>
3282 <errorname>SyntaxError</errorname>
3292 <errorname>pg.error</errorname>
3296 Invalid query result, or invalid connection.
3305 <refsect1 id="R1-PYGRESQL-PGQUERYOBJECT-LISTFIELDS-1">
3306 <title>Description</title>
3308 <function>listfields()</function> method returns the list of field names defined for the
3309 query result. The fields are in the same order as the result values.
3315 <!-- ********************************************************** -->
3317 <refentry id="PYGRESQL-PGQUERYOBJECT-FIELDNAME">
3319 <refentrytitle>fieldname</refentrytitle>
3320 <refmiscinfo>PYGRESQL - Fieldname</refmiscinfo>
3323 <refname>fieldname</refname>
3324 <refpurpose>field number-name conversion</refpurpose>
3329 fieldname(<replaceable>i</replaceable>)
3332 <refsect2 id="R2-PYGRESQL-PGQUERYOBJECT-FIELDNAME-1">
3333 <title>Parameters</title>
3337 <replaceable>i</replaceable>
3341 field number (integer).
3348 <refsect2 id="R2-PYGRESQL-PGQUERYOBJECT-FIELDNAME-2">
3349 <title>Return Type</title>
3364 <refsect2 id="R2-PYGRESQL-PGQUERYOBJECT-FIELDNAME-3">
3365 <title>Exceptions</title>
3369 <errorname>TypeError</errorname>
3373 Bad parameter type, or too many arguments.
3379 <replaceable>ValueError</replaceable>
3383 Invalid field number.
3389 <errorname>pg.error</errorname>
3393 Invalid query result, or invalid connection.
3402 <refsect1 id="R1-PYGRESQL-PGQUERYOBJECT-FIELDNAME-1">
3403 <title>Description</title>
3405 <function>fieldname()</function> method allows to find a field name from its rank number. It can be
3406 useful for displaying a result. The fields are in the same order than the
3413 <!-- ********************************************************** -->
3415 <refentry id="PYGRESQL-PGQUERYOBJECT-FIELDNUM">
3417 <refentrytitle>fieldnum</refentrytitle>
3418 <refmiscinfo>PYGRESQL - Fieldnum</refmiscinfo>
3421 <refname>fieldnum</refname>
3422 <refpurpose>field name-number conversion</refpurpose>
3427 fieldnum(<replaceable>name</replaceable>)
3430 <refsect2 id="R2-PYGRESQL-PGQUERYOBJECT-FIELDNUM-1">
3431 <title>Parameters</title>
3435 <replaceable>name</replaceable>
3439 field name (string).
3446 <refsect2 id="R2-PYGRESQL-PGQUERYOBJECT-FIELDNUM-2">
3447 <title>Return Type</title>
3455 field number (integer).
3462 <refsect2 id="R2-PYGRESQL-PGQUERYOBJECT-FIELDNUM-3">
3463 <title>Exceptions</title>
3467 <errorname>TypeError</errorname>
3471 Bad parameter type, or too many arguments.
3477 <replaceable>ValueError</replaceable>
3487 <errorname>pg.error</errorname>
3491 Invalid query result, or invalid connection.
3500 <refsect1 id="R1-PYGRESQL-PGQUERYOBJECT-FIELDNUM-1">
3501 <title>Description</title>
3503 <function>fieldnum()</function> method returns a field number from its name.
3504 It can be used to build a function that converts result list strings to their correct
3505 type, using a hardcoded table definition. The number returned is the
3506 field rank in the result values list.
3512 <!-- ********************************************************** -->
3514 <refentry id="PYGRESQL-PGQUERYOBJECT-NTUPLES">
3516 <refentrytitle>ntuples</refentrytitle>
3517 <refmiscinfo>PYGRESQL - Ntuples</refmiscinfo>
3520 <refname>ntuples</refname>
3521 <refpurpose>returns the number of tuples in query object</refpurpose>
3529 <refsect2 id="R2-PYGRESQL-PGQUERYOBJECT-NTUPLES-1">
3530 <title>Parameters</title>
3536 <refsect2 id="R2-PYGRESQL-PGQUERYOBJECT-NTUPLES-2">
3537 <title>Return Type</title>
3545 The number of tuples in query object.
3552 <refsect2 id="R2-PYGRESQL-PGQUERYOBJECT-NTUPLES-3">
3553 <title>Exceptions</title>
3557 <errorname>SyntaxError</errorname>
3570 <refsect1 id="R1-PYGRESQL-PGQUERYOBJECT-NTUPLES-1">
3571 <title>Description</title>
3573 <function>ntuples()</function> method returns the number of tuples found in a query.
3582 <sect1 id="pygresql-pg-pglarge">
3583 <title>Large Object: <classname>pglarge</classname></title>
3586 This object handles all the request concerning a
3587 <productname>PostgreSQL</productname> large object. It embeds and
3588 hides all the <quote>recurrent</quote> variables (object oid and
3589 connection), exactly in the same way
3590 <classname>pgobject</classname>s do, thus only keeping significant
3591 parameters in function calls. It keeps a reference to the <classname>pgobject</classname>
3592 used for its creation, sending requests though with its
3593 parameters. Any modification but dereferencing the
3594 <classname>pgobject</classname> will thus affect the
3595 <classname>pglarge</classname> object. Dereferencing the initial
3596 <classname>pgobject</classname> is not a problem since
3597 <application>Python</application> will not deallocate it before the
3598 large object dereference it. All functions return a generic error
3599 message on call error, whatever the exact error was. The
3600 <structfield>error</structfield> attribute of the object allows to
3601 get the exact error message.
3605 <classname>pglarge</classname> objects define a read-only set of
3606 attributes that allow to get some information about it. These
3614 the oid associated with the object
3623 the <classname>pgobject</classname> associated with the object
3632 the last warning/error message of the connection
3639 <title>Be careful</title>
3642 In multithreaded environments, <structfield>error</structfield>
3643 may be modified by another thread using the same
3644 <classname>pgobject</classname>. Remember these object are
3645 shared, not duplicated; you should provide some locking to be
3646 able if you want to check this. The oid attribute is very
3647 interesting because it allow you reuse the oid later, creating
3648 the <classname>pglarge</classname> object with a <classname>pgobject</classname>
3649 <function>getlo()</function> method call.
3655 See also <xref linkend="largeobjects"> for more information about the
3656 <productname>PostgreSQL</productname> large object interface.
3659 <!-- ********************************************************** -->
3661 <refentry id="PYGRESQL-PGLARGEOBJECT-OPEN">
3663 <refentrytitle>open</refentrytitle>
3664 <refmiscinfo>PYGRESQL - Open</refmiscinfo>
3667 <refname>open</refname>
3668 <refpurpose>opens a large object</refpurpose>
3673 open(<replaceable>mode</replaceable>)
3676 <refsect2 id="R2-PYGRESQL-PGLARGEOBJECT-OPEN-1">
3677 <title>Parameters</title>
3681 <replaceable>mode</replaceable>
3685 open mode definition (integer).
3692 <refsect2 id="R2-PYGRESQL-PGLARGEOBJECT-OPEN-2">
3693 <title>Return Type</title>
3699 <refsect2 id="R2-PYGRESQL-PGLARGEOBJECT-OPEN-3">
3700 <title>Exceptions</title>
3704 <errorname>TypeError</errorname>
3708 Bad parameter type, or too many arguments.
3714 <errorname>IOError</errorname>
3718 Already opened object, or open error.
3724 <errorname>pg.error</errorname>
3737 <refsect1 id="R1-PYGRESQL-PGLARGEOBJECT-OPEN-1">
3738 <title>Description</title>
3740 <function>open()</function> method opens a large object for reading/writing,
3741 in the same way than the <acronym>UNIX</acronym> <function>open()</function>
3742 function. The mode value can be obtained by OR-ing the constants defined in
3743 the pg module (<literal>INV_READ, INV_WRITE</literal>).
3749 <!-- ********************************************************** -->
3751 <refentry id="PYGRESQL-PGLARGEOBJECT-CLOSE">
3753 <refentrytitle>close</refentrytitle>
3754 <refmiscinfo>PYGRESQL - Close</refmiscinfo>
3757 <refname>close</refname>
3758 <refpurpose>closes the large object</refpurpose>
3766 <refsect2 id="R2-PYGRESQL-PGLARGEOBJECT-CLOSE-1">
3767 <title>Parameters</title>
3773 <refsect2 id="R2-PYGRESQL-PGLARGEOBJECT-CLOSE-2">
3774 <title>Return Type</title>
3780 <refsect2 id="R2-PYGRESQL-PGLARGEOBJECT-CLOSE-3">
3781 <title>Exceptions</title>
3785 <errorname>SyntaxError</errorname>
3795 <errorname>IOError</errorname>
3799 Object is not opened, or close error.
3805 <errorname>pg.error</errorname>
3818 <refsect1 id="R1-PYGRESQL-PGLARGEOBJECT-CLOSE-1">
3819 <title>Description</title>
3821 <function>close()</function> method closes previously opened large object,
3822 in the same way than the <acronym>UNIX</acronym> <function>close()</function> function.
3828 <!-- ********************************************************** -->
3830 <refentry id="PYGRESQL-PGLARGEOBJECT-READ">
3832 <refentrytitle>read</refentrytitle>
3833 <refmiscinfo>PYGRESQL - Read</refmiscinfo>
3836 <refname>read</refname>
3837 <refpurpose>reads from the large object</refpurpose>
3842 read(<replaceable>size</replaceable>)
3845 <refsect2 id="R2-PYGRESQL-PGLARGEOBJECT-READ-1">
3846 <title>Parameters</title>
3850 <replaceable>size</replaceable>
3854 Maximal size of the buffer to be read (integer).
3861 <refsect2 id="R2-PYGRESQL-PGLARGEOBJECT-READ-2">
3862 <title>Return Type</title>
3877 <refsect2 id="R2-PYGRESQL-PGLARGEOBJECT-READ-3">
3878 <title>Exceptions</title>
3882 <errorname>TypeError</errorname>
3886 Bad parameter type, or too many arguments.
3892 <errorname>IOError</errorname>
3896 Object is not opened, or read error.
3902 <errorname>pg.error</errorname>
3906 Invalid connection or invalid object.
3915 <refsect1 id="R1-PYGRESQL-PGLARGEOBJECT-READ-1">
3916 <title>Description</title>
3918 <function>read()</function> method allows to read data from the large object,
3919 starting at current position.
3925 <!-- ********************************************************** -->
3927 <refentry id="PYGRESQL-PGLARGEOBJECT-WRITE">
3929 <refentrytitle>write</refentrytitle>
3930 <refmiscinfo>PYGRESQL - Write</refmiscinfo>
3933 <refname>write</refname>
3934 <refpurpose>writes to the large object</refpurpose>
3939 write(<replaceable>string</replaceable>)
3942 <refsect2 id="R2-PYGRESQL-PGLARGEOBJECT-WRITE-1">
3943 <title>Parameters</title>
3947 <replaceable>string</replaceable>
3951 Buffer to be written (string).
3958 <refsect2 id="R2-PYGRESQL-PGLARGEOBJECT-WRITE-2">
3959 <title>Return Type</title>
3965 <refsect2 id="R2-PYGRESQL-PGLARGEOBJECT-WRITE-3">
3966 <title>Exceptions</title>
3970 <errorname>TypeError</errorname>
3974 Bad parameter type, or too many arguments.
3980 <errorname>IOError</errorname>
3984 Object is not opened, or write error.
3990 <errorname>pg.error</errorname>
3994 Invalid connection or invalid object.
4003 <refsect1 id="R1-PYGRESQL-PGLARGEOBJECT-WRITE-1">
4004 <title>Description</title>
4006 <function>write()</function> method allows to write data to the large object,
4007 starting at current position.
4013 <!-- ********************************************************** -->
4015 <refentry id="PYGRESQL-PGLARGEOBJECT-SEEK">
4017 <refentrytitle>seek</refentrytitle>
4018 <refmiscinfo>PYGRESQL - Seek</refmiscinfo>
4021 <refname>seek</refname>
4022 <refpurpose>change current position in the large object</refpurpose>
4027 seek(<replaceable>offset</replaceable>, <replaceable>whence</replaceable>)
4030 <refsect2 id="R2-PYGRESQL-PGLARGEOBJECT-SEEK-1">
4031 <title>Parameters</title>
4035 <replaceable>offset</replaceable>
4039 Position offset (integer).
4045 <replaceable>whence</replaceable>
4049 Positional parameter (integer).
4056 <refsect2 id="R2-PYGRESQL-PGLARGEOBJECT-SEEK-2">
4057 <title>Return Type</title>
4065 New current position in the object.
4072 <refsect2 id="R2-PYGRESQL-PGLARGEOBJECT-SEEK-3">
4073 <title>Exceptions</title>
4077 <errorname>TypeError</errorname>
4081 Bad parameter type, or too many arguments.
4087 <errorname>IOError</errorname>
4091 Object is not opened, or seek error.
4097 <errorname>pg.error</errorname>
4101 Invalid connection or invalid object.
4110 <refsect1 id="R1-PYGRESQL-PGLARGEOBJECT-SEEK-1">
4111 <title>Description</title>
4113 <function>seek()</function> method allows to move the cursor position
4114 in the large object. The whence parameter can be obtained by OR-ing the constants defined in the
4115 <literal>pg</literal> module (<literal>SEEK_SET, SEEK_CUR, SEEK_END</literal>).
4121 <!-- ********************************************************** -->
4123 <refentry id="PYGRESQL-PGLARGEOBJECT-TELL">
4125 <refentrytitle>tell</refentrytitle>
4126 <refmiscinfo>PYGRESQL - Tell</refmiscinfo>
4129 <refname>tell</refname>
4130 <refpurpose>returns current position in the large object</refpurpose>
4138 <refsect2 id="R2-PYGRESQL-PGLARGEOBJECT-TELL-1">
4139 <title>Parameters</title>
4145 <refsect2 id="R2-PYGRESQL-PGLARGEOBJECT-TELL-2">
4146 <title>Return Type</title>
4154 Current position in the object.
4161 <refsect2 id="R2-PYGRESQL-PGLARGEOBJECT-TELL-3">
4162 <title>Exceptions</title>
4166 <errorname>SyntaxError</errorname>
4176 <errorname>IOError</errorname>
4180 Object is not opened, or seek error.
4186 <errorname>pg.error</errorname>
4190 Invalid connection or invalid object.
4199 <refsect1 id="R1-PYGRESQL-PGLARGEOBJECT-TELL-1">
4200 <title>Description</title>
4202 <function>tell()</function> method allows to get the current position in the large object.
4208 <!-- ********************************************************** -->
4210 <refentry id="PYGRESQL-PGLARGEOBJECT-UNLINK">
4212 <refentrytitle>unlink</refentrytitle>
4213 <refmiscinfo>PYGRESQL - Unlink</refmiscinfo>
4216 <refname>unlink</refname>
4217 <refpurpose>deletes the large object</refpurpose>
4225 <refsect2 id="R2-PYGRESQL-PGLARGEOBJECT-UNLINK-1">
4226 <title>Parameters</title>
4232 <refsect2 id="R2-PYGRESQL-PGLARGEOBJECT-UNLINK-2">
4233 <title>Return Type</title>
4239 <refsect2 id="R2-PYGRESQL-PGLARGEOBJECT-UNLINK-3">
4240 <title>Exceptions</title>
4244 <errorname>SyntaxError</errorname>
4254 <errorname>IOError</errorname>
4258 Object is not closed, or unlink error.
4264 <errorname>pg.error</errorname>
4268 Invalid connection or invalid object.
4277 <refsect1 id="R1-PYGRESQL-PGLARGEOBJECT-UNLINK-1">
4278 <title>Description</title>
4280 <function>unlink()</function> method unlinks (deletes) the large object.
4286 <!-- ********************************************************** -->
4288 <refentry id="PYGRESQL-PGLARGEOBJECT-SIZE">
4290 <refentrytitle>size</refentrytitle>
4291 <refmiscinfo>PYGRESQL - Size</refmiscinfo>
4294 <refname>size</refname>
4295 <refpurpose>gives the large object size</refpurpose>
4303 <refsect2 id="R2-PYGRESQL-PGLARGEOBJECT-SIZE-1">
4304 <title>Parameters</title>
4310 <refsect2 id="R2-PYGRESQL-PGLARGEOBJECT-SIZE-2">
4311 <title>Return Type</title>
4319 The large object size.
4326 <refsect2 id="R2-PYGRESQL-PGLARGEOBJECT-SIZE-3">
4327 <title>Exceptions</title>
4331 <errorname>SyntaxError</errorname>
4341 <errorname>IOError</errorname>
4345 Object is not opened, or seek/tell error.
4351 <errorname>pg.error</errorname>
4355 Invalid connection or invalid object.
4364 <refsect1 id="R1-PYGRESQL-PGLARGEOBJECT-SIZE-1">
4365 <title>Description</title>
4367 <function>size()</function> method allows to get the size of
4368 the large object. It was implemented because this function
4369 is very useful for a WWW interfaced database.
4370 Currently the large object needs to be opened.
4376 <!-- ********************************************************** -->
4378 <refentry id="PYGRESQL-PGLARGEOBJECT-EXPORT">
4380 <refentrytitle>export</refentrytitle>
4381 <refmiscinfo>PYGRESQL - Export</refmiscinfo>
4384 <refname>export</refname>
4385 <refpurpose>saves the large object to file</refpurpose>
4390 export(<replaceable>filename</replaceable>)
4393 <refsect2 id="R2-PYGRESQL-PGLARGEOBJECT-EXPORT-1">
4394 <title>Parameters</title>
4398 <replaceable>filename</replaceable>
4402 The file to be created.
4409 <refsect2 id="R2-PYGRESQL-PGLARGEOBJECT-EXPORT-2">
4410 <title>Return Type</title>
4416 <refsect2 id="R2-PYGRESQL-PGLARGEOBJECT-EXPORT-3">
4417 <title>Exceptions</title>
4421 <errorname>TypeError</errorname>
4425 Bad argument type, or too many arguments.
4431 <errorname>IOError</errorname>
4435 Object is not closed, or export error.
4441 <errorname>pg.error</errorname>
4445 Invalid connection or invalid object.
4454 <refsect1 id="R1-PYGRESQL-PGLARGEOBJECT-EXPORT-1">
4455 <title>Description</title>
4457 <function>export()</function> method allows to dump the
4458 content of a large object in a very simple way.
4459 The exported file is created on the host of the program,
4460 not the server host.
4469 <sect1 id="pygresql-db-api">
4470 <title><acronym>DB-API</acronym> Interface</title>
4473 This section needs to be written.
4478 url="http://www.python.org/topics/database/DatabaseAPI-2.0.html"
4479 >http://www.python.org/topics/database/DatabaseAPI-2.0.html</ulink>
4480 for a description of the <acronym>DB-API</acronym> 2.0.