[pgsqlclient-checkins] pgsqlclient_10/PostgreSql.Data.PgSqlClient/source PgCommand.cs,1.6,1.7 PgConn
Status: Inactive
Brought to you by:
carlosga_fb
From: <car...@us...> - 2003-09-29 18:15:50
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source In directory sc8-pr-cvs1:/tmp/cvs-serv32726 Modified Files: PgCommand.cs PgConnection.cs Log Message: - Added better checking of command transaction ( matching SqlClient way ) Index: PgCommand.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgCommand.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** PgCommand.cs 27 Sep 2003 19:20:39 -0000 1.6 --- PgCommand.cs 29 Sep 2003 18:15:36 -0000 1.7 *************** *** 299,320 **** public int ExecuteNonQuery() ! { ! if (Connection == null || Connection.State != ConnectionState.Open) ! { ! throw new InvalidOperationException("Connection must valid and open"); ! } ! ! if (Connection.DataReader != null) ! { ! throw new InvalidOperationException("There is already an open DataReader associated with this Connection which must be closed first."); ! } ! ! if (Transaction != null) ! { ! if (!Connection.Equals(Transaction.Connection)) ! { ! throw new InvalidOperationException("Command Connection is not equal to Transaction Connection"); ! } ! } InternalPrepare(); --- 299,304 ---- public int ExecuteNonQuery() ! { ! checkCommand(); InternalPrepare(); *************** *** 343,363 **** public PgDataReader ExecuteReader(CommandBehavior behavior) { ! if (Connection == null || Connection.State != ConnectionState.Open) ! { ! throw new InvalidOperationException("Connection must valid and open"); ! } ! ! if (Connection.DataReader != null) ! { ! throw new InvalidOperationException("There is already an open DataReader associated with this Connection which must be closed first."); ! } ! ! if (Transaction != null) ! { ! if (!Connection.Equals(Transaction.Connection)) ! { ! throw new InvalidOperationException("Command Connection is not equal to Transaction Connection"); ! } ! } commandBehavior = behavior; --- 327,331 ---- public PgDataReader ExecuteReader(CommandBehavior behavior) { ! checkCommand(); commandBehavior = behavior; *************** *** 379,399 **** public object ExecuteScalar() { ! if (Connection == null || Connection.State != ConnectionState.Open) ! { ! throw new InvalidOperationException("Connection must valid and open"); ! } ! ! if (Connection.DataReader != null) ! { ! throw new InvalidOperationException("There is already an open DataReader associated with this Connection which must be closed first."); ! } ! ! if (Transaction != null) ! { ! if (!Connection.Equals(Transaction.Connection)) ! { ! throw new InvalidOperationException("Command Connection is not equal to Transaction Connection"); ! } ! } object returnValue = null; --- 347,351 ---- public object ExecuteScalar() { ! checkCommand(); object returnValue = null; *************** *** 412,427 **** public void Prepare() { ! if (Connection == null || Connection.State != ConnectionState.Open) ! { ! throw new InvalidOperationException("Connection must valid and open."); ! } ! ! if (Transaction != null) ! { ! if (!Connection.Equals(Transaction.Connection)) ! { ! throw new InvalidOperationException("Command Connection is not equal to Transaction Connection."); ! } ! } InternalPrepare(); --- 364,368 ---- public void Prepare() { ! checkCommand(); InternalPrepare(); *************** *** 433,436 **** --- 374,379 ---- string plan; + checkCommand(); + try { *************** *** 671,674 **** --- 614,644 ---- } } + } + } + + private void checkCommand() + { + if (connection == null || connection.State != ConnectionState.Open) + { + throw new InvalidOperationException("Connection must valid and open"); + } + if (connection.DataReader != null) + { + throw new InvalidOperationException("There is already an open DataReader associated with this Connection which must be closed first."); + } + if (connection.ActiveTransaction != null && + !connection.ActiveTransaction.IsUpdated && + this.Transaction == null) + { + throw new InvalidOperationException("Execute requires the Command object to have a Transaction object when the Connection object assigned to the command is in a pending local transaction. The Transaction property of the Command has not been initialized."); + } + if (transaction != null && + !connection.Equals(Transaction.Connection)) + { + throw new InvalidOperationException("Command Connection is not equal to Transaction Connection"); + } + if (commandText == String.Empty || commandText == null) + { + throw new InvalidOperationException ("The command text for this Command has not been set."); } } Index: PgConnection.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgConnection.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PgConnection.cs 22 Aug 2003 19:18:12 -0000 1.2 --- PgConnection.cs 29 Sep 2003 18:15:36 -0000 1.3 *************** *** 47,51 **** private string connectionString; private PgDataReader dataReader; ! private PgTransaction activeTxn; private ArrayList activeCommands; --- 47,51 ---- private string connectionString; private PgDataReader dataReader; ! private PgTransaction activeTransaction; private ArrayList activeCommands; *************** *** 180,183 **** --- 180,188 ---- } + internal PgTransaction ActiveTransaction + { + get { return activeTransaction; } + } + #endregion *************** *** 261,265 **** } ! if (activeTxn != null && !activeTxn.IsUpdated) { throw new InvalidOperationException("A transaction is currently active. Parallel transactions are not supported."); --- 266,270 ---- } ! if (activeTransaction != null && !activeTransaction.IsUpdated) { throw new InvalidOperationException("A transaction is currently active. Parallel transactions are not supported."); *************** *** 273,278 **** try { ! activeTxn = new PgTransaction(this); ! activeTxn.InternalBeginTransaction(); } catch (PgClientException ex) --- 278,283 ---- try { ! activeTransaction = new PgTransaction(this); ! activeTransaction.InternalBeginTransaction(); } catch (PgClientException ex) *************** *** 281,285 **** } ! return this.activeTxn; } --- 286,290 ---- } ! return this.activeTransaction; } *************** *** 291,295 **** } ! if (activeTxn != null && !activeTxn.IsUpdated) { throw new InvalidOperationException("A transaction is currently active. Parallel transactions are not supported."); --- 296,300 ---- } ! if (activeTransaction != null && !activeTransaction.IsUpdated) { throw new InvalidOperationException("A transaction is currently active. Parallel transactions are not supported."); *************** *** 303,308 **** try { ! activeTxn = new PgTransaction(this, level); ! activeTxn.InternalBeginTransaction(); } catch (PgClientException ex) --- 308,313 ---- try { ! activeTransaction = new PgTransaction(this, level); ! activeTransaction.InternalBeginTransaction(); } catch (PgClientException ex) *************** *** 311,315 **** } ! return this.activeTxn; } --- 316,320 ---- } ! return this.activeTransaction; } *************** *** 417,424 **** // Rollback active transation ! if (activeTxn != null) { ! activeTxn.Dispose(); ! activeTxn = null; } --- 422,429 ---- // Rollback active transation ! if (activeTransaction != null) { ! activeTransaction.Dispose(); ! activeTransaction = null; } |