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

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

Overview
Comment:Add tests for LoadDifferencesFromTable and stream-based change set creation.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sessions
Files: files | file ages | folders
SHA1: e3f513c15d19ca8553d31fddee4a6bdc868f5b92
User & Date: mistachkin 2017-10-12 00:00:52
Context
2017-10-12
00:03
Minor test cleanup. check-in: ac526d98e8 user: mistachkin tags: sessions
00:00
Add tests for LoadDifferencesFromTable and stream-based change set creation. check-in: e3f513c15d user: mistachkin tags: sessions
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
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Tests/session.eagle.

   185    185     }
   186    186   
   187    187     return false
   188    188   }
   189    189   
   190    190   ###############################################################################
   191    191   
   192         -proc createTheSchema { db } {
   193         -  sql execute $db {
   194         -    CREATE TABLE t1(x INTEGER PRIMARY KEY, y TEXT);
   195         -    CREATE TABLE t2(x INTEGER PRIMARY KEY, y TEXT);
   196         -  }
          192  +proc createTheSchema { db databaseName } {
          193  +  sql execute $db [subst {
          194  +    CREATE TABLE ${databaseName}.t1(x INTEGER PRIMARY KEY, y TEXT);
          195  +    CREATE TABLE ${databaseName}.t2(x INTEGER PRIMARY KEY, y TEXT);
          196  +  }]
   197    197   }
   198    198   
   199    199   ###############################################################################
   200    200   
   201    201   proc makeSomeChanges { db table types random {rowId ""} {count 5} } {
   202    202     foreach type $types {
   203    203       switch -nocase -- $type {
................................................................................
   340    340     setupDb [set fileName(0) session-1.1.db]
   341    341   
   342    342     set fileName(1) [getChangeSetFileName 1]
   343    343     set fileName(2) [getChangeSetFileName 2]
   344    344   
   345    345     cleanupSomeText
   346    346   } -body {
   347         -  createTheSchema $db
   348         -  makeSomeChanges $db t1 [list insert] true
          347  +  createTheSchema $db main
          348  +  makeSomeChanges $db t1 [list insert insert] false
   349    349   
   350    350     set connection [getDbConnection]
   351    351   
   352    352     set session [$connection -alias CreateSession main]
   353    353     $session AttachTable null
   354    354   
   355         -  makeSomeChanges $db t1 [list insert update delete] true
          355  +  makeSomeChanges $db t1 [list insert update delete] false
   356    356   
   357    357     set rawData [createChangeSetForSession $session]
   358    358     object removeref $rawData
   359    359   
   360    360     set stream(1) [object create -alias \
   361    361         System.IO.FileStream $fileName(1) Create Write]
   362    362   
................................................................................
   365    365   
   366    366     set stream(2) [object create -alias \
   367    367         System.IO.FileStream $fileName(2) Create Write]
   368    368   
   369    369     $session -alias CreateChangeSet $stream(2)
   370    370     $stream(2) Flush; $stream(2) Close
   371    371   
          372  +  set stream(3) [object create -alias \
          373  +      System.IO.FileStream $fileName(2) Open Read]
          374  +
          375  +  set changeSet [$connection -alias CreateChangeSet $stream(3) null]
          376  +
   372    377     list [expr {[file size $fileName(1)] > 0}] \
   373         -      [string equal [readFile $fileName(1)] [readFile $fileName(2)]]
          378  +      [string equal [readFile $fileName(1)] [readFile $fileName(2)]] \
          379  +      [changeSetToString $changeSet true] [$stream(3) Close]
   374    380   } -cleanup {
   375    381     cleanupSomeText
   376    382   
   377         -  unset -nocomplain stream rawData byteArray session
          383  +  unset -nocomplain changeSet stream rawData byteArray session
   378    384   
   379    385     freeDbConnection
   380    386   
   381    387     unset -nocomplain connection
   382    388   
   383    389     cleanupFile $fileName(2)
   384    390     cleanupFile $fileName(1)
   385    391   
   386    392     cleanupDb $fileName(0)
   387    393   
   388    394     unset -nocomplain db fileName
   389    395   } -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
   390    396   System.Data.SQLite SQLiteInterop\
   391         -defineConstant.System.Data.SQLite.INTEROP_SESSION_EXTENSION} -result \
   392         -{True True}}
          397  +defineConstant.System.Data.SQLite.INTEROP_SESSION_EXTENSION} -result {True True\
          398  +{{TableName t1 NumberOfColumns 2 OperationCode Delete Indirect False\
          399  +PrimaryKeyColumns {[True, False]} OldValue 0 1 NewValue 0 <nullObject>\
          400  +ConflictValue 0 <nullObject> OldValue 1 {"inserted: Alpha Bravo Charlie Delta\
          401  +Echo"} NewValue 1 <nullObject> ConflictValue 1 <nullObject>} {TableName t1\
          402  +NumberOfColumns 2 OperationCode Update Indirect False PrimaryKeyColumns {[True,\
          403  +False]} OldValue 0 2 NewValue 0 <nullObject> ConflictValue 0 <nullObject>\
          404  +OldValue 1 {"inserted: Foxtrot Golf Hotel India Juliet"} NewValue 1 {"updated:\
          405  +Papa Quebec Romeo Sierra Tango"} ConflictValue 1 <nullObject>} {TableName t1\
          406  +NumberOfColumns 2 OperationCode Insert Indirect False PrimaryKeyColumns {[True,\
          407  +False]} OldValue 0 <nullObject> NewValue 0 3 ConflictValue 0 <nullObject>\
          408  +OldValue 1 <nullObject> NewValue 1 {"inserted: Kilo Lima Mike November Oscar"}\
          409  +ConflictValue 1 <nullObject>}} {}}}
   393    410   
   394    411   ###############################################################################
   395    412   
   396    413   runTest {test session-1.2 {session change set enumeration} -setup {
   397    414     setupDb [set fileName session-1.2.db]
   398    415   
   399    416     cleanupSomeText
   400    417   } -body {
   401         -  createTheSchema $db
          418  +  createTheSchema $db main
   402    419     makeSomeChanges $db t1 [list insert insert insert] false
   403    420   
   404    421     set connection [getDbConnection]
   405    422   
   406    423     set session [$connection -alias CreateSession main]
   407    424     $session AttachTable null
   408    425   
................................................................................
   466    483   ###############################################################################
   467    484   
   468    485   runTest {test session-1.3 {session enabled/disabled state} -setup {
   469    486     setupDb [set fileName session-1.3.db]
   470    487   
   471    488     cleanupSomeText
   472    489   } -body {
   473         -  createTheSchema $db
          490  +  createTheSchema $db main
   474    491     makeSomeChanges $db t1 [list insert] false
   475    492   
   476    493     set connection [getDbConnection]
   477    494   
   478    495     set session [$connection -alias CreateSession main]
   479    496     lappend result IsEnabled [$session IsEnabled]
   480    497   
................................................................................
   525    542   ###############################################################################
   526    543   
   527    544   runTest {test session-1.4 {session direct/indirect state} -setup {
   528    545     setupDb [set fileName session-1.4.db]
   529    546   
   530    547     cleanupSomeText
   531    548   } -body {
   532         -  createTheSchema $db
          549  +  createTheSchema $db main
   533    550     makeSomeChanges $db t1 [list insert] false
   534    551   
   535    552     set connection [getDbConnection]
   536    553   
   537    554     set session [$connection -alias CreateSession main]
   538    555     lappend result IsIndirect [$session IsIndirect]
   539    556   
................................................................................
   583    600   ###############################################################################
   584    601   
   585    602   runTest {test session-1.5 {session table filter} -setup {
   586    603     setupDb [set fileName session-1.5.db]
   587    604   
   588    605     cleanupSomeText
   589    606   } -body {
   590         -  createTheSchema $db
          607  +  createTheSchema $db main
   591    608     makeSomeChanges $db t1 [list insert] false
   592    609   
   593    610     set connection [getDbConnection]
   594    611   
   595    612     set session [$connection -alias CreateSession main]
   596    613   
   597    614     $session -marshalflags +DynamicCallback \
................................................................................
   657    674   ###############################################################################
   658    675   
   659    676   runTest {test session-1.6 {combine and apply change sets} -setup {
   660    677     setupDb [set fileName session-1.6.db]
   661    678   
   662    679     cleanupSomeText
   663    680   } -body {
   664         -  createTheSchema $db
          681  +  createTheSchema $db main
   665    682     makeSomeChanges $db t1 [list insert insert] false
   666    683   
   667    684     set connection [getDbConnection]
   668    685   
   669    686     set rawData(1) [captureChangeSetRawData $connection main null {
   670    687       makeSomeChanges $db t1 [list delete] false 1
   671    688     }]; object removeref $rawData(1)
................................................................................
   713    730   Echo"} NewValue 1 <nullObject> ConflictValue 1 <nullObject>} {TableName t1\
   714    731   NumberOfColumns 2 OperationCode Insert Indirect False PrimaryKeyColumns {[True,\
   715    732   False]} OldValue 0 <nullObject> NewValue 0 3 ConflictValue 0 <nullObject>\
   716    733   OldValue 1 <nullObject> NewValue 1 {"inserted: Papa Quebec Romeo Sierra Tango"}\
   717    734   ConflictValue 1 <nullObject>}} Data {1 {inserted: Kilo Lima Mike November\
   718    735   Oscar} 2 {inserted: Foxtrot Golf Hotel India Juliet} 3 {inserted: Papa Quebec\
   719    736   Romeo Sierra Tango}}}}
          737  +
          738  +###############################################################################
          739  +
          740  +runTest {test session-1.7 {differences between tables} -setup {
          741  +  setupDb [set fileName session-1.7.db]
          742  +
          743  +  cleanupSomeText
          744  +} -body {
          745  +  createTheSchema $db main
          746  +  makeSomeChanges $db t1 [list insert insert] false
          747  +
          748  +  set result [list]
          749  +
          750  +  lappend result [sql execute -execute reader -format list $db \
          751  +      {SELECT x, y FROM t1 ORDER BY x;}]
          752  +
          753  +  createTheSchema $db temp
          754  +  sql execute $db {INSERT INTO temp.t1 SELECT * FROM main.t1;}
          755  +  makeSomeChanges $db temp.t1 [list insert insert] false
          756  +
          757  +  set connection [getDbConnection]
          758  +
          759  +  set session [$connection -alias CreateSession main]
          760  +  $session AttachTable null
          761  +  $session LoadDifferencesFromTable temp t1
          762  +
          763  +  lappend result [sql execute -execute reader -format list $db \
          764  +      {SELECT x, y FROM t1 ORDER BY x;}]
          765  +} -cleanup {
          766  +  cleanupSomeText
          767  +
          768  +  unset -nocomplain result session
          769  +
          770  +  freeDbConnection
          771  +
          772  +  unset -nocomplain connection
          773  +
          774  +  cleanupDb $fileName
          775  +
          776  +  unset -nocomplain db fileName
          777  +} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
          778  +System.Data.SQLite SQLiteInterop\
          779  +defineConstant.System.Data.SQLite.INTEROP_SESSION_EXTENSION} -result {{1\
          780  +{inserted: Alpha Bravo Charlie Delta Echo} 2 {inserted: Foxtrot Golf Hotel\
          781  +India Juliet}} {1 {inserted: Alpha Bravo Charlie Delta Echo} 2 {inserted:\
          782  +Foxtrot Golf Hotel India Juliet} 3 {inserted: Kilo Lima Mike November Oscar} 4\
          783  +{inserted: Papa Quebec Romeo Sierra Tango}}}}
          784  +
          785  +###############################################################################
          786  +
          787  +
          788  +
          789  +
   720    790   
   721    791   ###############################################################################
   722    792   
   723    793   rename conflictCallback ""
   724    794   rename tableFilterCallbackT1 ""
   725    795   rename createByteArray ""
   726    796   rename arrayToList ""