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

« back to all changes in this revision

Viewing changes to src/datasources/drivers/sqlrelay/sqlrelay/Connection.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
# SQLRelay/DBdriver.py
 
23
#
 
24
# DESCRIPTION:
 
25
# Driver to provide access to data via SQLRelay's Python Driver
 
26
# Requires SQLRelay + Python-DB Driver (http://www.firstworks.com/sqlrelay)
 
27
#
 
28
# NOTES:
 
29
#
 
30
#   Supported attributes (via connections.conf or <database> tag)
 
31
#
 
32
#     host=      This is the SQLRelay host for your connection (required)
 
33
#                In the format hostname:port (or ipaddr:port)
 
34
#
 
35
 
 
36
__all__ = ['Connection']
 
37
 
 
38
####                                   ####
 
39
#### IF YOU MODIFY ANY CONNECTION      ####
 
40
#### ATTRIBUTES, PLEASE UPDATE info.py ####
 
41
####                                   ####
 
42
 
 
43
 
 
44
from string import lower
 
45
import sys
 
46
from gnue.common.datasources import GDataObjects, GConditions, GConnections
 
47
from gnue.common.apps import GDebug
 
48
from gnue.common.datasources.drivers import DBSIG2
 
49
 
 
50
try:
 
51
  from SQLRelay import PySQLRDB as SIG2api
 
52
except ImportError:
 
53
  raise GConnections.DependencyError, ('SQLRelay', None)
 
54
 
 
55
 
 
56
from gnue.common.datasources.drivers.sqlrelay.Schema.Discovery.Introspection import Introspection
 
57
 
 
58
 
 
59
######################################################################
 
60
#
 
61
#  GConnection object for PostgreSQL-based drivers
 
62
#
 
63
class Connection(DBSIG2.Connection):
 
64
 
 
65
  _driver = SIG2api
 
66
  defaultBehavior = Introspection
 
67
  _DatabaseError = SIG2api.DatabaseError
 
68
  supportedDataObjects = {
 
69
    'object': DataObject_Object,
 
70
    'sql':    DataObject_SQL
 
71
  }
 
72
 
 
73
 
 
74
  def connect(self, connectData={}):
 
75
    GDebug.printMesg(9,"SQLRelay database driver initializing")
 
76
 
 
77
    host = connectData['host']
 
78
    try:
 
79
      port = int(connectData['port'])
 
80
    except ValueError:
 
81
      port = 9000
 
82
 
 
83
    try:
 
84
      self.native = SIG2api.connect( host, port, '', \
 
85
                   connectData['_username'], \
 
86
                   connectData['_password'], \
 
87
                   0,1)
 
88
    except self._DatabaseError, value:
 
89
      raise GDataObjects.LoginError, value
 
90