One of the things that annoys me about working with SQL in OO languages is to define SQL statements in strings.
When I was working on IBM mainframes, the languages used the SQL preprocessor to parse SQL statements from native code, so the statements could be written to the cleartext text file without obfuscating the lines, for example, EXEC SQL exists in Cobol .... Syntax Design END- EXEC, which allows pure SQL statements to be embedded in Cobol code.
<pure cobol code, including assignment of value to local variable HOSTVARIABLE> EXEC SQL SELECT COL_A, COL_B, COL_C INTO :COLA, :COLB, :COLC FROM TAB_A WHERE COL_D = :HOSTVARIABLE END_EXEC <more cobol code, variables COLA, COLB, COLC have been set>
... this makes the SQL statement very easy to read and check for errors. Between EXEC SQL tokens .... END-EXEC there are no restrictions on indentation, lines, etc., Therefore, you can format the SQL statement to taste.
Note that this example is designed to select a single row, when a result set with multiple rows is expected, the encoding is different (but still v. Is easy to read).
So, taking Java as an example
What made the old COBOL approach undesirable? With this approach, not only SQL, but also system calls can be more readable. Let me call it the built-in preprocessor method in a foreign language.
Will an embedded preprocessor for foreign languages for SQL be useful? Would you see the advantage of writing your own SQL statements inside java code?
Edit
I really ask if you think SQL in OO is a return, and if not, what can be done to make it better.
java sql preprocessor
Steve de caux
source share