fix: update import queries and fix bug for MySQL & MariaDB

This commit is contained in:
johnnyfish
2024-09-02 13:55:09 +03:00
committed by Jonathan Fishner
parent 0a11b6f883
commit 89e0cddd42
5 changed files with 9 additions and 9 deletions

View File

@@ -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(REPLACE(cols.column_default, '"', '\\"'), ''),
',"default":"', IFNULL(REPLACE(REPLACE(cols.column_default, '\\\\', ''), '"', '\\"'), ''),
'","collation":"', IFNULL(cols.collation_name, ''), '"}'
)))))
), indexes as (
@@ -125,6 +125,6 @@ export const mariaDBQuery = `WITH fk_info as (
'], "tables":[',IFNULL(@tbls,''),
'], "views":[',IFNULL(@views,''),
'], "database_name": "', DATABASE(),
'", "version": "', VERSION(), '"}') AS CHAR) AS ''
'", "version": "', VERSION(), '"}') AS CHAR) AS metadata_json_to_import
FROM fk_info, pk_info, cols, indexes, tbls, views);
`;

View File

@@ -80,7 +80,7 @@ export const getMySQLQuery = (
END,
',"ordinal_position":"', cols.ordinal_position,
'","nullable":', IF(cols.is_nullable = 'YES', 'true', 'false'),
',"default":"', IFNULL(REPLACE(cols.column_default, '"', '\\"'), ''),
',"default":"', IFNULL(REPLACE(REPLACE(cols.column_default, '\\\\', ''), '"', 'ֿֿֿ\\"'), ''),
'","collation":"', IFNULL(cols.collation_name, ''), '"}'
)))))
), indexes as (
@@ -135,7 +135,7 @@ export const getMySQLQuery = (
'], "tables":[',IFNULL(@tbls,''),
'], "views":[',IFNULL(@views,''),
'], "database_name": "', DATABASE(),
'", "version": "', VERSION(), '"}') AS CHAR) AS ''
'", "version": "', VERSION(), '"}') AS CHAR) AS metadata_json_to_import
FROM fk_info, pk_info, cols, indexes, tbls, views);
`;
@@ -196,7 +196,7 @@ export const getMySQLQuery = (
',"scale":', IFNULL(cols.numeric_scale, 'null'), '}'), 'null'),
',"ordinal_position":"', cols.ordinal_position,
'","nullable":', IF(cols.is_nullable = 'YES', 'true', 'false'),
',"default":"', IFNULL(REPLACE(cols.column_default, '"', '\\"'), ''),
',"default":"', IFNULL(REPLACE(REPLACE(cols.column_default, '\\\\', ''), '"', '\\"'), ''),
'","collation":"', IFNULL(cols.collation_name, ''), '"}')
) FROM (
SELECT cols.table_schema,
@@ -274,7 +274,7 @@ export const getMySQLQuery = (
WHERE vws.table_schema = DATABASE()
) AS vws), ''),
'], "database_name": "', DATABASE(),
'", "version": "', VERSION(), '"}') AS CHAR) AS ''
'", "version": "', VERSION(), '"}') AS CHAR) AS metadata_json_to_import
`;
// To avoid the nondeterministic truncation and ensure that your query results are consistent.

View File

@@ -223,7 +223,7 @@ SELECT CONCAT('{ "fk_info": [', COALESCE(fk_metadata, ''),
'], "tables":[', COALESCE(tbls_metadata, ''),
'], "views":[', COALESCE(views_metadata, ''),
'], "database_name": "', CURRENT_DATABASE(), '', '", "version": "', '',
'"}') AS " "
'"}') AS metadata_json_to_import
FROM fk_info${databaseEdition ? '_' + databaseEdition : ''}, pk_info, cols, indexes_metadata, tbls, config, views;
`;

View File

@@ -159,5 +159,5 @@ replace(replace(replace(
'version', sqlite_version()
),
'\\"', '"'),'"[', '['), ']"', ']'
)AS database_info;
) AS metadata_json_to_import;
`;

View File

@@ -179,5 +179,5 @@ SELECT JSON_QUERY(
', "views": ' + ISNULL((SELECT cast(all_views_json as nvarchar(max)) FROM views), N'[]') +
', "database_name": "' + DB_NAME() + '"' +
', "version": ""}'
) AS full_json_result;
) AS metadata_json_to_import;
`;