Debian Codegraph @

mysql-test/suite/storage_engine/create_table.inc

raw
1 ##################################
2 #
3 # This include file will be used for all CREATE 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 $create_definition = <column names, types, indexes) # optional, default a $int_col, b $char_col (based on defaults)
12 # --let $table_name = <table name> # optional, default t1
13 # --let $table_options = <table options> # optional, default based on define_engine.inc
14 # --let $partition_options = <partitioning definition> # optional, default none
15 # --let $as_select = <SELECT statement> # optional, default empty
16 # --let $error_codes = <expected error codes, as in --error> # optional, default 0
17 # --let $if_not_exists = [0|1] # optional, default 0 (1 adds IF NOT EXISTS clause)
18 # --let $default_engine = [0|1] # optional, default 0 (with 1 will rely on default engine, no ENGINE=)
19 # --let $temporary = [0|1] # optional, default 0 (1 adds TEMPORARY)
20 # --let $disable_query_log = [0|1] # optional, default 0 (1 disables logging of CREATE)
21 #
22 # Usage examples:
23 #
24 # --source create_table.inc -- creates a default table
25 #
26 # --let $create_definition = a INT NOT NULL, b CHAR(1) PRIMARY KEY, INDEX(a)
27 # --let $table_options = AUTO_INCREMENT = 100
28 # --let $partition_options = PARTITION BY HASH(a) PARTITIONS 2
29 # --let $as_select = SELECT 1, 'a'
30 # --source create_table.inc
31 #
32 # Additionally, a test can define $extra_tbl_options. The difference with $table_options
33 # is that its value is persistent and will be used until it is unset explicitly, or
34 # until the test ends. The purpose of it is to allow one test to call another test,
35 # when the called test does not know about specific options the calling test might require,
36 # and thus cannot set them on per-create basis.
37
38 --let $create_statement = CREATE
39
40 if ($temporary)
41 {
42 --let $create_statement = $create_statement TEMPORARY
43 }
44
45 --let $create_statement = $create_statement TABLE
46
47 if ($if_not_exists)
48 {
49 --let $create_statement = $create_statement IF NOT EXISTS
50 }
51
52 if (!$table_name)
53 {
54 --let $table_name = t1
55 }
56
57 --let $create_statement = $create_statement $table_name
58
59 if (!$create_definition)
60 {
61 # If $create_definition is not defined, and AS SELECT is requested,
62 # we should not set $create_definition to the default value,
63 # because it might be inconsistent with the SELECT.
64 if (!$as_select)
65 {
66 --let $create_definition = a $int_col, b $char_col
67 }
68 }
69
70 if ($create_definition)
71 {
72 --let $create_statement = $create_statement ($create_definition)
73 }
74
75 # If $default_engine is set, we will rely on the default storage engine
76
77 if (!$default_engine)
78 {
79 --let $create_statement = $create_statement ENGINE=$storage_engine
80 }
81
82 # Default table options from define_engine.inc
83 --let $create_statement = $create_statement $default_tbl_opts
84
85 # The calling script could request additional table options
86 if ($table_options)
87 {
88 --let $create_statement = $create_statement $table_options
89 }
90
91 # The difference between $extra_tbl_opts and $table_options
92 # is that its $extra_tbl_opts is persistent -- it will not be unset at the end of this file,
93 # and will be used until it is unset explicitly by the calling test,
94 # or until the test ends. The purpose of it is to allow one test to call another test,
95 # when the called test does not know about specific options the calling test might require,
96 # and thus cannot set them on per-create basis.
97
98 if ($extra_tbl_opts)
99 {
100 --let $create_statement = $create_statement $extra_tbl_opts
101 }
102
103 if ($as_select)
104 {
105 --let $create_statement = $create_statement AS $as_select
106 }
107
108 if ($partition_options)
109 {
110 --let $create_statement = $create_statement $partition_options
111 }
112
113 # We now have the complete CREATE statement in $create_statement.
114 # If your CREATE statement should be composed differently,
115 # modify the logic above.
116
117 #####################
118 # Here you can add logic needed BEFORE the main table creation
119 # (e.g. the table needs a base table, a reference table, etc.).
120 # Surround it by --disable_query_log/--enable_query_log
121 # if you don't want it to appear in the result output.
122 #####################
123
124 if ($disable_query_log)
125 {
126 --disable_query_log
127 }
128
129 --source obfuscate.inc
130
131 eval $create_statement;
132 --source strict_check_errors.inc
133
134 # Make sure you don't add any statements between the main CREATE (above)
135 # and saving mysql_errno and mysql_errname (below)
136 # They are saved in case you want to add more logic after the main CREATE,
137 # because we need the result code of the table creation.
138 # Also, do not change $create_statement after it is executed!
139
140 --let $my_errno = $mysql_errno
141 --let $my_errname = $mysql_errname
142
143
144 if ($disable_query_log)
145 {
146 --enable_query_log
147 }
148
149 #####################
150 # Here you can add logic needed AFTER the main table creation,
151 # e.g. triggers creation.
152 # Surround it by --disable_query_log/--enable_query_log
153 # if you don't want it to appear in the result output.
154 #####################
155
156
157 # Unset the parameters, we don't want them to be accidentally reused later
158 --let $create_definition =
159 --let $table_name = t1
160 --let $table_options =
161 --let $partition_options =
162 --let $as_select = 0
163 --let $error_codes =
164 --let $if_not_exists = 0
165 --let $default_engine = 0
166 --let $temporary = 0
167 --let $disable_query_log = 0
168
169 # Restore the error codes of the main statement
170 --let $mysql_errno = $my_errno
171 --let $mysql_errname = $my_errname
172 # Make sure you don't add any SQL statements after restoring
173 # mysql_errno and mysql_errname (above)
174