|
libfossil
|
Represents a prepared statement handle. More...
#include "db.h"
Data Fields | |
| fsl_db * | db |
| The db which prepared this statement. | |
| struct { | |
| void const * allocStamp | |
| A marker which tells fsl_stmt_finalize() whether or not fsl_stmt_malloc() allocated this instance (in which case fsl_stmt_finalize() will fsl_free() it) or not (in which case it does not free() it). More... | |
| uint32_t cachedHits | |
| Internal use only: counts the number of times this query has been resolved as cached via fsl_db_prepare_cached(). More... | |
| fsl_flag16_t flags | |
| Internal state flags. More... | |
| fsl_stmt * next | |
| For internal use in creating linked lists. More... | |
| } | impl |
| Private implementation details. | |
| fsl_flag16_t | role |
| Describes the database(s) used by this statement handle, in the form of a bitmask of fsl_dbrole_e values. | |
| fsl_size_t | rowCount |
| The number of times this statement has fetched a row via fsl_stmt_step(). | |
| fsl_buffer | sql |
| The SQL used to prepare this statement. | |
| fsl_stmt_t * | stmt |
| Underlying db driver-level statement handle. | |
Represents a prepared statement handle.
Intended usage:
Script binding implementations can largely avoid exposing the statement handle (and its related cleanup ordering requirements) to script code. They need to have some mechanism for binding values to SQL (or implement all the escaping themselves), but that can be done without exposing all of the statement class if desired. For example, here's some hypothetical script code:
Ideally, script code should not have direct access to the Statement because managing lifetimes can be difficult in the face of flow-control changes caused by exceptions (as the above example demonstrates). Statements can be completely hidden from clients if the DB wrapper is written to support it. For example, in pseudo-JavaScript that might look like:
| void const* fsl_stmt::allocStamp |
A marker which tells fsl_stmt_finalize() whether or not fsl_stmt_malloc() allocated this instance (in which case fsl_stmt_finalize() will fsl_free() it) or not (in which case it does not free() it).
| uint32_t fsl_stmt::cachedHits |
Internal use only: counts the number of times this query has been resolved as cached via fsl_db_prepare_cached().
| fsl_flag16_t fsl_stmt::flags |
| struct { ... } fsl_stmt::impl |
Private implementation details.
| fsl_stmt* fsl_stmt::next |
| fsl_flag16_t fsl_stmt::role |
Describes the database(s) used by this statement handle, in the form of a bitmask of fsl_dbrole_e values.
This is a bit of a kludge used to allow the internals to flush cached statements from the fossil global config db when detaching that database. Code which requires this to be set must set it itself and must set it correctly. Hypothetically, no client-level code requires it but some libfossil-internal code does.
| fsl_size_t fsl_stmt::rowCount |
The number of times this statement has fetched a row via fsl_stmt_step().
This is primarily intended for use by fsl_stmt_each_f() implementations so that they can keep track of when to emit a header (or similar pre-first-row setup).
| fsl_buffer fsl_stmt::sql |
The SQL used to prepare this statement.
We keep this, rather than simply fetching the SQL on demand, only for facilitate fsl_db_prepare_cached(). But since we have it, and it might be interesting, in client code, it's a public part of the interface.
| fsl_stmt_t* fsl_stmt::stmt |