Update of /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source
In directory sc8-pr-cvs1:/tmp/cvs-serv14613
Modified Files:
PgDataReader.cs
Log Message:
- Improved GetSchemaTable method using prepared statements for retrieve column
and primary key information..
Index: PgDataReader.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgDataReader.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** PgDataReader.cs 3 Aug 2003 12:01:11 -0000 1.5
--- PgDataReader.cs 7 Aug 2003 10:58:32 -0000 1.6
***************
*** 219,229 ****
schemaTable.BeginLoadData();
for (int i = 0; i < command.Statement.RowDescriptor.Fields.Length; i++)
{
// Get Column Information
! object[] columnInfo = getColumnInfo(command.Statement.RowDescriptor.Fields[i]);
// Get Primary Key Info
! System.Array pKeyInfo = getPrimaryKeyInfo(command.Statement.RowDescriptor.Fields[i]);
// Add row information
--- 219,254 ----
schemaTable.BeginLoadData();
+ PgCommand cInfoCmd = getColumnInfoCmd();
+ PgCommand pKeyCmd = getPrimaryKeyInfoCmd();
+
for (int i = 0; i < command.Statement.RowDescriptor.Fields.Length; i++)
{
+ object[] columnInfo = null;
+ System.Array pKeyInfo = null;
+
+ // Execute commands
+ cInfoCmd.Parameters[0].Value = command.Statement.RowDescriptor.Fields[i].OidNumber;
+ cInfoCmd.Parameters[1].Value = command.Statement.RowDescriptor.Fields[i].OidTable;
+
+ pKeyCmd.Parameters[0].Value = command.Statement.RowDescriptor.Fields[i].OidTable;
+
+ cInfoCmd.InternalPrepare();
+ pKeyCmd.InternalPrepare();
+
+ cInfoCmd.InternalExecute();
+ pKeyCmd.InternalExecute();
+
// Get Column Information
! if (cInfoCmd.Statement.Rows.Count > 0)
! {
! columnInfo = (object[])cInfoCmd.Statement.Rows[0];
! }
// Get Primary Key Info
! if (pKeyCmd.Statement.Rows.Count > 0)
! {
! object[] temp = (object[])pKeyCmd.Statement.Rows[0];
! pKeyInfo = (System.Array)temp[3];
! }
// Add row information
***************
*** 276,330 ****
schemaTable.EndLoadData();
! }
!
return schemaTable;
}
! private object[] getColumnInfo(PgFieldDescriptor field)
{
- object[] columnInfo = null;
-
IDbSchema dbSchema = PgDbSchemaFactory.GetSchema(PgDbSchemaType.Columns);
! dbSchema.AddWhereFilter("pg_attribute.attnum = " + field.OidNumber);
! dbSchema.AddWhereFilter("pg_attribute.attrelid = " + field.OidTable);
!
! PgCommand schemaCmd = new PgCommand(dbSchema.GetCommandText(null), command.Connection);
! schemaCmd.InternalPrepare();
! schemaCmd.InternalExecute();
!
! if (schemaCmd.Statement.Rows.Count > 0)
! {
! columnInfo = (object[])schemaCmd.Statement.Rows[0];
! }
!
! schemaCmd.InternalClose();
! schemaCmd.Dispose();
! return columnInfo;
}
! private System.Array getPrimaryKeyInfo(PgFieldDescriptor field)
{
- System.Array columnInfo = null;
-
IDbSchema dbSchema = PgDbSchemaFactory.GetSchema(PgDbSchemaType.Primary_Keys);
! dbSchema.AddWhereFilter("pg_class.oid = " + field.OidTable);
! PgCommand schemaCmd = new PgCommand(dbSchema.GetCommandText(null), command.Connection);
! schemaCmd.InternalPrepare();
! schemaCmd.InternalExecute();
!
! if (schemaCmd.Statement.Rows.Count > 0)
! {
! object[] temp = (object[])schemaCmd.Statement.Rows[0];
! columnInfo = (System.Array)temp[3];
! }
! schemaCmd.InternalClose();
! schemaCmd.Dispose();
! return columnInfo;
}
--- 301,338 ----
schemaTable.EndLoadData();
!
! cInfoCmd.Dispose();
! pKeyCmd.Dispose();
! }
!
return schemaTable;
}
! private PgCommand getColumnInfoCmd()
{
IDbSchema dbSchema = PgDbSchemaFactory.GetSchema(PgDbSchemaType.Columns);
! dbSchema.AddWhereFilter("pg_attribute.attnum = @OidNumber");
! dbSchema.AddWhereFilter("pg_attribute.attrelid = @OidTable");
!
! PgCommand cmd = new PgCommand(dbSchema.GetCommandText(null), command.Connection);
! cmd.Parameters.Add("@OidNumber", PgDbType.Int4);
! cmd.Parameters.Add("@OidTable", PgDbType.Int4);
!
! return cmd;
}
! private PgCommand getPrimaryKeyInfoCmd()
{
IDbSchema dbSchema = PgDbSchemaFactory.GetSchema(PgDbSchemaType.Primary_Keys);
! dbSchema.AddWhereFilter("pg_class.oid = @OidTable");
! PgCommand cmd = new PgCommand(dbSchema.GetCommandText(null), command.Connection);
! cmd.Parameters.Add("@OidTable", PgDbType.Int4);
! return cmd;
}
|