Actually I use these quite often. In the case of your SQL, which could as well come from the FireDAC query editor, I just copy the whole code, create a string array constant with a simple template, multi-paste the SQL and format the results:
const
cArr: TArray<string> = [ //
'SELECT', //
'DATE_FORMAT(co.order_date, ''%Y-%m'') AS order_month,', //
'DATE_FORMAT(co.order_date, ''%Y-%m-%d'') AS order_day,', //
'COUNT(DISTINCT co.order_id) AS num_orders,', //
'COUNT(ol.book_id) AS num_books,', //
'SUM(ol.price) AS total_price,', //
'SUM(COUNT(ol.book_id)) OVER (', //
' ORDER BY DATE_FORMAT(co.order_date, ''%Y-%m-%d'')', //
') AS running_total_num_books', //
'FROM cust_order co', //
'INNER JOIN order_line ol ON co.order_id = ol.order_id', //
'GROUP BY ', //
' DATE_FORMAT(co.order_date, ''%Y-%m''),', //
' DATE_FORMAT(co.order_date, ''%Y-%m-%d'')', //
'ORDER BY co.order_date ASC;', //
''];
procedure UseSQL;
begin
var qry := TFDQuery.Create(nil);
try
qry.SQL.AddStrings(cArr);
// ...
finally
qry.Free;
end;
end;
The same scheme also works for JSON or XML.
Interesting, that you bring up the SQL text, which is neatly split into multiple lines - probably for better readability.
Despite allowing string constants with more than 255 characters in one line, it would be more helpful to have string constants over multiple lines preserving linefeeds. Then it wouldn't even matter if the lines are limited to 255 characters each, although I expect this limit being lifted anyway whenever such a feature will be implemented.