[pgsqlclient-checkins] pgsqlclient_10/PostgreSql.Data.PgSqlClient/source PgCommand.cs,1.7,1.8 PgData
Status: Inactive
Brought to you by:
carlosga_fb
From: <car...@us...> - 2003-10-07 09:05:05
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source In directory sc8-pr-cvs1:/tmp/cvs-serv19013 Modified Files: PgCommand.cs PgDataReader.cs Log Message: Implemented NextResult stuff Index: PgCommand.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgCommand.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** PgCommand.cs 29 Sep 2003 18:15:36 -0000 1.7 --- PgCommand.cs 7 Oct 2003 09:05:01 -0000 1.8 *************** *** 40,43 **** --- 40,45 ---- private CommandBehavior commandBehavior; private bool disposed; + private int actualCommand; + private string[] commands; private string commandText; private CommandType commandType; *************** *** 58,71 **** public string CommandText { ! get { return commandText; } set { ! if (statement != null && commandText != value && ! commandText != null && commandText.Length != 0) { ! InternalClose(); } ! commandText = value; } } --- 60,75 ---- public string CommandText { ! get { return this.commandText; } set { ! if (this.statement != null && this.commandText != value && ! this.commandText != null && this.commandText.Length != 0) { ! this.InternalClose(); } ! this.commandText = value; ! this.actualCommand = 0; ! this.splitBatchCommands(); } } *************** *** 76,81 **** public CommandType CommandType { ! get { return commandType; } ! set { commandType = value; } } --- 80,85 ---- public CommandType CommandType { ! get { return this.commandType; } ! set { this.commandType = value; } } *************** *** 84,88 **** public int CommandTimeout { ! get { return commandTimeout; } set { --- 88,92 ---- public int CommandTimeout { ! get { return this.commandTimeout; } set { *************** *** 100,105 **** IDbConnection IDbCommand.Connection { ! get { return Connection; } ! set { Connection = (PgConnection)value; } } --- 104,109 ---- IDbConnection IDbCommand.Connection { ! get { return this.Connection; } ! set { this.Connection = (PgConnection)value; } } *************** *** 107,128 **** public PgConnection Connection { ! get { return connection; } set { ! if (transaction != null && !transaction.IsUpdated) { throw new InvalidOperationException("The Connection property was changed while a transaction was in progress."); } ! if (connection != value) { ! if (transaction != null) { ! transaction = null; } ! InternalClose(); } ! connection = value; } } --- 111,137 ---- public PgConnection Connection { ! get { return this.connection; } set { ! if (this.connection != null && ! this.connection.DataReader != null) ! { ! throw new InvalidOperationException("There is already an open DataReader associated with this Connection which must be closed first."); ! } ! if (this.transaction != null && !this.transaction.IsUpdated) { throw new InvalidOperationException("The Connection property was changed while a transaction was in progress."); } ! if (this.connection != value) { ! if (this.transaction != null) { ! this.transaction = null; } ! this.InternalClose(); } ! this.connection = value; } } *************** *** 139,143 **** IDataParameterCollection IDbCommand.Parameters { ! get { return Parameters; } } --- 148,152 ---- IDataParameterCollection IDbCommand.Parameters { ! get { return this.Parameters; } } *************** *** 146,156 **** public PgParameterCollection Parameters { ! get { return parameters; } } IDbTransaction IDbCommand.Transaction { ! get { return Transaction; } ! set { Transaction = (PgTransaction)value; } } --- 155,165 ---- public PgParameterCollection Parameters { ! get { return this.parameters; } } IDbTransaction IDbCommand.Transaction { ! get { return this.Transaction; } ! set { this.Transaction = (PgTransaction)value; } } *************** *** 160,174 **** public PgTransaction Transaction { ! get { return transaction; } set { ! if (transaction != null && transaction.IsUpdated) ! { ! transaction = value; ! } ! else { ! transaction = value; } } } --- 169,182 ---- public PgTransaction Transaction { ! get { return this.transaction; } set { ! if (this.connection != null && ! this.connection.DataReader != null) { ! throw new InvalidOperationException("There is already an open DataReader associated with this Connection which must be closed first."); } + + this.transaction = value; } } *************** *** 177,197 **** public UpdateRowSource UpdatedRowSource { ! get { return updatedRowSource; } ! set { updatedRowSource = value; } } internal CommandBehavior CommandBehavior { ! get { return commandBehavior; } } internal PgStatement Statement { ! get { return statement; } } internal bool IsDisposed { ! get { return disposed; } } --- 185,205 ---- public UpdateRowSource UpdatedRowSource { ! get { return this.updatedRowSource; } ! set { this.updatedRowSource = value; } } internal CommandBehavior CommandBehavior { ! get { return this.commandBehavior; } } internal PgStatement Statement { ! get { return this.statement; } } internal bool IsDisposed { ! get { return this.disposed; } } *************** *** 202,213 **** public PgCommand() { ! commandText = String.Empty; ! commandType = CommandType.Text; ! commandTimeout = 30; ! updatedRowSource = UpdateRowSource.Both; ! commandBehavior = CommandBehavior.Default; ! designTimeVisible = true; ! parameters = new PgParameterCollection(); ! search = new Regex("(@([a-zA-Z-$][a-zA-Z0-9_$]*))"); } --- 210,222 ---- public PgCommand() { ! this.commandText = String.Empty; ! this.commandType = CommandType.Text; ! this.commandTimeout = 30; ! this.actualCommand = -1; ! this.updatedRowSource = UpdateRowSource.Both; ! this.commandBehavior = CommandBehavior.Default; ! this.designTimeVisible = true; ! this.parameters = new PgParameterCollection(); ! this.search = new Regex("(@([a-zA-Z-$][a-zA-Z0-9_$]*))"); } *************** *** 222,228 **** public PgCommand(string cmdText, PgConnection connection, PgTransaction transaction) : this() { ! CommandText = cmdText; ! Connection = connection; ! Transaction = transaction; } --- 231,237 ---- public PgCommand(string cmdText, PgConnection connection, PgTransaction transaction) : this() { ! this.CommandText = cmdText; ! this.Connection = connection; ! this.Transaction = transaction; } *************** *** 239,243 **** protected override void Dispose(bool disposing) { ! if (!disposed) { try --- 248,252 ---- protected override void Dispose(bool disposing) { ! if (!this.disposed) { try *************** *** 245,257 **** if (disposing) { ! if (connection.ActiveCommands != null) { ! connection.ActiveCommands.Remove(this); } // release any managed resources ! InternalClose(); ! commandText = String.Empty; } --- 254,269 ---- if (disposing) { ! if (this.connection.ActiveCommands != null) { ! this.connection.ActiveCommands.Remove(this); } // release any managed resources ! this.InternalClose(); ! this.commandText = String.Empty; ! this.actualCommand = -1; ! this.search = null; ! this.commands = null; } *************** *** 274,278 **** { PgCommand command = new PgCommand(CommandText, Connection, Transaction); ! command.CommandType = commandType; return command; --- 286,290 ---- { PgCommand command = new PgCommand(CommandText, Connection, Transaction); ! command.CommandType = this.commandType; return command; *************** *** 405,429 **** try { ! if (statement == null || statement.Status == PgStatementStatus.Initial || statement.Status == PgStatementStatus.Error) { if (commandType == CommandType.StoredProcedure) { ! CommandText = parseSPCommandText(); } // Get named parameters in CommandText ! namedParameters = search.Matches(CommandText); ! ! if (parameters.Count != 0 || namedParameters.Count != 0) ! { ! // Subst parameterNames with $position ! parseParameterNames(); ! } ! string prepareName = "PS" + getStmtName(); string portalName = "PR" + getStmtName(); ! statement = connection.DbConnection.DB.CreateStatement(prepareName, portalName, commandText); // Parse the statment --- 417,439 ---- try { ! if (statement == null || ! statement.Status == PgStatementStatus.Initial || statement.Status == PgStatementStatus.Error) { if (commandType == CommandType.StoredProcedure) { ! commands[actualCommand] = parseSPCommandText(); } // Get named parameters in CommandText ! namedParameters = search.Matches(commands[actualCommand]); ! string prepareName = "PS" + getStmtName(); string portalName = "PR" + getStmtName(); ! statement = connection.DbConnection.DB.CreateStatement( ! prepareName, ! portalName, ! parseParameterNames()); // Parse the statment *************** *** 499,505 **** internal bool NextResult() { ! /* TODO: Add implementation */ ! return false; } --- 509,541 ---- internal bool NextResult() { ! bool returnValue = false; ! if (commandBehavior != CommandBehavior.SingleResult) ! { ! this.actualCommand++; ! ! if (actualCommand >= commands.Length) ! { ! this.actualCommand--; ! } ! else ! { ! string commandText = this.commands[actualCommand]; ! ! if (commandText != null && commandText.Trim().Length > 0) ! { ! statement.Close(); ! statement.ClosePortal(); ! statement = null; ! ! InternalPrepare(); ! InternalExecute(); ! ! returnValue = true; ! } ! } ! } ! ! return returnValue; } *************** *** 569,581 **** } ! private void parseParameterNames() { if (namedParameters.Count != 0) { for (int i = 0; i < namedParameters.Count; i++) { ! commandText = search.Replace(commandText, @"$$" + (i + 1).ToString(), 1); } } } --- 605,621 ---- } ! private string parseParameterNames() { + string sql = commands[actualCommand]; + if (namedParameters.Count != 0) { for (int i = 0; i < namedParameters.Count; i++) { ! sql = search.Replace(sql, @"$$" + (i + 1).ToString(), 1); } } + + return sql; } *************** *** 641,644 **** --- 681,702 ---- { throw new InvalidOperationException ("The command text for this Command has not been set."); + } + } + + private void splitBatchCommands() + { + MatchCollection matches = Regex.Matches( + this.commandText, + "([^';]+('[^']*'))*[^';]*(?=;*)"); + + commands = new string[matches.Count/2]; + int count = 0; + for (int i = 0; i < matches.Count; i++) + { + if (matches[i].Value.Trim() != String.Empty) + { + this.commands[count] = matches[i].Value.Trim(); + count++; + } } } Index: PgDataReader.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgDataReader.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** PgDataReader.cs 22 Aug 2003 15:13:50 -0000 1.7 --- PgDataReader.cs 7 Oct 2003 09:05:01 -0000 1.8 *************** *** 144,150 **** // Set values of output parameters command.InternalSetOutputParameters(); - - // Close statement - command.InternalClose(); if ((command.CommandBehavior & CommandBehavior.CloseConnection) == CommandBehavior.CloseConnection) --- 144,147 ---- *************** *** 172,176 **** if (returnValue) { ! position = STARTPOS; } --- 169,178 ---- if (returnValue) { ! fieldCount = command.Statement.RowDescriptor.Fields.Length; ! position = STARTPOS; ! } ! else ! { ! row = null; } |