FieldNameList | Names of variables to use for each field in each record. |
SelectStatement | A SELECT statement to run and get a result set from. |
Body | What to execute for each record in the result set. |
In a future release, we plan to improve on this functionality by parsing the SELECT statement and automatically create variables with the column names, similar to dict with
.
Also note, dbcmd eval
has similar functionality but will ask that you put the fields in an array. Note also, the tdbc::resultset
package exists, though this author has not yet taken a close look at its functionality.
Check this page for info about how to set up Gen for using database-related commands.
This code: (1) Creates a table and populates it, (2) Does a select and iterates over the result set, printing each record.
% RunSqlCreate my_table {id {integer primary key} desc text notes text}
% QQ [SqlInsertStatement my_table {desc 'one' notes 'uno'}]
% QQ [SqlInsertStatement my_table {desc 'two' notes 'dos'}]
% ForeachRecord {Desc Notes} {SELECT desc, notes FROM my_table} { puts "desc = $Desc, notes = $Notes" }
desc = one, notes = uno
desc = two, notes = dos