Delphi - How to split string concatenation into multiple lines
I have a long SQL text that I want to assign to a SQL query. I do it like this:
SQL.Text:= 'SELECT T1.COLUMN1,T2.COLUMN2,T1COLUMN3..........,'+
' T1.COLUMNn FROM TABLE1 T1 INNER JOIN '+
' TABLE2 T2 ON T1.ID=T2.ID'+
' WHERE T1.COLUMN10=100'
The actual SQL is 20 times longer than this. My problem is with line breaks. When I format the original code (Ctrl + D) it sometimes leaves lines as I type, but other times it removes line breaks and I get something like this:
'SELECT T1.COLUMN1,T2.COLUMN2,T1COLUMN3 ' + 'FROM TABLE1 T1 INNER JOIN '+ 'TABLE2 T2 ON T1.ID=T2.ID'
And this leads to the error "string is too long (more than 1023 characters)". Interestingly, this does not happen with all lines. I cannot understand the difference between the lines that will be affected and those that will not. I need a line break after or before the "+" sign. How to do it?
+3
source to share
2 answers
Try assigning a value on each line:
SQL.Text := 'SELECT T1.COLUMN1,T2.COLUMN2,T1COLUMN3..........,';
SQL.Text := SQL.Text + ' T1.COLUMNn FROM TABLE1 T1 INNER JOIN ';
SQL.Text := SQL.Text + ' TABLE2 T2 ON T1.ID=T2.ID';
SQL.Text := SQL.Text + ' WHERE T1.COLUMN10=100';
I know it looks ugly, but I think it solves your problem.
-1
source to share