lib/csvsql/db.rb in csvsql-0.1.3 vs lib/csvsql/db.rb in csvsql-0.1.4
- old
+ new
@@ -40,21 +40,21 @@
db.prepare(sql)
rescue SQLite3::SQLException => e
process_sql_error(sql, e)
end
- def import(csv_data_or_path)
+ def import(csv_data_or_path, encoding: 'utf-8')
case csv_data_or_path
when StringIO, IO
@csv_io = csv_data_or_path
else
@csv_path = csv_data_or_path
end
@db = SQLite3::Database.new(get_db_path(@csv_path))
tables = db.execute("SELECT name FROM sqlite_master WHERE type='table';").flatten
unless tables.include?('csv')
- init_db_by_csv(@csv_io ? CSV.new(@csv_io) : CSV.open(@csv_path))
+ init_db_by_csv(@csv_io ? CSV.new(@csv_io) : CSV.open(@csv_path, "r:#{encoding}"))
end
true
end
private