db.postgresql.lib: if PQsetdbLogin fails, PQfinish must be called
parent
b90e52b527
commit
101780d2cd
|
@ -42,8 +42,9 @@ M: postgresql-result-null summary ( obj -- str )
|
|||
PGRES_COMMAND_OK PGRES_TUPLES_OK 2array member? ;
|
||||
|
||||
: connect-postgres ( host port pgopts pgtty db user pass -- conn )
|
||||
PQsetdbLogin
|
||||
dup PQstatus zero? [ (postgresql-error-message) throw ] unless ;
|
||||
PQsetdbLogin dup PQstatus zero? [
|
||||
[ (postgresql-error-message) ] [ PQfinish ] bi throw
|
||||
] unless ;
|
||||
|
||||
: do-postgresql-statement ( statement -- res )
|
||||
db-connection get handle>> swap sql>> PQexec dup postgresql-result-ok? [
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
USING: kernel db.postgresql alien continuations io classes
|
||||
prettyprint sequences namespaces tools.test db db.private
|
||||
prettyprint sequences math namespaces tools.test db db.private
|
||||
db.tuples db.types unicode.case accessors system db.tester ;
|
||||
IN: db.postgresql.tests
|
||||
|
||||
: nonexistant-db ( -- db )
|
||||
<postgresql-db>
|
||||
"localhost" >>host
|
||||
"fake-user" >>username
|
||||
"no-pass" >>password
|
||||
"dont-exist" >>database ;
|
||||
|
||||
! Don't leak connections
|
||||
[ ] [
|
||||
2000 [ [ nonexistant-db [ ] with-db ] ignore-errors ] times
|
||||
] unit-test
|
||||
|
||||
! Ensure the table exists
|
||||
[ ] [ postgresql-test-db [ ] with-db ] unit-test
|
||||
|
|
Loading…
Reference in New Issue