Skip to content

Commit 4a787ae

Browse files
committed
fix comments
1 parent e804d23 commit 4a787ae

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

pum/utils/execute_sql.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ def remove_sql_comments(sql):
3939
# Remove multiline comments (/* ... */)
4040
sql = re.sub(r'/\*.*?\*/', '', sql, flags=re.DOTALL)
4141
# Remove single-line comments (-- ...)
42-
sql = re.sub(r'--.*?(\r\n|\r|\n)', '', sql)
42+
sql = re.sub(r'(?m)(^|;)\s*--.*?(\r\n|\r|\n)', r'\1', sql)
4343
return sql
4444
sql_content = remove_sql_comments(sql_content)
45-
print(sql_content)
4645
if parameters:
4746
for key, value in parameters.items():
4847
sql_content = sql_content.replace(f"{{{{ {key} }}}}", str(value))

test/data/complex_files_content/changelogs/1.2.3/create_northwind.sql

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ CREATE TABLE pum_test_data.some_table (
88
amount NUMERIC(10,2)
99
);
1010

11-
COMMENT ON COLUMN pum_test_data.some_table.created_date IS 'A comment with semi column; , quotes '' and a backslash \\';
11+
COMMENT ON COLUMN pum_test_data.some_table.created_date IS 'A comment with semi column; , quotes '' and a backslash \\ and -- dashes';
1212

1313
-- commented code that has ; in it
14-
/* ALTER TABLE mytable ADD COLUMN newcol varchar (16);
14+
15+
/* ALTER TABLE mytable ADD COLUMN newcolvarchar (16);
1516
ALTER TABLE mytable ADD COLUMN newcol2 varchar (16); */
1617

18+
/* -- ; ' */
19+
1720
-- This is a comment with a semicolon; and a quote ' and a backslash \
1821

1922
COMMENT ON TABLE pum_test_data.some_table IS 'Une table écrite en français avec un commentaire contenant un point-virgule ; et une apostrophe '' et un antislash \\';

0 commit comments

Comments
 (0)