summaryrefslogtreecommitdiff
path: root/storage/innobase/dict
diff options
context:
space:
mode:
authorJan Lindström <jan.lindstrom@mariadb.com>2015-12-14 14:34:32 +0200
committerJan Lindström <jan.lindstrom@mariadb.com>2015-12-14 22:10:37 +0200
commit99404c3437b35b5ee51578c2ea74209ccb9ba890 (patch)
tree7dc58eefe89b0d799589d2ca3d95a452e6e69916 /storage/innobase/dict
parent0db50be89349761d5677441f2d60ab52c23947f0 (diff)
downloadmariadb-git-99404c3437b35b5ee51578c2ea74209ccb9ba890.tar.gz
MDEV-9276: MySQL Bug #78754: FK definitions missing from SHOW CREATE TABLE in "innodb_read_only" mode
Diffstat (limited to 'storage/innobase/dict')
-rw-r--r--storage/innobase/dict/dict0dict.cc110
1 files changed, 60 insertions, 50 deletions
diff --git a/storage/innobase/dict/dict0dict.cc b/storage/innobase/dict/dict0dict.cc
index 09893d2d645..b5e97a2c3f4 100644
--- a/storage/innobase/dict/dict0dict.cc
+++ b/storage/innobase/dict/dict0dict.cc
@@ -2,6 +2,7 @@
Copyright (c) 1996, 2015, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2012, Facebook Inc.
+Copyright (c) 2014, 2015, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
@@ -28,6 +29,7 @@ Created 1/8/1996 Heikki Tuuri
#include "fts0fts.h"
#include "fil0fil.h"
#include <algorithm>
+#include <string>
#ifdef UNIV_NONINL
#include "dict0dict.ic"
@@ -3468,11 +3470,13 @@ dict_foreign_error_report(
dict_foreign_t* fk, /*!< in: foreign key constraint */
const char* msg) /*!< in: the error message */
{
+ std::string fk_str;
mutex_enter(&dict_foreign_err_mutex);
dict_foreign_error_report_low(file, fk->foreign_table_name);
fputs(msg, file);
fputs(" Constraint:\n", file);
- dict_print_info_on_foreign_key_in_create_format(file, NULL, fk, TRUE);
+ fk_str = dict_print_info_on_foreign_key_in_create_format(NULL, fk, TRUE);
+ fputs(fk_str.c_str(), file);
putc('\n', file);
if (fk->foreign_index) {
fputs("The index in the foreign key in table is ", file);
@@ -5861,16 +5865,16 @@ dict_field_print_low(
Outputs info on a foreign key of a table in a format suitable for
CREATE TABLE. */
UNIV_INTERN
-void
+std::string
dict_print_info_on_foreign_key_in_create_format(
/*============================================*/
- FILE* file, /*!< in: file where to print */
trx_t* trx, /*!< in: transaction */
dict_foreign_t* foreign, /*!< in: foreign key constraint */
ibool add_newline) /*!< in: whether to add a newline */
{
const char* stripped_id;
ulint i;
+ std::string str;
if (strchr(foreign->id, '/')) {
/* Strip the preceding database name from the constraint id */
@@ -5880,96 +5884,99 @@ dict_print_info_on_foreign_key_in_create_format(
stripped_id = foreign->id;
}
- putc(',', file);
+ str.append(",");
if (add_newline) {
/* SHOW CREATE TABLE wants constraints each printed nicely
on its own line, while error messages want no newlines
inserted. */
- fputs("\n ", file);
+ str.append("\n ");
}
- fputs(" CONSTRAINT ", file);
- ut_print_name(file, trx, FALSE, stripped_id);
- fputs(" FOREIGN KEY (", file);
+ str.append(" CONSTRAINT ");
+
+ str.append(ut_get_name(trx, FALSE, stripped_id));
+ str.append(" FOREIGN KEY (");
for (i = 0;;) {
- ut_print_name(file, trx, FALSE, foreign->foreign_col_names[i]);
+ str.append(ut_get_name(trx, FALSE, foreign->foreign_col_names[i]));
if (++i < foreign->n_fields) {
- fputs(", ", file);
+ str.append(", ");
} else {
break;
}
}
- fputs(") REFERENCES ", file);
+ str.append(") REFERENCES ");
if (dict_tables_have_same_db(foreign->foreign_table_name_lookup,
foreign->referenced_table_name_lookup)) {
/* Do not print the database name of the referenced table */
- ut_print_name(file, trx, TRUE,
+ str.append(ut_get_name(trx, TRUE,
dict_remove_db_name(
- foreign->referenced_table_name));
+ foreign->referenced_table_name)));
} else {
- ut_print_name(file, trx, TRUE,
- foreign->referenced_table_name);
+ str.append(ut_get_name(trx, TRUE,
+ foreign->referenced_table_name));
}
- putc(' ', file);
- putc('(', file);
+ str.append(" (");
for (i = 0;;) {
- ut_print_name(file, trx, FALSE,
- foreign->referenced_col_names[i]);
+ str.append(ut_get_name(trx, FALSE,
+ foreign->referenced_col_names[i]));
+
if (++i < foreign->n_fields) {
- fputs(", ", file);
+ str.append(", ");
} else {
break;
}
}
- putc(')', file);
+ str.append(")");
if (foreign->type & DICT_FOREIGN_ON_DELETE_CASCADE) {
- fputs(" ON DELETE CASCADE", file);
+ str.append(" ON DELETE CASCADE");
}
if (foreign->type & DICT_FOREIGN_ON_DELETE_SET_NULL) {
- fputs(" ON DELETE SET NULL", file);
+ str.append(" ON DELETE SET NULL");
}
if (foreign->type & DICT_FOREIGN_ON_DELETE_NO_ACTION) {
- fputs(" ON DELETE NO ACTION", file);
+ str.append(" ON DELETE NO ACTION");
}
if (foreign->type & DICT_FOREIGN_ON_UPDATE_CASCADE) {
- fputs(" ON UPDATE CASCADE", file);
+ str.append(" ON UPDATE CASCADE");
}
if (foreign->type & DICT_FOREIGN_ON_UPDATE_SET_NULL) {
- fputs(" ON UPDATE SET NULL", file);
+ str.append(" ON UPDATE SET NULL");
}
if (foreign->type & DICT_FOREIGN_ON_UPDATE_NO_ACTION) {
- fputs(" ON UPDATE NO ACTION", file);
+ str.append(" ON UPDATE NO ACTION");
}
+
+ return str;
}
/**********************************************************************//**
Outputs info on foreign keys of a table. */
UNIV_INTERN
-void
+std::string
dict_print_info_on_foreign_keys(
/*============================*/
ibool create_table_format, /*!< in: if TRUE then print in
a format suitable to be inserted into
a CREATE TABLE, otherwise in the format
of SHOW TABLE STATUS */
- FILE* file, /*!< in: file where to print */
trx_t* trx, /*!< in: transaction */
dict_table_t* table) /*!< in: table */
{
dict_foreign_t* foreign;
+ std::string str;
mutex_enter(&(dict_sys->mutex));
@@ -5980,64 +5987,67 @@ dict_print_info_on_foreign_keys(
foreign = *it;
if (create_table_format) {
- dict_print_info_on_foreign_key_in_create_format(
- file, trx, foreign, TRUE);
+ str.append(
+ dict_print_info_on_foreign_key_in_create_format(
+ trx, foreign, TRUE));
} else {
ulint i;
- fputs("; (", file);
+ str.append("; (");
for (i = 0; i < foreign->n_fields; i++) {
if (i) {
- putc(' ', file);
+ str.append(" ");
}
- ut_print_name(file, trx, FALSE,
- foreign->foreign_col_names[i]);
+ str.append(ut_get_name(trx, FALSE,
+ foreign->foreign_col_names[i]));
}
- fputs(") REFER ", file);
- ut_print_name(file, trx, TRUE,
- foreign->referenced_table_name);
- putc('(', file);
+ str.append(") REFER ");
+ str.append(ut_get_name(trx, TRUE,
+ foreign->referenced_table_name));
+ str.append(")");
for (i = 0; i < foreign->n_fields; i++) {
if (i) {
- putc(' ', file);
+ str.append(" ");
}
- ut_print_name(
- file, trx, FALSE,
- foreign->referenced_col_names[i]);
+ str.append(ut_get_name(
+ trx, FALSE,
+ foreign->referenced_col_names[i]));
}
- putc(')', file);
+ str.append(")");
if (foreign->type == DICT_FOREIGN_ON_DELETE_CASCADE) {
- fputs(" ON DELETE CASCADE", file);
+ str.append(" ON DELETE CASCADE");
}
if (foreign->type == DICT_FOREIGN_ON_DELETE_SET_NULL) {
- fputs(" ON DELETE SET NULL", file);
+ str.append(" ON DELETE SET NULL");
}
if (foreign->type & DICT_FOREIGN_ON_DELETE_NO_ACTION) {
- fputs(" ON DELETE NO ACTION", file);
+ str.append(" ON DELETE NO ACTION");
}
if (foreign->type & DICT_FOREIGN_ON_UPDATE_CASCADE) {
- fputs(" ON UPDATE CASCADE", file);
+ str.append(" ON UPDATE CASCADE");
}
if (foreign->type & DICT_FOREIGN_ON_UPDATE_SET_NULL) {
- fputs(" ON UPDATE SET NULL", file);
+ str.append(" ON UPDATE SET NULL");
}
if (foreign->type & DICT_FOREIGN_ON_UPDATE_NO_ACTION) {
- fputs(" ON UPDATE NO ACTION", file);
+ str.append(" ON UPDATE NO ACTION");
}
}
}
mutex_exit(&(dict_sys->mutex));
+
+ return str;
}
/********************************************************************//**