db: add `sqlite3-available?'
Loading `db/sqlite3' no longer raises an exception if the SQLite library isn't found. Instead, `sqlite3-connect' raises an exception, while `sqlite3-available?' reports whether it will work. The dynamic test allows the documentation-help system to continue to work if SQLite3 is not available. Currently, though, `raco setup' still insists on using SQLite3 to build the database of documented tags.
This commit is contained in:
parent
8c1b5db815
commit
41e9e3e5ff
|
@ -14,7 +14,8 @@
|
|||
mysql-guess-socket-path
|
||||
mysql-password-hash)]
|
||||
["private/sqlite3/main.rkt"
|
||||
(sqlite3-connect)]
|
||||
(sqlite3-connect
|
||||
sqlite3-available?)]
|
||||
["private/odbc/main.rkt"
|
||||
(odbc-connect
|
||||
odbc-driver-connect
|
||||
|
@ -71,6 +72,8 @@
|
|||
#:use-place boolean?
|
||||
#:debug? any/c)
|
||||
connection?)]
|
||||
[sqlite3-available?
|
||||
(-> boolean?)]
|
||||
|
||||
;; Duplicates contracts at odbc.rkt
|
||||
[odbc-connect
|
||||
|
|
|
@ -5,10 +5,14 @@
|
|||
(provide (all-from-out "ffi-constants.rkt")
|
||||
(protect-out (all-defined-out)))
|
||||
|
||||
(define-ffi-definer define-sqlite
|
||||
(define sqlite-lib
|
||||
(case (system-type)
|
||||
((windows) (ffi-lib "sqlite3.dll"))
|
||||
(else (ffi-lib "libsqlite3" '("0" #f)))))
|
||||
[(windows) (ffi-lib "sqlite3.dll" #:fail (lambda () #f))]
|
||||
[else (ffi-lib "libsqlite3" '("0" #f) #:fail (lambda () #f))]))
|
||||
|
||||
(define-ffi-definer define-sqlite
|
||||
sqlite-lib
|
||||
#:default-make-fail make-not-available)
|
||||
|
||||
; Types
|
||||
(define-cpointer-type _sqlite3_database)
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
"connection.rkt"
|
||||
"dbsystem.rkt"
|
||||
"ffi.rkt")
|
||||
(provide sqlite3-connect)
|
||||
(provide sqlite3-connect
|
||||
sqlite3-available?)
|
||||
|
||||
(define (sqlite3-connect #:database path
|
||||
#:mode [mode 'read/write]
|
||||
|
@ -53,3 +54,6 @@
|
|||
(class place-proxy-connection%
|
||||
(super-new)
|
||||
(define/override (get-dbsystem) dbsystem)))
|
||||
|
||||
(define (sqlite3-available?)
|
||||
(and sqlite-lib #t))
|
||||
|
|
|
@ -247,6 +247,13 @@ Base connections are made using the following functions.
|
|||
(new connection%)]]
|
||||
}
|
||||
|
||||
|
||||
@defproc[(sqlite3-available?) boolean?]{
|
||||
|
||||
Reports whether the SQLite native library is found, in which case
|
||||
@racket[sqlite3-connect] works, otherwise it raises an exception.}
|
||||
|
||||
|
||||
@defproc[(odbc-connect [#:dsn dsn string?]
|
||||
[#:user user (or/c string? #f) #f]
|
||||
[#:password password (or/c string? #f) #f]
|
||||
|
@ -742,10 +749,9 @@ Provides only @racket[mysql-connect] and
|
|||
|
||||
@defmodule*/no-declare[(db/sqlite3)]
|
||||
|
||||
Provides only @racket[sqlite3-connect]. In contrast to
|
||||
@racketmodname[db], this module immediately attempts to
|
||||
load the SQLite native library when required, and it raises an
|
||||
exception if it cannot be found.
|
||||
Provides @racket[sqlite3-connect] plus @racket[sqlite3-available?]. When
|
||||
the SQLite native library cannot be found, @racket[sqlite3-connect]
|
||||
raises an exception.
|
||||
|
||||
@defmodule*/no-declare[(db/odbc)]
|
||||
|
||||
|
|
|
@ -12,4 +12,6 @@
|
|||
#:busy-retry-delay (and/c rational? (not/c negative?))
|
||||
#:use-place any/c
|
||||
#:debug? any/c)
|
||||
connection?)])
|
||||
connection?)]
|
||||
[sqlite3-available?
|
||||
(-> boolean?)])
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
doc-db-key->path
|
||||
doc-db-file->connection)
|
||||
|
||||
(define (doc-db-available?) #t)
|
||||
(define (doc-db-available?)
|
||||
(sqlite3-available?))
|
||||
|
||||
(define (doc-db-file->connection db-file)
|
||||
(sqlite3-connect #:database db-file))
|
||||
|
|
Loading…
Reference in New Issue
Block a user