PQexecParams Interface

public interface PQexecParams

Contents


Module Procedures

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)