Database[SQLite] - Maple Programming Help

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

Database[SQLite]

 FetchRow
 fetch row from prepared statement

 Calling Sequence FetchRow( statement, column, valuetype  )

Parameters

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

Description

 • The FetchRow command returns value of all columns for the current row.
 • In order to fetch the next row call the Step command while it return RESULT_ROW.
 • If valuetype is a string then the type conversion it specifies applies to all columns.
 • If valuetype is a list of strings then type of column is determined by a corresponding entry in the list.

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 2"\right)$
 ${\mathrm{stmt}}{≔}{"SQLite statement"}{,}{"SELECT date, CAN FROM population LIMIT 2"}$ (2)
 > $\mathrm{Step}\left(\mathrm{stmt}\right):$

Fetch the first row

 > $\mathrm{FetchRow}\left(\mathrm{stmt}\right)$
 $\left[{"1960-12-31"}{,}{1.7909009}{}{{10}}^{{7}}\right]$ (3)

Fetch the second row, but change the valuetype to "integer" for the first column and "text" for the second

 > $\mathrm{Step}\left(\mathrm{stmt}\right):$
 > $\mathrm{FetchRow}\left(\mathrm{stmt},'\mathrm{valuetype}'=\left["integer","text"\right]\right)$
 $\left[{1961}{,}{"18271000.0"}\right]$ (4)
 > $\mathrm{Finalize}\left(\mathrm{stmt}\right):$

Select all data row by row

 > $\mathrm{stmt}≔\mathrm{Prepare}\left(\mathrm{connection},"SELECT date, CAN FROM population LIMIT 10"\right)$
 ${\mathrm{stmt}}{≔}{"SQLite statement"}{,}{"SELECT date, CAN FROM population LIMIT 10"}$ (5)
 > $\mathbf{while}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{Step}\left(\mathrm{stmt}\right)=\mathrm{RESULT_ROW}\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{print}\left(\mathrm{FetchRow}\left(\mathrm{stmt},'\mathrm{valuetype}'="integer"\right)\right)\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\mathbf{end}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}$
 $\left[{1960}{,}{17909009}\right]$
 $\left[{1961}{,}{18271000}\right]$
 $\left[{1962}{,}{18614000}\right]$
 $\left[{1963}{,}{18964000}\right]$
 $\left[{1964}{,}{19325000}\right]$
 $\left[{1965}{,}{19678000}\right]$
 $\left[{1966}{,}{20048000}\right]$
 $\left[{1967}{,}{20412000}\right]$
 $\left[{1968}{,}{20744000}\right]$
 $\left[{1969}{,}{21028000}\right]$ (6)
 > $\mathrm{Finalize}\left(\mathrm{stmt}\right):$
 > $\mathrm{Close}\left(\mathrm{connection}\right):$

Compatibility

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