PersistentTable/Get - Maple Help

PersistentTable

 Get
 retrieve a row from a PersistentTable connection
 MaybeGet
 maybe retrieve a row from a PersistentTable connection
 Set
 enter a row into a PersistentTable connection

 Calling Sequence Get(connection, [keys]) connection[keys] MaybeGet(connection, [keys], default) Set(connection, [keys], values) connection[keys] := values

Parameters

 connection - PersistentTable object created with the Open command keys - expression sequence of values for the key columns default - expression sequence of values to return if the keys are not found values - expression sequence of values to use for the non-key columns

Description

 • The Get command retrieves the row in the table given by the connection object that has the values in keys as its primary key, and returns the values that are not part of the primary key. If no such row exists, then it generates an error.
 • Indexing the connection object with keys is equivalent to calling Get.
 • The MaybeGet command retrieves the row in the table given by the connection object that has the values in keys as its primary key, and returns the values that are not part of the primary key. If no such row exists, then it returns default.
 • The Set command enters a new row into the connection object, or modifies an existing row, depending on whether a row with the given keys exists.
 • Assigning to a connection object indexed with keys is equivalent to calling Set.

 • 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{connection}≔\mathrm{Open}\left(":memory:",\mathrm{style}=\left[\mathrm{k1}::\mathrm{anything},\mathrm{k2}::'\mathrm{integer}',v::\mathrm{anything},\mathrm{primarykey}=2\right]\right)$
 ${\mathrm{connection}}{≔}{\mathrm{<< 3-column persistent table at :memory: >>}}$ (2)

We can add rows with the Set command or using indexing.

 > $\mathrm{Set}\left(\mathrm{connection},\left[x,3\right],{y}^{2}\right)$
 > $\mathrm{connection}\left[z,5\right]≔{y}^{3}$
 ${{\mathrm{connection}}}_{{z}{,}{5}}{≔}{{y}}^{{3}}$ (3)

If we retrieve a row, we can use Get, indexing, or MaybeGet. The former two methods generate an error if the key does not exist; the latter does not.

 > $\mathrm{Get}\left(\mathrm{connection},\left[x,3\right]\right)$
 ${{y}}^{{2}}$ (4)
 > $\mathrm{connection}\left[z,5\right]$
 ${{y}}^{{3}}$ (5)
 > $\mathrm{MaybeGet}\left(\mathrm{connection},\left[z,5\right],1\right)$
 ${{y}}^{{3}}$ (6)
 > $\mathrm{Get}\left(\mathrm{connection},\left[a,4\right]\right)$
 > $\mathrm{connection}\left[a,4\right]$
 > $\mathrm{MaybeGet}\left(\mathrm{connection},\left[a,4\right],1\right)$
 ${1}$ (7)
 > $\mathrm{Close}\left(\mathrm{connection}\right)$

Compatibility

 • The PersistentTable[Get], PersistentTable[MaybeGet] and PersistentTable[Set] commands were introduced in Maple 2021.