IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 12, 2014, 4:10:18 PM (12 years ago)
Author:
eugene
Message:

merge changes from branches/eam_branches/ipp-20140717

File:
1 edited

Legend:

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

    r35417 r37246  
    8383    '''
    8484    def lockTable(self, table):
     85        # print "Locking table: " + table
    8586        self.execute("LOCK TABLES " + table + " WRITE")
    8687
     
    8990    '''
    9091    def unlockTables(self):
     92        # print "Unlocking tables"
    9193        self.execute("UNLOCK TABLES")
    9294
     
    109111            print "failed to kill connection: ", connectionID
    110112
     113    def listTables(self):
     114
     115        sql = "show tables"
     116        rs = self.executeQuery(sql) 
     117        while (rs.next()):
     118            tableName = rs.getString(1)
     119            # print "table: " + tableName
     120        rs.close()
     121
    111122    '''
    112123    Checks whether this table exists
     
    200211
    201212    '''
     213    Add a column to the table
     214    '''
     215    def addColumn(self, table, column, type):
     216
     217        sql = "ALTER TABLE " + table + " ADD COLUMN " + column + " " + type
     218        try: self.execute(sql)
     219        except: return
     220
     221    '''
    202222    Drops a list of tables
    203223    '''
     
    271291        except: pass
    272292            #self.logger.warn("Index already in place on '" + column + "' for table '" + table + "'")
     293
     294    def addPrimaryKeyWithIgnore(self, table, column):
     295        # note that in mysql versions later than 5.1, this fails
     296        # unless the following is called first:
     297        # "set session old_alter_table=1"
     298
     299        # follow the command with
     300        # "set session old_alter_table=0"
     301
     302        # OF COURSE, this fails for mysql version <= 5.1...
     303        if self.scratchDb.version > 5.1:
     304            self.scratchDb.execute("set session old_alter_table=1")
     305
     306        # I should probably do this before the whole table is built, right?
     307        sql = "ALTER IGNORE TABLE " + table + " ADD PRIMARY KEY (" + column + ")"
     308        self.scratchDb.execute(sql)
     309       
     310        if self.scratchDb.version > 5.1:
     311            self.scratchDb.execute("set session old_alter_table=0")
    273312
    274313    '''
Note: See TracChangeset for help on using the changeset viewer.