Inheritance: System.Data.Common.DbConnection
Beispiel #1
0
 internal DeveelDbLob(DeveelDbConnection connection, ObjectId objId, long size)
     : this(objId, size, FileAccess.Read)
 {
     this.connection = connection;
     lobChannel      = connection.OpenLargeObjectChannel(objId);
     readStream      = new BufferedStream(new LobInputStream(this), (int)(size / 64));
 }
Beispiel #2
0
        public LocalQueryResult(DeveelDbConnection connection)
        {
            this.connection = connection;

            MaxFetchSize = connection.Settings.MaxFetchSize;
            DefaultFetchSize = connection.Settings.FetchSize;
        }
        public DeveelDbCommand(DeveelDbConnection connection, string commandText)
        {
            Connection  = connection;
            CommandText = commandText;

            parameters = new DeveelDbParameterCollection(this);
        }
Beispiel #4
0
        internal static ObjectId Upload(DeveelDbConnection connection, DeveelDbLob lob)
        {
            if (connection == null)
            {
                throw new InvalidOperationException("An open connection is required to upload the LOB");
            }

            var objId = connection.CreateLargeObject(lob.Length);

            using (var channel = connection.OpenLargeObjectChannel(objId)) {
                const int bufferSize = 2048;
                var       copyBuffer = new byte[bufferSize];
                int       readCount;
                long      copyOffset = 0;
                lob.writeStream.Seek(0, SeekOrigin.Begin);

                while ((readCount = lob.writeStream.Read(copyBuffer, 0, bufferSize)) > 0)
                {
                    channel.PushData(copyOffset, copyBuffer, readCount);
                    copyOffset += readCount;
                }
            }

            return(objId);
        }
Beispiel #5
0
 internal DeveelDbLob(DeveelDbConnection connection, ObjectId objId, long size)
     : this(objId, size, FileAccess.Read)
 {
     this.connection = connection;
     lobChannel = connection.OpenLargeObjectChannel(objId);
     readStream = new BufferedStream(new LobInputStream(this), (int)(size/64));
 }
Beispiel #6
0
        public DeveelDbEnlistment(DeveelDbConnection connection, Transaction scope)
        {
            transaction = connection.BeginTransaction();

            Scope = scope;
            Scope.EnlistVolatile(this, EnlistmentOptions.None);
        }
Beispiel #7
0
        public DeveelDbCommand(DeveelDbConnection connection, string commandText)
        {
            Connection = connection;
            CommandText = commandText;

            parameters = new DeveelDbParameterCollection(this);
        }
        public DeveelDbEnlistment(DeveelDbConnection connection, Transaction scope)
        {
            transaction = connection.BeginTransaction();

            Scope = scope;
            Scope.EnlistVolatile(this, EnlistmentOptions.None);
        }
Beispiel #9
0
 public void CreateCommandOnClosedConnection()
 {
     const string connString = "Host=Heap;UserID=SA;Password=123456;Database=testdb;BootOrCreate=true";
     var connection = new DeveelDbConnection(connString);
     DeveelDbCommand command = null;
     Assert.DoesNotThrow(() => command = connection.CreateCommand());
     Assert.IsNotNull(command);
     command.CommandText = "SELECT * FROM Person WHERE Name = 'antonello'";
 }
Beispiel #10
0
 public LocalRowCache(DeveelDbConnection connection)
 {
     this.connection = connection;
     if (connection.Settings != null) {
         rowCache = new SizeLimitedCache (connection.Settings.RowCacheSize);
     } else {
         int defaultCacheSize = new DeveelDbConnectionStringBuilder ().RowCacheSize;
         rowCache = new SizeLimitedCache (defaultCacheSize);
     }
 }
Beispiel #11
0
        internal DeveelDbTransaction(DeveelDbConnection connection, IsolationLevel isolationLevel, int commitId)
        {
            if (connection == null)
                throw new ArgumentNullException("connection");

            this.connection = connection;
            CommitId = commitId;
            this.isolationLevel = isolationLevel;
            connection.Transaction = this;
        }
Beispiel #12
0
        internal DeveelDbTransaction(DeveelDbConnection connection, IsolationLevel isolationLevel, int commitId)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            this.connection        = connection;
            CommitId               = commitId;
            this.isolationLevel    = isolationLevel;
            connection.Transaction = this;
        }
 public LocalRowCache(DeveelDbConnection connection)
 {
     this.connection = connection;
     if (connection.Settings != null)
     {
         rowCache = new SizeLimitedCache(connection.Settings.RowCacheSize);
     }
     else
     {
         int defaultCacheSize = new DeveelDbConnectionStringBuilder().RowCacheSize;
         rowCache = new SizeLimitedCache(defaultCacheSize);
     }
 }
Beispiel #14
0
        protected override void OnAfterSetup(string testName)
        {
            var connString = new DeveelDbConnectionStringBuilder {
                UserName   = AdminUserName,
                Password   = AdminPassword,
                DataSource = "memory",
                Database   = DatabaseName,
                Schema     = "APP",
                Create     = true
            };

            connection = (DeveelDbConnection)Database.CreateDbConnection(AdminUserName, AdminPassword);
        }
Beispiel #15
0
        public void CreateCommandWithMixedParameters()
        {
            // by default "Parameter Style" configuration is set to "Marker" in connection strings
            const string connString = "Host=Heap;UserID=SA;Password=123456;Database=testdb;BootOrCreate=true";
            var connection = new DeveelDbConnection(connString);
            Assert.DoesNotThrow(connection.Open);

            var command = connection.CreateCommand();
            command.CommandText = "SELECT * FROM Person WHERE Name = ?";
            Assert.DoesNotThrow(() => command.Parameters.Add("antonelllo"));
            Assert.DoesNotThrow(() => command.Parameters.Add("Name", "antonello"));
            Assert.Throws<InvalidOperationException>(() => command.ExecuteReader());
        }
Beispiel #16
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (!finished)
                {
                    Rollback();
                }
            }

            connection = null;

            base.Dispose(disposing);
        }
Beispiel #17
0
        public void ConnectToLocal()
        {
            // since we're connecting locally, we can specify the option
            // 'CreateOrBoot' to tell the system to startup a database or
            // to create it, if not existing...
            // Usernmae and password have to be the administrator's credentials
            // for both the operations..
            const string connString = "Host=Local;User=SA;Password=123456;CreateOrBoot=true;Database=testdb";

            var connection = new DeveelDbConnection(connString);
            Assert.DoesNotThrow(connection.Open);
            Assert.IsTrue(connection.State == ConnectionState.Open);
            Assert.DoesNotThrow(connection.Close);
            Assert.IsTrue(connection.State == ConnectionState.Closed);
        }
Beispiel #18
0
        public void OpenForAdmin()
        {
            var connString = new DeveelDbConnectionStringBuilder {
                UserName = AdminUserName,
                Password = AdminPassword,
                DataSource = "memory",
                Database = DatabaseName,
                Schema = "APP",
                Create = true
            };

            var connection = new DeveelDbConnection(connString);
            Assert.AreEqual(ConnectionState.Closed, connection.State);
            Assert.DoesNotThrow(() => connection.Open());
            Assert.AreEqual(ConnectionState.Open, connection.State);
            Assert.DoesNotThrow(() => connection.Close());
            Assert.AreEqual(ConnectionState.Closed, connection.State);
        }
Beispiel #19
0
        public void OpenForAdmin()
        {
            var connString = new DeveelDbConnectionStringBuilder {
                UserName   = AdminUserName,
                Password   = AdminPassword,
                DataSource = "memory",
                Database   = DatabaseName,
                Schema     = "APP",
                Create     = true
            };

            var connection = new DeveelDbConnection(connString);

            Assert.AreEqual(ConnectionState.Closed, connection.State);
            Assert.DoesNotThrow(() => connection.Open());
            Assert.AreEqual(ConnectionState.Open, connection.State);
            Assert.DoesNotThrow(() => connection.Close());
            Assert.AreEqual(ConnectionState.Closed, connection.State);
        }
Beispiel #20
0
        public void CreateCommandWithNamedParameters(string paramName, string paramValue)
        {
            const string connString = "Host=Heap;UserID=SA;Password=123456;Database=testdb;Parameter Style=Named;BootOrCreate=true";
            var connection = new DeveelDbConnection(connString);
            Assert.DoesNotThrow(connection.Open);

            var command = connection.CreateCommand();

            command.CommandText = "CREATE TABLE Person (Id Identity, Name VARCHAR NOT NULL, LastName VarChar)";
            var result = command.ExecuteNonQuery();

            command.CommandText = String.Format("SELECT * FROM Person WHERE Name = {0}", paramName);
            Assert.DoesNotThrow(() => command.Parameters.Add(paramName, paramValue));

            DeveelDbDataReader reader = null;
            Assert.DoesNotThrow(() => reader = command.ExecuteReader());
            Assert.IsNotNull(reader);
            reader.Close();

            command.CommandText = "DROP TABLE Person";
            command.ExecuteNonQuery();
        }
Beispiel #21
0
        public void CreateCommandWithMarkerParameters()
        {
            const string connString = "Host=Heap;UserID=SA;Password=123456;Database=testdb;Parameter Style=Marker;BootOrCreate=true";
            var connection = new DeveelDbConnection(connString);
            Assert.DoesNotThrow(connection.Open);

            var command = connection.CreateCommand();

            command.CommandText = "CREATE TABLE Person (Id Identity, Name VARCHAR NOT NULL, LastName VarChar)";
            var result = command.ExecuteNonQuery();

            Assert.AreEqual(0, result);

            command.CommandText = "SELECT * FROM Person WHERE Name = ?";
            Assert.DoesNotThrow(() => command.Parameters.Add("antonelllo"));

            object value = null;
            Assert.DoesNotThrow(() => value = command.ExecuteScalar());
            Assert.IsNull(value);

            command.CommandText = "DROP TABLE Person";
            command.ExecuteNonQuery();
        }
 protected override void OnAfterSetup(string testName)
 {
     connection = (DeveelDbConnection)Database.CreateDbConnection(AdminUserName, AdminPassword);
 }
Beispiel #23
0
 public DeveelDbDataAdapter(DeveelDbConnection connection, string commandText)
 {
     SelectCommand = new DeveelDbCommand(connection, commandText);
 }
Beispiel #24
0
        public void SetUp()
        {
            DbConfig config = DbConfig.Default;
            OnConfigure(config);
            DbController controller = DbController.Create(Environment.CurrentDirectory, config);

            system = !controller.DatabaseExists(DatabaseName)
                        ? controller.CreateDatabase(config, DatabaseName, AdminUser, AdminPassword)
                        : controller.StartDatabase(config, DatabaseName);

            connection = (DeveelDbConnection)system.GetConnection(AdminUser, AdminPassword);
            // connection.AutoCommit = true;
        }
Beispiel #25
0
        internal static ObjectId Upload(DeveelDbConnection connection, DeveelDbLob lob)
        {
            if (connection == null)
                throw new InvalidOperationException("An open connection is required to upload the LOB");

            var objId = connection.CreateLargeObject(lob.Length);
            using (var channel = connection.OpenLargeObjectChannel(objId)) {
                const int bufferSize = 2048;
                var copyBuffer = new byte[bufferSize];
                int readCount;
                long copyOffset = 0;
                lob.writeStream.Seek(0, SeekOrigin.Begin);

                while ((readCount = lob.writeStream.Read(copyBuffer, 0, bufferSize)) > 0) {
                    channel.PushData(copyOffset, copyBuffer, readCount);
                    copyOffset += readCount;
                }
            }

            return objId;
        }
Beispiel #26
0
 public DeveelDbCommand(DeveelDbConnection connection)
     : this(connection, null)
 {
 }
Beispiel #27
0
        protected override void Dispose(bool disposing)
        {
            if (disposing) {
                if (!finished)
                    Rollback();
            }

            connection = null;

            base.Dispose(disposing);
        }
Beispiel #28
0
        ///<summary>
        /// Makes a connection to the database and returns a <see cref="IDbConnection"/> 
        /// object that can be used to execute queries on the database.
        ///</summary>
        ///<param name="schema">The initial database schema to start the connection in.</param>
        ///<param name="username">The user to login to the database under.</param>
        ///<param name="password">The password of the user.</param>
        /// <remarks>
        /// This is a standard connection that talks directly with the database without 
        /// having to go through any communication protocol layers.
        /// <para>
        /// For example, if this control is for a database server, the <see cref="IDbConnection"/>
        /// returned here does not go through the TCP/IP connection.  For this reason certain database 
        /// configuration constraints (such as number of concurrent connection on the database) may not 
        /// apply to this connection.
        /// </para>
        /// </remarks>
        ///<returns>
        /// Returns a <see cref="IDbConnection"/> instance used to access the database.
        /// </returns>
        /// <exception cref="DataException">
        /// Thrown if the login fails with the credentials given.
        /// </exception>
        public IDbConnection GetConnection(string schema, string username, string password)
        {
            // Create the database interface for an internal database connection.
            var localSystem = new LocalSystem(controller);
            var localDatabase = localSystem.ControlDatabase(name);

            // Create the DeveelDbConnection object (very minimal cache settings for an
            // internal connection).
            var s = new DeveelDbConnectionStringBuilder {
                Database = name,
                Schema = schema,
                UserName = username,
                Password = password,
                RowCacheSize = 8,
                MaxCacheSize = 4092000,
                BootOrCreate = true
            };

            if (Config.IsHeapStorageSystem()) {
                s.Host = "Heap";
            } else {
                s.Host = "Local";
                s.Path = Config.DatabaseFullPath();
            }

            int id = ++internalCounter;

            var connection = new DeveelDbConnection(s.ToString(), localDatabase);
            connection.StateChange += (sender, args) => {
                if (args.CurrentState == ConnectionState.Open) {
                    if (connections == null)
                        connections = new Dictionary<int, DeveelDbConnection>();

                    connections[id] = connection;
                } else if (args.CurrentState == ConnectionState.Closed) {
                    connections.Remove(id);
                }
            };

            connection.Disposed += (sender, args) => {
                // TODO: do further disposal
            };

            // Attempt to log in with the given username and password (default schema)
            connection.Open();
            if (connection.State != ConnectionState.Open)
                throw new InvalidOperationException("Unable to open the connection.");

            // And return the new connection
            return connection;
        }
 public DeveelDbDataAdapter(DeveelDbConnection connection, string commandText)
 {
     SelectCommand = new DeveelDbCommand(connection, commandText);
 }
Beispiel #30
0
        public void TestSetUp()
        {
            connection = (DeveelDbConnection)system.GetConnection(AdminUser, AdminPassword);
            if (connection.State != ConnectionState.Open)
                connection.Open();

            OnTestSetUp();
        }
 private void Dispose(DeveelDbConnection connection)
 {
     connection.Dispose();
     transaction = null;
     Scope       = null;
 }
Beispiel #32
0
 public LocalRowCache(DeveelDbConnection connection)
 {
     this.connection = connection;
     rowCache = new MemoryCache(connection.Settings.RowCacheSize, connection.Settings.MaxCacheSize, 20);
 }
Beispiel #33
0
 private void Dispose(DeveelDbConnection connection)
 {
     connection.Dispose();
     transaction = null;
     Scope = null;
 }
Beispiel #34
0
        public void ExecuteMultipleStatements()
        {
            const string connString = "Host=Heap;UserID=SA;Password=123456;Database=testdb;BootOrCreate=true";
            var connection = new DeveelDbConnection(connString);

            Assert.DoesNotThrow(connection.Open);
            Assert.IsTrue(connection.State == ConnectionState.Open);

            DeveelDbCommand command = connection.CreateCommand();
            command.CommandText = "DECLARE firstName STRING NOT NULL; SET firstName = 'antonello'; SELECT :firstName;";
            var reader = command.ExecuteReader();
            Assert.IsTrue(reader.NextResult());
            Assert.IsTrue(reader.NextResult());
            Assert.IsTrue(reader.Read());
            Assert.IsFalse(reader.IsDBNull(0));
            Assert.AreEqual("antonello", reader.GetString(0));
            connection.Close();
        }
Beispiel #35
0
 public DeveelDbDataAdapter(string connectionString, string commandText)
 {
     var connection = new DeveelDbConnection(connectionString);
     SelectCommand = new DeveelDbCommand(connection, commandText);
 }
 public DatabaseMetadata(DeveelDbConnection connection)
 {
     this.connection = connection;
 }
 public DeveelDbCommand(DeveelDbConnection connection)
     : this(connection, null)
 {
 }
Beispiel #38
0
        protected override void OnAfterSetup(string testName)
        {
            var connString = new DeveelDbConnectionStringBuilder {
                UserName = AdminUserName,
                Password = AdminPassword,
                DataSource = "memory",
                Database = DatabaseName,
                Schema = "APP",
                Create = true
            };

            connection = (DeveelDbConnection) Database.CreateDbConnection(AdminUserName, AdminPassword);
        }
        public DeveelDbDataAdapter(string connectionString, string commandText)
        {
            var connection = new DeveelDbConnection(connectionString);

            SelectCommand = new DeveelDbCommand(connection, commandText);
        }
Beispiel #40
0
        private void Dispose(bool disposing)
        {
            if (disposing) {
                try {
                    Close();
                } catch (DeveelDbException) {
                    // Ignore
                    // We ignore exceptions because handling cases where the server
                    // connection has broken for many ResultSets would be annoying.
                }
            }

            connection = null;
            columns = null;
            resultBlock = null;
        }
Beispiel #41
0
 public DatabaseMetadata(DeveelDbConnection connection)
 {
     this.connection = connection;
 }
Beispiel #42
0
 public LocalRowCache(DeveelDbConnection connection)
 {
     this.connection = connection;
     rowCache = new SizeLimitedCache(connection.Settings.RowCacheSize);
 }
 protected override void OnAfterSetup(string testName)
 {
     connection = (DeveelDbConnection) Database.CreateDbConnection(AdminUserName, AdminPassword);
 }
Beispiel #44
0
        public void ExecuteScalarOnsingleColumn()
        {
            const string connString = "Host=Heap;UserID=SA;Password=123456;Database=testdb;BootOrCreate=true";
            var connection = new DeveelDbConnection(connString);
            connection.Open();

            // TODO: Open the connection, create a transaction, declare some variables

            DeveelDbCommand command = null;
            Assert.DoesNotThrow(() => command = connection.CreateCommand());
            Assert.IsNotNull(command);
            command.CommandText = "SELECT Age FROM Person WHERE Name = 'antonello'";
        }