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.
16 using Mono.Data.Sqlite;
17 using NUnit.Framework;
19 namespace MonoTests.Mono.Data.Sqlite {
22 public class SqliteiOS82BugTests {
23 readonly static string dbPath = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.Personal), "adodemo.db3");
24 readonly static string connectionString = "Data Source=" + dbPath;
25 static SqliteConnection cnn = new SqliteConnection (connectionString);
31 if(File.Exists(dbPath)) {
33 // We want to start with a fresh db for each full run
34 // The database is created on the first open()
43 using (var createCommand = new SqliteCommand ("CREATE TABLE Company (RecordId int, Name text);", cnn))
44 using (var insertCommand = new SqliteCommand ("INSERT INTO Company VALUES (1, 'Test CO')", cnn)) {
46 createCommand.ExecuteNonQuery();
47 insertCommand.ExecuteNonQuery();
51 Console.WriteLine (e);
52 throw new AssertionException ("Create table failed", e);
59 // Ref: https://bugzilla.xamarin.com/show_bug.cgi?id=27864
60 // 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
61 // The pruppose of this test is to know when apple fixes this. Expected test behaivour is as follows.
62 // If iOS 8.2+ Test will pass as long as apple does not fix the bug
63 // If iOS < 8.2 Test will pass as it does work as expected
64 // 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
66 public void SqliteSelectTestBug27864()
69 var cmdText = "SELECT " +
71 "com.Name AS 'Company.Name' " +
77 "com.Name AS 'Company.Name' " +
82 "SortOrder COLLATE NOCASE";
85 using (var cmd = new SqliteCommand (cmdText, cnn)) {
87 using (SqliteDataReader dr = cmd.ExecuteReader()) {
90 Assert.AreEqual(dr["SortOrder"], i);
91 Assert.AreEqual(dr["Company.Name"], "Test CO");
94 Assert.IsTrue(dr.FieldCount>0, i.ToString ());
97 } 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"));