sqlconv 0.8.0 → 0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/sqlconv +19 -5
- data/sqlconv.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 983c1c2fc4a1dbdd9ee7c4f80af79cf939c6e3c680b620241156eeb35dc7ef0c
|
4
|
+
data.tar.gz: 917c85af386c08ad81f711548f41d5b3244a6ecfa607408aae58acc8c759e74a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6eab5df9b47ab5797cc02d832277a9bcf637b7c7131f1caf2f7d7035923bb27d734f7244993201cbf7fece5943da40ad3069d03e9b396e06e480360e1e1467d
|
7
|
+
data.tar.gz: 935fd564e8799acbc67831008d4745197f978aea6d13fe4a95b0c2797263267739ce6ba917032471ba89587f3798e2e4c542126214b890177ce66a18d7391a62
|
data/bin/sqlconv
CHANGED
@@ -62,7 +62,7 @@ def grok(want)
|
|
62
62
|
end
|
63
63
|
|
64
64
|
# convert the insert statements
|
65
|
-
def conv(tab1, map1, tab2, map2,
|
65
|
+
def conv(tab1, map1, tab2, map2, mode, dump)
|
66
66
|
data = StringScanner.new("")
|
67
67
|
need = grok(map1)
|
68
68
|
cols = nil
|
@@ -73,7 +73,7 @@ def conv(tab1, map1, tab2, map2, repl, dump)
|
|
73
73
|
|
74
74
|
# statement prefix
|
75
75
|
pref = [
|
76
|
-
"#{
|
76
|
+
"#{mode == 'replace' ? 'replace' : 'insert'} into #{tab2 || tab1}",
|
77
77
|
(" (#{map2})" if map2),
|
78
78
|
" values (",
|
79
79
|
].compact.join
|
@@ -83,6 +83,11 @@ def conv(tab1, map1, tab2, map2, repl, dump)
|
|
83
83
|
into = data.scan_for(/insert into (['"`]?)#{tab1}\1 values /io)
|
84
84
|
into or die "unable to find insert statements for the '#{tab1}' table"
|
85
85
|
|
86
|
+
# if needed, output pipes header
|
87
|
+
if mode == "pipes" && map2
|
88
|
+
puts map2.gsub(',','|')
|
89
|
+
end
|
90
|
+
|
86
91
|
# process each line
|
87
92
|
loop do
|
88
93
|
|
@@ -119,6 +124,7 @@ def conv(tab1, map1, tab2, map2, repl, dump)
|
|
119
124
|
case item.func
|
120
125
|
when "rand" then ours.push("'random number here!'")
|
121
126
|
when "n","null" then ours.push("null")
|
127
|
+
when "z" then ours.push((val = cols[item.from-1]) == "NULL" ? 0 : val)
|
122
128
|
else
|
123
129
|
defined?(item.func) == "method" or die "undefined function '#{item.func}'"
|
124
130
|
ours.push *(send item.func, *Array[cols[item.from-1]])
|
@@ -154,7 +160,12 @@ def conv(tab1, map1, tab2, map2, repl, dump)
|
|
154
160
|
end
|
155
161
|
|
156
162
|
# output insert statement
|
157
|
-
|
163
|
+
if mode == "pipes"
|
164
|
+
ours.map! {|item| item == "NULL" ? '' : item.gsub("|","~").gsub("''", "'")[1..-2]}
|
165
|
+
puts ours * "|"
|
166
|
+
else
|
167
|
+
puts [pref, ours * ",", ");"].join
|
168
|
+
end
|
158
169
|
end
|
159
170
|
end
|
160
171
|
|
@@ -173,7 +184,9 @@ ARGV.size.times do
|
|
173
184
|
end
|
174
185
|
|
175
186
|
if ARGV.delete "-r"
|
176
|
-
|
187
|
+
mode = "replace"
|
188
|
+
elsif ARGV.delete "--pipes"
|
189
|
+
mode = "pipes"
|
177
190
|
end
|
178
191
|
|
179
192
|
if ARGV.shift =~ /^([a-z][-\w]*):?(.+)?$/
|
@@ -192,12 +205,13 @@ end
|
|
192
205
|
tab1 or die [
|
193
206
|
"Usage: #{File.basename $0}",
|
194
207
|
"[-p <plugin1.rb> [-p <plugin2.rb>]...]",
|
208
|
+
"[--pipes] (to output pipe separated values instead of SQL",
|
195
209
|
"[-r] (to use 'replace into' instead of 'insert into')",
|
196
210
|
"<src_table>(:[sel1,sel2,...])",
|
197
211
|
"[dst_table][:][col1,col2,...] file"
|
198
212
|
] * ' '
|
199
213
|
|
200
|
-
conv tab1, map1, tab2 || tab1, map2,
|
214
|
+
conv tab1, map1, tab2 || tab1, map2, mode, ARGF
|
201
215
|
|
202
216
|
__END__
|
203
217
|
|
data/sqlconv.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sqlconv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.9'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Shreeve
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Allows mapping columns from a source to a destination table
|
14
14
|
email: steve.shreeve@gmail.com
|
@@ -43,7 +43,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
43
|
version: '0'
|
44
44
|
requirements: []
|
45
45
|
rubyforge_project:
|
46
|
-
rubygems_version: 2.7.
|
46
|
+
rubygems_version: 2.7.7
|
47
47
|
signing_key:
|
48
48
|
specification_version: 4
|
49
49
|
summary: Handy utility to massage MySQL dump files
|