JOIN funcionando
This commit is contained in:
parent
a684fa3fdb
commit
d18b5f2efd
2
main.py
2
main.py
|
@ -7,7 +7,7 @@ def main():
|
||||||
print("Bem vindo ao SGBD")
|
print("Bem vindo ao SGBD")
|
||||||
print("Digite a pasta onde está os arquivos CSV:")
|
print("Digite a pasta onde está os arquivos CSV:")
|
||||||
#csv_folder = input()
|
#csv_folder = input()
|
||||||
csv_folder = "/mnt/c/Users/jose/Desktop/jcSQL-main/source"
|
csv_folder = "./source"
|
||||||
|
|
||||||
tables = {}
|
tables = {}
|
||||||
|
|
||||||
|
|
42
sql.py
42
sql.py
|
@ -38,19 +38,7 @@ class SQL:
|
||||||
# parse TABLE
|
# parse TABLE
|
||||||
table = self.tables[query_parts[3]]
|
table = self.tables[query_parts[3]]
|
||||||
|
|
||||||
# parse SELECT COLUMNS
|
# join columns
|
||||||
column_list = query_parts[1].split(",")
|
|
||||||
for i in range(len(column_list)):
|
|
||||||
column_list[i] = column_list[i].strip()
|
|
||||||
|
|
||||||
if column_list[0] == '*':
|
|
||||||
column_list = table.columns
|
|
||||||
|
|
||||||
# print the columns
|
|
||||||
print(', '.join(column_list))
|
|
||||||
print('-' * 20)
|
|
||||||
|
|
||||||
# print the rows
|
|
||||||
tables_columns = table.columns
|
tables_columns = table.columns
|
||||||
tables_rows = table.rows
|
tables_rows = table.rows
|
||||||
|
|
||||||
|
@ -58,19 +46,29 @@ class SQL:
|
||||||
join_table = join_stmt[0]
|
join_table = join_stmt[0]
|
||||||
join_column = join_stmt[1]
|
join_column = join_stmt[1]
|
||||||
|
|
||||||
for row in table.rows:
|
for i in range(len(tables_rows)):
|
||||||
column_index = table.columns.index(join_column)
|
for j in range(len(join_table.rows)):
|
||||||
row_value = row[column_index]
|
row_column_index = table.columns.index(join_column)
|
||||||
|
join_row_column_index = join_table.columns.index(join_column)
|
||||||
|
|
||||||
for join_row in join_table.rows:
|
if tables_rows[i][row_column_index] == join_table.rows[j][join_row_column_index]:
|
||||||
join_column_index = join_table.columns.index(join_column)
|
tables_rows[i] += join_table.rows[j]
|
||||||
join_row_value = join_row[join_column_index]
|
|
||||||
|
|
||||||
if row_value == join_row_value:
|
|
||||||
tables_rows.append(row + join_row)
|
|
||||||
|
|
||||||
tables_columns = table.columns + join_table.columns
|
tables_columns = table.columns + join_table.columns
|
||||||
|
|
||||||
|
# parse SELECT COLUMNS
|
||||||
|
column_list = query_parts[1].split(",")
|
||||||
|
for i in range(len(column_list)):
|
||||||
|
column_list[i] = column_list[i].strip()
|
||||||
|
|
||||||
|
if column_list[0] == '*':
|
||||||
|
column_list = tables_columns
|
||||||
|
|
||||||
|
# print the columns
|
||||||
|
print(', '.join(column_list))
|
||||||
|
print('-' * 20)
|
||||||
|
|
||||||
|
# print the rows
|
||||||
for row in tables_rows:
|
for row in tables_rows:
|
||||||
if where_filter is not None:
|
if where_filter is not None:
|
||||||
column_index = tables_columns.index(where_filter[0])
|
column_index = tables_columns.index(where_filter[0])
|
||||||
|
|
Loading…
Reference in New Issue