Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "datab.h"
- t_db *InitializareBazaDeDate(char *name) {
- // aloc memorie pentru o baza de date
- t_db *database = (t_db *)calloc(1, sizeof(t_db));
- if (database == NULL) {
- printf("Allocation failed");
- exit(1);
- }
- strcpy(database->name, name);
- database->tables = NULL;
- return database;
- }
- t_table *AlocaTabel(char *name, size_t dataType) {
- t_table *table = (t_table *)malloc(sizeof(t_table));
- if (table == NULL) {
- printf("Allocation failed");
- exit(1);
- }
- table->type = dataType;
- strcpy(table->name, name);
- table->lines = NULL;
- table->columns = NULL;
- table->next = NULL;
- return table;
- }
- t_table *AdaugareTabel(t_db *database, char *name, size_t dataType) {
- t_table *table = AlocaTabel(name, dataType);
- if (database->tables == NULL) {
- database->tables = table;
- database->tables->next = NULL;
- } else {
- // table->next = database->tables;
- // database->tables = table;
- t_table *p = database->tables;
- while (p->next != NULL) {
- p = p->next;
- }
- p->next = table;
- p->next->next = NULL;
- }
- return table;
- }
- t_column *AlocaColoana(char *name) {
- t_column *column = (t_column *)malloc(sizeof(t_column));
- if (column == NULL) {
- printf("Allocation Failed");
- exit(1);
- }
- strcpy(column->name, name);
- column->next = NULL;
- return column;
- }
- void AdaugareColoana(t_table *table, char *name) {
- t_column *column = AlocaColoana(name);
- if (table->columns == NULL) {
- table->columns = column;
- table->columns->next = NULL;
- } else {
- t_column *p = table->columns;
- while (p->next != NULL) {
- p = p->next;
- }
- p->next = column;
- p->next->next = NULL;
- }
- }
- t_table *GasesteTabel(t_db *database, char *name) {
- t_table *table = database->tables;
- while (table != NULL) {
- if (strcmp(table->name, name) == 0) {
- return table;
- }
- table = table->next;
- }
- return NULL;
- }
- t_floatLine *AlocaLinieFLOAT() {
- t_floatLine *line = (t_floatLine *)malloc(sizeof(t_floatLine));
- line->cells = NULL;
- line->next = NULL;
- return line;
- }
- t_floatCell *AlocaCelulaFLOAT(float value) {
- t_floatCell *cell = (t_floatCell *)malloc(sizeof(t_floatCell));
- cell->value = value;
- cell->next = NULL;
- return cell;
- }
- t_floatLine *AdaugaLinieFLOAT(t_table *table) {
- t_floatLine *line = (t_floatLine *)malloc(sizeof(t_floatLine));
- t_floatLine *p;
- line->cells = NULL;
- p = table->lines;
- if (table->lines == NULL) {
- table->lines = line;
- line->next = NULL;
- } else {
- while (p->next != NULL) {
- p = p->next;
- }
- p->next = line;
- p->next->next = NULL;
- }
- return line;
- }
- void AdaugaCelulaFLOAT(t_floatLine *line, float value) {
- t_floatCell *cell = AlocaCelulaFLOAT(value);
- t_floatCell *p = line->cells;
- if (p == NULL) {
- line->cells = cell;
- cell->next = NULL;
- } else {
- while (p->next != NULL) {
- p = p->next;
- }
- p->next = cell;
- p->next->next = NULL;
- }
- }
- void AfiseazaLinieFLOAT(t_floatLine *line) {
- t_floatCell *cell = line->cells;
- while (cell != NULL) {
- printf("%f", cell->value);
- for (int i = 0; i < 23; i++) printf(" ");
- cell = cell->next;
- }
- printf("\n");
- }
- t_intCell *AlocaCelulaINT(int value) {
- t_intCell *cell = (t_intCell *)malloc(sizeof(t_intCell));
- cell->next = NULL;
- cell->value = value;
- return cell;
- }
- t_intLine *AlocaLinieINT() {
- t_intLine *line = (t_intLine *)malloc(sizeof(t_intLine));
- line->cells = NULL;
- line->next = NULL;
- return line;
- }
- t_intLine *AdaugaLinieINT(t_table *table) {
- t_intLine *line = AlocaLinieINT();
- t_intLine *p;
- p = table->lines;
- if (table->lines == NULL) {
- table->lines = line;
- line->next = NULL;
- } else {
- while (p->next != NULL) {
- p = p->next;
- }
- p->next = line;
- p->next->next = NULL;
- }
- return line;
- }
- void AdaugaCelulaInt(t_intLine *line, int value) {
- t_intCell *cell = AlocaCelulaINT(value);
- t_intCell *p = line->cells;
- if (line->cells == NULL) {
- line->cells = cell;
- cell->next = NULL;
- } else {
- while (p->next != NULL) {
- p = p->next;
- }
- p->next = cell;
- p->next->next = NULL;
- }
- }
- void AfiseazaLinieINT(t_intLine *line) {
- t_intCell *cell = line->cells;
- while (cell != NULL) {
- printf("%-30d ", cell->value);
- cell = cell->next;
- }
- printf("\n");
- }
- t_stringCell *AlocaCelulaSTRING(char *value) {
- t_stringCell *cell = (t_stringCell *)malloc(sizeof(t_stringCell));
- cell->value = value;
- cell->next = NULL;
- return cell;
- }
- t_stringLine *AlocaLinieSTRING() {
- t_stringLine *line = (t_stringLine *)malloc(sizeof(t_stringLine));
- line->cells = NULL;
- line->next = NULL;
- return line;
- }
- t_stringLine *AdaugaLinieSTRING(t_table *table) {
- t_stringLine *line = AlocaLinieSTRING();
- t_stringLine *p;
- p = table->lines;
- if (table->lines == NULL) {
- table->lines = line;
- line->next = NULL;
- } else {
- while (p->next != NULL) {
- p = p->next;
- }
- p->next = line;
- p->next->next = NULL;
- }
- return line;
- }
- void AdaugaCelulaSTRING(t_stringLine *line, char *value) {
- t_stringCell *cell = (t_stringCell *)malloc(sizeof(t_stringCell));
- cell->value = (char *)malloc(20 * sizeof(char));
- strcpy(cell->value, value);
- cell->next = NULL;
- t_stringCell *p = line->cells;
- if (line->cells == NULL) {
- line->cells = cell;
- cell->next = NULL;
- } else {
- while (p->next != NULL) {
- p = p->next;
- }
- p->next = cell;
- p->next->next = NULL;
- }
- }
- void AfiseazaLinieSTRING(t_stringLine *line) {
- t_stringCell *cell = line->cells;
- while (cell != NULL) {
- printf("%s", cell->value);
- for (unsigned int j = 0; j < 30 - strlen(cell->value) + 1; j++) {
- printf(" ");
- }
- cell = cell->next;
- }
- printf("\n");
- }
- int GasesteIndexColoana(t_table *table, char *name_column) {
- t_column *column = table->columns;
- int index = 0;
- while (column != NULL) {
- index++;
- if (strcmp(name_column, column->name) == 0) {
- return index;
- }
- column = column->next;
- }
- return 0;
- }
- t_intCell *GasesteCelulaINT(t_intLine *line, int index) {
- t_intCell *cell = line->cells;
- int index_cell = 0;
- while (cell != NULL) {
- index_cell++;
- if (index_cell == index) {
- return cell;
- }
- cell = cell->next;
- }
- return NULL;
- }
- t_floatCell *GasesteCelulaFLOAT(t_floatLine *line, int index) {
- t_floatCell *cell = line->cells;
- int index_cell = 0;
- while (cell != NULL) {
- index_cell++;
- if (index_cell == index) {
- return cell;
- }
- cell = cell->next;
- }
- return NULL;
- }
- t_stringCell *GasesteCelulaSTRING(t_stringLine *line, int index) {
- t_stringCell *cell = line->cells;
- int index_cell = 0;
- while (cell != NULL) {
- index_cell++;
- if (index_cell == index) {
- return cell;
- }
- cell = cell->next;
- }
- return NULL;
- }
- int VerificareConditieINT(t_intCell *cell, char *relation, char *value) {
- int int_value = atoi(value);
- if (strcmp(relation, "==") == 0) {
- if (int_value == cell->value) {
- return 1;
- }
- }
- if (strcmp(relation, "<=") == 0) {
- if (cell->value <= int_value) {
- return 1;
- }
- }
- if (strcmp(relation, ">=") == 0) {
- if (cell->value >= int_value) {
- return 1;
- }
- }
- if (strcmp(relation, "<") == 0) {
- if (cell->value < int_value) {
- return 1;
- }
- }
- if (strcmp(relation, ">") == 0) {
- if (cell->value > int_value) {
- return 1;
- }
- }
- if (strcmp(relation, "!=") == 0) {
- if (cell->value != int_value) {
- return 1;
- }
- }
- return 0;
- }
- float VerificareConditieFLOAT(t_floatCell *cell, char *relation, char *value) {
- float float_value = atof(value);
- if (strcmp(relation, "==") == 0) {
- if (float_value == cell->value) {
- return 1;
- }
- }
- if (strcmp(relation, "<=") == 0) {
- if (cell->value <= float_value) {
- return 1;
- }
- }
- if (strcmp(relation, ">=") == 0) {
- if (cell->value >= float_value) {
- return 1;
- }
- }
- if (strcmp(relation, "<") == 0) {
- if (cell->value < float_value) {
- return 1;
- }
- }
- if (strcmp(relation, ">") == 0) {
- if (cell->value > float_value) {
- return 1;
- }
- }
- if (strcmp(relation, "!=") == 0) {
- if (cell->value != float_value) {
- return 1;
- }
- }
- return 0;
- }
- int VerificareConditieSTRING(t_stringCell *cell, char *relation, char *value) {
- if (strcmp(relation, "==") == 0) {
- if (strcmp(cell->value, value) == 0) {
- return 1;
- }
- }
- if (strcmp(relation, "!=") == 0) {
- if (strcmp(cell->value, value) != 0) {
- return 1;
- }
- }
- if (strcmp(relation, ">") == 0) {
- if (strcmp(cell->value, value) > 0) {
- return 1;
- }
- }
- if (strcmp(relation, "<") == 0) {
- if (strcmp(cell->value, value) < 0) {
- return 1;
- }
- }
- if (strcmp(relation, ">=") == 0) {
- if (strcmp(cell->value, value) >= 0) {
- return 1;
- }
- }
- if (strcmp(relation, "<=") == 0) {
- if (strcmp(cell->value, value) <= 0) {
- return 1;
- }
- }
- return 0;
- }
- void Verificare(t_table *table, char *name_column, char *relation,
- char *value) {
- int index;
- if (table->type == INT) {
- index = GasesteIndexColoana(table, name_column);
- t_intLine *line = table->lines;
- t_intCell *cell;
- while (line != NULL) {
- cell = GasesteCelulaINT(line, index);
- if (VerificareConditieINT(cell, relation, value) == 1) {
- AfiseazaLinieINT(line);
- }
- line = line->next;
- }
- }
- if (table->type == FLOAT) {
- index = GasesteIndexColoana(table, name_column);
- t_floatLine *line = table->lines;
- t_floatCell *cell;
- while (line != NULL) {
- cell = GasesteCelulaFLOAT(line, index);
- if (VerificareConditieFLOAT(cell, relation, value) == 1) {
- AfiseazaLinieFLOAT(line);
- }
- line = line->next;
- }
- }
- if (table->type == STRING) {
- index = GasesteIndexColoana(table, name_column);
- t_stringLine *line = table->lines;
- t_stringCell *cell;
- while (line != NULL) {
- cell = GasesteCelulaSTRING(line, index);
- if (VerificareConditieSTRING(cell, relation, value) == 1) {
- AfiseazaLinieSTRING(line);
- }
- line = line->next;
- }
- }
- }
- void ElibereazaLinieFLOAT(t_floatLine *line) {
- t_floatCell *cell = line->cells;
- t_floatCell *cell_next = cell->next;
- while (cell != NULL && cell_next != NULL) {
- free(cell);
- cell = cell_next;
- cell_next = cell_next->next;
- }
- free(cell);
- line->cells = NULL;
- }
- void ElibereazaLinieSTRING(t_stringLine *line) {
- t_stringCell *cell = line->cells;
- t_stringCell *cell_next = cell->next;
- while (cell != NULL && cell_next != NULL) {
- free(cell->value);
- free(cell);
- cell = cell_next;
- cell_next = cell_next->next;
- }
- free(cell->value);
- free(cell);
- line->cells = NULL;
- }
- void ElibereazaLinieINT(t_intLine *line) {
- t_intCell *cell = line->cells;
- t_intCell *cell_next = cell->next;
- while (cell != NULL && cell_next != NULL) {
- free(cell);
- cell = cell_next;
- cell_next = cell_next->next;
- }
- free(cell);
- line->cells = NULL;
- }
- void EliminareLinieINT(t_table *table, int index_line) {
- if (index_line < 1) {
- return;
- }
- t_intLine *prev = NULL;
- t_intLine *line = table->lines;
- t_intLine *lineToBeDeleted = NULL;
- int index = 1;
- if (index_line == 1) {
- prev = NULL;
- lineToBeDeleted = line;
- line = lineToBeDeleted->next;
- table->lines = lineToBeDeleted->next;
- ElibereazaLinieINT(lineToBeDeleted);
- free(lineToBeDeleted);
- } else {
- while (line != NULL && index != index_line) {
- index++;
- prev = line;
- line = line->next;
- }
- lineToBeDeleted = line;
- line = lineToBeDeleted->next;
- ElibereazaLinieINT(lineToBeDeleted);
- free(lineToBeDeleted);
- prev->next = line;
- }
- }
- void EliminareLinieFLOAT(t_table *table, int index_line) {
- if (index_line < 1) {
- return;
- }
- t_floatLine *prev = NULL;
- t_floatLine *line = table->lines;
- t_floatLine *lineToBeDeleted = NULL;
- int index = 1;
- if (index_line == 1) {
- prev = NULL;
- lineToBeDeleted = line;
- line = lineToBeDeleted->next;
- table->lines = line;
- ElibereazaLinieFLOAT(lineToBeDeleted);
- free(lineToBeDeleted);
- } else {
- while (line != NULL && index != index_line) {
- index++;
- prev = line;
- line = line->next;
- }
- lineToBeDeleted = line;
- line = lineToBeDeleted->next;
- ElibereazaLinieFLOAT(lineToBeDeleted);
- free(lineToBeDeleted);
- prev->next = line;
- }
- }
- void EliminareLinieSTRING(t_table *table, int index_line) {
- if (index_line < 1) {
- return;
- }
- t_stringLine *prev = NULL;
- t_stringLine *line = table->lines;
- t_stringLine *lineToBeDeleted = NULL;
- int index = 1;
- if (index_line == 1) {
- prev = NULL;
- lineToBeDeleted = line;
- line = lineToBeDeleted->next;
- table->lines = lineToBeDeleted->next;
- ElibereazaLinieSTRING(lineToBeDeleted);
- free(lineToBeDeleted);
- } else {
- while (line != NULL && index != index_line) {
- index++;
- prev = line;
- line = line->next;
- }
- lineToBeDeleted = line;
- line = lineToBeDeleted->next;
- ElibereazaLinieSTRING(lineToBeDeleted);
- free(lineToBeDeleted);
- prev->next = line;
- }
- }
- void VerificareEliminare(t_table *table, char *name_column, char *relation,
- char *value) {
- int index;
- int index_line = 0;
- index = GasesteIndexColoana(table, name_column);
- if (table->type == INT) {
- t_intLine *line = table->lines;
- t_intCell *cell;
- while (line != NULL) {
- index_line++;
- cell = GasesteCelulaINT(line, index);
- if (VerificareConditieINT(cell, relation, value) == 1) {
- line = line->next;
- EliminareLinieINT(table, index_line);
- index_line = index_line - 1;
- } else {
- line = line->next;
- }
- }
- }
- if (table->type == FLOAT) {
- t_floatLine *line = table->lines;
- t_floatCell *cell;
- while (line != NULL) {
- index_line++;
- cell = GasesteCelulaFLOAT(line, index);
- if (VerificareConditieFLOAT(cell, relation, value) == 1) {
- line = line->next;
- EliminareLinieFLOAT(table, index_line);
- index_line = index_line - 1;
- } else {
- line = line->next;
- }
- }
- }
- if (table->type == STRING) {
- t_stringLine *line = table->lines;
- t_stringCell *cell;
- while (line != NULL) {
- index_line++;
- cell = GasesteCelulaSTRING(line, index);
- if (VerificareConditieSTRING(cell, relation, value) == 1) {
- line = line->next;
- EliminareLinieSTRING(table, index_line);
- index_line = index_line - 1;
- } else {
- line = line->next;
- }
- }
- }
- }
- void AfisareColoane(t_table *table) {
- printf("TABLE: %s\n", table->name);
- int count = 0;
- t_column *column = table->columns;
- while (column != NULL) {
- printf("%s", column->name);
- for (unsigned int i = 0; i < 30 - strlen(column->name) + 1; i++) {
- printf(" ");
- }
- count++;
- column = column->next;
- }
- printf("\n");
- int i = 0;
- while (i < count) {
- printf("------------------------------ ");
- i++;
- }
- printf("\n");
- }
- void AfisareTabel(t_table *table) {
- AfisareColoane(table);
- if (table == NULL) {
- return;
- }
- if (table->type == INT) {
- int count_lines = 0;
- t_intLine *line = table->lines;
- while (line != NULL) {
- count_lines++;
- AfiseazaLinieINT(line);
- line = line->next;
- }
- }
- if (table->type == FLOAT) {
- int count_lines = 0;
- t_floatLine *line = table->lines;
- while (line != NULL) {
- count_lines++;
- AfiseazaLinieFLOAT(line);
- line = line->next;
- }
- }
- if (table->type == STRING) {
- int count_lines = 0;
- t_stringLine *line = table->lines;
- while (line != NULL) {
- count_lines++;
- AfiseazaLinieSTRING(line);
- line = line->next;
- }
- }
- printf("\n");
- }
- void AfisareBazaDeDate(t_db *database) {
- printf("DATABASE: ");
- printf("%s\n\n", database->name);
- t_table *p = database->tables;
- while (p != NULL) {
- AfisareTabel(p);
- p = p->next;
- }
- }
- int VerificaExistentaColoana(t_table *table, char *name_column) {
- t_column *column = table->columns;
- int found = 0;
- while (column != NULL) {
- if (strcmp(column->name, name_column) == 0) {
- found = 1;
- }
- column = column->next;
- }
- return found;
- }
- void EliberareLinii(t_table *table) {
- if (table->type == INT) {
- t_intLine *line = table->lines;
- t_intLine *lineToBeDeleted;
- while (line != NULL) {
- lineToBeDeleted = line;
- line = lineToBeDeleted->next;
- ElibereazaLinieINT(lineToBeDeleted);
- free(lineToBeDeleted);
- }
- table->lines = NULL;
- }
- if (table->type == FLOAT) {
- t_floatLine *line = table->lines;
- t_floatLine *lineToBeDeleted;
- while (line != NULL) {
- lineToBeDeleted = line;
- line = lineToBeDeleted->next;
- ElibereazaLinieFLOAT(lineToBeDeleted);
- free(lineToBeDeleted);
- }
- table->lines = NULL;
- }
- if (table->type == STRING) {
- t_stringLine *line = table->lines;
- t_stringLine *lineToBeDeleted;
- while (line != NULL) {
- lineToBeDeleted = line;
- line = lineToBeDeleted->next;
- ElibereazaLinieSTRING(lineToBeDeleted);
- free(lineToBeDeleted);
- }
- table->lines = NULL;
- }
- }
- void EliberareColoane(t_table *table) {
- t_column *column = table->columns;
- t_column *column_next = column->next;
- while (column != NULL && column_next != NULL) {
- free(column);
- column = column_next;
- column_next = column_next->next;
- }
- free(column);
- table->columns = NULL;
- }
- void StergeTabel(t_db *database, char *name_table) {
- t_table *table = database->tables;
- t_table *prev = NULL;
- t_table *tableToBeDeleted = NULL;
- if (database->tables == NULL) {
- return;
- }
- if (strcmp(name_table, database->tables->name) == 0) {
- table = database->tables;
- database->tables = database->tables->next;
- EliberareColoane(table);
- EliberareLinii(table);
- return;
- }
- while (table != NULL) {
- if (strcmp(name_table, table->name) == 0) {
- tableToBeDeleted = table;
- table = tableToBeDeleted->next;
- EliberareColoane(tableToBeDeleted);
- EliberareLinii(tableToBeDeleted);
- free(tableToBeDeleted->lines);
- prev->next = table;
- return;
- }
- prev = table;
- table = table->next;
- }
- }
- void EliberareBazaDeDate(t_db *database) {
- t_table *table = database->tables;
- t_table *tableToBeDeleted = NULL;
- while (table != NULL) {
- tableToBeDeleted = table;
- table = tableToBeDeleted->next;
- StergeTabel(database, tableToBeDeleted->name);
- free(tableToBeDeleted);
- }
- free(database);
- }
- int main() {
- char c = '"';
- char *input = calloc(300, sizeof(char));
- char *name = calloc(30, sizeof(char));
- char *command = calloc(30, sizeof(char));
- char *dataType = calloc(30, sizeof(char));
- char *column = calloc(100, sizeof(char));
- t_db *database;
- char *token;
- t_table *table;
- while (1) {
- fgets(input, 200, stdin);
- strtok(input, "\n");
- token = strtok(input, " ");
- strcpy(command, token);
- command[strlen(command)] = '\0';
- token = strtok(NULL, " ");
- if (token != NULL) {
- strcpy(name, token);
- name[strlen(name)] = '\0';
- }
- if (strcmp(command, "INIT_DB") == 0) {
- database = InitializareBazaDeDate(name);
- } else if (strcmp(command, "CREATE") == 0) {
- token = strtok(NULL, " ");
- strcpy(dataType, token);
- t_table *table_found = GasesteTabel(database, name);
- if (table_found == NULL) {
- if (strcmp(dataType, "INT") == 0) {
- size_t type = INT;
- table = AdaugareTabel(database, name, type);
- } else if (strcmp(dataType, "FLOAT") == 0) {
- size_t type = FLOAT;
- table = AdaugareTabel(database, name, type);
- } else if (strcmp(dataType, "STRING") == 0) {
- size_t type = STRING;
- table = AdaugareTabel(database, name, type);
- } else {
- printf("Unknown data type: %c%s%c\n", c, dataType, c);
- }
- token = strtok(NULL, " ");
- while (token != NULL) {
- strcpy(column, token);
- AdaugareColoana(table, column);
- token = strtok(NULL, " ");
- }
- } else {
- printf("Table %c%s%c already exists.", c, name, c);
- printf("\n");
- }
- } else if (strcmp(command, "ADD") == 0) {
- t_table *table_found;
- table_found = GasesteTabel(database, name);
- token = strtok(NULL, " ");
- if (table_found != NULL) {
- if (table_found->type == STRING) {
- t_stringLine *line;
- line = AdaugaLinieSTRING(table_found);
- while (token != NULL) {
- char *cell = token;
- cell[strlen(cell)] = '\0';
- AdaugaCelulaSTRING(line, cell);
- token = strtok(NULL, " ");
- }
- }
- if (table_found->type == INT) {
- t_intLine *line;
- line = AdaugaLinieINT(table_found);
- while (token != NULL) {
- int cell = atoi(token);
- AdaugaCelulaInt(line, cell);
- token = strtok(NULL, " ");
- }
- }
- if (table_found->type == FLOAT) {
- t_floatLine *line;
- line = AdaugaLinieFLOAT(table_found);
- while (token != NULL) {
- float cell = atof(token);
- AdaugaCelulaFLOAT(line, cell);
- token = strtok(NULL, " ");
- }
- }
- } else {
- printf("Table %c%s%c not found in database.\n", c, name, c);
- }
- } else if (strcmp(command, "SEARCH") == 0) {
- token = strtok(NULL, " ");
- char name_column[20];
- strcpy(name_column, token);
- token = strtok(NULL, " ");
- char relation[20];
- strcpy(relation, token);
- token = strtok(NULL, " ");
- char value[20];
- strcpy(value, token);
- int found;
- t_table *table_found = GasesteTabel(database, name);
- if (table_found != NULL) {
- found = VerificaExistentaColoana(table_found, name_column);
- if (found == 1) {
- AfisareColoane(table_found);
- Verificare(table_found, name_column, relation, value);
- printf("\n");
- } else {
- printf("Table %c%s%c does not contain column %c%s%c.\n", c,
- table_found->name, c, c, name_column, c);
- }
- } else {
- printf("Table %c%s%c not found in database.\n", c, name, c);
- }
- } else if (strcmp(command, "DELETE") == 0) {
- t_table *table_found = GasesteTabel(database, name);
- if (table_found == NULL) {
- printf("Table %c%s%c not found in database.\n", c, name, c);
- } else {
- token = strtok(NULL, " ");
- if (token == NULL) {
- StergeTabel(database, name);
- free(table_found);
- } else {
- char name_column[20];
- strcpy(name_column, token);
- token = strtok(NULL, " ");
- char relation[20];
- strcpy(relation, token);
- token = strtok(NULL, " ");
- char value[20];
- strcpy(value, token);
- int found =
- VerificaExistentaColoana(table_found, name_column);
- if (found == 0) {
- printf("Table %c%s%c does not contain column %c%s%c.\n",
- c, table_found->name, c, c, name_column, c);
- } else {
- VerificareEliminare(table_found, name_column, relation,
- value);
- }
- }
- }
- } else if (strcmp(command, "CLEAR") == 0) {
- t_table *table_found = GasesteTabel(database, name);
- EliberareLinii(table_found);
- } else if (strcmp(command, "PRINT") == 0) {
- t_table *table_found;
- table_found = GasesteTabel(database, name);
- if (table_found == NULL) {
- printf("Table %c%s%c not found in database.\n", c, name, c);
- } else {
- AfisareTabel(table_found);
- }
- } else if (strcmp(command, "PRINT_DB") == 0) {
- AfisareBazaDeDate(database);
- } else if (strcmp(command, "DELETE_DB") == 0) {
- EliberareBazaDeDate(database);
- break;
- } else {
- printf("Unknown command: %c%s%c\n", c, command, c);
- }
- }
- free(input);
- free(name);
- free(command);
- free(dataType);
- free(column);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement