comparison roundup/backends/back_mysql.py @ 3156:e1da7b5b04ab maint-0.8

merge from HEAD
author Richard Jones <richard@users.sourceforge.net>
date Mon, 14 Feb 2005 02:55:31 +0000
parents 0a652c47bc9e
children 1128a4689367
comparison
equal deleted inserted replaced
3154:62b1a54107e6 3156:e1da7b5b04ab
36 from roundup.backends.rdbms_common import * 36 from roundup.backends.rdbms_common import *
37 from roundup.backends import rdbms_common 37 from roundup.backends import rdbms_common
38 import MySQLdb 38 import MySQLdb
39 import os, shutil 39 import os, shutil
40 from MySQLdb.constants import ER 40 from MySQLdb.constants import ER
41 import logging
41 42
42 def connection_dict(config, dbnamestr=None): 43 def connection_dict(config, dbnamestr=None):
43 d = rdbms_common.connection_dict(config, dbnamestr) 44 d = rdbms_common.connection_dict(config, dbnamestr)
44 if d.has_key('password'): 45 if d.has_key('password'):
45 d['passwd'] = d['password'] 46 d['passwd'] = d['password']
64 tables = cursor.fetchall() 65 tables = cursor.fetchall()
65 # stupid MySQL bug requires us to drop all the tables first 66 # stupid MySQL bug requires us to drop all the tables first
66 for table in tables: 67 for table in tables:
67 command = 'DROP TABLE %s'%table[0] 68 command = 'DROP TABLE %s'%table[0]
68 if __debug__: 69 if __debug__:
69 config.logging.getLogger('hyperdb').debug(command) 70 logging.getLogger('hyperdb').debug(command)
70 cursor.execute(command) 71 cursor.execute(command)
71 command = "DROP DATABASE %s"%config.RDBMS_NAME 72 command = "DROP DATABASE %s"%config.RDBMS_NAME
72 config.logging.getLogger('hyperdb').info(command) 73 logging.getLogger('hyperdb').info(command)
73 cursor.execute(command) 74 cursor.execute(command)
74 conn.commit() 75 conn.commit()
75 conn.close() 76 conn.close()
76 77
77 if os.path.exists(config.DATABASE): 78 if os.path.exists(config.DATABASE):
81 """Create the database.""" 82 """Create the database."""
82 kwargs = connection_dict(config) 83 kwargs = connection_dict(config)
83 conn = MySQLdb.connect(**kwargs) 84 conn = MySQLdb.connect(**kwargs)
84 cursor = conn.cursor() 85 cursor = conn.cursor()
85 command = "CREATE DATABASE %s"%config.RDBMS_NAME 86 command = "CREATE DATABASE %s"%config.RDBMS_NAME
86 config.logging.getLogger('hyperdb').info(command) 87 logging.getLogger('hyperdb').info(command)
87 cursor.execute(command) 88 cursor.execute(command)
88 conn.commit() 89 conn.commit()
89 conn.close() 90 conn.close()
90 91
91 def db_exists(config): 92 def db_exists(config):
136 hyperdb.Multilink : lambda x: x, # used in journal marshalling 137 hyperdb.Multilink : lambda x: x, # used in journal marshalling
137 } 138 }
138 139
139 def sql_open_connection(self): 140 def sql_open_connection(self):
140 kwargs = connection_dict(self.config, 'db') 141 kwargs = connection_dict(self.config, 'db')
141 self.config.logging.getLogger('hyperdb').info('open database %r'%( 142 logging.getLogger('hyperdb').info('open database %r'%(kwargs['db'],))
142 kwargs['db'],))
143 try: 143 try:
144 conn = MySQLdb.connect(**kwargs) 144 conn = MySQLdb.connect(**kwargs)
145 except MySQLdb.OperationalError, message: 145 except MySQLdb.OperationalError, message:
146 raise DatabaseError, message 146 raise DatabaseError, message
147 cursor = conn.cursor() 147 cursor = conn.cursor()
472 self.sql(sql, vals) 472 self.sql(sql, vals)
473 473
474 def sql_commit(self): 474 def sql_commit(self):
475 ''' Actually commit to the database. 475 ''' Actually commit to the database.
476 ''' 476 '''
477 self.config.logging.getLogger('hyperdb').info('commit') 477 logging.getLogger('hyperdb').info('commit')
478 self.conn.commit() 478 self.conn.commit()
479 479
480 # open a new cursor for subsequent work 480 # open a new cursor for subsequent work
481 self.cursor = self.conn.cursor() 481 self.cursor = self.conn.cursor()
482 482

Roundup Issue Tracker: http://roundup-tracker.org/