[pgsqlclient-checkins] pgsqlclient_10/PostgreSql.Data.PgSqlClient/source PgCommand.cs,1.33,1.34 PgCo
Status: Inactive
Brought to you by:
carlosga_fb
From: Carlos Guzm?n ?l. <car...@us...> - 2004-04-10 20:29:05
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12123 Modified Files: PgCommand.cs PgCommandBuilder.cs PgConnection.cs PgDbConnection.cs PgException.cs Log Message: 2004-04-10 Carlos Guzman Alvarez <car...@te...> * Started cleanup and unification of this keyword usage tasks. Index: PgCommand.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgCommand.cs,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** PgCommand.cs 1 Apr 2004 16:41:29 -0000 1.33 --- PgCommand.cs 10 Apr 2004 20:15:32 -0000 1.34 *************** *** 144,149 **** public bool DesignTimeVisible { ! get { return designTimeVisible; } ! set { designTimeVisible = value; } } --- 144,149 ---- public bool DesignTimeVisible { ! get { return this.designTimeVisible; } ! set { this.designTimeVisible = value; } } *************** *** 292,296 **** // release any unmanaged resources ! disposed = true; } finally --- 292,296 ---- // release any unmanaged resources ! this.disposed = true; } finally *************** *** 334,338 **** IDbDataParameter IDbCommand.CreateParameter() { ! return CreateParameter(); } --- 334,338 ---- IDbDataParameter IDbCommand.CreateParameter() { ! return this.CreateParameter(); } *************** *** 348,360 **** this.splitBatchCommands(false); ! if (this.connection.DbConnection.Settings.SimpleQueryMode) ! { ! this.InternalQuery(); ! } ! else ! { ! this.InternalPrepare(); ! this.InternalExecute(); ! } this.InternalSetOutputParameters(); --- 348,353 ---- this.splitBatchCommands(false); ! this.InternalPrepare(); ! this.InternalExecute(); this.InternalSetOutputParameters(); *************** *** 408,420 **** this.splitBatchCommands(false); ! if (this.connection.DbConnection.Settings.SimpleQueryMode) ! { ! this.InternalQuery(); ! } ! else ! { ! this.InternalPrepare(); ! this.InternalExecute(); ! } if (this.statement != null && this.statement.HasRows) --- 401,406 ---- this.splitBatchCommands(false); ! this.InternalPrepare(); ! this.InternalExecute(); if (this.statement != null && this.statement.HasRows) *************** *** 532,575 **** } - 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(); - } - - this.statement = this.connection.DbConnection.DB.CreateStatement( - String.Empty, - String.Empty, - this.parseParameterNames()); - - this.statement.Query(); - } - catch (PgClientException ex) - { - throw new PgException(ex.Message, ex); - } - } - internal void InternalClose() { --- 518,521 ---- *************** *** 602,606 **** this.actualCommand++; ! if (actualCommand >= commands.Length) { this.actualCommand--; --- 548,552 ---- this.actualCommand++; ! if (this.actualCommand >= this.commands.Length) { this.actualCommand--; *************** *** 618,622 **** } } ! } return returnValue; --- 564,568 ---- } } ! } return returnValue; *************** *** 626,632 **** { if (this.CommandType == CommandType.StoredProcedure && ! parameters.Count > 0) { ! IEnumerator paramEnumerator = Parameters.GetEnumerator(); int i = 0; --- 572,578 ---- { if (this.CommandType == CommandType.StoredProcedure && ! this.parameters.Count > 0) { ! IEnumerator paramEnumerator = this.parameters.GetEnumerator(); int i = 0; *************** *** 687,691 **** private string parseSPCommandText() { ! string result = CommandText; if (!commandText.Trim().ToLower().StartsWith("select ")) --- 633,637 ---- private string parseSPCommandText() { ! string result = CommandText; if (!commandText.Trim().ToLower().StartsWith("select ")) *************** *** 696,707 **** paramsText.Append(CommandText); paramsText.Append("("); ! for (int i = 0; i < parameters.Count; i++) { ! if (parameters[i].Direction == ParameterDirection.Input || ! parameters[i].Direction == ParameterDirection.InputOutput) { // Append parameter name to parameter list ! paramsText.Append(parameters[i].ParameterName); ! if (i != parameters.Count - 1) { paramsText = paramsText.Append(","); --- 642,655 ---- paramsText.Append(CommandText); paramsText.Append("("); ! ! for (int i = 0; i < this.parameters.Count; i++) { ! if (this.parameters[i].Direction == ParameterDirection.Input || ! this.parameters[i].Direction == ParameterDirection.InputOutput) { // Append parameter name to parameter list ! paramsText.Append(this.parameters[i].ParameterName); ! ! if (i != this.parameters.Count - 1) { paramsText = paramsText.Append(","); *************** *** 709,712 **** --- 657,661 ---- } } + paramsText.Append(")"); paramsText.Replace(",)", ")"); *************** *** 720,726 **** private string getStmtName() { ! return GetHashCode().ToString() + ! this.connection.GetHashCode().ToString() + ! DateTime.Now.Ticks; } --- 669,673 ---- private string getStmtName() { ! return GetHashCode().ToString() + this.connection.GetHashCode().ToString() + DateTime.Now.Ticks; } *************** *** 763,774 **** this.namedParameters.Add(g.Value); ! if (this.connection.DbConnection.Settings.SimpleQueryMode) ! { ! replace = this.parameters[matchIndex++].ConvertToPgString(); ! } ! else ! { ! replace = "$" + ((this.matchIndex++) + 1).ToString(); ! } this.matchReplaces.Add(g.Value, replace); --- 710,714 ---- this.namedParameters.Add(g.Value); ! replace = "$" + ((this.matchIndex++) + 1).ToString(); this.matchReplaces.Add(g.Value, replace); *************** *** 789,815 **** private void setParameterValues() { ! if (parameters.Count != 0) { for (int i = 0; i < this.statement.Parameters.Length; i++) { string parameterName = parameters[i].ParameterName; ! if (namedParameters.Count != 0) { try { ! parameterName = namedParameters[i].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) { this.statement.Parameters[i].Value = null; --- 729,756 ---- private void setParameterValues() { ! if (this.parameters.Count != 0) { for (int i = 0; i < this.statement.Parameters.Length; i++) { string parameterName = parameters[i].ParameterName; ! ! if (this.namedParameters.Count != 0) { try { ! parameterName = this.namedParameters[i].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 (this.parameters[index].Value == System.DBNull.Value) { this.statement.Parameters[i].Value = null; *************** *** 817,821 **** else { ! this.statement.Parameters[i].Value = parameters[index].Value; } } --- 758,762 ---- else { ! this.statement.Parameters[i].Value = this.parameters[index].Value; } } Index: PgException.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgException.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PgException.cs 9 Feb 2004 14:19:22 -0000 1.3 --- PgException.cs 10 Apr 2004 20:15:33 -0000 1.4 *************** *** 39,43 **** public PgErrorCollection Errors { ! get { return errors; } } --- 39,43 ---- public PgErrorCollection Errors { ! get { return this.errors; } } *************** *** 48,70 **** internal PgException() : base() { ! errors = new PgErrorCollection(); } internal PgException(string message) : base(message) { ! errors = new PgErrorCollection(); } internal PgException(SerializationInfo info, StreamingContext context) : base(info, context) { ! errors = new PgErrorCollection(); } ! internal PgException(string message, PgClientException ex) : base(message, ex) { ! errors = new PgErrorCollection(); ! Source = ex.Source; ! getPgExceptionErrors(ex); } --- 48,69 ---- internal PgException() : base() { ! this.errors = new PgErrorCollection(); } internal PgException(string message) : base(message) { ! this.errors = new PgErrorCollection(); } internal PgException(SerializationInfo info, StreamingContext context) : base(info, context) { ! this.errors = new PgErrorCollection(); } ! internal PgException(string message, PgClientException ex) : base(message) { ! this.errors = new PgErrorCollection(); ! this.getPgExceptionErrors(ex); } Index: PgConnection.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgConnection.cs,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** PgConnection.cs 6 Apr 2004 14:18:14 -0000 1.16 --- PgConnection.cs 10 Apr 2004 20:15:33 -0000 1.17 *************** *** 70,77 **** RefreshProperties(RefreshProperties.All), DefaultValue("")] - // Editor(typeof(DesingTime.ConnectionStringUIEditor), typeof(System.Drawing.Design.UITypeEditor))] public string ConnectionString { ! get { return connectionString; } set { --- 70,76 ---- RefreshProperties(RefreshProperties.All), DefaultValue("")] public string ConnectionString { ! get { return this.connectionString; } set { *************** *** 79,83 **** { PgDbConnection tmpConn = new PgDbConnection(value); ! connectionString = value; tmpConn = null; } --- 78,82 ---- { PgDbConnection tmpConn = new PgDbConnection(value); ! this.connectionString = value; tmpConn = null; } *************** *** 90,96 **** get { ! if (dbConnection != null) { ! return dbConnection.Settings.Timeout; } else --- 89,95 ---- get { ! if (this.dbConnection != null) { ! return this.dbConnection.Settings.Timeout; } else *************** *** 106,112 **** get { ! if (dbConnection != null) { ! return dbConnection.Settings.Database; } else --- 105,111 ---- get { ! if (this.dbConnection != null) { ! return this.dbConnection.Settings.Database; } else *************** *** 122,128 **** get { ! if (dbConnection != null) { ! return dbConnection.Settings.ServerName; } else --- 121,127 ---- get { ! if (this.dbConnection != null) { ! return this.dbConnection.Settings.ServerName; } else *************** *** 139,145 **** { int packetSize = 8192; ! if (dbConnection != null) { ! packetSize = dbConnection.Settings.PacketSize; } --- 138,144 ---- { int packetSize = 8192; ! if (this.dbConnection != null) { ! packetSize = this.dbConnection.Settings.PacketSize; } *************** *** 154,160 **** get { ! if (dbConnection != null) { ! return (string)dbConnection.DB.ParameterStatus["server_version"]; } else --- 153,159 ---- get { ! if (this.dbConnection != null) { ! return (string)this.dbConnection.DB.ParameterStatus["server_version"]; } else *************** *** 169,196 **** public ConnectionState State { ! get { return state; } } internal ArrayList ActiveCommands { ! get { return activeCommands; } } internal PgDataReader DataReader { ! get { return dataReader; } ! set { dataReader = value; } } internal PgDbConnection DbConnection { ! get { return dbConnection; } ! set { dbConnection = value; } } internal PgTransaction ActiveTransaction { ! get { return activeTransaction; } ! set { activeTransaction = value; } } --- 168,199 ---- public ConnectionState State { ! get { return this.state; } } + #endregion + + #region Internal properties + internal ArrayList ActiveCommands { ! get { return this.activeCommands; } } internal PgDataReader DataReader { ! get { return this.dataReader; } ! set { this.dataReader = value; } } internal PgDbConnection DbConnection { ! get { return this.dbConnection; } ! set { this.dbConnection = value; } } internal PgTransaction ActiveTransaction { ! get { return this.activeTransaction; } ! set { this.activeTransaction = value; } } *************** *** 201,206 **** public PgConnection() : base() { ! state = ConnectionState.Closed; ! connectionString = String.Empty; GC.SuppressFinalize(this); --- 204,209 ---- public PgConnection() : base() { ! this.state = ConnectionState.Closed; ! this.connectionString = String.Empty; GC.SuppressFinalize(this); *************** *** 225,232 **** { // release any managed resources ! Close(); ! dbConnection = null; ! connectionString = null; } --- 228,235 ---- { // release any managed resources ! this.Close(); ! this.dbConnection = null; ! this.connectionString = null; } *************** *** 238,242 **** } ! disposed = true; } } --- 241,245 ---- } ! this.disposed = true; } } *************** *** 248,252 **** object ICloneable.Clone() { ! return new PgConnection(ConnectionString); } --- 251,255 ---- object ICloneable.Clone() { ! return new PgConnection(this.connectionString); } *************** *** 257,281 **** IDbTransaction IDbConnection.BeginTransaction() { ! return BeginTransaction(); } IDbTransaction IDbConnection.BeginTransaction(IsolationLevel level) { ! return BeginTransaction(level); } public PgTransaction BeginTransaction() { ! if (state == ConnectionState.Closed) { throw new InvalidOperationException("BeginTransaction requires an open and available Connection."); } ! if (activeTransaction != null && !activeTransaction.IsUpdated) { throw new InvalidOperationException("A transaction is currently active. Parallel transactions are not supported."); } ! if (DataReader != null) { throw new InvalidOperationException("BeginTransaction requires an open and available Connection. The connection's current state is Open, Fetching."); --- 260,285 ---- IDbTransaction IDbConnection.BeginTransaction() { ! return this.BeginTransaction(); } IDbTransaction IDbConnection.BeginTransaction(IsolationLevel level) { ! return this.BeginTransaction(level); } public PgTransaction BeginTransaction() { ! if (this.state == ConnectionState.Closed) { throw new InvalidOperationException("BeginTransaction requires an open and available Connection."); } ! if (this.activeTransaction != null && ! !this.activeTransaction.IsUpdated) { throw new InvalidOperationException("A transaction is currently active. Parallel transactions are not supported."); } ! if (this.DataReader != null) { throw new InvalidOperationException("BeginTransaction requires an open and available Connection. The connection's current state is Open, Fetching."); *************** *** 284,289 **** try { ! activeTransaction = new PgTransaction(this); ! activeTransaction.InternalBeginTransaction(); } catch (PgClientException ex) --- 288,293 ---- try { ! this.activeTransaction = new PgTransaction(this); ! this.activeTransaction.InternalBeginTransaction(); } catch (PgClientException ex) *************** *** 297,306 **** public PgTransaction BeginTransaction(IsolationLevel level) { ! if (state == ConnectionState.Closed) { throw new InvalidOperationException("BeginTransaction requires an open and available Connection."); } ! if (activeTransaction != null && !activeTransaction.IsUpdated) { throw new InvalidOperationException("A transaction is currently active. Parallel transactions are not supported."); --- 301,311 ---- public PgTransaction BeginTransaction(IsolationLevel level) { ! if (this.state == ConnectionState.Closed) { throw new InvalidOperationException("BeginTransaction requires an open and available Connection."); } ! if (this.activeTransaction != null && ! !this.activeTransaction.IsUpdated) { throw new InvalidOperationException("A transaction is currently active. Parallel transactions are not supported."); *************** *** 314,319 **** try { ! activeTransaction = new PgTransaction(this, level); ! activeTransaction.InternalBeginTransaction(); } catch (PgClientException ex) --- 319,324 ---- try { ! this.activeTransaction = new PgTransaction(this, level); ! this.activeTransaction.InternalBeginTransaction(); } catch (PgClientException ex) *************** *** 327,331 **** public void ChangeDatabase(string db) { ! if (state == ConnectionState.Closed) { throw new InvalidOperationException("ChangeDatabase requires an open and available Connection."); --- 332,336 ---- public void ChangeDatabase(string db) { ! if (this.state == ConnectionState.Closed) { throw new InvalidOperationException("ChangeDatabase requires an open and available Connection."); *************** *** 364,368 **** public void Open() { ! if (state != ConnectionState.Closed) { throw new InvalidOperationException("Connection already Open."); --- 369,373 ---- public void Open() { ! if (this.state != ConnectionState.Closed) { throw new InvalidOperationException("Connection already Open."); *************** *** 371,377 **** try { ! state = ConnectionState.Connecting; ! dbConnection = new PgDbConnection(connectionString); // Add handler for Ssl connections --- 376,382 ---- try { ! this.state = ConnectionState.Connecting; ! this.dbConnection = new PgDbConnection(this.connectionString); // Add handler for Ssl connections *************** *** 379,403 **** // Open connection ! if (dbConnection.Settings.Pooling) { ! dbConnection = PgConnectionPool.GetConnection( ! connectionString, ! dbConnection); } else { ! dbConnection.Pooled = false; ! dbConnection.Connect(); } // Set connection state to Open ! state = ConnectionState.Open; ! if (StateChange != null) { ! StateChange(this, new StateChangeEventArgs(ConnectionState.Closed, state)); } // Initialize active commands list ! activeCommands = new ArrayList(); // Add Info message event handler --- 384,408 ---- // Open connection ! if (this.dbConnection.Settings.Pooling) { ! this.dbConnection = PgConnectionPool.GetConnection( ! this.connectionString, ! this.dbConnection); } else { ! this.dbConnection.Pooled = false; ! this.dbConnection.Connect(); } // Set connection state to Open ! this.state = ConnectionState.Open; ! if (this.StateChange != null) { ! this.StateChange(this, new StateChangeEventArgs(ConnectionState.Closed, state)); } // Initialize active commands list ! this.activeCommands = new ArrayList(); // Add Info message event handler *************** *** 422,426 **** try { ! lock (dbConnection) { // Close DataReader --- 427,431 ---- try { ! lock (this.dbConnection) { // Close DataReader *************** *** 460,464 **** // Close connection permanently or send it // back to the pool ! if (dbConnection.Pooled) { PgConnectionPool.FreeConnection(this.dbConnection); --- 465,469 ---- // Close connection permanently or send it // back to the pool ! if (this.dbConnection.Pooled) { PgConnectionPool.FreeConnection(this.dbConnection); *************** *** 471,478 **** // Update state ! state = ConnectionState.Closed; // Raise StateChange event ! if (StateChange != null) { this.StateChange( --- 476,483 ---- // Update state ! this.state = ConnectionState.Closed; // Raise StateChange event ! if (this.StateChange != null) { this.StateChange( *************** *** 490,494 **** IDbCommand IDbConnection.CreateCommand() { ! return CreateCommand(); } --- 495,499 ---- IDbCommand IDbConnection.CreateCommand() { ! return this.CreateCommand(); } *************** *** 496,500 **** { PgCommand command = new PgCommand(); - command.Connection = this; --- 501,504 ---- *************** *** 504,514 **** private void DisposeActiveCommands() { ! if (activeCommands != null) { ! if (activeCommands.Count > 0) { ! PgCommand[] commands = new PgCommand[activeCommands.Count]; ! activeCommands.CopyTo(0, commands, 0, commands.Length); foreach (PgCommand command in commands) { --- 508,518 ---- private void DisposeActiveCommands() { ! if (this.activeCommands != null) { ! if (this.activeCommands.Count > 0) { ! PgCommand[] commands = new PgCommand[this.activeCommands.Count]; ! this.activeCommands.CopyTo(0, commands, 0, commands.Length); foreach (PgCommand command in commands) { *************** *** 526,530 **** public DataTable GetDbSchemaTable(PgDbSchemaType schema, object[] restrictions) { ! if (DataReader != null) { throw new InvalidOperationException("GetDbSchemaTable requires an open and available Connection. The connection's current state is Open, Fetching."); --- 530,534 ---- public DataTable GetDbSchemaTable(PgDbSchemaType schema, object[] restrictions) { ! if (this.DataReader != null) { throw new InvalidOperationException("GetDbSchemaTable requires an open and available Connection. The connection's current state is Open, Fetching."); Index: PgDbConnection.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgDbConnection.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** PgDbConnection.cs 8 Mar 2004 15:12:26 -0000 1.8 --- PgDbConnection.cs 10 Apr 2004 20:15:33 -0000 1.9 *************** *** 179,186 **** this.settings.SSL = Boolean.Parse(element.Groups[2].Value.Trim()); break; - - case "simple query mode": - this.settings.SimpleQueryMode = Boolean.Parse(element.Groups[2].Value.Trim()); - break; } } --- 179,182 ---- Index: PgCommandBuilder.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgCommandBuilder.cs,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** PgCommandBuilder.cs 1 Apr 2004 16:41:29 -0000 1.20 --- PgCommandBuilder.cs 10 Apr 2004 20:15:33 -0000 1.21 *************** *** 136,140 **** this.sqlUpdate = "UPDATE {0} SET {1} WHERE ( {2} )"; this.sqlDelete = "DELETE FROM {0} WHERE ( {1} )"; ! this.whereClausule1 = "(({0} IS NULL AND ${1} = NULL) OR ({0} = ${2}))"; // this.whereClausule2 = "({0} = ${1})"; // this.setClausule = "{0} = ${1}"; --- 136,140 ---- this.sqlUpdate = "UPDATE {0} SET {1} WHERE ( {2} )"; this.sqlDelete = "DELETE FROM {0} WHERE ( {1} )"; ! this.whereClausule1 = "(({0} IS NULL AND ${1} = NULL) OR ({0} = ${2}))"; // this.whereClausule2 = "({0} = ${1})"; // this.setClausule = "{0} = ${1}"; |