FetchRow - Maple Help

Database[SQLite]

 FetchRow
 fetch row from a prepared SQL statement

 Calling Sequence FetchRow( statement, opts )

Parameters

 statement - prepared SQL statement obtained using the Prepare command

Options

 • valuetype = string or list(string)
 The valuetype option specifies the type of the value. It may be one of the strings "auto", "blob", "float", "integer", "text", or a list of those strings. If a list, then the type of a column is specified by the corresponding element in the list; if a string, then it specifies the type of all columns. See the Database[SQLite] help page for more information about type conversion between SQLite and Maple. The default is "auto".

Description

 • The FetchRow command returns the values of all columns of the current row of a prepared SQL statement.
 • In order to fetch the next row, call the Step command while it returns RESULT_ROW.

Examples

 > $\mathrm{with}\left(\mathrm{Database}\left[\mathrm{SQLite}\right]\right):$
 > $\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"}$ (1)
 > $\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]$ (2)

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]$ (3)
 > $\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"}$ (4)
 > $\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]$ (5)
 > $\mathrm{Finalize}\left(\mathrm{stmt}\right):$
 > $\mathrm{Close}\left(\mathrm{connection}\right):$

Compatibility

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