System.Data.SQLite
Check-in [e7e1b9dcf9]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add tests for the session extension change group methods. Remove extraneous byte array parameter check from the SQLiteChangeGroup.CreateChangeSet method.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e7e1b9dcf9de27e443e68d0d20b44dcc4751cac1
User & Date: mistachkin 2017-10-14 22:40:03
Context
2017-10-15
03:29
Minor tweak to one of the new session tests. check-in: c25b488f6d user: mistachkin tags: trunk
2017-10-14
22:40
Add tests for the session extension change group methods. Remove extraneous byte array parameter check from the SQLiteChangeGroup.CreateChangeSet method. check-in: e7e1b9dcf9 user: mistachkin tags: trunk
21:57
Update to tests for the session extension. check-in: 8ad03d5b81 user: mistachkin tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to System.Data.SQLite/SQLiteSession.cs.

2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
        public void CreateChangeSet(
            ref byte[] rawData
            )
        {
            CheckDisposed();
            CheckHandle();

            SQLiteSessionHelpers.CheckRawData(rawData);

            IntPtr pData = IntPtr.Zero;

            try
            {
                int nData = 0;

                SQLiteErrorCode rc = UnsafeNativeMethods.sqlite3changegroup_output(







<
<







2354
2355
2356
2357
2358
2359
2360


2361
2362
2363
2364
2365
2366
2367
        public void CreateChangeSet(
            ref byte[] rawData
            )
        {
            CheckDisposed();
            CheckHandle();



            IntPtr pData = IntPtr.Zero;

            try
            {
                int nData = 0;

                SQLiteErrorCode rc = UnsafeNativeMethods.sqlite3changegroup_output(

Changes to Tests/session.eagle.

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
...
165
166
167
168
169
170
171















172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
...
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
...
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
...
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
...
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
...
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
...
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
...
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
...
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
....
1241
1242
1243
1244
1245
1246
1247




















































































































1248
1249
1250
1251
1252
1253
1254
....
1255
1256
1257
1258
1259
1260
1261
1262

1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
  }

  return null
}

###############################################################################

proc createMemoryChangeSetForSession { session {patch false} } {
  if {[isObjectHandle $session] && $session ne "null"} then {
    set byteArray null

    if {$patch} then {
      $session -alias CreatePatchSet byteArray
    } else {
      $session -alias CreateChangeSet byteArray
    }

    set rawData [createByteArray [arrayToList byteArray]]
    object removeref $rawData

    return $rawData
  }
................................................................................
  }

  return false
}

###############################################################################
















proc writeStreamChangeSetForSession { session fileName {patch false} } {
  if {[isObjectHandle $session] && $session ne "null"} then {
    set stream [object create -alias \
        System.IO.FileStream $fileName Create Write]

    if {$patch} then {
      $session -alias CreatePatchSet $stream
    } else {
      $session -alias CreateChangeSet $stream
    }

    $stream Flush; $stream Close

    return true
  }

................................................................................
}

###############################################################################

proc matchSession { connection session expr } {
  if {[isObjectHandle $session] && $session ne "null"} then {
    if {![$session IsEmpty]} then {
      set rawData [createMemoryChangeSetForSession $session]
      object removeref $rawData

      if {[isObjectHandle $rawData] && $rawData ne "null"} then {
        return [matchChangeSet [set changeSet \
            [$connection -alias CreateChangeSet $rawData]] $expr]
      }
    }
................................................................................
  $session AttachTable $tableName

  if {![isObjectHandle $session] || $session eq "null"} then {
    error "cannot create session"
  }

  catch {uplevel 1 $script}
  set rawData [createMemoryChangeSetForSession $session $patch]
  object removeref $rawData

  return $rawData
}

###############################################################################

................................................................................
  $session AttachTable $tableName

  if {![isObjectHandle $session] || $session eq "null"} then {
    error "cannot create session"
  }

  catch {uplevel 1 $script}
  writeStreamChangeSetForSession $session $fileName $patch
}

###############################################################################

proc getChangeSetFileName { {suffix ""} } {
  return [file join \
      [getTemporaryDirectory] [appendArgs changes $suffix .bin]]
................................................................................
  set connection [getDbConnection]

  set session [$connection -alias CreateSession main]
  $session AttachTable null

  makeSomeChanges $db t1 [list insert update delete]

  set rawData [createMemoryChangeSetForSession $session]
  object removeref $rawData

  writeRawDataToFile $fileName(1) $rawData
  writeStreamChangeSetForSession $session $fileName(2)
  openStreamChangeSetForConnection $connection $fileName(2) "" state

  list [expr {[file size $fileName(1)] > 0}] \
      [string equal [readFile $fileName(1)] [readFile $fileName(2)]] \
      [changeSetToString $state(changeSet) true]
} -cleanup {
  cleanupSomeText
................................................................................
  set connection [getDbConnection]

  set session [$connection -alias CreateSession main]
  $session AttachTable null

  makeSomeChanges $db t1 [list insert update delete]

  set rawData [createMemoryChangeSetForSession $session]
  object removeref $rawData

  set changeSet(1) \
      [createMemoryChangeSetForConnection $connection $rawData]

  object removeref $changeSet(1)

................................................................................
  set connection [getDbConnection]

  set session [$connection -alias CreateSession main]
  $session AttachTable null

  makeSomeChanges $db t1 [list insert update delete]

  writeStreamChangeSetForSession $session $fileName(1)

  openStreamChangeSetForConnection \
      $connection $fileName(1) $fileName(2) state

  $state(changeSet) -alias Invert; unset state
  list [changeSetFileToString $connection $fileName(2) true]
} -cleanup {
................................................................................

  $session SetToDisabled
  lappend result IsEnabled [$session IsEnabled]

  makeSomeChanges $db t1 [list insert]
  lappend result IsEmpty [$session IsEmpty]

  set rawData [createMemoryChangeSetForSession $session]
  object removeref $rawData

  lappend result Length [$rawData Length]

  $session SetToEnabled
  lappend result IsEnabled [$session IsEnabled]

  makeSomeChanges $db t1 [list insert]
  lappend result IsEmpty [$session IsEmpty]

  set rawData [createMemoryChangeSetForSession $session]
  object removeref $rawData

  set changeSet(1) \
      [createMemoryChangeSetForConnection $connection $rawData]

  object removeref $changeSet(1)

................................................................................

  $session SetToIndirect
  lappend result IsIndirect [$session IsIndirect]

  makeSomeChanges $db t1 [list insert]
  lappend result IsEmpty [$session IsEmpty]

  set rawData [createMemoryChangeSetForSession $session]
  object removeref $rawData

  $session SetToDirect
  lappend result IsIndirect [$session IsIndirect]

  makeSomeChanges $db t1 [list insert]
  lappend result IsEmpty [$session IsEmpty]

  set rawData [createMemoryChangeSetForSession $session]
  object removeref $rawData

  set changeSet(1) \
      [createMemoryChangeSetForConnection $connection $rawData]

  object removeref $changeSet(1)

................................................................................
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite SQLiteInterop\
defineConstant.System.Data.SQLite.INTEROP_SESSION_EXTENSION} -result \
{06631bf3545dba83b25db5142afc4d229544ed55}}

###############################################################################





















































































































rename conflictCallback ""
rename tableFilterCallbackT1 ""
rename createByteArray ""
rename arrayToList ""
rename getChangeSetFileName ""
rename captureChangeSetFile ""
rename captureChangeSetRawData ""
................................................................................
rename makeSomeChanges ""
rename createTheSchema ""
rename matchChangeSet ""
rename matchSession ""
rename changeSetToString ""
rename metadataItemToString ""
rename changeSetFileToString ""
rename writeStreamChangeSetForSession ""

rename openStreamChangeSetForConnection ""
rename writeRawDataToFile ""
rename createMemoryChangeSetForSession ""
rename createMemoryChangeSetForConnection ""
rename forDisplay ""
rename cleanupSomeText ""
rename getSomeText ""

###############################################################################

runSQLiteTestEpilogue
runTestEpilogue







|
|



|

|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|




|

|







 







|







 







|







 







|







 







|



|







 







|







 







|







 







|










|







 







|








|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
>


|









96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
...
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
...
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
...
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
...
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
...
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
...
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
...
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
...
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
...
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
....
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
....
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
  }

  return null
}

###############################################################################

proc createMemoryChangeSetForObject { object {patch false} } {
  if {[isObjectHandle $object] && $object ne "null"} then {
    set byteArray null

    if {$patch} then {
      $object CreatePatchSet byteArray
    } else {
      $object CreateChangeSet byteArray
    }

    set rawData [createByteArray [arrayToList byteArray]]
    object removeref $rawData

    return $rawData
  }
................................................................................
  }

  return false
}

###############################################################################

proc addStreamChangeSetForObject { object fileName } {
  if {[isObjectHandle $object] && $object ne "null"} then {
    set stream [object create -alias \
        System.IO.FileStream $fileName Open Read]

    $object AddChangeSet $stream

    return true
  }

  return false
}

###############################################################################

proc writeStreamChangeSetForObject { object fileName {patch false} } {
  if {[isObjectHandle $object] && $object ne "null"} then {
    set stream [object create -alias \
        System.IO.FileStream $fileName Create Write]

    if {$patch} then {
      $object CreatePatchSet $stream
    } else {
      $object CreateChangeSet $stream
    }

    $stream Flush; $stream Close

    return true
  }

................................................................................
}

###############################################################################

proc matchSession { connection session expr } {
  if {[isObjectHandle $session] && $session ne "null"} then {
    if {![$session IsEmpty]} then {
      set rawData [createMemoryChangeSetForObject $session]
      object removeref $rawData

      if {[isObjectHandle $rawData] && $rawData ne "null"} then {
        return [matchChangeSet [set changeSet \
            [$connection -alias CreateChangeSet $rawData]] $expr]
      }
    }
................................................................................
  $session AttachTable $tableName

  if {![isObjectHandle $session] || $session eq "null"} then {
    error "cannot create session"
  }

  catch {uplevel 1 $script}
  set rawData [createMemoryChangeSetForObject $session $patch]
  object removeref $rawData

  return $rawData
}

###############################################################################

................................................................................
  $session AttachTable $tableName

  if {![isObjectHandle $session] || $session eq "null"} then {
    error "cannot create session"
  }

  catch {uplevel 1 $script}
  writeStreamChangeSetForObject $session $fileName $patch
}

###############################################################################

proc getChangeSetFileName { {suffix ""} } {
  return [file join \
      [getTemporaryDirectory] [appendArgs changes $suffix .bin]]
................................................................................
  set connection [getDbConnection]

  set session [$connection -alias CreateSession main]
  $session AttachTable null

  makeSomeChanges $db t1 [list insert update delete]

  set rawData [createMemoryChangeSetForObject $session]
  object removeref $rawData

  writeRawDataToFile $fileName(1) $rawData
  writeStreamChangeSetForObject $session $fileName(2)
  openStreamChangeSetForConnection $connection $fileName(2) "" state

  list [expr {[file size $fileName(1)] > 0}] \
      [string equal [readFile $fileName(1)] [readFile $fileName(2)]] \
      [changeSetToString $state(changeSet) true]
} -cleanup {
  cleanupSomeText
................................................................................
  set connection [getDbConnection]

  set session [$connection -alias CreateSession main]
  $session AttachTable null

  makeSomeChanges $db t1 [list insert update delete]

  set rawData [createMemoryChangeSetForObject $session]
  object removeref $rawData

  set changeSet(1) \
      [createMemoryChangeSetForConnection $connection $rawData]

  object removeref $changeSet(1)

................................................................................
  set connection [getDbConnection]

  set session [$connection -alias CreateSession main]
  $session AttachTable null

  makeSomeChanges $db t1 [list insert update delete]

  writeStreamChangeSetForObject $session $fileName(1)

  openStreamChangeSetForConnection \
      $connection $fileName(1) $fileName(2) state

  $state(changeSet) -alias Invert; unset state
  list [changeSetFileToString $connection $fileName(2) true]
} -cleanup {
................................................................................

  $session SetToDisabled
  lappend result IsEnabled [$session IsEnabled]

  makeSomeChanges $db t1 [list insert]
  lappend result IsEmpty [$session IsEmpty]

  set rawData [createMemoryChangeSetForObject $session]
  object removeref $rawData

  lappend result Length [$rawData Length]

  $session SetToEnabled
  lappend result IsEnabled [$session IsEnabled]

  makeSomeChanges $db t1 [list insert]
  lappend result IsEmpty [$session IsEmpty]

  set rawData [createMemoryChangeSetForObject $session]
  object removeref $rawData

  set changeSet(1) \
      [createMemoryChangeSetForConnection $connection $rawData]

  object removeref $changeSet(1)

................................................................................

  $session SetToIndirect
  lappend result IsIndirect [$session IsIndirect]

  makeSomeChanges $db t1 [list insert]
  lappend result IsEmpty [$session IsEmpty]

  set rawData [createMemoryChangeSetForObject $session]
  object removeref $rawData

  $session SetToDirect
  lappend result IsIndirect [$session IsIndirect]

  makeSomeChanges $db t1 [list insert]
  lappend result IsEmpty [$session IsEmpty]

  set rawData [createMemoryChangeSetForObject $session]
  object removeref $rawData

  set changeSet(1) \
      [createMemoryChangeSetForConnection $connection $rawData]

  object removeref $changeSet(1)

................................................................................
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite SQLiteInterop\
defineConstant.System.Data.SQLite.INTEROP_SESSION_EXTENSION} -result \
{06631bf3545dba83b25db5142afc4d229544ed55}}

###############################################################################

runTest {test session-1.10.1 {change group (memory)} -setup {
  setupDb [set fileName session-1.10.1.db]

  cleanupSomeText
} -body {
  createTheSchema $db main
  makeSomeChanges $db t1 [list insert insert]

  set connection [getDbConnection]

  set rawData(1) [captureChangeSetRawData $connection main null {
    makeSomeChanges $db t1 [list delete] 1
  }]; object removeref $rawData(1)

  set rawData(2) [captureChangeSetRawData $connection main null {
    makeSomeChanges $db t1 [list insert]
  }]; object removeref $rawData(2)

  set changeGroup [$connection -alias CreateChangeGroup]

  $changeGroup AddChangeSet $rawData(1)
  $changeGroup AddChangeSet $rawData(2)

  set rawData(3) [createMemoryChangeSetForObject $changeGroup]
  object removeref $rawData(3)

  set changeSet [$connection CreateChangeSet $rawData(3)]
  changeSetToString $changeSet true
} -cleanup {
  cleanupSomeText

  unset -nocomplain changeSet changeGroup rawData

  freeDbConnection

  unset -nocomplain connection

  cleanupDb $fileName

  unset -nocomplain db fileName
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite SQLiteInterop\
defineConstant.System.Data.SQLite.INTEROP_SESSION_EXTENSION} -result \
{{TableName t1 NumberOfColumns 2 OperationCode Delete Indirect False\
PrimaryKeyColumns {[True, False]} OldValue 0 1 NewValue 0 <nullObject>\
ConflictValue 0 <nullObject> OldValue 1 {"inserted: Alpha Bravo Charlie Delta\
Echo"} NewValue 1 <nullObject> ConflictValue 1 <nullObject>} {TableName t1\
NumberOfColumns 2 OperationCode Insert Indirect False PrimaryKeyColumns {[True,\
False]} OldValue 0 <nullObject> NewValue 0 3 ConflictValue 0 <nullObject>\
OldValue 1 <nullObject> NewValue 1 {"inserted: Kilo Lima Mike November Oscar"}\
ConflictValue 1 <nullObject>}}}

###############################################################################

runTest {test session-1.10.2 {change group (stream)} -setup {
  setupDb [set fileName(0) session-1.10.2.db]

  set fileName(1) [getChangeSetFileName 1]
  set fileName(2) [getChangeSetFileName 2]
  set fileName(3) [getChangeSetFileName 3]

  cleanupSomeText
} -body {
  createTheSchema $db main
  makeSomeChanges $db t1 [list insert insert]

  set connection [getDbConnection]

  captureChangeSetFile $connection main null {
    makeSomeChanges $db t1 [list delete] 1
  } $fileName(1)

  captureChangeSetFile $connection main null {
    makeSomeChanges $db t1 [list insert]
  } $fileName(2)

  set changeGroup [$connection -alias CreateChangeGroup]

  addStreamChangeSetForObject $changeGroup $fileName(1)
  addStreamChangeSetForObject $changeGroup $fileName(2)
  writeStreamChangeSetForObject $changeGroup $fileName(3)

  openStreamChangeSetForConnection \
      $connection $fileName(3) "" state

  changeSetToString $state(changeSet) true
} -cleanup {
  cleanupSomeText

  unset -nocomplain state changeGroup

  freeDbConnection

  unset -nocomplain connection

  cleanupFile $fileName(3)
  cleanupFile $fileName(2)
  cleanupFile $fileName(1)

  cleanupDb $fileName(0)

  unset -nocomplain db fileName
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite SQLiteInterop\
defineConstant.System.Data.SQLite.INTEROP_SESSION_EXTENSION} -result \
{{TableName t1 NumberOfColumns 2 OperationCode Delete Indirect False\
PrimaryKeyColumns {[True, False]} OldValue 0 1 NewValue 0 <nullObject>\
ConflictValue 0 <nullObject> OldValue 1 {"inserted: Alpha Bravo Charlie Delta\
Echo"} NewValue 1 <nullObject> ConflictValue 1 <nullObject>} {TableName t1\
NumberOfColumns 2 OperationCode Insert Indirect False PrimaryKeyColumns {[True,\
False]} OldValue 0 <nullObject> NewValue 0 3 ConflictValue 0 <nullObject>\
OldValue 1 <nullObject> NewValue 1 {"inserted: Kilo Lima Mike November Oscar"}\
ConflictValue 1 <nullObject>}}}

###############################################################################

rename conflictCallback ""
rename tableFilterCallbackT1 ""
rename createByteArray ""
rename arrayToList ""
rename getChangeSetFileName ""
rename captureChangeSetFile ""
rename captureChangeSetRawData ""
................................................................................
rename makeSomeChanges ""
rename createTheSchema ""
rename matchChangeSet ""
rename matchSession ""
rename changeSetToString ""
rename metadataItemToString ""
rename changeSetFileToString ""
rename writeStreamChangeSetForObject ""
rename addStreamChangeSetForObject ""
rename openStreamChangeSetForConnection ""
rename writeRawDataToFile ""
rename createMemoryChangeSetForObject ""
rename createMemoryChangeSetForConnection ""
rename forDisplay ""
rename cleanupSomeText ""
rename getSomeText ""

###############################################################################

runSQLiteTestEpilogue
runTestEpilogue