Function OdbcListSqlKeywords() Professional

Retrieves SQL keywords of the current data source.

Syntax
OdbcListSqlKeywords([<oSession>]) --> aKeywords
Parameters
<oSession>
The session object of a connected session to a datasource. If the parameter is not passed the current work area's session will be used. If the current workarea does not have a session, DacSession():getDefault() is used.
Return

The function returns an array containing SQL keywords used by the current ODBC data source.

Description

SQL (Structured Query Language) has - like any other programming language - so called keywords (in Xbase++ more strictly referred to as reserved keywords) which are used to construct a query statement, but also to manage the database. These keywords might not be used to name items of the database, like table or field names inside of a CREATE - statement.

Since not all data sources are conform to the same SQL standard and every vendor adds specific data types or other commands to the set of keywords it should be retrieved dynamically by using this function.

Examples
Potentially dangerous usage of DbCreate()
// DbCreate() 
PROCEDURE Test 
  // This is translated by the ODBCDBE into 
  // CREATE TABLE View (TIMESTAMP TIMESTAMP) 
  // Since "View" and "TIMESTAMP" are considered as keywords, this 
  // DbCreate() call will fail. 
  DbCreate( "View", {"TIMESTAMP", "D", 0, 0} ) 
RETURN 
Check for keywords first
// This is translated by the ODBCDBE into 
// CREATE TABLE View_ (TIMESTAMP_ TIMESTAMP) 
PROCEDURE CreateTable(cName, aStruct) 
  LOCAL aKw 

  aKw := OdbcListSqlKeywords(DacSession():getDefault()) 
  AEval( aStruct, {|e,i| IF(AScan(aKw, aStruct[i][1]) > 0, aStruct[i][1]] += "_")} ) 
  IF AScan( aKw, cName) > 0 
    cName += "_" 
  ENDIF 
  DbCreate( cName, aStruct ) 
RETURN 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.