diff options
author | Michael Widenius <monty@askmonty.org> | 2012-08-01 17:27:34 +0300 |
---|---|---|
committer | Michael Widenius <monty@askmonty.org> | 2012-08-01 17:27:34 +0300 |
commit | 1d0f70c2f894b27e98773a282871d32802f67964 (patch) | |
tree | 833e683e0ced29c4323c29a9d845703d4dfcd81b /storage/innobase/include/data0type.ic | |
parent | 5a86a61219826aadf8d08cbc447fe438f2bf50c3 (diff) | |
download | mariadb-git-1d0f70c2f894b27e98773a282871d32802f67964.tar.gz |
Temporary commit of merge of MariaDB 10.0-base and MySQL 5.6
Diffstat (limited to 'storage/innobase/include/data0type.ic')
-rw-r--r-- | storage/innobase/include/data0type.ic | 126 |
1 files changed, 111 insertions, 15 deletions
diff --git a/storage/innobase/include/data0type.ic b/storage/innobase/include/data0type.ic index 757dd815c5e..a5e94a8edff 100644 --- a/storage/innobase/include/data0type.ic +++ b/storage/innobase/include/data0type.ic @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1996, 2010, Innobase Oy. All Rights Reserved. +Copyright (c) 1996, 2011, 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 @@ -11,8 +11,8 @@ 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., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA *****************************************************************************/ @@ -23,6 +23,8 @@ Data types Created 1/16/1996 Heikki Tuuri *******************************************************/ +#include <string.h> /* strlen() */ + #include "mach0data.h" #ifndef UNIV_HOTBACKUP # include "ha_prototypes.h" @@ -36,7 +38,7 @@ dtype_get_charset_coll( /*===================*/ ulint prtype) /*!< in: precise data type */ { - return((prtype >> 16) & 0xFFUL); + return((prtype >> 16) & CHAR_COLL_MASK); } /*********************************************************************//** @@ -259,8 +261,8 @@ dtype_get_pad_char( switch (mtype) { case DATA_FIXBINARY: case DATA_BINARY: - if (UNIV_UNLIKELY(dtype_get_charset_coll(prtype) - == DATA_MYSQL_BINARY_CHARSET_COLL)) { + if (dtype_get_charset_coll(prtype) + == DATA_MYSQL_BINARY_CHARSET_COLL) { /* Starting from 5.0.18, do not pad VARBINARY or BINARY columns. */ return(ULINT_UNDEFINED); @@ -312,11 +314,11 @@ dtype_new_store_for_order_and_null_size( buf[0] = (byte)(type->mtype & 0xFFUL); if (type->prtype & DATA_BINARY_TYPE) { - buf[0] = buf[0] | 128; + buf[0] |= 128; } /* In versions < 4.1.2 we had: if (type->prtype & DATA_NONLATIN1) { - buf[0] = buf[0] | 64; + buf[0] |= 64; } */ @@ -326,7 +328,7 @@ dtype_new_store_for_order_and_null_size( mach_write_to_2(buf + 2, len & 0xFFFFUL); - ut_ad(dtype_get_charset_coll(type->prtype) < 256); + ut_ad(dtype_get_charset_coll(type->prtype) <= MAX_CHAR_COLL_NUM); mach_write_to_2(buf + 4, dtype_get_charset_coll(type->prtype)); if (type->prtype & DATA_NOT_NULL) { @@ -353,7 +355,7 @@ dtype_read_for_order_and_null_size( type->prtype = buf[1]; if (buf[0] & 128) { - type->prtype = type->prtype | DATA_BINARY_TYPE; + type->prtype |= DATA_BINARY_TYPE; } type->len = mach_read_from_2(buf + 2); @@ -393,10 +395,10 @@ dtype_new_read_for_order_and_null_size( type->len = mach_read_from_2(buf + 2); - charset_coll = mach_read_from_2(buf + 4) & 0x7fff; + charset_coll = mach_read_from_2(buf + 4) & CHAR_COLL_MASK; if (dtype_is_string_type(type->mtype)) { - ut_a(charset_coll < 256); + ut_a(charset_coll <= MAX_CHAR_COLL_NUM); if (charset_coll == 0) { /* This insert buffer record was inserted with MySQL @@ -412,6 +414,101 @@ dtype_new_read_for_order_and_null_size( } dtype_set_mblen(type); } + +/*********************************************************************//** +Returns the type's SQL name (e.g. BIGINT UNSIGNED) from mtype,prtype,len +@return the SQL type name */ +UNIV_INLINE +char* +dtype_sql_name( +/*===========*/ + unsigned mtype, /*!< in: mtype */ + unsigned prtype, /*!< in: prtype */ + unsigned len, /*!< in: len */ + char* name, /*!< out: SQL name */ + unsigned name_sz)/*!< in: size of the name buffer */ +{ + +#define APPEND_UNSIGNED() \ + do { \ + if (prtype & DATA_UNSIGNED) { \ + ut_snprintf(name + strlen(name), \ + name_sz - strlen(name), \ + " UNSIGNED"); \ + } \ + } while (0) + + ut_snprintf(name, name_sz, "UNKNOWN"); + + switch (mtype) { + case DATA_INT: + switch (len) { + case 1: + ut_snprintf(name, name_sz, "TINYINT"); + break; + case 2: + ut_snprintf(name, name_sz, "SMALLINT"); + break; + case 3: + ut_snprintf(name, name_sz, "MEDIUMINT"); + break; + case 4: + ut_snprintf(name, name_sz, "INT"); + break; + case 8: + ut_snprintf(name, name_sz, "BIGINT"); + break; + } + APPEND_UNSIGNED(); + break; + case DATA_FLOAT: + ut_snprintf(name, name_sz, "FLOAT"); + APPEND_UNSIGNED(); + break; + case DATA_DOUBLE: + ut_snprintf(name, name_sz, "DOUBLE"); + APPEND_UNSIGNED(); + break; + case DATA_FIXBINARY: + ut_snprintf(name, name_sz, "BINARY(%u)", len); + break; + case DATA_CHAR: + case DATA_MYSQL: + ut_snprintf(name, name_sz, "CHAR(%u)", len); + break; + case DATA_VARCHAR: + case DATA_VARMYSQL: + ut_snprintf(name, name_sz, "VARCHAR(%u)", len); + break; + case DATA_BINARY: + ut_snprintf(name, name_sz, "VARBINARY(%u)", len); + break; + case DATA_BLOB: + switch (len) { + case 9: + ut_snprintf(name, name_sz, "TINYBLOB"); + break; + case 10: + ut_snprintf(name, name_sz, "BLOB"); + break; + case 11: + ut_snprintf(name, name_sz, "MEDIUMBLOB"); + break; + case 12: + ut_snprintf(name, name_sz, "LONGBLOB"); + break; + } + } + + if (prtype & DATA_NOT_NULL) { + ut_snprintf(name + strlen(name), + name_sz - strlen(name), + " NOT NULL"); + } + + return(name); +} + #endif /* !UNIV_HOTBACKUP */ /***********************************************************************//** @@ -473,9 +570,8 @@ dtype_get_fixed_size_low( dtype_get_charset_coll(prtype), &i_mbminlen, &i_mbmaxlen); - if (UNIV_UNLIKELY - (DATA_MBMINMAXLEN(i_mbminlen, i_mbmaxlen) - != mbminmaxlen)) { + if (DATA_MBMINMAXLEN(i_mbminlen, i_mbmaxlen) + != mbminmaxlen) { ut_print_timestamp(stderr); fprintf(stderr, " InnoDB: " |