Fetch - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Database[SQLite]

 Fetch
 fetch value of a single column from a prepared SQL statement

 Calling Sequence Fetch( statement, column, opts )

Parameters

 statement - prepared SQL statement obtained using the Prepare command column - nonnegint; index of the column opts - (optional) equation(s) of the form option = value; specify options for the Fetch command

Options

 • valuetype = string
 The valuetype option specifies the type of the value. It may be one of the strings "auto", "blob", "float", "integer", or "text". See the Database[SQLite] help page for more information about type conversion between SQLite and Maple. The default is "auto".

Description

 • The Fetch command returns the value of a column for the current row.
 • The column parameter specifies the column index; the leftmost column has index 0.

Examples

 > $\mathrm{with}\left({\mathrm{Database}}_{\mathrm{SQLite}}\right):$
 > $\mathrm{db}≔{\mathrm{FileTools}}_{\mathrm{JoinPath}}\left(\left[\mathrm{kernelopts}\left('\mathrm{datadir}'\right),"SQLite","G20-Population.db"\right]\right):$
 > $\mathrm{connection}≔\mathrm{Open}\left(\mathrm{db}\right):$

Select all data from table - prepare statement

 > $\mathrm{stmt}≔\mathrm{Prepare}\left(\mathrm{connection},"SELECT date, CAN FROM population LIMIT 1"\right)$
 ${\mathrm{stmt}}{≔}{"SQLite statement"}{,}{"SELECT date, CAN FROM population LIMIT 1"}$ (1)
 > $\mathrm{Step}\left(\mathrm{stmt}\right):$

Fetch the first column

 > $\mathrm{Fetch}\left(\mathrm{stmt},0\right)$
 ${"1960-12-31"}$ (2)

Fetch the second column

 > $\mathrm{Fetch}\left(\mathrm{stmt},1\right)$
 ${1.7909009}{×}{{10}}^{{7}}$ (3)
 > $\mathrm{Reset}\left(\mathrm{stmt}\right)$

Fetch both columns using all possible values for valuetype option

 > $\mathbf{for}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{vt}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{in}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\left["auto","blob","float","integer","text"\right]\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{do}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{Step}\left(\mathrm{stmt}\right);\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{print}\left(\mathrm{vt},\mathrm{Fetch}\left(\mathrm{stmt},0,'\mathrm{valuetype}'=\mathrm{vt}\right)\right);\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{print}\left(\mathrm{vt},\mathrm{Fetch}\left(\mathrm{stmt},1,'\mathrm{valuetype}'=\mathrm{vt}\right)\right);\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{Reset}\left(\mathrm{stmt}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{end do}$
 ${"auto"}{,}{"1960-12-31"}$
 ${"auto"}{,}{1.7909009}{×}{{10}}^{{7}}$
 ${"blob"}{,}\left[\begin{array}{cccccccccc}{49}& {57}& {54}& {48}& {45}& {49}& {50}& {45}& {51}& {49}\end{array}\right]$
 ${"blob"}{,}\left[\begin{array}{cccccccccc}{49}& {55}& {57}& {48}& {57}& {48}& {48}& {57}& {46}& {48}\end{array}\right]$
 ${"float"}{,}{1960.}$
 ${"float"}{,}{1.7909009}{×}{{10}}^{{7}}$
 ${"integer"}{,}{1960}$
 ${"integer"}{,}{17909009}$
 ${"text"}{,}{"1960-12-31"}$
 ${"text"}{,}{"17909009.0"}$ (4)
 > $\mathrm{Finalize}\left(\mathrm{stmt}\right):$
 > $\mathrm{Close}\left(\mathrm{connection}\right):$

Compatibility

 • The Database[SQLite][Fetch] command was introduced in Maple 18.
 • For more information on Maple 18 changes, see Updates in Maple 18.