ジオメトリ(POINT、LINE、POLYGON)をsqlite DB(spatialite)のテーブルに挿入しようとしていますが、ジオメトリの列は常にNULLです。spatialiteのジオメトリを挿入すると常にNULLが挿入されますC#
INSERT後のDB内の情報。
どのようにすべき
:
public SQLiteConnection create_Open_SpatilaDB(string dbName)
{
try
{
dbName += DateTime.Now.ToString("ddMMyyyyHHmmssff") + ".sqlite";
string ruta = HttpContext.Current.Server.MapPath("/Uploads/" + dbName);
string strConexion = "Data Source=" + ruta + ";Version=3;";
SQLiteConnection conexion = null;
if (!File.Exists(ruta))
{
// create the connection
conexion = new SQLiteConnection(strConexion);
//Abrir la conexión
conexion.Open();
//Load the lib
conexion.EnableExtensions(true);
conexion.LoadExtension("libspatialite-2.dll");
//Create tables
string SQL = "CREATE TABLE AppVersion ("
+ " versionCode INTEGER NOT NULL PRIMARY KEY,"
+ " state INTEGER NOT NULL);";
SQLiteCommand cmd = new SQLiteCommand(SQL, conexion);
cmd.ExecuteNonQuery();
SQL = "CREATE TABLE Table1 ("
+ " Codigo TEXT NOT NULL PRIMARY KEY,"
+ " Nombre TEXT,"
+ " Geometry POLYGON);";
cmd = new SQLiteCommand(SQL, conexion);
cmd.ExecuteNonQuery();
SQL = "CREATE TABLE Table2("
+ " Codigo TEXT NOT NULL PRIMARY KEY,"
+ " Nombre TEXT NOT NULL,"
+ " Geometry POIN);";
cmd = new SQLiteCommand(SQL, conexion);
cmd.ExecuteNonQuery();
.
.
.
}
else
{
conexion = new SQLiteConnection(strConexion);
conexion.Open();
conexion.EnableExtensions(true);
conexion.LoadExtension("libspatialite-2.dll");
}
return conexion;
}
catch (Exception)
{
throw;
}
}
:
文字列のSQLの結果はOKですが、私はこれは、C#の私のコードです
INSERT INTO Table1(Codigo, Nombre, Geometry) VALUES('1','Andalucia',GeomFromText('POLYGON((-75.8396284742612 8.39962954808519, ..., -75.8396284742612 8.39962954808519))', 4326));
INSERT INTO Table2(Codigo, Nombre, Geometry) VALUES('1','Andalucia',GeomFromText('POINT(-75.8361480385065 8.40883548152381)', 4326));
を使用しています
ここに私は情報を挿入しています:
public void insertInfo(SQLiteConnection conexion)
{
try
{
string SQL = "BEGIN";
SQLiteCommand cmd = new SQLiteCommand(SQL, conexion);
cmd.ExecuteNonQuery();
//Insert info table1
List<Table1> list = getInfoTable1();
foreach (Table1 item in list)
{
SQL = "INSERT INTO Table1("
+ " Codigo,"
+ " Nombre,"
+ " Geometry) VALUES("
+ "'" + item.Codigo + "',"
+ "'" + item.Nombre + "',"
+ "GeomFromText(" + item.geom + "));";
cmd = new SQLiteCommand(SQL, conexion);
cmd.ExecuteNonQuery();
}
//Insert info table1
List<Table2> list = getInfoTable2();
foreach (Table2 item in list)
{
SQL = "INSERT INTO Table2("
+ " Codigo,"
+ " Nombre,"
+ " Geometry) VALUES("
+ "'" + item.Codigo + "',"
+ "'" + item.Nombre + "',"
+ "GeomFromText(" + item.geom + "));";
cmd = new SQLiteCommand(SQL, conexion);
cmd.ExecuteNonQuery();
}
.
.
.
SQL = "COMMIT";
cmd = new SQLiteCommand(SQL, conexion);
cmd.ExecuteNonQuery();
}
catch (Exception)
{
throw;
}
}