Database[SQLite] - Maple Programming Help

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

Database[SQLite]

 Fetch
 fetch value of a single column

 Calling Sequence Fetch( statement, column, valuetype  )

Parameters

 statement - prepared statement obtained using Prepare command column - index of the column valuetype - type of the output data, default is "auto"

Description

 • The Fetch command returns value of the column for the current row.
 • The leftmost column of the result set has the index 0.

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)
 > $\mathrm{db}≔\mathrm{FileTools}\left[\mathrm{JoinPath}\right]\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"}$ (2)
 > $\mathrm{Step}\left(\mathrm{stmt}\right):$

Fetch the first column

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

Fetch the second column

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

Fetch both columns using all possible values for valuetype option

 > $\mathbf{for}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{vt}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{in}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\left["auto","blob","float","integer","text"\right]\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{2.0em}{0.0ex}}\mathrm{Step}\left(\mathrm{stmt}\right);\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{2.0em}{0.0ex}}\mathrm{print}\left(\mathrm{vt},\mathrm{Fetch}\left(\mathrm{stmt},0,'\mathrm{valuetype}'=\mathrm{vt}\right)\right);\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{2.0em}{0.0ex}}\mathrm{print}\left(\mathrm{vt},\mathrm{Fetch}\left(\mathrm{stmt},1,'\mathrm{valuetype}'=\mathrm{vt}\right)\right);\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{2.0em}{0.0ex}}\mathrm{Reset}\left(\mathrm{stmt}\right)\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\mathbf{end}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{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"}$ (5)
 > $\mathrm{Finalize}\left(\mathrm{stmt}\right):$
 > $\mathrm{Close}\left(\mathrm{connection}\right):$

Compatibility

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