PQconnectStartParams Function

public function PQconnectStartParams(keywords, values, expand_dbname) result(conn)

Connect to the database server in a nonblocking manner.

Example

   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

References

cf. PQconnectStart, PQconnectPoll

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: keywords(:)
character(len=*), intent(in) :: values(:)
integer :: expand_dbname

Return Value type(c_ptr)


Contents