Coding SQL statements in C and C++ applications
To embed SQL statements in an ILE C or C++ program, you need to be aware of some unique application and coding requirements. This topic also defines the requirements for host structures and host variables.
Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.
- Defining the SQL communication area in C and C++ applications that use SQL
A C or C++ program can be written to use the SQLCA to check return status for embedded SQL statements, or the program can use the SQL diagnostics area to check return status. - Defining SQL descriptor areas in C and C++ applications that use SQL
There are two types of SQL descriptor areas. One is defined with the ALLOCATE DESCRIPTOR statement. The other is defined using the SQL descriptor area (SQLDA) structure. In this topic, only the SQLDA form is discussed. - Embedding SQL statements in C and C++ applications that use SQL
SQL statements can be coded in a C or C++ program wherever executable statements can appear. - Using host variables in C and C++ applications that use SQL
All host variables used in SQL statements must be explicitly declared prior to their first use. - Using host structures in C and C++ applications that use SQL
In C and C++ programs, you can define a host structure, which is a named set of elementary C or C++ variables. - Using arrays of host structures in C and C++ applications that use SQL
In C and C++ programs, you can define a host structure array that has the dimension attribute. Host structure arrays have a maximum of two levels, even though the array might occur within a multiple-level structure. Another structure is not needed if a varying-length character string or a varying-length graphic string is not used. - Using pointer data types in C and C++ applications that use SQL
You can also declare host variables that are pointers to the supported C and C++ data types, with the following restrictions. - Using typedef in C and C++ applications that use SQL
You can also use the typedef declarations to define your own identifiers that will be used in place of C type specifiers such as short, float, and double. - Using ILE C compiler external file descriptions in C and C++ applications that use SQL
You can use the C or C++ #pragma mapinc directive with the #include directive to include external file descriptions in your program. - Determining equivalent SQL and C or C++ data types
The precompiler determines the base SQLTYPE and SQLLEN of host variables based on the table. If a host variable appears with an indicator variable, the SQLTYPE is the base SQLTYPE plus one. - Using indicator variables in C and C++ applications that use SQL
An indicator variable is a two-byte integer (short int).
Parent topic: Embedded SQL programming
Related concepts: