Skip to content
76 changes: 76 additions & 0 deletions src/main/resources/db/migration/dbiemr/V78__rmnch_new_column.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
USE db_iemr;

SET @column_exists = (
SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 't_delivery_outcome'

Check failure on line 7 in src/main/resources/db/migration/dbiemr/V78__rmnch_new_column.sql

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal 4 times.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Amrit-DB&issues=AZ5FbBEXIO9wjLUi9kce&open=AZ5FbBEXIO9wjLUi9kce&pullRequest=127
AND COLUMN_NAME = 'gestational_age_at_delivery'
);

SET @sql = IF(@column_exists = 0,
'ALTER TABLE t_delivery_outcome

Check failure on line 12 in src/main/resources/db/migration/dbiemr/V78__rmnch_new_column.sql

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

An illegal character with code point 10 was found in this literal.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Amrit-DB&issues=AZ5FbBEWIO9wjLUi9kcZ&open=AZ5FbBEWIO9wjLUi9kcZ&pullRequest=127
ADD COLUMN gestational_age_at_delivery VARCHAR(255) DEFAULT NULL',
'SELECT "Column already exists"'

Check failure on line 14 in src/main/resources/db/migration/dbiemr/V78__rmnch_new_column.sql

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal 4 times.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Amrit-DB&issues=AZ5FbBEXIO9wjLUi9kcd&open=AZ5FbBEXIO9wjLUi9kcd&pullRequest=127
);
Comment on lines +11 to +15

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚑ Quick win

Fix Sonar-blocking multiline SQL string literals.

Line 12, Line 31, Line 50, and Line 69 use multiline quoted literals that are being flagged as illegal character (code point 10), which is currently failing analysis checks.

Proposed fix
-SET `@sql` = IF(`@column_exists` = 0,
-    'ALTER TABLE t_delivery_outcome
-        ADD COLUMN gestational_age_at_delivery VARCHAR(255) DEFAULT NULL',
+SET `@sql` = IF(`@column_exists` = 0,
+    'ALTER TABLE t_delivery_outcome ADD COLUMN gestational_age_at_delivery VARCHAR(255) DEFAULT NULL',
     'SELECT "Column already exists"'
 );
@@
-SET `@sql` = IF(`@column_exists` = 0,
-    'ALTER TABLE t_delivery_outcome
-        ADD COLUMN delivery_conducted_by VARCHAR(255) DEFAULT NULL',
+SET `@sql` = IF(`@column_exists` = 0,
+    'ALTER TABLE t_delivery_outcome ADD COLUMN delivery_conducted_by VARCHAR(255) DEFAULT NULL',
     'SELECT "Column already exists"'
 );
@@
-SET `@sql` = IF(`@column_exists` = 0,
-    'ALTER TABLE t_delivery_outcome
-        ADD COLUMN modeOf_delivery VARCHAR(255) DEFAULT NULL',
+SET `@sql` = IF(`@column_exists` = 0,
+    'ALTER TABLE t_delivery_outcome ADD COLUMN modeOf_delivery VARCHAR(255) DEFAULT NULL',
     'SELECT "Column already exists"'
 );
@@
-SET `@sql` = IF(`@column_exists` = 0,
-    'ALTER TABLE t_delivery_outcome
-        ADD COLUMN mother_condition VARCHAR(255) DEFAULT NULL',
+SET `@sql` = IF(`@column_exists` = 0,
+    'ALTER TABLE t_delivery_outcome ADD COLUMN mother_condition VARCHAR(255) DEFAULT NULL',
     'SELECT "Column already exists"'
 );

Also applies to: 30-34, 49-53, 68-72

🧰 Tools
πŸͺ› GitHub Check: SonarCloud Code Analysis

[failure] 14-14: Define a constant instead of duplicating this literal 4 times.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Amrit-DB&issues=AZ5FbBEXIO9wjLUi9kcd&open=AZ5FbBEXIO9wjLUi9kcd&pullRequest=127


[failure] 12-12: An illegal character with code point 10 was found in this literal.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Amrit-DB&issues=AZ5FbBEWIO9wjLUi9kcZ&open=AZ5FbBEWIO9wjLUi9kcZ&pullRequest=127

πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/resources/db/migration/dbiemr/V78__rmnch_new_column.sql` around
lines 11 - 15, The SQL migration uses multiline string literals assigned to `@sql`
(e.g., the ALTER TABLE 'ADD COLUMN gestational_age_at_delivery ...' block) which
include newline characters and trigger Sonar illegal character flags; replace
each multiline quoted literal (the four occurrences that build ALTER TABLE ...
ADD COLUMN or the 'SELECT "Column already exists"' alternatives) with a
single-line string constructed without literal newlines (for example use CONCAT
or explicit string concatenation so the final SQL has no embedded code point
10), ensuring you update the same variable `@sql` and keep the conditional
IF(`@column_exists` = 0) logic and the same table/column identifiers
(t_delivery_outcome, gestational_age_at_delivery) intact.


PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;


SET @column_exists = (
SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 't_delivery_outcome'
AND COLUMN_NAME = 'delivery_conducted_by'
);

SET @sql = IF(@column_exists = 0,
'ALTER TABLE t_delivery_outcome

Check failure on line 31 in src/main/resources/db/migration/dbiemr/V78__rmnch_new_column.sql

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

An illegal character with code point 10 was found in this literal.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Amrit-DB&issues=AZ5FbBEXIO9wjLUi9kca&open=AZ5FbBEXIO9wjLUi9kca&pullRequest=127
ADD COLUMN delivery_conducted_by VARCHAR(255) DEFAULT NULL',
'SELECT "Column already exists"'
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;


SET @column_exists = (
SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 't_delivery_outcome'
AND COLUMN_NAME = 'modeOf_delivery'
);

SET @sql = IF(@column_exists = 0,
'ALTER TABLE t_delivery_outcome

Check failure on line 50 in src/main/resources/db/migration/dbiemr/V78__rmnch_new_column.sql

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

An illegal character with code point 10 was found in this literal.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Amrit-DB&issues=AZ5FbBEXIO9wjLUi9kcb&open=AZ5FbBEXIO9wjLUi9kcb&pullRequest=127
ADD COLUMN modeOf_delivery VARCHAR(255) DEFAULT NULL',
'SELECT "Column already exists"'
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;


SET @column_exists = (
SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 't_delivery_outcome'
AND COLUMN_NAME = 'mother_condition'
);

SET @sql = IF(@column_exists = 0,
'ALTER TABLE t_delivery_outcome

Check failure on line 69 in src/main/resources/db/migration/dbiemr/V78__rmnch_new_column.sql

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

An illegal character with code point 10 was found in this literal.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Amrit-DB&issues=AZ5FbBEXIO9wjLUi9kcc&open=AZ5FbBEXIO9wjLUi9kcc&pullRequest=127
ADD COLUMN mother_condition VARCHAR(255) DEFAULT NULL',
'SELECT "Column already exists"'
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
Loading