Esempio n. 1
0
int main (int argc, char *argv[])
{
    spatialite_init(0);
    spatialite_cleanup();
    
    spatialite_init(1);
    spatialite_cleanup();
    
    sqlite3_reset_auto_extension();
    
    return 0;
}
Esempio n. 2
0
static void
close_connection (struct db_conn *conn)
{
    if (conn->db_path != NULL)
	free (conn->db_path);
    conn->db_path = NULL;
    if (conn->db_handle != NULL)
	sqlite3_close (conn->db_handle);
    conn->db_handle = NULL;
    if (conn->cache == NULL)
	spatialite_cleanup ();
}
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;

    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 databse: %s\n", sqlite3_errmsg (handle));
	sqlite3_close(handle);
	return -1;
    }
    
    ret = sqlite3_exec (handle, "SELECT InitSpatialMetadata()", 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();
#endif	/* end ICONV conditional */

    return 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;

    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 -1;
    }
    
    ret = sqlite3_exec (handle, "SELECT InitSpatialMetadata()", 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();
#endif	/* end ICONV conditional */

    return 0;
}
Esempio n. 5
0
int main (int argc, char *argv[])
{
#ifndef OMIT_ICONV	/* only if ICONV is supported */
    int ret;
    sqlite3 *handle;
    char *kmlname = __FILE__"test.kml";
    char *geojsonname = __FILE__"test.geojson"; 
    char *err_msg = NULL;
    int row_count;

    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 -1;
    }
    
    ret = sqlite3_exec (handle, "SELECT InitSpatialMetadata()", 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/taiwan/hystoric", "hystoric", "UTF-8", 4326, 
			  "col1", 1, 0, 1, 0, &row_count, err_msg);
    if (!ret) {
        fprintf (stderr, "load_shapefile() error for shp/taiwan/hystoric: %s\n", err_msg);
	sqlite3_close(handle);
	return -3;
    }
    if (row_count != 15) {
	fprintf (stderr, "unexpected row count for shp/taiwan/hystoric: %i\n", row_count);
	sqlite3_close(handle);
	return -4;
    }

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

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

#ifndef OMIT_PROJ	/* only if PROJ is supported */
    if (is_kml_constant (handle, "route", "name")) {
	fprintf(stderr, "unexpected result for is_kml_constant (1)\n");
	return -9;
    }
    if (! is_kml_constant (handle, "route", "foo")) {
	fprintf(stderr, "unexpected result for is_kml_constant (2)\n");
	return -10;
    }
    
    ret = dump_kml (handle, "route", "col1", kmlname, NULL, NULL, 10);
    if (!ret) {
        fprintf (stderr, "dump_kml (1) error for shp/taiwan/route: %s\n", err_msg);
	sqlite3_close(handle);
	return -11;
    }
    unlink(kmlname);

    ret = dump_kml (handle, "route", "col1", kmlname, "name", NULL, 10);
    if (!ret) {
        fprintf (stderr, "dump_kml (2) error for shp/taiwan/route: %s\n", err_msg);
	sqlite3_close(handle);
	return -12;
    }
    unlink(kmlname);

    ret = dump_kml (handle, "route", "col1", kmlname, "theta", NULL, 10);
    if (!ret) {
        fprintf (stderr, "dump_kml (3) error for shp/taiwan/route: %s\n", err_msg);
	sqlite3_close(handle);
	return -13;
    }
    unlink(kmlname);

    ret = dump_kml (handle, "route", "col1", kmlname, "name", "sub_type", 10);
    if (!ret) {
        fprintf (stderr, "dump_kml (4) error for shp/taiwan/route: %s\n", err_msg);
	sqlite3_close(handle);
	return -14;
    }
    unlink(kmlname);

    ret = dump_kml (handle, "route", "col1", kmlname, "theta", "beta", 10);
    if (!ret) {
        fprintf (stderr, "dump_kml (5) error for shp/taiwan/route: %s\n", err_msg);
	sqlite3_close(handle);
	return -15;
    }
    unlink(kmlname);
#endif	/* end PROJ conditional */

    ret = dump_geojson(handle, "route", "col1", geojsonname, 10, 5);
    if (!ret) {
        fprintf (stderr, "dump_geojson() error for shp/taiwan/route: %s\n", err_msg);
       sqlite3_close(handle);
       return -16;
    }
    unlink(geojsonname);

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

    return 0;
}
Esempio n. 6
0
int main (int argc, char *argv[])
{
    int ret;
    sqlite3 *handle;
    char *err_msg = NULL;
    int row_count;
    char **results;
    int rows;
    int columns;

    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 -1;
    }
    
    ret = sqlite3_exec (handle, "SELECT InitSpatialMetadata()", 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;
    }

    ret = sqlite3_close (handle);
    if (ret != SQLITE_OK) {
        fprintf (stderr, "sqlite3_close() error: %s\n", sqlite3_errmsg (handle));
	return -45;
    }
    
    spatialite_cleanup();
    sqlite3_reset_auto_extension();
    return 0;
}
int main (int argc, char *argv[])
{
    int ret;
    sqlite3 *handle;
    char *err_msg = NULL;
    char **results;
    int rows;
    int columns;

    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 db: %s\n", sqlite3_errmsg (handle));
	sqlite3_close(handle);
	return -1;
    }
    ret = sqlite3_exec (handle, "SELECT InitSpatialMetadata()", 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();
    
    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;
}
Esempio n. 9
0
int main (int argc, char *argv[])
{
    int ret;
    sqlite3 *handle;
    char *dumpname = __FILE__"dump";
    char *err_msg = NULL;
    int row_count;

    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 -1;
    }
    
    ret = sqlite3_exec (handle, "SELECT InitSpatialMetadata()", 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();
    sqlite3_reset_auto_extension();
    
    return 0;
}
int main (int argc, char *argv[])
{
    sqlite3 *db_handle = NULL;
    char *sql_statement;
    int ret;
    char *err_msg = NULL;
    int i;
    char **results;
    int rows;
    int columns;
    const char *sql;

    spatialite_init (0);

    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;
    }
    
    ret = sqlite3_exec (db_handle, "create VIRTUAL TABLE shapetest USING VirtualShape('shp/merano-3d/roads', CP1252, 25832);", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "VirtualShape error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -2;
    }

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

    ret = sqlite3_exec (db_handle, "create VIRTUAL TABLE shapetest USING VirtualShape(\"shp/merano-3d/roads\", 'CP1252', -1);", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "VirtualShape error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -4;
    }
    
    ret = sqlite3_exec (db_handle, "DROP TABLE shapetest;", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "DROP TABLE error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -5;
    }

    ret = sqlite3_exec (db_handle, "create VIRTUAL TABLE unquoted USING VirtualShape(shapetest1, UTF8, -1);", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "VirtualShape error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -6;
    }
    
    ret = sqlite3_exec (db_handle, "DROP TABLE unquoted;", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "DROP TABLE error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -7;
    }

    ret = sqlite3_exec (db_handle, "create VIRTUAL TABLE shapetest USING VirtualShape('shp/merano-3d/roads', \"CP1252\", 25832);", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "VirtualShape error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -8;
    }

    for (i = 0; steps[i].sql; ++i) {
	ret = sqlite3_get_table (db_handle, steps[i].sql, &results, &rows, &columns, &err_msg);
	if (ret != SQLITE_OK) {
	    fprintf (stderr, "Error: %s\n", err_msg);
	    sqlite3_free (err_msg);
	    return -9;
	}
	if (rows != steps[i].num_rows) {
	    fprintf (stderr, "Unexpected num of rows for test %i: %i.\n", i, rows);
	    return  -10;
	}
	sqlite3_free_table (results);
    }

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

    ret = sqlite3_exec (db_handle, "create VIRTUAL TABLE nosuchfile USING VirtualShape(nosuchfile, UTF8, -1);", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "VirtualShape error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -12;
    }
    
    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 -13;
    }

    ret = sqlite3_exec (db_handle, "create VIRTUAL TABLE toofewargs USING VirtualShape(\"shapetest1\", UTF8);", NULL, NULL, &err_msg);
    if (ret != SQLITE_ERROR) {
	fprintf (stderr, "VirtualShape unexpected result: %i\n", ret);
	return -14;
    }
    sqlite3_free (err_msg);

    ret = sqlite3_exec (db_handle, "create VIRTUAL TABLE toomanyargs USING VirtualShape(\"shapetest1\", UTF8, 4386, 1);", NULL, NULL, &err_msg);
    if (ret != SQLITE_ERROR) {
	fprintf (stderr, "VirtualShape unexpected result: %i\n", ret);
	return -15;
    }
    sqlite3_free (err_msg);
    
    sqlite3_close (db_handle);
    spatialite_cleanup();
    sqlite3_reset_auto_extension();
    
    return 0;
}
int main (int argc, char *argv[])
{
#ifndef OMIT_FREEXL		/* only if FreeXL is supported */
    sqlite3 *db_handle = NULL;
    char *sql_statement;
    int ret;
    char *err_msg = NULL;
    int i;
    char **results;
    int rows;
    int columns;

    spatialite_init (0);

    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;
    }
    
    ret = sqlite3_exec (db_handle, "create VIRTUAL TABLE xltest USING VirtualXL(\"testcase1.xls\");", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "VirtualXL error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -2;
    }

    asprintf(&sql_statement, "select col_2, col_4, col_5, col_7, rowid from xltest WHERE col_2 = \"Canal Creek\";");
    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 != 2) || (columns != 5)) {
	fprintf (stderr, "Unexpected error: select columns bad result: %i/%i.\n", rows, columns);
	return  -11;
    }
    if (strcmp(results[0], "col_2") != 0) {
	fprintf (stderr, "Unexpected error: header() bad result: %s.\n", results[0]);
	return  -12;
    }
    if (strcmp(results[5], "Canal Creek") != 0) {
	fprintf (stderr, "Unexpected error: name5() bad result: %s.\n", results[5]);
	return  -13;
    }
    if (strncmp(results[6], "-27.86667", 9) != 0) {
	fprintf (stderr, "Unexpected error: lat1() bad result: %s.\n", results[6]);
	return  -14;
    }
    if (strncmp(results[7], "151.51667", 9) != 0) {
	fprintf (stderr, "Unexpected error: lon2() bad result: %s.\n", results[7]);
	return  -15;
    }
    if (strcmp(results[10], "Canal Creek") != 0) {
	fprintf (stderr, "Unexpected error: name10() bad result: %s.\n", results[10]);
	return  -16;
    }
    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 -21;
    }

    ret = sqlite3_exec (db_handle, "DELETE FROM xltest WHERE col_14 > 100000;", NULL, NULL, &err_msg);
    if (ret != SQLITE_READONLY) {
	fprintf (stderr, "UPDATE error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -21;
    }
    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 -22;
    }
 
    for (i = 0; i < NUMSTEPS; ++i) {
	ret = sqlite3_get_table (db_handle, steps[i].sql, &results, &rows, &columns, &err_msg);
	if (ret != SQLITE_OK) {
	    fprintf (stderr, "Error: %s\n", err_msg);
	    sqlite3_free (err_msg);
	    return -23;
	}
	if (rows != steps[i].num_rows) {
	    fprintf (stderr, "Unexpected num of rows for test %i: %i.\n", i, rows);
	    return  -24;
	}
	sqlite3_free_table (results);
    }
    
    ret = sqlite3_exec (db_handle, "DROP TABLE xltest;", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "DROP TABLE error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -25;
    }

    ret = sqlite3_exec (db_handle, "create VIRTUAL TABLE nosuchworksheet USING VirtualXL(\"testcase1.xls\", 3);", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "VirtualXL error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -26;
    }
    ret = sqlite3_exec (db_handle, "DROP TABLE nosuchworksheet;", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "DROP TABLE error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -27;
    }

    ret = sqlite3_exec (db_handle, "create VIRTUAL TABLE nosuchfile USING VirtualXL(\"not_a_file.xls\", 3);", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "VirtualXL error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -28;
    }
    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 -29;
    }

    ret = sqlite3_exec (db_handle, "create VIRTUAL TABLE sheet2 USING VirtualXL(\"testcase1.xls\", 1, 1);", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "VirtualXL error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -30;
    }
    asprintf(&sql_statement, "select row_no, place, lat, lon, rowid from sheet2 WHERE place = \"Canal Creek\";");
    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 -31;
    }
    if ((rows != 4) || (columns != 5)) {
	fprintf (stderr, "Unexpected error: select columns bad result: %i/%i.\n", rows, columns);
	return  -32;
    }
    if (strcmp(results[0], "row_no") != 0) {
	fprintf (stderr, "Unexpected error: sheet2() bad result: %s.\n", results[0]);
	return  -33;
    }
    if (strcmp(results[6], "Canal Creek") != 0) {
	fprintf (stderr, "Unexpected error: sheet2() bad result place: %s.\n", results[6]);
	return  -34;
    }
    if (strncmp(results[7], "-27.86667", 9) != 0) {
	fprintf (stderr, "Unexpected error: sheet2() bad result lat: %s.\n", results[7]);
	return  -35;
    }
    if (strncmp(results[8], "151.51667", 9) != 0) {
	fprintf (stderr, "Unexpected error: sheet2() bad result lon: %s.\n", results[8]);
	return  -36;
    }
    if (strcmp(results[11], "Canal Creek") != 0) {
	fprintf (stderr, "Unexpected error: sheet2() bad result place2: %s.\n", results[11]);
	return  -37;
    }
    sqlite3_free_table (results);

    asprintf(&sql_statement, "select row_no, place, lat, lon, rowid from sheet2 WHERE row_no = 16");
    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 -38;
    }
    if ((rows != 1) || (columns != 5)) {
	fprintf (stderr, "Unexpected error: select columns bad result: %i/%i.\n", rows, columns);
	return  -39;
    }
    if (strcmp(results[0], "row_no") != 0) {
	fprintf (stderr, "Unexpected error: sheet2() bad result: %s.\n", results[0]);
	return  -40;
    }
    if (strcmp(results[6], "Canal Creek") != 0) {
	fprintf (stderr, "Unexpected error: sheet2() bad result place: %s.\n", results[6]);
	return  -41;
    }
    if (strncmp(results[7], "-27.86667", 9) != 0) {
	fprintf (stderr, "Unexpected error: sheet2() bad result lat: %s.\n", results[7]);
	return  -42;
    }
    if (strncmp(results[8], "151.51667", 9) != 0) {
	fprintf (stderr, "Unexpected error: sheet2() bad result lon: %s.\n", results[8]);
	return  -43;
    }
    sqlite3_free_table (results);

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

    ret = sqlite3_exec (db_handle, "create VIRTUAL TABLE noquote USING VirtualXL(testcase1.xls);", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "VirtualXL error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -45;
    }
    ret = sqlite3_exec (db_handle, "DROP TABLE noquote;", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "DROP TABLE error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -46;
    }
    ret = sqlite3_exec (db_handle, "create VIRTUAL TABLE noheader USING VirtualXL(\"testcase1.xls\", 0, 0);", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "VirtualXL error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -47;
    }
    ret = sqlite3_exec (db_handle, "DROP TABLE noheader;", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "DROP TABLE error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -48;
    }
    ret = sqlite3_exec (db_handle, "create VIRTUAL TABLE nofile USING VirtualXL();", NULL, NULL, &err_msg);
    if (ret != SQLITE_ERROR) {
	fprintf (stderr, "VirtualXL unexpected result: %i\n", ret);
	return -49;
    }
    sqlite3_free (err_msg);

    sqlite3_close (db_handle);
    spatialite_cleanup();
#endif	/* end FreeXL conditional */
    
    return 0;
}
Esempio n. 12
0
int main (int argc, char *argv[])
{
    FILE *fl;
    int sz = 0;
    int rd;
    int ok;
    int i;
    char tag_name[128];
    char human[8192];
    gaiaExifTagPtr pT;
    sqlite3_int64 val64;
    const char *result;
    unsigned char *blob = NULL;
    gaiaExifTagListPtr tag_list = NULL;
    double longitude;
    double latitude;

    spatialite_init (0);
    
    fl = fopen("sql_stmt_tests/DSC_1467.JPG", "rb");
    if (!fl) {
	fprintf(stderr, "cannot open EXIF-JPEG image: DSC_1467.JPG\n");
	return -1;
    }
    if (fseek(fl, 0, SEEK_END) == 0)
        sz = ftell(fl);
    if (sz <= 14) {
	fprintf(stderr, "invalid size EXIF-JPEG image: DSC_1467.JPG\n");
	return -2;
    }
    
    blob = (unsigned char *) malloc(sz);
    rewind(fl);
    rd = fread(blob, 1, sz, fl);
    if (rd != sz) {
	fprintf(stderr, "read error EXIF-JPEG image: DSC_1467.JPG\n");
	return -3;
    }
    
    tag_list = gaiaGetExifTags(blob, sz);
    if (tag_list == NULL) {
	fprintf(stderr, "cannot extract EXIF tags from JPEG image: DSC_1467.JPG\n");
	return -4;
    }

    val64 = get_pixel_x(tag_list, &ok);
    if (!ok) {
	fprintf(stderr, "DSC_1467.JPG: PixelX tag not found\n");
	return -5;
    }
    if (val64 != 2128) {
	fprintf(stderr, "DSC_1467.JPG: PixelX unexpected value: %d\n", (int)val64);
	return -6;
    }

    val64 = get_pixel_y(tag_list, &ok); 
    if (!ok) {
	fprintf(stderr, "DSC_1467.JPG: PixelY tag not found\n");
	return -7;
    }
    if (val64 != 1416) {
	fprintf(stderr, "DSC_1467.JPG: PixelY unexpected value: %d\n", (int)val64);
	return -8;
    }
  
    get_make(tag_list, &result, &ok);
    if (!ok) {
	fprintf(stderr, "DSC_1467.JPG: Make tag not found\n");
	return -9;
    }
    if (strcmp(result, "NIKON CORPORATION") != 0) {
	fprintf(stderr, "DSC_1467.JPG: Make unexpected value: %s|\n", result);
	return -10;
    };

    get_model(tag_list, &result, &ok);
    if (!ok) {
	fprintf(stderr, "DSC_1467.JPG: Model tag not found\n");
	return -11;
    }
    if (strcmp(result, "NIKON D700") != 0) {
	fprintf(stderr, "DSC_1467.JPG: Model unexpected value: %s|\n", result);
	return -12;
    };

    get_date(tag_list, &result, &ok);
    if (!ok) {
	fprintf(stderr, "DSC_1467.JPG: Date tag not found\n");
	return -13;
    }
    if (strcmp(result, "2011:03:26 11:01:13") != 0) {
	fprintf(stderr, "DSC_1467.JPG: Date unexpected value: %s|\n", result);
	return -14;
    };
            
    for (i = 0; i < gaiaGetExifTagsCount(tag_list); i++)
    {
        pT = gaiaGetExifTagByPos(tag_list, i);
        if (pT)
        {
            gaiaExifTagGetName(pT, tag_name, 128);
            gaiaExifTagGetValueType(pT);
            gaiaIsExifGpsTag(pT);
            gaiaExifTagGetValueType(pT);
            gaiaExifTagGetNumValues(pT);
            gaiaExifTagGetHumanReadable (pT, human, 8190, &ok);
        }
    }

    pT = gaiaGetExifTagById (tag_list, 0x0112);
    if (pT == NULL) {
	fprintf(stderr, "DSC_1467.JPG: tag Orientation not found: %s|\n", result);
	return -15;
    };

    pT = gaiaGetExifTagByName (tag_list, "YCbCrPositioning");
    if (pT == NULL) {
	fprintf(stderr, "DSC_1467.JPG: tag YCbCrPositioning not found: %s|\n", result);
	return -16;
    };

    for (i = 0x0000; i < 0xffff; i++)
    {
        gaiaExifTag tag;
        tag.Gps = 0;
        tag.TagId = i;
        gaiaExifTagGetName(&tag, tag_name, 128);
    }
    for (i = 0x0000; i < 0xffff; i++)
    {
        gaiaExifTag tag;
        tag.Gps = 1;
        tag.TagId = i;
        gaiaExifTagGetName(&tag, tag_name, 128);
    }

    if (blob)
        free(blob);
    if (tag_list)
        gaiaExifTagsFree(tag_list);
    fclose(fl);
       
    fl = fopen("sql_stmt_tests/DSCN0042.JPG", "rb");
    if (!fl) {
	fprintf(stderr, "cannot open EXIF-JPEG image: DSCN0042.JPG\n");
	return -100;
    }
    if (fseek(fl, 0, SEEK_END) == 0)
        sz = ftell(fl);
    if (sz <= 14) {
	fprintf(stderr, "invalid size EXIF-JPEG image: DSCN0042.JPG\n");
	return -17;
    }
    
    blob = (unsigned char *) malloc(sz);
    rewind(fl);
    rd = fread(blob, 1, sz, fl);
    if (rd != sz) {
	fprintf(stderr, "read error EXIF-JPEG image: DSCN0042.JPG\n");
	return -18;
    }
    
    tag_list = gaiaGetExifTags(blob, sz);
    if (tag_list == NULL) {
	fprintf(stderr, "cannot extract EXIF tags from JPEG image: DSCN0042.JPG\n");
	return -19;
    }

    val64 = get_pixel_x(tag_list, &ok);
    if (!ok) {
	fprintf(stderr, "DSCN0042.JPG: PixelX tag not found\n");
	return -20;
    }
    if (val64 != 640) {
	fprintf(stderr, "DSCN0042.JPG: PixelX unexpected value: %d\n", (int)val64);
	return -21;
    }

    val64 = get_pixel_y(tag_list, &ok); 
    if (!ok) {
	fprintf(stderr, "DSCN0042.JPG: PixelY tag not found\n");
	return -22;
    }
    if (val64 != 480) {
	fprintf(stderr, "DSCN0042.JPG: PixelY unexpected value: %d\n", (int)val64);
	return -23;
    }
  
    get_make(tag_list, &result, &ok);
    if (!ok) {
	fprintf(stderr, "DSCN0042.JPG: Make tag not found\n");
	return -24;
    }
    if (strcmp(result, "NIKON") != 0) {
	fprintf(stderr, "DSCN0042.JPG: Make unexpected value: %s|\n", result);
	return -25;
    };

    get_model(tag_list, &result, &ok);
    if (!ok) {
	fprintf(stderr, "DSCN0042.JPG: Model tag not found\n");
	return -26;
    }
    if (strcmp(result, "COOLPIX P6000") != 0) {
	fprintf(stderr, "DSCN0042.JPG: Model unexpected value: %s|\n", result);
	return -27;
    };

    get_date(tag_list, &result, &ok);
    if (!ok) {
	fprintf(stderr, "DSCN0042.JPG: Date tag not found\n");
	return -28;
    }
    if (strcmp(result, "2008:10:22 17:00:07") != 0) {
	fprintf(stderr, "DSCN0042.JPG: Date unexpected value: %s|\n", result);
	return -29;
    };
            
    for (i = 0; i < gaiaGetExifTagsCount(tag_list); i++)
    {
        pT = gaiaGetExifTagByPos(tag_list, i);
        if (pT)
        {
            gaiaExifTagGetName(pT, tag_name, 128);
            gaiaExifTagGetValueType(pT);
            gaiaIsExifGpsTag(pT);
            gaiaExifTagGetValueType(pT);
            gaiaExifTagGetNumValues(pT);
            gaiaExifTagGetHumanReadable (pT, human, 8190, &ok);
        }
    }

    pT = gaiaGetExifTagById (tag_list, 0x0112);
    if (pT == NULL) {
	fprintf(stderr, "DSCN0042.JPG: tag Orientation not found: %s|\n", result);
	return -30;
    };

    pT = gaiaGetExifTagByName (tag_list, "YCbCrPositioning");
    if (pT == NULL) {
	fprintf(stderr, "DSCN0042.JPG: tag YCbCrPositioning not found: %s|\n", result);
	return -31;
    };

    for (i = 0x0000; i < 0xffff; i++)
    {
        gaiaExifTag tag;
        tag.Gps = 0;
        tag.TagId = i;
        gaiaExifTagGetName(&tag, tag_name, 128);
    }
    for (i = 0x0000; i < 0xffff; i++)
    {
        gaiaExifTag tag;
        tag.Gps = 1;
        tag.TagId = i;
        gaiaExifTagGetName(&tag, tag_name, 128);
    }

    if (!gaiaGetGpsLatLong(blob, sz, human, 8192)) {
	fprintf(stderr, "cannot extract GPS coords from JPEG image: DSCN0042.JPG\n");
	return -32;
    }
    if (strcmp(human, "N 43.00 27.00 52.04 / E 11.00 52.00 53.32") != 0) {
	fprintf(stderr, "DSCN0042.JPG: GPS coords unexpected value: %s|\n", human);
	return -33;
    };
    if (!gaiaGetGpsLatLong(blob, sz, human, 20)) {
	fprintf(stderr, "cannot extract GPS coords(20) from JPEG image: DSCN0042.JPG\n");
	return -34;
    }
    if (strcmp(human, "N 43.00 27.00 52.04 ") != 0) {
	fprintf(stderr, "DSCN0042.JPG: GPS coords(20) unexpected value: %s|\n", human);
	return -35;
    };
    if (!gaiaGetGpsCoords(blob, sz, &longitude, &latitude)) {
	fprintf(stderr, "cannot extract GPS long/lat from JPEG image: DSCN0042.JPG\n");
	return -36;
    }
    if (longitude != 11.881478 || latitude != 43.464455) {
	fprintf(stderr, "DSCN0042.JPG: GPS long/lat unexpected values: %1.9f %1.9f|\n", longitude, latitude);
	return -37;
    };

    if (blob)
        free(blob);
    if (tag_list)
        gaiaExifTagsFree(tag_list);
    fclose(fl);
       
    fl = fopen("sql_stmt_tests/La_folla_durante_il_Palio.jpg", "rb");
    if (!fl) {
	fprintf(stderr, "cannot open EXIF-JPEG image: La_folla_durante_il_Palio.jpg\n");
	return -50;
    }
    if (fseek(fl, 0, SEEK_END) == 0)
        sz = ftell(fl);
    if (sz <= 14) {
	fprintf(stderr, "invalid size EXIF-JPEG image: La_folla_durante_il_Palio.jpg\n");
	return -51;
    }
    
    blob = (unsigned char *) malloc(sz);
    rewind(fl);
    rd = fread(blob, 1, sz, fl);
    if (rd != sz) {
	fprintf(stderr, "read error EXIF-JPEG image: La_folla_durante_il_Palio.jpg\n");
	return -52;
    }
    
    tag_list = gaiaGetExifTags(blob, sz);
    if (tag_list == NULL) {
	fprintf(stderr, "cannot extract EXIF tags from JPEG image: La_folla_durante_il_Palio.jpg\n");
	return -53;
    }

    val64 = get_pixel_x(tag_list, &ok);
    if (!ok) {
	fprintf(stderr, "La_folla_durante_il_Palio.jpg: PixelX tag not found\n");
	return -54;
    }
    if (val64 != 1280) {
	fprintf(stderr, "La_folla_durante_il_Palio.jpg: PixelX unexpected value: %d\n", (int)val64);
	return -55;
    }

    val64 = get_pixel_y(tag_list, &ok); 
    if (!ok) {
	fprintf(stderr, "La_folla_durante_il_Palio.jpg: PixelY tag not found\n");
	return -56;
    }
    if (val64 != 960) {
	fprintf(stderr, "La_folla_durante_il_Palio.jpg: PixelY unexpected value: %d\n", (int)val64);
	return -57;
    }
  
    get_make(tag_list, &result, &ok);
    if (!ok) {
	fprintf(stderr, "La_folla_durante_il_Palio.jpg: Make tag not found\n");
	return -58;
    }
    if (strcmp(result, "Nokia") != 0) {
	fprintf(stderr, "La_folla_durante_il_Palio.jpg: Make unexpected value: %s|\n", result);
	return -59;
    };

    get_model(tag_list, &result, &ok);
    if (!ok) {
	fprintf(stderr, "La_folla_durante_il_Palio.jpg: Model tag not found\n");
	return -60;
    }
    if (strcmp(result, "6630") != 0) {
	fprintf(stderr, "La_folla_durante_il_Palio.jpg: Model unexpected value: %s|\n", result);
	return -61;
    };
    
    for (i = 0; i < gaiaGetExifTagsCount(tag_list); i++)
    {
        pT = gaiaGetExifTagByPos(tag_list, i);
        if (pT)
        {
            gaiaExifTagGetName(pT, tag_name, 128);
            gaiaExifTagGetValueType(pT);
            gaiaIsExifGpsTag(pT);
            gaiaExifTagGetValueType(pT);
            gaiaExifTagGetNumValues(pT);
            gaiaExifTagGetHumanReadable (pT, human, 8190, &ok);
        }
    }

    for (i = 0x0000; i < 0xffff; i++)
    {
        gaiaExifTag tag;
        tag.Gps = 0;
        tag.TagId = i;
        gaiaExifTagGetName(&tag, tag_name, 128);
    }

    if (blob)
        free(blob);
    if (tag_list)
        gaiaExifTagsFree(tag_list);
    fclose(fl);
    
    spatialite_cleanup();
    
    return 0;
}
int main (int argc, char *argv[])
{
    sqlite3 *db_handle = NULL;
    char *sql_statement;
    int ret;
    char *err_msg = NULL;
    int i;
    char **results;
    int rows;
    int columns;

    spatialite_init (0);

    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;
    }
    
    ret = sqlite3_exec (db_handle, "create VIRTUAL TABLE dbftest USING VirtualDBF(\"shp/merano-3d/roads.dbf\", 'CP1252');", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "VirtualDBF error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -2;
    }
    
    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 -3;
    }

    ret = sqlite3_exec (db_handle, "create VIRTUAL TABLE dbftest USING VirtualDBF('shp/merano-3d/roads.dbf', \"CP1252\");", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "VirtualDBF error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -4;
    }
    
    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 -5;
    }

    ret = sqlite3_exec (db_handle, "create VIRTUAL TABLE dbftest USING VirtualDBF('shp/merano-3d/roads.dbf', CP1252);", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "VirtualDBF error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -6;
    }
    
    for (i = 0; steps[i].sql; ++i) {
	ret = sqlite3_get_table (db_handle, steps[i].sql, &results, &rows, &columns, &err_msg);
	if (ret != SQLITE_OK) {
	    fprintf (stderr, "Error: %s\n", err_msg);
	    sqlite3_free (err_msg);
	    return -7;
	}
	if (rows != steps[i].num_rows) {
	    fprintf (stderr, "Unexpected num of rows for test %i: %i.\n", i, rows);
	    return  -8;
	}
	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 -9;
    }

    sqlite3_close (db_handle);
    spatialite_cleanup();
    sqlite3_reset_auto_extension();
    
    return 0;
}
Esempio n. 14
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;

    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 db: %s\n", sqlite3_errmsg (handle));
        sqlite3_close(handle);
        return -1;
    }

    ret = sqlite3_exec (handle, "SELECT InitSpatialMetadata()", 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();
#endif	/* end FreeXL conditional */

    return 0;
}
int main (int argc, char *argv[])
{
    sqlite3 *db_handle = NULL;
    char *sql_statement;
    int ret;
    char *err_msg = NULL;
    int i;
    char **results;
    int rows;
    int columns;

    spatialite_init (0);

    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;
    }
    
    ret = sqlite3_exec (db_handle, "create VIRTUAL TABLE shapetest USING VirtualShape(\"shapetest1\", UTF-8, 4326);", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf (stderr, "VirtualShape error: %s\n", err_msg);
	sqlite3_free (err_msg);
	return -2;
    }

    asprintf(&sql_statement, "select testcase1, testcase2, AsText(Geometry) from shapetest 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 != 3)) {
	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[3], "windward") != 0) {
	fprintf (stderr, "Unexpected error: windward bad result: %s.\n", results[3]);
	return  -6;
    }
    if (strcmp(results[4], "2") != 0) {
	fprintf (stderr, "Unexpected error: integer() bad result: %s.\n", results[4]);
	return  -7;
    }
    if (strcmp(results[5], "POINT(3480766.311245 4495355.740524)") != 0) {
	fprintf (stderr, "Unexpected error: geometry() bad result: %s.\n", results[5]);
	return  -8;
    }
    sqlite3_free_table (results);

    asprintf(&sql_statement, "select testcase1, testcase2, AsText(Geometry) from shapetest 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 != 3)) {
	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[3], "windward") != 0) {
	fprintf (stderr, "Unexpected error: windward bad result: %s.\n", results[3]);
	return  -13;
    }
    if (strcmp(results[4], "2") != 0) {
	fprintf (stderr, "Unexpected error: integer() bad result: %s.\n", results[4]);
	return  -14;
    }
    if (strcmp(results[5], "POINT(3480766.311245 4495355.740524)") != 0) {
	fprintf (stderr, "Unexpected error: geometry() bad result: %s.\n", results[5]);
	return  -15;
    }
    sqlite3_free_table (results);

    asprintf(&sql_statement, "select testcase1, testcase2, AsText(Geometry) from shapetest 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 != 3)) {
	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[3], "orde lees") != 0) {
	fprintf (stderr, "Unexpected error: orde lees bad result: %s.\n", results[3]);
	return  -19;
    }
    if (strcmp(results[4], "20") != 0) {
	fprintf (stderr, "Unexpected error: integer2() bad result: %s.\n", results[4]);
	return  -20;
    }
    if (strcmp(results[5], "POINT(3482470.825574 4495691.054818)") != 0) {
	fprintf (stderr, "Unexpected error: geometry() bad result: %s.\n", results[5]);
	return  -21;
    }
    sqlite3_free_table (results);

    asprintf(&sql_statement, "select testcase1, testcase2, AsText(Geometry) from shapetest 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 != 3)) {
	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[3], "orde lees") != 0) {
	fprintf (stderr, "Unexpected error: orde lees2 bad result: %s.\n", results[3]);
	return  -25;
    }
    if (strcmp(results[4], "20") != 0) {
	fprintf (stderr, "Unexpected error: integer4() bad result: %s.\n", results[4]);
	return  -26;
    }
    if (strcmp(results[5], "POINT(3482470.825574 4495691.054818)") != 0) {
	fprintf (stderr, "Unexpected error: geometry() bad result: %s.\n", results[5]);
	return  -27;
    }
    sqlite3_free_table (results);

    asprintf(&sql_statement, "select testcase1, testcase2, AsText(Geometry) from shapetest 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 != 3)) {
	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[3], "orde lees") != 0) {
	fprintf (stderr, "Unexpected error: orde lees3 bad result: %s.\n", results[3]);
	return  -31;
    }
    if (strcmp(results[4], "20") != 0) {
	fprintf (stderr, "Unexpected error: integer5() bad result: %s.\n", results[4]);
	return  -32;
    }
    if (strcmp(results[5], "POINT(3482470.825574 4495691.054818)") != 0) {
	fprintf (stderr, "Unexpected error: geometry() bad result: %s.\n", results[5]);
	return  -33;
    }
    sqlite3_free_table (results);

    asprintf(&sql_statement, "select testcase1, testcase2, AsText(Geometry) from shapetest 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 != 3)) {
	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[3], "orde lees") != 0) {
	fprintf (stderr, "Unexpected error: orde lees bad result: %s.\n", results[3]);
	return  -37;
    }
    if (strcmp(results[4], "20") != 0) {
	fprintf (stderr, "Unexpected error: integer() bad result: %s.\n", results[4]);
	return  -38;
    }
    if (strcmp(results[5], "POINT(3482470.825574 4495691.054818)") != 0) {
	fprintf (stderr, "Unexpected error: geometry() bad result: %s.\n", results[5]);
	return  -39;
    }
    sqlite3_free_table (results);

    asprintf(&sql_statement, "select testcase1, testcase2, AsText(Geometry) from shapetest 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 != 3)) {
	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[3], "orde lees") != 0) {
	fprintf (stderr, "Unexpected error: orde lees bad result: %s.\n", results[3]);
	return  -43;
    }
    if (strcmp(results[4], "20") != 0) {
	fprintf (stderr, "Unexpected error: integer() bad result: %s.\n", results[4]);
	return  -44;
    }
    if (strcmp(results[5], "POINT(3482470.825574 4495691.054818)") != 0) {
	fprintf (stderr, "Unexpected error: geometry() bad result: %s.\n", results[5]);
	return  -45;
    }
    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, AsText(Geometry) from shapetest 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 != 3)) {
	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[3], "windward") != 0) {
	fprintf (stderr, "Unexpected error: windward bad result: %s.\n", results[3]);
	return  -51;
    }
    if (strcmp(results[4], "2") != 0) {
	fprintf (stderr, "Unexpected error: integer() bad result: %s.\n", results[4]);
	return  -52;
    }
    if (strcmp(results[5], "POINT(3480766.311245 4495355.740524)") != 0) {
	fprintf (stderr, "Unexpected error: geometry() bad result: %s.\n", results[5]);
	return  -53;
    }
    sqlite3_free_table (results);

    ret = sqlite3_exec (db_handle, "DELETE FROM shapetest 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, AsText(Geometry) from shapetest 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 != 3)) {
	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[3], "windward") != 0) {
	fprintf (stderr, "Unexpected error: windward bad result: %s.\n", results[3]);
	return  -57;
    }
    if (strcmp(results[4], "2") != 0) {
	fprintf (stderr, "Unexpected error: integer() bad result: %s.\n", results[4]);
	return  -58;
    }
    if (strcmp(results[5], "POINT(3480766.311245 4495355.740524)") != 0) {
	fprintf (stderr, "Unexpected error: geometry() bad result: %s.\n", results[5]);
	return  -59;
    }
    sqlite3_free_table (results);

    asprintf(&sql_statement, "select testcase1, testcase2, AsText(Geometry) from shapetest 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 != 3)) {
	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[3], "windward") != 0) {
	fprintf (stderr, "Unexpected error: windward bad result: %s.\n", results[3]);
	return  -57;
    }
    if (strcmp(results[4], "2") != 0) {
	fprintf (stderr, "Unexpected error: integer() bad result: %s.\n", results[4]);
	return  -58;
    }
    if (strcmp(results[5], "POINT(3480766.311245 4495355.740524)") != 0) {
	fprintf (stderr, "Unexpected error: geometry() bad result: %s.\n", results[5]);
	return  -59;
    }
    sqlite3_free_table (results);

    asprintf(&sql_statement, "select testcase1, testcase2, AsText(Geometry) from shapetest 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 != 3)) {
	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[3], "windward") != 0) {
	fprintf (stderr, "Unexpected error: windward bad result: %s.\n", results[3]);
	return  -63;
    }
    if (strcmp(results[4], "2") != 0) {
	fprintf (stderr, "Unexpected error: integer() bad result: %s.\n", results[4]);
	return  -64;
    }
    if (strcmp(results[5], "POINT(3480766.311245 4495355.740524)") != 0) {
	fprintf (stderr, "Unexpected error: geometry() bad result: %s.\n", results[5]);
	return  -65;
    }
    sqlite3_free_table (results);

    asprintf(&sql_statement, "select testcase1, testcase2, AsText(Geometry) from shapetest 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 != 3)) {
	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[3], "windward") != 0) {
	fprintf (stderr, "Unexpected error: windward bad result: %s.\n", results[3]);
	return  -69;
    }
    if (strcmp(results[4], "2") != 0) {
	fprintf (stderr, "Unexpected error: integer() bad result: %s.\n", results[4]);
	return  -70;
    }
    if (strcmp(results[5], "POINT(3480766.311245 4495355.740524)") != 0) {
	fprintf (stderr, "Unexpected error: geometry() bad result: %s.\n", results[5]);
	return  -71;
    }
    sqlite3_free_table (results);

    asprintf(&sql_statement, "select testcase1, testcase2, AsText(Geometry) from shapetest 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 != 3)) {
	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[3], "windward") != 0) {
	fprintf (stderr, "Unexpected error: windward bad result: %s.\n", results[3]);
	return  -75;
    }
    if (strcmp(results[4], "2") != 0) {
	fprintf (stderr, "Unexpected error: integer() bad result: %s.\n", results[4]);
	return  -76;
    }
    if (strcmp(results[5], "POINT(3480766.311245 4495355.740524)") != 0) {
	fprintf (stderr, "Unexpected error: geometry() bad result: %s.\n", results[5]);
	return  -77;
    }
    sqlite3_free_table (results);
    
    asprintf(&sql_statement, "select testcase1, testcase2, AsText(Geometry) from shapetest 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 != 3)) {
	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[3], "orde lees") != 0) {
	fprintf (stderr, "Unexpected error: orde lees bad result: %s.\n", results[3]);
	return  -81;
    }
    if (strcmp(results[4], "20") != 0) {
	fprintf (stderr, "Unexpected error: integer() bad result: %s.\n", results[4]);
	return  -82;
    }
    if (strcmp(results[5], "POINT(3482470.825574 4495691.054818)") != 0) {
	fprintf (stderr, "Unexpected error: geometry() bad result: %s.\n", results[5]);
	return  -83;
    }
    sqlite3_free_table (results);

    asprintf(&sql_statement, "select testcase1, testcase2, AsText(Geometry) from shapetest 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 != 3)) {
	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[3], "orde lees") != 0) {
	fprintf (stderr, "Unexpected error: orde lees bad result: %s.\n", results[3]);
	return  -87;
    }
    if (strcmp(results[4], "20") != 0) {
	fprintf (stderr, "Unexpected error: integer() bad result: %s.\n", results[4]);
	return  -88;
    }
    if (strcmp(results[5], "POINT(3482470.825574 4495691.054818)") != 0) {
	fprintf (stderr, "Unexpected error: geometry() bad result: %s.\n", results[5]);
	return  -89;
    }
    sqlite3_free_table (results);

    asprintf(&sql_statement, "select PKUID, testcase1, testcase2, AsText(Geometry) from shapetest 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 != 4)) {
	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[4], "1") != 0) {
	fprintf (stderr, "Unexpected error: windward PK bad result: %s.\n", results[4]);
	return  -93;
    }
    if (strcmp(results[5], "windward") != 0) {
	fprintf (stderr, "Unexpected error: windward bad result: %s.\n", results[5]);
	return  -94;
    }
    sqlite3_free_table (results);

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

    sqlite3_close (db_handle);
    spatialite_cleanup();
    sqlite3_reset_auto_extension();
    
    return 0;
}