fe_exec_m Module


Contents


Interfaces

public interface PQexecParams

  • private function PQexecParams_int32(conn, command, nParams, paramTypes, paramValues) result(res)

    Submits a command to the server and waits for the result, with the ability to pass parameters separately from the SQL command text.

    PQexecParams is like PQexec but offers additional functionality: parameter values can be specified separately from the command string proper, and query results can be requested in text or binary format.

    cf. PostgreSQL Documentation

    Example

     block
        character(:), allocatable :: command
        character(8) :: values(2)
        type(c_ptr) :: res
    
        command = "select $1::bigint + $2::bigint;"
        values(1) = "300"
        values(2) = "500"
    
        res = PQexecParams(conn, command, size(values), [0, 0], values)
        if (PQresultStatus(res) /= PGRES_TUPLES_OK) then
           print *, PQerrorMessage(conn)
           call PQclear(res)
        end if
    
        print *, PQgetvalue(res, 0, 0) ! the result "800" is expected.
        call PQclear(res)
    

    cf. PostgreSQL Documentation

    Arguments

    Type IntentOptional Attributes Name
    type(c_ptr), intent(in) :: conn

    The connection object to send the command through.

    character(len=*), intent(in) :: command

    The SQL command string to be executed. If parameters are used, they are referred to in the command string as $1, $2, etc.

    integer(kind=int32), intent(in) :: nParams

    The number of parameters supplied; it is the length of the arrays paramTypes, paramValues.

    integer(kind=int32), intent(in) :: paramTypes(:)

    Specifies, by OID, the data types to be assigned to the parameter symbols. If any particular element in the array is zero, the server infers a data type for the parameter symbol in the same way it would do for an untyped literal string.

    character(len=*), intent(in) :: paramValues(:)

    Specifies the actual values of the parameters. A empty string in this array means the corresponding parameter is null.

    Return Value type(c_ptr)

  • private function PQexecParams_int64(conn, command, nParams, paramTypes, paramValues) result(res)

    Submits a command to the server and waits for the result, with the ability to pass parameters separately from the SQL command text.

    PQexecParams is like PQexec but offers additional functionality: parameter values can be specified separately from the command string proper, and query results can be requested in text or binary format.

    cf. PostgreSQL Documentation

    Example

     block
        character(:), allocatable :: command
        character(8) :: values(2)
        type(c_ptr) :: res
    
        command = "select $1::bigint + $2::bigint;"
        values(1) = "300"
        values(2) = "500"
    
        res = PQexecParams(conn, command, size(values), [0_8, 0_8], values)
        if (PQresultStatus(res) /= PGRES_TUPLES_OK) then
           print *, PQerrorMessage(conn)
           call PQclear(res)
        end if
    
        print *, PQgetvalue(res, 0, 0) ! the result "800" is expected.
        call PQclear(res)
    

    cf. PostgreSQL Documentation

    Arguments

    Type IntentOptional Attributes Name
    type(c_ptr), intent(in) :: conn

    The connection object to send the command through.

    character(len=*), intent(in) :: command

    The SQL command string to be executed. If parameters are used, they are referred to in the command string as $1, $2, etc.

    integer(kind=int32), intent(in) :: nParams

    The number of parameters supplied; it is the length of the arrays paramTypes, paramValues.

    integer(kind=int64), intent(in) :: paramTypes(:)

    Specifies, by OID, the data types to be assigned to the parameter symbols. If any particular element in the array is zero, the server infers a data type for the parameter symbol in the same way it would do for an untyped literal string.

    character(len=*), intent(in) :: paramValues(:)

    Specifies the actual values of the parameters. A empty string in this array means the corresponding parameter is null.

    Return Value type(c_ptr)

public interface PQprepare

  • private function PQprepare_int32(conn, stmtName, query, nParams, paramTypes) result(res)

    Submits a request to create a prepared statement with the given parameters, and waits for completion.

    PQprepare creates a prepared statement for later execution with PQexecPrepared. This feature allows commands to be executed repeatedly without being parsed and planned each time; see PREPARE for details.

    The function create a prepared statement named stmtName from the query string, which must contain a single SQL command. stmtName can be "" to create an unnamed statement, in which case any pre-existing unnamed statement is automatically replaced; otherwise it is an error if the statement name is already defined in the current session. If any parameters are used, they are referred to in the as $1, $2, etc. nParams is the number of parameters for which types are pre-specified in the array paramTypes. paramTypes specifies, by OID, the data types to be assigned to the parameter symbols. If any particuler element in the paramTypes array is zero, the server assigns a data type to the parameter symbol in the same way it would do for an untyped literal string. Also, the query can use parameter symbols with the numbers higher than nParams; data types will be inferred for these symbols as well. (See PQdescribePrepared) for a means to find out what data types were inffered.)

    As with [[PQexec]], the result is normally a PGresult object whose contents indicate server-side success or failure. A null result indicates out-of-memory or inability to send to the command at all. Use PQerrorMessage to get more information about such errors.

    cf. PostgreSQL Documentation

    Arguments

    Type IntentOptional Attributes Name
    type(c_ptr), intent(in) :: conn
    character(len=*), intent(in) :: stmtName
    character(len=*), intent(in) :: query
    integer(kind=int32), intent(in) :: nParams
    integer(kind=int32), intent(in) :: paramTypes(:)

    Return Value type(c_ptr)

  • private function PQprepare_int64(conn, stmtName, query, nParams, paramTypes) result(res)

    Submits a request to create a prepared statement with the given parameters, and waits for completion.

    PQprepare creates a prepared statement for later execution with PQexecPrepared. This feature allows commands to be executed repeatedly without being parsed and planned each time; see PREPARE for details.

    The function create a prepared statement named stmtName from the query string, which must contain a single SQL command. stmtName can be "" to create an unnamed statement, in which case any pre-existing unnamed statement is automatically replaced; otherwise it is an error if the statement name is already defined in the current session. If any parameters are used, they are referred to in the as $1, $2, etc. nParams is the number of parameters for which types are pre-specified in the array paramTypes. paramTypes specifies, by OID, the data types to be assigned to the parameter symbols. If any particuler element in the paramTypes array is zero, the server assigns a data type to the parameter symbol in the same way it would do for an untyped literal string. Also, the query can use parameter symbols with the numbers higher than nParams; data types will be inferred for these symbols as well.

    As with PQexec, the result is normally a PGresult object whose contents indicate server-side success or failure. A null result indicates out-of-memory or inability to send to the command at all. Use PQerrorMessage to get more information about such errors.

    cf. PostgreSQL Documentation

    cf. PostgreSQL Documentation

    Arguments

    Type IntentOptional Attributes Name
    type(c_ptr), intent(in) :: conn
    character(len=*), intent(in) :: stmtName
    character(len=*), intent(in) :: query
    integer(kind=int32), intent(in) :: nParams
    integer(kind=int64), intent(in) :: paramTypes(:)

    Return Value type(c_ptr)

public interface PQsendPrepare

  • private function PQsendPrepare_int32(conn, stmtName, query, nParams, paramTypes) result(res)

    Sends a request to create a prepared statement with the given parameters, without waiting for completion.

    This is an asynchronous version of PQprepare: it returns 1 if it was able to dispatch the request, and 0 if not. After a successfull call, call PQgetResult to determine whether the server successfully created the prepared statement. The function's parameters are handled identically to PQprepare.

    cf. PostgreSQL Documentation

    Arguments

    Type IntentOptional Attributes Name
    type(c_ptr), intent(in) :: conn
    character(len=*), intent(in) :: stmtName
    character(len=*), intent(in) :: query
    integer(kind=int32), intent(in) :: nParams
    integer(kind=int32), intent(in) :: paramTypes(:)

    Return Value integer(kind=int32)

  • private function PQsendPrepare_int64(conn, stmtName, query, nParams, paramTypes) result(res)

    Sends a request to create a prepared statement with the given parameters, without waiting for completion.

    This is an asynchronous version of PQprepare: it returns 1 if it was able to dispatch the request, and 0 if not. After a successfull call, call PQgetResult to determine whether the server successfully created the prepared statement. The function's parameters are handled identically to PQprepare.

    cf. PostgreSQL Documentation cf. PostgreSQL Documentation

    Arguments

    Type IntentOptional Attributes Name
    type(c_ptr), intent(in) :: conn
    character(len=*), intent(in) :: stmtName
    character(len=*), intent(in) :: query
    integer(kind=int32), intent(in) :: nParams
    integer(kind=int64), intent(in) :: paramTypes(:)

    Return Value integer(kind=int32)

public interface PQsendQueryPrepared

  • private function PQsendQueryPrepared_text(conn, stmtName, nParams, paramValues) result(res)

    cf. PostgreSQL Documentation

    Arguments

    Type IntentOptional Attributes Name
    type(c_ptr), intent(in) :: conn
    character(len=*), intent(in) :: stmtName
    integer(kind=int32), intent(in) :: nParams
    character(len=*), intent(in) :: paramValues(:)

    Return Value integer(kind=int32)

public interface PQsendQueryParams

  • private function PQsendQueryParams_int32(conn, command, nParams, paramTypes, paramValues) result(res)

    Submit a command and separate parameter to the server without waiting for the result(s). This is equivalent to PQsendQuery, except that query parameters can be specified separately form the query string. This function's parameters are handled identically PQexecParams. Like PQexecParams, it allows only one command in the query.

    cf. PostgreSQL Documentation

    Arguments

    Type IntentOptional Attributes Name
    type(c_ptr), intent(in) :: conn
    character(len=*), intent(in) :: command
    integer(kind=int32), intent(in) :: nParams
    integer(kind=int32), intent(in) :: paramTypes(:)
    character(len=*), intent(in) :: paramValues(:)

    Return Value integer(kind=int32)

  • private function PQsendQueryParams_int64(conn, command, nParams, paramTypes, paramValues) result(res)

    Submit a command and separate parameter to the server without waiting for the result(s). This is equivalent to PQsendQuery, except that query parameters can be specified separately form the query string. This function's parameters are handled identically PQexecParams. Like PQexecParams, it allows only one command in the query.

    cf. PostgreSQL Documentation

    Arguments

    Type IntentOptional Attributes Name
    type(c_ptr), intent(in) :: conn
    character(len=*), intent(in) :: command
    integer(kind=int32), intent(in) :: nParams
    integer(kind=int64), intent(in) :: paramTypes(:)
    character(len=*), intent(in) :: paramValues(:)

    Return Value integer(kind=int32)


Functions

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

Send query to the server and wait until receiving the result.

Read more…

Arguments

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

Return Value type(c_ptr)

public function PQexecPrepared(conn, stmtName, nParams, paramValues) result(res)

Sends a request to execute a prepared statement with given parameters, and waits for the result.

Read more…

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: conn
character(len=*), intent(in) :: stmtName
integer(kind=int32), intent(in) :: nParams
character(len=*), intent(in) :: paramValues(:)

Return Value type(c_ptr)

public function PQdescribePrepared(conn, stmtName) result(res)

Submits a request to obtain information about the specified prepared statement, and waits for completion.

Read more…

Arguments

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

Return Value type(c_ptr)

public function PQdescribePortal(conn, portalName) result(res)

Submits a request to obtain information about the specified portral, and waits for completion.

Read more…

Arguments

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

Return Value type(c_ptr)

public function PQresultStatus(pgresult) result(res)

Returns the result status of the command.

Read more…

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: pgresult

Return Value integer(kind=int32)

public function PQresStatus(status) result(res)

Converts the enumerated type returned by PQresultStatus into a string constant describing the status code..

Read more…

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(in) :: status

Return Value character(len=:), pointer

public function PQresultErrorMessage(pgresult) result(res)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: pgresult

Return Value character(kind=c_char, len=:), pointer

public function PQresultVerboseErrorMessage(pgresult, verbosity, show_context) result(res)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: pgresult
integer(kind=int32), intent(in) :: verbosity
integer(kind=int32), intent(in) :: show_context

Return Value character(kind=c_char, len=:), pointer

public function PQresultErrorField(pgresult, fieldcode) result(res)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: pgresult
integer(kind=int32), intent(in) :: fieldcode

Return Value character(kind=c_char, len=:), pointer

public function PQntuples(pgresult) result(res)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: pgresult

Return Value integer(kind=int32)

public function PQnfields(pgresult) result(res)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: pgresult

Return Value integer(kind=int32)

public function PQfname(pgresult, field_num) result(res)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: pgresult
integer(kind=int32), intent(in) :: field_num

Return Value character(kind=c_char, len=:), pointer

public function PQfnumber(pgresult, column_name)

cf. PostgreSQL Documentation

Arguments

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

Return Value integer

public function PQftable(pgresult, column_number) result(res)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: pgresult
integer(kind=int32), intent(in) :: column_number

Return Value integer(kind=int64)

public function PQftablecol(pgresult, column_number) result(res)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: pgresult
integer(kind=int32), intent(in) :: column_number

Return Value integer(kind=int32)

public function PQfformat(pgresult, column_number) result(res)

Returns the format code indicating the format of the given column. Column numbers start at 0.

Read more…

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: pgresult
integer(kind=int32), intent(in) :: column_number

Return Value integer(kind=int32)

public function PQftype(pgresult, column_number) result(res)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: pgresult
integer(kind=int32), intent(in) :: column_number

Return Value integer(kind=int64)

public function PQfmod(pgresult, column_number) result(res)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: pgresult
integer(kind=int32), intent(in) :: column_number

Return Value integer(kind=int32)

public function PQfsize(pgresult, column_number) result(res)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: pgresult
integer(kind=int32), intent(in) :: column_number

Return Value integer(kind=int32)

public function PQbinaryTuples(pgresult)

Return .true. if the PQresult contains binary data and .false. if it contains text data.

Read more…

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: pgresult

Return Value logical

public function PQgetvalue(pgresult, tuple_num, field_num)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: pgresult
integer(kind=c_int), intent(in) :: tuple_num
integer(kind=c_int), intent(in) :: field_num

Return Value character(kind=c_char, len=:), pointer

public function PQgetisnull(pgresult, row_number, column_number)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: pgresult
integer(kind=int32), intent(in) :: row_number
integer(kind=int32), intent(in) :: column_number

Return Value logical

public function PQgetlength(pgresult)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: pgresult

Return Value integer(kind=int32)

public function PQnparams(pgresult)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: pgresult

Return Value integer(kind=int32)

public function PQparamtype(pgresult, param_number) result(res)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: pgresult
integer(kind=int32), intent(in) :: param_number

Return Value integer(kind=int64)

public function PQcmdStatus(pgresult) result(res)

Returns the command status tag from the SQL command that generated the PGresult.

Read more…

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: pgresult

Return Value character(len=:), pointer

public function PQcmdTuples(pgresult) result(res)

Returns the number of rows affected by the SQL command.

Read more…

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: pgresult

Return Value character(len=:), pointer

public function PQoidValue(pgresult) result(res)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: pgresult

Return Value integer(kind=int64)

public function PQescapeLiteral(conn, str, length, errmsg) result(res)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: conn
character(len=*), intent(in) :: str
integer(kind=c_size_t), intent(in) :: length
character(len=*), intent(inout), optional :: errmsg

Return Value character(len=:), pointer

public function PQescapeIdentifier(conn, str, length, errmsg) result(res)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: conn
character(len=*), intent(in) :: str
integer(kind=c_size_t), intent(in) :: length
character(len=*), intent(inout), optional :: errmsg

Return Value character(len=:), pointer

public function PQsendQuery(conn, command) result(res)

Submits a command to the server without waiting for the result(s). 1 is returned if the command was successfully dispatched and 0 if not (in which case, use PQerrorMessage to get more information about the failure).

Read more…

Arguments

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

Return Value integer(kind=int32)

public function PQsendDescribePrepared(conn, stmtName) result(res)

cf. PostgreSQL Documentation

Arguments

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

Return Value integer(kind=int32)

public function PQsendDescribePortal(conn, portalName) result(res)

cf. PostgreSQL Documentation

Arguments

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

Return Value integer(kind=int32)

public function PQgetResult(conn) result(res)

Waits for the next result from a prior PQsendQuery, PQsendQueryParams, PQsendPrepare, PQsendQueryPrepared, PQsendDescribePrepared, PQsendDescribePortal, or PQpipelineSync call, and returns it. A null pointer is returned when the command is complete and there will be no more results.

Read more…

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: conn

Return Value type(c_ptr)

public function PQconsumeInput(conn) result(res)

If input is available from the server, consume it.

Read more…

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: conn

Return Value integer(kind=int32)

public function PQisBusy(conn) result(isBusy)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: conn

Return Value logical

public function PQsetnonblocking(conn, arg) result(res)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: conn
integer(kind=int32), intent(in) :: arg

Return Value integer(kind=int32)

public function PQisnonblocking(conn) result(isNonblocking)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: conn

Return Value logical

public function PQflush(conn)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: conn

Return Value integer(kind=int32)

public function PQpipelineStatus(conn) result(res)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: conn

Return Value integer(kind=int32)

public function PQenterPipelineMode(conn) result(res)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: conn

Return Value integer(kind=int32)

public function PQexitPipelineMode(conn) result(res)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: conn

Return Value integer(kind=int32)

public function PQpipelineSync(conn) result(res)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: conn

Return Value integer(kind=int32)

public function PQsendFlushRequest(conn) result(res)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: conn

Return Value integer(kind=int32)

public function PQsetSingleRowMode(conn) result(res)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: conn

Return Value integer(kind=int32)

public function PQnotifies(conn) result(res)

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: conn

Return Value type(c_ptr)

public function PQmakeEmptyPGresult(conn, status) result(res)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: conn
integer(kind=int32), intent(in) :: status

Return Value type(c_ptr)

public function PQcopyResult(conn, res)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: conn
type(c_ptr), intent(in) :: res

Return Value type(c_ptr)

public function PQisthreadsafe()

Get the threadsafety status of the current running libpq library. cf. PostgreSQL Documentation

Arguments

None

Return Value logical


Subroutines

public subroutine PQclear(res)

Frees the storage associated with a PGresult. Every command result should be freed via PQclear when it is no longer needed.

Read more…

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: res

public subroutine PQfreemem(cptr)

cf. PostgreSQL Documentation

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: cptr