Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix escape for column default values #35

Merged
merged 1 commit into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix escape for column default values
  • Loading branch information
johnnyfish committed Aug 25, 2024
commit da972738afbc6d68d652af4a2b2cdae219ca04b1
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
Loading