C More Info added Database Generally a user should instantia
C++
More Info added:
Database:
Generally, a user should instantiate a single database object and work from there. The database object should include commands to do the following:
You should allow a constructor function with no arguments (other constructors may be included if desired). This creates an “empty” database.
An add table function that takes a single table object and a name, and adds that table to the database.
A drop function that takes a table name and deletes it from the database
* A save function that takes a file name and saves the database to that file (save format is entirely up to you).
* A load function that takes in a file name and loads in a database from that file. Any existing database should be deleted.
* A merge function that allows another database to be merged into that one.
* A copy function that copies an entire database.
A list table function that returns a list of all table names in the database
A get tables function that returns all the tables in the database.
A query function (described below, separately)
* A delete command. The structure of the delete command should follow that of the query command, except that instead of returning a table, the table in the FROM portion has the appropriate tuples deleted.
* An update/modify command. The modify command should take a table name, a WHERE clause (as in the query command), and a SET clause. The SET clause should be able to reference attributes of the table, and set them to values that are either a constant or (in the case integers and floats) a computed function on attribute values (from that table). The operations +, - , *, and / should be supported. Note that there are multiple ways to handle a returned list of names or the tables. For instance, you might use an array, or a vector, or you might return a set or some other container.
Implement the following code:
Note: Don\'t use map, please vectors only.
[Code]
#include \"database.h\"
Database::Database(){
}
Database::Database(vector Tables){
}
//Add a table to the database
//Ownership of the table is permanently transferred to the database, and it will be destroyed when the database is destroyed.
//Throws an \\a InvalidOperationError if \\a name already exists in the database
//param name what to call the table in the database
void Database::add_Table(string table_name, Table tab){
}
//Remove a table from the database.
//The table is destroyed with \'delete\' when this function is called.
//Throws a \\a TableDoesNotExistError if \\a name does not exist in the database.
//param name which table to remove from the database
//returns A pointer to the Table, which can now be destroyed
void Database::drop_Table(string table_name){
}
/*
Save the database to a file,
Throws an \\a IOError on failture.
\\param filename the output fie
*/
void Database::save(string filename){
}
/*
Load a database from a file, this will clear any existing records
Throws an \\a IOError on failture.
\\param filename the input file
*/
void Database::load(string filename){
}
/*
Merge another database into this one.
Tables in this database are overwritten by tables in \\a database.
\\param database The database that you want to merge into this one.
*/
void Database::merge(const Database& database){
}
/**
Make a copy of this database
\ eturns a one-for-one copy / clone of this database
**/
Database Database::copy(){
}
//Returns a list of all the tables currently in the database
vector Database::list_Tables(){
}
//Returns the table named *table_Name* in the database.
//Throws a \\a TableDoesNotExistError if \\a table_Name does not exist in the database
vector
* Database::getTables(){
}
/****
//Perform a query on the database
//Throws a \\a TableDoesNotExistError if \\a from does not exist.
//Throws a \\a QuerySyntaxError if \\a select or \\a where have a syntax error.
\\param select which columns to include in the returned Table
\\param from which table to query from
\\param where the conditions for the query from
\ eturn A pointer to Table with all of the records that match the query
**/
Table Database::query(string select, string from, string where){
}
/******
Delete all records that match the query
Throws a \\a TableDoesNotExistError if \\a from does not exist.
Throws a \\a QuerySyntaxError if \\a where has a syntax error.
\\param from which table to query from
\\param where the conditions for the query to match
******/
void Database::delete_From(string from, string where){
}
//********
Must modify the records in table.
Throws a \\a TableDoesNotExistError if \\a table does not exist
Throws a \\a QuerySyntaxError if \\a where or \\a set have a syntax error
\\param table_name name of the table to update records in
\\param where a SQL where clause to find records in the table
\\param set a SQL set clause
*****************//
void Database::update(string table_Name, string where, string set){
}
[/EndCode]
Solution
#include \"database.h\"
Database::Database(){
}
Database::Database(vector Tables){
}
//Add a table to the database
//Ownership of the table is permanently transferred to the database, and it will be destroyed when the database is destroyed.
//Throws an \\a InvalidOperationError if \\a name already exists in the database
//param name what to call the table in the database
void Database::add_Table(string table_name, Table tab){
}
//Remove a table from the database.
//The table is destroyed with \'delete\' when this function is called.
//Throws a \\a TableDoesNotExistError if \\a name does not exist in the database.
//param name which table to remove from the database
//returns A pointer to the Table, which can now be destroyed
void Database::drop_Table(string table_name){
}
/*
Save the database to a file,
Throws an \\a IOError on failture.
\\param filename the output fie
*/
void Database::save(string filename){
}
/*
Load a database from a file, this will clear any existing records
Throws an \\a IOError on failture.
\\param filename the input file
*/
void Database::load(string filename){
}
/*
Merge another database into this one.
Tables in this database are overwritten by tables in \\a database.
\\param database The database that you want to merge into this one.
*/
void Database::merge(const Database& database){
}
/**
Make a copy of this database
\ eturns a one-for-one copy / clone of this database
**/
Database Database::copy(){
}
//Returns a list of all the tables currently in the database
vector Database::list_Tables(){
}
//Returns the table named *table_Name* in the database.
//Throws a \\a TableDoesNotExistError if \\a table_Name does not exist in the database
vector
* Database::getTables(){
}
/****
//Perform a query on the database
//Throws a \\a TableDoesNotExistError if \\a from does not exist.
//Throws a \\a QuerySyntaxError if \\a select or \\a where have a syntax error.
\\param select which columns to include in the returned Table
\\param from which table to query from
\\param where the conditions for the query from
\ eturn A pointer to Table with all of the records that match the query
**/
Table Database::query(string select, string from, string where){
}
/******
Delete all records that match the query
Throws a \\a TableDoesNotExistError if \\a from does not exist.
Throws a \\a QuerySyntaxError if \\a where has a syntax error.
\\param from which table to query from
\\param where the conditions for the query to match
******/
void Database::delete_From(string from, string where){
}
//********
Must modify the records in table.
Throws a \\a TableDoesNotExistError if \\a table does not exist
Throws a \\a QuerySyntaxError if \\a where or \\a set have a syntax error
\\param table_name name of the table to update records in
\\param where a SQL where clause to find records in the table
\\param set a SQL set clause
*****************//
void Database::update(string table_Name, string where, string set){
}
[/EndCode]





