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? [
|
||||
|
@ -147,7 +148,7 @@ M: postgresql-malloc-destructor dispose ( obj -- )
|
|||
&postgresql-free
|
||||
] if
|
||||
] with-out-parameters memory>byte-array
|
||||
] with-destructors
|
||||
] with-destructors
|
||||
] [
|
||||
drop pq-get-is-null nip [ f ] [ B{ } clone ] if
|
||||
] if ;
|
||||
|
|
|
@ -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
|
||||
|
@ -84,4 +95,4 @@ IN: db.postgresql.tests
|
|||
postgresql-test-db [
|
||||
"select * from person" sql-query length
|
||||
] with-db
|
||||
] unit-test
|
||||
] unit-test
|
||||
|
|
Loading…
Reference in New Issue