Debian Codegraph @

mysql-test/suite/ndb/t/print_foreign_keys.inc

raw
1 #
2 # Print the foreign key constraints associated with the given table
3 #
4 # ==== Usage ====
5 # [--let $ndb_db_name= <database name>]
6 # --let $ndb_table_name= <table name>
7 # --source print_foreign_keys.inc
8 #
9 # Parameters:
10 # $ndb_db_name, $ndb_table_name,
11
12
13 # Table name is mandatory option
14 if (!$ndb_table_name) {
15 --die ERROR IN TEST: Please set $ndb_table_name before calling print_foreign_keys.inc script
16 }
17
18 if (!$ndb_db_name) {
19 let $ndb_db_name=test;
20 }
21
22
23 # Find the object id of the table whose FKs we have to list and verify
24 let $ndb_table_id= `SELECT id FROM ndbinfo.dict_obj_info
25 WHERE type = 2 /* UserTable */
26 AND fq_name = "$ndb_db_name/def/$ndb_table_name"`;
27
28 --disable_query_log
29
30 # Now list all the foreign key names using this table id.
31 # They will be of form <parent_id>/<child_id>/fk_name
32 --vertical_results
33 # truncated table as parent
34 eval SELECT REGEXP_REPLACE(fk_info.fq_name, '$ndb_table_id/[0-9]+/', '')
35 AS "Foreign keys referenced by $ndb_db_name.$ndb_table_name : "
36 FROM ndbinfo.dict_obj_info as fk_info
37 WHERE fk_info.type = 25 /* ForeignKey */
38 AND fk_info.fq_name LIKE '$ndb_table_id/%';
39 # truncated table as child
40 eval SELECT REGEXP_REPLACE(fk_info.fq_name, '[0-9]+/$ndb_table_id/', '')
41 AS "Foreign keys on $ndb_db_name.$ndb_table_name : "
42 FROM ndbinfo.dict_obj_info as fk_info
43 WHERE fk_info.type = 25 /* ForeignKey */
44 AND fk_info.fq_name LIKE '%/$ndb_table_id/%';
45 --horizontal_results
46
47 --enable_query_log
48
49 # Reset input parameters
50 --let $ndb_db_name=
51 --let $ndb_table_name=
52