| 1 |
# |
| 2 |
# NOT NULL attribute in columns |
| 3 |
# |
| 4 |
# Usage: |
| 5 |
# let $col_definition = <column type (and possibly more options)>; |
| 6 |
# let $col_default = <default non-null value for a column>; |
| 7 |
# --source col_not_null.inc |
| 8 |
# |
| 9 |
# We will add NOT NULL at the end of $col; |
| 10 |
# |
| 11 |
# Also, if $col_default is defined, |
| 12 |
# we will create a table with 2 columns |
| 13 |
# (one with DEFAULT $col_default, and one without any default), |
| 14 |
# and will also attempt to add a column with DEFAULT NULL. |
| 15 |
# |
| 16 |
|
| 17 |
--disable_warnings |
| 18 |
DROP TABLE IF EXISTS t1; |
| 19 |
--enable_warnings |
| 20 |
|
| 21 |
--let $create_definition = c $col_definition NOT NULL |
| 22 |
--source create_table.inc |
| 23 |
if ($mysql_errname) |
| 24 |
{ |
| 25 |
--source unexpected_result.inc |
| 26 |
} |
| 27 |
if (!$mysql_errname) |
| 28 |
{ |
| 29 |
SHOW COLUMNS IN t1; |
| 30 |
|
| 31 |
--let $error_codes = ER_BAD_NULL_ERROR |
| 32 |
INSERT INTO t1 (c) VALUES (NULL); |
| 33 |
--source check_errors.inc |
| 34 |
|
| 35 |
DROP TABLE t1; |
| 36 |
} |
| 37 |
|
| 38 |
if ($col_default != '') |
| 39 |
{ |
| 40 |
let $create_definition = |
| 41 |
c $col_definition NOT NULL, |
| 42 |
c2 $col_definition NOT NULL DEFAULT $col_default |
| 43 |
; |
| 44 |
--source create_table.inc |
| 45 |
if ($mysql_errname) |
| 46 |
{ |
| 47 |
--source unexpected_result.inc |
| 48 |
} |
| 49 |
if (!$mysql_errname) |
| 50 |
{ |
| 51 |
SHOW COLUMNS IN t1; |
| 52 |
|
| 53 |
--let $error_codes = ER_INVALID_DEFAULT |
| 54 |
--let $alter_definition = ADD COLUMN err $col_definition NOT NULL DEFAULT NULL |
| 55 |
--source alter_table.inc |
| 56 |
if ($mysql_errname != ER_INVALID_DEFAULT) |
| 57 |
{ |
| 58 |
--let $functionality = ALTER or DEFAULT |
| 59 |
--source unexpected_result.inc |
| 60 |
} |
| 61 |
|
| 62 |
--let $error_codes = ER_BAD_NULL_ERROR |
| 63 |
INSERT INTO t1 (c) VALUES (NULL); |
| 64 |
--source check_errors.inc |
| 65 |
if ($mysql_errname != ER_BAD_NULL_ERROR) |
| 66 |
{ |
| 67 |
--let $functionality = NOT NULL columns |
| 68 |
--source unexpected_result.inc |
| 69 |
} |
| 70 |
|
| 71 |
# HEX should be universal for all column types |
| 72 |
SELECT HEX(c), HEX(c2) FROM t1; |
| 73 |
|
| 74 |
--let $error_codes = ER_BAD_NULL_ERROR |
| 75 |
INSERT INTO t1 (c2) VALUES (NULL); |
| 76 |
--source check_errors.inc |
| 77 |
|
| 78 |
--eval INSERT INTO t1 (c) VALUES ($col_default) |
| 79 |
if ($mysql_errname) |
| 80 |
{ |
| 81 |
--let $functionality = DEFAULT |
| 82 |
--source unexpected_result.inc |
| 83 |
} |
| 84 |
SELECT COUNT(c), COUNT(c2) FROM t1; |
| 85 |
|
| 86 |
DROP TABLE t1; |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
# We don't want to preserve it |
| 91 |
let $col_default = ; |
| 92 |
|