Thread: [pgsqlclient-checkins] pgsqlclient_10/PostgreSql.Data.PgSqlClient/source PgCommand.cs,1.27,1.28 PgDb
Status: Inactive
Brought to you by:
carlosga_fb
From: <car...@us...> - 2004-02-12 19:55:51
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21087 Modified Files: PgCommand.cs PgDbConnection.cs Log Message: Rework simple query protocol implementation Index: PgCommand.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgCommand.cs,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** PgCommand.cs 9 Feb 2004 21:52:04 -0000 1.27 --- PgCommand.cs 12 Feb 2004 19:50:41 -0000 1.28 *************** *** 28,32 **** namespace PostgreSql.Data.PgSqlClient ! { [ToolboxItem(true), ToolboxBitmap(typeof(PgCommand), "Resources.ToolBox.PgCommand.bmp")] --- 28,32 ---- namespace PostgreSql.Data.PgSqlClient ! { [ToolboxItem(true), ToolboxBitmap(typeof(PgCommand), "Resources.ToolBox.PgCommand.bmp")] *************** *** 51,56 **** private int matchIndex; private Hashtable matchReplaces; - private bool isPrepared; - private PgStatement statement; --- 51,54 ---- *************** *** 66,70 **** get { return this.commandText; } set ! { if (this.statement != null && this.commandText != value && this.commandText != null && this.commandText.Length != 0) --- 64,68 ---- get { return this.commandText; } set ! { if (this.statement != null && this.commandText != value && this.commandText != null && this.commandText.Length != 0) *************** *** 75,79 **** this.commandText = value; this.actualCommand = 0; ! this.commands = null; } } --- 73,77 ---- this.commandText = value; this.actualCommand = 0; ! this.commands = null; } } *************** *** 283,291 **** #endregion ! #region ICloneable MEthods object ICloneable.Clone() { ! PgCommand command = new PgCommand(CommandText, Connection, Transaction); command.CommandType = this.commandType; --- 281,293 ---- #endregion ! #region ICloneable Methods object ICloneable.Clone() { ! PgCommand command = new PgCommand( ! this.commandText, ! this.connection, ! this.transaction); ! command.CommandType = this.commandType; *************** *** 298,302 **** public void Cancel() ! { throw new NotSupportedException(); } --- 300,304 ---- public void Cancel() ! { throw new NotSupportedException(); } *************** *** 318,334 **** this.splitBatchCommands(false); ! #if (SIMPLE_PROTOCOL) ! if (this.isPrepared) { ! this.InternalExecute(); } else { ! this.InternalQuery(); } - #else - this.InternalPrepare(); - this.InternalExecute(); - #endif this.InternalSetOutputParameters(); --- 320,332 ---- this.splitBatchCommands(false); ! if (this.connection.DbConnection.Settings.SimpleQueryMode) { ! this.InternalQuery(); } else { ! this.InternalPrepare(); ! this.InternalExecute(); } this.InternalSetOutputParameters(); *************** *** 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,362 ---- this.checkCommand(); ! commandBehavior = behavior; this.splitBatchCommands(true); this.InternalPrepare(); if ((commandBehavior & System.Data.CommandBehavior.SequentialAccess) == System.Data.CommandBehavior.SequentialAccess || *************** *** 370,385 **** commandBehavior == System.Data.CommandBehavior.Default) { - #if (SIMPLE_PROTOCOL) - if (this.isPrepared) - { - this.InternalExecute(); - } - else - { - this.InternalQuery(); - } - #else this.InternalExecute(); - #endif } --- 366,370 ---- *************** *** 395,413 **** this.splitBatchCommands(false); ! #if (SIMPLE_PROTOCOL) ! if (this.isPrepared) { ! this.InternalExecute(); } else { ! this.InternalQuery(); } - #else - this.InternalPrepare(); - this.InternalExecute(); - #endif ! if (this.statement.HasRows) { returnValue = ((object[])this.statement.Rows[0])[0]; --- 380,394 ---- this.splitBatchCommands(false); ! if (this.connection.DbConnection.Settings.SimpleQueryMode) { ! this.InternalQuery(); } else { ! this.InternalPrepare(); ! this.InternalExecute(); } ! if (this.statement != null && this.statement.HasRows) { returnValue = ((object[])this.statement.Rows[0])[0]; *************** *** 422,427 **** this.splitBatchCommands(false); - this.InternalPrepare(); } --- 403,408 ---- this.splitBatchCommands(false); this.InternalPrepare(); + this.connection.ActiveCommands.Add(this); } *************** *** 459,465 **** internal void InternalPrepare() { ! if (this.commands == null) { ! this.splitBatchCommands(false); } --- 440,446 ---- internal void InternalPrepare() { ! if (commands == null) { ! splitBatchCommands(false); } *************** *** 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(); --- 451,461 ---- 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(); *************** *** 485,489 **** prepareName, portalName, ! this.parseParameterNames()); // Parse statement --- 465,469 ---- prepareName, portalName, ! parseParameterNames()); // Parse statement *************** *** 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 --- 472,475 ---- *************** *** 512,517 **** throw new PgException(ex.Message, ex); } - - this.isPrepared = true; } --- 483,486 ---- *************** *** 520,527 **** try { ! if (this.parameters.Count != 0) { // Set parameter values ! this.setParameterValues(); } --- 489,496 ---- try { ! if (parameters.Count != 0) { // Set parameter values ! setParameterValues(); } *************** *** 580,587 **** throw new PgException(ex.Message, ex); } - finally - { - this.isPrepared = false; - } } --- 549,552 ---- *************** *** 601,606 **** } } - - this.isPrepared = false; } --- 566,569 ---- *************** *** 609,613 **** bool returnValue = false; ! if ((this.CommandBehavior & CommandBehavior.SingleResult) != CommandBehavior.SingleResult) { this.actualCommand++; --- 572,576 ---- bool returnValue = false; ! if (commandBehavior != CommandBehavior.SingleResult) { this.actualCommand++; *************** *** 627,636 **** this.statement = null; - #if (SIMPLE_PROTOCOL) - this.InternalQuery(); - #else this.InternalPrepare(); this.InternalExecute(); ! #endif returnValue = true; } --- 590,596 ---- this.statement = null; this.InternalPrepare(); this.InternalExecute(); ! returnValue = true; } *************** *** 738,743 **** private string getStmtName() { ! return GetHashCode().ToString() + ! this.connection.GetHashCode().ToString() + DateTime.Now.Ticks; } --- 698,703 ---- private string getStmtName() { ! return GetHashCode().ToString() + ! this.connection.GetHashCode().ToString() + DateTime.Now.Ticks; } *************** *** 766,779 **** if (!this.matchReplaces.ContainsKey(match.Value)) { ! #if (SIMPLE_PROTOCOL) this.matchReplaces.Add( match.Value, this.parameters[matchIndex++].ConvertToPgString()); ! #else ! this.matchReplaces.Add( ! match.Value, ! "$" + ((matchIndex++) + 1).ToString()); ! #endif } return this.matchReplaces[match.Value].ToString(); } --- 726,743 ---- if (!this.matchReplaces.ContainsKey(match.Value)) { ! if (this.connection.DbConnection.Settings.SimpleQueryMode) ! { this.matchReplaces.Add( match.Value, this.parameters[matchIndex++].ConvertToPgString()); ! } ! else ! { ! this.matchReplaces.Add( ! match.Value, ! "$" + ((matchIndex++) + 1).ToString()); ! } } + return this.matchReplaces[match.Value].ToString(); } *************** *** 785,805 **** 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) --- 749,769 ---- 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) *************** *** 809,813 **** else { ! this.statement.Parameters[i].Value = this.parameters[index].Value; } } --- 773,777 ---- else { ! this.statement.Parameters[i].Value = parameters[index].Value; } } Index: PgDbConnection.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgDbConnection.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** PgDbConnection.cs 9 Feb 2004 14:19:22 -0000 1.6 --- PgDbConnection.cs 12 Feb 2004 19:50:41 -0000 1.7 *************** *** 178,181 **** --- 178,185 ---- settings.SSL = Boolean.Parse(element.Groups[2].Value.Trim()); break; + + case "simple query mode": + settings.SimpleQueryMode = Boolean.Parse(element.Groups[2].Value.Trim()); + break; } } |