From: Carlos G. Á. <car...@us...> - 2005-09-12 17:11:39
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/source/PostgreSql/Data/Schema In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17916 Added Files: MetaData.xml PgSchema.cs PgSchemaFactory.cs PgTables.cs Log Message: Started the rework of the Schema support --- NEW FILE: PgSchema.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; using System.Data; using System.Text; using System.Text.RegularExpressions; using System.Collections; using PostgreSql.Data.PostgreSqlClient; namespace PostgreSql.Data.Schema { internal abstract class PgSchema { #region · Constructors · public PgSchema() { } #endregion #region · Abstract Methods · protected abstract string BuildSql(string[] restrictions); #endregion #region · Methods · public DataTable GetSchema(PgConnection connection, string collectionName, string[] restrictions) { DataTable dataTable = null; PgDataAdapter adapter = null; PgCommand command = new PgCommand(); try { command.Connection = connection; command.CommandText = this.BuildSql(this.ParseRestrictions(restrictions)); adapter = new PgDataAdapter(command); dataTable = new DataTable(collectionName); adapter.Fill(dataTable); } catch (PgException) { throw; } catch (Exception ex) { throw new PgException(ex.Message); } finally { command.Dispose(); adapter.Dispose(); } return dataTable; } #endregion #region · Protected Methods · protected virtual string[] ParseRestrictions(string[] restrictions) { return restrictions; } #endregion } } --- NEW FILE: PgSchemaFactory.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; using System.Data; using System.Data.Common; using System.IO; using System.Reflection; using System.Xml; using PostgreSql.Data.PostgreSqlClient; namespace PostgreSql.Data.Schema { internal sealed class PgSchemaFactory { #region · Static Members · private static readonly string ResName = "PostgreSql.Data.Schema.MetaData.xml"; #endregion #region · Constructors · private PgSchemaFactory() { } #endregion #region · Static Methods · public static DataTable GetSchema(PgConnection connection, string collectionName, string[] restrictions) { string filter = String.Format("CollectionName = '{0}'", collectionName); Stream xmlStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(ResName); DataSet ds = new DataSet(); ds.ReadXml(xmlStream); DataRow[] collection = ds.Tables[DbMetaDataCollectionNames.MetaDataCollections].Select(filter); if (collection.Length != 1) { throw new NotSupportedException("Unsupported collection name."); } if (restrictions != null && restrictions.Length > (int)collection[0]["NumberOfRestrictions"]) { throw new InvalidOperationException("The number of specified restrictions is not valid."); } if (ds.Tables[DbMetaDataCollectionNames.Restrictions].Select(filter).Length != (int)collection[0]["NumberOfRestrictions"]) { throw new InvalidOperationException("Incorrect restriction definition."); } switch (collection[0]["PopulationMechanism"].ToString()) { case "PrepareCollection": return PrepareCollection(connection, collectionName, restrictions); case "DataTable": return ds.Tables[collection[0]["PopulationString"].ToString()].Copy(); case "SQLCommand": return SqlCommandCollection(connection, collectionName, (string)collection[0]["PopulationString"], restrictions); default: throw new NotSupportedException("Unsupported population mechanism"); } } #endregion #region · Schema Population Methods · private static DataTable PrepareCollection(PgConnection connection, string collectionName, string[] restrictions) { PgSchema schema = null; switch (collectionName.Trim().ToLower()) { case "tables": schema = new PgTables(); break; } return schema.GetSchema(connection, collectionName, restrictions); } private static DataTable SqlCommandCollection(PgConnection connection, string collectionName, string sql, string[] restrictions) { if (restrictions == null) { restrictions = new string[0]; } DataTable dataTable = null; PgDataAdapter adapter = null; PgCommand command = new PgCommand(String.Format(sql, restrictions), connection); try { adapter = new PgDataAdapter(command); dataTable = new DataTable(collectionName); adapter.Fill(dataTable); } catch (PgException) { throw; } catch (Exception ex) { throw new PgException(ex.Message); } finally { command.Dispose(); adapter.Dispose(); } return dataTable; } #endregion } } --- NEW FILE: MetaData.xml --- <?xml version="1.0" standalone="yes"?> <NewDataSet> <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xs:element name="NewDataSet" msdata:IsDataSet="true"> <xs:complexType> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element name="MetaDataCollections" msdata:MinimumCapacity="9"> <xs:complexType> <xs:sequence> <xs:element name="CollectionName" type="xs:string" minOccurs="0" /> <xs:element name="NumberOfRestrictions" type="xs:int" minOccurs="0" /> <xs:element name="NumberOfIdentifierParts" type="xs:int" minOccurs="0" /> <xs:element name="PopulationMechanism" type="xs:string" minOccurs="0" /> <xs:element name="PopulationString" type="xs:string" minOccurs="0" /> <xs:element name="MinimumVersion" type="xs:string" minOccurs="0" /> <xs:element name="MaximumVersion" type="xs:string" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="Restrictions" msdata:MinimumCapacity="3"> <xs:complexType> <xs:sequence> <xs:element name="CollectionName" type="xs:string" minOccurs="0" /> <xs:element name="RestrictionName" type="xs:string" minOccurs="0" /> <xs:element name="RestrictionDefault" type="xs:string" minOccurs="0" /> <xs:element name="RestrictionNumber" type="xs:int" minOccurs="0" /> <xs:element name="MinimumVersion" type="xs:string" minOccurs="0" /> <xs:element name="MaximumVersion" type="xs:string" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="DataSourceInformation" msdata:MinimumCapacity="18"> <xs:complexType> <xs:sequence> <xs:element name="CompositeIdentifierSeparatorPattern" type="xs:string" minOccurs="0" /> <xs:element name="DataSourceProductName" type="xs:string" minOccurs="0" /> <xs:element name="DataSourceProductVersion" type="xs:string" minOccurs="0" /> <xs:element name="DataSourceProductVersionNormalized" type="xs:string" minOccurs="0" /> <xs:element name="GroupByBehavior" msdata:DataType="System.Data.Common.GroupByBehavior, System.Data, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" type="xs:string" minOccurs="0" /> <xs:element name="IdentifierPattern" type="xs:string" minOccurs="0" /> <xs:element name="IdentifierCase" msdata:DataType="System.Data.Common.IdentifierCase, System.Data, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" type="xs:string" minOccurs="0" /> <xs:element name="OrderByColumnsInSelect" type="xs:boolean" minOccurs="0" /> <xs:element name="ParameterMarkerFormat" type="xs:string" minOccurs="0" /> <xs:element name="ParameterMarkerPattern" type="xs:string" minOccurs="0" /> <xs:element name="ParameterNameMaxLength" type="xs:int" minOccurs="0" /> <xs:element name="ParameterNamePattern" type="xs:string" minOccurs="0" /> <xs:element name="QuotedIdentifierPattern" type="xs:string" minOccurs="0" /> <xs:element name="QuotedIdentifierCase" msdata:DataType="System.Data.Common.IdentifierCase, System.Data, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" type="xs:string" minOccurs="0" /> <xs:element name="StatementSeparatorPattern" type="xs:string" minOccurs="0" /> <xs:element name="StringLiteralPattern" type="xs:string" minOccurs="0" /> <xs:element name="SupportedJoinOperators" msdata:DataType="System.Data.Common.SupportedJoinOperators, System.Data, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" type="xs:string" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="DataTypes" msdata:MinimumCapacity="18"> <xs:complexType> <xs:sequence> <xs:element name="TypeName" type="xs:string" minOccurs="0" /> <xs:element name="ProviderDbType" type="xs:int" minOccurs="0" /> <xs:element name="ColumnSize" type="xs:long" minOccurs="0" /> <xs:element name="CreateFormat" type="xs:string" minOccurs="0" /> <xs:element name="CreateParameters" type="xs:string" minOccurs="0" /> <xs:element name="DataType" type="xs:string" minOccurs="0" /> <xs:element name="IsAutoIncrementable" type="xs:boolean" minOccurs="0" /> <xs:element name="IsBestMatch" type="xs:boolean" minOccurs="0" /> <xs:element name="IsCaseSensitive" type="xs:boolean" minOccurs="0" /> <xs:element name="IsFixedLength" type="xs:boolean" minOccurs="0" /> <xs:element name="IsFixedPrecisionScale" type="xs:boolean" minOccurs="0" /> <xs:element name="IsLong" type="xs:boolean" minOccurs="0" /> <xs:element name="IsNullable" type="xs:boolean" minOccurs="0" /> <xs:element name="IsSearchable" type="xs:boolean" minOccurs="0" /> <xs:element name="IsSearchableWithLike" type="xs:boolean" minOccurs="0" /> <xs:element name="IsUnsigned" type="xs:boolean" minOccurs="0" /> <xs:element name="MaximumScale" type="xs:short" minOccurs="0" /> <xs:element name="MinimumScale" type="xs:short" minOccurs="0" /> <xs:element name="IsConcurrencyType" type="xs:boolean" minOccurs="0" /> <xs:element name="MaximumVersion" type="xs:string" minOccurs="0" /> <xs:element name="MinimumVersion" type="xs:string" minOccurs="0" /> <xs:element name="IsLiteralSupported" type="xs:boolean" minOccurs="0" /> <xs:element name="LiteralPrefix" type="xs:string" minOccurs="0" /> <xs:element name="LiteralSuffix" type="xs:string" minOccurs="0" /> <xs:element name="DbType" type="xs:int" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="ReservedWords" msdata:MinimumCapacity="3"> <xs:complexType> <xs:sequence> <xs:element name="ReservedWord" type="xs:string" minOccurs="0" /> <xs:element name="MaximumVersion" type="xs:string" minOccurs="0" /> <xs:element name="MinimumVersion" type="xs:string" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element> </xs:choice> </xs:complexType> </xs:element> </xs:schema> <MetaDataCollections> <CollectionName>Aggregates</CollectionName> <NumberOfRestrictions>0</NumberOfRestrictions> <NumberOfIdentifierParts>0</NumberOfIdentifierParts> <PopulationMechanism>SQLCommand</PopulationMechanism> <PopulationString>SELECT pg_aggregate.aggfnoid AS AGGREGATE_FUNCTION, pg_aggregate.aggtransfn AS TRANSITION_FUNCTION, pg_aggregate.aggfinalfn AS FINAL_FUNCTION, pg_aggregate.agginitval AS INITIAL_VALUE, pg_type.typname AS BASE_TYPE FROM pg_aggregate left join pg_type ON pg_aggregate.aggtranstype = pg_type.oid ORDER BY pg_aggregate.aggfnoid</PopulationString> </MetaDataCollections> <MetaDataCollections> <CollectionName>Casts</CollectionName> <NumberOfRestrictions>0</NumberOfRestrictions> <NumberOfIdentifierParts>0</NumberOfIdentifierParts> <PopulationMechanism>PrepareCollection</PopulationMechanism> </MetaDataCollections> <MetaDataCollections> <CollectionName>CheckConstraints</CollectionName> <NumberOfRestrictions>3</NumberOfRestrictions> <NumberOfIdentifierParts>0</NumberOfIdentifierParts> <PopulationMechanism>PrepareCollection</PopulationMechanism> </MetaDataCollections> <MetaDataCollections> <CollectionName>CheckConstraintsByTable</CollectionName> <NumberOfRestrictions>3</NumberOfRestrictions> <NumberOfIdentifierParts>0</NumberOfIdentifierParts> <PopulationMechanism>PrepareCollection</PopulationMechanism> </MetaDataCollections> <MetaDataCollections> <CollectionName>Columns</CollectionName> <NumberOfRestrictions>4</NumberOfRestrictions> <NumberOfIdentifierParts>0</NumberOfIdentifierParts> <PopulationMechanism>PrepareCollection</PopulationMechanism> </MetaDataCollections> <MetaDataCollections> <CollectionName>Databases</CollectionName> <NumberOfRestrictions>0</NumberOfRestrictions> <NumberOfIdentifierParts>0</NumberOfIdentifierParts> <PopulationMechanism>DataTable</PopulationMechanism> <PopulationString>DataSourceInformation</PopulationString> </MetaDataCollections> <MetaDataCollections> <CollectionName>DataSourceInformation</CollectionName> <NumberOfRestrictions>0</NumberOfRestrictions> <NumberOfIdentifierParts>0</NumberOfIdentifierParts> <PopulationMechanism>DataTable</PopulationMechanism> <PopulationString>DataSourceInformation</PopulationString> </MetaDataCollections> <MetaDataCollections> <CollectionName>User Defined Types</CollectionName> <NumberOfRestrictions>0</NumberOfRestrictions> <NumberOfIdentifierParts>0</NumberOfIdentifierParts> <PopulationMechanism>DataTable</PopulationMechanism> <PopulationString>DataTypes</PopulationString> </MetaDataCollections> <MetaDataCollections> <CollectionName>ForeignKeyColumns</CollectionName> <NumberOfRestrictions>5</NumberOfRestrictions> <NumberOfIdentifierParts>0</NumberOfIdentifierParts> <PopulationMechanism>PrepareCollection</PopulationMechanism> </MetaDataCollections> <MetaDataCollections> <CollectionName>ForeignKeys</CollectionName> <NumberOfRestrictions>4</NumberOfRestrictions> <NumberOfIdentifierParts>0</NumberOfIdentifierParts> <PopulationMechanism>PrepareCollection</PopulationMechanism> </MetaDataCollections> <MetaDataCollections> <CollectionName>Functions</CollectionName> <NumberOfRestrictions>0</NumberOfRestrictions> <NumberOfIdentifierParts>0</NumberOfIdentifierParts> <PopulationMechanism>PrepareCollection</PopulationMechanism> </MetaDataCollections> <MetaDataCollections> <CollectionName>Groups</CollectionName> <NumberOfRestrictions>0</NumberOfRestrictions> <NumberOfIdentifierParts>0</NumberOfIdentifierParts> <PopulationMechanism>PrepareCollection</PopulationMechanism> </MetaDataCollections> <MetaDataCollections> <CollectionName>IndexColumns</CollectionName> <NumberOfRestrictions>4</NumberOfRestrictions> <NumberOfIdentifierParts>0</NumberOfIdentifierParts> <PopulationMechanism>PrepareCollection</PopulationMechanism> </MetaDataCollections> <MetaDataCollections> <CollectionName>Indexes</CollectionName> <NumberOfRestrictions>4</NumberOfRestrictions> <NumberOfIdentifierParts>0</NumberOfIdentifierParts> <PopulationMechanism>PrepareCollection</PopulationMechanism> </MetaDataCollections> <MetaDataCollections> <CollectionName>MetaDataCollections</CollectionName> <NumberOfRestrictions>0</NumberOfRestrictions> <NumberOfIdentifierParts>0</NumberOfIdentifierParts> <PopulationMechanism>DataTable</PopulationMechanism> <PopulationString>MetaDataCollections</PopulationString> </MetaDataCollections> <MetaDataCollections> <CollectionName>PrimaryKeys</CollectionName> <NumberOfRestrictions>3</NumberOfRestrictions> <NumberOfIdentifierParts>0</NumberOfIdentifierParts> <PopulationMechanism>PrepareCollection</PopulationMechanism> </MetaDataCollections> <MetaDataCollections> <CollectionName>ReservedWords</CollectionName> <NumberOfRestrictions>0</NumberOfRestrictions> <NumberOfIdentifierParts>0</NumberOfIdentifierParts> <PopulationMechanism>DataTable</PopulationMechanism> <PopulationString>ReservedWords</PopulationString> </MetaDataCollections> <MetaDataCollections> <CollectionName>Restrictions</CollectionName> <NumberOfRestrictions>0</NumberOfRestrictions> <NumberOfIdentifierParts>0</NumberOfIdentifierParts> <PopulationMechanism>DataTable</PopulationMechanism> <PopulationString>Restrictions</PopulationString> </MetaDataCollections> <MetaDataCollections> <CollectionName>Schemas</CollectionName> <NumberOfRestrictions>0</NumberOfRestrictions> <NumberOfIdentifierParts>0</NumberOfIdentifierParts> <PopulationMechanism>PrepareCollection</PopulationMechanism> </MetaDataCollections> <MetaDataCollections> <CollectionName>SQL Languages</CollectionName> <NumberOfRestrictions>4</NumberOfRestrictions> <NumberOfIdentifierParts>0</NumberOfIdentifierParts> <PopulationMechanism>PrepareCollection</PopulationMechanism> </MetaDataCollections> <MetaDataCollections> <CollectionName>Tables</CollectionName> <NumberOfRestrictions>4</NumberOfRestrictions> <NumberOfIdentifierParts>0</NumberOfIdentifierParts> <PopulationMechanism>PrepareCollection</PopulationMechanism> </MetaDataCollections> <MetaDataCollections> <CollectionName>TableConstraints</CollectionName> <NumberOfRestrictions>7</NumberOfRestrictions> <NumberOfIdentifierParts>0</NumberOfIdentifierParts> <PopulationMechanism>PrepareCollection</PopulationMechanism> </MetaDataCollections> <MetaDataCollections> <CollectionName>TablePrivileges</CollectionName> <NumberOfRestrictions>5</NumberOfRestrictions> <NumberOfIdentifierParts>0</NumberOfIdentifierParts> <PopulationMechanism>PrepareCollection</PopulationMechanism> </MetaDataCollections> <MetaDataCollections> <CollectionName>Triggers</CollectionName> <NumberOfRestrictions>4</NumberOfRestrictions> <NumberOfIdentifierParts>0</NumberOfIdentifierParts> <PopulationMechanism>PrepareCollection</PopulationMechanism> </MetaDataCollections> <MetaDataCollections> <CollectionName>ViewColumns</CollectionName> <NumberOfRestrictions>4</NumberOfRestrictions> <NumberOfIdentifierParts>0</NumberOfIdentifierParts> <PopulationMechanism>PrepareCollection</PopulationMechanism> </MetaDataCollections> <MetaDataCollections> <CollectionName>ViewPrivileges</CollectionName> <NumberOfRestrictions>5</NumberOfRestrictions> <NumberOfIdentifierParts>0</NumberOfIdentifierParts> <PopulationMechanism>PrepareCollection</PopulationMechanism> </MetaDataCollections> <MetaDataCollections> <CollectionName>Views</CollectionName> <NumberOfRestrictions>3</NumberOfRestrictions> <NumberOfIdentifierParts>0</NumberOfIdentifierParts> <PopulationMechanism>PrepareCollection</PopulationMechanism> </MetaDataCollections> <Restrictions> <CollectionName>Tables</CollectionName> <RestrictionName>Catalog</RestrictionName> <RestrictionDefault>table_catalog</RestrictionDefault> <RestrictionNumber>1</RestrictionNumber> </Restrictions> <Restrictions> <CollectionName>Tables</CollectionName> <RestrictionName>Schema</RestrictionName> <RestrictionDefault>table_schema</RestrictionDefault> <RestrictionNumber>2</RestrictionNumber> </Restrictions> <Restrictions> <CollectionName>Tables</CollectionName> <RestrictionName>Name</RestrictionName> <RestrictionDefault>table_name</RestrictionDefault> <RestrictionNumber>3</RestrictionNumber> </Restrictions> <Restrictions> <CollectionName>Tables</CollectionName> <RestrictionName>Type</RestrictionName> <RestrictionDefault>table_type</RestrictionDefault> <RestrictionNumber>4</RestrictionNumber> </Restrictions> <DataSourceInformation> <CompositeIdentifierSeparatorPattern>.</CompositeIdentifierSeparatorPattern> <DataSourceProductName>PostgreSQL</DataSourceProductName> <DataSourceProductVersion>7.4+</DataSourceProductVersion> <DataSourceProductVersionNormalized>7.4+</DataSourceProductVersionNormalized> <GroupByBehavior>2</GroupByBehavior> <IdentifierPattern>(^\[\p{Lo}\p{Lu}\p{Ll}_@#][\p{Lo}\p{Lu}\p{Ll}\p{Nd}@$#_]*$)|(^\[[^\]\0]|\]\]+\]$)|(^\"[^\"\0]|\"\"+\"$)</IdentifierPattern> <IdentifierCase>2</IdentifierCase> <OrderByColumnsInSelect>false</OrderByColumnsInSelect> <ParameterMarkerFormat>{0}</ParameterMarkerFormat> <ParameterMarkerPattern>@[\p{Lo}\p{Lu}\p{Ll}\p{Lm}_@#][\p{Lo}\p{Lu}\p{Ll}\p{Lm}\p{Nd}\uff3f_@#\$]*(?=\s+|$)</ParameterMarkerPattern> <ParameterNameMaxLength>128</ParameterNameMaxLength> <ParameterNamePattern>^[\p{Lo}\p{Lu}\p{Ll}\p{Lm}_@#][\p{Lo}\p{Lu}\p{Ll}\p{Lm}\p{Nd}\uff3f_@#\$]*(?=\s+|$)</ParameterNamePattern> <QuotedIdentifierPattern>(([^\""|\"\")*)</QuotedIdentifierPattern> <QuotedIdentifierCase>2</QuotedIdentifierCase> <StatementSeparatorPattern>;</StatementSeparatorPattern> <StringLiteralPattern>'(([^']|'')*)'</StringLiteralPattern> <SupportedJoinOperators>15</SupportedJoinOperators> </DataSourceInformation> <DataTypes> <TypeName>char</TypeName> <ProviderDbType>3</ProviderDbType> <ColumnSize>32767</ColumnSize> <CreateFormat /> <CreateParameters>length</CreateParameters> <DataType>System.String</DataType> <IsAutoIncrementable>false</IsAutoIncrementable> <IsBestMatch>false</IsBestMatch> <IsCaseSensitive>true</IsCaseSensitive> <IsFixedLength>false</IsFixedLength> <IsFixedPrecisionScale>false</IsFixedPrecisionScale> <IsLong>false</IsLong> <IsNullable>true</IsNullable> <IsSearchable>true</IsSearchable> <IsSearchableWithLike>true</IsSearchableWithLike> <IsUnsigned>false</IsUnsigned> <MaximumScale>0</MaximumScale> <MinimumScale>0</MinimumScale> <IsConcurrencyType>false</IsConcurrencyType> <IsLiteralSupported>true</IsLiteralSupported> <LiteralPrefix>'</LiteralPrefix> <LiteralSuffix>'</LiteralSuffix> <DbType>23</DbType> </DataTypes> <ReservedWords> <ReservedWord>ACTION</ReservedWord> </ReservedWords> </NewDataSet> --- NEW FILE: PgTables.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 PgTables : PgSchema { #region · Protected 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, " + "case pg_class.relkind " + "when 'r' THEN 'TABLE' " + "when 'v' THEN 'VIEW' " + "END AS TABLE_TYPE, " + "pg_class.relhasindex AS HAS_INDEXES, " + "pg_class.relisshared AS IS_SHARED, " + "pg_class.relchecks AS CONSTRAINT_COUNT, " + "pg_class.reltriggers AS TRIGGER_COUNT, " + "pg_class.relhaspkey AS HAS_PRIMARY_KEY, " + "pg_class.relhasrules AS HAS_RULES, " + "pg_class.relhassubclass AS HAS_SUBCLASS, " + "pg_description.description AS DESCRIPTION "+ "FROM pg_class " + "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) { 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]); } // TABLE_TYPE if (restrictions.Length > 2 && restrictions[2] != null) { sql += String.Format("pg_class.relkind = '{0}'", restrictions[2]); } } return sql; } #endregion #region · Protected Methods · protected override string[] ParseRestrictions(string[] restrictions) { string[] parsed = restrictions; if (parsed != null) { if (parsed.Length == 4 && parsed[3] != null) { switch (parsed[3].ToString().ToUpper()) { case "TABLE": parsed[3] = "r"; break; case "VIEW": parsed[3] = "v"; break; } } } return parsed; } #endregion } } |