sqlite::execute inherits from sqlite::command but offers a
simplified constructor that optionally executes immediately. Use it for DDL and DML
statements when you do not need to iterate over result rows.
Use cases
- Ideal for one-shot schema migrations—set
immediately = trueso the SQL runs as soon as the object is constructed. - Rebind and call
operator()as many times as needed; under the hood it reuses the prepared statement stored in the connection’s statement cache. - Returns
truefromstep_once()only when SQLite reportsSQLITE_ROW, which usually indicates a trigger produced output.
Example usage
sqlite::execute migrate{
db,
R\"SQL(
CREATE TABLE IF NOT EXISTS users(
id INTEGER PRIMARY KEY,
email TEXT NOT NULL UNIQUE,
created_at INTEGER NOT NULL
)
)SQL\",
true // run immediately
};
sqlite::execute insert{db, "INSERT INTO users(email, created_at) VALUES(?, ?)"};
insert % "dev@example.com" % sqlite::clock::now();
insert();
Nothing fancy happens here—execute literally inherits command,
so all the binding helpers and error handling behave exactly the same.
Public API
| Member | Description |
|---|---|
execute(connection& con, std::string const& sql, bool immediately = false) |
Prepares sql and, if immediately is true, runs step_once() inside the constructor. |
~execute() |
Inherits command's destructor to finalize the statement. |