sqlColumns function
Converts a list of fields to a SQL fragment separated by comma.
Note: if fields is null, "*" is returned, i.e., all fields are assumed.
if fields is empty, 1 is returned (so it is easier to construct
a SQL statement).
Each field will be enclosed with a pair of double quotations, such as
foo => "foo".
However, if it starts with a number or contains ( or ",
it'll be output directly. In other words, it is considered as an expression.
For example, you can pass a field as
("assignee" is not null or "due" is null).
Furthermore, you can name it with an alias:
("assignee" is not null or "due" is null) alive
Here is another example:
access.query('select ${sqlColumns(fields)} from "Foo"');
shortcut- the table shortcut to prefix the field (column name). If specified, the result will beT."field1",T."field2"ifshortcutisT. Note:shortcutis case insensitive.
Implementation
String sqlColumns(Iterable<String>? fields, [String? shortcut]) {
if (fields == null) return "*";
if (fields.isEmpty) return '1';
final sql = StringBuffer();
addSqlColumns(sql, fields, shortcut);
return sql.toString();
}