def load_xml_files_into_database(xmlfiles, verbose = False): """ Initializes in-memory sqlite data base and loads xmlfiles into it Returns connection and curusor objects """ # initialize sqlite connection and cursor object connection = sqlite3.connect(":memory:") cursor = connection.cursor() # set connection in content handler idq_content_handler.connection = connection # load files into database if verbose: print "Loading files into data base ..." for filename in xmlfiles: ligolw_sqlite.insert_from_url(filename, \ contenthandler = idq_tables.use_in_db(idq_content_handler), \ verbose = verbose) # unset connection in content handler idq_content_handler.connection = None return connection, cursor
for n, filename in enumerate(databases, 1): # # access the document # if options.verbose: print >>sys.stderr, "%d/%d:" % (n, len(databases)), if filename.endswith(".xml") or filename.endswith(".xml.gz"): # load XML file into in-ram database for processing fileformat = "xml" working_filename = None connection = sqlite3.connect(":memory:") @dbtables.use_in class LIGOLWContentHandler(ligolw.LIGOLWContentHandler): connection = connection ligolw_sqlite.insert_from_url(filename, contenthandler = LIGOLWContentHandler, preserve_ids = True, verbose = options.verbose) del LIGOLWContentHandler else: # assume it's an SQLite file fileformat = "sqlite" working_filename = dbtables.get_connection_filename(filename, tmp_path = options.tmp_space, verbose = options.verbose) connection = sqlite3.connect(working_filename) # also use the scratch space for sqlite's temp store, but don't try # to do so if the working filename is the same as the original # filename as that most likely indicates some problem was found # with the scratch space like that it's full if options.tmp_space is not None and working_filename != filename: dbtables.set_temp_store_directory(connection, options.tmp_space, verbose = options.verbose) # # apply SQL
# if options.verbose: print("%d/%d:" % (n, len(databases)), end=' ', file=sys.stderr) if filename.endswith(".xml") or filename.endswith(".xml.gz"): # load XML file into in-ram database for processing fileformat = "xml" working_filename = None connection = sqlite3.connect(":memory:") @dbtables.use_in class LIGOLWContentHandler(ligolw.LIGOLWContentHandler): connection = connection ligolw_sqlite.insert_from_url(filename, contenthandler=LIGOLWContentHandler, preserve_ids=True, verbose=options.verbose) del LIGOLWContentHandler else: # assume it's an SQLite file fileformat = "sqlite" working_filename = dbtables.get_connection_filename( filename, tmp_path=options.tmp_space, verbose=options.verbose) connection = sqlite3.connect(working_filename) # also use the scratch space for sqlite's temp store, but don't try # to do so if the working filename is the same as the original # filename as that most likely indicates some problem was found # with the scratch space like that it's full if options.tmp_space is not None and working_filename != filename: dbtables.set_temp_store_directory(connection, options.tmp_space,