System.Data.SQLite

Check-in [d279011853]
Login

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

Overview
Comment:Initial work on being able to change limits via sqlite3_limit().
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | limits
Files: files | file ages | folders
SHA1: d279011853abd504c1f858f42a17539da83e116f
User & Date: mistachkin 2019-10-24 22:37:59.615
Context
2019-10-26
23:06
Some fixes. Add tests. Update version history docs. check-in: e82be4000d user: mistachkin tags: limits
2019-10-24
22:37
Initial work on being able to change limits via sqlite3_limit(). check-in: d279011853 user: mistachkin tags: limits
2019-10-20
04:37
Update Eagle in externals to the beta 45 release. check-in: a8c34ef499 user: mistachkin tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to System.Data.SQLite/SQLite3.cs.
2855
2856
2857
2858
2859
2860
2861
















































2862
2863
2864
2865
2866
2867
2868
            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>







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







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
2913
2914
2915
2916
            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="SQLiteLimitOpsEnum" />
    /// enumeration.
    /// </summary>
    /// <returns>
    /// The built string fragment.
    /// </returns>
    private static string GetLimitOpsNames()
    {
        StringBuilder builder = new StringBuilder();

#if !PLATFORM_COMPACTFRAMEWORK
        foreach (string name in Enum.GetNames(
                typeof(SQLiteLimitOpsEnum)))
        {
            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
        //       "SQLiteLimitOpsEnum" enumeration change.
        //
        builder.AppendFormat(CultureInfo.InvariantCulture,
            "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}",
            SQLiteConfigDbOpsEnum.SQLITE_LIMIT_LENGTH,
            SQLiteConfigDbOpsEnum.SQLITE_LIMIT_SQL_LENGTH,
            SQLiteConfigDbOpsEnum.SQLITE_LIMIT_COLUMN,
            SQLiteConfigDbOpsEnum.SQLITE_LIMIT_EXPR_DEPTH,
            SQLiteConfigDbOpsEnum.SQLITE_LIMIT_COMPOUND_SELECT,
            SQLiteConfigDbOpsEnum.SQLITE_LIMIT_VDBE_OP,
            SQLiteConfigDbOpsEnum.SQLITE_LIMIT_FUNCTION_ARG,
            SQLiteConfigDbOpsEnum.SQLITE_LIMIT_ATTACHED,
            SQLiteConfigDbOpsEnum.SQLITE_LIMIT_LIKE_PATTERN_LENGTH,
            SQLiteConfigDbOpsEnum.SQLITE_LIMIT_VARIABLE_NUMBER,
            SQLiteConfigDbOpsEnum.SQLITE_LIMIT_TRIGGER_DEPTH,
            SQLiteConfigDbOpsEnum.SQLITE_LIMIT_WORKER_THREADS);
#endif

        return builder.ToString();
    }

    /// <summary>
    /// Builds an error message string fragment containing the
    /// defined values of the <see cref="SQLiteConfigDbOpsEnum" />
    /// enumeration.
    /// </summary>
    /// <returns>
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
        }
#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}",

            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_NONE,
            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_MAINDBNAME,
            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_LOOKASIDE,
            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_ENABLE_FKEY,
            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_ENABLE_TRIGGER,
            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER,
            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION,
            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







|
>









|
>
>
>
>
>
>
>







2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
        }
#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}, {12}, {13}, {14}, {15}, {16}",
            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_NONE,
            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_MAINDBNAME,
            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_LOOKASIDE,
            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_ENABLE_FKEY,
            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_ENABLE_TRIGGER,
            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER,
            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION,
            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE,
            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_ENABLE_QPSG,
            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_TRIGGER_EQP,
            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_RESET_DATABASE,
            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_DEFENSIVE,
            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_WRITABLE_SCHEMA,
            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_LEGACY_ALTER_TABLE,
            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_DQS_DML,
            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_DQS_DDL,
            SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_ENABLE_VIEW);
#endif

        return builder.ToString();
    }

    /// <summary>
    /// Returns the current and/or highwater values for the specified
2939
2940
2941
2942
2943
2944
2945
2946
2947




























2948
2949
2950
2951
2952
2953
2954
2955
2956
                "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.
    /// </param>
    /// <param name="value">
    /// The new value for the specified configuration option.
    /// </param>









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

<







2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032

3033
3034
3035
3036
3037
3038
3039
                "unrecognized status option, must be: {0}",
                GetStatusDbOpsNames()));
        }

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

    /// <summary>
    /// Change a limit value for the database.
    /// </summary>
    /// <param name="option">
    /// The database limit to change.
    /// </param>
    /// <param name="value">
    /// The new value for the specified limit.
    /// </param>
    /// <returns>
    /// A standard SQLite return code.
    /// </returns>
    internal override SQLiteErrorCode SetLimitOption(
        SQLiteLimitOpsEnum option,
        int value
        )
    {
        if (!Enum.IsDefined(typeof(SQLiteLimitOpsEnum), option))
        {
            throw new SQLiteException(HelperMethods.StringFormat(
                CultureInfo.CurrentCulture,
                "unrecognized limit option, must be: {0}",
                GetLimitOpsNames()));
        }

        return UnsafeNativeMethods.sqlite3_limit(_sql, option, value);
    }

    /// <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.
    /// </param>
Changes to System.Data.SQLite/SQLiteBase.cs.
390
391
392
393
394
395
396













397
398
399
400
401
402
403
    /// 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.







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







390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
    /// 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 limit value for the database.
    /// </summary>
    /// <param name="option">
    /// The database limit to change.
    /// </param>
    /// <param name="value">
    /// The new value for the specified limit.
    /// </param>
    /// <returns>
    /// A standard SQLite return code.
    /// </returns>
    internal abstract SQLiteErrorCode SetLimitOption(SQLiteLimitOpsEnum option, int value);
    /// <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.
1703
1704
1705
1706
1707
1708
1709
1710










































































  {
      SQLITE_TRACE_NONE = 0x0, // nil
      SQLITE_TRACE_STMT = 0x1, // pStmt, zSql
      SQLITE_TRACE_PROFILE = 0x2, // pStmt, piNsec64
      SQLITE_TRACE_ROW = 0x4, // pStmt
      SQLITE_TRACE_CLOSE = 0x8 // pDb
  }
}

















































































|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
  {
      SQLITE_TRACE_NONE = 0x0, // nil
      SQLITE_TRACE_STMT = 0x1, // pStmt, zSql
      SQLITE_TRACE_PROFILE = 0x2, // pStmt, piNsec64
      SQLITE_TRACE_ROW = 0x4, // pStmt
      SQLITE_TRACE_CLOSE = 0x8 // pDb
  }

  /// <summary>
  /// These constants are used with the sqlite3_limit() API.
  /// </summary>
  public enum SQLiteLimitOpsEnum
  {
      /// <summary>
      /// The maximum size of any string or BLOB or table row, in bytes.
      /// </summary>
      SQLITE_LIMIT_LENGTH = 0,

      /// <summary>
      /// The maximum length of an SQL statement, in bytes.
      /// </summary>
      SQLITE_LIMIT_SQL_LENGTH = 1,

      /// <summary>
      /// The maximum number of columns in a table definition or in the
      /// result set of a SELECT or the maximum number of columns in an
      /// index or in an ORDER BY or GROUP BY clause.
      /// </summary>
      SQLITE_LIMIT_COLUMN = 2,

      /// <summary>
      /// The maximum depth of the parse tree on any expression.
      /// </summary>
      SQLITE_LIMIT_EXPR_DEPTH = 3,

      /// <summary>
      /// The maximum number of terms in a compound SELECT statement.
      /// </summary>
      SQLITE_LIMIT_COMPOUND_SELECT = 4,

      /// <summary>
      /// The maximum number of instructions in a virtual machine program
      /// used to implement an SQL statement. If sqlite3_prepare_v2() or
      /// the equivalent tries to allocate space for more than this many
      /// opcodes in a single prepared statement, an SQLITE_NOMEM error
      /// is returned.
      /// </summary>
      SQLITE_LIMIT_VDBE_OP = 5,

      /// <summary>
      /// The maximum number of arguments on a function.
      /// </summary>
      SQLITE_LIMIT_FUNCTION_ARG = 6,

      /// <summary>
      /// The maximum number of attached databases.
      /// </summary>
      SQLITE_LIMIT_ATTACHED = 7,

      /// <summary>
      /// The maximum length of the pattern argument to the LIKE or GLOB
      /// operators.
      /// </summary>
      SQLITE_LIMIT_LIKE_PATTERN_LENGTH = 8,

      /// <summary>
      /// The maximum index number of any parameter in an SQL statement.
      /// </summary>
      SQLITE_LIMIT_VARIABLE_NUMBER = 9,

      /// <summary>
      /// The maximum depth of recursion for triggers.
      /// </summary>
      SQLITE_LIMIT_TRIGGER_DEPTH = 10,

      /// <summary>
      /// The maximum number of auxiliary worker threads that a single
      /// prepared statement may start.
      /// </summary>
      SQLITE_LIMIT_WORKER_THREADS = 11
  }
}
Changes to System.Data.SQLite/SQLiteConnection.cs.
3927
3928
3929
3930
3931
3932
3933




























3934
3935
3936
3937
3938
3939
3940
        catch
        {
            result = 0;
            return false;
        }
#endif
    }





























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







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







3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
        catch
        {
            result = 0;
            return false;
        }
#endif
    }

    /// <summary>
    /// Change a limit value for the database.
    /// </summary>
    /// <param name="option">
    /// The database limit to change.
    /// </param>
    /// <param name="value">
    /// The new value for the specified limit.
    /// </param>
    public void SetLimitOption(
        SQLiteLimitOpsEnum option,
        int value
        )
    {
        CheckDisposed();

        if (_sql == null)
        {
            throw new InvalidOperationException(
                "Database connection not valid for changing a limit option.");
        }

        SQLiteErrorCode rc = _sql.SetLimitOption(option, value);

        if (rc != SQLiteErrorCode.Ok)
            throw new SQLiteException(rc, null);
    }

    /// <summary>
    /// Change a configuration option value for the database.
    /// </summary>
    /// <param name="option">
    /// The database configuration option to change.
    /// </param>
Changes to System.Data.SQLite/UnsafeNativeMethods.cs.
4303
4304
4305
4306
4307
4308
4309







4310
4311
4312
4313
4314
4315
4316
#if !PLATFORM_COMPACTFRAMEWORK
    [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
#else
    [DllImport(SQLITE_DLL)]
#endif
    internal static extern IntPtr sqlite3_trace_v2(IntPtr db, SQLiteTraceFlags mask, SQLiteTraceCallback2 func, IntPtr pvUser);








    // Since sqlite3_config() takes a variable argument list, we have to overload declarations
    // for all possible calls that we want to use.
#if !PLATFORM_COMPACTFRAMEWORK
    [DllImport(SQLITE_DLL, EntryPoint = "sqlite3_config", CallingConvention = CallingConvention.Cdecl)]
#else
    [DllImport(SQLITE_DLL, EntryPoint = "sqlite3_config")]
#endif







>
>
>
>
>
>
>







4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
#if !PLATFORM_COMPACTFRAMEWORK
    [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
#else
    [DllImport(SQLITE_DLL)]
#endif
    internal static extern IntPtr sqlite3_trace_v2(IntPtr db, SQLiteTraceFlags mask, SQLiteTraceCallback2 func, IntPtr pvUser);

#if !PLATFORM_COMPACTFRAMEWORK
    [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]
#else
    [DllImport(SQLITE_DLL)]
#endif
    internal static extern SQLiteErrorCode sqlite3_limit(IntPtr db, SQLiteLimitOpsEnum op, int value);

    // Since sqlite3_config() takes a variable argument list, we have to overload declarations
    // for all possible calls that we want to use.
#if !PLATFORM_COMPACTFRAMEWORK
    [DllImport(SQLITE_DLL, EntryPoint = "sqlite3_config", CallingConvention = CallingConvention.Cdecl)]
#else
    [DllImport(SQLITE_DLL, EntryPoint = "sqlite3_config")]
#endif