File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -132,7 +132,9 @@ QgsMssqlProvider::QgsMssqlProvider( QString uri )
132
132
mGeometryColName = anUri.geometryColumn ();
133
133
134
134
if ( mSRId < 0 || mWkbType == QGis::WKBUnknown || mGeometryColName .isEmpty () )
135
+ {
135
136
loadMetadata ();
137
+ }
136
138
loadFields ();
137
139
UpdateStatistics ( mUseEstimatedMetadata );
138
140
@@ -1324,7 +1326,11 @@ QgsCoordinateReferenceSystem QgsMssqlProvider::crs()
1324
1326
{
1325
1327
if ( !mCrs .isValid () && mSRId > 0 )
1326
1328
{
1327
- // try to load crs
1329
+ mCrs .createFromSrid ( mSRId );
1330
+ if ( mCrs .isValid () )
1331
+ return mCrs ;
1332
+
1333
+ // try to load crs from the database tables as a fallback
1328
1334
QSqlQuery query = QSqlQuery ( mDatabase );
1329
1335
query.setForwardOnly ( true );
1330
1336
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()
1336
1342
query.finish ();
1337
1343
}
1338
1344
query.clear ();
1345
+
1346
+ // Look in the system reference table for the data if we can't find it yet
1339
1347
execOk = query.exec ( QString ( " select well_known_text from sys.spatial_reference_systems where spatial_reference_id = %1" ).arg ( QString::number ( mSRId ) ) );
1340
1348
if ( execOk && query.isActive () && query.next () && mCrs .createFromWkt ( query.value ( 0 ).toString () ) )
1341
1349
return mCrs ;
Original file line number Diff line number Diff line change @@ -527,6 +527,7 @@ void QgsMssqlSourceSelect::on_btnConnect_clicked()
527
527
{
528
528
QString testquery ( " SELECT count(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'geometry_columns'" );
529
529
q.exec ( testquery );
530
+ q.first ();
530
531
int count = q.value ( 0 ).toInt ();
531
532
bool geometryColumnsFound = count != 0 ;
532
533
if ( !geometryColumnsFound )
You can’t perform that action at this time.
0 commit comments