A Standard SQL Syntax
Standardized SQL syntax is something of a Holy Grail. ODBC drivers generally do a good job of implementing it, whereas the DBI just ducks the issue entirely! The problem is that while SQL may be a standardized language in theory, in practice it’s far enough from the standard on most vendors’ databases to cause portability problems.
For example, even a simple task like concatenating two database fields needs to be written like this (for databases conforming to the SQL-92 standard):
SELECT first_name || ' ' || last_name FROM table
Other databases require one of these forms:
SELECT first_name + ' ' + last_name FROM table SELECT CONCAT(first_name, ' ', last_name) FROM table SELECT CONCAT(CONCAT(first_name, ' '), last_name) FROM table SELECT first_name CONCAT ' ' CONCAT last_name FROM table
The SQL dialect used by different database systems is riddled with such inconsistencies, not to mention endless “extensions” to the standard. This is a major headache for developers wishing to write an application that will work with any of a number of databases.
The ODBC approach to this problem is rather elegant. It allows portability when using standard SQL, but doesn’t prevent access to database-specific features. When an application passes an SQL statement to the driver, the driver parses it as an SQL-92 statement, and then rewrites it to match the actual syntax of the database being used.
If the parse fails because the SQL doesn’t conform to the standard, then the original SQL ...