Entering content frame

 General Rules 

Observe the following general rules when you embed SQL statements.

·        Precede each embedded SQL statement with the key words EXEC SQL to delimit it from the programming language statements. These key words must be on the same line, and can only be split with a blank character.

·        Finish each embedded SQL statement with a semicolon.

·        You can write embedded SQL statements that run over multiple lines.

·        You can interrupt embedded SQL statements with comments. Place the comments between the characters /* and */.

·        You can place comments about SQL statements at the end of the line. Precede comments at the end of a line with two dashes, --.

·        Precede the names of host variables and indicator variables within embedded SQL statements with a colon :

·        No other names used in an application program are allowed to start with a colon :

·        Names used in an application program must not start with the characters sq. This combination of characters is also reserved by the precompiler.

·        The program parts analyzed by the precompiler must not be elements of the preprocessor include statements (#define, #include).

See also: Overview of Precompiler Statements

EXEC SQL BEGIN DECLARE SECTION;
char addr [6];
char fname [8], lname [8];
EXEC SQL END DECLARE SECTION;

/* Generate table „customer“ */

EXEC SQL CREATE TABLE customer
(cno FIXED (4) KEY, address CHAR (5),
firstname CHAR (7), lastname CHAR (7));

/* Get values */

/* Add values to database */

EXEC SQL INSERT INTO customer
(cno, address, first name, last name)
VALUES (100, :addr, :fname, :lname);

/* Message in event of error */

if (sqlca.sqlcode != 0)
printf ("%d       ",sqlca.sqlcode);

 

Leaving content frame