IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 3, 2012, 4:40:01 PM (14 years ago)
Author:
rhenders
Message:

added methid to add a column to any table that represents a row count

File:
1 edited

Legend:

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

    r33491 r33683  
    3535
    3636        # set up JDBC connection
    37         self.url = "jdbc:mysql://"+self.dbHost+"/"+self.dbName+"?user="+self.dbUser+"&password="+self.dbPass
     37        self.url = "jdbc:mysql://"+self.dbHost+"/"+self.dbName+"?autoReconnect=true&user="+self.dbUser+"&password="+self.dbPass
    3838        try:
    3939            self.con = DriverManager.getConnection(self.url)
     
    148148
    149149        return name
     150
     151    '''
     152    Drops a column from a table
     153    '''
     154    def dropColumn(self, table, column):
     155
     156        sql = "ALTER TABLE " + table + " DROP " + column
     157        try: self.execute(sql)
     158        except: return
    150159
    151160    '''
     
    355364            return -1
    356365
    357 
     366    '''
     367    Adds a column to this table which contains a row count
     368    '''
     369    def addRowCountColumn(self, table, colName):
     370
     371        self.execute("ALTER TABLE " + table + " ADD COLUMN " + colName + " INTEGER FIRST")
     372        self.execute("SET @i = 0")
     373        self.execute("UPDATE " + table + " SET " + colName + "=(@i:=@i+1)")
     374        self.execute("ALTER TABLE " + table + " ADD PRIMARY KEY (" + colName + ")")
     375
Note: See TracChangeset for help on using the changeset viewer.