Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Add tests for Apply and CombineWith. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | sessions |
Files: | files | file ages | folders |
SHA1: |
d1def95f7b98a0e759a0ce00acbcb88c |
User & Date: | mistachkin 2017-10-11 21:22:08.344 |
Context
2017-10-11
| ||
23:58 | Revise IDisposable semantics of the SQLiteStreamAdapter class: stop setting the contained (not owned) stream to null when disposed. check-in: 057f76abdc user: mistachkin tags: sessions | |
21:22 | Add tests for Apply and CombineWith. check-in: d1def95f7b user: mistachkin tags: sessions | |
21:21 | Create the metadata item for the xConflict callback. check-in: e3f2fe8d85 user: mistachkin tags: sessions | |
Changes
Changes to Tests/session.eagle.
︙ | ︙ | |||
102 103 104 105 106 107 108 109 110 111 112 113 | } return null } ############################################################################### proc changeSetToString { changeSet includeValues } { set result [list] if {[isObjectHandle $changeSet] && $changeSet ne "null"} then { object foreach -alias item $changeSet { | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > < < < < | < < < < < < < < < < < < < < < < < < < < < < < | 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | } return null } ############################################################################### proc metadataItemToString { item includeValues } { set result [list] if {[isObjectHandle $item] && $item ne "null"} then { lappend result TableName [$item TableName] lappend result NumberOfColumns [$item NumberOfColumns] lappend result OperationCode [$item OperationCode] lappend result Indirect [$item Indirect] lappend result PrimaryKeyColumns \ [forDisplay $item PrimaryKeyColumns] if {$includeValues} then { set numberOfColumns [$item NumberOfColumns] for {set index 0} {$index < $numberOfColumns} {incr index} { set oldValue [$item GetOldValue $index] lappend result OldValue $index \ [forDisplay $oldValue GetObject] set newValue [$item GetNewValue $index] lappend result NewValue $index \ [forDisplay $newValue GetObject] set conflictValue [$item GetConflictValue $index] lappend result ConflictValue $index \ [forDisplay $conflictValue GetObject] } } } return $result } ############################################################################### proc changeSetToString { changeSet includeValues } { set result [list] if {[isObjectHandle $changeSet] && $changeSet ne "null"} then { object foreach -alias item $changeSet { lappend result [metadataItemToString $item $includeValues] } } return $result } ############################################################################### |
︙ | ︙ | |||
182 183 184 185 186 187 188 | CREATE TABLE t1(x INTEGER PRIMARY KEY, y TEXT); CREATE TABLE t2(x INTEGER PRIMARY KEY, y TEXT); } } ############################################################################### | | > | > > > > | | > > | > > > > | | | | | > > | > > > > | | | | | | > > > > > > > > > > > > > > > > > > > > > > | 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | CREATE TABLE t1(x INTEGER PRIMARY KEY, y TEXT); CREATE TABLE t2(x INTEGER PRIMARY KEY, y TEXT); } } ############################################################################### proc makeSomeChanges { db table types random {rowId ""} {count 5} } { foreach type $types { switch -nocase -- $type { insert { set text [appendArgs "inserted: " [getSomeText $random $count]] if {[string is integer -strict $rowId]} then { sql execute $db [subst { INSERT INTO ${table}(x, y) VALUES(?, ?); }] [list param1 Int32 $rowId] [list param2 String $text] } else { sql execute $db [subst { INSERT INTO ${table}(y) VALUES(?); }] [list param1 String $text] } } update { set text [appendArgs "updated: " [getSomeText $random $count]] if {[string is integer -strict $rowId]} then { sql execute $db [subst { UPDATE ${table} SET y = ? WHERE x = ?; }] [list param1 String $text] [list param2 Int32 $rowId] } else { sql execute $db [subst { UPDATE ${table} SET y = ? WHERE x NOT IN ( (SELECT MIN(x) FROM ${table}), (SELECT MAX(x) FROM ${table}) ); }] [list param1 String $text] } } delete { if {[string is integer -strict $rowId]} then { sql execute $db [subst { DELETE FROM ${table} WHERE x = ?; }] [list param1 Int32 $rowId] } else { sql execute $db [subst { DELETE FROM ${table} WHERE x = (SELECT MIN(x) FROM ${table}); }] } } } } } ############################################################################### proc captureChangeSetRawData { connection databaseName tableName script } { if {![isObjectHandle $connection] || $connection eq "null"} then { error "connection is invalid" } set session [$connection -alias CreateSession $databaseName] $session AttachTable $tableName if {![isObjectHandle $session] || $session eq "null"} then { error "cannot create session" } catch {uplevel 1 $script} set rawData [createChangeSetForSession $session] object removeref $rawData return $rawData } ############################################################################### proc getChangeSetFileName { {suffix ""} } { return [file join \ [getTemporaryDirectory] [appendArgs changes $suffix .bin]] } |
︙ | ︙ | |||
254 255 256 257 258 259 260 261 262 263 264 265 266 267 | ############################################################################### proc tableFilterCallbackT1 { clientData name } { lappend ::callbackResults [object invoke -create \ System.Boolean Parse [expr {[$name ToString] in [list t1]}]] return [lindex $::callbackResults end] } ############################################################################### runTest {test session-1.1 {basic session extension usage} -setup { setupDb [set fileName(0) session-1.1.db] | > > > > > > > > > > > > > > > > > > > > > > | 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | ############################################################################### proc tableFilterCallbackT1 { clientData name } { lappend ::callbackResults [object invoke -create \ System.Boolean Parse [expr {[$name ToString] in [list t1]}]] return [lindex $::callbackResults end] } ############################################################################### proc conflictCallback { clientData type item } { set result Abort if {[isObjectHandle $item] && $item ne "null"} then { set result Omit if {[$item OperationCode] ne "Delete"} then { if {[isObjectHandle $type] && $type ne "null" && \ [$type ToString] in [list Data Conflict]} then { set result Replace } } } lappend ::callbackResults [object invoke -create Enum Parse \ System.Data.SQLite.SQLiteChangeSetConflictResult $result false] return [lindex $::callbackResults end] } ############################################################################### runTest {test session-1.1 {basic session extension usage} -setup { setupDb [set fileName(0) session-1.1.db] |
︙ | ︙ | |||
354 355 356 357 358 359 360 | 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 \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 | 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 Update Indirect False PrimaryKeyColumns {[True,\ False]} OldValue 0 2 NewValue 0 <nullObject> ConflictValue 0 <nullObject>\ OldValue 1 {"inserted: Foxtrot Golf Hotel India Juliet"} NewValue 1 {"updated:\ Uniform Victor Whiskey X-ray Yankee"} ConflictValue 1 <nullObject>} {TableName\ t1 NumberOfColumns 2 OperationCode Update Indirect False PrimaryKeyColumns\ {[True, False]} OldValue 0 3 NewValue 0 <nullObject> ConflictValue 0\ <nullObject> OldValue 1 {"inserted: Kilo Lima Mike November Oscar"} NewValue 1\ {"updated: Uniform Victor Whiskey X-ray Yankee"} ConflictValue 1 <nullObject>}\ {TableName t1 NumberOfColumns 2 OperationCode Insert Indirect False\ PrimaryKeyColumns {[True, False]} OldValue 0 <nullObject> NewValue 0 4\ ConflictValue 0 <nullObject> OldValue 1 <nullObject> NewValue 1 {"inserted:\ Papa Quebec Romeo Sierra Tango"} ConflictValue 1 <nullObject>}} {{TableName t1\ NumberOfColumns 2 OperationCode Insert Indirect False PrimaryKeyColumns {[True,\ False]} OldValue 0 <nullObject> NewValue 0 1 ConflictValue 0 <nullObject>\ OldValue 1 <nullObject> NewValue 1 {"inserted: Alpha Bravo Charlie Delta Echo"}\ ConflictValue 1 <nullObject>} {TableName t1 NumberOfColumns 2 OperationCode\ Update Indirect False PrimaryKeyColumns {[True, False]} OldValue 0 2 NewValue 0\ <nullObject> ConflictValue 0 <nullObject> OldValue 1 {"updated: Uniform Victor\ Whiskey X-ray Yankee"} NewValue 1 {"inserted: Foxtrot Golf Hotel India Juliet"}\ ConflictValue 1 <nullObject>} {TableName t1 NumberOfColumns 2 OperationCode\ Update Indirect False PrimaryKeyColumns {[True, False]} OldValue 0 3 NewValue 0\ <nullObject> ConflictValue 0 <nullObject> OldValue 1 {"updated: Uniform Victor\ Whiskey X-ray Yankee"} NewValue 1 {"inserted: Kilo Lima Mike November Oscar"}\ ConflictValue 1 <nullObject>} {TableName t1 NumberOfColumns 2 OperationCode\ Delete Indirect False PrimaryKeyColumns {[True, False]} OldValue 0 4 NewValue 0\ <nullObject> ConflictValue 0 <nullObject> OldValue 1 {"inserted: Papa Quebec\ Romeo Sierra Tango"} NewValue 1 <nullObject> ConflictValue 1 <nullObject>}}}} ############################################################################### runTest {test session-1.3 {session enabled/disabled state} -setup { setupDb [set fileName session-1.3.db] cleanupSomeText |
︙ | ︙ | |||
442 443 444 445 446 447 448 | 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 {IsEnabled\ True IsEnabled True IsEnabled False IsEmpty True Length 0 IsEnabled True\ | | | | 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 | 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 {IsEnabled\ True IsEnabled True IsEnabled False IsEmpty True Length 0 IsEnabled True\ IsEmpty False {{TableName t1 NumberOfColumns 2 OperationCode Insert Indirect\ False PrimaryKeyColumns {[True, False]}}}}} ############################################################################### runTest {test session-1.4 {session direct/indirect state} -setup { setupDb [set fileName session-1.4.db] cleanupSomeText |
︙ | ︙ | |||
499 500 501 502 503 504 505 | 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 \ {IsIndirect False IsIndirect False IsIndirect True IsEmpty False IsIndirect\ | | | | | 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 | 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 \ {IsIndirect False IsIndirect False IsIndirect True IsEmpty False IsIndirect\ False IsEmpty False {{TableName t1 NumberOfColumns 2 OperationCode Insert\ Indirect True PrimaryKeyColumns {[True, False]}} {TableName t1 NumberOfColumns\ 2 OperationCode Insert Indirect False PrimaryKeyColumns {[True, False]}}}}} ############################################################################### runTest {test session-1.5 {session table filter} -setup { setupDb [set fileName session-1.5.db] cleanupSomeText |
︙ | ︙ | |||
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 | System.Data.SQLite SQLiteInterop\ defineConstant.System.Data.SQLite.INTEROP_SESSION_EXTENSION} -result {IsEmpty\ True MatchT2 false IsEmpty False MatchT1 true IsEmpty False MatchT2 true\ IsEmpty False MatchT1 true}} ############################################################################### rename tableFilterCallbackT1 "" rename createByteArray "" rename arrayToList "" rename getChangeSetFileName "" rename makeSomeChanges "" rename createTheSchema "" rename matchChangeSet "" rename matchSession "" rename changeSetToString "" rename createChangeSetForSession "" rename forDisplay "" rename cleanupSomeText "" rename getSomeText "" ############################################################################### runSQLiteTestEpilogue runTestEpilogue | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 652 653 654 655 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 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 | System.Data.SQLite SQLiteInterop\ defineConstant.System.Data.SQLite.INTEROP_SESSION_EXTENSION} -result {IsEmpty\ True MatchT2 false IsEmpty False MatchT1 true IsEmpty False MatchT2 true\ IsEmpty False MatchT1 true}} ############################################################################### runTest {test session-1.6 {combine and apply change sets} -setup { setupDb [set fileName session-1.6.db] cleanupSomeText } -body { createTheSchema $db makeSomeChanges $db t1 [list insert insert] false set connection [getDbConnection] set rawData(1) [captureChangeSetRawData $connection main null { makeSomeChanges $db t1 [list delete] false 1 }]; object removeref $rawData(1) makeSomeChanges $db t1 [list insert] false 1 set rawData(2) [captureChangeSetRawData $connection main null { makeSomeChanges $db t1 [list insert] false }]; object removeref $rawData(2) set changeSet(1) [$connection -alias CreateChangeSet $rawData(1)] set changeSet(2) [$connection -alias CreateChangeSet $rawData(2)] set changeSet(3) [$changeSet(1) -alias CombineWith $changeSet(2)] $changeSet(3) -marshalflags +DynamicCallback Apply conflictCallback null list [changeSetToString $changeSet(3) true] Data [sql execute -execute \ reader -format list $db {SELECT x, y FROM t1 ORDER BY x;}] } -cleanup { cleanupSomeText unset -nocomplain changeSet rawData freeDbConnection unset -nocomplain connection cleanupDb $fileName catch {object removecallback conflictCallback} catch { foreach callbackResult $callbackResults { catch {object dispose $callbackResult} } } unset -nocomplain callbackResult callbackResults 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: Papa Quebec Romeo Sierra Tango"}\ ConflictValue 1 <nullObject>}} Data {1 {inserted: Kilo Lima Mike November\ Oscar} 2 {inserted: Foxtrot Golf Hotel India Juliet} 3 {inserted: Papa Quebec\ Romeo Sierra Tango}}}} ############################################################################### rename conflictCallback "" rename tableFilterCallbackT1 "" rename createByteArray "" rename arrayToList "" rename getChangeSetFileName "" rename captureChangeSetRawData "" rename makeSomeChanges "" rename createTheSchema "" rename matchChangeSet "" rename matchSession "" rename changeSetToString "" rename metadataItemToString "" rename createChangeSetForSession "" rename forDisplay "" rename cleanupSomeText "" rename getSomeText "" ############################################################################### runSQLiteTestEpilogue runTestEpilogue |