module ICalPal
def self.load_data(db_file, q)
def self.load_data(db_file, q) $log.debug(q.gsub("\n", ' ')) rows = [] begin # Open the database $log.debug("Opening database: #{db_file}") db = SQLite3::Database.new(db_file, { readonly: true, results_as_hash: true }) # Prepare the query stmt = db.prepare(q) abort(stmt.columns.sort.join(' ')) if $opts[:props].any? 'list' $opts[:props] = stmt.columns - $opts[:eep] if $opts[:props].any? 'all' # Iterate the SQLite3::ResultSet once stmt.execute.each_with_index { |i, j| rows[j] = i } stmt.close # Close the database db.close $log.debug("Closed #{db_file}") rescue SQLite3::BusyException => e $log.error("Non-fatal error closing database #{db.filename}") raise e rescue SQLite3::CantOpenException => e $log.debug("Can't open #{db_file}") raise e rescue SQLite3::SQLException => e $log.info("#{db_file}: #{e}") raise e rescue SQLite3::Exception => e abort("#{db_file}: #{e}") end rows end