[QGIS Commit] r10472 - in trunk/qgis/src: app providers/spatialite

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sun Apr 5 06:43:36 EDT 2009


Author: jef
Date: 2009-04-05 06:43:36 -0400 (Sun, 05 Apr 2009)
New Revision: 10472

Modified:
   trunk/qgis/src/app/qgsspatialitesourceselect.cpp
   trunk/qgis/src/providers/spatialite/qgsspatialiteprovider.cpp
Log:
make spatialite provider work on windows

Modified: trunk/qgis/src/app/qgsspatialitesourceselect.cpp
===================================================================
--- trunk/qgis/src/app/qgsspatialitesourceselect.cpp	2009-04-05 10:39:51 UTC (rev 10471)
+++ trunk/qgis/src/app/qgsspatialitesourceselect.cpp	2009-04-05 10:43:36 UTC (rev 10472)
@@ -31,8 +31,9 @@
 #include <QHeaderView>
 #include <QStringList>
 
-#include <cassert>
-#include <iostream>
+#ifdef _MSC_VER
+#define strcasecmp(a,b) stricmp(a,b)
+#endif
 
 QgsSpatiaLiteSourceSelect::QgsSpatiaLiteSourceSelect( QgisApp * app, Qt::WFlags fl ):
     QDialog( app, fl ), qgisApp( app )
@@ -491,7 +492,7 @@
   else
   {
     qDebug( "Unable to get list of spatially enabled tables from the database" );
-    qDebug( sqlite3_errmsg( handle ) );
+    qDebug( "%s", sqlite3_errmsg( handle ) );
   }
   closeSpatiaLiteDb( handle );
 
@@ -572,6 +573,7 @@
   }
   QMessageBox::critical( this, tr( "SpatiaLite getTableInfo Error" ),
                          tr( "Failure exploring tables from: %1\n\n%2" ).arg( mSqlitePath ).arg( errCause ) );
+  return false;
 }
 
 void QgsSpatiaLiteSourceSelect::showHelp()

Modified: trunk/qgis/src/providers/spatialite/qgsspatialiteprovider.cpp
===================================================================
--- trunk/qgis/src/providers/spatialite/qgsspatialiteprovider.cpp	2009-04-05 10:39:51 UTC (rev 10471)
+++ trunk/qgis/src/providers/spatialite/qgsspatialiteprovider.cpp	2009-04-05 10:43:36 UTC (rev 10472)
@@ -32,6 +32,10 @@
 
 #include "qgslogger.h"
 
+#ifdef _MSC_VER
+#define strcasecmp(a,b) stricmp(a,b)
+#endif
+
 const QString SPATIALITE_KEY = "spatialite";
 const QString SPATIALITE_DESCRIPTION = "SpatiaLite data provider";
 
@@ -213,13 +217,13 @@
     sql += ", ";
     sql += fieldname;
   }
-  if ( fetchGeometry == true )
+  if ( fetchGeometry )
   {
     sql += QString( ", AsBinary(%1)" ).arg( geometryColumn );
   }
   sql += QString( " FROM %1 WHERE ROWID = %2" ).arg( quotedValue( mTableName ) ).arg( featureId );
 
-  const char *xSql = sql.toUtf8();
+  QByteArray xSql = sql.toUtf8();
   if ( sqlite3_prepare_v2( sqliteHandle, xSql, strlen( xSql ), &stmt, NULL ) != SQLITE_OK )
   {
     // some error occurred
@@ -239,7 +243,7 @@
   if ( ret == SQLITE_ROW )
   {
     // one valid row has been fetched from the result set
-    if ( mFetchGeom == false )
+    if ( !mFetchGeom )
     {
       // no geometry was required
       feature.setGeometryAndOwnership( 0, 0 );
@@ -300,7 +304,7 @@
         if ( mFetchGeom )
         {
           QString geoCol = QString( "AsBinary(%1)" ).arg( geometryColumn );
-          const char *geomName = geoCol.toUtf8();
+          QByteArray geomName = geoCol.toUtf8();
           if ( strcasecmp( geomName, sqlite3_column_name( stmt, ic ) ) == 0 )
           {
             if ( sqlite3_column_type( stmt, ic ) == SQLITE_BLOB )
@@ -362,7 +366,7 @@
   if ( ret == SQLITE_ROW )
   {
     // one valid row has been fetched from the result set
-    if ( mFetchGeom == false )
+    if ( !mFetchGeom )
     {
       // no geometry was required
       feature.setGeometryAndOwnership( 0, 0 );
@@ -423,7 +427,7 @@
         if ( mFetchGeom )
         {
           QString geoCol = QString( "AsBinary(%1)" ).arg( geometryColumn );
-          const char *geomName = geoCol.toUtf8();
+          QByteArray geomName = geoCol.toUtf8();
           if ( strcasecmp( geomName, sqlite3_column_name( sqliteStatement, ic ) ) == 0 )
           {
             if ( sqlite3_column_type( sqliteStatement, ic ) == SQLITE_BLOB )
@@ -484,7 +488,7 @@
     sql += ", ";
     sql += fieldname;
   }
-  if ( fetchGeometry == true )
+  if ( fetchGeometry )
   {
     sql += QString( ", AsBinary(%1)" ).arg( geometryColumn );
   }
@@ -492,10 +496,10 @@
 
   QString whereClause;
 
-  if ( rect.isEmpty() == false )
+  if ( !rect.isEmpty() )
   {
     // some kind of MBR spatial filtering is required
-    whereClause = "WHERE ";
+    whereClause = " WHERE ";
     if ( useIntersect )
     {
       // we are requested to evaluate a true INTERSECT relationship
@@ -505,7 +509,7 @@
                     arg( QString::number( rect.xMaximum(), 'f', 6 ) ).arg( QString::number( rect.yMaximum(), 'f', 6 ) );
       whereClause += QString( "Intersects(%1, BuildMbr(%2)) AND " ).arg( geometryColumn ).arg( mbr );
     }
-    if ( spatialIndexRTree == true )
+    if ( spatialIndexRTree )
     {
       // using the RTree spatial index
       QString mbrFilter = QString( "xmin <= %1 AND " ).arg( QString::number( rect.xMaximum(), 'f', 6 ) );
@@ -515,7 +519,7 @@
       QString idxName = QString( "idx_%1_%2" ).arg( mTableName ).arg( geometryColumn );
       whereClause += QString( "ROWID IN (SELECT pkid FROM %1 WHERE %2)" ).arg( idxName ).arg( mbrFilter );
     }
-    else if ( spatialIndexMbrCache == true )
+    else if ( spatialIndexMbrCache )
     {
       // using the MbrCache spatial index
       QString mbr = QString( "%1, %2, %3, %4" ).
@@ -536,12 +540,12 @@
     }
   }
 
-  if ( whereClause.isEmpty() == false )
+  if ( !whereClause.isEmpty() )
     sql += whereClause;
 
   mFetchGeom = fetchGeometry;
   mAttributesToFetch = fetchAttributes;
-  const char *xSql = sql.toUtf8();
+  QByteArray xSql = sql.toUtf8();
   if ( sqlite3_prepare_v2( sqliteHandle, xSql, strlen( xSql ), &sqliteStatement, NULL ) != SQLITE_OK )
   {
     // some error occurred
@@ -753,7 +757,7 @@
   sql = QString( "SELECT DISTINCT %1 FROM %2 ORDER BY %1" ).arg( fld.name() ).arg( quotedValue( mTableName ) );
 
   // SQLite prepared statement
-  const char *xSql = sql.toUtf8();
+  QByteArray xSql = sql.toUtf8();
   if ( sqlite3_prepare_v2( sqliteHandle, xSql, strlen( xSql ), &stmt, NULL ) != SQLITE_OK )
   {
     // some error occurred
@@ -829,7 +833,7 @@
   QString sql;
   QString values;
   int ia;
-  const char *xSql;
+  QByteArray xSql;
 
   if ( flist.size() == 0 )
     return true;
@@ -844,7 +848,7 @@
   }
   toCommit = true;
 
-  if ( primaryKey.isEmpty() == false )
+  if ( !primaryKey.isEmpty() )
   {
     sql = QString( "INSERT INTO %1 (%2, %3" ).
           arg( quotedValue( mTableName ) ).arg( quotedValue( primaryKey ) ).arg( quotedValue( geometryColumn ) );
@@ -934,7 +938,7 @@
         // binding a TEXT value
         QString txt = it->toString();
         int len = txt.length();
-        const char *vl = txt.toUtf8();
+        QByteArray vl = txt.toUtf8();
         sqlite3_bind_text( stmt, ++ia, vl, len, SQLITE_TRANSIENT );
       }
       else
@@ -997,7 +1001,7 @@
   char *errMsg = NULL;
   bool toCommit = false;
   QString sql;
-  const char *xSql;
+  QByteArray xSql;
 
   sql = "BEGIN";
   int ret = sqlite3_exec( sqliteHandle, sql.toUtf8(), NULL, NULL, &errMsg );
@@ -1221,7 +1225,7 @@
   char *errMsg = NULL;
   bool toCommit = false;
   QString sql;
-  const char *xSql;
+  QByteArray xSql;
 
   sql = "BEGIN";
   int ret = sqlite3_exec( sqliteHandle, sql.toUtf8(), NULL, NULL, &errMsg );



More information about the QGIS-commit mailing list