/// <summary> /// Loads mod_spatialite.dll on the given connection /// </summary> public static void Load(SQLiteConnection conn) { lock (Lock) { //Need to work out where the file is and add it to the path so it can load all the other dlls too if (!_haveSetPath) { var spatialitePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), (Environment.Is64BitProcess ? "x64" : "x86"), "spatialite"); Environment.SetEnvironmentVariable("PATH", spatialitePath + ";" + Environment.GetEnvironmentVariable("PATH")); _haveSetPath = true; } } conn.LoadExtension("mod_spatialite.dll"); }
static void Main(string[] args) { string mod_spatialite_folderPath = "mod_spatialite-4.3.0a-win-amd64"; if (is64bitProcess()) { Console.WriteLine("64bit process"); mod_spatialite_folderPath = "mod_spatialite-4.3.0a-win-amd64"; } else if(is32bitProcess()) { Console.WriteLine("32bit process"); mod_spatialite_folderPath = "mod_spatialite-4.3.0a-win-x86"; } //using relative path, cannot use absolute path, dll load will fail //string mod_spatialite_dllPath = @"mod_spatialite-4.3.0a-win-amd64\mod_spatialite"; string path = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.Machine) + ";" + mod_spatialite_folderPath; Environment.SetEnvironmentVariable("Path", path, EnvironmentVariableTarget.Process); string sqlitePath = "_BCC_replication.sqlite"; //select 'geometry::STGeomFromWKB(0x' || hex(ST_AsBinary(geometry)) || ', 28356) ' as geometry2 from qpp_airport_ols; string sqliteConnectionString = getSqliteV3ConnectionString(sqlitePath); using (var sqliteConnection = new SQLiteConnection(sqliteConnectionString)) { sqliteConnection.Open(); Console.WriteLine("Load-ing mod_spatialite"); string mod_spatialite_dllPath = mod_spatialite_folderPath + @"\mod_spatialite"; sqliteConnection.LoadExtension(mod_spatialite_dllPath); Console.WriteLine("Load-ed mod_spatialite"); sqliteConnection.Execute("update qpp_airport_ols set lga_code = 111122 where ogc_fid = 2;"); } Console.ReadLine(); }