-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
1224 lines (838 loc) · 32 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2019 Koushik R <rkoushik.14@gmail.com>.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#include <limits>
#include "globals.h"
#include "db.h"
#include "buffer_manager.h"
#include "SysTableOverlay.h"
#include "DBOverlay.h"
#include "SysColumnOverlay.h"
#include "Utils.h"
#include "MegaStruct.h"
#define SIMPLE 0
#define COMPLEX 1
//#include <strstream>
using namespace std;
//int Verbose_Flag;
#define TESTPAGE 29
bool select_flag;
typedef std::vector<mega_struct> mega_list;
buffer_manager buffer1;
Database db;
/*Declarations*/
//UI functions Declarations
int PrintTypeofQueryMenu();
int Print_Main_options();
int Print_DB_Gui_Options();
int PrintSQLqueryMenu();
int Print_Buffer_Gui_Options();
int Print_Gui_Options();
//SQL functions declarations
int CreateTable();
mega_list BulkCreateTable();
int InsertTable();
int InstantInsertTable();
int BulkInsert();
int SelectTable();
int Rec_insert_Cond(mega_struct *mega);
int Delete_record();
int DeleteTable();
int DescribeTable();
int showTables();
//Other functions declarations
int Showslot();
void Clear_Options();
void Process_Options(int argc,char *argv[]);
// Main Function
int main(int argc,char *argv[])
{
//string temp;
Clear_Options();
//printf("========== %d",sizeof(dp_page));
// Get choice option for testing GUI
int opt,i, cont = 0;
char aks_db_name[MAX_FILE_NAME];
long numpages, status, initsize;
//Verbose_Flag = FSET;
// Process the command prompt options
Process_Options(argc,argv);
Replace_Policy = LRU;
// Give opt some high value to exit
opt=20;
buffer1.PrintVerbose("MAIN:: The program is in verbose mode");
//long ff;
//ff = ((PG_DATASIZE - sizeof(dp_page))/sizeof(de_struct));
//printf("\nde----------%ld\n",ff);
printf("\n\t\tBUFFER MANAGER");
printf("\n\t\t--------------\n");
printf("Size for the buffer Manager(in KB): ");
scanf("%ld",&initsize);
Buffer_Pool::InitBuffer(initsize);
//buffer1.InitBuffer(initsize);
strcpy(Current_Open_DB_Name, "\0");
int option = 10, main_opt = 10, buffer_opt = 20, db_opt = 20, sql_opt = 20;
bool check_exit = false;
int result;
mega_struct *mega_str;
mega_list m;
do {
if(check_exit == true) break;
main_opt = Print_Main_options();
switch(main_opt){
case 1:
//Buffer_Manager
do{
buffer_opt = Print_Buffer_Gui_Options();
switch(buffer_opt){
// Create DB
case 1:
buffer1.Reset_String(aks_db_name,MAX_FILE_NAME);
printf("\t\nEnter the name for the new database(max 16chars): ");
scanf("\t%s",aks_db_name);
printf("\t\nEnter the number of DB pages: ");
scanf("\t%ld",&numpages);
buffer1.CreateDB (aks_db_name, numpages, PAGESIZE);
break;
// Delete DB
case 2:
buffer1.Reset_String(aks_db_name,MAX_FILE_NAME);
printf("\nEnter the name for the new database(max 16chars): ");
scanf("%s",aks_db_name);
buffer1.DeleteDB (aks_db_name);
break;
// Increment DB
case 3:
printf("\nEnter the number of DB pages for increamenting: ");
scanf("%ld",&numpages);
buffer1.IncrementDB (numpages, PAGESIZE);
break;
// Read Page
case 4:
// use the current DB and page num will be stored in numpages
buffer1.Reset_String(aks_db_name,MAX_FILE_NAME);
printf("\nEnter the name for the database to be read: ");
scanf("%s",aks_db_name);
printf("\nEnter the page number: ");
scanf("%ld",&numpages);
buffer1.ReadPage (aks_db_name, numpages);
break;
// Write Page
case 5:
buffer1.Reset_String(aks_db_name,MAX_FILE_NAME);
printf("\nEnter the name for the database to be read: ");
scanf("%s",aks_db_name);
printf("\nEnter the page number: ");
scanf("%ld",&numpages);
buffer1.WritePage (aks_db_name, numpages);
break;
// Show Frame
case 6:
// Here numpages takes form of frame number
printf("\nEnter the frame number: ");
scanf("%ld",&numpages);
buffer1.ShowFrame(numpages);
break;
// Show Frames
case 7:
buffer1.ShowFrames();
break;
// Commit
case 8:
buffer1.Reset_String(aks_db_name,MAX_FILE_NAME);
printf("\nEnter the name for the database to commit: ");
scanf("%s",aks_db_name);
printf("\nEnter the page number: ");
scanf("%ld",&numpages);
buffer1.Commit(aks_db_name, numpages);
break;
// Commit All
case 9:
buffer1.Reset_String(aks_db_name,MAX_FILE_NAME);
printf("\nEnter the name for the database to commit: ");
scanf("%s",aks_db_name);
buffer1.CommitAll(aks_db_name);
break;
// Release Buffer and Exit
case 10:
buffer1.CommitAll(Current_Open_DB_Name);
Buffer_Pool::ReleaseBuffer();
break;
// Open the DB
case 11:
buffer1.Reset_String(aks_db_name,MAX_FILE_NAME);
printf("\nEnter the name for the database to open: ");
scanf("%s",aks_db_name);
status = buffer1.OpenDB (aks_db_name);
if (status==ERROR)
printf("\nError has occured from OpenDB");
break;
//Print all the entries in Db Handler
case 12:
if (curDbOpen == 0)
printf("\nThe DB Table Index is Empty");
else
{
printf("\n----------Printing DB Handler entries--------------");
for (i=0;i<curDbOpen;i++)
{
printf("\nIndex: %d",i+1);
printf("\nDb Name: %s",db_handle[i]._dbname);
printf("\nDb Index: %ld",db_handle[i]._db_index);
printf("\n\n");
}
}
break;
//go back to main menu
case 13:
break;
default:
printf("\tERROR:: Unknown Option\n");
}
}while(buffer_opt != 13);
break;
case 2:
//DAtabase Module
do{
if(check_exit == true) break;//break to exit
db_opt = Print_DB_Gui_Options();
switch(db_opt){
case 1:
//Create DB
buffer1.Reset_String(aks_db_name,MAX_FILE_NAME);
printf("\nEnter the name for the new database(max 16chars): ");
scanf("%s",aks_db_name);
printf("\nEnter the number of DB pages: ");
scanf("%ld",&numpages);
db.Create_DB (aks_db_name, numpages, PAGESIZE);
break;
case 2:
//useDB
char dbname[NAME_LENGTH];
printf("\nEnter the name of the database to be used\n");
scanf("%s",dbname);
db.Use_DB(dbname);
break;
case 3:
//SQL module
do{
sql_opt = PrintSQLqueryMenu();
switch(sql_opt){
case 1:
//CREATE MENU
result = CreateTable();
if(result == 0){
printf("\nsuccess");
break;
}
case 2:
//INSTANT INSERT MENU
//InstantInsertTable();
break;
case 3:
//INSERT MENU
InsertTable();
cout <<endl;
cout <<"One record inserted"<< endl;
cout << endl;
cout << endl;
Utils::pressEnter();
break;
case 4:
//delete records from table
//PrintMegaStructure(mega);
Delete_record();
cout << endl;
cout << endl;
Utils::pressEnter();
break;
case 5:
//Show tables
showTables();
cout << endl;
cout << endl;
Utils::pressEnter();
break;
case 6:
//Select table
SelectTable();
cout << endl;
cout << endl;
Utils::pressEnter();
break;
case 7:
//Bulk CReate table
m = BulkCreateTable();
for(i = 0; i< m.size();i++){
mega_str = &m[i];
result = db.Create_Table(mega_str);
}
if(result == 0){
printf("\nsuccess");
break;
}
case 8:
//Show slot
//Showslot();
BulkInsert();
break;
case 9:
//Describe table
DescribeTable();
cout << endl;
cout << endl;
Utils::pressEnter();
break;
case 10:
//go to database module menu
break;
default:
printf("\tERROR:: Unknown Option\n");
}
}while(sql_opt != 10);
break;
case 4:
//Commit All
buffer1.Reset_String(aks_db_name,MAX_FILE_NAME);
printf("\nEnter the name for the database to commit: ");
scanf("%s",aks_db_name);
buffer1.CommitAll(aks_db_name);
break;
case 5:
//Release buffer and exit
buffer1.CommitAll(Current_Open_DB_Name);
Buffer_Pool::ReleaseBuffer();
check_exit = true;
break;
case 6:
//GO to main menu
break;
default:
printf("\tERROR:: Unknown Option\n");
}
}while(db_opt != 6 );
break;
case 3:
//exit from main print menu
break;
default:
printf("\tERROR:: Unknown Option\n");
}
}while(main_opt !=3);
return 0;
}
void Clear_Options()
{
Verbose_Flag = FRSET;
}
void Process_Options(int argc,char *argv[])
{
int i;
i = 1;
while (i < argc)
{
if (argv[i][0] == '-')
{
switch (toupper(argv[i][1]))
{
case 'V':
Verbose_Flag = FSET;
break;
default:
printf("\n Unknown Option ");
printf("\n");
exit(ERROR);
}
}
i++;
}
}
int Print_Main_options(){
int get_opt;
printf("\n\n\n\t\t================\n");
printf("\t\t1. BUFFER MANAGER");
printf("\n\n\n\t\t================\n");
printf("\t\t2. DATABASE MODULE");
printf("\n\n\n\t\t================\n");
printf("\t\t3. FINISH PROGRAM");
printf("\n\nEnter your option(1-3):: ");
scanf("%d",&get_opt);
return (get_opt);
}
int Print_Buffer_Gui_Options()
{
int get_opt;
printf("\n\n\t Buffer Manager Testing Module \n");
printf("\t ----------------------------- \n");
printf("\n\n");
printf("\t List of Options: \n");
printf("\t 1. Create DB: \n");
printf("\t 2. Delete DB: \n");
printf("\t 3. Increment DB: \n");
printf("\t 4. Read Page: \n");
printf("\t 5. Write Page: \n");
printf("\t 6. Show Frame: \n");
printf("\t 7. Show Frames: \n");
printf("\t 8. Commit: \n");
printf("\t 9. Commit All: \n");
printf("\t 10. Release Buffer and Exit: \n");
printf("\t 11. OpenDB: \n");
printf("\t 12. Print DB Index: \n");
printf("\t 13. Go Back to Previous menu: \n");
printf("\t ----------------------------- \n\n");
printf("Enter your option(1-13):: ");
scanf("%d",&get_opt);
return (get_opt);
}
int Print_DB_Gui_Options(){
int get_opt;
printf("\n\n\t Database Testing Module \n");
printf("\t ----------------------------- \n");
printf("\t 1. Create_DB: \n");
printf("\t 2. Use_DB: \n");
printf("\t 3. SQL commands: \n");
printf("\t 4. Commit All: \n");
printf("\t 5. Release Buffer and Exit: \n");
printf("\t 6. Go Back to Previous menu: \n");
printf("\t ----------------------------- \n\n");
printf("Enter your option(1-6):: ");
printf("\n\n");
scanf("%d",&get_opt);
return (get_opt);
}
int PrintSQLqueryMenu(){
int option;
printf("\n\n\t SQL Query Module \n");
printf("\t ----------------------------- \n");
printf("\t1. Create Table Query: \n");
printf("\t2. Instant Insert into Table: \n");
printf("\t3. Insert Into Table: \n");
printf("\t4. Delete from Table: \n");
printf("\t5. Print systable: \n");
printf("\t6. Select * from Table: \n");
printf("\t7. Bulk create Tables: \n");
printf("\t8. Bulk Insert Records: \n");
printf("\t9. Describe Table: \n");
printf("\t10. flush Query and go back to previous menu \n");
//printf("1. Create Table Query \n");
printf("\t ----------------------------- \n\n");
printf("\n\n");
printf("\tEnter Option(1-10):: ");
scanf("%d",&option);
return (option);
}
int CreateTable(){
mega_struct *imega;
int i;
char str[NAME_LENGTH];
char dataType[NAME_LENGTH];
imega = MegaStruct::Initialize();
printf("\tEnter name of the table \n");
scanf("\t%s",str);
strcpy(imega->Table, str);
printf("\tEnter the number of columns\n");
scanf("\t%ld",&(imega->NumPattr));
Attribute *a;
for(i = 0; i< imega->NumPattr; i++){
a = (Attribute *)malloc(sizeof(Attribute));
printf("\tEnter Column# %d name\n",i);
a->ppos = (i + 1);
a->value = NULL;
scanf("\t%s",a->attr_name);
printf("\tEnter column type\n");
scanf("\t%s", dataType);
// Fill in the dataType
if ( strcmp(dataType, "INT") == 0 )
a->type = INT;
else if ( strcmp(dataType, "VARCHAR") == 0 )
a->type = VARCHAR;
else if ( strcmp(dataType, "CHAR") == 0 )
a->type = CHAR;
else if ( strcmp(dataType, "FLOAT") == 0 )
a->type = FLOAT;
else
a->type = VARCHAR;
// Erase The DataType
memset(dataType,'\0',NAME_LENGTH);
printf("\tEnter length\n");
scanf("\t%d",&(a->length));
if(a->type == INT){
a->length = sizeof(int);
}
if(a->type == FLOAT){
a->length = sizeof(float);
}
printf("\tEnter 0 if primary key attribute else enter 1\n");
//cout << "\t";
cin >> a->IsPrimary;
a->value = (char *)malloc(a->length*sizeof(char));
a->ppos = i+1;
a->IsNull = false;
imega->Pattr.push_back(a);
}
imega->Relation = CREATE;
printf("\n in main's create\n");
UI::PrintColumns(imega);
db.Create_Table(imega);
MegaStruct::Destroy(&imega);
return 0;
}
mega_list BulkCreateTable(){
mega_list m;
mega_struct imega;
long number_of_tables, i;
char *str, *str1;
printf("\tEnter number of the table \n");
scanf("\t%ld",&number_of_tables);
Attribute *a;
for(i = 0 ; i < number_of_tables ; i++){
a = (Attribute *)malloc(sizeof(Attribute));
a->ppos = (i + 1);
a->value = NULL;
strcpy(a->attr_name,"c1");
a->type = INT;
a->IsPrimary = 1;
a->length = sizeof(int);
str = (char *)malloc(NAME_LENGTH * sizeof(char));
str1 = (char *)malloc(NAME_LENGTH * sizeof(char));
Utils::itoa(i,str1,10);
strcpy(str,"t");
strcat(str,str1);
strcpy(imega.Table,str);
free(str);
imega.NumPattr = 1;
imega.Pattr.push_back(a);
imega.Relation = CREATE;
m.push_back(imega);
}
return m;
}
int BulkInsert(){
mega_struct *imega;
imega = MegaStruct::Initialize();
printf("\n Enter the table name\n");
scanf("%s",imega->Table);
imega->Relation = INSERT;
db.Bulk_Insert_Table(imega);
MegaStruct::Destroy(&imega);
return 0;
}
//void InstantInsertTable()
//{
// int i;
// int dataType;
// char *data;
// for(i = 0; i< mega->NumPattr; i++){
//
// /* if (mega->Pattr[i].value != NULL)
// {
// void *freeptr;
// freeptr = mega->Pattr[i].value;
// free(freeptr);
// mega->Pattr[i].value = NULL;
// }
// */
// memset(mega->Pattr[i].value,NULL,mega->Pattr[i].length);
//
// printf("\tEnter column value for Column Name: %s \n", mega->Pattr[i].attr_name);
// dataType = mega->Pattr[i].type;
// data = (char*)mega->Pattr[i].value;
// //data = (char*)malloc(mega->Pattr[i].length * sizeof(char));
// //memset(data,NULL,mega->Pattr[i].length);
// switch (dataType)
// {
// case INT:
// scanf("\t%d", (int *)data);
// break;
// case FLOAT:
// scanf("\t%f", (float *)data);
// break;
// case CHAR:
// scanf("\t%s", (char *)data);
// break;
// case VARCHAR:
// scanf("\t%s", (char *)data);
// break;
// }
// //mega->Pattr[i].value = data;
// }
//
// buffer_manager bm;
// DBOverlay *dbp;
// genpage *mypage;
// mypage = bm.BufferWrite(Current_Open_DB_Name,TESTPAGE);
//
// dbp = new DBOverlay(mypage, DB_PAGE_PRIORITY);
// long rec_length;
// rec_length = DBOverlay::computeSize(mega);
// dbp->insert_slot(mega,rec_length);
//
// bm.ReleasePage(Current_Open_DB_Name, mypage->_page_number);
// //bm.Commit(Current_Open_DB_Name,mypage->_page_number);
//}
int InsertTable(){
mega_struct *imega;
char table_name[NAME_LENGTH];
imega = MegaStruct::Initialize();
printf("\tEnter the table name\n");
scanf("\t%s",table_name);
strcpy(imega->Table,table_name);
imega->Relation = INSERT;
db.Insert_Table(imega);
MegaStruct::Destroy(&imega);
return 0;
}
int SelectTable(){
mega_struct *imega;
int option;
Attribute *a;
imega = MegaStruct::Initialize();
char tablename[NAME_LENGTH];
printf("\tEnter table name to be printed\n");
scanf("\t%s",tablename);
strcpy(imega->Table,tablename);
imega->NumPattr = 0;
printf("\tEnter column names to be projected\n");
int count = 0;
int test = 1;
select_flag = false;
//inputting Projection attributes
while(1){
count++;
printf("\tEnter column # %d name\n", count);
a = (Attribute *)malloc(sizeof(Attribute));
scanf("%s", a->attr_name);
if(strcmp(a->attr_name,"*") == 0){
//SET select_flag
select_flag = true;
free(a);
break;
}
imega->Pattr.push_back(a);
imega->NumPattr = imega->NumPattr + 1;
printf("\tDo you wish to enter more columns... enter 1 for 'yes' and 0 for 'no'\n");
scanf("%d",&test);
if(test != 1)
{
break;
}
}
//fill sattr ----- select attributes
//set number of select attributes to zero initially
imega->NumSattr = 0;
//filling conditions in postfix order
printf("\nDo you wish to enter conditions? 1 for yes or 0 for no\n");
scanf("%d",&option);
if(option == 1){
Rec_insert_Cond(imega);
//checking if the order is indeed postfix..
printf("\n");
for(int j = 0; j < imega->Condition.size(); j++){
if(imega->Condition[j]->type != COLUMN){
printf("%s\t", (char *)imega->Condition[j]->value);
}
else{
int p = *(int *)imega->Condition[j]->value;
printf("%s\t",imega->Sattr[p-1]->attr_name);
}
}
}
imega->Relation = SELECT;
db.Select_Table(imega);
MegaStruct::Destroy(&imega);
return 0;
}
int Rec_insert_Cond(mega_struct *mega){
int type;
condition *cond;
bool cond_set = false;
Attribute *a;
char *op_name1 = NULL , *op_name2 = NULL, *op = NULL;
printf("\n Enter type of first operand 0. SIMPLE 1. COMPLEX\n");
scanf("%d",&type);
if(type == SIMPLE){
printf("\n the first operand type is simple \n");
cond = (condition *)malloc(sizeof(condition));
printf("\n Enter first operand type-----> 0. COLUMN 1. LITERAL 2. OPERATOR\n");
scanf("%d",&(cond->type));
printf("\n Enter first operand name\n");
op_name1 = (char *)malloc(NAME_LENGTH * sizeof(char));
scanf("%s", op_name1);
if(cond->type == COLUMN){
a = (Attribute *)malloc(sizeof(Attribute));
strcpy(a->attr_name,op_name1);
for(int i = 0; i < mega->Sattr.size(); i++){
if(strcmp(op_name1, mega->Sattr[i]->attr_name) == 0){
cond->value = (int *)malloc(sizeof(int));
*(int*)cond->value = i;
cond_set = true;
}
}
mega->Sattr.push_back(a);
mega->NumSattr = mega->NumSattr + 1;
if(cond_set == false){
cond->value = (int *)malloc(sizeof(int));
*(int*)cond->value = mega->Sattr.size();
}
}
else if(cond->type != COLUMN){
cond->value = (char *)malloc(NAME_LENGTH * sizeof(char));
strcpy((char*)cond->value, op_name1);
//mega->Condition.push_back(cond);
}
mega->Condition.push_back(cond);
}
else
{
printf("\n the first operand type is complex \n");
Rec_insert_Cond(mega);
}