Exemplo n.º 1
1
        internal MonetDbDataReader(IEnumerable<MonetDbQueryResponseInfo> ri, MonetDbConnection connection)
        {
            _metaData = null;
            _schemaTable = null;

            _connection = connection;
            _responseInfoEnumerable = ri;
            _responeInfoEnumerator = ri.GetEnumerator();
            NextResult();
        }
        public void TestChangeDatabase()
        {
            Assert.Throws<MonetDbException>(() =>
            {
                var conn = new MonetDbConnection(TestConnectionString);
                conn.Open();
                Assert.IsTrue(conn.State == ConnectionState.Open);

                conn.ChangeDatabase("demo2");
            },
                "This should throw a message that the database doesn't exist, but it's successfully changing the database name and reconnecting if it's doing so");
        }
        public void TestConnect()
        {
            var connection = new MonetDbConnection();
            Assert.IsTrue(connection.State == ConnectionState.Closed);

            try
            {
                connection.Open();
            }
            catch (InvalidOperationException)
            {
            }

            connection = new MonetDbConnection(TestConnectionString);
            connection.Open();
            Assert.IsTrue(connection.State == ConnectionState.Open);
            Assert.AreEqual(connection.Database, "demo");
            connection.Close();
            Assert.IsTrue(connection.State == ConnectionState.Closed);
            Assert.AreEqual(connection.Database, "demo");

            try
            {
                connection = new MonetDbConnection(TestConnectionString.Replace("ssl=false", "ssl=true"));
                connection.Open();
            }
            catch (MonetDbException ex)
            {
                if (ex.Message.IndexOf("not supported", StringComparison.InvariantCultureIgnoreCase) < 0)
                    throw;
            }
            finally
            {
                connection.Close();
            }
        }
 public void TestConnectDoubleOpen()
 {
     Assert.Throws<InvalidOperationException>(() =>
     {
         var conn = new MonetDbConnection(TestConnectionString);
         conn.Open();
         conn.Open();
     });
 }
        public void TestSchemaTable()
        {
            var query = "SELECT * FROM env();";

            using (var connection = new MonetDbConnection(TestConnectionString))
            {
                connection.Open();

                using (var command = connection.CreateCommand())
                {
                    // create table
                    command.CommandText = query;

                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var schema = reader.GetSchemaTable();

                            Assert.IsNotNull(schema);
                            Assert.IsTrue(schema.Columns.Contains("name"));
                            Assert.IsTrue(schema.Columns.Contains("value"));
                            Assert.AreEqual(typeof (string), schema.Columns["name"].DataType);
                            Assert.AreEqual(typeof (string), schema.Columns["value"].DataType);
                        }
                    }
                }
            }
        }
        public void TestCreateInsertSelectDropTable()
        {
            // random table name
            var tableName = Guid.NewGuid().ToString();

            // random integer value
            var value = new Random().Next();

            // SQL scripts
            var createScript = string.Format("CREATE TABLE \"{0}\" (id int);", tableName);
            var insertScript = string.Format("INSERT INTO \"{0}\" VALUES({1});", tableName, value);
            var selectScript = string.Format("SELECT * FROM \"{0}\";", tableName);
            var dropScript = string.Format("DROP TABLE \"{0}\";", tableName);

            using (var connection = new MonetDbConnection(TestConnectionString))
            {
                connection.Open();

                using (var command = connection.CreateCommand())
                {
                    // create table
                    command.CommandText = createScript;
                    command.ExecuteNonQuery();

                    // insert into
                    command.CommandText = insertScript;
                    // rows affected 0 or 1
                    Assert.Contains(command.ExecuteNonQuery(), new[] {0, 1});

                    // select from
                    command.CommandText = selectScript;
                    var value2 = (int) command.ExecuteScalar();
                    Assert.AreEqual(value, value2);

                    // drop table
                    command.CommandText = dropScript;
                    command.ExecuteNonQuery();
                }
            }
        }
        public void TestConnectionPooling()
        {
            //This test is intended to be run through a debugger and see if the connection pooling is
            //dynamically creating and destroying the connection pools.
            //Only run this test, because the other tests will mess up the connection pool settings...
            //I know it's not very TDD and this is a code smell, but this is pretty standard fare for
            //database connectivity.
            var modifiedConnString = TestConnectionString + "poolminimum=1;poolmaximum=5;";
            var connections = new MonetDbConnection[5];

            for (var i = 0; i < connections.Length; i++)
            {
                connections[i] = new MonetDbConnection(modifiedConnString);
                connections[i].Open();
            }

            foreach (var connection in connections)
            {
                connection.Close();
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes a new command.
 /// </summary>
 /// <param name="cmdText"></param>
 /// <param name="connection"></param>
 /// <param name="transaction"></param>
 public MonetDbCommand(string cmdText, MonetDbConnection connection, MonetDbTransaction transaction)
     : this(cmdText, connection)
 {
     Transaction = transaction;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Initializes a new command.
 /// </summary>
 /// <param name="cmdText"></param>
 /// <param name="connection"></param>
 public MonetDbCommand(string cmdText, MonetDbConnection connection)
     : this(cmdText)
 {
     Connection = connection;
 }