Changeset 797

Show
Ignore:
Timestamp:
03/06/07 22:43:41 (1 year ago)
Author:
mfenniak
Message:

Begin adding library documentation.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • pg8000/trunk/pg8000.py

    r796 r797  
     1# vim: sw=4:expandtab:foldmethod=marker 
     2# 
     3# Copyright (c) 2007, Mathieu Fenniak 
     4# All rights reserved. 
     5# 
     6# Redistribution and use in source and binary forms, with or without 
     7# modification, are permitted provided that the following conditions are 
     8# met: 
     9# 
     10# * Redistributions of source code must retain the above copyright notice, 
     11# this list of conditions and the following disclaimer. 
     12# * Redistributions in binary form must reproduce the above copyright notice, 
     13# this list of conditions and the following disclaimer in the documentation 
     14# and/or other materials provided with the distribution. 
     15# * The name of the author may not be used to endorse or promote products 
     16# derived from this software without specific prior written permission. 
     17# 
     18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
     19# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
     20# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
     21# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
     22# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
     23# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
     24# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
     25# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
     26# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
     27# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
     28# POSSIBILITY OF SUCH DAMAGE. 
     29 
     30__author__ = "Mathieu Fenniak" 
     31 
    132import socket 
    233import struct 
     
    5283        return retval 
    5384 
    54  
     85## 
     86# This class represents a connection to a PostgreSQL database. 
     87# <p> 
     88# A single PostgreSQL connection can only perform a single query at a time, 
     89# which is an important restriction to note.  This limitation can be overcome 
     90# by retrieving all results immediately after a query, but this approach is not 
     91# taken by this library. 
     92# <p> 
     93# Stability: Added in v1.00, stability guaranteed for v1.xx. 
     94
     95# @param host   The hostname of the PostgreSQL server to connect with.  Only 
     96# TCP/IP connections are presently supported, so this parameter is mandatory. 
     97
     98# @param user   The username to connect to the PostgreSQL server with.  This 
     99# parameter is mandatory. 
     100
     101# @param port   The TCP/IP port of the PostgreSQL server instance.  This 
     102# parameter defaults to 5432, the registered and common port of PostgreSQL 
     103# TCP/IP servers. 
     104
     105# @param database   The name of the database instance to connect with.  This 
     106# parameter is optional, if omitted the PostgreSQL server will assume the 
     107# database name is the same as the username. 
     108
     109# @param password   The user password to connect to the server with.  This 
     110# parameter is optional.  If omitted, and the database server requests password 
     111# based authentication, the connection will fail.  On the other hand, if this 
     112# parameter is provided and the database does not request password 
     113# authentication, then the password will not be used. 
    55114class Connection(object): 
    56115 
     116    ## 
     117    # A configuration variable that determines whether iterating over the 
     118    # connection will return tuples of queried rows (False), or dictionaries 
     119    # indexed by column name/alias (True).  By default, this variable is set to 
     120    # False. 
     121    # <p> 
     122    # Stability: Added in v1.00, stability guaranteed for v1.xx. 
    57123    iterate_dicts = False 
    58124 
     
    78144        return tuple([Types.convert(row.fields[i], self._row_desc.fields[i]) for i in range(len(row.fields))]) 
    79145 
     146    ## 
     147    # Read a row from the database server, and return it in a dictionary 
     148    # indexed by column name/alias.  This method will raise an error if two 
     149    # columns have the same name. 
     150    # <p> 
     151    # Stability: Added in v1.00, stability guaranteed for v1.xx. 
    80152    def read_dict(self): 
    81153        row = self._fetch() 
     
    90162        return retval 
    91163 
     164    ## 
     165    # Read a row from the database server, and return it as a tuple of values. 
     166    # <p> 
     167    # Stability: Added in v1.00, stability guaranteed for v1.xx. 
    92168    def read_tuple(self): 
    93169        row = self._fetch() 
     
    96172        return row 
    97173 
     174    ## 
     175    # Iterate over query results.  The behaviour of iterating over this object 
     176    # is dependent upon the value of the {@link #Connection.iterate_dicts 
     177    # iterate_dicts} variable. 
     178    # <p> 
     179    # Stability: Added in v1.00, stability guaranteed for v1.xx. 
    98180    def __iter__(self): 
    99181        return DataIterator(self)