Skip to content

Commit

Permalink
Removed Insert statements from schema
Browse files Browse the repository at this point in the history
  • Loading branch information
suyashgautam committed Jan 12, 2024
1 parent 0531d74 commit b11cbde
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
22 changes: 0 additions & 22 deletions src/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,28 +98,6 @@
}
]

def save_uploaded_file(uploaded_file, target_folder, new_filename):
if not os.path.exists(target_folder):
os.makedirs(target_folder)

target_file_path = os.path.join(target_folder, secure_filename(new_filename))
with open(target_file_path, 'wb') as f:
f.write(uploaded_file)

return target_file_path

def read_file(file_path):
try:
print(os.getcwd(), file_path)
with open(file_path, 'r') as file:
content = file.read()
return content
except Exception as e:
logging.error("ERROR: {e}")
print(f"ERROR: {e}, {e.print_exc()}")
return ""


def get_tables_from_schema_id(G):
tables_list = []
for node, attrs in G.nodes(data=True):
Expand Down
28 changes: 27 additions & 1 deletion src/server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,30 @@ def extract_sql_query(input_text):
# Join multiple SQL queries into a single string
result = ' '.join(sql_queries)

return result
return result

def remove_insert_statements(sql_content):

# Split the SQL content into statements
statements = sql_content.split(b';')

# Filter out INSERT INTO statements
filtered_statements = [statement.strip() for statement in statements if not statement.strip().startswith(b'INSERT INTO')]

# Join the filtered statements back into a single string
filtered_content = b';\n\n'.join(filtered_statements)

return filtered_content

def save_uploaded_file(schema_file, target_folder, new_filename):

if not os.path.exists(target_folder):
os.makedirs(target_folder)

filtered_content = remove_insert_statements(schema_file)

target_file_path = os.path.join(target_folder, secure_filename(new_filename))
with open(target_file_path, 'wb') as f:
f.write(filtered_content)

return target_file_path

0 comments on commit b11cbde

Please sign in to comment.