PQexec Function

public function PQexec(conn, query) result(res)

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. The PQresultStatus 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). Use PQerrorMessage to get more information about such errors.

cf. PostgreSQL Documentation

Example

 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)

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: conn
character(len=*), intent(in) :: query

Return Value type(c_ptr)


Contents