1

I am attempting to do a few short spatial queries using a spatialite database from clojure. I am using the xerial sqlite-jdbc connector to connect.

My attempt at loading the spatialite extension fails with a "not authorized" error:

(sql/with-connection db
  (try
    (sql/with-query-results foo
        ["SELECT load_extension('/usr/local/lib/libspatialite.dylib');"]
      (dorun (map #(println foo))))
    (catch Exception e (print e))))

#<SQLException java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (not authorized)>#<SQLException java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (not authorized)>

This page describes a method in Java wherein you instantiate a SQLiteConfig object, set some attributes, and then pass the configuration object when setting up the database connection.

Being new to Clojure, this is breaking my brain. Can anyone provide an example of connecting to a spatialite-enable sqlite database?

Peter
  • 4,219
  • 4
  • 28
  • 40

1 Answers1

0

Try by including the below key value in the db map.

{
  <other key/val>
  :enable_load_extension true
}
Ankur
  • 33,367
  • 2
  • 46
  • 72
  • After adding this key value, the Clojure process tanks and disconnects me from my REPL without any sign of a stack trace. Looks like I need to figure out how to do some lower level debugging. – Peter Aug 02 '12 at 17:45
  • Running outside of SLIME gives me an error: Invalid memory access of location 0x608500800 rip=0x7fff89fa6bd9 Exception in thread "Thread-2" java.lang.Exception: Process exited with 139 ...followed by a long java stack trace. – Peter Aug 02 '12 at 17:58