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