IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 33780


Ignore:
Timestamp:
Apr 13, 2012, 2:10:56 PM (14 years ago)
Author:
rhenders
Message:

new method to check if a table exists; new method to drop a list of tables

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippToPsps/jython/mysql.py

    r33683 r33780  
    9090
    9191    '''
     92    Checks whether this table exists
     93    '''
     94    def tableExists(self, tableName):
     95
     96        sql = "SELECT COUNT(*) \
     97               FROM information_schema.tables \
     98               WHERE table_schema = '" + self.dbName + "' \
     99               AND table_name = '" + tableName + "'"
     100
     101        try:
     102            rs = self.executeQuery(sql)
     103            rs.first()
     104            if rs.getInt(1) > 0: return True
     105            else: return False
     106        except:
     107            self.logger.errorPair("Could not check if table exists", sql)
     108            pass
     109
     110        return False
     111
     112    '''
    92113    Checks whether there are any other connections to this database
    93114    '''
     
    157178        try: self.execute(sql)
    158179        except: return
     180
     181    '''
     182    Drops a list of tables
     183    '''
     184    def dropTables(self, tables):
     185        for table in tables: self.dropTable(table)
    159186
    160187    '''
Note: See TracChangeset for help on using the changeset viewer.