39 |
try: |
try: |
40 |
import MySQLdb |
import MySQLdb |
41 |
except ImportError, message: |
except ImportError, message: |
42 |
tmsg = _("Driver not installed: sapdbapi for SAP-DB 7.x \n[%s]") % message |
tmsg = _("\nCould not load MySQLdb. For MySQL support, please install \n") \ |
43 |
|
+ _("mysql-python 0.9.0 or later from") \ |
44 |
|
+ "http://sourceforge.net/projects/mysql-python\n" \ |
45 |
|
+ _("[Error: %s]") % message |
46 |
|
|
47 |
raise GConnections.AdapterNotInstalled, tmsg |
raise GConnections.AdapterNotInstalled, tmsg |
48 |
|
|
49 |
from gnue.common.datasources.drivers import DBSIG2 |
from gnue.common.datasources.drivers import DBSIG2 |
64 |
'sql': DataObject_SQL |
'sql': DataObject_SQL |
65 |
} |
} |
66 |
|
|
67 |
self._mysql = MySQLdb |
_mysql = MySQLdb |
68 |
|
|
69 |
def connect(self, connectData={}): |
def connect(self, connectData={}): |
70 |
GDebug.printMesg(1,"Mysql database driver initializing") |
GDebug.printMesg(1,"Mysql database driver initializing") |
71 |
|
|
72 |
|
# 1. just allow string type username/password 2. None -> '' |
73 |
|
user = str(connectData['_username'] or '') |
74 |
|
passwd = str(connectData['_password'] or '') |
75 |
|
|
76 |
try: |
try: |
77 |
self.native = MySQLdb.connect(user=connectData['_username'], |
self.native = MySQLdb.connect(user=user, |
78 |
passwd=connectData['_password'], |
passwd=passwd, |
79 |
host=connectData['host'], |
host=connectData['host'], |
80 |
db=connectData['dbname']) |
db=connectData['dbname']) |
81 |
|
|
82 |
except self._DatabaseError, value: |
except self._DatabaseError, value: |
83 |
raise GDataObjects.LoginError, value |
raise GDataObjects.LoginError, value |
84 |
|
|
92 |
pass |
pass |
93 |
|
|
94 |
|
|
95 |
|
######### |
96 |
# Return the current date, according to database |
# |
97 |
# def getDate(self): |
# Extensions to the basic GConnection object |
98 |
# pass |
# |
99 |
|
|
100 |
|
# Return the current date, according to database |
101 |
|
def getTimeStamp(self): |
102 |
|
return self.__singleQuery("select current_timestamp") |
103 |
|
|
104 |
# Return a sequence number from sequence 'name' |
# Return a sequence number from sequence 'name' |
105 |
# def getSequence(self, name): |
#def getSequence(self, name): |
106 |
# pass |
# raise "Not supported" |
107 |
|
|
108 |
# Run the SQL statement 'statement' |
# Run the SQL statement 'statement' |
109 |
# def sql(self, statement): |
def sql(self, statement): |
110 |
# pass |
cursor = self.native.cursor() |
111 |
|
try: |
112 |
|
cursor.execute(statement) |
113 |
|
cursor.close() |
114 |
|
except: |
115 |
|
cursor.close() |
116 |
|
raise |
117 |
|
|
118 |
|
# Used internally |
119 |
|
def __singleQuery(self, statement): |
120 |
|
cursor = self.native.cursor() |
121 |
|
try: |
122 |
|
cursor.execute(statement) |
123 |
|
rv = cursor.fetchone() |
124 |
|
cursor.close() |
125 |
|
except: |
126 |
|
print "DBdriver.py", "You've got your bar in my foo! And you've got your foo on my bar! Two great reams that ream well together!" |
127 |
|
GDebug.printMesg(1,"**** Unable to execute extension query") |
128 |
|
GDebug.printMesg(1,"**** %s" % sys.exc_info()[1]) |
129 |
|
cursor.close() |
130 |
|
raise |
131 |
|
|
132 |
|
try: |
133 |
|
return rv[0] |
134 |
|
except: |
135 |
|
return None |