System.Data.SQLite

Check-in [d1fe039ff7]
Login

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

Overview
Comment:Merge updates from trunk.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | delegateFunction
Files: files | file ages | folders
SHA1: d1fe039ff718884e23c568f0ae4e6634611ee3f3
User & Date: mistachkin 2015-08-15 17:12:56.118
Context
2015-08-15
21:57
Enhance the 'isBuildAvailable' routine in the test suite infrastructure to support architecture names in addition to platform names. check-in: e56653e255 user: mistachkin tags: delegateFunction
17:12
Merge updates from trunk. check-in: d1fe039ff7 user: mistachkin tags: delegateFunction
17:08
Coding style and comment tweaks. check-in: 5c8e02eb62 user: mistachkin tags: trunk
04:04
Remove incorrect comments. check-in: b33115baa1 user: mistachkin tags: delegateFunction
Changes
Side-by-Side Diff Ignore Whitespace Patch
Changes to Doc/Extra/Provider/version.html.
44
45
46
47
48
49
50

51
52
53
54
55
56
57
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58







+







    <div id="mainBody">
    <h1 class="heading">Version History</h1>
    <p><b>1.0.98.0 - August XX, 2015 <font color="red">(release scheduled)</font></b></p>
    <ul>
      <li>Updated to <a href="https://www.sqlite.org/releaselog/3_8_11_1.html">SQLite 3.8.11.1</a>.</li>
      <li>Add full support for Visual Studio 2015 and the .NET Framework 4.6.</li>
      <li>Implement the Substring method for LINQ using the &quot;substr&quot; core SQL function.&nbsp;<b>** Potentially Incompatible Change **</b></li>
      <li>Prevent encrypted connections from being used with the connection pool. Pursuant to <a href="https://system.data.sqlite.org/index.html/info/89d3a159f1">[89d3a159f1]</a>.&nbsp;<b>** Potentially Incompatible Change **</b></li>
      <li>Honor the second argument to Math.Round when using LINQ.&nbsp;<b>** Potentially Incompatible Change **</b></li>
      <li>Honor the pre-existing flags for connections during the Open method. Fix for <a href="https://system.data.sqlite.org/index.html/info/964063da16">[964063da16]</a>.&nbsp;<b>** Potentially Incompatible Change **</b></li>
      <li>Remove errant semi-colons from the SQL used by LINQ to INSERT and then SELECT rows with composite primary keys. Fix for <a href="https://system.data.sqlite.org/index.html/info/9d353b0bd8">[9d353b0bd8]</a>.</li>
      <li>Change the base type for the SQLiteConnectionFlags enumeration to long integer.&nbsp;<b>** Potentially Incompatible Change **</b></li>
      <li>Add extended return codes to the SQLiteErrorCode enumeration. Pursuant to <a href="https://system.data.sqlite.org/index.html/info/71bedaca19">[71bedaca19]</a>.&nbsp;<b>** Potentially Incompatible Change **</b></li>
      <li>Improve exception handling in all native callbacks implemented in the SQLiteConnection class.</li>
      <li>Add Progress event and ProgressOps connection string property to enable raising progress events during long-running queries.</li>
Changes to Externals/Eagle/bin/Eagle.dll.

cannot compute difference between binary files

Changes to Externals/Eagle/bin/EagleShell.exe.

cannot compute difference between binary files

Changes to Externals/Eagle/bin/EagleShell32.exe.

cannot compute difference between binary files

Changes to Externals/Eagle/bin/x64/Spilornis.dll.

cannot compute difference between binary files

Changes to Externals/Eagle/bin/x86/Spilornis.dll.

cannot compute difference between binary files

Changes to Externals/Eagle/lib/Eagle1.0/init.eagle.
2033
2034
2035
2036
2037
2038
2039
2040

2041
2042
2043
2044
2045
2046
2047
2033
2034
2035
2036
2037
2038
2039

2040
2041
2042
2043
2044
2045
2046
2047







-
+







      if {[llength $args] > 2} then {
        error "wrong # args: should be \"parray a ?pattern?\""
      }

      upvar 1 $a array

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

      set names [lsort [eval array names array $args]]
      set maxLength 0

      foreach name $names {
        set length [string length $name]
2154
2155
2156
2157
2158
2159
2160
2161















































































































2162
2163
2164
2165



2166
2167
2168





















2169





2170
2171
2172
2173
2174
2175
2176
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274


2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301

2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313








+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
-
+
+
+



+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+







        # NOTE: Old style test, use [test1] command.
        #
        set command test1
      }

      return [uplevel 1 [list $command $name $description] $args]
    }

    proc isObjectHandle { value } {
      set pattern [string map [list \\ \\\\ \[ \\\[ \] \\\]] $value]
      set objects [info objects $pattern]

      if {[llength $objects] == 1 && [lindex $objects 0] eq $value} then {
        return true
      }

      return false
    }

    proc isManagedType { name } {
      if {[llength [info commands object]] > 0} then {
        if {![isObjectHandle $name]} then {
          if {[catch {
            object members -matchnameonly -nameonly -pattern Equals $name
          } result] == 0 && $result eq "Equals"} then {
            return true
          }
        }
      }

      return false
    }

    proc canGetManagedType { name {varName ""} } {
      if {[llength [info commands object]] > 0} then {
        if {![isObjectHandle $name]} then {
          set cultureInfo [object invoke Interpreter.GetActive CultureInfo]
          set type null

          set code [object invoke -create -alias -flags +NonPublic \
              Value GetType "" $name null null None $cultureInfo type]

          if {[$code ToString] eq "Ok"} then {
            if {[string length $varName] > 0} then {
              upvar 1 $varName typeName
            }

            set typeName [$type AssemblyQualifiedName]

            if {[isManagedType $typeName]} then {
              return true
            }
          }
        }
      }

      return false
    }

    proc unknownObjectInvoke { level name args } {
      #
      # NOTE: This is an [unknown] procedure that attempts to lookup the
      #       name as a CLR type and then attempts to use [object invoke]
      #       with it, merging options and arguments as necessary.
      #
      if {[llength [info commands object]] > 0 && \
          ([isManagedType $name] || [canGetManagedType $name name])} then {
        #
        # NOTE: Get possible options for the [object invoke] sub-command.
        #
        set options [object invoke Utility GetInvokeOptions Invoke]

        #
        # NOTE: Create argument list for the artificial [object invoke]
        #       alias.  This always has two arguments.
        #
        set arguments1 [object create ArgumentList object invoke]

        #
        # NOTE: Create argument list for the entire command being handled.
        #       There may be options right after the command name itself.
        #
        set arguments2 [eval \
            object create ArgumentList [concat [list $name] $args]]

        #
        # NOTE: Setup output arguments needed for the MergeArguments method.
        #
        set arguments3 null; set error null

        #
        # NOTE: Attempt to merge the option and non-option arguments into a
        #       single list of arguments.
        #
        set code [object invoke -alias -flags +NonPublic \
            Interpreter.GetActive MergeArguments $options $arguments1 \
            $arguments2 2 1 false false arguments3 error]

        #
        # NOTE: Was the argument merging process successful?
        #
        if {$code eq "Ok"} then {
          #
          # NOTE: Jump up from our call frame (and optionally that of our
          #       caller) and attempt to invoke the specified static object
          #       method with the final list of merged arguments.
          #
          return [uplevel [expr {$level + 1}] [$arguments3 ToString]]
        } else {
          #
          # NOTE: Failed to merge the arguments, raise an error.
          #
          error [$error ToString]
        }
      }

      continue; # NOTE: Not handled.
    }

    proc unknown { name args } {
      #
      # NOTE: This is a stub unknown procedure that simply produces an
      #       appropriate error message.
      # NOTE: This is an [unknown] procedure that normally produces an
      #       appropriate error message; however, it can optionally try
      #       to invoke a static object method.
      #
      # TODO: Add support for auto-loading packages here in the future?
      #
      if {[hasRuntimeOption unknownObjectInvoke] && \
          [llength [info commands object]] > 0} then {
        #
        # NOTE: In the context of the caller, attempt to invoke a static
        #       object method using the specified arguments (which may
        #       contain variable names).
        #
        if {[catch {
          eval unknownObjectInvoke 1 [list $name] $args
        } result] == 0} then {
          #
          # NOTE: The static object method was invoked successfully.
          #       Return its result.
          #
          return -code ok $result
        } elseif {[string length $result] > 0} then {
          #
          # NOTE: Attempting to invoke the static object method raised
          #       an error.  Re-raise it now.  If no error message was
          #       provided, fallback on the default (below).
          #
      return -code error "invalid command name \"$name\""
          return -code error $result
        }
      }

      return -code error [appendArgs "invalid command name \"" $name \"]
    }

    namespace eval ::tcl::tm {
      #
      # NOTE: Ideally, this procedure should be created in the "::tcl::tm"
      #       namespace.
      #
2193
2194
2195
2196
2197
2198
2199










2200
2201
2202
2203
2204
2205
2206
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353







+
+
+
+
+
+
+
+
+
+








    proc tclLog { string } {
      #
      # NOTE: This should work properly in both Tcl and Eagle.
      #
      catch {puts stderr $string}
    }

    proc makeProcedureFast { name fast } {
      #
      # NOTE: This should work properly in Eagle only.
      #
      catch {
        uplevel 1 [list object invoke -flags +NonPublic \
            Interpreter.GetActive MakeProcedureFast $name $fast]
      }
    }

    proc makeVariableFast { name fast } {
      #
      # NOTE: This should work properly in Eagle only.
      #
      catch {
        uplevel 1 [list object invoke -flags +NonPublic \
2239
2240
2241
2242
2243
2244
2245
















































2246
2247
2248
2249
2250
2251
2252
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







          }
        }
      }

      foreach dir [split [exec -unicode $::env(ComSpec) /u /c dir \
          /ahd /b [appendArgs \" [file nativename $pattern] \"]] \n] {
        set dir [string trim $dir]

        if {[string length $dir] > 0} then {
          set dir [getDirResultPath $pattern $dir]

          if {[lsearch -variable -exact -nocase result $dir] == -1} then {
            lappend result $dir
          }
        }
      }

      return $result
    }

    proc findDirectoriesRecursive { pattern } {
      #
      # NOTE: Block non-Windows platforms since this is Windows specific.
      #
      if {![isWindows]} then {
        error "not supported on this operating system"
      }

      #
      # NOTE: This should work properly in Eagle only.
      #
      set dir ""; set result [list]

      #
      # HACK: Optimize the variable access in this procedure to be
      #       as fast as possible.
      #
      makeVariableFast dir true; makeVariableFast result true

      foreach dir [split [exec -unicode $::env(ComSpec) /u /c dir \
          /ad /s /b [appendArgs \" [file nativename $pattern] \"]] \n] {
        set dir [string trim $dir]

        if {[string length $dir] > 0} then {
          set dir [getDirResultPath $pattern $dir]

          if {[lsearch -variable -exact -nocase result $dir] == -1} then {
            lappend result $dir
          }
        }
      }

      foreach dir [split [exec -unicode $::env(ComSpec) /u /c dir \
          /ahd /s /b [appendArgs \" [file nativename $pattern] \"]] \n] {
        set dir [string trim $dir]

        if {[string length $dir] > 0} then {
          set dir [getDirResultPath $pattern $dir]

          if {[lsearch -variable -exact -nocase result $dir] == -1} then {
            lappend result $dir
          }
2393
2394
2395
2396
2397
2398
2399




































































2400
2401
2402
2403
2404
2405
2406
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







          [file normalize $pattern]]

      eval lappend result [glob -nocomplain -types {d hidden} \
          [file normalize $pattern]]

      return $result
    }

    proc findDirectoriesRecursive { pattern } {
      #
      # NOTE: Block non-Windows platforms since this is Windows specific.
      #
      if {![isWindows]} then {
        error "not supported on this operating system"
      }

      #
      # NOTE: This should work properly in Tcl only.
      #
      set result [list]

      catch {
        foreach dir [split [exec $::env(ComSpec) /c dir /ad /s /b \
            [file nativename $pattern]] \n] {
          set dir [string trim $dir]

          if {[string length $dir] > 0} then {
            set dir [getDirResultPath $pattern $dir]

            #
            # HACK: The -nocase option to [lsearch] is only available
            #       starting with Tcl 8.5.
            #
            if {$::tcl_version >= 8.5} then {
              if {[lsearch -exact -nocase $result $dir] == -1} then {
                lappend result $dir
              }
            } else {
              if {[lsearch -exact [string tolower $result] \
                  [string tolower $dir]] == -1} then {
                lappend result $dir
              }
            }
          }
        }
      }

      catch {
        foreach dir [split [exec $::env(ComSpec) /c dir /ahd /s /b \
            [file nativename $pattern]] \n] {
          set dir [string trim $dir]

          if {[string length $dir] > 0} then {
            set dir [getDirResultPath $pattern $dir]

            #
            # HACK: The -nocase option to [lsearch] is only available
            #       starting with Tcl 8.5.
            #
            if {$::tcl_version >= 8.5} then {
              if {[lsearch -exact -nocase $result $dir] == -1} then {
                lappend result $dir
              }
            } else {
              if {[lsearch -exact [string tolower $result] \
                  [string tolower $dir]] == -1} then {
                lappend result $dir
              }
            }
          }
        }
      }

      return $result
    }

    proc findFiles { pattern } {
      #
      # NOTE: This should work properly in Tcl only.
      #
      eval lappend result [glob -nocomplain -types {f} \
          [file normalize $pattern]]
2428
2429
2430
2431
2432
2433
2434





2435
2436








2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449





2450
2451








2452
2453
2454
2455
2456
2457
2458
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702


2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728


2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743







+
+
+
+
+
-
-
+
+
+
+
+
+
+
+













+
+
+
+
+
-
-
+
+
+
+
+
+
+
+







        foreach fileName [split [exec $::env(ComSpec) /c dir /a-d /s /b \
            [file nativename $pattern]] \n] {
          set fileName [string trim $fileName]

          if {[string length $fileName] > 0} then {
            set fileName [getDirResultPath $pattern $fileName]

            #
            # HACK: The -nocase option to [lsearch] is only available
            #       starting with Tcl 8.5.
            #
            if {$::tcl_version >= 8.5} then {
            if {[lsearch -exact -nocase $result $fileName] == -1} then {
              lappend result $fileName
              if {[lsearch -exact -nocase $result $fileName] == -1} then {
                lappend result $fileName
              }
            } else {
              if {[lsearch -exact [string tolower $result] \
                  [string tolower $fileName]] == -1} then {
                lappend result $fileName
              }
            }
          }
        }
      }

      catch {
        foreach fileName [split [exec $::env(ComSpec) /c dir /ah-d /s /b \
            [file nativename $pattern]] \n] {
          set fileName [string trim $fileName]

          if {[string length $fileName] > 0} then {
            set fileName [getDirResultPath $pattern $fileName]

            #
            # HACK: The -nocase option to [lsearch] is only available
            #       starting with Tcl 8.5.
            #
            if {$::tcl_version >= 8.5} then {
            if {[lsearch -exact -nocase $result $fileName] == -1} then {
              lappend result $fileName
              if {[lsearch -exact -nocase $result $fileName] == -1} then {
                lappend result $fileName
              }
            } else {
              if {[lsearch -exact [string tolower $result] \
                  [string tolower $fileName]] == -1} then {
                lappend result $fileName
              }
            }
          }
        }
      }

      return $result
    }
2510
2511
2512
2513
2514
2515
2516
2517
2518



2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2795
2796
2797
2798
2799
2800
2801


2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817







-
-
+
+
+













        isSameFileName getEnvironmentVariable combineFlags getCompileInfo \
        getPlatformInfo getPluginPath appendArgs lappendArgs \
        getDictionaryValue getColumnValue getRowColumnValue tqputs tqlog \
        readFile readSharedFile writeFile appendFile appendLogFile \
        appendSharedFile appendSharedLogFile readAsciiFile writeAsciiFile \
        readUnicodeFile writeUnicodeFile getDirResultPath addToPath \
        removeFromPath execShell lshuffle ldifference filter map reduce \
        getLengthModifier debug findDirectories findFiles findFilesRecursive \
        exportAndImportPackageCommands] false false
        getLengthModifier debug findDirectories findDirectoriesRecursive \
        findFiles findFilesRecursive exportAndImportPackageCommands] false \
        false

    ###########################################################################
    ############################## END Tcl ONLY ###############################
    ###########################################################################
  }

  #
  # NOTE: Provide the Eagle library package to the interpreter.
  #
  package provide Eagle.Library \
    [expr {[isEagle] ? [info engine PatchLevel] : "1.0"}]
}

Changes to Externals/Eagle/lib/Eagle1.0/shell.eagle.
26
27
28
29
30
31
32












33

34




























































































35
36
37
38
39
40
41
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145







+
+
+
+
+
+
+
+
+
+
+
+

+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







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

    #
    # NOTE: Commands specific to initializing the Eagle interactive shell
    #       environment should be placed here.
    #
    proc help { args } {
      host result Break [appendArgs \
          "\nFor interactive help please use: #help " $args \
          "\nFor commercial support, please use: #support\n"]

      catch {
        object invoke Interpreter.GetActive Host.WriteLine \
            "\nPlease press any key to continue...\n"

        set key null; object invoke Interpreter.GetActive \
            Host.ReadKey true key
      }

      eval lappend command #help $args; debug icommand $command
    }
      error "for interactive help please use: #help $args"

    proc #support {} {
      # <help>
      # Shows the requirements for obtaining commercial support and/or
      # redirects to the appropriate web site using the default browser.
      # </help>

      if {[catch {
        package require Licensing.Enterprise
        set fileName(1) [certificate current]

        if {[string length $fileName(1)] == 0} then {
          error "No certificate file is available."
        }

        set certificate [certificate import -alias $fileName(1)]

        if {[string length $certificate] == 0} then {
          error [appendArgs \
              "No certificate is available, current file \"" \
              $fileName(1) "\" could not be imported."]
        }

        if {[catch {
          certificate flags -hasflags S -hasall -strict $certificate
        } error(2)]} then {
          error [appendArgs \
              "Support is not enabled for certificate \"" \
              [$certificate Id] " - " [$certificate EntityName] \
              "\", the original error message was: \{" $error(2) \
              \}.]
        }

        set uri [$certificate -create -alias Support]

        if {[string length $uri] == 0} then {
          error [appendArgs \
              "No support information found in certificate \"" \
              [$certificate Id] " - " [$certificate EntityName] \".]
        }

        if {[$uri Scheme] ni [list http https]} then {
          error [appendArgs \
              "Support URI scheme \"" [$uri Scheme] \
              "\" in certificate \"" [$certificate Id] " - " \
              [$certificate EntityName] "\" is not supported, " \
              "must be \"http\" or \"https\"."]
        }

        exec -shell [$uri ToString] &
      } error(1)]} then {
        set fileName(2) [file tempname]; set fileData ""

        foreach varName [lsort [info vars]] {
          if {$varName in [list fileData]} then {
            continue
          }

          if {$varName eq "certificate" && \
              [string length $certificate] > 0} then {
            append fileData [appendArgs \n \
                [list array set certificate \
                [$certificate -flags +NonPublic \
                ToDictionary.KeysAndValuesToString \
                null false]]]

            continue
          }

          if {[array exists $varName]} then {
            append fileData [appendArgs \n \
                [list array set $varName [array get $varName]]]
          } else {
            append fileData [appendArgs \n \
                [list set $varName [set $varName]]]
          }
        }

        append fileData \n; writeFile $fileName(2) $fileData
        set ::eagle_shell(errorFileName) $fileName(2)

        error [appendArgs \
            "\n\nIn order to obtain commercial support, at least " \
            "one of the\nfollowing requirements must be met:\n\n" \
            "\t1. Valid, non-expired commercial license agreement\n" \
            "\t   for Eagle Enterprise Edition.\n\n" \
            "\t2. Valid, non-expired commercial support contract\n" \
            "\t   for Eagle Standard Edition.\n\n" \
            "The original error information was saved to the file:\n\n" \
            [string repeat - 60] \n $fileName(2) \n [string repeat - 60] \
            "\n\nPlease provide this file when contacting support."]
      }
    }

    ###########################################################################
    ############################# END Eagle ONLY ##############################
    ###########################################################################
  } else {
    ###########################################################################
Changes to Externals/Eagle/lib/Eagle1.0/test.eagle.
233
234
235
236
237
238
239




240
241
242
243
244
245
246
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250







+
+
+
+







    }
  }

  proc testArrayGet { varName {integer false} } {
    #
    # NOTE: Returns the results of [array get] in a well-defined order.
    #
    if {[string length $varName] == 0} then {
      return [list]
    }

    upvar 1 $varName array

    #
    # NOTE: Build the command that will sort the array names into order.
    #
    set command [list lsort]
    if {$integer} then {lappend command -integer}
477
478
479
480
481
482
483
484






485
486
487
488

489
490
491
492





493
494
495
496
497
498





499
500
501
502
503
504
505
481
482
483
484
485
486
487

488
489
490
491
492
493
494
495
496
497
498




499
500
501
502
503
504
505




506
507
508
509
510
511
512
513
514
515
516
517







-
+
+
+
+
+
+




+
-
-
-
-
+
+
+
+
+


-
-
-
-
+
+
+
+
+







        tputs $::test_channel [appendArgs \
            "---- skipped " $type " file: \"" $fileName \
            "\", it does not exist\n"]
      }
    }
  }

  proc processTestArguments { varName args } {
  proc processTestArguments { varName strict args } {
    #
    # NOTE: Initially, there are no unknown (i.e. unprocessed) arguments.
    #
    set result [list]

    #
    # NOTE: We are going to place the configured options in the variable
    #       identified by the name provided by the caller.
    #
    if {[string length $varName] > 0} then {
    upvar 1 $varName array

    #
    # TODO: Add more support for standard tcltest options here.
      upvar 1 $varName array
    }

    #
    # TODO: Add more support for standard "tcltest" options here.
    #
    set options [list \
        -breakOnLeak -configuration -constraints -exitOnComplete -file \
        -logFile -machine -match -no -notFile -platform -postTest -preTest \
        -postWait -preWait -randomOrder -skip -startFile -stopFile \
        -stopOnFailure -stopOnLeak -suffix -suite -tclsh -threshold]
        -breakOnLeak -configuration -constraints -exitOnComplete \
        -file -logFile -machine -match -no -notFile -platform \
        -postTest -preTest -postWait -preWait -randomOrder -skip \
        -startFile -stopFile -stopOnFailure -stopOnLeak -suffix \
        -suite -tclsh -threshold]

    set length [llength $args]

    for {set index 0} {$index < $length} {incr index} {
      #
      # NOTE: Grab the current list element, which should be the name of
      #       the test option.
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
561
562
563






564
565
566
567
568
569
570
571
572
573
574
575
576

577
578
579
580
581
582
583
547
548
549
550
551
552
553
554
555
556
557



558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573

574
575
576
577
578
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
604
605
606
607
608
609
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
638
639
640
641
642







+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+

+
+


-
+



+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+







+
+
+
+
+
+












-
+







        # NOTE: Is there another list element available for the value?  If
        #       not, it does not conform to the standard command line name
        #       and value pattern.
        #
        if {$index + 1 < $length} then {
          incr index; set value [lindex $args $index]

          if {!$strict && [lsearch -exact $options $value] != -1} then {
            incr index -1; # HACK: Resynchronize with valid test option.
            lappend result [list $name]

          tqputs $::test_channel [appendArgs \
              "---- unknown test option \"" $name "\" with value \"" \
              $value "\" ignored\n"]
            tqputs $::test_channel [appendArgs \
                "---- no value for unknown test option \"" $name \
                "\", ignored, backing up one for test option \"" \
                $value \"...\n]
          } else {
            lappend result [list $name $value]

            tqputs $::test_channel [appendArgs \
                "---- unknown test option \"" $name "\" with value \"" \
                $value "\", ignored\n"]
          }
        } else {
          lappend result [list $name]

          tqputs $::test_channel [appendArgs \
              "---- no value for unknown test option \"" $name \
              "\" ignored\n"]
              "\", ignored\n"]
        }
      } else {
        #
        # NOTE: Is there another list element available for the value?  If
        #       not, it does not conform to the standard command line name
        #       and value pattern.
        #
        if {$index + 1 < $length} then {
          incr index; set value [lindex $args $index]

          if {!$strict && [lsearch -exact $options $value] != -1} then {
            incr index -1; # HACK: Resynchronize with valid test argument.
            lappend result [list $name]

            tqputs $::test_channel [appendArgs \
                "---- no value for unknown argument \"" $name \
                "\", ignored, backing up one for test option \"" \
                $value \"...\n]
          } else {
            lappend result [list $name $value]

            tqputs $::test_channel [appendArgs \
                "---- unknown argument \"" $name "\" with value \"" \
                $value "\", ignored\n"]
          }
        } else {
          #
        # NOTE: This is not an option of *any* kind that we know about.
        #       Ignore it and issue a warning.
        #
        tqputs $::test_channel [appendArgs \
            "---- unknown argument \"" $name "\" ignored\n"]
          # NOTE: This is not an option of *any* kind that we know about.
          #       Ignore it and issue a warning.
          #
          lappend result [list $name]

          tqputs $::test_channel [appendArgs \
              "---- unknown argument \"" $name "\", ignored\n"]
        }
      }
    }

    #
    # NOTE: Now, attempt to flush the test log queue, if available.
    #
    tlog ""

    #
    # NOTE: Return the nested list of unknown arguments, formatted as
    #       name/value pairs, to the caller.
    #
    return $result
  }

  proc getTclShellFileName { automatic kits } {
    #
    # NOTE: Start out with an empty list of candiate Tcl shells.
    #
    set shells [list]

    #
    # NOTE: Check all environment variables we know about that
    #       may contain the path where the Tcl shell is located.
    #
    foreach name [list Eagle_Tcl_Shell Tcl_Shell] {
    foreach name [list Eagle_Tcl_Shell Tcl_Shell EAGLE_TCLSH TCLSH] {
      set value [getEnvironmentVariable $name]

      #
      # TODO: Possibly add a check if the file actually exists
      #       here.
      #
      if {[string length $value] > 0} then {
1292
1293
1294
1295
1296
1297
1298
1299
1300


1301
1302
1303
1304
1305
1306
1307
1351
1352
1353
1354
1355
1356
1357


1358
1359
1360
1361
1362
1363
1364
1365
1366







-
-
+
+







    if {![info exists ::no(epilogue.eagle)] && [info exists ::path]} then {
      unset ::path
    }
  }

  proc hookPuts {} {
    #
    # NOTE: This code was stolen from tcltest and heavily modified to work
    #       with Eagle.
    # NOTE: This code was stolen from "tcltest" and heavily modified to
    #       work with Eagle.
    #
    proc [namespace current]::testPuts { args } {
      switch [llength $args] {
        1 {
          #
          # NOTE: Only the string to be printed is specified (stdout).
          #
2313
2314
2315
2316
2317
2318
2319
2320


















































































































































































































































2321






2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340

2341
2342
2343

2344
2345

2346
2347
2348
2349
2350

2351
2352
2353
2354
2355

2356
2357
2358
2359
2360
2361
2362
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646

2647
2648
2649

2650
2651

2652
2653
2654
2655
2656

2657
2658
2659
2660
2661

2662
2663
2664
2665
2666
2667
2668
2669








+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+


















-
+


-
+

-
+




-
+




-
+







  proc isTestSuiteRunning {} {
    #
    # NOTE: Return non-zero if the test suite appears to be running.
    #
    return [expr {[info exists ::test_suite_running] && \
        $::test_suite_running}]
  }

  proc getTestChannelOrDefault {} {
    if {[info exists ::test_channel]} then {
      return $::test_channel
    }

    return stdout; # TODO: Good default?
  }

  proc checkForAndSetTestPath { whatIf {quiet false} } {
    #
    # NOTE: Everything in this procedure requires access to the file system;
    #       therefore, it cannot be used in a stock "safe" interpreter.
    #
    if {![interp issafe] && ![info exists ::test_path]} then {
      #
      # NOTE: Grab the name of the current script file.  If this is an empty
      #       string, many test path checks will have to be skipped.
      #
      set script [info script]

      #
      # NOTE: Eagle and native Tcl have different requirements and possible
      #       locations for the test path; therefore, handle them separately.
      #
      if {[isEagle]} then {
        #
        # NOTE: Grab the base directory and the library directory.  Without
        #       these, several test path checks will be skipped.
        #
        set library [getTestLibraryDirectory]; set base [info base]

        if {[string length $library] > 0} then {
          #
          # NOTE: Try the source release directory structure.  For this
          #       case, the final test path would be:
          #
          #           $library/../../Library/Tests
          #
          set ::test_path [file normalize [file join [file dirname [file \
              dirname $library]] Library Tests]]

          if {!$quiet} then {
            tqputs [getTestChannelOrDefault] [appendArgs \
                "---- checking #1 for Eagle test path at \"" \
                $::test_path \"...\n]
          }
        }

        if {[string length $base] > 0 && ($whatIf || \
            ![info exists ::test_path] || ![file exists $::test_path] || \
            ![file isdirectory $::test_path])} then {
          #
          # NOTE: Try the source release directory structure again; this
          #       time, assume only the embedded script library was used.
          #       For this case, the final test path would be:
          #
          #           $base/Library/Tests
          #
          set ::test_path [file normalize [file join $base Library Tests]]

          if {!$quiet} then {
            tqputs [getTestChannelOrDefault] [appendArgs \
                "---- checking #2 for Eagle test path at \"" \
                $::test_path \"...\n]
          }
        }

        if {[string length $script] > 0 && ($whatIf || \
            ![info exists ::test_path] || ![file exists $::test_path] || \
            ![file isdirectory $::test_path])} then {
          #
          # NOTE: Try for the test package directory.  For this case, the
          #       final test path would be:
          #
          #           $script/../Test1.0
          #
          set ::test_path [file normalize [file join [file dirname [file \
              dirname $script]] [appendArgs Test [info engine Version]]]]

          if {!$quiet} then {
            tqputs [getTestChannelOrDefault] [appendArgs \
                "---- checking #3 for Eagle test path at \"" \
                $::test_path \"...\n]
          }
        }

        if {[string length $base] > 0 && ($whatIf || \
            ![info exists ::test_path] || ![file exists $::test_path] || \
            ![file isdirectory $::test_path])} then {
          #
          # NOTE: Try for the test package directory again; this time, use
          #       the base path and assume the source release directory
          #       structure.  For this case, the final test path would be:
          #
          #           $base/lib/Test1.0
          #
          set ::test_path [file normalize [file join $base lib [appendArgs \
              Test [info engine Version]]]]

          if {!$quiet} then {
            tqputs [getTestChannelOrDefault] [appendArgs \
                "---- checking #4 for Eagle test path at \"" \
                $::test_path \"...\n]
          }
        }

        if {[string length $base] > 0 && ($whatIf || \
            ![info exists ::test_path] || ![file exists $::test_path] || \
            ![file isdirectory $::test_path])} then {
          #
          # NOTE: Try for the test package directory again; this time, use
          #       the base path.  For this case, the final test path would
          #       be:
          #
          #           $base/Test1.0
          #
          set ::test_path [file normalize [file join $base [appendArgs \
              Test [info engine Version]]]]

          if {!$quiet} then {
            tqputs [getTestChannelOrDefault] [appendArgs \
                "---- checking #5 for Eagle test path at \"" \
                $::test_path \"...\n]
          }
        }

        if {[string length $library] > 0 && ($whatIf || \
            ![info exists ::test_path] || ![file exists $::test_path] || \
            ![file isdirectory $::test_path])} then {
          #
          # NOTE: This must be a binary release, no "Library" directory
          #       then.  Also, binary releases have an upper-case "Tests"
          #       directory name that originates from the "update.bat"
          #       tool.  This must match the casing used in "update.bat".
          #       For this case, the final test path would be:
          #
          #           $library/../../Tests
          #
          set ::test_path [file normalize [file join [file dirname [file \
              dirname $library]] Tests]]

          if {!$quiet} then {
            tqputs [getTestChannelOrDefault] [appendArgs \
                "---- checking #6 for Eagle test path at \"" \
                $::test_path \"...\n]
          }
        }

        if {[string length $base] > 0 && ($whatIf || \
            ![info exists ::test_path] || ![file exists $::test_path] || \
            ![file isdirectory $::test_path])} then {
          #
          # NOTE: Fallback to using the base directory and checking for a
          #       "Tests" directory beneath it.  For this case, the final
          #       test path would be:
          #
          #           $base/Tests
          #
          set ::test_path [file normalize [file join $base Tests]]

          if {!$quiet} then {
            tqputs [getTestChannelOrDefault] [appendArgs \
                "---- checking #7 for Eagle test path at \"" \
                $::test_path \"...\n]
          }
        }

        if {!$quiet} then {
          tqputs [getTestChannelOrDefault] [appendArgs \
              "---- final Eagle test path is \"" \
              [expr {[info exists ::test_path] ? \
              $::test_path : "<none>"}] \"\n]
        }
      } else {
        if {[string length $script] > 0} then {
          #
          # NOTE: Try the source release directory structure.  For this
          #       case, the final test path would be:
          #
          #           $script/../../Library/Tests
          #
          set ::test_path [file normalize [file join [file dirname [file \
              dirname [file dirname $script]]] Library Tests]]

          if {!$quiet} then {
            tqputs [getTestChannelOrDefault] [appendArgs \
                "---- checking #1 for Tcl test path at \"" \
                $::test_path \"...\n]
          }
        }

        if {[string length $script] > 0 && ($whatIf || \
            ![info exists ::test_path] || ![file exists $::test_path] || \
            ![file isdirectory $::test_path])} then {
          #
          # NOTE: Try for the test package directory.  For this case, the
          #       final test path would be:
          #
          #           $script/../Test1.0
          #
          set ::test_path [file normalize [file join [file dirname [file \
              dirname $script]] Test1.0]]

          if {!$quiet} then {
            tqputs [getTestChannelOrDefault] [appendArgs \
                "---- checking #2 for Tcl test path at \"" \
                $::test_path \"...\n]
          }
        }

        if {[string length $script] > 0 && ($whatIf || \
            ![info exists ::test_path] || ![file exists $::test_path] || \
            ![file isdirectory $::test_path])} then {
          #
          # NOTE: This must be a binary release, no "Library" directory
          #       then.  Also, binary releases have an upper-case "Tests"
          #       directory name that originates from the "update.bat"
          #       tool.  This must match the casing used in "update.bat".
          #       For this case, the final test path would be:
          #
          #           $script/../../Tests
          #
          set ::test_path [file normalize [file join [file dirname [file \
              dirname [file dirname $script]]] Tests]]

          if {!$quiet} then {
            tqputs [getTestChannelOrDefault] [appendArgs \
                "---- checking #3 for Tcl test path at \"" \
                $::test_path \"...\n]
          }
        }

        if {!$quiet} then {
          tqputs [getTestChannelOrDefault] [appendArgs \
              "---- final Tcl test path is \"" \
              [expr {[info exists ::test_path] ? \
              $::test_path : "<none>"}] \"\n]
        }
      }
    }
  }

  proc configureTcltest { match skip constraints imports force } {
    #
    # NOTE: Eagle and native Tcl have different configuration requirements
    #       for the "tcltest" package.  For Eagle, the necessary testing
    #       functionality is built-in.  In native Tcl, the package must be
    #       loaded now and that cannot be done in a "safe" interpreter.
    #
    if {[isEagle]} then {
      #
      # HACK: Flag the "test" and "runTest" script library procedures so
      #       that they use the script location of their caller and not
      #       their own.
      #
      # BUGBUG: Even this does not yet fix the script location issues in
      #         the test suite:
      #
      #         debug procedureflags test +ScriptLocation
      #         debug procedureflags runTest +ScriptLocation
      #
      # NOTE: Setup the necessary compatibility shims for the test suite.
      #
      namespace eval ::tcltest {}; # HACK: Force namespace creation now.
      setupTestShims true [expr {![isTestSuiteRunning]}]

      #
      # NOTE: Fake having the tcltest package.
      # NOTE: Fake having the package as the functionality is built-in.
      #
      package provide tcltest 2.2.10; # Tcl 8.4
    } else {
    } elseif {![interp issafe]} then {
      #
      # NOTE: Attempt to detect if the tcltest package is already loaded.
      # NOTE: Attempt to detect if the package is already loaded.
      #
      set loaded [expr {[catch {package present tcltest}] == 0}]

      #
      # NOTE: Always attempt to load the tcltest package.
      # NOTE: Always attempt to load the package.
      #
      package require tcltest

      #
      # NOTE: Configure tcltest for our use (only when it was not loaded).
      # NOTE: Configure it for our use (only when it was not loaded).
      #
      if {!$loaded} then {
        ::tcltest::configure -verbose bpste
      }

      #
      # NOTE: We need to copy the Eagle test names to match over to Tcl.
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2834
2835
2836
2837
2838
2839
2840








2841
2842
2843
2844
2845
2846
2847







-
-
-
-
-
-
-
-








        if {[info exists test_flags(-constraints)]} then {
            eval lappend eagle_tests(Constraints) $test_flags(-constraints)
        }
      }
    }

    proc getTestChannelOrDefault {} {
      if {[info exists ::test_channel]} then {
        return $::test_channel
      }

      return stdout; # TODO: Good default?
    }

    proc setupTestShims { setup {quiet false} } {
      if {$setup} then {
        #
        # HACK: Compatibility shim(s) for use with various tests in the Tcl
        #       test suite.  Make sure these commands do not already exist
        #       prior to attempt to adding them.
        #
3088
3089
3090
3091
3092
3093
3094
3095


3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106









3107
3108
3109
3110
3111
3112
3113






3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126

3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138


3139
3140
3141

3142
3143
3144
3145
3146
3147
3148
3149
3150
3151

3152
3153
3154
3155
3156
3157
3158
3159
3160


3161
3162
3163
3164

3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176

3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190

3191
3192
3193
3194

3195
3196
3197
3198
3199
3200
3201
3202
3203
3204

3205
3206

3207
3208
3209
3210
3211
3212
3213
3387
3388
3389
3390
3391
3392
3393

3394
3395
3396










3397
3398
3399
3400
3401
3402
3403
3404
3405
3406






3407
3408
3409
3410
3411
3412













3413












3414
3415



3416










3417









3418
3419




3420












3421














3422
3423



3424










3425


3426
3427
3428
3429
3430
3431
3432
3433







-
+
+

-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+

-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
-
-
+







      object unimport -importpattern System.Windows.Forms.Layout
      object unimport -importpattern System.Windows.Forms.PropertyGridInternal
      object unimport -importpattern System.Windows.Forms.VisualStyles
    }

    proc getTestLibraryDirectory {} {
      #
      # NOTE: First, query the location of the script library.
      # NOTE: First, query the location of the script library.  This will
      #       not work right in a "safe" interpreter.
      #
      set result [info library]

      #
      # NOTE: Next, If the script library is embedded within the core
      #       library itself (i.e. the script library location refers
      #       to a file, not a directory), strip off the file name.
      #
      if {[file exists $result] && [file isfile $result]} then {
        set result [file dirname $result]
      }
      if {[catch {info library} result] == 0} then {
        #
        # NOTE: Next, If the script library is embedded within the core
        #       library itself (i.e. the script library location refers
        #       to a file, not a directory), strip off the file name.
        #
        if {[file exists $result] && [file isfile $result]} then {
          set result [file dirname $result]
        }

      #
      # NOTE: Finally, return the resulting script library directory.
      #
      return $result
    }

        #
        # NOTE: Finally, return the resulting script library directory.
        #
        return $result
      }

    #
    # NOTE: Setup the test path relative to the library path.
    #
    if {![interp issafe] && ![info exists ::test_path]} then {
      #
      # NOTE: Try the source release directory structure.  For this case,
      #       the final test path would be:
      #
      #           $library/../../Library/Tests
      #
      set ::test_path [file join [file normalize [file dirname \
          [file dirname [getTestLibraryDirectory]]]] Library Tests]

      return ""
      if {![file exists $::test_path] || \
          ![file isdirectory $::test_path]} then {
        #
        # NOTE: Try the source release directory structure again; this time,
        #       assume only the embedded script library was used.  For this
        #       case, the final test path would be:
        #
        #           $base/Library/Tests
        #
        set ::test_path [file join [info base] Library Tests]
      }

    }

      if {![file exists $::test_path] || \
          ![file isdirectory $::test_path]} then {
        #
    #
        # NOTE: Try for the test package directory.  For this case, the final
        #       test path would be:
        #
        #           $script/../Test1.0
        #
        set ::test_path [file join [file normalize [file dirname \
            [file dirname [info script]]]] [appendArgs Test \
            [info engine Version]]]
      }

    # NOTE: Check for the test path in the various well-known locations
      if {![file exists $::test_path] || \
          ![file isdirectory $::test_path]} then {
        #
        # NOTE: Try for the test package directory again; this time, use the
        #       base path and assume the source release directory structure.
        #       For this case, the final test path would be:
        #
        #           $base/lib/Test1.0
        #
    #       and set the associated variable.
    #
        set ::test_path [file join [info base] lib [appendArgs Test \
            [info engine Version]]]
      }

    if {![info exists ::no(checkForAndSetTestPath)]} then {
      if {![file exists $::test_path] || \
          ![file isdirectory $::test_path]} then {
        #
        # NOTE: Try for the test package directory again; this time, use the
        #       base path.  For this case, the final test path would be:
        #
        #           $base/Test1.0
        #
        set ::test_path [file join [info base] [appendArgs Test \
            [info engine Version]]]
      }

      checkForAndSetTestPath false [expr {![isTestSuiteRunning]}]
      if {![file exists $::test_path] || \
          ![file isdirectory $::test_path]} then {
        #
        # NOTE: This must be a binary release, no "Library" directory then.
        #       Also, binary releases have an upper-case "Tests" directory
        #       name that originates from the "update.bat" tool.  This must
        #       match the casing used in "update.bat".  For this case, the
        #       final test path would be:
        #
        #           $library/../../Tests
        #
        set ::test_path [file join [file normalize [file dirname \
            [file dirname [getTestLibraryDirectory]]]] Tests]
      }
    }

      if {![file exists $::test_path] || \
          ![file isdirectory $::test_path]} then {
        #
    #
        # NOTE: Fallback to using the base directory and checking for a
        #       "Tests" directory beneath it.  For this case, the final
        #       test path would be:
        #
        #           $base/Tests
        #
        set ::test_path [file join [info base] Tests]
      }
    }

    # NOTE: Fake loading and configuring the "tcltest" package unless we
    #
    # NOTE: Fake having the tcltest package unless we are prevented.
    #       are prevented.
    #
    if {![info exists ::no(configureTcltest)]} then {
      configureTcltest [list] [list] [list] [list] false
    }

    ###########################################################################
    ############################# END Eagle ONLY ##############################
3235
3236
3237
3238
3239
3240
3241
3242

3243
3244
3245
3246
3247
3248
3249
3250

3251
3252
3253

3254
3255
3256
3257

3258
3259

3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272



3273
3274

3275
3276

3277
3278
3279
3280
3281
3282
3283
3455
3456
3457
3458
3459
3460
3461

3462








3463



3464




3465


3466













3467
3468
3469


3470
3471

3472
3473
3474
3475
3476
3477
3478
3479







-
+
-
-
-
-
-
-
-
-
+
-
-
-
+
-
-
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
+

-
+







            double($::tcltest::numTests(Total)))}]
      }

      return 0; # no tests were run, etc.
    }

    #
    # NOTE: Setup the test path relative to the path of this file.
    # NOTE: Check for the test path in the various well-known locations
    #
    if {![interp issafe] && ![info exists ::test_path]} then {
      #
      # NOTE: Try the source release directory structure.
      #
      set ::test_path [file join [file normalize [file dirname \
          [file dirname [file dirname [info script]]]]] Library Tests]

    #       and set the associated variable.
      if {![file exists $::test_path] || \
          ![file isdirectory $::test_path]} then {
        #
    #
        # NOTE: Try for the test package directory.
        #
        set ::test_path [file join [file normalize [file dirname \
            [file dirname [info script]]]] Test1.0]
    if {![info exists ::no(checkForAndSetTestPath)]} then {
      }

      checkForAndSetTestPath false [expr {![isTestSuiteRunning]}]
      if {![file exists $::test_path] || \
          ![file isdirectory $::test_path]} then {
        #
        # NOTE: This must be a binary release, no "Library" directory then.
        #       Also, binary releases have an upper-case "Tests" directory
        #       name that originates from the "update.bat" tool.  This must
        #       match the casing used in "update.bat".
        #
        set ::test_path [file join [file normalize [file dirname \
            [file dirname [file dirname [info script]]]]] Tests]
      }
    }

    }

    #
    #
    # NOTE: Load and configure the tcltest package unless we are prevented.
    # NOTE: Load and configure the "tcltest" package unless we are prevented.
    #
    if {![interp issafe] && ![info exists ::no(configureTcltest)]} then {
    if {![info exists ::no(configureTcltest)]} then {
      configureTcltest [list] [list] [list] [list test testConstraint] false
    }

    #
    # NOTE: We need several of our test related commands in the global
    #       namespace as well.
    #
3292
3293
3294
3295
3296
3297
3298
3299
3300


3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3488
3489
3490
3491
3492
3493
3494


3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509







-
-
+
+













        getTestSuffix testExec testClrExec execTestShell isRandomOrder \
        isBreakOnLeak isStopOnFailure isStopOnLeak isExitOnComplete \
        returnInfoScript runTestPrologue runTestEpilogue hookPuts unhookPuts \
        runTest testDebugBreak testArrayGet testShim tsource \
        recordTestStatistics reportTestStatistics formatList formatListAsDict \
        pathToRegexp inverseLsearchGlob removePathFromFileNames formatDecimal \
        clearTestPercent reportTestPercent runAllTests isTestSuiteRunning \
        configureTcltest machineToPlatform getPassPercentage \
        getSkipPercentage] false false
        getTestChannelOrDefault checkForAndSetTestPath configureTcltest \
        machineToPlatform getPassPercentage getSkipPercentage] false false

    ###########################################################################
    ############################## END Tcl ONLY ###############################
    ###########################################################################
  }

  #
  # NOTE: Provide the Eagle test package to the interpreter.
  #
  package provide Eagle.Test \
    [expr {[isEagle] ? [info engine PatchLevel] : "1.0"}]
}

Changes to Externals/Eagle/lib/Test1.0/all.eagle.
38
39
40
41
42
43
44





45
46



47
48
49

50
51
52
53
54
55
56
57
58
59


60
61
62
63
64
65
66
67
68
69
70
71

38
39
40
41
42
43
44
45
46
47
48
49
50

51
52
53
54
55

56
57
58
59
60
61
62
63
64


65
66
67
68
69
70
71
72
73
74
75
76
77

78







+
+
+
+
+

-
+
+
+


-
+








-
-
+
+











-
+
#
#       When using the above code snippet, the following code snippet may also
#       be used at the very end of the corresponding "all.eagle" file instead
#       of evaluating the "epilogue.eagle" file directly:
#
#           runTestEpilogue
#
if {![info exists test_all_path]} then {
  set test_all_path \
      [file normalize [file dirname [info script]]]
}

if {![info exists test_path]} then {
  set test_path [file normalize [file dirname [info script]]]
  set test_path [file normalize [file join \
      [file dirname [file dirname $test_all_path]] \
      Library Tests]]
}

source [file join $test_path prologue.eagle]
source [file join $test_all_path prologue.eagle]

set no(prologue.eagle) true
set no(epilogue.eagle) true

set test_time [time {
  runAllTests $test_channel $test_path \
      [getTestFiles [list $test_path] $test_flags(-file) \
          $test_flags(-notFile)] \
      [list [file tail [info script]] *.tcl pkgIndex.eagle \
          constraints.eagle epilogue.eagle prologue.eagle] \
      [list [file tail [info script]] *.tcl \
          epilogue.eagle prologue.eagle] \
      $test_flags(-startFile) $test_flags(-stopFile)
}]

tputs $test_channel [appendArgs "---- all tests completed in " $test_time \n]
unset test_time

unset no(epilogue.eagle)
unset no(prologue.eagle)

if {[array size no] == 0} then {unset no}

source [file join $test_path epilogue.eagle]
source [file join $test_all_path epilogue.eagle]
Changes to Externals/Eagle/lib/Test1.0/constraints.eagle.
52
53
54
55
56
57
58
59


60
61
62
63
64
65
66
52
53
54
55
56
57
58

59
60
61
62
63
64
65
66
67







-
+
+







    #
    # NOTE: This job of this procedure is to return the list of "known"
    #       versions of Mono supported by the test suite infrastructure.
    #
    return [list \
        [list 2 0] [list 2 2] [list 2 4] [list 2 6] [list 2 8] [list 2 10] \
        [list 2 11] [list 2 12] [list 3 0] [list 3 1] [list 3 2] [list 3 3] \
        [list 3 4] [list 3 5] [list 3 6] [list 3 8] [list 3 10] [list 3 12]]
        [list 3 4] [list 3 5] [list 3 6] [list 3 8] [list 3 10] [list 3 12] \
        [list 4 0]]
  }

  #
  # NOTE: This procedure was adapted from the one listed on the Tcl Wiki page
  #       at "http://wiki.tcl.tk/43".  It is only intended to be used on very
  #       small lists because of its heavy use of recursion and complexity on
  #       the order of O(N!).
99
100
101
102
103
104
105
106

107
108
109
110
111
112
113
100
101
102
103
104
105
106

107
108
109
110
111
112
113
114







-
+








    #
    # NOTE: If this Eagle version lacks [interp readylimit] -OR- it has
    #       the default value (i.e. it always fully checks readiness),
    #       return true.
    #
    return [expr {
      [catch {interp readylimit {}} readylimit] != 0 || $readylimit == 0
      [catch {interp readylimit {}} readylimit] || $readylimit == 0
    }]
  }

  #
  # NOTE: This procedure should return non-zero if the "whoami" command may
  #       be executed by the test suite infrastructure outside the context
  #       of any specific tests.
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
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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356

357


358
359
360
361
362
363
364







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+










-
+
-
-







        # NOTE: If the test suite file exists, add it to the list of file
        #       names to process.
        #
        if {[file exists $fileName]} then {
          lappend fileNames $fileName
        }
      }

      #
      # TODO: If additional test suite files are added within the base
      #       package path, add them here as well.
      #
      foreach fileNameOnly [list \
          all.eagle constraints.eagle epilogue.eagle pkgIndex.eagle \
          pkgIndex.tcl prologue.eagle] {
        #
        # NOTE: First, check if the file resides in the Eagle-specific
        #       package sub-directory.  Failing that, fallback to using
        #       the base package path itself.
        #
        set fileName [file join \
            $::test_package_path Test1.0 $fileNameOnly]

        if {![file exists $fileName]} then {
          set fileName [file join $::test_package_path $fileNameOnly]
        }

        #
        # NOTE: If the test suite file exists, add it to the list of file
        #       names to process.
        #
        if {[file exists $fileName]} then {
          lappend fileNames $fileName
        }
      }
    }

    #
    # NOTE: Check if the test package path is available.
    #
    if {[info exists ::test_path]} then {
      #
      # TODO: If additional test suite files are added within the test
      #       package path, add them here as well.
      #
      foreach fileNameOnly [list \
      foreach fileNameOnly [list all.eagle epilogue.eagle prologue.eagle] {
          all.eagle constraints.eagle epilogue.eagle pkgIndex.eagle \
          pkgIndex.tcl prologue.eagle] {
        #
        # NOTE: Check if the file resides in the test package directory.
        #
        set fileName [file join $::test_path $fileNameOnly]

        #
        # NOTE: If the test suite file exists, add it to the list of file
1582
1583
1584
1585
1586
1587
1588
















1589
1590
1591
1592
1593
1594
1595
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







      addConstraint timeIntensive

      tputs $channel yes\n
    } else {
      tputs $channel no\n
    }
  }

  proc checkForFullTest { channel } {
    tputs $channel "---- checking for full testing... "

    #
    # NOTE: Are we allowed to do full testing (i.e. to run rarely
    #       needed tests)?
    #
    if {![info exists ::no(fullTest)]} then {
      addConstraint fullTest

      tputs $channel yes\n
    } else {
      tputs $channel no\n
    }
  }

  proc checkForMemoryIntensive { channel } {
    tputs $channel "---- checking for memory intensive testing... "

    #
    # NOTE: Are we allowed to do memory intensive testing?
    #
1945
1946
1947
1948
1949
1950
1951














































































1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970

1971
1972
1973
1974
1975
1976
1977
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090

2091
2092
2093
2094
2095
2096
2097
2098







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


















-
+







        addConstraint strongName

        tputs $channel yes\n
      } else {
        tputs $channel no\n
      }
    }

    proc checkForStrongNameKey { channel } {
      tputs $channel "---- checking for strong name key... "

      if {[catch {info engine PublicKeyToken} publicKeyToken] == 0 && \
          [string length $publicKeyToken] > 0} then {
        #
        # NOTE: Add a test constraint for this specific strong name key.
        #
        addConstraint [appendArgs strongName. $publicKeyToken]

        #
        # NOTE: Show the strong name key that we found.
        #
        tputs $channel [appendArgs "yes (" $publicKeyToken ")\n"]

        #
        # BUGBUG: Tcl 8.4 does not seem to like this expression because it
        #         contains the "ni" operator added in Tcl 8.5 (and Tcl 8.4
        #         tries to compile it even though it will only be evaluated
        #         in Eagle).
        #
        set expr {$publicKeyToken ni \
            "29c6297630be05eb 1e22ec67879739a2 358030063a832bc3"}

        if {[expr $expr]} then {
          #
          # NOTE: The Eagle core library is strong name signed with a key that
          #       is not official.  This is also not an error, per se; however,
          #       it may cause some tests to fail and it should be reported to
          #       the user and noted in the test suite log file.
          #
          addConstraint strongName.unofficial

          #
          # NOTE: Unless forbidden, issue and log a warning.
          #
          if {![info exists no(warningForStrongNameKey)] && \
              ![haveConstraint quiet]} then {
            tputs $channel [appendArgs \
                "==== WARNING: unofficial Eagle strong name signature " \
                "detected: " $publicKeyToken \n]
          }
        } else {
          #
          # NOTE: Several tests require one of the official strong name keys to
          #       be used in order for them to pass.
          #
          addConstraint strongName.official

          tputs $channel [appendArgs \
              "---- official Eagle strong name signature detected: " \
              $publicKeyToken \n]
        }
      } else {
        #
        # NOTE: The Eagle core library is not signed with a strong name key.
        #       This is not an error, per se; however, it may cause selected
        #       tests to fail and it should be reported to the user and noted
        #       in the test suite log file.
        #
        addConstraint strongName.none

        #
        # NOTE: Show that we did not find a strong name key.
        #
        tputs $channel no\n

        #
        # NOTE: Unless forbidden, issue and log a warning.
        #
        if {![info exists no(warningForStrongNameKey)] && \
            ![haveConstraint quiet]} then {
          tputs $channel \
              "==== WARNING: no Eagle strong name signature detected...\n"
        }
      }
    }

    proc checkForCertificate { channel } {
      tputs $channel "---- checking for certificate... "

      if {[catch {
        object invoke Interpreter.GetActive GetCertificate
      } certificate] == 0 && [string length $certificate] > 0} then {
        #
        # NOTE: Yes, it appears that the core library was signed with a
        #       code-signing certificate.
        #
        addConstraint certificate

        #
        # NOTE: Attempt to query the subject from the certificate.
        #
        if {[catch {
          object invoke $certificate Subject
        } subject] != 0 || [string length $subject] == 0} then {
        } subject] || [string length $subject] == 0} then {
          #
          # TODO: No certificate subject, better handling here?
          #
          set subject unknown
        }

        tputs $channel [appendArgs "yes (" $subject ")\n"]
2065
2066
2067
2068
2069
2070
2071
2072

2073
2074
2075
2076

2077
2078
2079
2080
2081
2082
2083
2186
2187
2188
2189
2190
2191
2192

2193
2194
2195
2196

2197
2198
2199
2200
2201
2202
2203
2204







-
+



-
+







      tputs $channel "---- checking for default application domain... "

      if {[catch {
        object invoke AppDomain CurrentDomain
      } appDomain] == 0 && [string length $appDomain] > 0} then {
        if {[catch {
          object invoke $appDomain IsDefaultAppDomain
        } default] != 0 || [string length $default] == 0} then {
        } default] || [string length $default] == 0} then {
          set default false
        }

        if {[catch {object invoke $appDomain Id} id] != 0 || \
        if {[catch {object invoke $appDomain Id} id] || \
            [string length $id] == 0} then {
          set id unknown
        }

        if {$default} then {
          addConstraint defaultAppDomain

2372
2373
2374
2375
2376
2377
2378















































2379
2380
2381
2382
2383
2384
2385
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








        tputs $channel [appendArgs $result ", " $::tcl_platform(processBits) \
            -bit " " $::tcl_platform(machine) \n]
      } else {
        tputs $channel "no, unknown\n"
      }
    }

    proc checkForTestCallStack { channel } {
      tputs $channel "---- checking for test call stack... "

      #
      # NOTE: Search for a call frame with associated arguments.
      #       At this point, there must be at least one such call
      #       frame (this one).  Therefore, this loop will always
      #       terminate.
      #
      set index 0; set arguments [list]
      set script {info level [info level]}

      while {1} {
        set level [appendArgs ## $index]

        if {[catch {uplevel $level $script} arguments] == 0} then {
          break
        }

        incr index
      }

      #
      # NOTE: Grab the command name from the arguments, if any.
      #
      set command [expr {
        [llength $arguments] > 0 ? [lindex $arguments 0] : ""
      }]

      #
      # HACK: Make sure the call stack does not end up confusing
      #       the tests that rely on absolute call frames.
      #
      if {$command in [list checkForTestCallStack]} then {
        addConstraint testCallStack

        tputs $channel [appendArgs "yes (\"" $command "\")\n"]

        #
        # NOTE: We are done here, return now.
        #
        return
      }

      tputs $channel [appendArgs "no (\"" $command "\")\n"]
    }

    proc checkForGarudaDll { channel } {
      #
      # NOTE: Skip automatic Tcl shell machine detection if we are not
      #       allowed to execute external commands.
      #
      if {[canExecTclShell]} then {
3218
3219
3220
3221
3222
3223
3224

















3225
3226


3227
3228
3229
3230
3231
3232
3233
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409


3410
3411
3412
3413
3414
3415
3416
3417
3418







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+







          return
        }
      }

      tputs $channel no\n
    }

    proc getFrameworkSetup46Value {} {
      #
      # NOTE: Check if we are running on Windows 10 or later.
      #
      if {[isWindows] && $::tcl_platform(osVersion) >= 10.0} then {
        #
        # NOTE: We are running on Windows 10, return the special value.
        #
        return 393295
      }

      #
      # NOTE: We are not running on Windows 10, return the normal value.
      #
      return 393297
    }

    proc checkForNetFx45 { channel } {
      tputs $channel "---- checking for .NET Framework 4.5... "
    proc checkForNetFx4x { channel } {
      tputs $channel "---- checking for .NET Framework 4.x... "

      #
      # NOTE: Platform must be Windows for this constraint to even be
      #       checked (i.e. we require the registry).
      #
      if {[isWindows]} then {
        #
3260
3261
3262
3263
3264
3265
3266
3267
3268


3269
3270
3271

3272
3273



3274
3275
3276
3277
3278

3279
3280
3281
3282
3283
3284
3285
3445
3446
3447
3448
3449
3450
3451


3452
3453



3454
3455

3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471







-
-
+
+
-
-
-
+

-
+
+
+





+







          #
          # NOTE: If the "release" value is greater than or equal to 378758
          #       (or 378675 for Windows 8.1), then the .NET Framework 4.5.1
          #       is installed.  However, if the "release" value is also
          #       greater than or equal to 379893, then the .NET Framework
          #       4.5.2 is installed, which is an in-place upgrade to 4.5.1
          #       (and 4.5).  If the "release" value is also greater than or
          #       equal to 393246, then the .NET Framework 4.6 is installed,
          #       which is an in-place upgrade to 4.5.x.
          #       equal to 393297 (393295 on Windows 10), then the .NET
          #       Framework 4.6 is installed, which is an in-place upgrade
          #
          # TODO: Change the value 393246 when the .NET Framework 4.6 goes
          #       final.
          #       to 4.5.x.
          #
          if {$release >= 393246} then {
          if {$release >= [getFrameworkSetup46Value]} then {
            addConstraint dotNet451OrHigher
            addConstraint dotNet452OrHigher
            addConstraint dotNet46
            addConstraint dotNet46OrHigher

            set version 4.6
          } elseif {$release >= 379893} then {
            addConstraint dotNet451OrHigher
            addConstraint dotNet452
            addConstraint dotNet452OrHigher

            set version 4.5.2
          } elseif {$release >= 378675} then {
            addConstraint dotNet451
            addConstraint dotNet451OrHigher
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530




3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3706
3707
3708
3709
3710
3711
3712




3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729







-
-
-
-
+
+
+
+













        checkForGaruda checkForShell checkForDebug checkForTk checkForVersion \
        checkForCommand checkForNamespaces checkForTestExec \
        checkForTestMachine checkForTestPlatform checkForTestConfiguration \
        checkForTestSuffix checkForFile checkForPathFile checkForNativeCode \
        checkForTip127 checkForTip194 checkForTip207 checkForTip241 \
        checkForTip285 checkForTip405 checkForTip426 checkForTip429 \
        checkForTiming checkForPerformance checkForBigLists \
        checkForTimeIntensive checkForMemoryIntensive checkForStackIntensive \
        checkForInteractive checkForInteractiveCommand checkForUserInteraction \
        checkForNetwork checkForCompileOption checkForKnownCompileOptions] \
        false false
        checkForTimeIntensive checkForFullTest checkForMemoryIntensive \
        checkForStackIntensive checkForInteractive checkForInteractiveCommand \
        checkForUserInteraction checkForNetwork checkForCompileOption \
        checkForKnownCompileOptions] false false

    ###########################################################################
    ############################## END Tcl ONLY ###############################
    ###########################################################################
  }

  #
  # NOTE: Provide the Eagle test constraints package to the interpreter.
  #
  package provide Eagle.Test.Constraints \
    [expr {[isEagle] ? [info engine PatchLevel] : "1.0"}]
}

Changes to Externals/Eagle/lib/Test1.0/epilogue.eagle.
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37









38
39
40
41
42
43
44
45
21
22
23
24
25
26
27










28
29
30
31
32
33
34
35
36

37
38
39
40
41
42
43







-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-








  #
  # NOTE: Verify that the current call frame is correct and that the
  #       interpreter call stack has not been imbalanced by previous
  #       tests or other errors.  This check only applies to Eagle.
  #
  if {[isEagle] && [llength [info commands object]] > 0} then {
    catch {
      #
      # NOTE: Check the name of the current call frame against the one
      #       that should be used for evaluating this script file.
      #
      if {[object invoke -flags +NonPublic \
              Interpreter.GetActive.CurrentFrame Name] ne \
          [list source [file normalize [info script]]]} then {
        unset -nocomplain test_suite_running
        error "cannot run, current frame is not for this script"
    #
    # NOTE: Check the name of the current call frame against the one
    #       that should be used for evaluating this script file.
    #
    if {[object invoke -flags +NonPublic \
            Interpreter.GetActive.CurrentFrame Name] ne \
        [list source [file normalize [info script]]]} then {
      unset -nocomplain test_suite_running
      error "cannot run epilogue, current frame not for this script"
      }
    }
  }

  #
  # NOTE: Make sure all the variables used by this epilogue are unset.
  #
  unset -nocomplain memory stack name count passedOrSkipped percent \
Changes to Externals/Eagle/lib/Test1.0/prologue.eagle.
19
20
21
22
23
24
25
26
27


28
29
30
31
32
33
34
35







36
37
38
39
40


41
42
43
44
45
46
47
19
20
21
22
23
24
25


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
54
55







-
-
+
+








+
+
+
+
+
+
+




-
+
+







    error "cannot run, current level is not global"
  }

  #
  # NOTE: Make sure all the variables used by this prologue are unset.
  #
  unset -nocomplain pkg_dir pattern dummy directory name value exec encoding \
      host memory stack drive publicKeyToken expr server database timeout \
      user password percent checkout timeStamp loaded
      host memory stack drive server database timeout user password percent \
      checkout timeStamp loaded

  #
  # NOTE: Indicate that the test suite is currently running.
  #
  if {![info exists test_suite_running] || !$test_suite_running} then {
    set test_suite_running true
  }

  #
  # NOTE: Set the location of the test suite package, if necessary.
  #
  if {![info exists test_all_path]} then {
    set test_all_path [file normalize [file dirname [info script]]]
  }

  #
  # NOTE: Set the location of the test suite, if necessary.
  #
  if {![info exists test_path]} then {
    set test_path [file normalize [file dirname [info script]]]
    set test_path [file normalize [file join \
        [file dirname [file dirname $test_all_path]] Library Tests]]
  }

  #
  # NOTE: Set the location of the test suite data, if necessary.
  #
  if {![info exists test_data_path]} then {
    set test_data_path [file join $test_path data]
177
178
179
180
181
182
183





184




185
186
187
188
189
190
191
185
186
187
188
189
190
191
192
193
194
195
196

197
198
199
200
201
202
203
204
205
206
207







+
+
+
+
+
-
+
+
+
+







  # NOTE: Make sure our primary package path is part of the auto-path.
  #
  if {[lsearch -exact $auto_path $test_package_path] == -1} then {
    lappend auto_path $test_package_path
  }

  #
  # NOTE: Make sure the test suite package is part of the auto-path.
  #
  if {[lsearch -exact $auto_path $test_all_path] == -1} then {
    lappend auto_path $test_all_path
  }
  # NOTE: Make sure our test package path is part of the auto-path.

  #
  # NOTE: Make sure the test suite is part of the auto-path.  This is
  #       now done for legacy compatibility only.
  #
  if {[lsearch -exact $auto_path $test_path] == -1} then {
    lappend auto_path $test_path
  }

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

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
232
233
234
235
236
237
238










239
240
241
242
243
244
245
246
247

248
249
250
251
252
253
254







-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-







  #
  # NOTE: Verify that the current call frame is correct and that the
  #       interpreter call stack has not been imbalanced by previous
  #       tests or other errors.  This check only applies to Eagle.
  #       This block requires the "Eagle.Library" package.
  #
  if {[isEagle] && [llength [info commands object]] > 0} then {
    catch {
      #
      # NOTE: Check the name of the current call frame against the one
      #       that should be used for evaluating this script file.
      #
      if {[object invoke -flags +NonPublic \
              Interpreter.GetActive.CurrentFrame Name] ne \
          [list source [file normalize [info script]]]} then {
        unset -nocomplain test_suite_running
        error "cannot run, current frame is not for this script"
    #
    # NOTE: Check the name of the current call frame against the one
    #       that should be used for evaluating this script file.
    #
    if {[object invoke -flags +NonPublic \
            Interpreter.GetActive.CurrentFrame Name] ne \
        [list source [file normalize [info script]]]} then {
      unset -nocomplain test_suite_running
      error "cannot run prologue, current frame not for this script"
      }
    }
  }

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

  #
  # NOTE: Set the local root directory of the source checkout (i.e. of Eagle
305
306
307
308
309
310
311


312
313
314
315
316
317

318
319
320
321
322
323
324
319
320
321
322
323
324
325
326
327
328
329
330
331
332

333
334
335
336
337
338
339
340







+
+





-
+







  set test_flags(-stopOnLeak) ""; # default to continue on leak.
  set test_flags(-exitOnComplete) ""; # default to not exit after complete.
  set test_flags(-preTest) ""; # default to not evaluating anything.
  set test_flags(-postTest) ""; # default to not evaluating anything.
  set test_flags(-preWait) ""; # default to not waiting.
  set test_flags(-postWait) ""; # default to not waiting.
  set test_flags(-tclsh) ""; # Tcl shell, default to empty.
  set test_flags(-bad) [list]; # these are the unrecognized arguments.
  set test_flags(-no) [list]; # default to not having any restrictions.

  #
  # NOTE: Check for and process any command line arguments.
  #
  if {[info exists argv]} then {
    eval processTestArguments test_flags $argv
    set test_flags(-bad) [eval processTestArguments test_flags false $argv]

    if {[info exists test_flags(-no)] && \
        [string length $test_flags(-no)] > 0} then {
      #
      # NOTE: Set the test run restrictions based on the provided command line
      #       argument value (which is assumed to be a "dictionary-style" list
      #       containing name/value pairs to add to the global "no" array).
728
729
730
731
732
733
734





735
736
737
738
739
740
741
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762







+
+
+
+
+








  tputs $test_channel [appendArgs "---- executable: \"" \
      $bin_file \"\n]

  tputs $test_channel [appendArgs "---- command line: " \
      [expr {[info exists argv] && [string length $argv] > 0 ? \
          $argv : "<none>"}] \n]

  tputs $test_channel [appendArgs "---- unrecognized arguments: " \
      [expr {[info exists test_flags(-bad)] && \
          [string length $test_flags(-bad)] > 0 ? \
              $test_flags(-bad) : "<none>"}] \n]

  tputs $test_channel [appendArgs "---- logging to: " \
      [expr {[info exists test_log] && [string length $test_log] > 0 ? \
          [appendArgs \" $test_log \"] : "<none>"}] \n]

  tputs $test_channel [appendArgs "---- pass threshold: " \
      [expr {[info exists test_threshold] && \
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
901
902
903
904
905
906
907




































































908
909
910
911
912
913
914







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







      #       "debug-1.4", "glob-99.*", "object-10.*", "perf-2.2",
      #       and various other places within the test suite code
      #       itself.
      #
      checkForQuiet $test_channel false
    }

    #
    # NOTE: Has strong name key detection been disabled?
    #
    if {![info exists no(strongNameKey)]} then {
      catch {info engine PublicKeyToken} publicKeyToken

      if {[string length $publicKeyToken] == 0} then {
        #
        # NOTE: The Eagle core library is not signed with a strong name key.
        #       This is not an error, per se; however, it may cause selected
        #       tests to fail and it should be reported to the user and noted
        #       in the test suite log file.
        #
        addConstraint strongName.none

        if {![info exists no(warningForStrongNameKey)] && \
            ![haveConstraint quiet]} then {
          tputs $test_channel \
              "==== WARNING: no Eagle strong name signature detected...\n"
        }
      } else {
        #
        # NOTE: Add a test constraint for this specific strong name key.
        #
        addConstraint [appendArgs strongName. $publicKeyToken]

        #
        # BUGBUG: Tcl 8.4 does not seem to like this expression because it
        #         contains the "ni" operator added in Tcl 8.5 (and Tcl 8.4
        #         tries to compile it even though it will only be evaluated
        #         in Eagle).
        #
        set expr {$publicKeyToken ni \
            "29c6297630be05eb 1e22ec67879739a2 358030063a832bc3"}

        if {[expr $expr]} then {
          #
          # NOTE: The Eagle core library is strong name signed with a key that
          #       is not official.  This is also not an error, per se; however,
          #       it may cause some tests to fail and it should be reported to
          #       the user and noted in the test suite log file.
          #
          addConstraint strongName.unofficial

          if {![info exists no(warningForStrongNameKey)] && \
              ![haveConstraint quiet]} then {
            tputs $test_channel [appendArgs \
                "==== WARNING: unofficial Eagle strong name signature " \
                "detected: " $publicKeyToken \n]
          }
        } else {
          #
          # NOTE: Several tests require one of the official strong name keys to
          #       be used in order for them to pass.
          #
          addConstraint strongName.official

          tputs $test_channel [appendArgs \
              "---- official Eagle strong name signature detected: " \
              $publicKeyToken \n]
        }

        unset expr
      }

      unset publicKeyToken
    }

    #
    # NOTE: Has administrator detection support been disabled?  We do
    #       this check [nearly] first as it may [eventually] be used
    #       to help determine if other constraints should be skipped.
    #
    if {![info exists no(administrator)]} then {
      checkForAdministrator $test_channel
1039
1040
1041
1042
1043
1044
1045







1046
1047
1048
1049
1050
1051
1052
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012







+
+
+
+
+
+
+







    if {![info exists no(machine)]} then {
      checkForMachine $test_channel 32 intel; # (i.e. x86)
      checkForMachine $test_channel 32 arm;   # (i.e. arm)
      checkForMachine $test_channel 64 ia64;  # (i.e. itanium)
      checkForMachine $test_channel 64 amd64; # (i.e. x64)
    }

    #
    # NOTE: Has test suite call stack probing been disabled?
    #
    if {![info exists no(testCallStack)]} then {
      checkForTestCallStack $test_channel
    }

    #
    # NOTE: Has culture detection support been disabled?
    #
    if {![info exists no(culture)]} then {
      checkForCulture $test_channel
    }

1066
1067
1068
1069
1070
1071
1072







1073
1074
1075
1076
1077
1078
1079
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046







+
+
+
+
+
+
+








    #
    # NOTE: Has strong name detection support been disabled?
    #
    if {![info exists no(strongName)]} then {
      checkForStrongName $test_channel
    }

    #
    # NOTE: Has strong name key detection been disabled?
    #
    if {![info exists no(strongNameKey)]} then {
      checkForStrongNameKey $test_channel
    }

    #
    # NOTE: Has certificate detection support been disabled?
    #
    if {![info exists no(certificate)]} then {
      checkForCertificate $test_channel
    }
1613
1614
1615
1616
1617
1618
1619



































1620
1621
1622
1623
1624
1625
1626
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







        #
        # NOTE: For test "lpermute-1.3".
        #
        checkForObjectMember $test_channel Eagle._Tests.Default \
            *TestPermute*
      }

      if {![info exists no(testDynamicCallback)]} then {
        #
        # NOTE: For tests "object-8.1??".
        #
        checkForObjectMember $test_channel Eagle._Tests.Default \
            *TestCallDynamicCallback0*

        checkForObjectMember $test_channel Eagle._Tests.Default \
            *TestCallDynamicCallback1*

        checkForObjectMember $test_channel Eagle._Tests.Default \
            *TestCallDynamicCallback2*

        checkForObjectMember $test_channel Eagle._Tests.Default \
            *TestCallDynamicCallback3*

        checkForObjectMember $test_channel Eagle._Tests.Default \
            *TestGetDynamicCallbacks*

        checkForObjectMember $test_channel Eagle._Tests.Default \
            *TestCallStaticDynamicCallback0*

        checkForObjectMember $test_channel Eagle._Tests.Default \
            *TestCallStaticDynamicCallback1*

        checkForObjectMember $test_channel Eagle._Tests.Default \
            *TestCallStaticDynamicCallback2*

        checkForObjectMember $test_channel Eagle._Tests.Default \
            *TestCallStaticDynamicCallback3*

        checkForObjectMember $test_channel Eagle._Tests.Default \
            *TestGetStaticDynamicCallbacks*
      }

      #
      # NOTE: Has DateTime testing support been disabled?
      #
      if {![info exists no(testDateTime)]} then {
        #
        # NOTE: For test "vwait-1.11".
        #
2115
2116
2117
2118
2119
2120
2121
2122

2123
2124

2125
2126
2127
2128

2129
2130
2131
2132
2133
2134
2135
2117
2118
2119
2120
2121
2122
2123

2124
2125

2126
2127
2128
2129

2130
2131
2132
2133
2134
2135
2136
2137







-
+

-
+



-
+







      #
      # NOTE: For test "hash-1.1".
      #
      checkForNetFx20ServicePack $test_channel
    }

    #
    # NOTE: Has .NET Framework 4.5 testing support been disabled?
    # NOTE: Has .NET Framework 4.x testing support been disabled?
    #
    if {![info exists no(netFx45)]} then {
    if {![info exists no(netFx4x)]} then {
      #
      # NOTE: For test "object-12.1.*".
      #
      checkForNetFx45 $test_channel
      checkForNetFx4x $test_channel
    }

    #
    # NOTE: Has target framework testing support been disabled?
    #
    if {![info exists no(targetFramework)]} then {
      checkForTargetFramework $test_channel
2351
2352
2353
2354
2355
2356
2357







2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371







2372
2373
2374
2375
2376
2377
2378
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394







+
+
+
+
+
+
+














+
+
+
+
+
+
+







    #
    # NOTE: For tests "benchmark-1.3[89]" and "benchmark-1.40".
    #
    if {![info exists no(benchmark.txt)]} then {
      checkForFile $test_channel [file join $test_data_path benchmark.txt]
    }

    #
    # NOTE: For test "benchmark-1.42".
    #
    if {![info exists no(pngDump.txt)]} then {
      checkForFile $test_channel [file join $test_data_path pngDump.txt]
    }

    #
    # NOTE: For test "garuda-1.1".
    #
    if {![info exists no(pkgAll.tcl)]} then {
      checkForFile $test_channel [file join $base_path Native Package \
          Tests all.tcl] pkgAll.tcl
    }

    #
    # NOTE: For tests "subst-1.*".
    #
    if {![info exists no(bad_subst.txt)]} then {
      checkForFile $test_channel [file join $test_data_path bad_subst.txt]
    }

    #
    # NOTE: For test "processIsolation-1.1".
    #
    if {![info exists no(isolated.eagle)]} then {
      checkForFile $test_channel [file join $test_data_path isolated.eagle]
    }

    #
    # NOTE: This is not currently used by any tests.
    #
    if {![info exists no(evaluate.eagle)]} then {
      checkForFile $test_channel [file join $test_data_path evaluate.eagle]
    }
2619
2620
2621
2622
2623
2624
2625




2626
2627
2628
2629
2630
2631
2632
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652







+
+
+
+







  if {![info exists no(checkForBigLists)]} then {
    checkForBigLists $test_channel
  }

  if {![info exists no(checkForTimeIntensive)]} then {
    checkForTimeIntensive $test_channel
  }

  if {![info exists no(checkForFullTest)]} then {
    checkForFullTest $test_channel
  }

  if {![info exists no(checkForMemoryIntensive)]} then {
    checkForMemoryIntensive $test_channel
  }

  if {![info exists no(checkForStackIntensive)]} then {
    checkForStackIntensive $test_channel
Added Setup/build_mono.bat.


















































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@ECHO OFF

::
:: build_mono.bat --
::
:: Mono Wrapper Tool for MSBuild
::
:: Written by Joe Mistachkin.
:: Released to the public domain, use at your own risk!
::

SETLOCAL

REM SET __ECHO=ECHO
REM SET __ECHO3=ECHO
IF NOT DEFINED _AECHO (SET _AECHO=REM)
IF NOT DEFINED _CECHO (SET _CECHO=REM)
IF NOT DEFINED _VECHO (SET _VECHO=REM)

%_AECHO% Running %0 %*

SET DUMMY2=%1

IF DEFINED DUMMY2 (
  GOTO usage
)

SET TOOLS=%~dp0
SET TOOLS=%TOOLS:~0,-1%

%_VECHO% Tools = '%TOOLS%'

SET BUILD_CONFIGURATIONS=DebugManagedOnly ReleaseManagedOnly
SET PLATFORMS="Any CPU"
SET YEARS=2008 2013
SET NOUSER=1
SET MSBUILD_ARGS=/property:UseInteropDll=false
SET MSBUILD_ARGS=%MSBUILD_ARGS% /property:UseSqliteStandard=true
SET MSBUILD_ARGS=%MSBUILD_ARGS% /property:InteropCodec=false
SET MSBUILD_ARGS=%MSBUILD_ARGS% /property:InteropExtensionFunctions=false
SET MSBUILD_ARGS=%MSBUILD_ARGS% /property:InteropVirtualTable=false
SET MSBUILD_ARGS=%MSBUILD_ARGS% /property:InteropTestExtension=false

CALL :fn_ResetErrorLevel

%__ECHO3% CALL "%TOOLS%\build_all.bat"

IF ERRORLEVEL 1 (
  ECHO Failed to build Mono binaries.
  GOTO errors
)

:fn_ResetErrorLevel
  VERIFY > NUL
  GOTO :EOF

:fn_SetErrorLevel
  VERIFY MAYBE 2> NUL
  GOTO :EOF

:usage
  ECHO.
  ECHO Usage: %~nx0
  ECHO.
  GOTO errors

:errors
  CALL :fn_SetErrorLevel
  ENDLOCAL
  ECHO.
  ECHO Build failure, errors were encountered.
  GOTO end_of_file

:no_errors
  CALL :fn_ResetErrorLevel
  ENDLOCAL
  ECHO.
  ECHO Build success, no errors were encountered.
  GOTO end_of_file

:end_of_file
%__ECHO% EXIT /B %ERRORLEVEL%
Changes to Setup/clean.bat.
38
39
40
41
42
43
44
45

46
47
48
49
50
51
52
38
39
40
41
42
43
44

45
46
47
48
49
50
51
52







-
+







IF NOT EXIST "%TEMP%" (
  ECHO The TEMP directory, "%TEMP%", does not exist.
  GOTO usage
)

IF DEFINED CLEANDIRS GOTO skip_cleanDirs

SET CLEANDIRS=bin obj Doc\Output Setup\Output
SET CLEANDIRS=.vs bin obj Doc\Output Setup\Output
SET CLEANDIRS=%CLEANDIRS% SQLite.Designer\bin SQLite.Designer\obj
SET CLEANDIRS=%CLEANDIRS% SQLite.Interop\bin SQLite.Interop\obj
SET CLEANDIRS=%CLEANDIRS% System.Data.SQLite\bin System.Data.SQLite\obj
SET CLEANDIRS=%CLEANDIRS% System.Data.SQLite.Linq\bin System.Data.SQLite.Linq\obj
SET CLEANDIRS=%CLEANDIRS% test\bin test\obj testce\bin testce\obj testlinq\bin
SET CLEANDIRS=%CLEANDIRS% testlinq\obj tools\install\bin tools\install\obj

Changes to System.Data.SQLite/LINQ/SQLiteFactory_Linq.cs.
39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
39
40
41
42
43
44
45

46
47
48
49
50
51
52
53







-
+








    static SQLiteFactory()
    {
#if (SQLITE_STANDARD || USE_INTEROP_DLL || PLATFORM_COMPACTFRAMEWORK) && PRELOAD_NATIVE_LIBRARY
        UnsafeNativeMethods.Initialize();
#endif

#if INTEROP_LOG
#if USE_INTEROP_DLL && INTEROP_LOG
        if (UnsafeNativeMethods.sqlite3_config_log_interop() == SQLiteErrorCode.Ok)
        {
            UnsafeNativeMethods.sqlite3_log(
                SQLiteErrorCode.Ok, SQLiteConvert.ToUTF8("logging initialized."));
        }
#endif

86
87
88
89
90
91
92
93

94
95
96
97
98

99
100
101
102
103
104
105
86
87
88
89
90
91
92

93
94
95
96
97

98
99
100
101
102
103
104
105







-
+




-
+







            string typeName = UnsafeNativeMethods.GetSettingValue(
                "TypeName_SQLiteProviderServices", null);

            Version version = this.GetType().Assembly.GetName().Version;

            if (typeName != null)
            {
                typeName = String.Format(
                typeName = UnsafeNativeMethods.StringFormat(
                    CultureInfo.InvariantCulture, typeName, version);
            }
            else
            {
                typeName = String.Format(
                typeName = UnsafeNativeMethods.StringFormat(
                    CultureInfo.InvariantCulture, DefaultTypeName, version);
            }

            Type type = Type.GetType(typeName, false);

            if (type != null)
            {
Changes to System.Data.SQLite/SQLite3.cs.
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
274
275
276
277
278
279
280

281
282
283
284
285
286
287
288
289

290
291
292
293
294
295
296
297
298
299
300
301
302
303

304
305
306
307
308
309
310
311
312

313
314
315
316
317
318
319
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
274
275
276
277
278
279

280
281
282
283
284
285
286
287
288

289
290
291
292
293
294
295
296
297
298
299
300
301
302

303
304
305
306
307
308
309
310
311

312
313
314
315
316
317
318
319







-
+








-
+



















-
+








-
+













-
+








-
+







              if (SQLiteBase.ResetConnection(_sql, _sql, canThrow))
              {
                  if (unbindFunctions)
                  {
                      if (SQLiteFunction.UnbindAllFunctions(this, _flags, false))
                      {
#if !NET_COMPACT_20 && TRACE_CONNECTION
                          Trace.WriteLine(String.Format(
                          Trace.WriteLine(UnsafeNativeMethods.StringFormat(
                              CultureInfo.CurrentCulture,
                              "UnbindFunctions (Pool) Success: {0}",
                              HandleToString()));
#endif
                      }
                      else
                      {
#if !NET_COMPACT_20 && TRACE_CONNECTION
                          Trace.WriteLine(String.Format(
                          Trace.WriteLine(UnsafeNativeMethods.StringFormat(
                              CultureInfo.CurrentCulture,
                              "UnbindFunctions (Pool) Failure: {0}",
                              HandleToString()));
#endif
                      }
                  }

#if INTEROP_VIRTUAL_TABLE
                  DisposeModules();
#endif

                  SQLiteConnectionPool.Add(_fileName, _sql, _poolVersion);

                  SQLiteConnection.OnChanged(null, new ConnectionEventArgs(
                      SQLiteConnectionEventType.ClosedToPool, null, null,
                      null, null, _sql, _fileName, new object[] {
                      typeof(SQLite3), canThrow, _fileName, _poolVersion }));

#if !NET_COMPACT_20 && TRACE_CONNECTION
                  Trace.WriteLine(String.Format(
                  Trace.WriteLine(UnsafeNativeMethods.StringFormat(
                      CultureInfo.CurrentCulture,
                      "Close (Pool) Success: {0}",
                      HandleToString()));
#endif
              }
#if !NET_COMPACT_20 && TRACE_CONNECTION
              else
              {
                  Trace.WriteLine(String.Format(
                  Trace.WriteLine(UnsafeNativeMethods.StringFormat(
                      CultureInfo.CurrentCulture,
                      "Close (Pool) Failure: {0}",
                      HandleToString()));
              }
#endif
          }
          else
          {
              if (unbindFunctions)
              {
                  if (SQLiteFunction.UnbindAllFunctions(this, _flags, false))
                  {
#if !NET_COMPACT_20 && TRACE_CONNECTION
                      Trace.WriteLine(String.Format(
                      Trace.WriteLine(UnsafeNativeMethods.StringFormat(
                          CultureInfo.CurrentCulture,
                          "UnbindFunctions Success: {0}",
                          HandleToString()));
#endif
                  }
                  else
                  {
#if !NET_COMPACT_20 && TRACE_CONNECTION
                      Trace.WriteLine(String.Format(
                      Trace.WriteLine(UnsafeNativeMethods.StringFormat(
                          CultureInfo.CurrentCulture,
                          "UnbindFunctions Failure: {0}",
                          HandleToString()));
#endif
                  }
              }

885
886
887
888
889
890
891
892

893
894
895
896
897
898
899
885
886
887
888
889
890
891

892
893
894
895
896
897
898
899







-
+







        SQLiteConnection.OnChanged(null, new ConnectionEventArgs(
            SQLiteConnectionEventType.OpenedFromPool, null, null,
            null, null, _sql, strFilename, new object[] {
            typeof(SQLite3), strFilename, vfsName, connectionFlags,
            openFlags, maxPoolSize, usePool, _poolVersion }));

#if !NET_COMPACT_20 && TRACE_CONNECTION
        Trace.WriteLine(String.Format(
        Trace.WriteLine(UnsafeNativeMethods.StringFormat(
            CultureInfo.CurrentCulture,
            "Open (Pool): {0}", HandleToString()));
#endif
      }

      if (_sql == null)
      {
916
917
918
919
920
921
922
923

924
925
926
927
928
929
930
916
917
918
919
920
921
922

923
924
925
926
927
928
929
930







-
+







          else
#endif
          {
            n = UnsafeNativeMethods.sqlite3_open_v2(ToUTF8(strFilename), ref db, openFlags, ToUTF8(vfsName));
          }

#if !NET_COMPACT_20 && TRACE_CONNECTION
          Trace.WriteLine(String.Format(
          Trace.WriteLine(UnsafeNativeMethods.StringFormat(
              CultureInfo.CurrentCulture,
              "Open: {0}", db));
#endif

          if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, null);
          _sql = new SQLiteConnectionHandle(db, true);
        }
1241
1242
1243
1244
1245
1246
1247
1248

1249
1250
1251
1252

1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269

1270
1271
1272
1273
1274
1275
1276
1241
1242
1243
1244
1245
1246
1247

1248
1249
1250
1251

1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268

1269
1270
1271
1272
1273
1274
1275
1276







-
+



-
+
















-
+







        //       data classes.
        //
        string baseSchemaName = (cnn != null) ? cnn._baseSchemaName : null;

        if (!String.IsNullOrEmpty(baseSchemaName))
        {
          strSql = strSql.Replace(
              String.Format(CultureInfo.InvariantCulture,
              UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture,
              "[{0}].", baseSchemaName), String.Empty);

          strSql = strSql.Replace(
              String.Format(CultureInfo.InvariantCulture,
              UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture,
              "{0}.", baseSchemaName), String.Empty);
        }
      }

      SQLiteConnectionFlags flags =
          (cnn != null) ? cnn.Flags : SQLiteConnectionFlags.Default;

      if (
#if !PLATFORM_COMPACTFRAMEWORK
          ForceLogPrepare() ||
#endif
          ((flags & SQLiteConnectionFlags.LogPrepare) == SQLiteConnectionFlags.LogPrepare))
      {
          if ((strSql == null) || (strSql.Length == 0) || (strSql.Trim().Length == 0))
              SQLiteLog.LogMessage("Preparing {<nothing>}...");
          else
              SQLiteLog.LogMessage(String.Format(
              SQLiteLog.LogMessage(UnsafeNativeMethods.StringFormat(
                  CultureInfo.CurrentCulture, "Preparing {{{0}}}...", strSql));
      }

      IntPtr stmt = IntPtr.Zero;
      IntPtr ptr = IntPtr.Zero;
      int len = 0;
      SQLiteErrorCode n = SQLiteErrorCode.Schema;
1309
1310
1311
1312
1313
1314
1315
1316

1317
1318
1319
1320
1321
1322
1323
1309
1310
1311
1312
1313
1314
1315

1316
1317
1318
1319
1320
1321
1322
1323







-
+







#else
            n = UnsafeNativeMethods.sqlite3_prepare(_sql, psql, b.Length - 1, ref stmt, ref ptr);
#endif
            len = -1;
#endif

#if !NET_COMPACT_20 && TRACE_STATEMENT
            Trace.WriteLine(String.Format(
            Trace.WriteLine(UnsafeNativeMethods.StringFormat(
                CultureInfo.CurrentCulture,
                "Prepare ({0}): {1}", n, stmt));
#endif

            if ((n == SQLiteErrorCode.Ok) && (stmt != IntPtr.Zero))
            {
              if (statementHandle != null) statementHandle.Dispose();
1445
1446
1447
1448
1449
1450
1451
1452

1453
1454
1455
1456
1457
1458
1459
1460
1461
1462


1463
1464
1465
1466
1467
1468
1469
1445
1446
1447
1448
1449
1450
1451

1452
1453
1454
1455
1456
1457
1458
1459
1460
1461

1462
1463
1464
1465
1466
1467
1468
1469
1470







-
+









-
+
+







      }
    }

    protected static void LogBind(SQLiteStatementHandle handle, int index)
    {
        IntPtr handleIntPtr = handle;

        SQLiteLog.LogMessage(String.Format(
        SQLiteLog.LogMessage(UnsafeNativeMethods.StringFormat(
            CultureInfo.CurrentCulture,
            "Binding statement {0} paramter #{1} as NULL...",
            handleIntPtr, index));
    }

    protected static void LogBind(SQLiteStatementHandle handle, int index, ValueType value)
    {
        IntPtr handleIntPtr = handle;

        SQLiteLog.LogMessage(String.Format(
        SQLiteLog.LogMessage(UnsafeNativeMethods.StringFormat(
            CultureInfo.CurrentCulture,
            "Binding statement {0} paramter #{1} as type {2} with value {{{3}}}...",
            handleIntPtr, index, value.GetType(), value));
    }

    private static string FormatDateTime(DateTime value)
    {
        StringBuilder result = new StringBuilder();
1477
1478
1479
1480
1481
1482
1483
1484


1485
1486
1487
1488
1489
1490
1491
1492
1493


1494
1495
1496
1497
1498
1499
1500
1478
1479
1480
1481
1482
1483
1484

1485
1486
1487
1488
1489
1490
1491
1492
1493
1494

1495
1496
1497
1498
1499
1500
1501
1502
1503







-
+
+








-
+
+







        return result.ToString();
    }

    protected static void LogBind(SQLiteStatementHandle handle, int index, DateTime value)
    {
        IntPtr handleIntPtr = handle;

        SQLiteLog.LogMessage(String.Format(
        SQLiteLog.LogMessage(UnsafeNativeMethods.StringFormat(
            CultureInfo.CurrentCulture,
            "Binding statement {0} paramter #{1} as type {2} with value {{{3}}}...",
            handleIntPtr, index, typeof(DateTime), FormatDateTime(value)));
    }

    protected static void LogBind(SQLiteStatementHandle handle, int index, string value)
    {
        IntPtr handleIntPtr = handle;

        SQLiteLog.LogMessage(String.Format(
        SQLiteLog.LogMessage(UnsafeNativeMethods.StringFormat(
            CultureInfo.CurrentCulture,
            "Binding statement {0} paramter #{1} as type {2} with value {{{3}}}...",
            handleIntPtr, index, typeof(String), (value != null) ? value : "<null>"));
    }

    private static string ToHexadecimalString(
        byte[] array
        )
1512
1513
1514
1515
1516
1517
1518
1519


1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534

1535
1536

1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1515
1516
1517
1518
1519
1520
1521

1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545

1546
1547
1548
1549
1550
1551
1552







-
+
+















+


+



-







        return result.ToString();
    }

    protected static void LogBind(SQLiteStatementHandle handle, int index, byte[] value)
    {
        IntPtr handleIntPtr = handle;

        SQLiteLog.LogMessage(String.Format(
        SQLiteLog.LogMessage(UnsafeNativeMethods.StringFormat(
            CultureInfo.CurrentCulture,
            "Binding statement {0} paramter #{1} as type {2} with value {{{3}}}...",
            handleIntPtr, index, typeof(Byte[]), (value != null) ? ToHexadecimalString(value) : "<null>"));
    }

    internal override void Bind_Double(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, double value)
    {
        SQLiteStatementHandle handle = stmt._sqlite_stmt;

        if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
        {
            LogBind(handle, index, value);
        }

#if !PLATFORM_COMPACTFRAMEWORK
        SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_double(handle, index, value);
        if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
#elif !SQLITE_STANDARD
        SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_double_interop(handle, index, ref value);
        if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
#else
        throw new NotImplementedException();
#endif
        if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
    }

    internal override void Bind_Int32(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, int value)
    {
        SQLiteStatementHandle handle = stmt._sqlite_stmt;

        if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
1592
1593
1594
1595
1596
1597
1598

1599
1600

1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617

1618
1619

1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610

1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630

1631
1632
1633
1634
1635
1636
1637







+


+



-













+


+



-







#if !PLATFORM_COMPACTFRAMEWORK
        if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
        {
            LogBind(handle, index, value);
        }

        SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_int64(handle, index, value);
        if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
#elif !SQLITE_STANDARD
        SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_int64_interop(handle, index, ref value);
        if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
#else
        throw new NotImplementedException();
#endif
        if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
    }

    internal override void Bind_UInt64(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, ulong value)
    {
        SQLiteStatementHandle handle = stmt._sqlite_stmt;

#if !PLATFORM_COMPACTFRAMEWORK
        if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
        {
            LogBind(handle, index, value);
        }

        SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_uint64(handle, index, value);
        if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
#elif !SQLITE_STANDARD
        SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_uint64_interop(handle, index, ref value);
        if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
#else
        throw new NotImplementedException();
#endif
        if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
    }

    internal override void Bind_Text(SQLiteStatement stmt, SQLiteConnectionFlags flags, int index, string value)
    {
        SQLiteStatementHandle handle = stmt._sqlite_stmt;

#if !PLATFORM_COMPACTFRAMEWORK
1680
1681
1682
1683
1684
1685
1686


1687
1688


1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705


1706
1707


1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724


1725
1726


1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702


1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723


1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744


1745
1746
1747
1748
1749
1750
1751







+
+


+
+



-
-












+
+


+
+



-
-












+
+


+
+



-
-







#if !PLATFORM_COMPACTFRAMEWORK
                    if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
                    {
                        LogBind(handle, index, value);
                    }

                    SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_int64(handle, index, value);
                    if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
                    break;
#elif !SQLITE_STANDARD
                    SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_int64_interop(handle, index, ref value);
                    if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
                    break;
#else
                    throw new NotImplementedException();
#endif
                    if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
                    break;
                }
            case SQLiteDateFormats.JulianDay:
                {
                    double value = ToJulianDay(dt);

#if !PLATFORM_COMPACTFRAMEWORK
                    if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
                    {
                        LogBind(handle, index, value);
                    }

                    SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_double(handle, index, value);
                    if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
                    break;
#elif !SQLITE_STANDARD
                    SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_double_interop(handle, index, ref value);
                    if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
                    break;
#else
                    throw new NotImplementedException();
#endif
                    if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
                    break;
                }
            case SQLiteDateFormats.UnixEpoch:
                {
                    long value = Convert.ToInt64(dt.Subtract(UnixEpoch).TotalSeconds);

#if !PLATFORM_COMPACTFRAMEWORK
                    if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
                    {
                        LogBind(handle, index, value);
                    }

                    SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_int64(handle, index, value);
                    if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
                    break;
#elif !SQLITE_STANDARD
                    SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_bind_int64_interop(handle, index, ref value);
                    if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
                    break;
#else
                    throw new NotImplementedException();
#endif
                    if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
                    break;
                }
            default:
                {
                    byte[] b = ToUTF8(dt);

#if !PLATFORM_COMPACTFRAMEWORK
                    if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
1783
1784
1785
1786
1787
1788
1789
1790

1791
1792
1793
1794
1795
1796
1797
1796
1797
1798
1799
1800
1801
1802

1803
1804
1805
1806
1807
1808
1809
1810







-
+







        SQLiteStatementHandle handle = stmt._sqlite_stmt;
        int value = UnsafeNativeMethods.sqlite3_bind_parameter_count(handle);

        if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
        {
            IntPtr handleIntPtr = handle;

            SQLiteLog.LogMessage(String.Format(
            SQLiteLog.LogMessage(UnsafeNativeMethods.StringFormat(
                CultureInfo.CurrentCulture,
                "Statement {0} paramter count is {1}.",
                handleIntPtr, value));
        }

        return value;
    }
1808
1809
1810
1811
1812
1813
1814
1815

1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833

1834
1835
1836
1837
1838
1839
1840
1821
1822
1823
1824
1825
1826
1827

1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845

1846
1847
1848
1849
1850
1851
1852
1853







-
+

















-
+







        name = UTF8ToString(UnsafeNativeMethods.sqlite3_bind_parameter_name(handle, index), -1);
#endif

        if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
        {
            IntPtr handleIntPtr = handle;

            SQLiteLog.LogMessage(String.Format(
            SQLiteLog.LogMessage(UnsafeNativeMethods.StringFormat(
                CultureInfo.CurrentCulture,
                "Statement {0} paramter #{1} name is {{{2}}}.",
                handleIntPtr, index, name));
        }

        return name;
    }

    internal override int Bind_ParamIndex(SQLiteStatement stmt, SQLiteConnectionFlags flags, string paramName)
    {
        SQLiteStatementHandle handle = stmt._sqlite_stmt;
        int index = UnsafeNativeMethods.sqlite3_bind_parameter_index(handle, ToUTF8(paramName));

        if ((flags & SQLiteConnectionFlags.LogBind) == SQLiteConnectionFlags.LogBind)
        {
            IntPtr handleIntPtr = handle;

            SQLiteLog.LogMessage(String.Format(
            SQLiteLog.LogMessage(UnsafeNativeMethods.StringFormat(
                CultureInfo.CurrentCulture,
                "Statement {0} paramter index of name {{{1}}} is #{2}.",
                handleIntPtr, paramName, index));
        }

        return index;
    }
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983

1984
1985

1986

1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1987
1988
1989
1990
1991
1992
1993

1994

1995
1996

1997
1998
1999
2000
2001
2002

2003
2004
2005
2006
2007
2008
2009







-

-
+

-
+

+



-







      notNull = (nnotNull == 1);
      primaryKey = (nprimaryKey == 1);
      autoIncrement = (nautoInc == 1);
    }

    internal override double GetDouble(SQLiteStatement stmt, int index)
    {
      double value;
#if !PLATFORM_COMPACTFRAMEWORK
      value = UnsafeNativeMethods.sqlite3_column_double(stmt._sqlite_stmt, index);
      return UnsafeNativeMethods.sqlite3_column_double(stmt._sqlite_stmt, index);
#elif !SQLITE_STANDARD
      value = 0.0;
      double value = 0.0;
      UnsafeNativeMethods.sqlite3_column_double_interop(stmt._sqlite_stmt, index, ref value);
      return value;
#else
      throw new NotImplementedException();
#endif
      return value;
    }

    internal override sbyte GetSByte(SQLiteStatement stmt, int index)
    {
      return unchecked((sbyte)(GetInt32(stmt, index) & byte.MaxValue));
    }

2018
2019
2020
2021
2022
2023
2024
2025
2026
2027

2028
2029

2030

2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2030
2031
2032
2033
2034
2035
2036

2037

2038
2039

2040
2041
2042
2043
2044
2045

2046
2047
2048
2049
2050
2051
2052







-

-
+

-
+

+



-







    internal override uint GetUInt32(SQLiteStatement stmt, int index)
    {
      return unchecked((uint)GetInt32(stmt, index));
    }

    internal override long GetInt64(SQLiteStatement stmt, int index)
    {
      long value;
#if !PLATFORM_COMPACTFRAMEWORK
      value = UnsafeNativeMethods.sqlite3_column_int64(stmt._sqlite_stmt, index);
      return UnsafeNativeMethods.sqlite3_column_int64(stmt._sqlite_stmt, index);
#elif !SQLITE_STANDARD
      value = 0;
      long value = 0;
      UnsafeNativeMethods.sqlite3_column_int64_interop(stmt._sqlite_stmt, index, ref value);
      return value;
#else
      throw new NotImplementedException();
#endif
      return value;
    }

    internal override ulong GetUInt64(SQLiteStatement stmt, int index)
    {
      return unchecked((ulong)GetInt64(stmt, index));
    }

2249
2250
2251
2252
2253
2254
2255
2256
2257
2258

2259
2260

2261

2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277

2278
2279

2280

2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2260
2261
2262
2263
2264
2265
2266

2267

2268
2269

2270
2271
2272
2273
2274
2275

2276
2277
2278
2279
2280
2281
2282
2283
2284

2285

2286
2287

2288
2289
2290
2291
2292
2293

2294
2295
2296
2297
2298
2299
2300







-

-
+

-
+

+



-









-

-
+

-
+

+



-







      }

      return nCopied;
    }

    internal override double GetParamValueDouble(IntPtr ptr)
    {
      double value;
#if !PLATFORM_COMPACTFRAMEWORK
      value = UnsafeNativeMethods.sqlite3_value_double(ptr);
      return UnsafeNativeMethods.sqlite3_value_double(ptr);
#elif !SQLITE_STANDARD
      value = 0.0;
      double value = 0.0;
      UnsafeNativeMethods.sqlite3_value_double_interop(ptr, ref value);
      return value;
#else
      throw new NotImplementedException();
#endif
      return value;
    }

    internal override int GetParamValueInt32(IntPtr ptr)
    {
      return UnsafeNativeMethods.sqlite3_value_int(ptr);
    }

    internal override long GetParamValueInt64(IntPtr ptr)
    {
      Int64 value;
#if !PLATFORM_COMPACTFRAMEWORK
      value = UnsafeNativeMethods.sqlite3_value_int64(ptr);
      return UnsafeNativeMethods.sqlite3_value_int64(ptr);
#elif !SQLITE_STANDARD
      value = 0;
      Int64 value = 0;
      UnsafeNativeMethods.sqlite3_value_int64_interop(ptr, ref value);
      return value;
#else
      throw new NotImplementedException();
#endif
      return value;
    }

    internal override string GetParamValueText(IntPtr ptr)
    {
#if !SQLITE_STANDARD
      int len = 0;
      return UTF8ToString(UnsafeNativeMethods.sqlite3_value_text_interop(ptr, ref len), len);
2384
2385
2386
2387
2388
2389
2390
2391

2392
2393
2394
2395
2396
2397
2398
2393
2394
2395
2396
2397
2398
2399

2400
2401
2402
2403
2404
2405
2406
2407







-
+







            _modules.Add(module.Name, module);

            if (_usePool)
            {
                _usePool = false;

#if !NET_COMPACT_20 && TRACE_CONNECTION
                Trace.WriteLine(String.Format(
                Trace.WriteLine(UnsafeNativeMethods.StringFormat(
                    CultureInfo.CurrentCulture,
                    "CreateModule (Pool) Disabled: {0}",
                    HandleToString()));
#endif
            }
        }
        else
2631
2632
2633
2634
2635
2636
2637

2638
2639
2640
2641
2642
2643

2644
2645
2646
2647
2648
2649
2650
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661







+






+







    }

#if INTEROP_CODEC || INTEROP_INCLUDE_SEE
    internal override void SetPassword(byte[] passwordBytes)
    {
      SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_key(_sql, passwordBytes, passwordBytes.Length);
      if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
      _usePool = false;
    }

    internal override void ChangePassword(byte[] newPasswordBytes)
    {
      SQLiteErrorCode n = UnsafeNativeMethods.sqlite3_rekey(_sql, newPasswordBytes, (newPasswordBytes == null) ? 0 : newPasswordBytes.Length);
      if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, GetLastError());
      _usePool = false;
    }
#endif

    internal override void SetProgressHook(int nOps, SQLiteProgressCallback func)
    {
        UnsafeNativeMethods.sqlite3_progress_handler(_sql, nOps, func, IntPtr.Zero);
    }
Changes to System.Data.SQLite/SQLite3_UTF16.cs.
8
9
10
11
12
13
14
15
16
17

18
19

20
21
22
23
24
25
26
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25
26
27







-


+


+







namespace System.Data.SQLite
{
  using System;
  using System.Collections.Generic;

#if !NET_COMPACT_20 && TRACE_CONNECTION
  using System.Diagnostics;
  using System.Globalization;
#endif

  using System.Globalization;
  using System.IO;
  using System.Runtime.InteropServices;


  /// <summary>
  /// Alternate SQLite3 object, overriding many text behaviors to support UTF-16 (Unicode)
  /// </summary>
  internal sealed class SQLite3_UTF16 : SQLite3
  {
    /// <summary>
158
159
160
161
162
163
164
165

166
167
168
169
170
171
172
159
160
161
162
163
164
165

166
167
168
169
170
171
172
173







-
+







            SQLiteConnectionEventType.OpenedFromPool, null, null,
            null, null, _sql, strFilename, new object[] {
            typeof(SQLite3_UTF16), strFilename, vfsName,
            connectionFlags, openFlags, maxPoolSize, usePool,
            _poolVersion }));

#if !NET_COMPACT_20 && TRACE_CONNECTION
        Trace.WriteLine(String.Format(
        Trace.WriteLine(UnsafeNativeMethods.StringFormat(
            CultureInfo.CurrentCulture,
            "Open16 (Pool): {0}",
            HandleToString()));
#endif
      }

      if (_sql == null)
197
198
199
200
201
202
203
204


205
206
207
208
209
210
211
212

213
214
215
216
217
218
219
198
199
200
201
202
203
204

205
206
207
208
209
210
211
212
213

214
215
216
217
218
219
220
221







-
+
+







-
+







            //       a flags parameter.
            //
            if (((openFlags & SQLiteOpenFlagsEnum.Create) != SQLiteOpenFlagsEnum.Create) && !File.Exists(strFilename))
              throw new SQLiteException(SQLiteErrorCode.CantOpen, strFilename);

            if (vfsName != null)
            {
              throw new SQLiteException(SQLiteErrorCode.CantOpen, String.Format(
              throw new SQLiteException(SQLiteErrorCode.CantOpen, UnsafeNativeMethods.StringFormat(
                CultureInfo.CurrentCulture,
                "cannot open using UTF-16 and VFS \"{0}\": need interop assembly", vfsName));
            }

            n = UnsafeNativeMethods.sqlite3_open16(strFilename, ref db);
          }

#if !NET_COMPACT_20 && TRACE_CONNECTION
          Trace.WriteLine(String.Format(
          Trace.WriteLine(UnsafeNativeMethods.StringFormat(
              CultureInfo.CurrentCulture,
              "Open16: {0}", db));
#endif

          if (n != SQLiteErrorCode.Ok) throw new SQLiteException(n, null);
          _sql = new SQLiteConnectionHandle(db, true);
        }
Changes to System.Data.SQLite/SQLiteBase.cs.
947
948
949
950
951
952
953

954
955
956
957
958

959
960
961
962
963
964
965

966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983

984
985
986
987
988
989
990
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994







+





+







+


















+








      /// <summary>
      /// Prevent this <see cref="SQLiteConnection" /> object instance from
      /// loading extensions.
      /// </summary>
      NoLoadExtension = 0x200,

#if INTEROP_VIRTUAL_TABLE
      /// <summary>
      /// Prevent this <see cref="SQLiteConnection" /> object instance from
      /// creating virtual table modules.
      /// </summary>
      NoCreateModule = 0x400,
#endif

      /// <summary>
      /// Skip binding any functions provided by other managed assemblies when
      /// opening the connection.
      /// </summary>
      NoBindFunctions = 0x800,

#if INTEROP_VIRTUAL_TABLE
      /// <summary>
      /// Skip setting the logging related properties of the
      /// <see cref="SQLiteModule" /> object instance that was passed to
      /// the <see cref="SQLiteConnection.CreateModule" /> method.
      /// </summary>
      NoLogModule = 0x1000,

      /// <summary>
      /// Enable logging of all virtual table module errors seen by the
      /// <see cref="SQLiteModule.SetTableError(IntPtr,String)" /> method.
      /// </summary>
      LogModuleError = 0x2000,

      /// <summary>
      /// Enable logging of certain virtual table module exceptions that cannot
      /// be easily discovered via other means.
      /// </summary>
      LogModuleException = 0x4000,
#endif

      /// <summary>
      /// Enable tracing of potentially important [non-fatal] error conditions
      /// that cannot be easily reported through other means.
      /// </summary>
      TraceWarning = 0x8000,

1161
1162
1163
1164
1165
1166
1167

1168
1169
1170




1171
1172
1173
1174

1175



1176
1177
1178
1179
1180
1181
1182
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195







+



+
+
+
+




+

+
+
+







      /// </summary>
      ConvertAndBindAndGetAllAsInvariantText = BindAndGetAllAsText |
                                               ConvertAndBindInvariantText,

      /// <summary>
      /// Enable all logging.
      /// </summary>
#if INTEROP_VIRTUAL_TABLE
      LogAll = LogPrepare | LogPreBind | LogBind |
               LogCallbackException | LogBackup | LogModuleError |
               LogModuleException,
#else
      LogAll = LogPrepare | LogPreBind | LogBind |
               LogCallbackException | LogBackup,
#endif

      /// <summary>
      /// The default extra flags for new connections.
      /// </summary>
#if INTEROP_VIRTUAL_TABLE
      Default = LogCallbackException | LogModuleException,
#else
      Default = LogCallbackException,
#endif

      /// <summary>
      /// The default extra flags for new connections with all logging enabled.
      /// </summary>
      DefaultAndLogAll = Default | LogAll
  }

Changes to System.Data.SQLite/SQLiteCommandBuilder.cs.
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
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







-
+









-
+







    /// <summary>
    /// Returns a valid named parameter
    /// </summary>
    /// <param name="parameterName">The name of the parameter</param>
    /// <returns>Error</returns>
    protected override string GetParameterName(string parameterName)
    {
      return String.Format(CultureInfo.InvariantCulture, "@{0}", parameterName);
      return UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "@{0}", parameterName);
    }

    /// <summary>
    /// Returns a named parameter for the given ordinal
    /// </summary>
    /// <param name="parameterOrdinal">The i of the parameter</param>
    /// <returns>Error</returns>
    protected override string GetParameterName(int parameterOrdinal)
    {
      return String.Format(CultureInfo.InvariantCulture, "@param{0}", parameterOrdinal);
      return UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "@param{0}", parameterOrdinal);
    }

    /// <summary>
    /// Returns a placeholder character for the specified parameter i.
    /// </summary>
    /// <param name="parameterOrdinal">The index of the parameter to provide a placeholder for</param>
    /// <returns>Returns a named parameter</returns>
Changes to System.Data.SQLite/SQLiteConnection.cs.
294
295
296
297
298
299
300
301








302
303
304
305
306
307
308
294
295
296
297
298
299
300

301
302
303
304
305
306
307
308
309
310
311
312
313
314
315







-
+
+
+
+
+
+
+
+







  /// <b>False</b> - Store GUID columns as text
  /// </description>
  /// <description>N</description>
  /// <description>True</description>
  /// </item>
  /// <item>
  /// <description>Cache Size</description>
  /// <description>{size in bytes}</description>
  /// <description>
  /// If the argument N is positive then the suggested cache size is set to N.
  /// If the argument N is negative, then the number of cache pages is adjusted
  /// to use approximately abs(N*1024) bytes of memory. Backwards compatibility
  /// note: The behavior of cache_size with a negative N was different in SQLite
  /// versions prior to 3.7.10. In version 3.7.9 and earlier, the number of
  /// pages in the cache was set to the absolute value of N.
  /// </description>
  /// <description>N</description>
  /// <description>2000</description>
  /// </item>
  /// <item>
  /// <description>Synchronous</description>
  /// <description>
  /// <b>Normal</b> - Normal file flushing behavior
803
804
805
806
807
808
809

810
811
812
813
814
815
816
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824







+







    /// <param name="connectionString">The connection string to use.</param>
    public SQLiteConnection(string connectionString)
        : this(connectionString, false)
    {
        // do nothing.
    }

#if INTEROP_VIRTUAL_TABLE
    /// <summary>
    /// Initializes the connection with a pre-existing native connection handle.
    /// This constructor overload is intended to be used only by the private
    /// <see cref="SQLiteModule.CreateOrConnect" /> method.
    /// </summary>
    /// <param name="db">
    /// The native connection handle to use.
832
833
834
835
836
837
838

839
840
841
842
843
844
845
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854







+







        _flags = SQLiteConnectionFlags.None;

        _connectionState = (db != IntPtr.Zero) ?
            ConnectionState.Open : ConnectionState.Closed;

        _connectionString = null; /* unknown */
    }
#endif

    /// <summary>
    /// Initializes the connection with the specified connection string.
    /// </summary>
    /// <param name="connectionString">
    /// The connection string to use.
    /// </param>
877
878
879
880
881
882
883
884

885
886
887
888
889
890
891
886
887
888
889
890
891
892

893
894
895
896
897
898
899
900







-
+








              if (_versionNumber >= 3007014)
                  SQLiteConnectionHandle.closeConnection = SQLiteBase.CloseConnectionV2;
          }
      }
#endif

#if INTEROP_LOG
#if USE_INTEROP_DLL && INTEROP_LOG
      if (UnsafeNativeMethods.sqlite3_config_log_interop() == SQLiteErrorCode.Ok)
      {
          UnsafeNativeMethods.sqlite3_log(
              SQLiteErrorCode.Ok, SQLiteConvert.ToUTF8("logging initialized."));
      }
#endif

925
926
927
928
929
930
931
932

933
934
935
936
937
938
939
934
935
936
937
938
939
940

941
942
943
944
945
946
947
948







-
+







          {
            string str = row[0].ToString();
            if (String.Compare(str, "main", StringComparison.OrdinalIgnoreCase) != 0
              && String.Compare(str, "temp", StringComparison.OrdinalIgnoreCase) != 0)
            {
              using (SQLiteCommand cmd = CreateCommand())
              {
                cmd.CommandText = String.Format(CultureInfo.InvariantCulture, "ATTACH DATABASE '{0}' AS [{1}]", row[1], row[0]);
                cmd.CommandText = UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "ATTACH DATABASE '{0}' AS [{1}]", row[1], row[0]);
                cmd.ExecuteNonQuery();
              }
            }
          }
        }
      }
    }
1158
1159
1160
1161
1162
1163
1164
1165

1166
1167
1168
1169
1170
1171
1172
1167
1168
1169
1170
1171
1172
1173

1174
1175
1176
1177
1178
1179
1180
1181







-
+







                    break;
            }
        }
        catch (Exception e)
        {
            if ((_flags & SQLiteConnectionFlags.LogBackup) == SQLiteConnectionFlags.LogBackup)
            {
                SQLiteLog.LogMessage(String.Format(
                SQLiteLog.LogMessage(UnsafeNativeMethods.StringFormat(
                    CultureInfo.CurrentCulture,
                    "Caught exception while backing up database: {0}", e));
            }

            throw;
        }
        finally
1444
1445
1446
1447
1448
1449
1450
1451

1452
1453
1454
1455
1456
1457
1458
1453
1454
1455
1456
1457
1458
1459

1460
1461
1462
1463
1464
1465
1466
1467







-
+







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

    /// <summary>
    /// Attempts to unbind the specified <see cref="SQLiteFunction" /> object
    /// instance to this connection.
    /// </summary>
    /// <param name="functionAttribute">
    /// The <see cref="SQLiteFunctionAttribute"/> object instance containing
    /// The <see cref="SQLiteFunctionAttribute" /> object instance containing
    /// the metadata for the function to be unbound.
    /// </param>
    /// <returns>Non-zero if the function was unbound.</returns>
    public bool UnbindFunction(
        SQLiteFunctionAttribute functionAttribute
        )
    {
1628
1629
1630
1631
1632
1633
1634
1635

1636
1637
1638
1639
1640
1641
1642
1637
1638
1639
1640
1641
1642
1643

1644
1645
1646
1647
1648
1649
1650
1651







-
+







    protected override void Dispose(bool disposing)
    {
#if !NET_COMPACT_20 && TRACE_WARNING
        if ((_flags & SQLiteConnectionFlags.TraceWarning) == SQLiteConnectionFlags.TraceWarning)
        {
            if (_noDispose)
            {
                System.Diagnostics.Trace.WriteLine(String.Format(
                System.Diagnostics.Trace.WriteLine(UnsafeNativeMethods.StringFormat(
                    CultureInfo.CurrentCulture,
                    "WARNING: Disposing of connection \"{0}\" with the no-dispose flag set.",
                    _connectionString));
            }
        }
#endif

2069
2070
2071
2072
2073
2074
2075

2076

2077
2078
2079
2080
2081
2082
2083
2078
2079
2080
2081
2082
2083
2084
2085

2086
2087
2088
2089
2090
2091
2092
2093







+
-
+







      if (UnsafeNativeMethods.GetSettingValue("No_SQLiteConnectionNewParser", null) != null)
          arParts = SQLiteConvert.Split(s, ';');
      else
          arParts = SQLiteConvert.NewSplit(s, ';', true, ref error);

      if (arParts == null)
      {
          throw new ArgumentException(UnsafeNativeMethods.StringFormat(
          throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
              CultureInfo.CurrentCulture,
              "Invalid ConnectionString format, cannot parse: {0}", (error != null) ?
              error : "could not split connection string into properties"));
      }

      int x = (arParts != null) ? arParts.Length : 0;
      // For each semi-colon piece, split into key and value pairs by the presence of the = sign
      for (n = 0; n < x; n++)
2093
2094
2095
2096
2097
2098
2099
2100

2101
2102
2103
2104
2105
2106
2107
2103
2104
2105
2106
2107
2108
2109

2110
2111
2112
2113
2114
2115
2116
2117







-
+







        int indexOf = arParts[n].IndexOf('=');

        if (indexOf != -1)
          ls.Add(UnwrapString(arParts[n].Substring(0, indexOf).Trim()), UnwrapString(arParts[n].Substring(indexOf + 1).Trim()));
        else if (allowNameOnly)
          ls.Add(UnwrapString(arParts[n].Trim()), String.Empty);
        else
          throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, "Invalid ConnectionString format for part \"{0}\", no equal sign found", arParts[n]));
          throw new ArgumentException(UnsafeNativeMethods.StringFormat(CultureInfo.CurrentCulture, "Invalid ConnectionString format for part \"{0}\", no equal sign found", arParts[n]));
      }
      return ls;
    }

    /// <summary>
    /// Parses a connection string using the built-in (i.e. framework provided)
    /// connection string parser class and returns the key/value pairs.  An
2293
2294
2295
2296
2297
2298
2299
2300

2301
2302
2303
2304
2305
2306
2307
2303
2304
2305
2306
2307
2308
2309

2310
2311
2312
2313
2314
2315
2316
2317







-
+







    public void EnableExtensions(
        bool enable
        )
    {
        CheckDisposed();

        if (_sql == null)
            throw new InvalidOperationException(String.Format(
            throw new InvalidOperationException(UnsafeNativeMethods.StringFormat(
                CultureInfo.CurrentCulture,
                "Database connection not valid for {0} extensions.",
                enable ? "enabling" : "disabling"));

        if ((_flags & SQLiteConnectionFlags.NoLoadExtension) == SQLiteConnectionFlags.NoLoadExtension)
            throw new SQLiteException("Loading extensions is disabled for this database connection.");

2416
2417
2418
2419
2420
2421
2422


2423

2424
2425
2426
2427
2428
2429
2430
2426
2427
2428
2429
2430
2431
2432
2433
2434

2435
2436
2437
2438
2439
2440
2441
2442







+
+
-
+








        StringBuilder result = new StringBuilder();

        int length = array.Length;

        for (int index = 0; index < length; index++)
#if NET_COMPACT_20
            result.Append(UnsafeNativeMethods.StringFormat(
                CultureInfo.InvariantCulture,
            result.Append(String.Format("{0:x2}", array[index]));
                "{0:x2}", array[index]));
#else
            result.AppendFormat("{0:x2}", array[index]);
#endif

        return result.ToString();
    }

2466
2467
2468
2469
2470
2471
2472
2473

2474
2475
2476
2477
2478
2479
2480
2478
2479
2480
2481
2482
2483
2484

2485
2486
2487
2488
2489
2490
2491
2492







-
+







        for (int index = 0; index < text.Length; index += 2)
        {
            string value = text.Substring(index, 2);

            if (!TryParseByte(value,
                    NumberStyles.HexNumber, out result[index / 2]))
            {
                error = String.Format(
                error = UnsafeNativeMethods.StringFormat(
                    CultureInfo.CurrentCulture,
                    "string contains \"{0}\", which cannot be converted to a byte value",
                    value);

                return null;
            }
        }
2622
2623
2624
2625
2626
2627
2628
2629

2630
2631
2632
2633
2634
2635
2636
2634
2635
2636
2637
2638
2639
2640

2641
2642
2643
2644
2645
2646
2647
2648







-
+







#if !NET_COMPACT_20 && TRACE_WARNING
      bool uri = false;
#endif
      bool fullUri = false;
      string fileName;

      if (Convert.ToInt32(FindKey(opts, "Version", DefaultVersion.ToString()), CultureInfo.InvariantCulture) != DefaultVersion)
        throw new NotSupportedException(String.Format(CultureInfo.CurrentCulture, "Only SQLite Version {0} is supported at this time", DefaultVersion));
        throw new NotSupportedException(UnsafeNativeMethods.StringFormat(CultureInfo.CurrentCulture, "Only SQLite Version {0} is supported at this time", DefaultVersion));

#if INTEROP_INCLUDE_ZIPVFS
      bool useZipVfs = false;
      string zipVfsVersion = FindKey(opts, "ZipVfsVersion", DefaultZipVfsVersion);

      if (zipVfsVersion != null)
      {
2646
2647
2648
2649
2650
2651
2652
2653

2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669

2670
2671
2672
2673
2674
2675
2676
2658
2659
2660
2661
2662
2663
2664

2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680

2681
2682
2683
2684
2685
2686
2687
2688







-
+















-
+







          else if (String.Compare(zipVfsVersion, ZipVfs_V3) == 0)
          {
              UnsafeNativeMethods.zipvfsInit_v3(0);
              useZipVfs = true;
          }
          else
          {
              throw new NotSupportedException(String.Format(
              throw new NotSupportedException(UnsafeNativeMethods.StringFormat(
                  CultureInfo.CurrentCulture, "Only ZipVFS versions {0}, {1}, and {2} are supported at this time",
                  ZipVfs_Automatic, ZipVfs_V2, ZipVfs_V3));
          }
      }
#endif

      fileName = FindKey(opts, "Data Source", DefaultDataSource);

      if (String.IsNullOrEmpty(fileName))
      {
        fileName = FindKey(opts, "Uri", DefaultUri);
        if (String.IsNullOrEmpty(fileName))
        {
          fileName = FindKey(opts, "FullUri", DefaultFullUri);
          if (String.IsNullOrEmpty(fileName))
            throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, "Data Source cannot be empty.  Use {0} to open an in-memory database", MemoryFileName));
            throw new ArgumentException(UnsafeNativeMethods.StringFormat(CultureInfo.CurrentCulture, "Data Source cannot be empty.  Use {0} to open an in-memory database", MemoryFileName));
          else
            fullUri = true;
        }
        else
        {
          fileName = MapUriPath(fileName);
#if !NET_COMPACT_20 && TRACE_WARNING
2684
2685
2686
2687
2688
2689
2690
2691

2692
2693
2694
2695
2696
2697
2698
2696
2697
2698
2699
2700
2701
2702

2703
2704
2705
2706
2707
2708
2709
2710







-
+







#if !NET_COMPACT_20 && TRACE_WARNING
      if ((_flags & SQLiteConnectionFlags.TraceWarning) == SQLiteConnectionFlags.TraceWarning)
      {
          if (!uri && !fullUri && !isMemory && !String.IsNullOrEmpty(fileName) &&
              fileName.StartsWith("\\", StringComparison.OrdinalIgnoreCase) &&
              !fileName.StartsWith("\\\\", StringComparison.OrdinalIgnoreCase))
          {
              System.Diagnostics.Trace.WriteLine(String.Format(
              System.Diagnostics.Trace.WriteLine(UnsafeNativeMethods.StringFormat(
                  CultureInfo.CurrentCulture,
                  "WARNING: Detected a possibly malformed UNC database file name \"{0}\" that " +
                  "may have originally started with two backslashes; however, four leading " +
                  "backslashes may be required, e.g.: \"Data Source=\\\\\\{0};\"",
                  fileName));
          }
      }
2766
2767
2768
2769
2770
2771
2772
2773

2774
2775
2776
2777
2778
2779
2780
2778
2779
2780
2781
2782
2783
2784

2785
2786
2787
2788
2789
2790
2791
2792







-
+







        if (hexPassword != null)
        {
            string error = null;
            byte[] hexPasswordBytes = FromHexString(hexPassword, ref error);

            if (hexPasswordBytes == null)
            {
                throw new FormatException(String.Format(
                throw new FormatException(UnsafeNativeMethods.StringFormat(
                    CultureInfo.CurrentCulture,
                    "Cannot parse 'HexPassword' property value into byte values: {0}",
                    error));
            }

            _sql.SetPassword(hexPasswordBytes);
        }
2810
2811
2812
2813
2814
2815
2816
2817

2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829

2830
2831
2832
2833
2834
2835
2836
2837
2838

2839
2840
2841
2842
2843
2844
2845
2846

2847
2848
2849
2850
2851
2852
2853
2854

2855
2856
2857
2858
2859
2860
2861
2862

2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877

2878
2879
2880
2881
2882
2883
2884
2885

2886
2887
2888
2889
2890
2891
2892
2893

2894
2895
2896
2897
2898
2899
2900
2822
2823
2824
2825
2826
2827
2828

2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840

2841
2842
2843
2844
2845
2846
2847
2848
2849

2850
2851
2852
2853
2854
2855
2856
2857

2858
2859
2860
2861
2862
2863
2864
2865

2866
2867
2868
2869
2870
2871
2872
2873

2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888

2889
2890
2891
2892
2893
2894
2895
2896

2897
2898
2899
2900
2901
2902
2903
2904

2905
2906
2907
2908
2909
2910
2911
2912







-
+











-
+








-
+







-
+







-
+







-
+














-
+







-
+







-
+








          if (boolValue)
          {
              using (SQLiteCommand cmd = CreateCommand())
              {
                  if (_busyTimeout != DefaultBusyTimeout)
                  {
                      cmd.CommandText = String.Format(CultureInfo.InvariantCulture, "PRAGMA busy_timeout={0}", _busyTimeout);
                      cmd.CommandText = UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "PRAGMA busy_timeout={0}", _busyTimeout);
                      cmd.ExecuteNonQuery();
                  }

                  int intValue;

                  if (!fullUri && !isMemory)
                  {
                      strValue = FindKey(opts, "Page Size", DefaultPageSize.ToString());
                      intValue = Convert.ToInt32(strValue, CultureInfo.InvariantCulture);
                      if (intValue != DefaultPageSize)
                      {
                          cmd.CommandText = String.Format(CultureInfo.InvariantCulture, "PRAGMA page_size={0}", intValue);
                          cmd.CommandText = UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "PRAGMA page_size={0}", intValue);
                          cmd.ExecuteNonQuery();
                      }
                  }

                  strValue = FindKey(opts, "Max Page Count", DefaultMaxPageCount.ToString());
                  intValue = Convert.ToInt32(strValue, CultureInfo.InvariantCulture);
                  if (intValue != DefaultMaxPageCount)
                  {
                      cmd.CommandText = String.Format(CultureInfo.InvariantCulture, "PRAGMA max_page_count={0}", intValue);
                      cmd.CommandText = UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "PRAGMA max_page_count={0}", intValue);
                      cmd.ExecuteNonQuery();
                  }

                  strValue = FindKey(opts, "Legacy Format", DefaultLegacyFormat.ToString());
                  boolValue = SQLiteConvert.ToBoolean(strValue);
                  if (boolValue != DefaultLegacyFormat)
                  {
                      cmd.CommandText = String.Format(CultureInfo.InvariantCulture, "PRAGMA legacy_file_format={0}", boolValue ? "ON" : "OFF");
                      cmd.CommandText = UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "PRAGMA legacy_file_format={0}", boolValue ? "ON" : "OFF");
                      cmd.ExecuteNonQuery();
                  }

                  strValue = FindKey(opts, "Synchronous", DefaultSynchronous.ToString());
                  enumValue = TryParseEnum(typeof(SQLiteSynchronousEnum), strValue, true);
                  if (!(enumValue is SQLiteSynchronousEnum) || ((SQLiteSynchronousEnum)enumValue != DefaultSynchronous))
                  {
                      cmd.CommandText = String.Format(CultureInfo.InvariantCulture, "PRAGMA synchronous={0}", strValue);
                      cmd.CommandText = UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "PRAGMA synchronous={0}", strValue);
                      cmd.ExecuteNonQuery();
                  }

                  strValue = FindKey(opts, "Cache Size", DefaultCacheSize.ToString());
                  intValue = Convert.ToInt32(strValue, CultureInfo.InvariantCulture);
                  if (intValue != DefaultCacheSize)
                  {
                      cmd.CommandText = String.Format(CultureInfo.InvariantCulture, "PRAGMA cache_size={0}", intValue);
                      cmd.CommandText = UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "PRAGMA cache_size={0}", intValue);
                      cmd.ExecuteNonQuery();
                  }

                  strValue = FindKey(opts, "Journal Mode", DefaultJournalMode.ToString());
                  enumValue = TryParseEnum(typeof(SQLiteJournalModeEnum), strValue, true);
                  if (!(enumValue is SQLiteJournalModeEnum) || ((SQLiteJournalModeEnum)enumValue != DefaultJournalMode))
                  {
                      string pragmaStr = "PRAGMA journal_mode={0}";

#if INTEROP_INCLUDE_ZIPVFS
                      if (useZipVfs)
                          pragmaStr = "PRAGMA zipvfs_journal_mode={0}";
#endif

                      cmd.CommandText = String.Format(CultureInfo.InvariantCulture, pragmaStr, strValue);
                      cmd.CommandText = UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, pragmaStr, strValue);
                      cmd.ExecuteNonQuery();
                  }

                  strValue = FindKey(opts, "Foreign Keys", DefaultForeignKeys.ToString());
                  boolValue = SQLiteConvert.ToBoolean(strValue);
                  if (boolValue != DefaultForeignKeys)
                  {
                      cmd.CommandText = String.Format(CultureInfo.InvariantCulture, "PRAGMA foreign_keys={0}", boolValue ? "ON" : "OFF");
                      cmd.CommandText = UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "PRAGMA foreign_keys={0}", boolValue ? "ON" : "OFF");
                      cmd.ExecuteNonQuery();
                  }

                  strValue = FindKey(opts, "Recursive Triggers", DefaultRecursiveTriggers.ToString());
                  boolValue = SQLiteConvert.ToBoolean(strValue);
                  if (boolValue != DefaultRecursiveTriggers)
                  {
                      cmd.CommandText = String.Format(CultureInfo.InvariantCulture, "PRAGMA recursive_triggers={0}", boolValue ? "ON" : "OFF");
                      cmd.CommandText = UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "PRAGMA recursive_triggers={0}", boolValue ? "ON" : "OFF");
                      cmd.ExecuteNonQuery();
                  }
              }
          }

          if (_progressHandler != null)
              _sql.SetProgressHook(_progressOps, _progressCallback);
3421
3422
3423
3424
3425
3426
3427


3428

3429
3430
3431
3432
3433
3434
3435
3433
3434
3435
3436
3437
3438
3439
3440
3441

3442
3443
3444
3445
3446
3447
3448
3449







+
+
-
+







            {
                if (sourceId == null)
                    sourceId = "0000000000000000000000000000000000000000";

                if (sourceTimeStamp == null)
                    sourceTimeStamp = "0000-00-00 00:00:00 UTC";

                return UnsafeNativeMethods.StringFormat(
                    CultureInfo.InvariantCulture,
                return String.Format("{0} {1}", sourceId, sourceTimeStamp);
                    "{0} {1}", sourceId, sourceTimeStamp);
            }
            else
            {
                return null;
            }
        }
    }
3495
3496
3497
3498
3499
3500
3501
3502

3503
3504
3505
3506
3507
3508
3509
3509
3510
3511
3512
3513
3514
3515

3516
3517
3518
3519
3520
3521
3522
3523







-
+







            throw new InvalidOperationException("Database connection not valid for shutdown.");

        _sql.Close(true); /* NOTE: MUST be closed before shutdown. */
        SQLiteErrorCode rc = _sql.Shutdown();

#if !NET_COMPACT_20 && TRACE_CONNECTION
        if (rc != SQLiteErrorCode.Ok)
            System.Diagnostics.Trace.WriteLine(String.Format(
            System.Diagnostics.Trace.WriteLine(UnsafeNativeMethods.StringFormat(
                CultureInfo.CurrentCulture,
                "Shutdown (Instance) Failed: {0}", rc));
#endif

        return rc;
    }

3525
3526
3527
3528
3529
3530
3531
3532

3533
3534
3535
3536
3537
3538
3539
3539
3540
3541
3542
3543
3544
3545

3546
3547
3548
3549
3550
3551
3552
3553







-
+







        )
    {
        SQLiteErrorCode rc = SQLite3.StaticShutdown(directories);

        if (rc != SQLiteErrorCode.Ok)
        {
#if !NET_COMPACT_20 && TRACE_CONNECTION
            System.Diagnostics.Trace.WriteLine(String.Format(
            System.Diagnostics.Trace.WriteLine(UnsafeNativeMethods.StringFormat(
                CultureInfo.CurrentCulture,
                "Shutdown (Static) Failed: {0}", rc));
#endif

            if (!noThrow)
                throw new SQLiteException(rc, null);
        }
4109
4110
4111
4112
4113
4114
4115
4116

4117
4118
4119
4120
4121
4122
4123
4124
4125

4126
4127
4128
4129
4130
4131
4132
4123
4124
4125
4126
4127
4128
4129

4130
4131
4132
4133
4134
4135
4136
4137
4138

4139
4140
4141
4142
4143
4144
4145
4146







-
+








-
+








      tbl.BeginLoadData();

      if (String.IsNullOrEmpty(strCatalog)) strCatalog = "main";

      string master = (String.Compare(strCatalog, "temp", StringComparison.OrdinalIgnoreCase) == 0) ? _tempmasterdb : _masterdb;

      using (SQLiteCommand cmdTables = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'table' OR [type] LIKE 'view'", strCatalog, master), this))
      using (SQLiteCommand cmdTables = new SQLiteCommand(UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'table' OR [type] LIKE 'view'", strCatalog, master), this))
      using (SQLiteDataReader rdTables = cmdTables.ExecuteReader())
      {
        while (rdTables.Read())
        {
          if (String.IsNullOrEmpty(strTable) || String.Compare(strTable, rdTables.GetString(2), StringComparison.OrdinalIgnoreCase) == 0)
          {
            try
            {
              using (SQLiteCommand cmd = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}]", strCatalog, rdTables.GetString(2)), this))
              using (SQLiteCommand cmd = new SQLiteCommand(UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}]", strCatalog, rdTables.GetString(2)), this))
              using (SQLiteDataReader rd = (SQLiteDataReader)cmd.ExecuteReader(CommandBehavior.SchemaOnly))
              using (DataTable tblSchema = rd.GetSchemaTable(true, true))
              {
                foreach (DataRow schemaRow in tblSchema.Rows)
                {
                  if (String.Compare(schemaRow[SchemaTableColumn.ColumnName].ToString(), strColumn, StringComparison.OrdinalIgnoreCase) == 0
                    || strColumn == null)
4212
4213
4214
4215
4216
4217
4218
4219

4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232

4233
4234
4235
4236
4237
4238
4239
4226
4227
4228
4229
4230
4231
4232

4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245

4246
4247
4248
4249
4250
4251
4252
4253







-
+












-
+








      tbl.BeginLoadData();

      if (String.IsNullOrEmpty(strCatalog)) strCatalog = "main";

      string master = (String.Compare(strCatalog, "temp", StringComparison.OrdinalIgnoreCase) == 0) ? _tempmasterdb : _masterdb;

      using (SQLiteCommand cmdTables = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'table'", strCatalog, master), this))
      using (SQLiteCommand cmdTables = new SQLiteCommand(UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'table'", strCatalog, master), this))
      using (SQLiteDataReader rdTables = cmdTables.ExecuteReader())
      {
        while (rdTables.Read())
        {
          maybeRowId = false;
          primaryKeys.Clear();
          if (String.IsNullOrEmpty(strTable) || String.Compare(rdTables.GetString(2), strTable, StringComparison.OrdinalIgnoreCase) == 0)
          {
            // First, look for any rowid indexes -- which sqlite defines are INTEGER PRIMARY KEY columns.
            // Such indexes are not listed in the indexes list but count as indexes just the same.
            try
            {
              using (SQLiteCommand cmdTable = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "PRAGMA [{0}].table_info([{1}])", strCatalog, rdTables.GetString(2)), this))
              using (SQLiteCommand cmdTable = new SQLiteCommand(UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "PRAGMA [{0}].table_info([{1}])", strCatalog, rdTables.GetString(2)), this))
              using (SQLiteDataReader rdTable = cmdTable.ExecuteReader())
              {
                while (rdTable.Read())
                {
                  if (rdTable.GetInt32(5) != 0)
                  {
                    primaryKeys.Add(rdTable.GetInt32(0));
4252
4253
4254
4255
4256
4257
4258
4259

4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274

4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292

4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308

4309
4310
4311
4312
4313
4314
4315
4266
4267
4268
4269
4270
4271
4272

4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287

4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305

4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321

4322
4323
4324
4325
4326
4327
4328
4329







-
+














-
+

















-
+















-
+







            {
              row = tbl.NewRow();

              row["TABLE_CATALOG"] = strCatalog;
              row["TABLE_NAME"] = rdTables.GetString(2);
              row["INDEX_CATALOG"] = strCatalog;
              row["PRIMARY_KEY"] = true;
              row["INDEX_NAME"] = String.Format(CultureInfo.InvariantCulture, "{1}_PK_{0}", rdTables.GetString(2), master);
              row["INDEX_NAME"] = UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "{1}_PK_{0}", rdTables.GetString(2), master);
              row["UNIQUE"] = true;

              if (String.Compare((string)row["INDEX_NAME"], strIndex, StringComparison.OrdinalIgnoreCase) == 0
              || strIndex == null)
              {
                tbl.Rows.Add(row);
              }

              primaryKeys.Clear();
            }

            // Now fetch all the rest of the indexes.
            try
            {
              using (SQLiteCommand cmd = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "PRAGMA [{0}].index_list([{1}])", strCatalog, rdTables.GetString(2)), this))
              using (SQLiteCommand cmd = new SQLiteCommand(UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "PRAGMA [{0}].index_list([{1}])", strCatalog, rdTables.GetString(2)), this))
              using (SQLiteDataReader rd = (SQLiteDataReader)cmd.ExecuteReader())
              {
                while (rd.Read())
                {
                  if (String.Compare(rd.GetString(1), strIndex, StringComparison.OrdinalIgnoreCase) == 0
                  || strIndex == null)
                  {
                    row = tbl.NewRow();

                    row["TABLE_CATALOG"] = strCatalog;
                    row["TABLE_NAME"] = rdTables.GetString(2);
                    row["INDEX_CATALOG"] = strCatalog;
                    row["INDEX_NAME"] = rd.GetString(1);
                    row["UNIQUE"] = SQLiteConvert.ToBoolean(rd.GetValue(2), CultureInfo.InvariantCulture, false);
                    row["PRIMARY_KEY"] = false;

                    // get the index definition
                    using (SQLiteCommand cmdIndexes = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{2}] WHERE [type] LIKE 'index' AND [name] LIKE '{1}'", strCatalog, rd.GetString(1).Replace("'", "''"), master), this))
                    using (SQLiteCommand cmdIndexes = new SQLiteCommand(UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{2}] WHERE [type] LIKE 'index' AND [name] LIKE '{1}'", strCatalog, rd.GetString(1).Replace("'", "''"), master), this))
                    using (SQLiteDataReader rdIndexes = cmdIndexes.ExecuteReader())
                    {
                      while (rdIndexes.Read())
                      {
                        if (rdIndexes.IsDBNull(4) == false)
                          row["INDEX_DEFINITION"] = rdIndexes.GetString(4);
                        break;
                      }
                    }

                    // Now for the really hard work.  Figure out which index is the primary key index.
                    // The only way to figure it out is to check if the index was an autoindex and if we have a non-rowid
                    // primary key, and all the columns in the given index match the primary key columns
                    if (primaryKeys.Count > 0 && rd.GetString(1).StartsWith("sqlite_autoindex_" + rdTables.GetString(2), StringComparison.InvariantCultureIgnoreCase) == true)
                    {
                      using (SQLiteCommand cmdDetails = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "PRAGMA [{0}].index_info([{1}])", strCatalog, rd.GetString(1)), this))
                      using (SQLiteCommand cmdDetails = new SQLiteCommand(UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "PRAGMA [{0}].index_info([{1}])", strCatalog, rd.GetString(1)), this))
                      using (SQLiteDataReader rdDetails = cmdDetails.ExecuteReader())
                      {
                        int nMatches = 0;
                        while (rdDetails.Read())
                        {
                          if (primaryKeys.Contains(rdDetails.GetInt32(1)) == false)
                          {
4358
4359
4360
4361
4362
4363
4364
4365

4366
4367
4368
4369
4370
4371
4372
4372
4373
4374
4375
4376
4377
4378

4379
4380
4381
4382
4383
4384
4385
4386







-
+








      tbl.BeginLoadData();

      if (String.IsNullOrEmpty(table)) table = null;
      if (String.IsNullOrEmpty(catalog)) catalog = "main";
      string master = (String.Compare(catalog, "temp", StringComparison.OrdinalIgnoreCase) == 0) ? _tempmasterdb : _masterdb;

      using (SQLiteCommand cmd = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT [type], [name], [tbl_name], [rootpage], [sql], [rowid] FROM [{0}].[{1}] WHERE [type] LIKE 'trigger'", catalog, master), this))
      using (SQLiteCommand cmd = new SQLiteCommand(UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "SELECT [type], [name], [tbl_name], [rootpage], [sql], [rowid] FROM [{0}].[{1}] WHERE [type] LIKE 'trigger'", catalog, master), this))
      using (SQLiteDataReader rd = (SQLiteDataReader)cmd.ExecuteReader())
      {
        while (rd.Read())
        {
          if (String.Compare(rd.GetString(1), triggerName, StringComparison.OrdinalIgnoreCase) == 0
            || triggerName == null)
          {
4413
4414
4415
4416
4417
4418
4419
4420

4421
4422
4423
4424
4425
4426
4427
4427
4428
4429
4430
4431
4432
4433

4434
4435
4436
4437
4438
4439
4440
4441







-
+







      tbl.Columns.Add("TABLE_DEFINITION", typeof(string));
      tbl.BeginLoadData();

      if (String.IsNullOrEmpty(strCatalog)) strCatalog = "main";

      string master = (String.Compare(strCatalog, "temp", StringComparison.OrdinalIgnoreCase) == 0) ? _tempmasterdb : _masterdb;

      using (SQLiteCommand cmd = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT [type], [name], [tbl_name], [rootpage], [sql], [rowid] FROM [{0}].[{1}] WHERE [type] LIKE 'table'", strCatalog, master), this))
      using (SQLiteCommand cmd = new SQLiteCommand(UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "SELECT [type], [name], [tbl_name], [rootpage], [sql], [rowid] FROM [{0}].[{1}] WHERE [type] LIKE 'table'", strCatalog, master), this))
      using (SQLiteDataReader rd = (SQLiteDataReader)cmd.ExecuteReader())
      {
        while (rd.Read())
        {
          strItem = rd.GetString(0);
          if (String.Compare(rd.GetString(2), 0, "SQLITE_", 0, 7, StringComparison.OrdinalIgnoreCase) == 0)
            strItem = "SYSTEM_TABLE";
4479
4480
4481
4482
4483
4484
4485
4486

4487
4488
4489
4490
4491
4492
4493
4493
4494
4495
4496
4497
4498
4499

4500
4501
4502
4503
4504
4505
4506
4507







-
+








      tbl.BeginLoadData();

      if (String.IsNullOrEmpty(strCatalog)) strCatalog = "main";

      string master = (String.Compare(strCatalog, "temp", StringComparison.OrdinalIgnoreCase) == 0) ? _tempmasterdb : _masterdb;

      using (SQLiteCommand cmd = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'view'", strCatalog, master), this))
      using (SQLiteCommand cmd = new SQLiteCommand(UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'view'", strCatalog, master), this))
      using (SQLiteDataReader rd = (SQLiteDataReader)cmd.ExecuteReader())
      {
        while (rd.Read())
        {
          if (String.Compare(rd.GetString(1), strView, StringComparison.OrdinalIgnoreCase) == 0
            || String.IsNullOrEmpty(strView))
          {
4628
4629
4630
4631
4632
4633
4634
4635

4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646

4647
4648
4649
4650
4651
4652
4653
4642
4643
4644
4645
4646
4647
4648

4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659

4660
4661
4662
4663
4664
4665
4666
4667







-
+










-
+








      if (String.IsNullOrEmpty(strCatalog)) strCatalog = "main";

      string master = (String.Compare(strCatalog, "temp", StringComparison.OrdinalIgnoreCase) == 0) ? _tempmasterdb : _masterdb;

      tbl.BeginLoadData();

      using (SQLiteCommand cmdTables = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'table'", strCatalog, master), this))
      using (SQLiteCommand cmdTables = new SQLiteCommand(UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'table'", strCatalog, master), this))
      using (SQLiteDataReader rdTables = cmdTables.ExecuteReader())
      {
        while (rdTables.Read())
        {
          maybeRowId = false;
          primaryKeys.Clear();
          if (String.IsNullOrEmpty(strTable) || String.Compare(rdTables.GetString(2), strTable, StringComparison.OrdinalIgnoreCase) == 0)
          {
            try
            {
              using (SQLiteCommand cmdTable = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "PRAGMA [{0}].table_info([{1}])", strCatalog, rdTables.GetString(2)), this))
              using (SQLiteCommand cmdTable = new SQLiteCommand(UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "PRAGMA [{0}].table_info([{1}])", strCatalog, rdTables.GetString(2)), this))
              using (SQLiteDataReader rdTable = cmdTable.ExecuteReader())
              {
                while (rdTable.Read())
                {
                  if (rdTable.GetInt32(5) == 1) // is a primary key
                  {
                    primaryKeys.Add(new KeyValuePair<int, string>(rdTable.GetInt32(0), rdTable.GetString(1)));
4662
4663
4664
4665
4666
4667
4668
4669

4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683

4684
4685
4686
4687
4688
4689
4690
4691
4692
4693

4694
4695
4696
4697
4698
4699
4700
4676
4677
4678
4679
4680
4681
4682

4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696

4697
4698
4699
4700
4701
4702
4703
4704
4705
4706

4707
4708
4709
4710
4711
4712
4713
4714







-
+













-
+









-
+







            {
            }
            // This is a rowid row
            if (primaryKeys.Count == 1 && maybeRowId == true)
            {
              row = tbl.NewRow();
              row["CONSTRAINT_CATALOG"] = strCatalog;
              row["CONSTRAINT_NAME"] = String.Format(CultureInfo.InvariantCulture, "{1}_PK_{0}", rdTables.GetString(2), master);
              row["CONSTRAINT_NAME"] = UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "{1}_PK_{0}", rdTables.GetString(2), master);
              row["TABLE_CATALOG"] = strCatalog;
              row["TABLE_NAME"] = rdTables.GetString(2);
              row["COLUMN_NAME"] = primaryKeys[0].Value;
              row["INDEX_NAME"] = row["CONSTRAINT_NAME"];
              row["ORDINAL_POSITION"] = 0; // primaryKeys[0].Key;
              row["COLLATION_NAME"] = "BINARY";
              row["SORT_MODE"] = "ASC";
              row["CONFLICT_OPTION"] = 2;

              if (String.IsNullOrEmpty(strIndex) || String.Compare(strIndex, (string)row["INDEX_NAME"], StringComparison.OrdinalIgnoreCase) == 0)
                tbl.Rows.Add(row);
            }

            using (SQLiteCommand cmdIndexes = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{2}] WHERE [type] LIKE 'index' AND [tbl_name] LIKE '{1}'", strCatalog, rdTables.GetString(2).Replace("'", "''"), master), this))
            using (SQLiteCommand cmdIndexes = new SQLiteCommand(UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{2}] WHERE [type] LIKE 'index' AND [tbl_name] LIKE '{1}'", strCatalog, rdTables.GetString(2).Replace("'", "''"), master), this))
            using (SQLiteDataReader rdIndexes = cmdIndexes.ExecuteReader())
            {
              while (rdIndexes.Read())
              {
                int ordinal = 0;
                if (String.IsNullOrEmpty(strIndex) || String.Compare(strIndex, rdIndexes.GetString(1), StringComparison.OrdinalIgnoreCase) == 0)
                {
                  try
                  {
                    using (SQLiteCommand cmdIndex = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "PRAGMA [{0}].index_info([{1}])", strCatalog, rdIndexes.GetString(1)), this))
                    using (SQLiteCommand cmdIndex = new SQLiteCommand(UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "PRAGMA [{0}].index_info([{1}])", strCatalog, rdIndexes.GetString(1)), this))
                    using (SQLiteDataReader rdIndex = cmdIndex.ExecuteReader())
                    {
                      while (rdIndex.Read())
                      {
                        row = tbl.NewRow();
                        row["CONSTRAINT_CATALOG"] = strCatalog;
                        row["CONSTRAINT_NAME"] = rdIndexes.GetString(1);
4786
4787
4788
4789
4790
4791
4792
4793

4794
4795
4796
4797
4798
4799
4800

4801
4802
4803
4804
4805
4806
4807
4800
4801
4802
4803
4804
4805
4806

4807
4808
4809
4810
4811
4812
4813

4814
4815
4816
4817
4818
4819
4820
4821







-
+






-
+








      if (String.IsNullOrEmpty(strCatalog)) strCatalog = "main";

      string master = (String.Compare(strCatalog, "temp", StringComparison.OrdinalIgnoreCase) == 0) ? _tempmasterdb : _masterdb;

      tbl.BeginLoadData();

      using (SQLiteCommand cmdViews = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'view'", strCatalog, master), this))
      using (SQLiteCommand cmdViews = new SQLiteCommand(UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'view'", strCatalog, master), this))
      using (SQLiteDataReader rdViews = cmdViews.ExecuteReader())
      {
        while (rdViews.Read())
        {
          if (String.IsNullOrEmpty(strView) || String.Compare(strView, rdViews.GetString(2), StringComparison.OrdinalIgnoreCase) == 0)
          {
            using (SQLiteCommand cmdViewSelect = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}]", strCatalog, rdViews.GetString(2)), this))
            using (SQLiteCommand cmdViewSelect = new SQLiteCommand(UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}]", strCatalog, rdViews.GetString(2)), this))
            {
              strSql = rdViews.GetString(4).Replace('\r', ' ').Replace('\n', ' ').Replace('\t', ' ');
              n = CultureInfo.InvariantCulture.CompareInfo.IndexOf(strSql, " AS ", CompareOptions.IgnoreCase);
              if (n < 0)
                continue;

              strSql = strSql.Substring(n + 4);
4891
4892
4893
4894
4895
4896
4897
4898

4899
4900
4901
4902
4903
4904
4905
4906
4907
4908

4909
4910
4911
4912
4913
4914
4915

4916
4917
4918
4919
4920
4921
4922
4905
4906
4907
4908
4909
4910
4911

4912
4913
4914
4915
4916
4917
4918
4919
4920
4921

4922
4923
4924
4925
4926
4927
4928

4929
4930
4931
4932
4933
4934
4935
4936







-
+









-
+






-
+








      if (String.IsNullOrEmpty(strCatalog)) strCatalog = "main";

      string master = (String.Compare(strCatalog, "temp", StringComparison.OrdinalIgnoreCase) == 0) ? _tempmasterdb : _masterdb;

      tbl.BeginLoadData();

      using (SQLiteCommand cmdTables = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'table'", strCatalog, master), this))
      using (SQLiteCommand cmdTables = new SQLiteCommand(UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'table'", strCatalog, master), this))
      using (SQLiteDataReader rdTables = cmdTables.ExecuteReader())
      {
        while (rdTables.Read())
        {
          if (String.IsNullOrEmpty(strTable) || String.Compare(strTable, rdTables.GetString(2), StringComparison.OrdinalIgnoreCase) == 0)
          {
            try
            {
              using (SQLiteCommandBuilder builder = new SQLiteCommandBuilder())
              using (SQLiteCommand cmdKey = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "PRAGMA [{0}].foreign_key_list([{1}])", strCatalog, rdTables.GetString(2)), this))
              using (SQLiteCommand cmdKey = new SQLiteCommand(UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "PRAGMA [{0}].foreign_key_list([{1}])", strCatalog, rdTables.GetString(2)), this))
              using (SQLiteDataReader rdKey = cmdKey.ExecuteReader())
              {
                while (rdKey.Read())
                {
                  row = tbl.NewRow();
                  row["CONSTRAINT_CATALOG"] = strCatalog;
                  row["CONSTRAINT_NAME"] = String.Format(CultureInfo.InvariantCulture, "FK_{0}_{1}_{2}", rdTables[2], rdKey.GetInt32(0), rdKey.GetInt32(1));
                  row["CONSTRAINT_NAME"] = UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "FK_{0}_{1}_{2}", rdTables[2], rdKey.GetInt32(0), rdKey.GetInt32(1));
                  row["TABLE_CATALOG"] = strCatalog;
                  row["TABLE_NAME"] = builder.UnquoteIdentifier(rdTables.GetString(2));
                  row["CONSTRAINT_TYPE"] = "FOREIGN KEY";
                  row["IS_DEFERRABLE"] = false;
                  row["INITIALLY_DEFERRED"] = false;
                  row["FKEY_ID"] = rdKey[0];
                  row["FKEY_FROM_COLUMN"] = builder.UnquoteIdentifier(rdKey[3].ToString());
5062
5063
5064
5065
5066
5067
5068
5069

5070
5071
5072
5073
5074
5075
5076
5076
5077
5078
5079
5080
5081
5082

5083
5084
5085
5086
5087
5088
5089
5090







-
+







        {
            try
            {
                if ((_flags & SQLiteConnectionFlags.LogCallbackException) ==
                        SQLiteConnectionFlags.LogCallbackException)
                {
                    SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
                        String.Format(CultureInfo.CurrentCulture,
                        UnsafeNativeMethods.StringFormat(CultureInfo.CurrentCulture,
                        "Caught exception in \"Progress\" method: {1}",
                        e)); /* throw */
                }
            }
            catch
            {
                // do nothing.
5115
5116
5117
5118
5119
5120
5121
5122

5123
5124
5125
5126
5127
5128
5129
5129
5130
5131
5132
5133
5134
5135

5136
5137
5138
5139
5140
5141
5142
5143







-
+







        {
            try
            {
                if ((_flags & SQLiteConnectionFlags.LogCallbackException) ==
                        SQLiteConnectionFlags.LogCallbackException)
                {
                    SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
                        String.Format(CultureInfo.CurrentCulture,
                        UnsafeNativeMethods.StringFormat(CultureInfo.CurrentCulture,
                        "Caught exception in \"Authorize\" method: {1}",
                        e)); /* throw */
                }
            }
            catch
            {
                // do nothing.
5164
5165
5166
5167
5168
5169
5170
5171

5172
5173
5174
5175
5176
5177
5178
5178
5179
5180
5181
5182
5183
5184

5185
5186
5187
5188
5189
5190
5191
5192







-
+







        {
            try
            {
                if ((_flags & SQLiteConnectionFlags.LogCallbackException) ==
                        SQLiteConnectionFlags.LogCallbackException)
                {
                    SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
                        String.Format(CultureInfo.CurrentCulture,
                        UnsafeNativeMethods.StringFormat(CultureInfo.CurrentCulture,
                        "Caught exception in \"Update\" method: {1}",
                        e)); /* throw */
                }
            }
            catch
            {
                // do nothing.
5255
5256
5257
5258
5259
5260
5261
5262

5263
5264
5265
5266
5267
5268
5269
5269
5270
5271
5272
5273
5274
5275

5276
5277
5278
5279
5280
5281
5282
5283







-
+







        {
            try
            {
                if ((_flags & SQLiteConnectionFlags.LogCallbackException) ==
                        SQLiteConnectionFlags.LogCallbackException)
                {
                    SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
                        String.Format(CultureInfo.CurrentCulture,
                        UnsafeNativeMethods.StringFormat(CultureInfo.CurrentCulture,
                        "Caught exception in \"Trace\" method: {1}",
                        e)); /* throw */
                }
            }
            catch
            {
                // do nothing.
5317
5318
5319
5320
5321
5322
5323
5324

5325
5326
5327
5328
5329
5330
5331
5331
5332
5333
5334
5335
5336
5337

5338
5339
5340
5341
5342
5343
5344
5345







-
+







        {
            try
            {
                if ((_flags & SQLiteConnectionFlags.LogCallbackException) ==
                        SQLiteConnectionFlags.LogCallbackException)
                {
                    SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
                        String.Format(CultureInfo.CurrentCulture,
                        UnsafeNativeMethods.StringFormat(CultureInfo.CurrentCulture,
                        "Caught exception in \"Commit\" method: {1}",
                        e)); /* throw */
                }
            }
            catch
            {
                // do nothing.
5359
5360
5361
5362
5363
5364
5365
5366

5367
5368
5369
5370
5371
5372
5373
5373
5374
5375
5376
5377
5378
5379

5380
5381
5382
5383
5384
5385
5386
5387







-
+







        {
            try
            {
                if ((_flags & SQLiteConnectionFlags.LogCallbackException) ==
                        SQLiteConnectionFlags.LogCallbackException)
                {
                    SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
                        String.Format(CultureInfo.CurrentCulture,
                        UnsafeNativeMethods.StringFormat(CultureInfo.CurrentCulture,
                        "Caught exception in \"Rollback\" method: {1}",
                        e)); /* throw */
                }
            }
            catch
            {
                // do nothing.
Changes to System.Data.SQLite/SQLiteConvert.cs.
1148
1149
1150
1151
1152
1153
1154
1155

1156
1157
1158
1159
1160
1161
1162
1148
1149
1150
1151
1152
1153
1154

1155
1156
1157
1158
1159
1160
1161
1162







-
+







            case TypeCode.Decimal:
                return ((decimal)obj) != Decimal.Zero ? true : false;
            case TypeCode.String:
                return viaFramework ?
                    Convert.ToBoolean(obj, provider) :
                    ToBoolean(ToStringWithProvider(obj, provider));
            default:
                throw new SQLiteException(String.Format(
                throw new SQLiteException(UnsafeNativeMethods.StringFormat(
                    CultureInfo.CurrentCulture,
                    "Cannot convert type {0} to boolean",
                    typeCode));
        }
    }

    /// <summary>
1439
1440
1441
1442
1443
1444
1445
1446

1447
1448
1449
1450
1451
1452
1453
1439
1440
1441
1442
1443
1444
1445

1446
1447
1448
1449
1450
1451
1452
1453







-
+







        DbType dbType,
        SQLiteConnectionFlags flags,
        string typeName
        )
    {
        if ((flags & SQLiteConnectionFlags.TraceWarning) == SQLiteConnectionFlags.TraceWarning)
        {
            Trace.WriteLine(String.Format(
            Trace.WriteLine(UnsafeNativeMethods.StringFormat(
                CultureInfo.CurrentCulture,
                "WARNING: Type mapping failed, returning default name \"{0}\" for type {1}.",
                typeName, dbType));
        }
    }

    /// <summary>
1468
1469
1470
1471
1472
1473
1474
1475

1476
1477
1478
1479
1480
1481
1482
1468
1469
1470
1471
1472
1473
1474

1475
1476
1477
1478
1479
1480
1481
1482







-
+







        SQLiteConnectionFlags flags,
        DbType? dbType
        )
    {
        if (!String.IsNullOrEmpty(typeName) &&
            ((flags & SQLiteConnectionFlags.TraceWarning) == SQLiteConnectionFlags.TraceWarning))
        {
            Trace.WriteLine(String.Format(
            Trace.WriteLine(UnsafeNativeMethods.StringFormat(
                CultureInfo.CurrentCulture,
                "WARNING: Type mapping failed, returning default type {0} for name \"{1}\".",
                dbType, typeName));
        }
    }
#endif

Changes to System.Data.SQLite/SQLiteDataReader.cs.
1076
1077
1078
1079
1080
1081
1082
1083

1084
1085
1086
1087
1088
1089
1090
1076
1077
1078
1079
1080
1081
1082

1083
1084
1085
1086
1087
1088
1089
1090







-
+







              }
            }
          }

          if (wantDefaultValue)
          {
            // Determine the default value for the column, which sucks because we have to query the schema for each column
            using (SQLiteCommand cmdTable = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "PRAGMA [{0}].TABLE_INFO([{1}])",
            using (SQLiteCommand cmdTable = new SQLiteCommand(UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "PRAGMA [{0}].TABLE_INFO([{1}])",
              row[SchemaTableOptionalColumn.BaseCatalogName],
              row[SchemaTableColumn.BaseTableName]
              ), _command.Connection))
            using (DbDataReader rdTable = cmdTable.ExecuteReader())
            {
              // Find the matching column
              while (rdTable.Read())
Changes to System.Data.SQLite/SQLiteEnlistment.cs.
92
93
94
95
96
97
98
99

100
101
102
103
104
105
106
92
93
94
95
96
97
98

99
100
101
102
103
104
105
106







-
+







        // NOTE: When in "strict" mode, throw an exception if the isolation
        //       level is not recognized; otherwise, fallback to the default
        //       isolation level specified by the caller.
        //
        if (throwOnUnsupported)
        {
            throw new InvalidOperationException(
                String.Format(CultureInfo.InvariantCulture,
                UnsafeNativeMethods.StringFormat(CultureInfo.CurrentCulture,
                "unsupported isolation level {0}", isolationLevel));
        }

        return defaultIsolationLevel;
    }

    ///////////////////////////////////////////////////////////////////////////
Changes to System.Data.SQLite/SQLiteException.cs.
1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19











+







/********************************************************
 * ADO.NET 2.0 Data Provider for SQLite Version 3.X
 * Written by Robert Simpson (robert@blackcastlesoft.com)
 *
 * Released to the public domain, use at your own risk!
 ********************************************************/

namespace System.Data.SQLite
{
  using System;
  using System.Data.Common;
  using System.Globalization;

#if !PLATFORM_COMPACTFRAMEWORK
  using System.Reflection;
  using System.Runtime.Serialization;
  using System.Security.Permissions;
#endif

178
179
180
181
182
183
184


185

186
187
188
189
190
191
192
179
180
181
182
183
184
185
186
187

188
189
190
191
192
193
194
195







+
+
-
+







    /// <param name="message">Optional detailed error message.</param>
    /// <returns>Error message text for the return code.</returns>
    private static string GetStockErrorMessage(
        SQLiteErrorCode errorCode,
        string message
        )
    {
        return UnsafeNativeMethods.StringFormat(
            CultureInfo.CurrentCulture,
        return String.Format("{0}{1}{2}",
            "{0}{1}{2}",
            GetErrorString(errorCode),
#if !NET_COMPACT_20
            Environment.NewLine, message).Trim();
#else
            "\r\n", message).Trim();
#endif
    }
Changes to System.Data.SQLite/SQLiteFunction.cs.
413
414
415
416
417
418
419
420

421
422
423
424
425
426
427
413
414
415
416
417
418
419

420
421
422
423
424
425
426
427







-
+







        {
            try
            {
                if ((_flags & SQLiteConnectionFlags.LogCallbackException) ==
                        SQLiteConnectionFlags.LogCallbackException)
                {
                    SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
                        String.Format(CultureInfo.CurrentCulture,
                        UnsafeNativeMethods.StringFormat(CultureInfo.CurrentCulture,
                        "Caught exception in \"Invoke\" method: {0}",
                        e)); /* throw */
                }
            }
            catch
            {
                // do nothing.
451
452
453
454
455
456
457
458

459
460
461
462
463
464
465
451
452
453
454
455
456
457

458
459
460
461
462
463
464
465







-
+







        {
            try
            {
                if ((_flags & SQLiteConnectionFlags.LogCallbackException) ==
                        SQLiteConnectionFlags.LogCallbackException)
                {
                    SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
                        String.Format(CultureInfo.CurrentCulture,
                        UnsafeNativeMethods.StringFormat(CultureInfo.CurrentCulture,
                        "Caught exception in \"Compare\" (UTF8) method: {0}",
                        e)); /* throw */
                }
            }
            catch
            {
                // do nothing.
498
499
500
501
502
503
504
505

506
507
508
509
510
511
512
498
499
500
501
502
503
504

505
506
507
508
509
510
511
512







-
+







        {
            try
            {
                if ((_flags & SQLiteConnectionFlags.LogCallbackException) ==
                        SQLiteConnectionFlags.LogCallbackException)
                {
                    SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
                        String.Format(CultureInfo.CurrentCulture,
                        UnsafeNativeMethods.StringFormat(CultureInfo.CurrentCulture,
                        "Caught exception in \"Compare\" (UTF16) method: {0}",
                        e)); /* throw */
                }
            }
            catch
            {
                // do nothing.
571
572
573
574
575
576
577
578

579
580
581
582
583
584
585
571
572
573
574
575
576
577

578
579
580
581
582
583
584
585







-
+







        {
            try
            {
                if ((_flags & SQLiteConnectionFlags.LogCallbackException) ==
                        SQLiteConnectionFlags.LogCallbackException)
                {
                    SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
                        String.Format(CultureInfo.CurrentCulture,
                        UnsafeNativeMethods.StringFormat(CultureInfo.CurrentCulture,
                        "Caught exception in \"Step\" method: {1}",
                        e)); /* throw */
                }
            }
            catch
            {
                // do nothing.
626
627
628
629
630
631
632
633

634
635
636
637
638
639
640
626
627
628
629
630
631
632

633
634
635
636
637
638
639
640







-
+







        {
            try
            {
                if ((_flags & SQLiteConnectionFlags.LogCallbackException) ==
                        SQLiteConnectionFlags.LogCallbackException)
                {
                    SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
                        String.Format(CultureInfo.CurrentCulture,
                        UnsafeNativeMethods.StringFormat(CultureInfo.CurrentCulture,
                        "Caught exception in \"Final\" method: {1}",
                        e)); /* throw */
                }
            }
            catch
            {
                // do nothing.
Changes to System.Data.SQLite/SQLiteFunctionAttribute.cs.
Changes to System.Data.SQLite/SQLiteKeyReader.cs.
54
55
56
57
58
59
60
61

62
63
64
65
66
67
68
54
55
56
57
58
59
60

61
62
63
64
65
66
67
68







-
+







            {
                _command = cnn.CreateCommand();
                for (int n = 0; n < columns.Length; n++)
                {
                    columns[n] = builder.QuoteIdentifier(columns[n]);
                }
            }
            _command.CommandText = String.Format(CultureInfo.InvariantCulture, "SELECT {0} FROM [{1}].[{2}] WHERE ROWID = ?", String.Join(",", columns), database, table);
            _command.CommandText = UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, "SELECT {0} FROM [{1}].[{2}] WHERE ROWID = ?", String.Join(",", columns), database, table);
            _command.Parameters.AddWithValue(null, (long)0);
        }

        internal bool IsValid
        {
            set
            {
Changes to System.Data.SQLite/SQLiteLog.cs.
100
101
102
103
104
105
106
107

108
109
110
111
112
113
114
100
101
102
103
104
105
106

107
108
109
110
111
112
113
114







-
+







        /// <summary>
        /// The default log event handler.
        /// </summary>
        private static SQLiteLogEventHandler _defaultHandler;

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

#if !INTEROP_LOG
#if !USE_INTEROP_DLL || !INTEROP_LOG
        /// <summary>
        /// The log callback passed to native SQLite engine.  This must live
        /// as long as the SQLite library has a pointer to it.
        /// </summary>
        private static SQLiteLogCallback _callback;

        ///////////////////////////////////////////////////////////////////////
174
175
176
177
178
179
180
181

182
183
184
185
186
187
188
174
175
176
177
178
179
180

181
182
183
184
185
186
187
188







-
+







                if (_domainUnload == null)
                {
                    _domainUnload = new EventHandler(DomainUnload);
                    AppDomain.CurrentDomain.DomainUnload += _domainUnload;
                }
#endif

#if !INTEROP_LOG
#if !USE_INTEROP_DLL || !INTEROP_LOG
                //
                // NOTE: Create an instance of the SQLite wrapper class.
                //
                if (_sql == null)
                {
                    _sql = new SQLite3(
                        SQLiteDateFormats.Default, DateTimeKind.Unspecified,
241
242
243
244
245
246
247
248

249
250
251
252
253
254
255
241
242
243
244
245
246
247

248
249
250
251
252
253
254
255







-
+








                //
                // NOTE: Disable logging.  If necessary, it can be re-enabled
                //       later by the Initialize method.
                //
                _enabled = false;

#if !INTEROP_LOG
#if !USE_INTEROP_DLL || !INTEROP_LOG
                //
                // BUGBUG: This will cause serious problems if other AppDomains
                //         have any open SQLite connections; however, there is
                //         currently no way around this limitation.
                //
                if (_sql != null)
                {
555
556
557
558
559
560
561
562

563
564
565
566
567
568

569
570
571
572
573
574
575
555
556
557
558
559
560
561

562
563
564
565
566
567

568
569
570
571
572
573
574
575







-
+





-
+







            {
                type = "trace";
            }

            if ((errorCode != null) &&
                !Object.ReferenceEquals(errorCode, String.Empty))
            {
                Trace.WriteLine(String.Format(
                Trace.WriteLine(UnsafeNativeMethods.StringFormat(
                    CultureInfo.CurrentCulture, "SQLite {0} ({1}): {2}",
                    type, errorCode, message));
            }
            else
            {
                Trace.WriteLine(String.Format(
                Trace.WriteLine(UnsafeNativeMethods.StringFormat(
                    CultureInfo.CurrentCulture, "SQLite {0}: {1}",
                    type, message));
            }
#endif
        }
    }
}
Changes to System.Data.SQLite/SQLiteModule.cs.
6163
6164
6165
6166
6167
6168
6169

6170

6171
6172
6173
6174
6175
6176
6177
6163
6164
6165
6166
6167
6168
6169
6170

6171
6172
6173
6174
6175
6176
6177
6178







+
-
+







                //
                try
                {
                    if (LogExceptionsNoThrow)
                    {
                        /* throw */
                        SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
                            UnsafeNativeMethods.StringFormat(
                            String.Format(CultureInfo.CurrentCulture,
                            CultureInfo.CurrentCulture,
                            "Caught exception in \"{0}\" method: {1}",
                            destroy ? "xDestroy" : "xDisconnect", e));
                    }
                }
                catch
                {
                    // do nothing.
6222
6223
6224
6225
6226
6227
6228

6229

6230
6231
6232
6233
6234
6235
6236
6223
6224
6225
6226
6227
6228
6229
6230

6231
6232
6233
6234
6235
6236
6237
6238







+
-
+







            )
        {
            try
            {
                if (logErrors)
                {
                    SQLiteLog.LogMessage(SQLiteErrorCode.Error,
                        UnsafeNativeMethods.StringFormat(
                        String.Format(CultureInfo.CurrentCulture,
                        CultureInfo.CurrentCulture,
                        "Virtual table error: {0}", error)); /* throw */
                }
            }
            catch
            {
                // do nothing.
            }
6269
6270
6271
6272
6273
6274
6275

6276

6277
6278
6279
6280
6281
6282
6283
6271
6272
6273
6274
6275
6276
6277
6278

6279
6280
6281
6282
6283
6284
6285
6286







+
-
+







            catch (Exception e) /* NOTE: Must catch ALL. */
            {
                try
                {
                    if (logExceptions)
                    {
                        SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
                            UnsafeNativeMethods.StringFormat(
                            String.Format(CultureInfo.CurrentCulture,
                            CultureInfo.CurrentCulture,
                            "Caught exception in \"SetTableError\" method: {0}",
                            e)); /* throw */
                    }
                }
                catch
                {
                    // do nothing.
6670
6671
6672
6673
6674
6675
6676
6677

6678
6679
6680
6681
6682
6683
6684
6673
6674
6675
6676
6677
6678
6679

6680
6681
6682
6683
6684
6685
6686
6687







-
+








            if ((tables != null) &&
                tables.TryGetValue(pVtab, out table))
            {
                return table;
            }

            SetTableError(pVtab, String.Format(
            SetTableError(pVtab, UnsafeNativeMethods.StringFormat(
                CultureInfo.CurrentCulture,
                "managed table for {0} not found", pVtab));

            return null;
        }

        ///////////////////////////////////////////////////////////////////////
6764
6765
6766
6767
6768
6769
6770
6771

6772
6773
6774
6775
6776
6777
6778
6767
6768
6769
6770
6771
6772
6773

6774
6775
6776
6777
6778
6779
6780
6781







-
+








            if ((cursors != null) &&
                cursors.TryGetValue(pCursor, out cursor))
            {
                return cursor;
            }

            SetTableError(pVtab, String.Format(
            SetTableError(pVtab, UnsafeNativeMethods.StringFormat(
                CultureInfo.CurrentCulture,
                "managed cursor for {0} not found", pCursor));

            return null;
        }

        ///////////////////////////////////////////////////////////////////////
6850
6851
6852
6853
6854
6855
6856


6857

6858
6859
6860
6861
6862
6863
6864
6853
6854
6855
6856
6857
6858
6859
6860
6861

6862
6863
6864
6865
6866
6867
6868
6869







+
+
-
+







        /// </returns>
        protected virtual string GetFunctionKey(
            int argumentCount,
            string name,
            SQLiteFunction function
            )
        {
            return UnsafeNativeMethods.StringFormat(
                CultureInfo.InvariantCulture,
            return String.Format("{0}:{1}", argumentCount, name);
                "{0}:{1}", argumentCount, name);
        }
        #endregion

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

        #region Table Declaration Helper Methods
        /// <summary>
8675
8676
8677
8678
8679
8680
8681

8682

8683
8684
8685
8686
8687
8688
8689
8680
8681
8682
8683
8684
8685
8686
8687

8688
8689
8690
8691
8692
8693
8694
8695







+
-
+







                catch (Exception e)
                {
                    try
                    {
                        if (LogExceptionsNoThrow)
                        {
                            SQLiteLog.LogMessage(SQLiteBase.COR_E_EXCEPTION,
                                UnsafeNativeMethods.StringFormat(
                                String.Format(CultureInfo.CurrentCulture,
                                CultureInfo.CurrentCulture,
                                "Caught exception in \"Dispose\" method: {0}",
                                e)); /* throw */
                        }
                    }
                    catch
                    {
                        // do nothing.
Changes to System.Data.SQLite/SQLiteModuleCommon.cs.
19
20
21
22
23
24
25
26
27
28




29
30
31
32
33
34
35
19
20
21
22
23
24
25



26
27
28
29
30
31
32
33
34
35
36







-
-
-
+
+
+
+







    public class SQLiteModuleCommon : SQLiteModuleNoop /* NOT SEALED */
    {
        #region Private Constants
        /// <summary>
        /// The CREATE TABLE statement used to declare the schema for the
        /// virtual table.
        /// </summary>
        private static readonly string declareSql = String.Format(
            CultureInfo.CurrentCulture, "CREATE TABLE {0}(x);",
            typeof(SQLiteModuleCommon).Name);
        private static readonly string declareSql =
            UnsafeNativeMethods.StringFormat(
                CultureInfo.InvariantCulture, "CREATE TABLE {0}(x);",
                typeof(SQLiteModuleCommon).Name);
        #endregion

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

        #region Private Data
        /// <summary>
        /// Non-zero if different object instances with the same value should
114
115
116
117
118
119
120
121
122



123
124
125
126
127
128
129
115
116
117
118
119
120
121


122
123
124
125
126
127
128
129
130
131







-
-
+
+
+







        protected virtual SQLiteErrorCode CursorTypeMismatchError(
            SQLiteVirtualTableCursor cursor,
            Type type
            )
        {
            if (type != null)
            {
                SetCursorError(cursor,
                    String.Format("not a \"{0}\" cursor", type));
                SetCursorError(cursor, UnsafeNativeMethods.StringFormat(
                    CultureInfo.CurrentCulture, "not a \"{0}\" cursor",
                    type));
            }
            else
            {
                SetCursorError(cursor, "cursor type mismatch");
            }

            return SQLiteErrorCode.Error;
Changes to System.Data.SQLite/SQLiteModuleEnumerable.cs.
499
500
501
502
503
504
505

506

507
508
509
510
511
512
513
499
500
501
502
503
504
505
506

507
508
509
510
511
512
513
514







+
-
+







            SQLiteIndex index
            )
        {
            CheckDisposed();

            if (!table.BestIndex(index))
            {
                SetTableError(table, UnsafeNativeMethods.StringFormat(
                SetTableError(table, String.Format(CultureInfo.CurrentCulture,
                    CultureInfo.CurrentCulture,
                    "failed to select best index for virtual table \"{0}\"",
                    table.TableName));

                return SQLiteErrorCode.Error;
            }

            return SQLiteErrorCode.Ok;
826
827
828
829
830
831
832

833

834
835
836
837
838
839
840
827
828
829
830
831
832
833
834

835
836
837
838
839
840
841
842







+
-
+







            SQLiteVirtualTable table,
            SQLiteValue[] values,
            ref long rowId
            )
        {
            CheckDisposed();

            SetTableError(table, UnsafeNativeMethods.StringFormat(
            SetTableError(table, String.Format(CultureInfo.CurrentCulture,
                CultureInfo.CurrentCulture,
                "virtual table \"{0}\" is read-only", table.TableName));

            return SQLiteErrorCode.Error;
        }

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

855
856
857
858
859
860
861

862

863
864
865
866
867
868
869
857
858
859
860
861
862
863
864

865
866
867
868
869
870
871
872







+
-
+







            string newName
            )
        {
            CheckDisposed();

            if (!table.Rename(newName))
            {
                SetTableError(table, UnsafeNativeMethods.StringFormat(
                SetTableError(table, String.Format(CultureInfo.CurrentCulture,
                    CultureInfo.CurrentCulture,
                    "failed to rename virtual table from \"{0}\" to \"{1}\"",
                    table.TableName, newName));

                return SQLiteErrorCode.Error;
            }

            return SQLiteErrorCode.Ok;
Changes to System.Data.SQLite/SQLiteParameterCollection.cs.
423
424
425
426
427
428
429
430

431
432
433
434
435
436
437
423
424
425
426
427
428
429

430
431
432
433
434
435
436
437







-
+








      foreach(SQLiteParameter p in _parameterList)
      {
        y ++;
        s = p.ParameterName;
        if (s == null)
        {
          s = String.Format(CultureInfo.InvariantCulture, ";{0}", nUnnamed);
          s = UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, ";{0}", nUnnamed);
          nUnnamed++;
        }

        int x;
        bool isMapped = false;

        if (activeStatement == null)
452
453
454
455
456
457
458
459

460
461
462
463
464
465
466
452
453
454
455
456
457
458

459
460
461
462
463
464
465
466







-
+







          stmt = null;
        }

        // If the parameter has a name, but the SQL statement uses unnamed references, this can happen -- attempt to map
        // the parameter by its index in the collection
        if (isMapped == false)
        {
          s = String.Format(CultureInfo.InvariantCulture, ";{0}", y);
          s = UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, ";{0}", y);

          stmt = activeStatement;
          for (n = 0; n < x; n++)
          {
            if (stmt == null) stmt = _command._statementList[n];
            if (stmt._paramNames != null)
            {
Changes to System.Data.SQLite/SQLiteStatement.cs.
1
2
3
4

5
6
7
8
9
10
11
1
2
3

4
5
6
7
8
9
10
11



-
+







/********************************************************
 * ADO.NET 2.0 Data Provider for SQLite Version 3.X
 * Written by Robert Simpson (robert@blackcastlesoft.com)
 * 
 *
 * Released to the public domain, use at your own risk!
 ********************************************************/

namespace System.Data.SQLite
{
  using System;
  using System.Globalization;
81
82
83
84
85
86
87
88

89
90
91
92
93
94
95
81
82
83
84
85
86
87

88
89
90
91
92
93
94
95







-
+







        _paramValues = new SQLiteParameter[n];

        for (x = 0; x < n; x++)
        {
          s = _sql.Bind_ParamName(this, _flags, x + 1);
          if (String.IsNullOrEmpty(s))
          {
            s = String.Format(CultureInfo.InvariantCulture, ";{0}", nCmdStart);
            s = UnsafeNativeMethods.StringFormat(CultureInfo.InvariantCulture, ";{0}", nCmdStart);
            nCmdStart++;
            _unnamedParameters++;
          }
          _paramNames[x] = s;
          _paramValues[x] = null;
        }
      }
200
201
202
203
204
205
206
207

208
209
210
211
212
213
214
200
201
202
203
204
205
206

207
208
209
210
211
212
213
214







-
+







    /// this statement, and if so, keeps a reference to the parameter so it can be bound later.
    /// </summary>
    /// <param name="s">The parameter name to map</param>
    /// <param name="p">The parameter to assign it</param>
    internal bool MapParameter(string s, SQLiteParameter p)
    {
      if (_paramNames == null) return false;
      

      int startAt = 0;
      if (s.Length > 0)
      {
        if (":$@;".IndexOf(s[0]) == -1)
          startAt = 1;
      }

254
255
256
257
258
259
260
261


262
263
264
265
266
267
268
254
255
256
257
258
259
260

261
262
263
264
265
266
267
268
269







-
+
+







      if ((obj != null) && (objType == DbType.Object))
          objType = SQLiteConvert.TypeToDbType(obj.GetType());

      if ((_flags & SQLiteConnectionFlags.LogPreBind) == SQLiteConnectionFlags.LogPreBind)
      {
          IntPtr handle = _sqlite_stmt;

          SQLiteLog.LogMessage(String.Format(
          SQLiteLog.LogMessage(UnsafeNativeMethods.StringFormat(
              CultureInfo.CurrentCulture,
              "Binding statement {0} paramter #{1} with database type {2} and raw value {{{3}}}...",
              handle, index, objType, obj));
      }

      if ((obj == null) || Convert.IsDBNull(obj))
      {
          _sql.Bind_Null(this, _flags, index);
Changes to System.Data.SQLite/UnsafeNativeMethods.cs.
117
118
119
120
121
122
123








































































124
125
126
127
128
129
130
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







      /// <summary>
      /// For now, this method simply calls the Initialize method.
      /// </summary>
      static UnsafeNativeMethods()
      {
          Initialize();
      }

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

      /// <summary>
      /// This type is only present when running on Mono.
      /// </summary>
      private static readonly string MonoRuntimeType = "Mono.Runtime";

      /// <summary>
      /// Keeps track of whether we are running on Mono.  Initially null, it is
      /// set by the <see cref="IsMono" /> method on its first call.  Later, it
      /// is returned verbatim by the <see cref="IsMono" /> method.
      /// </summary>
      private static bool? isMono = null;

      /// <summary>
      /// Determines whether or not this assembly is running on Mono.
      /// </summary>
      /// <returns>
      /// Non-zero if this assembly is running on Mono.
      /// </returns>
      private static bool IsMono()
      {
          try
          {
              lock (staticSyncRoot)
              {
                  if (isMono == null)
                      isMono = (Type.GetType(MonoRuntimeType) != null);

                  return (bool)isMono;
              }
          }
          catch
          {
              // do nothing.
          }

          return false;
      }

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

      /// <summary>
      /// This is a wrapper around the
      /// <see cref="String.Format(IFormatProvider,String,Object[])" /> method.
      /// On Mono, it has to call the method overload without the
      /// <see cref="IFormatProvider" /> parameter, due to a bug in Mono.
      /// </summary>
      /// <param name="provider">
      /// This is used for culture-specific formatting.
      /// </param>
      /// <param name="format">
      /// The format string.
      /// </param>
      /// <param name="args">
      /// An array the objects to format.
      /// </param>
      /// <returns>
      /// The resulting string.
      /// </returns>
      internal static string StringFormat(
          IFormatProvider provider,
          string format,
          params object[] args
          )
      {
          if (IsMono())
              return String.Format(format, args);
          else
              return String.Format(provider, format, args);
      }

      /////////////////////////////////////////////////////////////////////////
      /// <summary>
      /// Attempts to initialize this class by pre-loading the native SQLite
      /// library for the processor architecture of the current process.
      /// </summary>
      internal static void Initialize()
297
298
299
300
301
302
303
304
305



306
307
308
309
310
311
312
369
370
371
372
373
374
375


376
377
378
379
380
381
382
383
384
385







-
-
+
+
+







#if !PLATFORM_COMPACTFRAMEWORK
          bool expand = true;

          if (Environment.GetEnvironmentVariable("No_Expand") != null)
          {
              expand = false;
          }
          else if (Environment.GetEnvironmentVariable(String.Format(
                  "No_Expand_{0}", name)) != null)
          else if (Environment.GetEnvironmentVariable(StringFormat(
                  CultureInfo.InvariantCulture, "No_Expand_{0}",
                  name)) != null)
          {
              expand = false;
          }

          value = Environment.GetEnvironmentVariable(name);

          if (expand && !String.IsNullOrEmpty(value))
323
324
325
326
327
328
329
330


331
332
333
334
335
336
337
396
397
398
399
400
401
402

403
404
405
406
407
408
409
410
411







-
+
+







              if (fileName == null)
                  return @default;

              XmlDocument document = new XmlDocument();

              document.Load(fileName);

              XmlElement element = document.SelectSingleNode(String.Format(
              XmlElement element = document.SelectSingleNode(StringFormat(
                  CultureInfo.InvariantCulture,
                  "/configuration/appSettings/add[@key='{0}']", name)) as
                  XmlElement;

              if (element != null)
              {
                  if (element.HasAttribute("value"))
                      value = element.GetAttribute("value");
350
351
352
353
354
355
356
357

358
359
360
361
362
363
364
424
425
426
427
428
429
430

431
432
433
434
435
436
437
438







-
+







#else
          catch (Exception)
#endif
          {
#if !NET_COMPACT_20 && TRACE_SHARED
              try
              {
                  Trace.WriteLine(String.Format(
                  Trace.WriteLine(StringFormat(
                      CultureInfo.CurrentCulture,
                      "Native library pre-loader failed to get setting " +
                      "\"{0}\" value: {1}", name, e)); /* throw */
              }
              catch
              {
                  // do nothing.
466
467
468
469
470
471
472
473

474
475
476
477
478
479
480
540
541
542
543
544
545
546

547
548
549
550
551
552
553
554







-
+







                  directory, XmlConfigFileName);

              if (File.Exists(xmlConfigFileName))
              {
#if !NET_COMPACT_20 && TRACE_DETECTION
                  try
                  {
                      Trace.WriteLine(String.Format(
                      Trace.WriteLine(StringFormat(
                          CultureInfo.CurrentCulture,
                          "Native library pre-loader found XML configuration file " +
                          "via code base for currently executing assembly: \"{0}\"",
                          xmlConfigFileName)); /* throw */
                  }
                  catch
                  {
489
490
491
492
493
494
495
496

497
498
499
500
501
502
503
563
564
565
566
567
568
569

570
571
572
573
574
575
576
577







-
+







              List<string> matches = null;

              if (CheckForArchitecturesAndPlatforms(directory, ref matches) > 0)
              {
#if !NET_COMPACT_20 && TRACE_DETECTION
                  try
                  {
                      Trace.WriteLine(String.Format(
                      Trace.WriteLine(StringFormat(
                          CultureInfo.CurrentCulture,
                          "Native library pre-loader found native sub-directories " +
                          "via code base for currently executing assembly: \"{0}\"",
                          ListToString(matches))); /* throw */
                  }
                  catch
                  {
516
517
518
519
520
521
522
523

524
525
526
527
528
529
530
590
591
592
593
594
595
596

597
598
599
600
601
602
603
604







-
+







#else
          catch (Exception)
#endif
          {
#if !NET_COMPACT_20 && TRACE_SHARED
              try
              {
                  Trace.WriteLine(String.Format(
                  Trace.WriteLine(StringFormat(
                      CultureInfo.CurrentCulture,
                      "Native library pre-loader failed to check code base " +
                      "for currently executing assembly: {0}", e)); /* throw */
              }
              catch
              {
                  // do nothing.
583
584
585
586
587
588
589
590

591
592
593
594
595
596
597
657
658
659
660
661
662
663

664
665
666
667
668
669
670
671







-
+







#else
          catch (Exception)
#endif
          {
#if !NET_COMPACT_20 && TRACE_SHARED
              try
              {
                  Trace.WriteLine(String.Format(
                  Trace.WriteLine(StringFormat(
                      CultureInfo.CurrentCulture,
                      "Native library pre-loader failed to get directory " +
                      "for currently executing assembly: {0}", e)); /* throw */
              }
              catch
              {
                  // do nothing.
953
954
955
956
957
958
959
960

961
962
963
964
965
966
967
1027
1028
1029
1030
1031
1032
1033

1034
1035
1036
1037
1038
1039
1040
1041







-
+







#if !NET_COMPACT_20 && TRACE_DETECTION
              try
              {
                  //
                  // NOTE: Show that we hit a fairly unusual situation (i.e.
                  //       the "wrong" processor architecture was detected).
                  //
                  Trace.WriteLine(String.Format(
                  Trace.WriteLine(StringFormat(
                      CultureInfo.CurrentCulture,
                      "Native library pre-loader detected {0}-bit pointer " +
                      "size with processor architecture \"{1}\", using " +
                      "processor architecture \"{2}\" instead...",
                      IntPtr.Size * 8 /* bits */, savedProcessorArchitecture,
                      processorArchitecture)); /* throw */
              }
1172
1173
1174
1175
1176
1177
1178
1179

1180
1181
1182
1183
1184
1185
1186
1246
1247
1248
1249
1250
1251
1252

1253
1254
1255
1256
1257
1258
1259
1260







-
+







#if !NET_COMPACT_20 && TRACE_PRELOAD
              try
              {
                  //
                  // NOTE: Show exactly where we are trying to load the native
                  //       SQLite library from.
                  //
                  Trace.WriteLine(String.Format(
                  Trace.WriteLine(StringFormat(
                      CultureInfo.CurrentCulture,
                      "Native library pre-loader is trying to load native " +
                      "SQLite library \"{0}\"...", fileName)); /* throw */
              }
              catch
              {
                  // do nothing.
1212
1213
1214
1215
1216
1217
1218
1219

1220
1221
1222
1223
1224
1225
1226
1286
1287
1288
1289
1290
1291
1292

1293
1294
1295
1296
1297
1298
1299
1300







-
+







                  int lastError = Marshal.GetLastWin32Error(); /* throw */

                  //
                  // NOTE: Show where we failed to load the native SQLite
                  //       library from along with the Win32 error code and
                  //       exception information.
                  //
                  Trace.WriteLine(String.Format(
                  Trace.WriteLine(StringFormat(
                      CultureInfo.CurrentCulture,
                      "Native library pre-loader failed to load native " +
                      "SQLite library \"{0}\" (getLastError = {1}): {2}",
                      fileName, lastError, e)); /* throw */
              }
              catch
              {
2952
2953
2954
2955
2956
2957
2958
2959

2960
2961
2962
2963
2964
2965
2966
3026
3027
3028
3029
3030
3031
3032

3033
3034
3035
3036
3037
3038
3039
3040







-
+







                if (localHandle != IntPtr.Zero)
                    SQLiteBase.CloseConnection(this, localHandle);
#endif

#if !NET_COMPACT_20 && TRACE_HANDLE
                try
                {
                    Trace.WriteLine(String.Format(
                    Trace.WriteLine(UnsafeNativeMethods.StringFormat(
                        CultureInfo.CurrentCulture,
                        "CloseConnection: {0}", localHandle)); /* throw */
                }
                catch
                {
                }
#endif
2987
2988
2989
2990
2991
2992
2993
2994

2995
2996
2997
2998
2999
3000
3001
3061
3062
3063
3064
3065
3066
3067

3068
3069
3070
3071
3072
3073
3074
3075







-
+







#else
            catch (SQLiteException)
#endif
            {
#if !NET_COMPACT_20 && TRACE_HANDLE
                try
                {
                    Trace.WriteLine(String.Format(
                    Trace.WriteLine(UnsafeNativeMethods.StringFormat(
                        CultureInfo.CurrentCulture,
                        "CloseConnection: {0}, exception: {1}",
                        handle, e)); /* throw */
                }
                catch
                {
                }
3140
3141
3142
3143
3144
3145
3146
3147

3148
3149
3150
3151
3152
3153
3154
3214
3215
3216
3217
3218
3219
3220

3221
3222
3223
3224
3225
3226
3227
3228







-
+








                if (localHandle != IntPtr.Zero)
                    SQLiteBase.FinalizeStatement(cnn, localHandle);

#if !NET_COMPACT_20 && TRACE_HANDLE
                try
                {
                    Trace.WriteLine(String.Format(
                    Trace.WriteLine(UnsafeNativeMethods.StringFormat(
                        CultureInfo.CurrentCulture,
                        "FinalizeStatement: {0}", localHandle)); /* throw */
                }
                catch
                {
                }
#endif
3175
3176
3177
3178
3179
3180
3181
3182

3183
3184
3185
3186
3187
3188
3189
3249
3250
3251
3252
3253
3254
3255

3256
3257
3258
3259
3260
3261
3262
3263







-
+







#else
            catch (SQLiteException)
#endif
            {
#if !NET_COMPACT_20 && TRACE_HANDLE
                try
                {
                    Trace.WriteLine(String.Format(
                    Trace.WriteLine(UnsafeNativeMethods.StringFormat(
                        CultureInfo.CurrentCulture,
                        "FinalizeStatement: {0}, exception: {1}",
                        handle, e)); /* throw */
                }
                catch
                {
                }
3313
3314
3315
3316
3317
3318
3319
3320

3321
3322
3323
3324
3325
3326
3327
3387
3388
3389
3390
3391
3392
3393

3394
3395
3396
3397
3398
3399
3400
3401







-
+








                if (localHandle != IntPtr.Zero)
                    SQLiteBase.FinishBackup(cnn, localHandle);

#if !NET_COMPACT_20 && TRACE_HANDLE
                try
                {
                    Trace.WriteLine(String.Format(
                    Trace.WriteLine(UnsafeNativeMethods.StringFormat(
                        CultureInfo.CurrentCulture,
                        "FinishBackup: {0}", localHandle)); /* throw */
                }
                catch
                {
                }
#endif
3348
3349
3350
3351
3352
3353
3354
3355

3356
3357
3358
3359
3360
3361
3362
3422
3423
3424
3425
3426
3427
3428

3429
3430
3431
3432
3433
3434
3435
3436







-
+







#else
            catch (SQLiteException)
#endif
            {
#if !NET_COMPACT_20 && TRACE_HANDLE
                try
                {
                    Trace.WriteLine(String.Format(
                    Trace.WriteLine(UnsafeNativeMethods.StringFormat(
                        CultureInfo.CurrentCulture,
                        "FinishBackup: {0}, exception: {1}",
                        handle, e)); /* throw */
                }
                catch
                {
                }
Changes to Tests/authorizer.eagle.
120
121
122
123
124
125
126

127

128
129
130
131
132
133
134
120
121
122
123
124
125
126
127

128
129
130
131
132
133
134
135







+
-
+







    set filter $name; set data [list]
    set code [catch {sql execute $db $value} result]
    set result [lindex [split [string map [list \r\n \n] $result] \n] 0]
    lappend results [list $name $data $code $result]
  }
  lappend results [isTableInDb tDeny]

  string map \
  set results
      [list "SQLiteException (0x80004005):" "SQLiteException:"] $results
} -cleanup {
  catch {object invoke $connection remove_Authorize $callback}
  catch {object removecallback $callback}

  cleanupDb $fileName

  freeDbConnection
157
158
159
160
161
162
163
164

165
166
167
168
169
158
159
160
161
162
163
164

165
166
167
168
169
170







-
+





{{0 DropIndex i1 t1 main {}}} 0 0} {Recursive {{0 Recursive {} {} {} {}}} 0 -1}\
{DropTable {{0 DropTable t1 {} main {}}} 0 0} {Transaction {{0 Transaction\
BEGIN {} {} {}} {0 Transaction COMMIT {} {} {}}} 0 -1} {Savepoint {{0 Savepoint\
BEGIN s1 {} {}} {0 Savepoint RELEASE s1 {} {}}} 0 -1} {Attach {{0 Attach\
:memory: {} {} {}}} 0 -1} {Detach {{0 Detach d1 {} {} {}}} 0 -1} {CreateVtable\
{{0 CreateVtable t3 fts4 main {}}} 0 0} {DropVtable {{0 DropVtable t3 fts4 main\
{}}} 0 0} {CreateTable {{0 CreateTable tDeny {} main {}}} 1\
{System.Data.SQLite.SQLiteException (0x80004005): authorization denied}} False}}
{System.Data.SQLite.SQLiteException: authorization denied}} False}}

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

runSQLiteTestEpilogue
runTestEpilogue
Changes to Tests/basic.eagle.
1570
1571
1572
1573
1574
1575
1576
1577

1578
1579
1580
1581
1582
1583
1584
1570
1571
1572
1573
1574
1575
1576

1577
1578
1579
1580
1581
1582
1583
1584







-
+







      BuildTempSchema $connection
} -cleanup {
  cleanupDb $fileName

  freeDbConnection

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

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

runTest {test data-1.30 {EF6 ISQLiteSchemaExtensions.BuildTempSchema} -setup {
  setupDb [set fileName data-1.30.db]
} -body {
1592
1593
1594
1595
1596
1597
1598
1599

1600
1601
1602
1603
1604
1605
1606
1592
1593
1594
1595
1596
1597
1598

1599
1600
1601
1602
1603
1604
1605
1606







-
+







      BuildTempSchema $connection
} -cleanup {
  cleanupDb $fileName

  freeDbConnection

  unset -nocomplain providerServices connection db fileName
} -constraints {eagle command.object SQLite System.Data.SQLite\
} -constraints {eagle monoToDo command.object SQLite System.Data.SQLite\
System.Data.SQLite.EF6} -result {}}

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

runTest {test data-1.31 {VARCHAR / NVARCHAR types with spaces} -body {
  list [object invoke -flags +NonPublic System.Data.SQLite.SQLiteConvert \
      TypeNameToDbType null VARCHAR None] \
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389





2390
2391
2392
2393
2394
2395
2396
2379
2380
2381
2382
2383
2384
2385




2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397







-
-
-
-
+
+
+
+
+







      "SELECT replicate('1234', 4);"} output] $output

  set result
} -cleanup {
  cleanupDb $fileName

  unset -nocomplain output result db fileName
} -constraints \
{eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} -match \
regexp -result {^0 12341234 1 \{System\.Data\.SQLite\.SQLiteException\
\(0x80004005\): SQL logic error or missing database.*?\} 0 1234123412341234$}}
} -constraints {eagle monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite SQLiteInterop\
defineConstant.System.Data.SQLite.INTEROP_EXTENSION_FUNCTIONS} -match regexp \
-result {^0 12341234 1 \{System\.Data\.SQLite\.SQLiteException \(0x80004005\):\
SQL logic error or missing database.*?\} 0 1234123412341234$}}

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

runTest {test data-1.50 {column name and index lookup} -setup {
  setupDb [set fileName data-1.50.db]
} -body {
  sql execute $db {
2694
2695
2696
2697
2698
2699
2700
2701

2702
2703
2704
2705
2706
2707
2708
2695
2696
2697
2698
2699
2700
2701

2702
2703
2704
2705
2706
2707
2708
2709







-
+








  unset -nocomplain result connection

  cleanupDb $fileName

  unset -nocomplain db fileName
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite} -result {1 {} 1.01 {}}}
System.Data.SQLite SQLiteInterop} -result {1 {} 1.01 {}}}

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

runTest {test data-1.57 {regexp extension} -setup {
  setupDb [set fileName data-1.57.db]
} -body {
  unset -nocomplain pattern result
2754
2755
2756
2757
2758
2759
2760
2761
2762


2763
2764
2765
2766
2767
2768
2769
2755
2756
2757
2758
2759
2760
2761


2762
2763
2764
2765
2766
2767
2768
2769
2770







-
-
+
+








  unset -nocomplain pattern result connection

  cleanupDb $fileName

  unset -nocomplain db fileName
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite} -result {0 1 1 {unmatched '('} 0 1 1 {unmatched '('} 0 0 1\
{unmatched '('} 0 0 1 {unmatched '('}}}
System.Data.SQLite SQLiteInterop} -result {0 1 1 {unmatched '('} 0 1 1\
{unmatched '('} 0 0 1 {unmatched '('} 0 0 1 {unmatched '('}}}

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

reportSQLiteResources $test_channel

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

2836
2837
2838
2839
2840
2841
2842
2843

2844
2845
2846
2847
2848
2849
2850
2837
2838
2839
2840
2841
2842
2843

2844
2845
2846
2847
2848
2849
2850
2851







-
+








  unset -nocomplain result connection

  cleanupDb $fileName

  unset -nocomplain db fileName
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite} -result {0 4 -1 1.75}}
System.Data.SQLite SQLiteInterop} -result {0 4 -1 1.75}}

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

runTest {test data-1.60 {per-connection type mappings} -setup {
  setupDb [set fileName data-1.60.db] "" "" "" UseConnectionTypes
} -body {
  set connection [getDbConnection]
3168
3169
3170
3171
3172
3173
3174
3175


3176
3177
3178
3179
3180
3181
3182
3169
3170
3171
3172
3173
3174
3175

3176
3177
3178
3179
3180
3181
3182
3183
3184







-
+
+







  cleanupDb $fileName
  restoreSQLiteConnectionEnvironment

  freeDbConnection

  unset -nocomplain connection db fileName
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite} -result {Default Default}}
System.Data.SQLite} -match regexp -result \
{^Default Default|LogCallbackException LogCallbackException$}}

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

runTest {test data-1.69 {set env(DefaultFlags_SQLiteConnection)} -setup {
  saveSQLiteConnectionEnvironment

  set env(DefaultFlags_SQLiteConnection) "DetectTextAffinity, DetectStringType"
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285



3286
3287
3288
3289
3290
3291
3292
3278
3279
3280
3281
3282
3283
3284



3285
3286
3287
3288
3289
3290
3291
3292
3293
3294







-
-
-
+
+
+








  unset -nocomplain x result connection

  cleanupDb $fileName

  unset -nocomplain db fileName
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite} -match regexp -result {^\{fts5: \d{4}-\d{2}-\d{2}\
\d{2}:\d{2}:\d{2} [0-9a-f]{40}\} \{\} \{\} \{\} \{\} \{\} \{rowid 3 x horse\
rowid 4 x house\}$}}
System.Data.SQLite SQLiteInterop} -match regexp -result \
{^\{fts5: \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} [0-9a-f]{40}\} \{\} \{\} \{\}\
\{\} \{\} \{rowid 3 x horse rowid 4 x house\}$}}

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

runTest {test data-1.72 {unbind function from a connection} -setup {
  set fileName data-1.72.db
} -body {
  set id [object invoke Interpreter.GetActive NextId]
Changes to Tests/linq.eagle.
87
88
89
90
91
92
93

94
95
96
97
98





99
100
101
102
103
104
87
88
89
90
91
92
93
94





95
96
97
98
99
100
101
102
103
104
105







+
-
-
-
-
-
+
+
+
+
+






  } else {
    lappend result [string trim $error]
  }

  set result
} -cleanup {
  unset -nocomplain code output error result
} -constraints {eagle System.Data.SQLite.dll_v4.0.30319 monoToDo SQLite\
} -constraints {eagle monoToDo SQLite file_System.Data.SQLite.dll testExec\
file_System.Data.SQLite.Linq.dll file_testlinq.exe file_northwindEF.db} \
-result {0 {{ NewUnitPrice = 21.0 } { NewUnitPrice = 21.1 } { NewUnitPrice =\
21.05 } { NewUnitPrice = 23.0 } { NewUnitPrice = 23.3 } { NewUnitPrice = 23.25\
} { NewUnitPrice = 21.0 } { NewUnitPrice = 21.4 } { NewUnitPrice = 21.35 }}}}
file_System.Data.SQLite.dll testExec file_System.Data.SQLite.Linq.dll\
file_testlinq.exe file_northwindEF.db} -result {0 {{ NewUnitPrice = 21.0 } {\
NewUnitPrice = 21.1 } { NewUnitPrice = 21.05 } { NewUnitPrice = 23.0 } {\
NewUnitPrice = 23.3 } { NewUnitPrice = 23.25 } { NewUnitPrice = 21.0 } {\
NewUnitPrice = 21.4 } { NewUnitPrice = 21.35 }}}}

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

runSQLiteTestFilesEpilogue
runSQLiteTestEpilogue
runTestEpilogue
Changes to Tests/speed.eagle.
172
173
174
175
176
177
178
179

180
181
182
183
184
185
186
172
173
174
175
176
177
178

179
180
181
182
183
184
185
186







-
+







  }

  set result
} -cleanup {
  cleanupDb $fileName

  unset -nocomplain time sql table column result char db fileName
} -time true -constraints {eagle monoBug28 command.sql compile.DATA SQLite\
} -time true -constraints {eagle monoBug40 command.sql compile.DATA SQLite\
System.Data.SQLite} -result {3 3 3 3}}

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

#
# NOTE: Report after test.
#
Changes to Tests/stress.eagle.
1643
1644
1645
1646
1647
1648
1649
1650

1651
1652
1653
1654
1655
1656
1657
1643
1644
1645
1646
1647
1648
1649

1650
1651
1652
1653
1654
1655
1656
1657







-
+







  rename cleanupLogging ""
  rename setupLogging ""

  unset -nocomplain result thread index workload priority noWorkload \
      priorities srcDb db fileName compiled options count times logFileName \
      logListener event timeout connection indicators iterations exitOnFail \
      coTaskMem noTrace failures status workloadNames workloadCallbacks
} -time true -constraints {eagle command.object monoBug28 command.sql\
} -time true -constraints {eagle command.object monoBug40 command.sql\
compile.DATA SQLite System.Data.SQLite compileCSharp} -result {0}}

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

#
# NOTE: Report after test.
#
Changes to Tests/tkt-47c6fa04d3.eagle.
113
114
115
116
117
118
119
120

121
122
123
124
125
126
127
113
114
115
116
117
118
119

120
121
122
123
124
125
126
127







-
+







      [expr {$code eq "Ok" ? [catch {
        object invoke -alias _Dynamic${id}.Test${id} GetDataTable
      } result] : [set result ""]}] $result [getRowsFromDataTable $result]
} -cleanup {
  cleanupDb $fileName

  unset -nocomplain result results errors code sql dataSource id db fileName
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
} -constraints {eagle command.object monoBug40 command.sql compile.DATA SQLite\
System.Data.SQLite compileCSharp} -match regexp -result {^Ok\
System#CodeDom#Compiler#CompilerResults#\d+ \{\} 0 System#Data#DataTable#\d+\
\{\{\{id 2\} \{min 2\} \{max 3\} \{sum 5\}\} \{\{id 2\} \{min 1\} \{max 2\}\
\{sum 3\}\}\}$}}

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

Changes to Tests/tkt-4a791e70ab.eagle.
67
68
69
70
71
72
73
74

75
76
77
78
79
80
81
67
68
69
70
71
72
73

74
75
76
77
78
79
80
81







-
+







      [expr {$code eq "Ok" ? [catch {
        object invoke _Dynamic${id}.Test${id} Main
      } result] : [set result ""]}] $result
} -cleanup {
  cleanupDb $fileName

  unset -nocomplain result results errors code dataSource id db fileName
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
} -constraints {eagle command.object monoBug40 command.sql compile.DATA SQLite\
System.Data.SQLite compileCSharp} -match regexp -result {^Ok\
System#CodeDom#Compiler#CompilerResults#\d+ \{\} 0 \{\}$}}

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

runSQLiteTestEpilogue
runTestEpilogue
Changes to Tests/tkt-56b42d99c1.eagle.
95
96
97
98
99
100
101
102

103
104
105
106
107
108
109
95
96
97
98
99
100
101

102
103
104
105
106
107
108
109







-
+







      [expr {$code eq "Ok" ? [catch {
        object invoke _Dynamic${id}.Test${id} TryEnlistInTransaction
      } result] : [set result ""]}] $result
} -cleanup {
  cleanupDb $fileName

  unset -nocomplain result results errors code dataSource id db fileName
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
} -constraints {eagle command.object monoBug40 command.sql compile.DATA SQLite\
System.Data.SQLite compileCSharp} -match regexp -result {^Ok\
System#CodeDom#Compiler#CompilerResults#\d+ \{\} 0 True$}}

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

runTest {test tkt-56b42d99c1-1.2 {enlisted transaction isolation} -setup {
  setupDb [set fileName tkt-56b42d99c1-1.2.db]
172
173
174
175
176
177
178
179

180
181
182
183
184
185
186
172
173
174
175
176
177
178

179
180
181
182
183
184
185
186







-
+







      [expr {$code eq "Ok" ? [catch {
        object invoke _Dynamic${id}.Test${id} Main
      } result] : [set result ""]}] $result
} -cleanup {
  cleanupDb $fileName

  unset -nocomplain result results errors code sql dataSource id db fileName
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
} -constraints {eagle command.object monoBug40 command.sql compile.DATA SQLite\
System.Data.SQLite compileCSharp} -match regexp -result {^Ok\
System#CodeDom#Compiler#CompilerResults#\d+ \{\} 0 0$}}

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

runTest {test tkt-56b42d99c1-1.3 {enlisted transaction isolation} -setup {
  setupDb [set fileName tkt-56b42d99c1-1.3.db]
403
404
405
406
407
408
409
410

411
412
413
414
415
416
417
403
404
405
406
407
408
409

410
411
412
413
414
415
416
417







-
+







      [expr {$code eq "Ok" ? [catch {
        object invoke _Dynamic${id}.Test${id} Main
      } result] : [set result ""]}] $result
} -cleanup {
  cleanupDb $fileName

  unset -nocomplain result results errors code sql dataSource id db fileName
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
} -constraints {eagle command.object monoBug40 command.sql compile.DATA SQLite\
System.Data.SQLite compileCSharp} -match regexp -result {^Ok\
System#CodeDom#Compiler#CompilerResults#\d+ \{\} 0 1$}}

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

set flags MapIsolationLevels

Changes to Tests/tkt-964063da16.eagle.
25
26
27
28
29
30
31
32
33


34
35
36
37
38
39
40
25
26
27
28
29
30
31


32
33
34
35
36
37
38
39
40







-
-
+
+







      System.Data.SQLite.SQLiteConnection \
      "Data Source=:memory:;NoDefaultFlags=False;"]

  $connection Open
  $connection Flags
} -cleanup {
  unset -nocomplain connection
} -constraints {eagle command.object SQLite System.Data.SQLite} -result \
{Default}}
} -constraints {eagle command.object SQLite System.Data.SQLite} -match regexp \
-result {^Default|LogCallbackException$}}

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

runTest {test tkt-964063da16-1.2 {pre-existing connection flags} -body {
  set connection [object create -alias \
      System.Data.SQLite.SQLiteConnection \
      "Data Source=:memory:;NoDefaultFlags=True;"]
53
54
55
56
57
58
59
60
61



62
63
64
65
66
67
68
53
54
55
56
57
58
59


60
61
62
63
64
65
66
67
68
69







-
-
+
+
+







      System.Data.SQLite.SQLiteConnection \
      "Data Source=:memory:;NoDefaultFlags=False;"]

  $connection Flags NoExtensionFunctions; $connection Open
  $connection Flags
} -cleanup {
  unset -nocomplain connection
} -constraints {eagle command.object SQLite System.Data.SQLite} -result \
{NoExtensionFunctions, Default}}
} -constraints {eagle command.object SQLite System.Data.SQLite} -match regexp \
-result {^Default, NoExtensionFunctions|NoExtensionFunctions,\
Default|LogCallbackException, NoExtensionFunctions$}}

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

runTest {test tkt-964063da16-1.4 {pre-existing connection flags} -body {
  set connection [object create -alias \
      System.Data.SQLite.SQLiteConnection \
      "Data Source=:memory:;NoDefaultFlags=True;"]
Changes to Tests/tkt-9d353b0bd8.eagle.
50
51
52
53
54
55
56
57
58


59
60
61
62
63
64
50
51
52
53
54
55
56


57
58
59
60
61
62
63
64







-
-
+
+






    lappend result [string trim $error]
  }

  set result
} -cleanup {
  unset -nocomplain code output error result
} -constraints {eagle monoToDo SQLite file_System.Data.SQLite.dll testExec\
file_System.Data.SQLite.Linq.dll file_testlinq.exe file_northwindEF.db} \
-result {0 {inserted 1}}}
file_System.Data.SQLite.Linq.dll file_testlinq.exe file_northwindEF.db\
System.Data.SQLite.dll_v4.0.30319} -result {0 {inserted 1}}}

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

runSQLiteTestFilesEpilogue
runSQLiteTestEpilogue
runTestEpilogue
Changes to Tests/tkt-e06c4caff3.eagle.
27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
27
28
29
30
31
32
33

34
35
36
37
38
39
40
41







-
+








  sql execute $db "INSERT INTO t1 (x) VALUES(?);" \
      [list param1 Double [set NaN [object invoke Double NaN]]]
} -cleanup {
  cleanupDb $fileName

  unset -nocomplain NaN db fileName
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
} -constraints {eagle command.object monoBug40 command.sql compile.DATA SQLite\
System.Data.SQLite} -returnCodes 1 -match regexp -result [string map [list \n\
\r\n] {^System\.Data\.SQLite\.SQLiteException \(0x80004005\): constraint failed
NOT NULL constraint failed: t1\.x
.*$}]}

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

Changes to Tests/tkt-f8dbab8baf.eagle.
127
128
129
130
131
132
133
134

135
136
137
138
139
140
141
127
128
129
130
131
132
133

134
135
136
137
138
139
140
141







-
+







      [expr {[info exists rows(count)] ? $rows(count) : -1}] \
      [expr {[info exists rows(names)] ? $rows(names) : ""}]
} -cleanup {
  cleanupDb $fileName

  unset -nocomplain rows db fileName
} -constraints \
{eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} \
{eagle monoBug40 command.sql compile.DATA SQLite System.Data.SQLite} \
-returnCodes 1 -match regexp -result [string map [list \n \r\n] \
{^System\.Data\.SQLite\.SQLiteException \(0x80004005\): SQL logic error or\
missing database
no such table: t1.*$}]}

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

Changes to lib/System.Data.SQLite/common.eagle.
1519
1520
1521
1522
1523
1524
1525





1526
1527
1528



1529





1530

1531
1532
1533
1534
1535
1536
1537
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530



1531
1532
1533
1534
1535
1536
1537
1538
1539

1540
1541
1542
1543
1544
1545
1546
1547







+
+
+
+
+
-
-
-
+
+
+

+
+
+
+
+
-
+







        #       so, make it easy to spot.
        #
        if {[string length $sourceId] == 0} then {
          set sourceId null
        }

        #
        # NOTE: Before actually adding the test constraint, make sure the
        #       version is valid (i.e. not just that we could query it).
        #
        if {$version ne "null"} then {
          #
        # NOTE: Yes, the SQLite interop assembly appears to be available.
        #
        addConstraint SQLiteInterop
          # NOTE: Yes, the SQLite interop assembly appears to be available.
          #
          addConstraint SQLiteInterop

          set answer yes
        } else {
          set answer no
        }

        tputs $channel [appendArgs "yes (" $version " " $sourceId ")\n"]
        tputs $channel [appendArgs $answer " (" $version " " $sourceId ")\n"]
      } else {
        tputs $channel no\n
      }
    }

    proc checkForSQLiteDefineConstant { channel name } {
      tputs $channel [appendArgs \
Changes to readme.htm.
211
212
213
214
215
216
217

218
219
220
221
222
223
224
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225







+







<p>
    <b>1.0.98.0 - August XX, 2015 <font color="red">(release scheduled)</font></b>
</p>
<ul>
    <li>Updated to <a href="https://www.sqlite.org/releaselog/3_8_11_1.html">SQLite 3.8.11.1</a>.</li>
    <li>Add full support for Visual Studio 2015 and the .NET Framework 4.6.</li>
    <li>Implement the Substring method for LINQ using the &quot;substr&quot; core SQL function.&nbsp;<b>** Potentially Incompatible Change **</b></li>
    <li>Prevent encrypted connections from being used with the connection pool. Pursuant to [89d3a159f1].&nbsp;<b>** Potentially Incompatible Change **</b></li>
    <li>Honor the second argument to Math.Round when using LINQ.&nbsp;<b>** Potentially Incompatible Change **</b></li>
    <li>Honor the pre-existing flags for connections during the Open method. Fix for [964063da16].&nbsp;<b>** Potentially Incompatible Change **</b></li>
    <li>Remove errant semi-colons from the SQL used by LINQ to INSERT and then SELECT rows with composite primary keys. Fix for [9d353b0bd8].</li>
    <li>Change the base type for the SQLiteConnectionFlags enumeration to long integer.&nbsp;<b>** Potentially Incompatible Change **</b></li>
    <li>Add extended return codes to the SQLiteErrorCode enumeration. Pursuant to [71bedaca19].&nbsp;<b>** Potentially Incompatible Change **</b></li>
    <li>Improve exception handling in all native callbacks implemented in the SQLiteConnection class.</li>
    <li>Add Progress event and ProgressOps connection string property to enable raising progress events during long-running queries.</li>
Changes to test/TestCases.cs.
19
20
21
22
23
24
25
26

27
28
29
30
31
32
33
19
20
21
22
23
24
25

26
27
28
29
30
31
32
33







-
+







  {
    private const int NumThreads = 8;
    private const int ThreadTimeout = 60000;

    private List<string> droptables = new List<string>();
    private List<string> maydroptable = new List<string>();

#if !INTEROP_LOG
#if !USE_INTEROP_DLL || !INTEROP_LOG
    private long logevents = 0;
#endif

    internal TestCases()
    {
    }

1636
1637
1638
1639
1640
1641
1642
1643

1644
1645
1646
1647
1648
1649
1650
1636
1637
1638
1639
1640
1641
1642

1643
1644
1645
1646
1647
1648
1649
1650







-
+







        SQLiteErrorCode rc = cnn.ResultCode();
        SQLiteErrorCode xrc = cnn.ExtendedResultCode();

        cnn.Close();
      }
    }

#if !INTEROP_LOG
#if !USE_INTEROP_DLL || !INTEROP_LOG
    //Logging EventHandler
    public void OnLogEvent(object sender, LogEventArgs logEvent)
    {
        object errorCode = logEvent.ErrorCode;
        string err_msg = logEvent.Message;
        logevents++;
    }
Changes to testce/TestCases.cs.
288
289
290
291
292
293
294

295
296
297

298
299
300
301
302
303
304
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306







+



+







      try { UserCollation(cnn); frm.WriteLine("SUCCESS - UserCollation"); passed++; }
      catch (Exception) { frm.WriteLine("FAIL - UserCollation"); failed++; }

      total++;
      try { Int64Properties(cnn); frm.WriteLine("SUCCESS - Int64Properties"); passed++; }
      catch (Exception) { frm.WriteLine("FAIL - Int64Properties"); failed++; }

#if INTEROP_VIRTUAL_TABLE
      total++;
      try { ManagedVirtualTable(cnn); frm.WriteLine("SUCCESS - ManagedVirtualTable"); passed++; }
      catch (Exception) { frm.WriteLine("FAIL - ManagedVirtualTable"); failed++; }
#endif

      total++;
      try { MultipleThreadStress(cnn); frm.WriteLine("SUCCESS - MultipleThreadStress"); passed++; }
      catch (Exception) { frm.WriteLine("FAIL - MultipleThreadStress"); failed++; }

      total++;
      try { SimpleRTree(cnn); frm.WriteLine("SUCCESS - SimpleRTree"); passed++; }
1035
1036
1037
1038
1039
1040
1041

1042
1043
1044
1045
1046
1047
1048
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051







+








            return;
        }

        throw new NotSupportedException("not a SQLite connection");
    }

#if INTEROP_VIRTUAL_TABLE
    // Make sure that managed virtual table support works on the .NET Compact Framework.
    internal void ManagedVirtualTable(DbConnection cnn)
    {
        SQLiteConnection cnn2 = cnn as SQLiteConnection;

        if (cnn2 != null)
        {
1095
1096
1097
1098
1099
1100
1101

1102
1103
1104
1105
1106
1107
1108
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112







+







            }

            return;
        }

        throw new NotSupportedException("not a SQLite connection");
    }
#endif

    private int nextId = 0;
    private const int MAX_THREADS = 3;
    private const int MAX_ITERATIONS = 100;
    private ManualResetEvent goEvent = new ManualResetEvent(false);

    private static int GetThreadId()
Changes to testce/testce.2005.csproj.
101
102
103
104
105
106
107

108
109
110
111
112
113
114
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115







+







  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\System.Data.SQLite\System.Data.SQLite.Compact.2005.csproj">
      <Project>{AC139951-261A-4463-B6FA-AEBC25283A66}</Project>
      <Name>System.Data.SQLite.Compact.2005</Name>
    </ProjectReference>
  </ItemGroup>
  <Import Project="$(SQLiteNetDir)\System.Data.SQLite\Targets\System.Data.SQLite.Properties.targets" />
  <Import Condition="'$(TargetFrameworkVersion)' == 'v1.0'" Project="$(MSBuildBinPath)\Microsoft.CompactFramework.CSharp.v1.targets" />
  <Import Condition="'$(TargetFrameworkVersion)' == 'v2.0'" Project="$(MSBuildBinPath)\Microsoft.CompactFramework.CSharp.targets" />
  <Import Condition="'$(TargetFrameworkVersion)' == 'v3.5'" Project="$(MSBuildBinPath)\Microsoft.CompactFramework.CSharp.targets" />
  <ProjectExtensions>
    <VisualStudio>
      <FlavorProperties GUID="{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}">
        <HostingProcess disable="1" />
Changes to testce/testce.2008.csproj.
102
103
104
105
106
107
108

109
110
111
112
113
114
115
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116







+







  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\System.Data.SQLite\System.Data.SQLite.Compact.2008.csproj">
      <Project>{AC139951-261A-4463-B6FA-AEBC25283A66}</Project>
      <Name>System.Data.SQLite.Compact.2008</Name>
    </ProjectReference>
  </ItemGroup>
  <Import Project="$(SQLiteNetDir)\System.Data.SQLite\Targets\System.Data.SQLite.Properties.targets" />
  <Import Condition="'$(TargetFrameworkVersion)' == 'v1.0'" Project="$(MSBuildBinPath)\Microsoft.CompactFramework.CSharp.v1.targets" />
  <Import Condition="'$(TargetFrameworkVersion)' == 'v2.0'" Project="$(MSBuildBinPath)\Microsoft.CompactFramework.CSharp.targets" />
  <Import Condition="'$(TargetFrameworkVersion)' == 'v3.5'" Project="$(MSBuildBinPath)\Microsoft.CompactFramework.CSharp.targets" />
  <ProjectExtensions>
    <VisualStudio>
      <FlavorProperties GUID="{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}">
        <HostingProcess disable="1" />
Changes to testce/testce.2012.csproj.
86
87
88
89
90
91
92

93
94
95
96
97
98
99
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100







+







  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\System.Data.SQLite\System.Data.SQLite.Compact.2012.csproj">
      <Project>{AC139951-261A-4463-B6FA-AEBC25283A66}</Project>
      <Name>System.Data.SQLite.Compact.2012</Name>
    </ProjectReference>
  </ItemGroup>
  <Import Project="$(SQLiteNetDir)\System.Data.SQLite\Targets\System.Data.SQLite.Properties.targets" />
  <Import Condition="'$(TargetFrameworkVersion)' == 'v1.0'" Project="$(MSBuildBinPath)\Microsoft.CompactFramework.CSharp.v1.targets" />
  <Import Condition="'$(TargetFrameworkVersion)' == 'v2.0'" Project="$(MSBuildBinPath)\Microsoft.CompactFramework.CSharp.targets" />
  <Import Condition="'$(TargetFrameworkVersion)' == 'v3.5'" Project="$(MSBuildBinPath)\Microsoft.CompactFramework.CSharp.targets" />
  <Import Project="$(MSBuildExtensionsPath)\Microsoft\$(TargetFrameworkIdentifier)\v8.0\Microsoft.$(TargetFrameworkIdentifier).CSharp.targets" />
  <ProjectExtensions>
    <VisualStudio>
      <FlavorProperties GUID="{fae04ec0-301f-11d3-bf4b-00c04f79efbc}">
Changes to testlinq/Program.cs.
90
91
92
93
94
95
96

97
98
99
100

101
102
103
104
105
106
107
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109







+




+








                      return SkipTest(pageSize);
                  }
              case "substring":
                  {
                      return SubStringTest();
                  }
#if USE_INTEROP_DLL && INTEROP_EXTENSION_FUNCTIONS
              case "unionall":
                  {
                      return UnionAllTest();
                  }
#endif
              case "endswith":
                  {
                      string value = null;

                      if (args.Length > 1)
                      {
                          value = args[1];
140
141
142
143
144
145
146

147
148
149
150

151
152
153
154
155
156
157
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161







+




+








                              return 1;
                          }
                      }

                      return EFTransactionTest(value);
                  }
#if NET_40 || NET_45 || NET_451 || NET_46
              case "insert":
                  {
                      return InsertTest();
                  }
#endif
              case "update":
                  {
                      return UpdateTest();
                  }
              case "binaryguid":
                  {
                      bool value = false;
364
365
366
367
368
369
370

371
372
373
374
375
376
377
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382







+







                  once = true;
              }
          }

          return 0;
      }

#if USE_INTEROP_DLL && INTEROP_EXTENSION_FUNCTIONS
      //
      // NOTE: Used to test the fix for ticket [0a32885109].
      //
      private static int UnionAllTest()
      {
          using (northwindEFEntities db = new northwindEFEntities())
          {
434
435
436
437
438
439
440

441
442
443
444
445
446
447
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453







+







                  Console.Write(customer.CustomerID);
                  once = true;
              }
          }

          return 0;
      }
#endif

      //
      // NOTE: Used to test the fix for ticket [ccfa69fc32].
      //
      private static int EFTransactionTest(bool add)
      {
          //
548
549
550
551
552
553
554

555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568




569
570
571
572
573
574
575







+







-
-
-
-







#endif
              }
          }

          return 0;
      }

#if NET_40 || NET_45 || NET_451 || NET_46
      //
      // NOTE: Used to test the INSERT fix (i.e. an extra semi-colon in
      //       the SQL statement after the actual INSERT statement in
      //       the follow-up SELECT statement).
      //
      private static int InsertTest()
      {
          long[] orderIds = new long[] {
              0
          };

          using (northwindEFEntities db = new northwindEFEntities())
          {
              int[] counts = { 0 };

              //
              // NOTE: *REQUIRED* This is required so that the
              //       Entity Framework is prevented from opening
602
603
604
605
606
607
608

609
610
611
612
613
614
615
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619







+







              }

              Console.WriteLine("inserted {0}", counts[0]);
          }

          return 0;
      }
#endif

      //
      // NOTE: Used to test the UPDATE fix (i.e. the missing semi-colon
      //       in the SQL statement between the actual UPDATE statement
      //       and the follow-up SELECT statement).
      //
      private static int UpdateTest()
Changes to www/build.wiki.
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416

417
418
419
420
421
422
423
393
394
395
396
397
398
399










400
401
402
403



404
405
406
407
408
409
410
411







-
-
-
-
-
-
-
-
-
-




-
-
-
+







      be able to simply delete these directories.
    </li>

    <li>Open a normal command prompt window with &quot;cmd.exe&quot;.</li>

    <li>Change the current directory to &quot;&lt;root&gt;\Setup&quot;.</li>

    <li>
      Enter the following command to set the environment variable used to pass
      the necessary extra arguments to MSBuild:
      <br />
      <br />
      <b>SET&nbsp;MSBUILD_ARGS=/property:UseInteropDll=false&nbsp;/property:UseSqliteStandard=true</b>
      <br />
      <br />
    </li>

    <li>
      Enter the following command to build the managed-only binaries for Mono:
      <br />
      <br />
      <b>SET NOUSER=1</b>
      <br />
      <b>build.bat&nbsp;ReleaseManagedOnly</b>
      <b>build_mono.bat</b>
      <br />
      <br />
    </li>

    <li>
      Make sure everything succeeds with no errors; the log file
      &quot;%TEMP%\System.Data.SQLite.Build_ReleaseManagedOnly_Win32_&lt;year&gt;_Unknown.log&quot;
Changes to www/news.wiki.
1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19











+







<title>News</title>

<b>Version History</b>

<p>
    <b>1.0.98.0 - August XX, 2015 <font color="red">(release scheduled)</font></b>
</p>
<ul>
    <li>Updated to [https://www.sqlite.org/releaselog/3_8_11_1.html|SQLite 3.8.11.1].</li>
    <li>Add full support for Visual Studio 2015 and the .NET Framework 4.6.</li>
    <li>Implement the Substring method for LINQ using the &quot;substr&quot; core SQL function.&nbsp;<b>** Potentially Incompatible Change **</b></li>
    <li>Prevent encrypted connections from being used with the connection pool. Pursuant to [89d3a159f1].&nbsp;<b>** Potentially Incompatible Change **</b></li>
    <li>Honor the second argument to Math.Round when using LINQ.&nbsp;<b>** Potentially Incompatible Change **</b></li>
    <li>Honor the pre-existing flags for connections during the Open method. Fix for [964063da16].&nbsp;<b>** Potentially Incompatible Change **</b></li>
    <li>Remove errant semi-colons from the SQL used by LINQ to INSERT and then SELECT rows with composite primary keys. Fix for [9d353b0bd8].</li>
    <li>Change the base type for the SQLiteConnectionFlags enumeration to long integer.&nbsp;<b>** Potentially Incompatible Change **</b></li>
    <li>Add extended return codes to the SQLiteErrorCode enumeration. Pursuant to [71bedaca19].&nbsp;<b>** Potentially Incompatible Change **</b></li>
    <li>Improve exception handling in all native callbacks implemented in the SQLiteConnection class.</li>
    <li>Add Progress event and ProgressOps connection string property to enable raising progress events during long-running queries.</li>