Browse Source

fix(nocodb): symbol col.table_name not found

pull/4764/head
Wing-Kam Wong 2 years ago
parent
commit
4ee0beb0ac
  1. 130
      packages/nocodb/src/lib/db/sql-client/lib/mysql/mysql.queries.ts

130
packages/nocodb/src/lib/db/sql-client/lib/mysql/mysql.queries.ts

@ -222,7 +222,8 @@ AND t.table_name=?;`,
information_schema.KEY_COLUMN_USAGE AS kcu information_schema.KEY_COLUMN_USAGE AS kcu
INNER JOIN information_schema.REFERENTIAL_CONSTRAINTS AS rc ON INNER JOIN information_schema.REFERENTIAL_CONSTRAINTS AS rc ON
kcu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME kcu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME
Group by kcu.CONSTRAINT_NAME, Group by
kcu.CONSTRAINT_NAME,
kcu.TABLE_NAME, kcu.TABLE_NAME,
kcu.COLUMN_NAME, kcu.COLUMN_NAME,
kcu.POSITION_IN_UNIQUE_CONSTRAINT, kcu.POSITION_IN_UNIQUE_CONSTRAINT,
@ -230,71 +231,90 @@ AND t.table_name=?;`,
kcu.REFERENCED_COLUMN_NAME, kcu.REFERENCED_COLUMN_NAME,
rc.MATCH_OPTION, rc.MATCH_OPTION,
rc.UPDATE_RULE, rc.UPDATE_RULE,
rc.DELETE_RULE ,kcu.table_schema rc.DELETE_RULE ,
kcu.table_schema
Having Having
kcu.table_schema = ? kcu.table_schema = ?
AND kcu.referenced_column_name IS NOT NULL AND kcu.referenced_column_name IS NOT NULL
AND kcu.table_name=?`, AND kcu.table_name =?`,
paramsHints: ['database', 'tn'], paramsHints: ['database', 'tn'],
}, },
}, },
relationListAll: { relationListAll: {
default: { default: {
sql: ` sql: `SELECT
kcu.constraint_name AS cstn,
kcu.table_name AS tn,
kcu.column_name AS cn,
kcu.position_in_unique_constraint AS puc,
kcu.referenced_table_name AS rtn,
kcu.referenced_column_name AS rcn,
rc.match_option AS mo,
rc.update_rule AS ur,
rc.delete_rule AS dr,
kcu.table_schema AS ts
FROM
(
SELECT
table_schema,
constraint_name,
table_name,
column_name,
position_in_unique_constraint,
referenced_table_name,
referenced_column_name
FROM
information_schema.KEY_COLUMN_USAGE
WHERE
table_schema = 'xcdb') AS kcu
INNER JOIN
(
SELECT
constraint_schema,
match_option,
update_rule,
delete_rule,
constraint_name
FROM
information_schema.REFERENTIAL_CONSTRAINTS
WHERE
constraint_schema = 'xcdb') AS rc ON
kcu.constraint_name = rc.constraint_name
AND kcu.table_schema = rc.constraint_schema
INNER JOIN
(
SELECT
table_schema,
table_name,
column_name
FROM
information_schema.COLUMNS
WHERE
table_schema = 'xcdb'
AND table_name IN (
SELECT SELECT
kcu.CONSTRAINT_NAME AS cstn, table_name
kcu.TABLE_NAME AS tn,
kcu.COLUMN_NAME AS cn,
kcu.POSITION_IN_UNIQUE_CONSTRAINT AS puc,
kcu.REFERENCED_TABLE_NAME AS rtn,
kcu.REFERENCED_COLUMN_NAME AS rcn,
rc.MATCH_OPTION AS mo,
rc.UPDATE_RULE AS ur,
rc.DELETE_RULE AS dr,
kcu.table_schema AS ts
FROM FROM
(SELECT information_schema.TABLES
table_schema, WHERE
CONSTRAINT_NAME, table_schema = 'xcdb'
TABLE_NAME, AND Lower(table_type) = 'base table')) AS col ON
COLUMN_NAME, col.table_schema = kcu.table_schema
POSITION_IN_UNIQUE_CONSTRAINT, AND col.table_name = kcu.table_name
REFERENCED_TABLE_NAME, AND kcu.referenced_column_name IS NOT NULL
REFERENCED_COLUMN_NAME GROUP BY
FROM cstn ,
information_schema.KEY_COLUMN_USAGE tn ,
WHERE rcn ,
table_schema = :databaseName) AS kcu cn ,
INNER JOIN puc ,
(SELECT rtn ,
CONSTRAINT_SCHEMA, cn,
MATCH_OPTION, mo ,
UPDATE_RULE, ur ,
DELETE_RULE, dr ,
CONSTRAINT_NAME ts`,
FROM
information_schema.REFERENTIAL_CONSTRAINTS
WHERE
CONSTRAINT_SCHEMA = :databaseName) AS rc ON kcu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME
AND kcu.table_schema = rc.CONSTRAINT_SCHEMA
INNER JOIN
(SELECT
table_schema, TABLE_NAME, COLUMN_NAME
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
table_schema = :databaseName AND TABLE_NAME IN (SELECT
TABLE_NAME
FROM
INFORMATION_SCHEMA.TABLES
WHERE
table_schema = :databaseName
AND LOWER(TABLE_TYPE) = 'base table')) AS col ON col.table_schema = kcu.table_schema
AND col.table_name = kcu.TABLE_NAME
AND kcu.REFERENCED_COLUMN_NAME IS NOT NULL
GROUP BY cstn , tn , rcn , cn , puc , rtn ,cn, mo , ur , dr , ts`,
paramsHints: ['database'], paramsHints: ['database'],
}, },
}, },

Loading…
Cancel
Save