Skip to content

Commit

Permalink
fix escape for column default values
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyfish committed Aug 25, 2024
1 parent a803988 commit da97273
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/lib/data/import-metadata/scripts/maria-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const mariaDBQuery = `WITH fk_info as (
END,
',"ordinal_position":"', cols.ordinal_position,
'","nullable":', IF(cols.is_nullable = 'YES', 'true', 'false'),
',"default":"', IFNULL(cols.column_default, ''),
',"default":"', IFNULL(REPLACE(cols.column_default, '"', '\\"'), ''),
'","collation":"', IFNULL(cols.collation_name, ''), '"}'
)))))
), indexes as (
Expand Down
2 changes: 1 addition & 1 deletion src/lib/data/import-metadata/scripts/mysql-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const mySQLQuery = `WITH fk_info as (
END,
',"ordinal_position":"', cols.ordinal_position,
'","nullable":', IF(cols.is_nullable = 'YES', 'true', 'false'),
',"default":"', IFNULL(cols.column_default, ''),
',"default":"', IFNULL(REPLACE(cols.column_default, '"', '\\"'), ''),
'","collation":"', IFNULL(cols.collation_name, ''), '"}'
)))))
), indexes as (
Expand Down
2 changes: 1 addition & 1 deletion src/lib/data/import-metadata/scripts/postgres-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ cols as (
ELSE 'null'
END,
',"nullable":', case when (cols.IS_NULLABLE = 'YES') then 'true' else 'false' end,
',"default":"', COALESCE(cols.column_default, ''),
',"default":"', COALESCE(replace(cols.column_default, '"', E'\\"'), ''),
'","collation":"', coalesce(cols.COLLATION_NAME, ''), '"}')), ',') as cols_metadata
from information_schema.columns cols
where cols.table_schema not in ('information_schema', 'pg_catalog')
Expand Down
2 changes: 1 addition & 1 deletion src/lib/data/import-metadata/scripts/sqlite-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export const sqliteQuery = `WITH fk_info AS (
END
ELSE 'null'
END,
'default', COALESCE(p.dflt_value, '')
'default', COALESCE(REPLACE(p.dflt_value, '"', '\\"'), '')
)
) AS cols_metadata
FROM
Expand Down
2 changes: 1 addition & 1 deletion src/lib/data/import-metadata/scripts/sqlserver-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ cols AS (
', "nullable": "' +
CASE WHEN cols.IS_NULLABLE = 'YES' THEN 'true' ELSE 'false' END +
'", "default": "' +
COALESCE(CAST(cols.COLUMN_DEFAULT AS NVARCHAR(MAX)), '') +
COALESCE(REPLACE(CAST(cols.COLUMN_DEFAULT AS NVARCHAR(MAX)), '"', '\\"'), '') +
'", "collation": "' +
COALESCE(cols.COLLATION_NAME, '') +
'"}')
Expand Down

0 comments on commit da97273

Please sign in to comment.