Skip to content

Commit e50400e

Browse files
committed
handle ; in commented code
1 parent 90af0bb commit e50400e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

pum/utils/execute_sql.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ def execute_sql(
3535
)
3636
with open(sql) as file:
3737
sql_content = file.read()
38+
# Remove SQL comments
39+
def remove_sql_comments(sql):
40+
# Remove multiline comments (/* ... */)
41+
sql = re.sub(r'/\*.*?\*/', '', sql, flags=re.DOTALL)
42+
# Remove single-line comments (-- ...)
43+
sql = re.sub(r'--.*', '', sql)
44+
return sql
45+
sql_content = remove_sql_comments(sql_content)
3846
if parameters:
3947
for key, value in parameters.items():
4048
sql_content = sql_content.replace(f"{{{{ {key} }}}}", str(value))
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11

22
ALTER TABLE pum_test_data.some_table RENAME COLUMN created_date TO created;
33
COMMENT ON COLUMN pum_test_data.some_table.created IS 'A comment with semi column; , quotes '' and a backslash \\';
4+
5+
-- commented code that has ; in it
6+
/* ALTER TABLE mytable ADD COLUMN newcol varchar (16);
7+
ALTER TABLE mytable ADD COLUMN newcol2 varchar (16); */

0 commit comments

Comments
 (0)