How embedded SQL program in C gets executed as in the backend?

94 views Asked by At

When a C program is written using Embedded SQL, (eg: lets assume that a table is created with values inserted), how it gets executed in the backend before displaying the output table in the frontend? Help is appreciated...!

1

There are 1 answers

0
a3.14_Infinity On BEST ANSWER
  • SQL statements are embedded into host language, say for example: C
  • So, we have SQL statements and C language statements and in this case, SQL statements are embedded in C source code.
  • Host Language code is compiled by Host compiler, Embedded language code is first preprocessed by embedded SQL preprocessor and output of preprocessor is nothing but C code, which are C-library calls, which are compiled by C compiler.

As we have directives like #include, #define for a C preprocessor, we have few directives for SQL embedded preprocessor like: EXEC SQL begin declare section and EXEC SQL end declare section

EXEC SQL begin declare section;
int cno;
varchar cname[31];
varchar street[31];
int zip;
char phone[13];
EXEC SQL end declare section;

Here, the SQL embedded preprocessor conversion is shown below:-

/* varchar cname[31]; */
struct {
unsigned short len;
unsigned char arr[31];
} cname;

This is just to give an idea of how embedded SQL works. For more detailed presentation, you may refer to Oracle-8 Embedded SQL