3 ms·
Something like C++'s {fmt}, specialized for SQL. fmt ("SELECT foo, bar FROM mytable WHERE id = {}", id); 'id' gets properly quoted, so that's not a concern an
by agent327 5y ago
Something like C++'s {fmt}, specialized for SQL.
fmt ("SELECT foo, bar FROM mytable WHERE id = {}", id);
'id' gets properly quoted, so that's not a concern anymore.
- joshuamorton 5y agoThis is simpler than what gp is asking for, they want the ability to dynamically change which columns are requested too, so change it to "foo, bar, baz", but still do so with reasonable safety.
- agent327 5y agoThat's supported too: fmt ("SELECT {:v}, {:v} FROM {:v} WHERE id = {}", colname1, colname2, tablename, id); The :v means "don't quote this, insert this string exactly as specified." It also has specialized handling for NULL values (i.e. it can generate 'IS NULL' instead of '= ...' if the value passed on is intended as a NULL value).