[Mono.Data.Sqlite] Regression introduced by 04162ffbbdfed88ba298341f0384a35949b3c0f9...
authorMarek Safar <marek.safar@gmail.com>
Wed, 12 Oct 2016 10:04:19 +0000 (12:04 +0200)
committerMarek Safar <marek.safar@gmail.com>
Wed, 12 Oct 2016 10:06:30 +0000 (12:06 +0200)
mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLiteConvert.cs
mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_test.dll.sources
mcs/class/Mono.Data.Sqlite/Test/SqliteTests.cs [new file with mode: 0644]

index 7f35914d241f72792d3667671bf8add783dd3dca..45b2db176875cbf3a4dc9fc0811ae180b64a71d3 100644 (file)
@@ -221,7 +221,7 @@ namespace Mono.Data.Sqlite
         case SQLiteDateFormats.UnixEpoch:\r
           return ((long)(dateValue.Subtract(UnixEpoch).Ticks / TimeSpan.TicksPerSecond)).ToString();\r
         default:\r
-          return dateValue.ToString(_datetimeFormats[7], CultureInfo.InvariantCulture);\r
+          return dateValue.ToString(_datetimeFormats[5], CultureInfo.InvariantCulture);\r
       }\r
     }\r
 \r
index 0a02896ef8ddaa01b2ebec83459d4cfeadc88807..643c40a86da80e8ac3d3afd94d1d04c4cf43d7f2 100644 (file)
@@ -6,4 +6,4 @@ SqliteExceptionUnitTests.cs
 SqliteParameterUnitTests.cs
 SqliteFunctionTests.cs
 Bug27864.cs
-
+SqliteTests.cs
diff --git a/mcs/class/Mono.Data.Sqlite/Test/SqliteTests.cs b/mcs/class/Mono.Data.Sqlite/Test/SqliteTests.cs
new file mode 100644 (file)
index 0000000..1533945
--- /dev/null
@@ -0,0 +1,102 @@
+//
+// SqliteTests.cs
+//
+// Authors:
+//     Marek Safar  <marek.safar@gmail.com>
+//
+// Copyright (C) 2016 Xamarin Inc (http://www.xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Data;
+using System.IO;
+using System.Text;
+using Mono.Data.Sqlite;
+using NUnit.Framework;
+
+namespace MonoTests.Mono.Data.Sqlite
+{
+       [TestFixture]
+       public class SqliteTests
+       {
+               string _databasePath;
+
+               [SetUp]
+               public void Setup ()
+               {
+                       var dataFolder = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.Personal), "SqlTest");
+
+                       _databasePath = Path.Combine (dataFolder, "database.db");
+
+                       if (!Directory.Exists (dataFolder)) {
+                               Directory.CreateDirectory (dataFolder);
+                       }
+
+                       File.Delete (_databasePath);
+               }
+
+               [TearDown]
+               public void TearDown ()
+               {
+                       try {
+                               File.Delete (_databasePath);
+                       } catch {
+                       }
+               }
+
+               [Test]
+               public void DateTimeConvert ()
+               {
+                       var dateTime = new DateTime (2016, 9, 15, 12, 1, 53);
+                       var guid = Guid.NewGuid ();
+
+                       using (var connection = new SqliteConnection ("Data Source=" + _databasePath)) {
+                               connection.Open ();
+
+                               var sqlCreate = "CREATE TABLE TestTable (ID uniqueidentifier PRIMARY KEY, Modified datetime)";
+                               using (var cmd = new SqliteCommand (sqlCreate, connection)) {
+                                       cmd.ExecuteNonQuery ();
+                               }
+
+                               var sqlInsert = "INSERT INTO TestTable (ID, Modified) VALUES (@id, @mod)";
+                               using (var cmd = new SqliteCommand (sqlInsert, connection)) {
+                                       cmd.Parameters.Add (new SqliteParameter ("@id", guid));
+                                       cmd.Parameters.Add (new SqliteParameter ("@mod", dateTime));
+                                       cmd.ExecuteNonQuery ();
+                               }
+                       }
+
+                       using (var connection = new SqliteConnection ("Data Source=" + _databasePath)) {
+                               connection.Open ();
+
+                               var sqlSelect = "SELECT * from TestTable";
+                               using (var cmd = new SqliteCommand (sqlSelect, connection))
+                               using (var reader = cmd.ExecuteReader ()) {
+                                       while (reader.Read ()) {
+                                               Assert.AreEqual (guid, reader.GetGuid (0), "#1");
+                                               Assert.AreEqual (dateTime, reader.GetDateTime (1), "#2");
+                                       }
+                               }
+                       }
+               }
+       }
+}