IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 30, 2012, 2:49:37 PM (14 years ago)
Author:
eugene
Message:

merge changes from trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20111122/ippToPsps/jython/mysql.py

    r32457 r33638  
    1919    '''
    2020    Constructor
    21 
    22     '''
    23     def __init__(self, logger, doc, dbType):
     21    '''
     22    def __init__(self, logger, config, dbType, dbName=None):
    2423
    2524        # set up logging
    2625        self.logger = logger
    27         self.doc = doc
     26        self.config = config
    2827        self.logger.debug("MySql class constructor")
    2928
    3029        # 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)
    3535
    3636        # set up JDBC connection
     
    4242        except:
    4343            self.logger.error("Unable to connect to " + self.url)
    44             self.everythingOK = False
     44            self.everythingOK = False # TODO need this?
     45            self.connected = False
    4546            return
    4647
    4748        self.everythingOK = True
     49        self.connected = True
    4850
    4951    '''
     
    5254    def disconnect(self):
    5355        self.con.close()
     56        self.connected = False
    5457
    5558    '''
     
    8083        connectionID = self.getLastConnectionID()
    8184        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")
    8386            return
    8487
    8588        sql = "KILL %d" % connectionID
    8689        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
    87109
    88110    '''
     
    108130
    109131    '''
     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    '''
    110152    Drops a table
    111153    '''
     
    141183        except: pass
    142184            #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
    143205    '''
    144206    Adds an index to the supplied table and column
     
    244306        sql="DELETE FROM " + tableName + " WHERE " + columnName + " IS NULL"
    245307        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)
    247309
    248310        return nBad
Note: See TracChangeset for help on using the changeset viewer.