[QGIS Commit] r12324 - in trunk/qgis/src: core/spatialite providers/spatialite

svn_qgis at osgeo.org svn_qgis at osgeo.org
Thu Dec 3 09:28:02 EST 2009


Author: esseffe
Date: 2009-12-03 09:28:02 -0500 (Thu, 03 Dec 2009)
New Revision: 12324

Modified:
   trunk/qgis/src/core/spatialite/spatialite.c
   trunk/qgis/src/providers/spatialite/qgsspatialiteprovider.cpp
Log:
fix #2170: (double-quoting any SQL table or column name)


Modified: trunk/qgis/src/core/spatialite/spatialite.c
===================================================================
--- trunk/qgis/src/core/spatialite/spatialite.c	2009-12-03 13:46:15 UTC (rev 12323)
+++ trunk/qgis/src/core/spatialite/spatialite.c	2009-12-03 14:28:02 UTC (rev 12324)
@@ -7,7 +7,7 @@
 ** of 5% are more are commonly seen when SQLite is compiled as a single
 ** translation unit.
 **
-** This amalgamation was generated on 2009-11-12 09:49:19 +0100.
+** This amalgamation was generated on 2009-12-03 13:49:58 +0100.
 
 Author: Alessandro (Sandro) Furieri <a.furieri at lqt.it>
 
@@ -7387,6 +7387,7 @@
 	"AS",
 	"AUTOINCREMENT",
 	"BETWEEN",
+	"BLOB",
 	"BY",
 	"CASE",
 	"CHECK",
@@ -7395,10 +7396,13 @@
 	"CONSTRAINT",
 	"CREATE",
 	"CROSS",
+	"DATE",
+	"DATETIME",
 	"DEFAULT",
 	"DEFERRABLE",
 	"DELETE",
 	"DISTINCT",
+	"DOUBLE",
 	"DROP",
 	"ELSE",
 	"ESCAPE",
@@ -7413,11 +7417,13 @@
 	"INDEX",
 	"INNER",
 	"INSERT",
+	"INTEGER",
 	"INTERSECT",
 	"INTO",
 	"IS",
 	"ISNULL",
 	"JOIN",
+	"KEY",
 	"LEFT",
 	"LIKE",
 	"LIMIT",
@@ -7429,6 +7435,7 @@
 	"OR",
 	"ORDER",
 	"OUTER",
+	"PRAGMA",
 	"PRIMARY",
 	"REFERENCES",
 	"RIGHT",
@@ -7436,7 +7443,11 @@
 	"SELECT",
 	"SET",
 	"TABLE",
+	"TEMP",
+	"TEMPORARY",
 	"THEN",
+	"TEXT",
+	"TIMESTAMP",
 	"TO",
 	"TRANSACTION",
 	"UNION",
@@ -7444,6 +7455,7 @@
 	"UPDATE",
 	"USING",
 	"VALUES",
+	"VIEW",
 	"WHEN",
 	"WHERE",
 	NULL
@@ -24874,8 +24886,8 @@
 		else
 		  {
 		      /* compressing any other intermediate vertex */
-		      fx = x - last_x;
-		      fy = y - last_y;
+		      fx = (float) (x - last_x);
+		      fy = (float) (y - last_y);
 		      gaiaExportF32 (ptr, fx, 1, endian_arch);
 		      gaiaExportF32 (ptr + 4, fy, 1, endian_arch);
 		      ptr += 8;
@@ -24911,9 +24923,9 @@
 		else
 		  {
 		      /* compressing any other intermediate vertex */
-		      fx = x - last_x;
-		      fy = y - last_y;
-		      fz = z - last_z;
+		      fx = (float) (x - last_x);
+		      fy = (float) (y - last_y);
+		      fz = (float) (z - last_z);
 		      gaiaExportF32 (ptr, fx, 1, endian_arch);
 		      gaiaExportF32 (ptr + 4, fy, 1, endian_arch);
 		      gaiaExportF32 (ptr + 8, fz, 1, endian_arch);
@@ -24951,8 +24963,8 @@
 		else
 		  {
 		      /* compressing any other intermediate vertex */
-		      fx = x - last_x;
-		      fy = y - last_y;
+		      fx = (float) (x - last_x);
+		      fy = (float) (y - last_y);
 		      gaiaExportF32 (ptr, fx, 1, endian_arch);
 		      gaiaExportF32 (ptr + 4, fy, 1, endian_arch);
 		      gaiaExport64 (ptr + 8, m, 1, endian_arch);
@@ -24990,9 +25002,9 @@
 		else
 		  {
 		      /* compressing any other intermediate vertex */
-		      fx = x - last_x;
-		      fy = y - last_y;
-		      fz = z - last_z;
+		      fx = (float) (x - last_x);
+		      fy = (float) (y - last_y);
+		      fz = (float) (z - last_z);
 		      gaiaExportF32 (ptr, fx, 1, endian_arch);
 		      gaiaExportF32 (ptr + 4, fy, 1, endian_arch);
 		      gaiaExportF32 (ptr + 8, fz, 1, endian_arch);
@@ -25032,8 +25044,8 @@
 		else
 		  {
 		      /* compressing any other intermediate vertex */
-		      fx = x - last_x;
-		      fy = y - last_y;
+		      fx = (float) (x - last_x);
+		      fy = (float) (y - last_y);
 		      gaiaExportF32 (ptr, fx, 1, endian_arch);
 		      gaiaExportF32 (ptr + 4, fy, 1, endian_arch);
 		      ptr += 8;
@@ -25059,8 +25071,8 @@
 		      else
 			{
 			    /* compressing any other intermediate vertex */
-			    fx = x - last_x;
-			    fy = y - last_y;
+			    fx = (float) (x - last_x);
+			    fy = (float) (y - last_y);
 			    gaiaExportF32 (ptr, fx, 1, endian_arch);
 			    gaiaExportF32 (ptr + 4, fy, 1, endian_arch);
 			    ptr += 8;
@@ -25099,9 +25111,9 @@
 		else
 		  {
 		      /* compressing any other intermediate vertex */
-		      fx = x - last_x;
-		      fy = y - last_y;
-		      fz = z - last_z;
+		      fx = (float) (x - last_x);
+		      fy = (float) (y - last_y);
+		      fz = (float) (z - last_z);
 		      gaiaExportF32 (ptr, fx, 1, endian_arch);
 		      gaiaExportF32 (ptr + 4, fy, 1, endian_arch);
 		      gaiaExportF32 (ptr + 8, fz, 1, endian_arch);
@@ -25130,9 +25142,9 @@
 		      else
 			{
 			    /* compressing any other intermediate vertex */
-			    fx = x - last_x;
-			    fy = y - last_y;
-			    fz = z - last_z;
+			    fx = (float) (x - last_x);
+			    fy = (float) (y - last_y);
+			    fz = (float) (z - last_z);
 			    gaiaExportF32 (ptr, fx, 1, endian_arch);
 			    gaiaExportF32 (ptr + 4, fy, 1, endian_arch);
 			    gaiaExportF32 (ptr + 8, fz, 1, endian_arch);
@@ -25173,8 +25185,8 @@
 		else
 		  {
 		      /* compressing any other intermediate vertex */
-		      fx = x - last_x;
-		      fy = y - last_y;
+		      fx = (float) (x - last_x);
+		      fy = (float) (y - last_y);
 		      gaiaExportF32 (ptr, fx, 1, endian_arch);
 		      gaiaExportF32 (ptr + 4, fy, 1, endian_arch);
 		      gaiaExport64 (ptr + 8, m, 1, endian_arch);
@@ -25202,8 +25214,8 @@
 		      else
 			{
 			    /* compressing any other intermediate vertex */
-			    fx = x - last_x;
-			    fy = y - last_y;
+			    fx = (float) (x - last_x);
+			    fy = (float) (y - last_y);
 			    gaiaExportF32 (ptr, fx, 1, endian_arch);
 			    gaiaExportF32 (ptr + 4, fy, 1, endian_arch);
 			    gaiaExport64 (ptr + 8, m, 1, endian_arch);
@@ -25244,9 +25256,9 @@
 		else
 		  {
 		      /* compressing any other intermediate vertex */
-		      fx = x - last_x;
-		      fy = y - last_y;
-		      fz = z - last_z;
+		      fx = (float) (x - last_x);
+		      fy = (float) (y - last_y);
+		      fz = (float) (z - last_z);
 		      gaiaExportF32 (ptr, fx, 1, endian_arch);
 		      gaiaExportF32 (ptr + 4, fy, 1, endian_arch);
 		      gaiaExportF32 (ptr + 8, fz, 1, endian_arch);
@@ -25277,9 +25289,9 @@
 		      else
 			{
 			    /* compressing any other intermediate vertex */
-			    fx = x - last_x;
-			    fy = y - last_y;
-			    fz = z - last_z;
+			    fx = (float) (x - last_x);
+			    fy = (float) (y - last_y);
+			    fz = (float) (z - last_z);
 			    gaiaExportF32 (ptr, fx, 1, endian_arch);
 			    gaiaExportF32 (ptr + 4, fy, 1, endian_arch);
 			    gaiaExportF32 (ptr + 8, fz, 1, endian_arch);
@@ -25388,8 +25400,8 @@
 		      else
 			{
 			    /* compressing any other intermeditate vertex */
-			    fx = x - last_x;
-			    fy = y - last_y;
+			    fx = (float) (x - last_x);
+			    fy = (float) (y - last_y);
 			    gaiaExportF32 (ptr, fx, 1, endian_arch);	/* X */
 			    gaiaExportF32 (ptr + 4, fy, 1, endian_arch);	/* Y */
 			    ptr += 8;
@@ -25405,7 +25417,7 @@
 			    else
 			      {
 				  /* compressing any other intermeditate vertex */
-				  fz = z - last_z;
+				  fz = (float) (z - last_z);
 				  gaiaExportF32 (ptr, fz, 1, endian_arch);	/* Z */
 				  ptr += 4;
 			      }
@@ -25426,7 +25438,7 @@
 			    else
 			      {
 				  /* compressing any other intermeditate vertex */
-				  fz = z - last_z;
+				  fz = (float) (z - last_z);
 				  gaiaExportF32 (ptr, fz, 1, endian_arch);	/* Z */
 				  ptr += 4;
 			      }
@@ -25485,8 +25497,8 @@
 		      else
 			{
 			    /* compressing any other intermeditate vertex */
-			    fx = x - last_x;
-			    fy = y - last_y;
+			    fx = (float) (x - last_x);
+			    fy = (float) (y - last_y);
 			    gaiaExportF32 (ptr, fx, 1, endian_arch);	/* X */
 			    gaiaExportF32 (ptr + 4, fy, 1, endian_arch);	/* Y */
 			    ptr += 8;
@@ -25502,7 +25514,7 @@
 			    else
 			      {
 				  /* compressing any other intermeditate vertex */
-				  fz = z - last_z;
+				  fz = (float) (z - last_z);
 				  gaiaExportF32 (ptr, fz, 1, endian_arch);	/* Z */
 				  ptr += 4;
 			      }
@@ -25523,7 +25535,7 @@
 			    else
 			      {
 				  /* compressing any other intermeditate vertex */
-				  fz = z - last_z;
+				  fz = (float) (z - last_z);
 				  gaiaExportF32 (ptr, fz, 1, endian_arch);	/* Z */
 				  ptr += 4;
 			      }
@@ -25570,8 +25582,8 @@
 			    else
 			      {
 				  /* compressing any other intermeditate vertex */
-				  fx = x - last_x;
-				  fy = y - last_y;
+				  fx = (float) (x - last_x);
+				  fy = (float) (y - last_y);
 				  gaiaExportF32 (ptr, fx, 1, endian_arch);	/* X */
 				  gaiaExportF32 (ptr + 4, fy, 1, endian_arch);	/* Y */
 				  ptr += 8;
@@ -25587,7 +25599,7 @@
 				  else
 				    {
 					/* compressing any other intermeditate vertex */
-					fz = z - last_z;
+					fz = (float) (z - last_z);
 					gaiaExportF32 (ptr, fz, 1, endian_arch);	/* Z */
 					ptr += 4;
 				    }
@@ -25608,7 +25620,7 @@
 				  else
 				    {
 					/* compressing any other intermeditate vertex */
-					fz = z - last_z;
+					fz = (float) (z - last_z);
 					gaiaExportF32 (ptr, fz, 1, endian_arch);	/* Z */
 					ptr += 4;
 				    }
@@ -26466,7 +26478,7 @@
 	  x = gaiaImport64 (ptr, GAIA_LITTLE_ENDIAN, endian_arch);
 	  y = gaiaImport64 (ptr + 8, GAIA_LITTLE_ENDIAN, endian_arch);
 	  z = gaiaImport64 (ptr + 8, GAIA_LITTLE_ENDIAN, endian_arch);
-	  gaiaAddPointToGeomCollXYZ (geom, x, y, m);
+	  gaiaAddPointToGeomCollXYZ (geom, x, y, z);
       }
     else if (type == GAIA_XY_Z_M)
       {
@@ -33968,7 +33980,7 @@
 
 static int
 recoverGeomColumn (sqlite3 * sqlite, const unsigned char *table,
-		   const unsigned char *column, int xtype, int srid)
+		   const unsigned char *column, int xtype, int dims, int srid)
 {
 /* checks if TABLE.COLUMN exists and has the required features */
     int ok = 1;
@@ -33997,7 +34009,7 @@
 	      break;		/* end of result set */
 	  if (ret == SQLITE_ROW)
 	    {
-		/* cecking Geometry features */
+		/* checking Geometry features */
 		geom = NULL;
 		for (i_col = 0; i_col < sqlite3_column_count (stmt); i_col++)
 		  {
@@ -34012,6 +34024,8 @@
 				ok = 0;
 			    else
 			      {
+				  if (geom->DimensionModel != dims)
+				      ok = 0;
 				  if (geom->Srid != srid)
 				      ok = 0;
 				  type = gaiaGeometryType (geom);
@@ -34743,8 +34757,11 @@
     const unsigned char *column;
     const unsigned char *type;
     int xtype;
+    int xxtype;
     int srid = -1;
+    const unsigned char *txt_dims;
     int dimension = 2;
+    int dims = -1;
     char dummy[32];
     char sql[1024];
     char *errMsg = NULL;
@@ -34788,14 +34805,33 @@
 	  return;
       }
     type = sqlite3_value_text (argv[3]);
-    if (sqlite3_value_type (argv[4]) != SQLITE_INTEGER)
+    if (sqlite3_value_type (argv[4]) == SQLITE_INTEGER)
       {
+	  dimension = sqlite3_value_int (argv[4]);
+	  if (dimension == 2)
+	      dims = GAIA_XY;
+	  if (dimension == 3)
+	      dims = GAIA_XY_Z;
+      }
+    else if (sqlite3_value_type (argv[4]) == SQLITE_TEXT)
+      {
+	  txt_dims = sqlite3_value_text (argv[4]);
+	  if (strcasecmp ((char *) txt_dims, "XY") == 0)
+	      dims = GAIA_XY;
+	  if (strcasecmp ((char *) txt_dims, "XYZ") == 0)
+	      dims = GAIA_XY_Z;
+	  if (strcasecmp ((char *) txt_dims, "XYM") == 0)
+	      dims = GAIA_XY_M;
+	  if (strcasecmp ((char *) txt_dims, "XYZM") == 0)
+	      dims = GAIA_XY_Z_M;
+      }
+    else
+      {
 	  fprintf (stderr,
-		   "RecoverGeometryColumn() error: argument 5 [dimension] is not of the Integer type\n");
+		   "RecoverGeometryColumn() error: argument 5 [dimension] is not of the Integer or Text type\n");
 	  sqlite3_result_int (context, 0);
 	  return;
       }
-    dimension = sqlite3_value_int (argv[4]);
     xtype = GAIA_UNKNOWN;
     if (strcasecmp ((char *) type, "POINT") == 0)
 	xtype = GAIA_POINT;
@@ -34820,10 +34856,13 @@
 	  sqlite3_result_int (context, 0);
 	  return;
       }
-    if (dimension != 2)
+    if (dims == GAIA_XY || dims == GAIA_XY_Z || dims == GAIA_XY_M
+	|| dims == GAIA_XY_Z_M)
+	;
+    else
       {
 	  fprintf (stderr,
-		   "RecoverGeometryColumn() error: argument 5 [dimension] current version only accepts dimension=2\n");
+		   "RecoverGeometryColumn() error: argument 5 [dimension] ILLEGAL VALUE\n");
 	  sqlite3_result_int (context, 0);
 	  return;
       }
@@ -34853,8 +34892,137 @@
 	  sqlite3_result_int (context, 0);
 	  return;
       }
-    if (!recoverGeomColumn (sqlite, table, column, xtype, srid))
+/* adjusting the actucal GeometryType */
+    xxtype = xtype;
+    xtype = GAIA_UNKNOWN;
+    if (xxtype == GAIA_POINT)
       {
+	  switch (dims)
+	    {
+	    case GAIA_XY_Z:
+		xtype = GAIA_POINTZ;
+		break;
+	    case GAIA_XY_M:
+		xtype = GAIA_POINTM;
+		break;
+	    case GAIA_XY_Z_M:
+		xtype = GAIA_POINTZM;
+		break;
+	    default:
+		xtype = GAIA_POINT;
+		break;
+	    };
+      }
+    if (xxtype == GAIA_LINESTRING)
+      {
+	  switch (dims)
+	    {
+	    case GAIA_XY_Z:
+		xtype = GAIA_LINESTRINGZ;
+		break;
+	    case GAIA_XY_M:
+		xtype = GAIA_LINESTRINGM;
+		break;
+	    case GAIA_XY_Z_M:
+		xtype = GAIA_LINESTRINGZM;
+		break;
+	    default:
+		xtype = GAIA_LINESTRING;
+		break;
+	    };
+      }
+    if (xxtype == GAIA_POLYGON)
+      {
+	  switch (dims)
+	    {
+	    case GAIA_XY_Z:
+		xtype = GAIA_POLYGONZ;
+		break;
+	    case GAIA_XY_M:
+		xtype = GAIA_POLYGONM;
+		break;
+	    case GAIA_XY_Z_M:
+		xtype = GAIA_POLYGONZM;
+		break;
+	    default:
+		xtype = GAIA_POLYGON;
+		break;
+	    };
+      }
+    if (xxtype == GAIA_MULTIPOINT)
+      {
+	  switch (dims)
+	    {
+	    case GAIA_XY_Z:
+		xtype = GAIA_MULTIPOINTZ;
+		break;
+	    case GAIA_XY_M:
+		xtype = GAIA_MULTIPOINTM;
+		break;
+	    case GAIA_XY_Z_M:
+		xtype = GAIA_MULTIPOINTZM;
+		break;
+	    default:
+		xtype = GAIA_MULTIPOINT;
+		break;
+	    };
+      }
+    if (xxtype == GAIA_MULTILINESTRING)
+      {
+	  switch (dims)
+	    {
+	    case GAIA_XY_Z:
+		xtype = GAIA_MULTILINESTRINGZ;
+		break;
+	    case GAIA_XY_M:
+		xtype = GAIA_MULTILINESTRINGM;
+		break;
+	    case GAIA_XY_Z_M:
+		xtype = GAIA_MULTILINESTRINGZM;
+		break;
+	    default:
+		xtype = GAIA_MULTILINESTRING;
+		break;
+	    };
+      }
+    if (xxtype == GAIA_MULTIPOLYGON)
+      {
+	  switch (dims)
+	    {
+	    case GAIA_XY_Z:
+		xtype = GAIA_MULTIPOLYGONZ;
+		break;
+	    case GAIA_XY_M:
+		xtype = GAIA_MULTIPOLYGONM;
+		break;
+	    case GAIA_XY_Z_M:
+		xtype = GAIA_MULTIPOLYGONZM;
+		break;
+	    default:
+		xtype = GAIA_MULTIPOLYGON;
+		break;
+	    };
+      }
+    if (xxtype == GAIA_GEOMETRYCOLLECTION)
+      {
+	  switch (dims)
+	    {
+	    case GAIA_XY_Z:
+		xtype = GAIA_GEOMETRYCOLLECTIONZ;
+		break;
+	    case GAIA_XY_M:
+		xtype = GAIA_GEOMETRYCOLLECTIONM;
+		break;
+	    case GAIA_XY_Z_M:
+		xtype = GAIA_GEOMETRYCOLLECTIONZM;
+		break;
+	    default:
+		xtype = GAIA_GEOMETRYCOLLECTION;
+		break;
+	    };
+      }
+    if (!recoverGeomColumn (sqlite, table, column, xtype, dims, srid))
+      {
 	  fprintf (stderr, "RecoverGeometryColumn(): validation failed\n");
 	  sqlite3_result_int (context, 0);
 	  return;
@@ -34894,7 +35062,23 @@
 	  strcat (sql, "GEOMETRY");
 	  break;
       };
-    strcat (sql, "', 2, ");
+    strcat (sql, "', '");
+    switch (dims)
+      {
+      case GAIA_XY:
+	  strcat (sql, "XY");
+	  break;
+      case GAIA_XY_Z:
+	  strcat (sql, "XYZ");
+	  break;
+      case GAIA_XY_M:
+	  strcat (sql, "XYM");
+	  break;
+      case GAIA_XY_Z_M:
+	  strcat (sql, "XYZM");
+	  break;
+      };
+    strcat (sql, "', ");
     if (srid <= 0)
 	strcat (sql, "-1");
     else
@@ -37469,6 +37653,60 @@
 }
 
 static void
+fnct_CoordDimension (sqlite3_context * context, int argc, sqlite3_value ** argv)
+{
+/* SQL function:
+/ CoordDimension(BLOB encoded geometry)
+/
+/ returns:
+/ 'XY', 'XYM', 'XYZ', 'XYZM'
+/ or NULL if any error is encountered
+*/
+    unsigned char *p_blob;
+    int n_bytes;
+    int len;
+    char *p_dim = NULL;
+    char *p_result = NULL;
+    gaiaGeomCollPtr geo = NULL;
+    GAIA_UNUSED ();
+    if (sqlite3_value_type (argv[0]) != SQLITE_BLOB)
+      {
+	  sqlite3_result_null (context);
+	  return;
+      }
+    p_blob = (unsigned char *) sqlite3_value_blob (argv[0]);
+    n_bytes = sqlite3_value_bytes (argv[0]);
+    geo = gaiaFromSpatiaLiteBlobWkb (p_blob, n_bytes);
+    if (!geo)
+	sqlite3_result_null (context);
+    else
+      {
+	  if (geo->DimensionModel == GAIA_XY)
+	      p_dim = "XY";
+	  else if (geo->DimensionModel == GAIA_XY_Z)
+	      p_dim = "XYZ";
+	  else if (geo->DimensionModel == GAIA_XY_M)
+	      p_dim = "XYM";
+	  else if (geo->DimensionModel == GAIA_XY_Z_M)
+	      p_dim = "XYZM";
+	  if (p_dim)
+	    {
+		len = strlen (p_dim);
+		p_result = malloc (len + 1);
+		strcpy (p_result, p_dim);
+	    }
+	  if (!p_result)
+	      sqlite3_result_null (context);
+	  else
+	    {
+		len = strlen (p_result);
+		sqlite3_result_text (context, p_result, len, free);
+	    }
+      }
+    gaiaFreeGeomColl (geo);
+}
+
+static void
 fnct_GeometryType (sqlite3_context * context, int argc, sqlite3_value ** argv)
 {
 /* SQL function:
@@ -37825,6 +38063,7 @@
 	    {
 		gaiaMbrGeometry (geo);
 		bbox = gaiaAllocGeomColl ();
+		bbox->Srid = geo->Srid;
 		polyg = gaiaAddPolygonToGeomColl (bbox, 5, 0);
 		rect = polyg->Exterior;
 		gaiaSetPoint (rect->Coords, 0, geo->MinX, geo->MinY);	/* vertex # 1 */
@@ -43312,6 +43551,126 @@
 			     fnct_MPolyFromWkb1, 0, 0);
     sqlite3_create_function (db, "MultiPolygonFromWKB", 2, SQLITE_ANY, 0,
 			     fnct_MPolyFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_GeomFromText", 1, SQLITE_ANY, 0,
+			     fnct_GeomFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_GeomFromText", 2, SQLITE_ANY, 0,
+			     fnct_GeomFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_GeometryFromText", 1, SQLITE_ANY, 0,
+			     fnct_GeomFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_GeometryFromText", 2, SQLITE_ANY, 0,
+			     fnct_GeomFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_GeomCollFromText", 1, SQLITE_ANY, 0,
+			     fnct_GeomCollFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_GeomCollFromText", 2, SQLITE_ANY, 0,
+			     fnct_GeomCollFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_GeometryCollectionFromText", 1, SQLITE_ANY,
+			     0, fnct_GeomCollFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_GeometryCollectionFromText", 2, SQLITE_ANY,
+			     0, fnct_GeomCollFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_PointFromText", 1, SQLITE_ANY, 0,
+			     fnct_PointFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_PointFromText", 2, SQLITE_ANY, 0,
+			     fnct_PointFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_LineFromText", 1, SQLITE_ANY, 0,
+			     fnct_LineFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_LineFromText", 2, SQLITE_ANY, 0,
+			     fnct_LineFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_LineStringFromText", 1, SQLITE_ANY, 0,
+			     fnct_LineFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_LineStringFromText", 2, SQLITE_ANY, 0,
+			     fnct_LineFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_PolyFromText", 1, SQLITE_ANY, 0,
+			     fnct_PolyFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_PolyFromText", 2, SQLITE_ANY, 0,
+			     fnct_PolyFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_PolygonFromText", 1, SQLITE_ANY, 0,
+			     fnct_PolyFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_PolygonFromText", 2, SQLITE_ANY, 0,
+			     fnct_PolyFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_MPointFromText", 1, SQLITE_ANY, 0,
+			     fnct_MPointFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_MPointFromText", 2, SQLITE_ANY, 0,
+			     fnct_MPointFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_MultiPointFromText", 1, SQLITE_ANY, 0,
+			     fnct_MPointFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_MultiPointFromText", 2, SQLITE_ANY, 0,
+			     fnct_MPointFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_MLineFromText", 1, SQLITE_ANY, 0,
+			     fnct_MLineFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_MLineFromText", 2, SQLITE_ANY, 0,
+			     fnct_MLineFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_MultiLineStringFromText", 1, SQLITE_ANY, 0,
+			     fnct_MLineFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_MultiLineStringFromText", 2, SQLITE_ANY, 0,
+			     fnct_MLineFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_MPolyFromText", 1, SQLITE_ANY, 0,
+			     fnct_MPolyFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_MPolyFromText", 2, SQLITE_ANY, 0,
+			     fnct_MPolyFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_MultiPolygonFromText", 1, SQLITE_ANY, 0,
+			     fnct_MPolyFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_MultiPolygonFromText", 2, SQLITE_ANY, 0,
+			     fnct_MPolyFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_GeomFromWKB", 1, SQLITE_ANY, 0,
+			     fnct_GeomFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_GeomFromWKB", 2, SQLITE_ANY, 0,
+			     fnct_GeomFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_GeometryFromWKB", 1, SQLITE_ANY, 0,
+			     fnct_GeomFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_GeometryFromWKB", 2, SQLITE_ANY, 0,
+			     fnct_GeomFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_GeomCollFromWKB", 1, SQLITE_ANY, 0,
+			     fnct_GeomCollFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_GeomCollFromWKB", 2, SQLITE_ANY, 0,
+			     fnct_GeomCollFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_GeometryCollectionFromWKB", 1, SQLITE_ANY,
+			     0, fnct_GeomCollFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_GeometryCollectionFromWKB", 2, SQLITE_ANY,
+			     0, fnct_GeomCollFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_PointFromWKB", 1, SQLITE_ANY, 0,
+			     fnct_PointFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_PointFromWKB", 2, SQLITE_ANY, 0,
+			     fnct_PointFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_LineFromWKB", 1, SQLITE_ANY, 0,
+			     fnct_LineFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_LineFromWKB", 2, SQLITE_ANY, 0,
+			     fnct_LineFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_LineStringFromWKB", 1, SQLITE_ANY, 0,
+			     fnct_LineFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_LineStringFromWKB", 2, SQLITE_ANY, 0,
+			     fnct_LineFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_PolyFromWKB", 1, SQLITE_ANY, 0,
+			     fnct_PolyFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_PolyFromWKB", 2, SQLITE_ANY, 0,
+			     fnct_PolyFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_PolygonFromWKB", 1, SQLITE_ANY, 0,
+			     fnct_PolyFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_PolygonFromWKB", 2, SQLITE_ANY, 0,
+			     fnct_PolyFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_MPointFromWKB", 1, SQLITE_ANY, 0,
+			     fnct_MPointFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_MPointFromWKB", 2, SQLITE_ANY, 0,
+			     fnct_MPointFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_MultiPointFromWKB", 1, SQLITE_ANY, 0,
+			     fnct_MPointFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_MultiPointFromWKB", 2, SQLITE_ANY, 0,
+			     fnct_MPointFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_MLineFromWKB", 1, SQLITE_ANY, 0,
+			     fnct_MLineFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_MLineFromWKB", 2, SQLITE_ANY, 0,
+			     fnct_MLineFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_MultiLineStringFromWKB", 1, SQLITE_ANY, 0,
+			     fnct_MLineFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_MultiLineStringFromWKB", 2, SQLITE_ANY, 0,
+			     fnct_MLineFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_MPolyFromWKB", 1, SQLITE_ANY, 0,
+			     fnct_MPolyFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_MPolyFromWKB", 2, SQLITE_ANY, 0,
+			     fnct_MPolyFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_MultiPolygonFromWKB", 1, SQLITE_ANY, 0,
+			     fnct_MPolyFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_MultiPolygonFromWKB", 2, SQLITE_ANY, 0,
+			     fnct_MPolyFromWkb2, 0, 0);
     sqlite3_create_function (db, "GeomFromFGF", 1, SQLITE_ANY, 0,
 			     fnct_GeometryFromFGF1, 0, 0);
     sqlite3_create_function (db, "GeomFromFGF", 2, SQLITE_ANY, 0,
@@ -43350,6 +43709,8 @@
 			     0, 0);
     sqlite3_create_function (db, "ST_Dimension", 1, SQLITE_ANY, 0,
 			     fnct_Dimension, 0, 0);
+    sqlite3_create_function (db, "CoordDimension", 1, SQLITE_ANY, 0,
+			     fnct_CoordDimension, 0, 0);
     sqlite3_create_function (db, "GeometryType", 1, SQLITE_ANY, 0,
 			     fnct_GeometryType, 0, 0);
     sqlite3_create_function (db, "ST_GeometryType", 1, SQLITE_ANY, 0,
@@ -44004,6 +44365,126 @@
 			     fnct_PolyFromWkb1, 0, 0);
     sqlite3_create_function (db, "PolygonFromWKB", 2, SQLITE_ANY, 0,
 			     fnct_PolyFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_GeomFromText", 1, SQLITE_ANY, 0,
+			     fnct_GeomFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_GeomFromText", 2, SQLITE_ANY, 0,
+			     fnct_GeomFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_GeometryFromText", 1, SQLITE_ANY, 0,
+			     fnct_GeomFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_GeometryFromText", 2, SQLITE_ANY, 0,
+			     fnct_GeomFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_GeomCollFromText", 1, SQLITE_ANY, 0,
+			     fnct_GeomCollFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_GeomCollFromText", 2, SQLITE_ANY, 0,
+			     fnct_GeomCollFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_GeometryCollectionFromText", 1, SQLITE_ANY,
+			     0, fnct_GeomCollFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_GeometryCollectionFromText", 2, SQLITE_ANY,
+			     0, fnct_GeomCollFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_PointFromText", 1, SQLITE_ANY, 0,
+			     fnct_PointFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_PointFromText", 2, SQLITE_ANY, 0,
+			     fnct_PointFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_LineFromText", 1, SQLITE_ANY, 0,
+			     fnct_LineFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_LineFromText", 2, SQLITE_ANY, 0,
+			     fnct_LineFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_LineStringFromText", 1, SQLITE_ANY, 0,
+			     fnct_LineFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_LineStringFromText", 2, SQLITE_ANY, 0,
+			     fnct_LineFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_PolyFromText", 1, SQLITE_ANY, 0,
+			     fnct_PolyFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_PolyFromText", 2, SQLITE_ANY, 0,
+			     fnct_PolyFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_PolygonFromText", 1, SQLITE_ANY, 0,
+			     fnct_PolyFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_PolygonFromText", 2, SQLITE_ANY, 0,
+			     fnct_PolyFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_MPointFromText", 1, SQLITE_ANY, 0,
+			     fnct_MPointFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_MPointFromText", 2, SQLITE_ANY, 0,
+			     fnct_MPointFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_MultiPointFromText", 1, SQLITE_ANY, 0,
+			     fnct_MPointFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_MultiPointFromText", 2, SQLITE_ANY, 0,
+			     fnct_MPointFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_MLineFromText", 1, SQLITE_ANY, 0,
+			     fnct_MLineFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_MLineFromText", 2, SQLITE_ANY, 0,
+			     fnct_MLineFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_MultiLineStringFromText", 1, SQLITE_ANY, 0,
+			     fnct_MLineFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_MultiLineStringFromText", 2, SQLITE_ANY, 0,
+			     fnct_MLineFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_MPolyFromText", 1, SQLITE_ANY, 0,
+			     fnct_MPolyFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_MPolyFromText", 2, SQLITE_ANY, 0,
+			     fnct_MPolyFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_MultiPolygonFromText", 1, SQLITE_ANY, 0,
+			     fnct_MPolyFromText1, 0, 0);
+    sqlite3_create_function (db, "ST_MultiPolygonFromText", 2, SQLITE_ANY, 0,
+			     fnct_MPolyFromText2, 0, 0);
+    sqlite3_create_function (db, "ST_GeomFromWKB", 1, SQLITE_ANY, 0,
+			     fnct_GeomFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_GeomFromWKB", 2, SQLITE_ANY, 0,
+			     fnct_GeomFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_GeometryFromWKB", 1, SQLITE_ANY, 0,
+			     fnct_GeomFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_GeometryFromWKB", 2, SQLITE_ANY, 0,
+			     fnct_GeomFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_GeomCollFromWKB", 1, SQLITE_ANY, 0,
+			     fnct_GeomCollFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_GeomCollFromWKB", 2, SQLITE_ANY, 0,
+			     fnct_GeomCollFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_GeometryCollectionFromWKB", 1, SQLITE_ANY,
+			     0, fnct_GeomCollFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_GeometryCollectionFromWKB", 2, SQLITE_ANY,
+			     0, fnct_GeomCollFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_PointFromWKB", 1, SQLITE_ANY, 0,
+			     fnct_PointFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_PointFromWKB", 2, SQLITE_ANY, 0,
+			     fnct_PointFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_LineFromWKB", 1, SQLITE_ANY, 0,
+			     fnct_LineFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_LineFromWKB", 2, SQLITE_ANY, 0,
+			     fnct_LineFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_LineStringFromWKB", 1, SQLITE_ANY, 0,
+			     fnct_LineFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_LineStringFromWKB", 2, SQLITE_ANY, 0,
+			     fnct_LineFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_PolyFromWKB", 1, SQLITE_ANY, 0,
+			     fnct_PolyFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_PolyFromWKB", 2, SQLITE_ANY, 0,
+			     fnct_PolyFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_PolygonFromWKB", 1, SQLITE_ANY, 0,
+			     fnct_PolyFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_PolygonFromWKB", 2, SQLITE_ANY, 0,
+			     fnct_PolyFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_MPointFromWKB", 1, SQLITE_ANY, 0,
+			     fnct_MPointFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_MPointFromWKB", 2, SQLITE_ANY, 0,
+			     fnct_MPointFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_MultiPointFromWKB", 1, SQLITE_ANY, 0,
+			     fnct_MPointFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_MultiPointFromWKB", 2, SQLITE_ANY, 0,
+			     fnct_MPointFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_MLineFromWKB", 1, SQLITE_ANY, 0,
+			     fnct_MLineFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_MLineFromWKB", 2, SQLITE_ANY, 0,
+			     fnct_MLineFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_MultiLineStringFromWKB", 1, SQLITE_ANY, 0,
+			     fnct_MLineFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_MultiLineStringFromWKB", 2, SQLITE_ANY, 0,
+			     fnct_MLineFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_MPolyFromWKB", 1, SQLITE_ANY, 0,
+			     fnct_MPolyFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_MPolyFromWKB", 2, SQLITE_ANY, 0,
+			     fnct_MPolyFromWkb2, 0, 0);
+    sqlite3_create_function (db, "ST_MultiPolygonFromWKB", 1, SQLITE_ANY, 0,
+			     fnct_MPolyFromWkb1, 0, 0);
+    sqlite3_create_function (db, "ST_MultiPolygonFromWKB", 2, SQLITE_ANY, 0,
+			     fnct_MPolyFromWkb2, 0, 0);
     sqlite3_create_function (db, "GeomFromFGF", 1, SQLITE_ANY, 0,
 			     fnct_GeometryFromFGF1, 0, 0);
     sqlite3_create_function (db, "GeomFromFGF", 2, SQLITE_ANY, 0,
@@ -44042,6 +44523,8 @@
 			     0, 0);
     sqlite3_create_function (db, "ST_Dimension", 1, SQLITE_ANY, 0,
 			     fnct_Dimension, 0, 0);
+    sqlite3_create_function (db, "CoordDimension", 1, SQLITE_ANY, 0,
+			     fnct_CoordDimension, 0, 0);
     sqlite3_create_function (db, "GeometryType", 1, SQLITE_ANY, 0,
 			     fnct_GeometryType, 0, 0);
     sqlite3_create_function (db, "ST_GeometryType", 1, SQLITE_ANY, 0,
@@ -48066,7 +48549,7 @@
 					 strlen (cursor->solution->From->Code),
 					 SQLITE_STATIC);
 		else
-		    sqlite3_result_int (pContext, cursor->solution->From->Id);
+		    sqlite3_result_int64 (pContext, cursor->solution->From->Id);
 	    }
 	  if (column == 2)
 	    {
@@ -48076,7 +48559,7 @@
 					 strlen (cursor->solution->To->Code),
 					 SQLITE_STATIC);
 		else
-		    sqlite3_result_int (pContext, cursor->solution->To->Id);
+		    sqlite3_result_int64 (pContext, cursor->solution->To->Id);
 	    }
 	  if (column == 3)
 	    {

Modified: trunk/qgis/src/providers/spatialite/qgsspatialiteprovider.cpp
===================================================================
--- trunk/qgis/src/providers/spatialite/qgsspatialiteprovider.cpp	2009-12-03 13:46:15 UTC (rev 12323)
+++ trunk/qgis/src/providers/spatialite/qgsspatialiteprovider.cpp	2009-12-03 14:28:02 UTC (rev 12324)
@@ -141,7 +141,7 @@
   attributeFields.clear();
   mPrimaryKey.clear();
 
-  QString sql = QString( "PRAGMA table_info(%1)" ).arg( quotedValue( mTableName ) );
+  QString sql = QString( "PRAGMA table_info(\"%1\")" ).arg( mTableName );
 
   ret = sqlite3_get_table( sqliteHandle, sql.toUtf8().constData(), &results, &rows, &columns, &errMsg );
   if ( ret != SQLITE_OK )
@@ -152,7 +152,7 @@
   {
     for ( i = 1; i <= rows; i++ )
     {
-      QString name = results[( i * columns ) + 1];
+      QString name = QString::fromUtf8( results[( i * columns ) + 1] );
       const char *type = results[( i * columns ) + 2];
       QString pk = results[( i * columns ) + 5];
       if ( pk.toInt() != 0 )
@@ -223,14 +223,15 @@
   {
     const QgsField & fld = field( *it );
     const QString & fieldname = fld.name();
-    sql += ", ";
+    sql += ", \"";
     sql += fieldname;
+	sql += "\"";
   }
   if ( fetchGeometry )
   {
-    sql += QString( ", AsBinary(%1)" ).arg( mGeometryColumn );
+    sql += QString( ", AsBinary(\"%1\")" ).arg( mGeometryColumn );
   }
-  sql += QString( " FROM %1 WHERE ROWID = %2" ).arg( quotedValue( mTableName ) ).arg( featureId );
+  sql += QString( " FROM \"%1\" WHERE ROWID = %2" ).arg( mTableName ).arg( featureId );
 
   if ( sqlite3_prepare_v2( sqliteHandle, sql.toUtf8().constData(), -1, &stmt, NULL ) != SQLITE_OK )
   {
@@ -311,7 +312,7 @@
         }
         if ( mFetchGeom )
         {
-          QString geoCol = QString( "AsBinary(%1)" ).arg( mGeometryColumn );
+          QString geoCol = QString( "AsBinary(\"%1\")" ).arg( mGeometryColumn );
           if ( strcasecmp( geoCol.toUtf8().constData(), sqlite3_column_name( stmt, ic ) ) == 0 )
           {
             if ( sqlite3_column_type( stmt, ic ) == SQLITE_BLOB )
@@ -433,7 +434,7 @@
         }
         if ( mFetchGeom )
         {
-          QString geoCol = QString( "AsBinary(%1)" ).arg( mGeometryColumn );
+          QString geoCol = QString( "AsBinary(\"%1\")" ).arg( mGeometryColumn );
           if ( strcasecmp( geoCol.toUtf8().constData(), sqlite3_column_name( sqliteStatement, ic ) ) == 0 )
           {
             if ( sqlite3_column_type( sqliteStatement, ic ) == SQLITE_BLOB )
@@ -523,14 +524,15 @@
   {
     const QgsField & fld = field( *it );
     const QString & fieldname = fld.name();
-    sql += ", ";
+    sql += ", \"";
     sql += fieldname;
+	sql += "\"";
   }
   if ( fetchGeometry )
   {
-    sql += QString( ", AsBinary(%1)" ).arg( mGeometryColumn );
+    sql += QString( ", AsBinary(\"%1\")" ).arg( mGeometryColumn );
   }
-  sql += QString( " FROM %1" ).arg( quotedValue( mTableName ) );
+  sql += QString( " FROM \"%1\"" ).arg( mTableName );
 
   QString whereClause;
 
@@ -545,7 +547,7 @@
                     arg( QString::number( rect.xMinimum(), 'f', 6 ) ).
                     arg( QString::number( rect.yMinimum(), 'f', 6 ) ).
                     arg( QString::number( rect.xMaximum(), 'f', 6 ) ).arg( QString::number( rect.yMaximum(), 'f', 6 ) );
-      whereClause += QString( "Intersects(%1, BuildMbr(%2)) AND " ).arg( mGeometryColumn ).arg( mbr );
+      whereClause += QString( "Intersects(\"%1\", BuildMbr(%2)) AND " ).arg( mGeometryColumn ).arg( mbr );
     }
     if ( mVShapeBased )
     {
@@ -554,7 +556,7 @@
                     arg( QString::number( rect.xMinimum(), 'f', 6 ) ).
                     arg( QString::number( rect.yMinimum(), 'f', 6 ) ).
                     arg( QString::number( rect.xMaximum(), 'f', 6 ) ).arg( QString::number( rect.yMaximum(), 'f', 6 ) );
-      whereClause += QString( "MbrIntersects(%1, BuildMbr(%2))" ).arg( mGeometryColumn ).arg( mbr );
+      whereClause += QString( "MbrIntersects(\"%1\", BuildMbr(%2))" ).arg( mGeometryColumn ).arg( mbr );
     }
     else
     {
@@ -566,7 +568,7 @@
         mbrFilter += QString( "ymin <= %1 AND " ).arg( QString::number( rect.yMaximum(), 'f', 6 ) );
         mbrFilter += QString( "ymax >= %1" ).arg( QString::number( rect.yMinimum(), 'f', 6 ) );
         QString idxName = QString( "idx_%1_%2" ).arg( mIndexTable ).arg( mIndexGeometry );
-        whereClause += QString( "ROWID IN (SELECT pkid FROM %1 WHERE %2)" ).arg( idxName ).arg( mbrFilter );
+        whereClause += QString( "ROWID IN (SELECT pkid FROM \"%1\" WHERE %2)" ).arg( idxName ).arg( mbrFilter );
       }
       else if ( spatialIndexMbrCache )
       {
@@ -576,7 +578,7 @@
                       arg( QString::number( rect.yMinimum(), 'f', 6 ) ).
                       arg( QString::number( rect.xMaximum(), 'f', 6 ) ).arg( QString::number( rect.yMaximum(), 'f', 6 ) );
         QString idxName = QString( "cache_%1_%2" ).arg( mIndexTable ).arg( mIndexGeometry );
-        whereClause += QString( "ROWID IN (SELECT rowid FROM %1 WHERE mbr = FilterMbrIntersects(%2))" ).arg( idxName ).arg( mbr );
+        whereClause += QString( "ROWID IN (SELECT rowid FROM \"%1\" WHERE mbr = FilterMbrIntersects(%2))" ).arg( idxName ).arg( mbr );
       }
       else
       {
@@ -585,7 +587,7 @@
                       arg( QString::number( rect.xMinimum(), 'f', 6 ) ).
                       arg( QString::number( rect.yMinimum(), 'f', 6 ) ).
                       arg( QString::number( rect.xMaximum(), 'f', 6 ) ).arg( QString::number( rect.yMaximum(), 'f', 6 ) );
-        whereClause += QString( "MbrIntersects(%1, BuildMbr(%2))" ).arg( mGeometryColumn ).arg( mbr );
+        whereClause += QString( "MbrIntersects(\"%1\", BuildMbr(%2))" ).arg( mGeometryColumn ).arg( mbr );
       }
     }
   }
@@ -710,7 +712,7 @@
   // get the field name
   const QgsField & fld = field( index );
 
-  QString sql = QString( "SELECT Min(%1) FROM %2" ).arg( fld.name() ).arg( quotedValue( mTableName ) );
+  QString sql = QString( "SELECT Min(\"%1\") FROM \"%2\"" ).arg( fld.name() ).arg( mTableName );
 
   if ( !mSubsetString.isEmpty() )
   {
@@ -768,7 +770,7 @@
   // get the field name
   const QgsField & fld = field( index );
 
-  QString sql = QString( "SELECT Max(%1) FROM %2" ).arg( fld.name() ).arg( quotedValue( mTableName ) );
+  QString sql = QString( "SELECT Max(\"%1\") FROM \"%2\"" ).arg( fld.name() ).arg( mTableName );
 
   if ( !mSubsetString.isEmpty() )
   {
@@ -825,7 +827,7 @@
   // get the field name
   const QgsField & fld = field( index );
 
-  sql = QString( "SELECT DISTINCT %1 FROM %2 ORDER BY %1" ).arg( fld.name() ).arg( quotedValue( mTableName ) );
+  sql = QString( "SELECT DISTINCT \"%1\" FROM \"%2\" ORDER BY \"%1\"" ).arg( fld.name() ).arg( mTableName );
 
   if ( !mSubsetString.isEmpty() )
   {
@@ -928,13 +930,13 @@
 
   if ( !mPrimaryKey.isEmpty() )
   {
-    sql = QString( "INSERT INTO %1 (%2, %3" ).
-          arg( quotedValue( mTableName ) ).arg( quotedValue( mPrimaryKey ) ).arg( quotedValue( mGeometryColumn ) );
+    sql = QString( "INSERT INTO \"%1\" (\"%2\", \"%3\"" ).
+          arg( mTableName ).arg( mPrimaryKey ).arg( mGeometryColumn );
     values = QString( ") VALUES (NULL, GeomFromWKB(?, %1)" ).arg( mSrid );
   }
   else
   {
-    sql = QString( "INSERT INTO %1 (%2" ).arg( quotedValue( mTableName ) ).arg( quotedValue( mGeometryColumn ) );
+    sql = QString( "INSERT INTO \"%1\" (\"%2\"" ).arg( mTableName ).arg( mGeometryColumn );
     values = QString( ") VALUES (GeomFromWKB(?, %1)" ).arg( mSrid );
   }
 
@@ -948,8 +950,9 @@
     if ( fieldname.isEmpty() || fieldname == mGeometryColumn || fieldname == mPrimaryKey )
       continue;
 
-    sql += ", ";
-    sql += quotedValue( fieldname );
+    sql += ", \"";
+    sql += fieldname;
+	sql += "\"";
     values += ", ?";
   }
 
@@ -1030,7 +1033,7 @@
     // performing actual row insert
     ret = sqlite3_step( stmt );
 
-    if ( ret == SQLITE_DONE || ret == SQLITE_ROW )
+	if ( ret == SQLITE_DONE || ret == SQLITE_ROW )
     {
       numberFeatures++;
     }
@@ -1048,12 +1051,11 @@
   sqlite3_finalize( stmt );
 
   ret = sqlite3_exec( sqliteHandle, "COMMIT", NULL, NULL, &errMsg );
-  if ( ret == SQLITE_OK )
+  if ( ret != SQLITE_OK )
   {
     // some error occurred
     goto abort;
   }
-
   return true;
 
 abort:
@@ -1091,7 +1093,7 @@
   }
   toCommit = true;
 
-  sql = QString( "DELETE FROM %1 WHERE ROWID = ?" ).arg( quotedValue( mTableName ) );
+  sql = QString( "DELETE FROM \"%1\" WHERE ROWID = ?" ).arg( mTableName );
 
   // SQLite prepared statement
   if ( sqlite3_prepare_v2( sqliteHandle, sql.toUtf8().constData(), -1, &stmt, NULL ) != SQLITE_OK )
@@ -1175,9 +1177,9 @@
 
   for ( QList<QgsField>::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter )
   {
-    sql = QString( "ALTER TABLE %1 ADD COLUMN %2 %3" )
-          .arg( quotedValue( mTableName ) )
-          .arg( quotedValue( iter->name() ) )
+    sql = QString( "ALTER TABLE \"%1\" ADD COLUMN \"%2\" %3" )
+          .arg( mTableName )
+          .arg( iter->name() )
           .arg( iter->typeName() );
     ret = sqlite3_exec( sqliteHandle, sql.toUtf8().constData(), NULL, NULL, &errMsg );
     if ( ret != SQLITE_OK )
@@ -1197,7 +1199,7 @@
   return true;
 
 abort:
-  QString msg = QString( "assAttributes SQL error:\n%1\n" ).arg( sql );
+  QString msg = QString( "addAttributes SQL error:\n%1\n" ).arg( sql );
   if ( errMsg )
   {
     msg += errMsg;
@@ -1238,7 +1240,7 @@
     if ( fid < 0 )
       continue;
 
-    QString sql = QString( "UPDATE %1 SET " ).arg( mTableName );
+    QString sql = QString( "UPDATE \"%1\" SET " ).arg( mTableName );
     bool first = true;
 
     const QgsAttributeMap & attrs = iter.value();
@@ -1252,8 +1254,29 @@
         sql += ",";
       else
         first = false;
+	
+	  QVariant::Type type = siter->type();
+	  if ( siter->toString().isEmpty() )
+	  {
+	  // assuming to be a NULL value
+		type = QVariant::Invalid;
+	  }
 
-      sql += QString( "%1=%2" ).arg( quotedValue( fieldName ) ).arg( quotedValue( siter->toString() ) );
+	  if ( type == QVariant::Invalid )
+	  {
+	  // binding a NULL value
+		sql += QString( "\"%1\"=NULL" ).arg( fieldName );
+	  }
+	  else if ( type == QVariant::Int || type == QVariant::Double )
+	  {
+	  // binding a NUMERIC value
+		sql += QString( "\"%1\"=%2" ).arg( fieldName ).arg( siter->toString() );
+	  }
+	  else
+	  {
+	  // binding a TEXT value
+		sql += QString( "\"%1\"=%2" ).arg( fieldName ).arg( quotedValue( siter->toString() ) );
+	  }
     }
     sql += QString( " WHERE ROWID=%1" ).arg( fid );
 
@@ -1310,8 +1333,8 @@
   toCommit = true;
 
   sql =
-    QString( "UPDATE %1 SET %2 = GeomFromWKB(?, %3) WHERE ROWID = ?" ).
-    arg( quotedValue( mTableName ) ).arg( quotedValue( mGeometryColumn ) ).arg( mSrid );
+    QString( "UPDATE \"%1\" SET \"%2\" = GeomFromWKB(?, %3) WHERE ROWID = ?" ).
+    arg( mTableName ).arg( mGeometryColumn ).arg( mSrid );
 
   // SQLite prepared statement
   if ( sqlite3_prepare_v2( sqliteHandle, sql.toUtf8().constData(), -1, &stmt, NULL ) != SQLITE_OK )
@@ -1914,8 +1937,8 @@
   int columns;
   char *errMsg = NULL;
 
-  QString sql = QString( "SELECT Min(MbrMinX(%1)), Min(MbrMinY(%1)), "
-                         "Max(MbrMaxX(%1)), Max(MbrMaxY(%1)), Count(*) " "FROM %2" ).arg( mGeometryColumn ).arg( quotedValue( mTableName ) );
+  QString sql = QString( "SELECT Min(MbrMinX(\"%1\")), Min(MbrMinY(\"%1\")), "
+                         "Max(MbrMaxX(\"%1\")), Max(MbrMaxY(\"%1\")), Count(*) " "FROM \"%2\"" ).arg( mGeometryColumn ).arg( mTableName );
 
   if ( !mSubsetString.isEmpty() )
   {



More information about the QGIS-commit mailing list