- Timestamp:
- Mar 30, 2012, 2:49:37 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20111122/ippToPsps/jython/mysql.py
r32457 r33638 19 19 ''' 20 20 Constructor 21 22 ''' 23 def __init__(self, logger, doc, dbType): 21 ''' 22 def __init__(self, logger, config, dbType, dbName=None): 24 23 25 24 # set up logging 26 25 self.logger = logger 27 self. doc = doc26 self.config = config 28 27 self.logger.debug("MySql class constructor") 29 28 30 29 # open config and grab database parameters 31 self.dbName = self.doc.find(dbType +"/name").text 32 self.dbHost = self.doc.find(dbType +"/host").text 33 self.dbUser = self.doc.find(dbType +"/user").text 34 self.dbPass = self.doc.find(dbType +"/password").text 30 if not dbName: self.dbName = config.getDbName(dbType) 31 else: self.dbName = dbName 32 self.dbHost = config.getDbHost(dbType) 33 self.dbUser = config.getDbUser(dbType) 34 self.dbPass = config.getDbPassword(dbType) 35 35 36 36 # set up JDBC connection … … 42 42 except: 43 43 self.logger.error("Unable to connect to " + self.url) 44 self.everythingOK = False 44 self.everythingOK = False # TODO need this? 45 self.connected = False 45 46 return 46 47 47 48 self.everythingOK = True 49 self.connected = True 48 50 49 51 ''' … … 52 54 def disconnect(self): 53 55 self.con.close() 56 self.connected = False 54 57 55 58 ''' … … 80 83 connectionID = self.getLastConnectionID() 81 84 if connectionID == self.connectionID: 82 self.logger. error("NOT going to kill THIS connection ID")85 self.logger.debug("NOT going to kill THIS connection ID") 83 86 return 84 87 85 88 sql = "KILL %d" % connectionID 86 89 self.execute(sql) 90 91 ''' 92 Checks whether there are any other connections to this database 93 ''' 94 def anyOtherConnections(self): 95 96 sql = "SELECT COUNT(*) \ 97 FROM INFORMATION_SCHEMA.PROCESSLIST \ 98 WHERE DB='" + self.dbName + "'" 99 try: 100 rs = self.executeQuery(sql) 101 rs.first() 102 if rs.getInt(1) > 1: return True 103 else: return False 104 except: 105 self.logger.errorPair("Could not check for connection", sql) 106 pass 107 108 return True 87 109 88 110 ''' … … 108 130 109 131 ''' 132 OPTIMIZEs a table 133 ''' 134 def optimizeTable(self, table): 135 136 sql = "OPTIMIZE TABLE " + table 137 try: self.execute(sql) 138 except: return 139 140 ''' 141 Creates a MySQL-friendly table name from the provided string 142 ''' 143 def getDbFriendlyTableName(self, origName): 144 145 name = origName 146 name = name.replace('.', '_') 147 name = name.replace('/', '_') 148 149 return name 150 151 ''' 110 152 Drops a table 111 153 ''' … … 141 183 except: pass 142 184 #self.logger.warn("Index already in place on '" + column + "' for table '" + table + "'") 185 ''' 186 Changes the database engine for this table to InnoDb 187 ''' 188 def changeEngineToInnoDB(self, table): 189 self.changeEngine(table, "InnoDB") 190 191 ''' 192 Changes the database engine for this table 193 ''' 194 def changeEngine(self, table, engine): 195 196 sql = "ALTER TABLE " + table + " ENGINE=" + engine 197 try: 198 self.execute(sql) 199 except: 200 self.logger.errorPair("Could not change table engine", sql) 201 return False 202 203 return True 204 143 205 ''' 144 206 Adds an index to the supplied table and column … … 244 306 sql="DELETE FROM " + tableName + " WHERE " + columnName + " IS NULL" 245 307 self.execute(sql) 246 self.logger.debugPair("NULL %s values " % columnName, "%d deleted" % nBad)308 self.logger.debugPair("NULL %s values in %s" % (columnName, tableName), "%d deleted" % nBad) 247 309 248 310 return nBad
Note:
See TracChangeset
for help on using the changeset viewer.
