In-memory query engine over typed columns. Tables are filled row by row or loaded from sources (CSV files, folders, the program's own objects) and queried with SQL-like statements; aggregates, Describe() and Finder (file search) are included. Compile with -lib query.
Statement
A statement parsed once and run many times, with '?' placeholders for values bound before each run. Placeholders are numbered from 1, left to right. A SELECT runs with Execute; an INSERT, UPDATE, DELETE or CREATE TABLE with ExecuteUpdate.
Example
statement := table->Prepare("select id, score from runs where score > ? and label = ?");
statement->Bind(1, 0.5)->Bind(2, "cat");
results := statement->Execute();Operations
Bind #
Binds a value to a placeholder
method : public : Bind(index:Int, value:Compare) ~ StatementParameters
| Name | Type | Description |
|---|---|---|
| index | Int | placeholder number, from 1 |
| value | Compare | value |
Return
| Type | Description |
|---|---|
| Statement | this statement |
Bind #
Binds an Int to a placeholder
method : public : Bind(index:Int, value:Int) ~ StatementParameters
| Name | Type | Description |
|---|---|---|
| index | Int | placeholder number, from 1 |
| value | Int | value |
Return
| Type | Description |
|---|---|
| Statement | this statement |
Bind #
Binds a Float to a placeholder
method : public : Bind(index:Int, value:Float) ~ StatementParameters
| Name | Type | Description |
|---|---|---|
| index | Int | placeholder number, from 1 |
| value | Float | value |
Return
| Type | Description |
|---|---|
| Statement | this statement |
Bind #
Binds a Bool to a placeholder
method : public : Bind(index:Int, value:Bool) ~ StatementParameters
| Name | Type | Description |
|---|---|---|
| index | Int | placeholder number, from 1 |
| value | Bool | value |
Return
| Type | Description |
|---|---|
| Statement | this statement |
BindNull #
Binds NULL to a placeholder: an empty cell in INSERT and UPDATE; in a condition, a comparison no row passes, as every comparison with an empty cell is false
method : public : BindNull(index:Int) ~ StatementParameters
| Name | Type | Description |
|---|---|---|
| index | Int | placeholder number, from 1 |
Return
| Type | Description |
|---|---|
| Statement | this statement |
Execute #
Runs the query, copying the result into a new table
method : public : Execute() ~ TableReturn
| Type | Description |
|---|---|
| Table | result table, Nil on error (see GetError) |
ExecuteUpdate #
Runs an INSERT, UPDATE, DELETE, CREATE TABLE, CREATE INDEX or DROP INDEX (see Table->Execute). A statement that fails changes nothing.
method : public : ExecuteUpdate() ~ IntReturn
| Type | Description |
|---|---|
| Int | rows inserted, updated or deleted (0 for CREATE TABLE), -1 on error (see GetError) |
ExecuteView #
Runs the query without copying the result
method : public : ExecuteView() ~ ViewReturn
| Type | Description |
|---|---|
| View | result view, Nil on error (see GetError) |
Explain #
Tells how the statement reads its rows with the values bound now (see Table->Explain); a SELECT is run to find out, an UPDATE or DELETE is not
method : public : Explain() ~ StringReturn
| Type | Description |
|---|---|
| String | plan, Nil on error (see GetError) |
Example
s := table->Prepare("select * from runs where score > ?");
s->Bind(1, 0.9);
s->Explain()->PrintLine(); # where runs: SORTED index runs_score on score (>)GetError #
Gets the reason the last run failed
method : public : GetError() ~ StringReturn
| Type | Description |
|---|---|
| String | error, Nil if none |
GetParamCount #
Gets the number of placeholders
method : public : GetParamCount() ~ IntReturn
| Type | Description |
|---|---|
| Int | placeholder count |
IsQuery #
Whether the statement is a SELECT, which Execute runs; INSERT, UPDATE, DELETE and CREATE TABLE run with ExecuteUpdate
method : public : IsQuery() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true for a SELECT |