Thread: [pgsqlclient-checkins] SF.net SVN: pgsqlclient: [44] trunk/pgsqlclient/source/PostgreSql/Data/Postgr
Status: Inactive
Brought to you by:
carlosga_fb
From: <car...@us...> - 2006-03-22 12:09:24
|
Revision: 44 Author: carlosga_fb Date: 2006-03-22 04:09:12 -0800 (Wed, 22 Mar 2006) ViewCVS: http://svn.sourceforge.net/pgsqlclient/?rev=44&view=rev Log Message: ----------- Bug fixes Modified Paths: -------------- trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgConnection.cs trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgDataReader.cs Modified: trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgConnection.cs =================================================================== --- trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgConnection.cs 2006-03-22 12:08:42 UTC (rev 43) +++ trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgConnection.cs 2006-03-22 12:09:12 UTC (rev 44) @@ -305,6 +305,10 @@ public override void Open() { + if (this.connectionString == null || this.connectionString.Length == 0) + { + throw new InvalidOperationException("Connection String is not initialized."); + } if (this.state != ConnectionState.Closed) { throw new InvalidOperationException("Connection already Open."); @@ -356,52 +360,54 @@ { if (this.state == ConnectionState.Open) { - try - { - lock (this.connectionInternal) - { + try + { + lock (this.connectionInternal) + { PgDatabase database = this.connectionInternal.Database; - // Remove info message callback - this.connectionInternal.Database.InfoMessage = null; + // Remove info message callback + this.connectionInternal.Database.InfoMessage = null; - // Remove notification callback - this.connectionInternal.Database.Notification = null; + // Remove notification callback + this.connectionInternal.Database.Notification = null; // Remove SSL callback handlers - this.connectionInternal.Database.UserCertificateValidationCallback = null; - this.connectionInternal.Database.UserCertificateSelectionCallback = null; + this.connectionInternal.Database.UserCertificateValidationCallback = null; + this.connectionInternal.Database.UserCertificateSelectionCallback = null; - // Dispose Active commands - this.connectionInternal.ClosePreparedCommands(); + // Dispose Active commands + this.connectionInternal.ClosePreparedCommands(); - // Rollback active transaction - this.connectionInternal.DisposeActiveTransaction(); + // Rollback active transaction + this.connectionInternal.DisposeActiveTransaction(); - // Close connection permanently or send it back to the pool - if (this.connectionInternal.Pooled) - { - PgConnectionPool.FreeConnection(this.connectionInternal); - } - else - { - this.connectionInternal.Disconnect(); - } - } + // Close connection permanently or send it back to the pool + if (this.connectionInternal.Pooled) + { + PgConnectionPool.FreeConnection(this.connectionInternal); + } + else + { + this.connectionInternal.Disconnect(); + } + } + } + catch + { + } + finally + { - // Update state - this.state = ConnectionState.Closed; + // Update state + this.state = ConnectionState.Closed; - // Raise StateChange event - if (this.StateChange != null) - { - this.StateChange(this, new StateChangeEventArgs(ConnectionState.Open, this.state)); - } - } - catch (PgClientException ex) - { - throw new PgException(ex.Message, ex); - } + // Raise StateChange event + if (this.StateChange != null) + { + this.StateChange(this, new StateChangeEventArgs(ConnectionState.Open, this.state)); + } + } } } Modified: trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgDataReader.cs =================================================================== --- trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgDataReader.cs 2006-03-22 12:08:42 UTC (rev 43) +++ trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgDataReader.cs 2006-03-22 12:09:12 UTC (rev 44) @@ -221,12 +221,10 @@ PgCommand columnsCmd = new PgCommand(this.GetColumnsSql(), this.connection); columnsCmd.Parameters.Add("@OidNumber", PgDbType.Int4); columnsCmd.Parameters.Add("@OidTable", PgDbType.Int4); - columnsCmd.InternalPrepare(); - + PgCommand primaryKeyCmd = new PgCommand(this.GetPrimaryKeysSql(), this.connection); primaryKeyCmd.Parameters.Add("@OidTable", PgDbType.Int4); - primaryKeyCmd.InternalPrepare(); - + for (int i = 0; i < command.Statement.RowDescriptor.Fields.Length; i++) { object[] columnInfo = null; @@ -238,7 +236,10 @@ primaryKeyCmd.Parameters[0].Value = command.Statement.RowDescriptor.Fields[i].OidTable; - columnsCmd.InternalExecute(); + columnsCmd.InternalPrepare(); // First time it will prepare the command, next times it will close the open portal + columnsCmd.InternalExecute(); + + primaryKeyCmd.InternalPrepare(); // First time it will prepare the command, next times it will close the open portal primaryKeyCmd.InternalExecute(); // Get Column Information This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2006-03-28 12:14:01
|
Revision: 61 Author: carlosga_fb Date: 2006-03-28 04:13:51 -0800 (Tue, 28 Mar 2006) ViewCVS: http://svn.sourceforge.net/pgsqlclient/?rev=61&view=rev Log Message: ----------- ?\194?\183 More bug fixes Modified Paths: -------------- trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgCommand.cs trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgDataReader.cs Modified: trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgCommand.cs =================================================================== --- trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgCommand.cs 2006-03-28 11:24:30 UTC (rev 60) +++ trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgCommand.cs 2006-03-28 12:13:51 UTC (rev 61) @@ -45,8 +45,6 @@ private int commandTimeout; private bool designTimeVisible; private StringCollection namedParameters; - private int matchIndex; - private Hashtable matchReplaces; private PgStatement statement; private PgDataReader activeDataReader; @@ -219,9 +217,26 @@ #endregion - #region \xB7 Constructors \xB7 + #region \xB7 Private Properties \xB7 - public PgCommand() + public StringCollection NamedParameters + { + get + { + if (this.namedParameters == null) + { + this.namedParameters = new StringCollection(); + } + + return this.namedParameters; + } + } + + #endregion + + #region \xB7 Constructors \xB7 + + public PgCommand() : base() { this.commandText = String.Empty; @@ -230,8 +245,6 @@ this.updatedRowSource = UpdateRowSource.Both; this.commandBehavior = CommandBehavior.Default; this.designTimeVisible = true; - this.namedParameters = new StringCollection(); - this.matchReplaces = new Hashtable(); } public PgCommand(string cmdText) @@ -276,11 +289,11 @@ this.commandText = null; - this.matchReplaces.Clear(); - this.matchReplaces = null; - - this.namedParameters.Clear(); - this.namedParameters = null; + if (this.namedParameters != null) + { + this.namedParameters.Clear(); + this.namedParameters = null; + } } // release any unmanaged resources @@ -432,7 +445,7 @@ string prepareName = "PS" + this.GetStmtName(); string portalName = "PR" + this.GetStmtName(); - this.statement = conn.Database.CreateStatement(prepareName, portalName, this.ParseParameterNames(sql)); + this.statement = conn.Database.CreateStatement(prepareName, portalName, this.ParseNamedParameters(sql)); // Parse statement this.statement.Parse(); @@ -598,61 +611,66 @@ return GetHashCode().ToString() + this.connection.GetHashCode().ToString() + DateTime.Now.Ticks; } - private string ParseParameterNames(string commandText) - { - string sql = commandText; + private string ParseNamedParameters(string sql) + { + StringBuilder builder = new StringBuilder(); + StringBuilder paramBuilder = new StringBuilder(); + bool inCommas = false; + bool inParam = false; + int paramIndex = 0; - this.namedParameters.Clear(); + this.NamedParameters.Clear(); - if (commandText.IndexOf("@") != -1) - { - this.matchReplaces.Clear(); - this.matchIndex = 0; + if (sql.IndexOf('@') == -1) + { + return sql; + } - string pattern = @"(('[^']*?\@[^']*')*[^'@]*?)*(?<param>@\w+)*([^'@]*?('[^']*?\@*[^']*'))*"; + for (int i = 0; i < sql.Length; i++) + { + char sym = sql[i]; - Regex r = new Regex(pattern, RegexOptions.ExplicitCapture); + if (inParam) + { + if (Char.IsLetterOrDigit(sym) || sym == '_' || sym == '$') + { + paramBuilder.Append(sym); + } + else + { + this.NamedParameters.Add(paramBuilder.ToString()); + paramBuilder.Length = 0; + builder.AppendFormat("${0}", ++paramIndex); + builder.Append(sym); + inParam = false; + } + } + else + { + if (sym == '\'') + { + inCommas = !inCommas; + } + else if (!inCommas && sym == '@') + { + inParam = true; + paramBuilder.Append(sym); + continue; + } - MatchEvaluator me = new MatchEvaluator(NamedParamsMatchEvaluator); + builder.Append(sym); + } + } - sql = r.Replace(sql, me); + if (inParam) + { + this.NamedParameters.Add(paramBuilder.ToString()); + builder.AppendFormat("${0}", ++paramIndex); + } - this.matchReplaces.Clear(); - } + return builder.ToString(); + } - return sql; - } - - private string NamedParamsMatchEvaluator(Match match) - { - string input = match.Value; - string replace = String.Empty; - - if (match.Groups["param"].Success) - { - Group g = match.Groups["param"]; - - if (!this.matchReplaces.ContainsKey(g.Value)) - { - this.namedParameters.Add(g.Value); - - replace = "$$" + ((this.matchIndex++) + 1).ToString(); - - this.matchReplaces.Add(g.Value, replace); - } - else - { - replace = this.matchReplaces[g.Value].ToString(); - } - - return Regex.Replace(input, g.Value, replace); - } - else - { - return match.Value; - } - } - private void SetParameterValues() { if (this.Parameters.Count != 0) @@ -661,9 +679,9 @@ { int index = i; - if (this.namedParameters.Count > 0) + if (this.NamedParameters.Count > 0) { - index = this.Parameters.IndexOf(this.namedParameters[i]); + index = this.Parameters.IndexOf(this.NamedParameters[i]); } if (this.Parameters[index].Direction == ParameterDirection.Input || Modified: trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgDataReader.cs =================================================================== --- trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgDataReader.cs 2006-03-28 11:24:30 UTC (rev 60) +++ trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgDataReader.cs 2006-03-28 12:13:51 UTC (rev 61) @@ -258,8 +258,8 @@ // Add row information DataRow schemaRow = schemaTable.NewRow(); - schemaRow["ColumnName"] = Convert.ToString(columnInfo[2]); - schemaRow["ColumnOrdinal"] = Convert.ToInt32(columnInfo[5]); + schemaRow["ColumnName"] = this.GetName(i); + schemaRow["ColumnOrdinal"] = (i + 1); schemaRow["ColumnSize"] = this.GetSize(i); if (this.IsNumeric(i)) { @@ -287,7 +287,7 @@ schemaRow["BaseColumnName"] = columnInfo[2].ToString(); schemaRow["IsReadOnly"] = (bool)columnInfo[7]; schemaRow["IsAutoIncrement"] = (bool)columnInfo[7]; - schemaRow["IsKey"] = this.IsPrimaryKey(pKeyInfo, (int)schemaRow["ColumnOrdinal"]); + schemaRow["IsKey"] = this.IsPrimaryKey(pKeyInfo, Convert.ToInt32(columnInfo[5])); schemaRow["AllowDBNull"] = ((bool)columnInfo[6]) ? false : true; } else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2006-03-28 12:34:40
|
Revision: 63 Author: carlosga_fb Date: 2006-03-28 04:34:28 -0800 (Tue, 28 Mar 2006) ViewCVS: http://svn.sourceforge.net/pgsqlclient/?rev=63&view=rev Log Message: ----------- ?\194?\183 Changes for correct handling of SSL callbacks Modified Paths: -------------- trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgConnection.cs trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgConnectionInternal.cs trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgConnectionPool.cs Modified: trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgConnection.cs =================================================================== --- trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgConnection.cs 2006-03-28 12:14:23 UTC (rev 62) +++ trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgConnection.cs 2006-03-28 12:34:28 UTC (rev 63) @@ -326,6 +326,8 @@ else { this.connectionInternal = new PgConnectionInternal(this); + + this.SslSetup(); this.connectionInternal.OwningConnection = this; this.connectionInternal.Pooled = false; @@ -344,10 +346,6 @@ // Add notification event handler this.connectionInternal.Database.Notification = new NotificationCallback(this.OnNotification); - - // Add SSL callback handlers - this.connectionInternal.Database.UserCertificateValidationCallback = new RemoteCertificateValidationCallback(OnUserCertificateValidation); - this.connectionInternal.Database.UserCertificateSelectionCallback = new LocalCertificateSelectionCallback(OnUserCertificateSelection); } catch (PgClientException ex) { @@ -445,9 +443,20 @@ #endregion - #region \xB7 Event Handlers Methods \xB7 + #region \xB7 SSL Setup \xB7 - private void OnInfoMessage(PgClientException ex) + internal void SslSetup() + { + // Add SSL callback handlers + this.connectionInternal.Database.UserCertificateValidationCallback = new RemoteCertificateValidationCallback(OnUserCertificateValidation); + this.connectionInternal.Database.UserCertificateSelectionCallback = new LocalCertificateSelectionCallback(OnUserCertificateSelection); + } + + #endregion + + #region \xB7 Event Handlers Methods \xB7 + + private void OnInfoMessage(PgClientException ex) { if (this.InfoMessage != null) { Modified: trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgConnectionInternal.cs =================================================================== --- trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgConnectionInternal.cs 2006-03-28 12:14:23 UTC (rev 62) +++ trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgConnectionInternal.cs 2006-03-28 12:34:28 UTC (rev 63) @@ -101,6 +101,7 @@ { this.owningConnection = owningConnection; this.options = new PgConnectionOptions(owningConnection.ConnectionString); + this.database = new PgDatabase(this.options); this.created = 0; this.pooled = true; } @@ -113,7 +114,6 @@ { try { - this.database = new PgDatabase(this.options); this.database.Connect(); } catch (PgClientException ex) Modified: trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgConnectionPool.cs =================================================================== --- trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgConnectionPool.cs 2006-03-28 12:14:23 UTC (rev 62) +++ trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgConnectionPool.cs 2006-03-28 12:34:28 UTC (rev 63) @@ -137,10 +137,12 @@ newConnection = this.Create(owningConnection); - newConnection.OwningConnection = owningConnection; - newConnection.Pooled = true; - newConnection.Created = System.DateTime.Now.Ticks; + newConnection.OwningConnection = owningConnection; + newConnection.Pooled = true; + newConnection.Created = System.DateTime.Now.Ticks; + owningConnection.SslSetup(); + newConnection.Connect(); this.locked.Add(newConnection); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |