SQL Dialect Support in Gpre - Design Specification

See also: Functional Specification

High-Level Design

The InterBase 6.0 engine relies on sql dialects to unambiguously support sql date , time , delimited ids and 64 bit integers. Embedded sql programs need a way to specify dialects so that they can make use of these new features. gpre sets the default dialect based on the compile time database dialect. If the user elects to set a different dialect then he can do so by embedding SET SQL DIALECT statement within the program file. gpre will parse those statements and sets the dialects accordingly.

High-Level Algorithm

Gpre has a well defined behavior. It parses the input file in two passes. In pass1 it checks for the syntax correctness of the embedded statements while creating action items for each of these statements. As soon as it sees a database name, it gets the schema for that database and stores it in an internal table. Next it generates all the necessary blr and variables. In pass2 it creates the output file, comments the embedded statements and generates the necessary api calls. In order to support the sql dialect functionality gpre has to be modified to do the following.

  • Make gpre parse SET SQL DIALECT statement
  • On attaching to the database get the database dialect info.
  • Create action item representing SET SQL DIALECT statement.
  • Generate errors/warnings if needed.
  • Pass the specified dialect to the apis.


embedded sql programs can specify dialects by using statements "EXEC SQL SET DIALECT n" where n is 1, 2 or 3.

Detailed Design

Internal Data Structures

A new data structure to hold the dialect value is defined as

typedef struct sdt {
     USHORT sdt_dialect;
} *SDT;

Also a new action item type ACT_sql_dialect is defined. Two new variables sw_sql_dialect and compiletime_db_dialect are defined as USHORT.

Detailed Algorithm


This module takes care of parsing command line argument. The function get_switches() looks for IN_SW_GPRE_SQLDIALECT and gets the passed dialect. The old SQLDA command line argument is no longer valid. An error will be generated if the user tries to use it. XSQLDA will be the default.


The function MET_database() is modified to get the compiletime database dialect info. isc_database_info() call is made after attaching to the database to get the dialect info. If the info call returned error i.e. isc_info_error back them it is assumed that the server didn't understand the dialect info. This would mean that the server is pre 6.0 server and hence can only understand dialect 1. The result of the info call will be set as compiletime_db_dialect.


This module parses the SET SQL DIALECT statement. The function act_set() has been modified to parse the statement. When the function act_set() sees SET SQL DIALECT statement, it calls a new function act_set_dialect() which extracts the dialect value, creates ACT_sql_dialect action item, verifies if the dialect value is within the range of 1-3 and generate errors or warnings if necessary.

ada.c, c_cxx.c, cob.c, ftn.c, pas.c

These modules generate the language specific api calls hence all they have to do is get the current dialect from the action item and pass it to the api calls. Each of these module has an action function named as XXX_action(). In case of ada it is ADA_action(). In case of cob it is COB_action() and so on. These functions extract the dialect value from the action item. The following apis take dialect as one of their arguments.


New/Affected Modules

All affected modules are from gpre component.

  • ada.c, c_cxx.c, cob.c, ftn.c, pas.c: Pass the specified dialect to the api's
  • gpre.c: Parse the command line option for dialects
  • met.e: Gets the database dialect info.
  • sql.c: Parse the embedded program file for "SET DIALECT" statements and create action item.
  • gpre.h, gpreswi.h: Define the structure to hold dialect value.
  • hsh.h, words.h: Define the new symbol KW_DIALECT.

Testing Considerations

Two things.

  1. New tests should to be written which sets/unsets sql dialects in embedded sql programs.
  2. Old style SQLDA is retired in this version of gpre. Hence all those gpre tests which used -sqlda old should be rewritten and use XSQLDA. Chapter 4 in the programmers guide explains how to use XSQLDA.