| 1 |
# |
| 2 |
# NULL attribute and DEFAULT NULL 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_null.inc |
| 8 |
# |
| 9 |
# We will add NULL at the end of $col; |
| 10 |
# |
| 11 |
# Also, if $col_default is defined, |
| 12 |
# we will create a table with 3 columns (one with DEFAULT NULL, |
| 13 |
# one with DEFAULT $col_default, and one without any default) |
| 14 |
# |
| 15 |
|
| 16 |
--disable_warnings |
| 17 |
DROP TABLE IF EXISTS t1; |
| 18 |
--enable_warnings |
| 19 |
|
| 20 |
--let $create_definition = c $col_definition NULL |
| 21 |
--source create_table.inc |
| 22 |
SHOW COLUMNS IN t1; |
| 23 |
if ($mysql_errname) |
| 24 |
{ |
| 25 |
--source unexpected_result.inc |
| 26 |
} |
| 27 |
if (!$mysql_errname) |
| 28 |
{ |
| 29 |
INSERT INTO t1 (c) VALUES (NULL); |
| 30 |
if ($mysql_errname) |
| 31 |
{ |
| 32 |
--let $functionality = NULLable columns |
| 33 |
--source unexpected_result.inc |
| 34 |
} |
| 35 |
SELECT COUNT(c), COUNT(*) FROM t1; |
| 36 |
|
| 37 |
DROP TABLE t1; |
| 38 |
} |
| 39 |
|
| 40 |
if ($col_default != '') |
| 41 |
{ |
| 42 |
let $create_definition = |
| 43 |
c $col_definition NULL, |
| 44 |
c1 $col_definition NULL DEFAULT NULL, |
| 45 |
c2 $col_definition NULL DEFAULT $col_default |
| 46 |
; |
| 47 |
--source create_table.inc |
| 48 |
if ($mysql_errname) |
| 49 |
{ |
| 50 |
--source unexpected_result.inc |
| 51 |
} |
| 52 |
if (!$mysql_errname) |
| 53 |
{ |
| 54 |
SHOW COLUMNS IN t1; |
| 55 |
|
| 56 |
INSERT INTO t1 (c) VALUES (NULL); |
| 57 |
SELECT COUNT(c2), COUNT(c1), COUNT(c), COUNT(*) FROM t1; |
| 58 |
|
| 59 |
DROP TABLE t1; |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
# We don't want to preserve it |
| 64 |
let $col_default = ; |
| 65 |
|