42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
|
from table import Table
|
||
|
|
||
|
class SQL:
|
||
|
def __init__(self, tables: dict, query: str) -> None:
|
||
|
self.tables = tables
|
||
|
self.query = query.replace(";", "")
|
||
|
|
||
|
def __str__(self) -> str:
|
||
|
pass
|
||
|
|
||
|
# SELECIONAR * DE tabela
|
||
|
def execute(self):
|
||
|
query_parts = self.query.split(" ")
|
||
|
|
||
|
if query_parts[0] == "SELECIONAR":
|
||
|
self.select(query_parts)
|
||
|
else:
|
||
|
pass
|
||
|
|
||
|
# SELECIONAR * DE tabela ONDE coluna = valor JUNTAR tabela2 coluna
|
||
|
def select(self, query_parts: list) -> None:
|
||
|
where_filter = None
|
||
|
join_stmt = None
|
||
|
|
||
|
if "ONDE" in query_parts:
|
||
|
index = query_parts.index("ONDE")
|
||
|
where_filter_column = query_parts[index + 1]
|
||
|
where_filter_operator = query_parts[index + 2]
|
||
|
where_filter_value = query_parts[index + 3]
|
||
|
where_filter = [where_filter_column, where_filter_operator, where_filter_value]
|
||
|
|
||
|
if "JUNTAR" in query_parts:
|
||
|
index = query_parts.index("JUNTAR")
|
||
|
join_table = query_parts[index + 1]
|
||
|
join_column = query_parts[index + 2]
|
||
|
join_stmt = [self.tables[join_table], join_column]
|
||
|
|
||
|
table = self.tables[query_parts[3]]
|
||
|
table.print_columns(table.columns,
|
||
|
where_filter=where_filter,
|
||
|
join_stmt=join_stmt)
|