2 // Unit test for bug https://bugzilla.xamarin.com/show_bug.cgi?id=27864
5 // Thomas Zoechling <thomas.zoechling@gmx.at>
6 // Alex Soto <alex.soto@xamarin.com>
9 // Copyright 2015 Xamarin Inc.
17 using Mono.Data.Sqlite;
18 using NUnit.Framework;
20 namespace MonoTests.Mono.Data.Sqlite {
23 public class SqliteiOS82BugTests {
24 readonly static string dbPath = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.Personal), "adodemo.db3");
25 readonly static string connectionString = "Data Source=" + dbPath;
26 static SqliteConnection cnn = new SqliteConnection (connectionString);
32 if(File.Exists(dbPath)) {
34 // We want to start with a fresh db for each full run
35 // The database is created on the first open()
44 using (var createCommand = new SqliteCommand ("CREATE TABLE Company (RecordId int, Name text);", cnn))
45 using (var insertCommand = new SqliteCommand ("INSERT INTO Company VALUES (1, 'Test CO')", cnn)) {
47 createCommand.ExecuteNonQuery();
48 insertCommand.ExecuteNonQuery();
52 Console.WriteLine (e);
53 throw new AssertionException ("Create table failed", e);
60 // Ref: https://bugzilla.xamarin.com/show_bug.cgi?id=27864
61 // As of iOS 8.2 Apple updated Sqlite and broke queries that used to work pre iOS 8.2 like the select command in this test
62 // The pruppose of this test is to know when apple fixes this. Expected test behaivour is as follows.
63 // If iOS 8.2+ Test will pass as long as apple does not fix the bug
64 // If iOS < 8.2 Test will pass as it does work as expected
65 // If iOS 8.2+ and apple fixed bug 27864 test will fail and we will need to remove the fail check on lines 105 and 106
67 public void SqliteSelectTestBug27864()
70 var cmdText = "SELECT " +
72 "com.Name AS 'Company.Name' " +
78 "com.Name AS 'Company.Name' " +
83 "SortOrder COLLATE NOCASE";
86 using (var cmd = new SqliteCommand (cmdText, cnn)) {
88 using (SqliteDataReader dr = cmd.ExecuteReader()) {
91 Assert.AreEqual(dr["SortOrder"], i);
92 Assert.AreEqual(dr["Company.Name"], "Test CO");
95 Assert.IsTrue(dr.FieldCount>0, i.ToString ());
98 } catch (SqliteException ex) {
99 // Expected Exception from iOS 8.2 (broken) to 9.0 (fixed)
100 if (BCL.Tests.TestRuntime.CheckSystemVersion (8,2) && !BCL.Tests.TestRuntime.CheckSystemVersion (9,0))
101 Assert.That (ex.Message.Contains ("no such column: com.Name"));
103 throw new AssertionException ("Unexpected Sqlite Error", ex); // This should not happen