PQconnectStart Function

public function PQconnectStart(conninfo) result(conn)

Connect to the database server in a nonblocking manner.

Example

   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

References

cf. PQconnectPoll, PQconnectStartParams

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: conninfo

Return Value type(c_ptr)


Contents