MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / prepare_blob_field

Function prepare_blob_field

sql/sql_table.cc:1611–1650  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1609*/
1610
1611static bool prepare_blob_field(THD *thd, Create_field *sql_field)
1612{
1613 DBUG_ENTER("prepare_blob_field");
1614
1615 if (sql_field->length > MAX_FIELD_VARCHARLENGTH &&
1616 !(sql_field->flags & BLOB_FLAG))
1617 {
1618 /* Convert long VARCHAR columns to TEXT or BLOB */
1619 char warn_buff[MYSQL_ERRMSG_SIZE];
1620
1621 if (sql_field->def || thd->is_strict_mode())
1622 {
1623 my_error(ER_TOO_BIG_FIELDLENGTH, MYF(0), sql_field->field_name,
1624 static_cast<ulong>(MAX_FIELD_VARCHARLENGTH /
1625 sql_field->charset->mbmaxlen));
1626 DBUG_RETURN(1);
1627 }
1628 sql_field->sql_type= MYSQL_TYPE_BLOB;
1629 sql_field->flags|= BLOB_FLAG;
1630 my_snprintf(warn_buff, sizeof(warn_buff), ER(ER_AUTO_CONVERT), sql_field->field_name,
1631 (sql_field->charset == &my_charset_bin) ? "VARBINARY" : "VARCHAR",
1632 (sql_field->charset == &my_charset_bin) ? "BLOB" : "TEXT");
1633 push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, ER_AUTO_CONVERT,
1634 warn_buff);
1635 }
1636
1637 if ((sql_field->flags & BLOB_FLAG) && sql_field->length)
1638 {
1639 if (sql_field->sql_type == FIELD_TYPE_BLOB ||
1640 sql_field->sql_type == FIELD_TYPE_TINY_BLOB ||
1641 sql_field->sql_type == FIELD_TYPE_MEDIUM_BLOB)
1642 {
1643 /* The user has given a length to the blob column */
1644 sql_field->sql_type= get_blob_type_from_length(sql_field->length);
1645 sql_field->pack_length= calc_pack_length(sql_field->sql_type, 0);
1646 }
1647 sql_field->length= 0;
1648 }
1649 DBUG_RETURN(0);
1650}
1651
1652
1653/*

Callers 1

sp_prepare_create_fieldFunction · 0.85

Calls 6

my_errorFunction · 0.85
my_snprintfFunction · 0.85
push_warningFunction · 0.85
calc_pack_lengthFunction · 0.85
is_strict_modeMethod · 0.80

Tested by

no test coverage detected