/[gnue]/gnue-common/src/datasources/drivers/sapdb/sapdb/Connection.py
ViewVC logotype

Diff of /gnue-common/src/datasources/drivers/sapdb/sapdb/Connection.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by jcater, Fri Oct 10 01:21:30 2003 UTC revision 1.2 by jcater, Tue Nov 25 17:01:45 2003 UTC
# Line 0  Line 1 
1    #
2    # This file is part of GNU Enterprise.
3    #
4    # GNU Enterprise is free software; you can redistribute it
5    # and/or modify it under the terms of the GNU General Public
6    # License as published by the Free Software Foundation; either
7    # version 2, or (at your option) any later version.
8    #
9    # GNU Enterprise is distributed in the hope that it will be
10    # useful, but WITHOUT ANY WARRANTY; without even the implied
11    # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12    # PURPOSE. See the GNU General Public License for more details.
13    #
14    # You should have received a copy of the GNU General Public
15    # License along with program; see the file COPYING. If not,
16    # write to the Free Software Foundation, Inc., 59 Temple Place
17    # - Suite 330, Boston, MA 02111-1307, USA.
18    #
19    # Copyright 2000-2003 Free Software Foundation
20    #
21    # FILE:
22    # sapdb/DBdriver.py
23    #
24    # DESCRIPTION:
25    # Driver to provide access to data via SAP's SAP-DB/Python Driver
26    # Requires SAP-DB (http://www.sapdb.org/)
27    #
28    # NOTES:
29    #
30    #   Supported attributes (via connections.conf or <database> tag)
31    #
32    #     host=      This is the SAP-DB host for your connection (optional)
33    #     dbname=    This is the SAP-DB database to use (required)
34    #     timeout=   Command timeout in seconds (optional)
35    #     isolation= Isolation level (options)
36    #     sqlmode=   INTERNAl or ORACLE (optional)
37    #     sqlsubmode= ODBC or empty (optional)
38    #
39    
40    _exampleConfig = """
41    # This connection uses the SAP DB  driver
42    # We will be connecting to the SAP DB server on
43    # "localhost" to a database called "TST".
44    [sapdb]
45    comment = XYZ Development Database
46    provider = sapdb
47    dbname = TST
48    # host = localhost   # (optional)
49    # sqlmode = INTERNAL # (default) or ORACLE
50    # sqlsubmode = ODBC  # (for compatibility with the SAP DB ODBC driver)
51    # timeout = 900      # (command timeout in seconds)
52    # isolation = 1      # 0, 1 (default), 10, 15, 2, 20, 3, 30
53    """
54    
55    __all__ = ['Connection']
56    
57    #### THIS IS AN UNTESTED DRIVER ####
58    ####      Any volunteers?       ####
59    
60    import string
61    from string import lower
62    import sys
63    from gnue.common.datasources import GDataObjects, GConditions, GConnections
64    from gnue.common.apps import GDebug
65    from gnue.common.datasources.drivers import DBSIG2
66    
67    try:
68      import sapdbapi as SIG2api
69    except ImportError, message:
70      tmsg = _("Driver not installed: sapdbapi for SAP-DB 7.x \n[%s]") % message
71      raise GConnections.AdapterNotInstalled, tmsg
72    
73    from gnue.common.datasources.drivers.sapdb.Schema.Discovery.Introspection import Introspection
74    
75    
76    ######################################################################
77    #
78    #  GConnection object for PostgreSQL-based drivers
79    #
80    class Connection(DBSIG2.Connection):
81    
82      _DatabaseError = SIG2api.DatabaseError
83      defaultBehavior = Introspection
84      supportedDataObjects = {
85        'object': DataObject_Object,
86        'sql':    DataObject_SQL
87      }
88    
89      def connect(self, connectData={}):
90        GDebug.printMesg(1,"SAP database driver initializing")
91        try:
92          options = {'autocommit': 'off'}
93          for gnueName, sapdbName in [('sqlmode', 'sqlmode'),
94                                      ('timeout', 'timeout'),
95                                      ('isolation', 'isolation'),
96                                      ('sqlsubmode', 'component')]:
97              if connectData.has_key (gnueName):
98                  options [sapdbName] = connectData [gnueName]
99          self.native = apply (SIG2api.connect,
100            (connectData['_username'], connectData['_password'],
101            connectData['dbname'], connectData.get ('host', '')),
102            options)
103          #self.native = SIG2api.connect( \
104          #             user=connectData['_username'], \
105          #             password=connectData['_password'], \
106          #             database=connectData['dbname'], \
107          #             host=connectData.get ('host', ''), \
108          #             autocommit="off")
109        except self._DatabaseError, value:
110          raise GDataObjects.LoginError, value
111    
112    
113    def createConnection (conn, **overrides):
114        from gnue.common.datasources.GConnections import GConnections
115        connections = GConnections (r'D:\Python22\etc\connections.conf')
116        parameters = connections.getConnectionParameters (conn).copy ()
117        dataObject = connections.getDataObject (conn, 'object')
118        parameters.update (overrides)
119        dataObject.connect (parameters)
120        return dataObject
121    
122    def testConnection ():
123        conn, user, pwd = sys.argv [1:4]
124        connection = createConnection (conn, _username = user, _password = pwd)
125        connection.getSchemaList ()
126    
127    if __name__ == "__main__":
128        testConnection ()

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26