System.Data.SQLite

Check-in [40e0fb8133]
Login

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

Overview
Comment:Modularize the connection opaque object handle lookup done by several tests. Modify test data-1.34 to use the Enum typed ReturnCode property instead of the Int32 typed ErrorCode property. Improve comments and formatting in the common test suite infrastructure file.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 40e0fb8133bca317b7b694706e4d94c635b42127
User & Date: mistachkin 2012-09-22 18:50:35.105
Context
2012-09-22
18:56
Fix script variable name typo. check-in: 2381125d29 user: mistachkin tags: trunk
18:50
Modularize the connection opaque object handle lookup done by several tests. Modify test data-1.34 to use the Enum typed ReturnCode property instead of the Int32 typed ErrorCode property. Improve comments and formatting in the common test suite infrastructure file. check-in: 40e0fb8133 user: mistachkin tags: trunk
2012-09-21
10:05
Set minimum wait time between workload iterations in the stress test. check-in: e3dee8b8fc user: mistachkin tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to Tests/backup.eagle.
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109

    for {set index 0} {$index < 10} {incr index} {
      sql execute $memDb [subst {
        INSERT INTO t1 (x) VALUES('[string repeat ! 1048576]');
      }]
    }

    set memSource [object invoke -flags +NonPublic -objectflags +NoDispose \
        Interpreter.GetActive.connections get_Item $memDb]

    unset -nocomplain results errors

    set code [compileCSharpWith [subst {
      using System;
      using System.Data.SQLite;
      using System.Text;







|
<







94
95
96
97
98
99
100
101

102
103
104
105
106
107
108

    for {set index 0} {$index < 10} {incr index} {
      sql execute $memDb [subst {
        INSERT INTO t1 (x) VALUES('[string repeat ! 1048576]');
      }]
    }

    set memSource [getDbConnection memDb]


    unset -nocomplain results errors

    set code [compileCSharpWith [subst {
      using System;
      using System.Data.SQLite;
      using System.Text;
207
208
209
210
211
212
213


214
215
216
217
218
219
220
        [expr {[info exists errors] ? $errors : ""}] \
        [expr {$code eq "Ok" ? [catch {
          object invoke _Dynamic${id}.Test${id} BackupAndGetData "" $memSource
        } result] : [set result ""]}] $result $callbackResults
  } -cleanup {
    cleanupDb $fileName(2)
    cleanupDb $fileName(1) memDb



    unset -nocomplain result results errors code index memSource dataSource \
        id memDb db fileName callbackResults
  } -constraints \
{eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} \
-match regexp -result [appendArgs \
"^Ok System#CodeDom#Compiler#CompilerResults#\\d+ \\{\\} " \







>
>







206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
        [expr {[info exists errors] ? $errors : ""}] \
        [expr {$code eq "Ok" ? [catch {
          object invoke _Dynamic${id}.Test${id} BackupAndGetData "" $memSource
        } result] : [set result ""]}] $result $callbackResults
  } -cleanup {
    cleanupDb $fileName(2)
    cleanupDb $fileName(1) memDb

    freeDbConnection memSource

    unset -nocomplain result results errors code index memSource dataSource \
        id memDb db fileName callbackResults
  } -constraints \
{eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} \
-match regexp -result [appendArgs \
"^Ok System#CodeDom#Compiler#CompilerResults#\\d+ \\{\\} " \
Changes to Tests/basic.eagle.
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
\{\} \{\}$}}

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

runTest {test data-1.10 {Changes property} -setup {
  setupDb [set fileName data-1.10.db]
} -body {
  set connection [object invoke -flags +NonPublic -objectflags +NoDispose \
      Interpreter.GetActive.connections Item $db]

  set result [list]

  sql execute $db "CREATE TABLE t1(x INTEGER PRIMARY KEY ASC, y, z);"

  sql execute $db "INSERT INTO t1 (x, y, z) VALUES(1, 'foo', 1234);"
  sql execute $db "INSERT INTO t1 (x, y, z) VALUES(2, 'bar', 5678);"







|
<







587
588
589
590
591
592
593
594

595
596
597
598
599
600
601
\{\} \{\}$}}

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

runTest {test data-1.10 {Changes property} -setup {
  setupDb [set fileName data-1.10.db]
} -body {
  set connection [getDbConnection]


  set result [list]

  sql execute $db "CREATE TABLE t1(x INTEGER PRIMARY KEY ASC, y, z);"

  sql execute $db "INSERT INTO t1 (x, y, z) VALUES(1, 'foo', 1234);"
  sql execute $db "INSERT INTO t1 (x, y, z) VALUES(2, 'bar', 5678);"
611
612
613
614
615
616
617


618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
  foreach name [lsort -integer [array names rows -regexp {^\d+$}]] {
    lappend result [list $name $rows($name)]
  }

  set result
} -cleanup {
  cleanupDb $fileName



  unset -nocomplain name rows result connection db fileName
} -constraints \
{eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} \
-result {1 2 2 {1 {{x 1} {y foobar} {z 1234}}} {2 {{x 2} {y foobar} {z 5678}}}}}

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

runTest {test data-1.11 {LastInsertRowId property} -setup {
  setupDb [set fileName data-1.11.db]
} -body {
  set connection [object invoke -flags +NonPublic -objectflags +NoDispose \
      Interpreter.GetActive.connections Item $db]

  set result [list]

  sql execute $db "CREATE TABLE t1(x INTEGER PRIMARY KEY ASC, y, z);"

  sql execute $db "CREATE TABLE t2(x INTEGER PRIMARY KEY AUTOINCREMENT, y, z);"
  lappend result [object invoke $connection LastInsertRowId]







>
>











|
<







610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630

631
632
633
634
635
636
637
  foreach name [lsort -integer [array names rows -regexp {^\d+$}]] {
    lappend result [list $name $rows($name)]
  }

  set result
} -cleanup {
  cleanupDb $fileName

  freeDbConnection

  unset -nocomplain name rows result connection db fileName
} -constraints \
{eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} \
-result {1 2 2 {1 {{x 1} {y foobar} {z 1234}}} {2 {{x 2} {y foobar} {z 5678}}}}}

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

runTest {test data-1.11 {LastInsertRowId property} -setup {
  setupDb [set fileName data-1.11.db]
} -body {
  set connection [getDbConnection]


  set result [list]

  sql execute $db "CREATE TABLE t1(x INTEGER PRIMARY KEY ASC, y, z);"

  sql execute $db "CREATE TABLE t2(x INTEGER PRIMARY KEY AUTOINCREMENT, y, z);"
  lappend result [object invoke $connection LastInsertRowId]
667
668
669
670
671
672
673


674
675
676
677
678
679
680
  foreach name [lsort -integer [array names rows -regexp {^\d+$}]] {
    lappend result [list $name $rows($name)]
  }

  set result
} -cleanup {
  cleanupDb $fileName



  unset -nocomplain name rows result connection db fileName
} -constraints \
{eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} \
-result {0 1 2 2 1 2 2 2 {1 {{x 1} {y foobar} {z 1234}}} {2 {{x 2} {y foobar}\
{z 5678}}} 2 {1 {{x 1} {y foobar} {z 1234}}} {2 {{x 2} {y foobar} {z 5678}}}}}








>
>







667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
  foreach name [lsort -integer [array names rows -regexp {^\d+$}]] {
    lappend result [list $name $rows($name)]
  }

  set result
} -cleanup {
  cleanupDb $fileName

  freeDbConnection

  unset -nocomplain name rows result connection db fileName
} -constraints \
{eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} \
-result {0 1 2 2 1 2 2 2 {1 {{x 1} {y foobar} {z 1234}}} {2 {{x 2} {y foobar}\
{z 5678}}} 2 {1 {{x 1} {y foobar} {z 1234}}} {2 {{x 2} {y foobar} {z 5678}}}}}

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
1407
1408
1409
1410
1411
1412
1413


1414
1415
1416
1417
1418
1419
1420
    INSERT INTO t1 (x, y) VALUES(22, 'viper');
    INSERT INTO t1 (x, y) VALUES(23, 'weasel');
    INSERT INTO t1 (x, y) VALUES(24, 'xerus');
    INSERT INTO t1 (x, y) VALUES(25, 'yak');
    INSERT INTO t1 (x, y) VALUES(26, 'zebra');
  }

  set connection [object invoke -flags +NonPublic -objectflags +NoDispose \
      Interpreter.GetActive.connections get_Item $db]

  set command [object create -alias System.Data.SQLite.SQLiteCommand \
      "SELECT x, y, x, y FROM t1 ORDER BY y DESC;" $connection]

  set reader [$command -alias ExecuteReader]
  set collection [$reader -alias GetValues]
  set result [list]

  object foreach -alias item $collection {
    lappend result [$collection GetValues $item]
  }

  set result
} -cleanup {


  unset -nocomplain result item collection reader command connection

  cleanupDb $fileName; # NOTE: After object disposal.

  unset -nocomplain db fileName
} -constraints \
{eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} -result \
{{26 26} {zebra zebra}}}

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

runTest {test data-1.26 {LINQ ISQLiteSchemaExtensions.BuildTempSchema} -setup {
  setupDb [set fileName data-1.26.db]
} -body {
  set connection [object invoke -flags +NonPublic -objectflags +NoDispose \
      Interpreter.GetActive.connections Item $db]

  set providerServices [object invoke -flags +NonPublic \
      System.Data.SQLite.SQLiteProviderServices Instance]

  object invoke -flags +NonPublic -type \
      System.Data.SQLite.ISQLiteSchemaExtensions $providerServices \
      BuildTempSchema $connection
} -cleanup {
  cleanupDb $fileName



  unset -nocomplain providerServices connection db fileName
} -constraints {eagle SQLite System.Data.SQLite System.Data.SQLite.Linq} \
-result {}}

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








|
<














>
>














|
<









>
>







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

1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
    INSERT INTO t1 (x, y) VALUES(22, 'viper');
    INSERT INTO t1 (x, y) VALUES(23, 'weasel');
    INSERT INTO t1 (x, y) VALUES(24, 'xerus');
    INSERT INTO t1 (x, y) VALUES(25, 'yak');
    INSERT INTO t1 (x, y) VALUES(26, 'zebra');
  }

  set connection [getDbConnection]


  set command [object create -alias System.Data.SQLite.SQLiteCommand \
      "SELECT x, y, x, y FROM t1 ORDER BY y DESC;" $connection]

  set reader [$command -alias ExecuteReader]
  set collection [$reader -alias GetValues]
  set result [list]

  object foreach -alias item $collection {
    lappend result [$collection GetValues $item]
  }

  set result
} -cleanup {
  freeDbConnection

  unset -nocomplain result item collection reader command connection

  cleanupDb $fileName; # NOTE: After object disposal.

  unset -nocomplain db fileName
} -constraints \
{eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} -result \
{{26 26} {zebra zebra}}}

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

runTest {test data-1.26 {LINQ ISQLiteSchemaExtensions.BuildTempSchema} -setup {
  setupDb [set fileName data-1.26.db]
} -body {
  set connection [getDbConnection]


  set providerServices [object invoke -flags +NonPublic \
      System.Data.SQLite.SQLiteProviderServices Instance]

  object invoke -flags +NonPublic -type \
      System.Data.SQLite.ISQLiteSchemaExtensions $providerServices \
      BuildTempSchema $connection
} -cleanup {
  cleanupDb $fileName

  freeDbConnection

  unset -nocomplain providerServices connection db fileName
} -constraints {eagle SQLite System.Data.SQLite System.Data.SQLite.Linq} \
-result {}}

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

1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790

  $serializer Serialize $stream $exception(1)

  $stream Seek 0 Begin

  set exception(2) [$serializer -alias Deserialize $stream]

  list [$exception(1) ErrorCode] [$exception(1) Message] \
      [$exception(2) ErrorCode] [$exception(2) Message] \
      [expr {[$exception(1) ErrorCode] eq [$exception(2) ErrorCode]}] \
      [expr {[$exception(1) Message] eq [$exception(2) Message]}]
} -cleanup {
  unset -nocomplain exception stream serializer
} -constraints {eagle SQLite System.Data.SQLite} -result \
[string map [list \n \r\n] {CantOpen {unable to open database file
this is a test} CantOpen {unable to open database file
this is a test} True True}]}







|
|
|







1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794

  $serializer Serialize $stream $exception(1)

  $stream Seek 0 Begin

  set exception(2) [$serializer -alias Deserialize $stream]

  list [$exception(1) ReturnCode] [$exception(1) Message] \
      [$exception(2) ReturnCode] [$exception(2) Message] \
      [expr {[$exception(1) ReturnCode] eq [$exception(2) ReturnCode]}] \
      [expr {[$exception(1) Message] eq [$exception(2) Message]}]
} -cleanup {
  unset -nocomplain exception stream serializer
} -constraints {eagle SQLite System.Data.SQLite} -result \
[string map [list \n \r\n] {CantOpen {unable to open database file
this is a test} CantOpen {unable to open database file
this is a test} True True}]}
Changes to Tests/common.eagle.
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
      }
    }

    proc getBuildFileName { fileName } {
      #
      # NOTE: Returns the specified file name as if it were located in the
      #       build directory, discarding any directory information present
      #       in the file name as provided by the caller.
      #
      return [file nativename \
          [file join [getBuildDirectory] [file tail $fileName]]]
    }

    proc getBinaryDirectory {} {
      #







|







230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
      }
    }

    proc getBuildFileName { fileName } {
      #
      # NOTE: Returns the specified file name as if it were located in the
      #       build directory, discarding any directory information present
      #       in the file name as provided by our caller.
      #
      return [file nativename \
          [file join [getBuildDirectory] [file tail $fileName]]]
    }

    proc getBinaryDirectory {} {
      #
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
      }
    }

    proc getBinaryFileName { fileName } {
      #
      # NOTE: Returns the specified file name as if it were located in the
      #       binary directory, discarding any directory information present
      #       in the file name as provided by the caller.
      #
      return [file nativename \
          [file join [getBinaryDirectory] [file tail $fileName]]]
    }

    proc getCoreBinaryFileName { {standard false} } {
      #







|







260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
      }
    }

    proc getBinaryFileName { fileName } {
      #
      # NOTE: Returns the specified file name as if it were located in the
      #       binary directory, discarding any directory information present
      #       in the file name as provided by our caller.
      #
      return [file nativename \
          [file join [getBinaryDirectory] [file tail $fileName]]]
    }

    proc getCoreBinaryFileName { {standard false} } {
      #
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
    }

    proc getAppDomainPreamble { {prefix ""} {suffix ""} } {
      #
      # NOTE: This procedure returns a test setup script suitable for evaluation
      #       by a test interpreter created in an isolated application domain.
      #       The script being returned will be surrounded by the prefix and
      #       suffix "script fragments" specified by the caller, if any.  The
      #       entire script being returned will be substituted via [subst], in
      #       the context of the caller.  This step is necessary so that some
      #       limited context information, primarily related to the test build
      #       directory, can be transferred to the interpreter in the isolated
      #       application domain, making it able to successfully run tests that
      #       require one or more of the files in the build directory.  Callers
      #       to this procedure should keep in mind that the test script being
      #       returned cannot rely on any script library procedures not defined
      #       by the Eagle.Library package (i.e. "init.eagle").  Also, all







|

|







315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
    }

    proc getAppDomainPreamble { {prefix ""} {suffix ""} } {
      #
      # NOTE: This procedure returns a test setup script suitable for evaluation
      #       by a test interpreter created in an isolated application domain.
      #       The script being returned will be surrounded by the prefix and
      #       suffix "script fragments" specified by our caller, if any.  The
      #       entire script being returned will be substituted via [subst], in
      #       the context of our caller.  This step is necessary so that some
      #       limited context information, primarily related to the test build
      #       directory, can be transferred to the interpreter in the isolated
      #       application domain, making it able to successfully run tests that
      #       require one or more of the files in the build directory.  Callers
      #       to this procedure should keep in mind that the test script being
      #       returned cannot rely on any script library procedures not defined
      #       by the Eagle.Library package (i.e. "init.eagle").  Also, all
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372

        return
      }

      set targetFileName [getBinaryFileName $fileName]

      if {[catch {
          file copy -force $sourceFileName $targetFileName}] == 0} then {
        tputs $::test_channel [appendArgs \
            "---- copied build file from \"" $sourceFileName "\" to \"" \
            $targetFileName \"\n]
      } else {
        tputs $::test_channel [appendArgs \
            "---- failed to copy build file from \"" $sourceFileName \
            "\" to \"" $targetFileName \"\n]







|







358
359
360
361
362
363
364
365
366
367
368
369
370
371
372

        return
      }

      set targetFileName [getBinaryFileName $fileName]

      if {[catch {
              file copy -force $sourceFileName $targetFileName}] == 0} then {
        tputs $::test_channel [appendArgs \
            "---- copied build file from \"" $sourceFileName "\" to \"" \
            $targetFileName \"\n]
      } else {
        tputs $::test_channel [appendArgs \
            "---- failed to copy build file from \"" $sourceFileName \
            "\" to \"" $targetFileName \"\n]
434
435
436
437
438
439
440

441
442
443
444
445
446

447
448
449
450
451
452
453
454

      return ""
    }

    proc checkForSQLite { channel } {
      tputs $channel "---- checking for core SQLite library... "


      if {[catch {object invoke -flags +NonPublic System.Data.SQLite.SQLite3 \
              SQLiteVersion} version] == 0} then {
        #
        # NOTE: Attempt to query the Fossil source identifier for the SQLite
        #       core library.
        #

        if {[catch {object invoke -flags +NonPublic System.Data.SQLite.SQLite3 \
                SQLiteSourceId} sourceId]} then {
          #
          # NOTE: We failed to query the Fossil source identifier.
          #
          set sourceId unknown
        }








>
|





>
|







434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456

      return ""
    }

    proc checkForSQLite { channel } {
      tputs $channel "---- checking for core SQLite library... "

      if {[catch {
              object invoke -flags +NonPublic System.Data.SQLite.SQLite3 \
              SQLiteVersion} version] == 0} then {
        #
        # NOTE: Attempt to query the Fossil source identifier for the SQLite
        #       core library.
        #
        if {[catch {
                object invoke -flags +NonPublic System.Data.SQLite.SQLite3 \
                SQLiteSourceId} sourceId]} then {
          #
          # NOTE: We failed to query the Fossil source identifier.
          #
          set sourceId unknown
        }

464
465
466
467
468
469
470

471
472
473
474
475
476
477
478
    }

    proc checkForSQLiteDefineConstant { channel name } {
      tputs $channel [appendArgs \
          "---- checking for System.Data.SQLite define constant \"" $name \
          "\"... "]


      if {[catch {object invoke -flags +NonPublic System.Data.SQLite.SQLite3 \
              DefineConstants} defineConstants] == 0} then {
        if {[lsearch -exact -nocase $defineConstants $name] != -1} then {
          #
          # NOTE: Yes, this define constant was enabled when the managed
          #       assembly was compiled.
          #
          addConstraint [appendArgs defineConstant.System.Data.SQLite. $name]







>
|







466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
    }

    proc checkForSQLiteDefineConstant { channel name } {
      tputs $channel [appendArgs \
          "---- checking for System.Data.SQLite define constant \"" $name \
          "\"... "]

      if {[catch {
              object invoke -flags +NonPublic System.Data.SQLite.SQLite3 \
              DefineConstants} defineConstants] == 0} then {
        if {[lsearch -exact -nocase $defineConstants $name] != -1} then {
          #
          # NOTE: Yes, this define constant was enabled when the managed
          #       assembly was compiled.
          #
          addConstraint [appendArgs defineConstant.System.Data.SQLite. $name]
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
      }

      return $result
    }

    proc catchAndReturn { script {stackTrace false} {strict true} } {
      #
      # NOTE: Evaluate the script provided by the caller in their context,
      #       capturing both the result and the return code.
      #
      set code [catch {uplevel 1 $script} result]

      #
      # NOTE: Did the script provided by the caller NOT raise an error?
      #
      if {$strict && $code == 0 || !$strict && $code != 1} then {
        #
        # NOTE: Success.  Return a list with the return code and the result.
        #
        return [list $code $result]
      } elseif {$stackTrace} then {
        #
        # NOTE: Failure.  The caller wants a full stack trace (if applicable),
        #       return a list with the return code and the result verbatim.
        #
        return [list $code $result]
      } else {
        #
        # NOTE: Failure.  The caller does not want a full stack trace (if
        #       applicable), return a list with the return code, the error
        #       code for the interpreter, and the error message up to the
        #       point where the stack trace should start.
        #
        set index [string first "   at " $result]; # HACK: Reliable?

        return [list $code $::errorCode [expr {$index != -1 ? \







|





|








|





|







525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
      }

      return $result
    }

    proc catchAndReturn { script {stackTrace false} {strict true} } {
      #
      # NOTE: Evaluate the script provided by our caller in their context,
      #       capturing both the result and the return code.
      #
      set code [catch {uplevel 1 $script} result]

      #
      # NOTE: Did the script provided by our caller NOT raise an error?
      #
      if {$strict && $code == 0 || !$strict && $code != 1} then {
        #
        # NOTE: Success.  Return a list with the return code and the result.
        #
        return [list $code $result]
      } elseif {$stackTrace} then {
        #
        # NOTE: Failure.  Our caller wants a full stack trace (if applicable),
        #       return a list with the return code and the result verbatim.
        #
        return [list $code $result]
      } else {
        #
        # NOTE: Failure.  Our caller does not want a full stack trace (if
        #       applicable), return a list with the return code, the error
        #       code for the interpreter, and the error message up to the
        #       point where the stack trace should start.
        #
        set index [string first "   at " $result]; # HACK: Reliable?

        return [list $code $::errorCode [expr {$index != -1 ? \
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
          [string range $fileName 0 12] eq "file::memory:"}]
    }

    proc setupDb {
            fileName {mode ""} {dateTimeFormat ""} {dateTimeKind ""} {flags ""}
            {extra ""} {qualify true} {delete true} {uri false} {varName db} } {
      #
      # NOTE: First, see if the caller has requested an in-memory database.
      #
      set isMemory [isMemoryDb $fileName]

      #
      # NOTE: For now, all test databases used by the test suite are placed into
      #       the temporary directory.  Each database used by a test should be
      #       cleaned up by that test using the "cleanupDb" procedure, below.







|







613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
          [string range $fileName 0 12] eq "file::memory:"}]
    }

    proc setupDb {
            fileName {mode ""} {dateTimeFormat ""} {dateTimeKind ""} {flags ""}
            {extra ""} {qualify true} {delete true} {uri false} {varName db} } {
      #
      # NOTE: First, see if our caller has requested an in-memory database.
      #
      set isMemory [isMemoryDb $fileName]

      #
      # NOTE: For now, all test databases used by the test suite are placed into
      #       the temporary directory.  Each database used by a test should be
      #       cleaned up by that test using the "cleanupDb" procedure, below.
643
644
645
646
647
648
649
650
651
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
          tputs $::test_channel [appendArgs \
              "==== WARNING: failed to delete database file \"" $fileName \
              "\" during setup, error: " \n\t $error \n]
        }
      }

      #
      # NOTE: Refer to the specified variable (e.g. "db") in the context of the
      #       caller.  The handle to the opened database will be stored there.
      #
      upvar 1 $varName db

      #
      # NOTE: Start building the connection string.  The only required portion
      #       of the connection string is the data source, which contains the
      #       database file name itself.  If the caller wants to use a URI as
      #       the data source, use the FullUri connection string property to
      #       prevent the data source string from being mangled.
      #
      if {$uri} then {
        set connection {FullUri=${fileName}}
      } else {
        set connection {Data Source=${fileName}}
      }

      #
      # NOTE: Since this procedure has no special knowledge of what the default
      #       setting is for the ToFullPath connection string propery, always
      #       add the value we know about to the connection string.
      #
      append connection {;ToFullPath=${qualify}}

      #
      # NOTE: If the caller specified a journal mode, add the necessary portion
      #       of the connection string now.
      #
      if {[string length $mode] > 0} then {
        append connection {;Journal Mode=${mode}}
      }

      #
      # NOTE: If the caller specified a DateTime format, add the necessary
      #       portion of the connection string now.
      #
      if {[string length $dateTimeFormat] > 0} then {
        append connection {;DateTimeFormat=${dateTimeFormat}}
      }

      #
      # NOTE: If the caller specified a DateTimeKind, add the necessary portion
      #       of the connection string now.
      #
      if {[string length $dateTimeKind] > 0} then {
        append connection {;DateTimeKind=${dateTimeKind}}
      }

      #







|







|

















|







|







|







646
647
648
649
650
651
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
          tputs $::test_channel [appendArgs \
              "==== WARNING: failed to delete database file \"" $fileName \
              "\" during setup, error: " \n\t $error \n]
        }
      }

      #
      # NOTE: Refer to the specified variable (e.g. "db") in the context of our
      #       caller.  The handle to the opened database will be stored there.
      #
      upvar 1 $varName db

      #
      # NOTE: Start building the connection string.  The only required portion
      #       of the connection string is the data source, which contains the
      #       database file name itself.  If our caller wants to use a URI as
      #       the data source, use the FullUri connection string property to
      #       prevent the data source string from being mangled.
      #
      if {$uri} then {
        set connection {FullUri=${fileName}}
      } else {
        set connection {Data Source=${fileName}}
      }

      #
      # NOTE: Since this procedure has no special knowledge of what the default
      #       setting is for the ToFullPath connection string propery, always
      #       add the value we know about to the connection string.
      #
      append connection {;ToFullPath=${qualify}}

      #
      # NOTE: If our caller specified a journal mode, add the necessary portion
      #       of the connection string now.
      #
      if {[string length $mode] > 0} then {
        append connection {;Journal Mode=${mode}}
      }

      #
      # NOTE: If our caller specified a DateTime format, add the necessary
      #       portion of the connection string now.
      #
      if {[string length $dateTimeFormat] > 0} then {
        append connection {;DateTimeFormat=${dateTimeFormat}}
      }

      #
      # NOTE: If our caller specified a DateTimeKind, add the necessary portion
      #       of the connection string now.
      #
      if {[string length $dateTimeKind] > 0} then {
        append connection {;DateTimeKind=${dateTimeKind}}
      }

      #
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



























































744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761

762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
        set flags [combineFlags $flags $::connection_flags]

        tputs $::test_channel [appendArgs \
            "---- combined connection flags are: " $flags \n]
      }

      #
      # NOTE: If the caller specified a SQLiteConnectionFlags, add the necessary
      #       portion of the connection string now.
      #
      if {[string length $flags] > 0} then {
        append connection {;Flags=${flags}}
      }

      #
      # NOTE: If the caller specified an extra payload to the connection string,
      #       append it now.
      #
      if {[string length $extra] > 0} then {
        append connection \; $extra
      }

      #
      # NOTE: Open the database connection now, placing the opaque handle value
      #       into the variable specified by the caller.
      #
      set db [sql open -type SQLite [subst $connection]]
    }




























































    proc cleanupDb { fileName {varName db} {collect true} {qualify true}
                     {delete true} } {
      #
      # NOTE: Attempt to force all pending "garbage" objects to be collected,
      #       including SQLite statements and backup objects; this should allow
      #       the underlying database file to be deleted.
      #
      if {$collect && \
          [catch {object invoke GC GetTotalMemory true} error]} then {
        tputs $channel [appendArgs \
            "==== WARNING: failed full garbage collection, error: " \
            \n\t $error \n]
      }

      #
      # NOTE: Refer to the specified variable (e.g. "db") in the context of the
      #       caller.  The handle to the opened database is stored there.

      #
      upvar 1 $varName db

      #
      # NOTE: Close the connection to the database now.  This should allow us to
      #       delete the underlying database file.
      #
      if {[info exists db] && [catch {sql close $db} error]} then {
        #
        # NOTE: We somehow failed to close the database, report why.
        #
        tputs $::test_channel [appendArgs \
            "==== WARNING: failed to close database \"" $db "\", error: " \
            \n\t $error \n]
      }

      #
      # NOTE: First, see if the caller has requested an in-memory database.
      #
      set isMemory [isMemoryDb $fileName]

      #
      # NOTE: Build the full path to the database file name.  For now, all test
      #       database files are stored in the temporary directory.
      #







|







|








|



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
















|
|
>

















|







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
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
        set flags [combineFlags $flags $::connection_flags]

        tputs $::test_channel [appendArgs \
            "---- combined connection flags are: " $flags \n]
      }

      #
      # NOTE: If our caller specified a SQLiteConnectionFlags, add the necessary
      #       portion of the connection string now.
      #
      if {[string length $flags] > 0} then {
        append connection {;Flags=${flags}}
      }

      #
      # NOTE: If our caller specified an extra payload to the connection string,
      #       append it now.
      #
      if {[string length $extra] > 0} then {
        append connection \; $extra
      }

      #
      # NOTE: Open the database connection now, placing the opaque handle value
      #       into the variable specified by our caller.
      #
      set db [sql open -type SQLite [subst $connection]]
    }

    proc getDbConnection { {varName db} } {
      #
      # NOTE: Refer to the specified variable (e.g. "db") in the context of our
      #       caller.  The handle to the database previously opened by [setupDb]
      #       should be stored there.
      #
      upvar 1 $varName db

      #
      # NOTE: This returns the ADO.NET IDbConnection object instance for the
      #       specified databse handle.  Since getting this object relies upon
      #       Eagle internals, great care should be taken to avoid disposing of
      #       this object or otherwise putting it into an invalid state.
      #
      if {[info exists db]} then {
        if {[catch {
                object invoke -flags +NonPublic -objectflags +NoDispose \
                -alias Interpreter.GetActive.connections Item $db} \
                connection] == 0} then {
          #
          # NOTE: Success, return the opaque object handle.
          #
          return $connection
        } else {
          #
          # NOTE: Failure, report why.
          #
          tputs $::test_channel [appendArgs \
              "==== WARNING: failed to get connection handle for database \"" \
              $db "\", error: " \n\t $error \n]
        }
      }
    }

    proc freeDbConnection { {varName connection} } {
      #
      # NOTE: Refer to the specified variable (e.g. "connection") in the context
      #       of our caller.  The opaque object handle for an ADO.NET connection
      #       previously returned by [getDbConnection] should be stored there.
      #
      upvar 1 $varName connection

      #
      # NOTE: Attempt to remove the opaque object handle from the interpreter
      #       now.  This [object dispose] call will not actually dispose of the
      #       underlying object because the +NoDispose flag was set on it during
      #       creation of the opaque object handle.
      #
      if {[info exists connection] && \
          [catch {object dispose $connection} error]} then {
        #
        # NOTE: We somehow failed to remove the handle, report why.
        #
        tputs $::test_channel [appendArgs \
            "==== WARNING: failed to remove connection handle \"" $connection \
            "\", error: " \n\t $error \n]
      }
    }

    proc cleanupDb { fileName {varName db} {collect true} {qualify true}
                     {delete true} } {
      #
      # NOTE: Attempt to force all pending "garbage" objects to be collected,
      #       including SQLite statements and backup objects; this should allow
      #       the underlying database file to be deleted.
      #
      if {$collect && \
          [catch {object invoke GC GetTotalMemory true} error]} then {
        tputs $channel [appendArgs \
            "==== WARNING: failed full garbage collection, error: " \
            \n\t $error \n]
      }

      #
      # NOTE: Refer to the specified variable (e.g. "db") in the context of our
      #       caller.  The handle to the database previously opened by [setupDb]
      #       should be stored there.
      #
      upvar 1 $varName db

      #
      # NOTE: Close the connection to the database now.  This should allow us to
      #       delete the underlying database file.
      #
      if {[info exists db] && [catch {sql close $db} error]} then {
        #
        # NOTE: We somehow failed to close the database, report why.
        #
        tputs $::test_channel [appendArgs \
            "==== WARNING: failed to close database \"" $db "\", error: " \
            \n\t $error \n]
      }

      #
      # NOTE: First, see if our caller has requested an in-memory database.
      #
      set isMemory [isMemoryDb $fileName]

      #
      # NOTE: Build the full path to the database file name.  For now, all test
      #       database files are stored in the temporary directory.
      #
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
        set memory unknown

        if {!$quiet} then {
          tputs $channel [appendArgs $memory \n]
        }
      }

      set result $memory; # NOTE: Return memory in-use to caller.

      if {!$quiet} then {
        tputs $channel "---- maximum memory in use by SQLite... "
      }

      if {[catch {object invoke -flags +NonPublic \
              System.Data.SQLite.UnsafeNativeMethods \







|







965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
        set memory unknown

        if {!$quiet} then {
          tputs $channel [appendArgs $memory \n]
        }
      }

      set result $memory; # NOTE: Return memory in-use to our caller.

      if {!$quiet} then {
        tputs $channel "---- maximum memory in use by SQLite... "
      }

      if {[catch {object invoke -flags +NonPublic \
              System.Data.SQLite.UnsafeNativeMethods \
1068
1069
1070
1071
1072
1073
1074

1075
1076
1077
1078
1079
1080
1081
1082

        #
        # NOTE: Check if the sqlite3_win32_set_directory function is available.
        #
        tputs $::test_channel \
            "---- checking for function sqlite3_win32_set_directory... "


        if {[catch {object invoke -flags +NonPublic \
                System.Data.SQLite.UnsafeNativeMethods \
                sqlite3_win32_set_directory 0 null}] == 0} then {
          #
          # NOTE: Calling the sqlite3_win32_set_directory function does not
          #       cause an exception; therefore, it must be available (i.e.
          #       even though it should return a failure return code in this
          #       case).







>
|







1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146

        #
        # NOTE: Check if the sqlite3_win32_set_directory function is available.
        #
        tputs $::test_channel \
            "---- checking for function sqlite3_win32_set_directory... "

        if {[catch {
                object invoke -flags +NonPublic \
                System.Data.SQLite.UnsafeNativeMethods \
                sqlite3_win32_set_directory 0 null}] == 0} then {
          #
          # NOTE: Calling the sqlite3_win32_set_directory function does not
          #       cause an exception; therefore, it must be available (i.e.
          #       even though it should return a failure return code in this
          #       case).
Changes to Tests/tkt-17045010df.eagle.
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
runSQLiteTestPrologue

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

runTest {test tkt-17045010df-1.1 {EnableExtensions & LoadExtension} -setup {
  setupDb [set fileName tkt-17045010df-1.1.db]
} -body {
  set connection [object invoke -flags +NonPublic -objectflags +NoDispose \
      -alias Interpreter.GetActive.connections get_Item $db]

  lappend result [catchAndReturn {$connection EnableExtensions false}]
  lappend result [catchAndReturn {$connection LoadExtension \
      [getCoreBinaryFileName] interop_test_extension_init}]

  lappend result [catchAndReturn {sql execute -execute scalar $db \
      "SELECT interopTest('test1');"}]







|
<







19
20
21
22
23
24
25
26

27
28
29
30
31
32
33
runSQLiteTestPrologue

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

runTest {test tkt-17045010df-1.1 {EnableExtensions & LoadExtension} -setup {
  setupDb [set fileName tkt-17045010df-1.1.db]
} -body {
  set connection [getDbConnection]


  lappend result [catchAndReturn {$connection EnableExtensions false}]
  lappend result [catchAndReturn {$connection LoadExtension \
      [getCoreBinaryFileName] interop_test_extension_init}]

  lappend result [catchAndReturn {sql execute -execute scalar $db \
      "SELECT interopTest('test1');"}]
42
43
44
45
46
47
48


49
50
51
52
53
54
55
  lappend result [catchAndReturn {sql execute -execute scalar $db \
      "SELECT interopTest('test2');"}]
  lappend result [catchAndReturn {sql execute -execute scalar $db \
      "SELECT interopTest('test2', '5678');"}]

  string map [list \r\n ", "] $result
} -cleanup {


  unset -nocomplain result connection

  cleanupDb $fileName

  unset -nocomplain db fileName
} -constraints \
{eagle monoBug28 defineConstant.System.Data.SQLite.INTEROP_TEST_EXTENSION\







>
>







41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
  lappend result [catchAndReturn {sql execute -execute scalar $db \
      "SELECT interopTest('test2');"}]
  lappend result [catchAndReturn {sql execute -execute scalar $db \
      "SELECT interopTest('test2', '5678');"}]

  string map [list \r\n ", "] $result
} -cleanup {
  freeDbConnection

  unset -nocomplain result connection

  cleanupDb $fileName

  unset -nocomplain db fileName
} -constraints \
{eagle monoBug28 defineConstant.System.Data.SQLite.INTEROP_TEST_EXTENSION\