System.Data.SQLite
Check-in [cc5c576e43]
Not logged in

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

Overview
Comment:Cherrypick of [9b146be3f9aef0c3] and [ece910dd8df8ce5f], the Int32.ToString culture fix.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | branch-1.0.105
Files: files | file ages | folders
SHA1: cc5c576e434e65291d8a4136210b7eb1564d3471
User & Date: mistachkin 2017-05-11 15:36:23
Context
2017-05-11
15:37
Cherrypick of [2c31a6967460b852], test suite helper procedure fixes. check-in: 4578c9236b user: mistachkin tags: branch-1.0.105
15:36
Cherrypick of [9b146be3f9aef0c3] and [ece910dd8df8ce5f], the Int32.ToString culture fix. check-in: cc5c576e43 user: mistachkin tags: branch-1.0.105
15:34
Cherrypick of [e41a0aef927841ce], the doc links fix. check-in: 95d7239b6b user: mistachkin tags: branch-1.0.105
2017-05-08
19:15
Add test for the fix in check-in [9b146be3f9aef0c3]. check-in: ece910dd8d user: mistachkin tags: trunk
01:18
Avoid using the Int32.ToString method overload with no arguments. Depending on the current culture, it interacts badly when later parsing the returned strings with the invariant culture. Reported by David Rickard via the ML. check-in: 9b146be3f9 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

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

  3719   3719   
  3720   3720   #if !NET_COMPACT_20 && TRACE_WARNING
  3721   3721         bool uri = false;
  3722   3722   #endif
  3723   3723         bool fullUri = false;
  3724   3724         string fileName;
  3725   3725   
  3726         -      if (Convert.ToInt32(FindKey(opts, "Version", DefaultVersion.ToString()), CultureInfo.InvariantCulture) != DefaultVersion)
         3726  +      if (Convert.ToInt32(FindKey(opts, "Version", SQLiteConvert.ToString(DefaultVersion)), CultureInfo.InvariantCulture) != DefaultVersion)
  3727   3727           throw new NotSupportedException(HelperMethods.StringFormat(CultureInfo.CurrentCulture, "Only SQLite Version {0} is supported at this time", DefaultVersion));
  3728   3728   
  3729   3729   #if INTEROP_INCLUDE_ZIPVFS
  3730   3730         bool useZipVfs = false;
  3731   3731         string zipVfsVersion = FindKey(opts, "ZipVfsVersion", DefaultZipVfsVersion);
  3732   3732   
  3733   3733         if (zipVfsVersion != null)
................................................................................
  3810   3810             fileName = ExpandFileName(fileName, toFullPath);
  3811   3811           }
  3812   3812         }
  3813   3813   
  3814   3814         try
  3815   3815         {
  3816   3816           bool usePooling = SQLiteConvert.ToBoolean(FindKey(opts, "Pooling", GetDefaultPooling().ToString()));
  3817         -        int maxPoolSize = Convert.ToInt32(FindKey(opts, "Max Pool Size", DefaultMaxPoolSize.ToString()), CultureInfo.InvariantCulture);
         3817  +        int maxPoolSize = Convert.ToInt32(FindKey(opts, "Max Pool Size", SQLiteConvert.ToString(DefaultMaxPoolSize)), CultureInfo.InvariantCulture);
  3818   3818   
  3819         -        _defaultTimeout = Convert.ToInt32(FindKey(opts, "Default Timeout", DefaultConnectionTimeout.ToString()), CultureInfo.InvariantCulture);
  3820         -        _busyTimeout = Convert.ToInt32(FindKey(opts, "BusyTimeout", DefaultBusyTimeout.ToString()), CultureInfo.InvariantCulture);
  3821         -        _prepareRetries = Convert.ToInt32(FindKey(opts, "PrepareRetries", DefaultPrepareRetries.ToString()), CultureInfo.InvariantCulture);
  3822         -        _progressOps = Convert.ToInt32(FindKey(opts, "ProgressOps", DefaultProgressOps.ToString()), CultureInfo.InvariantCulture);
         3819  +        _defaultTimeout = Convert.ToInt32(FindKey(opts, "Default Timeout", SQLiteConvert.ToString(DefaultConnectionTimeout)), CultureInfo.InvariantCulture);
         3820  +        _busyTimeout = Convert.ToInt32(FindKey(opts, "BusyTimeout", SQLiteConvert.ToString(DefaultBusyTimeout)), CultureInfo.InvariantCulture);
         3821  +        _prepareRetries = Convert.ToInt32(FindKey(opts, "PrepareRetries", SQLiteConvert.ToString(DefaultPrepareRetries)), CultureInfo.InvariantCulture);
         3822  +        _progressOps = Convert.ToInt32(FindKey(opts, "ProgressOps", SQLiteConvert.ToString(DefaultProgressOps)), CultureInfo.InvariantCulture);
  3823   3823   
  3824   3824           enumValue = TryParseEnum(typeof(IsolationLevel), FindKey(opts, "Default IsolationLevel", DefaultIsolationLevel.ToString()), true);
  3825   3825           _defaultIsolation = (enumValue is IsolationLevel) ? (IsolationLevel)enumValue : DefaultIsolationLevel;
  3826   3826           _defaultIsolation = GetEffectiveIsolationLevel(_defaultIsolation);
  3827   3827   
  3828   3828           if (_defaultIsolation != ImmediateIsolationLevel && _defaultIsolation != DeferredIsolationLevel)
  3829   3829             throw new NotSupportedException("Invalid Default IsolationLevel specified");
................................................................................
  3916   3916                         cmd.ExecuteNonQuery();
  3917   3917                     }
  3918   3918   
  3919   3919                     int intValue;
  3920   3920   
  3921   3921                     if (!fullUri && !isMemory)
  3922   3922                     {
  3923         -                      strValue = FindKey(opts, "Page Size", DefaultPageSize.ToString());
         3923  +                      strValue = FindKey(opts, "Page Size", SQLiteConvert.ToString(DefaultPageSize));
  3924   3924                         intValue = Convert.ToInt32(strValue, CultureInfo.InvariantCulture);
  3925   3925                         if (intValue != DefaultPageSize)
  3926   3926                         {
  3927   3927                             cmd.CommandText = HelperMethods.StringFormat(CultureInfo.InvariantCulture, "PRAGMA page_size={0}", intValue);
  3928   3928                             cmd.ExecuteNonQuery();
  3929   3929                         }
  3930   3930                     }
  3931   3931   
  3932         -                  strValue = FindKey(opts, "Max Page Count", DefaultMaxPageCount.ToString());
         3932  +                  strValue = FindKey(opts, "Max Page Count", SQLiteConvert.ToString(DefaultMaxPageCount));
  3933   3933                     intValue = Convert.ToInt32(strValue, CultureInfo.InvariantCulture);
  3934   3934                     if (intValue != DefaultMaxPageCount)
  3935   3935                     {
  3936   3936                         cmd.CommandText = HelperMethods.StringFormat(CultureInfo.InvariantCulture, "PRAGMA max_page_count={0}", intValue);
  3937   3937                         cmd.ExecuteNonQuery();
  3938   3938                     }
  3939   3939   
................................................................................
  3949   3949                     enumValue = TryParseEnum(typeof(SQLiteSynchronousEnum), strValue, true);
  3950   3950                     if (!(enumValue is SQLiteSynchronousEnum) || ((SQLiteSynchronousEnum)enumValue != DefaultSynchronous))
  3951   3951                     {
  3952   3952                         cmd.CommandText = HelperMethods.StringFormat(CultureInfo.InvariantCulture, "PRAGMA synchronous={0}", strValue);
  3953   3953                         cmd.ExecuteNonQuery();
  3954   3954                     }
  3955   3955   
  3956         -                  strValue = FindKey(opts, "Cache Size", DefaultCacheSize.ToString());
         3956  +                  strValue = FindKey(opts, "Cache Size", SQLiteConvert.ToString(DefaultCacheSize));
  3957   3957                     intValue = Convert.ToInt32(strValue, CultureInfo.InvariantCulture);
  3958   3958                     if (intValue != DefaultCacheSize)
  3959   3959                     {
  3960   3960                         cmd.CommandText = HelperMethods.StringFormat(CultureInfo.InvariantCulture, "PRAGMA cache_size={0}", intValue);
  3961   3961                         cmd.ExecuteNonQuery();
  3962   3962                     }
  3963   3963   

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

  1167   1167       public static bool ToBoolean(object source)
  1168   1168       {
  1169   1169         if (source is bool) return (bool)source;
  1170   1170   
  1171   1171         return ToBoolean(ToStringWithProvider(
  1172   1172             source, CultureInfo.InvariantCulture));
  1173   1173       }
         1174  +
         1175  +    ///////////////////////////////////////////////////////////////////////////
         1176  +
         1177  +    /// <summary>
         1178  +    /// Converts an integer to a string that can be round-tripped using the
         1179  +    /// invariant culture.
         1180  +    /// </summary>
         1181  +    /// <param name="value">
         1182  +    /// The integer value to return the string representation for.
         1183  +    /// </param>
         1184  +    /// <returns>
         1185  +    /// The string representation of the specified integer value, using the
         1186  +    /// invariant culture.
         1187  +    /// </returns>
         1188  +    internal static string ToString(int value)
         1189  +    {
         1190  +        return value.ToString(CultureInfo.InvariantCulture);
         1191  +    }
         1192  +
         1193  +    ///////////////////////////////////////////////////////////////////////////
  1174   1194   
  1175   1195       /// <summary>
  1176   1196       /// Attempts to convert a <see cref="String" /> into a <see cref="Boolean" />.
  1177   1197       /// </summary>
  1178   1198       /// <param name="source">
  1179   1199       /// The <see cref="String" /> to convert, cannot be null.
  1180   1200       /// </param>

Changes to Tests/basic.eagle.

  4536   4536   
  4537   4537     unset -nocomplain db fileName
  4538   4538   } -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
  4539   4539   defineConstant.System.Data.SQLite.INTEROP_SHA1_EXTENSION\
  4540   4540   System.Data.SQLite SQLiteInterop} -result \
  4541   4541   {5578139b470e35a3c231a499d06589215e46e8df\
  4542   4542   a27f5e6f85a3872ed2e4e4018c8fd7dfaff052bc}}
         4543  +
         4544  +###############################################################################
         4545  +
         4546  +runTest {test data-1.86 {connection string integer parsing} -setup {
         4547  +  object import System.Globalization
         4548  +  object import System.Threading
         4549  +
         4550  +  set culture [object create -alias CultureInfo en-US]
         4551  +  $culture NumberFormat.NegativeSign /
         4552  +
         4553  +  set savedCulture [object invoke Thread.CurrentThread CurrentCulture]
         4554  +  object invoke Thread.CurrentThread CurrentCulture $culture
         4555  +} -body {
         4556  +  setupDb [set fileName data-1.86.db]
         4557  +} -cleanup {
         4558  +  cleanupDb $fileName
         4559  +
         4560  +  unset -nocomplain db fileName
         4561  +
         4562  +  catch {object invoke Thread.CurrentThread CurrentCulture $savedCulture}
         4563  +  unset -nocomplain savedCulture culture
         4564  +
         4565  +  object unimport -importpattern System.Threading
         4566  +  object unimport -importpattern System.Globalization
         4567  +} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
         4568  +defineConstant.System.Data.SQLite.INTEROP_SHA1_EXTENSION System.Data.SQLite\
         4569  +SQLiteInterop} -match regexp -result \
         4570  +{^System#Data#SQLite#SQLiteConnection#\d+$}}
  4543   4571   
  4544   4572   ###############################################################################
  4545   4573   
  4546   4574   reportSQLiteResources $test_channel
  4547   4575   
  4548   4576   ###############################################################################
  4549   4577   
  4550   4578   runSQLiteTestFilesEpilogue
  4551   4579   runSQLiteTestEpilogue
  4552   4580   runTestEpilogue