The following is an example that connects to the database defined as the default. All rows are then fetched from the table INFORMATION_SCHEMA.TABLES.
The example is stored in a file called simple.ec.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
exec sql BEGIN DECLARE SECTION;
static char SQLSTATE[6];
exec sql END DECLARE SECTION;
main()
{
exec sql BEGIN DECLARE SECTION;
varchar schema[129], table [129];
char type [21];
exec sql END DECLARE SECTION;
exec sql DECLARE MYCURSOR CURSOR FOR
SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE
FROM INFORMATION_SCHEMA.TABLES;
/* Connect to default database */
exec sql CONNECT TO '' USER 'SYSADM' USING 'SYSADM';
exec sql OPEN MYCURSOR;
while (1) {
exec sql FETCH MYCURSOR INTO :schema, :table, :type;
if (strcmp(SQLSTATE, "02000") == 0) break; /* No more rows */
printf("%s\t%s\t%s\n", schema, table, type);
}
exec sql CLOSE MYCURSOR;
exec sql COMMIT;
exec sql DISCONNECT ALL;
exit(0);
}
The program is preprocessed as follows:
esql –c simple.ec
The resulting file, ‘simple.c’, is compiled using a C-compiler and then linked to the MimerSQL shared library or DLL. Usually, as an aid to this step, an example makefile or a build procedure is available in the software distribution package.
When executing the resulting ‘simple’ program, a list of the items selected will be displayed.
You can find a more complete example in distributed example program example.ec