Hi Olivier,
correctly writing a prepared SQL statement requires some precautions,
and you must always carefully evaluate all consequences of binding
values at run time.
just a quick example; we'll start first using spatialite_gui, so to
check our basic SQL statements:
CREATE TABLE olivier (
id INTEGER PRIMARY KEY AUTOINCREMENT);
SELECT AddGeometryColumn('olivier', 'geom', 2154, 'POINT', 'XY');
INSERT INTO olivier VALUES (NULL,
ST_GeomFromText('POINT(848678.075879837 6408754.56379608)',2154));
all right, anything works as expected, so we can now pass to
test few prepared statements (I used a simple C program, but
you can easily replicate under VB):
test #1:
==============================================
sql = "INSERT INTO olivier (id, geom) VALUES (?, ?)";
sqlite3_bind_null(stmt, 1);
sqlite3_bind_text(stmt, 2,
"GeomFromText ('POINT (848678.075879837 6408754.56379608)',2154)",
-1, SQLITE_STATIC);
$ error: olivier.geom violates Geometry constraint [geom-type or SRID
not allowed]
test #2:
==============================================
sql = "INSERT INTO olivier (id, geom) VALUES (?, GeomFromText (?,
2154))";
sqlite3_bind_null(stmt, 1);
sqlite3_bind_text(stmt, 2,
"POINT (848678.075879837 6408754.56379608)",
-1, SQLITE_STATIC);
$ success
test #3:
==============================================
sql = "INSERT INTO olivier (id, geom) VALUES (?, GeomFromText ('POINT(?
?)', 2154))";
sqlite3_bind_null(stmt, 1);
sqlite3_bind_double(stmt, 2, 848678.075879837);
sqlite3_bind_double(stmt, 3, 6408754.56379608);
$ success
comments:
=========================
both test#2 and test#3 nicely work because we are correctly informing
the SQL engine that we intend to use an SQL function named
ST_GeomFromText(),
and this function must accept dynamic arguments.
test#1 will fail because in this case the SQL engine is unaware that
we intend using a SQL function, and consequently it will handle the
corresponding argument just as a plain text string.
in other words, from a pure SQL perspective, the following statement
will be effectively executed:
INSERT INTO olivier VALUES (NULL,
'ST_GeomFromText(''POINT(848678.075879837
6408754.56379608)'',2154)');
as you can easily check using spatialite_gui, such a malformed
statement
will cause the same violation of Geometry constraints.
bye Sandro