2

I want to create a new sqlite3 database. Taking a look at the examples of clsql I found this scenario. Which implies that

(ql:quickload "clsql")
(ql:quickload "clsql-sqlite3")

(uffi:def-function
    ("create_iso_8859_15_ci_collation" create-coll)
    ((db sqlite3:sqlite3-db))
  :returning :int
  :module "sqlite3-utils")

(clsql:connect (list "home/user/test.db" #'create-coll) :database-type :sqlite3)

should create a new database. But instead I get:

The alien function "create_iso_8859_15_ci_collation" is undefined. [Condition of type SB-KERNEL::UNDEFINED-ALIEN-FUNCTION-ERROR]

How can I create a new sqlite3 database from scratch?

Sim
  • 4,199
  • 4
  • 39
  • 77
  • Is the database file and the folder it resides in writable? Check permissions. – Colonel Thirty Two Jan 10 '15 at 18:01
  • @ColonelThirtyTwo it is my home dir. I further also already tested creating the file beforehand. open/close does not have any problems. Therefore the permissions should fit as long as clsql does not change user/privileges which would be weird. – Sim Jan 10 '15 at 18:01
  • Did you try creating db as described here http://www.sqlite.org/quickstart.html ? – Vadim Kirilchuk Jan 10 '15 at 18:12
  • @VadimKirilchuk yes it works perfectly. Though I want to do it automatized using the clsql facilities as they should support it. – Sim Jan 10 '15 at 18:30
  • Does it help if you specify absolute path, i.e. /home/username/test.db ? – Vadim Kirilchuk Jan 10 '15 at 18:45
  • @VadimKirilchuk yes it actually changes the error. I will update the question – Sim Jan 10 '15 at 18:46
  • Ok, now we need to find the function.. – Vadim Kirilchuk Jan 10 '15 at 18:53
  • 1
    May it be that it is located here ;;;; Load sqlite3-utils.so library. See Makefile for library creation. (unless (uffi:load-foreign-library "/usr/lib/clsql/sqlite3-utils.so" :module "sqlite3-utils" :supporting-libraries '("c")) (error "Unable to load foreign library")) ? – Vadim Kirilchuk Jan 10 '15 at 18:55
  • yes, that is the solution. I expected the library to be already loaded but it is not. Therefore one has to compile the respective c file and then load the library. I will accept this as an answer but I'd prefer a more generic solution not involving me to compile the library by myself and load it (as this will hardly be portable to another machine) – Sim Jan 10 '15 at 19:00
  • You could just 'like' my comments and wait for an answer. I am not lisp clsql specialist :) Only java, only hardcore. – Vadim Kirilchuk Jan 10 '15 at 19:04
  • Can you just use (clsql:connect '("/path/to/your/database/data.sqlite3") :database-type :sqlite3) without init function? Does it create empty db? – Vadim Kirilchuk Jan 10 '15 at 19:11
  • @VadimKirilchuk yes that actually works. I feel stupid for not trying that. I expected that the file has to be initialized first. Please just put your comment as an answer so I can give you credit for being smarter than me. – Sim Jan 10 '15 at 19:16

1 Answers1

5

Just use

(clsql:connect '("/path/to/your/database/data.sqlite3") 
               :database-type :sqlite3)

without init function.

Sim
  • 4,199
  • 4
  • 39
  • 77
Vadim Kirilchuk
  • 3,532
  • 4
  • 32
  • 49