StatementIterator
Implements: Iterator<Statement>, Iterable<Statement>
Source: api.js:744
An iterator over multiple SQL statements in a string, preparing and returning a Statement object for the next SQL statement on each iteration.
You can't instantiate this class directly, you have to use a Database object in order to create a statement iterator
@see Database#iterateStatements
Alias: StatementIterator
Example
// loop over and execute statements in string sql
for (let statement of db.iterateStatements(sql) {
statement.step();
// get results, etc.
// do not call statement.free() manually, each statement is freed
// before the next one is parsed
}
// capture any bad query exceptions with feedback
// on the bad sql
let it = db.iterateStatements(sql);
try {
for (let statement of it) {
statement.step();
}
} catch(e) {
console.log(
`The SQL string "${it.getRemainingSQL()}" ` +
`contains the following error: ${e}`
);
}Constructor
new StatementIterator(
sql: string,
db: Database,
): StatementIteratorParameters
sql(string) — A string containing multiple SQL statementsdb(Database) — The database from which this iterator was created
Instance Methods
next(): StatementIterator.StatementIteratorResult
Prepare the next available SQL statement
Returns
Throws
String— SQLite error or invalid iterator error
['return'](): StatementIterator.StatementIteratorResult
Free the resources held by this iterator, in case it will not be run to completion. This is called automatically when a for..of loop exits early (e.g. via break, return, or an exception), and can also be called manually.
Returns
getRemainingSQL(): String
Get any un-executed portions remaining of the original SQL string
Returns
String
Other
StatementIteratorResult: Object | Object
Properties
value(Statement) — the next available Statement (as returned byDatabase.prepare)done(boolean) — true if there are no more available statements