Graeme, I am a big fan of your messages. You have many good ideas and I sometimes read a theme that I am not interested in just to see your response.

In this case however I think you are wrong. Pascal has fantastic inherent type and error checking in its structure. It would be wrong to have an editor that can introduce unwanted errors. Just one way that I can see potential problems in you code style is the line end. Not every string is a SQL text which is very flexible in it's interpretation. Other string may want one or more spaces between the last symbol on the top line and the first on the second, today the editor normally strips these spaces away. If they are left in, they are spaces that visually I can not determine just by looking at the code. A mess.

For this reason I would be against this implementation. Maybe taking away the need for the + sign at the end of the line. The strings are concatenated until a semi-colon or other symbol is encountered


On 06/07/2017 11:13, Graeme Geldenhuys wrote:
Ever had a problem like this?  You have some SQL, say:

SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
FULL OUTER JOIN Orders
ON Customers.CustomerID = Orders.CustomerID
ORDER BY Customers.CustomerName;


and you want to add that SQL to the SQL property of a query at runtime. You end up either having to turn this into a string like this:

'SELECT Customers.CustomerName, Orders.OrderID' +
'FROM Customers' +
'FULL OUTER JOIN Orders' +
'ON Customers.CustomerID = Orders.CustomerID' +
'ORDER BY Customers.CustomerName;'

or manually in each line like this (oh please NEVER do this!):

FDQuery1.SQL.Add('SELECT Customers.CustomerName, Orders.OrderID');
FDQuery1.SQL.Add('FROM Customers');
FDQuery1.SQL.Add('FULL OUTER JOIN Orders');
FDQuery1.SQL.Add('ON Customers.CustomerID = Orders.CustomerID');
FDQuery1.SQL.Add('ORDER BY Customers.CustomerName;');


Now this has normally not been much of a problem for me, because part of tiOPF's support tools, there is a tool name tiSQLEditor that does bi-directional conversions for you - to and from quoted strings for SQL. And even straight from/to the clipboard. This tool has been around for 17+ years. But why must this be a tool problem or a IDE problem? Why can't the Object Pascal language solve this for us!

[the following part quoted from a online discussion by somebody else - I fully agree with his thoughts though]

Imagine if FPC had type inference and multi-line strings, neither very exotic features. The code then becomes:

=========================================
var query := '''SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
FULL OUTER JOIN Orders
ON Customers.CustomerID = Orders.CustomerID
ORDER BY Customers.CustomerName;'''

FDQuery1.SQL.Add(query);
=========================================


Easier to read, easier to edit, no need for a IDE wizard or external tools.

Language features like this is what increases productivity. But unfortunately it seems we all rather rely on a specific tool or IDE to improve our productivity - thus also locking us into using those tools only.


Regards,
  Graeme


_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to