@@ -35,7 +35,7 @@ QgsMssqlFeatureIterator::QgsMssqlFeatureIterator( QgsMssqlFeatureSource* source,
35
35
BuildStatement ( request );
36
36
37
37
// connect to the database
38
- mDatabase = GetDatabase ( mSource ->mDriver , mSource ->mHost , mSource ->mDatabaseName , mSource ->mUserName , mSource ->mPassword );
38
+ mDatabase = QgsMssqlProvider:: GetDatabase ( mSource ->mService , mSource ->mHost , mSource ->mDatabaseName , mSource ->mUserName , mSource ->mPassword );
39
39
40
40
if ( !mDatabase .open () )
41
41
{
@@ -63,7 +63,7 @@ void QgsMssqlFeatureIterator::BuildStatement( const QgsFeatureRequest& request )
63
63
// build sql statement
64
64
mStatement = QString ( " SELECT " );
65
65
66
- mStatement += QString (" [%1]" ).arg ( mSource ->mFidColName );
66
+ mStatement += QString ( " [%1]" ).arg ( mSource ->mFidColName );
67
67
mFidCol = mSource ->mFields .indexFromName ( mSource ->mFidColName );
68
68
mAttributesToFetch .append ( mFidCol );
69
69
@@ -74,15 +74,15 @@ void QgsMssqlFeatureIterator::BuildStatement( const QgsFeatureRequest& request )
74
74
if ( mSource ->mFidColName == fieldname )
75
75
continue ;
76
76
77
- mStatement += QString (" ,[%1]" ).arg ( fieldname );
77
+ mStatement += QString ( " ,[%1]" ).arg ( fieldname );
78
78
79
79
mAttributesToFetch .append ( i );
80
80
}
81
81
82
82
// get geometry col
83
83
if ( !( request.flags () & QgsFeatureRequest::NoGeometry ) && mSource ->isSpatial () )
84
84
{
85
- mStatement += QString (" ,[%1]" ).arg ( mSource ->mGeometryColName );
85
+ mStatement += QString ( " ,[%1]" ).arg ( mSource ->mGeometryColName );
86
86
}
87
87
88
88
mStatement += QString ( " FROM [%1].[%2]" ).arg ( mSource ->mSchemaName , mSource ->mTableName );
@@ -235,78 +235,6 @@ bool QgsMssqlFeatureIterator::close()
235
235
return true ;
236
236
}
237
237
238
- QSqlDatabase QgsMssqlFeatureIterator::GetDatabase ( QString driver, QString host, QString database, QString username, QString password )
239
- {
240
- QSqlDatabase db;
241
- QString connectionName;
242
-
243
- // create a separate database connection for each feature source
244
- QgsDebugMsg ( " Creating a separate database connection" );
245
- QString id;
246
-
247
- // QString::sprintf adds 0x prefix
248
- id.sprintf ( " %p" , this );
249
-
250
- if ( driver.isEmpty () )
251
- {
252
- if ( host.isEmpty () )
253
- {
254
- QgsDebugMsg ( " QgsMssqlProvider host name not specified" );
255
- return db;
256
- }
257
-
258
- if ( database.isEmpty () )
259
- {
260
- QgsDebugMsg ( " QgsMssqlProvider database name not specified" );
261
- return db;
262
- }
263
- connectionName = host + " ." + database + " ." + id;
264
- }
265
- else
266
- connectionName = driver;
267
-
268
- if ( !QSqlDatabase::contains ( connectionName ) )
269
- db = QSqlDatabase::addDatabase ( " QODBC" , connectionName );
270
- else
271
- db = QSqlDatabase::database ( connectionName );
272
-
273
- db.setHostName ( host );
274
- QString connectionString = " " ;
275
- if ( !driver.isEmpty () )
276
- {
277
- // driver was specified explicitly
278
- connectionString = driver;
279
- }
280
- else
281
- {
282
- #ifdef WIN32
283
- connectionString = " driver={SQL Server}" ;
284
- #else
285
- connectionString = " driver={FreeTDS};port=1433" ;
286
- #endif
287
- }
288
-
289
- if ( !host.isEmpty () )
290
- connectionString += " ;server=" + host;
291
-
292
- if ( !database.isEmpty () )
293
- connectionString += " ;database=" + database;
294
-
295
- if ( password.isEmpty () )
296
- connectionString += " ;trusted_connection=yes" ;
297
- else
298
- connectionString += " ;uid=" + username + " ;pwd=" + password;
299
-
300
- if ( !username.isEmpty () )
301
- db.setUserName ( username );
302
-
303
- if ( !password.isEmpty () )
304
- db.setPassword ( password );
305
-
306
- db.setDatabaseName ( connectionString );
307
- return db;
308
- }
309
-
310
238
// /////////////
311
239
312
240
QgsMssqlFeatureSource::QgsMssqlFeatureSource ( const QgsMssqlProvider* p )
@@ -317,6 +245,7 @@ QgsMssqlFeatureSource::QgsMssqlFeatureSource( const QgsMssqlProvider* p )
317
245
, mSchemaName( p->mSchemaName )
318
246
, mTableName( p->mTableName )
319
247
, mUserName( p->mUserName )
248
+ , mPassword( p->mPassword )
320
249
, mService( p->mService )
321
250
, mDatabaseName( p->mDatabaseName )
322
251
, mHost( p->mHost )
0 commit comments