​A selection of topics on IT and its application to finance. 
​Send me your comments, questions ​or suggestions by clicking
h​ere


elmama
A simple Embedded C/SQL program showing the use of a host array 



#include <stdio.h>
#include <stdlib.h>
EXEC SQL INCLUDE "sqlca.h";

void sql_error();
void db_connect();
void get_tables();
void print_tables();



EXEC SQL BEGIN DECLARE SECTION;
    char table_name[1000][31];
EXEC SQL END DECLARE SECTION;

EXEC SQL VAR table_name IS STRING;

int nr_tables = 0;

main()
{
    EXEC SQL WHENEVER SQLERROR do sql_error();

    db_connect();

    get_tables();

    print_tables();
}

void get_tables()
{
    EXEC SQL SELECT table_name
    INTO :table_name

    FROM user_tables;

    nr_tables = sqlca.sqlerrd[2];

}

void print_tables()
{
    int i = 0;
    for (i=0;i<nr_tables;i++)
       fprintf(stdout,"%d %s\n",i,table_name[i]);
}


void sql_error()
{

    fprintf(stdout,"Error number = %d\n",sqlca.sqlcode);
    fprintf(stdout,"Error message = %s\n",sqlca.sqlerrm.sqlerrmc);
    exit(-1);
}

void db_connect()
{
    EXEC SQL BEGIN DECLARE SECTION;
    char *username = "scott";
    char *password = "tiger";
    EXEC SQL END DECLARE SECTION;


    EXEC SQL CONNECT :username IDENTIFIED BY :password;
}