Connect to the database server in a nonblocking manner.
type(c_ptr) :: conn
integer :: res = -1
character(16) :: keywords(3), values(3)
type(c_ptr) :: conn
keywords(1) = 'host'; values(1) = 'localhost'
keywords(2) = 'user'; values(2) = 'postgres'
keywords(3) = 'dbname'; values(3) = 'postgres'
conn = PQconnectStartParams(keywords, values, 0)
if (c_associated(conn)) then
do while(res /= PGRES_POLLING_OK) ! loop for polling
res = PQconnectPoll(conn)
select case (res)
case (PGRES_POLLING_FAILED)
print *, PQerrorMessage(conn)
error stop
case (PGRES_POLLING_OK)
print *, "CONNECTION ESTABLISHED"
exit
case default
continue
! write some process here!
end select
end do
else
print *, "Cannot connect the server."
error stop
end if
cf. PQconnectStart, PQconnectPoll
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | keywords(:) | |||
character(len=*), | intent(in) | :: | values(:) | |||
integer | :: | expand_dbname |