everypolitician-daff 1.3.26
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +252 -0
- data/bin/daff.rb +3 -0
- data/lib/daff.rb +150 -0
- data/lib/lib/coopy/alignment.rb +307 -0
- data/lib/lib/coopy/cell_builder.rb +17 -0
- data/lib/lib/coopy/cell_info.rb +33 -0
- data/lib/lib/coopy/column_change.rb +16 -0
- data/lib/lib/coopy/combined_table.rb +127 -0
- data/lib/lib/coopy/combined_table_body.rb +151 -0
- data/lib/lib/coopy/combined_table_head.rb +103 -0
- data/lib/lib/coopy/compare_flags.rb +127 -0
- data/lib/lib/coopy/compare_table.rb +688 -0
- data/lib/lib/coopy/conflict_info.rb +23 -0
- data/lib/lib/coopy/coopy.rb +1065 -0
- data/lib/lib/coopy/cross_match.rb +17 -0
- data/lib/lib/coopy/csv.rb +290 -0
- data/lib/lib/coopy/diff_render.rb +339 -0
- data/lib/lib/coopy/diff_summary.rb +28 -0
- data/lib/lib/coopy/flat_cell_builder.rb +75 -0
- data/lib/lib/coopy/highlight_patch.rb +977 -0
- data/lib/lib/coopy/highlight_patch_unit.rb +38 -0
- data/lib/lib/coopy/index.rb +131 -0
- data/lib/lib/coopy/index_item.rb +37 -0
- data/lib/lib/coopy/index_pair.rb +96 -0
- data/lib/lib/coopy/json_table.rb +165 -0
- data/lib/lib/coopy/json_tables.rb +129 -0
- data/lib/lib/coopy/merger.rb +197 -0
- data/lib/lib/coopy/meta.rb +20 -0
- data/lib/lib/coopy/mover.rb +197 -0
- data/lib/lib/coopy/ndjson.rb +134 -0
- data/lib/lib/coopy/nested_cell_builder.rb +74 -0
- data/lib/lib/coopy/ordering.rb +54 -0
- data/lib/lib/coopy/property_change.rb +16 -0
- data/lib/lib/coopy/row.rb +11 -0
- data/lib/lib/coopy/row_change.rb +42 -0
- data/lib/lib/coopy/row_stream.rb +11 -0
- data/lib/lib/coopy/simple_meta.rb +314 -0
- data/lib/lib/coopy/simple_table.rb +345 -0
- data/lib/lib/coopy/simple_view.rb +70 -0
- data/lib/lib/coopy/sparse_sheet.rb +51 -0
- data/lib/lib/coopy/sql_column.rb +47 -0
- data/lib/lib/coopy/sql_compare.rb +605 -0
- data/lib/lib/coopy/sql_database.rb +21 -0
- data/lib/lib/coopy/sql_helper.rb +17 -0
- data/lib/lib/coopy/sql_table.rb +335 -0
- data/lib/lib/coopy/sql_table_name.rb +23 -0
- data/lib/lib/coopy/sql_tables.rb +128 -0
- data/lib/lib/coopy/sqlite_helper.rb +316 -0
- data/lib/lib/coopy/table.rb +24 -0
- data/lib/lib/coopy/table_comparison_state.rb +50 -0
- data/lib/lib/coopy/table_diff.rb +1185 -0
- data/lib/lib/coopy/table_io.rb +72 -0
- data/lib/lib/coopy/table_modifier.rb +40 -0
- data/lib/lib/coopy/table_stream.rb +102 -0
- data/lib/lib/coopy/table_view.rb +148 -0
- data/lib/lib/coopy/tables.rb +52 -0
- data/lib/lib/coopy/terminal_diff_render.rb +213 -0
- data/lib/lib/coopy/unit.rb +93 -0
- data/lib/lib/coopy/view.rb +20 -0
- data/lib/lib/coopy/viterbi.rb +177 -0
- data/lib/lib/haxe/ds/int_map.rb +19 -0
- data/lib/lib/haxe/ds/string_map.rb +19 -0
- data/lib/lib/haxe/format/json_parser.rb +265 -0
- data/lib/lib/haxe/format/json_printer.rb +240 -0
- data/lib/lib/haxe/imap.rb +10 -0
- data/lib/lib/haxe/io/bytes.rb +34 -0
- data/lib/lib/haxe/io/eof.rb +18 -0
- data/lib/lib/haxe/io/error.rb +22 -0
- data/lib/lib/haxe/io/output.rb +41 -0
- data/lib/lib/hx_overrides.rb +19 -0
- data/lib/lib/hx_sys.rb +74 -0
- data/lib/lib/lambda.rb +37 -0
- data/lib/lib/list.rb +36 -0
- data/lib/lib/math.rb +5 -0
- data/lib/lib/rb/boot.rb +39 -0
- data/lib/lib/rb/ruby_iterator.rb +50 -0
- data/lib/lib/reflect.rb +41 -0
- data/lib/lib/std.rb +12 -0
- data/lib/lib/string_buf.rb +19 -0
- data/lib/lib/sys/io/file_handle.rb +18 -0
- data/lib/lib/sys/io/file_output.rb +36 -0
- data/lib/lib/sys/io/hx_file.rb +20 -0
- data/lib/lib/type.rb +37 -0
- data/lib/lib/value_type.rb +23 -0
- data/lib/lib/x_list/list_iterator.rb +32 -0
- metadata +235 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
module Coopy
|
5
|
+
class SqlColumn
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@name = ""
|
9
|
+
@primary = false
|
10
|
+
@type_value = nil
|
11
|
+
@type_family = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_accessor :name
|
15
|
+
attr_accessor :primary
|
16
|
+
attr_accessor :type_value
|
17
|
+
attr_accessor :type_family
|
18
|
+
|
19
|
+
def set_name(name)
|
20
|
+
@name = name
|
21
|
+
end
|
22
|
+
|
23
|
+
def set_primary_key(primary)
|
24
|
+
@primary = primary
|
25
|
+
end
|
26
|
+
|
27
|
+
def set_type(value,family)
|
28
|
+
@type_value = value
|
29
|
+
@type_family = family
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_name
|
33
|
+
@name
|
34
|
+
end
|
35
|
+
|
36
|
+
def is_primary_key
|
37
|
+
@primary
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_s
|
41
|
+
_hx_str((((@primary) ? "*" : ""))) + _hx_str(@name)
|
42
|
+
end
|
43
|
+
|
44
|
+
haxe_me ["coopy", "SqlColumn"]
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,605 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
module Coopy
|
5
|
+
class SqlCompare
|
6
|
+
|
7
|
+
def initialize(db,local,remote,alt,align = nil)
|
8
|
+
@db = db
|
9
|
+
@local = local
|
10
|
+
@remote = remote
|
11
|
+
@alt = alt
|
12
|
+
@align = align
|
13
|
+
@peered = false
|
14
|
+
@alt_peered = false
|
15
|
+
if local != nil && remote != nil
|
16
|
+
if @remote.get_database.get_name_for_attachment != nil
|
17
|
+
if @remote.get_database.get_name_for_attachment != @local.get_database.get_name_for_attachment
|
18
|
+
local.get_database.get_helper.attach(db,"__peer__",@remote.get_database.get_name_for_attachment)
|
19
|
+
@peered = true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
if @alt != nil && local != nil
|
24
|
+
if @alt.get_database.get_name_for_attachment != nil
|
25
|
+
if @alt.get_database.get_name_for_attachment != @local.get_database.get_name_for_attachment
|
26
|
+
local.get_database.get_helper.attach(db,"__alt__",@alt.get_database.get_name_for_attachment)
|
27
|
+
@alt_peered = true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
attr_accessor :db
|
34
|
+
attr_accessor :local
|
35
|
+
attr_accessor :remote
|
36
|
+
attr_accessor :alt
|
37
|
+
|
38
|
+
protected
|
39
|
+
|
40
|
+
attr_accessor :at0
|
41
|
+
attr_accessor :at1
|
42
|
+
attr_accessor :at2
|
43
|
+
attr_accessor :diff_ct
|
44
|
+
attr_accessor :align
|
45
|
+
attr_accessor :peered
|
46
|
+
attr_accessor :alt_peered
|
47
|
+
attr_accessor :needed
|
48
|
+
|
49
|
+
def equal_array(a1,a2)
|
50
|
+
return false if a1.length != a2.length
|
51
|
+
begin
|
52
|
+
_g1 = 0
|
53
|
+
_g = a1.length
|
54
|
+
while(_g1 < _g)
|
55
|
+
i = _g1
|
56
|
+
_g1+=1
|
57
|
+
return false if a1[i] != a2[i]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
true
|
61
|
+
end
|
62
|
+
|
63
|
+
public
|
64
|
+
|
65
|
+
def validate_schema
|
66
|
+
all_cols1 = []
|
67
|
+
key_cols1 = []
|
68
|
+
access_error = false
|
69
|
+
pk_missing = false
|
70
|
+
if @local != nil
|
71
|
+
all_cols1 = @local.get_column_names
|
72
|
+
key_cols1 = @local.get_primary_key
|
73
|
+
access_error = true if all_cols1.length == 0
|
74
|
+
pk_missing = true if key_cols1.length == 0
|
75
|
+
end
|
76
|
+
all_cols2 = []
|
77
|
+
key_cols2 = []
|
78
|
+
if @remote != nil
|
79
|
+
all_cols2 = @remote.get_column_names
|
80
|
+
key_cols2 = @remote.get_primary_key
|
81
|
+
access_error = true if all_cols2.length == 0
|
82
|
+
pk_missing = true if key_cols2.length == 0
|
83
|
+
end
|
84
|
+
all_cols3 = all_cols2
|
85
|
+
key_cols3 = key_cols2
|
86
|
+
if @alt != nil
|
87
|
+
all_cols3 = @alt.get_column_names
|
88
|
+
key_cols3 = @alt.get_primary_key
|
89
|
+
access_error = true if all_cols3.length == 0
|
90
|
+
pk_missing = true if key_cols3.length == 0
|
91
|
+
end
|
92
|
+
raise hx_raise("Error accessing SQL table") if access_error
|
93
|
+
raise hx_raise("sql diff not possible when primary key not available") if pk_missing
|
94
|
+
pk_change = false
|
95
|
+
if @local != nil && @remote != nil
|
96
|
+
pk_change = true if !self.equal_array(key_cols1,key_cols2)
|
97
|
+
end
|
98
|
+
if @local != nil && @alt != nil
|
99
|
+
pk_change = true if !self.equal_array(key_cols1,key_cols3)
|
100
|
+
end
|
101
|
+
raise hx_raise("sql diff not possible when primary key changes") if pk_change
|
102
|
+
true
|
103
|
+
end
|
104
|
+
|
105
|
+
protected
|
106
|
+
|
107
|
+
def denull(x)
|
108
|
+
return -1 if x == nil
|
109
|
+
x
|
110
|
+
end
|
111
|
+
|
112
|
+
def link
|
113
|
+
@diff_ct+=1
|
114
|
+
mode = @db.get(0)
|
115
|
+
i0 = self.denull(@db.get(1))
|
116
|
+
i1 = self.denull(@db.get(2))
|
117
|
+
i2 = self.denull(@db.get(3))
|
118
|
+
if i0 == -3
|
119
|
+
i0 = @at0
|
120
|
+
@at0+=1
|
121
|
+
end
|
122
|
+
if i1 == -3
|
123
|
+
i1 = @at1
|
124
|
+
@at1+=1
|
125
|
+
end
|
126
|
+
if i2 == -3
|
127
|
+
i2 = @at2
|
128
|
+
@at2+=1
|
129
|
+
end
|
130
|
+
offset = 4
|
131
|
+
if i0 >= 0
|
132
|
+
begin
|
133
|
+
_g1 = 0
|
134
|
+
_g = @local.get_width
|
135
|
+
while(_g1 < _g)
|
136
|
+
x = _g1
|
137
|
+
_g1+=1
|
138
|
+
@local.set_cell_cache(x,i0,@db.get(x + offset))
|
139
|
+
end
|
140
|
+
end
|
141
|
+
offset += @local.get_width
|
142
|
+
end
|
143
|
+
if i1 >= 0
|
144
|
+
begin
|
145
|
+
_g11 = 0
|
146
|
+
_g2 = @remote.get_width
|
147
|
+
while(_g11 < _g2)
|
148
|
+
x1 = _g11
|
149
|
+
_g11+=1
|
150
|
+
@remote.set_cell_cache(x1,i1,@db.get(x1 + offset))
|
151
|
+
end
|
152
|
+
end
|
153
|
+
offset += @remote.get_width
|
154
|
+
end
|
155
|
+
if i2 >= 0
|
156
|
+
_g12 = 0
|
157
|
+
_g3 = @alt.get_width
|
158
|
+
while(_g12 < _g3)
|
159
|
+
x2 = _g12
|
160
|
+
_g12+=1
|
161
|
+
@alt.set_cell_cache(x2,i2,@db.get(x2 + offset))
|
162
|
+
end
|
163
|
+
end
|
164
|
+
if mode == 0 || mode == 2
|
165
|
+
@align.link(i0,i1)
|
166
|
+
@align.add_to_order(i0,i1)
|
167
|
+
end
|
168
|
+
if @alt != nil
|
169
|
+
if mode == 1 || mode == 2
|
170
|
+
@align.reference.link(i0,i2)
|
171
|
+
@align.reference.add_to_order(i0,i2)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def link_query(query,order)
|
177
|
+
if @db._begin(query,nil,order)
|
178
|
+
while(@db.read)
|
179
|
+
self.link
|
180
|
+
end
|
181
|
+
@db._end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def where(txt)
|
186
|
+
return " WHERE 1 = 0" if txt == ""
|
187
|
+
" WHERE " + _hx_str(txt)
|
188
|
+
end
|
189
|
+
|
190
|
+
public
|
191
|
+
|
192
|
+
def scan_columns(all_cols1,all_cols2,key_cols,present1,present2,align)
|
193
|
+
align.meta = ::Coopy::Alignment.new
|
194
|
+
begin
|
195
|
+
_g1 = 0
|
196
|
+
_g = all_cols1.length
|
197
|
+
while(_g1 < _g)
|
198
|
+
i = _g1
|
199
|
+
_g1+=1
|
200
|
+
key = all_cols1[i]
|
201
|
+
if present2.include?(key)
|
202
|
+
align.meta.link(i,present2[key])
|
203
|
+
else
|
204
|
+
align.meta.link(i,-1)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
begin
|
209
|
+
_g11 = 0
|
210
|
+
_g2 = all_cols2.length
|
211
|
+
while(_g11 < _g2)
|
212
|
+
i1 = _g11
|
213
|
+
_g11+=1
|
214
|
+
key1 = all_cols2[i1]
|
215
|
+
align.meta.link(-1,i1) if !present1.include?(key1)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
align.meta.range(all_cols1.length,all_cols2.length)
|
219
|
+
begin
|
220
|
+
_g3 = 0
|
221
|
+
while(_g3 < key_cols.length)
|
222
|
+
key2 = key_cols[_g3]
|
223
|
+
_g3+=1
|
224
|
+
unit = ::Coopy::Unit.new(present1[key2],present2[key2])
|
225
|
+
align.add_index_columns(unit)
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
def apply
|
231
|
+
return nil if @db == nil
|
232
|
+
@align = ::Coopy::Alignment.new if @align == nil
|
233
|
+
return nil if !self.validate_schema
|
234
|
+
rowid_name = @db.rowid
|
235
|
+
key_cols = []
|
236
|
+
data_cols = []
|
237
|
+
all_cols = []
|
238
|
+
all_cols1 = []
|
239
|
+
all_cols2 = []
|
240
|
+
all_cols3 = []
|
241
|
+
common = @local
|
242
|
+
if @local != nil
|
243
|
+
key_cols = @local.get_primary_key
|
244
|
+
data_cols = @local.get_all_but_primary_key
|
245
|
+
all_cols = @local.get_column_names
|
246
|
+
all_cols1 = @local.get_column_names
|
247
|
+
end
|
248
|
+
if @remote != nil
|
249
|
+
all_cols2 = @remote.get_column_names
|
250
|
+
common = @remote if common == nil
|
251
|
+
end
|
252
|
+
if @alt != nil
|
253
|
+
all_cols3 = @alt.get_column_names
|
254
|
+
common = @alt if common == nil
|
255
|
+
else
|
256
|
+
all_cols3 = all_cols2
|
257
|
+
end
|
258
|
+
all_common_cols = Array.new
|
259
|
+
data_common_cols = Array.new
|
260
|
+
present1 = {}
|
261
|
+
present2 = {}
|
262
|
+
present3 = {}
|
263
|
+
present_primary = {}
|
264
|
+
has_column_add = false
|
265
|
+
begin
|
266
|
+
_g1 = 0
|
267
|
+
_g = key_cols.length
|
268
|
+
while(_g1 < _g)
|
269
|
+
i = _g1
|
270
|
+
_g1+=1
|
271
|
+
present_primary[key_cols[i]] = i
|
272
|
+
end
|
273
|
+
end
|
274
|
+
begin
|
275
|
+
_g11 = 0
|
276
|
+
_g2 = all_cols1.length
|
277
|
+
while(_g11 < _g2)
|
278
|
+
i1 = _g11
|
279
|
+
_g11+=1
|
280
|
+
key = all_cols1[i1]
|
281
|
+
present1[key] = i1
|
282
|
+
end
|
283
|
+
end
|
284
|
+
begin
|
285
|
+
_g12 = 0
|
286
|
+
_g3 = all_cols2.length
|
287
|
+
while(_g12 < _g3)
|
288
|
+
i2 = _g12
|
289
|
+
_g12+=1
|
290
|
+
key1 = all_cols2[i2]
|
291
|
+
has_column_add = true if !present1.include?(key1)
|
292
|
+
present2[key1] = i2
|
293
|
+
end
|
294
|
+
end
|
295
|
+
begin
|
296
|
+
_g13 = 0
|
297
|
+
_g4 = all_cols3.length
|
298
|
+
while(_g13 < _g4)
|
299
|
+
i3 = _g13
|
300
|
+
_g13+=1
|
301
|
+
key2 = all_cols3[i3]
|
302
|
+
has_column_add = true if !present1.include?(key2)
|
303
|
+
present3[key2] = i3
|
304
|
+
if present1.include?(key2)
|
305
|
+
if present2.include?(key2)
|
306
|
+
all_common_cols.push(key2)
|
307
|
+
data_common_cols.push(key2) if !present_primary.include?(key2)
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|
312
|
+
@align.meta = ::Coopy::Alignment.new
|
313
|
+
begin
|
314
|
+
_g14 = 0
|
315
|
+
_g5 = all_cols1.length
|
316
|
+
while(_g14 < _g5)
|
317
|
+
i4 = _g14
|
318
|
+
_g14+=1
|
319
|
+
key3 = all_cols1[i4]
|
320
|
+
if present2.include?(key3)
|
321
|
+
@align.meta.link(i4,present2[key3])
|
322
|
+
else
|
323
|
+
@align.meta.link(i4,-1)
|
324
|
+
end
|
325
|
+
end
|
326
|
+
end
|
327
|
+
begin
|
328
|
+
_g15 = 0
|
329
|
+
_g6 = all_cols2.length
|
330
|
+
while(_g15 < _g6)
|
331
|
+
i5 = _g15
|
332
|
+
_g15+=1
|
333
|
+
key4 = all_cols2[i5]
|
334
|
+
@align.meta.link(-1,i5) if !present1.include?(key4)
|
335
|
+
end
|
336
|
+
end
|
337
|
+
self.scan_columns(all_cols1,all_cols2,key_cols,present1,present2,@align)
|
338
|
+
@align.tables(@local,@remote)
|
339
|
+
if @alt != nil
|
340
|
+
self.scan_columns(all_cols1,all_cols3,key_cols,present1,present3,@align.reference)
|
341
|
+
@align.reference.tables(@local,@alt)
|
342
|
+
end
|
343
|
+
sql_table1 = ""
|
344
|
+
sql_table2 = ""
|
345
|
+
sql_table3 = ""
|
346
|
+
sql_table1 = @local.get_quoted_table_name if @local != nil
|
347
|
+
sql_table2 = @remote.get_quoted_table_name if @remote != nil
|
348
|
+
sql_table3 = @alt.get_quoted_table_name if @alt != nil
|
349
|
+
if @peered
|
350
|
+
sql_table1 = "main." + _hx_str(sql_table1)
|
351
|
+
sql_table2 = "__peer__." + _hx_str(sql_table2)
|
352
|
+
end
|
353
|
+
sql_table2 = "__alt__." + _hx_str(sql_table3) if @alt_peered
|
354
|
+
sql_key_cols = ""
|
355
|
+
begin
|
356
|
+
_g16 = 0
|
357
|
+
_g7 = key_cols.length
|
358
|
+
while(_g16 < _g7)
|
359
|
+
i6 = _g16
|
360
|
+
_g16+=1
|
361
|
+
sql_key_cols += "," if i6 > 0
|
362
|
+
sql_key_cols += common.get_quoted_column_name(key_cols[i6])
|
363
|
+
end
|
364
|
+
end
|
365
|
+
sql_all_cols = ""
|
366
|
+
begin
|
367
|
+
_g17 = 0
|
368
|
+
_g8 = all_common_cols.length
|
369
|
+
while(_g17 < _g8)
|
370
|
+
i7 = _g17
|
371
|
+
_g17+=1
|
372
|
+
sql_all_cols += "," if i7 > 0
|
373
|
+
sql_all_cols += common.get_quoted_column_name(all_common_cols[i7])
|
374
|
+
end
|
375
|
+
end
|
376
|
+
sql_all_cols1 = ""
|
377
|
+
begin
|
378
|
+
_g18 = 0
|
379
|
+
_g9 = all_cols1.length
|
380
|
+
while(_g18 < _g9)
|
381
|
+
i8 = _g18
|
382
|
+
_g18+=1
|
383
|
+
sql_all_cols1 += "," if i8 > 0
|
384
|
+
sql_all_cols1 += @local.get_quoted_column_name(all_cols1[i8])
|
385
|
+
end
|
386
|
+
end
|
387
|
+
sql_all_cols2 = ""
|
388
|
+
begin
|
389
|
+
_g19 = 0
|
390
|
+
_g10 = all_cols2.length
|
391
|
+
while(_g19 < _g10)
|
392
|
+
i9 = _g19
|
393
|
+
_g19+=1
|
394
|
+
sql_all_cols2 += "," if i9 > 0
|
395
|
+
sql_all_cols2 += @remote.get_quoted_column_name(all_cols2[i9])
|
396
|
+
end
|
397
|
+
end
|
398
|
+
sql_all_cols3 = ""
|
399
|
+
if @alt != nil
|
400
|
+
_g110 = 0
|
401
|
+
_g20 = all_cols3.length
|
402
|
+
while(_g110 < _g20)
|
403
|
+
i10 = _g110
|
404
|
+
_g110+=1
|
405
|
+
sql_all_cols3 += "," if i10 > 0
|
406
|
+
sql_all_cols3 += @alt.get_quoted_column_name(all_cols3[i10])
|
407
|
+
end
|
408
|
+
end
|
409
|
+
sql_key_match2 = ""
|
410
|
+
begin
|
411
|
+
_g111 = 0
|
412
|
+
_g21 = key_cols.length
|
413
|
+
while(_g111 < _g21)
|
414
|
+
i11 = _g111
|
415
|
+
_g111+=1
|
416
|
+
sql_key_match2 += " AND " if i11 > 0
|
417
|
+
n = common.get_quoted_column_name(key_cols[i11])
|
418
|
+
sql_key_match2 += _hx_str(sql_table1) + "." + _hx_str(n) + " IS " + _hx_str(sql_table2) + "." + _hx_str(n)
|
419
|
+
end
|
420
|
+
end
|
421
|
+
sql_key_match3 = ""
|
422
|
+
if @alt != nil
|
423
|
+
_g112 = 0
|
424
|
+
_g22 = key_cols.length
|
425
|
+
while(_g112 < _g22)
|
426
|
+
i12 = _g112
|
427
|
+
_g112+=1
|
428
|
+
sql_key_match3 += " AND " if i12 > 0
|
429
|
+
n1 = common.get_quoted_column_name(key_cols[i12])
|
430
|
+
sql_key_match3 += _hx_str(sql_table1) + "." + _hx_str(n1) + " IS " + _hx_str(sql_table3) + "." + _hx_str(n1)
|
431
|
+
end
|
432
|
+
end
|
433
|
+
sql_data_mismatch = ""
|
434
|
+
begin
|
435
|
+
_g113 = 0
|
436
|
+
_g23 = data_common_cols.length
|
437
|
+
while(_g113 < _g23)
|
438
|
+
i13 = _g113
|
439
|
+
_g113+=1
|
440
|
+
sql_data_mismatch += " OR " if i13 > 0
|
441
|
+
n2 = common.get_quoted_column_name(data_common_cols[i13])
|
442
|
+
sql_data_mismatch += _hx_str(sql_table1) + "." + _hx_str(n2) + " IS NOT " + _hx_str(sql_table2) + "." + _hx_str(n2)
|
443
|
+
end
|
444
|
+
end
|
445
|
+
begin
|
446
|
+
_g114 = 0
|
447
|
+
_g24 = all_cols2.length
|
448
|
+
while(_g114 < _g24)
|
449
|
+
i14 = _g114
|
450
|
+
_g114+=1
|
451
|
+
key5 = all_cols2[i14]
|
452
|
+
if !present1.include?(key5)
|
453
|
+
sql_data_mismatch += " OR " if sql_data_mismatch != ""
|
454
|
+
n3 = common.get_quoted_column_name(key5)
|
455
|
+
sql_data_mismatch += _hx_str(sql_table2) + "." + _hx_str(n3) + " IS NOT NULL"
|
456
|
+
end
|
457
|
+
end
|
458
|
+
end
|
459
|
+
if @alt != nil
|
460
|
+
begin
|
461
|
+
_g115 = 0
|
462
|
+
_g25 = data_common_cols.length
|
463
|
+
while(_g115 < _g25)
|
464
|
+
i15 = _g115
|
465
|
+
_g115+=1
|
466
|
+
sql_data_mismatch += " OR " if sql_data_mismatch.length > 0
|
467
|
+
n4 = common.get_quoted_column_name(data_common_cols[i15])
|
468
|
+
sql_data_mismatch += _hx_str(sql_table1) + "." + _hx_str(n4) + " IS NOT " + _hx_str(sql_table3) + "." + _hx_str(n4)
|
469
|
+
end
|
470
|
+
end
|
471
|
+
begin
|
472
|
+
_g116 = 0
|
473
|
+
_g26 = all_cols3.length
|
474
|
+
while(_g116 < _g26)
|
475
|
+
i16 = _g116
|
476
|
+
_g116+=1
|
477
|
+
key6 = all_cols3[i16]
|
478
|
+
if !present1.include?(key6)
|
479
|
+
sql_data_mismatch += " OR " if sql_data_mismatch != ""
|
480
|
+
n5 = common.get_quoted_column_name(key6)
|
481
|
+
sql_data_mismatch += _hx_str(sql_table3) + "." + _hx_str(n5) + " IS NOT NULL"
|
482
|
+
end
|
483
|
+
end
|
484
|
+
end
|
485
|
+
end
|
486
|
+
sql_dbl_cols = ""
|
487
|
+
dbl_cols = []
|
488
|
+
begin
|
489
|
+
_g117 = 0
|
490
|
+
_g27 = all_cols1.length
|
491
|
+
while(_g117 < _g27)
|
492
|
+
i17 = _g117
|
493
|
+
_g117+=1
|
494
|
+
sql_dbl_cols += "," if sql_dbl_cols != ""
|
495
|
+
buf = "__coopy_" + _hx_str(i17)
|
496
|
+
n6 = common.get_quoted_column_name(all_cols1[i17])
|
497
|
+
sql_dbl_cols += _hx_str(sql_table1) + "." + _hx_str(n6) + " AS " + _hx_str(buf)
|
498
|
+
dbl_cols.push(buf)
|
499
|
+
end
|
500
|
+
end
|
501
|
+
begin
|
502
|
+
_g118 = 0
|
503
|
+
_g28 = all_cols2.length
|
504
|
+
while(_g118 < _g28)
|
505
|
+
i18 = _g118
|
506
|
+
_g118+=1
|
507
|
+
sql_dbl_cols += "," if sql_dbl_cols != ""
|
508
|
+
buf1 = "__coopy_" + _hx_str(i18) + "b"
|
509
|
+
n7 = common.get_quoted_column_name(all_cols2[i18])
|
510
|
+
sql_dbl_cols += _hx_str(sql_table2) + "." + _hx_str(n7) + " AS " + _hx_str(buf1)
|
511
|
+
dbl_cols.push(buf1)
|
512
|
+
end
|
513
|
+
end
|
514
|
+
if @alt != nil
|
515
|
+
_g119 = 0
|
516
|
+
_g29 = all_cols3.length
|
517
|
+
while(_g119 < _g29)
|
518
|
+
i19 = _g119
|
519
|
+
_g119+=1
|
520
|
+
sql_dbl_cols += "," if sql_dbl_cols != ""
|
521
|
+
buf2 = "__coopy_" + _hx_str(i19) + "c"
|
522
|
+
n8 = common.get_quoted_column_name(all_cols3[i19])
|
523
|
+
sql_dbl_cols += _hx_str(sql_table3) + "." + _hx_str(n8) + " AS " + _hx_str(buf2)
|
524
|
+
dbl_cols.push(buf2)
|
525
|
+
end
|
526
|
+
end
|
527
|
+
sql_order = ""
|
528
|
+
begin
|
529
|
+
_g120 = 0
|
530
|
+
_g30 = key_cols.length
|
531
|
+
while(_g120 < _g30)
|
532
|
+
i20 = _g120
|
533
|
+
_g120+=1
|
534
|
+
sql_order += "," if i20 > 0
|
535
|
+
n9 = common.get_quoted_column_name(key_cols[i20])
|
536
|
+
sql_order += n9
|
537
|
+
end
|
538
|
+
end
|
539
|
+
rowid = "-3"
|
540
|
+
rowid1 = "-3"
|
541
|
+
rowid2 = "-3"
|
542
|
+
rowid3 = "-3"
|
543
|
+
if rowid_name != nil
|
544
|
+
rowid = rowid_name
|
545
|
+
rowid1 = _hx_str(sql_table1) + "." + _hx_str(rowid_name) if @local != nil
|
546
|
+
rowid2 = _hx_str(sql_table2) + "." + _hx_str(rowid_name) if @remote != nil
|
547
|
+
rowid3 = _hx_str(sql_table3) + "." + _hx_str(rowid_name) if @alt != nil
|
548
|
+
end
|
549
|
+
@at0 = 1
|
550
|
+
@at1 = 1
|
551
|
+
@at2 = 1
|
552
|
+
@diff_ct = 0
|
553
|
+
if @remote != nil
|
554
|
+
sql_inserts = "SELECT DISTINCT 0 AS __coopy_code, NULL, " + _hx_str(rowid) + " AS rowid, NULL, " + _hx_str(sql_all_cols2) + " FROM " + _hx_str(sql_table2)
|
555
|
+
sql_inserts += " WHERE NOT EXISTS (SELECT 1 FROM " + _hx_str(sql_table1) + _hx_str(self.where(sql_key_match2)) + ")" if @local != nil
|
556
|
+
sql_inserts_order = ["__coopy_code","NULL","rowid","NULL"].concat(all_cols2)
|
557
|
+
self.link_query(sql_inserts,sql_inserts_order)
|
558
|
+
end
|
559
|
+
if @alt != nil
|
560
|
+
sql_inserts1 = "SELECT DISTINCT 1 AS __coopy_code, NULL, NULL, " + _hx_str(rowid) + " AS rowid, " + _hx_str(sql_all_cols3) + " FROM " + _hx_str(sql_table3)
|
561
|
+
sql_inserts1 += " WHERE NOT EXISTS (SELECT 1 FROM " + _hx_str(sql_table1) + _hx_str(self.where(sql_key_match3)) + ")" if @local != nil
|
562
|
+
sql_inserts_order1 = ["__coopy_code","NULL","NULL","rowid"].concat(all_cols3)
|
563
|
+
self.link_query(sql_inserts1,sql_inserts_order1)
|
564
|
+
end
|
565
|
+
if @local != nil && @remote != nil
|
566
|
+
sql_updates = "SELECT DISTINCT 2 AS __coopy_code, " + _hx_str(rowid1) + " AS __coopy_rowid0, " + _hx_str(rowid2) + " AS __coopy_rowid1, "
|
567
|
+
if @alt != nil
|
568
|
+
sql_updates += _hx_str(rowid3) + " AS __coopy_rowid2,"
|
569
|
+
else
|
570
|
+
sql_updates += " NULL,"
|
571
|
+
end
|
572
|
+
sql_updates += _hx_str(sql_dbl_cols) + " FROM " + _hx_str(sql_table1)
|
573
|
+
sql_updates += " INNER JOIN " + _hx_str(sql_table2) + " ON " + _hx_str(sql_key_match2) if sql_table1 != sql_table2
|
574
|
+
sql_updates += " INNER JOIN " + _hx_str(sql_table3) + " ON " + _hx_str(sql_key_match3) if @alt != nil && sql_table1 != sql_table3
|
575
|
+
sql_updates += self.where(sql_data_mismatch)
|
576
|
+
sql_updates_order = ["__coopy_code","__coopy_rowid0","__coopy_rowid1","__coopy_rowid2"].concat(dbl_cols)
|
577
|
+
self.link_query(sql_updates,sql_updates_order)
|
578
|
+
end
|
579
|
+
if @alt == nil
|
580
|
+
if @local != nil
|
581
|
+
sql_deletes = "SELECT DISTINCT 0 AS __coopy_code, " + _hx_str(rowid) + " AS rowid, NULL, NULL, " + _hx_str(sql_all_cols1) + " FROM " + _hx_str(sql_table1)
|
582
|
+
sql_deletes += " WHERE NOT EXISTS (SELECT 1 FROM " + _hx_str(sql_table2) + _hx_str(self.where(sql_key_match2)) + ")" if @remote != nil
|
583
|
+
sql_deletes_order = ["__coopy_code","rowid","NULL","NULL"].concat(all_cols1)
|
584
|
+
self.link_query(sql_deletes,sql_deletes_order)
|
585
|
+
end
|
586
|
+
end
|
587
|
+
if @alt != nil
|
588
|
+
sql_deletes1 = "SELECT 2 AS __coopy_code, " + _hx_str(rowid1) + " AS __coopy_rowid0, " + _hx_str(rowid2) + " AS __coopy_rowid1, "
|
589
|
+
sql_deletes1 += _hx_str(rowid3) + " AS __coopy_rowid2, "
|
590
|
+
sql_deletes1 += sql_dbl_cols
|
591
|
+
sql_deletes1 += " FROM " + _hx_str(sql_table1)
|
592
|
+
sql_deletes1 += " LEFT OUTER JOIN " + _hx_str(sql_table2) + " ON " + _hx_str(sql_key_match2) if @remote != nil
|
593
|
+
sql_deletes1 += " LEFT OUTER JOIN " + _hx_str(sql_table3) + " ON " + _hx_str(sql_key_match3)
|
594
|
+
sql_deletes1 += " WHERE __coopy_rowid1 IS NULL OR __coopy_rowid2 IS NULL"
|
595
|
+
sql_deletes_order1 = ["__coopy_code","__coopy_rowid0","__coopy_rowid1","__coopy_rowid2"].concat(dbl_cols)
|
596
|
+
self.link_query(sql_deletes1,sql_deletes_order1)
|
597
|
+
end
|
598
|
+
@align.mark_identical if @diff_ct == 0
|
599
|
+
@align
|
600
|
+
end
|
601
|
+
|
602
|
+
haxe_me ["coopy", "SqlCompare"]
|
603
|
+
end
|
604
|
+
|
605
|
+
end
|