6 Utilities
6.1 Connection utilities
| ||||||||||||||
generator : (-> connection?) | ||||||||||||||
timeout : (or/c #f (and/c rational? positive?)) = #f |
When given a connection produced by connection-generator, connected? indicates whether there is an actual connection associated with the current thread. Likewise, disconnect causes the current actual connection associated with the thread (if there is one) to be disconnected, but the connection will be recreated if a query function is executed.
Examples: | |||||
| |||||
> (connected? c) | |||||
#f | |||||
> (query-value c "select 1") | |||||
connecting! | |||||
1 | |||||
> (connected? c) | |||||
#t | |||||
> (void (thread (lambda () (displayln (query-value c "select 2"))))) | |||||
| |||||
> (disconnect c) | |||||
> (connected? c) | |||||
#f | |||||
> (query-value c "select 3") | |||||
connecting! | |||||
3 |
Connections produced by connection-generator may not be used with the prepare function. However, they may still be used to execute parameterized queries expressed as strings or encapsulated via statement-generator.
Examples: | |
> (prepare c "select 2 + $1") | |
prepare: cannot prepare statement with connection-generator | |
> (query-value c "select 2 + $1" 2) | |
4 | |
> (define pst (statement-generator "select 2 + $1")) | |
> (query-value c pst 3) | |
5 |
(kill-safe-connection c) → connection? |
c : connection? |
Note: A kill-safe connection whose underlying connection uses ports to communicate with a database server is not protected from a custodian shutting down its ports.