SYMPTOMS
An error may occur when, in order to preserve a set of square brackets, you add an extra set of brackets to an SQL statement. For example:
Select * from myview where [[tableA.field1]]
The error that is returned depends on which Open Database Connectivity (ODBC) driver is used and on the structure of the SQL statement, but can include a syntax error, an invalid table or field name, or a variety of other problems.
CAUSE
The Microsoft Foundation Classes (MFC) ODBC function
CDatabase::ReplaceBrackets replaces square brackets in an SQL statement with a driver-dependent quote character (SQL_IDENTIFIER_QUOTE_CHAR). The
CDatabase::ReplaceBrackets function, which is called by the
CRecordset::Open function, is used frequently.
When double brackets are replaced with single brackets, the string length changes but the
CDatabase::ReplaceBrackets function does not make the necessary adjustment. The SQL statement that is passed to the driver contains extra characters at the end of the string, which can cause errors.
WORKAROUND
Pad the end of your SQL statement with one blank space for each double bracket used. For example, in the following statement
"Select * from myview where [[tableA.field1]]"
place two spaces at the end of the statement:
"Select * from myview where [[tableA.field1]] "