No matching definitions.

postgres/stmt

src/postgres/stmt.tur
defn

stmt-prepare

(stmt-prepare [conn :int name :cstr sql :cstr nparams :int] :ptr<void>)

compile a named prepared statement on the server.

connconnection handle
nameunique name for this prepared statement
sqlSQL string with $1,$2,... placeholders
nparamsnumber of parameters in sql

(ok 0) on success; (err 0) on failure.

(stmt-prepare conn "insert-user" "INSERT INTO users (name) VALUES ($1)" 1)

Since: PG2

defn

stmt-exec-prepared

(stmt-exec-prepared [conn :int name :cstr params :int] :ptr<void>)

execute a previously prepared statement with parameters.

connconnection handle
namename used in stmt-prepare
paramscons list of :cstr parameter values (positional, 1-indexed)

(ok rows-handle) on success; (err 0) on failure. Free the rows-handle with rows-free from postgres/row when done.

(let [r (stmt-exec-prepared conn "insert-user" (cons "Alice" 0))]
    (if (ok? r) (rows-free (ok-val r)) (println "exec failed")))

Since: PG2

defn

stmt-deallocate

(stmt-deallocate [conn :int name :cstr] :ptr<void>)

drop a named prepared statement from the server.

connconnection handle
namename used in stmt-prepare

(ok 0) on success; (err 0) on failure.

(stmt-deallocate conn "insert-user")

Since: PG2

Internal definitions
__ok-- create an ok result wrapping integer value v.
__err-- create an err result wrapping integer error value e.
__params-count-- count the number of cells in a cons list.
__params-values-- build a heap-allocated char** from a cons list of :cstr.
__dealloc-sql-- build "DEALLOCATE name" as a heap-allocated cstr.
__pq-prepare-raw-- PQprepare; returns 1 on success, 0 on failure.
__pq-exec-prepared-raw-- PQexecPrepared; returns PGresult* as :int (0 on failure).
__pq-exec-raw-- execute SQL with no params; returns 1 on success, 0 on failure.