Files
CS-Classes/CS457/hw4
2025-06-17 14:42:22 -07:00
..
2025-06-17 14:42:22 -07:00
2025-06-17 14:42:22 -07:00
2025-06-17 14:42:22 -07:00
2025-06-17 14:42:22 -07:00
2025-06-17 14:42:22 -07:00
2025-06-17 14:42:22 -07:00
2025-06-17 14:42:22 -07:00
2025-06-17 14:42:22 -07:00
2025-06-17 14:42:22 -07:00
2025-06-17 14:42:22 -07:00
2025-06-17 14:42:22 -07:00
2025-06-17 14:42:22 -07:00
2025-06-17 14:42:22 -07:00
2025-06-17 14:42:22 -07:00
2025-06-17 14:42:22 -07:00

Please ensure that g++ is running version 11. This is needed for the filesystem library

To start program either:
./SQLExecutable for manual command input (please do not insert comments into the command line)
or
./SQLExecutable <filename> to run a test script

This program parses an SQL file and executes the commands in the file. 
Functionaliy includes Creating, deleting, and using databases
Aswell as Creating, deleting, Select(printing), and Altering tables.

The program organizes multiple databases by creating a new folder in the file path that
the executable is runned at. Then it gives that folder a inputed name and the program is able
to access any of the databases through a static directory file path that works by taking the initalized path + the database name.

The Program organizes multiple tables through a file path that is updated by the use database
function. Then the a table is created with the inputed name and can be accessed through the 
updated filepath + the tables name.

The program also stores tuples by first tokenizing the inputed data. Then the data is sent to an insert function that reads the 
file for the header(skipping it) and then appends the data to a new row for each insertion command.

The program does inner joins by taking the inputed data and tokenizing it to the inner join funcion. Then it reads the file and inserts the data into 
a vector of vectors. Then it iterates through the vector of vectors to find the row and column that matches the inputed data. Then it merges the data from both 
vector of vectors of the table data that match the condition. Then the new vector of vectors is printed to the screen.

The program does left joins by taking the inputed data and tokenizing it to the left join funcion. Then it reads the file and inserts the data into
a vector of vectors for each table. Then it iterates through the vector of vectors to find the row and column that matches the inputed data. Then it finds matches 
in both tables and merges the data from both vector of vectors of the table data that match the condition. If a match is not found then the column is inserted to the vector as null. 
Then the new vector of vectors is printed to the screen.

NEW FEATURES: 

The program now supports multuple terminals through table locking. It does this by parsing the begin transaction command which locks the file. 
The program then changes booleans transaction to true if the file is locked. If the file is locked then the program will not allow any other commands to be executed and aborts the transaction with both booleans transaction and abortTransaction set to true. The file unlocks after a commit command is approperiatly executed.

The program also now supports commits which saves the inputed user commands after begin transaction into a vector. If commit is detected and the conditions are correct the data is then read and inputed back into the parser to be executed. If false the program will not do anything and will follow the logic from the transaction function.




Database:

CreateDatabase:
Creates a directory to reperesent the database by making a new folder in the inital file path

DropDatabase:
Removes the database after directory is found in program and deletes the folder.

USEDATABASE:
Updates file path to selected database for table functions to read. 

Tables:

Create Table:
creates a table based on the inputed file path. Then creates a .csv file with the inputed table name

Drop Table: 
Deletes table inputed to program by taking inputed file path + the table's name. Then deleteing that target. 

Select Table:
Reads from a .csv that conatains table data and prints output from the table. Iterates by detecting a comma. 

Append Table:
Appends to a .csv file that contains table data. By reading inputed file, copying it to a temp file, then appending the new data to the temp file. Then deleting the original file and renaming the temp file to the original file name.

insert into table: 
Takes inputed tuples and tokenizes it. Then sends it to the insert function that reads the file for the header and then appends the data to a new row for each insertion command.

delete from table: 
Takes inputed data and tokenizes it. Then sends it to the delete function that calls the query function to find the row and column that matches the inputed data. Then it deletes using variables created by the query function to delete the data in the row that matches the inputed data.

update table: 
Takes inputed data and tokenizes it. Then sends it to the update function that reads the file calls the query function to find the row and column that matches the inputed data. Then it updates using variables created by the query function to update the data in the row and column that matches the inputed data.

select table:
If select table != * then it calls the query function to find the row and column that matches the inputed data. Then it reads the file and prints the data in the row and column that matches the inputed data.

query function: 
Takes inputed data and tokenizes it. Then it reads the file and inserts the data into a vector of vectors. Then it iterates through the vector of vectors to find the row and column that matches the inputed data. Then it returns the row and column that matches the inputed data as variables.

Inner Join:
Takes inputed data and tokenizes it to the inner join funcion. Then it reads the file and inserts the data into a vector of vectors. Then it iterates through the vector of vectors to find the row and column that matches the inputed data. Then it merges the data from both vector of vectors of the table data that match the condition. Then the new vector of vectors is printed to the screen.

Left Join:
Takes inputed data and tokenizes it to the left join funcion. Then it reads the file and inserts the data into a vector of vectors for each table. Then it iterates through the vector of vectors to find the row and column that matches the inputed data. Then it finds matches in both tables and merges the data from both vector of vectors of the table data that match the condition. If a match is not found then the column is inserted to the vector as null. Then the new vector of vectors is printed to the screen.

NEW FEATURES: 

begin Transaction:
works by taking the file path updated by datamanager functions such as update and insert. if the file path of the table file has a _locked at the endand then aborting if it's found.
if no locked file exists then one is created with the file path of the table file. when begin transaction is started it pushes commands from the user into a vector of strings that is later used by the commit command to execute the commands in the vector. 

commit:
works through an if condition testing the transaction boolean in the parser that either saves inputed user commands into a vector. If commit is detected and the conditions are correct the data is then read and inputed back into the parser to be executed. 

delete Locked: 
called by the commit command. It deletes any file that has a _locked at the end of the file path. The file path is updated by the functions from datamanager class.