mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Fixes while reviewing new code
Added option --count to mysqlshow (to show number of rows) Fixed possible core dump in information schema client/client_priv.h: --count for mysqlshow client/mysqlshow.c: Added option --count to be used when the user want's number of rows per table in the output (We shouldn't use count(*) as default as this can be a slow operation) mysys/my_thr_init.c: Correct comment sql/ha_berkeley.cc: Remove not used variable sql/ha_berkeley.h: Remove not used variable sql/ha_innodb.cc: Remove not used function sql/ha_ndbcluster.cc: false -> FALSE true -> TRUE sql/handler.cc: Added and fixed comments Remove 'strange' code to remove compiler warnings (better to do things like this with attribute) sql/item.cc: false -> FALSE sql/item_cmpfunc.cc: Fixed indentation sql/item_cmpfunc.h: marked BETWEEN as a bool function sql/item_func.cc: Simple optimzation sql/key.cc: Removed wrong code sql/log.cc: Check result from open_index_file() sql/mysql_priv.h: Simplyfy some test of netware sql/mysqld.cc: Fixed indentation Check result form open_index_file() Simplify code with IF_NETWARE() sql/opt_range.cc: false -> FALSE true -> TRUE Fixed indentation sql/opt_sum.cc: Fixed comments sql/sp_head.cc: Simple optimzation Move variable declarations to begining of blocks sql/sql_acl.cc: Fix long lines Rename xx -> column Move declaration to beginning of block sql/sql_parse.cc: Removed comment sql/sql_select.cc: Indentation fixes sql/sql_show.cc: Fixed reference outside of array (possible core dump) sql/sql_table.cc: Simplify code Combine common code sql/sql_test.cc: false -> FALSE sql/sql_trigger.cc: false -> false true -> TRUE sql/sql_yacc.yy: Simpler test sql/unireg.cc: Added comment
This commit is contained in:
128
sql/sql_table.cc
128
sql/sql_table.cc
@ -38,6 +38,7 @@ static int copy_data_between_tables(TABLE *from,TABLE *to,
|
||||
bool ignore,
|
||||
uint order_num, ORDER *order,
|
||||
ha_rows *copied,ha_rows *deleted);
|
||||
static bool prepare_blob_field(THD *thd, create_field *sql_field);
|
||||
|
||||
/*
|
||||
delete (drop) tables.
|
||||
@ -700,21 +701,20 @@ static int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
|
||||
String conv, *tmp;
|
||||
for (uint i= 0; (tmp= it++); i++)
|
||||
{
|
||||
uint lengthsp;
|
||||
if (String::needs_conversion(tmp->length(), tmp->charset(),
|
||||
cs, &dummy))
|
||||
{
|
||||
uint cnv_errs;
|
||||
conv.copy(tmp->ptr(), tmp->length(), tmp->charset(), cs, &cnv_errs);
|
||||
char *buf= (char*) sql_alloc(conv.length()+1);
|
||||
memcpy(buf, conv.ptr(), conv.length());
|
||||
buf[conv.length()]= '\0';
|
||||
interval->type_names[i]= buf;
|
||||
interval->type_names[i]= strmake_root(thd->mem_root, conv.ptr(),
|
||||
conv.length());
|
||||
interval->type_lengths[i]= conv.length();
|
||||
}
|
||||
|
||||
// Strip trailing spaces.
|
||||
uint lengthsp= cs->cset->lengthsp(cs, interval->type_names[i],
|
||||
interval->type_lengths[i]);
|
||||
lengthsp= cs->cset->lengthsp(cs, interval->type_names[i],
|
||||
interval->type_lengths[i]);
|
||||
interval->type_lengths[i]= lengthsp;
|
||||
((uchar *)interval->type_names[i])[lengthsp]= '\0';
|
||||
}
|
||||
@ -781,37 +781,8 @@ static int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
|
||||
}
|
||||
|
||||
sql_field->create_length_to_internal_length();
|
||||
if (sql_field->length > MAX_FIELD_VARCHARLENGTH &&
|
||||
!(sql_field->flags & BLOB_FLAG))
|
||||
{
|
||||
/* Convert long VARCHAR columns to TEXT or BLOB */
|
||||
char warn_buff[MYSQL_ERRMSG_SIZE];
|
||||
|
||||
if (sql_field->def)
|
||||
{
|
||||
my_error(ER_TOO_BIG_FIELDLENGTH, MYF(0), sql_field->field_name,
|
||||
MAX_FIELD_VARCHARLENGTH / sql_field->charset->mbmaxlen);
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
sql_field->sql_type= FIELD_TYPE_BLOB;
|
||||
sql_field->flags|= BLOB_FLAG;
|
||||
sprintf(warn_buff, ER(ER_AUTO_CONVERT), sql_field->field_name,
|
||||
"VARCHAR",
|
||||
(sql_field->charset == &my_charset_bin) ? "BLOB" : "TEXT");
|
||||
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, ER_AUTO_CONVERT,
|
||||
warn_buff);
|
||||
}
|
||||
|
||||
if ((sql_field->flags & BLOB_FLAG) && sql_field->length)
|
||||
{
|
||||
if (sql_field->sql_type == FIELD_TYPE_BLOB)
|
||||
{
|
||||
/* The user has given a length to the blob column */
|
||||
sql_field->sql_type= get_blob_type_from_length(sql_field->length);
|
||||
sql_field->pack_length= calc_pack_length(sql_field->sql_type, 0);
|
||||
}
|
||||
sql_field->length= 0; // Probably from an item
|
||||
}
|
||||
if (prepare_blob_field(thd, sql_field))
|
||||
DBUG_RETURN(-1);
|
||||
|
||||
if (!(sql_field->flags & NOT_NULL_FLAG))
|
||||
null_fields++;
|
||||
@ -1351,6 +1322,58 @@ static int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Extend long VARCHAR fields to blob & prepare field if it's a blob
|
||||
|
||||
SYNOPSIS
|
||||
prepare_blob_field()
|
||||
sql_field Field to check
|
||||
|
||||
RETURN
|
||||
0 ok
|
||||
1 Error (sql_field can't be converted to blob)
|
||||
In this case the error is given
|
||||
*/
|
||||
|
||||
static bool prepare_blob_field(THD *thd, create_field *sql_field)
|
||||
{
|
||||
DBUG_ENTER("prepare_blob_field");
|
||||
|
||||
if (sql_field->length > MAX_FIELD_VARCHARLENGTH &&
|
||||
!(sql_field->flags & BLOB_FLAG))
|
||||
{
|
||||
/* Convert long VARCHAR columns to TEXT or BLOB */
|
||||
char warn_buff[MYSQL_ERRMSG_SIZE];
|
||||
|
||||
if (sql_field->def)
|
||||
{
|
||||
my_error(ER_TOO_BIG_FIELDLENGTH, MYF(0), sql_field->field_name,
|
||||
MAX_FIELD_VARCHARLENGTH / sql_field->charset->mbmaxlen);
|
||||
DBUG_RETURN(1);
|
||||
}
|
||||
sql_field->sql_type= FIELD_TYPE_BLOB;
|
||||
sql_field->flags|= BLOB_FLAG;
|
||||
sprintf(warn_buff, ER(ER_AUTO_CONVERT), sql_field->field_name,
|
||||
"VARCHAR",
|
||||
(sql_field->charset == &my_charset_bin) ? "BLOB" : "TEXT");
|
||||
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, ER_AUTO_CONVERT,
|
||||
warn_buff);
|
||||
}
|
||||
|
||||
if ((sql_field->flags & BLOB_FLAG) && sql_field->length)
|
||||
{
|
||||
if (sql_field->sql_type == FIELD_TYPE_BLOB)
|
||||
{
|
||||
/* The user has given a length to the blob column */
|
||||
sql_field->sql_type= get_blob_type_from_length(sql_field->length);
|
||||
sql_field->pack_length= calc_pack_length(sql_field->sql_type, 0);
|
||||
}
|
||||
sql_field->length= 0;
|
||||
}
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Preparation of create_field for SP function return values.
|
||||
Based on code used in the inner loop of mysql_prepare_table() above
|
||||
@ -1395,33 +1418,12 @@ void sp_prepare_create_field(THD *thd, create_field *sql_field)
|
||||
FIELDFLAG_TREAT_BIT_AS_CHAR;
|
||||
}
|
||||
sql_field->create_length_to_internal_length();
|
||||
|
||||
if (sql_field->length > MAX_FIELD_VARCHARLENGTH &&
|
||||
!(sql_field->flags & BLOB_FLAG))
|
||||
{
|
||||
/* Convert long VARCHAR columns to TEXT or BLOB */
|
||||
char warn_buff[MYSQL_ERRMSG_SIZE];
|
||||
|
||||
sql_field->sql_type= FIELD_TYPE_BLOB;
|
||||
sql_field->flags|= BLOB_FLAG;
|
||||
sprintf(warn_buff, ER(ER_AUTO_CONVERT), sql_field->field_name,
|
||||
"VARCHAR",
|
||||
(sql_field->charset == &my_charset_bin) ? "BLOB" : "TEXT");
|
||||
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, ER_AUTO_CONVERT,
|
||||
warn_buff);
|
||||
}
|
||||
|
||||
if ((sql_field->flags & BLOB_FLAG) && sql_field->length)
|
||||
{
|
||||
if (sql_field->sql_type == FIELD_TYPE_BLOB)
|
||||
{
|
||||
/* The user has given a length to the blob column */
|
||||
sql_field->sql_type= get_blob_type_from_length(sql_field->length);
|
||||
sql_field->pack_length= calc_pack_length(sql_field->sql_type, 0);
|
||||
}
|
||||
sql_field->length= 0; // Probably from an item
|
||||
}
|
||||
DBUG_ASSERT(sql_field->def == 0);
|
||||
/* Can't go wrong as sql_field->def is not defined */
|
||||
(void) prepare_blob_field(thd, sql_field);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Create a table
|
||||
|
||||
|
Reference in New Issue
Block a user