Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
typedef struct Database
int id;
char name;
struct Table tables;
Database;
typedef struct Table
int id;
char name;
struct Database db;
struct Columns columnsCOLUMNS;
Table;
typedef struct Column
int id;
char name;
struct Table table;
int data;
Column;
int main
Database db; database
Table table; table
Column col col col; 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.
dbDatabase mallocsizeofDatabase;
tableTable mallocsizeofTable;
colColumn mallocsizeofColumn;
colColumn mallocsizeofColumn;
colColumn mallocsizeofColumn;
let\'s set and connect those objects together
First the DB
dbid ;
strcpydbname, \"Employeesdatabase\";
dbtables table;
Next, the table
tabledb db;
tableid ;
strcpytablename, \"EmployeesYOEsalary\";
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:
tablecolumns Column mallocsizeofColumn COLUMNS;
tablecolumns col;
tablecolumns col;
tablecolumns col;
Finally, we set the columns
coltable table;
coltable table;
coltable table;
colid ;
colid ;
colid ;
strcpycolname, \"employeeid;
strcpycolname, \"yearsofexperience\";
strcpycolname, \"salary\";
now we take insert requests from the user.
char in;
putsEnter command:\";
getsin;
It should be in the form:
INSERT INTO TABLE VALUES
char command;
int colVal, colVal, colVal;
strcpycommand strtokin;
for int i; i && strcpycommandi strtokNULLNULL; i;
strcpycommandi strtokNULL;
sscanfinsss command command command;
if strcmpcommand \"INSERT\" &&
strcmpcommand \"INTO\" &&
strcmpcommand \"TABLE\"
putsUnknown command! Exiting...\";
return ;
check the table name and the keyword VALUE
putstablename;
putscommand;
if strcmpcommand tablename
putsUnknown table name! Exiting...\";
return ;
finally read the integers and store them.
sscanfcommandd &coldata;
sscanfcommandd &coldata;
sscanfcommandd &coldata;
printfSuccessfully stored row: d d d
coldata coldata coldata;
return ;
ve it regard this code:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started