Skip to content
Permalink
Browse files
oracle provider improvements:
- 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 22, 2013
1 parent c0d9275 commit 3380961e9782600e39c953c774b906d38d4a7f95

Large diffs are not rendered by default.

Large diffs are not rendered by default.

@@ -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 )
@@ -61,6 +73,5 @@ void QgsOracleColumnTypeThread::run()
emit setLayerType( layerProperty );
}

mConn->disconnect();
mConn = 0;
conn->disconnect();
}
@@ -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.
@@ -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;
@@ -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 );
@@ -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;
}

@@ -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;

@@ -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" );
@@ -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;
@@ -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 );

0 comments on commit 3380961

Please sign in to comment.