slyce 1.3.2 → 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/slyce +35 -31
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e63de054e38ac6dd6b847b8aec37b750955c285c710bf8cc713c61c3e309b78
|
4
|
+
data.tar.gz: 6a1222e3f162739c198eb83084a6b73688a6acface1d094477884da68f797e6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 176b6aa4493b0e10a0a122d414e2924fe764b18016076b1bb0ecf95127cc4927fc8fc946e878232ab5e4e634a054e095f36fa0467bae6381ee7197c12b8e64a2
|
7
|
+
data.tar.gz: 24732fe38c896f45b6322594af7c55ed3c55e863029ba65146157bf4196e009c032d5d94e8dc68aacdfd19040fbec15b6979516ef1421b4924c7c887708c393c
|
data/bin/slyce
CHANGED
@@ -11,7 +11,7 @@ dbas = nil
|
|
11
11
|
tabl = nil
|
12
12
|
|
13
13
|
OptionParser.new.instance_eval do
|
14
|
-
@version = "1.3.
|
14
|
+
@version = "1.3.4"
|
15
15
|
@banner = "usage: #{program_name} [options] <database> <table>"
|
16
16
|
|
17
17
|
on "--csv" , "Output comma separated values"
|
@@ -19,7 +19,7 @@ OptionParser.new.instance_eval do
|
|
19
19
|
on "--tsv" , "Output tab separated values"
|
20
20
|
on "-a", "--ascii" , "Convert data to ASCII using AnyAscii"
|
21
21
|
on "-c", "--columns" , "Display column names and quit"
|
22
|
-
on "-d", "--dump" , "
|
22
|
+
on "-d", "--dump" , "Dump database schema and quit"
|
23
23
|
on "-h", "--help" , "Show help and command usage" do Kernel.abort to_s; end
|
24
24
|
on "-n", "--natural" , "Sort naturally, not numerically"
|
25
25
|
on "-r", "--rows <count>" , "Rows of data to show", Integer
|
@@ -27,7 +27,7 @@ OptionParser.new.instance_eval do
|
|
27
27
|
on "-t", "--tables" , "Display table names and quit"
|
28
28
|
on "-v", "--version" , "Show version number" do Kernel.abort "#{program_name} #{@version}"; end
|
29
29
|
on "-w", "--where <cond>" , "Where clause (eg - 'age>50 and state='AZ')"
|
30
|
-
on "-x", "--extract <a,b,c...>" , "Comma separated list of columns
|
30
|
+
on "-x", "--extract <a,b,c...>" , "Comma separated list of columns or tables to extract"
|
31
31
|
|
32
32
|
self
|
33
33
|
end.parse!(into: opts={}) rescue abort($!.message)
|
@@ -38,11 +38,12 @@ xtsv = opts[:tsv]
|
|
38
38
|
xprt = xcsv || xpsv || xtsv and require "censive"
|
39
39
|
|
40
40
|
asky = opts[:ascii ] and require "any_ascii"
|
41
|
-
|
42
|
-
|
41
|
+
dump = opts[:dump]
|
42
|
+
want = opts[:extract ].to_s.downcase.split(",")
|
43
43
|
natu = opts[:natural ]
|
44
44
|
show = opts[:rows ]
|
45
|
-
|
45
|
+
hide = opts[:suppress]
|
46
|
+
filt = opts[:where ] and filt = "\nwhere\n #{filt}"
|
46
47
|
|
47
48
|
dbas ||= ARGV.shift or abort "no database given"
|
48
49
|
tabl ||= ARGV.shift or opts[:tables] or !want.empty? or abort "no table given"
|
@@ -78,7 +79,9 @@ end
|
|
78
79
|
# ==[ Let 'er rip! ]==
|
79
80
|
|
80
81
|
# get database connection
|
81
|
-
if dbas.include?("/")
|
82
|
+
if !dbas.include?("/")
|
83
|
+
conf = { database: dbas }
|
84
|
+
else
|
82
85
|
dbas = $' if dbas =~ %r|^mysql://| # drop mysql:// prefix, if present
|
83
86
|
auth, dbas = dbas.split("/", 2)
|
84
87
|
if auth =~ /^(?:(\w+)(?::([^@]+))?@)?(?:([^:]+)?(?::(\d+))?)$/
|
@@ -93,20 +96,21 @@ if dbas.include?("/")
|
|
93
96
|
else
|
94
97
|
abort "invalid database value #{dbas.inspect}"
|
95
98
|
end
|
96
|
-
else
|
97
|
-
conf = { database: dbas }
|
98
99
|
end
|
99
100
|
|
101
|
+
# connect to database and get server version
|
100
102
|
conn = Mysql2::Client.new(**conf, as: :array)
|
103
|
+
ver5 = conn.server_info[:version] =~ /^5/
|
104
|
+
|
105
|
+
# dump database schema or show table names
|
106
|
+
if tabl.nil? || opts[:tables] || opts[:dump]
|
101
107
|
|
102
|
-
# get table names
|
103
|
-
if tabl.nil? || opts[:dump] || opts[:tables]
|
108
|
+
# get table names
|
104
109
|
resu = conn.sql("show tables")
|
105
110
|
tbls = resu.to_a.flatten
|
106
|
-
want = (want.empty? || opts[:tables]) ? tbls : want.select {|e| tbls.include?(e) }
|
107
|
-
|
108
|
-
#!# FIXME: this code is a mess... cleanup soon
|
111
|
+
want = (want.empty? || opts[:tables] || opts[:dump]) ? tbls : want.select {|e| tbls.include?(e) }
|
109
112
|
|
113
|
+
# dump database schema
|
110
114
|
if opts[:dump]
|
111
115
|
pict = "%Y-%m-%dT%H:%M:%S%z"
|
112
116
|
puts "-- Dump of `#{dbas}` database on #{Time.now.strftime(pict)}\n\n"
|
@@ -125,6 +129,7 @@ if tabl.nil? || opts[:dump] || opts[:tables]
|
|
125
129
|
exit
|
126
130
|
end
|
127
131
|
|
132
|
+
# show table names
|
128
133
|
puts want
|
129
134
|
exit
|
130
135
|
end
|
@@ -151,8 +156,7 @@ if xprt
|
|
151
156
|
select
|
152
157
|
#{list}
|
153
158
|
from
|
154
|
-
`#{tabl}
|
155
|
-
#{filt}
|
159
|
+
`#{tabl}`#{filt}
|
156
160
|
|
157
161
|
seps = xcsv ? "," : xtsv ? "\t" : xpsv ? "|" : abort("unknown separator #{seps.inspect}")
|
158
162
|
|
@@ -166,36 +170,36 @@ if xprt
|
|
166
170
|
exit
|
167
171
|
end
|
168
172
|
|
169
|
-
# MySQL 5.7 compatible version (still need to find replacement for regexp_instr)
|
170
|
-
# -if((`#{name}` rlike '^[-+]?((0|([1-9]\\\\d*)(\\\\.\\\\d*)?)|((0|([1-9]\\\\d*))\\\\.\\\\d+))$'), `#{name}` + 0, null) desc,
|
171
|
-
# -if((`#{name}` rlike '^0\\\\d+$'), length(`#{name}`), null) desc,
|
172
|
-
# -if((`#{name}` rlike '^\\\\d'), regexp_instr(`#{name}`, '[^\\\\d]'), null) desc,
|
173
|
-
|
174
173
|
want.each do |name|
|
175
174
|
sort = natu ? "" : "cnt desc,"
|
176
|
-
|
177
|
-
|
175
|
+
like =(ver5 ? <<~"" : <<~"").gsub(/(.)^/m, '\1 ').rstrip
|
176
|
+
-if((`#{name}` rlike '^[-+]?((0|([1-9][0-9]*)(\\\\.[0-9]*)?)|((0|([1-9][0-9]*))\\\\.[0-9]+))$'), `#{name}` + 0, null) desc,
|
177
|
+
-if((`#{name}` rlike '^0[0-9]+$'), length(`#{name}`), null) desc,
|
178
|
+
-if((`#{name}` rlike '^[0-9]'), length(concat("1", `#{name}`) + 0), null) desc,
|
179
|
+
|
180
|
+
-if(regexp_like(`#{name}`, '^[-+]?((0|([1-9]\\\\d*)(\\\\.\\\\d*)?)|((0|([1-9]\\\\d*))\\\\.\\\\d+))$'), `#{name}` + 0, null) desc,
|
181
|
+
-if(regexp_like(`#{name}`, '^0\\\\d+$'), length(`#{name}`), null) desc,
|
182
|
+
-if(regexp_like(`#{name}`, '^\\\\d'), regexp_instr(`#{name}`, '[^\\\\d]'), null) desc,
|
183
|
+
|
184
|
+
data = conn.sql(<<~"".rstrip).to_a
|
178
185
|
select
|
179
186
|
count(*) as cnt,
|
180
187
|
`#{name}` as val
|
181
188
|
from
|
182
|
-
`#{tabl}
|
183
|
-
#{filt}
|
189
|
+
`#{tabl}`#{filt}
|
184
190
|
group by
|
185
191
|
val
|
186
192
|
order by #{sort}
|
187
|
-
|
188
|
-
-if(regexp_like(`#{name}`, '^0\\\\d+$'), length(`#{name}`), null) desc,
|
189
|
-
-if(regexp_like(`#{name}`, '^\\\\d'), regexp_instr(`#{name}`, '[^\\\\d]'), null) desc,
|
193
|
+
#{like}
|
190
194
|
`#{name}` is null, `#{name}`
|
195
|
+
#{show ? "limit #{show}" : ""}
|
191
196
|
|
192
|
-
uniq, tots = conn.sql(<<~"").to_a[0]
|
197
|
+
uniq, tots = conn.sql(<<~"".rstrip).to_a[0]
|
193
198
|
select
|
194
199
|
count(distinct(ifnull(`#{name}`,0))),
|
195
200
|
count(ifnull(`#{name}`,0))
|
196
201
|
from
|
197
|
-
`#{tabl}
|
198
|
-
#{filt}
|
202
|
+
`#{tabl}`#{filt}
|
199
203
|
|
200
204
|
display(name, data, show, uniq, tots)
|
201
205
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slyce
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Shreeve
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-06-
|
11
|
+
date: 2023-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: any_ascii
|