#!/usr/bin/python # # # 10/19/2015 Paul Mattione # # ##### Fixes (swaps) 2 of the BCAL discriminator roc-ids # # import sqlite3 as lite import sys import os import re import datetime if len(sys.argv) != 2: print "You must supply a SQLite DB file to modify!" sys.exit(0); # Connect to SQLite DB file db_filename = sys.argv[1] print "" print "opening SQLite DB file: %s" % db_filename print "---------------------------------------------" con = lite.connect(db_filename) with con: # Specify that next cursor should be "dictionary" # (i.e. python's hash map) so columns can be indexed # by name con.row_factory = lite.Row # Create Cursor cur = con.cursor() # Check that this TT file has not already been updated cur.execute("SELECT * FROM Crate WHERE rocid=43 AND crateid=20") Nrows = len( cur.fetchall() ) if Nrows == 0: print 'Fix has already been applied, exiting' sys.exit(-1) # SET the rocid for the TOF discriminator crate query = "UPDATE Crate SET rocid=44 WHERE crateid=20" cur.execute(query) query = "UPDATE Crate SET rocid=43 WHERE crateid=27" cur.execute(query) print 'Done'