#include "zmsql.h"

#define NUM_SQLS 2
#define SERVER "localhost" 
#define DATABASE "test"
#define TABLE "zmsqltest"

main()
{
int NumFlds;
int NumDBs,NumTables;
char result[1000];
int i,j,k;
char data[2048];
ZField FldInfo;
int minid=70,maxid=75;
char namelike[]="item";
ZDBList DBList;
ZTableList TableList;

ZmSQLConnection TestDB;
ZmSQL sql(&TestDB);
NumDBs=TestDB.GetDBList(SERVER,DBList);
NumTables=TestDB.GetTableList(SERVER,DATABASE,TableList);
printf("Databases on %s\n****************\n",SERVER);
for(i=0;i<NumDBs;i++)	
	printf("%s\n",DBList[i]);
printf("Tables in \"%s\" on %s\n****************\n",DATABASE,SERVER);
for(i=0;i<NumTables;i++)	
	printf("%s\n",TableList[i]);
TestDB.SetServer(SERVER);
TestDB.SetDB(DATABASE);
printf("Fields in '%s'\n********************\n",DATABASE);
i=0;
while(TestDB.Field[i])	
	printf("%s\n",TestDB.Field[i++]->Name);
if(!sql.Open("select * from %s where num > %d and num < %d and name LIKE '%%%s%%'",TABLE,minid,maxid,namelike))	{
	printf("Error opening sql\n");
	return 0;
	}
NumFlds=sql.GetNumCols();
printf("\nField #\t\tField Name\t\tField Length\n______________________________________________________\n");
for(k=0;k<NumFlds;k++)	{
	sql.GetFieldInfo(k,&FldInfo);
	printf("%d\t\t%s.%s\t\t%d\n",k,FldInfo.Table,FldInfo.Name,FldInfo.Length);
	}
printf("\nThe SQL query result:\n"); 
while(sql.GetNextRecord())	{	
	printf("-----------------------------------\n");
	for(j=0;j<NumFlds;j++)	{
		sql.GetSQLData(j,data,sizeof(data));
		printf("%s\n",data);
		}
	}
printf("\n");
return 1;
}
