findFieldsReferencedTablesSQL static method

  1. @visibleForTesting
String findFieldsReferencedTablesSQL(
  1. String databaseName,
  2. String table
)

The SQL of findFieldsReferencedTablesImpl: the foreign keys of table in the database databaseName (both escaped as string literals, see mysqlStringLiteral).

Implementation

@visibleForTesting
static String findFieldsReferencedTablesSQL(
  String databaseName,
  String table,
) =>
    '''
  SELECT
    CONSTRAINT_NAME, TABLE_NAME, COLUMN_NAME,
    REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME
  FROM
    INFORMATION_SCHEMA.KEY_COLUMN_USAGE
  WHERE
    TABLE_SCHEMA = ${mysqlStringLiteral(databaseName)} AND TABLE_NAME = ${mysqlStringLiteral(table)}
    AND REFERENCED_TABLE_NAME IS NOT NULL AND REFERENCED_COLUMN_NAME IS NOT NULL
  ''';