Question: Modify the given database management system code. Extend its functionality to support creation of tables given the following query: CREATE TABLE more than two columns

Modify the given database management system code. Extend its functionality to support creation of tables given the following query:
CREATE TABLE
more than two columns may exist.
you can rearrange the given code into functions for readability.
Then, modify the code to support the insertion into any of the created tables.
sol#include
#include
#include
#define COLUMNS 3
typedef struct Database
{
int id;
char name[20];
struct Table * tables;
}Database;
typedef struct Table
{
int id;
char name[20];
struct Database * db;
struct Columns * columns[COLUMNS];
} Table;
typedef struct Column
{
int id;
char name[20];
struct Table * table;
int data[100];
} Column;
int main()
{
Database * db0; //1 database
Table * table0; //1 table
Column * col0,* col1,* col2; //3 columns: employee ID, years of experience, and salary
// First, we allocate enough space for each object
// Please mention here that every pointer we have is just an address to the allocated memory area.
db0=(Database *)malloc(sizeof(Database));
table0=(Table *)malloc(sizeof(Table));
col0=(Column *)malloc(sizeof(Column));
col1=(Column *)malloc(sizeof(Column));
col2=(Column *)malloc(sizeof(Column));
// let\'s set and connect those objects together
// First the DB
db0->id =0;
strcpy(db0->name, \"Employees_database\");
db0->tables = table0;
// Next, the table
table0->db = db0;
table0->id =0;
strcpy(table0->name, \"Employees_YOE_salary\");
// If we did not specify how many columns we have, we would have needed to allocate enough memory later when we know how many we need. It is done like this:
// table0->columns =(Column*) malloc(sizeof(Column)* COLUMNS);
table0->columns[0]= col0;
table0->columns[1]= col1;
table0->columns[2]= col2;
// Finally, we set the columns
col0->table = table0;
col1->table = table0;
col2->table = table0;
col0->id =0;
col1->id =1;
col2->id =2;
strcpy(col0->name, \"employee_id\");
strcpy(col1->name, \"years_of_experience\");
strcpy(col2->name, \"salary\");
//now, we take insert requests from the user.
char in[100];
puts(\"Enter command:\");
gets(in);
// It should be in the form:
// INSERT INTO TABLE VALUES
char command[10][30];
int col1Val, col2Val, col3Val;
strcpy(command[0], strtok(in,\"\"));
for (int i=1; i<8 && strcpy(command[i], strtok(NULL,\"\"))!=NULL; ++i);
// strcpy(command[i], strtok(NULL,\"\"));
// sscanf(in,\"%s%s%s\", command[0], command[1], command[2]);
if (strcmp(command[0], \"INSERT\") &&
strcmp(command[1], \"INTO\") &&
strcmp(command[2], \"TABLE\"))
{
puts(\"Unknown command! Exiting...\");
return 0;
}
//check the table name and the keyword VALUE
puts(table0->name);
puts(command[3]);
if (strcmp(command[3], table0->name))
{
puts(\"Unknown table name! Exiting...\");
return 0;
}
//finally, read the integers and store them.
sscanf(command[5],\"%d\", &col0->data[0]);
sscanf(command[6],\"%d\", &col1->data[0]);
sscanf(command[7],\"%d\", &col2->data[0]);
printf(\"Successfully stored row: %d %d %d.
\", col0->data[0], col1->data[0], col2->data[0]);
return 0;
}ve it regard this code:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!