| 1 |
################################## |
| 2 |
# |
| 3 |
# This include file will be used for all ALTER TABLE statements in the suite. |
| 4 |
# If you need to add additional steps or change the logic, copy the file |
| 5 |
# to storage/<engine>/mysql-test/storage_engine/ folder and modify it there. |
| 6 |
# |
| 7 |
################## |
| 8 |
# |
| 9 |
# Parameters: |
| 10 |
# |
| 11 |
# --let $alter_definition = <alter definition> # mandatory, everything that goes after the table name in ALTER statement |
| 12 |
# --let $table_name = <table name> # optional, default t1 |
| 13 |
# --let $error_codes = <expected error codes, as in --error> # optional, default 0 |
| 14 |
# --let $online = [0|1] # optional, default 0 (1 adds ONLINE) |
| 15 |
# --let $rename_to = <new table name> # optional, default empty. |
| 16 |
# # If set, means we are running RENAME TO, then alter definition is ignored |
| 17 |
# |
| 18 |
# Usage examples: |
| 19 |
# |
| 20 |
# --let $alter_definition = ADD COLUMN b $char_col DEFAULT '' |
| 21 |
# |
| 22 |
|
| 23 |
if ($rename_to) |
| 24 |
{ |
| 25 |
--let $alter_definition = RENAME TO $rename_to |
| 26 |
} |
| 27 |
|
| 28 |
if (!$alter_definition) |
| 29 |
{ |
| 30 |
--die # The ALTER statement is empty |
| 31 |
} |
| 32 |
|
| 33 |
--let $alter_statement = ALTER |
| 34 |
|
| 35 |
if ($online) |
| 36 |
{ |
| 37 |
--let $alter_statement = $alter_statement ONLINE |
| 38 |
} |
| 39 |
|
| 40 |
if (!$table_name) |
| 41 |
{ |
| 42 |
--let $table_name = t1 |
| 43 |
} |
| 44 |
|
| 45 |
--let $alter_statement = $alter_statement TABLE $table_name $alter_definition |
| 46 |
|
| 47 |
|
| 48 |
# We now have the complete ALTER statement in $alter_statement. |
| 49 |
# If your ALTER statement should be composed differently, |
| 50 |
# modify the logic above. |
| 51 |
|
| 52 |
##################### |
| 53 |
# Here you can add logic needed BEFORE the main statement |
| 54 |
# (e.g. base tables need to be altered, etc.). |
| 55 |
# Surround it by --disable_query_log/--enable_query_log |
| 56 |
# if you don't want it to appear in the result output. |
| 57 |
##################### |
| 58 |
|
| 59 |
--source obfuscate.inc |
| 60 |
|
| 61 |
eval $alter_statement; |
| 62 |
--source check_errors.inc |
| 63 |
|
| 64 |
# Make sure you don't add any statements between the main ALTER (above) |
| 65 |
# and saving mysql_errno and mysql_errname (below) |
| 66 |
# They are saved in case you want to add more logic after the main ALTER, |
| 67 |
# because we need the result code of the statement. |
| 68 |
# Also, do not change $alter_statement after it is executed! |
| 69 |
|
| 70 |
--let $my_errno = $mysql_errno |
| 71 |
--let $my_errname = $mysql_errname |
| 72 |
|
| 73 |
##################### |
| 74 |
# Here you can add logic needed AFTER the main statement. |
| 75 |
# Surround it by --disable_query_log/--enable_query_log |
| 76 |
# if you don't want it to appear in the result output. |
| 77 |
##################### |
| 78 |
|
| 79 |
# Unset the parameters, we don't want them to be accidentally reused later |
| 80 |
--let $alter_definition = |
| 81 |
--let $table_name = |
| 82 |
--let $error_codes = |
| 83 |
--let $online = 0 |
| 84 |
--let $rename_to = |
| 85 |
|
| 86 |
# Restore the error codes of the main statement |
| 87 |
--let $mysql_errno = $my_errno |
| 88 |
--let $mysql_errname = $my_errname |
| 89 |
# Make sure you don't add any SQL statements after restoring |
| 90 |
# mysql_errno and mysql_errname (above) |
| 91 |
|