db: allow mysql-connect without db
This commit is contained in:
parent
fd74709e1c
commit
b355abfdb3
|
@ -224,7 +224,7 @@
|
||||||
[mysql-data-source
|
[mysql-data-source
|
||||||
(->* ()
|
(->* ()
|
||||||
(#:user string?
|
(#:user string?
|
||||||
#:database string?
|
#:database (or/c string? #f)
|
||||||
#:server string?
|
#:server string?
|
||||||
#:port exact-positive-integer?
|
#:port exact-positive-integer?
|
||||||
#:socket (or/c string? 'guess)
|
#:socket (or/c string? 'guess)
|
||||||
|
|
|
@ -46,9 +46,9 @@
|
||||||
|
|
||||||
;; Duplicates contracts at mysql.rkt
|
;; Duplicates contracts at mysql.rkt
|
||||||
[mysql-connect
|
[mysql-connect
|
||||||
(->* (#:user string?
|
(->* (#:user string?)
|
||||||
#:database string?)
|
(#:database (or/c string? #f)
|
||||||
(#:password (or/c string? (list/c 'hash string?) #f)
|
#:password (or/c string? (list/c 'hash string?) #f)
|
||||||
#:server (or/c string? #f)
|
#:server (or/c string? #f)
|
||||||
#:port (or/c exact-positive-integer? #f)
|
#:port (or/c exact-positive-integer? #f)
|
||||||
#:socket (or/c path-string? 'guess #f)
|
#:socket (or/c path-string? 'guess #f)
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
;; FIXME: Contracts duplicated at main.rkt
|
;; FIXME: Contracts duplicated at main.rkt
|
||||||
(provide/contract
|
(provide/contract
|
||||||
[mysql-connect
|
[mysql-connect
|
||||||
(->* (#:user string?
|
(->* (#:user string?)
|
||||||
#:database string?)
|
(#:database (or/c string? #f)
|
||||||
(#:password (or/c string? (list/c 'hash string?) #f)
|
#:password (or/c string? (list/c 'hash string?) #f)
|
||||||
#:server (or/c string? #f)
|
#:server (or/c string? #f)
|
||||||
#:port (or/c exact-positive-integer? #f)
|
#:port (or/c exact-positive-integer? #f)
|
||||||
#:socket (or/c path-string? 'guess #f)
|
#:socket (or/c path-string? 'guess #f)
|
||||||
|
|
|
@ -184,7 +184,7 @@
|
||||||
(set! inport in)
|
(set! inport in)
|
||||||
(set! outport out))
|
(set! outport out))
|
||||||
|
|
||||||
;; start-connection-protocol : string string string/#f -> void
|
;; start-connection-protocol : string/#f string string/#f -> void
|
||||||
(define/public (start-connection-protocol dbname username password ssl ssl-context)
|
(define/public (start-connection-protocol dbname username password ssl ssl-context)
|
||||||
(with-disconnect-on-error
|
(with-disconnect-on-error
|
||||||
(fresh-exchange)
|
(fresh-exchange)
|
||||||
|
@ -199,11 +199,9 @@
|
||||||
(memq 'ssl capabilities)))
|
(memq 'ssl capabilities)))
|
||||||
(when (and (eq? ssl 'yes) (not do-ssl?))
|
(when (and (eq? ssl 'yes) (not do-ssl?))
|
||||||
(uerror 'mysql-connect "server refused SSL connection"))
|
(uerror 'mysql-connect "server refused SSL connection"))
|
||||||
(define wanted-capabilities (desired-capabilities capabilities do-ssl?))
|
(define wanted-capabilities (desired-capabilities capabilities do-ssl? dbname))
|
||||||
(when do-ssl?
|
(when do-ssl?
|
||||||
(send-message
|
(send-message (make-abbrev-client-auth-packet wanted-capabilities))
|
||||||
(make-abbrev-client-auth-packet
|
|
||||||
wanted-capabilities))
|
|
||||||
(let-values ([(sin sout)
|
(let-values ([(sin sout)
|
||||||
(ports->ssl-ports inport outport
|
(ports->ssl-ports inport outport
|
||||||
#:mode 'connect
|
#:mode 'connect
|
||||||
|
@ -244,13 +242,11 @@
|
||||||
rf)))
|
rf)))
|
||||||
REQUIRED-CAPABILITIES))
|
REQUIRED-CAPABILITIES))
|
||||||
|
|
||||||
(define/private (desired-capabilities capabilities ssl?)
|
(define/private (desired-capabilities capabilities ssl? dbname)
|
||||||
(let ([base
|
(append (if ssl? '(ssl) '())
|
||||||
(cons 'interactive
|
(if dbname '(connect-with-db) '())
|
||||||
(filter (lambda (c) (memq c DESIRED-CAPABILITIES))
|
'(interactive)
|
||||||
capabilities))])
|
(filter (lambda (c) (memq c DESIRED-CAPABILITIES)) capabilities)))
|
||||||
(cond [ssl? (cons 'ssl base)]
|
|
||||||
[else base])))
|
|
||||||
|
|
||||||
;; Set connection to use utf8 encoding
|
;; Set connection to use utf8 encoding
|
||||||
(define/private (after-connect)
|
(define/private (after-connect)
|
||||||
|
@ -576,7 +572,6 @@
|
||||||
transactions
|
transactions
|
||||||
protocol-41
|
protocol-41
|
||||||
secure-connection
|
secure-connection
|
||||||
connect-with-db
|
|
||||||
plugin-auth))
|
plugin-auth))
|
||||||
|
|
||||||
;; raise-backend-error : symbol ErrorPacket -> raises exn
|
;; raise-backend-error : symbol ErrorPacket -> raises exn
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
mysql-password-hash)
|
mysql-password-hash)
|
||||||
|
|
||||||
(define (mysql-connect #:user user
|
(define (mysql-connect #:user user
|
||||||
#:database database
|
#:database [database #f]
|
||||||
#:password [password #f]
|
#:password [password #f]
|
||||||
#:server [server #f]
|
#:server [server #f]
|
||||||
#:port [port #f]
|
#:port [port #f]
|
||||||
|
|
|
@ -343,9 +343,9 @@ Based on protocol documentation here:
|
||||||
(io:write-bytes out (make-bytes 23 0))
|
(io:write-bytes out (make-bytes 23 0))
|
||||||
(io:write-null-terminated-string out user)
|
(io:write-null-terminated-string out user)
|
||||||
(cond [(memq 'secure-connection client-flags)
|
(cond [(memq 'secure-connection client-flags)
|
||||||
(io:write-length-coded-bytes out scramble)]
|
(io:write-length-coded-bytes out (or scramble #""))]
|
||||||
[else ;; old-style scramble is *not* length-coded, but \0-terminated
|
[else ;; old-style scramble is *not* length-coded, but \0-terminated
|
||||||
(io:write-bytes out scramble)])
|
(io:write-bytes out (or scramble (bytes 0)))])
|
||||||
(when (memq 'connect-with-db client-flags)
|
(when (memq 'connect-with-db client-flags)
|
||||||
(io:write-null-terminated-string out database))
|
(io:write-null-terminated-string out database))
|
||||||
(when (memq 'plugin-auth client-flags)
|
(when (memq 'plugin-auth client-flags)
|
||||||
|
|
|
@ -144,7 +144,7 @@ Base connections are made using the following functions.
|
||||||
}
|
}
|
||||||
|
|
||||||
@defproc[(mysql-connect [#:user user string?]
|
@defproc[(mysql-connect [#:user user string?]
|
||||||
[#:database database string?]
|
[#:database database (or/c string? #f) #f]
|
||||||
[#:server server string? "localhost"]
|
[#:server server string? "localhost"]
|
||||||
[#:port port exact-positive-integer? 3306]
|
[#:port port exact-positive-integer? 3306]
|
||||||
[#:socket socket (or/c path-string? #f) #f]
|
[#:socket socket (or/c path-string? #f) #f]
|
||||||
|
@ -158,12 +158,16 @@ Base connections are made using the following functions.
|
||||||
void])
|
void])
|
||||||
connection?]{
|
connection?]{
|
||||||
|
|
||||||
Creates a connection to a MySQL server. The meaning of the keyword
|
Creates a connection to a MySQL server. If @racket[database] is
|
||||||
arguments is similar to those of the @racket[postgresql-connect]
|
@racket[#f], the connection is established without setting the
|
||||||
function, except that the first argument to a
|
current database; it should be subsequently set with the @tt{USE}
|
||||||
@racket[notice-handler] function is a MySQL-specific integer code
|
SQL command.
|
||||||
rather than a SQLSTATE string, and a @racket[socket] argument of
|
|
||||||
@racket['guess] is the same as supplying
|
The meaning of the other keyword arguments is similar to those of
|
||||||
|
the @racket[postgresql-connect] function, except that the first
|
||||||
|
argument to a @racket[notice-handler] function is a MySQL-specific
|
||||||
|
integer code rather than a SQLSTATE string, and a @racket[socket]
|
||||||
|
argument of @racket['guess] is the same as supplying
|
||||||
@racket[(mysql-guess-socket-path)].
|
@racket[(mysql-guess-socket-path)].
|
||||||
|
|
||||||
If the connection cannot be made, an exception is raised.
|
If the connection cannot be made, an exception is raised.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user