├── .github
└── FUNDING.yml
├── Contribution.txt
├── LICENSE
├── OurDB_Database
├── .idea
│ ├── OurDB_Database.iml
│ ├── misc.xml
│ ├── modules.xml
│ ├── vcs.xml
│ └── workspace.xml
├── CMakeLists.txt
├── Databases
│ ├── dbn
│ │ └── default.Ourdb
│ ├── fame
│ │ ├── default.Ourdb
│ │ └── tbl.Ourdb
│ └── ghd
│ │ └── deafault.Ourdb
├── Errors
│ └── error_variable.h
├── External_Libraries
│ ├── TextTable.h
│ └── json.hpp
├── OurDB_Database.h
├── Parth_module
│ ├── create_database
│ │ └── create_database.h
│ ├── create_table
│ │ └── create_table.h
│ ├── delete_database
│ │ └── delete_database.h
│ ├── rename_columns
│ │ └── rename_columns.h
│ ├── return_object
│ │ └── p_to_stringTable.h
│ ├── select_database
│ │ └── select_database.h
│ └── update_into_table
│ │ ├── ForUpdate.h
│ │ └── update_into_table.h
├── Success_Messages
│ └── Success_Msg.h
├── console.cpp
├── global_functions
│ ├── AfterWhereProcess.h
│ ├── SyntaxCheckerForResultString.h
│ ├── decryption.h
│ ├── encryption.h
│ ├── globalFunctionForSelectQuery.h
│ ├── global_function.h
│ └── keywords_checker.h
├── mihir_module
│ ├── add_column
│ │ └── add_column.h
│ ├── column_list
│ │ └── column_list.h
│ ├── current_database
│ │ └── current_database.h
│ ├── database_list
│ │ └── database_list.h
│ ├── foreign_key
│ │ └── add_foreign_key.h
│ ├── insert_into_table
│ │ └── insert_into_table.h
│ ├── primary_key
│ │ └── add_primary_key.h
│ ├── rename_database
│ │ └── rename_database.h
│ ├── rename_table
│ │ └── rename_table.h
│ ├── return_object
│ │ └── m_to_json.h
│ └── table_list
│ │ └── table_list.h
├── parth_errors
│ └── parth_errors.h
├── query_process.h
├── select_module
│ ├── mihir_select_module
│ │ ├── SelectFuncForAll.h
│ │ └── SelectFuncForAllWithAdditionalFunc.h
│ ├── parth_select_module
│ │ ├── SelectFuncForColWithAdditionalFunc.h
│ │ └── SelectFuncForCols.h
│ ├── select_module.h
│ └── zeel_select_module
│ │ ├── SelectFuncForAllWithWhere.h
│ │ ├── SelectFuncForAllWithWhereWithAdditionalFunc.h
│ │ ├── SelectFuncForColsWithWhere.h
│ │ └── SelectFuncForColsWithWhereWithAdditionalFunc.h
├── syntax.txt
├── task.txt
├── variables
│ └── query_variables.h
└── zeel_module
│ ├── delete_column_query
│ ├── delete_column_query.h
│ └── delete_column_query_logic.h
│ ├── delete_query
│ ├── delete_query.h
│ └── delete_query_logic.h
│ ├── delete_table
│ └── delete_table.h
│ └── return_object
│ └── z_to_map.h
├── OurDB_Database_Documentation.pdf
├── README.md
└── images
├── PrtScr capture_101.jpg
├── PrtScr capture_102.jpg
├── PrtScr capture_104.jpg
├── PrtScr capture_105.jpg
├── PrtScr capture_106.jpg
├── PrtScr capture_107.jpg
├── PrtScr capture_108.jpg
├── PrtScr capture_109.jpg
├── PrtScr capture_110.jpg
├── PrtScr capture_111.jpg
├── PrtScr capture_112.jpg
├── PrtScr capture_113.jpg
├── PrtScr capture_114.jpg
├── PrtScr capture_115.jpg
├── PrtScr capture_116.jpg
├── PrtScr capture_117.jpg
├── PrtScr capture_118.jpg
├── PrtScr capture_119.jpg
├── logo-mini.png
└── logo.png
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github:zeelsheladiya
4 | patreon: # Replace with a single Patreon username
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
13 |
--------------------------------------------------------------------------------
/Contribution.txt:
--------------------------------------------------------------------------------
1 |
2 | -> when you update something or add new module make sure you out comment so others can understand you update or new module
3 |
4 | -> when you make new syntax make sure to add all syntax varibles in variables/query_variables.h.
5 |
6 | -> all new query should be dynamic.
7 |
8 | -> do not commit direct any new update first contact with author than they will test your module and they will commit.
9 |
10 | -> make sure all error and success message have to registered in Errors/error_variable.h and success_message/Success_Msg.h respectivly.
11 |
12 | -> do not make static query.
13 |
14 | -> function should be in globle_functions folder.
15 |
16 | -> select related query should be in select_module folder.
17 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 zeel sheladiya
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/OurDB_Database/.idea/OurDB_Database.iml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/OurDB_Database/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/OurDB_Database/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/OurDB_Database/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/OurDB_Database/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 | 1618558459662
66 |
67 |
68 | 1618558459662
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/OurDB_Database/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.15)
2 | project(OurDB_Database)
3 |
4 | set(CMAKE_CXX_STANDARD 20)
5 |
6 | add_executable(OurDB_Database console.cpp Success_Messages/Success_Msg.h)
--------------------------------------------------------------------------------
/OurDB_Database/Databases/dbn/default.Ourdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeelsheladiya/OurDB-Database/c828a80e2c4fcf08e12b21d94513e693378ec992/OurDB_Database/Databases/dbn/default.Ourdb
--------------------------------------------------------------------------------
/OurDB_Database/Databases/fame/default.Ourdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeelsheladiya/OurDB-Database/c828a80e2c4fcf08e12b21d94513e693378ec992/OurDB_Database/Databases/fame/default.Ourdb
--------------------------------------------------------------------------------
/OurDB_Database/Databases/fame/tbl.Ourdb:
--------------------------------------------------------------------------------
1 | {"records":{"col_index":[1,2,3],"col_names":["id","pass","pa"],"last_col_index":3,"total_cols":3},"table_data":[{"1":"t","2":"- ))*","3":"+0))"},{"1":"w","2":"- )*","3":"+0))"}]}
--------------------------------------------------------------------------------
/OurDB_Database/Databases/ghd/deafault.Ourdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeelsheladiya/OurDB-Database/c828a80e2c4fcf08e12b21d94513e693378ec992/OurDB_Database/Databases/ghd/deafault.Ourdb
--------------------------------------------------------------------------------
/OurDB_Database/Errors/error_variable.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by zeel,mihir,parth,pranav on 13/04/2021.
3 | //
4 |
5 | #ifndef OURDB_DATABASE_ERROR_VARIABLE_H
6 | #define OURDB_DATABASE_ERROR_VARIABLE_H
7 |
8 | //first word of syntax is wrong
9 | inline std::string querySyntaxError[2] = {"Error index := 1 , Error := your initial query syntax is wrong","1"};
10 |
11 | //secend word of syntax is wrong
12 | inline std::string syntaxOfCreateError[2] = {"Error index := 2 , Error := invalid word in create query syntax","2"};
13 |
14 | //extra words in create query syntax
15 | inline std::string inSufficientWordInCreateSyntax[2] = {"Error index := 3 , Error := there are insufficient words and invalid world in create syntax","3"};
16 |
17 | //extra words in delete query syntax
18 | inline std::string ExtraWordInDeleteSyntax[2] = {"Error index := 4 , Error := there are some extra words and invalid world in delete syntax","4"};
19 |
20 | // second word of syntax is wrong
21 | inline std::string syntaxOfDeleteError[2] = {"Error index := 5 , Error := invalid word in create query syntax","5"};
22 |
23 | //error occur due to input wrong name type by user
24 | inline std::string syntaxOfCreateDatabase[2] = {"Error index := 6 , Error := invalid name for creating database ","6"};
25 |
26 | //error occur during creating database directory
27 | inline std::string errorCreatingDatabase[2] = {"Error index := 7 , Error := database creation failed. ","7"};
28 |
29 | //error occur when database can not be deleted
30 | inline std::string errorDeletingDatabase[2] = {"Error index := 8 , Error := unable to delete database. ","8"};
31 |
32 | //error occur when database name is not valid
33 | inline std::string errorSpecialchaDatabase[2] = {"Error index := 9 , Error := special character not allowed in database name. ","9"};
34 |
35 | //error occur when file (table) can not be created in database folder
36 | inline std::string errorCreatingFile[2] = {"Error index := 10 , Error := unable to create file ","10"};
37 |
38 | //error occur id that named database is already exist
39 | inline std::string errorDatatbaseExists[2] = {"Error index := 11 , Error := database already exist ","11"};
40 |
41 | // error selecting database
42 | inline std::string errorSelectingDatabase[2] = {"Error index := 12 , Error := error selecting database ","12"};
43 |
44 | // extrawords in database syntax..
45 | inline std::string ExtraWordInselectDatabaseSyntax[2] = {"Error index := 13 , Error := there are some extra words and invalid world in select database syntax","13"};
46 |
47 | // error when database is not there
48 | inline std::string errDatabaseNotFound[2] = {"Error index := 14 , Error := database not found","14"};
49 |
50 | // when database already and you try to create with same name
51 | inline std::string databaseAlreadySelected[2] = {"Error index := 15 , Error := database already selected","15"};
52 |
53 | // it is unknown error
54 | inline std::string SysUnRecognizedError[2] = {"Error index := 16 , Error := system unrecognized error","16"};
55 |
56 | // error in syntax of rename database
57 | inline std::string syntaxErrRenameDatabase[2] = {"Error index := 17 ,Error := syntax of rename database is wrong.. \n\t Syntax : rename database new_db_name ","17"};
58 |
59 | // giving wrong name to database
60 | inline std::string errrenameDatabase[2] = {"Error index := 18 ,Error := Renaming database error! Same name database might exist!! ","18"};
61 |
62 | // when someone rename the database he new to select the database for further process..
63 | inline std::string SelectTheDatabase[2] = {"Error index := 19 ,Error := First select the database ","19"};
64 |
65 | // when you try to rename the old database with same new name database.
66 | inline std::string sameNameDatabaseErr[2]= {"Error index := 20 ,Error := Same name of old and new database.." ,"20"};
67 |
68 | // error in syntax of show all database
69 | inline std::string syntaxErrShowList[2] = {"Error index := 21 ,Error := Syntax of displaying database/table list is wrong..\n \tSyntax : show/view/display all database/table ","21"};
70 |
71 | //extra words in delete query syntax
72 | inline std::string errExtraWordInShowListSyntax[2] = {"Error index := 22 , Error := there are some extra words or invalid word in show database/table/column list syntax","22"};
73 |
74 | //if no database exist and the list is empty
75 | inline std::string errDatabaseListIsEmpty[2] = {"Error index := 23 ,Error := No database exists!! Please create a database and then try again..","23"};
76 |
77 | // when user tries to ask what is current selected database but no database has been selected
78 | inline std::string errDatabaseNotSelected[2] = {"Error index := 24 ,Error := No database selected!! Please select a database first..","24"};
79 |
80 | // error in syntax of current database
81 | inline std::string syntaxErrCurrentDatabase[2] = {"Error index := 25 ,Error := Syntax of current database is wrong..\n \tSyntax : current/present database ","25"};
82 |
83 | // error in special character in table while creating
84 | inline std::string errorSpecialchaTable[2] = {"Error index := 26 , Error := special character not allowed in table name. ","26"};
85 |
86 | // table creation failed
87 | inline std::string syntaxOfCreateTable[2] = {"Error index := 27 , Error := syntax of creating table is wrong. ","27"};
88 |
89 | // if table already exists then it will gives error..
90 | inline std::string errTableAlreadyExist[2] = {"Error index := 28 , Error := table already exists.", "28"};
91 |
92 | //database name cant start with the numeric value
93 | inline std::string errFirstLetterNumeric[2] = {"Error index := 29 , Error := Name cannot start with numeric value! Only alphabets allowed.","29"};
94 |
95 | //if no table exist in current database and the list is empty
96 | inline std::string errTableListIsEmpty[2] = {"Error index := 30 ,Error := No tables exists in current database!! Please create a table or select another database..","30"};
97 |
98 | //extra word in rename table/database syntax
99 | inline std::string ExtraWordInRenameSyntax[2] = {"Error index := 31 ,Error := There is/are some extra words in rename query..","31"};
100 |
101 | // error in syntax of rename Table
102 | inline std::string syntaxErrRenameTable[2] = {"Error index := 32 ,Error := syntax of rename table is wrong.. \n\t Syntax : rename table old_name new_name ","32"};
103 |
104 | // not allowing to rename the default.Ourdb file
105 | inline std::string errRenamingDefaultTable[2] = {"Error index := 33 ,Error := You cannot rename default table!!","33"};
106 |
107 | // when you try to rename the old table with same new name table.
108 | inline std::string sameNameTableErr[2]= {"Error index := 34 ,Error := Same name of old and new table.." ,"34"};
109 |
110 | // Table renaming unknown error
111 | inline std::string errRenameTable[2] = {"Error index := 35 ,Error := Error renaming table! Same name table might exist already!! ","35"};
112 |
113 | // When user tries to rename table that doesnt exist in the database
114 | inline std::string errNoSuchTableExist[2] = {"Error index := 36 ,Error := No such table exists in the database!! ","36"};
115 |
116 | //error occur when table can not be deleted
117 | inline std::string errorDeletingTable[2] = {"Error index := 37 , Error := unable to delete table. ","37"};
118 |
119 | // not allowing to delete the default.Ourdb file
120 | inline std::string errDeletingDefaultTable[2] = {"Error index := 38 ,Error := You cannot delete default table!!","38"};
121 |
122 | // error while naming columns win table
123 | inline std::string errNamingColumn[2] = {"Error index := 39 ,Error := Invalid name for column!!","39"};
124 |
125 | //insufficient words in insert query syntax
126 | inline std::string inSufficientWordIninsertSyntax[2] = {"Error index := 40 , Error := there are insufficient words and invalid world in insert syntax","40"};
127 |
128 | // wrong syntax of insert query
129 | inline std::string ErrSyntaxInsertQuery[2] = {"Error index := 41 , Error := Wrong syntax of insert data query!\n\t Correct syntax : insert into @ '' '' ...","41"};
130 |
131 | // invalid no of data while inserting i.e. data not matching no. of columns
132 | inline std::string ErrDataNotEqualToNoOfCols[2] = {"Error index := 42 , Error := No. of data entered does not equals to no. of columns in the table!","42"};
133 |
134 | // error if column data is insufficient or data irregularity
135 | inline std::string ErrImproperData[2] = {"Error index := 43 , Error := Improper or No data insertion!!","43"};
136 |
137 | // error if two columns have same name (while creating the table and specifying col names)
138 | inline std::string ErrSameColName[2] = {"Error index := 44 , Error := Column name invalid! Another column with same name already exists!!","44"};
139 |
140 | // occurs error in syntax of delete query...
141 | inline std::string ErrdeleteQuerySyntax[2] = {"Error index := 45 , Error := error in syntax of delete query.. delete @ where (=/!) (&/|) (=/!) ","45"};
142 |
143 | // column(key) and value are not same..
144 | inline std::string ErrInsufficientColumnValue[2] = {"Error index := 46 ,Error := insufficient condition with column","46"};
145 |
146 | // conditions are not in order..
147 | inline std::string ErrorConditionNotInAppropriateOrder[2] = {"Error index : 47 , Error := conditions are not in appropriate order","47"};
148 |
149 | // missing some operator in the query std::string..
150 | inline std::string ErrorDontHaveEnoughOperator[2] = {"Error index : 48 , Error := value don't have sufficient oprator","48"};
151 |
152 | // column does not exists...
153 | inline std::string ErrColumnDoesNotExists[2] = {"Error index : 49, Error := column/s does not exist in the table","49"};
154 |
155 | // insufficient word in update query suntax
156 | inline std::string insufficientWordInUpdateSyntax[2] = {"Error index := 50 , Error := there are insufficient words and invalid world in update syntax","50"};
157 |
158 | // error in update query syntx
159 | inline std::string ErrUpdateQuerySyntax[2] = {"Error index := 51 , Error := Error in update query syntax .. update @ set/put '' where (=/|) ","51"};
160 |
161 | // table does not exists error
162 | inline std::string tableDoesNotExist[2] = {"Error index := 52 , Error := table does not exists ","52"};
163 |
164 | //insufficient words in update query syntax
165 | inline std::string inSufficientWordInUpdateSyntax[2] = {"Error index := 53 , Error := there are insufficient words or invalid world in update syntax","53"};
166 |
167 | // when user tries to insert/retrieve data to/from default table
168 | inline std::string ErrDataManipulationInDefault[2] = {"Error index : 54, Error := Cannot add or retrieve data from default table!!","54"};
169 |
170 | // error where keyword is not at its right place as per syntax
171 | inline std::string ErrWhereKeyword[2] = {"Error index : 55 Error := where keyword is not at its right place as per syntax","55"};
172 |
173 | //error that you cant delete anything from default table
174 | inline std::string ErrDeleteDefult[2] = {"Error index : 56 Error := can not perform any delete operation on default table","56"};
175 |
176 | //table does not have data to delete
177 | inline std::string ErrNoDataForDeleteInTable[2] = {"Error index : 57 := table does not have any data to perform delete operation","57"};
178 |
179 | //table does not have data to delete
180 | inline std::string ErrNoDataForUpdateInTable[2] = {"Error index : 58 := table does not have any data to perform update operation","58"};
181 |
182 | //column does not have right syntax
183 | inline std::string ErrorDeleteColumnSyntax[2] = {"Error index : 59 := syntax error in delete column query \n Syntax := delete column/col from @ ","59"};
184 |
185 | //column does not exist
186 | inline std::string ErrorColumnNotExist[2] = {"Error index : 60 := column does not exist into table ","60"};
187 |
188 | // error if adding two new columns having same name (while adding new cols)
189 | inline std::string ErrSelectSameColName[2] = {"Error index := 61 , Error := Same column name error! Selecting same column name more than once!!!","61"};
190 |
191 | // error if only one column is remaining in table while deleting column
192 | inline std::string ErrorOnlyOneColumnLeft[2] = {"Error index := 62 , only one column left into the table. So you should delete table instead of column","62"};
193 |
194 | // wrong syntax of add column query
195 | inline std::string ErrSyntaxAddColumn[2] = {"Error index := 63 , Error := Wrong syntax of add column query!\n\t Correct syntax : add col/column into @ ...","63"};
196 |
197 | // error Can not use < and > with string value
198 | inline std::string ErrorShouldBeInt[2] = {"Error index := 64 , Error := Can not use < , > , <= , >= with std::string value ","64"};
199 |
200 | //error column name cant be of any banned keywords
201 | inline std::string ErrorBannedKeywords[2] = {"Error index := 65 , Error := Can not use banned keywords in column name!!","65"};
202 |
203 | //column which you are trying to update is not available
204 | inline std::string ErrorDoestNotExistInSetCondition[2] = {"Error index := 68 , Error := Column which you are trying to update does not exist ","68"};
205 |
206 | // syntax of select query is wrong
207 | inline std::string ErrSyntaxInSelectQuery[2] = {"Error index := 69 , Error := Syntax of select query is wrong ","69"} ;
208 |
209 | //column does not match with the table columns
210 | inline std::string ErrorColumnDoesNotMatchFromTable[2] = {"Error index := 70 , Error := column doest not match with the table column ","70"};
211 |
212 | // @ symbol shouldn't be here wrong syntax
213 | inline std::string ErrAtSymbol[2] = {"Error index := 71 , Error := @ symbol shouldn't be here wrong syntax ","71"};
214 |
215 | //updation query syntax is not proper..
216 | inline std::string ErrInUpdateSyntaxForAt[2] = {"Error index := 72 , Error := wrong updation query ...\nselect */ .... @ Coniditinal_symbol where condition ","72"};
217 |
218 | //no data found in table
219 | inline std::string ErrNoDataFoundInTable[2] = {"Error index := 73 , Error := No data Found Into table " , "73"};
220 |
221 | //syntax error in displaying all columns from a table
222 | inline std::string syntaxErrShowCols[2] = {"Error index := 74 , Error := Wrong syntax of displaying columns from a table \n\t Correct Syntax : show/display/view all col/column @ " , "74"};
223 |
224 | // not allowing to update the default.Ourdb file
225 | inline std::string errUpdatingDefaultTable[2] = {"Error index := 75 ,Error := You cannot update default table!!","75"};
226 |
227 | //no column found in table
228 | inline std::string ErrNoColsFoundInTable[2] = {"Error index := 76 , Error := No column Found Into table " , "76"};
229 |
230 | //primary key constraint violated
231 | inline std::string ErrPrimaryKeyConstraintViolation[2] = {"Error index := 77 , Error := Violation of primary key constraint!!" , "77"};
232 |
233 | //does not allows to set primary key to column that has duplicate data
234 | inline std::string ErrPrimaryKeyDuplData[2] = {"Error index := 78 , Error := Cannot make this column as primary key because it contains duplicate data!!" , "78"};
235 |
236 | //syntax error in add primary key
237 | inline std::string ErrSyntaxPrimaryKey[2] = {"Error index := 79 , Error := Wrong syntax for adding primary key \n\t Correct Syntax : set $ @ !!" , "79"};
238 |
239 | //does not allows to set primary key to column that has duplicate data
240 | inline std::string ErrPrimaryKeyNullData[2] = {"Error index := 80 , Error := Cannot make this column as primary key because it contains NULL data!! " , "80"};
241 |
242 | //if you try to set the primary key to a column that is already a primary key
243 | inline std::string ErrAlreadyAPrimaryKey[2] = {"Error index := 81 , Error := This column is already the primary key!!" , "81"};
244 |
245 | //if you try to set foreign key to a table that does not have any primary key
246 | inline std::string ErrNoPrimaryKeyFound[2] = {"Error index := 82 , Error := No primary key found! Please add a primary key first!!" , "82"};
247 |
248 | //if you try to set foreign key to a table that does not have any primary key
249 | inline std::string ErrForeignKeyConstraintViolated[2] = {"Error index := 83 , Error := Violation of foreign key constraint!!" , "83"};
250 |
251 | //syntax error in add foreign key
252 | inline std::string ErrSyntaxForeignKey[2] = {"Error index := 84 , Error := Wrong syntax for adding foreign key \n\t Correct Syntax : set # @ $ !!" , "84"};
253 |
254 | //syntax error in add foreign key
255 | inline std::string ErrCantAddForeignKey[2] = {"Error index := 85 , Error := Cannot make this column a foreign key as it violates foreign key constraints!!" , "85"};
256 |
257 | //if you try to set foreign key to a column that is already a foreign key
258 | inline std::string ErrAlreadyAForeignKey[2] = {"Error index := 85 , Error := Cannot make this column a foreign key as it violates foreign key constraints!!" , "85"};
259 |
260 |
261 | #endif //OURDB_DATABASE_ERROR_VARIABLE_H
262 |
--------------------------------------------------------------------------------
/OurDB_Database/External_Libraries/TextTable.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by zeel on 03/07/2021.
3 | //
4 |
5 | #pragma once
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | #ifdef TEXTTABLE_ENCODE_MULTIBYTE_STRINGS
14 | #include
15 | #ifndef TEXTTABLE_USE_EN_US_UTF8
16 | #define TEXTTABLE_USE_EN_US_UTF8
17 | #endif
18 | #endif
19 |
20 | class TextTable {
21 |
22 | public:
23 | enum class Alignment { LEFT, RIGHT };
24 | typedef std::vector< std::string > Row;
25 | TextTable() :
26 | _horizontal( '-' ),
27 | _vertical( '|' ),
28 | _corner( '+' ),
29 | _has_ruler(true)
30 | {}
31 |
32 | TextTable( char horizontal, char vertical, char corner ) :
33 | _horizontal( horizontal ),
34 | _vertical( vertical ),
35 | _corner( corner ),
36 | _has_ruler(true)
37 | {}
38 |
39 | explicit TextTable( char vertical ) :
40 | _horizontal( '\0' ),
41 | _vertical( vertical ),
42 | _corner( '\0' ),
43 | _has_ruler( false )
44 | {}
45 |
46 | void setAlignment( unsigned i, Alignment alignment )
47 | {
48 | _alignment[ i ] = alignment;
49 | }
50 |
51 | Alignment alignment( unsigned i ) const
52 | { return _alignment[ i ]; }
53 |
54 | char vertical() const
55 | { return _vertical; }
56 |
57 | char horizontal() const
58 | { return _horizontal; }
59 |
60 | void add( std::string const & content )
61 | {
62 | _current.push_back( content );
63 | }
64 |
65 | void endOfRow()
66 | {
67 | _rows.push_back( _current );
68 | _current.assign( 0, "" );
69 | }
70 |
71 | template
72 | void addRow( Iterator begin, Iterator end )
73 | {
74 | for( auto i = begin; i != end; ++i ) {
75 | add( * i );
76 | }
77 | endOfRow();
78 | }
79 |
80 | template
81 | void addRow( Container const & container )
82 | {
83 | addRow( container.begin(), container.end() );
84 | }
85 |
86 | std::vector< Row > const & rows() const
87 | {
88 | return _rows;
89 | }
90 |
91 | void setup() const
92 | {
93 | determineWidths();
94 | setupAlignment();
95 | }
96 |
97 | std::string ruler() const
98 | {
99 | std::string result;
100 | result += _corner;
101 | for( auto width = _width.begin(); width != _width.end(); ++ width ) {
102 | result += repeat( * width, _horizontal );
103 | result += _corner;
104 | }
105 |
106 | return result;
107 | }
108 |
109 | int width( unsigned i ) const
110 | { return _width[ i ]; }
111 |
112 | bool has_ruler() const { return _has_ruler;}
113 |
114 | int correctDistance(std::string string_to_correct) const
115 | {
116 | return static_cast(string_to_correct.size()) - static_cast(glyphLength(string_to_correct));
117 | };
118 |
119 | private:
120 | const char _horizontal;
121 | const char _vertical;
122 | const char _corner;
123 | const bool _has_ruler;
124 | Row _current;
125 | std::vector< Row > _rows;
126 | std::vector< unsigned > mutable _width;
127 | std::vector< unsigned > mutable _utf8width;
128 | std::map< unsigned, Alignment > mutable _alignment;
129 |
130 | static std::string repeat( unsigned times, char c )
131 | {
132 | std::string result;
133 | for( ; times > 0; -- times )
134 | result += c;
135 |
136 | return result;
137 | }
138 |
139 | unsigned columns() const
140 | {
141 | return _rows[ 0 ].size();
142 | }
143 |
144 | unsigned glyphLength( std::string s ) const
145 | {
146 | unsigned int _byteLength = s.length();
147 | #ifdef TEXTTABLE_ENCODE_MULTIBYTE_STRINGS
148 | #ifdef TEXTTABLE_USE_EN_US_UTF8
149 | std::setlocale(LC_ALL, "en_US.utf8");
150 | #else
151 | #error You need to specify the encoding if the TextTable library uses multybyte string encoding!
152 | #endif
153 | unsigned int u = 0;
154 | const char *c_str = s.c_str();
155 | unsigned _glyphLength = 0;
156 | while(u < _byteLength)
157 | {
158 | u += std::mblen(&c_str[u], _byteLength - u);
159 | _glyphLength += 1;
160 | }
161 | return _glyphLength;
162 | #else
163 | return _byteLength;
164 | #endif
165 | }
166 |
167 | void determineWidths() const
168 | {
169 | _width.assign( columns(), 0 );
170 | _utf8width.assign( columns(), 0 );
171 | for ( auto rowIterator = _rows.begin(); rowIterator != _rows.end(); ++ rowIterator ) {
172 | Row const & row = * rowIterator;
173 | for ( unsigned i = 0; i < row.size(); ++i ) {
174 | _width[ i ] = _width[ i ] > glyphLength(row[ i ]) ? _width[ i ] : glyphLength(row[ i ]);
175 | }
176 | }
177 | }
178 |
179 | void setupAlignment() const
180 | {
181 | for ( unsigned i = 0; i < columns(); ++i ) {
182 | if ( _alignment.find( i ) == _alignment.end() ) {
183 | _alignment[ i ] = Alignment::LEFT;
184 | }
185 | }
186 | }
187 | };
188 |
189 | inline std::ostream & operator<<( std::ostream & stream, TextTable const & table )
190 | {
191 | table.setup();
192 | if (table.has_ruler()) {
193 | stream << table.ruler() << "\n";
194 | }
195 | for ( auto rowIterator = table.rows().begin(); rowIterator != table.rows().end(); ++ rowIterator ) {
196 | TextTable::Row const & row = * rowIterator;
197 | stream << table.vertical();
198 | for ( unsigned i = 0; i < row.size(); ++i ) {
199 | auto alignment = table.alignment( i ) == TextTable::Alignment::LEFT ? std::left : std::right;
200 | // std::setw( width ) works as follows: a string which goes in the stream with byte length (!) l is filled with n spaces so that l+n=width.
201 | // For a utf8 encoded string the glyph length g might be smaller than l. We need n spaces so that g+n=width which is equivalent to g+n+l-l=width ==> l+n = width+l-g
202 | // l-g (that means glyph length minus byte length) has to be added to the width argument.
203 | // l-g is computed by correctDistance.
204 | stream << std::setw( table.width( i ) + table.correctDistance(row[ i ])) << alignment << row[ i ];
205 | stream << table.vertical();
206 | }
207 | stream << "\n";
208 | if (table.has_ruler()) {
209 | stream << table.ruler() << "\n";
210 | }
211 | }
212 |
213 | return stream;
214 | }
215 |
--------------------------------------------------------------------------------
/OurDB_Database/OurDB_Database.h:
--------------------------------------------------------------------------------
1 | //
2 | // this is ourdb database which is created by zeel sheladiya , mihir surati , parth dabheliya , pranav patel
3 | //
4 |
5 |
6 | //#include
7 | //#include
8 | //#include
9 | //#include
10 | #include "query_process.h"
11 | //#include
12 | #include "global_functions/global_function.h"
13 | #include "External_Libraries/json.hpp"
14 | #include "mihir_module/return_object/m_to_json.h"
15 | #include "Parth_module/return_object/p_to_stringTable.h"
16 | #include "zeel_module/return_object/z_to_map.h"
17 | #include "Errors/error_variable.h"
18 |
19 | using ourdb = nlohmann::json;
20 |
21 |
22 |
23 | #ifndef OURDB_DATABASE_OURDB_DATABASE_H
24 | #define OURDB_DATABASE_OURDB_DATABASE_H
25 |
26 | std::string run_query(std::string query)
27 | {
28 | //query should not be null
29 | if(query.empty())
30 | {
31 | return querySyntaxError[0];
32 | }
33 |
34 | replace(query.begin(),query.end(),'\n',' ');
35 |
36 | //trim space from string
37 | trim(query);
38 |
39 | // replace multi space into one space
40 | std::string::iterator query_string_of_space = unique(query.begin(), query.end(), BothAreSpaces);
41 | query.erase(query_string_of_space,query.end());
42 |
43 | //convert whole string into lowercase
44 | transform(query.begin(),query.end(),query.begin(), [](unsigned char c){ return std::tolower(c); });
45 |
46 | //declaration of variable for string array
47 | std::vector query_string;
48 |
49 | //split using char
50 | split(query, split_char, query_string);
51 |
52 | //assign size of string to global string variable
53 | query_size = query_string.size();
54 |
55 | //returning string value from query_process function
56 | return query_process(query_string);
57 | //return query;
58 |
59 | }
60 |
61 | ourdb To_Json(std::string result)
62 | {
63 | return m_to_json(result);
64 | }
65 |
66 | std::string To_StringTable(std::string result)
67 | {
68 | return p_to_stringTable(result);
69 | }
70 |
71 | std::map> To_Map(std::string result)
72 | {
73 | return z_to_map(result);
74 | }
75 |
76 | #endif //OURDB_DATABASE_OURDB_DATABASE_H
--------------------------------------------------------------------------------
/OurDB_Database/Parth_module/create_database/create_database.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by zeel,mihir,parth,pranav on 13/04/2021.
3 | //
4 |
5 | //#include
6 | //#include
7 | //#include
8 | //#include
9 | //#include
10 | //#include
11 | #include "../../global_functions/global_function.h"
12 |
13 | //using namespace std;
14 |
15 | #ifndef OURDB_DATABASE_CREATE_DATABASE_H
16 | #define OURDB_DATABASE_CREATE_DATABASE_H
17 | /*
18 | string createDatabase(string databaseName)
19 | {
20 | firstLetterStore = databaseName.front(); //store the first character of string
21 | lastLetterStore = databaseName.back(); // stores last character of string
22 | if(firstLetterStore >= 97 && firstLetterStore <= 122) // check whether the first character is between "a to z" or not
23 | {
24 | if((lastLetterStore >= 32 && lastLetterStore <= 47) ||(lastLetterStore >= 58 && lastLetterStore <= 92) || (lastLetterStore >= 123 && lastLetterStore <= 126)) // check for special character
25 | {
26 |
27 | return errorSpecialchaDatabase[0]; // defined in Errors/error_variable.h
28 |
29 | }else{
30 | databaseName = strPath[0] + databaseName; //strpath[0]="path" defined in variables/query_variables.h
31 | if(!(filesystem::exists(databaseName.c_str()))) // checks for database that has already been created
32 | {
33 |
34 | if(mkdir(databaseName.c_str()) ==-1) // cretae directory, mkdir function defined in direct.h header file
35 | {
36 |
37 | return errorCreatingDatabase[0]; // defined in Errors/error_variable.h
38 |
39 | } else{
40 | databaseName = databaseName +
41 | "/default.Ourdb"; //it takes file path from above and add the path to file
42 | FileTable(databaseName); //creats file called default.Ourdb from above defined function
43 |
44 | return SuccessCreatingDatabaseMsg[0]; // Success_Messages/Success_Msg.h
45 | }
46 |
47 | }else{
48 | return errorDatatbaseExists[0];// defined in error.h
49 | }
50 | }
51 | }
52 | else if(!(firstLetterStore >= 97 && firstLetterStore <= 122)) // check if character is not between "a to z"...
53 | {
54 | return syntaxOfCreateDatabase[0]; // defined in Errors/error_variable.h
55 | }
56 |
57 | }
58 | */
59 | std::string createDatabase(std::string databaseName)
60 | {
61 | validate = validation(databaseName,errorSpecialchaDatabase[0],errFirstLetterNumeric[0]);
62 | if( validate == "true_true")
63 | {
64 | std::regex l("[a-zA-Z0-9_]{0,}"); // alphabet numeric and _ allowed betwwen letters..
65 | if ( regex_match(databaseName, l) ) {
66 | databaseName = strPath[0] + databaseName; //strpath[0]="path" defined in variables/query_variables.h
67 | if (!(std::filesystem::exists(databaseName.c_str()))) // checks for database that has already been created
68 | {
69 |
70 | if (mkdir(databaseName.c_str()) ==-1) // cretae directory, mkdir function defined in direct.h header file
71 | {
72 |
73 | return errorCreatingDatabase[0]; // defined in Errors/error_variable.h
74 |
75 | } else {
76 | databaseName = databaseName +
77 | "/default.Ourdb"; //it takes file path from above and add the path to file
78 | filetbReturnValue = FileTable(databaseName); //creats file called default.Ourdb from above defined function
79 |
80 | //return filetbReturnValue;
81 | return SuccessCreatingDatabaseMsg[0]; // Success_Messages/Success_Msg.h
82 | }
83 |
84 | } else {
85 | return errorDatatbaseExists[0];// defined in error.h
86 | }
87 | }
88 | else
89 | {
90 | return errorSpecialchaDatabase[0];
91 | }
92 | }else if(validate != "true_true")
93 | {
94 | return validate;
95 | }
96 | }
97 | #endif //OURDB_DATABASE_CREATE_DATABASE_H
98 |
--------------------------------------------------------------------------------
/OurDB_Database/Parth_module/create_table/create_table.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by dabhe on 05-May-21.
3 | //
4 | //#include
5 | //#include
6 | //#include
7 | //#include
8 | #include "../../variables/query_variables.h"
9 | #include "../../global_functions/global_function.h"
10 | #include "../../External_Libraries/json.hpp"
11 | #include "../../global_functions/encryption.h"
12 | #include "../../global_functions/decryption.h"
13 | #include "../../global_functions/keywords_checker.h"
14 |
15 | //using namespace std;
16 | using ourdb = nlohmann::json;
17 |
18 | #ifndef OURDB_DATABASE_CREATE_TABLE_H
19 | #define OURDB_DATABASE_CREATE_TABLE_H
20 |
21 | std::string createTable(std::string tablename ,std::vector a)
22 | {
23 | int count = 0;
24 | int samecol = 0; //var to check if there is a col with same name as another col
25 | int keycheck = 0;
26 |
27 | if(!(databaseSelectGlobal.empty()))
28 | {
29 | validate = validation(tablename,errorSpecialchaTable[0],errFirstLetterNumeric[0]);
30 | // variable for storing string value which is returned by validate function
31 | if ( validate == "true_true")
32 | {
33 | std::regex b("[a-zA-Z0-9_]{0,}"); // alphabet numeric and _ allowed betwwen letters..
34 | if ( regex_match(tablename, b) )
35 | {
36 | for(int i=0;i
7 | //#include
8 | //#include
9 | #include "../../variables/query_variables.h"
10 | //using namespace std;
11 |
12 | #ifndef OURDB_DATABASE_DELETE_DATABASE_H
13 | #define OURDB_DATABASE_DELETE_DATABASE_H
14 |
15 | /*
16 | string deleteDatabase(string databaseName)
17 | {
18 |
19 | firstLetterStore = databaseName.front(); //store the first character of string
20 | lastLetterStore = databaseName.back(); // stores last character of string
21 |
22 |
23 | if(firstLetterStore >= 97 && firstLetterStore <= 122) // check whether the first character is between "a to z" or not
24 | {
25 | if((lastLetterStore >= 32 && lastLetterStore <= 47) ||(lastLetterStore >= 58 && lastLetterStore <= 92) || (lastLetterStore >= 123 && lastLetterStore <= 126)) { // check for special character
26 |
27 | return errorSpecialchaDatabase[0]; // defined in Errors/error_variable.h
28 |
29 | }else{
30 |
31 | databaseName = strPath[0] + databaseName; //strpath[0]="path" defined in variables/query_variables.h
32 | if(filesystem::exists(databaseName.c_str())) {
33 | if (!(filesystem::remove_all(databaseName))) //from the filesystem function to remove directory
34 | {
35 |
36 | return errorDeletingDatabase[0]; // errorDeletingDatabase[0] defined in Errors/error_variable.h
37 |
38 | } else {
39 | databaseSelectGlobal = ""; // reset the global variable in ,defined in variables/query_variables.h
40 | databaseSavePath = " "; // reset the databaseSave path...
41 | return SuccessDeletingDatabaseMsg[0]; // SuccessDeletingDatabaseMsg defined in Success_Messages/Success_Msg.h
42 |
43 | }
44 | }
45 | else
46 | {
47 | return errDatabaseListIsEmpty[0];
48 | }
49 | }
50 | }
51 | else if(!(firstLetterStore >= 97 && firstLetterStore <= 122)) // check if character is not between "a to z"...
52 | {
53 | return syntaxOfCreateDatabase[0]; // defined in Errors/error_variable.h
54 | }
55 | }
56 | */
57 |
58 | std::string deleteDatabase(std::string databaseName)
59 | {
60 | validate = validation(databaseName,errorSpecialchaDatabase[0],errFirstLetterNumeric[0]);
61 | if( validate == "true_true")
62 | {
63 | std::regex l("[a-zA-Z0-9_]{0,}"); // alphabet numeric and _ allowed betwwen letters..
64 | if ( regex_match(databaseName, l) ) {
65 | databaseName = strPath[0] + databaseName; //strpath[0]="path" defined in variables/query_variables.h
66 | if(std::filesystem::exists(databaseName.c_str())) {
67 | if (!(std::filesystem::remove_all(databaseName))) //from the filesystem function to remove directory
68 | {
69 | return errorDeletingDatabase[0]; // errorDeletingDatabase[0] defined in Errors/error_variable.h
70 | } else {
71 | databaseSelectGlobal = ""; // reset the global variable in ,defined in variables/query_variables.h
72 | databaseSavePath = " "; // reset the databaseSave path...
73 | return SuccessDeletingDatabaseMsg[0]; // SuccessDeletingDatabaseMsg defined in Success_Messages/Success_Msg.h
74 |
75 | }
76 | }
77 | else
78 | {
79 | return errDatabaseListIsEmpty[0];
80 | }
81 | }
82 | else
83 | {
84 | return errorSpecialchaDatabase[0];
85 | }
86 | }else if(validate != "true_true")
87 | {
88 | return validate;
89 | }
90 | }
91 | #endif //OURDB_DATABASE_DELETE_DATABASE_H
92 |
--------------------------------------------------------------------------------
/OurDB_Database/Parth_module/rename_columns/rename_columns.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by dabhe on 10-Jun-21.
3 | //
4 | //#include
5 | //#include
6 | //#include
7 | //#include
8 | //#include
9 | //#include
10 | #include "../../variables/query_variables.h"
11 | #include "../../global_functions/global_function.h"
12 | #include "../../External_Libraries/json.hpp"
13 | #include "../../global_functions/encryption.h"
14 | #include "../../global_functions/decryption.h"
15 | #include "../../global_functions/keywords_checker.h"
16 |
17 | //using namespace std;
18 | using ourdb = nlohmann::json;
19 | #ifndef OURDB_DATABASE_UPDATE_COLUMNS_H
20 | #define OURDB_DATABASE_UPDATE_COLUMNS_H
21 |
22 | std::string rename_column(std::string table_name,std::vectorkey)
23 | {
24 | if(!(databaseSelectGlobal.empty()))
25 | {
26 | int keycheck = 0;
27 |
28 | for(int i=1; i> odb; // fs data into the json object odb
59 | int cunt = 0;
60 | int cuntx = 0; //
61 | for(int i=0;i 0) {
89 | return SuccessInRenamingColumn[0]; // success in renaming column
90 | }else
91 | {
92 | return ErrorInRenameOp[0]; // renaming operation error;
93 | }
94 |
95 | }
96 | else
97 | {
98 | return tableDoesNotExist[0]; // gives error if table does not exists
99 | }
100 | }
101 | else
102 | {
103 |
104 | return errorSpecialchaTable[0]; // error for special character found..
105 | }
106 | }else
107 | {
108 | return validate;
109 | }
110 | }else
111 | {
112 | return SelectTheDatabase[0];
113 | }
114 | }
115 | #endif //OURDB_DATABASE_UPDATE_COLUMNS_H
116 |
--------------------------------------------------------------------------------
/OurDB_Database/Parth_module/return_object/p_to_stringTable.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Micron on 02/07/2021.
3 | //
4 |
5 | #include "../../External_Libraries/TextTable.h"
6 |
7 | #ifndef OURDB_DATABASE_P_TO_STRINGTABLE_H
8 | #define OURDB_DATABASE_P_TO_STRINGTABLE_H
9 |
10 | std::string p_to_stringTable(std::string result)
11 | {
12 | ourdb myobj;
13 | if(SyntaxCheckerForResultString(result))
14 | {
15 | std::vector datastring; // for storing string data in vector
16 | std::regex r1("\n"); // regex for checking new line
17 | filterRegexInstring(result,datastring,r1,-1); // gives vector string which does not match with regex(newline separater)
18 | std::vector coldata; // for storing string column data
19 | std::regex r2(","); // regex for separation with ,
20 | filterRegexInstring(datastring[0],coldata,r2,-1); // gives the vector string with , separated data
21 |
22 | nullRomoverFromVectorString(datastring); // it will remove null value from vector..
23 | nullRomoverFromVectorString(coldata);
24 |
25 | for(int i = 0 ; i < datastring.size() ; i++) // iterate through datastring
26 | {
27 | if(datastring[i].empty()) // it will check whether the element in vector array is empty or not
28 | {
29 | datastring.erase(datastring.begin()+i); // if it is empty then it will erase..
30 | }
31 | }
32 |
33 | std::map> tabledata; //map to store table data
34 |
35 | for(int i=0;i
5 | //#include
6 | //#include
7 | #include "../../variables/query_variables.h"
8 | #include "../../global_functions/global_function.h"
9 | //using namespace std;
10 |
11 | #ifndef OURDB_DATABASE_SELECT_DATABASE_H
12 | #define OURDB_DATABASE_SELECT_DATABASE_H
13 |
14 | // this function helps for validation..
15 |
16 |
17 | std::string selectDatabase(std::string databaseName)
18 | {
19 | validate = validation(databaseName,errorSpecialchaDatabase[0],errFirstLetterNumeric[0]);
20 | if(validate == "true_true")
21 | {
22 | //the validation function calls and if it returns true_true then goes in these block
23 |
24 | dName = databaseName; //stores the databasename to dname variable
25 |
26 | databaseName = strPath[0] + databaseName; // concatnat the databasename with path..
27 |
28 | if (std::filesystem::exists(databaseName.c_str())) // it checks whether directory exist or not
29 | {
30 | if(!(databaseSelectGlobal == dName)) { // check if dummy variable != databaseGlobal then execute these..
31 |
32 | databaseSelectGlobal = dName; // if above condition is right then dummy assigned to databasesSlectGlobal
33 | databaseSavePath = databaseName;
34 | return SuccessDatabaseSelected[0] + dName; //it returns string selected..
35 | }else
36 | {
37 | return databaseAlreadySelected[0]; // it returns error already selected
38 | }
39 |
40 | } else {
41 |
42 | return errDatabaseNotFound[0]; // if database it not there then returns not found..
43 | }
44 |
45 | }
46 | else if(validate!="true_true")
47 | {
48 | return validate; // if validation some how fails this shows.
49 | }
50 | }
51 |
52 |
53 | #endif //OURDB_DATABASE_SELECT_DATABASE_H
54 |
--------------------------------------------------------------------------------
/OurDB_Database/Parth_module/update_into_table/ForUpdate.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by dabhe on 02-Jun-21.
3 | //
4 | //#include
5 | //#include
6 | //#include
7 | #include "../../variables/query_variables.h"
8 | #include "../../Errors/error_variable.h"
9 | #include "../../global_functions/global_function.h"
10 | #include "../../External_Libraries/json.hpp"
11 |
12 | //using namespace std;
13 | using ourdb = nlohmann::json;
14 |
15 | #ifndef OURDB_DATABASE_FORUPDATE_H
16 | #define OURDB_DATABASE_FORUPDATE_H
17 |
18 | void ForUpdate(int index,std::mapset_data,std::string table_name,std::vector strsep3)
19 | {
20 | ourdb odb;
21 | std::fstream fs1(table_name);
22 | fs1 >> odb;
23 | int countl=0;
24 |
25 |
26 | for (auto itr : set_data) { // iterate through map vale in set_data
27 | for (int i = 0; i < odb["records"]["col_names"].size(); i++) //iterate through col_names in json
28 | {
29 | if (to_string(odb["records"]["col_names"][i]) ==
30 | ('"' + itr.first + '"').c_str()) // matches the column in map with the column in json
31 | {
32 |
33 | std::string l = to_string(odb["records"]["col_index"][i]); // takes the value from column index ..
34 | odb["table_data"][index][l] = encryption(
35 | itr.second); // insert the new value in the particular filed..
36 |
37 | }
38 |
39 | }
40 |
41 |
42 | }
43 |
44 | std::ofstream fsm(table_name);
45 | fsm << odb; // print updated value in file from json object.
46 |
47 | }
48 | #endif //OURDB_DATABASE_FORUPDATE_H
49 |
--------------------------------------------------------------------------------
/OurDB_Database/Parth_module/update_into_table/update_into_table.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by dabhe on 02-Jun-21.
3 | //
4 | //#include
5 | //#include
6 | //#include
7 | #include "../../variables/query_variables.h"
8 | #include "../../global_functions/global_function.h"
9 | #include "../../global_functions/AfterWhereProcess.h"
10 | #include "../../External_Libraries/json.hpp"
11 |
12 | //using namespace std;
13 | using ourdb = nlohmann::json;
14 |
15 | #ifndef OURDB_DATABASE_UPDATE_INTO_TABLE_H
16 | #define OURDB_DATABASE_UPDATE_INTO_TABLE_H
17 |
18 | std::string updateTable(std::string table_name,std::map vc,std::string storedStringAfterWhere,std::vectorstrsep3)
19 | {
20 | if(!(databaseSelectGlobal.empty())) // checks whether database is selected or not
21 | {
22 | validate = validation(table_name,errorSpecialchaTable[0],errFirstLetterNumeric[0]); // validates the function
23 |
24 | if(validate == "true_true")
25 | {
26 | std::regex nl("[a-zA-Z0-9_]{0,}"); // alphabet numeric and _ allowed between letters..
27 | if(regex_match(table_name,nl))
28 | {
29 | tbname = "";
30 | tbname = databaseSavePath + "/" + table_name + ".Ourdb"; //saved table path
31 | tname = "";
32 | tname=table_name; // table name
33 | if(std::filesystem::exists(tbname.c_str()))
34 | {
35 | if( table_name == "default") // user can't perform the action in default table
36 | {
37 | return errUpdatingDefaultTable[0];
38 | }else
39 | {
40 | int CounterForCol = 0; // counter for column
41 | ourdb odb; // json object
42 | std::ifstream fs1(tbname);
43 | fs1 >> odb;
44 |
45 | for(auto lkey : vc) // iterate through map
46 | {
47 | for (auto key : odb["records"]["col_names"]) // iterate through col_names in json
48 | {
49 | if(to_string(key) == '"'+lkey.first+'"') // if map value and value in column matches
50 | {
51 | CounterForCol++; // increment the counter
52 | }
53 | }
54 | }
55 |
56 | if(CounterForCol == vc.size()) // i
57 | {
58 | return globalFuncForWhereClouse(storedStringAfterWhere, tbname, vc, 1, strsep3);
59 | }
60 | else
61 | {
62 | return ErrorDoestNotExistInSetCondition[0]; // column doest not exist...
63 | }
64 | }
65 | }
66 | else
67 | {
68 | return tableDoesNotExist[0]; // table does not exist
69 | }
70 |
71 | }
72 | else
73 | {
74 | return errorSpecialchaTable[0]; // error for special character found..
75 | }
76 | }else
77 | {
78 | return validate; // if the error from validate function..
79 | }
80 | }else
81 | {
82 | return SelectTheDatabase[0]; // select database error.
83 | }
84 |
85 | }
86 |
87 | #endif //OURDB_DATABASE_UPDATE_INTO_TABLE_H
88 |
--------------------------------------------------------------------------------
/OurDB_Database/Success_Messages/Success_Msg.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by zeel,mihir,parth,pranav on 17-Apr-21.
3 | //
4 |
5 |
6 | #ifndef OURDB_DATABASE_SUCCESS_MSG_H
7 | #define OURDB_DATABASE_SUCCESS_MSG_H
8 |
9 | //success for creation of database..
10 | inline std::string SuccessCreatingDatabaseMsg[2] = {"Success index := 101 , Success := database Created","101"};
11 |
12 | //success for deletion of database
13 | inline std::string SuccessDeletingDatabaseMsg[2] = {"Success index := 102 , Success := database Deleted","102"};
14 |
15 | //success creation of table...
16 | inline std::string SuccessCreatingFileMsg[2] = {"Success index := 103 , Success := table created","103"};
17 |
18 | // database selected success
19 | inline std::string SuccessDatabaseSelected[2] = {"Success index := 104 , Success := database selected named : ","104"};
20 |
21 | // database rename success
22 | inline std::string SuccessRenamingDatabaseMsg[2] = {"Success index := 105 , Success := database renamed success : ","105"};
23 |
24 | // table rename success
25 | inline std::string SuccessRenamingTableMsg[2] = {"Success index := 106 , Success := Table renamed successfully :) : ","106"};
26 |
27 | // table rename success
28 | inline std::string SuccessDeletingTableMsg[2] = {"Success index := 107 , Success := Table deleted successfully :) : ","107"};
29 |
30 | // data insertion in table success
31 | inline std::string SuccessInsertDataTableMsg[2] = {"Success index := 108 , Success := Data inserted into table successfully :) : ","108"};
32 |
33 | // data update in table success
34 | inline std::string SuccessUpdateDataTableMsg[2] = {"Success index := 109 , Success := Data updated into table successfully :) : ","109"};
35 |
36 | // data delete in table sucess
37 | inline std::string SuccessDeleteDataTableMsg[2] = {"Success index := 110 , Success := Data deleted into table successfully :) : ","110"};
38 |
39 | //table column renmed successfully
40 | inline std::string SuccessAddColumnMsg[2] = {"Success index := 111 , Success := Column/s addded successfully :) : ","111"};
41 |
42 | //table column renmed successfully
43 | inline std::string SuccessInRenamingColumn[2] = {"Success index := 112 , Success := table column renamed successfully :) : ","112"};
44 |
45 | //table column delete successfully
46 | inline std::string SuccessDeleteColumn[2] = {"Success index := 113 , Success := table column deleted successfully :) : ","113"};
47 |
48 | //primary key added successfully
49 | inline std::string SuccessPrimaryKey[2] = {"Success index := 114 , Success := Primary key added successfully :) : ","114"};
50 |
51 | //foreign key added successfully
52 | inline std::string SuccessForeignKey[2] = {"Success index := 115 , Success := Foreign key added successfully :) : ","115"};
53 |
54 | #endif //OURDB_DATABASE_SUCCESS_MSG_H
55 |
--------------------------------------------------------------------------------
/OurDB_Database/console.cpp:
--------------------------------------------------------------------------------
1 | #include "OurDB_Database.h"
2 | #include
3 | #include
4 | #include "variables/query_variables.h"
5 | #include "global_functions/global_function.h"
6 | #include "global_functions/SyntaxCheckerForResultString.h"
7 |
8 | using namespace std;
9 |
10 | template
11 | bool selectChecker(const Element & s ,const Container & s1)
12 | {
13 | for(string i : s1)
14 | {
15 | //cout << i << endl << s.find(i) << endl;
16 | if(s.find(i) != -1)
17 | {
18 | return true;
19 | }
20 | }
21 |
22 | return false;
23 | }
24 |
25 |
26 | int main() {
27 |
28 | string s;
29 |
30 | while(true) {
31 |
32 | cout << "Enter Your query : ";
33 | getline(cin, s);
34 |
35 | if(selectChecker(s,select_db_query))
36 | {
37 | if(selectChecker(s,colSymbol))
38 | {
39 | string check = run_query(s);
40 |
41 | if(SyntaxCheckerForResultString(check))
42 | {
43 | cout << endl << To_StringTable(run_query(s)) << endl;
44 | }
45 | else
46 | cout << endl << run_query(s) << endl;
47 | }
48 | else
49 | {
50 | cout << endl << run_query(s) << endl;
51 | }
52 | }
53 | else
54 | {
55 | cout << endl << run_query(s) << endl;
56 | }
57 | }
58 |
59 | return 0;
60 | }
61 |
--------------------------------------------------------------------------------
/OurDB_Database/global_functions/SyntaxCheckerForResultString.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Micron on 19/06/2021.
3 | //
4 |
5 | //#include
6 | //#include
7 | //#include
8 | //#include
9 | //#include
10 | //#include
11 | #include
12 | #include "AfterWhereProcess.h"
13 | #include "global_function.h"
14 |
15 |
16 |
17 | #ifndef OURDB_DATABASE_SYNTAXCHECKERFORRESULTSTRING_H
18 | #define OURDB_DATABASE_SYNTAXCHECKERFORRESULTSTRING_H
19 |
20 | bool SyntaxCheckerForResultString(std::string result)
21 | {
22 | if(result == "")
23 | {
24 | return false; // if result will empty it will return false
25 | }
26 | else
27 | {
28 | std::vector datastring; // for storing string data in vector
29 | std::regex r1("\n"); // regex for checking new line
30 | filterRegexInstring(result,datastring,r1,-1); // gives vector string which does not match with regex(newline separater)
31 | std::vector coldata; // for storing string column data
32 | std::regex r2(","); // regex for separation with ,
33 | filterRegexInstring(datastring[0],coldata,r2,-1); // gives the vector string with , separated data
34 |
35 | if(datastring.size() < 3) // if datastring vector array is less than 3
36 | {
37 | return false; // return false
38 | }
39 |
40 | if(coldata.size() < 0) // if coldata vector less than 0
41 | {
42 | return false; // return false
43 | }
44 |
45 | nullRomoverFromVectorString(datastring); // it will remove null value from vector..
46 | nullRomoverFromVectorString(coldata);
47 |
48 | for(int i = 0 ; i < datastring.size() ; i++) // iterate through datastring
49 | {
50 | if(datastring[i] == "\n") // it will check whether the element in vector array is empty or not
51 | {
52 | datastring.erase(datastring.begin()+i); // if it is empty then it will erase..
53 | }
54 | }
55 |
56 | if(coldata.size() > datastring.size()-3) // minimum value comparision with col data
57 | {
58 | return false; // return false
59 | }
60 |
61 | int colcount = coldata.size(); // stores the coldata size in colcount
62 |
63 | if(datastring[1]!=" ") // if datastring of 2nd value is return error
64 | {
65 | return false;
66 | }
67 |
68 | int datacounter = 0;
69 |
70 | for(int i = 2 ; i < datastring.size() ; i++) // iterate through datastring
71 | {
72 | if(datacounter == colcount) // if datacounter and colcount matches
73 | {
74 | if(datastring[i] != " ") // if datastring of ith value is then return false
75 | {
76 | return false; // return false
77 | }
78 | datacounter = 0; // initialize the datacounter with zero
79 | continue; // if above condition matches then skip the loop
80 | }
81 |
82 | if(datacounter != colcount) // if datacounter is not equal to colcount
83 | {
84 | datacounter++; // datacounter increment
85 | }
86 |
87 | }
88 |
89 | return true; // return true
90 |
91 | }
92 | }
93 |
94 | #endif //OURDB_DATABASE_SYNTAXCHECKERFORRESULTSTRING_H
95 |
--------------------------------------------------------------------------------
/OurDB_Database/global_functions/decryption.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Mihir on 15-05-2021.
3 | //
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include "../variables/query_variables.h"
10 | #include "../global_functions/global_function.h"
11 | #include "../External_Libraries/json.hpp"
12 |
13 | #ifndef OURDB_DATABASE_DECRYPTION_H
14 | #define OURDB_DATABASE_DECRYPTION_H
15 |
16 | std::string decryption(std::string data) // code for decryption
17 | {
18 | //here goes decryption code..
19 | enc_dec=""; // variable resides in variable.h
20 | for(char c : data)
21 | {
22 | // logic for decryption
23 | enc_dec += c ^ 69;
24 | }
25 |
26 | return enc_dec;//return the decrypted data
27 | }
28 |
29 | #endif //OURDB_DATABASE_DECRYPTION_H
30 |
--------------------------------------------------------------------------------
/OurDB_Database/global_functions/encryption.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Mihir on 15-05-2021.
3 | //
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include "../variables/query_variables.h"
10 | #include "../global_functions/global_function.h"
11 | #include "../External_Libraries/json.hpp"
12 |
13 | //using namespace std;
14 | using ourdb = nlohmann::json;
15 |
16 | #ifndef OURDB_DATABASE_ENCRYPTION_H
17 | #define OURDB_DATABASE_ENCRYPTION_H
18 |
19 | std::string encryption(std::string data) // code for encryption
20 | {
21 | //here goes encryption code..
22 | enc_dec=""; // variable in variable.h file
23 |
24 | for(char c : data)
25 | {
26 | //logic of encryption...
27 | enc_dec += c ^ 69;
28 |
29 | }
30 | //return the encrypt data
31 | return enc_dec;
32 | }
33 |
34 | #endif //OURDB_DATABASE_ENCRYPTION_H
35 |
--------------------------------------------------------------------------------
/OurDB_Database/global_functions/globalFunctionForSelectQuery.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by dabhe on 19-Jun-21.
3 | //
4 |
5 | #ifndef OURDB_DATABASE_GLOBALFUNCTIONFORSELECTQUERY_H
6 | #define OURDB_DATABASE_GLOBALFUNCTIONFORSELECTQUERY_H
7 |
8 | std::string SelectQueryStructureCreater(std::vector vect,std::vector>vectl)
9 | {
10 | std::string ml=""; // string which will strings
11 | for(int i=0;i
40 | // col1_value\ncol2_value\nco3_value
41 | //
42 | // col1_value\ncol2_value\nco3_value
43 | //
44 | // col1_value\ncol2_value\nco3_value
45 | //
46 |
47 | }
48 |
49 | void ascending_sort(std::vector> &data)
50 | {
51 | sort(data.begin(),data.end());
52 | }
53 |
54 | void descending_sort(std::vector> &data)
55 | {
56 | sort(data.begin(),data.end(),std::greater <>());
57 | }
58 |
59 | bool selectingSameColsMulTimes(std::vector beforeat)
60 | {
61 | int colcounter = 0;
62 |
63 | for(int i=0;i
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include "Errors/error_variable.h"
14 |
15 | //using namespace std;
16 | #ifndef OURDB_DATABASE_GLOBAL_FUNCTION_H
17 | #define OURDB_DATABASE_GLOBAL_FUNCTION_H
18 |
19 | // functions in this header file ----------------------------------------------------------------
20 | // validation function
21 | // filetable function for create table
22 | // ltrim function to trim left side
23 | // rtrim function to trim right side
24 | // trim function to trim both side
25 | // botharespacies function to check multiple spaces in string
26 | // split function for string into string array
27 | // function for remove null values into vector string
28 |
29 | //---------------------------------------------------------------------------------------------
30 |
31 | // check word with global word variable
32 | template
33 | bool syntaxCompare(const Element & keyvalue ,const Container & variablearray)
34 | {
35 | return find(begin(variablearray), end(variablearray), keyvalue) != end(variablearray);
36 | }
37 |
38 | // string validation in terms of name
39 | inline std::string validation(std::string dbname,std::string ferror,std::string serror)
40 | {
41 | firstLetterStore = dbname.front(); //store the first character of string
42 | lastLetterStore = dbname.back(); // stores last character of string
43 | if(firstLetterStore >= 97 && firstLetterStore <= 122) // check whether the first character is between "a to z" or not
44 | {
45 | if((lastLetterStore >= 32 && lastLetterStore <= 47) ||(lastLetterStore >= 58 && lastLetterStore <= 92) || (lastLetterStore >= 123 && lastLetterStore <= 126)) // check for special character
46 | {
47 | return ferror; // returns ferror variable i.e. no spl char allowed in db/table name
48 |
49 | }else{
50 |
51 | return "true_true"; // return true_true for execution of these block
52 | }
53 | }
54 | else if((firstLetterStore >= 48 && firstLetterStore <= 57)) // check if character is not between "a to z"...
55 | {
56 | return serror; // returns serror variable i.e. first letter cant be a numeric value
57 |
58 | }else if(!(firstLetterStore >= 97 && firstLetterStore <= 122)){
59 |
60 | return ferror; // returns ferror variable i.e. no spl char allowed in db/table name
61 | }
62 |
63 | }
64 |
65 | // create file in terms of table
66 | inline std::string FileTable(std::string nm)
67 | {
68 | std::fstream tb; // creats the object of class "fstream"... here "tb" obj is created
69 | tb.open(nm,std::ios::in | std::ios::out | std::ios::trunc ); // in for writing , out for writing and trunc
70 | if(!tb.is_open()) // is_open is defined in "fstream" which check file is created or not if created then open it
71 | {
72 | return errorCreatingFile[0]; // defined in Errors/error_variable.h
73 | }
74 | tb.close(); // closes the file
75 |
76 | return SuccessCreatingFileMsg[0];
77 | }
78 |
79 | //function for trimming string from front
80 | inline std::string& ltrim(std::string& str, const std::string& chars = "\t\n\v\f\r ")
81 | {
82 | str.erase(0, str.find_first_not_of(chars));
83 | return str;
84 | }
85 |
86 | //function for trimming string from end
87 | inline std::string& rtrim(std::string& str, const std::string& chars = "\t\n\v\f\r ")
88 | {
89 | str.erase(str.find_last_not_of(chars) + 1);
90 | return str;
91 | }
92 |
93 | //function for trimming string from the both side
94 | inline std::string& trim(std::string& str, const std::string& chars = "\t\n\v\f\r ")
95 | {
96 | return ltrim(rtrim(str, chars), chars);
97 | }
98 |
99 | // function for replace all space form string into one space
100 | inline bool BothAreSpaces(char lhs, char rhs) { return (lhs == rhs) && (lhs == ' '); }
101 |
102 | // split function for string into string array
103 | inline void split(std::string const &str, const char delim,std::vector &out)
104 | {
105 | size_t start;
106 | size_t end = 0;
107 |
108 | while ((start = str.find_first_not_of(delim, end)) != std::string::npos)
109 | {
110 | end = str.find(delim, start);
111 | out.push_back(str.substr(start, end - start));
112 | }
113 | }
114 |
115 | //separate the query after specific position (after '@' to be precise)
116 | std::vector InputStringSeparation(std::vector arr)
117 | {
118 | if(!(databaseSelectGlobal.empty()))
119 | {
120 | std::string tbname = arr[2]; //var to store table name and check if it exists or not!
121 | std::string path = databaseSavePath + "/" + tbname + ".Ourdb"; //path where table is stored
122 |
123 | if(std::filesystem::exists(path.c_str())) //checks if the path is valid i.e. if table exists or not
124 | {
125 | std::string temp; //string to store vector string array
126 |
127 | for(int i=0;i data; //vector string to return inserted data
138 |
139 | std::regex words_regex("'(.*?)'"); //regex to remove ' ' from the data
140 |
141 | for(std::sregex_iterator it = std::sregex_iterator(
142 | temp.begin(), temp.end(), words_regex);
143 | it != std::sregex_iterator(); it++)
144 | {
145 | std::smatch match = *it;
146 | std::string match_str = match.str(1);
147 | data.insert(data.end(),match_str); //data inserted after separating into vector string
148 | }
149 |
150 | if(data.size() == count/2) //checks if the data is equal to no. of data inserted by user
151 | {
152 | return data; //returning vector string that contains records for inserting
153 | }
154 | else
155 | {
156 | std::vector error;
157 | error.insert(error.end(),ErrImproperData[0]); //error if improper insertion of data
158 |
159 | return error; //return error
160 | }
161 | }
162 | else
163 | {
164 | std::vector error;
165 | error.insert(error.end(),errNoSuchTableExist[0]); //error if table doesnt exists
166 |
167 | return error; //return error
168 | }
169 | }
170 | else
171 | {
172 | std::vector error;
173 | error.insert(error.end(),SelectTheDatabase[0]); //error if database not selected
174 |
175 | return error; //return error
176 | }
177 | }
178 |
179 | std::string string_quote_cutter(std::string strx)
180 | {
181 | strx.erase(std::remove(strx.begin(),strx.end(),'\''),strx.end());
182 | return strx;
183 | }
184 |
185 | std::string string_quote_cutter(std::string strx, char cut)
186 | {
187 | strx.erase(std::remove(strx.begin(),strx.end(),cut),strx.end());
188 | return strx;
189 | }
190 |
191 | void nullRomoverFromVectorString(std::vector &vec)
192 | {
193 | if(vec.size() > 0)
194 | {
195 | for(int i = 0 ; i < vec.size() ; i++)
196 | {
197 | if(vec[i].empty()) // it will check whether the element in vector array is empty or not
198 | {
199 | vec.erase(vec.begin()+i); // if it is empty then it will erase..
200 | }
201 | }
202 | }
203 | }
204 |
205 |
206 | #endif //OURDB_DATABASE_GLOBAL_FUNCTION_H
207 |
--------------------------------------------------------------------------------
/OurDB_Database/global_functions/keywords_checker.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Mihir on 15-06-2021.
3 | //
4 |
5 | #ifndef OURDB_DATABASE_KEYWORDS_CHECKER_H
6 | #define OURDB_DATABASE_KEYWORDS_CHECKER_H
7 |
8 | bool keywords_checker(std::string s)
9 | {
10 | if(syntaxCompare(s,bannedkeywords))
11 | {
12 | return 1;
13 | }
14 | else
15 | return 0;
16 | }
17 |
18 | #endif //OURDB_DATABASE_KEYWORDS_CHECKER_H
19 |
--------------------------------------------------------------------------------
/OurDB_Database/mihir_module/add_column/add_column.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Mihir on 10-06-2021.
3 | //
4 |
5 | //#include
6 | //#include
7 | //#include
8 | //#include
9 | #include "../../variables/query_variables.h"
10 | #include "../../global_functions/global_function.h"
11 | #include "../../External_Libraries/json.hpp"
12 |
13 | //using namespace std;
14 | using ourdb = nlohmann::json;
15 |
16 | #ifndef OURDB_DATABASE_ADD_COLUMN_H
17 | #define OURDB_DATABASE_ADD_COLUMN_H
18 |
19 | std::string addColumn(std::string tablename,std::vector a)
20 | {
21 | if(!(databaseSelectGlobal.empty()))
22 | {
23 | if(tablename == "default")
24 | {
25 | return ErrDataManipulationInDefault[0]; //error if user tries to insert into default table
26 | }
27 | else
28 | {
29 | int samecol = 0;
30 | int colaldthere = 0;
31 | int keycheck = 0;
32 |
33 | std::string path = databaseSavePath + "/" + tablename + ".Ourdb"; //path where table is stored
34 |
35 | if(std::filesystem::exists(path)) //checks if table exists or not
36 | {
37 | std::ifstream in(path);
38 |
39 | ourdb coldata; //var to store json data
40 |
41 | in >> coldata; //taking json data from table into coldata variable
42 | for(int i=0;i
6 | #include "../../variables/query_variables.h"
7 | #include "../../External_Libraries/json.hpp"
8 |
9 | //using namespace std;
10 | using ourdb = nlohmann::json;
11 |
12 | #ifndef OURDB_DATABASE_COLUMN_LIST_H
13 | #define OURDB_DATABASE_COLUMN_LIST_H
14 |
15 | std::string columnList(std::string tablename)
16 | {
17 | if(!(databaseSelectGlobal.empty()))
18 | {
19 | std::string path = databaseSavePath + "/" + tablename + ".Ourdb"; //path where table is stored
20 |
21 | if(std::filesystem::exists(path))
22 | {
23 | if(tablename == "default")
24 | {
25 | return "Can't access default table!!";
26 | }
27 | else
28 | {
29 | std::string collist;
30 | std::ifstream in(path);
31 |
32 | ourdb coldata; //var to store json data
33 |
34 | in >> coldata; //taking json data from table into coldata variable
35 |
36 | if(coldata["records"]["col_names"].empty())
37 | {
38 | return ErrNoColsFoundInTable[0];
39 | }
40 |
41 | collist += "Columns in table " + tablename + " are :\n\t";
42 |
43 | for(auto &i : coldata["records"]["col_names"])
44 | {
45 | collist += i;
46 | collist += "\n\t";
47 | }
48 |
49 | return collist;
50 | }
51 | }
52 | else
53 | {
54 | return tableDoesNotExist[0];
55 | }
56 | }
57 | else
58 | {
59 | return SelectTheDatabase[0]; //select database error if database isn't selected
60 | }
61 | }
62 |
63 | #endif //OURDB_DATABASE_COLUMN_LIST_H
64 |
--------------------------------------------------------------------------------
/OurDB_Database/mihir_module/current_database/current_database.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Mihir on 04-05-2021.
3 | //
4 |
5 | //#include
6 | //#include
7 | #include "../../variables/query_variables.h"
8 |
9 | #ifndef CONSOLE_CPP_CURRENT_DATABASE_H
10 | #define CONSOLE_CPP_CURRENT_DATABASE_H
11 |
12 | std::string currentDatabase()
13 | {
14 | std::string a = databaseSelectGlobal;
15 |
16 | if(a == "")
17 | {
18 | return errDatabaseNotSelected[0];
19 | }
20 | else
21 | return "Your currently selected database is \n\t" + a;
22 | }
23 |
24 | #endif //CONSOLE_CPP_CURRENT_DATABASE_H
25 |
--------------------------------------------------------------------------------
/OurDB_Database/mihir_module/database_list/database_list.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Mihir on 04-05-2021.
3 | //
4 |
5 | //#include
6 | //#include
7 | //#include
8 | #include "../../variables/query_variables.h"
9 |
10 | //using namespace std;
11 |
12 | #ifndef OURDB_DATABASE_DATABASE_LIST_H
13 | #define OURDB_DATABASE_DATABASE_LIST_H
14 |
15 | std::string databaseList()
16 | {
17 | std::filesystem::path path(strPath[0]); //path where all our databases are created and stored
18 | std::string list; //string to store the list of databases
19 |
20 | if(!std::filesystem::is_empty(path)) //checks if the current path to database is empty or not
21 | {
22 | list += "Databases are : \n";
23 | for (auto &i : std::filesystem::directory_iterator(path)) //increments the existing folders(databases) at given path
24 | {
25 | if(i.is_directory())
26 | {
27 | list += i.path().filename().string() + "\n"; //store the names of all the folders(databases) in list string
28 | }
29 | }
30 | return list; //returns the list string which has all the database's name
31 | }
32 | else
33 | return errDatabaseListIsEmpty[0]; //error to be displayed if there is no database at given path
34 | }
35 |
36 |
37 |
38 | #endif //OURDB_DATABASE_DATABASE_LIST_H
39 |
--------------------------------------------------------------------------------
/OurDB_Database/mihir_module/foreign_key/add_foreign_key.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Mihir on 01-10-2021.
3 | //
4 |
5 | #include "../../External_Libraries/json.hpp"
6 | #include "../../global_functions/decryption.h"
7 | #include
8 |
9 | using ourdb = nlohmann::json;
10 |
11 | #ifndef CONSOLE_CPP_ADD_FOREIGN_KEY_H
12 | #define CONSOLE_CPP_ADD_FOREIGN_KEY_H
13 |
14 | std::string addForeignKey(std::string frcolname,std::string frtbname,std::string prtbname)
15 | {
16 | if(!(databaseSelectGlobal.empty()))
17 | {
18 | if(frtbname == "default" || prtbname == "default")
19 | {
20 | return errUpdatingDefaultTable[0]; //doesnt allow user to update the default.Ourdb file(table)
21 | }
22 |
23 | std::string frtb = strPath[0] + databaseSelectGlobal + "/" + frtbname + ".Ourdb"; //path of foreign key's table
24 | std::string prtb = strPath[0] + databaseSelectGlobal + "/" + prtbname + ".Ourdb"; //path of primary table
25 |
26 | if(std::filesystem::exists(frtb.c_str()) && std::filesystem::exists(prtb.c_str())) // checks if file exists or not
27 | {
28 | std::ifstream infr(frtb);
29 | std::ifstream inpr(prtb);
30 |
31 | ourdb prcoldata;
32 | ourdb frcoldata;
33 | ourdb frdatafinal; //temp var to store foreign key and add it to foreign key table
34 |
35 | infr >> frcoldata;
36 | inpr >> prcoldata;
37 |
38 | if(prcoldata["records"]["col_names"].empty() || frcoldata["records"]["col_names"].empty())
39 | {
40 | return ErrNoColsFoundInTable[0]; //if no columns exist in the table
41 | }
42 | if(prcoldata["records"]["primary_key"].empty())
43 | {
44 | return ErrNoPrimaryKeyFound[0]; //if there is no primary key in primary table
45 | }
46 |
47 | if(!frcoldata["records"]["foreign_key"].empty())
48 | {
49 | for(auto & i : frcoldata["records"]["foreign_key"])
50 | {
51 | if(i[0] == frcolname)
52 | {
53 | return ErrAlreadyAForeignKey[0]; //if you try to add a foreign key that is already a foreign key to another or same primary table
54 | }
55 | }
56 | }
57 |
58 | std::string prkeycol = prcoldata["records"]["primary_key"]; //primary key of primary table
59 |
60 | int countforpkey = 0; //to count primary key's index in primary table
61 | int countforfkey = 0; //to count foreign key's index in its table
62 |
63 | for(auto & i : prcoldata["records"]["col_names"])
64 | {
65 | if(i == prkeycol)
66 | {
67 | break;
68 | }
69 | countforpkey++;
70 | }
71 |
72 | for(auto & i : frcoldata["records"]["col_names"])
73 | {
74 | if(i == frcolname)
75 | {
76 | break;
77 | }
78 | countforfkey++;
79 | }
80 |
81 | if(countforfkey >= frcoldata["records"]["col_names"].size())
82 | {
83 | return ErrColumnDoesNotExists[0]; //if column doesnt exist in the table
84 | }
85 |
86 | if(frcoldata["table_data"].empty())
87 | {
88 | frdatafinal["records"]["foreign_key"] = {frcolname,prtbname}; //sets foreign key col data in pair of column_name and primary_table_name
89 |
90 | frcoldata["records"]["foreign_key"] += frdatafinal["records"]["foreign_key"]; //adds it to table's column data
91 |
92 | std::ofstream ofr(frtb); //writes on the table (file)
93 | ofr << frcoldata << std::endl;
94 |
95 | return SuccessForeignKey[0]; //succesfully added foreign key!
96 | }
97 | else if(prcoldata["table_data"].empty() && !(frcoldata["table_data"].empty()))
98 | {
99 | return ErrForeignKeyConstraintViolated[0]; //if theres no data in primary table's primary key column
100 | }
101 | else
102 | {
103 | int prcolindex = prcoldata["records"]["col_index"][countforpkey]; //to store column index of the primary key column
104 | std::string prcolindexstr = std::to_string(prcolindex); //converting it to string
105 |
106 | int frcolindex = frcoldata["records"]["col_index"][countforfkey]; //to store column index of the primary key column
107 | std::string frcolindexstr = std::to_string(frcolindex); //converting it to string
108 |
109 | std::vector arrprdata; //to store primary columns data
110 |
111 | for(auto & i : prcoldata["table_data"])
112 | {
113 | arrprdata.insert(arrprdata.end(), decryption(i[prcolindexstr])); //inserting primary col's data into a vector
114 | }
115 |
116 | int countforfrdatacheck = 0; //to check if foreign key col's data is valid acc to primary key's data or not
117 |
118 | for(auto& i : frcoldata["table_data"])
119 | {
120 | std::string frdata = decryption(i[frcolindexstr]);
121 |
122 | if(std::count(arrprdata.begin(),arrprdata.end(), frdata))
123 | {
124 | countforfrdatacheck++; //increases if data is found and so is valid
125 | }
126 | }
127 |
128 | if(countforfrdatacheck == frcoldata["table_data"].size()) //if all of the data are valid
129 | {
130 | frdatafinal["records"]["foreign_key"] = {frcolname,prtbname}; //sets foreign key col data in pair of column_name and primary_table_name
131 |
132 | frcoldata["records"]["foreign_key"] += frdatafinal["records"]["foreign_key"]; //adds it to table's column data
133 |
134 | std::ofstream ofr(frtb); //writes on the table (file)
135 | ofr << frcoldata << std::endl;
136 |
137 | return SuccessForeignKey[0]; //succesfully added foreign key!
138 | }
139 | else
140 | {
141 | return ErrCantAddForeignKey[0]; //if data isnt valid acc to primary col's data
142 | }
143 | }
144 | }
145 | else
146 | {
147 | return tableDoesNotExist[0]; //if either of the tables doesnt exist
148 | }
149 | }
150 | else
151 | {
152 | return SelectTheDatabase[0]; //if database is not selected
153 | }
154 | }
155 |
156 | #endif //CONSOLE_CPP_ADD_FOREIGN_KEY_H
157 |
--------------------------------------------------------------------------------
/OurDB_Database/mihir_module/insert_into_table/insert_into_table.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by zeel,mihir,parth,pranav on 17/05/2021.
3 | //
4 |
5 | #include "../../variables/query_variables.h"
6 | #include "../../global_functions/global_function.h"
7 | #include "../../External_Libraries/json.hpp"
8 | #include "../../global_functions/encryption.h"
9 | #include "../../global_functions/decryption.h"
10 |
11 | using ourdb = nlohmann::json;
12 |
13 | #ifndef OURDB_DATABASE_INSERT_INTO_TABLE_H
14 | #define OURDB_DATABASE_INSERT_INTO_TABLE_H
15 |
16 | std::string insertIntoTable(std::string tbname,std::vector a)
17 | {
18 | if(!(databaseSelectGlobal.empty()))
19 | {
20 | if(tbname == "default")
21 | {
22 | return ErrDataManipulationInDefault[0]; //error if user tries to insert into default table
23 | }
24 | else
25 | {
26 | std::string path = databaseSavePath + "/" + tbname + ".Ourdb"; //path where table is stored
27 |
28 | std::ifstream in(path);
29 |
30 | ourdb coldata;
31 | ourdb tbdata;
32 |
33 | in >> coldata;
34 |
35 | if (a.size() == coldata["records"]["total_cols"]) //checks if no. of data inserted is equals to no. of columns in the table
36 | {
37 | std::string tmp;
38 | std::vector st;
39 |
40 | for (auto& x : coldata["records"]["col_index"].items())
41 | st.insert(st.end(), to_string(x.value()));
42 |
43 | if(!coldata["records"]["primary_key"].empty()) //checks if primary key is set on table or not
44 | {
45 | std::string primarykey = coldata["records"]["primary_key"];
46 |
47 | int prcount=0; //counter for index of column_name
48 | for(auto & i : coldata["records"]["col_names"])
49 | {
50 | if(i == primarykey)
51 | {
52 | break;
53 | }
54 | prcount++;
55 | }
56 |
57 | if(a[prcount].empty()) //if user tries to insert null data in primary key
58 | {
59 | return ErrPrimaryKeyConstraintViolation[0]; //primary key constraint violated
60 | }
61 |
62 | int colindex = coldata["records"]["col_index"][prcount]; //to store column index of the primary key column
63 | std::string colindexstr = std::to_string(colindex); //converting it to string
64 |
65 | for(auto & i : coldata["table_data"])
66 | {
67 | if(a[prcount] == decryption(i[colindexstr])) //checks if duplicate data is being added to the primary key
68 | {
69 | return ErrPrimaryKeyConstraintViolation[0]; //primary key constraint violated
70 | }
71 | }
72 | }
73 |
74 | if(!coldata["records"]["foreign_key"].empty()) //checks if foreign key is set on table or not
75 | {
76 | for(auto & i : coldata["records"]["foreign_key"])
77 | {
78 | std::string foreignkey = i[0]; //stores foreign key for checking
79 | std::string prtbname = i[1];
80 | ourdb prtabledata;
81 |
82 | std::string prtbpath = strPath[0] + databaseSelectGlobal + "/" + prtbname + ".Ourdb";
83 |
84 | if(!std::filesystem::exists(prtbpath.c_str()))
85 | {
86 | return errNoSuchTableExist[0];
87 | }
88 |
89 | std::ifstream prin(prtbpath);
90 |
91 | prin >> prtabledata;
92 |
93 | int frcount=0; //counter for index of foreign key column_name
94 | for(auto & j : coldata["records"]["col_names"])
95 | {
96 | if(j == foreignkey)
97 | {
98 | break;
99 | }
100 | frcount++;
101 | }
102 |
103 | std::string prtbprimarykey = prtabledata["records"]["primary_key"]; //primary table's primary key
104 |
105 | int prcount=0; //counter for index of primary column_name
106 | for(auto & j : prtabledata["records"]["col_names"])
107 | {
108 | if(j == prtbprimarykey)
109 | {
110 | break;
111 | }
112 | prcount++;
113 | }
114 |
115 | int frcolindex = coldata["records"]["col_index"][frcount]; //to store column index of the foreign key column
116 | std::string frcolindexstr = std::to_string(frcolindex); //converting it to string
117 |
118 | int prcolindex = prtabledata["records"]["col_index"][prcount]; //to store column index of the primary key column
119 | std::string prcolindexstr = std::to_string(prcolindex); //converting it to string
120 |
121 | int frdatachecker = 0;
122 |
123 | for(auto & k : prtabledata["table_data"])
124 | {
125 | if(a[frcount] == decryption(k[prcolindexstr])) //checks if duplicate data is being added to the primary key
126 | {
127 | break;
128 | }
129 | frdatachecker++;
130 | }
131 |
132 | if(frdatachecker == prtabledata["table_data"].size())
133 | {
134 | return ErrForeignKeyConstraintViolated[0]; //if data in foreign key is not found in the primary key it is asociated with
135 | }
136 | }
137 | }
138 |
139 | for (int i = 0; i < a.size(); i++)
140 | {
141 | //tbdata["table_data"][to_string(i+1)] = encryption(a[i]); //data encrypted and added to tbdata
142 | if(a[i].empty())
143 | {
144 | a[i] = "null";
145 | }
146 | tbdata["table_data"][st[i]] = encryption(a[i]); //data encrypted and added to tbdata
147 | }
148 |
149 | coldata["table_data"] += tbdata["table_data"]; //data appended to table from tbdata
150 | std::ofstream o(path);
151 | o << coldata << std::endl;
152 |
153 | return SuccessInsertDataTableMsg[0]; //successfully inserted data into table
154 | }
155 | else
156 | {
157 | return ErrDataNotEqualToNoOfCols[0]; //error if no. of cols isnt equal to no. of data inserted
158 | }
159 |
160 | }
161 | }
162 | else
163 | {
164 | return SelectTheDatabase[0]; //select database error if database isnt selected
165 | }
166 | }
167 |
168 | #endif //OURDB_DATABASE_INSERT_INTO_TABLE_H
--------------------------------------------------------------------------------
/OurDB_Database/mihir_module/primary_key/add_primary_key.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Mihir on 19-08-2021.
3 | //
4 |
5 | #include "../../External_Libraries/json.hpp"
6 | #include "../../global_functions/decryption.h"
7 |
8 | using ourdb = nlohmann::json;
9 |
10 | #ifndef CONSOLE_CPP_ADD_PRIMARY_KEY_H
11 | #define CONSOLE_CPP_ADD_PRIMARY_KEY_H
12 |
13 | std::string addPrimaryKey(std::string colname , std::string tbname)
14 | {
15 | if(!(databaseSelectGlobal.empty()))
16 | {
17 | if(tbname == "default")
18 | {
19 | return errUpdatingDefaultTable[0]; //doesnt allow user to update the default.Ourdb file(table)
20 | }
21 |
22 | tbname = strPath[0] + databaseSelectGlobal + "/" + tbname + ".Ourdb";
23 | if(std::filesystem::exists(tbname.c_str())) // checks if file exists or not
24 | {
25 | std::ifstream in(tbname);
26 |
27 | ourdb coldata;
28 | int count = 0; //counter for checking if column exists or not
29 |
30 | in >> coldata;
31 |
32 | if(coldata["records"]["col_names"].empty())
33 | {
34 | return ErrNoColsFoundInTable[0]; //no columns exist in the table
35 | }
36 |
37 | if(coldata["records"]["primary_key"] == colname)
38 | {
39 | return ErrAlreadyAPrimaryKey[0]; //if the column is already the primary key
40 | }
41 |
42 | for(auto & i : coldata["records"]["col_names"])
43 | {
44 | if(i == colname)
45 | {
46 | break;
47 | }
48 | count++; //to store position of the column
49 | }
50 |
51 | if(count >= coldata["records"]["col_names"].size())
52 | {
53 | return ErrColumnDoesNotExists[0]; //if column doesnt exist in the table
54 | }
55 | else
56 | {
57 | if(!coldata["table_data"].empty())
58 | {
59 | int countforduplicatedata = 0;
60 | int countfornulldata = 0;
61 |
62 | int colindex = coldata["records"]["col_index"][count]; //to store column index of the primary key column
63 | std::string colindexstr = std::to_string(colindex); //converting it to string
64 |
65 | for(int i=0;i
5 | //#include
6 | //#include
7 | #include "../../variables/query_variables.h"
8 | //using namespace std;
9 |
10 | #ifndef OURDB_DATABASE_RENAME_DATABASE_H
11 | #define OURDB_DATABASE_RENAME_DATABASE_H
12 |
13 | std::string renameDatabase(std::string databaseName)
14 | {
15 | if(!(databaseSelectGlobal.empty()))
16 | {
17 | validate = validation(databaseName,errorSpecialchaDatabase[0],errFirstLetterNumeric[0]);
18 | if(validate == "true_true")
19 | {
20 | std::regex l("[a-zA-Z0-9_]{0,}"); // alphabet numeric and _ allowed between letters..
21 | if ( regex_match(databaseName, l) )
22 | {
23 | databaseName = strPath[0] + databaseName; //strpath[0]="path" defined in variables/query_variables.h
24 | if (!(databaseSavePath == databaseName))
25 | {
26 | if (rename(databaseSavePath.c_str(), databaseName.c_str()) != 0) // rename the directory
27 | {
28 | return errrenameDatabase[0]; // defined in Errors/error_variable.h
29 | }
30 | else
31 | {
32 | databaseSelectGlobal = ""; // after renaming it has to be empty.. sp again have to select in order to rename
33 | return SuccessRenamingDatabaseMsg[0]; // Success_Messages/Success_Msg.h
34 | }
35 | }
36 | else
37 | {
38 | return sameNameDatabaseErr[0];
39 | }
40 | }
41 | else
42 | {
43 | return errorSpecialchaDatabase[0];
44 | }
45 | }
46 | else if(validate != "true_true")
47 | return validate;
48 | }
49 | else
50 | {
51 | return SelectTheDatabase[0]; // if database is not selected before renaming then it gives error..
52 | }
53 | }
54 |
55 | #endif //OURDB_DATABASE_RENAME_DATABASE_H
56 |
--------------------------------------------------------------------------------
/OurDB_Database/mihir_module/rename_table/rename_table.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Mihir on 07-05-2021.
3 | //
4 |
5 | //#include
6 | //#include
7 | //#include
8 | #include "../../variables/query_variables.h"
9 |
10 | #ifndef OURDB_DATABASE_RENAME_TABLE_H
11 | #define OURDB_DATABASE_RENAME_TABLE_H
12 |
13 | std::string renameTable(std::string oldName,std::string newName)
14 | {
15 | if(!(databaseSelectGlobal.empty()))
16 | {
17 | if(oldName == "default")
18 | {
19 | return errRenamingDefaultTable[0]; //doesnt allow user to rename the default.Ourdb file(table)
20 | }
21 |
22 | dName = databaseSelectGlobal; //to store current database name
23 |
24 | validate = validation(oldName,errorSpecialchaTable[0],errFirstLetterNumeric[0]); //validating old table name
25 | if(validate == "true_true")
26 | {
27 | std::regex l("[a-zA-Z0-9_]{0,}"); // alphabet numeric and _ allowed between letters..
28 | if ( regex_match(oldName, l) )
29 | {
30 |
31 | validate = validation(newName,errorSpecialchaTable[0],errFirstLetterNumeric[0]); //validating new table name
32 | if(validate == "true_true")
33 | {
34 | oldName = strPath[0] + databaseSelectGlobal + "/" + oldName + ".Ourdb";
35 | if(std::filesystem::exists(oldName.c_str())) // checks if file already exist or not
36 | {
37 | std::regex l("[a-zA-Z0-9_]{0,}"); // alphabet numeric and _ allowed between letters..
38 | if (regex_match(newName, l))
39 | {
40 | newName = strPath[0] + databaseSelectGlobal + "/" + newName + ".Ourdb";
41 |
42 | if(oldName == newName) //if both old and new name are same then return error
43 | {
44 | return sameNameTableErr[0]; //same old and new name error
45 | }
46 | else
47 | {
48 | if(rename(oldName.c_str(),newName.c_str()) != 0) //if rename function doesnt work then return error
49 | {
50 | return errRenameTable[0]; //renaming table error
51 | }
52 | else
53 | {
54 | return SuccessRenamingTableMsg[0]; //success msg if the table is renamed successfully!
55 | }
56 | }
57 | }
58 | else
59 | {
60 | return errorSpecialchaTable[0];
61 | }
62 | }
63 | else
64 | return errNoSuchTableExist[0];
65 |
66 | }
67 | else if(validate != "true_true")
68 | return validate;
69 | }
70 | else
71 | {
72 | return errorSpecialchaTable[0];
73 | }
74 | }
75 | else if(validate != "true_true")
76 | return validate;
77 | }
78 | else
79 | {
80 | return SelectTheDatabase[0]; // if database is not selected before renaming then it gives error..
81 | }
82 | }
83 |
84 | #endif //OURDB_DATABASE_RENAME_TABLE_H
85 |
--------------------------------------------------------------------------------
/OurDB_Database/mihir_module/return_object/m_to_json.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by zeel on 02/07/2021.
3 | //
4 |
5 | #ifndef OURDB_DATABASE_M_TO_JSON_H
6 | #define OURDB_DATABASE_M_TO_JSON_H
7 |
8 | #include "../../global_functions/SyntaxCheckerForResultString.h"
9 |
10 | ourdb m_to_json(std::string result)
11 | {
12 | ourdb myobj;
13 | if(SyntaxCheckerForResultString(result))
14 | {
15 | std::vector datastring; // for storing string data in vector
16 | std::regex r1("\n"); // regex for checking new line
17 | filterRegexInstring(result,datastring,r1,-1); // gives vector string which does not match with regex(newline separater)
18 | std::vector coldata; // for storing string column data
19 | std::regex r2(","); // regex for separation with ,
20 | filterRegexInstring(datastring[0],coldata,r2,-1); // gives the vector string with , separated data
21 |
22 | nullRomoverFromVectorString(datastring); // it will remove null value from vector..
23 | nullRomoverFromVectorString(coldata);
24 |
25 | for(int i = 0 ; i < datastring.size() ; i++) // iterate through datastring
26 | {
27 | if(datastring[i].empty()) // it will check whether the element in vector array is empty or not
28 | {
29 | datastring.erase(datastring.begin()+i); // if it is empty then it will erase..
30 | }
31 | }
32 |
33 | //myobj = datastring;
34 | //myobj["col_names"] = coldata;
35 |
36 | std::map> tabledata; //map to store table data
37 |
38 | for(int i=0;ifirst << "\t";
50 | for(auto &j : itr->second)
51 | {
52 | myobj[itr->first] += j;
53 | }
54 | std::cout << std::endl;
55 | }
56 |
57 | return myobj;
58 | }
59 | else
60 | {
61 | return myobj;
62 | }
63 | }
64 |
65 | #endif //OURDB_DATABASE_M_TO_JSON_H
66 |
--------------------------------------------------------------------------------
/OurDB_Database/mihir_module/table_list/table_list.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Mihir on 05-05-2021.
3 | //
4 |
5 | //#include
6 | //#include
7 | //#include
8 | #include "../../variables/query_variables.h"
9 |
10 | #ifndef OURDB_DATABASE_TABLE_LIST_H
11 | #define OURDB_DATABASE_TABLE_LIST_H
12 |
13 | std::string tableList()
14 | {
15 | if(databaseSelectGlobal == "")
16 | {
17 | return errDatabaseNotSelected[0];
18 | }
19 | else
20 | {
21 | std::string path = strPath[0] + databaseSelectGlobal + "./"; //path to current database where our tables are created and stored
22 | std::string list; //string to store the list of tables
23 |
24 | if (!std::filesystem::is_empty(path)) //checks if the current path to table is empty or not
25 | {
26 | list += "Tables are : \n";
27 | for (auto &i : std::filesystem::directory_iterator(path)) //increments the existing files(tables) at given path
28 | {
29 | list += i.path().filename().stem().string() + "\n"; //store the names of all the files(tables) in list string without extension
30 | }
31 | return list; //returns the list string which has all the tables's name
32 | }
33 | else
34 | return errTableListIsEmpty[0]; //error to be displayed if there is no table present at selected database
35 | }
36 | }
37 |
38 | #endif //OURDB_DATABASE_TABLE_LIST_H
39 |
--------------------------------------------------------------------------------
/OurDB_Database/parth_errors/parth_errors.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by dabhe on 10-Jun-21.
3 | //
4 | //#include
5 | //using namespace std;
6 | #ifndef OURDB_DATABASE_PARTH_ERRORS_H
7 | #define OURDB_DATABASE_PARTH_ERRORS_H
8 |
9 | // syntax error in renaming query..
10 | inline std::string ErrorInRenameQuery[2] = {"Error index := P.1 , Error := Rename column Syntax is not right\n rename column/col from @ ","P.1"};
11 |
12 | //renaming operation failed..
13 | inline std::string ErrorInRenameOp[2] = {"Error index := P.2 , Error := Renaming column operation failed .. inserted column name pr order may be wrong ","P.2"};
14 |
15 | //wrong column name...
16 | inline std::string ErrorInColumnName[2] = {"Error index := P.3 , Error := Wrong column name or insertion syntax wrong\n update @ @ set/put '' where (=/|)","P.3"};
17 |
18 | // same column name already exist...
19 | inline std::string ErrSameColumnNameExit[2]={"Error index := P.4 , Error := Same column name already exist in other column\n update @ @ set/put '' where (=/|)","P.4"};
20 | #endif //OURDB_DATABASE_PARTH_ERRORS_H
21 |
--------------------------------------------------------------------------------
/OurDB_Database/query_process.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by zeel,mihir,parth,pranav on 13/04/2021.
3 | //
4 | //#include
5 | //#include
6 | #include
7 | //#include
8 | #include "Errors/error_variable.h"
9 | #include "parth_errors/parth_errors.h"
10 | #include "variables/query_variables.h"
11 | #include "Success_Messages/Success_Msg.h"
12 | #include "Parth_module/create_database/create_database.h"
13 | #include "Parth_module/delete_database/delete_database.h"
14 | #include "Parth_module/select_database/select_database.h"
15 | #include "mihir_module/rename_database/rename_database.h"
16 | #include "mihir_module/database_list/database_list.h"
17 | #include "mihir_module/current_database/current_database.h"
18 | #include "Parth_module/create_table/create_table.h"
19 | #include "mihir_module/table_list/table_list.h"
20 | #include "mihir_module/rename_table/rename_table.h"
21 | #include "zeel_module/delete_table/delete_table.h"
22 | #include "mihir_module/insert_into_table/insert_into_table.h"
23 | #include "Parth_module/update_into_table/update_into_table.h"
24 | #include "Parth_module/update_into_table/ForUpdate.h"
25 | #include "zeel_module/delete_query/delete_query.h"
26 | #include "Parth_module/rename_columns/rename_columns.h"
27 | #include "zeel_module/delete_column_query/delete_column_query.h"
28 | #include "mihir_module/add_column/add_column.h"
29 | #include "select_module/select_module.h"
30 | #include "mihir_module/column_list/column_list.h"
31 | #include "mihir_module/primary_key/add_primary_key.h"
32 | #include "mihir_module/foreign_key/add_foreign_key.h"
33 |
34 | //using namespace std;
35 |
36 | #ifndef OURDB_DATABASE_QUERY_PROCESS_H
37 | #define OURDB_DATABASE_QUERY_PROCESS_H
38 |
39 | // function for query process
40 | std::string query_process(std::vector query)
41 | {
42 | //check for create's queries
43 | if(syntaxCompare(query[0],create_query))
44 | {
45 | // all create queries
46 | if(query_size == 3) {
47 |
48 | if (syntaxCompare(query[1], database))//check for database's word
49 | { //for create database
50 | return createDatabase(query[2]); // parth's part
51 | }
52 | else
53 | {
54 | // else part of create query
55 | return syntaxOfCreateError[0];
56 | }
57 | }
58 | if(query_size > 3)
59 | {
60 | if (syntaxCompare(query[1], table))
61 | { //check for table name
62 |
63 | if(syntaxCompare(query[3],colSymbol))
64 | {
65 | std::vector a;
66 | int j = 4;
67 |
68 | for(int i=0;i= 4)
112 | {
113 | if(syntaxCompare(query[1],colSymbol))
114 | {
115 | StoreTempString = "";
116 | for(int i=4;i 3)
176 | {
177 | return SelectQuery(query);
178 | }
179 | else
180 | {
181 | return ExtraWordInselectDatabaseSyntax[0];
182 | }
183 |
184 | }
185 | else if(syntaxCompare(query[0],rename_query))
186 | {
187 | // for rename the database
188 | if(query_size == 3)
189 | {
190 | if (syntaxCompare(query[1], database)) //check for database's word
191 | {
192 | return renameDatabase(query[2]);
193 | }
194 | else
195 | {
196 | return syntaxErrRenameDatabase[0];
197 | }
198 | }
199 | else if(query_size == 4)
200 | {
201 | if (syntaxCompare(query[1], table)) //check for table's word
202 | {
203 | return renameTable(query[2],query[3]);
204 | }
205 | else
206 | {
207 | return syntaxErrRenameTable[0];
208 | }
209 | }
210 | else if(query_size > 5)
211 | {
212 | if (syntaxCompare(query[1], column)) //check for column's word
213 | {
214 | if(syntaxCompare(query[2],from)) //checks for 'from' word
215 | {
216 | if(syntaxCompare(query[4],colSymbol)) //checks for colsymbol
217 | {
218 | std::vector vc;
219 | std::regex fb("[a-z0-9_]{0,}");
220 | for(int i = 5;i 3)
326 | {
327 | if(syntaxCompare(query[1],into))
328 | {
329 | if(syntaxCompare(query[3],colSymbol))
330 | {
331 | std::vector a = InputStringSeparation(query); //vector string separated by ''
332 | if(a.empty() || a[0] == ErrImproperData[0])
333 | {
334 | return ErrImproperData[0]; //error if there is improper data insertion
335 | }
336 | else if(a[0] == errNoSuchTableExist[0] || a[0] == SelectTheDatabase[0])
337 | {
338 | return a[0]; //error if table doesnt exist or database not selected
339 | }
340 | else
341 | {
342 | return insertIntoTable(query[2],a); // return table creation
343 | }
344 | }
345 | else
346 | {
347 | // else part of insert query
348 | return ErrSyntaxInsertQuery[0];
349 | }
350 | }
351 | else if(syntaxCompare(query[1],column))
352 | {
353 | //add col/column into @
354 | if(syntaxCompare(query[2],into))
355 | {
356 | if(syntaxCompare(query[4],colSymbol))
357 | {
358 | std::vector a;
359 |
360 | for(int i=5;i < query_size;i++)
361 | {
362 | a.insert(a.end(),query[i]);
363 | }
364 |
365 | return addColumn(query[3],a);
366 | }
367 | else
368 | {
369 | return ErrSyntaxAddColumn[0];
370 | }
371 | }
372 | else
373 | {
374 | return ErrSyntaxAddColumn[0];
375 | }
376 | }
377 | else
378 | {
379 | // else part of create query
380 | return ErrSyntaxInsertQuery[0];
381 | }
382 | }
383 | else
384 | {
385 | return inSufficientWordIninsertSyntax[0];
386 | }
387 | }
388 | else if(syntaxCompare(query[0],update))
389 | {
390 | if(query_size > 6)
391 | {
392 | if(syntaxCompare(query[1],colSymbol))
393 | {
394 | if(syntaxCompare(query[3],setx))
395 | {
396 | std::map mx;
397 | StoreTempString = ""; // it will store the value for after where process
398 | //int j = 4; // index for after set keyword...
399 | std::regex fb("[a-z0-9_']{0,}");
400 | std::regex rl("[a-z0-9_ ]{1,}"); // regex for checking alphanumericals values
401 | std::regex rf("'[^']*'"); // checking the value which resides in ''
402 |
403 | std::string setString;
404 | std::vector strsep1;
405 | std::vector strsep2;
406 | std::vector strsep3;
407 | std::vector strsep;
408 |
409 | int j = 4; // again set the j=4 for operation
410 | while(!syntaxCompare(query[j],where))
411 | {
412 | setString += query[j] + " "; // stores the value in the string set .......... where
413 | j++; // increment j for the further process for getting index of j
414 | }
415 |
416 | filterRegexInstring(setString,strsep1,rf,-1); // it will filter with the regex and stores the value in the vector string
417 | filterRegexInstring(setString,strsep2,rf,0); // it will filter with the regex and stores the value in the vector string
418 | filterRegexInstring(setString,strsep3,rf,-1); // it will filter ' ' and gives the vector array without it
419 | nullRomoverFromVectorString(strsep1); // removes the null value from the vector
420 | nullRomoverFromVectorString(strsep2);
421 | nullRomoverFromVectorString(strsep3);
422 |
423 | for(auto & i : strsep1)
424 | {
425 | trim(i," ");
426 | }
427 |
428 | if(strsep1.size() >= strsep2.size())
429 | {
430 | for(int i=0 ; i(strsep1[i], string_quote_cutter(strsep2[i]))); // string_quote_cutter removes the quote from the string
472 | // stores the vector in the map
473 | }
474 | }
475 | else
476 | {
477 | return ErrUpdateQuerySyntax[0]; //error in update query syntax
478 | }
479 |
480 | j++; // increment to pass the 'where' into the query.
481 | for(int i = j; i @ $
526 | if(query_size == 7)
527 | {
528 | if(syntaxCompare(query[3],colSymbol)) //checks syntax for colsymbol '@'
529 | {
530 | if(syntaxCompare(query[5],pkey)) //checks syntax for primary key symbol '$'
531 | {
532 | return addForeignKey(query[2],query[4],query[6]); //calls addForeignKey method that takes column_name, table_name & primary_table_name
533 | }
534 | else
535 | {
536 | return ErrSyntaxForeignKey[0]; //foreign key syntax error
537 | }
538 | }
539 | else
540 | {
541 | return ErrSyntaxForeignKey[0]; //foreign key syntax error
542 | }
543 | }
544 | else
545 | {
546 | return ErrSyntaxForeignKey[0]; //foreign key syntax error
547 | }
548 | }
549 | else
550 | {
551 | return querySyntaxError[0]; // syntax error
552 | }
553 | }
554 | else
555 | {
556 | return querySyntaxError[0]; // syntax error
557 | }
558 | }
559 |
560 | #endif //OURDB_DATABASE_QUERY_PROCESS_H
561 |
--------------------------------------------------------------------------------
/OurDB_Database/select_module/mihir_select_module/SelectFuncForAll.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Mihir on 15-06-2021.
3 | //
4 |
5 | #ifndef OURDB_DATABASE_SELECTFUNCFORALL_H
6 | #define OURDB_DATABASE_SELECTFUNCFORALL_H
7 |
8 | #include "../../global_functions/globalFunctionForSelectQuery.h"
9 |
10 | //using namespace std;
11 | using ourdb = nlohmann::json;
12 |
13 | std::string SelectFuncForAll(std::string tablepath)
14 | {
15 | std::ifstream in(tablepath);
16 |
17 | ourdb coldata;
18 |
19 | in >> coldata;
20 |
21 | if(coldata["table_data"].size()>0)
22 | {
23 | std::vector colname; //vector string for col names
24 | std::vector> data; //vector of vector string for table data
25 |
26 | for (auto& x : coldata["records"]["col_names"].items())
27 | {
28 | colname.insert(colname.end(), string_quote_cutter(to_string(x.value()),'\"')); //col name inserted to vector colname
29 | }
30 |
31 | for(int i=0; i < coldata["table_data"].size();i++)
32 | {
33 | std::vector jval; //temporary vector to store value to add into vector of vector 'data'
34 | for(auto &j : coldata["table_data"][i].items())
35 | {
36 | jval.push_back(decryption(j.value())); //value pushed to vector of vector string 'data'
37 | }
38 | data.push_back(jval);
39 | }
40 |
41 | return SelectQueryStructureCreater(colname,data); //global func for select query
42 | }
43 | else
44 | return ErrNoDataFoundInTable[0]; //error if no data found in the table
45 | }
46 |
47 | #endif //OURDB_DATABASE_SELECTFUNCFORALL_H
48 |
--------------------------------------------------------------------------------
/OurDB_Database/select_module/mihir_select_module/SelectFuncForAllWithAdditionalFunc.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Micron on 18/06/2021.
3 | //
4 |
5 | #ifndef OURDB_DATABASE_SELECTFUNCFORALLWITHADDITIONALFUNC_H
6 | #define OURDB_DATABASE_SELECTFUNCFORALLWITHADDITIONALFUNC_H
7 |
8 | #include "../../global_functions/globalFunctionForSelectQuery.h"
9 |
10 | //using namespace std;
11 | using ourdb = nlohmann::json;
12 |
13 | std::string SelectFuncForAllwithAdditionalFunc(std::string tablepath ,std::string additionalFunc)
14 | {
15 |
16 | std::ifstream in(tablepath);
17 |
18 | ourdb coldata;
19 |
20 | in >> coldata;
21 |
22 | if(coldata["table_data"].size()>0)
23 | {
24 | std::vector colname; //vector string for col names
25 | std::vector> data; //vector of vector string for table data
26 |
27 | for (auto& x : coldata["records"]["col_names"].items())
28 | {
29 | colname.insert(colname.end(), string_quote_cutter(to_string(x.value()),'\"')); //col name inserted to vector colname
30 | }
31 |
32 | for(int i=0; i < coldata["table_data"].size();i++)
33 | {
34 | std::vector jval; //temporary vector to store value to add into vector of vector 'data'
35 | for(auto &j : coldata["table_data"][i].items())
36 | {
37 | jval.push_back(decryption(j.value())); //value pushed to vector of vector string 'data'
38 | }
39 | data.push_back(jval);
40 | }
41 |
42 |
43 | if(additionalFunc == "<")
44 | {
45 | ascending_sort(data);
46 | }
47 | else if(additionalFunc == ">")
48 | {
49 | descending_sort(data);
50 | }
51 |
52 | return SelectQueryStructureCreater(colname,data);
53 | }
54 | else
55 | return ErrNoDataFoundInTable[0];
56 | }
57 |
58 | #endif //OURDB_DATABASE_SELECTFUNCFORALLWITHADDITIONALFUNC_H
59 |
--------------------------------------------------------------------------------
/OurDB_Database/select_module/parth_select_module/SelectFuncForColWithAdditionalFunc.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Micron on 18/06/2021.
3 | //
4 |
5 | #ifndef OURDB_DATABASE_SELECTFUNCFORCOLWITHADDITIONALFUNC_H
6 | #define OURDB_DATABASE_SELECTFUNCFORCOLWITHADDITIONALFUNC_H
7 |
8 | std::string SelectFuncForColswithAdditionalFunc(std::string tablename ,std::string AdditionalFunc ,std::vector beforeat)
9 | {
10 | ourdb our1; // object of json
11 | std::fstream fs(tablename); // file pointer points to tablePath
12 | std::vector > data; //2d vector array...
13 | fs >> our1; // data of tablePath to json object..
14 | if(our1["table_data"].size() > 0)
15 | { // check whether there is data in table or not
16 |
17 | for(int k=0 ;k newvec; // create new string vector for storing single row data in it...
20 | for (int j = 0; j < beforeat.size(); j++)
21 | { // iterate through beforeat(column name) vector
22 | for (int i = 0; i < our1["records"]["col_names"].size(); i++)
23 | { //
24 |
25 | if(selectingSameColsMulTimes(beforeat)) //checks if same column is selected more than once
26 | {
27 | return ErrSelectSameColName[0];
28 | }
29 |
30 | if (our1["records"]["col_names"][i] == beforeat[j])
31 | { // it checks data are same in beforeat and json object
32 | std::string l = to_string(our1["records"]["col_index"][i]); // takes the value from column index ..
33 | newvec.insert(newvec.end(), decryption(our1["table_data"][k][l])); //insert decrypted data in newvec
34 | }
35 | }
36 |
37 | }
38 | data.push_back(newvec); // it will push beck data newvec into data vector..
39 | }
40 |
41 | if(AdditionalFunc == "<")
42 | {
43 | ascending_sort(data);
44 | }else if(AdditionalFunc == ">")
45 | {
46 | descending_sort(data);
47 | }
48 | return SelectQueryStructureCreater(beforeat,data); // it will return string.. function defined in global fun for select
49 | }
50 | else
51 | {
52 | return ErrNoDataFoundInTable[0];
53 | }
54 |
55 | }
56 |
57 | #endif //OURDB_DATABASE_SELECTFUNCFORCOLWITHADDITIONALFUNC_H
58 |
--------------------------------------------------------------------------------
/OurDB_Database/select_module/parth_select_module/SelectFuncForCols.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Mihir on 15-06-2021.
3 | //
4 |
5 | #include "../../global_functions/globalFunctionForSelectQuery.h"
6 |
7 |
8 | //using namespace std;
9 | using ourdb = nlohmann::json;
10 | #ifndef OURDB_DATABASE_SELECTFORCOLS_H
11 | #define OURDB_DATABASE_SELECTFORCOLS_H
12 |
13 | std::string SelectFuncForCols(std::string tablePath,std::vector beforeat)
14 | {
15 | ourdb our1; // object of json
16 | std::fstream fs(tablePath); // file pointer points to tablePath
17 | std::vector > data; //2d vector array...
18 | fs >> our1; // data of tablePath to json object..
19 | if(our1["table_data"].size() > 0)
20 | { // check whether there is data in table or not
21 |
22 | if(selectingSameColsMulTimes(beforeat)) //checks if same column is selected more than once
23 | {
24 | return ErrSelectSameColName[0];
25 | }
26 |
27 | for(int k=0 ;k newvec; // create new string vector for storing single row data in it...
30 | for (int j = 0; j < beforeat.size(); j++)
31 | {// iterate through beforeat(column name) vector
32 | for (int i = 0; i < our1["records"]["col_names"].size(); i++)
33 | { //
34 | if (our1["records"]["col_names"][i] == beforeat[j])
35 | { // it checks data are same in beforeat and json object
36 | std::string l = to_string(our1["records"]["col_index"][i]); // takes the value from column index ..
37 | newvec.insert(newvec.end(), decryption(our1["table_data"][k][l])); //insert decrypted data in newvec
38 | break;
39 | }
40 | }
41 | }
42 | data.push_back(newvec); // it will push beck data newvec into data vector..
43 | }
44 |
45 | return SelectQueryStructureCreater(beforeat,data); // it will return string.. function defined in global fun for select
46 | }
47 | else
48 | {
49 | return ErrNoDataFoundInTable[0];
50 | }
51 |
52 |
53 | }
54 |
55 | #endif //OURDB_DATABASE_SELECTFORCOLS_H
56 |
--------------------------------------------------------------------------------
/OurDB_Database/select_module/select_module.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Mihir on 15-06-2021.
3 | //
4 |
5 | #include "zeel_select_module/SelectFuncForAllWithWhere.h"
6 | #include "zeel_select_module/SelectFuncForColsWithWhere.h"
7 | #include "zeel_select_module/SelectFuncForAllWithWhereWithAdditionalFunc.h"
8 | #include "zeel_select_module/SelectFuncForColsWithWhereWithAdditionalFunc.h"
9 | #include "mihir_select_module/SelectFuncForAll.h"
10 | #include "parth_select_module/SelectFuncForCols.h"
11 | #include "parth_select_module/SelectFuncForColWithAdditionalFunc.h"
12 | #include "mihir_select_module/SelectFuncForAllWithAdditionalFunc.h"
13 |
14 | #ifndef OURDB_DATABASE_SELECT_MODULE_H
15 | #define OURDB_DATABASE_SELECT_MODULE_H
16 |
17 | // function for allocating select query
18 | std::string SelectQuery(std::vector query)
19 | {
20 | // check whether database is selected or not
21 | if(!(databaseSelectGlobal.empty()))
22 | {
23 | // string for after @ symbol
24 | std::string afterselect = "";
25 |
26 | // check for @ symbol
27 | if(query[1]==colSymbol[0])
28 | {
29 | return ErrAtSymbol[0];
30 | }
31 |
32 | // regex for separation using @
33 | std::regex regexforat("^[^@]*@[^@]*$");
34 |
35 | // add space in after select word
36 | for(int i=1;i beforeafterat; //vector string to return inserted data
49 | std::regex regexat("@");
50 |
51 | // will return unmatched vector string array
52 | filterRegexInstring(afterselect,beforeafterat,regexat,-1);
53 |
54 | // check before @ size
55 | if(beforeafterat.size()!=2)
56 | {
57 | return ErrSyntaxInSelectQuery[0];
58 | }
59 |
60 | // variable allocation for after and before @
61 | std::vector afterat;
62 | std::vector beforeat;
63 |
64 | std::regex regexspaceforat(" ");
65 |
66 | // will return unmatched values in terms of vector string array
67 | filterRegexInstring(beforeafterat[0],beforeat,regexspaceforat,-1);
68 | filterRegexInstring(beforeafterat[1],afterat,regexspaceforat,-1);
69 |
70 | // filter it out null values into vector string array
71 | for(int i=0;i> ourdb;
98 | int countforcolcheck = 0; //counter to check if select column name is present in table
99 |
100 | // regex for additional functions alt + 24 = ↑ and alt + 25 = ↓
101 | std::regex regexForConditionalOperation("[<>]{1}");
102 |
103 | // allocation of select query
104 | if(beforeat[0] == var_for_func_inselect[0] && beforeat.size()==1)
105 | {
106 | if(afterat.size()==1)
107 | {
108 | //select query for all data w/o where
109 | return SelectFuncForAll(tablename);
110 | }
111 | else if(afterat.size()==2)
112 | {
113 | if(regex_match(afterat[1],regexForConditionalOperation)==1)
114 | {
115 | //select query with where condition and function with additional function
116 | return SelectFuncForAllwithAdditionalFunc(tablename,afterat[1]);
117 | }
118 | else
119 | {
120 | return ErrSyntaxInSelectQuery[0];
121 | }
122 | }
123 | else if(afterat.size()>=3)
124 | {
125 | if(syntaxCompare(afterat[1],where))
126 | {
127 | //select query for all data with where
128 | return SelectFuncForAllWithWhere(afterat[0],afterat);
129 | }
130 | else if(regex_match(afterat[1],regexForConditionalOperation) && syntaxCompare(afterat[2],where))
131 | {
132 | //select query with where condition and function with additional function
133 | return SelectFuncForAllWithWhereWithAdditionalFunc(afterat[0],afterat[1],afterat);
134 | }
135 | else
136 | {
137 | return ErrSyntaxInSelectQuery[0];
138 | }
139 | }
140 | else
141 | {
142 | return ErrSyntaxInSelectQuery[0];
143 | }
144 |
145 | } //write code here in else-if statement to add more select statement functionalities
146 | else
147 | {
148 | // check columns into table
149 | for(auto &j : beforeat)
150 | {
151 | for(auto &i : ourdb["records"]["col_names"])
152 | {
153 | if(j == i)
154 | {
155 | countforcolcheck++;
156 | }
157 | }
158 | }
159 | if(countforcolcheck == beforeat.size())
160 | {
161 | if(afterat.size()==1)
162 | {
163 | //select query for cols data w/o where
164 | return SelectFuncForCols(tablename,beforeat);
165 | }
166 | else if(afterat.size()==2)
167 | {
168 | if(regex_match(afterat[1],regexForConditionalOperation))
169 | {
170 | //select query with where condition and function with additional function
171 | return SelectFuncForColswithAdditionalFunc(tablename,afterat[1],beforeat);
172 | }
173 | else
174 | {
175 | return ErrSyntaxInSelectQuery[0];
176 | }
177 | }
178 | else if(afterat.size()>=3)
179 | {
180 | if(syntaxCompare(afterat[1],where))
181 | {
182 | //select query for cols data with where
183 | return SelectFuncForColsWithWhere(afterat[0],beforeat,afterat);
184 | }
185 | else if(regex_match(afterat[1],regexForConditionalOperation) && syntaxCompare(afterat[2],where))
186 | {
187 | //select query with where condition and function with additional function
188 | return SelectFuncForColsWithWhereWithAdditionalFunc(afterat[0],afterat[1],beforeat,afterat);
189 | }
190 | else
191 | {
192 | return ErrSyntaxInSelectQuery[0];
193 | }
194 | }
195 | else
196 | {
197 | return ErrSyntaxInSelectQuery[0];
198 | }
199 | }
200 | else
201 | return ErrorColumnDoesNotMatchFromTable[0];
202 | }
203 |
204 | }
205 | else
206 | {
207 | return tableDoesNotExist[0];
208 | }
209 |
210 |
211 | }
212 | else
213 | {
214 | return SelectTheDatabase[0]; //select database error if database isn't selected
215 | }
216 | }
217 |
218 |
219 | #endif //OURDB_DATABASE_SELECT_MODULE_H
220 |
--------------------------------------------------------------------------------
/OurDB_Database/select_module/zeel_select_module/SelectFuncForAllWithWhere.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Mihir,zeel on 15-06-2021.
3 | //
4 |
5 | #include "../../global_functions/globalFunctionForSelectQuery.h"
6 |
7 | #ifndef OURDB_DATABASE_SELECTFUNCFORALLWITHWHERE_H
8 | #define OURDB_DATABASE_SELECTFUNCFORALLWITHWHERE_H
9 |
10 | std::string SelectFuncForAllWithWhere(std::string tablename,std::vector afterat)
11 | {
12 | //string for where condition
13 | std::string whereConditionString;
14 |
15 | // convert vector into string
16 | for(int i = 2 ; i < afterat.size(); i++ )
17 | {
18 | whereConditionString += afterat[i];
19 | }
20 |
21 | // string of index where condition mathed
22 | std::string indexies = globalFuncForWhereClouse(whereConditionString,tablename,2);
23 |
24 | // regex for onliy number
25 | std::regex regexForOnlyInt("[0-9]{1,}");
26 |
27 |
28 | if(regex_match(indexies,regexForOnlyInt))
29 | {
30 | //main logic
31 |
32 | std::string tablepath = databaseSavePath +"/"+ tablename +".Ourdb";
33 |
34 | std::ifstream in(tablepath);
35 |
36 | ourdb coldata;
37 |
38 | in >> coldata;
39 |
40 | std::vector ind;
41 |
42 | for(auto zeel : indexies)
43 | {
44 | ind.insert(ind.end(),std::to_string(zeel-48));
45 | }
46 |
47 | std::vector colname; //vector string for col names
48 | std::vector> data; //vector of vector string for table data
49 |
50 | for (auto& x : coldata["records"]["col_names"].items())
51 | {
52 | colname.insert(colname.end(), string_quote_cutter(to_string(x.value()),'\"')); //col name inserted to vector colname
53 | }
54 |
55 | for(int i=0; i < ind.size();i++)
56 | {
57 | std::vector jval; //temporary vector to store value to add into vector of vector 'data'
58 | for(auto &j : coldata["table_data"][stoi(ind[i])].items())
59 | {
60 | jval.push_back(decryption(j.value())); //value pushed to vector of vector string 'data'
61 | }
62 | data.push_back(jval);
63 | }
64 |
65 | return SelectQueryStructureCreater(colname,data); //global func for select query
66 | }
67 | else if (indexies == "")
68 | {
69 | // error no data found
70 | return ErrNoDataFoundInTable[0];
71 | }
72 | else
73 | {
74 | // it will give you an error
75 | return indexies;
76 | }
77 |
78 | }
79 |
80 | #endif //OURDB_DATABASE_SELECTFUNCFORALLWITHWHERE_H
81 |
--------------------------------------------------------------------------------
/OurDB_Database/select_module/zeel_select_module/SelectFuncForAllWithWhereWithAdditionalFunc.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Micron on 18/06/2021.
3 | //
4 |
5 | #ifndef OURDB_DATABASE_SELECTFUNCFORALLWITHWHEREWITHADDITIONALFUNC_H
6 | #define OURDB_DATABASE_SELECTFUNCFORALLWITHWHEREWITHADDITIONALFUNC_H
7 |
8 | std::string SelectFuncForAllWithWhereWithAdditionalFunc(std::string tablename,std::string additionalFunc ,std::vector afterat)
9 | {
10 | //string for where condition
11 | std::string whereConditionString;
12 |
13 | // convert vector into string
14 | for(int i = 3 ; i < afterat.size(); i++ )
15 | {
16 | whereConditionString += afterat[i];
17 | }
18 |
19 | // string of index where condition mathed
20 | std::string indexies = globalFuncForWhereClouse(whereConditionString,tablename,2);
21 |
22 | // regex for onliy number
23 | std::regex regexForOnlyInt("[0-9]{1,}");
24 |
25 |
26 | if(regex_match(indexies,regexForOnlyInt))
27 | {
28 | //main logic
29 |
30 | std::string tablepath = databaseSavePath +"/"+ tablename +".Ourdb";
31 |
32 | std::ifstream in(tablepath);
33 |
34 | ourdb coldata;
35 |
36 | in >> coldata;
37 |
38 | std::vector ind;
39 |
40 | for(auto zeel : indexies)
41 | {
42 | ind.insert(ind.end(),std::to_string(zeel-48));
43 | }
44 |
45 | std::vector colname; //vector string for col names
46 | std::vector> data; //vector of vector string for table data
47 |
48 | for (auto& x : coldata["records"]["col_names"].items())
49 | {
50 | colname.insert(colname.end(), string_quote_cutter(to_string(x.value()),'\"')); //col name inserted to vector colname
51 | }
52 |
53 | for(int i=0; i < ind.size();i++)
54 | {
55 | std::vector jval; //temporary vector to store value to add into vector of vector 'data'
56 | for(auto &j : coldata["table_data"][stoi(ind[i])].items())
57 | {
58 | jval.push_back(decryption(j.value())); //value pushed to vector of vector string 'data'
59 | }
60 | data.push_back(jval);
61 | }
62 |
63 | if(additionalFunc == "<")
64 | {
65 | ascending_sort(data);
66 | }
67 | else if(additionalFunc == ">")
68 | {
69 | descending_sort(data);
70 | }
71 |
72 | return SelectQueryStructureCreater(colname,data); //global func for select query
73 | }
74 | else if (indexies == "")
75 | {
76 | // error no data found
77 | return ErrNoDataFoundInTable[0];
78 | }
79 | else
80 | {
81 | // it will give you an error
82 | return indexies;
83 | }
84 |
85 | }
86 |
87 | #endif //OURDB_DATABASE_SELECTFUNCFORALLWITHWHEREWITHADDITIONALFUNC_H
88 |
--------------------------------------------------------------------------------
/OurDB_Database/select_module/zeel_select_module/SelectFuncForColsWithWhere.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Mihir,zeel on 15-06-2021.
3 | //
4 |
5 | #ifndef OURDB_DATABASE_SELECTFUNCFORCOLSWITHWHERE_H
6 | #define OURDB_DATABASE_SELECTFUNCFORCOLSWITHWHERE_H
7 |
8 | std::string SelectFuncForColsWithWhere(std::string tablename,std::vector beforeat,std::vector afterat)
9 | {
10 | //string for where condition
11 | std::string whereConditionString;
12 |
13 | // convert vector into string
14 | for(int i = 2 ; i < afterat.size(); i++ )
15 | {
16 | whereConditionString += afterat[i];
17 | }
18 |
19 | // string of index where condition mathed
20 | std::string indexies = globalFuncForWhereClouse(whereConditionString,tablename,2);
21 |
22 | // regex for onliy number
23 | std::regex regexForOnlyInt("[0-9]{0,}");
24 |
25 |
26 | if(regex_match(indexies,regexForOnlyInt))
27 | {
28 | if(selectingSameColsMulTimes(beforeat)) //checks if same column is selected more than once
29 | {
30 | return ErrSelectSameColName[0];
31 | }
32 |
33 | std::string tablepath = databaseSavePath +"/"+ tablename +".Ourdb";
34 |
35 | ourdb our1;
36 | std::fstream fs(tablepath);
37 | std::vector> data;
38 | std::string ml;
39 | fs >> our1;
40 |
41 | std::vector ind;
42 |
43 | for(auto zeel : indexies)
44 | {
45 | ind.insert(ind.end(),std::to_string(zeel-48));
46 | }
47 |
48 | for(int k=0 ;k newvec;
51 | for (int j = 0; j < beforeat.size(); j++) //loop for checking cols that are specified by user before '@'
52 | {
53 | for (int i = 0; i < our1["records"]["col_names"].size(); i++) //loop for checking col names with col indexes
54 | {
55 | if (our1["records"]["col_names"][i] == beforeat[j]) //checks user specified col with col in table
56 | {
57 | std::string l = to_string(our1["records"]["col_index"][i]); // takes the value from column index ..
58 | newvec.insert(newvec.end(), decryption(our1["table_data"][stoi(ind[k])][l]));
59 | }
60 | }
61 | }
62 | data.push_back(newvec); //inserting vector 'newvec' into vector of vector 'data'
63 | }
64 |
65 | return SelectQueryStructureCreater(beforeat,data);
66 | }
67 | else if (indexies == "")
68 | {
69 | // error no data found
70 | return ErrNoDataFoundInTable[0];
71 | }
72 | else
73 | {
74 | // it will give you an error
75 | return indexies;
76 | }
77 |
78 | }
79 |
80 | #endif //OURDB_DATABASE_SELECTFUNCFORCOLSWITHWHERE_H
81 |
--------------------------------------------------------------------------------
/OurDB_Database/select_module/zeel_select_module/SelectFuncForColsWithWhereWithAdditionalFunc.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Micron on 18/06/2021.
3 | //
4 |
5 | #ifndef OURDB_DATABASE_SELECTFUNCFORCOLSWITHWHEREWITHADDITIONALFUNC_H
6 | #define OURDB_DATABASE_SELECTFUNCFORCOLSWITHWHEREWITHADDITIONALFUNC_H
7 |
8 | std::string SelectFuncForColsWithWhereWithAdditionalFunc(std::string tablename,std::string additionalFunc ,std::vector beforeat , std::vector afterat)
9 | {
10 | //string for where condition
11 | std::string whereConditionString;
12 |
13 | // convert vector into string
14 | for(int i = 3 ; i < afterat.size(); i++ )
15 | {
16 | whereConditionString += afterat[i];
17 | }
18 |
19 | // string of index where condition mathed
20 | std::string indexies = globalFuncForWhereClouse(whereConditionString,tablename,2);
21 |
22 | // regex for onliy number
23 | std::regex regexForOnlyInt("[0-9]{0,}");
24 |
25 |
26 | if(regex_match(indexies,regexForOnlyInt))
27 | {
28 | if(selectingSameColsMulTimes(beforeat)) //checks if same column is selected more than once
29 | {
30 | return ErrSelectSameColName[0];
31 | }
32 |
33 | std::string tablepath = databaseSavePath +"/"+ tablename +".Ourdb";
34 |
35 | ourdb our1;
36 | std::fstream fs(tablepath);
37 | std::vector > data;
38 | std::string ml;
39 | fs >> our1;
40 |
41 | std::vector ind;
42 |
43 | for(auto zeel : indexies)
44 | {
45 | ind.insert(ind.end(),std::to_string(zeel-48));
46 | }
47 |
48 | for(int k=0 ;k newvec;
51 | for (int j = 0; j < beforeat.size(); j++) //loop for checking cols that are specified by user before '@'
52 | {
53 | for (int i = 0; i < our1["records"]["col_names"].size(); i++) //loop for checking col names with col indexes
54 | {
55 | if (our1["records"]["col_names"][i] == beforeat[j]) //checks user specified col with col in table
56 | {
57 | std::string l = to_string(our1["records"]["col_index"][i]); // takes the value from column index ..
58 | newvec.insert(newvec.end(), decryption(our1["table_data"][stoi(ind[k])][l]));
59 | }
60 | }
61 | }
62 | data.push_back(newvec); //inserting vector 'newvec' into vector of vector 'data'
63 | }
64 |
65 | if(additionalFunc == "<")
66 | {
67 | ascending_sort(data);
68 | }
69 | else if(additionalFunc == ">")
70 | {
71 | descending_sort(data);
72 | }
73 |
74 | return SelectQueryStructureCreater(beforeat,data);
75 | }
76 | else if (indexies == "")
77 | {
78 | // error no data found
79 | return ErrNoDataFoundInTable[0];
80 | }
81 | else
82 | {
83 | // it will give you an error
84 | return indexies;
85 | }
86 | }
87 |
88 | #endif //OURDB_DATABASE_SELECTFUNCFORCOLSWITHWHEREWITHADDITIONALFUNC_H
89 |
--------------------------------------------------------------------------------
/OurDB_Database/syntax.txt:
--------------------------------------------------------------------------------
1 |
2 | ==================== syntax format ================================================
3 | // - syntax for header file source
4 |
5 | ====================================================================================
6 |
7 | 1. create queries :-
8 |
9 | words for create :
10 | ->create
11 | ->make
12 |
13 | --------------------------------------------------------
14 | -> create database // -> in parth module
15 | -> create table @ ...
16 |
17 |
18 | 2. insert queries :-
19 |
20 | words for insert :
21 | ->insert
22 | ->add
23 |
24 | --------------------------------------------------------------------------
25 | -> insert into @ '' '' .....
26 | -> add col/column into @
27 |
28 |
29 |
30 | 3. update queries :-
31 |
32 | words for update :
33 | -> update
34 |
35 | ------------------------------------------------------------------------------
36 | update @ set/put '' where (=|!)
37 |
38 |
39 |
40 |
41 |
42 | 4. delete queries :-
43 |
44 | words for delete
45 | ->delete
46 | ->destroy
47 |
48 | -------------------------------------------------------------
49 | -> delete database // parth module
50 | -> delete table // zeel module
51 | -> delete @ where (=/!) (&/|) (=/!)