From: Carlos G. Á. <car...@us...> - 2005-09-12 18:27:54
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/source/PostgreSql/Data/Schema In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1495/Data/Schema Modified Files: MetaData.xml PgSchemaFactory.cs PgTables.cs Added Files: PgColumns.cs Log Message: Started the rework of the Schema support --- NEW FILE: PgColumns.cs --- /* * PgSqlClient - ADO.NET Data Provider for PostgreSQL 7.4+ * * The contents of this file are subject to the Initial * Developer's Public License Version 1.0 (the "License"); * you may not use this file except in compliance with the * License. * * Software distributed under the License is distributed on * an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either * express or implied. See the License for the specific * language governing rights and limitations under the License. * * Copyright (c) 2003, 2005 Carlos Guzman Alvarez * All Rights Reserved. */ using System; namespace PostgreSql.Data.Schema { internal class PgColumns : PgSchema { #region · Methods · protected override string BuildSql(string[] restrictions) { string sql = "SELECT " + "null AS TABLE_CATALOG, " + "pg_namespace.nspname AS TABLE_SCHEMA, " + "pg_class.relname AS TABLE_NAME, " + "pg_attribute.attname AS COLUMN_NAME, " + "pg_attribute.atttypid AS DATA_TYPE, " + "cast(0 as int4) AS NUMERIC_PRECISION, " + "cast(0 as int4) AS NUMERIC_SCALE, " + "pg_attribute.attlen AS COLUMN_SIZE, " + "pg_attribute.attndims AS COLUMN_DIMENSIONS, " + "pg_attribute.attnum AS ORDINAL_POSITION, " + "pg_attrdef.adsrc AS COLUMN_DEFAULT, " + "pg_attribute.attnotnull AS IS_NOT_NULL, " + "(pg_depend.objid is not null) AS IS_AUTOINCREMENT, " + "case pg_attribute.attstorage " + "when 'p' THEN 'PLAIN' " + "when 'e' THEN 'EXTERNAL' "+ "when 'm' THEN 'MAIN' " + "when 'x' THEN 'EXTENDED' " + "END AS STORAGE, " + "pg_description.description AS DESCRIPTION " + "FROM pg_attribute " + "left join pg_class ON pg_attribute.attrelid = pg_class.oid " + "left join pg_namespace ON pg_class.relnamespace = pg_namespace.oid " + "left join pg_attrdef ON (pg_class.oid = pg_attrdef.adrelid AND pg_attribute.attnum = pg_attrdef.adnum) " + "left join pg_description ON (pg_attribute.attrelid = pg_description.objoid AND pg_attribute.attnum = pg_description.objsubid) " + "left join pg_depend ON (pg_attribute.attrelid = pg_depend.refobjid AND pg_attribute.attnum = pg_depend.refobjsubid AND pg_depend.deptype = 'i') " + "WHERE pg_attribute.attisdropped = false AND pg_attribute.attnum > 0 "; if (restrictions != null && restrictions.Length > 0) { sql += " WHERE "; // TABLE_CATALOG if (restrictions.Length > 0) { } // TABLE_SCHEMA if (restrictions.Length > 1 && restrictions[1] != null) { sql += String.Format("pg_namespace.nspname = '{0}'", restrictions[1]); } // TABLE_NAME if (restrictions.Length > 2 && restrictions[2] != null) { sql += String.Format("pg_class.relname = '{0}'", restrictions[1]); } // COLUMN_NAME if (restrictions.Length > 3 && restrictions[3] != null) { sql += String.Format("pg_attribute.attname = '{0}'", restrictions[2]); } } sql += " ORDER BY pg_namespace.nspname, pg_class.relname, pg_attribute.attnum"; return sql; } #endregion } } Index: PgSchemaFactory.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/source/PostgreSql/Data/Schema/PgSchemaFactory.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PgSchemaFactory.cs 12 Sep 2005 17:11:30 -0000 1.1 --- PgSchemaFactory.cs 12 Sep 2005 18:27:45 -0000 1.2 *************** *** 95,98 **** --- 95,102 ---- switch (collectionName.Trim().ToLower()) { + case "columns": + schema = new PgColumns(); + break; + case "tables": schema = new PgTables(); Index: MetaData.xml =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/source/PostgreSql/Data/Schema/MetaData.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MetaData.xml 12 Sep 2005 17:11:30 -0000 1.1 --- MetaData.xml 12 Sep 2005 18:27:45 -0000 1.2 *************** *** 267,270 **** --- 267,294 ---- </MetaDataCollections> <Restrictions> + <CollectionName>Columns</CollectionName> + <RestrictionName>Catalog</RestrictionName> + <RestrictionDefault>table_catalog</RestrictionDefault> + <RestrictionNumber>1</RestrictionNumber> + </Restrictions> + <Restrictions> + <CollectionName>Columns</CollectionName> + <RestrictionName>Schema</RestrictionName> + <RestrictionDefault>table_schema</RestrictionDefault> + <RestrictionNumber>2</RestrictionNumber> + </Restrictions> + <Restrictions> + <CollectionName>Columns</CollectionName> + <RestrictionName>Table</RestrictionName> + <RestrictionDefault>table_name</RestrictionDefault> + <RestrictionNumber>3</RestrictionNumber> + </Restrictions> + <Restrictions> + <CollectionName>Columns</CollectionName> + <RestrictionName>Name</RestrictionName> + <RestrictionDefault>column_name</RestrictionDefault> + <RestrictionNumber>4</RestrictionNumber> + </Restrictions> + <Restrictions> <CollectionName>Tables</CollectionName> <RestrictionName>Catalog</RestrictionName> Index: PgTables.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/source/PostgreSql/Data/Schema/PgTables.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PgTables.cs 12 Sep 2005 17:11:30 -0000 1.1 --- PgTables.cs 12 Sep 2005 18:27:45 -0000 1.2 *************** *** 46,51 **** "left join pg_namespace ON pg_class.relnamespace = pg_namespace.oid " + "left join pg_description ON pg_class.oid = pg_description.objoid " + ! "WHERE pg_class.relkind = 'r' " + ! "ORDER BY pg_class.relkind, pg_namespace.nspname, pg_class.relname"; if (restrictions != null && restrictions.Length > 0) --- 46,50 ---- "left join pg_namespace ON pg_class.relnamespace = pg_namespace.oid " + "left join pg_description ON pg_class.oid = pg_description.objoid " + ! "WHERE pg_class.relkind = 'r' "; if (restrictions != null && restrictions.Length > 0) *************** *** 71,75 **** // TABLE_TYPE ! if (restrictions.Length > 2 && restrictions[2] != null) { sql += String.Format("pg_class.relkind = '{0}'", restrictions[2]); --- 70,74 ---- // TABLE_TYPE ! if (restrictions.Length > 3 && restrictions[3] != null) { sql += String.Format("pg_class.relkind = '{0}'", restrictions[2]); *************** *** 77,80 **** --- 76,81 ---- } + sql += " ORDER BY pg_class.relkind, pg_namespace.nspname, pg_class.relname"; + return sql; } |