Skip to content
Permalink
Browse files
Provide an option to the user to constrain searches for spatial table…
…s not

in the geometry_columns table to just those in the public schema. For some
databases which have a lot of ancillary stuff out of the public schema this
can significantly reduce the time that qgis takes to produce the list of 
tables to load.  

Also tidy up the cause of some console warning messages about unknown
geometry types that happened when a spatial table not in the geometry_columns
table had no non-null geometries in it.


git-svn-id: http://svn.osgeo.org/qgis/trunk@5711 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
g_j_m committed Aug 20, 2006
1 parent c6d88ad commit cb20fd4
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 87 deletions.
@@ -188,7 +188,7 @@ void QgsDbSourceSelect::setLayerType(QString schema,
}
else
{
qDebug(("Unknown geometry type of " + type).toLocal8Bit().data());
qDebug(("Unknown geometry type of ." + type + ",.").toLocal8Bit().data());
p = &(mLayerIcons.value("UNKNOWN").second);
toolTipText = mLayerIcons.value("UNKNOWN").first;
}
@@ -313,6 +313,7 @@ void QgsDbSourceSelect::on_btnConnect_clicked()
QString username = settings.readEntry(key + "/username");
connString += username;
QString password = settings.readEntry(key + "/password");
bool searchPublicOnly = settings.readBoolEntry(key + "/publicOnly");
bool makeConnection = true;
if (password == QString::null)
{
@@ -393,7 +394,7 @@ void QgsDbSourceSelect::on_btnConnect_clicked()

// get the list of suitable tables and columns and populate the UI
geomCol details;
if (getGeometryColumnInfo(pd, details))
if (getGeometryColumnInfo(pd, details, searchPublicOnly))
{
details.sort();
geomCol::const_iterator iter = details.begin();
@@ -409,7 +410,7 @@ void QgsDbSourceSelect::on_btnConnect_clicked()
}
else
{
qDebug(("Unknown geometry type of " + iter->second).toLocal8Bit().data());
qDebug(("Unknown geometry type of '" + iter->second + "'.").toLocal8Bit().data());
p = &(mLayerIcons.value("UNKNOWN").second);
toolTipText = mLayerIcons.value("UNKNOWN").first;
}
@@ -518,7 +519,7 @@ void QgsDbSourceSelect::setSql(QTableWidgetItem *item)
}

bool QgsDbSourceSelect::getGeometryColumnInfo(PGconn *pg,
geomCol& details)
geomCol& details, bool searchPublicOnly)
{
bool ok = false;

@@ -579,8 +580,12 @@ bool QgsDbSourceSelect::getGeometryColumnInfo(PGconn *pg,
sql = "select pg_class.relname, pg_namespace.nspname, pg_attribute.attname, "
"pg_class.relkind from "
"pg_attribute, pg_class, pg_type, pg_namespace where pg_type.typname = 'geometry' and "
"pg_attribute.atttypid = pg_type.oid and pg_attribute.attrelid = pg_class.oid "
"and cast(pg_class.relname as character varying) not in "
"pg_attribute.atttypid = pg_type.oid and pg_attribute.attrelid = pg_class.oid ";

if (searchPublicOnly)
sql += "and pg_namespace.nspname = 'public' ";

sql += "and cast(pg_class.relname as character varying) not in "
"(select f_table_name from geometry_columns) "
"and pg_namespace.oid = pg_class.relnamespace "
"and pg_class.relkind in ('v', 'r')"; // only from views and relations (tables)
@@ -614,7 +619,7 @@ bool QgsDbSourceSelect::getGeometryColumnInfo(PGconn *pg,
tr("\nhas failed. The database said:\n"));
qDebug(myError + QString(PQresultErrorMessage(gresult)));
}
else
else if (PQntuples(gresult) > 0)
type = PQgetvalue(gresult, 0, 0); // GeometryType
PQclear(gresult);
}
@@ -97,7 +97,7 @@ class QgsDbSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
typedef std::list<geomPair > geomCol;

bool getGeometryColumnInfo(PGconn *pd,
geomCol& details);
geomCol& details, bool searchPublicOnly);
// Set the position of the database connection list to the last
// used one.
void setConnectionListPosition();
@@ -45,6 +45,10 @@ QgsNewConnection::QgsNewConnection(QWidget *parent, const QString& connName, Qt:
}
txtPort->setText(port);
txtUsername->setText(settings.readEntry(key + "/username"));
Qt::CheckState s = Qt::Checked;
if ( ! settings.readBoolEntry(key + "/publicOnly", false))
s = Qt::Unchecked;
cb_publicSchemaOnly->setCheckState(s);
if (settings.readEntry(key + "/save") == "true")
{
txtPassword->setText(settings.readEntry(key + "/password"));
@@ -114,6 +118,7 @@ void QgsNewConnection::saveConnection()
settings.writeEntry(baseKey + "/port", txtPort->text());
settings.writeEntry(baseKey + "/username", txtUsername->text());
settings.writeEntry(baseKey + "/password", txtPassword->text());
settings.writeEntry(baseKey + "/publicOnly", cb_publicSchemaOnly->isChecked());
if (chkStorePassword->isChecked())
{
settings.writeEntry(baseKey + "/save", "true");
@@ -8,10 +8,18 @@
<rect>
<x>0</x>
<y>0</y>
<width>394</width>
<height>282</height>
<width>435</width>
<height>389</height>
</rect>
</property>
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>3</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle" >
<string>Create a New PostGIS connection</string>
</property>
@@ -20,82 +28,11 @@
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>11</number>
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="1" >
<layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QPushButton" name="btnOk" >
<property name="text" >
<string>OK</string>
</property>
<property name="shortcut" >
<string/>
</property>
<property name="autoDefault" >
<bool>true</bool>
</property>
<property name="default" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnCancel" >
<property name="text" >
<string>Cancel</string>
</property>
<property name="shortcut" >
<string/>
</property>
<property name="autoDefault" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnHelp" >
<property name="enabled" >
<bool>true</bool>
</property>
<property name="text" >
<string>Help</string>
</property>
<property name="shortcut" >
<string>F1</string>
</property>
<property name="autoDefault" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<size>
<width>0</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="0" column="0" >
<widget class="Q3GroupBox" name="GroupBox1" >
<property name="title" >
@@ -104,14 +41,14 @@
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<layout class="QGridLayout" >
<layout class="QVBoxLayout" >
<property name="margin" >
<number>11</number>
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
<number>0</number>
</property>
<item row="0" column="0" >
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
@@ -231,7 +168,7 @@
</item>
</layout>
</item>
<item row="1" column="0" >
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
@@ -255,9 +192,93 @@
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="cb_publicSchemaOnly" >
<property name="toolTip" >
<string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;/head>&lt;body style=" white-space: pre-wrap; font-family:Sans Serif; font-size:12pt; font-weight:400; font-style:normal; text-decoration:none;">&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Restrict the search to the public schema for spatial tables not in the geometry_columns table&lt;/p>&lt;/body>&lt;/html></string>
</property>
<property name="whatsThis" >
<string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;/head>&lt;body style=" white-space: pre-wrap; font-family:Sans Serif; font-size:12pt; font-weight:400; font-style:normal; text-decoration:none;">&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">When searching for spatial tables that are not in the geometry_columns tables, restrict the search to tables that are in the public schema (for some databases this can save lots of time)&lt;/p>&lt;/body>&lt;/html></string>
</property>
<property name="text" >
<string>Only look in the 'public' schema</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="1" >
<layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QPushButton" name="btnOk" >
<property name="text" >
<string>OK</string>
</property>
<property name="shortcut" >
<string/>
</property>
<property name="autoDefault" >
<bool>true</bool>
</property>
<property name="default" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnCancel" >
<property name="text" >
<string>Cancel</string>
</property>
<property name="shortcut" >
<string/>
</property>
<property name="autoDefault" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnHelp" >
<property name="enabled" >
<bool>true</bool>
</property>
<property name="text" >
<string>Help</string>
</property>
<property name="shortcut" >
<string>F1</string>
</property>
<property name="autoDefault" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<size>
<width>87</width>
<height>200</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11" />

0 comments on commit cb20fd4

Please sign in to comment.