- Timestamp:
- Mar 5, 2012, 5:19:48 PM (14 years ago)
- Location:
- branches/meh_branches/ppstack_test
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippToPsps/jython/mysql.py (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/meh_branches/ppstack_test
- Property svn:mergeinfo changed
-
branches/meh_branches/ppstack_test/ippToPsps/jython/mysql.py
r32105 r33415 21 21 22 22 ''' 23 def __init__(self, logger, doc, dbType):23 def __init__(self, logger, config, dbType, dbName=None): 24 24 25 25 # set up logging 26 26 self.logger = logger 27 self. doc = doc27 self.config = config 28 28 self.logger.debug("MySql class constructor") 29 29 30 30 # 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 31 if not dbName: self.dbName = config.getDbName(dbType) 32 else: self.dbName = dbName 33 self.dbHost = config.getDbHost(dbType) 34 self.dbUser = config.getDbUser(dbType) 35 self.dbPass = config.getDbPassword(dbType) 35 36 36 37 # set up JDBC connection … … 42 43 except: 43 44 self.logger.error("Unable to connect to " + self.url) 44 self.everythingOK = False 45 self.everythingOK = False # TODO need this? 46 self.connected = False 45 47 return 46 48 47 49 self.everythingOK = True 48 50 self.connected = True 49 51 50 52 ''' … … 53 55 def disconnect(self): 54 56 self.con.close() 57 self.connected = False 55 58 56 59 ''' … … 61 64 self.logger.debug("MySql destructor") 62 65 self.disconnect() 66 67 ''' 68 Locks a table. This is wait if the locks is already held by another session 69 ''' 70 def lockTable(self, table): 71 self.execute("LOCK TABLES " + table + " WRITE") 72 73 ''' 74 Unlocks all tables locked by this session. 75 ''' 76 def unlockTables(self): 77 self.execute("UNLOCK TABLES") 63 78 64 79 ''' … … 69 84 connectionID = self.getLastConnectionID() 70 85 if connectionID == self.connectionID: 71 self.logger. error("NOT going to kill THIS connection ID")86 self.logger.debug("NOT going to kill THIS connection ID") 72 87 return 73 88 74 89 sql = "KILL %d" % connectionID 75 90 self.execute(sql) 91 92 ''' 93 Checks whether there are any other connections to this database 94 ''' 95 def anyOtherConnections(self): 96 97 sql = "SELECT COUNT(*) \ 98 FROM INFORMATION_SCHEMA.PROCESSLIST \ 99 WHERE DB='" + self.dbName + "'" 100 try: 101 rs = self.executeQuery(sql) 102 rs.first() 103 if rs.getInt(1) > 1: return True 104 else: return False 105 except: 106 self.logger.errorPair("Could not check for connection", sql) 107 pass 108 109 return True 76 110 77 111 ''' … … 97 131 98 132 ''' 133 OPTIMIZEs a table 134 ''' 135 def optimizeTable(self, table): 136 137 sql = "OPTIMIZE TABLE " + table 138 try: self.execute(sql) 139 except: return 140 141 ''' 142 Creates a MySQL-friendly table name from the provided string 143 ''' 144 def getDbFriendlyTableName(self, origName): 145 146 name = origName 147 name = name.replace('.', '_') 148 name = name.replace('/', '_') 149 150 return name 151 152 ''' 99 153 Drops a table 100 154 ''' … … 215 269 nBad = rs.getInt(1) 216 270 217 sql="DELETE from" + tableName + " WHERE " + columnName + " = " + value271 sql="DELETE FROM " + tableName + " WHERE " + columnName + " = " + value 218 272 self.execute(sql) 219 self.logger.info("%s '%s' values in %s %5d deleted" % (columnName, value, tableName, nBad)) 273 self.logger.debugPair("%s rows with %s" % (columnName, value), "%d deleted" % nBad) 274 275 return nBad 220 276 221 277 ''' … … 229 285 nBad = rs.getInt(1) 230 286 231 sql="DELETE from" + tableName + " WHERE " + columnName + " IS NULL"287 sql="DELETE FROM " + tableName + " WHERE " + columnName + " IS NULL" 232 288 self.execute(sql) 233 self.logger.debugPair("NULL %s values " % columnName, "%d deleted" % nBad)289 self.logger.debugPair("NULL %s values in %s" % (columnName, tableName), "%d deleted" % nBad) 234 290 235 291 return nBad
Note:
See TracChangeset
for help on using the changeset viewer.
