#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>

exec sql include sqlca;

#define       SQLCODE    sqlca.sqlcode

void
db_error (char *msg)
{
	sqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml] = '\0';
	printf ("%s: db error %s\n", msg, sqlca.sqlerrm.sqlerrmc);
	exit (1);
}

int
main ()
{
exec sql begin declare section;
	long i;
exec sql end declare section;
	struct timeval tvs, tve;

	gettimeofday(&tvs, NULL);

	exec sql connect 'mm';
	if (SQLCODE)
		db_error ("connect");

	exec sql create table perftest(number int4, ascii char16);
	if (SQLCODE)
                db_error ("create t");

	exec sql create unique index number on perftest(number);
	if (SQLCODE)
                db_error ("create i");

	for (i = 0;i < 1407; i++)
	{
		exec sql begin declare section;
			char text[16];
		exec sql end declare section;

		sprintf(text, "%ld", i);
		exec sql insert into perftest(number, ascii) values (:i, :text);
		if (SQLCODE)
			db_error ("insert");

		exec sql commit;
		if (SQLCODE)	
			db_error ("commit");
	}

	exec sql drop index number;
	if (SQLCODE)	
		db_error ("drop i");

	exec sql drop table perftest;
	if (SQLCODE)	
		db_error ("drop t");

	exec sql commit;
	if (SQLCODE)	
		db_error ("commit");

	gettimeofday(&tve, NULL);

	printf("I needed %ld seconds and %ld microseconds for this test\n", tve.tv_sec - tvs.tv_sec, tve.tv_usec - tvs.tv_usec);

	return (0);
}
