@@ -121,14 +121,12 @@ QgsSpatiaLiteProvider::createEmptyLayer(
121
121
122
122
// create the table
123
123
{
124
- QgsSqliteHandle *handle;
125
- sqlite3 *mSqliteHandle = nullptr ;
126
124
char *errMsg = nullptr ;
127
125
int toCommit = false ;
128
126
QString sql;
129
127
130
128
// trying to open the SQLite DB
131
- handle = QgsSqliteHandle::openDb ( sqlitePath );
129
+ QgsSqliteHandle * handle = QgsSqliteHandle::openDb ( sqlitePath );
132
130
if ( !handle )
133
131
{
134
132
QgsDebugMsg ( " Connection to database failed. Import of layer aborted." );
@@ -137,7 +135,7 @@ QgsSpatiaLiteProvider::createEmptyLayer(
137
135
return QgsVectorLayerImport::ErrConnectionFailed;
138
136
}
139
137
140
- mSqliteHandle = handle->handle ();
138
+ sqlite3 *sqliteHandle = handle->handle ();
141
139
142
140
// get the pk's name and type
143
141
if ( primaryKey.isEmpty () )
@@ -190,7 +188,7 @@ QgsSpatiaLiteProvider::createEmptyLayer(
190
188
191
189
try
192
190
{
193
- int ret = sqlite3_exec ( mSqliteHandle , " BEGIN" , nullptr , nullptr , &errMsg );
191
+ int ret = sqlite3_exec ( sqliteHandle , " BEGIN" , nullptr , nullptr , &errMsg );
194
192
if ( ret != SQLITE_OK )
195
193
throw SLException ( errMsg );
196
194
@@ -202,14 +200,14 @@ QgsSpatiaLiteProvider::createEmptyLayer(
202
200
sql = QString ( " DROP TABLE IF EXISTS %1" )
203
201
.arg ( quotedIdentifier ( tableName ) );
204
202
205
- ret = sqlite3_exec ( mSqliteHandle , sql.toUtf8 ().constData (), nullptr , nullptr , &errMsg );
203
+ ret = sqlite3_exec ( sqliteHandle , sql.toUtf8 ().constData (), nullptr , nullptr , &errMsg );
206
204
if ( ret != SQLITE_OK )
207
205
throw SLException ( errMsg );
208
206
209
207
sql = QString ( " DELETE FROM geometry_columns WHERE upper(f_table_name) = upper(%1)" )
210
208
.arg ( quotedValue ( tableName ) );
211
209
212
- ret = sqlite3_exec ( mSqliteHandle , sql.toUtf8 ().constData (), nullptr , nullptr , &errMsg );
210
+ ret = sqlite3_exec ( sqliteHandle , sql.toUtf8 ().constData (), nullptr , nullptr , &errMsg );
213
211
if ( ret != SQLITE_OK )
214
212
throw SLException ( errMsg );
215
213
}
@@ -219,7 +217,7 @@ QgsSpatiaLiteProvider::createEmptyLayer(
219
217
quotedIdentifier ( primaryKey ),
220
218
primaryKeyType );
221
219
222
- ret = sqlite3_exec ( mSqliteHandle , sql.toUtf8 ().constData (), nullptr , nullptr , &errMsg );
220
+ ret = sqlite3_exec ( sqliteHandle , sql.toUtf8 ().constData (), nullptr , nullptr , &errMsg );
223
221
if ( ret != SQLITE_OK )
224
222
throw SLException ( errMsg );
225
223
@@ -291,7 +289,7 @@ QgsSpatiaLiteProvider::createEmptyLayer(
291
289
.arg ( QgsSpatiaLiteProvider::quotedValue ( geometryType ) )
292
290
.arg ( dim );
293
291
294
- ret = sqlite3_exec ( mSqliteHandle , sql.toUtf8 ().constData (), nullptr , nullptr , &errMsg );
292
+ ret = sqlite3_exec ( sqliteHandle , sql.toUtf8 ().constData (), nullptr , nullptr , &errMsg );
295
293
if ( ret != SQLITE_OK )
296
294
throw SLException ( errMsg );
297
295
}
@@ -300,7 +298,7 @@ QgsSpatiaLiteProvider::createEmptyLayer(
300
298
geometryColumn = QString ();
301
299
}
302
300
303
- ret = sqlite3_exec ( mSqliteHandle , " COMMIT" , nullptr , nullptr , &errMsg );
301
+ ret = sqlite3_exec ( sqliteHandle , " COMMIT" , nullptr , nullptr , &errMsg );
304
302
if ( ret != SQLITE_OK )
305
303
throw SLException ( errMsg );
306
304
@@ -321,7 +319,7 @@ QgsSpatiaLiteProvider::createEmptyLayer(
321
319
if ( toCommit )
322
320
{
323
321
// ROLLBACK after some previous error
324
- sqlite3_exec ( mSqliteHandle , " ROLLBACK" , nullptr , nullptr , nullptr );
322
+ sqlite3_exec ( sqliteHandle , " ROLLBACK" , nullptr , nullptr , nullptr );
325
323
}
326
324
327
325
QgsSqliteHandle::closeDb ( handle );
@@ -5259,32 +5257,29 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
5259
5257
const QString& styleName, const QString& styleDescription,
5260
5258
const QString& uiFileContent, bool useAsDefault, QString& errCause )
5261
5259
{
5262
- QgsSqliteHandle *handle;
5263
- sqlite3 *mSqliteHandle = nullptr ;
5264
- char **results;
5265
- int rows;
5266
- int columns;
5267
- char *errMsg = nullptr ;
5268
-
5269
5260
QgsDataSourceURI dsUri ( uri );
5270
5261
QString sqlitePath = dsUri.database ();
5271
5262
QgsDebugMsg ( " Database is: " + sqlitePath );
5272
5263
5273
5264
// trying to open the SQLite DB
5274
- handle = QgsSqliteHandle::openDb ( sqlitePath );
5265
+ QgsSqliteHandle * handle = QgsSqliteHandle::openDb ( sqlitePath );
5275
5266
if ( !handle )
5276
5267
{
5277
5268
QgsDebugMsg ( " Connection to database failed. Save style aborted." );
5278
5269
errCause = QObject::tr ( " Connection to database failed" );
5279
5270
return false ;
5280
5271
}
5281
5272
5282
- mSqliteHandle = handle->handle ();
5273
+ sqlite3 *sqliteHandle = handle->handle ();
5283
5274
5284
5275
// check if layer_styles table already exist
5285
5276
QString countIfExist = QString ( " SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='%1';" ).arg ( " layer_styles" );
5286
5277
5287
- int ret = sqlite3_get_table ( mSqliteHandle , countIfExist.toUtf8 ().constData (), &results, &rows, &columns, &errMsg );
5278
+ char **results;
5279
+ int rows;
5280
+ int columns;
5281
+ char *errMsg = nullptr ;
5282
+ int ret = sqlite3_get_table ( sqliteHandle, countIfExist.toUtf8 ().constData (), &results, &rows, &columns, &errMsg );
5288
5283
if ( SQLITE_OK != ret )
5289
5284
{
5290
5285
QgsSqliteHandle::closeDb ( handle );
@@ -5320,7 +5315,7 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
5320
5315
" ,ui text"
5321
5316
" ,update_time timestamp DEFAULT CURRENT_TIMESTAMP"
5322
5317
" )" );
5323
- ret = sqlite3_exec ( mSqliteHandle , createQuery.toUtf8 ().constData (), nullptr , nullptr , &errMsg );
5318
+ ret = sqlite3_exec ( sqliteHandle , createQuery.toUtf8 ().constData (), nullptr , nullptr , &errMsg );
5324
5319
if ( SQLITE_OK != ret )
5325
5320
{
5326
5321
QgsSqliteHandle::closeDb ( handle );
@@ -5368,7 +5363,7 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
5368
5363
.arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.geometryColumn () ) )
5369
5364
.arg ( QgsSpatiaLiteProvider::quotedValue ( styleName.isEmpty () ? dsUri.table () : styleName ) );
5370
5365
5371
- ret = sqlite3_get_table ( mSqliteHandle , checkQuery.toUtf8 ().constData (), &results, &rows, &columns, &errMsg );
5366
+ ret = sqlite3_get_table ( sqliteHandle , checkQuery.toUtf8 ().constData (), &results, &rows, &columns, &errMsg );
5372
5367
if ( SQLITE_OK != ret )
5373
5368
{
5374
5369
QgsSqliteHandle::closeDb ( handle );
@@ -5428,7 +5423,7 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
5428
5423
sql = QString ( " BEGIN; %1; %2; COMMIT;" ).arg ( removeDefaultSql, sql );
5429
5424
}
5430
5425
5431
- ret = sqlite3_exec ( mSqliteHandle , sql.toUtf8 ().constData (), nullptr , nullptr , &errMsg );
5426
+ ret = sqlite3_exec ( sqliteHandle , sql.toUtf8 ().constData (), nullptr , nullptr , &errMsg );
5432
5427
if ( SQLITE_OK != ret )
5433
5428
{
5434
5429
QgsSqliteHandle::closeDb ( handle );
@@ -5447,28 +5442,20 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
5447
5442
5448
5443
QGISEXTERN QString loadStyle ( const QString& uri, QString& errCause )
5449
5444
{
5450
- QgsSqliteHandle *handle;
5451
- sqlite3 *mSqliteHandle = nullptr ;
5452
- char **results;
5453
- int rows;
5454
- int columns;
5455
- char *errMsg = nullptr ;
5456
- QString sql;
5457
-
5458
5445
QgsDataSourceURI dsUri ( uri );
5459
5446
QString sqlitePath = dsUri.database ();
5460
5447
QgsDebugMsg ( " Database is: " + sqlitePath );
5461
5448
5462
5449
// trying to open the SQLite DB
5463
- handle = QgsSqliteHandle::openDb ( sqlitePath );
5450
+ QgsSqliteHandle * handle = QgsSqliteHandle::openDb ( sqlitePath );
5464
5451
if ( !handle )
5465
5452
{
5466
5453
QgsDebugMsg ( " Connection to database failed. Save style aborted." );
5467
5454
errCause = QObject::tr ( " Connection to database failed" );
5468
5455
return " " ;
5469
5456
}
5470
5457
5471
- mSqliteHandle = handle->handle ();
5458
+ sqlite3 *sqliteHandle = handle->handle ();
5472
5459
5473
5460
QString selectQmlQuery = QString ( " SELECT styleQML"
5474
5461
" FROM layer_styles"
@@ -5483,7 +5470,11 @@ QGISEXTERN QString loadStyle( const QString& uri, QString& errCause )
5483
5470
.arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.table () ) )
5484
5471
.arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.geometryColumn () ) );
5485
5472
5486
- int ret = sqlite3_get_table ( mSqliteHandle , selectQmlQuery.toUtf8 ().constData (), &results, &rows, &columns, &errMsg );
5473
+ char **results;
5474
+ int rows;
5475
+ int columns;
5476
+ char *errMsg = nullptr ;
5477
+ int ret = sqlite3_get_table ( sqliteHandle, selectQmlQuery.toUtf8 ().constData (), &results, &rows, &columns, &errMsg );
5487
5478
if ( SQLITE_OK != ret )
5488
5479
{
5489
5480
QgsSqliteHandle::closeDb ( handle );
@@ -5502,33 +5493,29 @@ QGISEXTERN QString loadStyle( const QString& uri, QString& errCause )
5502
5493
QGISEXTERN int listStyles ( const QString &uri, QStringList &ids, QStringList &names,
5503
5494
QStringList &descriptions, QString& errCause )
5504
5495
{
5505
- QgsSqliteHandle *handle;
5506
- sqlite3 *mSqliteHandle = nullptr ;
5507
- char **results;
5508
- int rows;
5509
- int columns;
5510
- char *errMsg = nullptr ;
5511
- QString sql;
5512
-
5513
5496
QgsDataSourceURI dsUri ( uri );
5514
5497
QString sqlitePath = dsUri.database ();
5515
5498
QgsDebugMsg ( " Database is: " + sqlitePath );
5516
5499
5517
5500
// trying to open the SQLite DB
5518
- handle = QgsSqliteHandle::openDb ( sqlitePath );
5501
+ QgsSqliteHandle * handle = QgsSqliteHandle::openDb ( sqlitePath );
5519
5502
if ( !handle )
5520
5503
{
5521
5504
QgsDebugMsg ( " Connection to database failed. Save style aborted." );
5522
5505
errCause = QObject::tr ( " Connection to database failed" );
5523
5506
return -1 ;
5524
5507
}
5525
5508
5526
- mSqliteHandle = handle->handle ();
5509
+ sqlite3 *sqliteHandle = handle->handle ();
5527
5510
5528
5511
// check if layer_styles table already exist
5529
5512
QString countIfExist = QString ( " SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='%1';" ).arg ( " layer_styles" );
5530
5513
5531
- int ret = sqlite3_get_table ( mSqliteHandle , countIfExist.toUtf8 ().constData (), &results, &rows, &columns, &errMsg );
5514
+ char **results;
5515
+ int rows;
5516
+ int columns;
5517
+ char *errMsg = nullptr ;
5518
+ int ret = sqlite3_get_table ( sqliteHandle, countIfExist.toUtf8 ().constData (), &results, &rows, &columns, &errMsg );
5532
5519
if ( SQLITE_OK != ret )
5533
5520
{
5534
5521
QgsSqliteHandle::closeDb ( handle );
@@ -5564,7 +5551,7 @@ QGISEXTERN int listStyles( const QString &uri, QStringList &ids, QStringList &na
5564
5551
.arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.table () ) )
5565
5552
.arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.geometryColumn () ) );
5566
5553
5567
- ret = sqlite3_get_table ( mSqliteHandle , selectRelatedQuery.toUtf8 ().constData (), &results, &rows, &columns, &errMsg );
5554
+ ret = sqlite3_get_table ( sqliteHandle , selectRelatedQuery.toUtf8 ().constData (), &results, &rows, &columns, &errMsg );
5568
5555
if ( SQLITE_OK != ret )
5569
5556
{
5570
5557
QgsSqliteHandle::closeDb ( handle );
@@ -5591,7 +5578,7 @@ QGISEXTERN int listStyles( const QString &uri, QStringList &ids, QStringList &na
5591
5578
.arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.table () ) )
5592
5579
.arg ( QgsSpatiaLiteProvider::quotedValue ( dsUri.geometryColumn () ) );
5593
5580
5594
- ret = sqlite3_get_table ( mSqliteHandle , selectOthersQuery.toUtf8 ().constData (), &results, &rows, &columns, &errMsg );
5581
+ ret = sqlite3_get_table ( sqliteHandle , selectOthersQuery.toUtf8 ().constData (), &results, &rows, &columns, &errMsg );
5595
5582
if ( SQLITE_OK != ret )
5596
5583
{
5597
5584
QgsSqliteHandle::closeDb ( handle );
@@ -5614,32 +5601,28 @@ QGISEXTERN int listStyles( const QString &uri, QStringList &ids, QStringList &na
5614
5601
5615
5602
QGISEXTERN QString getStyleById ( const QString& uri, QString styleId, QString& errCause )
5616
5603
{
5617
- QgsSqliteHandle *handle;
5618
- sqlite3 *mSqliteHandle = nullptr ;
5619
- char **results;
5620
- int rows;
5621
- int columns;
5622
- char *errMsg = nullptr ;
5623
- QString sql;
5624
-
5625
5604
QgsDataSourceURI dsUri ( uri );
5626
5605
QString sqlitePath = dsUri.database ();
5627
5606
QgsDebugMsg ( " Database is: " + sqlitePath );
5628
5607
5629
5608
// trying to open the SQLite DB
5630
- handle = QgsSqliteHandle::openDb ( sqlitePath );
5609
+ QgsSqliteHandle * handle = QgsSqliteHandle::openDb ( sqlitePath );
5631
5610
if ( !handle )
5632
5611
{
5633
5612
QgsDebugMsg ( " Connection to database failed. Save style aborted." );
5634
5613
errCause = QObject::tr ( " Connection to database failed" );
5635
5614
return " " ;
5636
5615
}
5637
5616
5638
- mSqliteHandle = handle->handle ();
5617
+ sqlite3 *sqliteHandle = handle->handle ();
5639
5618
5640
5619
QString style;
5641
5620
QString selectQmlQuery = QString ( " SELECT styleQml FROM layer_styles WHERE id=%1" ).arg ( QgsSpatiaLiteProvider::quotedValue ( styleId ) );
5642
- int ret = sqlite3_get_table ( mSqliteHandle , selectQmlQuery.toUtf8 ().constData (), &results, &rows, &columns, &errMsg );
5621
+ char **results;
5622
+ int rows;
5623
+ int columns;
5624
+ char *errMsg = nullptr ;
5625
+ int ret = sqlite3_get_table ( sqliteHandle, selectQmlQuery.toUtf8 ().constData (), &results, &rows, &columns, &errMsg );
5643
5626
if ( SQLITE_OK == ret )
5644
5627
{
5645
5628
if ( 1 == rows )
0 commit comments