Esempio n. 1
0
        public void GetStringOrDefault_Test()
        {
            string connectionString = SQLiteExtensions.GetConnectionString(_sampleDatabaseFile);

            string queryText = string.Format(
                "Select\n" +
                "    \"Hello, world!\" AS DataPresentation,\n" +
                "    null AS DataPresentationEmpty\n" +
                "From\n" +
                "    EventLog el\n" +
                "Where RowID > {0}\n" +
                "Order By rowID\n" +
                "Limit {1}\n", 0, 1);

            string dataPresentation      = null;
            string dataPresentationEmpty = null;

            using (SQLiteConnection connection = new SQLiteConnection(connectionString))
            {
                connection.Open();
                using SQLiteCommand command = new SQLiteCommand(queryText, connection);
                SQLiteDataReader reader = command.ExecuteReader();
                if (reader.Read())
                {
                    dataPresentation      = SQLiteExtensions.GetStringOrDefault(reader, 0);
                    dataPresentationEmpty = SQLiteExtensions.GetStringOrDefault(reader, 1);
                }
            }

            Assert.Equal("Hello, world!", dataPresentation);
            Assert.Equal(String.Empty, dataPresentationEmpty);
        }