Send query to the server and wait until receiving the result.
Submit a command to the server and waits for the result.
Returns a
PGresult
pointer or possibly a null pointer. A non-null pointer will generally be returned except in out-of-memory conditions or serious errors such as inability to send the command to the server. ThePQresultStatus
function should be called to check the return value for any errors (including the value of a null pointer, in which case it will return PGRES_FATAL_ERROR). UsePQerrorMessage
to get more information about such errors.
type(c_ptr) :: conn, res
integer :: stat
conn = PQconnectdb("dbname=postgres")
!...error handling...
res = PQexec(conn, "select 1234;")
stat = PQresultStatus(res)
if (stat /= PGRES_COMMAND_OK .and. stat /= PGRES_TUPLES_OK) then
print *, PQerrorMessage(conn)
call PQclear(res)
call PQfinish(conn)
error stop
end if
! ... some statements ...
call PQclear(res)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | conn | |||
character(len=*), | intent(in) | :: | query |