System.Data.SQLite
Check-in [7ee168e2ff]
Not logged in

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

Overview
Comment:Add tests for the enabled/disabled state of the session object.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sessions
Files: files | file ages | folders
SHA1: 7ee168e2ff5036740792c5edf78a5cd2c1088b68
User & Date: mistachkin 2017-10-10 22:42:30
Context
2017-10-10
23:02
Move the rawData parameter checking code into its own (static) method. check-in: 0adbed8ca0 user: mistachkin tags: sessions
22:42
Add tests for the enabled/disabled state of the session object. check-in: 7ee168e2ff user: mistachkin tags: sessions
21:58
Remove unused string constant. check-in: a9cc684e27 user: mistachkin tags: sessions
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

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

550
551
552
553
554
555
556



557
558
559
560
561
562
563
....
1025
1026
1027
1028
1029
1030
1031



1032
1033
1034
1035
1036
1037
1038
....
1081
1082
1083
1084
1085
1086
1087



1088
1089
1090
1091
1092
1093
1094
....
1792
1793
1794
1795
1796
1797
1798



1799
1800
1801
1802
1803
1804
1805
        public static SQLiteMemoryChangeSetIterator Create(
            byte[] rawData
            )
        {
            if (rawData == null)
                throw new ArgumentNullException("rawData");




            SQLiteMemoryChangeSetIterator result = null;
            IntPtr pData = IntPtr.Zero;
            IntPtr iterator = IntPtr.Zero;

            try
            {
                int nData = 0;
................................................................................
        {
            CheckDisposed();
            CheckHandle();

            if (rawData == null)
                throw new ArgumentNullException("rawData");




            IntPtr pData = IntPtr.Zero;

            try
            {
                int nData = 0;

                pData = SQLiteBytes.ToIntPtr(rawData, ref nData);
................................................................................
        {
            CheckDisposed();
            CheckHandle();

            if (rawData == null)
                throw new ArgumentNullException("rawData");




            IntPtr pData = IntPtr.Zero;

            try
            {
                int nData = 0;

                SQLiteErrorCode rc = UnsafeNativeMethods.sqlite3changegroup_output(
................................................................................
        ///////////////////////////////////////////////////////////////////////

        #region Private Methods
        private void CheckRawData()
        {
            if (rawData == null)
                throw new InvalidOperationException("no change set data");



        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region ISQLiteChangeSet Members
        public ISQLiteChangeSet Invert()







>
>
>







 







>
>
>







 







>
>
>







 







>
>
>







550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
....
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
....
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
....
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
        public static SQLiteMemoryChangeSetIterator Create(
            byte[] rawData
            )
        {
            if (rawData == null)
                throw new ArgumentNullException("rawData");

            if (rawData.Length == 0)
                throw new ArgumentException("empty change set data", "rawData");

            SQLiteMemoryChangeSetIterator result = null;
            IntPtr pData = IntPtr.Zero;
            IntPtr iterator = IntPtr.Zero;

            try
            {
                int nData = 0;
................................................................................
        {
            CheckDisposed();
            CheckHandle();

            if (rawData == null)
                throw new ArgumentNullException("rawData");

            if (rawData.Length == 0)
                throw new ArgumentException("empty change set data", "rawData");

            IntPtr pData = IntPtr.Zero;

            try
            {
                int nData = 0;

                pData = SQLiteBytes.ToIntPtr(rawData, ref nData);
................................................................................
        {
            CheckDisposed();
            CheckHandle();

            if (rawData == null)
                throw new ArgumentNullException("rawData");

            if (rawData.Length == 0)
                throw new ArgumentException("empty change set data", "rawData");

            IntPtr pData = IntPtr.Zero;

            try
            {
                int nData = 0;

                SQLiteErrorCode rc = UnsafeNativeMethods.sqlite3changegroup_output(
................................................................................
        ///////////////////////////////////////////////////////////////////////

        #region Private Methods
        private void CheckRawData()
        {
            if (rawData == null)
                throw new InvalidOperationException("no change set data");

            if (rawData.Length == 0)
                throw new InvalidOperationException("empty change set data");
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region ISQLiteChangeSet Members
        public ISQLiteChangeSet Invert()

Changes to Tests/session.eagle.

89
90
91
92
93
94
95

96
97
98
99
100
101
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
...
171
172
173
174
175
176
177


178
179
180
181
182
183
184
185
186
187

188
189
190
191
192
193
194
...
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
...
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
...
317
318
319
320
321
322
323

































































324
325
326
327
328
329
330
}

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

proc changeSetToString { changeSet includeValues } {
  set result [list]


  object foreach -alias item $changeSet {
    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
}

................................................................................
  return [file join \
      [getTemporaryDirectory] [appendArgs changes $suffix .bin]]
}

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

proc arrayToList { varName } {


  upvar 1 $varName array

  if {![array exists array]} {
    error [appendArgs \" $a "\" isn't an array"]
  }

  set result [list]

  foreach name [lsort -integer [array names array]] {
    lappend result $array($name)

  }

  return $result
}

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

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

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

  makeSomeChanges $db [list insert update delete] true

  set byteArray null
  set changeSet(1) [$session -alias CreateChangeSet byteArray]
  set rawData [createByteArray [arrayToList byteArray]]
  object removeref $rawData

  set stream(1) [object create -alias \
      System.IO.FileStream $fileName(1) Create Write]

  $stream(1) Write $rawData 0 [$rawData Length]
  $stream(1) Flush; $stream(1) Close

  set stream(2) [object create -alias \
      System.IO.FileStream $fileName(2) Create Write]

  set changeSet(2) [$session -alias CreateChangeSet $stream(2)]
  $stream(2) Flush; $stream(2) Close

  list [expr {[file size $fileName(1)] > 0}] \
      [string equal [readFile $fileName(1)] [readFile $fileName(2)]]
} -cleanup {
  cleanupSomeText

  unset -nocomplain changeSet stream rawData byteArray session

  freeDbConnection

  unset -nocomplain connection

  cleanupFile $fileName(2)
  cleanupFile $fileName(1)
................................................................................

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

  makeSomeChanges $db [list insert update delete] false

  set byteArray null
  set changeSet(1) [$session -alias CreateChangeSet byteArray]
  set rawData [createByteArray [arrayToList byteArray]]
  object removeref $rawData

  set changeSet(2) [$connection -alias CreateChangeSet $rawData]

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

  unset -nocomplain oldValue newValue conflictValue
  unset -nocomplain changeSet rawData byteArray session

  freeDbConnection
................................................................................
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>}}


































































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

rename createByteArray ""
rename arrayToList ""
rename getChangeSetFileName ""
rename makeSomeChanges ""







>
|
|
|
|
|

|
|

|
|

|
|

|
|

|

|
|

|

|
|
>







 







>
>


|
<
<
<
<
<
|
|
>







 







|












|







|







 







|



|

|







 







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







89
90
91
92
93
94
95
96
97
98
99
100
101
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
...
173
174
175
176
177
178
179
180
181
182
183
184





185
186
187
188
189
190
191
192
193
194
...
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
...
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
...
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
}

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

proc changeSetToString { changeSet includeValues } {
  set result [list]

  if {[isObjectHandle $changeSet] && $changeSet ne "null"} then {
    object foreach -alias item $changeSet {
      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
}

................................................................................
  return [file join \
      [getTemporaryDirectory] [appendArgs changes $suffix .bin]]
}

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

proc arrayToList { varName } {
  set result [list]

  upvar 1 $varName array

  if {[array exists array]} then {





    foreach name [lsort -integer [array names array]] {
      lappend result $array($name)
    }
  }

  return $result
}

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

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

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

  makeSomeChanges $db [list insert update delete] true

  set byteArray null
  $session -alias CreateChangeSet byteArray
  set rawData [createByteArray [arrayToList byteArray]]
  object removeref $rawData

  set stream(1) [object create -alias \
      System.IO.FileStream $fileName(1) Create Write]

  $stream(1) Write $rawData 0 [$rawData Length]
  $stream(1) Flush; $stream(1) Close

  set stream(2) [object create -alias \
      System.IO.FileStream $fileName(2) Create Write]

  $session -alias CreateChangeSet $stream(2)
  $stream(2) Flush; $stream(2) Close

  list [expr {[file size $fileName(1)] > 0}] \
      [string equal [readFile $fileName(1)] [readFile $fileName(2)]]
} -cleanup {
  cleanupSomeText

  unset -nocomplain stream rawData byteArray session

  freeDbConnection

  unset -nocomplain connection

  cleanupFile $fileName(2)
  cleanupFile $fileName(1)
................................................................................

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

  makeSomeChanges $db [list insert update delete] false

  set byteArray null
  $session -alias CreateChangeSet byteArray
  set rawData [createByteArray [arrayToList byteArray]]
  object removeref $rawData

  set changeSet(1) [$connection -alias CreateChangeSet $rawData]

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

  unset -nocomplain oldValue newValue conflictValue
  unset -nocomplain changeSet rawData byteArray session

  freeDbConnection
................................................................................
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>}}

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

runTest {test session-1.3 {session enabled/disabled state} -setup {
  setupDb [set fileName session-1.3.db]

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

  set connection [getDbConnection]

  set session [$connection -alias CreateSession main]
  lappend result [$session IsEnabled]

  $session AttachTable null
  lappend result [$session IsEnabled]

  $session SetToDisabled
  lappend result [$session IsEnabled]

  makeSomeChanges $db [list insert update delete] false

  set byteArray null
  $session -alias CreateChangeSet byteArray
  set rawData [createByteArray [arrayToList byteArray]]
  object removeref $rawData

  lappend result [$rawData Length]

  $session SetToEnabled
  lappend result [$session IsEnabled]

  makeSomeChanges $db [list insert update delete] false

  set byteArray null
  $session -alias CreateChangeSet byteArray
  set rawData [createByteArray [arrayToList byteArray]]
  object removeref $rawData

  set changeSet(1) [$connection -alias CreateChangeSet $rawData]
  lappend result [changeSetToString $changeSet(1) false]
} -cleanup {
  cleanupSomeText

  unset -nocomplain oldValue newValue conflictValue
  unset -nocomplain result changeSet rawData byteArray session

  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 {True True\
False 0 True {TableName t1 NumberOfColumns 2 OperationCode Delete Indirect\
False PrimaryKeyColumns {[True, False]} TableName t1 NumberOfColumns 2\
OperationCode Update Indirect False PrimaryKeyColumns {[True, False]} TableName\
t1 NumberOfColumns 2 OperationCode Update Indirect False PrimaryKeyColumns\
{[True, False]} TableName t1 NumberOfColumns 2 OperationCode Insert Indirect\
False PrimaryKeyColumns {[True, False]}}}}

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

rename createByteArray ""
rename arrayToList ""
rename getChangeSetFileName ""
rename makeSomeChanges ""