def save_data(uniq_keys, values_array, tbl_name)
      values_array = [values_array].flatten(1) # coerce to an array
      all_field_names = values_array.map(&:keys).flatten.uniq
      all_field_names_as_string = format_field_names_as_string(all_field_names)
      all_field_names_as_symbol_string = all_field_names.map{ |k| ":#{k}" }.join(',') # need to appear as symbols
      begin
        values_array.each do |values_hash|
          # mustn't use nil value in unique value due to fact that SQLite considers NULL values to be different from
          # each other in UNIQUE indexes. See http://www.sqlite.org/lang_createindex.html
          raise DatabaseError.new("Data has nil value for unique key. Unique keys are #{uniq_keys}. Offending data: #{values_hash.inspect}") unless uniq_keys.all?{ |k| values_hash[k] }
          sql_query =  "INSERT OR REPLACE INTO #{tbl_name} (#{all_field_names_as_string}) VALUES (#{all_field_names_as_symbol_string})"
          database.execute(sql_query, values_hash)
        end
      rescue SQLite3::SQLException => e
        puts "Exception (#{e.inspect}) raised" if verbose?
        case e.message
        when /no such table/
          create_table(tbl_name, all_field_names, uniq_keys)
          retry
        when /has no column/
          add_columns(tbl_name, all_field_names)
          retry
        else
          raise e
        end
      end
    end
def save_data(uniq_keys, values_array, tbl_name)
      values_array = [values_array].flatten(1) # coerce to an array
      all_field_names = values_array.map(&:keys).flatten.uniq
      all_field_names_as_string = format_field_names_as_string(all_field_names)
      all_field_names_as_symbol_string = all_field_names.map{ |k| ":#{k}" }.join(',') # need to appear as symbols
      begin
        values_array.each do |values_hash|
          # mustn't use nil value in unique value due to fact that SQLite considers NULL values to be different from
          # each other in UNIQUE indexes. See http://www.sqlite.org/lang_createindex.html
          raise DatabaseError.new("Data has nil value for unique key. Unique keys are #{uniq_keys}. Offending data: #{values_hash.inspect}") unless uniq_keys.all?{ |k| values_hash[k] }
          sql_query =  "INSERT OR REPLACE INTO #{tbl_name} (#{all_field_names_as_string}) VALUES (#{all_field_names_as_symbol_string})"
          database.execute(sql_query, values_hash)
        end
      rescue SQLite3::SQLException => e
        puts "Exception (#{e.inspect}) raised" if verbose?
        case e.message
        when /no such table/
          create_table(tbl_name, all_field_names, uniq_keys)
          retry
        when /has no column/
          add_columns(tbl_name, all_field_names)
          retry
        else
          raise e
        end
      end
    end
#save data into the database