Connect to the database server in a nonblocking manner.
character(:), allocatable :: conninfo
type(c_ptr) :: conn
integer :: res = -1
conninfo = "host=localhost user=postgres dbname=postgres"
conn = PQconnectStart(conninfo)
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. PQconnectPoll, PQconnectStartParams
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | conninfo |