[Larceny-users] sqlite3 FFI
Felix Klock
felixluser at pnkfx.org
Sat May 31 10:17:25 EDT 2008
On May 31, 2008, at 10:07 AM, Felix Klock wrote:
>
> On May 30, 2008, at 10:56 PM, Peter Keller wrote:
>
>> Hello,
>>
>> I have another question, if I may ask:
>>
>> in my sqlite3 library, I have this:
>>
>> (define-c-info (include<> "sqlite3.h")
>> (const SQLITE_INTEGER int "SQLITE_INTEGER")
>> (const SQLITE_FLOAT int "SQLITE_FLOAT")
>> (const SQLITE_BLOB int "SQLITE_BLOB")
>> (const SQLITE_TEXT int "SQLITE_TEXT"))
>>
>> and then later something like this:
>>
>> (define sqlite3-column
>> (lambda (stmt colid)
>> (case (sqlite3-column-type stmt colid)
>> ((SQLITE_INTEGER)
>> (sqlite3-column-int stmt colid))
>> ((SQLITE_TEXT)
>> (sqlite3-column-text stmt colid))
>> (else
>> 'oops)))) ;; <- obviously this is still test code!
>>
>> It looks like the SQLITE_INTEGER and SQLITE_TEXT in the sqlite3-
>> column
>> function are not available to me (as the code simply doesn't work and
>> I get 'oops all the time) while in the library codes. If I replace
>> them
>> with the real constants 1 and 3 respectively, or use SQLITE_INTEGER
>> and
>> SQLITE_TEXT in a piece of code which imports the sqlite3 library,
>> then
>> sqlite3-column behaves properly.
>>
>> Any ideas?
>
> Are you sure you mean to use Scheme's case special form in the above?
>
> That is, is (sqlite3-column-type stmt colid) going to produce a
> Symbol, or an Integer? If it produces a Symbol, then your case
> expression might work. If it produces an Integer, then you will never
> get anything other than 'oops back.
One more thing: if you do want to get symbols instead of integers,
there is another library, foreign-cenums, that is a derivative of the
foreign-ctools library but provides C enum values as symbols rather
than integers.
(It does this by internally keeping a table mapping between the
integers produced by define-c-info and the symbols you provide to the
define-c-enum or define-c-enum-set special forms. The code isn't
anything terribly special and so you may be better off sticking with
define-c-info, but I thought I should point it out just in case you do
want to use symbols instead of global variables or integers for the
SQLITE constants.)
-Felix
More information about the Larceny-users
mailing list