System.Data.SQLite
Check-in [14d18ee826]
Not logged in

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

Overview
Comment:Do not allow read-only connections into (or out of) the connection pool.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:14d18ee82623c85ff431f737c912d5e60c2e9d27
User & Date: mistachkin 2018-07-10 01:53:48
References
2018-07-10
11:10
Add another test to verify the behavior of read-only connections with respect to the connection pool. See also check-in [14d18ee82623c85f]. check-in: 5e689a7650 user: mistachkin tags: trunk
Context
2018-07-10
11:10
Add another test to verify the behavior of read-only connections with respect to the connection pool. See also check-in [14d18ee82623c85f]. check-in: 5e689a7650 user: mistachkin tags: trunk
01:53
Do not allow read-only connections into (or out of) the connection pool. check-in: 14d18ee826 user: mistachkin tags: trunk
2018-07-07
16:10
Make sure the assembly built for .NET Core is strong named signed. check-in: 51270bcb44 user: mistachkin tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

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

971
972
973
974
975
976
977




















978
979
980
981
982
983
984
...
990
991
992
993
994
995
996









997
998
999
1000
1001
1002
1003
    {
        if (_sql == null)
            return null;

        return UTF8ToString(UnsafeNativeMethods.sqlite3_db_filename_bytes(
            _sql, ToUTF8(dbName)), -1);
    }





















    internal override void Open(string strFilename, string vfsName, SQLiteConnectionFlags connectionFlags, SQLiteOpenFlagsEnum openFlags, int maxPoolSize, bool usePool)
    {
      //
      // NOTE: If the database connection is currently open, attempt to
      //       close it now.  This must be done because the file name or
      //       other parameters that may impact the underlying database
................................................................................
      // NOTE: If the connection was not closed successfully, throw an
      //       exception now.
      //
      if (_sql != null)
          throw new SQLiteException("connection handle is still active");

      _usePool = usePool;









      _fileName = strFilename;
      _flags = connectionFlags;

      if (usePool)
      {
        _sql = SQLiteConnectionPool.Remove(strFilename, maxPoolSize, out _poolVersion);








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







 







>
>
>
>
>
>
>
>
>







971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
....
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
    {
        if (_sql == null)
            return null;

        return UTF8ToString(UnsafeNativeMethods.sqlite3_db_filename_bytes(
            _sql, ToUTF8(dbName)), -1);
    }

    /// <summary>
    /// This method attempts to determine if a database connection opened
    /// with the specified <see cref="SQLiteOpenFlagsEnum" /> should be
    /// allowed into the connection pool.
    /// </summary>
    /// <param name="openFlags">
    /// The <see cref="SQLiteOpenFlagsEnum" /> that were specified when the
    /// connection was opened.
    /// </param>
    /// <returns>
    /// Non-zero if the connection should (eventually) be allowed into the
    /// connection pool; otherwise, zero.
    /// </returns>
    private static bool IsAllowedToUsePool(
        SQLiteOpenFlagsEnum openFlags
        )
    {
        return openFlags == SQLiteOpenFlagsEnum.Default;
    }

    internal override void Open(string strFilename, string vfsName, SQLiteConnectionFlags connectionFlags, SQLiteOpenFlagsEnum openFlags, int maxPoolSize, bool usePool)
    {
      //
      // NOTE: If the database connection is currently open, attempt to
      //       close it now.  This must be done because the file name or
      //       other parameters that may impact the underlying database
................................................................................
      // NOTE: If the connection was not closed successfully, throw an
      //       exception now.
      //
      if (_sql != null)
          throw new SQLiteException("connection handle is still active");

      _usePool = usePool;

      //
      // BUGFIX: Do not allow a connection into the pool if it was opened
      //         with flags that are incompatible with the default flags
      //         (e.g. read-only).
      //
      if (_usePool && !IsAllowedToUsePool(openFlags))
          _usePool = false;

      _fileName = strFilename;
      _flags = connectionFlags;

      if (usePool)
      {
        _sql = SQLiteConnectionPool.Remove(strFilename, maxPoolSize, out _poolVersion);

Changes to Tests/basic.eagle.

5030
5031
5032
5033
5034
5035
5036

































































5037
5038
5039
5040
5041
5042
5043
5044
5045
5046

  unset -nocomplain current highwater ints count size ptr value
  unset -nocomplain result dbConfig dbConfigs
  unset -nocomplain connection db fileName
} -constraints {eagle monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite} -match regexp -result {^\{\} \{\} \{\} \{\} \{\} \{\} \{\}\
\{\} \{\} \{\} Ok 0 0 Ok \d+ \d+ True True$}}


































































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

reportSQLiteResources $test_channel

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

runSQLiteTestFilesEpilogue
runSQLiteTestEpilogue
runTestEpilogue







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










5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111

  unset -nocomplain current highwater ints count size ptr value
  unset -nocomplain result dbConfig dbConfigs
  unset -nocomplain connection db fileName
} -constraints {eagle monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite} -match regexp -result {^\{\} \{\} \{\} \{\} \{\} \{\} \{\}\
\{\} \{\} \{\} Ok 0 0 Ok \d+ \d+ True True$}}

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

runTest {test data-1.96 {connection pool interaction with read-only} -setup {
  catch {
    object invoke -flags +NonPublic \
        System.Data.SQLite.SQLiteConnectionPool _poolOpened 0

    object invoke -flags +NonPublic \
        System.Data.SQLite.SQLiteConnectionPool _poolClosed 0
  }

  proc getPoolCounts {} {
    if {[catch {
      object invoke -flags +NonPublic \
          System.Data.SQLite.SQLiteConnectionPool _poolOpened
    } opened] == 0 && [catch {
      object invoke -flags +NonPublic \
          System.Data.SQLite.SQLiteConnectionPool _poolClosed
    } closed] == 0} then {
      return [list $opened $closed]
    } else {
      tputs $::test_channel \
          "==== WARNING: connection pool counts are not available\n"

      return [list 0 0]
    }
  }

  setupDb [set fileName data-1.96.db]
} -body {
  sql execute $db "CREATE TABLE t1(x);"
  sql execute $db "INSERT INTO t1 (x) VALUES(1);"

  cleanupDb $fileName db true false false
  setupDb $fileName "" "" "" "" "Read Only=True;Pooling=True;" true false

  set code(1) [catch {
    sql execute $db "INSERT INTO t1 (x) VALUES(2);"
  } error(1)]

  cleanupDb $fileName db true false false
  setupDb $fileName "" "" "" "" "Read Only=True;Pooling=True;" true false

  set code(2) [catch {
    sql execute $db "INSERT INTO t1 (x) VALUES(3);"
  } error(2)]

  cleanupDb $fileName db true false false
  setupDb $fileName "" "" "" "" "" true false

  list [getPoolCounts] \
      $code(1) [extractSystemDataSQLiteExceptionMessage $error(1)] \
      $code(2) [extractSystemDataSQLiteExceptionMessage $error(2)] \
      [sql execute -execute scalar $db "SELECT SUM(x) FROM t1;"]
} -cleanup {
  cleanupDb $fileName

  unset -nocomplain error code db fileName

  rename getPoolCounts ""
} -constraints \
{eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} -result \
{{0 0} 1 {attempt to write a readonly database} 1 {attempt to write a readonly\
database} 1}}

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

reportSQLiteResources $test_channel

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

runSQLiteTestFilesEpilogue
runSQLiteTestEpilogue
runTestEpilogue