summaryrefslogtreecommitdiff
path: root/innobase/include/row0mysql.ic
diff options
context:
space:
mode:
authorunknown <marko@hundin.mysql.fi>2005-02-17 17:15:29 +0200
committerunknown <marko@hundin.mysql.fi>2005-02-17 17:15:29 +0200
commit6075463f0342c0bf178c40dd7f9ecdeb7d5c8235 (patch)
treec7f0fcd17c220dc071ec22c5ba7c04fc4544d346 /innobase/include/row0mysql.ic
parentca021698d1f41d63bacfb3baf5a73dc40790547c (diff)
downloadmariadb-git-6075463f0342c0bf178c40dd7f9ecdeb7d5c8235.tar.gz
InnoDB: Make CREATE TABLE return error when the minimum row length
exceeds the maximum record size. (Bug #5682) innobase/data/data0type.c: Remove function dtype_str_needs_mysql_cmp(). Document dtype_get_at_most_n_mbchars(). dtype_get_at_most_n_mbchars(): Use mbminlen and mbmaxlen. innobase/dict/dict0crea.c: dict_build_table_def_step(): Reject if minimum row size is too big. innobase/include/data0type.h: Remove dtype_str_needs_mysql_cmp(). Document dtype_get_at_most_n_mbchars(). Add dtype_get_min_size(). innobase/include/data0type.ic: Add dtype_get_min_size(). innobase/include/row0mysql.h: row_mysql_store_col_in_innobase_format(): Add parameter comp, as we will only truncate UTF-8 CHAR(n) columns in row_format=compact. innobase/include/row0mysql.ic: row_mysql_store_col_in_innobase_format(): Add parameter comp, as we will only truncate UTF-8 CHAR(n) columns in row_format=compact. innobase/row/row0mysql.c: Pass parameter comp to row_mysql_store_col_in_innobase_format(). innobase/row/row0sel.c: Pass parameter comp to row_mysql_store_col_in_innobase_format(). row_sel_field_store_in_mysql_format(): Undo the stripping of UTF-8 CHAR(n) columns by padding with spaces.
Diffstat (limited to 'innobase/include/row0mysql.ic')
-rw-r--r--innobase/include/row0mysql.ic32
1 files changed, 32 insertions, 0 deletions
diff --git a/innobase/include/row0mysql.ic b/innobase/include/row0mysql.ic
index 1f5d0b0c990..910546e298c 100644
--- a/innobase/include/row0mysql.ic
+++ b/innobase/include/row0mysql.ic
@@ -67,6 +67,7 @@ row_mysql_store_col_in_innobase_format(
as dfield is used! */
ulint col_len, /* in: MySQL column length */
ulint type, /* in: data type */
+ bool comp, /* in: TRUE=compact format */
ulint is_unsigned) /* in: != 0 if unsigned integer type */
{
byte* ptr = mysql_data;
@@ -113,6 +114,37 @@ row_mysql_store_col_in_innobase_format(
col_len--;
}
}
+ } else if (comp && type == DATA_MYSQL
+ && dtype_get_mbminlen(dfield_get_type(dfield)) == 1
+ && dtype_get_mbmaxlen(dfield_get_type(dfield)) > 1) {
+ /* We assume that this CHAR field is encoded in a
+ variable-length character set where spaces have
+ 1:1 correspondence to 0x20 bytes, such as UTF-8.
+
+ Consider a CHAR(n) field, a field of n characters.
+ It will contain between n*mbminlen and n*mbmaxlen bytes.
+ We will try to truncate it to n bytes by stripping
+ space padding. If the field contains single-byte
+ characters only, it will be truncated to n characters.
+ Consider a CHAR(5) field containing the string ".a "
+ where "." denotes a 3-byte character represented by
+ the bytes "$%&". After our stripping, the string will
+ be stored as "$%&a " (5 bytes). The string ".abc "
+ will be stored as "$%&abc" (6 bytes).
+
+ The space padding will be restored in row0sel.c, function
+ row_sel_field_store_in_mysql_format(). */
+
+ ulint n_chars;
+ dtype_t* dtype = dfield_get_type(dfield);
+
+ ut_a(!(dtype_get_len(dtype) % dtype_get_mbmaxlen(dtype)));
+ n_chars = dtype_get_len(dtype) / dtype_get_mbmaxlen(dtype);
+
+ /* Strip space padding. */
+ while (col_len > n_chars && ptr[col_len - 1] == 0x20) {
+ col_len--;
+ }
} else if (type == DATA_BLOB) {
ptr = row_mysql_read_blob_ref(&col_len, mysql_data, col_len);
}