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 +4 -4
- data/exe/csvsql +8 -1
- data/lib/csvsql/db.rb +2 -2
- data/lib/csvsql/version.rb +1 -1
- data/lib/csvsql.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5aeb3aec3aede0115a427c13a63f1b19aba0b81b
|
4
|
+
data.tar.gz: 106281657817a283a65ed681234c7a4760dff1a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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],
|
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
|
data/lib/csvsql/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2018-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sqlite3
|