[pgsqlclient-checkins] pgsqlclient_10/source/PostgreSql/Data/DbSchema PgAggregatesSchema.cs,NONE,1.1
Status: Inactive
Brought to you by:
carlosga_fb
Update of /cvsroot/pgsqlclient/pgsqlclient_10/source/PostgreSql/Data/DbSchema In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6002 Added Files: PgAggregatesSchema.cs PgCastsSchema.cs PgCheckConstraints.cs PgCheckConstraintsByTable.cs PgColumnsSchema.cs PgDatabaseSchema.cs PgDbSchema.cs PgDbSchemaFactory.cs PgDomainsSchema.cs PgForeignKeysSchema.cs PgFunctionPrivilegesSchema.cs PgFunctionsSchema.cs PgGroupsSchema.cs PgIndexesSchema.cs PgPrimaryKeysSchema.cs PgProviderTypesSchema.cs PgSchemataSchema.cs PgSqlLanguagesSchema.cs PgTableConstraintsSchema.cs PgTablePrivilegesSchema.cs PgTablesSchema.cs PgTableStatisticsSchema.cs PgTriggersSchema.cs PgUsersSchema.cs PgViewPrivilegesSchema.cs PgViewsSchema.cs Log Message: Started the reorganization of the CVS module --- NEW FILE: PgCastsSchema.cs --- /* PgSqlClient - ADO.NET Data Provider for PostgreSQL 7.4+ * Copyright (c) 2003-2005 Carlos Guzman Alvarez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using System; using System.Data; using System.Text; namespace PostgreSql.Data.DbSchema { internal class PgCastsSchema : PgDbSchema { #region · Constructors · public PgCastsSchema() : base("Casts") { } #endregion #region · Add Methods · public override void AddTables() { AddTable("pg_cast"); } public override void AddRestrictionColumns() { } public override void AddDataColumns() { AddDataColumn("pg_typesrc.typname" , "SOURCE_TYPE"); AddDataColumn("pg_typetgt.typname" , "TARGET_TYPE"); AddDataColumn("pg_namespace.nspname", "FUNCTION_SCHEMA"); AddDataColumn("pg_proc.proname" , "FUNCTION_NAME"); AddDataColumn(this.GetContextExpression("pg_cast.castcontext"), "CAST_CONTEXT"); } public override void AddJoins() { AddJoin("left join", "pg_type as pg_typesrc", "pg_cast.castsource = pg_typesrc.oid"); AddJoin("left join", "pg_type as pg_typetgt", "pg_cast.casttarget = pg_typetgt.oid"); AddJoin("left join", "pg_proc" , "pg_cast.castfunc = pg_proc.oid"); AddJoin("left join", "pg_namespace" , "pg_proc.pronamespace = pg_namespace.oid"); } public override void AddOrderByColumns() { AddOrderBy("pg_proc.proname"); } public override void AddWhereFilters() { } #endregion #region · Parse Methods · public override string[] ParseRestrictions(string[] restrictions) { string[] parsed = restrictions; return parsed; } #endregion #region · Private Methods · private string GetContextExpression(string fieldName) { StringBuilder expression = new StringBuilder(); expression.AppendFormat(" case {0} ", fieldName); expression.Append(" when 'e' THEN 'EXPLICIT'"); expression.Append(" when 'a' THEN 'ASSIGNMENT'"); expression.Append(" when 'i' THEN 'EXPRESSIONS'"); expression.Append(" END "); return expression.ToString(); } #endregion } } --- NEW FILE: PgTriggersSchema.cs --- /* PgSqlClient - ADO.NET Data Provider for PostgreSQL 7.4+ * Copyright (c) 2003-2005 Carlos Guzman Alvarez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using System; using System.Data; using System.Text; namespace PostgreSql.Data.DbSchema { internal class PgTriggersSchema : PgDbSchema { #region · Constructors · public PgTriggersSchema() : base("Triggers") { } #endregion #region · Add Methods · public override void AddTables() { AddTable("pg_trigger"); } public override void AddRestrictionColumns() { AddRestrictionColumn("pg_namespace.nspname" , "TRIGGER_SCHEMA", null); AddRestrictionColumn("pg_proc.proname" , "TRIGGER_NAME", null); AddRestrictionColumn("pg_class.relnamespace", "TABLE_SCHEMA", null); AddRestrictionColumn("pg_class.relname" , "TABLE_NAME", null); } public override void AddDataColumns() { AddDataColumn("pg_language.lanname" , "PROCEDURE_LANGUAGE"); AddDataColumn("pg_proc.proisagg" , "IS_AGGREGATE"); AddDataColumn("pg_proc.prosecdef" , "IS_SECURITY_DEFINER"); AddDataColumn("pg_proc.proisstrict" , "IS_STRICT"); AddDataColumn("pg_proc.proretset" , "RETURNS_SET"); } public override void AddJoins() { AddJoin("left join", "pg_class" , "pg_trigger.tgconstrrelid = pg_class.oid"); AddJoin("left join", "pg_proc" , "pg_trigger.tgfoid = pg_proc.oid"); AddJoin("left join", "pg_namespace" , "pg_proc.pronamespace = pg_namespace.oid"); AddJoin("left join", "pg_language" , "pg_proc.prolang = pg_language.oid"); } public override void AddOrderByColumns() { AddOrderBy("pg_namespace.nspname"); AddOrderBy("pg_proc.proname"); } public override void AddWhereFilters() { } #endregion #region · Parse Methods · public override string[] ParseRestrictions(string[] restrictions) { string[] parsed = restrictions; return parsed; } #endregion } } --- NEW FILE: PgProviderTypesSchema.cs --- /* PgSqlClient - ADO.NET Data Provider for PostgreSQL 7.4+ * Copyright (c) 2003-2005 Carlos Guzman Alvarez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using System; using System.Data; using System.Text; namespace PostgreSql.Data.DbSchema { internal class PgProviderTypesSchema : PgDbSchema { #region · Constructors · public PgProviderTypesSchema() : base("ProviderTypes") { } #endregion #region · Add Methods · public override void AddTables() { AddTable("pg_type"); } public override void AddRestrictionColumns() { AddRestrictionColumn("pg_namespace.nspname", "TYPE_SCHEMA", null); AddRestrictionColumn("pg_type.typname", "TYPE_NAME", null); AddRestrictionColumn("pg_type.oid", "DATA_TYPE", null); } public override void AddDataColumns() { AddDataColumn("pg_type.typlen", "COLUMN_SIZE"); AddDataColumn("pg_type.typnotnull", "IS_NOT_NULL"); AddDataColumn("pg_type.typndims", "ARRAY_DIMENSIONS"); AddDataColumn("pg_type.typelem", "ELEMENT_TYPE"); AddDataColumn("pg_type.typbasetype", "BASE_TYPE"); AddDataColumn("pg_type.typtypmod", "BASE_TYPE_MODIFIER"); AddDataColumn("pg_description.description", "DESCRIPTION"); } public override void AddJoins() { AddJoin("left join", "pg_namespace", "pg_type.typnamespace = pg_namespace.oid"); AddJoin("left join", "pg_description", "pg_type.oid = pg_description.objoid"); } public override void AddOrderByColumns() { AddOrderBy("pg_type.typname"); } public override void AddWhereFilters() { } #endregion #region · Parse Methods · public override string[] ParseRestrictions(string[] restrictions) { string[] parsed = restrictions; return parsed; } #endregion } } --- NEW FILE: PgIndexesSchema.cs --- /* PgSqlClient - ADO.NET Data Provider for PostgreSQL 7.4+ * Copyright (c) 2003-2005 Carlos Guzman Alvarez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using System; using System.Data; using System.Text; namespace PostgreSql.Data.DbSchema { internal class PgIndexesSchema : PgDbSchema { #region · Constructors · public PgIndexesSchema() : base("Indexes") { } #endregion #region · Add Methods · public override void AddTables() { AddTable("pg_index"); } public override void AddRestrictionColumns() { AddRestrictionColumn("pg_namespace.nspname" , "TABLE_SCHEMA", null); AddRestrictionColumn("pg_class.relname" , "TABLE_NAME", null); AddRestrictionColumn("pg_classidx.relname" , "INDEX_NAME", null); } public override void AddDataColumns() { AddDataColumn("Pgnamespidx.nspname" , "INDEX_SCHEMA"); AddDataColumn("pg_am.amname" , "TYPE"); AddDataColumn("pg_index.indkey" , "INDEX_KEY"); AddDataColumn("pg_index.indisclustered" , "CLUSTERED"); AddDataColumn("pg_index.indisunique" , "UNIQUE"); AddDataColumn("pg_index.indisprimary" , "PRIMARY"); AddDataColumn("pg_am.amindexnulls" , "ALLOW_NULLS"); AddDataColumn("pg_am.amcanmulticol" , "MULTICOLUMN"); AddDataColumn("pg_am.amconcurrent" , "CONCURRENT"); AddDataColumn("pg_description.description", "DESCRIPTION"); } public override void AddJoins() { AddJoin("left join", "pg_class", "pg_index.indrelid = pg_class.oid"); AddJoin("left join", "pg_class as pg_classidx", "pg_index.indexrelid = pg_classidx.oid"); AddJoin("left join", "pg_namespace", "pg_classidx.relnamespace = pg_namespace.oid"); AddJoin("left join", "pg_namespace as Pgnamespidx", "pg_classidx.relnamespace = Pgnamespidx.oid"); AddJoin("left join", "pg_am", "pg_classidx.relam = pg_am.oid"); AddJoin("left join", "pg_description", "pg_index.indexrelid = pg_description.objoid"); } public override void AddOrderByColumns() { AddOrderBy("pg_namespace.nspname"); AddOrderBy("pg_class.relname"); AddOrderBy("pg_classidx.relname"); } public override void AddWhereFilters() { } #endregion #region · Parse Methods · public override string[] ParseRestrictions(string[] restrictions) { string[] parsed = restrictions; return parsed; } #endregion } } --- NEW FILE: PgTablePrivilegesSchema.cs --- /* PgSqlClient - ADO.NET Data Provider for PostgreSQL 7.4+ * Copyright (c) 2003-2005 Carlos Guzman Alvarez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using System; using System.Data; using System.Text; using System.Text.RegularExpressions; namespace PostgreSql.Data.DbSchema { internal class PgTablePrivilegesSchema : PgDbSchema { #region · Constructors · public PgTablePrivilegesSchema() : base("Table_Privileges") { } #endregion #region · Add Methods · public override void AddTables() { AddTable("pg_class"); } public override void AddRestrictionColumns() { AddRestrictionColumn("pg_namespace.nspname" , "TABLE_SCHEMA", null); AddRestrictionColumn("pg_class.relname" , "TABLE_NAME", null); } public override void AddDataColumns() { AddDataColumn("pg_class.relacl", "PRIVILEGES"); } public override void AddJoins() { AddJoin("left join", "pg_namespace", "pg_class.relnamespace = pg_namespace.oid"); } public override void AddOrderByColumns() { AddOrderBy("pg_namespace.nspname"); AddOrderBy("pg_class.relname"); } public override void AddWhereFilters() { AddWhereFilter("pg_class.relkind = 'r'"); } #endregion #region · Overriden Methods · public override DataTable GetSchema(PgConnection connection, string[] restrictions) { DataTable tablesSchema= base.GetSchema(connection, restrictions); DataTable privileges = this.GetPrivilegesDataTable(); privileges.BeginLoadData(); foreach (DataRow row in tablesSchema.Rows) { if (row["PRIVILEGES"] != System.DBNull.Value) { PgPrivilege[] priv = DecodePrivileges((string[])row["PRIVILEGES"]); for (int i = 0; i < priv.Length; i++) { DataRow newRow = privileges.NewRow(); newRow["TABLE_SCHEMA"] = row["TABLE_SCHEMA"]; newRow["TABLE_NAME"] = row["TABLE_NAME"]; newRow["USER_NAME"] = priv[i].User; FillPrivileges(newRow, priv[i].Privileges); privileges.Rows.Add(newRow); } } } privileges.EndLoadData(); return privileges; } private DataTable GetPrivilegesDataTable() { DataTable privileges = new DataTable("Table_Privileges"); privileges.BeginInit(); privileges.Columns.Add("TABLE_SCHEMA", Type.GetType("System.String")); privileges.Columns.Add("TABLE_NAME", Type.GetType("System.String")); privileges.Columns.Add("USER_NAME", Type.GetType("System.String")); AddPrivilegesColumns(privileges); privileges.EndInit(); return privileges; } #endregion #region · Parse Methods · public override string[] ParseRestrictions(string[] restrictions) { return restrictions; } #endregion } } --- NEW FILE: PgFunctionPrivilegesSchema.cs --- /* PgSqlClient - ADO.NET Data Provider for PostgreSQL 7.4+ * Copyright (c) 2003-2005 Carlos Guzman Alvarez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using System; using System.Data; using System.Text; namespace PostgreSql.Data.DbSchema { internal class PgFunctionPrivilegesSchema : PgDbSchema { #region · Constructors · public PgFunctionPrivilegesSchema() : base("Function_Privileges") { } #endregion #region · Add Methods · public override void AddTables() { AddTable("pg_proc"); } public override void AddRestrictionColumns() { AddRestrictionColumn("pg_namespace.nspname" , "FUNCTION_SCHEMA", null); AddRestrictionColumn("pg_proc.proname" , "FUNCTION_NAME", null); } public override void AddDataColumns() { AddDataColumn("pg_proc.proacl", "PRIVILEGES"); } public override void AddJoins() { AddJoin("left join", "pg_namespace" , "pg_proc.pronamespace = pg_namespace.oid"); } public override void AddOrderByColumns() { AddOrderBy("pg_namespace.nspname"); AddOrderBy("pg_proc.proname"); } public override void AddWhereFilters() { } #endregion #region · Parse Methods · public override string[] ParseRestrictions(string[] restrictions) { string[] parsed = restrictions; return parsed; } #endregion #region · Overriden Methods · public override DataTable GetSchema(PgConnection connection, string[] restrictions) { DataTable functionsSchema = base.GetSchema(connection, restrictions); DataTable privileges = this.GetPrivilegesDataTable(); privileges.BeginLoadData(); foreach (DataRow row in functionsSchema.Rows) { if (row["PRIVILEGES"] != System.DBNull.Value) { PgPrivilege[] priv = this.DecodePrivileges((string[])row["PRIVILEGES"]); for (int i = 0; i < priv.Length; i++) { DataRow newRow = privileges.NewRow(); newRow["FUNCTION_SCHEMA"] = row["FUNCTION_SCHEMA"]; newRow["FUNCTION_NAME"] = row["FUNCTION_NAME"]; newRow["USER_NAME"] = priv[i].User; this.FillPrivileges(newRow, priv[i].Privileges); privileges.Rows.Add(newRow); } } } privileges.EndLoadData(); return privileges; } private DataTable GetPrivilegesDataTable() { DataTable privileges = new DataTable("Function_Privileges"); privileges.BeginInit(); privileges.Columns.Add("FUNCTION_SCHEMA", Type.GetType("System.String")); privileges.Columns.Add("FUNCTION_NAME" , Type.GetType("System.String")); privileges.Columns.Add("USER_NAME" , Type.GetType("System.String")); this.AddPrivilegesColumns(privileges); privileges.EndInit(); return privileges; } #endregion #region · Private Methods · private string GetVolatileExpression(string fieldName) { StringBuilder expression = new StringBuilder(); expression.AppendFormat(" case {0} ", fieldName); expression.Append(" when 'i' THEN 'INMUTABLE'"); expression.Append(" when 's' THEN 'STABLE'"); expression.Append(" when 'v' THEN 'VOLATILE'"); expression.Append(" END "); return expression.ToString(); } #endregion } } --- NEW FILE: PgUsersSchema.cs --- /* PgSqlClient - ADO.NET Data Provider for PostgreSQL 7.4+ * Copyright (c) 2003-2005 Carlos Guzman Alvarez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using System; using System.Data; using System.Text; namespace PostgreSql.Data.DbSchema { internal class PgUsersSchema : PgDbSchema { #region · Constructors · public PgUsersSchema() : base("Users") { } #endregion #region · Add Methods · public override void AddTables() { AddTable("pg_shadow"); } public override void AddRestrictionColumns() { AddRestrictionColumn("pg_shadow.usename", "USER_NAME", null); } public override void AddDataColumns() { AddDataColumn("pg_shadow.usecreatedb", "CREATE_DATABASE"); AddDataColumn("pg_shadow.usesuper", "IS_SUPERUSER"); AddDataColumn("pg_shadow.usecatupd", "UPDATE_SYSCATALOGS"); AddDataColumn("pg_shadow.passwd", "PASSWORD"); AddDataColumn("pg_shadow.useconfig", "CONFIGURATION"); } public override void AddJoins() { } public override void AddOrderByColumns() { AddOrderBy("pg_shadow.usename"); } public override void AddWhereFilters() { } #endregion #region · Parse Methods · public override string[] ParseRestrictions(string[] restrictions) { string[] parsed = restrictions; return parsed; } #endregion } } --- NEW FILE: PgForeignKeysSchema.cs --- /* PgSqlClient - ADO.NET Data Provider for PostgreSQL 7.4+ * Copyright (c) 2003-2005 Carlos Guzman Alvarez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using System; using System.Data; using System.Text; namespace PostgreSql.Data.DbSchema { internal class PgForeignKeysSchema : PgDbSchema { #region · Constructors · public PgForeignKeysSchema() : base("ForeignKeys") { } #endregion #region · Add Methods · public override void AddTables() { AddTable("pg_constraint"); } public override void AddRestrictionColumns() { AddRestrictionColumn("pg_namespace.nspname" , "PK_TABLE_SCHEMA", null); AddRestrictionColumn("pk_table.relname" , "PK_TABLE_NAME", null); AddRestrictionColumn("pg_namespace.nspname" , "FK_TABLE_SCHEMA", null); AddRestrictionColumn("fk_table.relname" , "FK_TABLE_NAME", null); } public override void AddDataColumns() { AddDataColumn("pg_constraint.conkey" , "PK_COLUMNS"); AddDataColumn("pg_constraint.confkey" , "FK_COLUMNS"); AddDataColumn(this.GetRuleExpression("pg_constraint.confupdtype"), "UPDATE_RULE"); AddDataColumn(this.GetRuleExpression("pg_constraint.confdeltype"), "DELETE_RULE"); AddDataColumn("pg_constraint.conname" , "FK_NAME"); AddDataColumn("pg_constraint.condeferrable" , "DEFERRABILITY"); AddDataColumn("pg_constraint.condeferred" , "IS_DEFERRED"); AddDataColumn("pg_description.description" , "DESCRIPTION"); } public override void AddJoins() { AddJoin("left join" , "pg_namespace", "pg_constraint.connamespace = pg_namespace.oid"); AddJoin("left join" , "pg_class as pk_table", "pg_constraint.conrelid = pk_table.oid"); AddJoin("right join", "pg_class as fk_table", "pg_constraint.confrelid = fk_table.oid"); AddJoin("left join" , "pg_description", "pg_constraint.oid = pg_description.objoid"); } public override void AddOrderByColumns() { AddOrderBy("pg_namespace.nspname"); AddOrderBy("pk_table.relname"); AddOrderBy("pg_constraint.conname"); } public override void AddWhereFilters() { // Get Only Primary Key information AddWhereFilter("pg_constraint.contype = 'f'"); } #endregion #region · Parse Methods · public override string[] ParseRestrictions(string[] restrictions) { string[] parsed = restrictions; return parsed; } #endregion #region · Private Methods · private string GetRuleExpression(string fieldName) { StringBuilder expression = new StringBuilder(); expression.AppendFormat(" case {0} ", fieldName); expression.Append(" when 'a' THEN 'NO ACTION'"); expression.Append(" when 'r' THEN 'RESTRICT'"); expression.Append(" when 'c' THEN 'CASCADE'"); expression.Append(" when 'd' THEN 'SET DEFAULT'"); expression.Append(" when 'n' THEN 'SET NULL'"); expression.Append(" END "); return expression.ToString(); } #endregion } } --- NEW FILE: PgFunctionsSchema.cs --- /* PgSqlClient - ADO.NET Data Provider for PostgreSQL 7.4+ * Copyright (c) 2003-2005 Carlos Guzman Alvarez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using System; using System.Data; using System.Text; namespace PostgreSql.Data.DbSchema { internal class PgFunctionsSchema : PgDbSchema { #region · Constructors · public PgFunctionsSchema() : base("Functions") { } #endregion #region · Add Methods · public override void AddTables() { AddTable("pg_proc"); } public override void AddRestrictionColumns() { AddRestrictionColumn("pg_namespace.nspname" , "FUNCTION_SCHEMA", null); AddRestrictionColumn("pg_proc.proname" , "FUNCTION_NAME", null); } public override void AddDataColumns() { AddDataColumn("pg_language.lanname" , "PROCEDURE_LANGUAGE"); AddDataColumn("pg_proc.proisagg" , "IS_AGGREGATE"); AddDataColumn("pg_proc.prosecdef" , "IS_SECURITY_DEFINER"); AddDataColumn("pg_proc.proisstrict" , "IS_STRICT"); AddDataColumn(this.GetVolatileExpression("pg_proc.provolatile"), "VOLATILE"); AddDataColumn("pg_proc.proretset" , "RETURNS_SET"); AddDataColumn("pg_proc.prorettype" , "RETURN_TYPE"); AddDataColumn("pg_proc.pronargs" , "ARGUMENT_NUMBER"); AddDataColumn("pg_proc.proargtypes" , "ARGUMENTS"); AddDataColumn("pg_proc.prosrc" , "SOURCE"); AddDataColumn("pg_description.description", "DESCRIPTION"); } public override void AddJoins() { AddJoin("left join", "pg_namespace" , "pg_proc.pronamespace = pg_namespace.oid"); AddJoin("left join", "pg_language" , "pg_proc.prolang = pg_language.oid"); AddJoin("left join", "pg_description", "pg_proc.oid = pg_description.objoid"); } public override void AddOrderByColumns() { AddOrderBy("pg_namespace.nspname"); AddOrderBy("pg_proc.proname"); } public override void AddWhereFilters() { } #endregion #region · Parse Methods · public override string[] ParseRestrictions(string[] restrictions) { string[] parsed = restrictions; return parsed; } #endregion #region · Private Methods · private string GetVolatileExpression(string fieldName) { StringBuilder expression = new StringBuilder(); expression.AppendFormat(" case {0} ", fieldName); expression.Append(" when 'i' THEN 'INMUTABLE'"); expression.Append(" when 's' THEN 'STABLE'"); expression.Append(" when 'v' THEN 'VOLATILE'"); expression.Append(" END "); return expression.ToString(); } #endregion } } --- NEW FILE: PgCheckConstraints.cs --- /* PgSqlClient - ADO.NET Data Provider for PostgreSQL 7.4+ * Copyright (c) 2003-2005 Carlos Guzman Alvarez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using System; using System.Data; using System.Text; namespace PostgreSql.Data.DbSchema { internal class PgCheckConstraintsSchema : PgDbSchema { #region · Constructors · public PgCheckConstraintsSchema() : base("CheckConstraints") { } #endregion #region · Add Methods · public override void AddTables() { AddTable("pg_constraint"); } public override void AddRestrictionColumns() { AddRestrictionColumn("pg_namespace.nspname", "CONSTRAINT_SCHEMA", null); AddRestrictionColumn("pg_constraint.conname", "CONSTRAINT_NAME", null); } public override void AddDataColumns() { AddDataColumn("pg_get_constraintdef(pg_constraint.oid)", "CHECK_CLAUSULE"); AddDataColumn("pg_description.description", "DESCRIPTION"); } public override void AddJoins() { AddJoin("left join", "pg_namespace" , "pg_constraint.connamespace = pg_namespace.oid"); AddJoin("left join", "pg_description" , "pg_constraint.oid = pg_description.objoid"); } public override void AddOrderByColumns() { AddOrderBy("pg_namespace.nspname"); AddOrderBy("pg_constraint.conname"); } public override void AddWhereFilters() { AddWhereFilter("pg_constraint.contype = 'c'"); } #endregion #region · Parse Methods · public override string[] ParseRestrictions(string[] restrictions) { string[] parsed = restrictions; if (parsed != null) { if (parsed.Length == 7 && parsed[6] != null) { switch (parsed[6].ToString().ToUpper()) { case "UNIQUE": parsed[3] = "u"; break; case "PRIMARY KEY": parsed[3] = "p"; break; case "FOREIGN KEY": parsed[3] = "f"; break; case "CHECK": parsed[3] = "c"; break; } } } return parsed; } #endregion #region · Private Methods · private string GetConstraintTypeExpression(string fieldName) { StringBuilder expression = new StringBuilder(); expression.AppendFormat(" case {0} ", fieldName); expression.Append(" when 'u' THEN 'UNIQUE'"); expression.Append(" when 'p' THEN 'PRIMARY KEY'"); expression.Append(" when 'f' THEN 'FOREIGN KEY'"); expression.Append(" when 'c' THEN 'CHECK'"); expression.Append(" END "); return expression.ToString(); } #endregion } } --- NEW FILE: PgColumnsSchema.cs --- /* PgSqlClient - ADO.NET Data Provider for PostgreSQL 7.4+ * Copyright (c) 2003-2005 Carlos Guzman Alvarez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using System; using System.Data; using System.Text; namespace PostgreSql.Data.DbSchema { internal class PgColumnsSchema : PgDbSchema { #region · Constructors · public PgColumnsSchema() : base("Columns") { } #endregion #region · Add Methods · public override void AddTables() { AddTable("pg_attribute"); } public override void AddRestrictionColumns() { AddRestrictionColumn("pg_namespace.nspname" , "TABLE_SCHEMA", null); AddRestrictionColumn("pg_class.relname" , "TABLE_NAME", null); AddRestrictionColumn("pg_attribute.attname" , "COLUMN_NAME", null); } public override void AddDataColumns() { AddDataColumn("pg_attribute.atttypid" , "DATA_TYPE"); AddDataColumn("pg_attribute.attlen" , "COLUMN_SIZE"); AddDataColumn("pg_attribute.attndims" , "COLUMN_DIMENSIONS"); AddDataColumn("pg_attribute.attnum" , "ORDINAL_POSITION"); AddDataColumn("pg_attribute.atthasdef" , "HAS_DEFAULT"); AddDataColumn("pg_attrdef.adsrc" , "COLUMN_DEFAULT"); AddDataColumn("pg_attribute.attnotnull" , "IS_NOT_NULL"); AddDataColumn("(pg_depend.objid is not null)", "IS_AUTOINCREMENT"); AddDataColumn(this.GetStorageExpression("pg_attribute.attstorage"), "STORAGE"); AddDataColumn("pg_description.description", "DESCRIPTION"); } public override void AddJoins() { AddJoin("left join", "pg_class" , "pg_attribute.attrelid = pg_class.oid"); AddJoin("left join", "pg_namespace" , "pg_class.relnamespace = pg_namespace.oid"); AddJoin("left join", "pg_attrdef" , "(pg_class.oid = pg_attrdef.adrelid AND pg_attribute.attnum = pg_attrdef.adnum)"); AddJoin("left join", "pg_description", "(pg_attribute.attrelid = pg_description.objoid AND pg_attribute.attnum = pg_description.objsubid)"); AddJoin("left join", "pg_depend", "(pg_attribute.attrelid = pg_depend.refobjid AND pg_attribute.attnum = pg_depend.refobjsubid AND pg_depend.deptype = 'i')"); } public override void AddOrderByColumns() { AddOrderBy("pg_namespace.nspname"); AddOrderBy("pg_class.relname"); AddOrderBy("pg_attribute.attnum"); } public override void AddWhereFilters() { // Do not get dropped columns AddWhereFilter("pg_attribute.attisdropped = false"); // Get only columns with a number > 0 AddWhereFilter("pg_attribute.attnum > 0"); } #endregion #region · Parse Methods · public override string[] ParseRestrictions(string[] restrictions) { string[] parsed = restrictions; return parsed; } #endregion #region · Private Methods · private string GetSerialExpression(string fieldName) { StringBuilder expression = new StringBuilder(); expression.AppendFormat(" case {0} ", fieldName); expression.Append(" when 0 THEN true"); expression.Append(" default THEN false"); expression.Append(" END "); return expression.ToString(); } private string GetStorageExpression(string fieldName) { StringBuilder expression = new StringBuilder(); expression.AppendFormat(" case {0} ", fieldName); expression.Append(" when 'p' THEN 'PLAIN'"); expression.Append(" when 'e' THEN 'EXTERNAL'"); expression.Append(" when 'm' THEN 'MAIN'"); expression.Append(" when 'x' THEN 'EXTENDED'"); expression.Append(" END "); return expression.ToString(); } #endregion } } --- NEW FILE: PgGroupsSchema.cs --- /* PgSqlClient - ADO.NET Data Provider for PostgreSQL 7.4+ * Copyright (c) 2003-2005 Carlos Guzman Alvarez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using System; using System.Data; using System.Text; namespace PostgreSql.Data.DbSchema { internal class PgGroupsSchema : PgDbSchema { #region · Constructors · public PgGroupsSchema() : base("Groups") { } #endregion #region · Add Methods · public override void AddTables() { AddTable("pg_group"); } public override void AddRestrictionColumns() { AddRestrictionColumn("pg_group.groname", "GROUP_NAME", null); } public override void AddDataColumns() { AddRestrictionColumn("pg_group.grolist", "GROUP_USERS", null); } public override void AddJoins() { } public override void AddOrderByColumns() { AddOrderBy("pg_group.groname"); } public override void AddWhereFilters() { } #endregion #region · Parse Methods · public override string[] ParseRestrictions(string[] restrictions) { string[] parsed = restrictions; return parsed; } #endregion } } --- NEW FILE: PgDbSchemaFactory.cs --- /* PgSqlClient - ADO.NET Data Provider for PostgreSQL 7.4+ * Copyright (c) 2003-2005 Carlos Guzman Alvarez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using System; namespace PostgreSql.Data.DbSchema { internal class PgDbSchemaFactory { public static PgDbSchema GetSchema(string collectionName) { PgDbSchema returnSchema = null; switch (collectionName.ToLower()) { case "aggregates": returnSchema = new PgAggregatesSchema(); break; case "casts": returnSchema = new PgCastsSchema(); break; case "checkconstraints": returnSchema = new PgCheckConstraintsSchema(); break; case "checkconstraintsbytable": returnSchema = new PgCheckConstraintsByTableSchema(); break; case "columns": returnSchema = new PgColumnsSchema(); break; case "database": returnSchema = new PgDatabaseSchema(); break; case "domains": returnSchema = new PgDomainsSchema(); break; case "foreignkeys": returnSchema = new PgForeignKeysSchema(); break; case "groups": returnSchema = new PgGroupsSchema(); break; case "indexes": returnSchema = new PgIndexesSchema(); break; case "primarykeys": returnSchema = new PgPrimaryKeysSchema(); break; case "functionprivileges": returnSchema = new PgFunctionPrivilegesSchema(); break; case "functions": returnSchema = new PgFunctionsSchema(); break; case "providertypes": returnSchema = new PgProviderTypesSchema(); break; case "schemata": returnSchema = new PgSchemataSchema(); break; case "sqllanguages": returnSchema = new PgSqlLanguagesSchema(); break; case "statistics": break; case "tables": returnSchema = new PgTablesSchema(); break; case "tableconstraint": returnSchema = new PgTableConstraintsSchema(); break; case "tablesinfo": break; case "tableprivileges": returnSchema = new PgTablePrivilegesSchema(); break; case "tablestatistics": break; case "triggers": returnSchema = new PgTriggersSchema(); break; case "users": returnSchema = new PgUsersSchema(); break; case "views": returnSchema = new PgViewsSchema(); break; case "viewprivileges": returnSchema = new PgViewPrivilegesSchema(); break; } return returnSchema; } } } --- NEW FILE: PgCheckConstraintsByTable.cs --- /* PgSqlClient - ADO.NET Data Provider for PostgreSQL 7.4+ * Copyright (c) 2003-2005 Carlos Guzman Alvarez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using System; using System.Data; using System.Text; namespace PostgreSql.Data.DbSchema { internal class PgCheckConstraintsByTableSchema : PgDbSchema { #region · Constructors · public PgCheckConstraintsByTableSchema() : base("CheckConstraintsByTable") { } #endregion #region · Add Methods · public override void AddTables() { AddTable("pg_constraint"); } public override void AddRestrictionColumns() { AddRestrictionColumn("pg_namespace.nspname" , "CONSTRAINT_SCHEMA" , null); AddRestrictionColumn("pg_constraint.conname", "CONSTRAINT_NAME" , null); AddRestrictionColumn("tbn.nspname" , "TABLE_SCHEMA" , null); AddRestrictionColumn("pg_class.relname" , "TABLE_NAME" , null); } public override void AddDataColumns() { AddDataColumn("pg_get_constraintdef(pg_constraint.oid)", "CHECK_CLAUSULE"); AddDataColumn("pg_description.description", "DESCRIPTION"); } public override void AddJoins() { AddJoin("left join", "pg_class" , "pg_class.oid = pg_constraint.conrelid"); AddJoin("left join", "pg_namespace tbn" , "pg_class.relnamespace = tbn.oid"); AddJoin("left join", "pg_namespace" , "pg_constraint.connamespace = pg_namespace.oid"); AddJoin("left join", "pg_description" , "pg_constraint.oid = pg_description.objoid"); } public override void AddOrderByColumns() { AddOrderBy("pg_namespace.nspname"); AddOrderBy("pg_class.relname"); AddOrderBy("pg_constraint.conname"); } public override void AddWhereFilters() { AddWhereFilter("pg_constraint.contype = 'c'"); AddWhereFilter("pg_class.relkind = 'r'"); } #endregion #region · Parse Methods · public override string[] ParseRestrictions(string[] restrictions) { string[] parsed = restrictions; if (parsed != null) { if (parsed.Length == 7 && parsed[6] != null) { switch (parsed[6].ToString().ToUpper()) { case "UNIQUE": parsed[3] = "u"; break; case "PRIMARY KEY": parsed[3] = "p"; break; case "FOREIGN KEY": parsed[3] = "f"; break; case "CHECK": parsed[3] = "c"; break; } } } return parsed; } #endregion #region · Private Methods · private string GetConstraintTypeExpression(string fieldName) { StringBuilder expression = new StringBuilder(); expression.AppendFormat(" case {0} ", fieldName); expression.Append(" when 'u' THEN 'UNIQUE'"); expression.Append(" when 'p' THEN 'PRIMARY KEY'"); expression.Append(" when 'f' THEN 'FOREIGN KEY'"); expression.Append(" when 'c' THEN 'CHECK'"); expression.Append(" END "); return expression.ToString(); } #endregion } } --- NEW FILE: PgPrimaryKeysSchema.cs --- /* PgSqlClient - ADO.NET Data Provider for PostgreSQL 7.4+ * Copyright (c) 2003-2005 Carlos Guzman Alvarez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using System; using System.Data; using System.Text; namespace PostgreSql.Data.DbSchema { internal class PgPrimaryKeysSchema : PgDbSchema { #region · Constructors · public PgPrimaryKeysSchema() : base("PrimaryKeys") { } #endregion #region · Add Methods · public override void AddTables() { AddTable("pg_constraint"); } public override void AddRestrictionColumns() { AddRestrictionColumn("pg_namespace.nspname" , "TABLE_SCHEMA", null); AddRestrictionColumn("pg_class.relname" , "TABLE_NAME", null); } public override void AddDataColumns() { AddDataColumn("pg_constraint.conname" , "PK_NAME"); AddDataColumn("pg_constraint.conkey" , "PK_COLUMNS"); AddDataColumn("pg_description.description", "DESCRIPTION"); } public override void AddJoins() { AddJoin("left join", "pg_class", "pg_constraint.conrelid = pg_class.oid"); AddJoin("left join", "pg_namespace", "pg_constraint.connamespace = pg_namespace.oid"); AddJoin("left join", "pg_description", "pg_constraint.oid = pg_description.objoid"); } public override void AddOrderByColumns() { AddOrderBy("pg_namespace.nspname"); AddOrderBy("pg_class.relname"); AddOrderBy("pg_constraint.conname"); } public override void AddWhereFilters() { // Get Only Primary Key information AddWhereFilter("pg_constraint.contype = 'p'"); } #endregion #region · Parse Methods · public override string[] ParseRestrictions(string[] restrictions) { string[] parsed = restrictions; return parsed; } #endregion } } --- NEW FILE: PgDbSchema.cs --- /* PgSqlClient - ADO.NET Data Provider for PostgreSQL 7.4+ * Copyright (c) 2003-2005 Carlos Guzman Alvarez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using System; using System.Data; using System.Text; using System.Text.RegularExpressions; using System.Collections; namespace PostgreSql.Data.DbSchema { #region Structures internal struct PgColumn { public string ColumnName; public string ColumnAlias; public string WhereColumnName; } internal struct PgTableJoin { public string JoinType; public string RightTable; public string Expression; } internal struct PgPrivilege { public string User; public MatchCollection Privileges; } #endregion internal abstract class PgDbSchema { #region · Fields · private ArrayList restrictionColumns; private ArrayList dataColumns; private ArrayList tables; private ArrayList joins; private ArrayList orderByColumns; private ArrayList whereFilters; private string tableName; #endregion #region · Properties · public ArrayList RestrictionColumns { get { return restrictionColumns; } } #endregion #region · Constructors · public PgDbSchema() { this.restrictionColumns = new ArrayList(); this.dataColumns = new ArrayList(); this.tables = new ArrayList(); this.joins = new ArrayList(); this.orderByColumns = new ArrayList(); this.whereFilters = new ArrayList(); this.AddTables(); this.AddRestrictionColumns(); this.AddDataColumns(); this.AddJoins(); this.AddOrderByColumns(); this.AddWhereFilters(); } public PgDbSchema(string tableName) : this() { this.tableName = tableName; } #endregion #region Abstract Methods public abstract void AddTables(); public abstract void AddRestrictionColumns(); public abstract void AddDataColumns(); public abstract void AddJoins(); public abstract void AddOrderByColumns(); public abstract void AddWhereFilters(); public abstract string[] ParseRestrictions(string[] restrictions); #endregion #region · Add Methods · public void AddTable(string tableName) { tables.Add(tableName); } public void AddRestrictionColumn(string columnName, string columnAlias, string whereColumnName) { PgColumn column = new PgColumn(); column.ColumnName = columnName; column.ColumnAlias = columnAlias; if (whereColumnName != null) { column.WhereColumnName = whereColumnName; } else { column.WhereColumnName = columnName; } restrictionColumns.Add(column); } public void AddDataColumn(string columnName, string columnAlias) { PgColumn column = new PgColumn(); column.ColumnName = columnName; column.ColumnAlias = columnAlias; dataColumns.Add(column); } public void AddJoin(string joinType, string rightTable, string expression) { PgTableJoin join = new PgTableJoin(); join.JoinType = joinType; join.RightTable = rightTable; join.Expression = expression; joins.Add(join); } public void AddOrderBy(string column) { orderByColumns.Add(column); } public void AddWhereFilter(string filter) { whereFilters.Add(filter); } #endregion #region · Methods · public virtual DataTable GetSchema(PgConnection connection, string[] restrictions) { restrictions = this.ParseRestrictions(restrictions); DataSet dataSet = null; PgDataAdapter adapter = null; PgCommand command = new PgCommand(); try { command.Connection = connection; command.CommandText = GetCommandText(restrictions); if (connection.InternalConnection.HasActiveTransaction) { command.Transaction = connection.InternalConnection.ActiveTransaction; } adapter = new PgDataAdapter(command); dataSet = new DataSet(tableName); adapter.Fill(dataSet, tableName); } catch (PgException pgex) { throw pgex; } catch (Exception ex) { throw new PgException(ex.Message); } finally { command.Dispose(); adapter.Dispose(); } return dataSet.Tables[tableName]; } public string GetCommandText(object[] restrictions) { StringBuilder sql = new StringBuilder(); // Add restriction columns sql.Append("SELECT "); foreach (PgColumn column in restrictionColumns) { sql.AppendFormat("{0} AS {1}", column.ColumnName, column.ColumnAlias); if ((restrictionColumns.IndexOf(column) + 1) < restrictionColumns.Count) { sql.Append(", "); } } // Add DataColumns if (restrictionColumns.Count > 0 && dataColumns.Count > 0) { sql.Append(", "); } foreach (PgColumn column in dataColumns) { sql.AppendFormat("{0} AS {1}", column.ColumnName, column.ColumnAlias); if ((dataColumns.IndexOf(column) + 1) < dataColumns.Count) { sql.Append(", "); } } // Add tables sql.Append(" FROM "); foreach (string table in tables) { sql.Append(table); if ((tables.IndexOf(table) + 1) < tables.Count) { sql.Append(", "); } } if (joins.Count != 0) { foreach (PgTableJoin join in joins) { sql.AppendFormat(" {0} {1} ON {2}", join.JoinType, join.RightTable, join.Expression); } } // Add restrictions StringBuilder whereFilter = new StringBuilder(); if (restrictions != null && restrictions.Length > 0) { for (int i = 0; i < restrictions.Length; i++) { if (restrictions[i] != null) { if (whereFilter.Length > 0) { whereFilter.Append(" AND "); } whereFilter.AppendFormat("{0} = '{1}'", ((PgColumn)restrictionColumns[i]).WhereColumnName, restrictions[i]); } } } if (whereFilters != null && whereFilters.Count > 0) { foreach (string condition in whereFilters) { if (whereFilter.Length > 0) { whereFilter.Append(" AND "); } whereFilter.Append(condition); } } if (whereFilter.Length > 0) { sql.AppendFormat(" WHERE {0}", whereFilter); } // Add Order By if (orderByColumns.Count > 0) { sql.Append(" ORDER BY "); foreach (string columnName in orderByColumns) { sql.Append(columnName); if ((orderByColumns.IndexOf(columnName) + 1) < orderByColumns.Count) { sql.Append(", "); } } } return sql.ToString(); } #endregion #region Protected Methods protected void AddPrivilegesColumns(DataTable table) { table.Columns.Add("INSERT", Type.GetType("System.Boolean")); table.Columns["INSERT"].DefaultValue = false; table.Columns.Add("INSERT_WITH_GRANT", Type.GetType("System.Boolean")); table.Columns["INSERT_WITH_GRANT"].DefaultValue = false; table.Columns.Add("SELECT", Type.GetType("System.Boolean")); table.Columns["SELECT"].DefaultValue = false; table.Columns.Add("SELECT_WITH_GRANT", Type.GetType("System.Boolean")); table.Columns["SELECT_WITH_GRANT"].DefaultValue = false; table.Columns.Add("UPDATE", Type.GetType("System.Boolean")); table.Columns["UPDATE"].DefaultValue = false; table.Columns.Add("UPDATE_WITH_GRANT", Type.GetType("System.Boolean")); table.Columns["UPDATE_WITH_GRANT"].DefaultValue = false; table.Columns.Add("DELETE", Type.GetType("System.Boolean")); table.Columns["DELETE"].DefaultValue = false; table.Columns.Add("DELETE_WITH_GRANT", Type.GetType("System.Boolean")); table.Columns["DELETE_WITH_GRANT"].DefaultValue = false; table.Columns.Add("RULE", Type.GetType("System.Boolean")); table.Columns["RULE"].DefaultValue = false; table.Columns.Add("RULE_WITH_GRANT", Type.GetType("System.Boolean")); table.Columns["RULE_WITH_GRANT"].DefaultValue = false; table.Columns.Add("REFERENCES", Type.GetType("System.Boolean")); table.Columns["REFERENCES"].DefaultValue = false; table.Columns.Add("REFERENCES_WITH_GRANT", Type.GetType("System.Boolean")); table.Columns["REFERENCES_WITH_GRANT"].DefaultValue = false; table.Columns.Add("TRIGGER", Type.GetType("System.Boolean")); table.Columns["TRIGGER"].DefaultValue = false; table.Columns.Add("TRIGGER_WITH_GRANT", Type.GetType("System.Boolean")); table.Columns["TRIGGER_WITH_GRANT"].DefaultValue = false; } protected PgPrivilege[] DecodePrivileges(string[] acl) { Regex search = new Regex(@"((a|r|w|d|R|x|t)\*?)"); PgPrivilege[] priv = new PgPrivilege[acl.Length]; for (int i = 0; i < acl.Length; i++) { priv[i].User = acl[i].Split('=')[0]; if (priv[i].User.Length == 0) { priv[i].User = "PUBLIC"; } string aclitem = acl[i].Split('=')[1]; aclitem = aclitem.Split('/')[0]; priv[i].Privileges = search.Matches(aclitem); } return priv; } protected void FillPrivileges(DataRow row, MatchCollection privileges) { foreach (Match privilege in privileges) { switch (privilege.Value) { case "a": case "a*": row["INSERT"] = true; if (privilege.Value.IndexOf("*") != -1) { row["INSERT_WITH_GRANT"] = true; } break; case "r": case "r*": row["SELECT"] = true; if (privilege.Value.IndexOf("*") != -1) { row["SELECT_WITH_GRANT"] = true; } break; case "w": case "w*": row["UPDATE"] = true; if (privilege.Value.IndexOf("*") != -1) { row["UPDATE_WITH_GRANT"] = true; } break; case "d": case "d*": row["DELETE"] = true; if (privilege.Value.IndexOf("*") != -1) { row["DELETE_WITH_GRANT"] = false; } break; case "R": case "R*": row["RULE"] = true; if (privilege.Value.IndexOf("*") != -1) { row["RULE_WITH_GRANT"] = true; } break; case "x": case "x*": row["REFERENCES"] = true; if (privilege.Value.IndexOf("*") != -1) { row["REFERENCES_WITH_GRANT"] = true; } break; case "t": case "t*": row["TRIGGER"] = true; if (privilege.Value.IndexOf("*") != -1) { row["TRIGGER_WITH_GRANT"] = true; } break; } } } #endregion } } --- NEW FILE: PgDatabaseSchema.cs --- /* PgSqlClient - ADO.NET Data Provider for PostgreSQL 7.4+ * Copyright (c) 2003-2005 Carlos Guzman Alvarez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using System; using System.Data; using System.Text; namespace PostgreSql.Data.DbSchema { internal class PgDatabaseSchema : PgDbSchema { #region · Constructors · public PgDatabaseSchema() : base("Database") { } #endregion #region · Add Methods · public override void AddTables() { AddTable("pg_database"); } public override void AddRestrictionColumns() { AddRestrictionColumn("pg_database.datname", "DATABASE_NAME", null); } public override void AddDataColumns() { AddDataColumn("pg_database.datistemplate" , "IS_TEMPLATE"); AddDataColumn("pg_database.datallowconn" , "ALLOW_CONNECTION"); AddDataColumn("pg_database.datconfig" , "DATABASE_CONFIG"); } public override void AddJoins() { } public override void AddOrderByColumns() { } public override void AddWhereFilters() { } #endregion #region · Parse Methods · public override string[] ParseRestrictions(string[] restrictions) { string[] parsed = restrictions; return parsed; } #endregion } } --- NEW FILE: PgSqlLanguagesSchema.cs --- /* PgSqlClient - ADO.NET Data Provider for PostgreSQL 7.4+ * Copyright (c) 2003-2005 Carlos Guzman Alvarez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using System; using System.Data; using System.Text; namespace PostgreSql.Data.DbSchema { internal class PgSqlLanguagesSchema : PgDbSchema { #region · Constructors · public PgSqlLanguagesSchema() : base("SqlLanguages") { } #endregion #region · Add Methods · public override void AddTables() { AddTable("pg_language"); } public override void AddRestrictionColumns() { } public override void AddDataColumns() { AddDataColumn("pg_language.lanname", ... [truncated message content] |