Skip to content

Commit

Permalink
oracle provider improvements:
Browse files Browse the repository at this point in the history
- improve srs lookup
- insert crs to oracle table on import, if not existent (requires INSERT privilege on MDSYS.SDO_COORD_REF_SYSTEM)
- move table lookup into thread
- use QgsMessageOutput for import errors (also in postgres and spatialite)
- german translation update
  • Loading branch information
jef-n committed Jan 14, 2013
1 parent fcb5045 commit 831f99a
Show file tree
Hide file tree
Showing 15 changed files with 1,217 additions and 1,144 deletions.
66 changes: 33 additions & 33 deletions doc/TRANSLATORS

Large diffs are not rendered by default.

1,677 changes: 838 additions & 839 deletions i18n/qgis_de.ts

Large diffs are not rendered by default.

35 changes: 23 additions & 12 deletions src/providers/oracle/qgsoraclecolumntypethread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,51 @@ email : jef at norbit dot de
***************************************************************************/

#include "qgsoraclecolumntypethread.h"
#include "qgslogger.h"

#include <QMetaType>

QgsOracleColumnTypeThread::QgsOracleColumnTypeThread( QgsOracleConn *conn, bool useEstimatedMetaData )
QgsOracleColumnTypeThread::QgsOracleColumnTypeThread( QString name, bool useEstimatedMetadata )
: QThread()
, mConn( conn )
, mUseEstimatedMetadata( useEstimatedMetaData )
, mName( name )
, mUseEstimatedMetadata( useEstimatedMetadata )
{
qRegisterMetaType<QgsOracleLayerProperty>( "QgsOracleLayerProperty" );
}

void QgsOracleColumnTypeThread::addGeometryColumn( QgsOracleLayerProperty layerProperty )
{
layerProperties << layerProperty;
}

void QgsOracleColumnTypeThread::stop()
{
mStopped = true;
}

void QgsOracleColumnTypeThread::run()
{
if ( !mConn )
QgsDataSourceURI uri = QgsOracleConn::connUri( mName );
QgsOracleConn *conn = QgsOracleConn::connectDb( uri.connectionInfo() );
if ( !conn )
{
QgsDebugMsg( "Connection failed - " + uri.connectionInfo() );
return;
}

mStopped = false;

QgsDebugMsg( "retrieving supported layers - connection " + mName );
QVector<QgsOracleLayerProperty> layerProperties;
if ( !conn->supportedLayers( layerProperties,
QgsOracleConn::geometryColumnsOnly( mName ),
QgsOracleConn::userTablesOnly( mName ),
QgsOracleConn::allowGeometrylessTables( mName ) ) ||
layerProperties.isEmpty() )
{
return;
}

foreach ( QgsOracleLayerProperty layerProperty, layerProperties )
{
if ( !mStopped )
{
mConn->retrieveLayerTypes( layerProperty, mUseEstimatedMetadata );
conn->retrieveLayerTypes( layerProperty, mUseEstimatedMetadata );
}

if ( mStopped )
Expand All @@ -61,6 +73,5 @@ void QgsOracleColumnTypeThread::run()
emit setLayerType( layerProperty );
}

mConn->disconnect();
mConn = 0;
conn->disconnect();
}
5 changes: 2 additions & 3 deletions src/providers/oracle/qgsoraclecolumntypethread.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class QgsOracleColumnTypeThread : public QThread
{
Q_OBJECT
public:
QgsOracleColumnTypeThread( QgsOracleConn *conn, bool useEstimatedMetaData );
QgsOracleColumnTypeThread( QString connName, bool useEstimatedMetaData );

// These functions get the layer types and pass that information out
// by emitting the setLayerType() signal.
Expand All @@ -38,13 +38,12 @@ class QgsOracleColumnTypeThread : public QThread
void setLayerType( QgsOracleLayerProperty layerProperty );

public slots:
void addGeometryColumn( QgsOracleLayerProperty layerProperty );
void stop();

private:
QgsOracleColumnTypeThread() {}

QgsOracleConn *mConn;
QString mName;
bool mUseEstimatedMetadata;
bool mStopped;
QList<QgsOracleLayerProperty> layerProperties;
Expand Down
55 changes: 40 additions & 15 deletions src/providers/oracle/qgsoracleconn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,34 +173,37 @@ QStringList QgsOracleConn::pkCandidates( QString ownerName, QString viewName )
return cols;
}

bool QgsOracleConn::tableInfo( bool geometryTablesOnly, bool userTablesOnly, bool allowGeometrylessTables )
bool QgsOracleConn::tableInfo( bool geometryColumnsOnly, bool userTablesOnly, bool allowGeometrylessTables )
{
QgsDebugMsg( "Entering." );

mLayersSupported.clear();

QString sql, delim;

sql = QString( "SELECT c.owner,c.table_name,c.column_name,%1,t.table_name AS isview"
" FROM %2 c"
" LEFT OUTER JOIN all_tables t ON c.owner=t.owner AND c.table_name=t.table_name%3" )
.arg( geometryTablesOnly ? "c.srid" : "NULL AS srid" )
.arg( geometryTablesOnly ? "all_sdo_geom_metadata" : "all_tab_columns" )
.arg( geometryTablesOnly ? "" : " WHERE c.data_type='SDO_GEOMETRY' AND c.data_type_owner='MDSYS'" );
QString
prefix( userTablesOnly ? "user" : "all" ),
owner( userTablesOnly ? "user AS owner" : "c.owner" );

sql = QString( "SELECT %1,c.table_name,c.column_name,%2,t.table_name AS isview"
" FROM %3_%4 c"
" LEFT OUTER JOIN %3_tables t ON c.table_name=t.table_name%5%6" )
.arg( owner )
.arg( geometryColumnsOnly ? "c.srid" : "NULL AS srid" )
.arg( prefix )
.arg( geometryColumnsOnly ? "sdo_geom_metadata" : "tab_columns" )
.arg( userTablesOnly ? "" : " AND c.owner=t.owner" )
.arg( geometryColumnsOnly ? "" : " WHERE c.data_type='SDO_GEOMETRY' AND c.data_type_owner='MDSYS'" );

if ( allowGeometrylessTables )
{
sql += " UNION SELECT owner,table_name,NULL AS column_name,NULL AS srid,table_name AS isview FROM all_tables"
" UNION SELECT owner,view_name,NULL AS column_name,NULL AS srid,NULL AS isview FROM all_views";
sql += QString( " UNION SELECT %1,table_name,NULL AS column_name,NULL AS srid,table_name AS isview FROM %2_tables c"
" UNION SELECT %1,view_name,NULL AS column_name,NULL AS srid,NULL AS isview FROM %2_views c" )
.arg( owner ).arg( prefix );
}

sql = "SELECT * FROM (" + sql + ")";

if ( userTablesOnly )
{
sql += " WHERE owner=user";
}

sql += " ORDER BY owner,isview,table_name,column_name";

QSqlQuery qry( mDatabase );
Expand All @@ -221,6 +224,12 @@ bool QgsOracleConn::tableInfo( bool geometryTablesOnly, bool userTablesOnly, boo
layerProperty.isView = qry.value( 4 ).isNull();
layerProperty.pkCols.clear();

if ( allowGeometrylessTables )
{
layerProperty.types << QGis::WKBNoGeometry;
layerProperty.srids << 0;
}

mLayersSupported << layerProperty;
}

Expand Down Expand Up @@ -313,7 +322,11 @@ QString QgsOracleConn::fieldExpression( const QgsField &fld )

void QgsOracleConn::retrieveLayerTypes( QgsOracleLayerProperty &layerProperty, bool useEstimatedMetadata )
{
if ( layerProperty.geometryColName.isEmpty() )
return;

QgsDebugMsg( "entering: " + layerProperty.toString() );

QString table;
QString where;

Expand Down Expand Up @@ -569,7 +582,7 @@ void QgsOracleConn::deleteConnection( QString theConnName )
settings.remove( key + "/database" );
settings.remove( key + "/username" );
settings.remove( key + "/password" );
settings.remove( key + "/publicOnly" );
settings.remove( key + "/userTablesOnly" );
settings.remove( key + "/geometryColumnsOnly" );
settings.remove( key + "/allowGeometrylessTables" );
settings.remove( key + "/estimatedMetadata" );
Expand Down Expand Up @@ -635,12 +648,24 @@ bool QgsOracleConn::userTablesOnly( QString theConnName )
return settings.value( "/Oracle/connections/" + theConnName + "/userTablesOnly", false ).toBool();
}

bool QgsOracleConn::geometryColumnsOnly( QString theConnName )
{
QSettings settings;
return settings.value( "/Oracle/connections/" + theConnName + "/geometryColumnsOnly", false ).toBool();
}

bool QgsOracleConn::allowGeometrylessTables( QString theConnName )
{
QSettings settings;
return settings.value( "/Oracle/connections/" + theConnName + "/allowGeometrylessTables", false ).toBool();
}

bool QgsOracleConn::estimatedMetadata( QString theConnName )
{
QSettings settings;
return settings.value( "/Oracle/connections/" + theConnName + "/estimatedMetadata", false ).toBool();
}

QString QgsOracleConn::databaseName( QString database, QString host, QString port )
{
QString db;
Expand Down
2 changes: 2 additions & 0 deletions src/providers/oracle/qgsoracleconn.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ class QgsOracleConn : public QThread
static void setSelectedConnection( QString theConnName );
static QgsDataSourceURI connUri( QString theConnName );
static bool userTablesOnly( QString theConnName );
static bool geometryColumnsOnly( QString theConnName );
static bool allowGeometrylessTables( QString theConnName );
static bool estimatedMetadata( QString theConnName );
static void deleteConnection( QString theConnName );
static QString databaseName( QString database, QString host, QString port );

Expand Down
Loading

0 comments on commit 831f99a

Please sign in to comment.