Next / Previous / TCC home / NMT home

Source listing for ora_db.py

logo
"""ora_db.py:  Oracle version of `dbhelpers' database interface

    Exports all functions from `db_helpers.py', which see
"""

VERSION = "$Revision: 1.1 $  $Date: 2000/07/11 20:24:20 $"


#================================================================
# Imports
#----------------------------------------------------------------

from db_helpers import *    # Basic database interface functions

import DCOracle             # Oracle interface

SQL_DEBUG = 1       # Display SQL commands if set



# - - -   T h e D a t a b a s e   - - -

def TheDatabase ( options ):
    if  not Database.instance:
        Database.instance  =  Database(options)

    return Database.instance


# - - - - -   c l a s s   D a t a b a s e   - - - - -

class Database(BasicDatabase):
    """Sybase implementation of db_helpers.Database

      Exports everything from BasicDatabase, except:
        Database ( options )
          [ if (options is a string of the form
            "username/password@database") ->
              if Oracle will accept that connection ->
                return a new Database object representing
                that database
              else -> raise DBHelpersError ]
    """


# - - -   D a t a b a s e . _ _ i n i t _ _   - - -

    def __init__ ( self, options ):
        """ Constructor for Database
        """
        #-- 1 --
        # [ call the parent constructor ]
        BasicDatabase.__init__ ( self, options )

        #-- 2 --
        # [ if options is a valid option string for an Oracle connect ->
        #     self.connect  :=  a ctsybase object for that connection
        #   else ->
        #     raise DBHelpersError ]
        try:
            self.connect  =  DCOracle.Connect(options)
        except Exception, detail:
            raise DBHelpersError, ( "Oracle error: %s" % detail )


# - - -   D a t a b a s e . e x e c u t e   - - -

    def execute ( self, sql ):
        """ Executes a line of SQL against self.
        """
        if  SQL_DEBUG:
            sys.stderr.write("$$$ %s\n" % sql)

        # NB: Some operations can be executed from the connection
        # object and some must be executed from cursors.  Check
        # your database's documentation.
        result  =  self.connect.execute ( sql )
        return result


# - - - - -   c l a s s   T a b l e   - - - -

class Table(BasicTable):
    """Oracle implementation of BasicTable

      Exports: all functions of BasicTable.
    """


# - - -   T a b l e . e x i s t s   - - -

    def exists ( self ):
        """Does the table exist in the db?
        """
        raise DBHelpersError, "Unimplemented function: Table.exists()"

See also: Python database helper functions
TCC home: TCC home
NMT home: NMT home

Last updated: 2014-04-24 08:34 MDT