System.Data.SQLite

Check-in [b3872ff42e]
Login

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

Overview
Comment:Add tests for the database option values added via check-in [b7ba6996c1].
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: b3872ff42e5c23017ef56ac778df6b8c836aafd7
User & Date: mistachkin 2018-02-26 19:17:37.403
Context
2018-02-26
19:31
Enhancements to tests added by the previous check-in. check-in: e2dffd3a80 user: mistachkin tags: trunk
19:17
Add tests for the database option values added via check-in [b7ba6996c1]. check-in: b3872ff42e user: mistachkin tags: trunk
17:36
The initial result code for SQLITE_DBCONFIG_MAINDBNAME must be an error in order to make the finally cleanup logic correct. check-in: b8d115e87d user: mistachkin tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to System.Data.SQLite/SQLite3.cs.
2765
2766
2767
2768
2769
2770
2771
















































2772
2773
2774
2775
2776
2777
2778
            {
                SQLiteMemory.Free(pName);
                pName = IntPtr.Zero;
            }
        }
    }
#endif

















































    /// <summary>
    /// Builds an error message string fragment containing the
    /// defined values of the <see cref="SQLiteConfigDbOpsEnum" />
    /// enumeration.
    /// </summary>
    /// <returns>







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







2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
            {
                SQLiteMemory.Free(pName);
                pName = IntPtr.Zero;
            }
        }
    }
#endif

    /// <summary>
    /// Builds an error message string fragment containing the
    /// defined values of the <see cref="SQLiteStatusOpsEnum" />
    /// enumeration.
    /// </summary>
    /// <returns>
    /// The built string fragment.
    /// </returns>
    private static string GetStatusDbOpsNames()
    {
        StringBuilder builder = new StringBuilder();

#if !PLATFORM_COMPACTFRAMEWORK
        foreach (string name in Enum.GetNames(
                typeof(SQLiteStatusOpsEnum)))
        {
            if (String.IsNullOrEmpty(name))
                continue;

            if (builder.Length > 0)
                builder.Append(", ");

            builder.Append(name);
        }
#else
        //
        // TODO: Update this list if the available values in the
        //       "SQLiteConfigDbOpsEnum" enumeration change.
        //
        builder.AppendFormat(CultureInfo.InvariantCulture,
            "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}",
            SQLiteStatusOpsEnum.SQLITE_DBSTATUS_LOOKASIDE_USED,
            SQLiteStatusOpsEnum.SQLITE_DBSTATUS_CACHE_USED,
            SQLiteStatusOpsEnum.SQLITE_DBSTATUS_SCHEMA_USED,
            SQLiteStatusOpsEnum.SQLITE_DBSTATUS_STMT_USED,
            SQLiteStatusOpsEnum.SQLITE_DBSTATUS_LOOKASIDE_HIT,
            SQLiteStatusOpsEnum.SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE,
            SQLiteStatusOpsEnum.SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL,
            SQLiteStatusOpsEnum.SQLITE_DBSTATUS_CACHE_HIT,
            SQLiteStatusOpsEnum.SQLITE_DBSTATUS_CACHE_MISS,
            SQLiteStatusOpsEnum.SQLITE_DBSTATUS_CACHE_WRITE,
            SQLiteStatusOpsEnum.SQLITE_DBSTATUS_DEFERRED_FKS,
            SQLiteStatusOpsEnum.SQLITE_DBSTATUS_CACHE_USED_SHARED);
#endif

        return builder.ToString();
    }

    /// <summary>
    /// Builds an error message string fragment containing the
    /// defined values of the <see cref="SQLiteConfigDbOpsEnum" />
    /// enumeration.
    /// </summary>
    /// <returns>
2811
2812
2813
2814
2815
2816
2817






































2818
2819
2820
2821
2822
2823
2824
            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE,
            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_ENABLE_QPSG,
            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_TRIGGER_EQP);
#endif

        return builder.ToString();
    }







































    /// <summary>
    /// Change a configuration option value for the database.
    /// connection.
    /// </summary>
    /// <param name="option">
    /// The database configuration option to change.







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







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
            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE,
            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_ENABLE_QPSG,
            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_TRIGGER_EQP);
#endif

        return builder.ToString();
    }

    /// <summary>
    /// Returns the current and/or highwater values for the specified
    /// database status parameter.
    /// </summary>
    /// <param name="option">
    /// The database status parameter to query.
    /// </param>
    /// <param name="reset">
    /// Non-zero to reset the highwater value to the current value.
    /// </param>
    /// <param name="current">
    /// If applicable, receives the current value.
    /// </param>
    /// <param name="highwater">
    /// If applicable, receives the highwater value.
    /// </param>
    /// <returns>
    /// A standard SQLite return code.
    /// </returns>
    internal override SQLiteErrorCode GetStatusParameter(
        SQLiteStatusOpsEnum option,
        bool reset,
        ref int current,
        ref int highwater
        )
    {
        if (!Enum.IsDefined(typeof(SQLiteStatusOpsEnum), option))
        {
            throw new SQLiteException(HelperMethods.StringFormat(
                CultureInfo.CurrentCulture,
                "unrecognized status option, must be: {0}",
                GetStatusDbOpsNames()));
        }

        return UnsafeNativeMethods.sqlite3_db_status(
            _sql, option, ref current, ref highwater, reset ? 1 : 0);
    }

    /// <summary>
    /// Change a configuration option value for the database.
    /// connection.
    /// </summary>
    /// <param name="option">
    /// The database configuration option to change.
Changes to System.Data.SQLite/SQLiteBase.cs.
370
371
372
373
374
375
376



















377
378
379
380
381
382
383
    /// <returns>
    /// A standard SQLite return code.
    /// </returns>
    internal abstract SQLiteErrorCode DeclareVirtualFunction(SQLiteModule module, int argumentCount, string name, ref string error);
#endif

    /// <summary>



















    /// Change a configuration option value for the database.
    /// </summary>
    /// <param name="option">
    /// The database configuration option to change.
    /// </param>
    /// <param name="value">
    /// The new value for the specified configuration option.







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







370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
    /// <returns>
    /// A standard SQLite return code.
    /// </returns>
    internal abstract SQLiteErrorCode DeclareVirtualFunction(SQLiteModule module, int argumentCount, string name, ref string error);
#endif

    /// <summary>
    /// Returns the current and/or highwater values for the specified database status parameter.
    /// </summary>
    /// <param name="option">
    /// The database status parameter to query.
    /// </param>
    /// <param name="reset">
    /// Non-zero to reset the highwater value to the current value.
    /// </param>
    /// <param name="current">
    /// If applicable, receives the current value.
    /// </param>
    /// <param name="highwater">
    /// If applicable, receives the highwater value.
    /// </param>
    /// <returns>
    /// A standard SQLite return code.
    /// </returns>
    internal abstract SQLiteErrorCode GetStatusParameter(SQLiteStatusOpsEnum option, bool reset, ref int current, ref int highwater);
    /// <summary>
    /// Change a configuration option value for the database.
    /// </summary>
    /// <param name="option">
    /// The database configuration option to change.
    /// </param>
    /// <param name="value">
    /// The new value for the specified configuration option.
1361
1362
1363
1364
1365
1366
1367



















































































































1368
1369
1370
1371
1372
1373
1374
      Default = LogDefault | BindInvariantDecimal | GetInvariantDecimal,

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




















































































































  /// <summary>
  /// These are the supported configuration verbs for use with the native
  /// SQLite library.  They are used with the
  /// <see cref="SQLiteConnection.SetConfigurationOption" /> method.
  /// </summary>
  public enum SQLiteConfigDbOpsEnum







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







1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
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
1471
1472
1473
1474
1475
1476
1477
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
1504
1505
1506
1507
1508
      Default = LogDefault | BindInvariantDecimal | GetInvariantDecimal,

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

  /// <summary>
  /// These are the supported status parameters for use with the native
  /// SQLite library.
  /// </summary>
  internal enum SQLiteStatusOpsEnum
  {
      /// <summary>
      /// This parameter returns the number of lookaside memory slots
      /// currently checked out.
      /// </summary>
      SQLITE_DBSTATUS_LOOKASIDE_USED = 0,

      /// <summary>
      /// This parameter returns the approximate number of bytes of
      /// heap memory used by all pager caches associated with the
      /// database connection. The highwater mark associated with
      /// SQLITE_DBSTATUS_CACHE_USED is always 0.
      /// </summary>
      SQLITE_DBSTATUS_CACHE_USED = 1,

      /// <summary>
      /// This parameter returns the approximate number of bytes of
      /// heap memory used to store the schema for all databases
      /// associated with the connection - main, temp, and any ATTACH-ed
      /// databases. The full amount of memory used by the schemas is
      /// reported, even if the schema memory is shared with other
      /// database connections due to shared cache mode being enabled.
      /// The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED
      /// is always 0.
      /// </summary>
      SQLITE_DBSTATUS_SCHEMA_USED = 2,

      /// <summary>
      /// This parameter returns the number malloc attempts that might
      /// have been satisfied using lookaside memory but failed due to
      /// all lookaside memory already being in use. Only the high-water
      /// value is meaningful; the current value is always zero.
      /// </summary>
      SQLITE_DBSTATUS_STMT_USED = 3,

      /// <summary>
      /// This parameter returns the number malloc attempts that were
      /// satisfied using lookaside memory. Only the high-water value
      /// is meaningful; the current value is always zero.
      /// </summary>
      SQLITE_DBSTATUS_LOOKASIDE_HIT = 4,

      /// <summary>
      /// This parameter returns the number malloc attempts that might
      /// have been satisfied using lookaside memory but failed due to
      /// the amount of memory requested being larger than the lookaside
      /// slot size. Only the high-water value is meaningful; the current
      /// value is always zero.
      /// </summary>
      SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE = 5,

      /// <summary>
      /// This parameter returns the number malloc attempts that might
      /// have been satisfied using lookaside memory but failed due to
      /// the amount of memory requested being larger than the lookaside
      /// slot size. Only the high-water value is meaningful; the current
      /// value is always zero.
      /// </summary>
      SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL = 6,

      /// <summary>
      /// This parameter returns the number of pager cache hits that
      /// have occurred. The highwater mark associated with
      /// SQLITE_DBSTATUS_CACHE_HIT is always 0.
      /// </summary>
      SQLITE_DBSTATUS_CACHE_HIT = 7,

      /// <summary>
      /// This parameter returns the number of pager cache misses that
      /// have occurred. The highwater mark associated with
      /// SQLITE_DBSTATUS_CACHE_MISS is always 0.
      /// </summary>
      SQLITE_DBSTATUS_CACHE_MISS = 8,

      /// <summary>
      /// This parameter returns the number of dirty cache entries that
      /// have been written to disk. Specifically, the number of pages
      /// written to the wal file in wal mode databases, or the number
      /// of pages written to the database file in rollback mode
      /// databases. Any pages written as part of transaction rollback
      /// or database recovery operations are not included. If an IO or
      /// other error occurs while writing a page to disk, the effect
      /// on subsequent SQLITE_DBSTATUS_CACHE_WRITE requests is
      /// undefined. The highwater mark associated with
      /// SQLITE_DBSTATUS_CACHE_WRITE is always 0.
      /// </summary>
      SQLITE_DBSTATUS_CACHE_WRITE = 9,

      /// <summary>
      /// This parameter returns zero for the current value if and only
      /// if all foreign key constraints (deferred or immediate) have
      /// been resolved. The highwater mark is always 0.
      /// </summary>
      SQLITE_DBSTATUS_DEFERRED_FKS = 10,

      /// <summary>
      /// This parameter is similar to DBSTATUS_CACHE_USED, except that
      /// if a pager cache is shared between two or more connections the
      /// bytes of heap memory used by that pager cache is divided evenly
      /// between the attached connections. In other words, if none of
      /// the pager caches associated with the database connection are
      /// shared, this request returns the same value as DBSTATUS_CACHE_USED.
      /// Or, if one or more or the pager caches are shared, the value
      /// returned by this call will be smaller than that returned by
      /// DBSTATUS_CACHE_USED. The highwater mark associated with
      /// SQLITE_DBSTATUS_CACHE_USED_SHARED is always 0.
      /// </summary>
      SQLITE_DBSTATUS_CACHE_USED_SHARED = 11
  }

  /// <summary>
  /// These are the supported configuration verbs for use with the native
  /// SQLite library.  They are used with the
  /// <see cref="SQLiteConnection.SetConfigurationOption" /> method.
  /// </summary>
  public enum SQLiteConfigDbOpsEnum
Changes to System.Data.SQLite/UnsafeNativeMethods.cs.
3858
3859
3860
3861
3862
3863
3864







3865
3866
3867
3868
3869
3870
3871
#if !PLATFORM_COMPACTFRAMEWORK
    [DllImport(SQLITE_DLL, EntryPoint = "sqlite3_db_config", CallingConvention = CallingConvention.Cdecl)]
#else
    [DllImport(SQLITE_DLL, EntryPoint = "sqlite3_db_config")]
#endif
    internal static extern SQLiteErrorCode sqlite3_db_config_intptr_two_ints(IntPtr db, SQLiteConfigDbOpsEnum op, IntPtr ptr, int int0, int int1);








#if !PLATFORM_COMPACTFRAMEWORK
    [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
#else
    [DllImport(SQLITE_DLL)]
#endif
    internal static extern IntPtr sqlite3_rollback_hook(IntPtr db, SQLiteRollbackCallback func, IntPtr pvUser);








>
>
>
>
>
>
>







3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
#if !PLATFORM_COMPACTFRAMEWORK
    [DllImport(SQLITE_DLL, EntryPoint = "sqlite3_db_config", CallingConvention = CallingConvention.Cdecl)]
#else
    [DllImport(SQLITE_DLL, EntryPoint = "sqlite3_db_config")]
#endif
    internal static extern SQLiteErrorCode sqlite3_db_config_intptr_two_ints(IntPtr db, SQLiteConfigDbOpsEnum op, IntPtr ptr, int int0, int int1);

#if !PLATFORM_COMPACTFRAMEWORK
    [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
#else
    [DllImport(SQLITE_DLL)]
#endif
    internal static extern SQLiteErrorCode sqlite3_db_status(IntPtr db, SQLiteStatusOpsEnum op, ref int current, ref int highwater, int resetFlag);

#if !PLATFORM_COMPACTFRAMEWORK
    [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
#else
    [DllImport(SQLITE_DLL)]
#endif
    internal static extern IntPtr sqlite3_rollback_hook(IntPtr db, SQLiteRollbackCallback func, IntPtr pvUser);

Changes to Tests/basic.eagle.
4921
4922
4923
4924
4925
4926
4927


















































































4928
4929
4930
4931
4932
4933
4934
warning message} 231 {unknown error ==> unknown error} {0 {}}\
Ok_Load_Permanently {not an error ==> not an error} Error_Retry {SQL logic\
error ==> SQL logic error} IoErr_Short_Read {disk I/O error ==> disk I/O error}\
CantOpen_NoTempDir {unable to open database file ==> unable to open database\
file} Notice_Recover_Rollback {notification message ==> notification message}\
Warning_AutoIndex {warning message ==> warning message} 999 {unknown error ==>\
unknown error}}}



















































































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

reportSQLiteResources $test_channel

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








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







4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
warning message} 231 {unknown error ==> unknown error} {0 {}}\
Ok_Load_Permanently {not an error ==> not an error} Error_Retry {SQL logic\
error ==> SQL logic error} IoErr_Short_Read {disk I/O error ==> disk I/O error}\
CantOpen_NoTempDir {unable to open database file ==> unable to open database\
file} Notice_Recover_Rollback {notification message ==> notification message}\
Warning_AutoIndex {warning message ==> warning message} 999 {unknown error ==>\
unknown error}}}

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

runTest {test data-1.95 {SetConfigurationOption method} -setup {
  setupDb [set fileName data-1.95.db]
} -body {
  set dbConfigs [list]

  lappend dbConfigs SQLITE_DBCONFIG_NONE; # nil
  lappend dbConfigs SQLITE_DBCONFIG_MAINDBNAME; # char*
  lappend dbConfigs SQLITE_DBCONFIG_LOOKASIDE; # void* int int

  lappend dbConfigs SQLITE_DBCONFIG_ENABLE_FKEY; # int int*
  lappend dbConfigs SQLITE_DBCONFIG_ENABLE_TRIGGER; # int int*
  lappend dbConfigs SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER; # int int*
  lappend dbConfigs SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION; # int int*
  lappend dbConfigs SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE; # int int*
  lappend dbConfigs SQLITE_DBCONFIG_ENABLE_QPSG; # int int*
  lappend dbConfigs SQLITE_DBCONFIG_TRIGGER_EQP; # int int*

  set connection [getDbConnection]

  foreach dbConfig $dbConfigs {
    switch -exact -- $dbConfig {
      SQLITE_DBCONFIG_NONE {
        set value null
      }
      SQLITE_DBCONFIG_MAINDBNAME {
        set value [object create String test]
      }
      SQLITE_DBCONFIG_LOOKASIDE {
        if {[info exists ptr]} then {
          error "pointer value should not exist yet"
        }

        set ptr [object invoke -create -flags +NonPublic \
            System.Data.SQLite.SQLiteMemory Allocate 20000]

        set ints(0) [object invoke -create Int32 Parse 10000]
        set ints(1) [object invoke -create Int32 Parse 2]

        set value [object create -alias Object\[\] 3]

        $value SetValue $ptr 0
        $value SetValue $ints(0) 1
        $value SetValue $ints(1) 2
      }
      default {
        set value [object invoke -create System.Boolean Parse true]
      }
    }

    lappend result [$connection SetConfigurationOption $dbConfig $value]
  }

  sql execute $db {
    CREATE TABLE t1(x);
    INSERT INTO t1 (x) VALUES(RANDOMBLOB(1024));
  }

  set current 0; set highwater 0

  lappend result [$connection -flags +NonPublic \
      _sql.GetStatusParameter SQLITE_DBSTATUS_LOOKASIDE_USED \
      false current highwater]

  lappend result $current $highwater
} -cleanup {
  cleanupDb $fileName

  freeDbConnection

  if {[info exists ptr]} then {
    object invoke -flags +NonPublic \
        System.Data.SQLite.SQLiteMemory Free $ptr
  }

  unset -nocomplain current highwater ints ptr value
  unset -nocomplain result dbConfig dbConfigs
  unset -nocomplain connection db fileName
} -constraints {eagle monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite} -result {{} {} {} {} {} {} {} {} {} {} Ok 48 100}}

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

reportSQLiteResources $test_channel

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