SQLBOX_REBIND(3) | Library Functions Manual | SQLBOX_REBIND(3) |
sqlbox_rebind
—
#include <stdint.h>
#include <sqlbox.h>
size_t
sqlbox_rebind
(struct sqlbox
*box, size_t id, size_t
psz, const struct sqlbox_parm *ps);
The ps array, if psz
is non-zero, consists of typed values bound to those parameters. Types must
correspond to typed values, for example, floats of type
SQLBOX_PARM_FLOAT
must be set in the
fparm of struct sqlbox_parm.
The sz of struct sqlbox_parm is ignored for floats and integers, but must be provided for blobs and optionally for strings. For strings, a zero indicates it should be computed using strlen(3). Otherwise, it should be the full string length including the NUL terminator. If the string is shorter than the given length (i.e., contains an embedded NUL terminator), the database will still return the full given length of the original size (terminating NUL inclusive).
If rebinding to the statement fails, subsequent box access will fail. Use sqlbox_ping(3) to check explicitly.
If sqlbox_rebind
() fails,
box is no longer accessible beyond
sqlbox_ping(3) and sqlbox_free(3).
size_t dbid, stmtid; struct sqlbox *p; struct sqlbox_cfg cfg; struct sqlbox_src srcs[] = { { .fname = (char *)"db.db", .mode = SQLBOX_SRC_RW } }; struct sqlbox_pstmt pstmts = { .stmt = (char *)"INSERT INTO foo " "(bar, baz) VALUES (?,?)" }; struct sqlbox_parm parms1[] = { { .iparm = 10, .type = SQLBOX_PARM_INT }, { .iparm = 20, .type = SQLBOX_PARM_INT }, }; struct sqlbox_parm parms2[] = { { .iparm = 30, .type = SQLBOX_PARM_INT }, }; const struct sqlbox_parmset *res; memset(&cfg, 0, sizeof(struct sqlbox_cfg)); cfg.msg.func_short = warnx; cfg.srcs.srcsz = 1; cfg.srcs.srcs = srcs; cfg.stmts.stmtsz = 1; cfg.stmts.stmts = &pstmt; if ((p = sqlbox_alloc(&cfg)) == NULL) errx(EXIT_FAILURE, "sqlbox_alloc"); if (!(dbid = sqlbox_open(p, 0))) errx(EXIT_FAILURE, "sqlbox_open"); if (!(stmtid = sqlbox_prepare_bind(p, dbid, 1, 2, parms1, 0))) errx(EXIT_FAILURE, "sqlbox_prepare_bind"); if (sqlbox_step(p, stmtid) == NULL) errx(EXIT_FAILURE, "sqlbox_step"); if (!sqlbox_rebind(p, stmtid, 1, parms2)) errx(EXIT_FAILURE, "sqlbox_rebind"); if (sqlbox_step(p, stmtid) == NULL) errx(EXIT_FAILURE, "sqlbox_step"); if (!sqlbox_finalise(p, stmtid)) errx(EXIT_FAILURE, "sqlbox_finalise"); sqlbox_free(p);
November 8, 2019 | OpenBSD 6.5 |