Changeset 35417 for trunk/ippToPsps/jython/scratchdb.py
- Timestamp:
- Apr 19, 2013, 4:35:54 PM (13 years ago)
- Location:
- trunk/ippToPsps
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
jython/scratchdb.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps
- Property svn:mergeinfo changed
/branches/eam_branches/ipp-20130307/ippToPsps (added) merged: 35350,35352,35369,35402-35404,35413
- Property svn:mergeinfo changed
-
trunk/ippToPsps/jython/scratchdb.py
r35226 r35417 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) … … 38 38 self.dvoSkyTable = "dvoSkyTable" 39 39 self.dvoPhotcodesTable = "dvoPhotcodes" 40 self.memoryTableSize = config.getDbMemory(dbType) 40 41 41 42 ''' … … 368 369 369 370 ''' 371 Checks whether the given chipID is in the DVO Image table 372 ''' 373 def haveThisChip(self, imageID, sourceID): 374 375 sql = "SELECT EXTERN_ID FROM " \ 376 + self.dvoImagesTable + \ 377 " WHERE EXTERN_ID = " + str(imageID) + \ 378 " AND SOURCE_ID = " + str(sourceID) 379 380 try: 381 rs = self.executeQuery(sql) 382 383 if not rs: 384 print "missing result set for imageID query" 385 raise 386 387 # if no returned rows, return an error 388 if not rs.next(): 389 print "DVO lacks imageID ", imageID 390 print "sql: ", sql 391 return False 392 393 if rs.getInt(1) == int(imageID): 394 # print "DVO has imageID ", imageID 395 return True 396 397 else: 398 print "DVO has wrong imageID? ", imageID 399 print "result was ", rs.getInt(1) 400 print "sql: ", sql 401 raise 402 403 except: 404 print "DVO imageID query failed ", imageID 405 print "sql: ", sql 406 raise 407 408 # how can I reach this? 409 return True 410 411 ''' 370 412 Creates a table for for ID matching 371 413 ''' … … 409 451 objID BIGINT, \ 410 452 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, \453 zp FLOAT, \ 454 zpErr FLOAT, \ 455 airMass FLOAT, \ 456 expTime FLOAT, \ 457 ra DOUBLE, \ 458 dec_ DOUBLE, \ 459 raErr FLOAT, \ 460 decErr FLOAT, \ 419 461 PRIMARY KEY (imageID, ippDetectID), \ 420 462 KEY (objID, detectID) \ … … 463 505 Drops and recreates tables necessary for dvoToMySQL program. Be very careful before using this... 464 506 ''' 507 def resetDvoDetectionTable(self): 508 509 self.logger.infoPair("Dropping table", self.dvoDetectionTable) 510 self.dropTable(self.dvoDetectionTable) 511 512 # we need a big enough memory table for the incoming detections 513 print "requested memory in gigs: ", self.memoryTableSize 514 tableSize = int(self.memoryTableSize) * 1024 * 1024 * 1024 515 sql = "set @@max_heap_table_size = " + str(tableSize) 516 print "setting max heap size: ", sql 517 try: self.execute(sql) 518 except: 519 self.logger.errorPair("Unable to set max MEMORY table size for ", self.dvoDetectionTable) 520 return False 521 522 # create detections table 523 self.logger.infoPair("Creating table", self.dvoDetectionTable) 524 sql = "CREATE TABLE " + self.dvoDetectionTable + " LIKE dvoDetection" 525 try: self.execute(sql) 526 except: 527 self.logger.errorPair("Unable to create table", self.dvoDetectionTable) 528 return False 529 530 # XXX changing the dvoDetectionFull table to MEMORY 531 # self.changeEngineToInnoDB(self.dvoDetectionTable) 532 533 # set engine to memory 534 sql = "ALTER TABLE " + self.dvoDetectionTable + " ENGINE = MEMORY" 535 try: self.execute(sql) 536 except: 537 self.logger.errorPair("Unable to set engine to MEMORY for ", self.dvoDetectionTable) 538 return False 539 540 return True 541 542 ''' 543 Drops and recreates tables necessary for dvoToMySQL program. Be very careful before using this... 544 ''' 465 545 def resetAllDvoTables(self): 466 546 … … 485 565 self.changeEngineToInnoDB(self.dvoDoneTable) 486 566 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) 567 # blow away existing dvoDetection table & re-crate 568 if not self.resetDvoDetectionTable(): 569 self.logger.errorPair("Unable to reset scratch table", "DvoDetectionFull") 493 570 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 571 519 572 return True
Note:
See TracChangeset
for help on using the changeset viewer.
