mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
BUG#4788 - show create table provides incorrect statement.
Added code to adjust the field_length of user variables in dependence on the field type. Aded new constants for numeric field widths.
This commit is contained in:
@ -136,6 +136,11 @@ enum enum_server_command
|
||||
struct st_vio; /* Only C */
|
||||
typedef struct st_vio Vio;
|
||||
|
||||
#define MAX_TINYINT_WIDTH 3 /* Max width for a TINY w.o. sign */
|
||||
#define MAX_SMALLINT_WIDTH 5 /* Max width for a SHORT w.o. sign */
|
||||
#define MAX_MEDIUMINT_WIDTH 8 /* Max width for a INT24 w.o. sign */
|
||||
#define MAX_INT_WIDTH 10 /* Max width for a LONG w.o. sign */
|
||||
#define MAX_BIGINT_WIDTH 20 /* Max width for a LONGLONG */
|
||||
#define MAX_CHAR_WIDTH 255 /* Max length for a CHAR colum */
|
||||
#define MAX_BLOB_WIDTH 8192 /* Default width for blob */
|
||||
|
||||
|
@ -452,3 +452,29 @@ set global log_warnings = @tstlw;
|
||||
show global variables like 'log_warnings';
|
||||
Variable_name Value
|
||||
log_warnings 1
|
||||
create table t1 (
|
||||
c1 tinyint,
|
||||
c2 smallint,
|
||||
c3 mediumint,
|
||||
c4 int,
|
||||
c5 bigint);
|
||||
show create table t1;
|
||||
Table Create Table
|
||||
t1 CREATE TABLE `t1` (
|
||||
`c1` tinyint(4) default NULL,
|
||||
`c2` smallint(6) default NULL,
|
||||
`c3` mediumint(9) default NULL,
|
||||
`c4` int(11) default NULL,
|
||||
`c5` bigint(20) default NULL
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1
|
||||
drop table t1;
|
||||
set @arg00= 8, @arg01= 8.8, @arg02= 'a string';
|
||||
create table t1 as select @arg00 as c1, @arg01 as c2, @arg02 as c3;
|
||||
show create table t1;
|
||||
Table Create Table
|
||||
t1 CREATE TABLE `t1` (
|
||||
`c1` bigint(20) default NULL,
|
||||
`c2` double default NULL,
|
||||
`c3` longtext
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1
|
||||
drop table t1;
|
||||
|
@ -335,3 +335,22 @@ show global variables like 'log_warnings';
|
||||
set global log_warnings = @tstlw;
|
||||
show global variables like 'log_warnings';
|
||||
|
||||
#
|
||||
# BUG#4788 show create table provides incorrect statement
|
||||
#
|
||||
# What default width have numeric types?
|
||||
create table t1 (
|
||||
c1 tinyint,
|
||||
c2 smallint,
|
||||
c3 mediumint,
|
||||
c4 int,
|
||||
c5 bigint);
|
||||
show create table t1;
|
||||
drop table t1;
|
||||
#
|
||||
# What types and widths have variables?
|
||||
set @arg00= 8, @arg01= 8.8, @arg02= 'a string';
|
||||
create table t1 as select @arg00 as c1, @arg01 as c2, @arg02 as c3;
|
||||
show create table t1;
|
||||
drop table t1;
|
||||
|
||||
|
@ -2724,7 +2724,19 @@ void Item_func_get_user_var::fix_length_and_dec()
|
||||
error= get_var_with_binlog(thd, name, &var_entry);
|
||||
|
||||
if (var_entry)
|
||||
{
|
||||
collation.set(var_entry->collation);
|
||||
switch (var_entry->type) {
|
||||
case REAL_RESULT:
|
||||
max_length= DBL_DIG + 8;
|
||||
case INT_RESULT:
|
||||
max_length= MAX_BIGINT_WIDTH;
|
||||
break;
|
||||
case STRING_RESULT:
|
||||
max_length= MAX_BLOB_WIDTH;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
null_value= 1;
|
||||
|
||||
|
@ -4208,23 +4208,23 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type,
|
||||
|
||||
switch (type) {
|
||||
case FIELD_TYPE_TINY:
|
||||
if (!length) new_field->length=3+sign_len;
|
||||
if (!length) new_field->length=MAX_TINYINT_WIDTH+sign_len;
|
||||
allowed_type_modifier= AUTO_INCREMENT_FLAG;
|
||||
break;
|
||||
case FIELD_TYPE_SHORT:
|
||||
if (!length) new_field->length=5+sign_len;
|
||||
if (!length) new_field->length=MAX_SMALLINT_WIDTH+sign_len;
|
||||
allowed_type_modifier= AUTO_INCREMENT_FLAG;
|
||||
break;
|
||||
case FIELD_TYPE_INT24:
|
||||
if (!length) new_field->length=8+sign_len;
|
||||
if (!length) new_field->length=MAX_MEDIUMINT_WIDTH+sign_len;
|
||||
allowed_type_modifier= AUTO_INCREMENT_FLAG;
|
||||
break;
|
||||
case FIELD_TYPE_LONG:
|
||||
if (!length) new_field->length=10+sign_len;
|
||||
if (!length) new_field->length=MAX_INT_WIDTH+sign_len;
|
||||
allowed_type_modifier= AUTO_INCREMENT_FLAG;
|
||||
break;
|
||||
case FIELD_TYPE_LONGLONG:
|
||||
if (!length) new_field->length=20;
|
||||
if (!length) new_field->length=MAX_BIGINT_WIDTH;
|
||||
allowed_type_modifier= AUTO_INCREMENT_FLAG;
|
||||
break;
|
||||
case FIELD_TYPE_NULL:
|
||||
|
Reference in New Issue
Block a user