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. |
Submits a request to create a prepared statement with the given parameters, and waits for completion.
PQprepare
creates a prepared statement for later execution withPQexecPrepared
. 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 thequery
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 arrayparamTypes
.paramTypes
specifies, by OID, the data types to be assigned to the parameter symbols. If any particuler element in theparamTypes
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 thannParams
; 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 aPGresult
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. UsePQerrorMessage
to get more information about such errors.
Type | Intent | Optional | 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(:) |
Submits a request to create a prepared statement with the given parameters, and waits for completion.
PQprepare
creates a prepared statement for later execution withPQexecPrepared
. 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 thequery
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 arrayparamTypes
.paramTypes
specifies, by OID, the data types to be assigned to the parameter symbols. If any particuler element in theparamTypes
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 thannParams
; data types will be inferred for these symbols as well.As with
PQexec
, the result is normally aPGresult
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. UsePQerrorMessage
to get more information about such errors.
Type | Intent | Optional | 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(:) |
Sends a request to create a prepared statement with the given parameters, without waiting for completion.
This is an asynchronous version of
PQprepare
: it returns1
if it was able to dispatch the request, and0
if not. After a successfull call, callPQgetResult
to determine whether the server successfully created the prepared statement. The function's parameters are handled identically toPQprepare
.
Type | Intent | Optional | 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(:) |
Sends a request to create a prepared statement with the given parameters, without waiting for completion.
This is an asynchronous version of
PQprepare
: it returns1
if it was able to dispatch the request, and0
if not. After a successfull call, callPQgetResult
to determine whether the server successfully created the prepared statement. The function's parameters are handled identically toPQprepare
.
Type | Intent | Optional | 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(:) |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | conn | |||
character(len=*), | intent(in) | :: | stmtName | |||
integer(kind=int32), | intent(in) | :: | nParams | |||
character(len=*), | intent(in) | :: | paramValues(:) |
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 identicallyPQexecParams
. LikePQexecParams
, it allows only one command in the query.
Type | Intent | Optional | 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(:) |
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 identicallyPQexecParams
. LikePQexecParams
, it allows only one command in the query.
Type | Intent | Optional | 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(:) |
Send query to the server and wait until receiving the result.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | conn | |||
character(len=*), | intent(in) | :: | query |
Sends a request to execute a prepared statement with given parameters, and waits for the result.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | conn | |||
character(len=*), | intent(in) | :: | stmtName | |||
integer(kind=int32), | intent(in) | :: | nParams | |||
character(len=*), | intent(in) | :: | paramValues(:) |
Submits a request to obtain information about the specified prepared statement, and waits for completion.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | conn | |||
character(len=*), | intent(in) | :: | stmtName |
Submits a request to obtain information about the specified portral, and waits for completion.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | conn | |||
character(len=*), | intent(in) | :: | portalName |
Returns the result status of the command.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | pgresult |
Converts the enumerated type returned by PQresultStatus
into a string constant describing the status code..
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=int32), | intent(in) | :: | status |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | pgresult |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | pgresult | |||
integer(kind=int32), | intent(in) | :: | verbosity | |||
integer(kind=int32), | intent(in) | :: | show_context |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | pgresult | |||
integer(kind=int32), | intent(in) | :: | fieldcode |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | pgresult |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | pgresult |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | pgresult | |||
integer(kind=int32), | intent(in) | :: | field_num |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | pgresult | |||
character(len=*), | intent(in) | :: | column_name |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | pgresult | |||
integer(kind=int32), | intent(in) | :: | column_number |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | pgresult | |||
integer(kind=int32), | intent(in) | :: | column_number |
Returns the format code indicating the format of the given column.
Column numbers start at 0
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | pgresult | |||
integer(kind=int32), | intent(in) | :: | column_number |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | pgresult | |||
integer(kind=int32), | intent(in) | :: | column_number |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | pgresult | |||
integer(kind=int32), | intent(in) | :: | column_number |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | pgresult | |||
integer(kind=int32), | intent(in) | :: | column_number |
Return .true.
if the PQresult contains binary data and .false.
if it contains text data.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | pgresult |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | pgresult | |||
integer(kind=c_int), | intent(in) | :: | tuple_num | |||
integer(kind=c_int), | intent(in) | :: | field_num |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | pgresult | |||
integer(kind=int32), | intent(in) | :: | row_number | |||
integer(kind=int32), | intent(in) | :: | column_number |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | pgresult |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | pgresult |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | pgresult | |||
integer(kind=int32), | intent(in) | :: | param_number |
Returns the command status tag from the SQL command that generated the PGresult
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | pgresult |
Returns the number of rows affected by the SQL command.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | pgresult |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | pgresult |
Type | Intent | Optional | 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 |
Type | Intent | Optional | 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 |
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).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | conn | |||
character(len=*), | intent(in) | :: | command |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | conn | |||
character(len=*), | intent(in) | :: | stmtName |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | conn | |||
character(len=*), | intent(in) | :: | portalName |
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.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | conn |
If input is available from the server, consume it.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | conn |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | conn |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | conn | |||
integer(kind=int32), | intent(in) | :: | arg |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | conn |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | conn |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | conn |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | conn |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | conn |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | conn |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | conn |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | conn |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | conn |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | conn | |||
integer(kind=int32), | intent(in) | :: | status |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | conn | |||
type(c_ptr), | intent(in) | :: | res |
Get the threadsafety status of the current running libpq library. cf. PostgreSQL Documentation
Frees the storage associated with a PGresult
.
Every command result should be freed via PQclear
when it is no longer needed.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | res |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | cptr |