[pgsqlclient-checkins] SF.net SVN: pgsqlclient: [142] trunk/PostgreSqlClient/source/PostgreSql/Data/
Status: Inactive
Brought to you by:
carlosga_fb
From: <car...@us...> - 2006-05-18 13:32:22
|
Revision: 142 Author: carlosga_fb Date: 2006-05-18 06:32:04 -0700 (Thu, 18 May 2006) ViewCVS: http://svn.sourceforge.net/pgsqlclient/?rev=142&view=rev Log Message: ----------- 2006-05-18 Carlos Guzman Alvarez (car...@gm...) * Initial implementation for PostgreSql Domains, not all domains are supported only those who have a base data type that is supported by the provider Modified Paths: -------------- trunk/PostgreSqlClient/source/PostgreSql/Data/Protocol/PgParameter.cs trunk/PostgreSqlClient/source/PostgreSql/Data/Protocol/PgStatement.cs Modified: trunk/PostgreSqlClient/source/PostgreSql/Data/Protocol/PgParameter.cs =================================================================== --- trunk/PostgreSqlClient/source/PostgreSql/Data/Protocol/PgParameter.cs 2006-05-18 11:37:30 UTC (rev 141) +++ trunk/PostgreSqlClient/source/PostgreSql/Data/Protocol/PgParameter.cs 2006-05-18 13:32:04 UTC (rev 142) @@ -24,6 +24,7 @@ #region \xB7 Fields \xB7 private PgType dataType; + private int dataTypeOid; private object data; #endregion @@ -42,6 +43,11 @@ set { this.data = value; } } + public int DataTypeOid + { + get { return this.dataTypeOid; } + } + #endregion #region \xB7 Constructors \xB7 @@ -50,9 +56,14 @@ { } - public PgParameter(int dataType) + public PgParameter(int dataTypeOid) { - this.dataType = PgDatabase.DataTypes[dataType]; + this.dataTypeOid = dataTypeOid; + + if (PgDatabase.DataTypes.Contains(dataTypeOid)) + { + this.dataType = PgDatabase.DataTypes[dataTypeOid]; + } } public PgParameter(int dataType, object data) : this(dataType) Modified: trunk/PostgreSqlClient/source/PostgreSql/Data/Protocol/PgStatement.cs =================================================================== --- trunk/PostgreSqlClient/source/PostgreSql/Data/Protocol/PgStatement.cs 2006-05-18 11:37:30 UTC (rev 141) +++ trunk/PostgreSqlClient/source/PostgreSql/Data/Protocol/PgStatement.cs 2006-05-18 13:32:04 UTC (rev 142) @@ -210,7 +210,7 @@ { this.Describe('P'); } - + private void Describe(char stmtType) { lock (this.db) @@ -239,6 +239,40 @@ } while (!response.IsRowDescription && !response.IsNoData); + // Review if there are some parameter witha domain as a Data Type + foreach (PgParameter parameter in this.parameters) + { + if (parameter.DataType == null) + { + // It's a non supported data type or a domain data type + PgStatement stmt = new PgStatement(this.db, String.Format("select typbasetype from pg_type where oid = {0} and typtype = 'd'", parameter.DataTypeOid)); + + try + { + stmt.Query(); + + if (!stmt.HasRows) + { + throw new PgClientException("Unsupported data type"); + } + + int baseTypeOid = Convert.ToInt32(stmt.FetchRow()[0]); + + if (baseTypeOid == 0 || !PgDatabase.DataTypes.Contains(baseTypeOid)) + { + throw new PgClientException("Unsupported data type"); + } + + // Try to add the data type to the list of supported data types + parameter.DataType = PgDatabase.DataTypes[baseTypeOid]; + } + catch + { + throw new PgClientException("Unsupported data type"); + } + } + } + // Update status this.status = PgStatementStatus.Described; } @@ -417,63 +451,64 @@ lock (this.db) { - try - { - PgOutputPacket packet = new PgOutputPacket(this.db.Encoding); + try + { + PgOutputPacket packet = new PgOutputPacket(this.db.Encoding); - packet.WriteNullString(this.stmtText); + packet.WriteNullString(this.stmtText); - // Send packet to the server - this.db.SendPacket(packet, PgFrontEndCodes.QUERY); + // Send packet to the server + this.db.SendPacket(packet, PgFrontEndCodes.QUERY); - // Update Status - this.status = PgStatementStatus.OnQuery; + // Update Status + this.status = PgStatementStatus.OnQuery; - // Set fetch size - this.fetchSize = 1; + // Set fetch size + this.fetchSize = 1; - // Receive response - PgResponsePacket response = null; - - do - { - response = this.db.ReceiveResponsePacket(); - this.ProcessSqlPacket(response); + // Receive response + PgResponsePacket response = null; - if (this.hasRows && - response.Message == PgBackendCodes.DATAROW) - { - innerRows.Add(this.rows[0]); - this.rowIndex = 0; - } - } - while (!response.IsReadyForQuery); - - if (this.hasRows) - { - // Obtain all the rows - this.rows = (object[])innerRows.ToArray(typeof(object)); + do + { + response = this.db.ReceiveResponsePacket(); + this.ProcessSqlPacket(response); - // reset rowIndex - this.rowIndex = 0; + if (this.hasRows && response.Message == PgBackendCodes.DATAROW) + { + innerRows.Add(this.rows[0]); + this.rowIndex = 0; + } + } + while (!response.IsReadyForQuery); - // Set allRowsFetched flag - this.allRowsFetched = true; - } + if (this.hasRows) + { + // Obtain all the rows + this.rows = (object[])innerRows.ToArray(typeof(object)); - // reset fetch size - this.fetchSize = 200; + // reset rowIndex + this.rowIndex = 0; - // Update status - this.status = PgStatementStatus.Executed; - } - catch - { - // Update status - this.status = PgStatementStatus.Error; - // Throw exception - throw; - } + // Set allRowsFetched flag + this.allRowsFetched = true; + } + + // Update status + this.status = PgStatementStatus.Executed; + } + catch + { + // Update status + this.status = PgStatementStatus.Error; + // Throw exception + throw; + } + finally + { + // reset fetch size + this.fetchSize = 200; + } } } @@ -529,31 +564,31 @@ { string name = ((stmtType == 'S') ? this.ParseName : this.PortalName); - PgOutputPacket packet = new PgOutputPacket(this.db.Encoding); + PgOutputPacket packet = new PgOutputPacket(this.db.Encoding); - packet.Write((byte)stmtType); - packet.WriteNullString(name); + packet.Write((byte)stmtType); + packet.WriteNullString(String.IsNullOrEmpty(name) ? "" : name); - // Send packet to the server - this.db.SendPacket(packet, PgFrontEndCodes.CLOSE); + // Send packet to the server + this.db.SendPacket(packet, PgFrontEndCodes.CLOSE); - // Sync server and client - this.db.Flush(); + // Sync server and client + this.db.Flush(); - // Read until CLOSE COMPLETE message is received - PgResponsePacket response = null; - - do - { - response = this.db.ReceiveResponsePacket(); - this.ProcessSqlPacket(response); - } - while (!response.IsCloseComplete); + // Read until CLOSE COMPLETE message is received + PgResponsePacket response = null; - // Clear rows - this.rows = null; - this.rowIndex = 0; + do + { + response = this.db.ReceiveResponsePacket(); + this.ProcessSqlPacket(response); + } + while (!response.IsCloseComplete); + // Clear rows + this.rows = null; + this.rowIndex = 0; + // Update Status this.status = PgStatementStatus.Initial; } @@ -703,7 +738,7 @@ this.rowDescriptor.Fields[i].DataType = PgDatabase.DataTypes[packet.ReadInt32()]; this.rowDescriptor.Fields[i].DataTypeSize = packet.ReadInt16(); this.rowDescriptor.Fields[i].TypeModifier = packet.ReadInt32(); - this.rowDescriptor.Fields[i].FormatCode = (PgTypeFormat)packet.ReadInt16(); + this.rowDescriptor.Fields[i].FormatCode = (PgTypeFormat)packet.ReadInt16(); } } @@ -713,7 +748,7 @@ for (int i = 0; i < parameters.Length; i++) { - this.parameters[i] = new PgParameter(packet.ReadInt32()); + this.parameters[i] = new PgParameter(packet.ReadInt32()); } } @@ -739,7 +774,7 @@ break; default: - if (this.rowDescriptor.Fields[i].DataType.FormatCode == PgTypeFormat.Text) + if (this.rowDescriptor.Fields[i].FormatCode == PgTypeFormat.Text) { values[i] = packet.ReadValueFromString(this.rowDescriptor.Fields[i].DataType, length); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |