/// <summary> /// Raises the <see cref="E:Warning"/> event. /// </summary> /// <param name="warning"> /// The instance containing the event data. /// </param> internal void OnWarning(HsqlWarningEventArgs warning) { HsqlWarningEventHandler handler = this.Warning; if (handler == null) { HsqlConnection connection = this.Connection; if (connection != null) { connection.OnWarning(warning); } } else { try { handler(this, warning); } catch (Exception ex) { if (HsqlDiagnostics.MustRethrowEventProcessingException(ex)) { throw; } } } }
public virtual void ChangeDatabase() { using (HsqlConnection testSubject = new HsqlConnection("DataSource=mem:test2")) { string databaseName = "test1"; testSubject.ChangeDatabase(databaseName); testSubject.Open(); } using (HsqlConnection testSubject = new HsqlConnection("DataSource=mem:test2")) { testSubject.Open(); string databaseName = "test1"; try { testSubject.ChangeDatabase(databaseName); Assert.Fail("it is not expected that it is legal to change database while a connection is open."); } catch (Exception) { } } }
/// <summary> /// Releases, if present, the underlying <c>HsqlStatement</c> and /// makes eligible for garbage collection any related resources. /// </summary> internal void InvalidateStatement() { try { // localize member references to minimize // potential race conditions regarding // null status of instance variables. HsqlConnection connection = m_dbConnection; HsqlStatement statement = m_statement; // Don't leak compiled statement handles if (connection != null && connection.State == ConnectionState.Open && statement != null) { statement.Free(Session); } } finally { m_statement = null; m_tokenList = null; m_storedProcedureCommandText = null; m_tableDirectCommandText = null; } }
public virtual void BeginTransaction() { using (HsqlConnection testSubject = new HsqlConnection()) { testSubject.Open(); using (HsqlTransaction transaction = testSubject.BeginTransaction()) { } } object[] expected = new object[] { IsolationLevel.Chaos, false, IsolationLevel.ReadCommitted, true, IsolationLevel.ReadUncommitted, true, IsolationLevel.RepeatableRead, true, IsolationLevel.Serializable, true, IsolationLevel.Snapshot, true, IsolationLevel.Unspecified, true }; IsolationLevel isolationLevel; bool isolationLevelIsSupported; for (int i = 0; i < expected.Length; i += 2) { isolationLevel = (IsolationLevel)expected[i]; isolationLevelIsSupported = (bool) expected[i+1]; TestBeginTransaction(isolationLevel, isolationLevelIsSupported); } }
public HsqlDataReader( org.hsqldb.Result result, CommandBehavior commandBehavior, HsqlCommand originatingCommand, HsqlConnection originatingConnection) : this(result) { m_commandBehavior = commandBehavior; m_originatingCommand = originatingCommand; m_originatingConnection = originatingConnection; }
/// <summary> /// Initializes a new instance of the /// <see cref="HsqlTransaction"/> class. /// </summary> /// <param name="dbConnection">The db connection.</param> /// <param name="isolationLevel">The isolation level.</param> internal HsqlTransaction( HsqlConnection dbConnection, IsolationLevel isolationLevel) : base() { // PRE: Caller ensures connection is non-null and open. m_connection = dbConnection; // PRE: Caller ensures IsolationLevel is supported. m_isolationLevel = isolationLevel; m_valid = true; }
/// <summary> /// Initializes a new instance of the /// <see cref="HsqlTransaction"/> class. /// </summary> /// <param name="dbConnection">The db connection.</param> /// <param name="isolationLevel">The isolation level.</param> internal HsqlTransaction( HsqlConnection dbConnection, IsolationLevel isolationLevel) : base() { // PRE: Caller ensures connection is non-null and open. m_connection = dbConnection; // PRE: Caller ensures IsolationLevel is supported. m_isolationLevel = isolationLevel; m_valid = true; }
/// <summary> /// Releases the resources used by this object and /// optionally causes the underlying database transaction to /// be rolled back. /// </summary> /// <param name="rollback"> /// When <c>true</c>, the transaction is rolled back; /// otherwise, the transaction is left in its current state. /// </param> internal void DisposeInternal(bool rollback) { lock (m_syncRoot) { if (m_valid) { if (rollback) { m_connection.EndTransactionInternal(this, true); } m_valid = false; m_connection = null; } } }
public HsqlDataReader( org.hsqldb.Result result, CommandBehavior commandBehavior, HsqlCommand originatingCommand, HsqlConnection originatingConnection) : this(result) { m_commandBehavior = commandBehavior; m_originatingCommand = originatingCommand; m_originatingConnection = originatingConnection; }
/// <summary> /// Constructs a new <c>HsqlCommand</c> instance with the given /// connection, command text and command type. /// </summary> /// <param name="connection"> /// The connection with which this command is initially associated. /// </param> /// <param name="commandText"> /// The initial command text to execute. /// </param> /// <param name="commandType"> /// The way in which to initially interpret the command text. /// </param> public HsqlCommand(HsqlConnection connection, String commandText, CommandType commandType) : this(connection, commandText) { this.CommandType = commandType; }
/// <summary> /// Closes this connection. /// </summary> internal void CloseInternal() { ConnectionState state = m_connectionState; if (state == ConnectionState.Closed) { return; } HsqlSession session = m_session; if (m_session == null) { // Sanity-Check: Should never happen. throw new InvalidOperationException( "HsqlSession is null"); // NOI18N } // Handle dispose/close while enlisted in a system transaction. HsqlTransaction transaction = m_transaction; HsqlEnlistment enlistment = m_enlistment; bool enlisted = (enlistment != null); bool preserveEnlistment = (enlisted && !enlistment.m_disposeConnection); if (preserveEnlistment) { #if DEBUG // Without this, it is difficult to debug // because the m_enlistment's connection // ceases to be this one and this connection // loses its reference to the enlistment // (m_enlistment is set null below). m_enlistment_dbg = m_enlistment; #endif // ...then until it ceases to participate in a // System.Transactions.Transaction, the enlistment // needs a valid local transaction to commit or // rollback HsqlConnection connection = new HsqlConnection(this); connection.m_connectionState = ConnectionState.Open; connection.m_session = session; connection.m_enlistment = enlistment; connection.m_transaction = transaction; enlistment.m_dbConnection = connection; enlistment.m_disposeConnection = true; if (transaction != null) { transaction.m_connection = connection; } } SetStateInternal(ConnectionState.Closed); m_session = null; m_transaction = null; m_enlistment = null; m_dbMetaData = null; m_settings = null; if (!enlisted) { // No need to roll back here. This will happen automatically // a moment later on the back end in response to the // session.Close() call below. if (transaction != null) { transaction.DisposeInternal(/*rollback*/false); } // release the back-end session and any associated resources, // such as network sockets, etc. session.Close(); } }
/// <summary> /// Releases the resources used by this object and /// optionally causes the underlying database transaction to /// be rolled back. /// </summary> /// <param name="rollback"> /// When <c>true</c>, the transaction is rolled back; /// otherwise, the transaction is left in its current state. /// </param> internal void DisposeInternal(bool rollback) { lock (m_syncRoot) { if (m_valid) { if (rollback) { m_connection.EndTransactionInternal(this, true); } m_valid = false; m_connection = null; } } }
public virtual void Open() { using (HsqlConnection testSubject = new HsqlConnection()) { testSubject.Open(); try { testSubject.Open(); Assert.Fail("A second Open() invocation should not succeed when a connection is already open."); } catch (Exception) { } } }
public virtual void GetSchema() { using (HsqlConnection testSubject = new HsqlConnection()) { DataTable dataTable = testSubject.GetSchema(); Console.WriteLine("Table Name: " + dataTable.TableName); Console.WriteLine("-----------------------------------"); foreach (DataRow row in dataTable.Rows) { foreach (DataColumn column in dataTable.Columns) { Console.WriteLine(column.Caption + ": " + row[column]); } } //testSubject.GetSchema(""); //testSubject.GetSchema("",new string[]); } }
public virtual void CreateCommand() { using (HsqlConnection testSubject = new HsqlConnection()) { HsqlCommand command = testSubject.CreateCommand(); Assert.AreSame(testSubject, command.Connection); Assert.AreEqual(string.Empty, command.CommandText); Assert.AreEqual(CommandType.Text, command.CommandType); Assert.AreEqual(true, command.DesignTimeVisible); Assert.AreEqual(false, command.IsPrepared); Assert.AreEqual(UpdateRowSource.Both, command.UpdatedRowSource); Assert.AreEqual(null, command.Transaction); } }
/// <summary> /// Initializes a new instance of the <see cref="HsqlDataAdapter"/> class /// with an SQL SELECT statement and a connection string. /// </summary> /// <param name="selectCommandText"> /// The string representation of the SQL SELECT statement or stored procedure /// to be executed by the <see cref="SelectCommand"/> property of this object. /// </param> /// <param name="selectConnectionString"> /// The connection string used to obtain the connection object on which the /// <see cref="SelectCommand"/> property of this object executes. /// </param> public HsqlDataAdapter(string selectCommandText, string selectConnectionString) { HsqlConnection connection = new HsqlConnection(selectConnectionString); SelectCommand = new HsqlCommand(connection, selectCommandText); }
/// <summary> /// Returns the collection of currently valid initial schema names, /// given the specified context. /// </summary> /// <param name="context"> /// An <see cref="ITypeDescriptorContext"></see> whose <c>Instance</c> /// property supplies the <c>HsqlConnectionStringBuilder</c> use to /// connect to a data source to retrieve the currently valid initial /// schema names. /// </param> /// <returns> /// A <see cref="TypeConverter.StandardValuesCollection"/> that holds /// collection of currently valid initial schema names. /// </returns> public override TypeConverter.StandardValuesCollection GetStandardValues( ITypeDescriptorContext context) { if (!IsStandardValuesSupported(context)) { return null; } List<string> values = new List<string>(); try { HsqlConnectionStringBuilder builder = (HsqlConnectionStringBuilder)context.Instance; // TODO: this is sub-optimal, but is currently the best (only?) // solution to the problem of how to avoid creating and/or // leaving open embedded database instances. if (IsEmbeddedProtocol(builder)) { builder = new HsqlConnectionStringBuilder( builder.ConnectionString); builder.AutoShutdown = true; builder.IfExists = true; } using (HsqlConnection connection = new HsqlConnection()) { connection.ConnectionString = builder.ConnectionString; using (HsqlCommand command = new HsqlCommand( connection, SchemaQuery)) { connection.Open(); using (HsqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { values.Add(reader.GetString(0)); } } } } } catch (Exception exception) { #if DEBUG Debug.WriteLine(exception); #endif } return new TypeConverter.StandardValuesCollection(values); }
/// <summary> /// Contructs a new <c>HsqlConnection</c> with the /// connection string of the other /// <c>HsqlConnection</c> object. /// </summary> /// <param name="other"> /// From which to obtain the connection string. /// </param> internal HsqlConnection(HsqlConnection other) : this(other.ConnectionString) { }
/// <summary> /// Provides the core logic for the /// <see cref="ExecuteReader(CommandBehavior)"/> method. /// </summary> /// <param name="behavior">The requested behavior.</param> /// <returns> /// The result generated by executing the query. /// </returns> internal HsqlDataReader ExecuteReaderInternal(CommandBehavior behavior) { if (Behavior.IsSchemaOnly(behavior)) { bool wasAlreadyPrepared = IsPrepared; if (!wasAlreadyPrepared) { Prepare(); // already correctly locked. } Result descriptor = m_statement.ResultDescriptor; HsqlCommand originatingCommand = this; HsqlConnection originatingConnection = m_dbConnection; HsqlDataReader reader0 = new HsqlDataReader(descriptor, behavior, originatingCommand, originatingConnection); if (Behavior.IsKeyInfo(behavior)) { // Do it now, so that it does not fail later if // originating connection is closed before first // client invocation of reader.GetSchemaTable(). reader0.GetSchemaTable(); } if (!wasAlreadyPrepared) { UnPrepare(); } return(reader0); } Result result; int maxRows = (Behavior.IsSingleRow(behavior)) ? 1 : 0; if (IsPrepared) { ApplyParameters(); HsqlSession session = Session; session.MaxRows = maxRows; result = m_statement.Execute(session); } else { HsqlSession session = Session; session.MaxRows = maxRows; result = session.ExecuteDirect(StaticallyBoundCommandText); } HsqlDataReader reader = new HsqlDataReader(result, behavior, this, this.m_dbConnection); if (Behavior.IsKeyInfo(behavior)) { // Do it now, so that it does not fail later if // originating connection is closed before first // client invocation of reader.GetSchemaTable(). reader.GetSchemaTable(); } return(reader); }
/// <summary> /// Closes this connection. /// </summary> internal void CloseInternal() { ConnectionState state = m_connectionState; if (state == ConnectionState.Closed) { return; } HsqlSession session = m_session; if (m_session == null) { // Sanity-Check: Should never happen. throw new InvalidOperationException( "HsqlSession is null"); // NOI18N } // Handle dispose/close while enlisted in a system transaction. HsqlTransaction transaction = m_transaction; HsqlEnlistment enlistment = m_enlistment; bool enlisted = (enlistment != null); bool preserveEnlistment = (enlisted && !enlistment.m_disposeConnection); if (preserveEnlistment) { #if DEBUG // Without this, it is difficult to debug // because the m_enlistment's connection // ceases to be this one and this connection // loses its reference to the enlistment // (m_enlistment is set null below). m_enlistment_dbg = m_enlistment; #endif // ...then until it ceases to participate in a // System.Transactions.Transaction, the enlistment // needs a valid local transaction to commit or // rollback HsqlConnection connection = new HsqlConnection(this); connection.m_connectionState = ConnectionState.Open; connection.m_session = session; connection.m_enlistment = enlistment; connection.m_transaction = transaction; enlistment.m_dbConnection = connection; enlistment.m_disposeConnection = true; if (transaction != null) { transaction.m_connection = connection; } } SetStateInternal(ConnectionState.Closed); m_session = null; m_transaction = null; m_enlistment = null; m_dbMetaData = null; m_settings = null; if (!enlisted) { // No need to roll back here. This will happen automatically // a moment later on the back end in response to the // session.Close() call below. if (transaction != null) { transaction.DisposeInternal(/*rollback*/ false); } // release the back-end session and any associated resources, // such as network sockets, etc. session.Close(); } }
/// <summary> /// Initializes a new instance of the <see cref="HsqlDataAdapter"/> class /// with an SQL SELECT statement and an <see cref="HsqlConnection"/>. /// </summary> /// <param name="selectCommandText"> /// The string representation of the SQL SELECT statement or stored procedure /// to be executed by the <see cref="SelectCommand"/> property of this object. /// </param> /// <param name="selectConnection">The select connection.</param> public HsqlDataAdapter(string selectCommandText, HsqlConnection selectConnection) : this() { SelectCommand = new HsqlCommand(selectConnection, selectCommandText); }
/// <summary> /// Initializes a new instance of the <see cref="HsqlDataAdapter"/> class /// with an SQL SELECT statement and an <see cref="HsqlConnection"/>. /// </summary> /// <param name="selectCommandText"> /// The string representation of the SQL SELECT statement or stored procedure /// to be executed by the <see cref="SelectCommand"/> property of this object. /// </param> /// <param name="selectConnection">The select connection.</param> public HsqlDataAdapter(string selectCommandText, HsqlConnection selectConnection) : this() { SelectCommand = new HsqlCommand(selectConnection, selectCommandText); }
/// <summary> /// Initializes a new instance of the <see cref="HsqlDataAdapter"/> class /// with an SQL SELECT statement and a connection string. /// </summary> /// <param name="selectCommandText"> /// The string representation of the SQL SELECT statement or stored procedure /// to be executed by the <see cref="SelectCommand"/> property of this object. /// </param> /// <param name="selectConnectionString"> /// The connection string used to obtain the connection object on which the /// <see cref="SelectCommand"/> property of this object executes. /// </param> public HsqlDataAdapter(string selectCommandText, string selectConnectionString) { HsqlConnection connection = new HsqlConnection(selectConnectionString); SelectCommand = new HsqlCommand(connection, selectCommandText); }
public virtual void Close() { using (HsqlConnection testSubject = new HsqlConnection()) { Assert.That(testSubject.State == ConnectionState.Closed); testSubject.Open(); Assert.That(testSubject.State == ConnectionState.Open); testSubject.Close(); Assert.That(testSubject.State == ConnectionState.Closed); testSubject.Close(); Assert.That(testSubject.State == ConnectionState.Closed); } }
/// <summary> /// Constructs a new <c>HsqlCommand</c> instance that is initially /// associated with the given connection. /// </summary> /// <remarks> /// The initial <c>CommandType</c> is <see cref="System.Data.CommandType.Text"/> /// and the initial <c>CommandText</c> is empty. /// </remarks> /// <param name="connection"> /// The connection with which this command is initially associated. /// </param> public HsqlCommand(HsqlConnection connection) : this() { Connection = connection; }
public virtual void EnlistTransaction() { HsqlConnection testSubject = new HsqlConnection(); using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.Required)) { testSubject.Open(); testSubject.EnlistTransaction(Transaction.Current); try { testSubject.BeginTransaction(); Assert.Fail("The test subject allowed a local transaction to be started " + "explicitly while participating in a system transaction"); } catch (Exception) { } transactionScope.Complete(); try { testSubject.BeginTransaction(); Assert.Fail("The test subject allowed a local transaction to be started " + "explicitly while participating in a system transaction"); } catch (Exception) { } } using (HsqlTransaction transaction = testSubject.BeginTransaction()) { transaction.Commit(); } }
/// <summary> /// Constructs a new <c>HsqlCommand</c> instance with the given /// connection and command text. /// </summary> /// <remarks> /// The initial <c>CommandType</c> is <see cref="System.Data.CommandType.Text"/> /// </remarks> /// <param name="connection"> /// The connection with which this command is initially associated. /// </param> /// <param name="commandText"> /// The initial command text. /// </param> public HsqlCommand(HsqlConnection connection, string commandText) : this(connection) { CommandText = commandText; }
/// <summary> /// Constructs a new <c>HsqlCommand</c> instance with the given /// connection, command text and command type. /// </summary> /// <param name="connection"> /// The connection with which this command is initially associated. /// </param> /// <param name="commandText"> /// The initial command text to execute. /// </param> /// <param name="commandType"> /// The way in which to initially interpret the command text. /// </param> public HsqlCommand(HsqlConnection connection, String commandText, CommandType commandType) : this(connection, commandText) { this.CommandType = commandType; }
/// <summary> /// Constructs a new <c>HsqlCommand</c> instance that is initially /// associated with the given connection. /// </summary> /// <remarks> /// The initial <c>CommandType</c> is <see cref="System.Data.CommandType.Text"/> /// and the initial <c>CommandText</c> is empty. /// </remarks> /// <param name="connection"> /// The connection with which this command is initially associated. /// </param> public HsqlCommand(HsqlConnection connection) : this() { Connection = connection; }
void TestBeginTransaction(IsolationLevel isolationLevel, bool isolationLevelIsSupported) { try { using (HsqlConnection testSubject = new HsqlConnection()) { testSubject.Open(); using (HsqlTransaction transaction = testSubject.BeginTransaction(isolationLevel)) { } } Assert.That(isolationLevelIsSupported, "System.Data.IsolationLevel: " + Enum.GetName(typeof(IsolationLevel), isolationLevel)); } catch (Exception) { Assert.That(!isolationLevelIsSupported, "System.Data.IsolationLevel: " + Enum.GetName(typeof(IsolationLevel), isolationLevel)); } }
/// <summary> /// Constructs a new <c>HsqlCommand</c> instance with the given /// connection and command text. /// </summary> /// <remarks> /// The initial <c>CommandType</c> is <see cref="System.Data.CommandType.Text"/> /// </remarks> /// <param name="connection"> /// The connection with which this command is initially associated. /// </param> /// <param name="commandText"> /// The initial command text. /// </param> public HsqlCommand(HsqlConnection connection, string commandText) : this(connection) { CommandText = commandText; }
public virtual void Clone() { string connectionString = "DataSource=mem:test"; using (HsqlConnection testSubject = new HsqlConnection(connectionString)) { HsqlConnection copy = testSubject.Clone(); Assert.AreEqual(connectionString, testSubject.ConnectionString); } }
/// <summary> /// Contructs a new <c>HsqlConnection</c> with the /// connection string of the other /// <c>HsqlConnection</c> object. /// </summary> /// <param name="other"> /// From which to obtain the connection string. /// </param> internal HsqlConnection(HsqlConnection other) : this(other.ConnectionString) { }