public void Read()
        {
            IParameterFactory   parameterFactory   = new SqliteParameterFactory();
            IDataAdapterFactory dataAdapterFactory = new SqliteDataAdapterFactory();
            IConnectionFactory  connectionFactory  = new SqliteConnectionFactory();

            using (var connection = connectionFactory.Open(_connectionString))
                using (var command = new Command(connection, parameterFactory))
                    using (var reader = new SqlReader(connection, parameterFactory, dataAdapterFactory))
                    {
                        command.Execute("drop table if exists ReadTest");
                        command.Execute("create table if not exists ReadTest(TestColumn text)");
                        //command.Execute("insert into ReadTest values(null)");
                        command.Execute("insert into ReadTest values('one')");
                        command.Execute("insert into ReadTest values('two')");

                        var dataSet = reader.Read("select * from ReadTest");
                        //reader.Prepare("select * from ReadTest");
                        //using (var dataReader = reader.ExecuteReader(null))
                        //{
                        //    while (dataReader.Read())
                        //    {
                        //        for (var i = 0; i < dataReader.FieldCount; ++i)
                        //        {
                        //            var isnull = dataReader.IsDBNull(i);
                        //            var o = dataReader.GetValue(i);
                        //        }
                        //    }
                        //}
                        Assert.IsNotNull(dataSet);
                        Assert.AreEqual(1, dataSet.Tables.Count);
                        Assert.IsTrue(dataSet.Tables[0].Rows.Count > 0);
                    }
        }
Exemplo n.º 2
0
        public void Open()
        {
            IConnectionFactory factory = new SqliteConnectionFactory();

            using (var connection = factory.Open(_connectionString))
            {
                Assert.IsNotNull(connection);
                Assert.AreEqual(ConnectionState.Open, connection.State);
                connection.Close();
            }
        }
        public void Constructor()
        {
            IParameterFactory   parameterFactory   = new SqliteParameterFactory();
            IDataAdapterFactory dataAdapterFactory = new SqliteDataAdapterFactory();
            IConnectionFactory  connectionFactory  = new SqliteConnectionFactory();

            using (var connection = connectionFactory.Open(_connectionString))
                using (var reader = new SqlReader(connection, parameterFactory, dataAdapterFactory))
                {
                    Assert.IsNotNull(reader);
                }
        }
        public void BeginTransaction()
        {
            ITransactionFactory transactionFactory = new TransactionFactory();
            IConnectionFactory  connectionFactory  = new SqliteConnectionFactory();

            using (var connection = connectionFactory.Open(_connectionString))
                using (var transaction = transactionFactory.BeginTransaction(connection))
                {
                    Assert.IsNotNull(transaction);
                    Assert.AreEqual(connection, transaction.Connection);
                    Assert.AreEqual(IsolationLevel.Serializable, transaction.IsolationLevel);
                    transaction.Rollback();
                }
        }
        public void CreateDataAdapter()
        {
            Assert.IsTrue(_connectionString.CompareTo(_connectionString.ToUTF8()) == 0);

            IDataAdapterFactory dataAdapterFactory = new SqliteDataAdapterFactory();
            IConnectionFactory  connectionFactory  = new SqliteConnectionFactory();

            using (var connection = connectionFactory.Open(_connectionString))
                using (var command = connection.CreateCommand())
                    using (var dataAdapter = dataAdapterFactory.CreateDataAdapter(command))
                    {
                        Assert.IsNotNull(dataAdapter);
                        Assert.AreEqual(command, dataAdapter.SelectCommand);
                    }
        }
        public void BeginTransaction_WithIsolationLevel_Failure()
        {
            // sqlite only supports IsolationLevel.Serializable
            ITransactionFactory transactionFactory = new TransactionFactory();
            IConnectionFactory  connectionFactory  = new SqliteConnectionFactory();

            using (var connection = connectionFactory.Open(_connectionString))
                using (var transaction = transactionFactory.BeginTransaction(connection, IsolationLevel.Snapshot))
                {
                    Assert.IsNotNull(transaction);
                    Assert.AreEqual(connection, transaction.Connection);
                    Assert.AreEqual(IsolationLevel.Snapshot, transaction.IsolationLevel);
                    transaction.Rollback();
                }
        }
        public void Read_Count()
        {
            IParameterFactory   parameterFactory   = new SqliteParameterFactory();
            IDataAdapterFactory dataAdapterFactory = new SqliteDataAdapterFactory();
            IConnectionFactory  connectionFactory  = new SqliteConnectionFactory();

            using (var connection = connectionFactory.Open(_connectionString))
                using (var command = new Command(connection, parameterFactory))
                    using (var reader = new SqlReader(connection, parameterFactory, dataAdapterFactory))
                    {
                        command.Execute("drop table if exists ReadCountTest");
                        command.Execute("create table if not exists ReadCountTest(TestColumn text)");
                        command.Execute("insert into ReadCountTest values('one')");
                        command.Execute("insert into ReadCountTest values('two')");

                        var dataSet = reader.Read("select count(*) from ReadCountTest");
                        Assert.IsNotNull(dataSet);
                        Assert.AreEqual(1, dataSet.Tables.Count);
                        Assert.AreEqual(1, dataSet.Tables[0].Rows.Count);
                        Assert.AreEqual(2L, (long)dataSet.Tables[0].Rows[0][0]);
                    }
        }
        public void Read_WithParams()
        {
            IParameterFactory   parameterFactory   = new SqliteParameterFactory();
            IDataAdapterFactory dataAdapterFactory = new SqliteDataAdapterFactory();
            IConnectionFactory  connectionFactory  = new SqliteConnectionFactory();

            using (var connection = connectionFactory.Open(_connectionString))
                using (var command = new Command(connection, parameterFactory))
                    using (var reader = new SqlReader(connection, parameterFactory, dataAdapterFactory))
                    {
                        command.Execute("drop table if exists ReadWParamsTest");
                        command.Execute("create table if not exists ReadWParamsTest(TestId integer primary key autoincrement, TestValue text)");
                        command.Execute("insert into ReadWParamsTest(TestValue) values('one')");
                        command.Execute("insert into ReadWParamsTest(TestValue) values('two')");

                        var dataSet = reader.Read("select * from ReadWParamsTest where TestId=@TestId", new Dictionary <string, object> {
                            ["TestId"] = 1
                        });
                        Assert.IsNotNull(dataSet);
                        Assert.AreEqual(1, dataSet.Tables.Count);
                        Assert.AreEqual(1, dataSet.Tables[0].Rows.Count);
                    }
        }