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 |
|
# SQLitedb/DBdriver.py |
23 |
|
# |
24 |
|
# DESCRIPTION: |
25 |
|
# Driver to provide access to data via SQLite's Python Driver. |
26 |
|
# Requires PySQLite (http://pysqlite.sf.net/) |
27 |
|
# |
28 |
|
# NOTES: |
29 |
|
# |
30 |
|
# Supported attributes (via connections.conf or <database> tag) |
31 |
|
# |
32 |
|
# dbname= This is the SQLite database to use (required) |
33 |
|
# |
34 |
|
|
35 |
|
__all__ = ['Connection'] |
36 |
|
|
37 |
|
from string import lower,find,rfind,split,strip |
38 |
|
import sys |
39 |
|
from gnue.common.datasources import GDataObjects, GConditions, GConnections |
40 |
|
from gnue.common.apps import GDebug |
41 |
|
from gnue.common.datasources.drivers import DBSIG2 |
42 |
|
|
43 |
|
try: |
44 |
|
import sqlite as SIG2api |
45 |
|
except ImportError, message: |
46 |
|
tmsg = _("Driver not installed: SQLitedbapi for SQLite 7.x \n[%s]") % message |
47 |
|
raise GConnections.AdapterNotInstalled, tmsg |
48 |
|
|
49 |
|
from gnue.common.datasources.drivers.sqlite.Schema.Discovery.Introspection import Introspection |
50 |
|
|
51 |
|
|
52 |
|
###################################################################### |
53 |
|
# |
54 |
|
# GConnection object for PostgreSQL-based drivers |
55 |
|
# |
56 |
|
class Connection(DBSIG2.Connection): |
57 |
|
|
58 |
|
_DatabaseError = SIG2api.DatabaseError |
59 |
|
defaultBehavior = Introspection |
60 |
|
supportedDataObjects = { |
61 |
|
'object': DataObject_Object, |
62 |
|
'sql': DataObject_SQL |
63 |
|
} |
64 |
|
|
65 |
|
def connect(self, connectData={}): |
66 |
|
GDebug.printMesg(1,"SQLite database driver initializing") |
67 |
|
try: |
68 |
|
self.native = SIG2api.connect( \ |
69 |
|
db=connectData['dbname'], \ |
70 |
|
mode=077 ) |
71 |
|
except self._DatabaseError, value: |
72 |
|
raise GDataObjects.LoginError, value |
73 |
|
|
74 |
|
|
75 |
|
# Return a list of necessary login fields (e.g., user/pass). |
76 |
|
# Each list item is another list of ["field label", isPassword?] |
77 |
|
def getLoginFields(self): |
78 |
|
return [] |
79 |
|
|
80 |
|
|