~ubuntu-branches/ubuntu/hardy/gnue-common/hardy

« back to all changes in this revision

Viewing changes to src/datasources/drivers/informix/informix/DataObject.py

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2005-03-09 11:06:31 UTC
  • Revision ID: james.westby@ubuntu.com-20050309110631-8gvvn39q7tjz1kj6
Tags: upstream-0.5.14
ImportĀ upstreamĀ versionĀ 0.5.14

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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-2005 Free Software Foundation
 
20
#
 
21
# FILE:
 
22
# informix/DBdriver.py
 
23
#
 
24
# DESCRIPTION:
 
25
# Driver to provide access to data via Alexander Kuznetsov's
 
26
# Informix/Python Driver  *  Requires Kinfxdb 0.2+
 
27
# (http://thor.prohosting.com/~alexan/pub/Kinfxdb/Kinfxdb-0.2.tar.gz)
 
28
#
 
29
# NOTES:
 
30
#
 
31
#     dbame=      This is the Informix database to use (required)
 
32
#     host=      This is the Informix host for your connection  (optional)
 
33
#
 
34
 
 
35
#### THIS IS AN UNTESTED DRIVER ####
 
36
####      Any volunteers?       ####
 
37
 
 
38
 
 
39
from string import lower
 
40
import sys
 
41
from gnue.common.datasources import GDataObjects, GConditions
 
42
from gnue.common.apps import GDebug
 
43
from gnue.common.datasources.drivers import DBSIG2
 
44
 
 
45
raise "This data driver has not been upgraded to the new format."
 
46
 
 
47
 
 
48
import informixdb as SIG2api
 
49
 
 
50
 
 
51
class Informix_RecordSet(DBSIG2.RecordSet):
 
52
  pass
 
53
 
 
54
 
 
55
class Informix_ResultSet(DBSIG2.ResultSet):
 
56
  def __init__(self, dataObject, cursor=None, defaultValues={}, masterRecordSet=None):
 
57
    DBSIG2.ResultSet.__init__(self, dataObject, \
 
58
            cursor, defaultValues, masterRecordSet)
 
59
    self._recordSetClass = Informix_RecordSet
 
60
    self._uniqueIdField = "__GNUeF__uniqueKey_%s" % (self._dataObject.table)
 
61
    self._uniqueIdFormat = "ROWID='%s'"
 
62
 
 
63
 
 
64
 
 
65
class Informix_DataObject(DBSIG2.DataObject):
 
66
  def __init__(self):
 
67
    DBSIG2.DataObject.__init__(self)
 
68
    self._DatabaseError = SIG2api.DatabaseError
 
69
    self._resultSetClass = Informix_ResultSet
 
70
 
 
71
 
 
72
  def connect(self, connectData={}):
 
73
    GDebug.printMesg(9,"Informix database driver initializing")
 
74
    try:
 
75
      if connectData.has_key('host') and len(connectData['host']):
 
76
        db = connectData['dbname'] + "@" + connectData['host']
 
77
      else:
 
78
        db = connectData['dbname']
 
79
      self._dataConnection = SIG2api.connect( \
 
80
                   dbname=connectData['dbname'], \
 
81
                   user=connectData['_username'], \
 
82
                   passwd=connectData['_password'])
 
83
    except self._DatabaseError, value:
 
84
      raise GDataObjects.LoginError, value
 
85
 
 
86
    self._postConnect()
 
87
 
 
88
 
 
89
 
 
90
  #
 
91
  # Schema (metadata) functions
 
92
  #
 
93
 
 
94
  # TODO: See postgresql for an example of what these functions do.
 
95
 
 
96
  # Return a list of the types of Schema objects this driver provides
 
97
  def getSchemaTypes(self):
 
98
    return [('view',_('Views'),1),
 
99
            ('table',_('Tables'),1)]
 
100
 
 
101
  # Return a list of Schema objects
 
102
  def getSchemaList(self, type=None):
 
103
    return []
 
104
 
 
105
  # Find a schema object with specified name
 
106
  def getSchemaByName(self, name, type=None):
 
107
    return None
 
108
 
 
109
  def _postConnect(self):
 
110
    self.triggerExtensions = TriggerExtensions(self._dataConnection)
 
111
 
 
112
 
 
113
class Informix_DataObject_Object(Informix_DataObject, \
 
114
      DBSIG2.DataObject_Object):
 
115
 
 
116
  def __init__(self):
 
117
    Informix_DataObject.__init__(self)
 
118
 
 
119
  def _buildQuery(self, conditions={},forDetail=None,additionalSQL=""):
 
120
    return DBSIG2.DataObject_Object._buildQuery(self, conditions,forDetail,additionalSQL)
 
121
 
 
122
 
 
123
class Informix_DataObject_SQL(Informix_DataObject, \
 
124
      DBSIG2.DataObject_SQL):
 
125
  def __init__(self):
 
126
    # Call DBSIG init first because Informix_DataObject needs to overwrite
 
127
    # some of its values
 
128
    DBSIG2.DataObject_SQL.__init__(self)
 
129
    Informix_DataObject.__init__(self)
 
130
 
 
131
  def _buildQuery(self, conditions={}):
 
132
    return DBSIG2.DataObject_SQL._buildQuery(self, conditions)
 
133
 
 
134
 
 
135
#
 
136
#  Extensions to Trigger Namespaces
 
137
#
 
138
class TriggerExtensions:
 
139
 
 
140
  def __init__(self, connection):
 
141
    self.__connection = connection
 
142
 
 
143
 
 
144
 
 
145
 
 
146
######################################
 
147
#
 
148
#  The following hashes describe
 
149
#  this driver's characteristings.
 
150
#
 
151
######################################
 
152
 
 
153
#
 
154
#  All datasouce "types" and corresponding DataObject class
 
155
#
 
156
supportedDataObjects = {
 
157
  'object': Informix_DataObject_Object,
 
158
  'sql':    Informix_DataObject_SQL
 
159
}
 
160