System.Data.SQLite
Check-in [6a90082172]
Not logged in

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

Overview
Comment:Add enumerated Flags property to the SQLiteConnection class to control extra behavioral options.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 6a90082172d317c3ff1ea88e441574a908b4482e
User & Date: mistachkin 2012-01-25 17:09:59
Context
2012-01-25
17:37
Fix the default value of the connection flags for the setupDb unit test infrastructure script library procedure. check-in: 96c981c40b user: mistachkin tags: trunk
17:09
Add enumerated Flags property to the SQLiteConnection class to control extra behavioral options. check-in: 6a90082172 user: mistachkin tags: trunk
09:27
Update MSVC redists in Externals to the latest ones from Microsoft. check-in: bbec0d9d38 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to System.Data.SQLite/SQLite3.cs.

   363    363             strSql = strSql.Replace(
   364    364                 String.Format("[{0}].", baseSchemaName), String.Empty);
   365    365   
   366    366             strSql = strSql.Replace(
   367    367                 String.Format("{0}.", baseSchemaName), String.Empty);
   368    368           }
   369    369         }
          370  +
          371  +      if ((cnn != null) &&
          372  +          ((cnn.Flags & SQLiteConnectionFlags.LogPrepare) == SQLiteConnectionFlags.LogPrepare))
          373  +      {
          374  +          LogMessage(0, String.Format("Preparing {{{0}}}...", strSql));
          375  +      }
   370    376   
   371    377         IntPtr stmt = IntPtr.Zero;
   372    378         IntPtr ptr = IntPtr.Zero;
   373    379         int len = 0;
   374    380         int n = 17;
   375    381         int retries = 0;
   376    382         byte[] b = ToUTF8(strSql);

Changes to System.Data.SQLite/SQLiteBase.cs.

   364    364       None = 0,
   365    365       ReadOnly = 0x01,
   366    366       ReadWrite = 0x02,
   367    367       Create = 0x04,
   368    368       SharedCache = 0x01000000,
   369    369       Default = 0x06,
   370    370     }
          371  +
          372  +  /// <summary>
          373  +  /// The extra behavioral flags that can be applied to a connection.
          374  +  /// </summary>
          375  +  [Flags()]
          376  +  public enum SQLiteConnectionFlags
          377  +  {
          378  +      /// <summary>
          379  +      /// No extra flags.
          380  +      /// </summary>
          381  +      None = 0x0,
          382  +
          383  +      /// <summary>
          384  +      /// Enable logging of all SQL statements to be prepared.
          385  +      /// </summary>
          386  +      LogPrepare = 0x1,
          387  +
          388  +      /// <summary>
          389  +      /// The default extra flags for new connections.
          390  +      /// </summary>
          391  +      Default = None
          392  +  }
   371    393   
   372    394     // These are the options to the internal sqlite3_config call.
   373    395     internal enum SQLiteConfigOpsEnum
   374    396     {
   375    397       SQLITE_CONFIG_NONE = 0, // nil 
   376    398       SQLITE_CONFIG_SINGLETHREAD = 1, // nil 
   377    399       SQLITE_CONFIG_MULTITHREAD = 2, // nil 

Changes to System.Data.SQLite/SQLiteConnection.cs.

   159    159     /// </item>
   160    160     /// <item>
   161    161     /// <description>Foreign Keys</description>
   162    162     /// <description>Enable foreign key constraints</description>
   163    163     /// <description>N</description>
   164    164     /// <description>False</description>
   165    165     /// </item>
          166  +  /// <item>
          167  +  /// <description>Flags</description>
          168  +  /// <description>Extra behavioral flags for the connection.  See the SQLiteConnectionFlags enumeration for possible values.</description>
          169  +  /// <description>N</description>
          170  +  /// <description>Default</description>
          171  +  /// </item>
   166    172     /// </list>
   167    173     /// </remarks>
   168    174     public sealed partial class SQLiteConnection : DbConnection, ICloneable
   169    175     {
   170    176       /// <summary>
   171    177       /// The default "stub" (i.e. placeholder) base schema name to use when
   172    178       /// returning column schema information.  Used as the initial value of
................................................................................
   221    227   
   222    228       /// <summary>
   223    229       /// The "stub" (i.e. placeholder) base schema name to use when returning
   224    230       /// column schema information.
   225    231       /// </summary>
   226    232       internal string _baseSchemaName;
   227    233   
          234  +    /// <summary>
          235  +    /// The extra behavioral flags for this connection, if any.  See the
          236  +    /// SQLiteConnectionFlags enumeration for a list of possible values.
          237  +    /// </summary>
          238  +    private SQLiteConnectionFlags _flags;
          239  +
   228    240       /// <summary>
   229    241       /// Default command timeout
   230    242       /// </summary>
   231    243       private int _defaultTimeout = 30;
   232    244   
   233    245       internal bool _binaryGuid;
   234    246   
................................................................................
   266    278       /// <param name="connectionString">The connection string to use on the connection</param>
   267    279       public SQLiteConnection(string connectionString)
   268    280       {
   269    281   #if !PLATFORM_COMPACTFRAMEWORK
   270    282         SQLiteLog.Initialize();
   271    283   #endif
   272    284   
          285  +      _flags = SQLiteConnectionFlags.Default;
   273    286         _connectionState = ConnectionState.Closed;
   274    287         _connectionString = "";
   275    288         //_commandList = new List<WeakReference>();
   276    289   
   277    290         if (connectionString != null)
   278    291           ConnectionString = connectionString;
   279    292       }
................................................................................
   827    840       {
   828    841         if (_connectionState != ConnectionState.Closed)
   829    842           throw new InvalidOperationException();
   830    843   
   831    844         Close();
   832    845   
   833    846         SortedList<string, string> opts = ParseConnectionString(_connectionString);
          847  +
          848  +      _flags = (SQLiteConnectionFlags)Enum.Parse(typeof(SQLiteConnectionFlags), FindKey(opts, "Flags", "Default"), true);
          849  +
   834    850         string fileName;
   835    851   
   836    852         if (Convert.ToInt32(FindKey(opts, "Version", "3"), CultureInfo.InvariantCulture) != 3)
   837    853           throw new NotSupportedException("Only SQLite Version 3 is supported at this time");
   838    854   
   839    855         fileName = FindKey(opts, "Data Source", "");
   840    856   
................................................................................
  1013   1029       /// This can also be set in the ConnectionString with "Default Timeout"
  1014   1030       /// </summary>
  1015   1031       public int DefaultTimeout
  1016   1032       {
  1017   1033         get { return _defaultTimeout; }
  1018   1034         set { _defaultTimeout = value; }
  1019   1035       }
         1036  +
         1037  +    /// <summary>
         1038  +    /// Gets/sets the extra behavioral flags for this connection.  See the
         1039  +    /// SQLiteConnectionFlags enumeration for a list of possible values.
         1040  +    /// </summary>
         1041  +    public SQLiteConnectionFlags Flags
         1042  +    {
         1043  +      get { return _flags; }
         1044  +      set { _flags = value; }
         1045  +    }
  1020   1046   
  1021   1047       /// <summary>
  1022   1048       /// Returns the version of the underlying SQLite database engine
  1023   1049       /// </summary>
  1024   1050   #if !PLATFORM_COMPACTFRAMEWORK
  1025   1051       [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1026   1052   #endif

Changes to System.Data.SQLite/SQLiteConnectionStringBuilder.cs.

   534    534               return SQLiteConvert.ToBoolean(value);
   535    535           }
   536    536           set
   537    537           {
   538    538               this["foreign keys"] = value;
   539    539           }
   540    540       }
          541  +
          542  +    /// <summary>
          543  +    /// Gets/Sets the extra behavioral flags.
          544  +    /// </summary>
          545  +    [Browsable(true)]
          546  +    [DefaultValue(SQLiteConnectionFlags.Default)]
          547  +    public SQLiteConnectionFlags Flags
          548  +    {
          549  +        get
          550  +        {
          551  +            object value;
          552  +
          553  +            if (TryGetValue("flags", out value))
          554  +            {
          555  +                if (value is SQLiteConnectionFlags)
          556  +                    return (SQLiteConnectionFlags)value;
          557  +                else if (value != null)
          558  +                    return (SQLiteConnectionFlags)TypeDescriptor.GetConverter(
          559  +                        typeof(SQLiteConnectionFlags)).ConvertFrom(value);
          560  +            }
          561  +
          562  +            return SQLiteConnectionFlags.Default;
          563  +        }
          564  +        set
          565  +        {
          566  +            this["flags"] = value;
          567  +        }
          568  +    }
   541    569   
   542    570       /// <summary>
   543    571       /// Helper function for retrieving values from the connectionstring
   544    572       /// </summary>
   545    573       /// <param name="keyword">The keyword to retrieve settings for</param>
   546    574       /// <param name="value">The resulting parameter value</param>
   547    575       /// <returns>Returns true if the value was found and returned</returns>

Changes to Tests/basic.eagle.

   954    954   
   955    955     if {$code eq "Ok"} then {
   956    956       set keys [list null Version Synchronous UseUTF16Encoding Pooling \
   957    957                      BinaryGUID "Data Source" Uri "Default Timeout" \
   958    958                      Enlist FailIfMissing "Legacy Format" "Read Only" \
   959    959                      Password "Page Size" "Max Page Count" "Cache Size" \
   960    960                      DateTimeFormat DateTimeKind BaseSchemaName \
   961         -                   "Journal Mode" "Default IsolationLevel" "Foreign Keys"]
          961  +                   "Journal Mode" "Default IsolationLevel" "Foreign Keys" \
          962  +                   Flags]
   962    963   
   963    964       set values [list null 3 Full True False \
   964    965                        True test.db test.db 60 \
   965    966                        False True False True \
   966    967                        secret 4096 1024 8192 \
   967    968                        UnixEpoch Utc sqlite_schema \
   968         -                     Memory Serializable False]
          969  +                     Memory Serializable False \
          970  +                     Default]
   969    971   
   970    972       set propertyNames [list null Version SyncMode UseUTF16Encoding Pooling \
   971    973                               BinaryGUID DataSource Uri DefaultTimeout \
   972    974                               Enlist FailIfMissing LegacyFormat ReadOnly \
   973    975                               Password PageSize MaxPageCount CacheSize \
   974    976                               DateTimeFormat DateTimeKind BaseSchemaName \
   975         -                            JournalMode DefaultIsolationLevel ForeignKeys]
          977  +                            JournalMode DefaultIsolationLevel ForeignKeys \
          978  +                            Flags]
   976    979   
   977    980       foreach key $keys value $values propertyName $propertyNames {
   978    981         set code [catch {
   979    982           object invoke _Dynamic${id}.Test${id} GetConnectionString \
   980    983               $key $value $propertyName
   981    984         } result]
   982    985   
................................................................................
   996    999   Source=test\.db\} 0 \{test\.db, Uri=test\.db\} 0 \{60, Default Timeout=60\} 0\
   997   1000   \{False, Enlist=False\} 0 \{True, FailIfMissing=True\} 0 \{False, Legacy\
   998   1001   Format=False\} 0 \{True, Read Only=True\} 0 \{secret, Password=secret\} 0\
   999   1002   \{4096, Page Size=4096\} 0 \{1024, Max Page Count=1024\} 0 \{8192, Cache\
  1000   1003   Size=8192\} 0 \{UnixEpoch, DateTimeFormat=UnixEpoch\} 0 \{Utc,\
  1001   1004   DateTimeKind=Utc\} 0 \{sqlite_schema, BaseSchemaName=sqlite_schema\} 0\
  1002   1005   \{Memory, Journal Mode=Memory\} 0 \{Serializable, Default\
  1003         -IsolationLevel=Serializable\} 0 \{False, Foreign Keys=False\}$}}
         1006  +IsolationLevel=Serializable\} 0 \{False, Foreign Keys=False\} 0 \{Default,\
         1007  +Flags=Default\}$}}
  1004   1008   
  1005   1009   ###############################################################################
  1006   1010   
  1007   1011   runTest {test data-1.17 {SQLiteConvert ToDateTime (Julian Day)} -body {
  1008   1012     set dateTime [object invoke System.Data.SQLite.SQLiteConvert ToDateTime \
  1009   1013         2455928.0 Utc]
  1010   1014   

Changes to Tests/common.eagle.

   435    435         # NOTE: Evaluate the constructed [compileCSharp] command and return the
   436    436         #       result.
   437    437         #
   438    438         eval $command
   439    439       }
   440    440   
   441    441       proc setupDb {
   442         -            fileName {mode ""} {dateTimeFormat ""} {dateTimeKind ""} {extra ""}
   443         -            {delete true} {varName db} } {
          442  +            fileName {mode ""} {dateTimeFormat ""} {dateTimeKind ""} {flags "LogPrepare"}
          443  +            {extra ""} {delete true} {varName db} } {
   444    444         #
   445    445         # NOTE: For now, all test databases used by the test suite are placed into
   446    446         #       the temporary directory.  Each database used by a test should be
   447    447         #       cleaned up by that test using the "cleanupDb" procedure, below.
   448    448         #
   449    449         set fileName [file join [getDatabaseDirectory] [file tail $fileName]]
   450    450   
................................................................................
   498    498         #
   499    499         # NOTE: If the caller specified a DateTimeKind, add the necessary portion
   500    500         #       of the connection string now.
   501    501         #
   502    502         if {[string length $dateTimeKind] > 0} then {
   503    503           append connection {;DateTimeKind=${dateTimeKind}}
   504    504         }
          505  +
          506  +      #
          507  +      # NOTE: If the caller specified a SQLiteConnectionFlags, add the necessary
          508  +      #       portion of the connection string now.
          509  +      #
          510  +      if {[string length $flags] > 0} then {
          511  +        append connection {;Flags=${flags}}
          512  +      }
   505    513   
   506    514         #
   507    515         # NOTE: If the caller specified an extra payload to the connection string,
   508    516         #       append it now.
   509    517         #
   510    518         if {[string length $extra] > 0} then {
   511    519           append connection \; $extra

Changes to Tests/tkt-448d663d11.eagle.

    32     32   
    33     33   ###############################################################################
    34     34   
    35     35   runTest {test tkt-448d663d11-1.2 {missing journal mode, WAL db} -body {
    36     36     set fileName tkt-448d663d11-1.2.db
    37     37     file copy -force [file join $path wal.db] \
    38     38         [file join [getDatabaseDirectory] $fileName]
    39         -  setupDb $fileName "" "" "" "" false
           39  +  setupDb $fileName "" "" "" "" "" false
    40     40     sql execute -execute scalar $db "PRAGMA journal_mode;"
    41     41   } -cleanup {
    42     42     cleanupDb $fileName
    43     43     unset -nocomplain db fileName
    44     44   } -constraints \
    45     45   {eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} -result \
    46     46   {wal}}
................................................................................
    47     47   
    48     48   ###############################################################################
    49     49   
    50     50   runTest {test tkt-448d663d11-1.3 {missing journal mode, non-WAL db} -body {
    51     51     set fileName tkt-448d663d11-1.3.db
    52     52     file copy -force [file join $path nonWal.db] \
    53     53         [file join [getDatabaseDirectory] $fileName]
    54         -  setupDb $fileName "" "" "" "" false
           54  +  setupDb $fileName "" "" "" "" "" false
    55     55     sql execute -execute scalar $db "PRAGMA journal_mode;"
    56     56   } -cleanup {
    57     57     cleanupDb $fileName
    58     58     unset -nocomplain db fileName
    59     59   } -constraints \
    60     60   {eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} -result \
    61     61   {delete}}
................................................................................
    74     74   
    75     75   ###############################################################################
    76     76   
    77     77   runTest {test tkt-448d663d11-1.5 {'Default' journal mode, WAL db} -body {
    78     78     set fileName tkt-448d663d11-1.5.db
    79     79     file copy -force [file join $path wal.db] \
    80     80         [file join [getDatabaseDirectory] $fileName]
    81         -  setupDb $fileName Default "" "" "" false
           81  +  setupDb $fileName Default "" "" "" "" false
    82     82     sql execute -execute scalar $db "PRAGMA journal_mode;"
    83     83   } -cleanup {
    84     84     cleanupDb $fileName
    85     85     unset -nocomplain db fileName
    86     86   } -constraints \
    87     87   {eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} -result \
    88     88   {wal}}
................................................................................
    89     89   
    90     90   ###############################################################################
    91     91   
    92     92   runTest {test tkt-448d663d11-1.6 {'Default' journal mode, non-WAL db} -body {
    93     93     set fileName tkt-448d663d11-1.6.db
    94     94     file copy -force [file join $path nonWal.db] \
    95     95         [file join [getDatabaseDirectory] $fileName]
    96         -  setupDb $fileName Default "" "" "" false
           96  +  setupDb $fileName Default "" "" "" "" false
    97     97     sql execute -execute scalar $db "PRAGMA journal_mode;"
    98     98   } -cleanup {
    99     99     cleanupDb $fileName
   100    100     unset -nocomplain db fileName
   101    101   } -constraints \
   102    102   {eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} -result \
   103    103   {delete}}
................................................................................
   116    116   
   117    117   ###############################################################################
   118    118   
   119    119   runTest {test tkt-448d663d11-1.8 {'Delete' journal mode, WAL db} -body {
   120    120     set fileName tkt-448d663d11-1.8.db
   121    121     file copy -force [file join $path wal.db] \
   122    122         [file join [getDatabaseDirectory] $fileName]
   123         -  setupDb $fileName Delete "" "" "" false
          123  +  setupDb $fileName Delete "" "" "" "" false
   124    124     sql execute -execute scalar $db "PRAGMA journal_mode;"
   125    125   } -cleanup {
   126    126     cleanupDb $fileName
   127    127     unset -nocomplain db fileName
   128    128   } -constraints \
   129    129   {eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} -result \
   130    130   {delete}}
................................................................................
   131    131   
   132    132   ###############################################################################
   133    133   
   134    134   runTest {test tkt-448d663d11-1.9 {'Delete' journal mode, non-WAL db} -body {
   135    135     set fileName tkt-448d663d11-1.9.db
   136    136     file copy -force [file join $path nonWal.db] \
   137    137         [file join [getDatabaseDirectory] $fileName]
   138         -  setupDb $fileName Delete "" "" "" false
          138  +  setupDb $fileName Delete "" "" "" "" false
   139    139     sql execute -execute scalar $db "PRAGMA journal_mode;"
   140    140   } -cleanup {
   141    141     cleanupDb $fileName
   142    142     unset -nocomplain db fileName
   143    143   } -constraints \
   144    144   {eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} -result \
   145    145   {delete}}
................................................................................
   206    206   
   207    207   ###############################################################################
   208    208   
   209    209   runTest {test tkt-448d663d11-1.15 {'Wal' journal mode, non-WAL db} -body {
   210    210     set fileName tkt-448d663d11-1.15.db
   211    211     file copy -force [file join $path nonWal.db] \
   212    212         [file join [getDatabaseDirectory] $fileName]
   213         -  setupDb $fileName Wal "" "" "" false
          213  +  setupDb $fileName Wal "" "" "" "" false
   214    214     sql execute -execute scalar $db "PRAGMA journal_mode;"
   215    215   } -cleanup {
   216    216     cleanupDb $fileName
   217    217     unset -nocomplain db fileName
   218    218   } -constraints \
   219    219   {eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} -result \
   220    220   {wal}}
................................................................................
   221    221   
   222    222   ###############################################################################
   223    223   
   224    224   runTest {test tkt-448d663d11-1.16 {'Wal' journal mode, WAL db} -body {
   225    225     set fileName tkt-448d663d11-1.16.db
   226    226     file copy -force [file join $path wal.db] \
   227    227         [file join [getDatabaseDirectory] $fileName]
   228         -  setupDb $fileName Wal "" "" "" false
          228  +  setupDb $fileName Wal "" "" "" "" false
   229    229     sql execute -execute scalar $db "PRAGMA journal_mode;"
   230    230   } -cleanup {
   231    231     cleanupDb $fileName
   232    232     unset -nocomplain db fileName
   233    233   } -constraints \
   234    234   {eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} -result \
   235    235   {wal}}
................................................................................
   248    248   
   249    249   ###############################################################################
   250    250   
   251    251   runTest {test tkt-448d663d11-1.18 {'Bad' journal mode, non-WAL db} -body {
   252    252     set fileName tkt-448d663d11-1.18.db
   253    253     file copy -force [file join $path nonWal.db] \
   254    254         [file join [getDatabaseDirectory] $fileName]
   255         -  setupDb $fileName Bad "" "" "" false
          255  +  setupDb $fileName Bad "" "" "" "" false
   256    256     sql execute -execute scalar $db "PRAGMA journal_mode;"
   257    257   } -cleanup {
   258    258     cleanupDb $fileName
   259    259     unset -nocomplain db fileName
   260    260   } -constraints \
   261    261   {eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} -result \
   262    262   {delete}}
................................................................................
   263    263   
   264    264   ###############################################################################
   265    265   
   266    266   runTest {test tkt-448d663d11-1.19 {'Bad' journal mode, WAL db} -body {
   267    267     set fileName tkt-448d663d11-1.19.db
   268    268     file copy -force [file join $path wal.db] \
   269    269         [file join [getDatabaseDirectory] $fileName]
   270         -  setupDb $fileName Bad "" "" "" false
          270  +  setupDb $fileName Bad "" "" "" "" false
   271    271     sql execute -execute scalar $db "PRAGMA journal_mode;"
   272    272   } -cleanup {
   273    273     cleanupDb $fileName
   274    274     unset -nocomplain db fileName
   275    275   } -constraints \
   276    276   {eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} -result \
   277    277   {wal}}
   278    278   
   279    279   ###############################################################################
   280    280   
   281    281   runSQLiteTestEpilogue
   282    282   runTestEpilogue