Thread: [pgsqlclient-checkins] pgsqlclient_10/PostgreSql.Data.PgSqlClient/source PgCommand.cs,1.24,1.25
Status: Inactive
Brought to you by:
carlosga_fb
From: <car...@us...> - 2004-01-03 15:41:41
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source In directory sc8-pr-cvs1:/tmp/cvs-serv25678 Modified Files: PgCommand.cs Log Message: 2004-01-03 Carlos Guzmán Álvarez <car...@te...> * source/PgCommand.cs: - Added an initial implementation of the simple query protocol that will be available using an SIMPLE_PROTOCOL define at build time. Index: PgCommand.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgCommand.cs,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** PgCommand.cs 18 Dec 2003 10:27:32 -0000 1.24 --- PgCommand.cs 3 Jan 2004 15:41:38 -0000 1.25 *************** *** 51,54 **** --- 51,55 ---- private int matchIndex; private Hashtable matchReplaces; + private bool isPrepared; private PgStatement statement; *************** *** 74,78 **** this.commandText = value; this.actualCommand = 0; ! this.commands = null; } } --- 75,79 ---- this.commandText = value; this.actualCommand = 0; ! this.commands = null; } } *************** *** 297,301 **** public void Cancel() ! { throw new NotSupportedException(); } --- 298,302 ---- public void Cancel() ! { throw new NotSupportedException(); } *************** *** 316,323 **** this.splitBatchCommands(false); this.InternalPrepare(); this.InternalExecute(); ! InternalSetOutputParameters(); return this.statement.RecordsAffected; --- 317,336 ---- this.splitBatchCommands(false); + + #if (SIMPLE_PROTOCOL) + if (this.isPrepared) + { + this.InternalExecute(); + } + else + { + this.InternalQuery(); + } + #else this.InternalPrepare(); this.InternalExecute(); + #endif ! this.InternalSetOutputParameters(); return this.statement.RecordsAffected; *************** *** 343,350 **** this.checkCommand(); ! commandBehavior = behavior; this.splitBatchCommands(true); this.InternalPrepare(); if ((commandBehavior & System.Data.CommandBehavior.SequentialAccess) == System.Data.CommandBehavior.SequentialAccess || --- 356,366 ---- this.checkCommand(); ! this.commandBehavior = behavior; this.splitBatchCommands(true); + + #if (!SIMPLE_PROTOCOL) this.InternalPrepare(); + #endif if ((commandBehavior & System.Data.CommandBehavior.SequentialAccess) == System.Data.CommandBehavior.SequentialAccess || *************** *** 354,358 **** --- 370,385 ---- commandBehavior == System.Data.CommandBehavior.Default) { + #if (SIMPLE_PROTOCOL) + if (this.isPrepared) + { + this.InternalExecute(); + } + else + { + this.InternalQuery(); + } + #else this.InternalExecute(); + #endif } *************** *** 367,372 **** this.splitBatchCommands(false); ! this.InternalPrepare(); this.InternalExecute(); if (this.statement.HasRows) --- 394,411 ---- this.splitBatchCommands(false); ! ! #if (SIMPLE_PROTOCOL) ! if (this.isPrepared) ! { ! this.InternalExecute(); ! } ! else ! { ! this.InternalQuery(); ! } ! #else ! this.InternalPrepare(); this.InternalExecute(); + #endif if (this.statement.HasRows) *************** *** 383,388 **** this.splitBatchCommands(false); this.InternalPrepare(); - this.connection.ActiveCommands.Add(this); } --- 422,427 ---- this.splitBatchCommands(false); + this.InternalPrepare(); } *************** *** 420,426 **** internal void InternalPrepare() { ! if (commands == null) { ! splitBatchCommands(false); } --- 459,465 ---- internal void InternalPrepare() { ! if (this.commands == null) { ! this.splitBatchCommands(false); } *************** *** 431,441 **** this.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(); --- 470,481 ---- this.statement.Status == PgStatementStatus.Error) { ! if (this.commandType == CommandType.StoredProcedure) { ! this.commands[actualCommand] = this.parseSPCommandText(); } // Get named parameters in CommandText ! this.namedParameters = this.search.Matches( ! this.commands[actualCommand]); string prepareName = "PS" + getStmtName(); *************** *** 445,449 **** prepareName, portalName, ! parseParameterNames()); // Parse statement --- 485,489 ---- prepareName, portalName, ! this.parseParameterNames()); // Parse statement *************** *** 452,455 **** --- 492,504 ---- // Describe statement this.statement.Describe(); + + // Add this command to the active command list + if (this.connection.ActiveCommands != null) + { + if (!this.connection.ActiveCommands.Contains(this)) + { + this.connection.ActiveCommands.Add(this); + } + } } else *************** *** 463,466 **** --- 512,517 ---- throw new PgException(ex.Message, ex); } + + this.isPrepared = true; } *************** *** 469,476 **** try { ! if (parameters.Count != 0) { // Set parameter values ! setParameterValues(); } --- 520,527 ---- try { ! if (this.parameters.Count != 0) { // Set parameter values ! this.setParameterValues(); } *************** *** 489,495 **** internal void InternalQuery() { try { ! this.statement = this.connection.DbConnection.DB.CreateStatement(commandText); this.statement.Query(); } --- 540,577 ---- internal void InternalQuery() { + if (this.commands == null) + { + this.splitBatchCommands(false); + } + + // Add this command to the active command list + if (this.connection.ActiveCommands != null) + { + if (!this.connection.ActiveCommands.Contains(this)) + { + this.connection.ActiveCommands.Add(this); + } + } + try { ! string commandText = String.Empty; ! ! commandText = null; ! ! if (this.commandType == CommandType.StoredProcedure) ! { ! this.commands[actualCommand] = this.parseSPCommandText(); ! } ! ! // Get named parameters in CommandText ! this.namedParameters = this.search.Matches( ! this.commands[this.actualCommand]); ! ! this.statement = this.connection.DbConnection.DB.CreateStatement( ! String.Empty, ! String.Empty, ! this.parseParameterNames()); ! this.statement.Query(); } *************** *** 498,501 **** --- 580,587 ---- throw new PgException(ex.Message, ex); } + finally + { + this.isPrepared = false; + } } *************** *** 515,518 **** --- 601,606 ---- } } + + this.isPrepared = false; } *************** *** 521,525 **** bool returnValue = false; ! if (commandBehavior != CommandBehavior.SingleResult) { this.actualCommand++; --- 609,613 ---- bool returnValue = false; ! if ((this.CommandBehavior & CommandBehavior.SingleResult) != CommandBehavior.SingleResult) { this.actualCommand++; *************** *** 539,545 **** this.statement = null; this.InternalPrepare(); this.InternalExecute(); ! returnValue = true; } --- 627,636 ---- this.statement = null; + #if (SIMPLE_PROTOCOL) + this.InternalQuery(); + #else this.InternalPrepare(); this.InternalExecute(); ! #endif returnValue = true; } *************** *** 647,652 **** private string getStmtName() { ! return GetHashCode().ToString() + ! this.connection.GetHashCode().ToString() + DateTime.Now.Ticks; } --- 738,743 ---- private string getStmtName() { ! return GetHashCode().ToString() + ! this.connection.GetHashCode().ToString() + DateTime.Now.Ticks; } *************** *** 673,682 **** private string matchEvaluator(Match match) { ! if (!matchReplaces.ContainsKey(match.Value)) { ! matchReplaces.Add(match.Value, "$" + ((matchIndex++) + 1).ToString()); } ! ! return matchReplaces[match.Value].ToString(); } --- 764,783 ---- private string matchEvaluator(Match match) { ! if (!this.matchReplaces.ContainsKey(match.Value)) { ! if (this.isPrepared) ! { ! this.matchReplaces.Add( ! match.Value, ! "$" + ((matchIndex++) + 1).ToString()); ! } ! else ! { ! this.matchReplaces.Add( ! match.Value, ! this.parameters[matchIndex++].ConvertToPgString()); ! } } ! return this.matchReplaces[match.Value].ToString(); } *************** *** 687,707 **** for (int i = 0; i < this.statement.Parameters.Length; i++) { ! string parameterName = parameters[i].ParameterName; if (namedParameters.Count != 0) { try { ! parameterName = namedParameters[i].Value.Trim(); } catch { ! parameterName = parameters[i].ParameterName; } } ! int index = parameters.IndexOf(parameterName); ! if (parameters[index].Direction == ParameterDirection.Input || ! parameters[index].Direction == ParameterDirection.InputOutput) { if (parameters[index].Value == System.DBNull.Value) --- 788,808 ---- for (int i = 0; i < this.statement.Parameters.Length; i++) { ! string parameterName = this.parameters[i].ParameterName; if (namedParameters.Count != 0) { try { ! parameterName = this.namedParameters[i].Value.Trim(); } catch { ! parameterName = this.parameters[i].ParameterName; } } ! int index = this.parameters.IndexOf(parameterName); ! if (this.parameters[index].Direction == ParameterDirection.Input || ! this.parameters[index].Direction == ParameterDirection.InputOutput) { if (parameters[index].Value == System.DBNull.Value) *************** *** 711,715 **** else { ! this.statement.Parameters[i].Value = parameters[index].Value; } } --- 812,816 ---- else { ! this.statement.Parameters[i].Value = this.parameters[index].Value; } } |