Skip to content

Commit

Permalink
Fix #12254 - Fix lookup of SRID for SQL Server layers
Browse files Browse the repository at this point in the history
Funded by TechnoglogyOne, Australia

- Backported to 2.8.3
- Cherry-picked from 9c73a22
  • Loading branch information
NathanW2 committed Jun 19, 2015
1 parent 7878b3f commit fedced8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/providers/mssql/qgsmssqlprovider.cpp
Expand Up @@ -132,7 +132,9 @@ QgsMssqlProvider::QgsMssqlProvider( QString uri )
mGeometryColName = anUri.geometryColumn();

if ( mSRId < 0 || mWkbType == QGis::WKBUnknown || mGeometryColName.isEmpty() )
{
loadMetadata();
}
loadFields();
UpdateStatistics( mUseEstimatedMetadata );

Expand Down Expand Up @@ -1324,7 +1326,11 @@ QgsCoordinateReferenceSystem QgsMssqlProvider::crs()
{
if ( !mCrs.isValid() && mSRId > 0 )
{
// try to load crs
mCrs.createFromSrid( mSRId );
if ( mCrs.isValid() )
return mCrs;

// try to load crs from the database tables as a fallback
QSqlQuery query = QSqlQuery( mDatabase );
query.setForwardOnly( true );
bool execOk = query.exec( QString( "select srtext from spatial_ref_sys where srid = %1" ).arg( QString::number( mSRId ) ) );
Expand All @@ -1336,6 +1342,8 @@ QgsCoordinateReferenceSystem QgsMssqlProvider::crs()
query.finish();
}
query.clear();

// Look in the system reference table for the data if we can't find it yet
execOk = query.exec( QString( "select well_known_text from sys.spatial_reference_systems where spatial_reference_id = %1" ).arg( QString::number( mSRId ) ) );
if ( execOk && query.isActive() && query.next() && mCrs.createFromWkt( query.value( 0 ).toString() ) )
return mCrs;
Expand Down
1 change: 1 addition & 0 deletions src/providers/mssql/qgsmssqlsourceselect.cpp
Expand Up @@ -527,6 +527,7 @@ void QgsMssqlSourceSelect::on_btnConnect_clicked()
{
QString testquery( "SELECT count(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'geometry_columns'" );
q.exec( testquery );
q.first();
int count = q.value( 0 ).toInt();
bool geometryColumnsFound = count != 0;
if ( !geometryColumnsFound )
Expand Down

0 comments on commit fedced8

Please sign in to comment.