Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Replace use of deprecated QSqlError::number
  • Loading branch information
nyalldawson committed Sep 5, 2017
1 parent b196d37 commit 83e6858
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/providers/db2/qgsdb2dataitems.cpp
Expand Up @@ -185,16 +185,16 @@ QVector<QgsDataItem *> QgsDb2ConnectionItem::createChildren()
}

QgsDb2GeometryColumns db2GC = QgsDb2GeometryColumns( db );
int sqlcode = db2GC.open();
QString sqlcode = db2GC.open();

/* Enabling the DB2 Spatial Extender creates the DB2GSE schema and tables,
so the Extender is either not enabled or set up if SQLCODE -204 is returned. */
if ( sqlcode == -204 )
if ( sqlcode == QStringLiteral( "-204" ) )
{
children.append( new QgsErrorItem( this, tr( "DB2 Spatial Extender is not enabled or set up." ), mPath + "/error" ) );
return children;
}
else if ( sqlcode != 0 )
else if ( !sqlcode.isEmpty() && sqlcode != QStringLiteral( "0" ) )
{
children.append( new QgsErrorItem( this, db.lastError().text(), mPath + "/error" ) );
return children;
Expand Down
18 changes: 9 additions & 9 deletions src/providers/db2/qgsdb2geometrycolumns.cpp
Expand Up @@ -32,12 +32,12 @@ QgsDb2GeometryColumns::~QgsDb2GeometryColumns()
mQuery.clear();
}

int QgsDb2GeometryColumns::open()
QString QgsDb2GeometryColumns::open()
{
return open( QString(), QString() );
}

int QgsDb2GeometryColumns::open( const QString &schemaName, const QString &tableName )
QString QgsDb2GeometryColumns::open( const QString &schemaName, const QString &tableName )
{
QString queryExtents( "SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, TYPE_NAME, "
"SRS_ID, SRS_NAME, MIN_X, MIN_Y, MAX_X, MAX_Y "
Expand All @@ -46,7 +46,7 @@ int QgsDb2GeometryColumns::open( const QString &schemaName, const QString &table
"SRS_ID, SRS_NAME "
"FROM DB2GSE.ST_GEOMETRY_COLUMNS" );
mQuery = QSqlQuery( mDatabase );
int sqlcode = 0;
QString nativeError;
mEnvironment = ENV_LUW;

if ( !schemaName.isEmpty() && !tableName.isEmpty() )
Expand All @@ -61,30 +61,30 @@ int QgsDb2GeometryColumns::open( const QString &schemaName, const QString &table
if ( !mQuery.exec( queryExtents ) )
{
QgsDebugMsg( "ST_Geometry_Columns query failed: " + mDatabase.lastError().text() );
sqlcode = mQuery.lastError().number();
QgsDebugMsg( QString( "SQLCODE: %1" ).arg( sqlcode ) );
nativeError = mQuery.lastError().nativeErrorCode();
QgsDebugMsg( QString( "SQLCODE: %1" ).arg( nativeError ) );
/* The MIN_X, MIN_Y, MAX_X, and MAX_Y columns are not available on z/OS (and LUW 9.5)
so SQLCODE -206 is returned when specifying non-existent columns. */
if ( mQuery.lastError().number() == -206 )
if ( mQuery.lastError().nativeErrorCode() == QStringLiteral( "-206" ) )
{
QgsDebugMsg( "Try query with no extents" );
mQuery.clear();

if ( !mQuery.exec( queryNoExtents ) )
{
QgsDebugMsg( QString( "SQLCODE: %1" ).arg( mQuery.lastError().number() ) );
QgsDebugMsg( QString( "SQLCODE: %1" ).arg( mQuery.lastError().nativeErrorCode() ) );
}
else
{
QgsDebugMsg( "success; must be z/OS" );
mEnvironment = ENV_ZOS;
sqlcode = 0;
nativeError.clear();
}
}
}
// QgsDebugMsg( QString( "sqlcode: %1" ).arg( sqlcode ) );

return sqlcode;
return nativeError;
}

bool QgsDb2GeometryColumns::isActive()
Expand Down
4 changes: 2 additions & 2 deletions src/providers/db2/qgsdb2geometrycolumns.h
Expand Up @@ -37,8 +37,8 @@ class QgsDb2GeometryColumns // clazy:exclude=rule-of-three

bool isActive();
void close();
int open();
int open( const QString &schemaName, const QString &tableName );
QString open();
QString open( const QString &schemaName, const QString &tableName );
bool populateLayerProperty( QgsDb2LayerProperty &layer );
int db2Environment();

Expand Down
10 changes: 5 additions & 5 deletions src/providers/db2/qgsdb2provider.cpp
Expand Up @@ -583,8 +583,8 @@ void QgsDb2Provider::updateStatistics() const

QgsDebugMsg( QString( "mSRId: %1" ).arg( mSRId ) );
QgsDb2GeometryColumns gc( mDatabase );
int rc = gc.open( mSchemaName, mTableName ); // returns SQLCODE if failure
if ( rc == 0 )
QString rc = gc.open( mSchemaName, mTableName ); // returns SQLCODE if failure
if ( rc.isEmpty() || rc == QStringLiteral( "0" ) )
{
mEnvironment = gc.db2Environment();
if ( -1 == mSRId )
Expand Down Expand Up @@ -1394,7 +1394,7 @@ QgsVectorLayerExporter::ExportError QgsDb2Provider::createEmptyLayer( const QStr
sql = "DROP TABLE " + fullName;
if ( !q.exec( sql ) )
{
if ( q.lastError().number() != -206 ) // -206 is "not found" just ignore
if ( q.lastError().nativeErrorCode() != QStringLiteral( "-206" ) ) // -206 is "not found" just ignore
{
QString lastError = q.lastError().text();
QgsDebugMsg( lastError );
Expand Down Expand Up @@ -1498,8 +1498,8 @@ QgsVectorLayerExporter::ExportError QgsDb2Provider::createEmptyLayer( const QStr

// get the environment
QgsDb2GeometryColumns gc( db );
int rc = gc.open( schemaName, tableName ); // returns SQLCODE if failure
if ( rc == 0 )
QString rc = gc.open( schemaName, tableName ); // returns SQLCODE if failure
if ( rc.isEmpty() || rc == QStringLiteral( "0" ) )
{
db2Environment = gc.db2Environment();
}
Expand Down
4 changes: 2 additions & 2 deletions src/providers/db2/qgsdb2sourceselect.cpp
Expand Up @@ -495,8 +495,8 @@ void QgsDb2SourceSelect::on_btnConnect_clicked()
}

QgsDb2GeometryColumns db2GC = QgsDb2GeometryColumns( db );
int sqlcode = db2GC.open();
if ( 0 != sqlcode )
QString sqlcode = db2GC.open();
if ( !sqlcode.isEmpty() && QStringLiteral( "0" ) != sqlcode )
{
QMessageBox::warning( this, tr( "DB2GSE.ST_GEOMETRY_COLUMNS Not Found" ),
tr( "DB2GSE.ST_GEOMETRY_COLUMNS not found. The DB2 Spatial Extender is not enabled or set up." ) );
Expand Down

0 comments on commit 83e6858

Please sign in to comment.