IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 29, 2012, 5:07:20 PM (14 years ago)
Author:
eugene
Message:

merging changes from trunk

File:
1 edited

Legend:

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

    r33683 r33948  
    3434        self.dbPass = config.getDbPassword(dbType)
    3535
     36        # a user friendly connection sring
     37        connectionStr = self.dbName + "@" + self.dbHost
     38
    3639        # set up JDBC connection
    3740        self.url = "jdbc:mysql://"+self.dbHost+"/"+self.dbName+"?autoReconnect=true&user="+self.dbUser+"&password="+self.dbPass
     
    3942            self.con = DriverManager.getConnection(self.url)
    4043            self.connectionID = self.getLastConnectionID()
    41             self.logger.debug("MySQL connection to %s with ID %d" % (dbType, self.connectionID))
     44            self.logger.infoPair("Connected to MySQL Db", connectionStr)
    4245        except:
    43             self.logger.error("Unable to connect to " + self.url)
    44             self.everythingOK = False # TODO need this?
     46            self.logger.errorPair("Unable to connect to", connectionStr)
    4547            self.connected = False
    46             return
    47 
    48         self.everythingOK = True
     48            raise
     49
    4950        self.connected = True
    5051
     
    8889        sql = "KILL %d" % connectionID
    8990        self.execute(sql)
     91
     92    '''
     93    Checks whether this table exists
     94    '''
     95    def tableExists(self, tableName):
     96
     97        sql = "SELECT COUNT(*) \
     98               FROM information_schema.tables \
     99               WHERE table_schema = '" + self.dbName + "' \
     100               AND table_name = '" + tableName + "'"
     101
     102        try:
     103            rs = self.executeQuery(sql)
     104            rs.first()
     105            if rs.getInt(1) > 0: return True
     106            else: return False
     107        except:
     108            self.logger.errorPair("Could not check if table exists", sql)
     109            pass
     110
     111        return False
    90112
    91113    '''
     
    159181
    160182    '''
     183    Drops a list of tables
     184    '''
     185    def dropTables(self, tables):
     186        for table in tables: self.dropTable(table)
     187
     188    '''
    161189    Drops a table
    162190    '''
     
    224252        except: pass
    225253            #self.logger.warn("Index already in place on '" + column + "' for table '" + table + "'")
     254
     255    '''
     256    Checks that we have a connection
     257    '''
     258    def isConnected(self):
     259
     260        try:
     261            self.con
     262            self.connected = True
     263        except:
     264            self.logger.errorPair("Not connected to", self.url)
     265            self.connected = False
     266
     267        return self.connected
     268
    226269    '''
    227270    TODO
    228271    '''
    229272    def execute(self, sql):
     273
     274        if not self.isConnected(): raise
    230275
    231276        stmt = self.con.createStatement()
     
    238283    def executeQuery(self, sql):
    239284
     285        if not self.isConnected(): raise
     286 
    240287        stmt = self.con.createStatement()
    241288        rs = stmt.executeQuery(sql)
Note: See TracChangeset for help on using the changeset viewer.