PersistentTable/RawCommand - Maple Help

PersistentTable

 RawCommand
 issue a command to the database managing a PersistentTable connection

 Calling Sequence RawCommand(connection, command)

Parameters

 connection - PersistentTable object created with the Open command command - string giving an SQLite command

Description

 • The RawCommand command issues a command to the database managing a PersistentTable connection. This calls the Database[SQLite][Execute] command and returns what it returns.
 • The internal layout of PersistentTable tables is not documented, and not guaranteed to remain the same in future Maple releases. We do not recommended that you rely on this layout with your code.
 • The RawCommand command can be used to manage database transactions, issuing the command RawCommand("BEGIN TRANSACTION") to start a transaction and RawCommand("COMMIT TRANSACTION") to commit it or RawCommand("ROLLBACK TRANSACTION") to roll it back. In a PersistentTable (or any SQLite database), by default, each change to the database is a separate transaction. If you make many changes to a SQLite database, you generally get much better performance if you put them in a single transaction rather than in many individual transactions. Moreover, if you are able to group logically connected changes together in a transaction, then if something goes wrong (such as a power failure, or if your Maple session crashes, for example), the connected changes will either all be written to the database, or none of them will. This can help ensure that the database is in a consistent state upon restart.

 • Persistent tables are in general thread safe as of Maple 2021; see the Thread Safety section of the PersistentTable overview page for more details and caveats.

Examples

 > $\mathrm{with}\left(\mathrm{PersistentTable}\right)$
 $\left[{\mathrm{Close}}{,}{\mathrm{Count}}{,}{\mathrm{Get}}{,}{\mathrm{GetAll}}{,}{\mathrm{GetKeys}}{,}{\mathrm{Has}}{,}{\mathrm{MaybeGet}}{,}{\mathrm{Open}}{,}{\mathrm{RawCommand}}{,}{\mathrm{Set}}\right]$ (1)
 > $\mathrm{store}≔\mathrm{Open}\left(":memory:",\mathrm{style}=\left[k::'\mathrm{integer}',v::\mathrm{anything}\right]\right)$
 ${\mathrm{store}}{≔}{\mathrm{<< 2-column persistent table at :memory: >>}}$ (2)

These values are stored before the start of the transaction.

 > $\mathrm{store}\left[5\right]≔v\left(5\right)$
 ${{\mathrm{store}}}_{{5}}{≔}{v}{}\left({5}\right)$ (3)
 > $\mathrm{store}\left[4\right]≔v\left(4\right)$
 ${{\mathrm{store}}}_{{4}}{≔}{v}{}\left({4}\right)$ (4)
 > $\mathrm{GetAll}\left(\mathrm{store}\right)$
 $\left\{\left[{4}{,}{v}{}\left({4}\right)\right]{,}\left[{5}{,}{v}{}\left({5}\right)\right]\right\}$ (5)
 > $\mathrm{RawCommand}\left(\mathrm{store},"BEGIN TRANSACTION"\right)$
 > $\mathrm{store}\left[3\right]≔v\left(3\right)$
 ${{\mathrm{store}}}_{{3}}{≔}{v}{}\left({3}\right)$ (6)
 > $\mathrm{store}\left[7\right]≔v\left(7\right)$
 ${{\mathrm{store}}}_{{7}}{≔}{v}{}\left({7}\right)$ (7)
 > $\mathrm{store}\left[5\right]≔v\left(6\right)$
 ${{\mathrm{store}}}_{{5}}{≔}{v}{}\left({6}\right)$ (8)
 > $\mathrm{GetAll}\left(\mathrm{store}\right)$
 $\left\{\left[{3}{,}{v}{}\left({3}\right)\right]{,}\left[{4}{,}{v}{}\left({4}\right)\right]{,}\left[{5}{,}{v}{}\left({6}\right)\right]{,}\left[{7}{,}{v}{}\left({7}\right)\right]\right\}$ (9)

Now we abort the transaction. The changes since the start of the transaction are rolled back.

 > $\mathrm{RawCommand}\left(\mathrm{store},"ROLLBACK TRANSACTION"\right)$
 > $\mathrm{GetAll}\left(\mathrm{store}\right)$
 $\left\{\left[{4}{,}{v}{}\left({4}\right)\right]{,}\left[{5}{,}{v}{}\left({5}\right)\right]\right\}$ (10)
 > $\mathrm{Close}\left(\mathrm{store}\right)$

Compatibility

 • The PersistentTable[RawCommand] command was introduced in Maple 2021.