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

exec sql whenever sqlerror sqlprint;

exec sql include sqlca;
exec sql include ../regression;

int
main (void)
{
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[25] = "klmnopqrst";
	char *t = (char *)malloc(11);
	double f;
EXEC SQL END DECLARE SECTION;

	strcpy(t, "0123456789");
	setlocale(LC_ALL, "C");

	ECPGdebug(1, stderr);

        EXEC SQL CONNECT TO REGRESSDB1;

	EXEC SQL SET AUTOCOMMIT = ON;

 	EXEC SQL BEGIN WORK;

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

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

	EXEC SQL INSERT INTO test(f,i,a,text) VALUES(140787.0,2,:a,:text);

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

	EXEC SQL COMMIT;

	EXEC SQL BEGIN WORK; 

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

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

	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 SELECT a
	 INTO :text
	 FROM test
	 WHERE f = :f;

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

	EXEC SQL DROP TABLE test;

	EXEC SQL COMMIT;

	EXEC SQL DISCONNECT;

	free(t);

	return (0);
}
