Below is the list of changes that have just been committed into a local
5.1 repository of andrey. When andrey does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@stripped, 2006-10-27 20:16:41+02:00, andrey@stripped +1 -0
Fix for bug#22909
Using CREATE ... LIKE is possible to create field with invalid default value
Some values become disallowed in newer versions of the server. CREATE TABLE
(..) with such default values is not possible, but it was possible to do
CREATE TABLE ... LIKE , when the like_table was created by previous MySQL
version.
sql/sql_table.cc@stripped, 2006-10-27 20:16:29+02:00, andrey@stripped +46 -12
When creating a new table which is alike an older one
check that the default values are allowed in the newer version.
It could happen that some value is invalid for a newer version
(0001-01-01 since 5.1.12) for example. Old tables are not touched,
but disallow creation of new ones.
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: andrey
# Host: example.com
# Root: /work/bug22909/my51
--- 1.368/sql/sql_table.cc 2006-10-27 20:16:55 +02:00
+++ 1.369/sql/sql_table.cc 2006-10-27 20:16:55 +02:00
@@ -4582,6 +4582,7 @@ bool mysql_create_like_table(THD* thd, T
bool res= TRUE;
enum legacy_db_type not_used;
HA_CREATE_INFO *create_info;
+ TABLE *table_ptr;
TABLE_LIST src_tables_list;
DBUG_ENTER("mysql_create_like_table");
@@ -4633,9 +4634,7 @@ bool mysql_create_like_table(THD* thd, T
}
}
- /*
- create like should be not allowed for Views, Triggers, ...
- */
+ /* Create like should be not allowed for Views, Triggers, ... */
if (mysql_frm_type(thd, src_path, ¬_used) != FRMTYPE_TABLE)
{
my_error(ER_WRONG_OBJECT, MYF(0), src_db, src_table, "BASE TABLE");
@@ -4715,6 +4714,50 @@ bool mysql_create_like_table(THD* thd, T
}
/*
+ Let's open and lock the table: it will be closed (and
+ unlocked) by close_thread_tables() at the end of the
+ statement anyway.
+ */
+ if (!(table_ptr= open_ltable(thd, table, TL_WRITE)))
+ goto err;
+
+ /*
+ Check validity of default values because the old table could have
+ default values which are invalid in this version. For example,
+ see bug#22909.
+ We set read_set because ASSERT_COLUMN_MARKED_FOR_READ in ::val_str()
+ will crash us otherwise.
+ We set write_set because ASSERT_COLUMN_MARKED_FOR_WRITE in ::store()
+ will crash us otherwise.
+ */
+ bitmap_set_all(table_ptr->read_set);
+ bitmap_set_all(table_ptr->write_set);
+ for (Field **field= table_ptr->field; *field; field++)
+ {
+ char field_value_buffer[STRING_BUFFER_USUAL_SIZE];
+ String field_value(field_value_buffer, sizeof(field_value_buffer),
+ &my_charset_bin);
+
+ if ((*field)->is_null_in_record((uchar*)table_ptr->s->default_values))
+ {
+ (*field)->set_null();
+ // is null
+ }
+ else
+ {
+ (*field)->set_notnull();
+ (*field)->val_str(&field_value, (char*) (table_ptr->s->default_values
+
+ (*field)->offset()));
+ if ((*field)->store(field_value.c_ptr_safe(), field_value.length(),
+ &my_charset_bin))
+ {
+ my_error(ER_INVALID_DEFAULT, MYF(0), (*field)->field_name);
+ goto err;
+ }
+ }
+ }
+
+ /*
We have to write the query before we unlock the tables.
*/
if (thd->current_stmt_binlog_row_based)
@@ -4745,16 +4788,7 @@ bool mysql_create_like_table(THD* thd, T
char buf[2048];
String query(buf, sizeof(buf), system_charset_info);
query.length(0); // Have to zero it since constructor doesn't
- TABLE *table_ptr;
int error;
-
- /*
- Let's open and lock the table: it will be closed (and
- unlocked) by close_thread_tables() at the end of the
- statement anyway.
- */
- if (!(table_ptr= open_ltable(thd, table, TL_READ_NO_INSERT)))
- goto err;
int result= store_create_info(thd, table, &query, create_info);
| Thread |
|---|
| • bk commit into 5.1 tree (andrey:1.2325) BUG#22909 | ahristov | 27 Oct |