#include <locale.h>
#include <string.h>

exec sql whenever sqlerror sqlprint;

exec sql include sqlca;

int
main ()
{
EXEC SQL BEGIN DECLARE SECTION;
	int i = 1;
	int *did = &i;
	int a[10] = {9,8,7,6,5,4,3,2,1,0};
	char text[10] = "klmnopqrst";
	char *t = "uvwxyz1234";
	double f;
	bool b = true;
	varchar database[3];
EXEC SQL END DECLARE SECTION;
	FILE *dbgs;

	setlocale(LC_ALL, "de_DE");
        
	if ((dbgs = fopen("log", "w")) != NULL)
                ECPGdebug(1, dbgs);

	strcpy(database.arr, "mm");
        EXEC SQL CONNECT TO :database;

	EXEC SQL SET AUTOCOMMIT = ON;

 	EXEC SQL BEGIN WORK;

	EXEC SQL CREATE TABLE test (f float, i int, a int[10], text char(10), b bool);

	EXEC SQL INSERT INTO test(f,i,a,text,b) VALUES(404.90,3,'{0,1,2,3,4,5,6,7,8,9}','abcdefghij', 'f');

	EXEC SQL INSERT INTO test(f,i,a,text,b) VALUES(140787.0,2,:a,:text,'t');
	
	EXEC SQL INSERT INTO test(f,i,a,text,b) VALUES(14.07,:did,:a,:t,:b);

	EXEC SQL COMMIT;

	EXEC SQL BEGIN WORK; 

	EXEC SQL SELECT f,text,b
         INTO :f,:text,:b
         FROM test
         WHERE i = 1;

	printf("Found f=%f text=%10.10s b=%d\n", f, text, b);

	f=140787;
	EXEC SQL SELECT a,text
	 INTO :a,:t
	 FROM test
	 WHERE f = :f;

	for (i = 0; i < 10; i++)
		printf("Found a[%d] = %d\n", i, a[i]);

	printf("Found text=%10.10s\n", t);

	EXEC SQL DROP TABLE test;

	EXEC SQL COMMIT;

	EXEC SQL DISCONNECT;

	if (dbgs != NULL)
                fclose(dbgs);

	return (0);
}
