[pgsqlclient-checkins] pgsqlclient_10/PostgreSql.Data.PgSqlClient/source PgCommand.cs,1.41,1.42 PgCo
Status: Inactive
Brought to you by:
carlosga_fb
Update of /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15260 Modified Files: PgCommand.cs PgCommandBuilder.cs PgConnection.cs PgConnectionPool.cs PgDataAdapter.cs PgDataReader.cs Log Message: Mayor update of the PgSqlClient sources Index: PgConnectionPool.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgConnectionPool.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** PgConnectionPool.cs 22 Jul 2004 10:57:53 -0000 1.7 --- PgConnectionPool.cs 29 Sep 2004 12:08:12 -0000 1.8 *************** *** 42,53 **** } ! public static PgDbConnection GetConnection(string connectionString, PgDbConnection connection) { Init(); ! return ((PgDbConnection)pool.CheckOut(connectionString, connection)); } ! public static void FreeConnection(PgDbConnection c) { pool.CheckIn(c); --- 42,53 ---- } ! public static PgConnectionInternal GetConnection(string connectionString, PgConnection owningConnection) { Init(); ! return ((PgConnectionInternal)pool.CheckOut(connectionString, owningConnection)); } ! public static void FreeConnection(PgConnectionInternal c) { pool.CheckIn(c); *************** *** 84,96 **** #region Methods ! public PgDbConnection CheckOut(string connectionString) ! { ! return this.CheckOut(connectionString, null); ! } ! ! public PgDbConnection CheckOut(string connectionString, PgDbConnection instance) { ! PgDbConnection newConnection = null; ! long now = System.DateTime.Now.Ticks; lock (typeof(PgConnectionPool)) --- 84,90 ---- #region Methods ! public PgConnectionInternal CheckOut(string connectionString, PgConnection owningConnection) { ! PgConnectionInternal newConnection = null; lock (typeof(PgConnectionPool)) *************** *** 98,105 **** if (this.unlocked.Count > 0) { ! PgDbConnection[] list = new PgDbConnection[this.unlocked.Count]; this.unlocked.CopyTo(0, list, 0, list.Length); ! foreach (PgDbConnection connection in list) { if (this.Validate(connection, connectionString)) --- 92,101 ---- if (this.unlocked.Count > 0) { ! long now = System.DateTime.Now.Ticks; ! ! PgConnectionInternal[] list = new PgConnectionInternal[this.unlocked.Count]; this.unlocked.CopyTo(0, list, 0, list.Length); ! foreach (PgConnectionInternal connection in list) { if (this.Validate(connection, connectionString)) *************** *** 116,120 **** this.unlocked.Remove(connection); this.locked.Add(connection); ! return connection; } --- 112,118 ---- this.unlocked.Remove(connection); this.locked.Add(connection); ! ! connection.OwningConnection = owningConnection; ! return connection; } *************** *** 136,150 **** } ! if (instance == null) ! { ! newConnection = this.Create(connectionString); ! } ! else ! { ! newConnection = instance; ! newConnection.Connect(); ! } ! newConnection.Pooled = true; ! newConnection.Created = System.DateTime.Now.Ticks; this.locked.Add(newConnection); --- 134,144 ---- } ! newConnection = this.Create(connectionString); ! ! newConnection.OwningConnection = owningConnection; ! newConnection.Pooled = true; ! newConnection.Created = System.DateTime.Now.Ticks; ! ! newConnection.Connect(); this.locked.Add(newConnection); *************** *** 154,162 **** } ! public void CheckIn(PgDbConnection connection) { lock (typeof(PgConnectionPool)) ! { connection.Created = System.DateTime.Now.Ticks; this.locked.Remove(connection); --- 148,157 ---- } ! public void CheckIn(PgConnectionInternal connection) { lock (typeof(PgConnectionPool)) ! { connection.Created = System.DateTime.Now.Ticks; + connection.OwningConnection = null; this.locked.Remove(connection); *************** *** 181,190 **** } ! private PgDbConnection Create(string connectionString) { try { ! PgDbConnection connection = new PgDbConnection(connectionString); ! connection.Connect(); return connection; --- 176,184 ---- } ! private PgConnectionInternal Create(string connectionString) { try { ! PgConnectionInternal connection = new PgConnectionInternal(connectionString); return connection; *************** *** 196,200 **** } ! private bool Validate(PgDbConnection connection, string connectionString) { try --- 190,194 ---- } ! private bool Validate(PgConnectionInternal connection, string connectionString) { try *************** *** 209,213 **** } ! private void Expire(PgDbConnection connection) { try --- 203,207 ---- } ! private void Expire(PgConnectionInternal connection) { try *************** *** 232,239 **** if (this.unlocked.Count > 0) { ! PgDbConnection[] list = new PgDbConnection[this.unlocked.Count]; this.unlocked.CopyTo(0, list, 0, list.Length); ! foreach (PgDbConnection connection in list) { if (connection.Lifetime != 0) --- 226,233 ---- if (this.unlocked.Count > 0) { ! PgConnectionInternal[] list = new PgConnectionInternal[this.unlocked.Count]; this.unlocked.CopyTo(0, list, 0, list.Length); ! foreach (PgConnectionInternal connection in list) { if (connection.Lifetime != 0) Index: PgDataAdapter.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgDataAdapter.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** PgDataAdapter.cs 10 Apr 2004 21:35:36 -0000 1.7 --- PgDataAdapter.cs 29 Sep 2004 12:08:12 -0000 1.8 *************** *** 33,38 **** #endregion ! [ToolboxItem(true), ! ToolboxBitmap(typeof(PgDataAdapter), "Resources.ToolBox.PgDataAdapter.bmp"), DefaultEvent("RowUpdated")] public sealed class PgDataAdapter : DbDataAdapter, IDbDataAdapter --- 33,37 ---- #endregion ! [ToolboxItem(true), ToolboxBitmap(typeof(PgDataAdapter), "Resources.ToolBox.PgDataAdapter.bmp"), DefaultEvent("RowUpdated")] public sealed class PgDataAdapter : DbDataAdapter, IDbDataAdapter Index: PgCommandBuilder.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgCommandBuilder.cs,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** PgCommandBuilder.cs 22 Jul 2004 10:57:53 -0000 1.22 --- PgCommandBuilder.cs 29 Sep 2004 12:08:06 -0000 1.23 *************** *** 207,212 **** command.Parameters.Clear(); ! DataTable spSchema = command.Connection.GetDbSchemaTable(PgDbSchemaType.Functions, ! new object[] {null, command.CommandText.ToLower()}); if (spSchema.Rows.Count != 0) --- 207,211 ---- command.Parameters.Clear(); ! DataTable spSchema = command.Connection.GetSchema("Functions", new string[] { null, command.CommandText.ToLower() }); if (spSchema.Rows.Count != 0) *************** *** 315,321 **** #region Build Command Methods ! private PgCommand BuildInsertCommand( ! DataRow row, ! DataTableMapping tableMapping) { StringBuilder sql = new StringBuilder(); --- 314,318 ---- #region Build Command Methods ! private PgCommand BuildInsertCommand(DataRow row, DataTableMapping tableMapping) { StringBuilder sql = new StringBuilder(); Index: PgCommand.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgCommand.cs,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** PgCommand.cs 28 Aug 2004 20:50:10 -0000 1.41 --- PgCommand.cs 29 Sep 2004 12:08:05 -0000 1.42 *************** *** 30,35 **** namespace PostgreSql.Data.PgSqlClient { ! [ToolboxItem(true), ! ToolboxBitmap(typeof(PgCommand), "Resources.ToolBox.PgCommand.bmp")] public sealed class PgCommand : Component, IDbCommand, ICloneable { --- 30,34 ---- namespace PostgreSql.Data.PgSqlClient { ! [ToolboxItem(true), ToolboxBitmap(typeof(PgCommand), "Resources.ToolBox.PgCommand.bmp")] public sealed class PgCommand : Component, IDbCommand, ICloneable { *************** *** 42,47 **** private CommandBehavior commandBehavior; private bool disposed; - private int actualCommand; - private string[] commands; private string commandText; private CommandType commandType; --- 41,44 ---- *************** *** 52,55 **** --- 49,53 ---- private Hashtable matchReplaces; private PgStatement statement; + private PgDataReader activeDataReader; #endregion *************** *** 57,63 **** #region Properties ! [Category("Data"), ! DefaultValue(""), ! RefreshProperties(RefreshProperties.All)] public string CommandText { --- 55,59 ---- #region Properties ! [Category("Data"), DefaultValue(""), RefreshProperties(RefreshProperties.All)] public string CommandText { *************** *** 71,83 **** } ! this.commandText = value; ! this.actualCommand = 0; ! this.commands = null; } } ! [Category("Data"), ! DefaultValue(CommandType.Text), ! RefreshProperties(RefreshProperties.All)] public CommandType CommandType { --- 67,75 ---- } ! this.commandText = value; } } ! [Category("Data"), DefaultValue(CommandType.Text), RefreshProperties(RefreshProperties.All)] public CommandType CommandType { *************** *** 86,91 **** } ! [ReadOnly(true), ! DefaultValue(30)] public int CommandTimeout { --- 78,82 ---- } ! [ReadOnly(true), DefaultValue(30)] public int CommandTimeout { *************** *** 116,131 **** 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) { --- 107,115 ---- set { ! if (this.connection != null && this.ActiveDataReader != null) { throw new InvalidOperationException("There is already an open DataReader associated with this Connection which must be closed first."); } if (this.connection != value) { *************** *** 142,148 **** } ! [Browsable(false), ! DesignOnly(true), ! DefaultValue(true)] public bool DesignTimeVisible { --- 126,130 ---- } ! [Browsable(false), DesignOnly(true), DefaultValue(true)] public bool DesignTimeVisible { *************** *** 156,161 **** } ! [Category("Data"), ! DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public PgParameterCollection Parameters { --- 138,142 ---- } ! [Category("Data"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public PgParameterCollection Parameters { *************** *** 169,175 **** } ! [Browsable(false), ! DataSysDescription("Tansaction context used by the command."), ! DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public PgTransaction Transaction { --- 150,154 ---- } ! [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public PgTransaction Transaction { *************** *** 177,181 **** 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."); --- 156,160 ---- set { ! if (this.connection != null && this.ActiveDataReader != null) { throw new InvalidOperationException("There is already an open DataReader associated with this Connection which must be closed first."); *************** *** 197,200 **** --- 176,185 ---- #region Internal Properties + internal PgDataReader ActiveDataReader + { + get { return this.activeDataReader; } + set { this.activeDataReader = value; } + } + internal CommandBehavior CommandBehavior { *************** *** 233,237 **** this.commandType = CommandType.Text; this.commandTimeout = 30; - this.actualCommand = -1; this.updatedRowSource = UpdateRowSource.Both; this.commandBehavior = CommandBehavior.Default; --- 218,221 ---- *************** *** 240,245 **** this.namedParameters = new StringCollection(); this.matchReplaces = new Hashtable(); - - GC.SuppressFinalize(this); } --- 224,227 ---- *************** *** 255,260 **** { this.CommandText = cmdText; ! this.connection = connection; ! this.transaction = transaction; } --- 237,242 ---- { this.CommandText = cmdText; ! this.Connection = connection; ! this.Transaction = transaction; } *************** *** 274,287 **** if (this.connection != null && ! this.connection.ActiveCommands != null) { ! this.connection.ActiveCommands.Remove(this); } this.InternalClose(); ! this.commandText = String.Empty; ! this.actualCommand = -1; ! this.commands = null; this.matchReplaces.Clear(); --- 256,267 ---- if (this.connection != null && ! this.connection.InternalConnection != null) { ! this.connection.InternalConnection.RemovePreparedCommand(this); } this.InternalClose(); ! this.commandText = null; this.matchReplaces.Clear(); *************** *** 293,297 **** // release any unmanaged resources - this.disposed = true; } --- 273,276 ---- *************** *** 348,353 **** this.CheckCommand(); - this.SplitBatchCommands(false); - this.InternalPrepare(); this.InternalExecute(); --- 327,330 ---- *************** *** 379,384 **** this.commandBehavior = behavior; - this.SplitBatchCommands(true); - this.InternalPrepare(); --- 356,359 ---- *************** *** 392,396 **** } ! return new PgDataReader(this, this.connection); } --- 367,373 ---- } ! this.activeDataReader = new PgDataReader(this, this.connection); ! ! return this.activeDataReader; } *************** *** 401,406 **** object returnValue = null; - this.SplitBatchCommands(false); - this.InternalPrepare(); this.InternalExecute(); --- 378,381 ---- *************** *** 418,424 **** this.CheckCommand(); - this.SplitBatchCommands(false); this.InternalPrepare(); - this.connection.ActiveCommands.Add(this); } --- 393,397 ---- *************** *** 433,437 **** if (this.statement == null) { ! this.statement = this.connection.DbConnection.DB.CreateStatement(commandText); plan = this.statement.GetPlan(verbose); this.statement = null; --- 406,410 ---- if (this.statement == null) { ! this.statement = this.connection.InternalConnection.Database.CreateStatement(commandText); plan = this.statement.GetPlan(verbose); this.statement = null; *************** *** 456,466 **** internal void InternalPrepare() { ! if (this.commands == null) ! { ! this.SplitBatchCommands(false); ! } try { if (this.statement == null || this.statement.Status == PgStatementStatus.Initial || --- 429,440 ---- internal void InternalPrepare() { ! PgConnectionInternal conn = this.connection.InternalConnection; ! ! conn.AddPreparedCommand(this); try { + string sql = this.commandText; + if (this.statement == null || this.statement.Status == PgStatementStatus.Initial || *************** *** 469,473 **** if (this.commandType == CommandType.StoredProcedure) { ! this.commands[actualCommand] = this.BuildStoredProcedureSql(); } --- 443,447 ---- if (this.commandType == CommandType.StoredProcedure) { ! sql = this.BuildStoredProcedureSql(sql); } *************** *** 475,482 **** string portalName = "PR" + this.GetStmtName(); ! this.statement = this.connection.DbConnection.DB.CreateStatement( ! prepareName, ! portalName, ! this.ParseParameterNames()); // Parse statement --- 449,454 ---- string portalName = "PR" + this.GetStmtName(); ! this.statement = conn.Database.CreateStatement( ! prepareName, portalName, this.ParseParameterNames(sql)); // Parse statement *************** *** 536,572 **** } } ! ! internal bool NextResult() ! { ! bool returnValue = false; ! ! this.statement.Close(); ! this.statement.ClosePortal(); ! this.statement = null; ! ! if ((this.commandBehavior & CommandBehavior.SingleResult) != CommandBehavior.SingleResult) ! { ! this.actualCommand++; ! ! if (this.actualCommand >= this.commands.Length) ! { ! this.actualCommand--; ! } ! else ! { ! string commandText = this.commands[actualCommand]; ! if (commandText != null && commandText.Trim().Length > 0) ! { ! this.InternalPrepare(); ! this.InternalExecute(); ! ! returnValue = true; ! } ! } ! } ! ! return returnValue; ! } ! internal void InternalSetOutputParameters() { --- 508,512 ---- } } ! internal void InternalSetOutputParameters() { *************** *** 609,630 **** this.transaction = null; } if (this.connection == null || this.connection.State != ConnectionState.Open) { throw new InvalidOperationException("Connection must valid and open"); } ! if (this.connection.DataReader != null) { ! throw new InvalidOperationException("There is already an open DataReader associated with this Connection which must be closed first."); } ! if (this.connection.ActiveTransaction != null && ! !this.connection.ActiveTransaction.IsUpdated && this.Transaction == null) { throw new InvalidOperationException("Execute requires the Command object to have a Transaction object when the Connection object assigned to the command is in a pending local transaction. The Transaction property of the Command has not been initialized."); } if (this.transaction != null && !this.connection.Equals(Transaction.Connection)) { throw new InvalidOperationException("Command Connection is not equal to Transaction Connection"); } if (this.commandText == null || this.commandText.Length == 0) { --- 549,574 ---- this.transaction = null; } + if (this.connection == null || this.connection.State != ConnectionState.Open) { throw new InvalidOperationException("Connection must valid and open"); + } ! if (this.ActiveDataReader != null) { ! throw new InvalidOperationException("There is already an open DataReader associated with this Command which must be closed first."); } ! ! if (this.connection.InternalConnection.HasActiveTransaction && this.Transaction == null) { throw new InvalidOperationException("Execute requires the Command object to have a Transaction object when the Connection object assigned to the command is in a pending local transaction. The Transaction property of the Command has not been initialized."); } + if (this.transaction != null && !this.connection.Equals(Transaction.Connection)) { throw new InvalidOperationException("Command Connection is not equal to Transaction Connection"); } + if (this.commandText == null || this.commandText.Length == 0) { *************** *** 633,640 **** } ! private string BuildStoredProcedureSql() { - string commandText = this.commands[actualCommand]; - if (!commandText.Trim().ToLower().StartsWith("select ")) { --- 577,582 ---- } ! private string BuildStoredProcedureSql(string commandText) { if (!commandText.Trim().ToLower().StartsWith("select ")) { *************** *** 674,684 **** } ! private string ParseParameterNames() { ! string sql = this.commands[actualCommand]; ! this.namedParameters.Clear(); ! if (sql.IndexOf("@") != -1) { this.matchReplaces.Clear(); --- 616,626 ---- } ! private string ParseParameterNames(string commandText) { ! string sql = commandText; ! this.namedParameters.Clear(); ! if (commandText.IndexOf("@") != -1) { this.matchReplaces.Clear(); *************** *** 758,789 **** } - private void SplitBatchCommands(bool batchAllowed) - { - if (this.commands == null) - { - if (batchAllowed) - { - MatchCollection matches = Regex.Matches( - this.commandText, - "([^';]+('[^']*'))*[^';]*(?=;*)"); - - this.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++; - } - } - } - else - { - this.commands = new string[]{this.commandText}; - } - } - } - #endregion } --- 700,703 ---- Index: PgDataReader.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgDataReader.cs,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** PgDataReader.cs 22 Jul 2004 10:57:53 -0000 1.23 --- PgDataReader.cs 29 Sep 2004 12:08:12 -0000 1.24 *************** *** 61,68 **** internal PgDataReader(PgCommand command, PgConnection connection) : this() { ! this.command = command; ! this.behavior = this.command.CommandBehavior; ! this.connection = connection; ! this.connection.DataReader = this; this.fieldCount = this.command.Statement.RowDescriptor.Fields.Length; } --- 61,67 ---- internal PgDataReader(PgCommand command, PgConnection connection) : this() { ! this.command = command; ! this.behavior = this.command.CommandBehavior; ! this.connection = connection; this.fieldCount = this.command.Statement.RowDescriptor.Fields.Length; } *************** *** 155,164 **** this.command.InternalSetOutputParameters(); } ! } if (this.connection != null) { - this.connection.DataReader = null; - if ((this.behavior & CommandBehavior.CloseConnection) == CommandBehavior.CloseConnection) { --- 154,163 ---- this.command.InternalSetOutputParameters(); } ! ! this.command.ActiveDataReader = null; ! } if (this.connection != null) { if ((this.behavior & CommandBehavior.CloseConnection) == CommandBehavior.CloseConnection) { *************** *** 173,196 **** public bool NextResult() { ! if (this.IsClosed) ! { ! throw new InvalidOperationException("The datareader must be opened."); ! } ! ! this.UpdateRecordsAffected(); ! ! bool returnValue = this.command.NextResult(); ! ! if (returnValue) ! { ! this.fieldCount = this.command.Statement.RowDescriptor.Fields.Length; ! this.position = STARTPOS; ! } ! else ! { ! this.row = null; ! } ! ! return returnValue; } --- 172,176 ---- public bool NextResult() { ! return false; } *************** *** 331,335 **** private PgCommand GetColumnInfoCmd() { ! PgDbSchema dbSchema = PgDbSchemaFactory.GetSchema(PgDbSchemaType.Columns); dbSchema.AddWhereFilter("pg_attribute.attnum = @OidNumber"); --- 311,315 ---- private PgCommand GetColumnInfoCmd() { ! PgDbSchema dbSchema = PgDbSchemaFactory.GetSchema("Columns"); dbSchema.AddWhereFilter("pg_attribute.attnum = @OidNumber"); *************** *** 346,350 **** private PgCommand GetPrimaryKeyInfoCmd() { ! PgDbSchema dbSchema = PgDbSchemaFactory.GetSchema(PgDbSchemaType.Primary_Keys); dbSchema.AddWhereFilter("pg_class.oid = @OidTable"); --- 326,330 ---- private PgCommand GetPrimaryKeyInfoCmd() { ! PgDbSchema dbSchema = PgDbSchemaFactory.GetSchema("PrimaryKeys"); dbSchema.AddWhereFilter("pg_class.oid = @OidTable"); Index: PgConnection.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgConnection.cs,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** PgConnection.cs 22 Jul 2004 10:57:53 -0000 1.19 --- PgConnection.cs 29 Sep 2004 12:08:12 -0000 1.20 *************** *** 29,38 **** using PostgreSql.Data.NPgClient; - using PostgreSql.Data.PgSqlClient.DbSchema; namespace PostgreSql.Data.PgSqlClient { ! [ToolboxItem(true), ! ToolboxBitmap(typeof(PgConnection), "Resources.ToolBox.PgConnection.bmp"), DefaultEvent("InfoMessage")] public sealed class PgConnection : Component, IDbConnection, ICloneable --- 29,36 ---- using PostgreSql.Data.NPgClient; namespace PostgreSql.Data.PgSqlClient { ! [ToolboxItem(true), ToolboxBitmap(typeof(PgConnection), "Resources.ToolBox.PgConnection.bmp"), DefaultEvent("InfoMessage")] public sealed class PgConnection : Component, IDbConnection, ICloneable *************** *** 43,49 **** public event PgInfoMessageEventHandler InfoMessage; public event PgNotificationEventHandler Notification; public event CertificateValidationCallback ServerCertValidation; public event CertificateSelectionCallback ClientCertSelection; - public event PrivateKeySelectionCallback PrivateKeySelection; #endregion --- 41,51 ---- public event PgInfoMessageEventHandler InfoMessage; public event PgNotificationEventHandler Notification; + + #endregion + + #region SSL Events + public event CertificateValidationCallback ServerCertValidation; public event CertificateSelectionCallback ClientCertSelection; #endregion *************** *** 51,61 **** #region Fields ! private PgDbConnection dbConnection; ! private ConnectionState state; ! private bool disposed; ! private string connectionString; ! private PgDataReader dataReader; ! private PgTransaction activeTransaction; ! private ArrayList activeCommands; #endregion --- 53,60 ---- #region Fields ! private PgConnectionInternal connectionInternal; ! private ConnectionState state; ! private bool disposed; ! private string connectionString; #endregion *************** *** 63,70 **** #region Properties ! [Category("Data"), ! RecommendedAsConfigurableAttribute(true), ! RefreshProperties(RefreshProperties.All), ! DefaultValue("")] public string ConnectionString { --- 62,67 ---- #region Properties ! [Category("Data"), RecommendedAsConfigurableAttribute(true), ! RefreshProperties(RefreshProperties.All), DefaultValue("")] public string ConnectionString { *************** *** 74,80 **** if (state == ConnectionState.Closed) { ! PgDbConnection tmpConn = new PgDbConnection(value); this.connectionString = value; - tmpConn = null; } } --- 71,76 ---- if (state == ConnectionState.Closed) { ! PgConnectionInternal tmpConn = new PgConnectionInternal(value); this.connectionString = value; } } *************** *** 86,92 **** get { ! if (this.dbConnection != null) { ! return this.dbConnection.Settings.Timeout; } else --- 82,88 ---- get { ! if (this.connectionInternal != null) { ! return this.connectionInternal.Options.Timeout; } else *************** *** 102,108 **** get { ! if (this.dbConnection != null) { ! return this.dbConnection.Settings.Database; } else --- 98,104 ---- get { ! if (this.connectionInternal != null) { ! return this.connectionInternal.Options.Database; } else *************** *** 118,124 **** get { ! if (this.dbConnection != null) { ! return this.dbConnection.Settings.ServerName; } else --- 114,120 ---- get { ! if (this.connectionInternal != null) { ! return this.connectionInternal.Options.ServerName; } else *************** *** 135,141 **** { int packetSize = 8192; ! if (this.dbConnection != null) { ! packetSize = this.dbConnection.Settings.PacketSize; } --- 131,137 ---- { int packetSize = 8192; ! if (this.connectionInternal != null) { ! packetSize = this.connectionInternal.Options.PacketSize; } *************** *** 144,156 **** } ! [Browsable(false), ! DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public string ServerVersion { get { ! if (this.dbConnection != null) { ! return (string)this.dbConnection.DB.ParameterStatus["server_version"]; } else --- 140,151 ---- } ! [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public string ServerVersion { get { ! if (this.connectionInternal != null) { ! return (string)this.connectionInternal.Database.ParameterStatus["server_version"]; } else *************** *** 161,166 **** } ! [Browsable(false), ! DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public ConnectionState State { --- 156,160 ---- } ! [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public ConnectionState State { *************** *** 172,196 **** #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; } } --- 166,173 ---- #region Internal properties ! internal PgConnectionInternal InternalConnection { ! get { return this.connectionInternal; } ! set { this.connectionInternal = value; } } *************** *** 208,213 **** this.connectionString = String.Empty; - GC.SuppressFinalize(this); - if (connString != null) { --- 185,188 ---- *************** *** 231,235 **** this.Close(); ! this.dbConnection = null; this.connectionString = null; } --- 206,210 ---- this.Close(); ! this.connectionInternal = null; this.connectionString = null; } *************** *** 271,301 **** 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."); ! } ! ! try ! { ! this.activeTransaction = new PgTransaction(this); ! this.activeTransaction.InternalBeginTransaction(); ! } ! catch (PgClientException ex) ! { ! throw new PgException(ex.Message, ex); ! } ! ! return this.activeTransaction; } --- 246,250 ---- public PgTransaction BeginTransaction() { ! return this.BeginTransaction(IsolationLevel.ReadCommitted); } *************** *** 307,332 **** } ! if (this.activeTransaction != null && ! !this.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."); ! } ! ! try ! { ! this.activeTransaction = new PgTransaction(this, level); ! this.activeTransaction.InternalBeginTransaction(); ! } ! catch (PgClientException ex) ! { ! throw new PgException(ex.Message, ex); ! } ! ! return this.activeTransaction; } --- 256,260 ---- } ! return this.connectionInternal.BeginTransaction(level); } *************** *** 343,352 **** } ! if (this.DataReader != null) ! { ! throw new InvalidOperationException("ChangeDatabase requires an open and available Connection. The connection's current state is Open, Fetching."); ! } ! ! string oldDb = this.dbConnection.Settings.Database; try --- 271,275 ---- } ! string oldDb = this.connectionInternal.Options.Database; try *************** *** 356,360 **** /* Set up the new Database */ ! this.dbConnection.Settings.Database = db; /* Open new connection to new database */ --- 279,283 ---- /* Set up the new Database */ ! this.connectionInternal.Options.Database = db; /* Open new connection to new database */ *************** *** 363,367 **** catch (PgException ex) { ! this.dbConnection.Settings.Database = oldDb; throw ex; } --- 286,290 ---- catch (PgException ex) { ! this.connectionInternal.Options.Database = oldDb; throw ex; } *************** *** 379,398 **** this.state = ConnectionState.Connecting; ! this.dbConnection = new PgDbConnection(this.connectionString); ! ! // Add handler for Ssl connections ! dbConnection.DB.SslConnection = new SslConnectionCallback(this.OnSslConnection); // Open connection ! if (this.dbConnection.Settings.Pooling) { ! this.dbConnection = PgConnectionPool.GetConnection( ! this.connectionString, ! this.dbConnection); } else { ! this.dbConnection.Pooled = false; ! this.dbConnection.Connect(); } --- 302,319 ---- this.state = ConnectionState.Connecting; ! PgConnectionInternal tmp = new PgConnectionInternal(connectionString); // Open connection ! if (tmp.Options.Pooling) { ! this.connectionInternal = PgConnectionPool.GetConnection(this.connectionString, this); } else { ! this.connectionInternal = new PgConnectionInternal(this.connectionString); ! ! this.connectionInternal.OwningConnection = this; ! this.connectionInternal.Pooled = false; ! this.connectionInternal.Connect(); } *************** *** 404,415 **** } - // Initialize active commands list - this.activeCommands = new ArrayList(); - // Add Info message event handler ! this.dbConnection.DB.InfoMessage = new InfoMessageCallback(this.OnInfoMessage); // Add notification event handler ! this.dbConnection.DB.Notification = new NotificationCallback(this.OnNotification); } catch (PgClientException ex) --- 325,333 ---- } // Add Info message event handler ! this.connectionInternal.Database.InfoMessage = new InfoMessageCallback(this.OnInfoMessage); // Add notification event handler ! this.connectionInternal.Database.Notification = new NotificationCallback(this.OnNotification); } catch (PgClientException ex) *************** *** 425,467 **** { try ! { ! lock (this.dbConnection) { // Remove info message callback ! this.dbConnection.DB.InfoMessage = null; // Remove notification callback ! this.dbConnection.DB.Notification = null; ! // Close DataReader ! if (this.dataReader != null && !this.dataReader.IsClosed) ! { ! this.dataReader.Close(); ! } // Dispose Active commands ! this.DisposeActiveCommands(); // Rollback active transation ! if (this.activeTransaction != null) ! { ! this.activeTransaction.Dispose(); ! this.activeTransaction = null; ! } ! ! // Remove SSL handlers ! this.ServerCertValidation = null; ! this.ClientCertSelection = null; ! this.PrivateKeySelection = null; // Close connection permanently or send it // back to the pool ! if (this.dbConnection.Pooled) { ! PgConnectionPool.FreeConnection(this.dbConnection); } else { ! this.dbConnection.Disconnect(); } } --- 343,378 ---- { try ! { ! lock (this.connectionInternal) { + PgDbClient database = this.connectionInternal.Database; + // Remove info message callback ! this.connectionInternal.Database.InfoMessage = null; // Remove notification callback ! this.connectionInternal.Database.Notification = null; ! // Remove SSL handlers ! database.SslClientStream.ServerCertValidationDelegate = null; ! database.SslClientStream.ClientCertSelectionDelegate = null; ! this.ServerCertValidation = null; ! this.ClientCertSelection = null; // Dispose Active commands ! this.connectionInternal.DisposePreparedCommands(); // Rollback active transation ! 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(); } } *************** *** 498,600 **** } ! 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) ! { ! command.Dispose(); ! } ! ! commands = null; ! } ! ! activeCommands.Clear(); ! activeCommands = null; ! } } ! 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."); ! } ! ! PgDbSchema dbSchema = PgDbSchemaFactory.GetSchema(schema); ! ! if (dbSchema == null) ! { ! throw new NotSupportedException("Specified schema type is not supported."); ! } ! if (restrictions != null) ! { ! if (restrictions.Length > dbSchema.RestrictionColumns.Count) ! { ! throw new InvalidOperationException("The number of specified restrictions is not valid."); ! } ! } ! ! return dbSchema.GetDbSchemaTable(this, restrictions); } ! public void CreateDatabase(string database, string owner, string location, string template, string encoding) { ! if (DataReader != null) ! { ! throw new InvalidOperationException("CreateDatabase requires an open and available Connection. The connection's current state is Open, Fetching."); ! } ! ! if (database == null) { ! throw new InvalidOperationException("You need to specify the database name to create."); } ! try ! { ! lock (this) ! { ! if (owner == null) ! { ! owner = "DEFAULT"; ! } ! if (location == null) ! { ! location = "DEFAULT"; ! } ! if (template == null) ! { ! template = "template0"; ! } ! if (encoding == null) ! { ! encoding = "SQL_ASCII"; ! } ! ! // Build the command text ! StringBuilder commandText = new StringBuilder(); ! commandText.AppendFormat( ! "CREATE DATABASE {0} WITH OWNER={1} LOCATION={2} TEMPLATE={3} ENCODING='{4}'", ! database, ! owner, ! location, ! template, ! encoding); ! ! // Create database ! PgCommand command = new PgCommand(commandText.ToString(), this); ! command.ExecuteNonQuery(); ! command.Dispose(); ! } ! } ! catch (PgClientException ex) ! { ! throw new PgException(ex.Message, ex); ! } } --- 409,430 ---- } ! public DataTable GetSchema() { ! return this.GetSchema("MetaDataCollections"); } ! public DataTable GetSchema(string collectionName) { ! return this.GetSchema(collectionName, null); } ! public DataTable GetSchema(string collectionName, string[] restrictions) { ! if (this.state == ConnectionState.Closed) { ! throw new InvalidOperationException(""); } ! return this.connectionInternal.GetSchema(collectionName, restrictions); } *************** *** 619,637 **** } ! private void OnSslConnection() ! { ! PgDbClient db = this.dbConnection.DB; ! ! // Server certificate validation ! db.SslClientStream.ServerCertValidationDelegate = new CertificateValidationCallback(OnServerCertificateValidation); ! ! // Client certificate selection ! db.SslClientStream.ClientCertSelectionDelegate = new CertificateSelectionCallback(OnClientCertificateSelection); ! // Private key selection ! db.SslClientStream.PrivateKeyCertSelectionDelegate = new PrivateKeySelectionCallback(OnPrivateKeySelection); ! } ! private bool OnServerCertificateValidation( X509Certificate certificate, int[] certificateErrors) --- 449,457 ---- } ! #endregion ! #region SSL Event handlers ! internal bool OnServerCertificateValidation( X509Certificate certificate, int[] certificateErrors) *************** *** 645,649 **** } ! private X509Certificate OnClientCertificateSelection( X509CertificateCollection clientCertificates, X509Certificate serverCertificate, --- 465,469 ---- } ! internal X509Certificate OnClientCertificateSelection( X509CertificateCollection clientCertificates, X509Certificate serverCertificate, *************** *** 663,678 **** } - private AsymmetricAlgorithm OnPrivateKeySelection( - X509Certificate clientCertificate, - string targetHost) - { - if (this.PrivateKeySelection != null) - { - return this.PrivateKeySelection(clientCertificate, targetHost); - } - - return null; - } - #endregion } --- 483,486 ---- |