Skip to content

Commit 69bc426

Browse files
committed
Merge branch 'master' of github.com:csdashes/DB-Implementation
2 parents eb4b624 + 587833f commit 69bc426

File tree

6 files changed

+73
-90
lines changed

6 files changed

+73
-90
lines changed
Binary file not shown.
Binary file not shown.

Windows_Code/TexnologiaVasewnDedomenwn/TexnologiaVasewnDedomenwn/REM_RecordFileScan.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ t_rc REM_RecordFileScan::GetNextRecord(REM_RecordHandle &rh) {
5252
if (!this->isOpen) { return REM_FSCLOSED; }
5353
t_rc rc;
5454

55-
// KATI PAIZEI EDW PERA. DEN KATALAVAINW...
5655
do {
5756
char *pData;
5857
int pageID;

Windows_Code/TexnologiaVasewnDedomenwn/TexnologiaVasewnDedomenwn/SSQLM_DML_Manager.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,6 @@ t_rc SSQLM_DML_Manager::Where(const char *tName, char *conditions, vector<char *
264264

265265
remrh->GetData(pdata);
266266

267-
cout<<"AAAAAAAAAAAAAAAA "<<pdata<<" AAAAAAAAAA"<<endl;
268-
269267
int pDataLength = strlen(pdata);
270268
char * newInput;
271269
newInput = (char *)malloc(pDataLength);
@@ -282,28 +280,25 @@ t_rc SSQLM_DML_Manager::Where(const char *tName, char *conditions, vector<char *
282280
// 8a psaksoume to attribute tou ka8e condition sto arxeio attrmet
283281
// // wste na paroume plhrofories gia to attribute (offset,type,...)
284282
int offset2,size2,indexID2; // me teliko stoxo na elegksoume poia apo ta records pou epestrepsan
285-
char *type2; // oi indexers, epalh8euoun ta conditions xwris index.
283+
char *type2; // oi indexers, epalh8euoun ta conditions xwris index.
286284

287-
for(int i=0; i< (int) conditionsListWithoutIndex.size(); i++){ // Gia ka8e tetoio condition loipon,
285+
for(int i=0; i< (int) conditionsListWithoutIndex.size(); i++){ // Gia ka8e tetoio condition loipon,
288286

289287
rc = GetConditionInfo(conditionsListWithoutIndex[i],conditionAttribute,comp,conditionValue); // vres ta systatika tou merh (attribute, comperator, value)
290288
if (rc != OK) {return rc; }
291289

292-
rc = FindAttributeInAttrmet(tName,conditionAttribute,offset2,type2,size2,indexID2); // kai psakse mesa sto attrmet to record gia to sygkekrimeno attribute. Pare tis plhrofories gia to attribute.
290+
rc = FindAttributeInAttrmet(tName,conditionAttribute,offset2,type2,size2,indexID2); // kai psakse mesa sto attrmet to record gia to sygkekrimeno attribute. Pare tis plhrofories gia to attribute.
293291
if (rc != OK) {return rc; }
294292

295293
int j = 0;
296294
if(!recordsFromIndexes.empty()){
297-
for(int j=0; j<(int)recordsFromIndexes.size(); j++){ // Sygkrine an isxyei h syn8hkh me ola ta records pou epestrepsan oi indexes.
298-
//for ( ridsToRecords_Iter = ridsToRecords.begin( ); ridsToRecords_Iter != ridsToRecords.end( ); ridsToRecords_Iter++ ){
299-
295+
for(int j=0; j<(int)recordsFromIndexes.size(); j++){ // Sygkrine an isxyei h syn8hkh me ola ta records pou epestrepsan oi indexes.
300296

301297
char *value; // Ean h syn8hkh epalh8euetai, pros8ese to record sthn lista eksodou finalResultRecords.
302298
value = (char *)malloc(size);
303299
int z;
304300
for(z=0; z<size; z++){
305301
value[z] = recordsFromIndexes[j][offset+z];
306-
//value[z] = ridsToRecords_Iter->second[offset+z];
307302
}
308303
value[z] = '\0';
309304
if(strstr(type,"TYPE_INT")){
@@ -386,7 +381,7 @@ t_rc SSQLM_DML_Manager::Where(const char *tName, char *conditions, vector<char *
386381
int atoiCondition = atoi(conditionValue);
387382
int *key = new int(atoiCondition);
388383

389-
rc = remrfs->OpenRecordScan(*remrfh2,TYPE_INT,size,offset,comp,key); // DEN EPISTREFEI SWSTA APOTELESMATA. PX id<2 TA EPISTREFEI OLA.
384+
rc = remrfs->OpenRecordScan(*remrfh2,TYPE_INT,size,offset,comp,key);
390385
if (rc != OK) {return rc; }
391386
}
392387
else{
@@ -452,7 +447,7 @@ t_rc SSQLM_DML_Manager::Select(const char *tName, vector<char *> columns, vector
452447
int offset, size, indexID;
453448
char *type;
454449

455-
for(int n = 0; n < (int)columns.size(); n++) { // Gia ka8e column
450+
for(int n = 0; n < (int)columns.size(); n++) { // Gia ka8e column
456451
vector<char *> tempList; // ftiaxnw thn lista me ta dedomena apo to ka8e record.
457452

458453
t_rc rc = FindAttributeInAttrmet(tName,columns[n],offset,type,size,indexID); // Vriskw to offset tou column

Windows_Code/TexnologiaVasewnDedomenwn/TexnologiaVasewnDedomenwn/SYSM_DatabaseManager.cpp

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -68,32 +68,9 @@ bool SYSM_DatabaseManager::isOpen(){
6868

6969

7070
t_rc SYSM_DatabaseManager::DropDatabase (const char *dbName){
71-
// ifstream myfile;
72-
// int i=0;
73-
// char relpath[260];
74-
// char attrpath[260];
75-
// char tablename[255];
76-
// char deletename[255];
77-
// const char *name;
78-
// _snprintf_s(relpath,sizeof(relpath),"%s/rel.met",dbName);
79-
// _snprintf_s(attrpath, sizeof(attrpath), "%s/attr.met",dbName);
80-
// myfile.open(relpath);
81-
// while (myfile.getline(tablename,255)){
82-
// while (tablename[i]!=' ' && tablename[i]!='\0') {
83-
// i++;
84-
// }
85-
// tablename[i]='\0';
86-
// name=tablename;
87-
// _snprintf_s(deletename,sizeof(deletename),"%s/%s",dbName,name);
88-
// remove(deletename);
89-
// remove(relpath);
90-
// remove(attrpath);
91-
// getchar();
92-
// rmdir(dbName);
93-
// }
9471
char dir[200];
95-
strcpy (dir,"rmdir /S /Q /Data/");
96-
strcpy (dir, dbName);
72+
strcpy (dir,"rmdir /S /Q \Data\\");
73+
strcat (dir, dbName);
9774
system (dir);
9875
return OK;
9976
}

Windows_Code/TexnologiaVasewnDedomenwn/TexnologiaVasewnDedomenwn/main.cpp

Lines changed: 65 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -355,16 +355,16 @@ void testSYSM() {
355355
SYSM_DatabaseManager *sdm = new SYSM_DatabaseManager(rfm);
356356

357357
// Create the folder "testingDB" which contains the files rel.met and attr.met
358-
//t_rc rc = sdm->CreateDatabase("testingDB");
359-
//if (rc != OK) {DisplayReturnCode(rc);exit(-1);}
360-
361-
//// Open the database to use it
362-
//rc = sdm->OpenDatabase("testingDB");
363-
//if (rc != OK) {DisplayReturnCode(rc);exit(-1);}
358+
t_rc rc = sdm->CreateDatabase("testingDB");
359+
if (rc != OK) {DisplayReturnCode(rc);exit(-1);}
364360

365-
t_rc rc = sdm->DropDatabase("testingDB");
361+
// Open the database to use it
362+
rc = sdm->OpenDatabase("testingDB");
366363
if (rc != OK) {DisplayReturnCode(rc);exit(-1);}
367364

365+
/*t_rc rc = sdm->DropDatabase("testingDB");
366+
if (rc != OK) {DisplayReturnCode(rc);exit(-1);} */
367+
368368
//delete sdm;
369369
//delete rfm;
370370
}
@@ -410,15 +410,10 @@ void testSSQLM() {
410410
rc = ddlm->CreateIndex("table3","born");
411411
if (rc != OK) {DisplayReturnCode(rc);exit(-1);}
412412

413-
414-
415413
// Drop table
416414
//rc = ddlm->DropTable("table1");
417415
//if (rc != OK) {DisplayReturnCode(rc);exit(-1);}
418416

419-
// TEST IF DELETE REALLY WORKS
420-
//rc = ddlm->PrintFirstRecordInAttrMet("table2");
421-
//if (rc != OK) {DisplayReturnCode(rc);exit(-1);}
422417
// Drop index
423418
//rc = ddlm->DropIndex("table1","name",1);
424419
//if (rc != OK) {DisplayReturnCode(rc);exit(-1);}
@@ -503,53 +498,26 @@ void testSSQLM() {
503498
REM_RecordID rids[50];
504499
int slott;
505500
vector <char*> finalResultRecords3;
501+
vector <char*> finalResultRecords7;
506502
vector <REM_RecordID> finalResultRIDs3;
507503

508504
dmlm3->Where("table1","id>0",&finalResultRecords3,&finalResultRIDs3); //************************************
509505
if (rc != OK) {DisplayReturnCode(rc);exit(-1);} //** Show all records
510506
//**
511-
cout<<"ALL RECORDS IN THE TABLE:"<<endl; //** (SELECT *
507+
cout<<"ALL RECORDS IN THE TABLE1:"<<endl; //** (SELECT *
512508
for(int interator = 0; interator < (int)finalResultRecords3.size(); interator++){//** FROM table1
513509
finalResultRIDs3[interator].GetSlot(slott); //** WHERE id>0)
514-
cout<<slott<<" -> "<<finalResultRecords3[interator]<<endl; //**
510+
cout<<finalResultRecords3[interator]<<endl; //**
515511
} //*************************************
516512
cout<<endl;
517513

518-
int until; //*************************************
519-
do { //** TEST DELETE
520-
vector <char*> finalResultRecords2; //**
521-
vector <REM_RecordID> finalResultRIDs2; //**
522-
//** (DELETE
523-
dmlm3->Where("table1","age>25",&finalResultRecords2,&finalResultRIDs2); //** FROM table1
524-
if (rc != OK) {DisplayReturnCode(rc);exit(-1);} //** WHERE age > 25)
525-
//**
526-
if(finalResultRecords2.size()!=0){ //**
527-
dmlm3->Delete("table1",finalResultRIDs2[0],finalResultRecords2[0]); //**
528-
if (rc != OK) {DisplayReturnCode(rc);exit(-1);} //**
529-
} //**
530-
until = finalResultRecords2.size(); //**
531-
}while(until != 0); //**
532-
//**
533-
vector <char*> finalResultRecords; //**
534-
vector <REM_RecordID> finalResultRIDs; //**
535-
//**
536-
dmlm3->Where("table1","id>0",&finalResultRecords,&finalResultRIDs); //**
537-
if (rc != OK) {DisplayReturnCode(rc);exit(-1);} //**
538-
//**
539-
cout<<"TEST DELETE. ALL RECORDS IN THE TABLE (DELETE WHERE age > 25):"<<endl; //** Show all records after delete
540-
for(int interator = 0; interator < (int)finalResultRecords.size(); interator++){//**
541-
finalResultRIDs[interator].GetSlot(slott); //**
542-
cout<<slott<<" -> "<<finalResultRecords[interator]<<endl; //**
543-
} //**************************************
544-
cout<<endl;
545-
546514
vector <char*> finalResultRecordsSelect; //**************************************
547515
vector <char*> columns; //** TEST SELECT
548516
columns.push_back("name"); //** kanw push ta columns pou 8elw na krathsw
549517
columns.push_back("age"); //**
550518
//columns.push_back("*"); //** (SELECT name, age
551519
//** FROM table1
552-
dmlm3->Select("table1",columns,finalResultRecords,&finalResultRecordsSelect); //** WHERE id > 0)
520+
dmlm3->Select("table1",columns,finalResultRecords3,&finalResultRecordsSelect); //** WHERE id > 0)
553521
if (rc != OK) {DisplayReturnCode(rc);exit(-1);} //**
554522
//**
555523
cout<<"TEST SELECT. RECORDS CHOPPED BY SELECT( name, age ):"<<endl; //**
@@ -561,24 +529,68 @@ void testSSQLM() {
561529
vector <char*> finalResultRecords4; //**************************************
562530
vector <REM_RecordID> finalResultRIDs4; //** TEST UPDATE
563531
//**
564-
dmlm3->Where("table1","id<2",&finalResultRecords4,&finalResultRIDs4); //**
532+
dmlm3->Where("table1","id>2",&finalResultRecords4,&finalResultRIDs4); //**
565533
if (rc != OK) {DisplayReturnCode(rc);exit(-1);} //** (UPDATE table1
566534
//** set age = 30
567535
dmlm3->Update("table1",finalResultRIDs4,"age=30__"); //** WHERE id < 2)
568536
if (rc != OK) {DisplayReturnCode(rc);exit(-1);} //**
569537
//**
570-
cout<<"TEST UPDATE. RECORDS AFTER UPDATE set age=30 WHERE id<2:"<<endl; //**
571-
for(int interator = 0; interator < (int)finalResultRecords4.size(); interator++){//**
572-
cout<<finalResultRecords4[interator]<<endl; //**
538+
dmlm3->Where("table1","id>2",&finalResultRecords7,&finalResultRIDs4); //**
539+
if (rc != OK) {DisplayReturnCode(rc);exit(-1);} //**
540+
//**
541+
cout<<"TEST UPDATE. RECORDS AFTER UPDATE set age=30 WHERE id>2:"<<endl; //**
542+
for(int interator = 0; interator < (int)finalResultRecords7.size(); interator++){//**
543+
cout<<finalResultRecords7[interator]<<endl; //**
573544
} //**
574545
cout<<endl; //**************************************
575546

576-
cout<<"TEST JOIN. table1, table2 - age:"<<endl;
577-
rc = dmlm3->Join("table1","table2","age");
578-
if (rc != OK) {DisplayReturnCode(rc);exit(-1);}
547+
vector <char*> finalResultRecords8; //**************************************
548+
vector <REM_RecordID> finalResultRIDs8; //**
549+
//** SELECT *
550+
dmlm3->Where("table2","born>0",&finalResultRecords8,&finalResultRIDs8); //** FROM table2
551+
if (rc != OK) {DisplayReturnCode(rc);exit(-1);} //**
552+
//**
553+
cout<<"ALL RECORDS IN TABLE2:"<<endl; //**
554+
for(int interator = 0; interator < (int)finalResultRecords8.size(); interator++){//**
555+
cout<<finalResultRecords8[interator]<<endl; //**
556+
} //**************************************
557+
558+
cout<<endl;
559+
cout<<"TEST JOIN. table1, table2 - age:"<<endl; //**************************************
560+
rc = dmlm3->Join("table1","table2","age"); //** TEST JOIN
561+
if (rc != OK) {DisplayReturnCode(rc);exit(-1);} //** SELECT *
562+
//** FROM table1,table2
563+
//rc = dmlm3->Join("tempTableForJoin","table3","born"); //** WHERE table1.age = table2.age
564+
//if (rc != OK) {DisplayReturnCode(rc);exit(-1);} //**
565+
cout<<endl; //**************************************
579566

580-
//rc = dmlm3->Join("tempTableForJoin","table3","born");
581-
//if (rc != OK) {DisplayReturnCode(rc);exit(-1);}
567+
int until; //**************************************
568+
do { //** TEST DELETE
569+
vector <char*> finalResultRecords2; //**
570+
vector <REM_RecordID> finalResultRIDs2; //**
571+
//** (DELETE
572+
dmlm3->Where("table1","age=25",&finalResultRecords2,&finalResultRIDs2); //** FROM table1
573+
if (rc != OK) {DisplayReturnCode(rc);exit(-1);} //** WHERE age = 25)
574+
//**
575+
if(finalResultRecords2.size()!=0){ //**
576+
dmlm3->Delete("table1",finalResultRIDs2[0],finalResultRecords2[0]); //**
577+
if (rc != OK) {DisplayReturnCode(rc);exit(-1);} //**
578+
} //**
579+
until = finalResultRecords2.size(); //**
580+
}while(until != 0); //**
581+
//**
582+
vector <char*> finalResultRecords; //**
583+
vector <REM_RecordID> finalResultRIDs; //**
584+
//**
585+
dmlm3->Where("table1","id>0",&finalResultRecords,&finalResultRIDs); //**
586+
if (rc != OK) {DisplayReturnCode(rc);exit(-1);} //**
587+
//**
588+
cout<<"TEST DELETE. ALL RECORDS IN THE TABLE (DELETE WHERE age = 25):"<<endl; //** Show all records after delete
589+
for(int interator = 0; interator < (int)finalResultRecords.size(); interator++){//**
590+
finalResultRIDs[interator].GetSlot(slott); //**
591+
cout<<finalResultRecords[interator]<<endl; //**
592+
} //**************************************
593+
582594

583595
system("pause");
584596
}
@@ -593,7 +605,7 @@ int main() {
593605

594606
testSYSM();
595607

596-
// testSSQLM();
608+
testSSQLM();
597609

598610
return (0);
599611
}

0 commit comments

Comments
 (0)