- Timestamp:
- Apr 3, 2013, 12:52:33 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20130307/ippToPsps/jython/scratchdb.py
r35226 r35352 29 29 dbType = "localdatabase" 30 30 31 print "trying to connect: ", dbType31 # print "trying to connect: ", dbType 32 32 33 33 dbName = config.getDbName(dbType) … … 368 368 369 369 ''' 370 Checks whether the given chipID is in the DVO Image table 371 ''' 372 def haveThisChip(self, imageID): 373 374 sql = "SELECT IMAGE_ID FROM " + self.dvoImagesTable + " WHERE IMAGE_ID = " + str(imageID) 375 376 try: 377 rs = self.executeQuery(sql) 378 rs.first() 379 if rs.getInt(1) == int(imageID): 380 # print "DVO has imageID ", imageID 381 return True 382 else: 383 print "DVO lacks imageID ", imageID 384 print "result was ", rs.getInt(1) 385 print "sql: ", sql 386 return False 387 except: 388 print "DVO imageID query failed ", imageID 389 print "sql: ", sql 390 return False 391 392 return True 393 394 ''' 370 395 Creates a table for for ID matching 371 396 ''' … … 409 434 objID BIGINT, \ 410 435 flags INT, \ 411 zp REAL, \412 zpErr REAL, \413 airMass REAL, \414 expTime REAL, \415 ra FLOAT, \416 dec_ FLOAT, \417 raErr REAL, \418 decErr REAL, \436 zp FLOAT, \ 437 zpErr FLOAT, \ 438 airMass FLOAT, \ 439 expTime FLOAT, \ 440 ra DOUBLE, \ 441 dec_ DOUBLE, \ 442 raErr FLOAT, \ 443 decErr FLOAT, \ 419 444 PRIMARY KEY (imageID, ippDetectID), \ 420 445 KEY (objID, detectID) \ … … 463 488 Drops and recreates tables necessary for dvoToMySQL program. Be very careful before using this... 464 489 ''' 490 def resetDvoDetectionTable(self): 491 492 self.logger.infoPair("Dropping table", self.dvoDetectionTable) 493 self.dropTable(self.dvoDetectionTable) 494 495 # create detections table 496 self.logger.infoPair("Creating table", self.dvoDetectionTable) 497 sql = "CREATE TABLE " + self.dvoDetectionTable + " LIKE dvoDetection" 498 try: self.execute(sql) 499 except: 500 self.logger.errorPair("Unable to create table", self.dvoDetectionTable) 501 return False 502 503 # XXX changing the dvoDetectionFull table to MEMORY 504 # self.changeEngineToInnoDB(self.dvoDetectionTable) 505 506 # set engine to memory 507 sql = "ALTER TABLE " + self.dvoDetectionTable + " ENGINE = MEMORY" 508 try: self.execute(sql) 509 except: 510 self.logger.errorPair("Unable to set engine to MEMORY for ", self.dvoDetectionTable) 511 return False 512 513 return True 514 515 ''' 516 Drops and recreates tables necessary for dvoToMySQL program. Be very careful before using this... 517 ''' 465 518 def resetAllDvoTables(self): 466 519 … … 485 538 self.changeEngineToInnoDB(self.dvoDoneTable) 486 539 487 # create detections table 488 self.logger.infoPair("Creating table", self.dvoDetectionTable) 489 sql = "CREATE TABLE " + self.dvoDetectionTable + " LIKE dvoDetection" 490 try: self.execute(sql) 491 except: 492 self.logger.errorPair("Unable to create table", self.dvoDetectionTable) 540 # blow away existing dvoDetection table & re-crate 541 if not self.resetDvoDetectionTable(): 542 self.logger.errorPair("Unable to reset scratch table", "DvoDetectionFull") 493 543 return False 494 self.changeEngineToInnoDB(self.dvoDetectionTable)495 496 # add fileID column497 sql = "ALTER TABLE " + self.dvoDetectionTable + " ADD fileID INT NOT NULL"498 try: self.execute(sql)499 except:500 self.logger.errorPair("Unable to add fileID column to ", self.dvoDetectionTable)501 return False502 503 # add an index to the fileID column504 self.createIndex(self.dvoDetectionTable, "fileID")505 506 # XXX : this should be based on choice of useStilts (which is set in dvo.py and must be moved)507 if (False):508 # now add a delete cascading foreign key constraint on fileID509 sql = "ALTER TABLE dvoDetectionFull \510 ADD CONSTRAINT fk_fileID \511 FOREIGN KEY (fileID) \512 REFERENCES dvoDone(id) \513 ON DELETE CASCADE"514 try: self.execute(sql)515 except:516 self.logger.errorPair("Unable to create foreign key on", self.dvoDoneTable)517 return False518 544 519 545 return True
Note:
See TracChangeset
for help on using the changeset viewer.
