csvsql 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dce133a74ba9ec0a5b04f8707ac7726050479c36
4
- data.tar.gz: ae991420839c6c9d384c540e0682643abb48cef7
3
+ metadata.gz: 5aeb3aec3aede0115a427c13a63f1b19aba0b81b
4
+ data.tar.gz: 106281657817a283a65ed681234c7a4760dff1a3
5
5
  SHA512:
6
- metadata.gz: 69c18609d496c4879f6d27baf5b27e93f765d3875ed3302cbd87782d6f88d48dc45ba84e7156d379055bdf372e72644c9d535848875774dec531579ac5fb40e8
7
- data.tar.gz: 55a2436a8e436d4e674f0dc0879131c9de5be513723ddd93cf22df3f379631f2a8208acdd85d5091c6358fde0352ee3941003a514491653912b256549020a4f8
6
+ metadata.gz: d9065c162a7e4c0468cbd42bd37d669af905f365ce04c4ededbb5ac4e2df8fa606899a94a4c1dc01aa630bcd0b7204e426c693cca6afb19f41e1ee6cefe5f7e7
7
+ data.tar.gz: fbde2ef9b1f8b43247701b9c48c20ee0fbab9705ccd599c10cdb7d20589a2f907e3b49c42eabe000f6f5afbb221e331dac7fc266fe047c59f360ed5de16af784
data/exe/csvsql CHANGED
@@ -26,6 +26,10 @@ OptionParser.new do |opts|
26
26
  options[:batch_rows] = n.to_i
27
27
  end
28
28
 
29
+ opts.on('-e', '--encoding encoding', "Set the file encoding, default is UTF-8") do |encoding|
30
+ options[:encoding] = encoding
31
+ end
32
+
29
33
  opts.on('--clear-cache', "Clear all cache data") do
30
34
  options[:clear_cache] = true
31
35
  end
@@ -49,6 +53,9 @@ csv_data = options[:csv_path] || StringIO.new($stdin.read)
49
53
 
50
54
  puts Csvsql.execute(
51
55
  ARGV[0], csv_data,
52
- use_cache: options[:use_cache], batch_rows: options[:batch_rows], sql_error_action: 'exit'
56
+ use_cache: options[:use_cache],
57
+ batch_rows: options[:batch_rows],
58
+ sql_error_action: 'exit',
59
+ encoding: options[:encoding]
53
60
  )
54
61
 
data/lib/csvsql/db.rb CHANGED
@@ -42,7 +42,7 @@ class Csvsql::Db
42
42
  process_sql_error(sql, e)
43
43
  end
44
44
 
45
- def import(csv_data_or_path)
45
+ def import(csv_data_or_path, encoding: 'utf-8')
46
46
  case csv_data_or_path
47
47
  when StringIO, IO
48
48
  @csv_io = csv_data_or_path
@@ -53,7 +53,7 @@ class Csvsql::Db
53
53
 
54
54
  tables = db.execute("SELECT name FROM sqlite_master WHERE type='table';").flatten
55
55
  unless tables.include?('csv')
56
- init_db_by_csv(@csv_io ? CSV.new(@csv_io) : CSV.open(@csv_path))
56
+ init_db_by_csv(@csv_io ? CSV.new(@csv_io) : CSV.open(@csv_path, "r:#{encoding}"))
57
57
  end
58
58
  true
59
59
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Csvsql
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
data/lib/csvsql.rb CHANGED
@@ -10,8 +10,9 @@ require 'csvsql/tracker'
10
10
 
11
11
  module Csvsql
12
12
  def self.execute(sql, csv_data, opts = {})
13
+ encoding = opts.delete(:encoding)
13
14
  csvdb = Csvsql::Db.new(opts)
14
- csvdb.import(csv_data)
15
+ csvdb.import(csv_data, encoding: encoding)
15
16
  pst = Csvsql::Tracker.commit(:execute_query_sql) do
16
17
  csvdb.prepare(sql)
17
18
  end
@@ -22,4 +23,3 @@ module Csvsql
22
23
  end.tap { Csvsql::Tracker.commit(:output_format) }
23
24
  end
24
25
  end
25
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csvsql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - jiangzhi.xie
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-19 00:00:00.000000000 Z
11
+ date: 2018-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sqlite3