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 likePQexec
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.
Binary format have not been implemented yet.
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)
Type | Intent | Optional | 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 |
||
integer(kind=int32), | intent(in) | :: | nParams |
The number of parameters supplied; it is the length of the arrays |
||
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. |
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 likePQexec
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.
Binary format have not been implemented yet.
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)
Type | Intent | Optional | 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 |
||
integer(kind=int32), | intent(in) | :: | nParams |
The number of parameters supplied; it is the length of the arrays |
||
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. |