@@ -32,6 +32,10 @@ email : a.furieri@lqt.it
3232
3333#include " qgslogger.h"
3434
35+ #ifdef _MSC_VER
36+ #define strcasecmp (a,b ) stricmp(a,b)
37+ #endif
38+
3539const QString SPATIALITE_KEY = " spatialite" ;
3640const QString SPATIALITE_DESCRIPTION = " SpatiaLite data provider" ;
3741
@@ -213,13 +217,13 @@ bool QgsSpatiaLiteProvider::featureAtId( int featureId, QgsFeature & feature, bo
213217 sql += " , " ;
214218 sql += fieldname;
215219 }
216- if ( fetchGeometry == true )
220+ if ( fetchGeometry )
217221 {
218222 sql += QString ( " , AsBinary(%1)" ).arg ( geometryColumn );
219223 }
220224 sql += QString ( " FROM %1 WHERE ROWID = %2" ).arg ( quotedValue ( mTableName ) ).arg ( featureId );
221225
222- const char * xSql = sql.toUtf8 ();
226+ QByteArray xSql = sql.toUtf8 ();
223227 if ( sqlite3_prepare_v2 ( sqliteHandle, xSql, strlen ( xSql ), &stmt, NULL ) != SQLITE_OK )
224228 {
225229 // some error occurred
@@ -239,7 +243,7 @@ bool QgsSpatiaLiteProvider::featureAtId( int featureId, QgsFeature & feature, bo
239243 if ( ret == SQLITE_ROW )
240244 {
241245 // one valid row has been fetched from the result set
242- if ( mFetchGeom == false )
246+ if ( ! mFetchGeom )
243247 {
244248 // no geometry was required
245249 feature.setGeometryAndOwnership ( 0 , 0 );
@@ -300,7 +304,7 @@ bool QgsSpatiaLiteProvider::featureAtId( int featureId, QgsFeature & feature, bo
300304 if ( mFetchGeom )
301305 {
302306 QString geoCol = QString ( " AsBinary(%1)" ).arg ( geometryColumn );
303- const char * geomName = geoCol.toUtf8 ();
307+ QByteArray geomName = geoCol.toUtf8 ();
304308 if ( strcasecmp ( geomName, sqlite3_column_name ( stmt, ic ) ) == 0 )
305309 {
306310 if ( sqlite3_column_type ( stmt, ic ) == SQLITE_BLOB )
@@ -362,7 +366,7 @@ bool QgsSpatiaLiteProvider::nextFeature( QgsFeature & feature )
362366 if ( ret == SQLITE_ROW )
363367 {
364368 // one valid row has been fetched from the result set
365- if ( mFetchGeom == false )
369+ if ( ! mFetchGeom )
366370 {
367371 // no geometry was required
368372 feature.setGeometryAndOwnership ( 0 , 0 );
@@ -423,7 +427,7 @@ bool QgsSpatiaLiteProvider::nextFeature( QgsFeature & feature )
423427 if ( mFetchGeom )
424428 {
425429 QString geoCol = QString ( " AsBinary(%1)" ).arg ( geometryColumn );
426- const char * geomName = geoCol.toUtf8 ();
430+ QByteArray geomName = geoCol.toUtf8 ();
427431 if ( strcasecmp ( geomName, sqlite3_column_name ( sqliteStatement, ic ) ) == 0 )
428432 {
429433 if ( sqlite3_column_type ( sqliteStatement, ic ) == SQLITE_BLOB )
@@ -484,18 +488,18 @@ void QgsSpatiaLiteProvider::select( QgsAttributeList fetchAttributes, QgsRectang
484488 sql += " , " ;
485489 sql += fieldname;
486490 }
487- if ( fetchGeometry == true )
491+ if ( fetchGeometry )
488492 {
489493 sql += QString ( " , AsBinary(%1)" ).arg ( geometryColumn );
490494 }
491495 sql += QString ( " FROM %1" ).arg ( quotedValue ( mTableName ) );
492496
493497 QString whereClause;
494498
495- if ( rect.isEmpty () == false )
499+ if ( ! rect.isEmpty () )
496500 {
497501 // some kind of MBR spatial filtering is required
498- whereClause = " WHERE " ;
502+ whereClause = " WHERE " ;
499503 if ( useIntersect )
500504 {
501505 // we are requested to evaluate a true INTERSECT relationship
@@ -505,7 +509,7 @@ void QgsSpatiaLiteProvider::select( QgsAttributeList fetchAttributes, QgsRectang
505509 arg ( QString::number ( rect.xMaximum (), ' f' , 6 ) ).arg ( QString::number ( rect.yMaximum (), ' f' , 6 ) );
506510 whereClause += QString ( " Intersects(%1, BuildMbr(%2)) AND " ).arg ( geometryColumn ).arg ( mbr );
507511 }
508- if ( spatialIndexRTree == true )
512+ if ( spatialIndexRTree )
509513 {
510514 // using the RTree spatial index
511515 QString mbrFilter = QString ( " xmin <= %1 AND " ).arg ( QString::number ( rect.xMaximum (), ' f' , 6 ) );
@@ -515,7 +519,7 @@ void QgsSpatiaLiteProvider::select( QgsAttributeList fetchAttributes, QgsRectang
515519 QString idxName = QString ( " idx_%1_%2" ).arg ( mTableName ).arg ( geometryColumn );
516520 whereClause += QString ( " ROWID IN (SELECT pkid FROM %1 WHERE %2)" ).arg ( idxName ).arg ( mbrFilter );
517521 }
518- else if ( spatialIndexMbrCache == true )
522+ else if ( spatialIndexMbrCache )
519523 {
520524 // using the MbrCache spatial index
521525 QString mbr = QString ( " %1, %2, %3, %4" ).
@@ -536,12 +540,12 @@ void QgsSpatiaLiteProvider::select( QgsAttributeList fetchAttributes, QgsRectang
536540 }
537541 }
538542
539- if ( whereClause.isEmpty () == false )
543+ if ( ! whereClause.isEmpty () )
540544 sql += whereClause;
541545
542546 mFetchGeom = fetchGeometry;
543547 mAttributesToFetch = fetchAttributes;
544- const char * xSql = sql.toUtf8 ();
548+ QByteArray xSql = sql.toUtf8 ();
545549 if ( sqlite3_prepare_v2 ( sqliteHandle, xSql, strlen ( xSql ), &sqliteStatement, NULL ) != SQLITE_OK )
546550 {
547551 // some error occurred
@@ -753,7 +757,7 @@ void QgsSpatiaLiteProvider::uniqueValues( int index, QList < QVariant > &uniqueV
753757 sql = QString ( " SELECT DISTINCT %1 FROM %2 ORDER BY %1" ).arg ( fld.name () ).arg ( quotedValue ( mTableName ) );
754758
755759 // SQLite prepared statement
756- const char * xSql = sql.toUtf8 ();
760+ QByteArray xSql = sql.toUtf8 ();
757761 if ( sqlite3_prepare_v2 ( sqliteHandle, xSql, strlen ( xSql ), &stmt, NULL ) != SQLITE_OK )
758762 {
759763 // some error occurred
@@ -829,7 +833,7 @@ bool QgsSpatiaLiteProvider::addFeatures( QgsFeatureList & flist )
829833 QString sql;
830834 QString values;
831835 int ia;
832- const char * xSql;
836+ QByteArray xSql;
833837
834838 if ( flist.size () == 0 )
835839 return true ;
@@ -844,7 +848,7 @@ bool QgsSpatiaLiteProvider::addFeatures( QgsFeatureList & flist )
844848 }
845849 toCommit = true ;
846850
847- if ( primaryKey.isEmpty () == false )
851+ if ( ! primaryKey.isEmpty () )
848852 {
849853 sql = QString ( " INSERT INTO %1 (%2, %3" ).
850854 arg ( quotedValue ( mTableName ) ).arg ( quotedValue ( primaryKey ) ).arg ( quotedValue ( geometryColumn ) );
@@ -934,7 +938,7 @@ bool QgsSpatiaLiteProvider::addFeatures( QgsFeatureList & flist )
934938 // binding a TEXT value
935939 QString txt = it->toString ();
936940 int len = txt.length ();
937- const char * vl = txt.toUtf8 ();
941+ QByteArray vl = txt.toUtf8 ();
938942 sqlite3_bind_text ( stmt, ++ia, vl, len, SQLITE_TRANSIENT );
939943 }
940944 else
@@ -997,7 +1001,7 @@ bool QgsSpatiaLiteProvider::deleteFeatures( const QgsFeatureIds & id )
9971001 char *errMsg = NULL ;
9981002 bool toCommit = false ;
9991003 QString sql;
1000- const char * xSql;
1004+ QByteArray xSql;
10011005
10021006 sql = " BEGIN" ;
10031007 int ret = sqlite3_exec ( sqliteHandle, sql.toUtf8 (), NULL , NULL , &errMsg );
@@ -1221,7 +1225,7 @@ bool QgsSpatiaLiteProvider::changeGeometryValues( QgsGeometryMap & geometry_map
12211225 char *errMsg = NULL ;
12221226 bool toCommit = false ;
12231227 QString sql;
1224- const char * xSql;
1228+ QByteArray xSql;
12251229
12261230 sql = " BEGIN" ;
12271231 int ret = sqlite3_exec ( sqliteHandle, sql.toUtf8 (), NULL , NULL , &errMsg );
0 commit comments