From: <car...@us...> - 2006-04-11 14:56:15
|
Revision: 90 Author: carlosga_fb Date: 2006-04-11 07:56:02 -0700 (Tue, 11 Apr 2006) ViewCVS: http://svn.sourceforge.net/pgsqlclient/?rev=90&view=rev Log Message: ----------- ?\194?\183 Database Schema Fixes Modified Paths: -------------- trunk/PostgreSqlClient/source/PostgreSql/Data/Schema/PgColumns.cs trunk/PostgreSqlClient/source/PostgreSql/Data/Schema/PgTables.cs Modified: trunk/PostgreSqlClient/source/PostgreSql/Data/Schema/PgColumns.cs =================================================================== --- trunk/PostgreSqlClient/source/PostgreSql/Data/Schema/PgColumns.cs 2006-04-11 12:43:34 UTC (rev 89) +++ trunk/PostgreSqlClient/source/PostgreSql/Data/Schema/PgColumns.cs 2006-04-11 14:56:02 UTC (rev 90) @@ -25,6 +25,7 @@ protected override string BuildSql(string[] restrictions) { + string where = ""; string sql = "SELECT " + "table_catalog, " + @@ -54,29 +55,45 @@ // TABLE_CATALOG if (restrictions.Length > 0 && restrictions[0] != null) { - sql += String.Format(" and table_catalog = '{0}'", restrictions[0]); + if (where.Length > 0) + { + where += " and "; + } + where += String.Format(" and table_catalog = '{0}'", restrictions[0]); } // TABLE_SCHEMA if (restrictions.Length > 1 && restrictions[1] != null) { - sql += String.Format(" and table_schema = '{0}'", restrictions[1]); + if (where.Length > 0) + { + where += " and "; + } + where += String.Format(" and table_schema = '{0}'", restrictions[1]); } // TABLE_NAME if (restrictions.Length > 2 && restrictions[2] != null) { - sql += String.Format(" and table_name = '{0}'", restrictions[2]); + if (where.Length > 0) + { + where += " and "; + } + where += String.Format(" and table_name = '{0}'", restrictions[2]); } // COLUMN_NAME if (restrictions.Length > 3 && restrictions[3] != null) { - sql += String.Format(" and column_name = '{0}'", restrictions[3]); + if (where.Length > 0) + { + where += " and "; + } + where += String.Format(" and column_name = '{0}'", restrictions[3]); } } - sql += " ORDER BY table_catalog, table_schema, table_name, ordinal_position"; + sql += "WHERE " + where + " ORDER BY table_catalog, table_schema, table_name, ordinal_position"; return sql; } Modified: trunk/PostgreSqlClient/source/PostgreSql/Data/Schema/PgTables.cs =================================================================== --- trunk/PostgreSqlClient/source/PostgreSql/Data/Schema/PgTables.cs 2006-04-11 12:43:34 UTC (rev 89) +++ trunk/PostgreSqlClient/source/PostgreSql/Data/Schema/PgTables.cs 2006-04-11 14:56:02 UTC (rev 90) @@ -25,6 +25,7 @@ protected override string BuildSql(string[] restrictions) { + string where = ""; string sql = "SELECT " + "current_database() AS TABLE_CATALOG, " + @@ -48,44 +49,69 @@ "left join pg_tablespace ON pg_class.reltablespace = pg_tablespace.oid " + "left join pg_description ON pg_class.oid = pg_description.objoid "; - if (restrictions != null && restrictions.Length > 0) - { - // TABLE_CATALOG - if (restrictions.Length > 0 && restrictions[0] != null) - { - } + sql += "WHERE "; - // TABLE_SCHEMA - if (restrictions.Length > 1 && restrictions[1] != null) - { - sql += String.Format(" and pg_namespace.nspname = '{0}'", restrictions[1]); - } + if (restrictions != null && restrictions.Length > 0) + { + // TABLE_CATALOG + if (restrictions.Length > 0 && restrictions[0] != null) + { + } - // TABLE_NAME - if (restrictions.Length > 2 && restrictions[2] != null) - { - sql += String.Format(" and pg_class.relname = '{0}'", restrictions[2]); - } + // TABLE_SCHEMA + if (restrictions.Length > 1 && restrictions[1] != null) + { + if (where.Length > 0) + { + where += " and "; + } + where += String.Format("pg_namespace.nspname = '{0}'", restrictions[1]); + } - // TABLE_TYPE - if (restrictions.Length > 3 && restrictions[3] != null) - { - sql += String.Format(" and pg_class.relkind = '{0}'", restrictions[3]); - } + // TABLE_NAME + if (restrictions.Length > 2 && restrictions[2] != null) + { + if (where.Length > 0) + { + where += " and "; + } + where += String.Format("pg_class.relname = '{0}'", restrictions[2]); + } + // TABLE_TYPE + if (restrictions.Length > 3 && restrictions[3] != null) + { + if (where.Length > 0) + { + where += " and "; + } + where += String.Format("pg_class.relkind = '{0}'", restrictions[3]); + } + else + { + if (where.Length > 0) + { + where += " and "; + } + where += "pg_class.relkind = 'r'"; + } + // TABLESPACE if (restrictions.Length > 4 && restrictions[4] != null) { - sql += String.Format(" and pg_tablespace.spcname = '{0}'", restrictions[4]); + if (where.Length > 0) + { + where += " and "; + } + where += String.Format("pg_tablespace.spcname = '{0}'", restrictions[4]); } } - - if (restrictions != null && (restrictions.Length < 4 || restrictions[3] == null)) + else { - sql += "WHERE pg_class.relkind = 'r' "; + where += " pg_class.relkind = 'r'"; } - sql += " ORDER BY pg_class.relkind, pg_namespace.nspname, pg_class.relname"; + sql += where + " ORDER BY pg_class.relkind, pg_namespace.nspname, pg_class.relname"; return sql; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |