This is a shortcut for shoving the results of an inline into your choice of variables. Called without arguments, the tag will create one var for each field returned, named the same as the field. Or, use -name and -type to create a map, array, or pair array containing all the values. Finally, you can use -convert to pass a map of type conversions to the tag and you can override the type of any field. Requires [cast].
Parameters
-type
string, optional
Tells the tag to create either a map, array, or pairarray from the field values.
-name
string, optional
The name of the variable to create to hold the field values when -type is used. If omitted, uses 'result.'
-convert
map, optional
Shortcut to override the default type conversion for a given field. Accepts a map of field names to data types.
Sample Usage
var('sql' = 'SELECT * FROM global_prefs LIMIT 1');
inline(
-username='xxxxxx',
-password='xxxxxx',
-database='lasso_internal',
-sql=$sql
);
// with no arguments, creates a var for each field
fields_convert;
iterate(field_names, local('i'));
#i + ': ' + (var_defined(#i) ? 'defined' | 'not defined') + '<br>\n';
/iterate;
'<hr>\n';
// specify a name and type to create a map, array, or pair array
var('mytypes') = array('array','map','pairarray');
iterate($mytypes, local('t'));
'Type: ' + #t + '<br><br>\n';
fields_convert( -name='myrecord', -type=#t);
$myrecord;
'<hr>\n';
/iterate;
// optionally accepts a map of type conversions
// either for individual variables...
var('conversions') = map(
'id' = integer,
'size' = integer,
'modified' = date
);
fields_convert( -convert=$conversions);
iterate(field_names, local('f'));
#f + ': ' + var(#f)->type + '<br>\n';
/iterate;
'<hr>\n';
// ...or elements within the container type
// in this case, an array
fields_convert(
-name='myrecord',
-type='array',
-convert=$conversions
);
iterate($myrecord, local('f'));
#f + ': ' + #f->type + '<br>\n';
/iterate;
'<hr>\n';
// ...a map...
fields_convert(
-name='myrecord',
-type='map',
-convert=$conversions
);
iterate($myrecord->keys, local('f'));
#f + ': ' + $myrecord->find(#f)->type + '<br>\n';
/iterate;
'<hr>\n';
// ...or a pair array...
fields_convert(
-name='myrecord',
-type='pairarray',
-convert=$conversions
);
iterate($myrecord, local('f'));
#f->first + ': ' + #f->second->type + '<br>\n';
/iterate;
'<hr>\n';
/inline;
Source Code
Click the "Download" button below to retrieve a copy of this tag,
including the complete documentation and sample usage shown
on this page. Place the downloaded ".inc" file in your
LassoStartup folder, restart Lasso, and you can begin using this
tag immediately.