Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
#include"dqp.h"

void queryEditor(int,int,int,int,int,int,int,int);
void createTableQuery(char[250],int,int,int,int);
void insertQuery(char[250],int,int,int,int);
void deleteQuery(char[250],int,int,int,int);
void selectQuery(char[250],int,int,int,int);
void updateQuery(char[250],int,int,int,int);
void tableInfo(char[250],int,int,int,int);
void tableList(char[5],int,int,int,int);
void primaryKey(char[20]);
void sort(char [100][10][50],int,int,int,int);
void help();

void main()
{
char user[50],password[50];
int gm=DETECT,gd,button,x,y;
initgraph(&gm,&gd,"c:\\tc\\bgi");
initmouse();
MyWindow(0,0,630,470,"Database Query Processor");
restrictmouseptr(1,1,629,469);
showmouseptr();
setcolor(LIGHTRED);
settextstyle(4,0,5);
outtextxy(180,20,"WELCOME TO");

setcolor(YELLOW);
settextstyle(10,0,5);
outtextxy(30,60,"DATABASE QUERY");
outtextxy(145,140,"PROCESSOR");
setcolor(RED);
outtextxy(31,61,"DATABASE QUERY");
outtextxy(146,141,"PROCESSOR");

setcolor(BLUE);
settextstyle(0,0,2);
outtextxy(10,350,"Developed By:");

setcolor(BLACK);
settextstyle(8,0,2);
outtextxy(10,400,"Manik");
outtextxy(10,430,"Garg");
outtextxy(150,400,"Abhishek");
outtextxy(150,430,"Mairh");
outtextxy(300,400," Somil");
outtextxy(300,430,"Kr. Gupta");
outtextxy(500,400,"Ravindra");
outtextxy(500,430," Saini");

setcolor(BLACK);
Button(240,250,100,30,"Continue",0);
readMouse(240,250,100,30,"Continue");
/* ------------ mm -------------- */
setcolor(WHITE);
MyWindow(150,100,300,180,"Login");
setcolor(BLUE);
outtextxy(160,150,"Login: ");
outtextxy(160,180,"Password: ");
TextBox(250,150,150,20);
TextBox(250,180,150,20);
Button(220,230,60,30," OK",0);
Button(320,230,80,30,"Cancel",0);
strcpy(user,getString(253,153,150,20,1));
strcpy(password,getString(253,183,150,20,0));
if(strcmp(user,"Admin")==0
&& strcmp(password,"password")==0)
{
Button(220,230,60,30," OK",2);
readMouse(220,230,60,30," OK");
Button(220,230,60,30," OK",2);
initgraph(&gm,&gd,"c:\\tc\\bgi");
MyWindow(0,0,630,470,"Database Query Processor");
setcolor(BLACK);
outtextxy(10,40,"Submit your query here (click to submit query)" );
TextBox(5,60,620,100);
outtextxy(10,180,"Query Output");
TextBox(5,200,620,250);
initmouse();
restrictmouseptr(1,1,629,469);
showmouseptr();
queryEditor(5,60,620,100,5,200,620,250);
}
else
{
readMouse(320,230,80,30,"Cancel");
getch();
}
getch();
}

void queryEditor(int ix,int iy,int iw,int ih,int ox,int oy,int ow,int oh)
{
struct ffblk ffblk;
char sql[250],tableName[20];
int l;
while(strcpy(sql,getString(ix+3,iy+3,iw,ih,1)))
{
setcolor(BLUE);
bar(ix+3,iy+3,ix+iw,iy+ih);
if(strncmpi(sql,"QUIT",4)==0)
{
bar(ox+3,oy+3,ox+ow,oy+oh);
messageBox(220,100,190," Thanks for using, Database Query, Processor","Thanks");
outtextxy(ox+3,oy+3,"Thanks");
return;
}
else if(strncmpi(sql,"CREATE TABLE",12)==0)
{
createTableQuery(sql,ox,oy,ow,oh);
}
else if(strncmpi(sql,"SELECT",6)==0)
{
selectQuery(sql,ox,oy,ow,oh);
}
else if(strncmpi(sql,"INSERT INTO",11)==0)
{
insertQuery(sql,ox,oy,ow,oh);
}
else if(strncmpi(sql,"UPDATE",6)==0)
{
updateQuery(sql,ox,oy,ow,oh);
}

else if(strncmpi(sql,"DELETE FROM",11)==0)
{
deleteQuery(sql,ox,oy,ow,oh);
}
else if(strncmpi(sql,"HELP",4)==0)
{
help();
}
else if(strncmpi(sql,"TABLE INFO",10)==0)
{
tableInfo(sql,ox,oy,ow,oh);
}
else if(strncmpi(sql,"TABLE LIST",10)==0)
{
strcpy(sql,substr(sql,11,strlen(sql)));
if(locstrchar(sql,';')>0)
strcpy(sql,substr(sql,0,locstrchar(sql,';')-1));
if(strcmp(sql,"")==0)
strcpy(sql,"*.dbf");
tableList(sql,ox,oy,ow,oh);
}
else if(strncmpi(sql,"DROP TABLE",10)==0)
{
strcpy(tableName,substr(sql,11,strlen(sql)));
l=locstrchar(tableName,';');
if(l>0)
strcpy(tableName,substr(tableName,0,l-1));
else
{
error(ox,oy,ow,oh,"statement is not properly ended");
return;
}
strcpy(tableName,ltrim(tableName));
strcpy(tableName,rtrim(tableName));
strcat(tableName,".dbf");
if(findfirst(tableName,&ffblk,0)==0)
{
remove(tableName);
bar(ox+3,oy+3,ox+ow,oy+oh);
outtextxy(ox+3,oy+3,"table dropped successfully.");
}
else
{
bar(ox+3,oy+3,ox+ow,oy+oh);
outtextxy(ox+3,oy+3,"table does not exist.");
}
}

else if(strstr(strupr(sql),"CLEAR SCREEN")!=NULL)
{
bar(ox+3,oy+3,ox+ow,oy+oh);
}
else if(strcmpi(sql,"")==0)
{
}
else
{
setcolor(BLUE);
bar(ox+3,oy+3,ox+ow,oy+oh);
outtextxy(ox+3,oy+3,"Invalid DQP command.");
}
}
}

/* --------------------- function to create table ------------------ */

void createTableQuery(char sql[250],int ox,int oy,int ow,int oh)
{
FILE *fp;
char sql1[250],tableName[20],fields[10][32],datatypes[10][15];
int f,l1,l,i,size,recCount=0,j,fieldsCount,pos[20],pk;
strcpy(tableName,"");
for(i=0;i<10;i++)
{
strcpy(fields[i],"");
strcpy(datatypes[i],"");
}
strcpy(sql1,substr(sql,13,strlen(sql)));
strcpy(sql1,ltrim(sql1));
l=locstrchar(sql1,'(');
if(l>0)
strcpy(tableName,substr(sql1,0,l-1));
l=locstrchar(tableName,' ');
if(l>0)
strcpy(tableName,substr(tableName,0,l-1));
i=0;
l=locstrchar(sql,'(');
if(l>0)
strcpy(sql1,substr(sql,l,strlen(sql)));
else
{
error(ox,oy,ow,oh,"Syntax error");
return;
}
l=locstrchar(sql1,';');
if(l==0)
{
error(ox,oy,ow,oh,"DQP is not ended properly");
return;
}
strcpy(sql1,substr(sql1,locstrchar(sql1,'(')+1,locstrchar(sql1,';')-1));
strcpy(sql1,ltrim(sql1));
i=0;
j=0;
l=0;
f=0;
while(sql1[l]!=';')
{
if(f==0)
{
fields[i][j++]=sql1[l];
if(sql1[l]==' ')
{
fields[i][j-1]='\0';
//strcpy(fields[i],trim(fields[i]));
while(sql1[l++]==' ');
l--;
l--;
j=0;
f=1;
}
}
else
{
datatypes[i][j++]=sql1[l];
if(sql1[l]==' ' || sql1[l]==')')
{
datatypes[i][j]='\0';
if(datatypes[i][j-2]==',')
datatypes[i][j-2]='\0';
if(datatypes[i][j-2]=='y' && datatypes[i][j-1]==')')
datatypes[i][j-1]='\0';
//strcpy(datatypes[i],trim(datatypes[i]));
while(sql1[l]==' ' || sql1[l]==')' || sql1[l]==',')
l++;
l--;
i++;
j=0;
f=0;
}
}
l++;
}
fields[i][j]='\0';
datatypes[i][j]='\0';
l1=strlen(datatypes[i]);
if(strcmp(datatypes[i],")")==0)
{
strcpy(datatypes[i],"");
i--;
}
size=0;
pk=0;
fieldsCount=i;
if(fieldsCount==0)
{
error(ox,oy,ow,oh,"no column.");
return;
}

for(l=0;l<fieldscount;l++)>
{
if(strncmpi(datatypes[l],"NUMBER",6)==0)
{
strcpy(sql1,substr(datatypes[l],7,strlen(datatypes[l])-2));
size=size+atoi(sql1);
}
else if(strncmpi(datatypes[l],"STRING",6)==0)
{
strcpy(sql1,substr(datatypes[l],7,strlen(datatypes[l])-2));
size=size+atoi(sql1);
}
else if(strcmpi(datatypes[l],"KEY")==0)
{
if(pk>0)
{
error(ox,oy,ow,oh,"More than one primary keys");
return;
}
pk=l;
for(l1=l;l1<i;l1++)>
{
strcpy(fields[l1],fields[l1+1]);
strcpy(datatypes[l1],datatypes[l1+1]);
}
strcpy(fields[l1],"");
strcpy(datatypes[l1],"");
l--;
i--;
fieldsCount--;
}
else
{
bar(ox+3,oy+3,ox+ow,oy+oh);
outtextxy(ox+3,oy+3,"unknown column datatype");
return;
}
}
strcat(tableName,".dbf");
fp = fopen(tableName,"r");
if(fp!=NULL)
{
bar(ox+3,oy+3,ox+ow,oy+oh);
outtextxy(ox+3,oy+3,tableName);
outtextxy(ox+100,oy+3,"already exists.");
}
else
{
fp = fopen(tableName,"w");
fprintf(fp,"%d\t%d\t%d\t%d\t",fieldsCount,size,recCount,pk);
for(l=0;l<fieldscount;l++)>
{
fprintf(fp,"%s\t%s\t",fields[l],datatypes[l]);
}
fprintf(fp,"\n");
fclose(fp);
bar(ox+3,oy+3,ox+ow,oy+oh);
outtextxy(ox+3,oy+3,"table created successfully.");
/* input(tableName);
for(i=0;tableName[i]!='.';i++);
tableName[i+1]='d';
tableName[i+2]='b';
tableName[i+3]='f';
remove(tableName);*/

}
}

/* ------------ function to insert values into table --------------- */

void insertQuery(char sql[250],int ox,int oy,int ow,int oh)
{
FILE *fp;
struct ffblk ffblk;
char sql1[250],tableName[20],fields[10][32],datatypes[10][15];
int l,i,size,recCount,j,fieldsCount,pos[20],l1,pk;
char charData[10][50],data[10][50],buff[10][10];
strcpy(tableName,"");
for(i=0;i<10;i++)
{
strcpy(fields[i],"");
strcpy(datatypes[i],"");
strcpy(charData[i],"");
strcpy(data[i],"");
strcpy(buff[i],"");
}

l=12;
strcpy(sql1, substr(sql,12,strlen(sql) ));
strcpy(sql1,ltrim(sql1));
l1=locstrchar(sql1,' ');
strcpy(tableName,substr(sql1,0,l1-1));
strcpy(sql1,substr(sql1,l1+1,strlen(sql1)));
strcpy(sql1,ltrim(sql1));
l1=locstrchar(sql1,'(');
if(strncmpi(sql1,substr(sql1,0,l1),6)!=0)
{
error(ox,oy,ow,oh,"incorrect DQP syntax");
return;
}
/* strcat(tableName,".kmk");
decode(tableName);
for(i=0;tableName[i]!='.';i++);

tableName[i+1]='k';
tableName[i+2]='m';
tableName[i+3]='k';

remove(tableName);
tableName[strlen(tableName)-4]='\0';*/
strcat(tableName,".dbf");
if(locstrchar(sql1,')')==0 ||locstrchar(sql1,';')==0)
{
error(ox,oy,ow,oh,"DQP syntax is not properly ended");
return;
}
strcpy(sql1,substr(sql1,l1,strlen(sql1)-2));
if((fp = fopen(tableName,"r"))==NULL)
{
bar(ox+3,oy+3,ox+ow,oy+oh);
outtextxy(ox+3,oy+3,"Invalid table name.");
return;
}
else
{
fscanf(fp,"%d%d%d%d",&fieldsCount,&size,&recCount,&pk);
for(l=0;l<fieldscount;l++)>
{
fscanf(fp,"%s %s",fields[l],datatypes[l]);
}
l=1;
i=0;
j=0;
strcpy(sql1,substr(sql1,1,strlen(sql1)));
while(sql1[0]!=')')
{
if(locstrchar(sql1,',')>0)
strcpy(charData[i],substr(sql1,0,locstrchar(sql1,',')-1));
else
strcpy(charData[i],substr(sql1,0,locstrchar(sql1,')')-1));
strcpy(sql1,substr(sql1,strlen(charData[i]),strlen(sql1)));
strcpy(charData[i],ltrim(charData[i]));
strcpy(charData[i],rtrim(charData[i]));
strcpy(sql1,ltrim(sql1));
i++;
}

if(fieldsCount!=i)
{
bar(ox+3,oy+3,ox+ow,oy+oh);
outtextxy(ox+3,oy+3,"no. of values supplied mismatch.");
return;
}
for(j=0;j<fieldscount;j++)>
{
strcpy(buff[j],"%");
if(strncmpi(datatypes[j],"NUMBER",6)==0)
{
if(charData[j][0]=='\'')
{
error(ox,oy,ow,oh,"numeric data type mismatch or too long value");
return;
}
l=locstrchar(datatypes[j],')');
strcat(buff[j],substr(datatypes[j],7,l-1));
strcat(buff[j],"s\t");
}
else
{
if(charData[j][0]!='\'' || charData[j][strlen(charData[j])-1]!='\'')
{
error(ox,oy,ow,oh,"Invalid Character Data");
return;
}
l=locstrchar(datatypes[j],')');
strcat(buff[j],substr(datatypes[j],7,l-1));
strcat(buff[j],"s\t");
}
}
for(j=0;j<fieldscount;j++)>
{
strcpy(charData[j],ltrim(charData[j]));
if(charData[j][0]=='\'')
strcpy(charData[j],removeQuote(charData[j]));
}
if(pk)
for(i=0;i<reccount;i++)>
{
fgetc(fp);
for(j=0;j<fieldscount;j++)>
{
fgetc(fp);
fscanf(fp,"%[^\t]",data[j]);
if(j==pk-1)
{
if(strncmpi(datatypes[j],"NUMBER",6)==0)
if(atol(charData[pk-1])==atol(data[pk-1]))
{
bar(ox+3,oy+3,ox+ow,oy+oh);
outtextxy(ox+3,oy+3,"Duplicate value in primary ley");
fclose(fp);
return;
}
else
if(strcmpi(charData[pk-1],data[pk-1])==0)
{
bar(ox+3,oy+3,ox+ow,oy+oh);
outtextxy(ox+3,oy+3,"Duplicate value in primary key");
fclose(fp);
return;
}
}
}
}
fclose(fp);
fp=fopen(tableName,"a");
for(j=0;j<fieldscount;j++)>
{
fprintf(fp,buff[j],charData[j]);
}
recCount++;
fprintf(fp,"\n");
fclose(fp);
fp = fopen(tableName,"r+");
fseek(fp,0L,SEEK_SET);
fprintf(fp,"%d\t%d\t%d\t%d\t",fieldsCount,size,recCount,pk);
fclose(fp);
if(recCount!=1)
primaryKey(tableName);
bar(ox+3,oy+3,ox+ow,oy+oh);
outtextxy(ox+3,oy+3,"1 row inserted successfully.");
/* input(tableName);
for(i=0;tableName[i]!='.';i++);
tableName[i+1]='d';
tableName[i+2]='b';
tableName[i+3]='f';
remove(tableName);*/
}
}

void deleteQuery(char sql[250],int ox,int oy,int ow,int oh)
{
FILE *fp,*ftemp;
struct ffblk ffblk;
char sql1[250],tableName[20],fields[10][32],datatypes[10][15];
char cfld[10][32],cval[10][32],opr[10][2],buff[10][10];
int l,recCount,size,recSize,j,fieldsCount,charCount,pk;
int pos[20],row,k,m,l1,c=0,show=0,i;
char charData[10][50],columns[10][32],str[20];
strcpy(tableName,"");
strcpy(str,"");
for(i=0;i<10;i++)
{
strcpy(fields[i],"");
strcpy(datatypes[i],"");
strcpy(cfld[i],"");
strcpy(cval[i],"");
strcpy(opr[i],"");
strcpy(buff[i],"");
strcpy(charData[i],"");
strcpy(columns[i],"");
}

l=7;
strcpy(sql1, substr(sql,7,strlen(sql) ));
if(strncmpi(sql1,"FROM",4)!=0)
{
error(ox,oy,ow,oh,"From clause is missing");
return;
}
strcpy(sql1,substr(sql1,5,strlen(sql1)));
l1=locstrchar(sql1,' ');
strcpy(tableName,substr(sql1,0,l1-1));
l=l+strlen(tableName)+5;
strcpy(sql1,substr(sql,l+1,strlen(sql)));
strcpy(sql1,ltrim(sql1));
l1=locstrchar(sql1,';');
if(l1==0)
{
error(ox,oy,ow,oh,"Statement is properly ended");;
return;
}
if(strlen(sql1)!=1)
if(strncmpi(sql1,"WHERE",5)!=0)
{
error(ox,oy,ow,oh,"WHERE clause is missing");
return;
}
l1=locstrchar(sql1,' ');
if(l1>0)
{
strcpy(sql1,substr(sql1,6,strlen(sql1)));
c=1;
}
else
{
c=0;
}
/* strcat(tableName,".kmk");
decode(tableName);
for(i=0;tableName[i]!='.';i++);
tableName[i+1]='k';
tableName[i+2]='m';
tableName[i+3]='k';

remove(tableName);
tableName[strlen(tableName)-4]='\0';*/
strcat(tableName,".dbf");
ftemp=fopen("temp.$$$","w+");
if((fp = fopen(tableName,"r"))==NULL)
{
bar(ox+3,oy+3,ox+ow,oy+oh);
outtextxy(ox+3,oy+3,"Invalid table name.");
return;
}
else
{
l1=locstrchar(sql1,'<');
if(l1==0)
l1=locstrchar(sql1,'>');
if(l1==0)
l1=locstrchar(sql1,'!');
if(l1>0)
{
strcpy(cfld[0],substr(sql1,0,l1-1));
strcpy(opr[0],substr(sql1,l1,l1));
if(strcmp(substr(sql1,l1+1,l1+1),"=")==0)
{
opr[0][1]='=';
opr[0][2]='\0';
strcpy(sql1,substr(sql1,l1+2,strlen(sql1)));
l1=locstrchar(sql1,';');
if(l1>0)
strcpy(cval[0],substr(sql1,0,l1-1));
}
else
{
opr[0][1]='\0';
strcpy(sql1,substr(sql1,l1+1,strlen(sql1)));
l1=locstrchar(sql1,';');
if(l1>0)
strcpy(cval[0],substr(sql1,0,l1-1));
}
}
else
{
l1=locstrchar(sql1,'=');
if(l1>0)
{
strcpy(cfld[0],substr(sql1,0,l1-1));
strcpy(opr[0],substr(sql1,l1,l1));
strcpy(sql1,substr(sql1,l1+1,strlen(sql1)));
l1=locstrchar(sql1,';');
if(l1>0)
strcpy(cval[0],substr(sql1,0,l1-1));
}
}
fscanf(fp,"%d%d%d%d",&fieldsCount,&size,&recCount,&pk);
fprintf(ftemp,"%d\t%d\t%d\t%d\t",fieldsCount,size,recCount,pk);
for(l=0;l<fieldscount;l++)>
{
fscanf(fp,"%s %s",fields[l],datatypes[l]);
fprintf(ftemp,"%s\t%s\t",fields[l],datatypes[l]);
}
fprintf(ftemp,"\n");
m=0;
for(k=0;k<reccount;k++)>
{
fgetc(fp);
for(j=0;j<fieldscount;j++)>
{ fgetc(fp);
fscanf(fp,"%[^\t]",charData[j]);
}
for(j=0;j<fieldscount;j++)>
{
strcpy(buff[j],"%");
l=locstrchar(datatypes[j],')');
strcat(buff[j],substr(datatypes[j],7,l-1));
strcat(buff[j],"s\t");

if(c==1 && strcmpi(cfld[0],fields[j])==0)
if(strncmpi(datatypes[j],"NUMBER",6)==0 )
switch(opr[0][0])
{
case '=':
show=(atoi(cval[0]) == atoi(charData[j]))?1:0;
break;
case '<':
if(opr[0][1]=='=')
show=(atoi(charData[j]) <= atoi(cval[0]))?1:0;
else
show=(atoi(charData[j]) < atoi(cval[0]))?1:0;
break;
case '>':
if(opr[0][1]=='=')
show=(atoi(charData[j]) >= atoi(cval[0]))?1:0;
else
show=(atoi(charData[j]) > atoi(cval[0]))?1:0;
break;
case '!':
if(opr[0][1]=='=')
show=(atoi(cval[0]) != atoi(charData[j]))?1:0;
break;
}
else
switch(opr[0][0])
{
case '=':
show=(strcmp(substr(cval[0],1,strlen(cval[0])-2),charData[j])==0 )?1:0;
break;
case '<':
if(opr[0][1]=='=')
show=(strcmp(charData[j],substr(cval[0],1,strlen(cval[0])-2))<=0)?1:0;
else
show=(strcmp(charData[j],substr(cval[0],1,strlen(cval[0])-2))<0)?1:0;
break;
case '>':
if(opr[0][1]=='=')
show=(strcmp(charData[j],substr(cval[0],1,strlen(cval[0])-2))>=0)?1:0;
else
show=(strcmp(charData[j],substr(cval[0],1,strlen(cval[0])-2))>0)?1:0;
break;
case '!':
if(opr[0][1]=='=')
show=(strcmp(cval[0],substr(charData[j],1,strlen(cval[0])-2))!=0)?1:0;
break;
}
}
if(show!=1 && c==1)
{
for(j=0;j<fieldscount;j++)>
fprintf(ftemp,buff[j],charData[j]);
fprintf(ftemp,"\n");
}
else
{
m++;
}
}
recCount-=m;
bar(ox+3,oy+3,ox+ow,oy+oh);
itoa(m,sql1,10);
strcat(sql1," row(s) deleted.");
outtextxy(ox+3,oy+3,sql1);
fclose(fp);
// fclose(ftemp);
fseek(ftemp,0L,SEEK_SET);
fprintf(ftemp,"%d\t%d\t%d\t%d\t",fieldsCount,size,recCount,pk);
fclose(ftemp);
remove(tableName);
rename("temp.$$$",tableName);
primaryKey(tableName);
}
}

void selectQuery(char sql[250],int ox,int oy,int ow,int oh)
{
FILE *fp;
struct ffblk ffblk;
char sql1[250],tableName[20],fields[10][32],datatypes[10][15],temp[25];
char cfld[10][32],cval[10][32],opr[10][2],buff[10][10];
int l,i,size,recCount,j,fieldsCount,charCount,pk;
int pos[20],row,k,m,l1,c=0,show=0,cc=0,fl[10];
char charData[10][50],columns[10][32];
strcpy(tableName,"");
strcpy(temp,"");
for(i=0;i<10;i++)
{
strcpy(fields[i],"");
strcpy(datatypes[i],"");
strcpy(cfld[i],"");
strcpy(cval[i],"");
strcpy(opr[i],"");
strcpy(charData[i],"");
strcpy(columns[i],"");
strcpy(buff[i],"");
fl[i]=0;
}
l=7;
strcpy(sql1, substr(sql,7,strlen(sql) ));
strcpy(sql1,ltrim(sql1));
l1=locstrchar(sql1,' ');
k=0;
if(l1>0)
{
while(1)
{
if(strlen(sql1)<=0)
break;
strcpy(sql1,substr(sql1,strlen(columns[k]),strlen(sql1)));
strcpy(sql1,ltrim(sql1));
l1=locstrchar(sql1,',');
if(l1>0)
{
strcpy(columns[k++],substr(sql1,0,l1-1));
strcpy(columns[k-1],rtrim(columns[k-1]));
}
if(l1==0)
{
l1=locstrchar(sql1,' ');
if(l1>0)
strcpy(columns[k++],substr(sql1,0,l1-1));
strcpy(sql1,substr(sql1,strlen(columns[k-1]),strlen(sql1)));
strcpy(sql1,ltrim(sql1));
break;
}
strcpy(sql1,substr(sql1,strlen(columns[k-1]),strlen(sql1)));
strcpy(sql1,ltrim(sql1));
}
}
cc=k;
if(strncmpi(sql1,"FROM",4)!=0)
{
error(ox,oy,ow,oh,"FROM clause is missing");
return;
}
strcpy(sql1,substr(sql1,4,strlen(sql1)));
strcpy(sql1,ltrim(sql1));
l1=locstrchar(sql1,' ');
if(l1>0)
{
strcpy(tableName,substr(sql1,0,l1-1));
strcpy(sql1,substr(sql1,strlen(tableName),strlen(sql1)));
strcpy(sql1,ltrim(sql1));
if(sql1[0]==';')
goto out;
if(strncmpi(sql1,"WHERE",5)!=0)
{
error(ox,oy,ow,oh,"WHERE is missing");
return;
}
strcpy(sql1,substr(sql1,5,strlen(sql1)));
strcpy(sql1,ltrim(sql1));
c=1;
}
else
{
strtok(sql1,";");
strcpy(tableName,sql1);
}
out:
/* strcat(tableName,".kmk");
decode(tableName);
for(i=0;tableName[i]!='.';i++);
tableName[i+1]='k';
tableName[i+2]='m';
tableName[i+3]='k';

remove(tableName);
tableName[strlen(tableName)-4]='\0';*/
strcat(tableName,".dbf");
if((fp = fopen(tableName,"r"))==NULL)
{
bar(ox+3,oy+3,ox+ow,oy+oh);
outtextxy(ox+3,oy+3,"Invalid table name.");
return;
}
else
{
if(c==1)
{
l1=locstrchar(sql1,' ');
if(l1>0)
{
strcpy(cfld[0],substr(sql1,0,l1-1));
strcpy(sql1,substr(sql1,l1,strlen(sql1)));
strcpy(sql1,ltrim(sql1));
if(strncmpi(sql1,"LIKE",4)==0)
strcpy(opr[0],"L");
}
l1=locstrchar(sql1,'<');
if(l1==0)
l1=locstrchar(sql1,'>');
if(l1==0)
l1=locstrchar(sql1,'!');
if(l1>0)
{
strcpy(opr[0],substr(sql1,l1,l1));
if(strcmp(substr(sql1,l1+1,l1+1),"=")==0)
{
opr[0][1]='=';
opr[0][2]='\0';
strcpy(sql1,substr(sql1,l1+2,strlen(sql1)));
l1=locstrchar(sql1,';');
if(l1>0)
strcpy(cval[0],substr(sql1,0,l1-1));
else
{
error(ox,oy,ow,oh,"SQP Statement is properly ended");
return;
}
}
else
{
opr[0][1]='\0';
strcpy(sql1,substr(sql1,l1+1,strlen(sql1)));
l1=locstrchar(sql1,';');
if(l1>0)
strcpy(cval[0],substr(sql1,0,l1-1));
else
{
error(ox,oy,ow,oh,"Statment is not properly ended");
return;
}
}
}
else
{
l1=locstrchar(sql1,'=');
if(l1>0)
{
strcpy(cfld[0],substr(sql1,0,l1-1));
strcpy(opr[0],substr(sql1,l1,l1));
strcpy(sql1,substr(sql1,l1+1,strlen(sql1)));
l1=locstrchar(sql1,';');
if(l1>0)
strcpy(cval[0],substr(sql1,0,l1-1));
}
else
{
strcpy(cval[0],substr(sql1,5,strlen(sql1)-1));
if(cval[0][0]!='\'' || cval[0][strlen(cval[0])-1]=='\'')
{
error(ox,oy,ow,oh,"Error in character expression");
return;
}
strcpy(cval[0],removeQuote(cval[0]));
}
}
}
fscanf(fp,"%d%d%d%d",&fieldsCount,&size,&recCount,&pk);
for(l=0;l<fieldscount;l++)>
{
fscanf(fp,"%s %s",fields[l],datatypes[l]);
}
for(l=0;l<fieldscount;l++)>
{
l1=locstrchar(datatypes[l],'(');
fl[l]=atoi(substr(datatypes[l],l1+1,locstrchar(datatypes[l],')')-1));
}
if(strcmpi(columns[0],"*")==0)
{
row=oy+3;
bar(ox+3,oy+3,ox+ow,oy+oh);
i=0;
for(j=0;j<fieldscount;j++)>
{
if(strncmpi(datatypes[j],"NUMBER",6)==0)
sprintf(buff[j],"%c%ds",'%',fl[j]);
else
sprintf(buff[j],"%c-%ds",'%',fl[j]);
sprintf(temp,buff[j],fields[j]);
outtextxy(ox+3+i,row,temp);
for(k=0;k<fl[j]*8;k+> outtextxy(ox+3+k+i,row+10,"- ");
i+=textwidth(temp)+10;
}
row+=20;
for(k=0;k<reccount;k++)>
{
fgetc(fp);
for(j=0;j<fieldscount;j++)>
{
fgetc(fp);
fscanf(fp,"%[^\t]",charData[j]);
strcpy(charData[j],ltrim(charData[j]));
if(c==1 && strcmpi(cfld[0],fields[j])==0)
if(strncmpi(datatypes[j],"NUMBER",6)==0 )
switch(opr[0][0])
{
case '=':
show=(atoi(cval[0]) == atoi(charData[j]))?1:0;
break;
case '<':
if(opr[0][1]=='=')
show=(atoi(charData[j]) <= atoi(cval[0]))?1:0;
else
show=(atoi(charData[j]) < atoi(cval[0]))?1:0;
break;
case '>':
if(opr[0][1]=='=')
show=(atoi(charData[j]) >= atoi(cval[0]))?1:0;
else
show=(atoi(charData[j]) > atoi(cval[0]))?1:0;
break;
case '!':
if(opr[0][1]=='=')
show=(atoi(cval[0]) != atoi(charData[j]))?1:0;
break;
}
else
switch(opr[0][0])
{
case '=':
show=(strcmp(substr(cval[0],1,strlen(cval[0])-2),charData[j])==0 )?1:0;
break;
case '<':
if(opr[0][1]=='=')
show=(strcmp(charData[j],substr(cval[0],1,strlen(cval[0])-2))<=0)?1:0;
else
show=(strcmp(charData[j],substr(cval[0],1,strlen(cval[0])-2))<0)?1:0;
break;
case '>':
if(opr[0][1]=='=')
show=(strcmp(charData[j],substr(cval[0],1,strlen(cval[0])-2))>=0)?1:0;
else
show=(strcmp(charData[j],substr(cval[0],1,strlen(cval[0])-2))>0)?1:0;
break;
case '!':
if(opr[0][1]=='=')
show=(strcmp(cval[0],substr(charData[j],1,strlen(cval[0])-2))!=0)?1:0;
break;
case 'L':
show=(strncmpi(cval[0],charData[j],strlen(cval[0])-1)==0)?1:0;
break;
}
}
if(show==1 && c==1)
{
i=0;
for(j=0;j<fieldscount;j++)>
{
sprintf(temp,buff[j],charData[j]);
outtextxy(ox+3+i,row,temp);
i+=textwidth(temp)+10;
}
row+=10;
}
else if(c==0)
{
i=0;
for(j=0;j<fieldscount;j++)>
{
sprintf(temp,buff[j],charData[j]);
outtextxy(ox+3+i,row,temp);
i+=textwidth(temp)+10;
}
row+=10;
}
}
}
else
{
row=oy+3;
bar(ox+3,oy+3,ox+ow,oy+oh);
for(j=0;j<20;j++)
pos[j]=20;
m=0;
for(l1=0;l1<=cc;l1++)
{
for(j=0;j<fieldscount;j++)>
{
if(strcmpi(columns[l1],fields[j])==0)
pos[m++]=j;
}
}
if(pos[0]==20)
{
bar(ox+3,oy+3,ox+ow,oy+oh);
outtextxy(ox+3,oy+3,"Invalid column name.");
return;
}
i=0;
for(l1=0;l1<=cc;l1++)
{
for(j=0;j<fieldscount;j++)>
{
if(j==pos[l1])
{
sprintf(buff[j],"%c%ds",'%',fl[j]);
sprintf(temp,buff[j],fields[j]);
outtextxy(ox+3+i,row,temp);
for(k=0;k<fl[j]*8;k+> outtextxy(ox+3+k+i,row+10,"- ");
i+=textwidth(temp)+10;
}
}
}
row+=20;
for(k=0;k<reccount;k++)>
{
l1=0;
fgetc(fp);
for(j=0;j<fieldscount;j++)>
{
fgetc(fp);
fscanf(fp,"%[^\t]",charData[j]);
if(c==1 && strcmpi(cfld[0],fields[j])==0)
if(strncmpi(datatypes[j],"NUMBER",6)==0 )
switch(opr[0][0])
{
case '=':
show=(atoi(cval[0]) == atoi(charData[j]))?1:0;
break;
case '<':
if(opr[0][1]=='=')
show=(atoi(charData[j]) <= atoi(cval[0]))?1:0;
else
show=(atoi(charData[j]) < atoi(cval[0]))?1:0;
break;
case '>':
if(opr[0][1]=='=')
show=(atoi(charData[j]) >= atoi(cval[0]))?1:0;
else
show=(atoi(charData[j]) > atoi(cval[0]))?1:0;
break;
case '!':
if(opr[0][1]=='=')
show=(atoi(cval[0]) != atoi(charData[j]))?1:0;
break;
}
else
switch(opr[0][0])
{
case '=':
show=(strcmp(substr(cval[0],1,strlen(cval[0])-2),charData[j])==0 )?1:0;
break;
case '<':
if(opr[0][1]=='=')
show=(strcmp(charData[j],substr(cval[0],1,strlen(cval[0])-2))<=0)?1:0;
else
show=(strcmp(charData[j],substr(cval[0],1,strlen(cval[0])-2))<0)?1:0;
break;
case '>':
if(opr[0][1]=='=')
show=(strcmp(charData[j],substr(cval[0],1,strlen(cval[0])-2))>=0)?1:0;
else
show=(strcmp(charData[j],substr(cval[0],1,strlen(cval[0])-2))>0)?1:0;
break;
case '!':
if(opr[0][1]=='=')
show=(strcmp(cval[0],substr(charData[j],1,strlen(cval[0])-2))!=0)?1:0;
break;
}
}
i=0;
for(l1=0;l1<=cc;l1++)
{
for(j=0;j<fieldscount;j++)>
if(c==1 && show==1 && j==pos[l1])
{
sprintf(temp,buff[j],charData[j]);
outtextxy(ox+3+i,row,temp);
i+=textwidth(temp)+10;
}
else if(c==0 && j==pos[l1])
{
sprintf(temp,buff[j],charData[j]);
outtextxy(ox+3+i,row,temp);
i+=textwidth(temp)+10;
}
}
if(c==1 && show==1)
row+=10;
else if(c==0)
row+=10;
}
}
fclose(fp);
free(sql1);
free(datatypes);
free(fields);
free(cfld);
free(opr);
free(cval);
/* input(tableName);
for(i=0;tableName[i]!='.';i++);
tableName[i+1]='d';
tableName[i+2]='b';
tableName[i+3]='f';
remove(tableName);*/
}
}

void updateQuery(char sql[250],int ox,int oy,int ow,int oh)
{
FILE *fp,*ftemp;
struct ffblk ffblk;
char sql1[250],tableName[20],fields[10][32],datatypes[10][15];
char cfld[10][32],cval[10][32],opr[10][2];
int l,recCount,size,j,fieldsCount,charCount,pk;
int pos[20],row,k,m,l1,c=0,show=0,cc,i,uc;
char charData[10][50],columns[10][32],str[20];
strcpy(tableName,"");
strcpy(str,"");
for(i=0;i<10;i++)
{
strcpy(fields[i],"");
strcpy(datatypes[i],"");
strcpy(cfld[i],"");
strcpy(cval[i],"");
strcpy(opr[i],"");
strcpy(charData[i],"");
strcpy(columns[i],"");
}

l=7;
strcpy(sql1, substr(sql,7,strlen(sql) ));
l1=locstrchar(sql1,' ');
strcpy(tableName,substr(sql1,0,l1-1));
l=l+strlen(tableName);
strcpy(sql1,substr(sql,l,strlen(sql)));
strcpy(sql1,ltrim(sql1));
if(strncmpi(sql1,"SET",3)!=0)
{
error(ox,oy,ow,oh,"SET is missing");
return;
}
strcpy(sql1,substr(sql1,3,strlen(sql1)));
strcpy(sql1,ltrim(sql1));
k=0;
cc=0;
while((l1=locstrchar(sql1,','))>0)
{
strcpy(columns[k++],substr(sql1,0,l1-1));
strcpy(sql1,substr(sql1,l1+1,strlen(sql1)));
cc++;
}
cc++;
l1=locstrchar(sql1,'\'');
if(l1>0)
{
strcpy(columns[k],substr(sql1,0,l1));
strcpy(sql1,substr(sql1,l1+1,strlen(sql1)));
l1=locstrchar(sql1,'\'');
if(l1==0)
{
error(ox,oy,ow,oh,"open quote in set clause");
return;
}
strcat(columns[k],substr(sql1,0,l1));
strcpy(sql1,substr(sql1,l1+1,strlen(sql1)));
strcpy(sql1,ltrim(sql1));
}
else
{
strcpy(columns[k++],substr(sql1,0,l1-1));
strcpy(sql1,substr(sql1,l1+1,strlen(sql1)));
strcpy(sql1,ltrim(sql1));
}
l1=locstrchar(sql1,';');
if(l1==0)
{
error(ox,oy,ow,oh,"Statement is not properly ended");
return;
}
if(strlen(sql1)!=1)
if(strncmpi(sql1,"WHERE",5)!=0)
{
error(ox,oy,ow,oh,"WHERE clause is missing");
return;
}
l1=locstrchar(sql1,' ');
if(l1>0)
{
strcpy(sql1,substr(sql1,6,strlen(sql1)));
c=1;
}
else
{
c=0;
}
/* strcat(tableName,".kmk");
decode(tableName);
for(i=0;tableName[i]!='.';i++);
tableName[i+1]='k';
tableName[i+2]='m';
tableName[i+3]='k';

remove(tableName);
tableName[strlen(tableName)-4]='\0';*/
strcat(tableName,".dbf");
ftemp=fopen("temp.$$$","w");
if((fp = fopen(tableName,"r"))==NULL)
{
bar(ox+3,oy+3,ox+ow,oy+oh);
outtextxy(ox+3,oy+3,"Invalid table name.");
return;
}
else
{
l1=locstrchar(sql1,'<');
if(l1==0)
l1=locstrchar(sql1,'>');
if(l1==0)
l1=locstrchar(sql1,'!');
if(l1>0)
{
strcpy(cfld[0],substr(sql1,0,l1-1));
strcpy(opr[0],substr(sql1,l1,l1));
if(strcmp(substr(sql1,l1+1,l1+1),"=")==0)
{
opr[0][1]='=';
opr[0][2]='\0';
strcpy(sql1,substr(sql1,l1+2,strlen(sql1)));
l1=locstrchar(sql1,';');
if(l1>0)
strcpy(cval[0],substr(sql1,0,l1-1));
}
else
{
opr[0][1]='\0';
strcpy(sql1,substr(sql1,l1+1,strlen(sql1)));
l1=locstrchar(sql1,';');
if(l1>0)
strcpy(cval[0],substr(sql1,0,l1-1));
}
}
else
{
l1=locstrchar(sql1,'=');
if(l1>0)
{
strcpy(cfld[0],substr(sql1,0,l1-1));
strcpy(opr[0],substr(sql1,l1,l1));
strcpy(sql1,substr(sql1,l1+1,strlen(sql1)));
l1=locstrchar(sql1,';');
if(l1>0)
strcpy(cval[0],substr(sql1,0,l1-1));
}
}
fscanf(fp,"%d%d%d%d",&fieldsCount,&size,&recCount,&pk);
fprintf(ftemp,"%d\t%d\t%d\t%d\t",fieldsCount,size,recCount,pk);
for(l=0;l<fieldscount;l++)>
{
fscanf(fp,"%s %s",fields[l],datatypes[l]);
fprintf(ftemp,"%s\t%s\t",fields[l],datatypes[l]);
}
fprintf(ftemp,"\n");
uc=0;
for(k=0;k<reccount;k++)>
{
fgetc(fp);
for(j=0;j<fieldscount;j++)>
{ fgetc(fp);
fscanf(fp,"%[^\t]",charData[j]);
strcpy(charData[j],ltrim(charData[j]));
}
for(j=0;j<fieldscount;j++)>
{
if(c==1 && strcmpi(cfld[0],fields[j])==0)
if(strncmpi(datatypes[j],"NUMBER",6)==0 )
switch(opr[0][0])
{
case '=':
show=(atoi(cval[0]) == atoi(charData[j]))?1:0;
break;
case '<':
if(opr[0][1]=='=')
show=(atoi(charData[j]) <= atoi(cval[0]))?1:0;
else
show=(atoi(charData[j]) < atoi(cval[0]))?1:0;
break;
case '>':
if(opr[0][1]=='=')
show=(atoi(charData[j]) >= atoi(cval[0]))?1:0;
else
show=(atoi(charData[j]) > atoi(cval[0]))?1:0;
break;
case '!':
if(opr[0][1]=='=')
show=(atoi(cval[0]) != atoi(charData[j]))?1:0;
break;
}
else
switch(opr[0][0])
{
case '=':
show=(strcmp(substr(cval[0],1,strlen(cval[0])-2),charData[j])==0 )?1:0;
break;
case '<':
if(opr[0][1]=='=')
show=(strcmp(charData[j],substr(cval[0],1,strlen(cval[0])-2))<=0)?1:0;
else
show=(strcmp(charData[j],substr(cval[0],1,strlen(cval[0])-2))<0)?1:0;
break;
case '>':
if(opr[0][1]=='=')
show=(strcmp(charData[j],substr(cval[0],1,strlen(cval[0])-2))>=0)?1:0;
else
show=(strcmp(charData[j],substr(cval[0],1,strlen(cval[0])-2))>0)?1:0;
break;
case '!':
if(opr[0][1]=='=')
show=(strcmp(cval[0],substr(charData[j],1,strlen(cval[0])-2))!=0)?1:0;
break;
}
}
for(j=0;j<cc;j++)>
{
if(show==1 && c==1)
{
uc++;
l1=locstrchar(columns[j],'=');
if(l1>0)
for(l=0;l<fieldscount;l++)>
{
if(c==1 && strncmpi(columns[j],fields[l],strlen(fields[l]))==0)
if(strncmpi(datatypes[l],"NUMBER",6)==0 )
{
strcpy(str,substr(columns[j],l1+1,strlen(columns[j])));
if(atol(charData[l])==atol(str) && l==pk-1)
{
error(ox,oy,ow,oh,"Duplicate value in primary key");
}
else
strcpy(charData[l],str);
}
else
{
strcpy(str,substr(columns[j],l1+1,strlen(columns[j])));
strcpy(str,removeQuote(str));
if(strcmpi(charData[l],str)==0 && l==pk-1)
{
error(ox,oy,ow,oh,"Duplicate value in primary key");
return;
}
else
strcpy(charData[l],ltrim(str));
}
}
else
{
error(ox,oy,ow,oh,"Error in criteria");
return;
}

}
}
for(j=0;j<fieldscount;j++)>
fprintf(ftemp,"%s\t",charData[j]);
fprintf(ftemp,"\n");
}

bar(ox+3,oy+3,ox+ow,oy+oh);
sprintf(sql1,"(%d) row(s) updated successfully.",uc);
error(ox,oy,ow,oh,sql1);

fclose(fp);
fclose(ftemp);
remove(tableName);
rename("temp.$$$",tableName);
primaryKey(tableName);
}
}

void tableInfo(char sql[250],int ox,int oy,int ow,int oh)
{
FILE *fp;
char sql1[250],tableName[20],fields[10][32],datatypes[10][15];
int l,j,fieldsCount,recSize,recCount,l1,pk,i;
strcpy(tableName,"");
for(i=0;i<10;i++)
{
strcpy(fields[i],"");
strcpy(datatypes[i],"");
}

l=11;
strcpy(sql1, substr(sql,11,strlen(sql) ));
l1 = locstrchar(sql1,';');
if(l1>0)
strcpy(tableName,substr(sql1,0,l1-1));
else
strcpy(tableName,sql1);
/* strcat(tableName,".kmk");
decode(tableName);
for(i=0;tableName[i]!='.';i++);
tableName[i+1]='k';
tableName[i+2]='m';
tableName[i+3]='k';
remove(tableName);
tableName[strlen(tableName)-4]='\0';*/
strcat(tableName,".dbf");
if((fp = fopen(tableName,"r"))==NULL)
{
bar(ox+3,oy+3,ox+ow,oy+oh);
outtextxy(ox+3,oy+3,"Invalid table name.");
return;
}
else
{
fscanf(fp,"%d%d%d%d",&fieldsCount,&recSize,&recCount,&pk);
bar(ox+3,oy+3,ox+ow,oy+oh);
sprintf(sql1,"No. of Fields: %d",fieldsCount);
outtextxy(ox+3,oy+3,sql1);
sprintf(sql1,"Fields Size: %d",recSize);
outtextxy(ox+3,oy+13,sql1);
sprintf(sql1,"Structure: ");
outtextxy(ox+3,oy+37,sql1);
sprintf(sql1,"========== ");
outtextxy(ox+3,oy+47,sql1);

for(l=0;l<fieldscount;l++)>
{
fscanf(fp,"%s %s",fields[l],datatypes[l]);
outtextxy(ox+3,oy+57+l*10,fields[l]);
outtextxy(ox+100,oy+57+l*10,datatypes[l]);
}
if(pk==0)
sprintf(sql1,"Primary Key: None");
else
sprintf(sql1,"Primary Key: %s",fields[pk-1]);
outtextxy(ox+3,oy+23,sql1);

fclose(fp);
}
}

void tableList(char pat[5],int ox,int oy,int ow,int oh)
{
struct ffblk ffblk;
char sql1[80],tableName[20];
int i,r,c,fCount=0;
strcpy(sql1,"");
strcpy(tableName,"");
bar(ox+3,oy+3,ox+ow,oy+oh);
sprintf(sql1,"File List: ");
outtextxy(ox+3,oy+3,sql1);
sprintf(sql1,"========== ");
outtextxy(ox+3,oy+10,sql1);
i=findfirst(pat,&ffblk,0);
r=20;
c=0;
while(!i)
{
sprintf(sql1,"%s", ffblk.ff_name);
outtextxy(ox+3+c,oy+r,sql1);
fCount++;
i=findnext(&ffblk);
if(c>=500)
{
if(r>100)
{
r=15;
c=0;
getch();
bar(ox+3,oy+3,ox+ow,oy+oh);
}
else
{
r=r+20;
c=0;
}
}
else
c=c+100;
}
sprintf(sql1,"Tatal File(s): %d",fCount);
setcolor(RED);
outtextxy(ox+3,oy+r+20,sql1);
setcolor(BLUE);
}


void primaryKey(char table[20])
{
FILE *fp1,*ftemp;
char data[100][10][50],buff[10],fields[10][32],datatypes[10][15];
int j,k,l,fieldsCount,size,recCount,pk,i;
strcpy(buff,"");
for(i=0;i<10;i++)
{
strcpy(fields[i],"");
strcpy(datatypes[i],"");
}

ftemp=fopen("temp.$$$","w+");
fp1=fopen(table,"r");
fscanf(fp1,"%d%d%d%d",&fieldsCount,&size,&recCount,&pk);
fprintf(ftemp,"%d\t%d\t%d\t%d\t",fieldsCount,size,recCount,pk);
for(l=0;l<fieldscount;l++)>
{
fscanf(fp1,"%s %s",fields[l],datatypes[l]);
fprintf(ftemp,"%s\t%s\t",fields[l],datatypes[l]);
}
fprintf(ftemp,"\n");
for(k=0;k<reccount;k++)>
{
fgetc(fp1);
for(j=0;j<fieldscount;j++)>
{ fgetc(fp1);
fscanf(fp1,"%[^\t]",data[k][j]);
}
}
for(j=0;j<fieldscount;j++)>
{
if(j==(pk-1))
if(strncmpi(datatypes[j],"NUMBER",6)==0 )
sort(data,pk,fieldsCount,recCount,0);
else
sort(data,pk,fieldsCount,recCount,1);
}
for(k=0;k<reccount;k++)>
{
for(j=0;j<fieldscount;j++)>
{
strcpy(buff,"%");
if(strncmpi(datatypes[j],"NUMBER",6)==0)
{
l=locstrchar(datatypes[j],')');
strcat(buff,substr(datatypes[j],7,l-1));
strcat(buff,"s\t");
}
else
{
l=locstrchar(datatypes[j],')');
strcat(buff,substr(datatypes[j],7,l-1));
strcat(buff,"s\t");
}
fprintf(ftemp,buff,data[k][j]);
}

}
fclose(fp1);
fclose(ftemp);
remove(table);
rename("temp.$$$",table);
}

void sort(char data[100][10][50],int pk,int fc, int rc,int type)
{
char temp[10][50];
int i,j,k;
for(i=0;i<10;i++)
{
strcpy(temp[i],"");
}
for(i=0;i<rc;i++)>
{
for(j=i+1;j<rc;j++)>
{
if(type==0)
{
if(atol(data[i][pk-1])>atol(data[j][pk-1]))
{
for(k=0;k<fc;k++)>
{
strcpy(temp[k],data[i][k]);
strcpy(data[i][k],data[j][k]);
strcpy(data[j][k],temp[k]);
}
}
}
else
{
if(strcmpi(data[i][pk-1],data[j][pk-1])>0)
{
for(k=0;k<fc;k++)>
{
strcpy(temp[k],data[i][k]);
strcpy(data[i][k],data[j][k]);
strcpy(data[j][k],temp[k]);
}

}
}
}
}
}

void help()
{
system("c:\\progra~1\\intern~1\\iexplore.exe www.yahoo.com");
}
Posted
Comments
Member 10754440 16-Apr-14 15:31pm    
how can this be solved ??
[no name] 16-Apr-14 15:38pm    
How can what be solved? All you have done is dump your entire code base here, unformatted, without any explanation, question or description of a problem. Except some impossible blurb about a linker error at runtime.
Sergey Alexandrovich Kryukov 16-Apr-14 15:44pm    
Error "while it's running" is not a linker error by definition. Period.
—SA
Andreas Gieriet 16-Apr-14 19:26pm    
What error? Work smarter not harder: tell first what the excat "error" message is.
Cheers
Andi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900