daff 1.3.2 → 1.3.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,6 +11,9 @@ module Coopy
11
11
  def useForColumnChanges() puts "Abstract Meta.useForColumnChanges called" end
12
12
  def useForRowChanges() puts "Abstract Meta.useForRowChanges called" end
13
13
  def getRowStream() puts "Abstract Meta.getRowStream called" end
14
+ def isNested() puts "Abstract Meta.isNested called" end
15
+ def isSql() puts "Abstract Meta.isSql called" end
16
+ def getName() puts "Abstract Meta.getName called" end
14
17
  haxe_me ["coopy", "Meta"]
15
18
  end
16
19
 
@@ -0,0 +1,314 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ module Coopy
5
+ class SimpleMeta
6
+
7
+ def initialize(t,has_properties = true,may_be_nested = false)
8
+ @t = t
9
+ self.row_change
10
+ self.col_change
11
+ @has_properties = has_properties
12
+ @may_be_nested = may_be_nested
13
+ @metadata = nil
14
+ @keys = nil
15
+ @row_active = false
16
+ @row_change_cache = nil
17
+ end
18
+
19
+ protected
20
+
21
+ attr_accessor :t
22
+ attr_accessor :name2row
23
+ attr_accessor :name2col
24
+ attr_accessor :has_properties
25
+ attr_accessor :metadata
26
+ attr_accessor :keys
27
+ attr_accessor :row_active
28
+ attr_accessor :row_change_cache
29
+ attr_accessor :may_be_nested
30
+
31
+ public
32
+
33
+ def store_row_changes(changes)
34
+ @row_change_cache = changes
35
+ @row_active = true
36
+ end
37
+
38
+ protected
39
+
40
+ def row_change
41
+ @name2row = nil
42
+ end
43
+
44
+ def col_change
45
+ @name2col = nil
46
+ end
47
+
48
+ def col(key)
49
+ return -1 if @t.get_height < 1
50
+ if @name2col == nil
51
+ @name2col = {}
52
+ w = @t.get_width
53
+ begin
54
+ _g = 0
55
+ while(_g < w)
56
+ c = _g
57
+ _g+=1
58
+ begin
59
+ key1 = @t.get_cell(c,0)
60
+ @name2col[key1] = c
61
+ end
62
+ end
63
+ end
64
+ end
65
+ return -1 if !@name2col.include?(key)
66
+ @name2col[key]
67
+ end
68
+
69
+ def row(key)
70
+ return -1 if @t.get_width < 1
71
+ if @name2row == nil
72
+ @name2row = {}
73
+ h = @t.get_height
74
+ begin
75
+ _g = 1
76
+ while(_g < h)
77
+ r = _g
78
+ _g+=1
79
+ begin
80
+ key1 = @t.get_cell(0,r)
81
+ @name2row[key1] = r
82
+ end
83
+ end
84
+ end
85
+ end
86
+ return -1 if !@name2row.include?(key)
87
+ @name2row[key]
88
+ end
89
+
90
+ public
91
+
92
+ def alter_columns(columns)
93
+ target = {}
94
+ wfate = 0
95
+ if @has_properties
96
+ target["@"] = wfate
97
+ wfate+=1
98
+ end
99
+ begin
100
+ _g1 = 0
101
+ _g = columns.length
102
+ while(_g1 < _g)
103
+ i = _g1
104
+ _g1+=1
105
+ col = columns[i]
106
+ target[col.prev_name] = wfate if col.prev_name != nil
107
+ wfate+=1 if col.name != nil
108
+ end
109
+ end
110
+ fate = Array.new
111
+ begin
112
+ _g11 = 0
113
+ _g2 = @t.get_width
114
+ while(_g11 < _g2)
115
+ i1 = _g11
116
+ _g11+=1
117
+ targeti = -1
118
+ name = @t.get_cell(i1,0)
119
+ targeti = target[name] if target.include?(name)
120
+ fate.push(targeti)
121
+ end
122
+ end
123
+ @t.insert_or_delete_columns(fate,wfate)
124
+ start = nil
125
+ if @has_properties
126
+ start = 1
127
+ else
128
+ start = 0
129
+ end
130
+ at = start
131
+ begin
132
+ _g12 = 0
133
+ _g3 = columns.length
134
+ while(_g12 < _g3)
135
+ i2 = _g12
136
+ _g12+=1
137
+ col1 = columns[i2]
138
+ if col1.name != nil
139
+ @t.set_cell(at,0,col1.name) if col1.name != col1.prev_name
140
+ end
141
+ at+=1 if col1.name != nil
142
+ end
143
+ end
144
+ return true if !@has_properties
145
+ self.col_change
146
+ at = start
147
+ begin
148
+ _g13 = 0
149
+ _g4 = columns.length
150
+ while(_g13 < _g4)
151
+ i3 = _g13
152
+ _g13+=1
153
+ col2 = columns[i3]
154
+ if col2.name != nil
155
+ _g21 = 0
156
+ _g31 = col2.props
157
+ while(_g21 < _g31.length)
158
+ prop = _g31[_g21]
159
+ _g21+=1
160
+ self.set_cell(col2.name,prop.name,prop.val)
161
+ end
162
+ end
163
+ at+=1 if col2.name != nil
164
+ end
165
+ end
166
+ true
167
+ end
168
+
169
+ protected
170
+
171
+ def set_cell(c,r,val)
172
+ ri = self.row(r)
173
+ return false if ri == -1
174
+ ci = self.col(c)
175
+ return false if ci == -1
176
+ @t.set_cell(ci,ri,val)
177
+ true
178
+ end
179
+
180
+ public
181
+
182
+ def add_meta_data(column,property,val)
183
+ if @metadata == nil
184
+ @metadata = {}
185
+ @keys = {}
186
+ end
187
+ if !@metadata.include?(column)
188
+ value = {}
189
+ @metadata[column] = value
190
+ end
191
+ props = @metadata[column]
192
+ begin
193
+ value1 = val
194
+ begin
195
+ value2 = value1
196
+ props[property] = value2
197
+ end
198
+ end
199
+ @keys[property] = true
200
+ end
201
+
202
+ def as_table
203
+ return @t if @has_properties && @metadata == nil
204
+ return nil if @metadata == nil
205
+ w = @t.get_width
206
+ props = Array.new
207
+ _it = ::Rb::RubyIterator.new(@keys.keys)
208
+ while(_it.has_next) do
209
+ k = _it._next
210
+ props.push(k)
211
+ end
212
+ props.sort!{|a,b| Reflect.compare(a,b)}
213
+ mt = ::Coopy::SimpleTable.new(w + 1,props.length + 1)
214
+ mt.set_cell(0,0,"@")
215
+ begin
216
+ _g = 0
217
+ while(_g < w)
218
+ x = _g
219
+ _g+=1
220
+ name = @t.get_cell(x,0)
221
+ mt.set_cell(1 + x,0,name)
222
+ next if !@metadata.include?(name)
223
+ vals = @metadata[name]
224
+ begin
225
+ _g2 = 0
226
+ _g1 = props.length
227
+ while(_g2 < _g1)
228
+ i = _g2
229
+ _g2+=1
230
+ mt.set_cell(1 + x,i + 1,vals[props[i]]) if vals.include?(props[i])
231
+ end
232
+ end
233
+ end
234
+ end
235
+ begin
236
+ _g11 = 0
237
+ _g3 = props.length
238
+ while(_g11 < _g3)
239
+ y = _g11
240
+ _g11+=1
241
+ mt.set_cell(0,y + 1,props[y])
242
+ end
243
+ end
244
+ mt
245
+ end
246
+
247
+ def clone_meta(table = nil)
248
+ result = ::Coopy::SimpleMeta.new(table)
249
+ if @metadata != nil
250
+ result.keys = {}
251
+ _it = ::Rb::RubyIterator.new(@keys.keys)
252
+ while(_it.has_next) do
253
+ k = _it._next
254
+ result.keys[k] = true
255
+ end
256
+ result.metadata = {}
257
+ _it2 = ::Rb::RubyIterator.new(@metadata.keys)
258
+ while(_it2.has_next) do
259
+ k1 = _it2._next
260
+ next if !@metadata.include?(k1)
261
+ vals = @metadata[k1]
262
+ nvals = {}
263
+ _it3 = ::Rb::RubyIterator.new(vals.keys)
264
+ while(_it3.has_next) do
265
+ p = _it3._next
266
+ value = vals[p]
267
+ begin
268
+ value1 = value
269
+ nvals[p] = value1
270
+ end
271
+ end
272
+ result.metadata[k1] = nvals
273
+ end
274
+ end
275
+ result
276
+ end
277
+
278
+ def use_for_column_changes
279
+ true
280
+ end
281
+
282
+ def use_for_row_changes
283
+ @row_active
284
+ end
285
+
286
+ def change_row(rc)
287
+ @row_change_cache.push(rc)
288
+ false
289
+ end
290
+
291
+ def apply_flags(flags)
292
+ false
293
+ end
294
+
295
+ def get_row_stream
296
+ ::Coopy::TableStream.new(@t)
297
+ end
298
+
299
+ def is_nested
300
+ @may_be_nested
301
+ end
302
+
303
+ def is_sql
304
+ false
305
+ end
306
+
307
+ def get_name
308
+ nil
309
+ end
310
+
311
+ haxe_me ["coopy", "SimpleMeta"]
312
+ end
313
+
314
+ end
@@ -233,6 +233,10 @@ module Coopy
233
233
  result
234
234
  end
235
235
 
236
+ def create
237
+ ::Coopy::SimpleTable.new(self.get_width,self.get_height)
238
+ end
239
+
236
240
  def set_meta(meta)
237
241
  @meta = meta
238
242
  end
@@ -52,6 +52,18 @@ module Coopy
52
52
  h.respond_to? :keys
53
53
  end
54
54
 
55
+ def is_table(t)
56
+ Std._is(t,::Coopy::Table)
57
+ end
58
+
59
+ def get_table(t)
60
+ t
61
+ end
62
+
63
+ def wrap_table(t)
64
+ t
65
+ end
66
+
55
67
  haxe_me ["coopy", "SimpleView"]
56
68
  end
57
69
 
@@ -11,14 +11,16 @@ module Coopy
11
11
  @alt = alt
12
12
  @align = align
13
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
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
18
21
  end
19
22
  end
20
- @alt_peered = false
21
- if @alt != nil
23
+ if @alt != nil && local != nil
22
24
  if @alt.get_database.get_name_for_attachment != nil
23
25
  if @alt.get_database.get_name_for_attachment != @local.get_database.get_name_for_attachment
24
26
  local.get_database.get_helper.attach(db,"__alt__",@alt.get_database.get_name_for_attachment)
@@ -38,6 +40,7 @@ module Coopy
38
40
  attr_accessor :at0
39
41
  attr_accessor :at1
40
42
  attr_accessor :at2
43
+ attr_accessor :diff_ct
41
44
  attr_accessor :align
42
45
  attr_accessor :peered
43
46
  attr_accessor :alt_peered
@@ -60,25 +63,42 @@ module Coopy
60
63
  public
61
64
 
62
65
  def validate_schema
63
- all_cols1 = @local.get_column_names
64
- all_cols2 = @remote.get_column_names
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
65
84
  all_cols3 = all_cols2
66
- key_cols1 = @local.get_primary_key
67
- key_cols2 = @remote.get_primary_key
68
85
  key_cols3 = key_cols2
69
86
  if @alt != nil
70
87
  all_cols3 = @alt.get_column_names
71
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
72
91
  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
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)
77
97
  end
78
- if key_cols1.length == 0
79
- puts "sql diff not possible when primary key not available"
80
- return false
98
+ if @local != nil && @alt != nil
99
+ pk_change = true if !self.equal_array(key_cols1,key_cols3)
81
100
  end
101
+ raise hx_raise("sql diff not possible when primary key changes") if pk_change
82
102
  true
83
103
  end
84
104
 
@@ -90,6 +110,7 @@ module Coopy
90
110
  end
91
111
 
92
112
  def link
113
+ @diff_ct+=1
93
114
  mode = @db.get(0)
94
115
  i0 = self.denull(@db.get(1))
95
116
  i1 = self.denull(@db.get(2))
@@ -208,18 +229,32 @@ module Coopy
208
229
 
209
230
  def apply
210
231
  return nil if @db == nil
232
+ @align = ::Coopy::Alignment.new if @align == nil
211
233
  return nil if !self.validate_schema
212
234
  rowid_name = @db.rowid
213
- @align = ::Coopy::Alignment.new if @align == nil
214
- key_cols = @local.get_primary_key
215
- data_cols = @local.get_all_but_primary_key
216
- all_cols = @local.get_column_names
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
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
223
258
  all_common_cols = Array.new
224
259
  data_common_cols = Array.new
225
260
  present1 = {}
@@ -305,9 +340,11 @@ module Coopy
305
340
  self.scan_columns(all_cols1,all_cols3,key_cols,present1,present3,@align.reference)
306
341
  @align.reference.tables(@local,@alt)
307
342
  end
308
- sql_table1 = @local.get_quoted_table_name
309
- sql_table2 = @remote.get_quoted_table_name
343
+ sql_table1 = ""
344
+ sql_table2 = ""
310
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
311
348
  sql_table3 = @alt.get_quoted_table_name if @alt != nil
312
349
  if @peered
313
350
  sql_table1 = "main." + _hx_str(sql_table1)
@@ -322,7 +359,7 @@ module Coopy
322
359
  i6 = _g16
323
360
  _g16+=1
324
361
  sql_key_cols += "," if i6 > 0
325
- sql_key_cols += @local.get_quoted_column_name(key_cols[i6])
362
+ sql_key_cols += common.get_quoted_column_name(key_cols[i6])
326
363
  end
327
364
  end
328
365
  sql_all_cols = ""
@@ -333,7 +370,7 @@ module Coopy
333
370
  i7 = _g17
334
371
  _g17+=1
335
372
  sql_all_cols += "," if i7 > 0
336
- sql_all_cols += @local.get_quoted_column_name(all_common_cols[i7])
373
+ sql_all_cols += common.get_quoted_column_name(all_common_cols[i7])
337
374
  end
338
375
  end
339
376
  sql_all_cols1 = ""
@@ -355,7 +392,7 @@ module Coopy
355
392
  i9 = _g19
356
393
  _g19+=1
357
394
  sql_all_cols2 += "," if i9 > 0
358
- sql_all_cols2 += @local.get_quoted_column_name(all_cols2[i9])
395
+ sql_all_cols2 += @remote.get_quoted_column_name(all_cols2[i9])
359
396
  end
360
397
  end
361
398
  sql_all_cols3 = ""
@@ -366,7 +403,7 @@ module Coopy
366
403
  i10 = _g110
367
404
  _g110+=1
368
405
  sql_all_cols3 += "," if i10 > 0
369
- sql_all_cols3 += @local.get_quoted_column_name(all_cols3[i10])
406
+ sql_all_cols3 += @alt.get_quoted_column_name(all_cols3[i10])
370
407
  end
371
408
  end
372
409
  sql_key_match2 = ""
@@ -377,7 +414,7 @@ module Coopy
377
414
  i11 = _g111
378
415
  _g111+=1
379
416
  sql_key_match2 += " AND " if i11 > 0
380
- n = @local.get_quoted_column_name(key_cols[i11])
417
+ n = common.get_quoted_column_name(key_cols[i11])
381
418
  sql_key_match2 += _hx_str(sql_table1) + "." + _hx_str(n) + " IS " + _hx_str(sql_table2) + "." + _hx_str(n)
382
419
  end
383
420
  end
@@ -389,7 +426,7 @@ module Coopy
389
426
  i12 = _g112
390
427
  _g112+=1
391
428
  sql_key_match3 += " AND " if i12 > 0
392
- n1 = @local.get_quoted_column_name(key_cols[i12])
429
+ n1 = common.get_quoted_column_name(key_cols[i12])
393
430
  sql_key_match3 += _hx_str(sql_table1) + "." + _hx_str(n1) + " IS " + _hx_str(sql_table3) + "." + _hx_str(n1)
394
431
  end
395
432
  end
@@ -401,7 +438,7 @@ module Coopy
401
438
  i13 = _g113
402
439
  _g113+=1
403
440
  sql_data_mismatch += " OR " if i13 > 0
404
- n2 = @local.get_quoted_column_name(data_common_cols[i13])
441
+ n2 = common.get_quoted_column_name(data_common_cols[i13])
405
442
  sql_data_mismatch += _hx_str(sql_table1) + "." + _hx_str(n2) + " IS NOT " + _hx_str(sql_table2) + "." + _hx_str(n2)
406
443
  end
407
444
  end
@@ -414,7 +451,7 @@ module Coopy
414
451
  key5 = all_cols2[i14]
415
452
  if !present1.include?(key5)
416
453
  sql_data_mismatch += " OR " if sql_data_mismatch != ""
417
- n3 = @remote.get_quoted_column_name(key5)
454
+ n3 = common.get_quoted_column_name(key5)
418
455
  sql_data_mismatch += _hx_str(sql_table2) + "." + _hx_str(n3) + " IS NOT NULL"
419
456
  end
420
457
  end
@@ -427,7 +464,7 @@ module Coopy
427
464
  i15 = _g115
428
465
  _g115+=1
429
466
  sql_data_mismatch += " OR " if sql_data_mismatch.length > 0
430
- n4 = @local.get_quoted_column_name(data_common_cols[i15])
467
+ n4 = common.get_quoted_column_name(data_common_cols[i15])
431
468
  sql_data_mismatch += _hx_str(sql_table1) + "." + _hx_str(n4) + " IS NOT " + _hx_str(sql_table3) + "." + _hx_str(n4)
432
469
  end
433
470
  end
@@ -440,7 +477,7 @@ module Coopy
440
477
  key6 = all_cols3[i16]
441
478
  if !present1.include?(key6)
442
479
  sql_data_mismatch += " OR " if sql_data_mismatch != ""
443
- n5 = @alt.get_quoted_column_name(key6)
480
+ n5 = common.get_quoted_column_name(key6)
444
481
  sql_data_mismatch += _hx_str(sql_table3) + "." + _hx_str(n5) + " IS NOT NULL"
445
482
  end
446
483
  end
@@ -456,7 +493,7 @@ module Coopy
456
493
  _g117+=1
457
494
  sql_dbl_cols += "," if sql_dbl_cols != ""
458
495
  buf = "__coopy_" + _hx_str(i17)
459
- n6 = @local.get_quoted_column_name(all_cols1[i17])
496
+ n6 = common.get_quoted_column_name(all_cols1[i17])
460
497
  sql_dbl_cols += _hx_str(sql_table1) + "." + _hx_str(n6) + " AS " + _hx_str(buf)
461
498
  dbl_cols.push(buf)
462
499
  end
@@ -469,7 +506,7 @@ module Coopy
469
506
  _g118+=1
470
507
  sql_dbl_cols += "," if sql_dbl_cols != ""
471
508
  buf1 = "__coopy_" + _hx_str(i18) + "b"
472
- n7 = @local.get_quoted_column_name(all_cols2[i18])
509
+ n7 = common.get_quoted_column_name(all_cols2[i18])
473
510
  sql_dbl_cols += _hx_str(sql_table2) + "." + _hx_str(n7) + " AS " + _hx_str(buf1)
474
511
  dbl_cols.push(buf1)
475
512
  end
@@ -482,7 +519,7 @@ module Coopy
482
519
  _g119+=1
483
520
  sql_dbl_cols += "," if sql_dbl_cols != ""
484
521
  buf2 = "__coopy_" + _hx_str(i19) + "c"
485
- n8 = @local.get_quoted_column_name(all_cols3[i19])
522
+ n8 = common.get_quoted_column_name(all_cols3[i19])
486
523
  sql_dbl_cols += _hx_str(sql_table3) + "." + _hx_str(n8) + " AS " + _hx_str(buf2)
487
524
  dbl_cols.push(buf2)
488
525
  end
@@ -495,7 +532,7 @@ module Coopy
495
532
  i20 = _g120
496
533
  _g120+=1
497
534
  sql_order += "," if i20 > 0
498
- n9 = @local.get_quoted_column_name(key_cols[i20])
535
+ n9 = common.get_quoted_column_name(key_cols[i20])
499
536
  sql_order += n9
500
537
  end
501
538
  end
@@ -505,49 +542,60 @@ module Coopy
505
542
  rowid3 = "-3"
506
543
  if rowid_name != nil
507
544
  rowid = rowid_name
508
- rowid1 = _hx_str(sql_table1) + "." + _hx_str(rowid_name)
509
- rowid2 = _hx_str(sql_table2) + "." + _hx_str(rowid_name)
510
- rowid3 = _hx_str(sql_table3) + "." + _hx_str(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
511
548
  end
512
549
  @at0 = 1
513
550
  @at1 = 1
514
551
  @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)
517
- self.link_query(sql_inserts,sql_inserts_order)
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
518
559
  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)) + ")"
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
520
562
  sql_inserts_order1 = ["__coopy_code","NULL","NULL","rowid"].concat(all_cols3)
521
563
  self.link_query(sql_inserts1,sql_inserts_order1)
522
564
  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)
534
- self.link_query(sql_updates,sql_updates_order)
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
535
579
  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)
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
539
586
  end
540
587
  if @alt != nil
541
588
  sql_deletes1 = "SELECT 2 AS __coopy_code, " + _hx_str(rowid1) + " AS __coopy_rowid0, " + _hx_str(rowid2) + " AS __coopy_rowid1, "
542
589
  sql_deletes1 += _hx_str(rowid3) + " AS __coopy_rowid2, "
543
590
  sql_deletes1 += sql_dbl_cols
544
591
  sql_deletes1 += " FROM " + _hx_str(sql_table1)
545
- sql_deletes1 += " LEFT OUTER JOIN " + _hx_str(sql_table2) + " ON " + _hx_str(sql_key_match2)
592
+ sql_deletes1 += " LEFT OUTER JOIN " + _hx_str(sql_table2) + " ON " + _hx_str(sql_key_match2) if @remote != nil
546
593
  sql_deletes1 += " LEFT OUTER JOIN " + _hx_str(sql_table3) + " ON " + _hx_str(sql_key_match3)
547
594
  sql_deletes1 += " WHERE __coopy_rowid1 IS NULL OR __coopy_rowid2 IS NULL"
548
595
  sql_deletes_order1 = ["__coopy_code","__coopy_rowid0","__coopy_rowid1","__coopy_rowid2"].concat(dbl_cols)
549
596
  self.link_query(sql_deletes1,sql_deletes_order1)
550
597
  end
598
+ @align.mark_identical if @diff_ct == 0
551
599
  @align
552
600
  end
553
601