@@ -32,6 +32,10 @@ email : a.furieri@lqt.it
32
32
33
33
#include " qgslogger.h"
34
34
35
+ #ifdef _MSC_VER
36
+ #define strcasecmp (a,b ) stricmp(a,b)
37
+ #endif
38
+
35
39
const QString SPATIALITE_KEY = " spatialite" ;
36
40
const QString SPATIALITE_DESCRIPTION = " SpatiaLite data provider" ;
37
41
@@ -213,13 +217,13 @@ bool QgsSpatiaLiteProvider::featureAtId( int featureId, QgsFeature & feature, bo
213
217
sql += " , " ;
214
218
sql += fieldname;
215
219
}
216
- if ( fetchGeometry == true )
220
+ if ( fetchGeometry )
217
221
{
218
222
sql += QString ( " , AsBinary(%1)" ).arg ( geometryColumn );
219
223
}
220
224
sql += QString ( " FROM %1 WHERE ROWID = %2" ).arg ( quotedValue ( mTableName ) ).arg ( featureId );
221
225
222
- const char * xSql = sql.toUtf8 ();
226
+ QByteArray xSql = sql.toUtf8 ();
223
227
if ( sqlite3_prepare_v2 ( sqliteHandle, xSql, strlen ( xSql ), &stmt, NULL ) != SQLITE_OK )
224
228
{
225
229
// some error occurred
@@ -239,7 +243,7 @@ bool QgsSpatiaLiteProvider::featureAtId( int featureId, QgsFeature & feature, bo
239
243
if ( ret == SQLITE_ROW )
240
244
{
241
245
// one valid row has been fetched from the result set
242
- if ( mFetchGeom == false )
246
+ if ( ! mFetchGeom )
243
247
{
244
248
// no geometry was required
245
249
feature.setGeometryAndOwnership ( 0 , 0 );
@@ -300,7 +304,7 @@ bool QgsSpatiaLiteProvider::featureAtId( int featureId, QgsFeature & feature, bo
300
304
if ( mFetchGeom )
301
305
{
302
306
QString geoCol = QString ( " AsBinary(%1)" ).arg ( geometryColumn );
303
- const char * geomName = geoCol.toUtf8 ();
307
+ QByteArray geomName = geoCol.toUtf8 ();
304
308
if ( strcasecmp ( geomName, sqlite3_column_name ( stmt, ic ) ) == 0 )
305
309
{
306
310
if ( sqlite3_column_type ( stmt, ic ) == SQLITE_BLOB )
@@ -362,7 +366,7 @@ bool QgsSpatiaLiteProvider::nextFeature( QgsFeature & feature )
362
366
if ( ret == SQLITE_ROW )
363
367
{
364
368
// one valid row has been fetched from the result set
365
- if ( mFetchGeom == false )
369
+ if ( ! mFetchGeom )
366
370
{
367
371
// no geometry was required
368
372
feature.setGeometryAndOwnership ( 0 , 0 );
@@ -423,7 +427,7 @@ bool QgsSpatiaLiteProvider::nextFeature( QgsFeature & feature )
423
427
if ( mFetchGeom )
424
428
{
425
429
QString geoCol = QString ( " AsBinary(%1)" ).arg ( geometryColumn );
426
- const char * geomName = geoCol.toUtf8 ();
430
+ QByteArray geomName = geoCol.toUtf8 ();
427
431
if ( strcasecmp ( geomName, sqlite3_column_name ( sqliteStatement, ic ) ) == 0 )
428
432
{
429
433
if ( sqlite3_column_type ( sqliteStatement, ic ) == SQLITE_BLOB )
@@ -484,18 +488,18 @@ void QgsSpatiaLiteProvider::select( QgsAttributeList fetchAttributes, QgsRectang
484
488
sql += " , " ;
485
489
sql += fieldname;
486
490
}
487
- if ( fetchGeometry == true )
491
+ if ( fetchGeometry )
488
492
{
489
493
sql += QString ( " , AsBinary(%1)" ).arg ( geometryColumn );
490
494
}
491
495
sql += QString ( " FROM %1" ).arg ( quotedValue ( mTableName ) );
492
496
493
497
QString whereClause;
494
498
495
- if ( rect.isEmpty () == false )
499
+ if ( ! rect.isEmpty () )
496
500
{
497
501
// some kind of MBR spatial filtering is required
498
- whereClause = " WHERE " ;
502
+ whereClause = " WHERE " ;
499
503
if ( useIntersect )
500
504
{
501
505
// we are requested to evaluate a true INTERSECT relationship
@@ -505,7 +509,7 @@ void QgsSpatiaLiteProvider::select( QgsAttributeList fetchAttributes, QgsRectang
505
509
arg ( QString::number ( rect.xMaximum (), ' f' , 6 ) ).arg ( QString::number ( rect.yMaximum (), ' f' , 6 ) );
506
510
whereClause += QString ( " Intersects(%1, BuildMbr(%2)) AND " ).arg ( geometryColumn ).arg ( mbr );
507
511
}
508
- if ( spatialIndexRTree == true )
512
+ if ( spatialIndexRTree )
509
513
{
510
514
// using the RTree spatial index
511
515
QString mbrFilter = QString ( " xmin <= %1 AND " ).arg ( QString::number ( rect.xMaximum (), ' f' , 6 ) );
@@ -515,7 +519,7 @@ void QgsSpatiaLiteProvider::select( QgsAttributeList fetchAttributes, QgsRectang
515
519
QString idxName = QString ( " idx_%1_%2" ).arg ( mTableName ).arg ( geometryColumn );
516
520
whereClause += QString ( " ROWID IN (SELECT pkid FROM %1 WHERE %2)" ).arg ( idxName ).arg ( mbrFilter );
517
521
}
518
- else if ( spatialIndexMbrCache == true )
522
+ else if ( spatialIndexMbrCache )
519
523
{
520
524
// using the MbrCache spatial index
521
525
QString mbr = QString ( " %1, %2, %3, %4" ).
@@ -536,12 +540,12 @@ void QgsSpatiaLiteProvider::select( QgsAttributeList fetchAttributes, QgsRectang
536
540
}
537
541
}
538
542
539
- if ( whereClause.isEmpty () == false )
543
+ if ( ! whereClause.isEmpty () )
540
544
sql += whereClause;
541
545
542
546
mFetchGeom = fetchGeometry;
543
547
mAttributesToFetch = fetchAttributes;
544
- const char * xSql = sql.toUtf8 ();
548
+ QByteArray xSql = sql.toUtf8 ();
545
549
if ( sqlite3_prepare_v2 ( sqliteHandle, xSql, strlen ( xSql ), &sqliteStatement, NULL ) != SQLITE_OK )
546
550
{
547
551
// some error occurred
@@ -753,7 +757,7 @@ void QgsSpatiaLiteProvider::uniqueValues( int index, QList < QVariant > &uniqueV
753
757
sql = QString ( " SELECT DISTINCT %1 FROM %2 ORDER BY %1" ).arg ( fld.name () ).arg ( quotedValue ( mTableName ) );
754
758
755
759
// SQLite prepared statement
756
- const char * xSql = sql.toUtf8 ();
760
+ QByteArray xSql = sql.toUtf8 ();
757
761
if ( sqlite3_prepare_v2 ( sqliteHandle, xSql, strlen ( xSql ), &stmt, NULL ) != SQLITE_OK )
758
762
{
759
763
// some error occurred
@@ -829,7 +833,7 @@ bool QgsSpatiaLiteProvider::addFeatures( QgsFeatureList & flist )
829
833
QString sql;
830
834
QString values;
831
835
int ia;
832
- const char * xSql;
836
+ QByteArray xSql;
833
837
834
838
if ( flist.size () == 0 )
835
839
return true ;
@@ -844,7 +848,7 @@ bool QgsSpatiaLiteProvider::addFeatures( QgsFeatureList & flist )
844
848
}
845
849
toCommit = true ;
846
850
847
- if ( primaryKey.isEmpty () == false )
851
+ if ( ! primaryKey.isEmpty () )
848
852
{
849
853
sql = QString ( " INSERT INTO %1 (%2, %3" ).
850
854
arg ( quotedValue ( mTableName ) ).arg ( quotedValue ( primaryKey ) ).arg ( quotedValue ( geometryColumn ) );
@@ -934,7 +938,7 @@ bool QgsSpatiaLiteProvider::addFeatures( QgsFeatureList & flist )
934
938
// binding a TEXT value
935
939
QString txt = it->toString ();
936
940
int len = txt.length ();
937
- const char * vl = txt.toUtf8 ();
941
+ QByteArray vl = txt.toUtf8 ();
938
942
sqlite3_bind_text ( stmt, ++ia, vl, len, SQLITE_TRANSIENT );
939
943
}
940
944
else
@@ -997,7 +1001,7 @@ bool QgsSpatiaLiteProvider::deleteFeatures( const QgsFeatureIds & id )
997
1001
char *errMsg = NULL ;
998
1002
bool toCommit = false ;
999
1003
QString sql;
1000
- const char * xSql;
1004
+ QByteArray xSql;
1001
1005
1002
1006
sql = " BEGIN" ;
1003
1007
int ret = sqlite3_exec ( sqliteHandle, sql.toUtf8 (), NULL , NULL , &errMsg );
@@ -1221,7 +1225,7 @@ bool QgsSpatiaLiteProvider::changeGeometryValues( QgsGeometryMap & geometry_map
1221
1225
char *errMsg = NULL ;
1222
1226
bool toCommit = false ;
1223
1227
QString sql;
1224
- const char * xSql;
1228
+ QByteArray xSql;
1225
1229
1226
1230
sql = " BEGIN" ;
1227
1231
int ret = sqlite3_exec ( sqliteHandle, sql.toUtf8 (), NULL , NULL , &errMsg );
0 commit comments