Skip to content

Commit

Permalink
Adjust indenting. no code changes
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@6608 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
g_j_m committed Feb 16, 2007
1 parent d050e90 commit 248644e
Showing 1 changed file with 78 additions and 77 deletions.
155 changes: 78 additions & 77 deletions src/providers/postgres/qgspostgresprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1151,44 +1151,44 @@ void QgsPostgresProvider::findColumns(tableCols& cols)
// This sql is derived from the one that defines the view
// 'information_schema.view_column_usage' in PostgreSQL, with a few
// mods to suit our purposes.
QString sql = ""
"SELECT DISTINCT "
" nv.nspname AS view_schema, "
" v.relname AS view_name, "
" a.attname AS view_column_name, "
" nt.nspname AS table_schema, "
" t.relname AS table_name, "
" a.attname AS column_name, "
" t.relkind as table_type, "
" typ.typname as column_type "
"FROM "
" pg_namespace nv, "
" pg_class v, "
" pg_depend dv,"
" pg_depend dt, "
" pg_class t, "
" pg_namespace nt, "
" pg_attribute a,"
" pg_user u, "
" pg_type typ "
"WHERE "
" nv.oid = v.relnamespace AND "
" v.relkind = 'v'::\"char\" AND "
" v.oid = dv.refobjid AND "
" dv.refclassid = 'pg_class'::regclass::oid AND "
" dv.classid = 'pg_rewrite'::regclass::oid AND "
" dv.deptype = 'i'::\"char\" AND "
" dv.objid = dt.objid AND "
" dv.refobjid <> dt.refobjid AND "
" dt.classid = 'pg_rewrite'::regclass::oid AND "
" dt.refclassid = 'pg_class'::regclass::oid AND "
" dt.refobjid = t.oid AND "
" t.relnamespace = nt.oid AND "
" (t.relkind = 'r'::\"char\" OR t.relkind = 'v'::\"char\") AND "
" t.oid = a.attrelid AND "
" dt.refobjsubid = a.attnum AND "
" nv.nspname NOT IN ('pg_catalog', 'information_schema' ) AND "
" a.atttypid = typ.oid";
QString sql = ""
"SELECT DISTINCT "
" nv.nspname AS view_schema, "
" v.relname AS view_name, "
" a.attname AS view_column_name, "
" nt.nspname AS table_schema, "
" t.relname AS table_name, "
" a.attname AS column_name, "
" t.relkind as table_type, "
" typ.typname as column_type "
"FROM "
" pg_namespace nv, "
" pg_class v, "
" pg_depend dv,"
" pg_depend dt, "
" pg_class t, "
" pg_namespace nt, "
" pg_attribute a,"
" pg_user u, "
" pg_type typ "
"WHERE "
" nv.oid = v.relnamespace AND "
" v.relkind = 'v'::\"char\" AND "
" v.oid = dv.refobjid AND "
" dv.refclassid = 'pg_class'::regclass::oid AND "
" dv.classid = 'pg_rewrite'::regclass::oid AND "
" dv.deptype = 'i'::\"char\" AND "
" dv.objid = dt.objid AND "
" dv.refobjid <> dt.refobjid AND "
" dt.classid = 'pg_rewrite'::regclass::oid AND "
" dt.refclassid = 'pg_class'::regclass::oid AND "
" dt.refobjid = t.oid AND "
" t.relnamespace = nt.oid AND "
" (t.relkind = 'r'::\"char\" OR t.relkind = 'v'::\"char\") AND "
" t.oid = a.attrelid AND "
" dt.refobjsubid = a.attnum AND "
" nv.nspname NOT IN ('pg_catalog', 'information_schema' ) AND "
" a.atttypid = typ.oid";

// A structure to store the results of the above sql.
typedef std::map<QString, TT> columnRelationsType;
Expand All @@ -1201,6 +1201,7 @@ void QgsPostgresProvider::findColumns(tableCols& cols)

PGresult* result = PQexec(connection, (const char*)(sql.utf8()));
// Store the results of the query for convenient access

for (int i = 0; i < PQntuples(result); ++i)
{
TT temp;
Expand All @@ -1220,45 +1221,45 @@ void QgsPostgresProvider::findColumns(tableCols& cols)
// adjust the view column name if necessary.


QString viewQuery = "SELECT definition FROM pg_views "
"WHERE schemaname = '" + temp.view_schema + "' AND "
"viewname = '" + temp.view_name + "'";

// Maintain a cache of the above SQL.
QString viewDef;
if (!viewDefs.contains(viewQuery))
{
PGresult* r = PQexec(connection, (const char*)(viewQuery.utf8()));
if (PQntuples(r) > 0)
viewDef = PQgetvalue(r, 0, 0);
else
QgsDebugMsg("Failed to get view definition for " + temp.view_schema + "." + temp.view_name);
viewDefs[viewQuery] = viewDef;
}

viewDef = viewDefs.value(viewQuery);

// Now pick the view definiton apart, looking for
// temp.column_name to the left of an 'AS'.

// This regular expression needs more testing. Since the view
// definition comes from postgresql and has been 'standardised', we
// don't need to deal with everything that the user could put in a view
// definition. Does the regexp have to deal with the schema??
if (!viewDef.isEmpty())
{
QRegExp s(".* \"?" + QRegExp::escape(temp.table_name) +
"\"?\\.\"?" + QRegExp::escape(temp.column_name) +
"\"? AS \"?(\\w+)\"?,* .*");

QgsDebugMsg(viewQuery + "\n" + viewDef + "\n" + s.pattern());

if (s.indexIn(viewDef) != -1)
{
temp.view_column_name = s.cap(1);
//std::cerr<<__FILE__<<__LINE__<<' '<<temp.view_column_name.toLocal8Bit().data()<<'\n';
}
}
QString viewQuery = "SELECT definition FROM pg_views "
"WHERE schemaname = '" + temp.view_schema + "' AND "
"viewname = '" + temp.view_name + "'";
// Maintain a cache of the above SQL.
QString viewDef;
if (!viewDefs.contains(viewQuery))
{
PGresult* r = PQexec(connection, (const char*)(viewQuery.utf8()));
if (PQntuples(r) > 0)
viewDef = PQgetvalue(r, 0, 0);
else
QgsDebugMsg("Failed to get view definition for " + temp.view_schema + "." + temp.view_name);
viewDefs[viewQuery] = viewDef;
}

viewDef = viewDefs.value(viewQuery);

// Now pick the view definiton apart, looking for
// temp.column_name to the left of an 'AS'.

// This regular expression needs more testing. Since the view
// definition comes from postgresql and has been 'standardised', we
// don't need to deal with everything that the user could put in a view
// definition. Does the regexp have to deal with the schema??
if (!viewDef.isEmpty())
{
QRegExp s(".* \"?" + QRegExp::escape(temp.table_name) +
"\"?\\.\"?" + QRegExp::escape(temp.column_name) +
"\"? AS \"?(\\w+)\"?,* .*");
QgsDebugMsg(viewQuery + "\n" + viewDef + "\n" + s.pattern());

if (s.indexIn(viewDef) != -1)
{
temp.view_column_name = s.cap(1);
//std::cerr<<__FILE__<<__LINE__<<' '<<temp.view_column_name.toLocal8Bit().data()<<'\n';
}
}

QgsDebugMsg(temp.view_schema + "."
+ temp.view_name + "."
Expand Down

0 comments on commit 248644e

Please sign in to comment.