mirror of
https://github.com/MariaDB/server.git
synced 2025-01-18 13:02:28 +01:00
98 lines
3 KiB
Text
98 lines
3 KiB
Text
/*****************************************************************************
|
|
|
|
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
|
|
|
|
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
|
|
Foundation; version 2 of the License.
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
this program; if not, write to the Free Software Foundation, Inc.,
|
|
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
|
|
|
|
*****************************************************************************/
|
|
|
|
/**************************************************//**
|
|
@file include/dict0crea.ic
|
|
Database object creation
|
|
|
|
Created 1/8/1996 Heikki Tuuri
|
|
*******************************************************/
|
|
|
|
#include "mem0mem.h"
|
|
|
|
/*********************************************************************//**
|
|
Checks if a table name contains the string "/#sql" which denotes temporary
|
|
tables in MySQL.
|
|
@return true if temporary table */
|
|
UNIV_INTERN
|
|
bool
|
|
row_is_mysql_tmp_table_name(
|
|
/*========================*/
|
|
const char* name) MY_ATTRIBUTE((warn_unused_result));
|
|
/*!< in: table name in the form
|
|
'database/tablename' */
|
|
|
|
|
|
/********************************************************************//**
|
|
Generate a foreign key constraint name when it was not named by the user.
|
|
A generated constraint has a name of the format dbname/tablename_ibfk_NUMBER,
|
|
where the numbers start from 1, and are given locally for this table, that is,
|
|
the number is not global, as it used to be before MySQL 4.0.18. */
|
|
UNIV_INLINE
|
|
dberr_t
|
|
dict_create_add_foreign_id(
|
|
/*=======================*/
|
|
ulint* id_nr, /*!< in/out: number to use in id generation;
|
|
incremented if used */
|
|
const char* name, /*!< in: table name */
|
|
dict_foreign_t* foreign)/*!< in/out: foreign key */
|
|
{
|
|
if (foreign->id == NULL) {
|
|
/* Generate a new constraint id */
|
|
ulint namelen = strlen(name);
|
|
char* id = static_cast<char*>(
|
|
mem_heap_alloc(foreign->heap,
|
|
namelen + 20));
|
|
|
|
if (row_is_mysql_tmp_table_name(name)) {
|
|
|
|
/* no overflow if number < 1e13 */
|
|
sprintf(id, "%s_ibfk_%lu", name,
|
|
(ulong) (*id_nr)++);
|
|
} else {
|
|
char table_name[MAX_TABLE_NAME_LEN + 20] = "";
|
|
uint errors = 0;
|
|
|
|
strncpy(table_name, name,
|
|
MAX_TABLE_NAME_LEN + 20);
|
|
|
|
innobase_convert_to_system_charset(
|
|
strchr(table_name, '/') + 1,
|
|
strchr(name, '/') + 1,
|
|
MAX_TABLE_NAME_LEN, &errors);
|
|
|
|
if (errors) {
|
|
strncpy(table_name, name,
|
|
MAX_TABLE_NAME_LEN + 20);
|
|
}
|
|
|
|
/* no overflow if number < 1e13 */
|
|
sprintf(id, "%s_ibfk_%lu", table_name,
|
|
(ulong) (*id_nr)++);
|
|
|
|
if (innobase_check_identifier_length(
|
|
strchr(id,'/') + 1)) {
|
|
return(DB_IDENTIFIER_TOO_LONG);
|
|
}
|
|
}
|
|
foreign->id = id;
|
|
}
|
|
|
|
return(DB_SUCCESS);
|
|
}
|
|
|