slyce 1.3.3 → 1.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/slyce +20 -19
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00d9ddd3a6d353a87ede364090e7b534adeb9f0f7c2bc64c374db8dcf9e181d9
4
- data.tar.gz: 2b22b3ee7f996cda2c5770af031fc8fa65db652d54b70bd16bcea03247ce9d3d
3
+ metadata.gz: 9e63de054e38ac6dd6b847b8aec37b750955c285c710bf8cc713c61c3e309b78
4
+ data.tar.gz: 6a1222e3f162739c198eb83084a6b73688a6acface1d094477884da68f797e6c
5
5
  SHA512:
6
- metadata.gz: d91171715f18698c3ced8c1f7a0a7eca87d28766a2b99e7272950760cc21f3cc6eab626f57f45d5adbd2e6b33590c04e56f6d55a8427241ecc31ff45d7506d74
7
- data.tar.gz: 3ea0f1d215bb9bb0a4c6cc70b7e579e61a7e7167950f83ec48e27bbb88f987df571da4b0bf31ee772ef3214768fa0b2df43f0d20af6dd80effa809a462a7846c
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.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"
@@ -43,7 +43,7 @@ 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 = "where\n #{filt}"
46
+ filt = opts[:where ] and filt = "\nwhere\n #{filt}"
47
47
 
48
48
  dbas ||= ARGV.shift or abort "no database given"
49
49
  tabl ||= ARGV.shift or opts[:tables] or !want.empty? or abort "no table given"
@@ -98,7 +98,9 @@ else
98
98
  end
99
99
  end
100
100
 
101
+ # connect to database and get server version
101
102
  conn = Mysql2::Client.new(**conf, as: :array)
103
+ ver5 = conn.server_info[:version] =~ /^5/
102
104
 
103
105
  # dump database schema or show table names
104
106
  if tabl.nil? || opts[:tables] || opts[:dump]
@@ -154,8 +156,7 @@ if xprt
154
156
  select
155
157
  #{list}
156
158
  from
157
- `#{tabl}`
158
- #{filt}
159
+ `#{tabl}`#{filt}
159
160
 
160
161
  seps = xcsv ? "," : xtsv ? "\t" : xpsv ? "|" : abort("unknown separator #{seps.inspect}")
161
162
 
@@ -169,36 +170,36 @@ if xprt
169
170
  exit
170
171
  end
171
172
 
172
- # MySQL 5.7 compatible version (still need to find replacement for regexp_instr)
173
- # -if((`#{name}` rlike '^[-+]?((0|([1-9]\\\\d*)(\\\\.\\\\d*)?)|((0|([1-9]\\\\d*))\\\\.\\\\d+))$'), `#{name}` + 0, null) desc,
174
- # -if((`#{name}` rlike '^0\\\\d+$'), length(`#{name}`), null) desc,
175
- # -if((`#{name}` rlike '^\\\\d'), regexp_instr(`#{name}`, '[^\\\\d]'), null) desc,
176
-
177
173
  want.each do |name|
178
174
  sort = natu ? "" : "cnt desc,"
179
- stmt = show ? "limit #{show}" : ""
180
- data = conn.sql(<<~"" + stmt).to_a
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
181
185
  select
182
186
  count(*) as cnt,
183
187
  `#{name}` as val
184
188
  from
185
- `#{tabl}`
186
- #{filt}
189
+ `#{tabl}`#{filt}
187
190
  group by
188
191
  val
189
192
  order by #{sort}
190
- -if(regexp_like(`#{name}`, '^[-+]?((0|([1-9]\\\\d*)(\\\\.\\\\d*)?)|((0|([1-9]\\\\d*))\\\\.\\\\d+))$'), `#{name}` + 0, null) desc,
191
- -if(regexp_like(`#{name}`, '^0\\\\d+$'), length(`#{name}`), null) desc,
192
- -if(regexp_like(`#{name}`, '^\\\\d'), regexp_instr(`#{name}`, '[^\\\\d]'), null) desc,
193
+ #{like}
193
194
  `#{name}` is null, `#{name}`
195
+ #{show ? "limit #{show}" : ""}
194
196
 
195
- uniq, tots = conn.sql(<<~"").to_a[0]
197
+ uniq, tots = conn.sql(<<~"".rstrip).to_a[0]
196
198
  select
197
199
  count(distinct(ifnull(`#{name}`,0))),
198
200
  count(ifnull(`#{name}`,0))
199
201
  from
200
- `#{tabl}`
201
- #{filt}
202
+ `#{tabl}`#{filt}
202
203
 
203
204
  display(name, data, show, uniq, tots)
204
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.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-29 00:00:00.000000000 Z
11
+ date: 2023-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: any_ascii