Skip to content
Permalink
Browse files

Fix #12254 - Fix lookup of SRID for SQL Server layers

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 fedced84284f6d6d4e250589c9a0a7c06eb8f757
Showing with 10 additions and 1 deletion.
  1. +9 −1 src/providers/mssql/qgsmssqlprovider.cpp
  2. +1 −0 src/providers/mssql/qgsmssqlsourceselect.cpp
@@ -132,7 +132,9 @@ QgsMssqlProvider::QgsMssqlProvider( QString uri )
mGeometryColName = anUri.geometryColumn();

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

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

0 comments on commit fedced8

Please sign in to comment.
You can’t perform that action at this time.