Database[SQLite] - Maple Programming Help

Home : Support : Online Help : Connectivity : Database Package : SQLite : Database/SQLite/Step

Database[SQLite]

 Step
 evaluate prepared SQL statement

 Calling Sequence Prepare( statement )

Parameters

 statement - prepared statement obtained using Prepare command

Description

 • The Evaluate command evaluates the prepared SQL statement.
 • Possible return values are:
 – RESULT_BUSY means that the database engine was unable to acquire the database locks it needs to do its job. If the statement is a COMMIT or occurs outside of an explicit transaction, then you can retry the statement. If the statement is not a COMMIT and occurs within an explicit transaction then you should rollback the transaction before continuing.
 – RESULT_DONE means that the statement has finished executing successfully. Step should not be called again on this prepared statement without first calling Reset to reset the statement back to its initial state.
 – RESULT_ROW is returned each time a new row of data is ready for processing. The values may be accessed using the Fetch or FetchRow commands. Call Step again to retrieve the next row of data.

Examples

 > $\mathrm{with}\left(\mathrm{Database}\left[\mathrm{SQLite}\right]\right)$
 $\left[{\mathrm{Attach}}{,}{\mathrm{Bind}}{,}{\mathrm{ClearBindings}}{,}{\mathrm{Close}}{,}{\mathrm{ColumnCount}}{,}{\mathrm{ColumnNames}}{,}{\mathrm{Execute}}{,}{\mathrm{Fetch}}{,}{\mathrm{FetchAll}}{,}{\mathrm{FetchRow}}{,}{\mathrm{Finalize}}{,}{\mathrm{Open}}{,}{\mathrm{Opened}}{,}{\mathrm{Prepare}}{,}{\mathrm{RESULT_BUSY}}{,}{\mathrm{RESULT_DONE}}{,}{\mathrm{RESULT_ROW}}{,}{\mathrm{Reset}}{,}{\mathrm{Step}}\right]$ (1)

Create in memory database

 > $\mathrm{db}≔\mathrm{Open}\left(":memory:"\right):$

Create table test with on column val1

 > $\mathrm{Execute}\left(\mathrm{db},"CREATE TABLE test \left(val1\right)"\right)$

Insert sample data - prepare statement

 > $\mathrm{stmt}≔\mathrm{Prepare}\left(\mathrm{db},"INSERT INTO test VALUES \left(\text{'}row1\text{'}\right), \left(\text{'}row2\text{'}\right), \left(\text{'}row3\text{'}\right)"\right)$
 ${\mathrm{stmt}}{≔}{"SQLite statement"}{,}{"INSERT INTO test VALUES \left(\text{'}row1\text{'}\right), \left(\text{'}row2\text{'}\right), \left(\text{'}row3\text{'}\right)"}$ (2)

Execute the statement

 > $\mathrm{Step}\left(\mathrm{stmt}\right):$

Finalize the statement

 > $\mathrm{Finalize}\left(\mathrm{stmt}\right):$

Select data from table - prepare statement

 > $\mathrm{stmt}≔\mathrm{Prepare}\left(\mathrm{db},"SELECT * FROM test"\right)$
 ${\mathrm{stmt}}{≔}{"SQLite statement"}{,}{"SELECT * FROM test"}$ (3)

Evaluate the statement to get the first row

 > $\mathrm{Step}\left(\mathrm{stmt}\right):$

Get value

 > $\mathrm{Fetch}\left(\mathrm{stmt},0\right)$
 ${"row1"}$ (4)

Evaluate statement to get the next row

 > $\mathrm{Step}\left(\mathrm{stmt}\right):$

Get value

 > $\mathrm{Fetch}\left(\mathrm{stmt},0\right)$
 ${"row2"}$ (5)

Evaluate the statement to the next row

 > $\mathrm{Step}\left(\mathrm{stmt}\right):$

Get value

 > $\mathrm{Fetch}\left(\mathrm{stmt},0\right)$
 ${"row3"}$ (6)

Finalize the statement

 > $\mathrm{Finalize}\left(\mathrm{stmt}\right):$

Close database connection

 > $\mathrm{Close}\left(\mathrm{db}\right):$

Compatibility

 • The Database[SQLite][Step] command was introduced in Maple 18.