1-1
This commit is contained in:
		
							
								
								
									
										16
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								main.py
									
									
									
									
									
								
							| @@ -2,16 +2,21 @@ import os | ||||
|  | ||||
| from table import Table | ||||
| from sql import SQL | ||||
| import mysql.connector | ||||
|  | ||||
| def main(): | ||||
|     print("Bem vindo ao SGBD") | ||||
|     print("Digite a pasta onde está os arquivos CSV:") | ||||
|     print("Bem-vindo!") | ||||
|     print("Deseja utilizar um banco de dados (BD) ou um arquivo .csv (CSV)?") | ||||
|     escolha = input() | ||||
|  | ||||
|     if escolha == "CSV": | ||||
|         print("Digite a pasta onde estão os arquivos CSV:") | ||||
|         #csv_folder = input() | ||||
|         csv_folder = "./source" | ||||
|  | ||||
|         tables = {} | ||||
|  | ||||
|     # get all csv files in the folder | ||||
|         # Seleciona todos o csv presentes na pasta | ||||
|         for file in os.listdir(csv_folder): | ||||
|             if file.endswith(".csv"): | ||||
|                 table_name = file.split(".")[0] | ||||
| @@ -34,5 +39,10 @@ def main(): | ||||
|  | ||||
|             print() | ||||
|  | ||||
|     elif escolha == "BD": | ||||
|         print("BD") | ||||
|     else: | ||||
|         print("Fora do intervalo!") | ||||
|  | ||||
| if __name__ == "__main__": | ||||
|     main() | ||||
							
								
								
									
										14
									
								
								sql.py
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								sql.py
									
									
									
									
									
								
							| @@ -8,28 +8,28 @@ class SQL: | ||||
|     def __str__(self) -> str: | ||||
|         pass | ||||
|  | ||||
|     # SELECIONAR * DE tabela | ||||
|     # ISCOLHE * DE tabela | ||||
|     def execute(self): | ||||
|         query_parts = self.query.split(" ") | ||||
|  | ||||
|         if query_parts[0] == "SELECIONAR": | ||||
|         if query_parts[0] == "ISCOLHE": | ||||
|             self.select(query_parts) | ||||
|         else: | ||||
|             pass | ||||
|  | ||||
|     # SELECIONAR * DE tabela JUNTAR tabela2 coluna ONDE coluna = valor | ||||
|     # ISCOLHE * DE tabela AJUNTAR tabela2 coluna DONDE coluna = valor | ||||
|     def select(self, query_parts: list) -> None: | ||||
|         where_filter = None | ||||
|         join_stmt = None | ||||
|  | ||||
|         if "JUNTAR" in query_parts: | ||||
|             index = query_parts.index("JUNTAR") | ||||
|         if "AJUNTAR" in query_parts: | ||||
|             index = query_parts.index("AJUNTAR") | ||||
|             join_table = query_parts[index + 1] | ||||
|             join_column = query_parts[index + 2] | ||||
|             join_stmt = [self.tables[join_table], join_column] | ||||
|  | ||||
|         if "ONDE" in query_parts: | ||||
|             index = query_parts.index("ONDE") | ||||
|         if "DONDE" in query_parts: | ||||
|             index = query_parts.index("DONDE") | ||||
|             where_filter_column = query_parts[index + 1] | ||||
|             where_filter_operator = query_parts[index + 2] | ||||
|             where_filter_value = query_parts[index + 3] | ||||
|   | ||||
		Reference in New Issue
	
	Block a user