static int
do_load_legacy (const char *path)
{
/* loading the Legacy Test DB */
    sqlite3 *db_handle;
    int ret;
    void *cache = NULL;
    const char *sql;
    char *sql_err = NULL;

    cache = spatialite_alloc_connection ();
    ret = sqlite3_open_v2 (path, &db_handle, SQLITE_OPEN_READWRITE, NULL);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "cannot open '%s': %s\n", path,
		   sqlite3_errmsg (db_handle));
	  sqlite3_close (db_handle);
	  return 0;
      }
    spatialite_init_ex (db_handle, cache, 0);

/* creating a table */
    sql = "CREATE TABLE test0 (id INTEGER NOT NULL PRIMARY KEY)";
    ret = sqlite3_exec (db_handle, sql, NULL, NULL, &sql_err);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "CREATE TABLE error: %s\n", sql_err);
	  sqlite3_free (sql_err);
	  return 0;
      }

/* adding a geometry */
    sql = "SELECT AddGeometryColumn('test0', 'geom', 4326, 'POINT', 'XY')";
    ret = sqlite3_exec (db_handle, sql, NULL, NULL, &sql_err);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "AddGeometryColumn error: %s\n", sql_err);
	  sqlite3_free (sql_err);
	  return 0;
      }

/* inserting one row */
    sql = "INSERT INTO test0 (id, geom) VALUES(1, MakePoint(1, 2, 4326))";
    ret = sqlite3_exec (db_handle, sql, NULL, NULL, &sql_err);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "INSERT INTO error: %s\n", sql_err);
	  sqlite3_free (sql_err);
	  return 0;
      }

    sqlite3_close (db_handle);
    spatialite_cleanup_ex (cache);
    return 1;
}
예제 #2
0
int QgsSLConnect::sqlite3_close_v2( sqlite3 *db )
{
  int res = ::sqlite3_close( db );

#if defined(SPATIALITE_VERSION_GE_4_0_0)
  if ( mSLconns.contains( db ) )
    spatialite_cleanup_ex( mSLconns.take( db ) );
#endif

  return res;
}
예제 #3
0
int main (int argc, char *argv[])
{
#ifndef OMIT_ICONV	/* only if ICONV is supported */
    int ret;
    sqlite3 *handle;
    char *err_msg = NULL;
    int row_count;
    void *cache = spatialite_alloc_connection();

    if (argc > 1 || argv[0] == NULL)
	argc = 1;		/* silencing stupid compiler warnings */

    ret = sqlite3_open_v2 (":memory:", &handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    if (ret != SQLITE_OK) {
	fprintf(stderr, "cannot open in-memory databse: %s\n", sqlite3_errmsg (handle));
	sqlite3_close(handle);
	return -1;
    }

    spatialite_init_ex (handle, cache, 0);
    
    ret = sqlite3_exec (handle, "SELECT InitSpatialMetadata(1)", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "InitSpatialMetadata() error: %s\n", err_msg);
	sqlite3_free(err_msg);
	sqlite3_close(handle);
	return -2;
    }
    
    ret = load_dbf (handle, "./shapetest1.dbf", "test1", "UTF-8", 1, &row_count, err_msg);
    if (!ret) {
        fprintf (stderr, "load_dbf() error: %s\n", err_msg);
	sqlite3_close(handle);
	return -3;
    }
    if (row_count != 2) {
	fprintf (stderr, "unexpected row count for load_dbf: %i\n", row_count);
	sqlite3_close(handle);
	return -4;
    }
    
    ret = sqlite3_close (handle);
    if (ret != SQLITE_OK) {
        fprintf (stderr, "sqlite3_close() error: %s\n", sqlite3_errmsg (handle));
	return -5;
    }
        
    spatialite_cleanup_ex(cache);

#endif	/* end ICONV conditional */

    return 0;
}
예제 #4
0
sqlite3* SpatialiteBase::open(const QString& aNom,
                                 const int aFlags)
{
    void *sp_connection = spatialite_alloc_connection();
    const int err = sqlite3_open_v2 (aNom.toUtf8().data(), &m_handle, aFlags, NULL);
    if (err != SQLITE_OK) {
        qDebug() << QString(sqlite3_errmsg(m_handle)) + " while opening: " + aNom;
        sqlite3_close (m_handle);
        spatialite_cleanup_ex(sp_connection);
        return NULL;
    }
    spatialite_init_ex(m_handle, sp_connection, 0);
    return m_handle;
}
예제 #5
0
SpatiaLiteDB::~SpatiaLiteDB() {
	spatialite_cleanup_ex(_connection);
}
예제 #6
0
int
main (int argc, char *argv[])
{
#ifndef OMIT_ICONV		/* only if ICONV is supported */
    int ret;
    sqlite3 *handle;
    char *err_msg = NULL;
    int row_count;
    char **results;
    int rows;
    int columns;
    int pt;
    void *cache = spatialite_alloc_connection ();

    if (argc > 1 || argv[0] == NULL)
	argc = 1;		/* silencing stupid compiler warnings */

    ret =
	sqlite3_open_v2 (":memory:", &handle,
			 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "cannot open in-memory database: %s\n",
		   sqlite3_errmsg (handle));
	  sqlite3_close (handle);
	  return -1;
      }

    spatialite_init_ex (handle, cache, 0);

    ret =
	sqlite3_exec (handle, "SELECT InitSpatialMetadata(1)", NULL, NULL,
		      &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "InitSpatialMetadata() error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  sqlite3_close (handle);
	  return -2;
      }

    ret = load_shapefile (handle, "shp/foggia/local_councils", "Councils",
			  "CP1252", 23032, "geom", 1, 0, 1, 0, &row_count,
			  err_msg);
    if (!ret)
      {
	  fprintf (stderr, "load_shapefile() error: %s\n", err_msg);
	  sqlite3_close (handle);
	  return -3;
      }
    if (row_count != 61)
      {
	  fprintf (stderr, "unexpected number of rows loaded: %i\n", row_count);
	  sqlite3_close (handle);
	  return -4;
      }

    ret =
	sqlite3_get_table (handle,
			   "SELECT lc_name FROM Councils WHERE MbrWithin(geom, BuildMbr(1040523, 4010000, 1140523, 4850000)) ORDER BY lc_name;",
			   &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -5;
      }
    if ((rows != 22) || (columns != 1))
      {
	  fprintf (stderr,
		   "Unexpected error: select lc_name bad result: %i/%i.\n",
		   rows, columns);
	  sqlite3_free_table (results);
	  sqlite3_close (handle);
	  return -6;
      }
    if (strcmp (results[1], "Ascoli Satriano") != 0)
      {
	  fprintf (stderr, "unexpected result at 1: %s\n", results[1]);
	  sqlite3_free_table (results);
	  sqlite3_close (handle);
	  return -7;
      }
    if (strcmp (results[22], "Zapponeta") != 0)
      {
	  fprintf (stderr, "unexpected result at 22: %s\n", results[22]);
	  sqlite3_free_table (results);
	  sqlite3_close (handle);
	  return -8;
      }
    sqlite3_free_table (results);

    ret = sqlite3_exec (handle, "SELECT CreateMbrCache('Councils', 'geom');",
			NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "CreateMbrCache error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -9;
      }

    rows = 0;
    columns = 0;
    ret =
	sqlite3_get_table (handle,
			   "SELECT lc_name FROM Councils WHERE ROWID IN (SELECT rowid FROM cache_Councils_geom WHERE mbr = FilterMbrWithin(1040523, 4010000, 1140523, 4850000)) ORDER BY lc_name;",
			   &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error in Mbr SELECT: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -14;
      }
    if ((rows != 22) || (columns != 1))
      {
	  fprintf (stderr,
		   "Unexpected error: select lc_name bad cache result: %i/%i.\n",
		   rows, columns);
	  sqlite3_free_table (results);
	  sqlite3_close (handle);
	  return -15;
      }
    if (strcmp (results[1], "Ascoli Satriano") != 0)
      {
	  fprintf (stderr, "unexpected mbr result at 1: %s\n", results[1]);
	  sqlite3_free_table (results);
	  sqlite3_close (handle);
	  return -16;
      }
    if (strcmp (results[22], "Zapponeta") != 0)
      {
	  fprintf (stderr, "unexpected mbr result at 22: %s\n", results[22]);
	  sqlite3_free_table (results);
	  sqlite3_close (handle);
	  return -17;
      }
    sqlite3_free_table (results);

    rows = 0;
    columns = 0;
    ret =
	sqlite3_get_table (handle,
			   "SELECT lc_name FROM Councils WHERE ROWID IN (SELECT rowid FROM cache_Councils_geom WHERE mbr = FilterMbrContains(997226.750031, 4627372.000018, 997226.750031, 4627372.000018)) ORDER BY lc_name;",
			   &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error in Mbr SELECT Contains: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -18;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr,
		   "Unexpected error: select lc_name bad cache result: %i/%i.\n",
		   rows, columns);
	  sqlite3_free_table (results);
	  sqlite3_close (handle);
	  return -19;
      }
    if (strcmp (results[1], "Carlantino") != 0)
      {
	  fprintf (stderr, "unexpected mbr result at 1: %s\n", results[1]);
	  sqlite3_free_table (results);
	  sqlite3_close (handle);
	  return -20;
      }
    sqlite3_free_table (results);

    rows = 0;
    columns = 0;
    ret =
	sqlite3_get_table (handle,
			   "SELECT lc_name FROM Councils WHERE ROWID IN (SELECT rowid FROM cache_Councils_geom WHERE mbr = FilterMbrIntersects(1040523, 4010000, 1140523, 4850000)) ORDER BY lc_name;",
			   &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error in Mbr SELECT: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -21;
      }
    if ((rows != 35) || (columns != 1))
      {
	  fprintf (stderr,
		   "Unexpected error: select lc_name bad cache result: %i/%i.\n",
		   rows, columns);
	  sqlite3_free_table (results);
	  sqlite3_close (handle);
	  return -22;
      }
    if (strcmp (results[1], "Apricena") != 0)
      {
	  fprintf (stderr, "unexpected mbr result at 1: %s\n", results[1]);
	  sqlite3_free_table (results);
	  sqlite3_close (handle);
	  return -23;
      }
    sqlite3_free_table (results);

    ret =
	sqlite3_exec (handle,
		      "DELETE FROM Councils WHERE lc_name = 'Zapponeta';", NULL,
		      NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "DELETE error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -24;
      }

    rows = 0;
    columns = 0;
    ret =
	sqlite3_get_table (handle,
			   "SELECT lc_name FROM Councils WHERE ROWID IN (SELECT rowid FROM cache_Councils_geom WHERE mbr = FilterMbrWithin(1040523, 4010000, 1140523, 4850000)) ORDER BY lc_name;",
			   &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error in Mbr SELECT: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -25;
      }
    if ((rows != 21) || (columns != 1))
      {
	  fprintf (stderr,
		   "Unexpected error: select lc_name bad cache result: %i/%i.\n",
		   rows, columns);
	  sqlite3_free_table (results);
	  sqlite3_close (handle);
	  return -26;
      }
    if (strcmp (results[1], "Ascoli Satriano") != 0)
      {
	  fprintf (stderr, "unexpected mbr result at 1: %s\n", results[1]);
	  sqlite3_free_table (results);
	  sqlite3_close (handle);
	  return -27;
      }
    if (strcmp (results[21], "Vieste") != 0)
      {
	  fprintf (stderr, "unexpected mbr result at 21: %s\n", results[21]);
	  sqlite3_free_table (results);
	  sqlite3_close (handle);
	  return -28;
      }
    sqlite3_free_table (results);

    ret =
	sqlite3_exec (handle,
		      "INSERT INTO Councils (lc_name, geom) VALUES ('Quairading', GeomFromText('MULTIPOLYGON(((997226.750031 4627372.000018, 997301.750031 4627332.000018, 997402.500031 4627344.000018, 997541.500031 4627326.500018,997226.750031 4627372.000018)))', 23032));",
		      NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "INSERT error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -29;
      }

    rows = 0;
    columns = 0;
    ret =
	sqlite3_get_table (handle,
			   "SELECT lc_name FROM Councils WHERE ROWID IN (SELECT rowid FROM cache_Councils_geom WHERE mbr = FilterMbrWithin(1040523, 4010000, 1140523, 4850000)) ORDER BY lc_name;",
			   &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error in Mbr SELECT2: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -30;
      }
    if ((rows != 21) || (columns != 1))
      {
	  fprintf (stderr,
		   "Unexpected error: select lc_name bad cache result: %i/%i.\n",
		   rows, columns);
	  sqlite3_free_table (results);
	  sqlite3_close (handle);
	  return -31;
      }
    if (strcmp (results[1], "Ascoli Satriano") != 0)
      {
	  fprintf (stderr, "unexpected mbr result at 1: %s\n", results[1]);
	  sqlite3_free_table (results);
	  sqlite3_close (handle);
	  return -32;
      }
    if (strcmp (results[21], "Vieste") != 0)
      {
	  fprintf (stderr, "unexpected mbr result at 21: %s\n", results[21]);
	  sqlite3_free_table (results);
	  sqlite3_close (handle);
	  return -33;
      }
    sqlite3_free_table (results);

    ret =
	sqlite3_exec (handle,
		      "UPDATE Councils SET geom = GeomFromText('MULTIPOLYGON(((987226.750031 4627372.000018, 997301.750031 4627331.000018, 997402.500032 4627344.000018, 997541.500031 4627326.500018, 987226.750031 4627372.000018)))', 23032) WHERE lc_name = \"Quairading\";",
		      NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "UPDATE error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -34;
      }

    rows = 0;
    columns = 0;
    ret =
	sqlite3_get_table (handle,
			   "SELECT lc_name FROM Councils WHERE ROWID IN (SELECT rowid FROM cache_Councils_geom WHERE mbr = FilterMbrWithin(1040523, 4010000, 1140523, 4850000)) ORDER BY lc_name;",
			   &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error in Mbr SELECT3: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -35;
      }
    if ((rows != 21) || (columns != 1))
      {
	  fprintf (stderr,
		   "Unexpected error: select lc_name bad cache result: %i/%i.\n",
		   rows, columns);
	  sqlite3_free_table (results);
	  sqlite3_close (handle);
	  return -36;
      }
    if (strcmp (results[1], "Ascoli Satriano") != 0)
      {
	  fprintf (stderr, "unexpected mbr result at 1: %s\n", results[1]);
	  sqlite3_free_table (results);
	  sqlite3_close (handle);
	  return -37;
      }
    if (strcmp (results[21], "Vieste") != 0)
      {
	  fprintf (stderr, "unexpected mbr result at 21: %s\n", results[21]);
	  sqlite3_free_table (results);
	  sqlite3_close (handle);
	  return -38;
      }
    sqlite3_free_table (results);

    rows = 0;
    columns = 0;
    ret =
	sqlite3_get_table (handle,
			   "SELECT rowid, mbr FROM cache_Councils_geom;",
			   &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error in Mbr SELECT: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -39;
      }
    if ((rows != 61) || (columns != 2))
      {
	  fprintf (stderr,
		   "Unexpected error: select lc_name bad cache2 result: %i/%i.\n",
		   rows, columns);
	  sqlite3_free_table (results);
	  sqlite3_close (handle);
	  return -40;
      }
    if (strcmp (results[2], "1") != 0)
      {
	  fprintf (stderr, "unexpected mbr result at 1: %s\n", results[2]);
	  sqlite3_free_table (results);
	  sqlite3_close (handle);
	  return -41;
      }
    if (strcmp (results[12], "6") != 0)
      {
	  fprintf (stderr, "unexpected mbr result at 6: %s\n", results[12]);
	  sqlite3_free_table (results);
	  sqlite3_close (handle);
	  return -42;
      }
    sqlite3_free_table (results);

    ret = sqlite3_exec (handle, "DROP TABLE Councils;", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "DROP TABLE Councils error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -44;
      }

/* creating and feeding a Point table */
    ret =
	sqlite3_exec (handle, "CREATE TABLE pt (id INTEGER);", NULL, NULL,
		      &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "CREATE TABLE pt error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -45;
      }
    ret =
	sqlite3_exec (handle,
		      "SELECT AddGeometryColumn('pt', 'g', 4326, 1, 'XY');",
		      NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "AddGeometryColumn pt error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -46;
      }
    ret =
	sqlite3_exec (handle,
		      "SELECT AddGeometryColumn('pt', 'g', 4326, 'POINT', 2.5);",
		      NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "AddGeometryColumn pt error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -47;
      }
    ret =
	sqlite3_exec (handle,
		      "SELECT AddGeometryColumn('pt', 'g', 4326, 'POINT', 'XY', 0.5);",
		      NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "AddGeometryColumn pt error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -48;
      }
    ret =
	sqlite3_exec (handle,
		      "SELECT AddGeometryColumn('pt', 'g', 4326, 'DUMMY', 'XY');",
		      NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "AddGeometryColumn pt error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -49;
      }
    ret =
	sqlite3_exec (handle,
		      "SELECT AddGeometryColumn('pt', 'g', 4326, 'POINT', 'DUMMY');",
		      NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "AddGeometryColumn pt error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -50;
      }
    ret =
	sqlite3_exec (handle,
		      "SELECT AddGeometryColumn('pt', 'g', 4326, 'POINT', 2);",
		      NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "AddGeometryColumn pt error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -51;
      }
    ret =
	sqlite3_exec (handle, "SELECT CreateMbrCache('pt', 'g');", NULL, NULL,
		      &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "CreateMbrCache pt.g error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -52;
      }
    for (pt = 0; pt < 10000; pt++)
      {
	  /* inserting Points */
	  char sql[1024];
	  sprintf (sql,
		   "INSERT INTO pt (id, g) VALUES (%d, GeomFromText('POINT(%1.2f %1.2f)', 4326));",
		   pt, 11.0 + (pt / 10000.0), 43.0 + (pt / 10000.0));
	  ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
	  if (ret != SQLITE_OK)
	    {
		fprintf (stderr, "INSERT INTO pt error: %s\n", err_msg);
		sqlite3_free (err_msg);
		return -53;
	    }
      }
    for (pt = 5000; pt < 6000; pt++)
      {
	  /* updating Points */
	  char sql[1024];
	  sprintf (sql,
		   "UPDATE pt SET g  = GeomFromText('POINT(%1.2f %1.2f)', 4326) WHERE id = %d;",
		   12.0 + (pt / 10000.0), 42.0 + (pt / 10000.0), pt);
	  ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
	  if (ret != SQLITE_OK)
	    {
		fprintf (stderr, "UPDATE pt error: %s\n", err_msg);
		sqlite3_free (err_msg);
		return -54;
	    }
      }
    for (pt = 7000; pt < 8000; pt++)
      {
	  /* deleting Points */
	  char sql[1024];
	  sprintf (sql, "DELETE FROM pt WHERE id = %d;", pt);
	  ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
	  if (ret != SQLITE_OK)
	    {
		fprintf (stderr, "UPDATE pt error: %s\n", err_msg);
		sqlite3_free (err_msg);
		return -55;
	    }
      }

    ret = sqlite3_exec (handle, "SELECT CreateMbrCache(1, 'geom');",
			NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "invalid CreateMbrCache error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -56;
      }
    ret = sqlite3_exec (handle, "SELECT CreateMbrCache('Councils', 2);",
			NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "invalid CreateMbrCache error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -57;
      }
    ret = sqlite3_exec (handle, "SELECT FilterMbrWithin('a', 2, 3, 4);",
			NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "invalid FilterMbrWithin error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -58;
      }
    ret = sqlite3_exec (handle, "SELECT FilterMbrWithin(1, 'a', 3, 4);",
			NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "invalid FilterMbrWithin error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -59;
      }
    ret = sqlite3_exec (handle, "SELECT FilterMbrWithin(1, 2, 'a', 4);",
			NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "invalid FilterMbrWithin error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -60;
      }
    ret = sqlite3_exec (handle, "SELECT FilterMbrWithin(1, 2, 3, 'a');",
			NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "invalid FilterMbrWithin error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -61;
      }

    ret = sqlite3_close (handle);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "sqlite3_close() error: %s\n",
		   sqlite3_errmsg (handle));
	  return -62;
      }

    spatialite_cleanup_ex (cache);
#endif /* end ICONV conditional */

    return 0;
}
예제 #7
0
int
main (int argc, char *argv[])
{
/* the MAIN function simply perform arguments checking */
    sqlite3 *handle;
    int i;
    int next_arg = ARG_NONE;
    const char *gml_path = NULL;
    const char *db_path = NULL;
    const char *table = NULL;
    int in_memory = 0;
    int error = 0;
    char Buff[BUFFSIZE];
    int done = 0;
    int len;
    XML_Parser parser;
    FILE *xml_file;
    struct gml_params params;
    int ret;
    char *err_msg = NULL;
    void *cache;

    params.db_handle = NULL;
    params.stmt = NULL;
    params.geometry_type = GEOM_NONE;
    params.srid = INT_MIN;
    params.is_feature = 0;
    params.is_fid = 0;
    params.is_point = 0;
    params.is_linestring = 0;
    params.is_polygon = 0;
    params.is_multi_point = 0;
    params.is_multi_linestring = 0;
    params.is_multi_polygon = 0;
    params.first = NULL;
    params.last = NULL;
    params.geometry = NULL;
    params.polygon.exterior = NULL;
    params.polygon.first = NULL;
    params.polygon.last = NULL;
    params.CharDataStep = 65536;
    params.CharDataMax = params.CharDataStep;
    params.CharData = malloc (params.CharDataStep);

    for (i = 1; i < argc; i++)
      {
	  /* parsing the invocation arguments */
	  if (next_arg != ARG_NONE)
	    {
		switch (next_arg)
		  {
		  case ARG_GML_PATH:
		      gml_path = argv[i];
		      break;
		  case ARG_DB_PATH:
		      db_path = argv[i];
		      break;
		  case ARG_TABLE:
		      table = argv[i];
		      break;
		  };
		next_arg = ARG_NONE;
		continue;
	    }
	  if (strcasecmp (argv[i], "--help") == 0
	      || strcmp (argv[i], "-h") == 0)
	    {
		do_help ();
		return -1;
	    }
	  if (strcmp (argv[i], "-g") == 0)
	    {
		next_arg = ARG_GML_PATH;
		continue;
	    }
	  if (strcasecmp (argv[i], "--gml-path") == 0)
	    {
		next_arg = ARG_GML_PATH;
		continue;
	    }
	  if (strcmp (argv[i], "-d") == 0)
	    {
		next_arg = ARG_DB_PATH;
		continue;
	    }
	  if (strcasecmp (argv[i], "--db-path") == 0)
	    {
		next_arg = ARG_DB_PATH;
		continue;
	    }
	  if (strcmp (argv[i], "-t") == 0)
	    {
		next_arg = ARG_TABLE;
		continue;
	    }
	  if (strcasecmp (argv[i], "--table-name") == 0)
	    {
		next_arg = ARG_TABLE;
		continue;
	    }
	  if (strcasecmp (argv[i], "-m") == 0)
	    {
		in_memory = 1;
		next_arg = ARG_NONE;
		continue;
	    }
	  if (strcasecmp (argv[i], "-in-memory") == 0)
	    {
		in_memory = 1;
		next_arg = ARG_NONE;
		continue;
	    }
	  if (strcasecmp (argv[i], "-n") == 0)
	    {
		next_arg = ARG_NONE;
		continue;
	    }
	  if (strcasecmp (argv[i], "-no-spatial-index") == 0)
	    {
		next_arg = ARG_NONE;
		continue;
	    }
	  fprintf (stderr, "unknown argument: %s\n", argv[i]);
	  error = 1;
      }
    if (error)
      {
	  do_help ();
	  return -1;
      }

/* checking the arguments */
    if (!gml_path)
      {
	  fprintf (stderr,
		   "did you forget setting the --gml-path argument ?\n");
	  error = 1;
      }
    if (!db_path)
      {
	  fprintf (stderr, "did you forget setting the --db-path argument ?\n");
	  error = 1;
      }
    if (!table)
      {
	  fprintf (stderr,
		   "did you forget setting the --table-name argument ?\n");
	  error = 1;
      }
    if (error)
      {
	  do_help ();
	  return -1;
      }

/* opening the DB */
    cache = spatialite_alloc_connection ();
    open_db (db_path, &handle, cache);
    if (!handle)
	return -1;
    params.db_handle = handle;
    if (in_memory)
      {
	  /* loading the DB in-memory */
	  sqlite3 *mem_db_handle;
	  sqlite3_backup *backup;
	  int ret;
	  ret =
	      sqlite3_open_v2 (":memory:", &mem_db_handle,
			       SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
			       NULL);
	  if (ret != SQLITE_OK)
	    {
		fprintf (stderr, "cannot open 'MEMORY-DB': %s\n",
			 sqlite3_errmsg (mem_db_handle));
		sqlite3_close (mem_db_handle);
		return -1;
	    }
	  backup = sqlite3_backup_init (mem_db_handle, "main", handle, "main");
	  if (!backup)
	    {
		fprintf (stderr, "cannot load 'MEMORY-DB'\n");
		sqlite3_close (handle);
		sqlite3_close (mem_db_handle);
		return -1;
	    }
	  while (1)
	    {
		ret = sqlite3_backup_step (backup, 1024);
		if (ret == SQLITE_DONE)
		    break;
	    }
	  ret = sqlite3_backup_finish (backup);
	  sqlite3_close (handle);
	  handle = mem_db_handle;
	  printf ("\nusing IN-MEMORY database\n");
	  spatialite_cleanup_ex (cache);
	  cache = spatialite_alloc_connection ();
	  spatialite_init_ex (handle, cache, 0);
      }

/* XML parsing */
    xml_file = fopen (gml_path, "rb");
    if (!xml_file)
      {
	  fprintf (stderr, "cannot open %s\n", gml_path);
	  sqlite3_close (handle);
	  return -1;
      }
    parser = XML_ParserCreate (NULL);
    if (!parser)
      {
	  fprintf (stderr, "Couldn't allocate memory for parser\n");
	  sqlite3_close (handle);
	  return -1;
      }

    XML_SetUserData (parser, &params);
/* XML parsing: pass I */
    XML_SetElementHandler (parser, start1_tag, end1_tag);
    XML_SetCharacterDataHandler (parser, gmlCharData);
    while (!done)
      {
	  len = fread (Buff, 1, BUFFSIZE, xml_file);
	  if (ferror (xml_file))
	    {
		fprintf (stderr, "XML Read error\n");
		sqlite3_close (handle);
		return -1;
	    }
	  done = feof (xml_file);
	  if (!XML_Parse (parser, Buff, len, done))
	    {
		fprintf (stderr, "Parse error at line %d:\n%s\n",
			 (int) XML_GetCurrentLineNumber (parser),
			 XML_ErrorString (XML_GetErrorCode (parser)));
		sqlite3_close (handle);
		return -1;
	    }
      }
    XML_ParserFree (parser);

/* creating the DB table */
    if (!create_table (&params, table))
	goto no_table;

/* XML parsing: pass II */
    parser = XML_ParserCreate (NULL);
    if (!parser)
      {
	  fprintf (stderr, "Couldn't allocate memory for parser\n");
	  sqlite3_close (handle);
	  return -1;
      }
    XML_SetUserData (parser, &params);
    XML_SetElementHandler (parser, start2_tag, end2_tag);
    XML_SetCharacterDataHandler (parser, gmlCharData);
    rewind (xml_file);
    params.is_feature = 0;
    params.is_fid = 0;
    params.is_point = 0;
    params.is_linestring = 0;
    params.is_polygon = 0;
    params.is_multi_point = 0;
    params.is_multi_linestring = 0;
    params.is_multi_polygon = 0;
    done = 0;
    while (!done)
      {
	  len = fread (Buff, 1, BUFFSIZE, xml_file);
	  if (ferror (xml_file))
	    {
		fprintf (stderr, "XML Read error\n");
		sqlite3_close (handle);
		return -1;
	    }
	  done = feof (xml_file);
	  if (!XML_Parse (parser, Buff, len, done))
	    {
		fprintf (stderr, "Parse error at line %d:\n%s\n",
			 (int) XML_GetCurrentLineNumber (parser),
			 XML_ErrorString (XML_GetErrorCode (parser)));
		sqlite3_close (handle);
		return -1;
	    }
      }
    XML_ParserFree (parser);
    if (params.stmt != NULL)
	sqlite3_finalize (params.stmt);
    params.stmt = NULL;

    /* COMMITTing the still pending Transaction */
    ret = sqlite3_exec (handle, "COMMIT", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "COMMIT TRANSACTION error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return 0;
      }

  no_table:
    free_columns (&params);
    fclose (xml_file);

    if (in_memory)
      {
	  /* exporting the in-memory DB to filesystem */
	  sqlite3 *disk_db_handle;
	  sqlite3_backup *backup;
	  int ret;
	  printf ("\nexporting IN_MEMORY database ... wait please ...\n");
	  ret =
	      sqlite3_open_v2 (db_path, &disk_db_handle,
			       SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
			       NULL);
	  if (ret != SQLITE_OK)
	    {
		fprintf (stderr, "cannot open '%s': %s\n", db_path,
			 sqlite3_errmsg (disk_db_handle));
		sqlite3_close (disk_db_handle);
		return -1;
	    }
	  backup = sqlite3_backup_init (disk_db_handle, "main", handle, "main");
	  if (!backup)
	    {
		fprintf (stderr, "Backup failure: 'MEMORY-DB' wasn't saved\n");
		sqlite3_close (handle);
		sqlite3_close (disk_db_handle);
		return -1;
	    }
	  while (1)
	    {
		ret = sqlite3_backup_step (backup, 1024);
		if (ret == SQLITE_DONE)
		    break;
	    }
	  ret = sqlite3_backup_finish (backup);
	  sqlite3_close (handle);
	  handle = disk_db_handle;
	  printf ("\tIN_MEMORY database succesfully exported\n");
      }

    sqlite3_close (handle);
    spatialite_cleanup_ex (cache);
    return 0;
}
예제 #8
0
static int
do_test (int legacy_mode)
{
#ifndef OMIT_GEOS		/* only if GEOS is supported */
    int ret;
    sqlite3 *handle;
    char *err_msg = NULL;
    const char *sql;
    int i;
    char **results;
    int rows;
    int columns;
    void *cache = NULL;
    if (!legacy_mode)
	cache = spatialite_alloc_connection ();
    else
	spatialite_init (0);

    ret = system ("cp sql_stmt_tests/testFDO.sqlite testFDO.sqlite");
    if (ret != 0)
      {
	  fprintf (stderr, "cannot copy testFDO.sqlite database\n");
	  return -1001;
      }

    ret =
	sqlite3_open_v2 ("testFDO.sqlite", &handle,
			 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "cannot open testFDO.sqlite db: %s\n",
		   sqlite3_errmsg (handle));
	  sqlite3_close (handle);
	  return -1000;
      }

    if (!legacy_mode)
	spatialite_init_ex (handle, cache, 0);

/* FDO start-up */
    sql = "SELECT AutoFDOStart()";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -1;
      }

/* testing aggregate Union() PointZ WKT "p02" */
    sql = "SELECT AsText(ST_Union(WKT_GEOMETRY)) FROM fdo_p02";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -2;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -3;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -4;
      }
    if (strcmp
	(results[1],
	 "MULTIPOINT Z(664350.17954 5171957.915655 314.52, 664642.363686 5169415.339218 294.37, 664964.447225 5170571.245732 318.25)")
	!= 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result %s\n", results[1]);
	  return -5;
      }
    sqlite3_free_table (results);

/* testing aggregate Union() PointZ WKB "p03" */
    sql =
	"SELECT AsText(ST_Union(GEOMETRY)) FROM fdo_p03 WHERE text_dil IS NULL AND OGC_FID < 3";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -6;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -7;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -8;
      }
    if (strcmp
	(results[1],
	 "MULTIPOINT Z(665216.306643 5169825.707161 296.06, 665224.506512 5169827.907054 296.16)")
	!= 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result |%s|\n",
		   results[1]);
	  return -9;
      }
    sqlite3_free_table (results);

/* testing aggregate Union() PointZ SpatiaLite "p05" */
    sql =
	"SELECT AsText(ST_Union(GEOMETRY)) FROM fdo_p05 WHERE text_dil IS NULL AND OGC_FID < 3";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -10;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -11;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result %s\n", results[1]);
	  return -12;
      }
    if (strcmp
	(results[1],
	 "MULTIPOINT Z(667687.978175 5169352.045712 583.140015, 667710.008189 5169402.894615 589.849976)")
	!= 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result b|%s|\n",
		   results[1]);
	  return -13;
      }
    sqlite3_free_table (results);

/* testing Sum(GLength()) LinestringZ WKT "l05" */
    sql = "SELECT Sum(GLength(WKT_GEOMETRY)) FROM fdo_l05";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -14;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -15;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -16;
      }
    if (strncmp (results[1], "59.417763", 9) != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -17;
      }
    sqlite3_free_table (results);

/* testing Sum(GLength()) LinestringZ WKB "l06" */
    sql = "SELECT Sum(GLength(GEOMETRY)) FROM fdo_l06";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -18;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -19;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -20;
      }
    if (strncmp (results[1], "273.076064", 10) != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -21;
      }
    sqlite3_free_table (results);

/* testing Sum(GLength()) LinestringZ SpatiaLite "l07" */
    sql = "SELECT Sum(GLength(GEOMETRY)) FROM fdo_l07";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -22;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -23;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -24;
      }
    if (strncmp (results[1], "219.459808", 10) != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -25;
      }
    sqlite3_free_table (results);

/* testing Sum(Area()) PolygonZ WKT "f04" */
    sql = "SELECT Sum(Area(WKT_GEOMETRY)) FROM fdo_f04";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -26;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -27;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -28;
      }
    if (strncmp (results[1], "9960.931239", 11) != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -29;
      }
    sqlite3_free_table (results);

/* testing Sum(Area()) PolygonZ WKB "f05" */
    sql = "SELECT Sum(Area(GEOMETRY)) FROM fdo_f05";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -30;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -31;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -32;
      }
    if (strncmp (results[1], "69972.113393", 12) != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -33;
      }
    sqlite3_free_table (results);

/* testing Sum(Area()) PolygonZ SpatiaLite "f06" */
    sql = "SELECT Sum(Area(GEOMETRY)) FROM fdo_f06";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -34;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -35;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -36;
      }
    if (strncmp (results[1], "1125.064396", 11) != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -37;
      }
    sqlite3_free_table (results);

/* testing IsValid() LinestringZ WKB "l06" */
    sql = "SELECT IsValid(GEOMETRY) FROM fdo_l06";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -38;
      }
    if ((rows != 12) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -39;
      }
    for (i = 1; i <= rows; i++)
      {
	  if (results[i] == NULL)
	    {
		fprintf (stderr, "Unexpected error: NULL result\n");
		return -40;
	    }
	  if (strcmp (results[i], "0") == 0)
	    {
		const char *geos_msg;
		if (legacy_mode)
		    geos_msg = gaiaGetGeosErrorMsg ();
		else
		    geos_msg = gaiaGetGeosErrorMsg_r (cache);
		if (geos_msg == NULL)
		  {
		      if (legacy_mode)
			  geos_msg = gaiaGetGeosWarningMsg ();
		      else
			  geos_msg = gaiaGetGeosWarningMsg_r (cache);
		  }
		if (geos_msg == NULL)
		  {
		      fprintf (stderr, "Unexpected error: invalid result\n");
		      return -41;
		  }
	    }
      }
    sqlite3_free_table (results);

/* testing IsValid() PolygonZ WKT "f04" */
    sql = "SELECT IsValid(WKT_GEOMETRY) FROM fdo_f04";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -42;
      }
    if ((rows != 16) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -43;
      }
    for (i = 1; i <= rows; i++)
      {
	  if (results[i] == NULL)
	    {
		fprintf (stderr, "Unexpected error: NULL result\n");
		return -44;
	    }
	  if (strcmp (results[i], "0") == 0)
	    {
		const char *geos_msg;
		if (legacy_mode)
		    geos_msg = gaiaGetGeosErrorMsg ();
		else
		    geos_msg = gaiaGetGeosErrorMsg_r (cache);
		if (geos_msg == NULL)
		  {
		      if (legacy_mode)
			  geos_msg = gaiaGetGeosWarningMsg ();
		      else
			  geos_msg = gaiaGetGeosWarningMsg_r (cache);
		  }
		if (geos_msg == NULL)
		  {
		      fprintf (stderr, "Unexpected error: invalid result\n");
		      return -45;
		  }
	    }
      }
    sqlite3_free_table (results);

/* testing IsValid() PolygonZ WKB "f05" */
    sql = "SELECT IsValid(GEOMETRY) FROM fdo_f05";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -46;
      }
    if ((rows != 13) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -47;
      }
    for (i = 1; i <= rows; i++)
      {
	  if (results[i] == NULL)
	    {
		fprintf (stderr, "Unexpected error: NULL result\n");
		return -48;
	    }
	  if (strcmp (results[i], "0") == 0)
	    {
		const char *geos_msg;
		if (legacy_mode)
		    geos_msg = gaiaGetGeosErrorMsg ();
		else
		    geos_msg = gaiaGetGeosErrorMsg_r (cache);
		if (geos_msg == NULL)
		  {
		      if (legacy_mode)
			  geos_msg = gaiaGetGeosWarningMsg ();
		      else
			  geos_msg = gaiaGetGeosWarningMsg_r (cache);
		  }
		if (geos_msg == NULL)
		  {
		      fprintf (stderr, "Unexpected error: invalid result\n");
		      return -49;
		  }
	    }
      }
    sqlite3_free_table (results);

/* testing DOUBLE and TEXT columns */
    sql = "SELECT datum, hoehe FROM fdo_p05 WHERE OGC_FID = 5";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -50;
      }
    if ((rows != 1) || (columns != 2))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -51;
      }
    if (results[2] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -52;
      }
    if (strcmp (results[2], "1997/03/07") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -53;
      }
    if (results[3] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -54;
      }
    if (strcmp (results[3], "277.55") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -54;
      }
    sqlite3_free_table (results);

/* FDO shut-down */
    sql = "SELECT AutoFDOStop()";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -55;
      }

    ret = sqlite3_close (handle);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "sqlite3_close() error: %s\n",
		   sqlite3_errmsg (handle));
	  return -56;
      }

    spatialite_cleanup_ex (cache);
    ret = unlink ("testFDO.sqlite");
    if (ret != 0)
      {
	  fprintf (stderr, "cannot remove testFDO database\n");
	  return -57;
      }
#endif /* end GEOS conditional */

    return 0;
}
int
main (int argc, char *argv[])
{
    sqlite3 *handle_in = NULL;
    sqlite3 *handle_out = NULL;
    void *cache_in = NULL;
    void *cache_out = NULL;
    const char *path_origin;
    const char *path_destination;
    int ret;
    if (argc > 1 || argv[0] == NULL)
	argc = 1;		/* silencing stupid compiler warnings */

    do_unlink_all ();

/* converting from SpatiaLite v4 to GPKG */
    ret = system ("cp ./gpkg_test.sqlite copy-gpkg_test.sqlite");
    if (ret != 0)
      {
	  fprintf (stderr, "cannot copy gpkg_test.sqlite database\n");
	  return -1;
      }
    path_origin = "./copy-gpkg_test.sqlite";
    path_destination = "./out1.gpkg";
    cache_in = spatialite_alloc_connection ();
    cache_out = spatialite_alloc_connection ();
    if (!open_connections
	(path_origin, path_destination, cache_in, cache_out, &handle_in,
	 &handle_out))
      {
	  do_unlink_all ();
	  return -1;
      }
    if (!gaiaSpatialite2GPKG
	(handle_in, path_origin, handle_out, path_destination))
      {
	  do_unlink_all ();
	  return -1;
      }
    sqlite3_close (handle_in);
    sqlite3_close (handle_out);
    spatialite_cleanup_ex (cache_in);
    spatialite_cleanup_ex (cache_out);

/* converting from GPKG to SpatiaLite */
    path_origin = "./out1.gpkg";
    path_destination = "./out1.sqlite";
    cache_in = spatialite_alloc_connection ();
    cache_out = spatialite_alloc_connection ();
    if (!open_connections
	(path_origin, path_destination, cache_in, cache_out, &handle_in,
	 &handle_out))
      {
	  do_unlink_all ();
	  return -1;
      }
    if (!gaiaGPKG2Spatialite
	(handle_in, path_origin, handle_out, path_destination))
      {
	  do_unlink_all ();
	  return -1;
      }
    sqlite3_close (handle_in);
    sqlite3_close (handle_out);
    spatialite_cleanup_ex (cache_in);
    spatialite_cleanup_ex (cache_out);

/* converting from SpatiaLite v3 to GPKG */
    ret =
	system ("cp ./test-legacy-3.0.1.sqlite copy-test-legacy-3.0.1.sqlite");
    if (ret != 0)
      {
	  do_unlink_all ();
	  fprintf (stderr, "cannot copy test-legacy-3.0.1.sqlite database\n");
	  return -1;
      }
    if (!do_load_legacy ("./copy-test-legacy-3.0.1.sqlite"))
      {
	  do_unlink_all ();
	  return -1;
      }
    path_origin = "./copy-test-legacy-3.0.1.sqlite";
    path_destination = "./out2.sqlite";
    cache_in = spatialite_alloc_connection ();
    cache_out = spatialite_alloc_connection ();
    if (!open_connections
	(path_origin, path_destination, cache_in, cache_out, &handle_in,
	 &handle_out))
      {
	  do_unlink_all ();
	  return -1;
      }
    if (!gaiaSpatialite2GPKG
	(handle_in, path_origin, handle_out, path_destination))
      {
	  do_unlink_all ();
	  return -1;
      }
    sqlite3_close (handle_in);
    sqlite3_close (handle_out);
    spatialite_cleanup_ex (cache_in);
    spatialite_cleanup_ex (cache_out);

    do_unlink_all ();
    return 0;
}
예제 #10
0
int main (int argc, char *argv[])
{
#ifndef OMIT_GEOS	/* only if GEOS is supported */
    int ret;
    sqlite3 *handle;
    char *err_msg = NULL;
    const char *sql;
    char **results;
    int rows;
    int columns;
    void *cache = spatialite_alloc_connection();

    if (argc > 1 || argv[0] == NULL)
	argc = 1;		/* silencing stupid compiler warnings */

    ret = system("cp sql_stmt_tests/testFGF.sqlite testFGF.sqlite");
    if (ret != 0)
    {
        fprintf(stderr, "cannot copy testFGF.sqlite database\n");
        return -1001;
    }
    ret = sqlite3_open_v2 ("testFGF.sqlite", &handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    if (ret != SQLITE_OK) {
	fprintf(stderr, "cannot open testFGF.sqlite db: %s\n", sqlite3_errmsg (handle));
	sqlite3_close(handle);
	return -1000;
    }

    spatialite_init_ex (handle, cache, 0);

/* FDO start-up */
    sql = "SELECT AutoFDOStart()";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -1;
    }

/* testing aggregate Union() Point FGF "HouseNumbers" */
    sql = "SELECT AsText(ST_Union(Geometry)) FROM fdo_HouseNumbers WHERE TEXT_LABEL LIKE '11%'";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -2;
    }
    if ((rows != 1) || (columns != 1)) {
      fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows, columns);
      return -3;
    }
    if (results[1] == NULL) {
      fprintf (stderr, "Unexpected error: NULL result\n");
      return -4;
    }
    if (strcmp(results[1], "MULTIPOINT(430417.1 5448290.9, 430666.6 5448125.4)") != 0) {        
      	    fprintf (stderr, "Unexpected error: invalid result |%s|\n", results[1]);
        return -5;
    }
    sqlite3_free_table (results);

/* testing Sum(GLength()) Linestring FGF "Centrerlines" */
    sql = "SELECT Sum(GLength(Geometry)) FROM fdo_Centerlines";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -6;
    }
    if ((rows != 1) || (columns != 1)) {
      fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows, columns);
      return -7;
    }
    if (results[1] == NULL) {
      fprintf (stderr, "Unexpected error: NULL result\n");
      return -8;
    }
    if (strncmp(results[1], "895.3351", 7) != 0) {        
      fprintf (stderr, "Unexpected error: invalid result\n");
      return -9;
    }
    sqlite3_free_table (results);

/* testing Sum(Area()) Polygon FGF "AssessmentParcels" */
    sql = "SELECT Sum(Area(Geometry)) FROM fdo_AssessmentParcels";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -10;
    }
    if ((rows != 1) || (columns != 1)) {
      fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows, columns);
      return -11;
    }
    if (results[1] == NULL) {
      fprintf (stderr, "Unexpected error: NULL result\n");
      return -12;
    }
    if (strncmp(results[1], "9022.1792", 9) != 0) {        
      fprintf (stderr, "Unexpected error: invalid result\n");
      return -13;
    }
    sqlite3_free_table (results);

/* FDO shut-down */
    sql = "SELECT AutoFDOStop()";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -14;
    }

    ret = sqlite3_close (handle);
    if (ret != SQLITE_OK) {
        fprintf (stderr, "sqlite3_close() error: %s\n", sqlite3_errmsg (handle));
	return -15;
    }
    
    spatialite_cleanup_ex (cache);
    ret = unlink("testFGF.sqlite");
    if (ret != 0)
    {
        fprintf(stderr, "cannot remove testFGF database\n");
        return -16;
    }
#endif	/* end GEOS conditional */
    
    return 0;
}
예제 #11
0
int
main (int argc, char *argv[])
{
    int result = 0;
    int ret;
    char *err_msg = NULL;
    sqlite3 *db_handle;
    void *cache = spatialite_alloc_connection ();
    void *priv_data = rl2_alloc_private ();
    char *old_SPATIALITE_SECURITY_ENV = NULL;

    if (argc > 1 || argv[0] == NULL)
	argc = 1;		/* silencing stupid compiler warnings */

    old_SPATIALITE_SECURITY_ENV = getenv ("SPATIALITE_SECURITY");
#ifdef _WIN32
    putenv ("SPATIALITE_SECURITY=relaxed");
#else /* not WIN32 */
    setenv ("SPATIALITE_SECURITY", "relaxed", 1);
#endif

/* opening and initializing the "memory" test DB */
    ret = sqlite3_open_v2 (":memory:", &db_handle,
			   SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "sqlite3_open_v2() error: %s\n",
		   sqlite3_errmsg (db_handle));
	  return -1;
      }
    spatialite_init_ex (db_handle, cache, 0);
    rl2_init (db_handle, priv_data, 0);
    ret =
	sqlite3_exec (db_handle, "SELECT InitSpatialMetadata(1)", NULL, NULL,
		      &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "InitSpatialMetadata() error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -2;
      }
    ret =
	sqlite3_exec (db_handle, "SELECT CreateRasterCoveragesTable()", NULL,
		      NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "CreateRasterCoveragesTable() error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -3;
      }

/* SRTM NILE-DOUBLE (GRID) tests */
    ret = -100;
    if (!test_coverage (db_handle, RL2_SAMPLE_INT8, TILE_256, &ret))
	return ret;
    ret = -120;
    if (!test_coverage (db_handle, RL2_SAMPLE_INT8, TILE_1024, &ret))
	return ret;
    ret = -140;
    if (!test_coverage (db_handle, RL2_SAMPLE_UINT8, TILE_256, &ret))
	return ret;
    ret = -160;
    if (!test_coverage (db_handle, RL2_SAMPLE_UINT8, TILE_1024, &ret))
	return ret;
    ret = -180;
    if (!test_coverage (db_handle, RL2_SAMPLE_INT16, TILE_256, &ret))
	return ret;
    ret = -200;
    if (!test_coverage (db_handle, RL2_SAMPLE_INT16, TILE_1024, &ret))
	return ret;
    ret = -220;
    if (!test_coverage (db_handle, RL2_SAMPLE_UINT16, TILE_256, &ret))
	return ret;
    ret = -240;
    if (!test_coverage (db_handle, RL2_SAMPLE_UINT16, TILE_1024, &ret))
	return ret;
    ret = -260;
    if (!test_coverage (db_handle, RL2_SAMPLE_INT32, TILE_256, &ret))
	return ret;
    ret = -280;
    if (!test_coverage (db_handle, RL2_SAMPLE_INT32, TILE_1024, &ret))
	return ret;
    ret = -300;
    if (!test_coverage (db_handle, RL2_SAMPLE_UINT32, TILE_256, &ret))
	return ret;
    ret = -320;
    if (!test_coverage (db_handle, RL2_SAMPLE_UINT32, TILE_1024, &ret))
	return ret;
    ret = -340;
    if (!test_coverage (db_handle, RL2_SAMPLE_FLOAT, TILE_256, &ret))
	return ret;
    ret = -360;
    if (!test_coverage (db_handle, RL2_SAMPLE_FLOAT, TILE_1024, &ret))
	return ret;
    ret = -380;
    if (!test_coverage (db_handle, RL2_SAMPLE_DOUBLE, TILE_256, &ret))
	return ret;
    ret = -400;
    if (!test_coverage (db_handle, RL2_SAMPLE_DOUBLE, TILE_1024, &ret))
	return ret;

/* closing the DB */
    sqlite3_close (db_handle);
    spatialite_cleanup_ex (cache);
    rl2_cleanup_private (priv_data);
    spatialite_shutdown ();
    if (old_SPATIALITE_SECURITY_ENV)
      {
#ifdef _WIN32
	  char *env = sqlite3_mprintf ("SPATIALITE_SECURITY=%s",
				       old_SPATIALITE_SECURITY_ENV);
	  putenv (env);
	  sqlite3_free (env);
#else /* not WIN32 */
	  setenv ("SPATIALITE_SECURITY", old_SPATIALITE_SECURITY_ENV, 1);
#endif
      }
    else
      {
#ifdef _WIN32
	  putenv ("SPATIALITE_SECURITY=");
#else /* not WIN32 */
	  unsetenv ("SPATIALITE_SECURITY");
#endif
      }
    return result;
}
예제 #12
0
int
main (int argc, char *argv[])
{
    int ret;
    sqlite3 *handle;
    void *cache = spatialite_alloc_connection ();

    if (argc > 1 || argv[0] == NULL)
	argc = 1;		/* silencing stupid compiler warnings */

    ret =
	sqlite3_open_v2 (":memory:", &handle,
			 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "cannot open in-memory db: %s\n",
		   sqlite3_errmsg (handle));
	  sqlite3_close (handle);
	  return -1;
      }

    spatialite_init_ex (handle, cache, 0);

#ifdef ENABLE_LIBXML2		/* only if LIBXML2 is supported */

    if (!check_parse (cache, "books.xml"))
      {
	  fprintf (stderr, "unable to parse \"books.xml\"\n");
	  return -2;
      }
    if (!check_parse (cache, "opera.xml"))
      {
	  fprintf (stderr, "unable to parse \"opera.xml\"\n");
	  return -3;
      }
    if (!check_parse (cache, "movies.xml"))
      {
	  fprintf (stderr, "unable to parse \"movies.xml\"\n");
	  return -4;
      }

    if (!check_validate (cache, "books.xml"))
      {
	  fprintf (stderr, "unable to validate \"books.xml\"\n");
	  return -5;
      }
    if (!check_validate (cache, "opera.xml"))
      {
	  fprintf (stderr, "unable to validate \"opera.xml\"\n");
	  return -6;
      }
    if (!check_validate (cache, "movies.xml"))
      {
	  fprintf (stderr, "unable to validate \"movies.xml\"\n");
	  return -7;
      }
    if (!check_extended (cache, "inspire-data-example.xml", ISO_METADATA))
      {
	  fprintf (stderr, "unable to parse \"inspire-data-example.xml\"\n");
	  return -8;
      }
    if (!check_extended (cache, "stazioni_se.xml", SLD_SE_STYLE))
      {
	  fprintf (stderr, "unable to parse \"stazioni_se.xml\"\n");
	  return -9;
      }
    if (!check_extended (cache, "thunderstorm_mild.svg", SVG))
      {
	  fprintf (stderr, "unable to parse \"thunderstorm_mild.svg\"\n");
	  return -10;
      }

    if (!check_bad_xml (cache))
      {
	  fprintf (stderr, "unable to test not well-formed XML\n");
	  return -11;
      }
    if (!check_bad_schema (cache))
      {
	  fprintf (stderr, "unable to test invalid Schema\n");
	  return -12;
      }

    if (!check_mline_gpx (handle, cache, "000323485.gpx"))
      {
	  fprintf (stderr, "unable to test \"000323485.gpx\"\n");
	  return -13;
      }
    if (!check_mline_gpx (handle, cache, "Gpx-sample.gpx"))
      {
	  fprintf (stderr, "unable to test \"Gpx-sample.gpx\"\n");
	  return -14;
      }

#endif

    ret = sqlite3_close (handle);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "sqlite3_close() error: %s\n",
		   sqlite3_errmsg (handle));
	  return -10;
      }

    spatialite_cleanup_ex (cache);

    spatialite_shutdown ();

    return 0;
}
int
main (int argc, char *argv[])
{
#ifndef OMIT_ICONV		/* only if ICONV is supported */
    int ret;
    sqlite3 *handle;
    void *cache = spatialite_alloc_connection ();

    if (argc > 1 || argv[0] == NULL)
	argc = 1;		/* silencing stupid compiler warnings */

    ret =
	sqlite3_open_v2 (":memory:", &handle,
			 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "cannot open in-memory database: %s\n",
		   sqlite3_errmsg (handle));
	  sqlite3_close (handle);
	  return -1;
      }

    spatialite_init_ex (handle, cache, 0);

    ret = do_test (handle, cache);
    if (ret != 0)
	return ret;

    ret = sqlite3_close (handle);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "sqlite3_close() error: %s\n",
		   sqlite3_errmsg (handle));
	  return -61;
      }

    spatialite_cleanup_ex (cache);

/* testing again in legacy mode */
    spatialite_init (0);

    ret =
	sqlite3_open_v2 (":memory:", &handle,
			 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "cannot open in-memory database: %s\n",
		   sqlite3_errmsg (handle));
	  sqlite3_close (handle);
	  return -62;
      }

    ret = do_test (handle, NULL);
    if (ret != 0)
	return ret;

    ret = sqlite3_close (handle);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "sqlite3_close() error: %s\n",
		   sqlite3_errmsg (handle));
	  return -63;

	  spatialite_cleanup ();
      }
#endif /* end ICONV conditional */

    spatialite_shutdown ();
    return 0;
}
예제 #14
0
int main (int argc, char *argv[])
{
    int ret;
    sqlite3 *handle;
    char *err_msg = NULL;
    char **results;
    int rows;
    int columns;
    unsigned char *blob;
    int blob_len;
    char *hexBlob;
    unsigned char *xml;
    int len;
    char *sql;
    void *cache = spatialite_alloc_connection();

    if (argc > 1 || argv[0] == NULL)
	argc = 1;		/* silencing stupid compiler warnings */

    ret = sqlite3_open_v2 (":memory:", &handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    if (ret != SQLITE_OK) {
	fprintf(stderr, "cannot open in-memory db: %s\n", sqlite3_errmsg (handle));
	sqlite3_close(handle);
	return -1;
    }

    spatialite_init_ex (handle, cache, 0);

    ret = sqlite3_exec (handle, "SELECT InitSpatialMetadata(1, 'WGS84')", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf(stderr, "Unexpected InitSpatialMetadata result: %i, (%s)\n", ret, err_msg);
	sqlite3_free (err_msg);
	return -2;
    }

#ifdef ENABLE_LIBXML2	/* only if LIBXML2 is supported */

    ret = sqlite3_get_table (handle, "SELECT CreateStylingTables(1)", &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error CreateStylingTables: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -3;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -4;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #0 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -5;
    }
    sqlite3_free_table(results);

    blob = load_blob("empty.png", &blob_len);
    if (blob == NULL) 
        return -6;
    hexBlob = build_hex_blob(blob, blob_len);
    free(blob);
    if (hexBlob == NULL)
        return -7;
    sql = sqlite3_mprintf("SELECT RegisterExternalGraphic('url-A', x%Q)", hexBlob);
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    sqlite3_free(sql);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error RegisterExternalGraphic #1: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -8;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -9;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #1 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -10;
    }
    sqlite3_free_table(results);

    sql = sqlite3_mprintf("SELECT RegisterExternalGraphic('url-A', x%Q, 'title', 'abstract', 'file_name')", hexBlob);
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    free(hexBlob);
    sqlite3_free(sql);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error RegisterExternalGraphic #2: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -11;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -12;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #2 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -13;
    }
    sqlite3_free_table(results);

    xml = load_xml("thunderstorm_mild.svg", &len);
    if (xml == NULL) 
        return -14;
    gaiaXmlToBlob (cache, xml, len, 1, NULL, &blob, &blob_len, NULL, NULL); 
    free(xml);
    if (blob == NULL) {
        fprintf (stderr, "this is not a well-formed XML !!!\n");
        return -15;
    }
    hexBlob = build_hex_blob(blob, blob_len);
    free(blob);
    if (hexBlob == NULL)
        return -16;
    sql = sqlite3_mprintf("SELECT RegisterExternalGraphic('url-B', x%Q, 'title', 'abstract', 'file_name')", hexBlob);
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    sqlite3_free(sql);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error RegisterExternalGraphic #3: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -17;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -18;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #3 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -19;
    }
    sqlite3_free_table(results);

    sql = sqlite3_mprintf("SELECT RegisterExternalGraphic('url-B', x%Q)", hexBlob);
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    free(hexBlob);
    sqlite3_free(sql);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error RegisterExternalGraphic #4: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -20;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -21;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #4 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -22;
    }
    sqlite3_free_table(results);

    ret = sqlite3_exec (handle, "CREATE TABLE table1 (id INTEGER PRIMARY KEY AUTOINCREMENT)", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error Create Table table1: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -23;
    }
    ret = sqlite3_get_table (handle, "SELECT AddGeometryColumn('table1', 'geom', 4326, 'POINT', 'XY')", &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error AddGeometryColumn: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -24;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -25;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #5 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -26;
    }
    sqlite3_free_table(results);

    xml = load_xml("stazioni_se.xml", &len);
    if (xml == NULL) 
        return -27;
    gaiaXmlToBlob (cache, xml, len, 1, NULL, &blob, &blob_len, NULL, NULL); 
    free(xml);
    if (blob == NULL) {
        fprintf (stderr, "this is not a well-formed XML !!!\n");
        return -28;
    }
    hexBlob = build_hex_blob(blob, blob_len);
    free(blob);
    if (hexBlob == NULL)
        return -29;
    sql = sqlite3_mprintf("SELECT RegisterVectorStyledLayer('table1', 'geom', x%Q)", hexBlob);
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    sqlite3_free(sql);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error RegisterVectorStyledLayer #6: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -30;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -31;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #6 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -32;
    }
    sqlite3_free_table(results);
    
    sql = sqlite3_mprintf("SELECT RegisterVectorStyledLayer('table1', 'geom', 0, x%Q)", hexBlob);
    free(hexBlob);
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    sqlite3_free(sql);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error RegisterVectorStyledLayer #7: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -33;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -34;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #7 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -35;
    }
    sqlite3_free_table(results);

    xml = load_xml("raster_se.xml", &len);
    if (xml == NULL) 
        return -36;
    gaiaXmlToBlob (cache, xml, len, 1, NULL, &blob, &blob_len, NULL, NULL); 
    free(xml);
    if (blob == NULL) {
        fprintf (stderr, "this is not a well-formed XML !!!\n");
        return -37;
    }
    hexBlob = build_hex_blob(blob, blob_len);
    free(blob);
    if (hexBlob == NULL)
        return -38;
    sql = sqlite3_mprintf("SELECT RegisterRasterStyledLayer('srtm', x%Q)", hexBlob);
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    sqlite3_free(sql);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error RegisterRasterStyledLayer #8: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -39;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -40;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #8 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -41;
    }
    sqlite3_free_table(results);
    
    sql = sqlite3_mprintf("SELECT RegisterRasterStyledLayer('srtm', 0, x%Q)", hexBlob);
    free(hexBlob);
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    sqlite3_free(sql);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error RegisterRasterStyledLayer #9: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -42;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -43;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #9 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -44;
    }
    sqlite3_free_table(results);
    
    ret = sqlite3_get_table (handle, "SELECT RegisterStyledGroup('group', 'srtm', 0)", &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error RegisterStyledGroup #10: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -45;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -46;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #10 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -47;
    }
    sqlite3_free_table(results);
    
    ret = sqlite3_get_table (handle, "SELECT RegisterStyledGroup('group', 'table1', 'geom', 0)", &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error RegisterStyledGroup #11: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -48;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -49;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #12 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -50;
    }
    sqlite3_free_table(results);
    
    ret = sqlite3_get_table (handle, "SELECT RegisterStyledGroup('group', 'srtm', 0, 4)", &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error RegisterStyledGroup #13: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -51;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -52;
    }
    if (strcmp(results[1 * columns + 0], "0") != 0)
    {
	fprintf (stderr, "Unexpected #13 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -53;
    }
    sqlite3_free_table(results);
    
    ret = sqlite3_get_table (handle, "SELECT RegisterStyledGroup('group', 'table1', 'geom', 0, 1)", &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error RegisterStyledGroup #14: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -54;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -55;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #14 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -56;
    }
    sqlite3_free_table(results);
    
    ret = sqlite3_get_table (handle, "SELECT SetStyledGroupInfos('group', 'title', 'abstract')", &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error RegisterStyledGroup #15: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -57;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -58;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #15 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -59;
    }
    sqlite3_free_table(results);
    
    ret = sqlite3_get_table (handle, "SELECT SetStyledGroupInfos('group-bis', 'title', 'abstract')", &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error RegisterStyledGroup #16: %s\n", err_msg);
      sqlite3_free (err_msg);
      return 60;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -61;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #16 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -62;
    }
    sqlite3_free_table(results);


#endif
    
    ret = sqlite3_close (handle);
    if (ret != SQLITE_OK) {
        fprintf (stderr, "sqlite3_close() error: %s\n", sqlite3_errmsg (handle));
	return -57;
    }
        
    spatialite_cleanup_ex (cache);

#ifdef ENABLE_LIBXML2	/* only if LIBXML2 is supported */
    xmlCleanupParser();
#endif
    
    return 0;
}
예제 #15
0
int
main (int argc, char *argv[])
{
#ifndef OMIT_ICONV		/* only if ICONV is supported */
    int ret;
    sqlite3 *handle;
    char *dbfname = __FILE__ "test.dbf";
    char *err_msg = NULL;
    int row_count;
    void *cache = spatialite_alloc_connection ();

    if (argc > 1 || argv[0] == NULL)
	argc = 1;		/* silencing stupid compiler warnings */

    ret =
	sqlite3_open_v2 (":memory:", &handle,
			 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "cannot open in-memory database: %s\n",
		   sqlite3_errmsg (handle));
	  sqlite3_close (handle);
	  return -1;
      }

    spatialite_init_ex (handle, cache, 0);

    ret =
	sqlite3_exec (handle, "SELECT InitSpatialMetadata(1)", NULL, NULL,
		      &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "InitSpatialMetadata() error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  sqlite3_close (handle);
	  return -2;
      }

    ret =
	load_shapefile (handle, "./shp/new-caledonia/points", "points",
			"CP1252", 4326, "col1", 1, 0, 1, 0, &row_count,
			err_msg);
    if (!ret)
      {
	  fprintf (stderr,
		   "load_shapefile() error for shp/new-caledonia/points: %s\n",
		   err_msg);
	  sqlite3_close (handle);
	  return -3;
      }
    if (row_count != 10)
      {
	  fprintf (stderr,
		   "unexpected row count for shp/new-caledonia/points: %i\n",
		   row_count);
	  sqlite3_close (handle);
	  return -4;
      }

    ret =
	load_shapefile (handle, "./shp/new-caledonia/railways", "railways",
			"CP1252", 4326, "col1", 1, 0, 1, 0, &row_count,
			err_msg);
    if (!ret)
      {
	  fprintf (stderr,
		   "load_shapefile() error for shp/new-caledonia/railways: %s\n",
		   err_msg);
	  sqlite3_close (handle);
	  return -5;
      }
    if (row_count != 13)
      {
	  fprintf (stderr,
		   "unexpected row count for shp/new-caledonia/points: %i\n",
		   row_count);
	  sqlite3_close (handle);
	  return -6;
      }

    ret =
	load_shapefile (handle, "./shp/new-caledonia/buildings", "buildings",
			"CP1252", 4326, "col1", 1, 0, 1, 0, &row_count,
			err_msg);
    if (!ret)
      {
	  fprintf (stderr,
		   "load_shapefile() error for shp/new-caledonia/buildings: %s\n",
		   err_msg);
	  sqlite3_close (handle);
	  return -7;
      }
    if (row_count != 10)
      {
	  fprintf (stderr,
		   "unexpected row count for shp/new-caledonia/buildings: %i\n",
		   row_count);
	  sqlite3_close (handle);
	  return -8;
      }

    ret = dump_dbf (handle, "points", dbfname, "CP1252", err_msg);
    if (!ret)
      {
	  fprintf (stderr, "dump_dbf() error for points: %s\n", err_msg);
	  sqlite3_close (handle);
	  return -9;
      }
    unlink (dbfname);

    ret = sqlite3_close (handle);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "sqlite3_close() error: %s\n",
		   sqlite3_errmsg (handle));
	  return -9;
      }

    spatialite_cleanup_ex (cache);
#endif /* end ICONV conditional */

    spatialite_shutdown ();
    return 0;
}
int
main (int argc, char *argv[])
{
    int ret;
    sqlite3 *handle;
    char *err_msg = NULL;
    char **results;
    int rows;
    int columns;
    void *cache = spatialite_alloc_connection ();

    if (argc > 1 || argv[0] == NULL)
	argc = 1;		/* silencing stupid compiler warnings */

    ret =
	sqlite3_open_v2 (":memory:", &handle,
			 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "cannot open in-memory db: %s\n",
		   sqlite3_errmsg (handle));
	  sqlite3_close (handle);
	  return -1;
      }

    spatialite_init_ex (handle, cache, 0);

    ret =
	sqlite3_exec (handle, "SELECT InitSpatialMetadata(1)", NULL, NULL,
		      &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "InitSpatialMetadata() error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  sqlite3_close (handle);
	  return -2;
      }

    ret =
	sqlite3_exec (handle,
		      "CREATE TABLE Point_Test (Name TEXT, Description TEXT)",
		      NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "CREATE TABLE error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  sqlite3_close (handle);
	  return -3;
      }

    ret =
	sqlite3_get_table (handle,
			   "SELECT AddGeometryColumn(26, 'geomZ', 4326, 'POINT', 'XYZ', 0)",
			   &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -4;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr,
		   "Unexpected result AddGeometryColumn int arg1 bad result: %i/%i.\n",
		   rows, columns);
	  return -5;
      }
    if (strcmp (results[1], "0") != 0)
      {
	  fprintf (stderr,
		   "Unexpected result: AddGeometryColumn with non-text arg1 passed: %s.\n",
		   results[1]);
	  return -6;
      }
    sqlite3_free_table (results);

    ret =
	sqlite3_get_table (handle,
			   "SELECT AddGeometryColumn('Point_Test', 8, 4326, 'POINT', 'XYZ', 0)",
			   &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -7;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr,
		   "Unexpected result AddGeometryColumn int arg2 bad result: %i/%i.\n",
		   rows, columns);
	  return -8;
      }
    if (strcmp (results[1], "0") != 0)
      {
	  fprintf (stderr,
		   "Unexpected result: AddGeometryColumn with non-text arg2 passed: %s.\n",
		   results[1]);
	  return -9;
      }
    sqlite3_free_table (results);

    ret =
	sqlite3_get_table (handle,
			   "SELECT AddGeometryColumn('Point_Test', 'geomZ', 'sometext', 'POINT', 'XYZ', 0)",
			   &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -10;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr,
		   "Unexpected result AddGeometryColumn text arg3 bad result: %i/%i.\n",
		   rows, columns);
	  return -11;
      }
    if (strcmp (results[1], "0") != 0)
      {
	  fprintf (stderr,
		   "Unexpected result: AddGeometryColumn with non-int arg3 passed: %s.\n",
		   results[1]);
	  return -12;
      }
    sqlite3_free_table (results);

    ret =
	sqlite3_get_table (handle,
			   "SELECT AddGeometryColumn('Point_Test', 'geomZ', 4326, 'POINT', 'XYZ', 0)",
			   &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -13;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr,
		   "Unexpected result AddGeometryColumn bad result: %i/%i.\n",
		   rows, columns);
	  return -14;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr,
		   "Unexpected error: AddGeometryColumn with good args failed: %s.\n",
		   results[1]);
	  return -15;
      }
    sqlite3_free_table (results);

    ret =
	sqlite3_exec (handle,
		      "INSERT INTO Point_Test (Name, Description, geomZ) VALUES ('Point 1', 'Some point', GeomFromText('POINTZ(136 -33 365)', 4326))",
		      NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "INSERT POINT XYZ error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  sqlite3_close (handle);
	  return -16;
      }

    ret =
	sqlite3_get_table (handle,
			   "SELECT DiscardGeometryColumn('Point_Test', 'geomZ')",
			   &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -17;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr,
		   "Unexpected result DiscardGeometryColumn bad result: %i/%i.\n",
		   rows, columns);
	  return -18;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr,
		   "Unexpected error: DiscardGeometryColumn failed: %s.\n",
		   results[1]);
	  return -19;
      }
    sqlite3_free_table (results);

    ret =
	sqlite3_get_table (handle,
			   "SELECT RecoverGeometryColumn('Point_Test', 'geomZ', 4326, 'POINT', 'XYZ')",
			   &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -20;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr,
		   "Unexpected result RecoverGeometryColumn bad result: %i/%i.\n",
		   rows, columns);
	  return -21;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr,
		   "Unexpected error: RecoverGeometryColumn failed: %s.\n",
		   results[1]);
	  return -22;
      }
    sqlite3_free_table (results);
    ret = sqlite3_close (handle);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "sqlite3_close() error: %s\n",
		   sqlite3_errmsg (handle));
	  return -23;
      }

    spatialite_cleanup_ex (cache);
    spatialite_shutdown ();

    return 0;
}
예제 #17
0
int main (int argc, char *argv[])
{
#ifndef OMIT_ICONV	/* only if ICONV is supported */
    int ret;
    sqlite3 *handle;
    char *err_msg = NULL;
    int row_count;
    void *cache = spatialite_alloc_connection();

    if (argc > 1 || argv[0] == NULL)
	argc = 1;		/* silencing stupid compiler warnings */

    ret = sqlite3_open_v2 (":memory:", &handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    if (ret != SQLITE_OK) {
	fprintf(stderr, "cannot open in-memory database: %s\n", sqlite3_errmsg (handle));
	sqlite3_close(handle);
	return -1;
    }

    spatialite_init_ex (handle, cache, 0);
    
    ret = sqlite3_exec (handle, "SELECT InitSpatialMetadata(1)", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "InitSpatialMetadata() error: %s\n", err_msg);
	sqlite3_free(err_msg);
	sqlite3_close(handle);
	return -2;
    }

    ret = load_shapefile (handle, "./shapetest1", "test1", "UTF-8", 4326, 
			  "col1", 1, 0, 1, 0, &row_count, err_msg);
    if (!ret) {
        fprintf (stderr, "load_shapefile() error: %s\n", err_msg);
	sqlite3_close(handle);
	return -3;
    }

#ifdef ENABLE_LWGEOM		/* only if LWGEOM is supported */

    ret = check_geometry_column (handle, "test1", "geometry", "./report.html", NULL, NULL, NULL);
    if (ret) {
        fprintf (stderr, "check_geometry_column() error\n");
	sqlite3_close(handle);
	return -4;
    }

    ret = sanitize_geometry_column (handle, "test1", "geometry", "tmp_test1", "./report.html", NULL, NULL, NULL, NULL, NULL); 
    if (ret) {
        fprintf (stderr, "sanitize_geometry_column() error\n");
	sqlite3_close(handle);
	return -5;
    }

    ret = check_geometry_column (handle, "test1", "col1", "./report.html", NULL, NULL, NULL);
    if (!ret) {
        fprintf (stderr, "check_geometry_column() error\n");
	sqlite3_close(handle);
	return -6;
    }

    ret = sanitize_geometry_column (handle, "test1", "col1", "tmp_test1", "./report.html", NULL, NULL, NULL, NULL, NULL); 
    if (!ret) {
        fprintf (stderr, "sanitize_geometry_column() error\n");
	sqlite3_close(handle);
	return -7;
    }

#endif /* end LWGEOM conditionals */
    
    ret = sqlite3_close (handle);
    if (ret != SQLITE_OK) {
        fprintf (stderr, "sqlite3_close() error: %s\n", sqlite3_errmsg (handle));
	return -8;
    }
    
    spatialite_cleanup_ex (cache);
#endif	/* end ICONV conditional */

    return 0;
}
예제 #18
0
int
main (int argc, char *argv[])
{
    sqlite3 *db_handle;
    int ret;
    const char *sql;
    void *cache = NULL;
    char *sql_err = NULL;
    if (argc > 1 || argv[0] == NULL)
	argc = 1;		/* silencing stupid compiler warnings */

    do_unlink_all ();

/* directly testing GPKG */
    ret = system ("cp ./gpkg_test.gpkg copy-gpkg_test.gpkg");
    if (ret != 0)
      {
	  fprintf (stderr, "cannot copy gpkg_test.gpkg database\n");
	  return -1;
      }

    cache = spatialite_alloc_connection ();
    ret =
	sqlite3_open_v2 ("./copy-gpkg_test.gpkg", &db_handle,
			 SQLITE_OPEN_READWRITE, NULL);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "cannot open '%s': %s\n", "copy-gpkg_test.gpkg",
		   sqlite3_errmsg (db_handle));
	  do_unlink_all ();
	  sqlite3_close (db_handle);
	  spatialite_cleanup_ex (cache);
	  spatialite_shutdown ();
	  return -1;
      }
    spatialite_init_ex (db_handle, cache, 0);

    if (!test_table (db_handle, "pt2d"))
      {
	  do_unlink_all ();
	  sqlite3_close (db_handle);
	  spatialite_cleanup_ex (cache);
	  spatialite_shutdown ();
	  return -1;
      }

    if (!test_table (db_handle, "ln3dz"))
      {
	  do_unlink_all ();
	  sqlite3_close (db_handle);
	  spatialite_cleanup_ex (cache);
	  spatialite_shutdown ();
	  return -1;
      }

    if (!test_table (db_handle, "pg2dm"))
      {
	  do_unlink_all ();
	  sqlite3_close (db_handle);
	  spatialite_cleanup_ex (cache);
	  spatialite_shutdown ();
	  return -1;
      }

    if (!test_table (db_handle, "mpt3dzm"))
      {
	  do_unlink_all ();
	  sqlite3_close (db_handle);
	  spatialite_cleanup_ex (cache);
	  spatialite_shutdown ();
	  return -1;
      }

    if (!test_table (db_handle, "mln2dm"))
      {
	  do_unlink_all ();
	  sqlite3_close (db_handle);
	  spatialite_cleanup_ex (cache);
	  spatialite_shutdown ();
	  return -1;
      }

    if (!test_table (db_handle, "mpg3dz"))
      {
	  do_unlink_all ();
	  sqlite3_close (db_handle);
	  spatialite_cleanup_ex (cache);
	  spatialite_shutdown ();
	  return -1;
      }

    if (!test_table (db_handle, "gc3dz"))
      {
	  do_unlink_all ();
	  sqlite3_close (db_handle);
	  spatialite_cleanup_ex (cache);
	  spatialite_shutdown ();
	  return -1;
      }

/* activating Auto GPKG Wrapping */
    sql = "SELECT AutoGPKGStart()";
    ret = sqlite3_exec (db_handle, sql, NULL, NULL, &sql_err);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "AutoGPKGStart error: %s\n", sql_err);
	  sqlite3_free (sql_err);
	  do_unlink_all ();
	  sqlite3_close (db_handle);
	  spatialite_cleanup_ex (cache);
	  spatialite_shutdown ();
	  return -1;
      }

/* testing the Virtual Tables */
    if (!test_vtable (db_handle, "pt2d", 0))
      {
	  do_unlink_all ();
	  sqlite3_close (db_handle);
	  spatialite_cleanup_ex (cache);
	  spatialite_shutdown ();
	  return -1;
      }

    if (!test_vtable (db_handle, "ln3dz", 0))
      {
	  do_unlink_all ();
	  sqlite3_close (db_handle);
	  spatialite_cleanup_ex (cache);
	  spatialite_shutdown ();
	  return -1;
      }

    if (!test_vtable (db_handle, "pg2dm", 0))
      {
	  do_unlink_all ();
	  sqlite3_close (db_handle);
	  spatialite_cleanup_ex (cache);
	  spatialite_shutdown ();
	  return -1;
      }

    if (!test_vtable (db_handle, "mpt3dzm", 0))
      {
	  do_unlink_all ();
	  sqlite3_close (db_handle);
	  spatialite_cleanup_ex (cache);
	  spatialite_shutdown ();
	  return -1;
      }

    if (!test_vtable (db_handle, "mln2dm", 0))
      {
	  do_unlink_all ();
	  sqlite3_close (db_handle);
	  spatialite_cleanup_ex (cache);
	  spatialite_shutdown ();
	  return -1;
      }

    if (!test_vtable (db_handle, "mpg3dz", 0))
      {
	  do_unlink_all ();
	  sqlite3_close (db_handle);
	  spatialite_cleanup_ex (cache);
	  spatialite_shutdown ();
	  return -1;
      }

    if (!test_vtable (db_handle, "gc3dz", 0))
      {
	  do_unlink_all ();
	  sqlite3_close (db_handle);
	  spatialite_cleanup_ex (cache);
	  spatialite_shutdown ();
	  return -1;
      }

    if (!test_vtable (db_handle, "test_pk", 1))
      {
	  do_unlink_all ();
	  sqlite3_close (db_handle);
	  spatialite_cleanup_ex (cache);
	  spatialite_shutdown ();
	  return -1;
      }

    if (!test_vtable_out (db_handle))
      {
	  do_unlink_all ();
	  sqlite3_close (db_handle);
	  spatialite_cleanup_ex (cache);
	  spatialite_shutdown ();
	  return -1;
      }

/* quitting Auto GPKG Wrapping */
    sql = "SELECT AutoGPKGStop()";
    ret = sqlite3_exec (db_handle, sql, NULL, NULL, &sql_err);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "AutoGPKGStop error: %s\n", sql_err);
	  sqlite3_free (sql_err);
	  do_unlink_all ();
	  sqlite3_close (db_handle);
	  spatialite_cleanup_ex (cache);
	  spatialite_shutdown ();
	  return -1;
      }

    sqlite3_close (db_handle);
    spatialite_cleanup_ex (cache);
    spatialite_shutdown ();

    do_unlink_all ();
    return 0;
}
예제 #19
0
int
main (int argc, char *argv[])
{
    int ret;
    sqlite3 *handle;
    sqlite3_stmt *stmt;
    gaiaGeomCollPtr geom;
    char sql[256];
    int i;
    int ic;
    char **results;
    int n_rows;
    int n_columns;
    char *err_msg = NULL;
    int len;
    char *table_name;
    char **p_geotables = NULL;
    int n_geotables = 0;
    int row_no;
    const void *blob;
    int blob_size;
    int geom_type;
    double measure;
    void *cache;


    if (argc != 2)
      {
	  fprintf (stderr, "usage: %s test_db_path\n", argv[0]);
	  return -1;
      }


/* 
trying to connect the test DB: 
- this demo was designed in order to connect the standard 
  TEST-2.3.SQLITE sample DB
- but you can try to use any SQLite/SpatiaLite DB at your will

Please notice: we'll establish a READ ONLY connection 
*/
    ret = sqlite3_open_v2 (argv[1], &handle, SQLITE_OPEN_READONLY, NULL);
    if (ret != SQLITE_OK)
      {
	  printf ("cannot open '%s': %s\n", argv[1], sqlite3_errmsg (handle));
	  sqlite3_close (handle);
	  return -1;
      }

/* 
VERY IMPORTANT: 
you must initialize the SpatiaLite extension [and related]
BEFORE attempting to perform any other SQLite call 
==========================================================
Please note: starting since 4.1.0 this is completely canged:
- a separate memory block (internal cache) is required by
  each single connection
- allocating/freeing this block falls under the responsibility 
  of the program handling the connection
- in multithreaded programs a connection can never be share by
  different threads; the internal-cache block must be allocated
  by the same thread holding the connection
*/
    
    cache = spatialite_alloc_connection ();
    spatialite_init_ex (handle, cache, 0);


/* showing the SQLite version */
    printf ("SQLite version: %s\n", sqlite3_libversion ());
/* showing the SpatiaLite version */
    printf ("SpatiaLite version: %s\n", spatialite_version ());
    printf ("\n\n");



/* 
SQL query #1 
we'll retrieve GEOMETRY tables from Spatial Metadata 
we are assuming this query will return only few rows, 
so this time we'll use the sqlite3_get_table() interface

this interface is very simple to use
the result set is returned as a rectangular array [rows/columns]
allocated in a temporary memory storage
so, this interface is well suited for small sized result sets,
but performs badly when accessing a large sized resul set

as a side effect, each column value is returned as text, and
isn't possible at all to retrieve true column types
(INTEGER, FLOAT ...)
*/
    strcpy (sql,
	    "SELECT DISTINCT f_table_name FROM geometry_columns ORDER BY 1");
    ret = sqlite3_get_table (handle, sql, &results, &n_rows, &n_columns,
			     &err_msg);
    if (ret != SQLITE_OK)
      {
/* some error occurred */
	  printf ("query#1 SQL error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  goto abort;
      }
    if (n_rows > 1)
      {
/* first row always contains column names and is meaningless in this context */
	  n_geotables = n_rows;
/* allocating a dynamic pointer array to store geotable names */
	  p_geotables = malloc (sizeof (char *) * n_geotables);
	  for (i = 1; i <= n_rows; i++)
	    {
/* 
now we'll fetch one row at each time [and we have only one column to fetch] 

this one is is a simplified demo; but when writing a real application 
you always must check for NULL values !!!!
*/
		table_name = results[(i * n_columns) + 0];
/* and we'll store each geotable name into the dynamic pointer array */
		len = strlen (table_name);
		p_geotables[i - 1] = malloc (len + 1);
		strcpy (p_geotables[i - 1], table_name);
	    }
/* we can now free the table results */
	  sqlite3_free_table (results);
      }



    for (i = 0; i < n_geotables; i++)
      {
/* now we'll scan each geotable we've found in Spatial Metadata */
	  printf ("========= table '%s' ========================\n",
		  p_geotables[i]);



/*
SQL query #2 
we'll retrieve any column from the current geotable 
we are assuming this query will return lots of rows, 
so we have to use sqlite3_prepare_v2() interface

this interface is a more complex one, but is well
suited in order to access huge sized result sets
and true value type control is supported
*/
	  sprintf (sql, "SELECT * FROM %s", p_geotables[i]);
	  ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
	  if (ret != SQLITE_OK)
	    {
/* some error occurred */
		printf ("query#2 SQL error: %s\n", sqlite3_errmsg (handle));
		goto abort;
	    }

/* 
the sqlite3_prepare_v2() call simply parses the SQL statement,
checking for syntax validity, allocating internal structs etc
but no result set row is really yet available
*/

/* we'll now save the #columns within the result set */
	  n_columns = sqlite3_column_count (stmt);
	  row_no = 0;


	  while (1)
	    {
/* this is an infinite loop, intended to fetch any row */

/* we are now trying to fetch the next available row */
		ret = sqlite3_step (stmt);
		if (ret == SQLITE_DONE)
		  {
/* there are no more rows to fetch - we can stop looping */
		      break;
		  }
		if (ret == SQLITE_ROW)
		  {
/* ok, we've just fetched a valid row to process */
		      row_no++;
		      printf ("row #%d\n", row_no);


		      for (ic = 0; ic < n_columns; ic++)
			{
/* 
and now we'll fetch column values

for each column we'll then get:
- the column name
- a column value, that can be of type: SQLITE_NULL, SQLITE_INTEGER, 
 SQLITE_FLOAT, SQLITE_TEXT or SQLITE_BLOB, according to internal DB storage type
*/
			    printf ("\t%-10s = ",
				    sqlite3_column_name (stmt, ic));
			    switch (sqlite3_column_type (stmt, ic))
			      {
			      case SQLITE_NULL:
				  printf ("NULL");
				  break;
			      case SQLITE_INTEGER:
				  printf ("%d", sqlite3_column_int (stmt, ic));
				  break;
			      case SQLITE_FLOAT:
				  printf ("%1.4f",
					  sqlite3_column_double (stmt, ic));
				  break;
			      case SQLITE_TEXT:
				  printf ("'%s'",
					  sqlite3_column_text (stmt, ic));
				  break;
			      case SQLITE_BLOB:
				  blob = sqlite3_column_blob (stmt, ic);
				  blob_size = sqlite3_column_bytes (stmt, ic);

/* checking if this BLOB actually is a GEOMETRY */
				  geom =
				      gaiaFromSpatiaLiteBlobWkb (blob,
								 blob_size);
				  if (!geom)
				    {
/* for sure this one is not a GEOMETRY */
					printf ("BLOB [%d bytes]", blob_size);
				    }
				  else
				    {
					geom_type = gaiaGeometryType (geom);
					if (geom_type == GAIA_UNKNOWN)
					    printf ("EMPTY or NULL GEOMETRY");
					else
					  {
					      char *geom_name;
					      if (geom_type == GAIA_POINT)
						  geom_name = "POINT";
					      if (geom_type == GAIA_LINESTRING)
						  geom_name = "LINESTRING";
					      if (geom_type == GAIA_POLYGON)
						  geom_name = "POLYGON";
					      if (geom_type == GAIA_MULTIPOINT)
						  geom_name = "MULTIPOINT";
					      if (geom_type ==
						  GAIA_MULTILINESTRING)
						  geom_name = "MULTILINESTRING";
					      if (geom_type ==
						  GAIA_MULTIPOLYGON)
						  geom_name = "MULTIPOLYGON";
					      if (geom_type ==
						  GAIA_GEOMETRYCOLLECTION)
						  geom_name =
						      "GEOMETRYCOLLECTION";
					      printf ("%s SRID=%d", geom_name,
						      geom->Srid);
					      if (geom_type == GAIA_LINESTRING
						  || geom_type ==
						  GAIA_MULTILINESTRING)
						{
#ifndef OMIT_GEOS		/* GEOS is required */
						    gaiaGeomCollLength (geom,
									&measure);
						    printf (" length=%1.2f",
							    measure);
#else
						    printf
							(" length=?? [no GEOS support available]");
#endif /* GEOS enabled/disabled */
						}
					      if (geom_type == GAIA_POLYGON ||
						  geom_type ==
						  GAIA_MULTIPOLYGON)
						{
#ifndef OMIT_GEOS		/* GEOS is required */
						    gaiaGeomCollArea (geom,
								      &measure);
						    printf (" area=%1.2f",
							    measure);
#else
						    printf
							("area=?? [no GEOS support available]");
#endif /* GEOS enabled/disabled */
						}
					  }
/* we have now to free the GEOMETRY */
					gaiaFreeGeomColl (geom);
				    }

				  break;
			      };
			    printf ("\n");
			}

		      if (row_no >= 5)
			{
/* we'll exit the loop after the first 5 rows - this is only a demo :-) */
			    break;
			}
		  }
		else
		  {
/* some unexpected error occurred */
		      printf ("sqlite3_step() error: %s\n",
			      sqlite3_errmsg (handle));
		      sqlite3_finalize (stmt);
		      goto abort;
		  }
	    }
/* we have now to finalize the query [memory cleanup] */
	  sqlite3_finalize (stmt);
	  printf ("\n\n");

      }



/* disconnecting the test DB */
    ret = sqlite3_close (handle);
    if (ret != SQLITE_OK)
      {
	  printf ("close() error: %s\n", sqlite3_errmsg (handle));
	  return -1;
      }

/* freeing the internal-cache memory block */
    spatialite_cleanup_ex (cache);

    printf ("\n\nsample successfully terminated\n");
/* we have to free the dynamic pointer array used to store geotable names */
    for (i = 0; i < n_geotables; i++)
      {
/* freeing each tablename */
	  free (p_geotables[i]);
      }
    free (p_geotables);
    spatialite_shutdown();
    return 0;

  abort:
    sqlite3_close (handle);

/* freeing the internal-cache memory block */
    spatialite_cleanup_ex (cache);

    if (p_geotables)
      {
/* we have to free the dynamic pointer array used to store geotable names */
	  for (i = 0; i < n_geotables; i++)
	    {
/* freeing each tablename */
		free (p_geotables[i]);
	    }
	  free (p_geotables);
      }
    spatialite_shutdown();
    return -1;
}
예제 #20
0
int
main (int argc, char *argv[])
{
    int ret;
    sqlite3 *handle;
    sqlite3_stmt *stmt;
    char sql[256];
    char *err_msg = NULL;
    double x;
    double y;
    int pk;
    int ix;
    int iy;
    gaiaGeomCollPtr geo = NULL;
    unsigned char *blob;
    int blob_size;
    int i;
    char **results;
    int n_rows;
    int n_columns;
    char *count;
    clock_t t0;
    clock_t t1;
    void *cache;


    if (argc != 2)
      {
	  fprintf (stderr, "usage: %s test_db_path\n", argv[0]);
	  return -1;
      }


/* 
trying to connect the test DB: 
- this demo is intended to create a new, empty database
*/
    ret = sqlite3_open_v2 (argv[1], &handle,
			   SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    if (ret != SQLITE_OK)
      {
	  printf ("cannot open '%s': %s\n", argv[1], sqlite3_errmsg (handle));
	  sqlite3_close (handle);
	  return -1;
      }
    cache = spatialite_alloc_connection ();
    spatialite_init_ex (handle, cache, 0);


/* showing the SQLite version */
    printf ("SQLite version: %s\n", sqlite3_libversion ());
/* showing the SpatiaLite version */
    printf ("SpatiaLite version: %s\n", spatialite_version ());
    printf ("\n\n");


/* 
we are supposing this one is an empty database,
so we have to create the Spatial Metadata
*/
    strcpy (sql, "SELECT InitSpatialMetadata(1)");
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
/* an error occurred */
	  printf ("InitSpatialMetadata() error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  goto abort;
      }


/*
now we can create the test table
for simplicity we'll define only one column, the primary key
*/
    strcpy (sql, "CREATE TABLE test (");
    strcat (sql, "PK INTEGER NOT NULL PRIMARY KEY)");
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
/* an error occurred */
	  printf ("CREATE TABLE 'test' error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  goto abort;
      }


/*
... we'll add a Geometry column of POINT type to the test table 
*/
    strcpy (sql, "SELECT AddGeometryColumn('test', 'geom', 3003, 'POINT', 2)");
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
/* an error occurred */
	  printf ("AddGeometryColumn() error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  goto abort;
      }


/*
and finally we'll enable this geo-column to have a Spatial Index based on R*Tree
*/
    strcpy (sql, "SELECT CreateSpatialIndex('test', 'geom')");
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
/* an error occurred */
	  printf ("CreateSpatialIndex() error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  goto abort;
      }

    printf
	("\nnow we are going to insert 1 million POINTs; wait, please ...\n\n");

    t0 = clock ();
/*
beginning a transaction

*** this step is absolutely critical ***

the SQLite engine is a TRANSACTIONAL one
the whole batch of INSERTs has to be performed as an unique transaction,
otherwise performance will be surely very poor
*/
    strcpy (sql, "BEGIN");
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
/* an error occurred */
	  printf ("BEGIN error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  goto abort;
      }



/* 
preparing to populate the test table
we'll use a Prepared Statement we can reuse in order to insert each row
*/
    strcpy (sql, "INSERT INTO test (pk, geom) VALUES (?, ?)");
    ret = sqlite3_prepare_v2 (handle, sql, strlen (sql), &stmt, NULL);
    if (ret != SQLITE_OK)
      {
/* an error occurred */
	  printf ("INSERT SQL error: %s\n", sqlite3_errmsg (handle));
	  goto abort;
      }

    pk = 0;
    for (ix = 0; ix < 1000; ix++)
      {
	  x = 1000000.0 + (ix * 10.0);
	  for (iy = 0; iy < 1000; iy++)
	    {
/* this double loop will insert 1 million rows into the the test table */

		y = 4000000.0 + (iy * 10.0);
		pk++;
		if ((pk % 25000) == 0)
		  {
		      t1 = clock ();
		      printf ("insert row: %d\t\t[elapsed time: %1.3f]\n",
			      pk, (double) (t1 - t0) / CLOCKS_PER_SEC);
		  }

/* preparing the geometry to insert */
		geo = gaiaAllocGeomColl ();
		geo->Srid = 3003;
		gaiaAddPointToGeomColl (geo, x, y);

/* transforming this geometry into the SpatiaLite BLOB format */
		gaiaToSpatiaLiteBlobWkb (geo, &blob, &blob_size);

/* we can now destroy the geometry object */
		gaiaFreeGeomColl (geo);

/* resetting Prepared Statement and bindings */
		sqlite3_reset (stmt);
		sqlite3_clear_bindings (stmt);

/* binding parameters to Prepared Statement */
		sqlite3_bind_int64 (stmt, 1, pk);
		sqlite3_bind_blob (stmt, 2, blob, blob_size, free);

/* performing actual row insert */
		ret = sqlite3_step (stmt);
		if (ret == SQLITE_DONE || ret == SQLITE_ROW)
		    ;
		else
		  {
/* an unexpected error occurred */
		      printf ("sqlite3_step() error: %s\n",
			      sqlite3_errmsg (handle));
		      sqlite3_finalize (stmt);
		      goto abort;
		  }

	    }
      }
/* we have now to finalize the query [memory cleanup] */
    sqlite3_finalize (stmt);



/*
committing the transaction

*** this step is absolutely critical ***

if we don't confirm the still pending transaction,
any update will be lost
*/
    strcpy (sql, "COMMIT");
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
/* an error occurred */
	  printf ("COMMIT error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  goto abort;
      }



/*
now we'll optimize the table
*/
    strcpy (sql, "ANALYZE test");
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
/* an error occurred */
	  printf ("ANALYZE error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  goto abort;
      }


    for (ix = 0; ix < 3; ix++)
      {
	  printf ("\nperforming test#%d - not using Spatial Index\n", ix);
/* 
now we'll perform the spatial query WITHOUT using the Spatial Index
we'll loop 3 times in order to avoid buffering-caching side effects
*/
	  strcpy (sql, "SELECT Count(*) FROM test ");
	  strcat (sql, "WHERE MbrWithin(geom, BuildMbr(");
	  strcat (sql, "1000400.5, 4000400.5, ");
	  strcat (sql, "1000450.5, 4000450.5))");
	  t0 = clock ();
	  ret = sqlite3_get_table (handle, sql, &results, &n_rows, &n_columns,
				   &err_msg);
	  if (ret != SQLITE_OK)
	    {
/* an error occurred */
		printf ("NoSpatialIndex SQL error: %s\n", err_msg);
		sqlite3_free (err_msg);
		goto abort;
	    }
	  count = "";
	  for (i = 1; i <= n_rows; i++)
	    {
		count = results[(i * n_columns) + 0];
	    }
	  t1 = clock ();
	  printf ("Count(*) = %d\t\t[elapsed time: %1.4f]\n", atoi (count),
		  (double) (t1 - t0) / CLOCKS_PER_SEC);
/* we can now free the table results */
	  sqlite3_free_table (results);
      }


    for (ix = 0; ix < 3; ix++)
      {
	  printf ("\nperforming test#%d - using the R*Tree Spatial Index\n",
		  ix);
/* 
now we'll perform the spatial query USING the R*Tree Spatial Index
we'll loop 3 times in order to avoid buffering-caching side effects
*/
	  strcpy (sql, "SELECT Count(*) FROM test ");
	  strcat (sql, "WHERE MbrWithin(geom, BuildMbr(");
	  strcat (sql, "1000400.5, 4000400.5, ");
	  strcat (sql, "1000450.5, 4000450.5)) AND ROWID IN (");
	  strcat (sql, "SELECT pkid FROM idx_test_geom WHERE ");
	  strcat (sql, "xmin > 1000400.5 AND ");
	  strcat (sql, "xmax < 1000450.5 AND ");
	  strcat (sql, "ymin > 4000400.5 AND ");
	  strcat (sql, "ymax < 4000450.5)");
/*
YES, this query is a very unhappy one
the idea is simply to simulate exactly the same conditions as above
*/
	  t0 = clock ();
	  ret = sqlite3_get_table (handle, sql, &results, &n_rows, &n_columns,
				   &err_msg);
	  if (ret != SQLITE_OK)
	    {
/* an error occurred */
		printf ("SpatialIndex SQL error: %s\n", err_msg);
		sqlite3_free (err_msg);
		goto abort;
	    }
	  count = "";
	  for (i = 1; i <= n_rows; i++)
	    {
		count = results[(i * n_columns) + 0];
	    }
	  t1 = clock ();
	  printf ("Count(*) = %d\t\t[elapsed time: %1.4f]\n", atoi (count),
		  (double) (t1 - t0) / CLOCKS_PER_SEC);
/* we can now free the table results */
	  sqlite3_free_table (results);
      }


/* disconnecting the test DB */
    ret = sqlite3_close (handle);
    if (ret != SQLITE_OK)
      {
	  printf ("close() error: %s\n", sqlite3_errmsg (handle));
	  return -1;
      }
    spatialite_cleanup_ex (cache);
    printf ("\n\nsample successfully terminated\n");
    return 0;

  abort:
    sqlite3_close (handle);
    spatialite_cleanup_ex (cache);
    spatialite_shutdown();
    return -1;
}
예제 #21
0
int main (int argc, char *argv[])
{
#ifndef OMIT_ICONV	/* only if ICONV is supported */
    int ret;
    sqlite3 *handle;
    char *dumpname = __FILE__"dump";
    char *err_msg = NULL;
    int row_count;
    void *cache = spatialite_alloc_connection();

    if (argc > 1 || argv[0] == NULL)
	argc = 1;		/* silencing stupid compiler warnings */

    ret = sqlite3_open_v2 (":memory:", &handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    if (ret != SQLITE_OK) {
	fprintf(stderr, "cannot open in-memory database: %s\n", sqlite3_errmsg (handle));
	sqlite3_close(handle);
	return -1;
    }

    spatialite_init_ex (handle, cache, 0);
    
    ret = sqlite3_exec (handle, "SELECT InitSpatialMetadata(1)", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "InitSpatialMetadata() error: %s\n", err_msg);
	sqlite3_free(err_msg);
	sqlite3_close(handle);
	return -2;
    }
    
    ret = load_shapefile (handle, "./shp/merano-3d/points", "points", "CP1252", 25832, 
			  "col1", 0, 0, 1, 0, &row_count, err_msg);
    if (!ret) {
        fprintf (stderr, "load_shapefile() error for shp/merano-3d/points: %s\n", err_msg);
	sqlite3_close(handle);
	return -3;
    }
    if (row_count != 20) {
	fprintf (stderr, "unexpected row count for shp/merano-3d/points: %i\n", row_count);
	sqlite3_close(handle);
	return -4;
    }

    ret = load_shapefile (handle, "./shp/merano-3d/polygons", "polygons", "CP1252", 25832, 
			  "col1", 0, 0, 1, 0, &row_count, err_msg);
    if (!ret) {
        fprintf (stderr, "load_shapefile() error for shp/merano-3d/polygons: %s\n", err_msg);
	sqlite3_close(handle);
	return -5;
    }
    if (row_count != 10) {
	fprintf (stderr, "unexpected row count for shp/merano-3d/polygons: %i\n", row_count);
	sqlite3_close(handle);
	return -6;
    }

    ret = load_shapefile (handle, "./shp/merano-3d/roads", "roads", "CP1252", 25832, 
			  "col1", 0, 0, 1, 0, &row_count, err_msg);
    if (!ret) {
        fprintf (stderr, "load_shapefile() error for shp/merano-3d/roads: %s\n", err_msg);
	sqlite3_close(handle);
	return -7;
    }
    if (row_count != 18) {
	fprintf (stderr, "unexpected row count for shp/merano-3d/roads: %i\n", row_count);
	sqlite3_close(handle);
	return -8;
    }

    ret = dump_shapefile (handle, "roads", "col1", dumpname, "CP1252", "LINESTRING", 1, &row_count, err_msg);
    if (!ret) {
        fprintf (stderr, "dump_shapefile() error for 3d roads: %s\n", err_msg);
	sqlite3_close(handle);
	return -9;
    }
    cleanup_shapefile(dumpname);
    if (row_count != 18) {
	fprintf (stderr, "unexpected row count for 3d roads: %i\n", row_count);
	sqlite3_close(handle);
	return -10;
    }

    ret = dump_shapefile (handle, "polygons", "col1", dumpname, "CP1252", "POLYGON", 1, &row_count, err_msg);
    if (!ret) {
        fprintf (stderr, "dump_shapefile() error for 3d polygons: %s\n", err_msg);
	sqlite3_close(handle);
	return -11;
    }
    cleanup_shapefile(dumpname);
    if (row_count != 10) {
	fprintf (stderr, "unexpected row count for 3d polygons: %i\n", row_count);
	sqlite3_close(handle);
	return -12;
    }

    ret = dump_shapefile (handle, "points", "col1", dumpname, "CP1252", "POINT", 1, &row_count, err_msg);
    if (!ret) {
        fprintf (stderr, "dump_shapefile() error for 3d points: %s\n", err_msg);
	sqlite3_close(handle);
	return -13;
    }
    cleanup_shapefile(dumpname);
    if (row_count != 20) {
	fprintf (stderr, "unexpected row count for 3d points: %i\n", row_count);
	sqlite3_close(handle);
	return -14;
    }

    ret = sqlite3_close (handle);
    if (ret != SQLITE_OK) {
        fprintf (stderr, "sqlite3_close() error: %s\n", sqlite3_errmsg (handle));
	return -15;
    }
    
    spatialite_cleanup_ex (cache);
#endif	/* end ICONV conditional */
    
    return 0;
}
예제 #22
0
int
main (int argc, char *argv[])
{
#ifndef OMIT_FREEXL		/* only if FreeXL is supported */
    int ret;
    sqlite3 *handle;
    char *err_msg = NULL;
    unsigned int row_count;
    int rcnt;
    void *cache = spatialite_alloc_connection ();

    if (argc > 1 || argv[0] == NULL)
	argc = 1;		/* silencing stupid compiler warnings */

    ret =
	sqlite3_open_v2 (":memory:", &handle,
			 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "cannot open in-memory db: %s\n",
		   sqlite3_errmsg (handle));
	  sqlite3_close (handle);
	  return -1;
      }

    spatialite_init_ex (handle, cache, 0);

    ret =
	sqlite3_exec (handle, "SELECT InitSpatialMetadata(1)", NULL, NULL,
		      &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "InitSpatialMetadata() error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  sqlite3_close (handle);
	  return -2;
      }

    ret =
	load_XL (handle, "./testcase1.xls", "test1", 0, 0, &row_count, err_msg);
    if (!ret)
      {
	  fprintf (stderr, "load_XL() error: %s\n", err_msg);
	  sqlite3_close (handle);
	  return -3;
      }
    if (row_count != 17)
      {
	  fprintf (stderr, "load_XL() unexpected row count: %u\n", row_count);
	  sqlite3_close (handle);
	  return -4;
      }

    ret =
	load_XL (handle, "./testcase1.xls", "test2", 1, 1, &row_count, err_msg);
    if (!ret)
      {
	  fprintf (stderr, "load_XL() error sheet 2: %s\n", err_msg);
	  sqlite3_close (handle);
	  return -5;
      }
    if (row_count != 19)
      {
	  fprintf (stderr, "load_XL() unexpected row count sheet 2: %u\n",
		   row_count);
	  sqlite3_close (handle);
	  return -6;
      }

    check_duplicated_rows (handle, "test1", &rcnt);
    if (rcnt != 0)
      {
	  fprintf (stderr,
		   "check_duplicated_rows() unexpected duplicate count: %d\n",
		   rcnt);
	  sqlite3_close (handle);
	  return -8;
      }

    check_duplicated_rows (handle, "test2", &rcnt);
    if (rcnt != 2)
      {
	  fprintf (stderr,
		   "check_duplicated_rows() unexpected duplicate count sheet 2: %d\n",
		   rcnt);
	  sqlite3_close (handle);
	  return -10;
      }

    remove_duplicated_rows (handle, "test1");

    remove_duplicated_rows (handle, "test2");

    ret = sqlite3_close (handle);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "sqlite3_close() error: %s\n",
		   sqlite3_errmsg (handle));
	  return -11;
      }

    spatialite_cleanup_ex (cache);
#endif /* end FreeXL conditional */

    spatialite_shutdown ();
    return 0;
}
예제 #23
0
int main (int argc, char *argv[])
{
#ifndef OMIT_ICONV	/* only if ICONV is supported */
    sqlite3 *db_handle = NULL;
    char *sql_statement;
    int ret;
    char *err_msg = NULL;
    char **results;
    int rows;
    int columns;
    void *cache = spatialite_alloc_connection();

    if (argc > 1 || argv[0] == NULL)
	argc = 1;		/* silencing stupid compiler warnings */

    ret = sqlite3_open_v2 (":memory:", &db_handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "cannot open in-memory db: %s\n", sqlite3_errmsg (db_handle));
	sqlite3_close (db_handle);
	db_handle = NULL;
	return -1;
    }

    spatialite_init_ex (db_handle, cache, 0);
    
    ret = sqlite3_exec (db_handle, "create VIRTUAL TABLE dbftest USING VirtualDBF(shapetest1.dbf, UTF-8);", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "VirtualDBF error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -2;
    }

    asprintf(&sql_statement, "select testcase1, testcase2 from dbftest where testcase2 < 20;");
    ret = sqlite3_get_table (db_handle, sql_statement, &results, &rows, &columns, &err_msg);
    free(sql_statement);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "Error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -3;
    }
    if ((rows != 1) || (columns != 2)) {
	fprintf (stderr, "Unexpected error: select columns bad result: %i/%i.\n", rows, columns);
	return  -4;
    }
    if (strcmp(results[0], "testcase1") != 0) {
	fprintf (stderr, "Unexpected error: header() bad result: %s.\n", results[0]);
	return  -5;
    }
    if (strcmp(results[2], "windward") != 0) {
	fprintf (stderr, "Unexpected error: windward bad result: %s.\n", results[2]);
	return  -6;
    }
    if (strcmp(results[3], "2") != 0) {
	fprintf (stderr, "Unexpected error: integer() bad result: %s.\n", results[3]);
	return  -7;
    }
    sqlite3_free_table (results);

    asprintf(&sql_statement, "select testcase1, testcase2 from dbftest where testcase2 <= 19;");
    ret = sqlite3_get_table (db_handle, sql_statement, &results, &rows, &columns, &err_msg);
    free(sql_statement);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "Error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -10;
    }
    if ((rows != 1) || (columns != 2)) {
	fprintf (stderr, "Unexpected error: select columns bad result: %i/%i.\n", rows, columns);
	return  -11;
    }
    if (strcmp(results[0], "testcase1") != 0) {
	fprintf (stderr, "Unexpected error: header() bad result: %s.\n", results[0]);
	return  -12;
    }
    if (strcmp(results[2], "windward") != 0) {
	fprintf (stderr, "Unexpected error: windward bad result: %s.\n", results[2]);
	return  -13;
    }
    if (strcmp(results[3], "2") != 0) {
	fprintf (stderr, "Unexpected error: integer() bad result: %s.\n", results[3]);
	return  -14;
    }
    sqlite3_free_table (results);

    asprintf(&sql_statement, "select testcase1, testcase2 from dbftest where testcase2 = 20;");
    ret = sqlite3_get_table (db_handle, sql_statement, &results, &rows, &columns, &err_msg);
    free(sql_statement);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "Error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -16;
    }
    if ((rows != 1) || (columns != 2)) {
	fprintf (stderr, "Unexpected error: select columns bad result: %i/%i.\n", rows, columns);
	return  -17;
    }
    if (strcmp(results[0], "testcase1") != 0) {
	fprintf (stderr, "Unexpected error: header() bad result: %s.\n", results[0]);
	return  -18;
    }
    if (strcmp(results[2], "orde lees") != 0) {
	fprintf (stderr, "Unexpected error: orde lees bad result: %s.\n", results[2]);
	return  -19;
    }
    if (strcmp(results[3], "20") != 0) {
	fprintf (stderr, "Unexpected error: integer2() bad result: %s.\n", results[3]);
	return  -20;
    }
    sqlite3_free_table (results);

    asprintf(&sql_statement, "select testcase1, testcase2 from dbftest where testcase2 > 2;");
    ret = sqlite3_get_table (db_handle, sql_statement, &results, &rows, &columns, &err_msg);
    free(sql_statement);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "Error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -22;
    }
    if ((rows != 1) || (columns != 2)) {
	fprintf (stderr, "Unexpected error: select columns bad result: %i/%i.\n", rows, columns);
	return  -23;
    }
    if (strcmp(results[0], "testcase1") != 0) {
	fprintf (stderr, "Unexpected error: header() bad result: %s.\n", results[0]);
	return  -24;
    }
    if (strcmp(results[2], "orde lees") != 0) {
	fprintf (stderr, "Unexpected error: orde lees2 bad result: %s.\n", results[2]);
	return  -25;
    }
    if (strcmp(results[3], "20") != 0) {
	fprintf (stderr, "Unexpected error: integer4() bad result: %s.\n", results[3]);
	return  -26;
    }
    sqlite3_free_table (results);

    asprintf(&sql_statement, "select testcase1, testcase2 from dbftest where testcase2 >= 20;");
    ret = sqlite3_get_table (db_handle, sql_statement, &results, &rows, &columns, &err_msg);
    free(sql_statement);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "Error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -28;
    }
    if ((rows != 1) || (columns != 2)) {
	fprintf (stderr, "Unexpected error: select columns bad result: %i/%i.\n", rows, columns);
	return  -29;
    }
    if (strcmp(results[0], "testcase1") != 0) {
	fprintf (stderr, "Unexpected error: header() bad result: %s.\n", results[0]);
	return  -30;
    }
    if (strcmp(results[2], "orde lees") != 0) {
	fprintf (stderr, "Unexpected error: orde lees3 bad result: %s.\n", results[2]);
	return  -31;
    }
    if (strcmp(results[3], "20") != 0) {
	fprintf (stderr, "Unexpected error: integer5() bad result: %s.\n", results[3]);
	return  -32;
    }
    sqlite3_free_table (results);

    asprintf(&sql_statement, "select testcase1, testcase2 from dbftest where testcase1 < \"p\";");
    ret = sqlite3_get_table (db_handle, sql_statement, &results, &rows, &columns, &err_msg);
    free(sql_statement);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "Error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -34;
    }
    if ((rows != 1) || (columns != 2)) {
	fprintf (stderr, "Unexpected error: select columns bad result: %i/%i.\n", rows, columns);
	return  -35;
    }
    if (strcmp(results[0], "testcase1") != 0) {
	fprintf (stderr, "Unexpected error: header() bad result: %s.\n", results[0]);
	return  -36;
    }
    if (strcmp(results[2], "orde lees") != 0) {
	fprintf (stderr, "Unexpected error: orde lees bad result: %s.\n", results[2]);
	return  -37;
    }
    if (strcmp(results[3], "20") != 0) {
	fprintf (stderr, "Unexpected error: integer() bad result: %s.\n", results[3]);
	return  -38;
    }
    sqlite3_free_table (results);

    asprintf(&sql_statement, "select testcase1, testcase2 from dbftest where testcase1 <= \"p\";");
    ret = sqlite3_get_table (db_handle, sql_statement, &results, &rows, &columns, &err_msg);
    free(sql_statement);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "Error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -40;
    }
    if ((rows != 1) || (columns != 2)) {
	fprintf (stderr, "Unexpected error: select columns bad result: %i/%i.\n", rows, columns);
	return  -41;
    }
    if (strcmp(results[0], "testcase1") != 0) {
	fprintf (stderr, "Unexpected error: header() bad result: %s.\n", results[0]);
	return  -42;
    }
    if (strcmp(results[2], "orde lees") != 0) {
	fprintf (stderr, "Unexpected error: orde lees bad result: %s.\n", results[2]);
	return  -43;
    }
    if (strcmp(results[3], "20") != 0) {
	fprintf (stderr, "Unexpected error: integer() bad result: %s.\n", results[3]);
	return  -44;
    }
    sqlite3_free_table (results);
    
    ret = sqlite3_exec (db_handle, "BEGIN;", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "BEGIN error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -46;
    }

    asprintf(&sql_statement, "select testcase1, testcase2 from dbftest where testcase1 > \"p\";");
    ret = sqlite3_get_table (db_handle, sql_statement, &results, &rows, &columns, &err_msg);
    free(sql_statement);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "Error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -48;
    }
    if ((rows != 1) || (columns != 2)) {
	fprintf (stderr, "Unexpected error: select columns bad result: %i/%i.\n", rows, columns);
	return  -49;
    }
    if (strcmp(results[0], "testcase1") != 0) {
	fprintf (stderr, "Unexpected error: header() bad result: %s.\n", results[0]);
	return  -50;
    }
    if (strcmp(results[2], "windward") != 0) {
	fprintf (stderr, "Unexpected error: windward bad result: %s.\n", results[2]);
	return  -51;
    }
    if (strcmp(results[3], "2") != 0) {
	fprintf (stderr, "Unexpected error: integer() bad result: %s.\n", results[3]);
	return  -52;
    }
    sqlite3_free_table (results);

    ret = sqlite3_exec (db_handle, "DELETE FROM dbftest WHERE testcase2 = 2;", NULL, NULL, &err_msg);
    if (ret != SQLITE_READONLY) {
	fprintf (stderr, "UPDATE error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -46;
    }
    sqlite3_free (err_msg);

    ret = sqlite3_exec (db_handle, "ROLLBACK;", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "ROLLBACK error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -47;
    }

    asprintf(&sql_statement, "select testcase1, testcase2 from dbftest where testcase1 >= \"p\";");
    ret = sqlite3_get_table (db_handle, sql_statement, &results, &rows, &columns, &err_msg);
    free(sql_statement);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "Error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -54;
    }
    if ((rows != 1) || (columns != 2)) {
	fprintf (stderr, "Unexpected error: select columns bad result: %i/%i.\n", rows, columns);
	return  -55;
    }
    if (strcmp(results[0], "testcase1") != 0) {
	fprintf (stderr, "Unexpected error: header() bad result: %s.\n", results[0]);
	return  -56;
    }
    if (strcmp(results[2], "windward") != 0) {
	fprintf (stderr, "Unexpected error: windward bad result: %s.\n", results[2]);
	return  -57;
    }
    if (strcmp(results[3], "2") != 0) {
	fprintf (stderr, "Unexpected error: integer() bad result: %s.\n", results[3]);
	return  -58;
    }
    sqlite3_free_table (results);

    asprintf(&sql_statement, "select testcase1, testcase2 from dbftest where testcase1 = \"windward\";");
    ret = sqlite3_get_table (db_handle, sql_statement, &results, &rows, &columns, &err_msg);
    free(sql_statement);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "Error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -54;
    }
    if ((rows != 1) || (columns != 2)) {
	fprintf (stderr, "Unexpected error: select columns bad result: %i/%i.\n", rows, columns);
	return  -55;
    }
    if (strcmp(results[0], "testcase1") != 0) {
	fprintf (stderr, "Unexpected error: header() bad result: %s.\n", results[0]);
	return  -56;
    }
    if (strcmp(results[2], "windward") != 0) {
	fprintf (stderr, "Unexpected error: windward bad result: %s.\n", results[2]);
	return  -57;
    }
    if (strcmp(results[3], "2") != 0) {
	fprintf (stderr, "Unexpected error: integer() bad result: %s.\n", results[3]);
	return  -58;
    }
    sqlite3_free_table (results);

    asprintf(&sql_statement, "select testcase1, testcase2 from dbftest where PKUID = 1;");
    ret = sqlite3_get_table (db_handle, sql_statement, &results, &rows, &columns, &err_msg);
    free(sql_statement);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "Error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -60;
    }
    if ((rows != 1) || (columns != 2)) {
	fprintf (stderr, "Unexpected error: select columns bad result: %i/%i.\n", rows, columns);
	return  -61;
    }
    if (strcmp(results[0], "testcase1") != 0) {
	fprintf (stderr, "Unexpected error: header() bad result: %s.\n", results[0]);
	return  -62;
    }
    if (strcmp(results[2], "windward") != 0) {
	fprintf (stderr, "Unexpected error: windward bad result: %s.\n", results[2]);
	return  -63;
    }
    if (strcmp(results[3], "2") != 0) {
	fprintf (stderr, "Unexpected error: integer() bad result: %s.\n", results[3]);
	return  -64;
    }
    sqlite3_free_table (results);

    asprintf(&sql_statement, "select testcase1, testcase2 from dbftest where PKUID < 2;");
    ret = sqlite3_get_table (db_handle, sql_statement, &results, &rows, &columns, &err_msg);
    free(sql_statement);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "Error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -66;
    }
    if ((rows != 1) || (columns != 2)) {
	fprintf (stderr, "Unexpected error: select columns bad result: %i/%i.\n", rows, columns);
	return  -67;
    }
    if (strcmp(results[0], "testcase1") != 0) {
	fprintf (stderr, "Unexpected error: header() bad result: %s.\n", results[0]);
	return  -68;
    }
    if (strcmp(results[2], "windward") != 0) {
	fprintf (stderr, "Unexpected error: windward bad result: %s.\n", results[2]);
	return  -69;
    }
    if (strcmp(results[3], "2") != 0) {
	fprintf (stderr, "Unexpected error: integer() bad result: %s.\n", results[3]);
	return  -70;
    }
    sqlite3_free_table (results);

    asprintf(&sql_statement, "select testcase1, testcase2 from dbftest where PKUID <= 1;");
    ret = sqlite3_get_table (db_handle, sql_statement, &results, &rows, &columns, &err_msg);
    free(sql_statement);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "Error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -72;
    }
    if ((rows != 1) || (columns != 2)) {
	fprintf (stderr, "Unexpected error: select columns bad result: %i/%i.\n", rows, columns);
	return  -73;
    }
    if (strcmp(results[0], "testcase1") != 0) {
	fprintf (stderr, "Unexpected error: header() bad result: %s.\n", results[0]);
	return  -74;
    }
    if (strcmp(results[2], "windward") != 0) {
	fprintf (stderr, "Unexpected error: windward bad result: %s.\n", results[2]);
	return  -75;
    }
    if (strcmp(results[3], "2") != 0) {
	fprintf (stderr, "Unexpected error: integer() bad result: %s.\n", results[3]);
	return  -76;
    }
    sqlite3_free_table (results);
    
    asprintf(&sql_statement, "select testcase1, testcase2 from dbftest where PKUID > 1;");
    ret = sqlite3_get_table (db_handle, sql_statement, &results, &rows, &columns, &err_msg);
    free(sql_statement);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "Error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -78;
    }
    if ((rows != 1) || (columns != 2)) {
	fprintf (stderr, "Unexpected error: select columns bad result: %i/%i.\n", rows, columns);
	return  -79;
    }
    if (strcmp(results[0], "testcase1") != 0) {
	fprintf (stderr, "Unexpected error: header() bad result: %s.\n", results[0]);
	return  -80;
    }
    if (strcmp(results[2], "orde lees") != 0) {
	fprintf (stderr, "Unexpected error: orde lees bad result: %s.\n", results[2]);
	return  -81;
    }
    if (strcmp(results[3], "20") != 0) {
	fprintf (stderr, "Unexpected error: integer() bad result: %s.\n", results[3]);
	return  -82;
    }
    sqlite3_free_table (results);

    asprintf(&sql_statement, "select testcase1, testcase2 from dbftest where PKUID >= 2;");
    ret = sqlite3_get_table (db_handle, sql_statement, &results, &rows, &columns, &err_msg);
    free(sql_statement);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "Error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -84;
    }
    if ((rows != 1) || (columns != 2)) {
	fprintf (stderr, "Unexpected error: select columns bad result: %i/%i.\n", rows, columns);
	return  -85;
    }
    if (strcmp(results[0], "testcase1") != 0) {
	fprintf (stderr, "Unexpected error: header() bad result: %s.\n", results[0]);
	return  -86;
    }
    if (strcmp(results[2], "orde lees") != 0) {
	fprintf (stderr, "Unexpected error: orde lees bad result: %s.\n", results[2]);
	return  -87;
    }
    if (strcmp(results[3], "20") != 0) {
	fprintf (stderr, "Unexpected error: integer() bad result: %s.\n", results[3]);
	return  -88;
    }
    sqlite3_free_table (results);

    asprintf(&sql_statement, "select PKUID, testcase1, testcase2 from dbftest where testcase1 LIKE \"wind%%\";");
    ret = sqlite3_get_table (db_handle, sql_statement, &results, &rows, &columns, &err_msg);
    free(sql_statement);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "Error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -90;
    }
    if ((rows != 1) || (columns != 3)) {
	fprintf (stderr, "Unexpected error: select columns bad result: %i/%i.\n", rows, columns);
	return  -91;
    }
    if (strcmp(results[0], "PKUID") != 0) {
	fprintf (stderr, "Unexpected error: header uid bad result: %s.\n", results[0]);
	return  -92;
    }
    if (strcmp(results[1], "testcase1") != 0) {
	fprintf (stderr, "Unexpected error: header bad result: %s.\n", results[1]);
	return  -93;
    }
    if (strcmp(results[3], "1") != 0) {
	fprintf (stderr, "Unexpected error: windward PK bad result: %s.\n", results[3]);
	return  -93;
    }
    if (strcmp(results[4], "windward") != 0) {
	fprintf (stderr, "Unexpected error: windward bad result: %s.\n", results[4]);
	return  -94;
    }
    sqlite3_free_table (results);

    ret = sqlite3_exec (db_handle, "DROP TABLE dbftest;", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "DROP TABLE error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -49;
    }

    /* error cases */
    ret = sqlite3_exec (db_handle, "create VIRTUAL TABLE toofewargs USING VirtualDBF(\"shapetest1.dbf\");", NULL, NULL, &err_msg);
    if (ret != SQLITE_ERROR) {
	fprintf (stderr, "VirtualDBF unexpected result: %i\n", ret);
	return -95;
    }
    sqlite3_free (err_msg);

    ret = sqlite3_exec (db_handle, "create VIRTUAL TABLE toomanyargs USING VirtualDBF(\"shapetest1.dbf\", UTF-8, 1);", NULL, NULL, &err_msg);
    if (ret != SQLITE_ERROR) {
	fprintf (stderr, "VirtualDBF unexpected result: %i\n", ret);
	return -96;
    }
    sqlite3_free (err_msg);

    ret = sqlite3_exec (db_handle, "create VIRTUAL TABLE nosuchfile USING VirtualDBF(\"not_a_file.dbf\", UTF-8);", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "VirtualDBF error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -97;
    }
    ret = sqlite3_get_table (db_handle, "SELECT * from nosuchfile;", &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "Error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -98;
    }
    if ((rows != 0) || (columns != 0)) {
	fprintf (stderr, "Unexpected error: select columns no suchfile: %i/%i.\n", rows, columns);
	return  -99;
    }
    sqlite3_free_table (results);
    ret = sqlite3_exec (db_handle, "DROP TABLE nosuchfile;", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "DROP TABLE error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -100;
    }

    ret = sqlite3_exec (db_handle, "create VIRTUAL TABLE onesidedquote USING VirtualDBF('shapetest1.dbf, UTF-8);", NULL, NULL, &err_msg);
    if (ret != SQLITE_ERROR) {
	fprintf (stderr, "VirtualDBF unexpected result: %i\n", ret);
	return -101;
    }
    sqlite3_free (err_msg);

    sqlite3_close (db_handle);
    spatialite_cleanup_ex (cache);
#endif	/* end ICONV conditional */
    
    return 0;
}
예제 #24
0
int main (int argc, char *argv[])
{
    int ret;
    sqlite3 *handle;
    char *err_msg = NULL;
    const char *sql;
    char **results;
    int rows;
    int columns;
    void *cache = spatialite_alloc_connection();

    if (argc > 1 || argv[0] == NULL)
	argc = 1;		/* silencing stupid compiler warnings */

    ret = sqlite3_open_v2 (":memory:", &handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    if (ret != SQLITE_OK) {
	fprintf(stderr, "cannot open in-memory database: %s\n", sqlite3_errmsg (handle));
	sqlite3_close(handle);
	return -1;
    }

    spatialite_init_ex (handle, cache, 0);

/* FDO initialization */
    sql = "SELECT InitFDOSpatialMetadata()";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -2;
    }

/* creating a Point 2D WKT table */
    sql = "CREATE TABLE pt_2d_wkt (id INTEGER, name TEXT, value DOUBLE)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -3;
    }
    sql = "SELECT AddFDOGeometryColumn('pt_2d_wkt', 'g', -1, 1, 2, 'WKT')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -4;
    }

/* creating a Point 3D WKT table */
    sql = "CREATE TABLE pt_3d_wkt (id INTEGER, pic1 BLOB, pic2 BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -5;
    } 
    sql = "SELECT AddFDOGeometryColumn('pt_3d_wkt', 'g', -1, 1, 3, 'WKT')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -6;
    }

/* creating a Point 2D WKB table */
    sql = "CREATE TABLE pt_2d_wkb (id INTEGER)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -6;
    }
    sql = "SELECT AddFDOGeometryColumn('pt_2d_wkb', 'g', -1, 1, 2, 'WKB')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -7;
    }

/* creating a Point 3D WKB table */
    sql = "CREATE TABLE pt_3d_wkb (id INTEGER)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -8;
    } 
    sql = "SELECT AddFDOGeometryColumn('pt_3d_wkb', 'g', -1, 1, 3, 'WKB')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -9;
    }

/* creating a Point 3D WKB table */
    sql = "CREATE TABLE pt_3d_spl (id INTEGER)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -10;
    } 
    sql = "SELECT AddFDOGeometryColumn('pt_3d_spl', 'g', -1, 1, 3, 'SPATIALITE')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -11;
    }

/* creating a Linestring 3D WKT table */
    sql = "CREATE TABLE ln_3d_wkt (id INTEGER)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -12;
    } 
    sql = "SELECT AddFDOGeometryColumn('ln_3d_wkt', 'g', -1, 2, 3, 'WKT')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -13;
    }

/* creating a Linestring 3D WKB table */
    sql = "CREATE TABLE ln_3d_wkb (id INTEGER)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -14;
    } 
    sql = "SELECT AddFDOGeometryColumn('ln_3d_wkb', 'g', -1, 2, 3, 'WKB')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -15;
    }

/* creating a Polygon 3D WKT table */
    sql = "CREATE TABLE pg_3d_wkt (id INTEGER)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -16;
    } 
    sql = "SELECT AddFDOGeometryColumn('pg_3d_wkt', 'g', -1, 3, 3, 'WKT')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -17;
    }

/* creating a Polygon 3D WKB table */
    sql = "CREATE TABLE pg_3d_wkb (id INTEGER)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -18;
    } 
    sql = "SELECT AddFDOGeometryColumn('pg_3d_wkb', 'g', -1, 3, 3, 'WKB')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -19;
    }

/* creating a MultiPoint 3D WKT table */
    sql = "CREATE TABLE mpt_3d_wkt (id INTEGER)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -20;
    } 
    sql = "SELECT AddFDOGeometryColumn('mpt_3d_wkt', 'g', -1, 4, 3, 'WKT')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -21;
    }

/* creating a MultiPoint 3D WKB table */
    sql = "CREATE TABLE mpt_3d_wkb (id INTEGER)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -22;
    } 
    sql = "SELECT AddFDOGeometryColumn('mpt_3d_wkb', 'g', -1, 4, 3, 'WKB')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -23;
    }

/* creating a MultiLinestring 3D WKT table */
    sql = "CREATE TABLE mln_3d_wkt (id INTEGER)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -24;
    } 
    sql = "SELECT AddFDOGeometryColumn('mln_3d_wkt', 'g', -1, 5, 3, 'WKT')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -25;
    }

/* creating a MultiLinestring 3D WKB table */
    sql = "CREATE TABLE mln_3d_wkb (id INTEGER)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -26;
    } 
    sql = "SELECT AddFDOGeometryColumn('mln_3d_wkb', 'g', -1, 5, 3, 'WKB')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -27;
    }

/* creating a MultiPolygon 3D WKT table */
    sql = "CREATE TABLE mpg_3d_wkt (id INTEGER)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -28;
    } 
    sql = "SELECT AddFDOGeometryColumn('mpg_3d_wkt', 'g', -1, 6, 3, 'WKT')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -29;
    }

/* creating a MultiPolygon 3D WKB table */
    sql = "CREATE TABLE mpg_3d_wkb (id INTEGER)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -30;
    } 
    sql = "SELECT AddFDOGeometryColumn('mpg_3d_wkb', 'g', -1, 6, 3, 'WKB')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -31;
    }

/* creating a GeometryCollection 3D WKT table */
    sql = "CREATE TABLE gcoll_3d_wkt (id INTEGER)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -32;
    } 
    sql = "SELECT AddFDOGeometryColumn('gcoll_3d_wkt', 'g', -1, 7, 3, 'WKT')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -33;
    }

/* creating a GeometryCollection 3D WKB table */
    sql = "CREATE TABLE gcoll_3d_wkb (id INTEGER)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -34;
    } 
    sql = "SELECT AddFDOGeometryColumn('gcoll_3d_wkb', 'g', -1, 7, 3, 'WKB')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -35;
    }

/* FDO start-up */
    sql = "SELECT AutoFDOStart()";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -36;
    }

/* Inserting into pt_2d_wkt */
    sql = "INSERT INTO fdo_pt_2d_wkt (id, name, value, g) VALUES (1, 'alpha', 0.1, GeomFromText('POINT(1 2)', -1))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -37;
    }

/* Updating pt_2d_wkt */
    sql = "UPDATE fdo_pt_2d_wkt SET name = 'beta', value = 0.2, g = GeomFromText('POINT(10 20)', -1) WHERE id = 1";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -38;
    }

/* Deleting form pt_2d_wkt */
    sql = "DELETE FROM fdo_pt_2d_wkt";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -39;
    }

/* Inserting into pt_3d_wkt */
    sql = "INSERT INTO fdo_pt_3d_wkt (id, pic1, pic2, g) VALUES (1, zeroblob(16), NULL, GeomFromText('POINTZ(1 2 3)', -1))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -40;
    }

/* Updating pt_3d_wkt */
    sql = "UPDATE fdo_pt_3d_wkt SET pic1 = NULL, pic2 = zeroblob(8), g = GeomFromText('POINTZ(10 20 30)', -1) WHERE id = 1";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -41;
    }

/* Inserting into pt_2d_wkb */
    sql = "INSERT INTO fdo_pt_2d_wkb (id, g) VALUES (1, GeomFromText('POINT(1 2)', -1))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -42;
    }

/* Updating pt_2d_wkb */
    sql = "UPDATE fdo_pt_2d_wkb SET g = GeomFromText('POINT(10 20)', -1) WHERE id = 1";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -43;
    }

/* Inserting into pt_3d_wkb */
    sql = "INSERT INTO fdo_pt_3d_wkb (id, g) VALUES (1, GeomFromText('POINTZ(1 2 3)', -1))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -44;
    }

/* Updating pt_3d_wkb */
    sql = "UPDATE fdo_pt_3d_wkb SET g = GeomFromText('POINTZ(10 20 30)', -1) WHERE id = 1";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -45;
    }

/* Inserting into pt_3d_spl */
    sql = "INSERT INTO fdo_pt_3d_spl (id, g) VALUES (1, GeomFromText('POINTZ(1 2 3)', -1))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -46;
    }

/* Updating pt_3d_spl */
    sql = "UPDATE fdo_pt_3d_spl SET g = GeomFromText('POINTZ(10 20 30)', -1) WHERE id = 1";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -47;
    }

/* Inserting into ln_3d_wkt */
    sql = "INSERT INTO fdo_ln_3d_wkt (id, g) VALUES (1, GeomFromText('LINESTRINGZ(1 2 3, 4 5 6)', -1))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -48;
    }

/* Inserting into ln_3d_wkb */
    sql = "INSERT INTO fdo_ln_3d_wkb (id, g) VALUES (1, GeomFromText('LINESTRINGZ(1 2 3, 4 5 6)', -1))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -49;
    }

/* Inserting into ln_3d_wkb */
    sql = "INSERT INTO fdo_ln_3d_wkb (id, g) VALUES (2, GeomFromText('LINESTRINGM(1 2 10, 4 5 11)', -1))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -50;
    }

/* Inserting into ln_3d_wkb */
    sql = "INSERT INTO fdo_ln_3d_wkb (id, g) VALUES (3, GeomFromText('LINESTRINGZM(1 2 3 10, 4 5 6 11)', -1))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -51;
    }

/* Inserting into ln_3d_wkb */
    sql = "INSERT INTO fdo_ln_3d_wkb (id, g) VALUES (4, GeomFromText('LINESTRING(1 2, 4 5)', -1))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -52;
    }

/* Inserting into pg_3d_wkt */
    sql = "INSERT INTO fdo_pg_3d_wkt (id, g) VALUES (1, GeomFromText('POLYGONZ((10 10 100, 15 10 101, 15 15 102, 10 15 103, 10 10 100), (11 11 100, 12 11 101, 1 12 102, 11 12 103, 11 11 100))', -1))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -53;
    }

/* Inserting into pg_3d_wkb */
    sql = "INSERT INTO fdo_pg_3d_wkb (id, g) VALUES (1, GeomFromText('POLYGONZ((10 10 100, 15 10 101, 15 15 102, 10 15 103, 10 10 100), (11 11 100, 12 11 101, 1 12 102, 11 12 103, 11 11 100))', -1))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -54;
    }

/* Inserting into pg_3d_wkb */
    sql = "INSERT INTO fdo_pg_3d_wkb (id, g) VALUES (2, GeomFromText('POLYGONZM((10 10 100 10, 15 10 101 11, 15 15 102 12, 10 15 103 13, 10 10 100 10), (11 11 100 10, 12 11 101 11, 1 12 102 12, 11 12 103 13, 11 11 100 10))', -1))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -55;
    }

/* Inserting into pg_3d_wkb */
    sql = "INSERT INTO fdo_pg_3d_wkb (id, g) VALUES (3, GeomFromText('POLYGONM((10 10 10, 15 10 11, 15 15 12, 10 15 13, 10 10 10), (11 11 10, 12 11 11, 1 12 12, 11 12 13, 11 11 10))', -1))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -56;
    }

/* Inserting into pg_3d_wkb */
    sql = "INSERT INTO fdo_pg_3d_wkb (id, g) VALUES (4, GeomFromText('POLYGON((10 10, 15 10, 15 15, 10 15, 10 10), (11 11, 12 11, 1 12, 11 12, 11 11))', -1))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -57;
    }

/* Inserting into mpt_3d_wkt */
    sql = "INSERT INTO fdo_mpt_3d_wkt (id, g) VALUES (1, GeomFromText('MULTIPOINTZ(1 2 3, 4 5 6)', -1))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -58;
    }

/* Inserting into mpt_3d_wkb */
    sql = "INSERT INTO fdo_mpt_3d_wkb (id, g) VALUES (1, GeomFromText('MULTIPOINTZ(1 2 3, 4 5 6)', -1))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -59;
    }

/* Inserting into mln_3d_wkt */
    sql = "INSERT INTO fdo_mln_3d_wkt (id, g) VALUES (1, GeomFromText('MULTILINESTRINGZ((1 2 3, 4 5 6), (7 8 9, 10 11 12))', -1))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -60;
    }

/* Inserting into mln_3d_wkb */
    sql = "INSERT INTO fdo_mln_3d_wkb (id, g) VALUES (1, GeomFromText('MULTILINESTRINGZ((1 2 3, 4 5 6), (7 8 9, 10 11 12))', -1))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -61;
    }

/* Inserting into mpg_3d_wkt */
    sql = "INSERT INTO fdo_mpg_3d_wkt (id, g) VALUES (1, GeomFromText('MULTIPOLYGONZ(((10 10 100, 15 10 101, 15 15 102, 10 15 103, 10 10 100), (11 11 100, 12 11 101, 1 12 102, 11 12 103, 11 11 100)), ((0 0 1, 1 0 2, 1 1 3, 0 1 4, 0 0 1)))', -1))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -62;
    }

/* Inserting into mpg_3d_wkb */
    sql = "INSERT INTO fdo_mpg_3d_wkb (id, g) VALUES (1, GeomFromText('MULTIPOLYGONZ(((10 10 100, 15 10 101, 15 15 102, 10 15 103, 10 10 100), (11 11 100, 12 11 101, 1 12 102, 11 12 103, 11 11 100)), ((0 0 1, 1 0 2, 1 1 3, 0 1 4, 0 0 1)))', -1))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -63;
    }

/* Inserting into gcoll_3d_wkt */
    sql = "INSERT INTO fdo_gcoll_3d_wkt (id, g) VALUES (1, GeomFromText('GEOMETRYCOLLECTIONZ(POINTZ(10 10 100), LINESTRINGZ(5 5 10, 6 6 11), POLYGONZ((0 0 1, 1 0 2, 1 1 3, 0 1 4, 0 0 1)))', -1))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -64;
    }

/* Inserting into gcoll_3d_wkb */
    sql = "INSERT INTO fdo_gcoll_3d_wkb (id, g) VALUES (1, GeomFromText('GEOMETRYCOLLECTIONZ(POINZ(10 10 100), LINESTRINGZ(5 5 10, 6 6 11), POLYGONZ((0 0 1, 1 0 2, 1 1 3, 0 1 4, 0 0 1)))', -1))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -65;
    }

/* checking MultiPoint 3D WKT */
    sql = "SELECT AsText(g) FROM fdo_mpt_3d_wkt";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -66;
    }
    if ((rows != 1) || (columns != 1)) {
      fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows, columns);
      return -67;
    }
    if (results[1] == NULL) {
      fprintf (stderr, "Unexpected error: NULL result\n");
      return -68;
    }
    if (strcmp(results[1], "MULTIPOINT Z(1 2 3, 4 5 6)") != 0) {        
      fprintf (stderr, "Unexpected error: invalid result\n");
      return -69;
    }
    sqlite3_free_table (results);

/* checking MultiLinestring 3D WKT */
    sql = "SELECT AsText(g) FROM fdo_mln_3d_wkt";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -70;
    }
    if ((rows != 1) || (columns != 1)) {
      fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows, columns);
      return -71;
    }
    if (results[1] == NULL) {
      fprintf (stderr, "Unexpected error: NULL result\n");
      return -72;
    }
    if (strcmp(results[1], "MULTILINESTRING Z((1 2 3, 4 5 6), (7 8 9, 10 11 12))") != 0) {        
      fprintf (stderr, "Unexpected error: invalid result\n");
      return -73;
    }
    sqlite3_free_table (results);

/* checking MultiPolygon 3D WKT */
    sql = "SELECT AsText(g) FROM fdo_mpg_3d_wkt";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -74;
    }
    if ((rows != 1) || (columns != 1)) {
      fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows, columns);
      return -75;
    }
    if (results[1] == NULL) {
      fprintf (stderr, "Unexpected error: NULL result\n");
      return -76;
    }
    if (strcmp(results[1], "MULTIPOLYGON Z(((10 10 100, 15 10 101, 15 15 102, 10 15 103, 10 10 100), (11 11 100, 12 11 101, 1 12 102, 11 12 103, 11 11 100)), ((0 0 1, 1 0 2, 1 1 3, 0 1 4, 0 0 1)))") != 0) {        
      fprintf (stderr, "Unexpected error: invalid result\n");
      return -77;
    }
    sqlite3_free_table (results);

/* checking GeometryCollection 3D WKT */
    sql = "SELECT AsText(g) FROM fdo_gcoll_3d_wkt";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -78;
    }
    if ((rows != 1) || (columns != 1)) {
      fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows, columns);
      return -79;
    }
    if (results[1] == NULL) {
      fprintf (stderr, "Unexpected error: NULL result\n");
      return -80;
    }
    if (strcmp(results[1], "GEOMETRYCOLLECTION Z(POINT Z(10 10 100), LINESTRING Z(5 5 10, 6 6 11), POLYGON Z((0 0 1, 1 0 2, 1 1 3, 0 1 4, 0 0 1)))") != 0) {        
      fprintf (stderr, "Unexpected error: invalid result\n");
      return -81;
    }
    sqlite3_free_table (results);

/* dropping an FDO virtual table */
    sql = "DROP TABLE fdo_mpt_3d_wkt";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -82;
    }

/* discarding an FDO Geometry column */
    sql = "SELECT DiscardFDOGeometryColumn('fdo_mpt_3d_wkt', 'g')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -83;
    }
    sql = "SELECT DiscardFDOGeometryColumn(1, 'g')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -84;
    }
    sql = "SELECT DiscardFDOGeometryColumn('mpt_3d_wkt', 2)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -85;
    }

/* recovering an FDO Geometry column */
    sql = "SELECT RecoverFDOGeometryColumn('mpt_3d_wkt', 'g', -1, 4, 3, 'WKT')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -86;
    }

/* FDO shut-down */
    sql = "SELECT AutoFDOStop()";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -66;
    }

    sql = "SELECT AddFDOGeometryColumn(1, 'g', -1, 7, 3, 'WKB')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -67;
    }
    sql = "SELECT AddFDOGeometryColumn('a', 2, -1, 7, 3, 'WKB')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -68;
    }
    sql = "SELECT AddFDOGeometryColumn('a', 'g', -1.5, 7, 3, 'WKB')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -69;
    }
    sql = "SELECT AddFDOGeometryColumn('a', 'g', -1, 'a', 3, 'WKB')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -70;
    }
    sql = "SELECT AddFDOGeometryColumn('a', 'g', -1, 7, 'a', 'WKB')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -71;
    }
    sql = "SELECT AddFDOGeometryColumn('a', 'g', -1, 17, 3, 'WKB')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -72;
    }
    sql = "SELECT AddFDOGeometryColumn('a', 'g', -1, 7, 13, 'WKB')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -73;
    }
    sql = "SELECT AddFDOGeometryColumn('a', 'g', -1, 7, 3, 'DUMMY')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -74;
    }

    sql = "SELECT RecoverFDOGeometryColumn(1, 'g', -1, 7, 3, 'WKB')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -75;
    }
    sql = "SELECT RecoverFDOGeometryColumn('a', 2, -1, 7, 3, 'WKB')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -76;
    }
    sql = "SELECT RecoverFDOGeometryColumn('a', 'g', -1.5, 7, 3, 'WKB')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -77;
    }
    sql = "SELECT RecoverFDOGeometryColumn('a', 'g', -1, 'a', 3, 'WKB')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -78;
    }
    sql = "SELECT RecoverFDOGeometryColumn('a', 'g', -1, 7, 'a', 'WKB')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -79;
    }
    sql = "SELECT RecoverFDOGeometryColumn('a', 'g', -1, 17, 3, 'WKB')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -80;
    }
    sql = "SELECT RecoverFDOGeometryColumn('a', 'g', -1, 7, 13, 'WKB')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -81;
    }
    sql = "SELECT RecoverFDOGeometryColumn('a', 'g', -1, 7, 3, 'DUMMY')";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -82;
    }

    ret = sqlite3_close (handle);
    if (ret != SQLITE_OK) {
        fprintf (stderr, "sqlite3_close() error: %s\n", sqlite3_errmsg (handle));
	return -83;
    }
    
    spatialite_cleanup_ex (cache);
    
    return 0;
}
예제 #25
0
int
main (int argc, char *argv[])
{
    int ret;
    sqlite3 *handle;
    char *err_msg = NULL;
    char **results;
    int rows;
    int columns;
    void *cache = spatialite_alloc_connection ();

    if (argc > 1 || argv[0] == NULL)
	argc = 1;		/* silencing stupid compiler warnings */

    ret =
	sqlite3_open_v2 (":memory:", &handle,
			 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "cannot open in-memory db: %s\n",
		   sqlite3_errmsg (handle));
	  sqlite3_close (handle);
	  return -1;
      }

    spatialite_init_ex (handle, cache, 0);

    ret =
	sqlite3_exec (handle, "SELECT InitSpatialMetadata(\"NONE\")", NULL,
		      NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "InitSpatialMetadata(\"NONE\") error: %s\n",
		   err_msg);
	  sqlite3_free (err_msg);
	  sqlite3_close (handle);
	  return -2;
      }

    ret =
	sqlite3_exec (handle, "SELECT InsertEpsgSrid(4326)", NULL, NULL,
		      &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Insert SRID 4326 error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  sqlite3_close (handle);
	  return -3;
      }

#ifndef OMIT_EPSG
/* only if full EPSG support is enabled */
    ret =
	sqlite3_exec (handle, "SELECT InsertEpsgSrid(2998)", NULL, NULL,
		      &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Insert SRID 2998 error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  sqlite3_close (handle);
	  return -4;
      }
#endif

    ret = sqlite3_close (handle);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "sqlite3_close() error: %s\n",
		   sqlite3_errmsg (handle));
	  return -5;
      }

    spatialite_cleanup_ex (cache);

    cache = spatialite_alloc_connection ();
    ret =
	sqlite3_open_v2 (":memory:", &handle,
			 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "cannot open in-memory db: %s\n",
		   sqlite3_errmsg (handle));
	  sqlite3_close (handle);
	  return -6;
      }

    spatialite_init_ex (handle, cache, 0);

    ret =
	sqlite3_get_table (handle, "SELECT InitSpatialMetadata(3.4)", &results,
			   &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -7;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr,
		   "Unexpected result InitSpatialMetadata() bad result: %i/%i.\n",
		   rows, columns);
	  return -8;
      }
    if (strcmp (results[1], "0") != 0)
      {
	  fprintf (stderr,
		   "Unexpected result: InitSpatialMetadata() with non-text passed: %s.\n",
		   results[1]);
	  return -9;
      }
    sqlite3_free_table (results);

    ret = sqlite3_close (handle);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "sqlite3_close() error: %s\n",
		   sqlite3_errmsg (handle));
	  return -10;
      }

    spatialite_cleanup_ex (cache);

    cache = spatialite_alloc_connection ();
    ret =
	sqlite3_open_v2 (":memory:", &handle,
			 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "cannot open in-memory db: %s\n",
		   sqlite3_errmsg (handle));
	  sqlite3_close (handle);
	  return -11;
      }

    spatialite_init_ex (handle, cache, 0);

    ret =
	sqlite3_get_table (handle, "SELECT InitSpatialMetadata(\"EMPTY\")",
			   &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -12;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr,
		   "Unexpected result InitSpatialMetadata(\"EMPTY\") bad result: %i/%i.\n",
		   rows, columns);
	  return -13;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr,
		   "Unexpected error: InitSpatialMetadata(\"EMPTY\"): %s.\n",
		   results[1]);
	  return -14;
      }
    sqlite3_free_table (results);

    ret =
	sqlite3_get_table (handle, "SELECT InsertEpsgSrid(4326)", &results,
			   &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -15;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr,
		   "Unexpected result InsertEpsgSrid(4326) bad result: %i/%i.\n",
		   rows, columns);
	  return -16;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: InsertEpsgSrid(4326): %s.\n",
		   results[1]);
	  return -17;
      }
    sqlite3_free_table (results);

    ret =
	sqlite3_get_table (handle, "SELECT InsertEpsgSrid(\"Non-integer\")",
			   &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -18;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr,
		   "Unexpected result InsertEpsgSrid(\"Non-integer\") bad result: %i/%i.\n",
		   rows, columns);
	  return -19;
      }
    if (strcmp (results[1], "0") != 0)
      {
	  fprintf (stderr,
		   "Unexpected result: InsertEpsgSrid() with non-integer passed: %s.\n",
		   results[1]);
	  return -20;
      }
    sqlite3_free_table (results);

    ret = sqlite3_close (handle);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "sqlite3_close() error: %s\n",
		   sqlite3_errmsg (handle));
	  return -21;
      }

    spatialite_cleanup_ex (cache);

    cache = spatialite_alloc_connection ();
    ret =
	sqlite3_open_v2 (":memory:", &handle,
			 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "cannot open in-memory db: %s\n",
		   sqlite3_errmsg (handle));
	  sqlite3_close (handle);
	  return -22;
      }

    spatialite_init_ex (handle, cache, 0);

    ret =
	sqlite3_get_table (handle, "SELECT InitSpatialMetadata(\"WGS84\")",
			   &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -23;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr,
		   "Unexpected result InitSpatialMetadata(\"WGS84\") bad result: %i/%i.\n",
		   rows, columns);
	  return -24;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr,
		   "Unexpected error: InitSpatialMetadata(\"WGS84\"): %s.\n",
		   results[1]);
	  return -25;
      }
    sqlite3_free_table (results);

#ifndef OMIT_EPSG
/* only if full EPSG support is enabled */
    ret =
	sqlite3_get_table (handle, "SELECT InsertEpsgSrid(3003)", &results,
			   &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -26;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr,
		   "Unexpected result InsertEpsgSrid(3003) bad result: %i/%i.\n",
		   rows, columns);
	  return -27;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: InsertEpsgSrid(3003): %s.\n",
		   results[1]);
	  return -28;
      }
    sqlite3_free_table (results);
#endif

    ret =
	sqlite3_get_table (handle, "SELECT InsertEpsgSrid(4326)", &results,
			   &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -29;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr,
		   "Unexpected result InsertEpsgSrid(4326) (dupe) bad result: %i/%i.\n",
		   rows, columns);
	  return -30;
      }
    if (strcmp (results[1], "0") != 0)
      {
	  fprintf (stderr,
		   "Unexpected result: InsertEpsgSrid(4326) duplicate passed: %s.\n",
		   results[1]);
	  return -31;
      }
    sqlite3_free_table (results);

    ret = sqlite3_close (handle);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "sqlite3_close() error: %s\n",
		   sqlite3_errmsg (handle));
	  return -32;
      }

    spatialite_cleanup_ex (cache);

    cache = spatialite_alloc_connection ();
    ret =
	sqlite3_open_v2 (":memory:", &handle,
			 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "cannot open in-memory db: %s\n",
		   sqlite3_errmsg (handle));
	  sqlite3_close (handle);
	  return -33;
      }

    spatialite_init_ex (handle, cache, 0);

    ret =
	sqlite3_get_table (handle, "SELECT InitSpatialMetadata(\"WGS84_only\")",
			   &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -34;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr,
		   "Unexpected result InitSpatialMetadata(\"WGS84_ONLY\") bad result: %i/%i.\n",
		   rows, columns);
	  return -35;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr,
		   "Unexpected error: InitSpatialMetadata(\"WGS84_ONLY\"): %s.\n",
		   results[1]);
	  return -36;
      }
    sqlite3_free_table (results);

    ret = sqlite3_close (handle);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "sqlite3_close() error: %s\n",
		   sqlite3_errmsg (handle));
	  return -32;
      }

    spatialite_cleanup_ex (cache);

    return 0;
}
예제 #26
0
static int
checkCache (void)
{
    int i;
    int max = 1024;
    void *cache[1024];
    char msg[64];
    const char *m;

    for (i = 0; i < max; i++)
      {
	  cache[i] = spatialite_alloc_connection ();
      }

    for (i = 0; i < max; i++)
      {
	  if (cache[i] != NULL)
	    {
		sprintf (msg, "Err%d", i);
		gaiaSetGeosErrorMsg_r (cache[i], msg);
		sprintf (msg, "Warn%d", i);
		gaiaSetGeosWarningMsg_r (cache[i], msg);
		sprintf (msg, "Aux%d", i);
		gaiaSetGeosAuxErrorMsg_r (cache[i], msg);
	    }
      }

    for (i = 0; i < max; i++)
      {
	  if (cache[i] != NULL)
	    {
		sprintf (msg, "Err%d", i);
		m = gaiaGetGeosErrorMsg_r (cache[i]);
		if (m == NULL)
		  {
		      fprintf (stderr, "unexpected NULL: GeosErrorMsg %d\n", i);
		      return -200 + i;
		  }
		if (strcmp (m, msg) != 0)
		  {
		      fprintf (stderr, "unexpected GeosErrorMsg %d \"%s\"\n", i,
			       m);
		      return -300 + i;
		  }
		sprintf (msg, "Warn%d", i);
		m = gaiaGetGeosWarningMsg_r (cache[i]);
		if (m == NULL)
		  {
		      fprintf (stderr, "unexpected NULL: GeosWarningMsg %d\n",
			       i);
		      return -400 + i;
		  }
		if (strcmp (m, msg) != 0)
		  {
		      fprintf (stderr,
			       "unexpected GeosWarningErrorMsg %d \"%s\"\n", i,
			       m);
		      return -500 + i;
		  }
		sprintf (msg, "Aux%d", i);
		m = gaiaGetGeosAuxErrorMsg_r (cache[i]);
		if (m == NULL)
		  {
		      fprintf (stderr, "unexpected NULL: GeosAuxErrorMsg %d\n",
			       i);
		      return -600 + i;
		  }
		if (strcmp (m, msg) != 0)
		  {
		      fprintf (stderr, "unexpected GeosAuxErrorMsg %d \"%s\"\n",
			       i, m);
		      return -700 + i;
		  }
	    }
      }

    for (i = 0; i < max; i++)
      {
	  if (cache[i] != NULL)
	      spatialite_cleanup_ex (cache[i]);
      }
    return 0;
}
예제 #27
0
int
main (int argc, char *argv[])
{
    int ret;
    sqlite3 *handle;
    char *err_msg = NULL;
    sqlite3_int64 log_pk;
    void *cache = spatialite_alloc_connection ();

    if (argc > 1 || argv[0] == NULL)
	argc = 1;		/* silencing stupid compiler warnings */

    ret =
	sqlite3_open_v2 (":memory:", &handle,
			 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "cannot open in-memory db: %s\n",
		   sqlite3_errmsg (handle));
	  sqlite3_close (handle);
	  return -1;
      }

    spatialite_init_ex (handle, cache, 0);

    ret =
	sqlite3_exec (handle, "SELECT InitSpatialMetadata(1)", NULL, NULL,
		      &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "InitSpatialMetadata() error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  sqlite3_close (handle);
	  return -2;
      }
    ret = sqlite3_exec (handle, "SELECT HasProj()", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "HasProj() error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  sqlite3_close (handle);
	  return -3;
      }
    ret = sqlite3_exec (handle, "SELECT HasGeos()", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "HasGeos() error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  sqlite3_close (handle);
	  return -4;
      }
    ret =
	sqlite3_exec (handle, "SELECT HasGeosAdvanced()", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "HasGeosAdvanced() error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  sqlite3_close (handle);
	  return -5;
      }
    ret =
	sqlite3_exec (handle, "SELECT HasGeosReentrant()", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "HasGeosReentrant() error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  sqlite3_close (handle);
	  return -6;
      }
    ret =
	sqlite3_exec (handle, "SELECT HasGeosOnlyReentrant()", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "HasGeosOnlyReentrant() error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  sqlite3_close (handle);
	  return -7;
      }
    ret = sqlite3_exec (handle, "SELECT HasIconv()", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "HasIconv() error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  sqlite3_close (handle);
	  return -8;
      }
    ret = sqlite3_exec (handle, "SELECT HasMathSql()", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "HasMathSql() error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  sqlite3_close (handle);
	  return -9;
      }
    ret =
	sqlite3_exec (handle, "SELECT HasGeoCallbacks()", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "HasGeoCallbacks() error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  sqlite3_close (handle);
	  return -10;
      }
    ret = sqlite3_exec (handle, "SELECT HasFreeXL()", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "HasFreeXL() error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  sqlite3_close (handle);
	  return -11;
      }
    ret = sqlite3_exec (handle, "SELECT HasEpsg()", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "HasEpsg() error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  sqlite3_close (handle);
	  return -12;
      }
    ret = sqlite3_exec (handle, "SELECT HasGeosTrunk()", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "HasGeoTrunk() error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  sqlite3_close (handle);
	  return -13;
      }
    ret = sqlite3_exec (handle, "SELECT HasLwGeom()", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "HasLwGeom() error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  sqlite3_close (handle);
	  return -14;
      }
    ret = sqlite3_exec (handle, "SELECT HasLibXml2()", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "HasLibXml2() error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  sqlite3_close (handle);
	  return -15;
      }

    gaiaInsertIntoSqlLog (handle, "test", "sql_statement_ok", &log_pk);
    gaiaUpdateSqlLog (handle, log_pk, 1, NULL);
    gaiaInsertIntoSqlLog (handle, "test", "sql_statement_no", &log_pk);
    gaiaUpdateSqlLog (handle, log_pk, 0, "some error message");

    ret = sqlite3_close (handle);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "sqlite3_close() error: %s\n",
		   sqlite3_errmsg (handle));
	  return -16;
      }

    spatialite_cleanup_ex (cache);

    ret = checkCache ();
    if (ret != 0)
	return ret;
    spatialite_shutdown ();

    return 0;
}
예제 #28
0
int
main (int argc, char *argv[])
{
#ifndef OMIT_ICONV		/* only if ICONV is supported */
    int ret;
    sqlite3 *handle;
    char *err_msg = NULL;
    void *cache = spatialite_alloc_connection ();

    if (argc > 1 || argv[0] == NULL)
	argc = 1;		/* silencing stupid compiler warnings */

/* testing current style metadata layout >= v.4.0.0 */
    ret =
	sqlite3_open_v2 (":memory:", &handle,
			 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "cannot open in-memory database: %s\n",
		   sqlite3_errmsg (handle));
	  sqlite3_close (handle);
	  return -1;
      }

    spatialite_init_ex (handle, cache, 0);

    ret =
	sqlite3_exec (handle, "SELECT InitSpatialMetadata(1)", NULL, NULL,
		      &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "InitSpatialMetadata() error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  sqlite3_close (handle);
	  return -2;
      }

    ret = do_test (handle, 0);
    if (ret != 0)
      {
	  fprintf (stderr,
		   "error while testing current style metadata layout\n");
	  return ret;
      }

    ret = sqlite3_close (handle);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "sqlite3_close() error: %s\n",
		   sqlite3_errmsg (handle));
	  return -19;
      }
    spatialite_cleanup_ex (cache);

/* testing legacy style metadata layout <= v.3.1.0 */
    cache = spatialite_alloc_connection ();
    ret =
	system
	("cp test-legacy-3.0.1.sqlite copy-utf8_1ex-legacy-3.0.1.sqlite");
    if (ret != 0)
      {
	  fprintf (stderr, "cannot copy legacy v.3.0.1 database\n");
	  return -1;
      }
    ret =
	sqlite3_open_v2 ("copy-utf8_1ex-legacy-3.0.1.sqlite", &handle,
			 SQLITE_OPEN_READWRITE, NULL);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "cannot open legacy v.3.0.1 database: %s\n",
		   sqlite3_errmsg (handle));
	  sqlite3_close (handle);
	  return -1;
      }

    spatialite_init_ex (handle, cache, 0);

    ret = do_test (handle, 1);
    if (ret != 0)
      {
	  fprintf (stderr,
		   "error while testing legacy style metadata layout\n");
	  return ret;
      }

    ret = sqlite3_close (handle);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "sqlite3_close() error: %s\n",
		   sqlite3_errmsg (handle));
	  return -19;
      }
    spatialite_cleanup_ex (cache);
    ret = unlink ("copy-utf8_1ex-legacy-3.0.1.sqlite");
    if (ret != 0)
      {
	  fprintf (stderr, "cannot remove legacy v.3.0.1 database\n");
	  return -20;
      }

#endif /* end ICONV conditional */

    spatialite_shutdown ();
    return 0;
}
예제 #29
0
int
main (int argc, char *argv[])
{
    int result = 0;
    void *cache = spatialite_alloc_connection ();
    struct db_conn conn;
    conn.db_path = NULL;
    conn.db_handle = NULL;
    conn.cache = cache;

/* testing in current mode */
    if (argc == 1)
      {
	  result = run_all_testcases (&conn, 0);
      }
    else
      {
	  result = run_specified_testcases (argc, argv, &conn, 0);
      }
    if (result != 0)
      {
	  /* it looks like if MinGW applies some wrong assumption   */
	  /* some negative values are incorrectly reported to be OK */
	  /* forcing -1 seems to resolve this issue                 */
	  result = -1;
      }

    close_connection (&conn);
    spatialite_cleanup_ex (conn.cache);
    conn.cache = NULL;

    if (result == 0)
      {
	  /* testing again in legacy mode */
	  fprintf (stderr,
		   "\n****************** testing again in legacy mode\n\n");
	  if (argc == 1)
	    {
		result = run_all_testcases (&conn, 0);
	    }
	  else
	    {
		result = run_specified_testcases (argc, argv, &conn, 0);
	    }
	  close_connection (&conn);
      }

    if (result == 0)
      {
	  /* testing again in load_extension mode */
	  fprintf (stderr,
		   "\n****************** testing again in load_extension mode\n\n");
	  if (argc == 1)
	    {
		result = run_all_testcases (&conn, 1);
	    }
	  else
	    {
		result = run_specified_testcases (argc, argv, &conn, 1);
	    }
	  close_connection (&conn);
      }

    spatialite_shutdown ();
    return result;
}
int
main (int argc, char *argv[])
{
    int ret;
    sqlite3 *handle;
    char *err_msg = NULL;
    const char *sql;
    char **results;
    int rows;
    int columns;
    void *cache = spatialite_alloc_connection ();

    if (argc > 1 || argv[0] == NULL)
	argc = 1;		/* silencing stupid compiler warnings */

    ret =
	sqlite3_open_v2 (":memory:", &handle,
			 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "cannot open in-memory database: %s\n",
		   sqlite3_errmsg (handle));
	  sqlite3_close (handle);
	  return -1;
      }

    spatialite_init_ex (handle, cache, 0);

    ret =
	sqlite3_exec (handle, "SELECT InitSpatialMetadata(1)", NULL, NULL,
		      &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "InitSpatialMetadata() error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  sqlite3_close (handle);
	  return -2;
      }
/* creating a Point XY table */
    sql = "CREATE TABLE pt_xy (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -3;
      }

/* creating a Point XYZ table */
    sql = "CREATE TABLE pt_xyz (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -4;
      }

/* creating a Point XYM table */
    sql = "CREATE TABLE pt_xym (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -5;
      }

/* creating a Point XYZM table */
    sql = "CREATE TABLE pt_xyzm (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -6;
      }

/* creating a Linestring XY table */
    sql = "CREATE TABLE ln_xy (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -7;
      }

/* creating a Linestring XYZ table */
    sql = "CREATE TABLE ln_xyz (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -8;
      }

/* creating a Linestring XYM table */
    sql = "CREATE TABLE ln_xym (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -9;
      }

/* creating a Linestring XYZM table */
    sql = "CREATE TABLE ln_xyzm (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -10;
      }

/* creating a Polygon XY table */
    sql = "CREATE TABLE pg_xy (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -11;
      }

/* creating a Polygon XYZ table */
    sql = "CREATE TABLE pg_xyz (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -12;
      }

/* creating a Polygon XYM table */
    sql = "CREATE TABLE pg_xym (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -13;
      }

/* creating a Polygon XYZM table */
    sql = "CREATE TABLE pg_xyzm (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -14;
      }

/* creating a MultiPoint XY table */
    sql = "CREATE TABLE mpt_xy (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -15;
      }

/* creating a MultiPoint XYZ table */
    sql = "CREATE TABLE mpt_XYZ (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -16;
      }

/* creating a MultiPoint XYM table */
    sql = "CREATE TABLE mpt_xym (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -17;
      }

/* creating a MultiPoint XYZM table */
    sql = "CREATE TABLE mpt_xyzm (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -18;
      }

/* creating a MultiLinestring XY table */
    sql = "CREATE TABLE mln_xy (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -19;
      }

/* creating a MultiLinestring XYZ table */
    sql = "CREATE TABLE mln_xyz (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -20;
      }

/* creating a MultiLinestring XYM table */
    sql = "CREATE TABLE mln_xym (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -21;
      }

/* creating a MultiLinestring XYZM table */
    sql = "CREATE TABLE mln_xyzm (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -22;
      }

/* creating a MultiPolygon XY table */
    sql = "CREATE TABLE mpg_xy (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -23;
      }

/* creating a MultiPolygon XYZ table */
    sql = "CREATE TABLE mpg_xyz (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -24;
      }

/* creating a MultiPolygon XYM table */
    sql = "CREATE TABLE mpg_xym (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -25;
      }

/* creating a MultiPolygon XYZM table */
    sql = "CREATE TABLE mpg_xyzm (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -26;
      }

/* creating a GeometryCollection XY table */
    sql = "CREATE TABLE gcoll_xy (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -27;
      }

/* creating a GeometryCollection XYZ table */
    sql = "CREATE TABLE gcoll_xyz (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -28;
      }

/* creating a GeometryCollection XYM table */
    sql = "CREATE TABLE gcoll_xym (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -29;
      }

/* creating a GeometryCollection XYZM table */
    sql = "CREATE TABLE gcoll_xyzm (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -30;
      }


/* creating a Geometry XY table */
    sql = "CREATE TABLE geom_xy (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -31;
      }

/* creating a Geometry XYZ table */
    sql = "CREATE TABLE geom_xyz (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -32;
      }

/* creating a Geometry XYM table */
    sql = "CREATE TABLE geom_xym (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -33;
      }

/* creating a Geometry XYZM table */
    sql = "CREATE TABLE geom_xyzm (id INTEGER, g BLOB)";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -34;
      }

/* Inserting into pt_xy */
    sql =
	"INSERT INTO pt_xy (id, g) VALUES (1, GeomFromText('POINT(1 2)', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -35;
      }

/* Inserting into pt_xyz */
    sql =
	"INSERT INTO pt_xyz (id, g) VALUES (1, GeomFromText('POINTZ(1 2 3)', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -36;
      }

/* Inserting into pt_xym */
    sql =
	"INSERT INTO pt_xym (id, g) VALUES (1, GeomFromText('POINTM(1 2 10)', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -37;
      }

/* Inserting into pt_xyzm */
    sql =
	"INSERT INTO pt_xyzm (id, g) VALUES (1, GeomFromText('POINTZM(1 2 3 10)', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -38;
      }

/* Inserting into ln_xy */
    sql =
	"INSERT INTO ln_xy (id, g) VALUES (1, GeomFromText('LINESTRING(1 2, 4 5)', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -39;
      }

/* Inserting into ln_xyz */
    sql =
	"INSERT INTO ln_xyz (id, g) VALUES (1, GeomFromText('LINESTRINGZ(1 2 3, 4 5 6)', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -40;
      }

/* Inserting into ln_xym */
    sql =
	"INSERT INTO ln_xym (id, g) VALUES (1, GeomFromText('LINESTRINGM(1 2 10, 4 5 11)', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -41;
      }

/* Inserting into ln_xyzm */
    sql =
	"INSERT INTO ln_xyzm (id, g) VALUES (2, GeomFromText('LINESTRINGZM(1 2 3 10, 4 5 6 11)', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -42;
      }

/* Inserting into pg_xy */
    sql =
	"INSERT INTO pg_xy (id, g) VALUES (1, GeomFromText('POLYGON((10 10, 15 10, 15 15, 10 15, 10 10), (11 11, 12 11, 1 12, 11 12, 11 11))', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -43;
      }

/* Inserting into pg_xyz */
    sql =
	"INSERT INTO pg_xyz (id, g) VALUES (1, GeomFromText('POLYGONZ((10 10 100, 15 10 101, 15 15 102, 10 15 103, 10 10 100), (11 11 100, 12 11 101, 1 12 102, 11 12 103, 11 11 100))', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -44;
      }

/* Inserting into pg_xym */
    sql =
	"INSERT INTO pg_xym (id, g) VALUES (1, GeomFromText('POLYGONM((10 10 10, 15 10 11, 15 15 12, 10 15 13, 10 10 10), (11 11 10, 12 11 11, 1 12 12, 11 12 13, 11 11 10))', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -45;
      }

/* Inserting into pg_xyzm */
    sql =
	"INSERT INTO pg_xyzm (id, g) VALUES (1, GeomFromText('POLYGONZM((10 10 100 10, 15 10 101 11, 15 15 102 12, 10 15 103 13, 10 10 100 10), (11 11 100 10, 12 11 101 11, 1 12 102 12, 11 12 103 13, 11 11 100 10))', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -46;
      }

/* Inserting into mpt_xy */
    sql =
	"INSERT INTO mpt_xy (id, g) VALUES (1, GeomFromText('MULTIPOINT(1 2, 4 5)', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -47;
      }

/* Inserting into mpt_xyz */
    sql =
	"INSERT INTO mpt_xyz (id, g) VALUES (1, GeomFromText('MULTIPOINTZ(1 2 3, 4 5 6)', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -48;
      }

/* Inserting into mpt_xym */
    sql =
	"INSERT INTO mpt_xym (id, g) VALUES (1, GeomFromText('MULTIPOINTM(1 2 10, 4 5 11)', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -49;
      }

/* Inserting into mpt_xyzm */
    sql =
	"INSERT INTO mpt_xyzm (id, g) VALUES (1, GeomFromText('MULTIPOINTZM(1 2 3 10, 4 5 6 10)', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -50;
      }

/* Inserting into mln_xy */
    sql =
	"INSERT INTO mln_xy (id, g) VALUES (1, GeomFromText('MULTILINESTRING((1 2, 4 5), (7 8, 10 11))', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -51;
      }

/* Inserting into mln_xyz */
    sql =
	"INSERT INTO mln_xyz (id, g) VALUES (1, GeomFromText('MULTILINESTRINGZ((1 2 3, 4 5 6), (7 8 9, 10 11 12))', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -52;
      }

/* Inserting into mln_xym */
    sql =
	"INSERT INTO mln_xym (id, g) VALUES (1, GeomFromText('MULTILINESTRINGM((1 2 10, 4 5 11), (7 8 12, 10 11 13))', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -53;
      }

/* Inserting into mln_xyzm */
    sql =
	"INSERT INTO mln_xyzm (id, g) VALUES (1, GeomFromText('MULTILINESTRINGZM((1 2 3 10, 4 5 6 11), (7 8 9 12, 10 11 12 13))', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -54;
      }

/* Inserting into mpg_xy */
    sql =
	"INSERT INTO mpg_xy (id, g) VALUES (1, GeomFromText('MULTIPOLYGON(((10 10, 15 10, 15 15, 10 15, 10 10), (11 11, 12 11, 1 12, 11 12, 11 11)), ((0 0, 1 0, 1 1, 0 1, 0 0)))', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -55;
      }

/* Inserting into mpg_xyz */
    sql =
	"INSERT INTO mpg_xyz (id, g) VALUES (1, GeomFromText('MULTIPOLYGONZ(((10 10 100, 15 10 101, 15 15 102, 10 15 103, 10 10 100), (11 11 100, 12 11 101, 1 12 102, 11 12 103, 11 11 100)), ((0 0 1, 1 0 2, 1 1 3, 0 1 4, 0 0 1)))', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -56;
      }

/* Inserting into mpg_xym */
    sql =
	"INSERT INTO mpg_xym (id, g) VALUES (1, GeomFromText('MULTIPOLYGONM(((10 10 11, 15 10 12, 15 15 13, 10 15 14, 10 10 11), (11 11 5, 12 11 6, 12 12 7, 11 12 8, 11 11 5)), ((0 0 11, 1 0 12, 1 1 13, 0 1 14, 0 0 11)))', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -57;
      }

/* Inserting into mpg_xyzm */
    sql =
	"INSERT INTO mpg_xyzm (id, g) VALUES (1, GeomFromText('MULTIPOLYGONZM(((10 10 100 11, 15 10 101 12, 15 15 102 13, 10 15 103 14, 10 10 100 11), (11 11 100 5, 12 11 101 6, 1 12 102 7, 11 12 103 8, 11 11 100 5)), ((0 0 1 11, 1 0 2 12, 1 1 3 13, 0 1 4 14, 0 0 1 11)))', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -58;
      }

/* Inserting into gcoll_xy */
    sql =
	"INSERT INTO gcoll_xy (id, g) VALUES (1, GeomFromText('GEOMETRYCOLLECTION(POINT(10 10), LINESTRING(5 5, 6 6), POLYGON((0 0, 1 0, 1 1, 0 1, 0 0)))', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -59;
      }

/* Inserting into gcoll_xyz */
    sql =
	"INSERT INTO gcoll_xyz (id, g) VALUES (1, GeomFromText('GEOMETRYCOLLECTIONZ(POINTZ(10 10 100), LINESTRINGZ(5 5 10, 6 6 11), POLYGONZ((0 0 1, 1 0 2, 1 1 3, 0 1 4, 0 0 1)))', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -60;
      }

/* Inserting into gcoll_xym */
    sql =
	"INSERT INTO gcoll_xym (id, g) VALUES (1, GeomFromText('GEOMETRYCOLLECTIONM(POINTM(10 10 100), LINESTRINGM(5 5 10, 6 6 11), POLYGONM((0 0 1, 1 0 2, 1 1 3, 0 1 4, 0 0 1)))', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -61;
      }

/* Inserting into gcoll_xyzm */
    sql =
	"INSERT INTO gcoll_xyzm (id, g) VALUES (1, GeomFromText('GEOMETRYCOLLECTIONZM(POINTZM(10 10 100 11), LINESTRINGZM(5 5 10 11, 6 6 11 12), POLYGONZM((0 0 1 10, 1 0 2 11, 1 1 3 12, 0 1 4 13, 0 0 1 10)))', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -62;
      }

/* Inserting into geom_xy */
    sql =
	"INSERT INTO geom_xy (id, g) VALUES (1, GeomFromText('GEOMETRYCOLLECTION(POINT(10 10), LINESTRING(5 5, 6 6), POLYGON((0 0, 1 0, 1 1, 0 1, 0 0)))', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -63;
      }
    sql =
	"INSERT INTO geom_xy (id, g) VALUES (2, GeomFromText('POINT(10 10)', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -64;
      }

/* Inserting into geom_xyz */
    sql =
	"INSERT INTO geom_xyz (id, g) VALUES (1, GeomFromText('GEOMETRYCOLLECTIONZ(POINTZ(10 10 100), LINESTRINGZ(5 5 10, 6 6 11), POLYGONZ((0 0 1, 1 0 2, 1 1 3, 0 1 4, 0 0 1)))', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -65;
      }
    sql =
	"INSERT INTO geom_xyz (id, g) VALUES (2, GeomFromText('POINTZ(10 10 100)', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -66;
      }

/* Inserting into geom_xym */
    sql =
	"INSERT INTO geom_xym (id, g) VALUES (1, GeomFromText('GEOMETRYCOLLECTIONM(POINTM(10 10 100), LINESTRINGM(5 5 10, 6 6 11), POLYGONM((0 0 1, 1 0 2, 1 1 3, 0 1 4, 0 0 1)))', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -67;
      }
    sql =
	"INSERT INTO geom_xym (id, g) VALUES (2, GeomFromText('POINTM(10 10 100)', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -68;
      }

/* Inserting into geom_xyzm */
    sql =
	"INSERT INTO geom_xyzm (id, g) VALUES (1, GeomFromText('GEOMETRYCOLLECTIONZM(POINTZM(10 10 100 11), LINESTRINGZM(5 5 10 11, 6 6 11 12), POLYGONZM((0 0 1 10, 1 0 2 11, 1 1 3 12, 0 1 4 13, 0 0 1 10)))', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -69;
      }
    sql =
	"INSERT INTO geom_xyzm (id, g) VALUES (2, GeomFromText('POINTZM(10 10 100 11)', 4326))";
    ret = sqlite3_exec (handle, sql, NULL, NULL, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -70;
      }

/* recovering pt_xy */
    sql = "SELECT RecoverGeometryColumn('pt_xy', 'g', 4326, 'POINT', 2);";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -71;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -72;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -73;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -74;
      }
    sqlite3_free_table (results);

/* recovering pt_xyz */
    sql = "SELECT RecoverGeometryColumn('pt_xyz', 'g', 4326, 'POINT', 3);";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -75;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -76;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -77;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -78;
      }
    sqlite3_free_table (results);

/* recovering pt_xym */
    sql = "SELECT RecoverGeometryColumn('pt_xym', 'g', 4326, 'POINT', 'XYM');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -79;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -80;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -81;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -82;
      }
    sqlite3_free_table (results);

/* recovering pt_xyzm */
    sql =
	"SELECT RecoverGeometryColumn('pt_xyzm', 'g', 4326, 'POINT', 'XYZM');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -83;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -84;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -85;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -86;
      }
    sqlite3_free_table (results);

/* recovering ln_xy */
    sql =
	"SELECT RecoverGeometryColumn('ln_xy', 'g', 4326, 'LINESTRING', 'XY');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -87;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -88;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -89;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -90;
      }
    sqlite3_free_table (results);

/* recovering ln_xyz */
    sql =
	"SELECT RecoverGeometryColumn('ln_xyz', 'g', 4326, 'LINESTRING', 'XYZ');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -91;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -92;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -93;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -94;
      }
    sqlite3_free_table (results);

/* recovering ln_xym */
    sql =
	"SELECT RecoverGeometryColumn('ln_xym', 'g', 4326, 'LINESTRING', 'XYM');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -95;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -96;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -97;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -98;
      }
    sqlite3_free_table (results);

/* recovering ln_xyzm */
    sql =
	"SELECT RecoverGeometryColumn('ln_xyzm', 'g', 4326, 'LINESTRING', 'XYZM');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -99;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -100;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -101;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -102;
      }
    sqlite3_free_table (results);

/* recovering pg_xy */
    sql = "SELECT RecoverGeometryColumn('pg_xy', 'g', 4326, 'POLYGON', 'XY');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -103;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -104;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -105;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -106;
      }
    sqlite3_free_table (results);

/* recovering pg_xyz */
    sql =
	"SELECT RecoverGeometryColumn('pg_xyz', 'g', 4326, 'POLYGON', 'XYZ');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -107;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -108;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -109;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -110;
      }
    sqlite3_free_table (results);

/* recovering pg_xym */
    sql =
	"SELECT RecoverGeometryColumn('pg_xym', 'g', 4326, 'POLYGON', 'XYM');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -111;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -112;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -113;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -114;
      }
    sqlite3_free_table (results);

/* recovering pg_xyzm */
    sql =
	"SELECT RecoverGeometryColumn('pg_xyzm', 'g', 4326, 'POLYGON', 'XYZM');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -115;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -116;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -117;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -118;
      }
    sqlite3_free_table (results);

/* recovering mpt_xy */
    sql =
	"SELECT RecoverGeometryColumn('mpt_xy', 'g', 4326, 'MULTIPOINT', 'XY');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -119;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -120;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -121;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -122;
      }
    sqlite3_free_table (results);

/* recovering mpt_xyz */
    sql =
	"SELECT RecoverGeometryColumn('mpt_xyz', 'g', 4326, 'MULTIPOINT', 'XYZ');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -123;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -124;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -125;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -126;
      }
    sqlite3_free_table (results);

/* recovering mpt_xym */
    sql =
	"SELECT RecoverGeometryColumn('mpt_xym', 'g', 4326, 'MULTIPOINT', 'XYM');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -127;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -128;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -129;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -130;
      }
    sqlite3_free_table (results);

/* recovering mpt_xyzm */
    sql =
	"SELECT RecoverGeometryColumn('mpt_xyzm', 'g', 4326, 'MULTIPOINT', 'XYZM');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -131;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -132;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -133;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -134;
      }
    sqlite3_free_table (results);

/* recovering mln_xy */
    sql =
	"SELECT RecoverGeometryColumn('mln_xy', 'g', 4326, 'MULTILINESTRING', 'XY');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -135;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -136;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -137;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -138;
      }
    sqlite3_free_table (results);

/* recovering mln_xyz */
    sql =
	"SELECT RecoverGeometryColumn('mln_xyz', 'g', 4326, 'MULTILINESTRING', 'XYZ');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -139;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -140;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -141;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -142;
      }
    sqlite3_free_table (results);

/* recovering mln_xym */
    sql =
	"SELECT RecoverGeometryColumn('mln_xym', 'g', 4326, 'MULTILINESTRING', 'XYM');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -143;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -144;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -145;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -146;
      }
    sqlite3_free_table (results);

/* recovering mln_xyzm */
    sql =
	"SELECT RecoverGeometryColumn('mln_xyzm', 'g', 4326, 'MULTILINESTRING', 'XYZM');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -147;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -148;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -149;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -150;
      }
    sqlite3_free_table (results);

/* recovering mpg_xy */
    sql =
	"SELECT RecoverGeometryColumn('mpg_xy', 'g', 4326, 'MULTIPOLYGON', 'XY');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -151;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -152;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -153;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -154;
      }
    sqlite3_free_table (results);

/* recovering mpg_xyz */
    sql =
	"SELECT RecoverGeometryColumn('mpg_xyz', 'g', 4326, 'MULTIPOLYGON', 'XYZ');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -155;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -156;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -157;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -158;
      }
    sqlite3_free_table (results);

/* recovering mpg_xym */
    sql =
	"SELECT RecoverGeometryColumn('mpg_xym', 'g', 4326, 'MULTIPOLYGON', 'XYM');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -159;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -160;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -161;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -162;
      }
    sqlite3_free_table (results);

/* recovering mpg_xyzm */
    sql =
	"SELECT RecoverGeometryColumn('mpg_xyzm', 'g', 4326, 'MULTIPOLYGON', 'XYZM');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -163;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -164;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -165;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -166;
      }
    sqlite3_free_table (results);

/* recovering gcoll_xy */
    sql =
	"SELECT RecoverGeometryColumn('gcoll_xy', 'g', 4326, 'GEOMETRYCOLLECTION', 'XY');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -167;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -168;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -169;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -170;
      }
    sqlite3_free_table (results);

/* recovering gcoll_xyz */
    sql =
	"SELECT RecoverGeometryColumn('gcoll_xyz', 'g', 4326, 'GEOMETRYCOLLECTION', 'XYZ');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -171;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -172;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -173;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -174;
      }
    sqlite3_free_table (results);

/* recovering gcoll_xym */
    sql =
	"SELECT RecoverGeometryColumn('gcoll_xym', 'g', 4326, 'GEOMETRYCOLLECTION', 'XYM');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -175;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -176;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -177;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -178;
      }
    sqlite3_free_table (results);

/* recovering gcoll_xyzm */
    sql =
	"SELECT RecoverGeometryColumn('gcoll_xyzm', 'g', 4326, 'GEOMETRYCOLLECTION', 'XYZM');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -179;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -180;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -181;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -182;
      }
    sqlite3_free_table (results);

/* recovering geom_xy */
    sql =
	"SELECT RecoverGeometryColumn('geom_xy', 'g', 4326, 'GEOMETRY', 'XY');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -183;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -184;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -185;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -186;
      }
    sqlite3_free_table (results);

/* recovering geom_xyz */
    sql =
	"SELECT RecoverGeometryColumn('geom_xyz', 'g', 4326, 'GEOMETRY', 'XYZ');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -187;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -188;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -189;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -190;
      }
    sqlite3_free_table (results);

/* recovering geom_xym */
    sql =
	"SELECT RecoverGeometryColumn('geom_xym', 'g', 4326, 'GEOMETRY', 'XYM');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -191;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -192;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -193;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -194;
      }
    sqlite3_free_table (results);

/* recovering geom_xyzm */
    sql =
	"SELECT RecoverGeometryColumn('geom_xyzm', 'g', 4326, 'GEOMETRY', 'XYZM');";
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -195;
      }
    if ((rows != 1) || (columns != 1))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -196;
      }
    if (results[1] == NULL)
      {
	  fprintf (stderr, "Unexpected error: NULL result\n");
	  return -197;
      }
    if (strcmp (results[1], "1") != 0)
      {
	  fprintf (stderr, "Unexpected error: invalid result\n");
	  return -198;
      }
    sqlite3_free_table (results);

    ret = sqlite3_close (handle);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "sqlite3_close() error: %s\n",
		   sqlite3_errmsg (handle));
	  return -199;
      }

    spatialite_cleanup_ex (cache);

    return 0;
}