System.Data.SQLite

Check-in [46b91cd7d0]
Login

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

Overview
Comment:Add tests for the new environment variables.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 46b91cd7d078f07de0e7ea9dad04ea627d0179fe
User & Date: mistachkin 2016-07-02 00:02:56.797
Context
2016-07-02
00:06
Improve comments. check-in: 4b9b00163e user: mistachkin tags: trunk
00:02
Add tests for the new environment variables. check-in: 46b91cd7d0 user: mistachkin tags: trunk
2016-07-01
23:18
Update version history docs. check-in: b21adfaffa user: mistachkin tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to System.Data.SQLite/UnsafeNativeMethods.cs.
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
      /////////////////////////////////////////////////////////////////////////
      /// <summary>
      /// This dictionary stores the read counts for the runtime configuration
      /// settings.  This information is only recorded when compiled in the
      /// "Debug" build configuration.
      /// </summary>
      private static Dictionary<string, int> settingReadCounts;









#endif
      #endregion
      #endregion

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

      #region Public Methods
#if DEBUG
      /// <summary>
      /// Creates the dictionary used to store the read counts for each of the
      /// runtime configuration settings.  These numbers are used for debugging
      /// and testing purposes only.
      /// </summary>
      public static void InitializeSettingReadCounts()
      {
          lock (staticSyncRoot)
          {
              //
              // NOTE: Create the list of statistics that will contain the
              //       number of times each setting value has been read.
              //
              if (settingReadCounts == null)
                  settingReadCounts = new Dictionary<string, int>();



          }
      }

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

      /// <summary>
      /// Increments the read count for the specified runtime configuration
      /// setting.  These numbers are used for debugging and testing purposes
      /// only.
      /// </summary>
      /// <param name="name">
      /// The name of the setting being read.
      /// </param>




      public static void IncrementSettingReadCount(
          string name

          )
      {
          lock (staticSyncRoot)
          {
              //
              // NOTE: Update statistics for this setting value.
              //














              if (settingReadCounts != null)
              {
                  int count;

                  if (settingReadCounts.TryGetValue(name, out count))
                        settingReadCounts[name] = count + 1;
                  else
                        settingReadCounts.Add(name, 1);

              }
          }
      }
#endif
      #endregion
  }
#endif







>
>
>
>
>
>
>
>
>


















|




>
>
>













>
>
>
>

|
>







>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|

|
|
|
|
>







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
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
      /////////////////////////////////////////////////////////////////////////
      /// <summary>
      /// This dictionary stores the read counts for the runtime configuration
      /// settings.  This information is only recorded when compiled in the
      /// "Debug" build configuration.
      /// </summary>
      private static Dictionary<string, int> settingReadCounts;

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

      /// <summary>
      /// This dictionary stores the read counts for the runtime configuration
      /// settings via the XML configuration file.  This information is only
      /// recorded when compiled in the "Debug" build configuration.
      /// </summary>
      private static Dictionary<string, int> settingFileReadCounts;
#endif
      #endregion
      #endregion

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

      #region Public Methods
#if DEBUG
      /// <summary>
      /// Creates the dictionary used to store the read counts for each of the
      /// runtime configuration settings.  These numbers are used for debugging
      /// and testing purposes only.
      /// </summary>
      public static void InitializeSettingReadCounts()
      {
          lock (staticSyncRoot)
          {
              //
              // NOTE: Create the lists of statistics that will contain the
              //       number of times each setting value has been read.
              //
              if (settingReadCounts == null)
                  settingReadCounts = new Dictionary<string, int>();

              if (settingFileReadCounts == null)
                  settingFileReadCounts = new Dictionary<string, int>();
          }
      }

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

      /// <summary>
      /// Increments the read count for the specified runtime configuration
      /// setting.  These numbers are used for debugging and testing purposes
      /// only.
      /// </summary>
      /// <param name="name">
      /// The name of the setting being read.
      /// </param>
      /// <param name="viaFile">
      /// Non-zero if the specified setting was read via the configuration
      /// file.
      /// </param>
      public static void IncrementSettingReadCount(
          string name,
          bool viaFile
          )
      {
          lock (staticSyncRoot)
          {
              //
              // NOTE: Update statistics for this setting value.
              //
              if (viaFile)
              {
                  if (settingFileReadCounts != null)
                  {
                      int count;

                      if (settingFileReadCounts.TryGetValue(name, out count))
                          settingFileReadCounts[name] = count + 1;
                      else
                          settingFileReadCounts.Add(name, 1);
                  }
              }
              else
              {
                  if (settingReadCounts != null)
                  {
                      int count;

                      if (settingReadCounts.TryGetValue(name, out count))
                          settingReadCounts[name] = count + 1;
                      else
                          settingReadCounts.Add(name, 1);
                  }
              }
          }
      }
#endif
      #endregion
  }
#endif
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
          if (name == null)
              return @default;

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

          #region Debug Build Only
#if DEBUG
          DebugData.IncrementSettingReadCount(name);
#endif
          #endregion

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

          string value = null;








|







810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
          if (name == null)
              return @default;

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

          #region Debug Build Only
#if DEBUG
          DebugData.IncrementSettingReadCount(name, false);
#endif
          #endregion

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

          string value = null;

819
820
821
822
823
824
825










826
827
828
829
830
831
832
          //
          if (Environment.GetEnvironmentVariable(
                "No_SQLiteXmlConfigFile") != null)
          {
              return @default;
          }
#endif











          try
          {
              string fileName = GetXmlConfigFileName();

              if (fileName == null)
                  return @default;







>
>
>
>
>
>
>
>
>
>







851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
          //
          if (Environment.GetEnvironmentVariable(
                "No_SQLiteXmlConfigFile") != null)
          {
              return @default;
          }
#endif

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

          #region Debug Build Only
#if DEBUG
          DebugData.IncrementSettingReadCount(name, true);
#endif
          #endregion

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

          try
          {
              string fileName = GetXmlConfigFileName();

              if (fileName == null)
                  return @default;
Changes to Tests/tkt-58ed318f2f.eagle.
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
###############################################################################

package require System.Data.SQLite.Test
runSQLiteTestPrologue

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

proc getSettingReadCount { name } {
  if {[haveConstraint buildConfiguration.Debug] && [catch {
    object invoke -flags +NonPublic -alias \
        System.Data.SQLite.DebugData settingReadCounts

  } settingReadCounts] == 0} then {

    if {[$settingReadCounts TryGetValue $name value]} then {
      tputs $::test_channel [appendArgs \
          "---- setting \"" $name "\" was read " $value " times\n"]


      return $value
    }



  }



  tputs $::test_channel [appendArgs \











      "---- setting \"" $name "\" was not read\n"]







  return -1
}

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

reportSQLiteResources $test_channel true







|


|
>

>
|
|
|
>

|
|
>
>
>
|
>
>

|
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>







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
###############################################################################

package require System.Data.SQLite.Test
runSQLiteTestPrologue

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

proc getSettingReadCount { name {viaFile false} } {
  if {[haveConstraint buildConfiguration.Debug] && [catch {
    object invoke -flags +NonPublic -alias \
        System.Data.SQLite.DebugData [expr {$viaFile ? \
        "settingFileReadCounts" : "settingReadCounts"}]
  } settingReadCounts] == 0} then {
    if {[string length $name] > 0} then {
      if {[$settingReadCounts TryGetValue $name value]} then {
        tputs $::test_channel [appendArgs \
            "---- setting \"" $name "\" was read " $value " times" \
            [expr {$viaFile ? " from the configuration file" : ""}] \n]

        return $value
      }
    } else {
      set nameCount [$settingReadCounts Count]
      set valueCount 0

      object foreach -alias pair $settingReadCounts {
        incr valueCount [$pair Value]

        tputs $::test_channel [appendArgs \
            "---- setting \"" [$pair Key] "\" was read " [$pair Value] \
            " times" [expr {$viaFile ? " from the configuration file" : \
            ""}] \n]
      }

      return [list $nameCount $valueCount]
    }
  }

  if {[string length $name] > 0} then {
    tputs $::test_channel [appendArgs \
        "---- setting \"" $name "\" was not read" [expr {$viaFile ? \
        " from the configuration file" : ""}] \n]
  } else {
    tputs $::test_channel [appendArgs \
        "---- no settings were read" [expr {$viaFile ? \
        " from the configuration file" : ""}] \n]
  }

  return -1
}

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

reportSQLiteResources $test_channel true
371
372
373
374
375
376
377



























































378
379
380
381
382
383
384
      [getSettingReadCount Use_SQLiteConvert_DefaultTypeName] == -1}
} -cleanup {
  cleanupDb $fileName

  freeDbConnection

  unset -nocomplain columns connection db fileName



























































} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite buildConfiguration.Debug} -result {True}}

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

rename getSettingReadCount ""








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







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
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
      [getSettingReadCount Use_SQLiteConvert_DefaultTypeName] == -1}
} -cleanup {
  cleanupDb $fileName

  freeDbConnection

  unset -nocomplain columns connection db fileName
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite buildConfiguration.Debug} -result {True}}

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

reportSQLiteResources $test_channel true

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

runTest {test tkt-58ed318f2f-1.13 {zero settings usage} -setup {
  saveGetSettingValueEnvironment

  set env(No_SQLiteGetSettingValue) 1

  setupDb [set fileName tkt-58ed318f2f-1.13.db]
} -body {
  sql execute $db {
    CREATE TABLE t1(x);
    INSERT INTO t1 (x) VALUES(0);
  }

  sql execute -execute reader -format list $db "SELECT x FROM t1;"

  expr {[getSettingReadCount ""] eq "0 0"}
} -cleanup {
  cleanupDb $fileName
  restoreGetSettingValueEnvironment

  unset -nocomplain db fileName
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite buildConfiguration.Debug} -result {True}}

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

reportSQLiteResources $test_channel true

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

runTest {test tkt-58ed318f2f-1.14 {zero XML configuration file usage} -setup {
  saveGetSettingValueEnvironment

  set env(No_SQLiteXmlConfigFile) 1

  setupDb [set fileName tkt-58ed318f2f-1.14.db]
} -body {
  sql execute $db {
    CREATE TABLE t1(x);
    INSERT INTO t1 (x) VALUES(0);
  }

  sql execute -execute reader -format list $db "SELECT x FROM t1;"

  expr {[getSettingReadCount ""] eq "10 13" && \
      [getSettingReadCount "" true] eq "0 0"}
} -cleanup {
  cleanupDb $fileName
  restoreGetSettingValueEnvironment

  unset -nocomplain db fileName
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite buildConfiguration.Debug} -result {True}}

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

rename getSettingReadCount ""

Changes to lib/System.Data.SQLite/common.eagle.
2821
2822
2823
2824
2825
2826
2827
















2828
2829
2830
2831
2832
2833
2834
      # NOTE: This is self-cleaning.  If no saved environment variables now
      #       exist, remove the array.
      #
      if {[array size savedEnv] == 0} then {
        unset -nocomplain savedEnv
      }
    }

















    proc saveSQLiteConnectionEnvironment {} {
      upvar 1 savedEnv savedEnv

      saveEnvironmentVariables [list \
          DefaultFlags_SQLiteConnection No_SQLiteConnectionNewParser] \
          savedEnv







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







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
      # NOTE: This is self-cleaning.  If no saved environment variables now
      #       exist, remove the array.
      #
      if {[array size savedEnv] == 0} then {
        unset -nocomplain savedEnv
      }
    }

    proc saveGetSettingValueEnvironment {} {
      upvar 1 savedEnv savedEnv

      saveEnvironmentVariables [list \
          No_Expand No_SQLiteGetSettingValue No_SQLiteXmlConfigFile] \
          savedEnv
    }

    proc restoreGetSettingValueEnvironment {} {
      upvar 1 savedEnv savedEnv

      restoreEnvironmentVariables [list \
          No_Expand No_SQLiteGetSettingValue No_SQLiteXmlConfigFile] \
          savedEnv
    }

    proc saveSQLiteConnectionEnvironment {} {
      upvar 1 savedEnv savedEnv

      saveEnvironmentVariables [list \
          DefaultFlags_SQLiteConnection No_SQLiteConnectionNewParser] \
          savedEnv
3277
3278
3279
3280
3281
3282
3283
3284

3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312




































3313
3314
3315
3316
3317
3318
3319
    proc reportSQLiteResources {
            channel {quiet false} {reset true} {collect true} } {
      #
      # NOTE: If available, report on (and possibly reset) the runtime
      #       configuration statistics.
      #
      if {[haveSQLiteObjectCommand] && \
          [haveConstraint buildConfiguration.Debug] && [catch {

        object invoke -flags +NonPublic -alias \
            System.Data.SQLite.DebugData settingReadCounts
      } settingReadCounts] == 0} then {
        set nameCount [$settingReadCounts Count]
        set valueCount 0

        object foreach -alias pair $settingReadCounts {
          incr valueCount [$pair Value]

          if {!$quiet} then {
            tputs $channel [appendArgs \
                "---- setting \"" [$pair Key] "\" was read " \
                [$pair Value] " times\n"]
          }
        }

        if {$reset} then {
          if {[catch {$settingReadCounts Clear} error] == 0} then {
            if {!$quiet} then {
              tputs $channel [appendArgs \
                  "---- reset setting statistics for the previous " \
                  $nameCount " names and " $valueCount " values read\n"]
            }
          } else {
            tputs $channel [appendArgs \
                "==== WARNING: failed to reset setting statistics for " \
                "the previous " $nameCount " names and " $valueCount \
                " values read, error: " \n\t $error \n]




































          }
        }
      }

      if {[haveSQLiteObjectCommand] && \
          [haveSQLiteDefineConstant INTEROP_VIRTUAL_TABLE] && \
          [haveSQLiteDefineConstant TRACK_MEMORY_BYTES]} then {







|
>
|
|
|
|
|

|
|

|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
    proc reportSQLiteResources {
            channel {quiet false} {reset true} {collect true} } {
      #
      # NOTE: If available, report on (and possibly reset) the runtime
      #       configuration statistics.
      #
      if {[haveSQLiteObjectCommand] && \
          [haveConstraint buildConfiguration.Debug]} then {
        if {[catch {
          object invoke -flags +NonPublic -alias \
              System.Data.SQLite.DebugData settingReadCounts
        } settingReadCounts] == 0} then {
          set nameCount [$settingReadCounts Count]
          set valueCount 0

          object foreach -alias pair $settingReadCounts {
            incr valueCount [$pair Value]

            if {!$quiet} then {
              tputs $channel [appendArgs \
                  "---- setting \"" [$pair Key] "\" was read " \
                  [$pair Value] " times\n"]
            }
          }

          if {$reset} then {
            if {[catch {$settingReadCounts Clear} error] == 0} then {
              if {!$quiet} then {
                tputs $channel [appendArgs \
                    "---- reset setting statistics for the previous " \
                    $nameCount " names and " $valueCount " values read\n"]
              }
            } else {
              tputs $channel [appendArgs \
                  "==== WARNING: failed to reset setting statistics for " \
                  "the previous " $nameCount " names and " $valueCount \
                  " values read, error: " \n\t $error \n]
            }
          }
        }

        if {[catch {
          object invoke -flags +NonPublic -alias \
              System.Data.SQLite.DebugData settingFileReadCounts
        } settingFileReadCounts] == 0} then {
          set nameCount [$settingFileReadCounts Count]
          set valueCount 0

          object foreach -alias pair $settingFileReadCounts {
            incr valueCount [$pair Value]

            if {!$quiet} then {
              tputs $channel [appendArgs \
                  "---- setting \"" [$pair Key] "\" was read " \
                  [$pair Value] " times from the configuration file\n"]
            }
          }

          if {$reset} then {
            if {[catch {$settingFileReadCounts Clear} error] == 0} then {
              if {!$quiet} then {
                tputs $channel [appendArgs \
                    "---- reset setting statistics for the previous " \
                    $nameCount " names and " $valueCount " values read " \
                    "from the configuration file\n"]
              }
            } else {
              tputs $channel [appendArgs \
                  "==== WARNING: failed to reset setting statistics for " \
                  "the previous " $nameCount " names and " $valueCount \
                  " values read from the configuration file, error: " \n\t \
                  $error \n]
            }
          }
        }
      }

      if {[haveSQLiteObjectCommand] && \
          [haveSQLiteDefineConstant INTEROP_VIRTUAL_TABLE] && \
          [haveSQLiteDefineConstant TRACK_MEMORY_BYTES]} then {