[racket] (sqlite3-connect) does not survive "raco distribute" on Windows, saying "sqlite3_open: implementation not found"

From: Dmitry Pavlov (dpavlov at ipa.nw.ru)
Date: Wed Sep 25 09:30:10 EDT 2013

Ryan,

After some short research, I figured that the following
small patch will fix the issue:

diff --git a/ffi.rkt.bk b/ffi.rkt
index c94aefb..1f610fb 100644
--- a/ffi.rkt.bk
+++ b/ffi.rkt
@@ -7,17 +7,17 @@
  (provide (all-from-out "ffi-constants.rkt")
           (protect-out (all-defined-out)))

-(define sqlite-lib
-  (case (system-type)
-    [(windows) (ffi-lib "sqlite3.dll" #:fail (lambda () #f))]
-    [else (ffi-lib "libsqlite3" '("0" #f) #:fail (lambda () #f))]))
-
  ;; raco distribute should include Racket's sqlite3 if present
  (define-runtime-path _sqlite-lib-for-distribute
    (case (system-type)
      [(windows) '(so "sqlite3")]
      [else '(so "libsqlite3")]))

+(define sqlite-lib
+  (case (system-type)
+    [(windows) (ffi-lib _sqlite-lib-for-distribute #:fail (lambda () #f))]
+    [else (ffi-lib _sqlite-lib-for-distribute '("0" #f) #:fail (lambda 
() #f))]))
+
  (define-ffi-definer define-sqlite
    sqlite-lib
    #:default-make-fail make-not-available)


Regards,

Dmitry


On 09/24/2013 06:52 PM, Dmitry Pavlov wrote:
> Ryan,
>
> I just downloaded and installed the Racket nightly build from here:
> http://www.cs.utah.edu/plt/snapshots/current/installers/racket-5.90.0.9-i386-win32.exe
>
> (I removed the old installation completely before installing
> the nightly build)
>
> The nightly build does seem to contain your changes in
> db/private/sqlite3/ffi.rkt
> which were supposed to fix the problem.
>
> However, it does not seem to work...
> I ran the same test with mytable.rkt and it has the same problem
> as before. Could you please look into that?
>
> Regards,
>
> Dmitry
>
>
> On 09/13/2013 10:02 PM, Ryan Culpepper wrote:
>> Thanks, fixed.
>>
>> Ryan
>>
>>
>> On 09/13/2013 01:20 PM, Matthew Flatt wrote:
>>> That's the right idea, but the "libsqlite3" is also needed for Mac OS X
>>> PPC.
>>>
>>> I think that
>>>
>>>   (define-runtime-path sqlite-path
>>>     (case (system-type)
>>>       [(windows) '(so "sqlite3")]
>>>       [else '(so "libsqlite3")]))
>>>
>>> is probably best, along the same lines as `openssl/libcrypto`.
>>>
>>> At Fri, 13 Sep 2013 13:17:27 -0400, Ryan Culpepper wrote:
>>>> I've pushed what I believe is a fix. I think the issue is that raco
>>>> distribute needs to bundle the Racket copy of sqlite3.dll on Windows,
>>>> since it's not a system library. Here's the code:
>>>>
>>>> ;; On Windows, raco distribute should include the local sqlite3.dll;
>>>> ;; other platforms have libsqlite3 as system library.
>>>> (define-runtime-path-list _sqlite-libs-for-distribute
>>>>     (case (system-type)
>>>>       [(windows) '((so "sqlite3.dll"))]
>>>>       [else '()]))
>>>>
>>>> Matthew: does that look right and safe for cross-platform zo
>>>> compilation?
>>>>
>>>> Ryan
>>>>
>>>>
>>>> On 09/13/2013 12:13 PM, Dmitry Pavlov wrote:
>>>>> Hello,
>>>>>
>>>>> [I actually filed a bug report, but have not received
>>>>> a confirmation, and decided to write here as well.]
>>>>>
>>>>> A program does a call to (sqlite3-connect). The program works well
>>>>> itself, and it works well after being translated into an executable
>>>>> by "raco exe", but "raco distribute" breaks it.
>>>>>
>>>>> The bug reproduces only on Windows; on Linux everything works fine.
>>>>>
>>>>>
>>>>> File mytable.rkt:
>>>>>
>>>>> #lang racket
>>>>>
>>>>> (require db)
>>>>> (define path "mytable.db")
>>>>>
>>>>> (when (file-exists? path)
>>>>>     (delete-directory/files path))
>>>>>
>>>>> (define conn (sqlite3-connect #:database path #:mode 'create))
>>>>> (query-exec conn "create table MYTABLE (n integer primary key)")
>>>>> (disconnect conn)
>>>>> (printf "OK\n")
>>>>>
>>>>>
>>>>> Steps to reproduce:
>>>>>
>>>>> C:\Documents and Settings\dpavlov>raco exe mytable.rkt
>>>>>
>>>>> C:\Documents and Settings\dpavlov>mytable.exe
>>>>> OK
>>>>>
>>>>> C:\Documents and Settings\dpavlov>raco distribute mytable-distr
>>>>> mytable.exe
>>>>>
>>>>> C:\Documents and Settings\dpavlov>mytable-distr\mytable.exe
>>>>> sqlite3_open: implementation not found; arguments: #"C:\\Documents and
>>>>> Settings\\dpavlov\\mytable.db" 6
>>>>>     context...:
>>>>>      c:\program
>>>>> files\racket\collects\db\private\sqlite3\main.rkt:11:0:
>>>>> sqlite3-connect13
>>>>>      #%mzc:mytable: [running body]
>>>>>      loop
>>>>>
>>>>>
>>>>> Regards,
>>>>>
>>>>> Dmitry
>>>>>
>>>>> ____________________
>>>>>    Racket Users list:
>>>>>    http://lists.racket-lang.org/users
>>
>>
>>
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>
>


Posted on the users mailing list.