IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 10, 2015, 12:40:44 PM (11 years ago)
Author:
eugene
Message:

make code less forgiving: sql execute aborts on failures; deal with various hidden problems: add IF EXISTS to drop table operations to avoid raising unneeded error, make sure tables exist before trying to add indexes, test for existence of the stack _xsrc, _xfit, etc tables (and skip if missing); fix sqlLine.group to cast inputs to string before performing string ops; getKeyFloat now returns a float value which is safe with sqlLine.group, but can be used in a math expression; use python math. operators as needed (sqrt, fabs); fulltest.sh runs for camera, stack, object stages; update dvoSkyTable to use REGION_ID instead of special word INDEX; add existsClient method (avoid using mysql failure as a test for table existence); no need to test for exceptions to sql.execute since we abort on failure; replace esoteric SQL with dropTable calls; trap errors in stilts.treads in setupScratchdb; drop StackObjecThin and StackDetOffMeta along with other stack scratch tables

File:
1 edited

Legend:

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

    r38763 r38837  
    914914
    915915    '''
     916    Returns boolean value for this column in clients table
     917    '''
     918    def existsClient(self, host, pid):
     919
     920        sql = "SELECT id FROM clients WHERE host = '" + host + "' AND pid = " + str(pid) + " LIMIT 1"
     921
     922        try:
     923            rs = self.executeQuery(sql)
     924            if rs.first() is False: return False
     925        except:
     926            self.logger.exception("Unable to check if " + host + "-" + str(pid) + " is in clients table")
     927
     928        return True
     929
     930    '''
    916931    Update clients, or inserts it for the first time
    917932    '''
    918933    def updateClient(self, type, host, pid):
    919934
    920         try:
     935        if self.existsClient(host, pid):
     936            self.execute("UPDATE clients SET timestamp = now() WHERE host = '" + host + "' AND pid = " + str(pid))
     937        else:
    921938            self.insertClient(type, host, pid)
    922         except:
    923             self.execute("UPDATE clients SET timestamp = now() WHERE host = '" + host + "' AND pid = " + str(pid))
    924939
    925940    '''
     
    13371352
    13381353        for id in ids:
    1339             sql = "INSERT IGNORE INTO pending \
     1354            # why is there an IGNORE here? we have deleted old versions already above
     1355            sql = "INSERT INTO pending \
    13401356               (box_id, batch_type, stage_id) \
    13411357               VALUES \
    13421358               (" + str(box_id) + ", '" + batchType + "', " + str(id) + ")"
    13431359
    1344             print sql
    1345             try: self.execute(sql)
    1346             except:
    1347                 print "failed to insert into pending"
    1348                 print "sql: " + sql
    1349                 raise
     1360            self.execute(sql)
    13501361
    13511362    '''
     
    16561667    def storeAllItems(self, rows):
    16571668
    1658         try:
    1659             self.execute("DROP TABLE all_pending")
    1660         except:
    1661             pass
     1669        self.dropTable("all_pending")
    16621670
    16631671        self.execute("CREATE TEMPORARY TABLE all_pending (stage_id bigint(20), ra_bore float, dec_bore float)")
    16641672        for row in rows:
    1665 
    16661673            try:
    16671674                sql = "INSERT INTO all_pending (stage_id, ra_bore, dec_bore) \
     
    16781685    '''
    16791686    def storeAllItemsInDvodb(self, rows, dvo_db, batchType):
    1680 
    1681         #try:
    1682         #    self.execute("DROP TABLE all_pending")
    1683         #except:
    1684         #    pass
    16851687
    16861688        #self.execute("CREATE TEMPORARY TABLE all_pending (stage_id bigint(20), ra_bore float, dec_bore float)")
     
    16991701        #self.logger.infoPair("Items written to Db", "%d" % count)
    17001702
    1701 
    1702 
    17031703    '''
    17041704    Gets all items in the all_pending temporary table within the bounds of this box
Note: See TracChangeset for help on using the changeset viewer.