Merge lp:~stewart/drizzle/table-proto-message-error-checking into lp:~drizzle-trunk/drizzle/development
- table-proto-message-error-checking
- Merge into development
Proposed by
Stewart Smith
Status: | Merged |
---|---|
Merged at revision: | not available |
Proposed branch: | lp:~stewart/drizzle/table-proto-message-error-checking |
Merge into: | lp:~drizzle-trunk/drizzle/development |
Prerequisite: | lp:~stewart/drizzle/enum_field_type_to_table_message_type |
Diff against target: |
654 lines (+479/-8) 18 files modified
drizzled/error.cc (+3/-1) drizzled/error.h (+2/-1) drizzled/message/table_writer.cc (+69/-5) drizzled/plugin/storage_engine.cc (+16/-1) drizzled/table.cc (+6/-0) plugin/blackhole/ha_blackhole.cc (+7/-0) plugin/tableprototester/plugin.ini (+5/-0) plugin/tableprototester/tableprototester.cc (+292/-0) plugin/tableprototester/tableprototester.h (+58/-0) plugin/tableprototester/tests/r/basic.result (+3/-0) plugin/tableprototester/tests/r/drop_table.result (+2/-0) plugin/tableprototester/tests/r/missing_engine.result (+5/-0) plugin/tableprototester/tests/t/basic-master.opt (+1/-0) plugin/tableprototester/tests/t/basic.test (+1/-0) plugin/tableprototester/tests/t/drop_table-master.opt (+1/-0) plugin/tableprototester/tests/t/drop_table.test (+2/-0) plugin/tableprototester/tests/t/missing_engine-master.opt (+1/-0) plugin/tableprototester/tests/t/missing_engine.test (+5/-0) |
To merge this branch: | bzr merge lp:~stewart/drizzle/table-proto-message-error-checking |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Brian Aker | Pending | ||
Drizzle Developers | Pending | ||
Review via email: mp+18672@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Stewart Smith (stewart) wrote : | # |
- 1315. By Stewart Smith
-
Merged enum_field_
type_to_ table_message_ type into table-proto- message- error-checking.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'drizzled/error.cc' | |||
2 | --- drizzled/error.cc 2010-02-04 08:14:46 +0000 | |||
3 | +++ drizzled/error.cc 2010-02-08 01:35:22 +0000 | |||
4 | @@ -1418,7 +1418,9 @@ | |||
5 | 1418 | /* ER_INVALID_ENUM_VALUE */ | 1418 | /* ER_INVALID_ENUM_VALUE */ |
6 | 1419 | N_("Received an invalid enum value '%s'."), | 1419 | N_("Received an invalid enum value '%s'."), |
7 | 1420 | /* ER_NO_PRIMARY_KEY_ON_REPLICATED_TABLE */ | 1420 | /* ER_NO_PRIMARY_KEY_ON_REPLICATED_TABLE */ |
9 | 1421 | N_("Tables which are replicated require a primary key.") | 1421 | N_("Tables which are replicated require a primary key."), |
10 | 1422 | /* ER_CORRUPT_TABLE_DEFINITION */ | ||
11 | 1423 | N_("Corrupt or invalid table definition: %s") | ||
12 | 1422 | }; | 1424 | }; |
13 | 1423 | 1425 | ||
14 | 1424 | const char * error_message(unsigned int code) | 1426 | const char * error_message(unsigned int code) |
15 | 1425 | 1427 | ||
16 | === modified file 'drizzled/error.h' | |||
17 | --- drizzled/error.h 2010-02-04 08:14:46 +0000 | |||
18 | +++ drizzled/error.h 2010-02-08 01:35:22 +0000 | |||
19 | @@ -723,7 +723,8 @@ | |||
20 | 723 | ER_INVALID_TIME_VALUE, | 723 | ER_INVALID_TIME_VALUE, |
21 | 724 | ER_INVALID_ENUM_VALUE, | 724 | ER_INVALID_ENUM_VALUE, |
22 | 725 | ER_NO_PRIMARY_KEY_ON_REPLICATED_TABLE, | 725 | ER_NO_PRIMARY_KEY_ON_REPLICATED_TABLE, |
24 | 726 | ER_ERROR_LAST= ER_NO_PRIMARY_KEY_ON_REPLICATED_TABLE | 726 | ER_CORRUPT_TABLE_DEFINITION, |
25 | 727 | ER_ERROR_LAST= ER_CORRUPT_TABLE_DEFINITION | ||
26 | 727 | }; | 728 | }; |
27 | 728 | 729 | ||
28 | 729 | } /* namespace drizzled */ | 730 | } /* namespace drizzled */ |
29 | 730 | 731 | ||
30 | === modified file 'drizzled/message/table_writer.cc' | |||
31 | --- drizzled/message/table_writer.cc 2009-12-11 21:54:18 +0000 | |||
32 | +++ drizzled/message/table_writer.cc 2010-02-08 01:35:22 +0000 | |||
33 | @@ -22,6 +22,7 @@ | |||
34 | 22 | #include <iostream> | 22 | #include <iostream> |
35 | 23 | #include <fstream> | 23 | #include <fstream> |
36 | 24 | #include <string> | 24 | #include <string> |
37 | 25 | #include <getopt.h> | ||
38 | 25 | #include <drizzled/message/table.pb.h> | 26 | #include <drizzled/message/table.pb.h> |
39 | 26 | 27 | ||
40 | 27 | using namespace std; | 28 | using namespace std; |
41 | @@ -78,6 +79,13 @@ | |||
42 | 78 | index->set_is_primary(is_primary); | 79 | index->set_is_primary(is_primary); |
43 | 79 | index->set_is_unique(is_unique); | 80 | index->set_is_unique(is_unique); |
44 | 80 | 81 | ||
45 | 82 | int key_length= 0; | ||
46 | 83 | |||
47 | 84 | for(int i=0; i< num_index_parts; i++) | ||
48 | 85 | key_length+= compare_lengths[i]; | ||
49 | 86 | |||
50 | 87 | index->set_key_length(key_length); | ||
51 | 88 | |||
52 | 81 | while (x < num_index_parts) | 89 | while (x < num_index_parts) |
53 | 82 | { | 90 | { |
54 | 83 | index_part= index->add_index_part(); | 91 | index_part= index->add_index_part(); |
55 | @@ -190,21 +198,77 @@ | |||
56 | 190 | 198 | ||
57 | 191 | } | 199 | } |
58 | 192 | 200 | ||
59 | 201 | static void fill_table1(message::Table *table) | ||
60 | 202 | { | ||
61 | 203 | message::Table::Field *field; | ||
62 | 204 | message::Table::TableOptions *tableopts; | ||
63 | 205 | |||
64 | 206 | table->set_name("t1"); | ||
65 | 207 | table->set_type(message::Table::INTERNAL); | ||
66 | 208 | |||
67 | 209 | tableopts= table->mutable_options(); | ||
68 | 210 | tableopts->set_comment("Table without a StorageEngine message"); | ||
69 | 211 | |||
70 | 212 | { | ||
71 | 213 | field= table->add_field(); | ||
72 | 214 | field->set_name("number"); | ||
73 | 215 | field->set_type(message::Table::Field::INTEGER); | ||
74 | 216 | } | ||
75 | 217 | |||
76 | 218 | } | ||
77 | 219 | |||
78 | 220 | static void usage(char *argv0) | ||
79 | 221 | { | ||
80 | 222 | cerr << "Usage: " << argv0 << " [-t N] TABLE_NAME.dfe" << endl; | ||
81 | 223 | cerr << endl; | ||
82 | 224 | cerr << "-t N\tTable Number" << endl; | ||
83 | 225 | cerr << "\t0 - default" << endl; | ||
84 | 226 | cerr << endl; | ||
85 | 227 | } | ||
86 | 228 | |||
87 | 193 | int main(int argc, char* argv[]) | 229 | int main(int argc, char* argv[]) |
88 | 194 | { | 230 | { |
89 | 231 | int opt; | ||
90 | 232 | int table_number= 0; | ||
91 | 233 | |||
92 | 195 | GOOGLE_PROTOBUF_VERIFY_VERSION; | 234 | GOOGLE_PROTOBUF_VERIFY_VERSION; |
93 | 196 | 235 | ||
95 | 197 | if (argc != 2) | 236 | while ((opt= getopt(argc, argv, "t:")) != -1) |
96 | 198 | { | 237 | { |
99 | 199 | cerr << "Usage: " << argv[0] << " SCHEMA" << endl; | 238 | switch (opt) |
100 | 200 | return -1; | 239 | { |
101 | 240 | case 't': | ||
102 | 241 | table_number= atoi(optarg); | ||
103 | 242 | break; | ||
104 | 243 | default: | ||
105 | 244 | usage(argv[0]); | ||
106 | 245 | exit(EXIT_FAILURE); | ||
107 | 246 | } | ||
108 | 247 | } | ||
109 | 248 | |||
110 | 249 | if (optind >= argc) { | ||
111 | 250 | fprintf(stderr, "Expected Table name argument\n\n"); | ||
112 | 251 | usage(argv[0]); | ||
113 | 252 | exit(EXIT_FAILURE); | ||
114 | 201 | } | 253 | } |
115 | 202 | 254 | ||
116 | 203 | message::Table table; | 255 | message::Table table; |
117 | 204 | 256 | ||
119 | 205 | fill_table(&table, "example_table"); | 257 | switch (table_number) |
120 | 258 | { | ||
121 | 259 | case 0: | ||
122 | 260 | fill_table(&table, "example_table"); | ||
123 | 261 | break; | ||
124 | 262 | case 1: | ||
125 | 263 | fill_table1(&table); | ||
126 | 264 | break; | ||
127 | 265 | default: | ||
128 | 266 | fprintf(stderr, "Invalid table number.\n\n"); | ||
129 | 267 | usage(argv[0]); | ||
130 | 268 | exit(EXIT_FAILURE); | ||
131 | 269 | } | ||
132 | 206 | 270 | ||
134 | 207 | fstream output(argv[1], ios::out | ios::trunc | ios::binary); | 271 | fstream output(argv[optind], ios::out | ios::trunc | ios::binary); |
135 | 208 | if (!table.SerializeToOstream(&output)) | 272 | if (!table.SerializeToOstream(&output)) |
136 | 209 | { | 273 | { |
137 | 210 | cerr << "Failed to write schema." << endl; | 274 | cerr << "Failed to write schema." << endl; |
138 | 211 | 275 | ||
139 | === modified file 'drizzled/plugin/storage_engine.cc' | |||
140 | --- drizzled/plugin/storage_engine.cc 2010-02-04 08:14:46 +0000 | |||
141 | +++ drizzled/plugin/storage_engine.cc 2010-02-08 01:35:22 +0000 | |||
142 | @@ -579,7 +579,7 @@ | |||
143 | 579 | if (ret != ENOENT) | 579 | if (ret != ENOENT) |
144 | 580 | *err= ret; | 580 | *err= ret; |
145 | 581 | 581 | ||
147 | 582 | return *err == EEXIST; | 582 | return *err == EEXIST || *err != ENOENT; |
148 | 583 | } | 583 | } |
149 | 584 | }; | 584 | }; |
150 | 585 | 585 | ||
151 | @@ -705,6 +705,13 @@ | |||
152 | 705 | identifier, | 705 | identifier, |
153 | 706 | &src_proto); | 706 | &src_proto); |
154 | 707 | 707 | ||
155 | 708 | if (error_proto == ER_CORRUPT_TABLE_DEFINITION) | ||
156 | 709 | { | ||
157 | 710 | my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0), | ||
158 | 711 | src_proto.InitializationErrorString().c_str()); | ||
159 | 712 | return ER_CORRUPT_TABLE_DEFINITION; | ||
160 | 713 | } | ||
161 | 714 | |||
162 | 708 | engine= plugin::StorageEngine::findByName(session, | 715 | engine= plugin::StorageEngine::findByName(session, |
163 | 709 | src_proto.engine().name()); | 716 | src_proto.engine().name()); |
164 | 710 | 717 | ||
165 | @@ -732,6 +739,14 @@ | |||
166 | 732 | if (error_proto && error == 0) | 739 | if (error_proto && error == 0) |
167 | 733 | return 0; | 740 | return 0; |
168 | 734 | 741 | ||
169 | 742 | if (((error_proto != EEXIST && error_proto != ENOENT) | ||
170 | 743 | && !engine && generate_warning) | ||
171 | 744 | | ( error && !engine && generate_warning)) | ||
172 | 745 | { | ||
173 | 746 | my_error(ER_GET_ERRNO, MYF(0), error_proto); | ||
174 | 747 | return error_proto; | ||
175 | 748 | } | ||
176 | 749 | |||
177 | 735 | if (error && generate_warning) | 750 | if (error && generate_warning) |
178 | 736 | { | 751 | { |
179 | 737 | /* | 752 | /* |
180 | 738 | 753 | ||
181 | === modified file 'drizzled/table.cc' | |||
182 | --- drizzled/table.cc 2010-02-08 01:35:22 +0000 | |||
183 | +++ drizzled/table.cc 2010-02-08 01:35:22 +0000 | |||
184 | @@ -262,6 +262,12 @@ | |||
185 | 262 | { | 262 | { |
186 | 263 | int error= 0; | 263 | int error= 0; |
187 | 264 | 264 | ||
188 | 265 | if (! table.IsInitialized()) | ||
189 | 266 | { | ||
190 | 267 | my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0), table.InitializationErrorString().c_str()); | ||
191 | 268 | return ER_CORRUPT_TABLE_DEFINITION; | ||
192 | 269 | } | ||
193 | 270 | |||
194 | 265 | share->setTableProto(new(nothrow) message::Table(table)); | 271 | share->setTableProto(new(nothrow) message::Table(table)); |
195 | 266 | 272 | ||
196 | 267 | share->storage_engine= plugin::StorageEngine::findByName(session, table.engine().name()); | 273 | share->storage_engine= plugin::StorageEngine::findByName(session, table.engine().name()); |
197 | 268 | 274 | ||
198 | === modified file 'plugin/blackhole/ha_blackhole.cc' | |||
199 | --- plugin/blackhole/ha_blackhole.cc 2010-02-04 08:14:46 +0000 | |||
200 | +++ plugin/blackhole/ha_blackhole.cc 2010-02-08 01:35:22 +0000 | |||
201 | @@ -259,6 +259,13 @@ | |||
202 | 259 | { | 259 | { |
203 | 260 | close(fd); | 260 | close(fd); |
204 | 261 | delete input; | 261 | delete input; |
205 | 262 | if (! table_proto->IsInitialized()) | ||
206 | 263 | { | ||
207 | 264 | my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0), | ||
208 | 265 | table_proto->InitializationErrorString().c_str()); | ||
209 | 266 | return ER_CORRUPT_TABLE_DEFINITION; | ||
210 | 267 | } | ||
211 | 268 | |||
212 | 262 | return HA_ERR_CRASHED_ON_USAGE; | 269 | return HA_ERR_CRASHED_ON_USAGE; |
213 | 263 | } | 270 | } |
214 | 264 | 271 | ||
215 | 265 | 272 | ||
216 | === added directory 'plugin/tableprototester' | |||
217 | === added file 'plugin/tableprototester/plugin.ini' | |||
218 | --- plugin/tableprototester/plugin.ini 1970-01-01 00:00:00 +0000 | |||
219 | +++ plugin/tableprototester/plugin.ini 2010-02-08 01:35:22 +0000 | |||
220 | @@ -0,0 +1,5 @@ | |||
221 | 1 | [plugin] | ||
222 | 2 | title=Table Proto Message Tester | ||
223 | 3 | description=Used only to test other bits of the server. | ||
224 | 4 | sources=tableprototester.cc | ||
225 | 5 | headers=tableprototester.h | ||
226 | 0 | 6 | ||
227 | === added file 'plugin/tableprototester/tableprototester.cc' | |||
228 | --- plugin/tableprototester/tableprototester.cc 1970-01-01 00:00:00 +0000 | |||
229 | +++ plugin/tableprototester/tableprototester.cc 2010-02-08 01:35:22 +0000 | |||
230 | @@ -0,0 +1,292 @@ | |||
231 | 1 | /* | ||
232 | 2 | Copyright (C) 2010 Stewart Smith | ||
233 | 3 | |||
234 | 4 | This program is free software; you can redistribute it and/or | ||
235 | 5 | modify it under the terms of the GNU General Public License | ||
236 | 6 | as published by the Free Software Foundation; either version 2 | ||
237 | 7 | of the License, or (at your option) any later version. | ||
238 | 8 | |||
239 | 9 | This program is distributed in the hope that it will be useful, | ||
240 | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
241 | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
242 | 12 | GNU General Public License for more details. | ||
243 | 13 | |||
244 | 14 | You should have received a copy of the GNU General Public License | ||
245 | 15 | along with this program; if not, write to the Free Software | ||
246 | 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
247 | 17 | */ | ||
248 | 18 | |||
249 | 19 | #include "config.h" | ||
250 | 20 | #include <drizzled/table.h> | ||
251 | 21 | #include <drizzled/error.h> | ||
252 | 22 | #include "drizzled/internal/my_pthread.h" | ||
253 | 23 | |||
254 | 24 | #include "tableprototester.h" | ||
255 | 25 | |||
256 | 26 | #include <fcntl.h> | ||
257 | 27 | |||
258 | 28 | #include <string> | ||
259 | 29 | #include <map> | ||
260 | 30 | #include <fstream> | ||
261 | 31 | #include <drizzled/message/table.pb.h> | ||
262 | 32 | #include "drizzled/internal/m_string.h" | ||
263 | 33 | |||
264 | 34 | #include "drizzled/global_charset_info.h" | ||
265 | 35 | |||
266 | 36 | |||
267 | 37 | using namespace std; | ||
268 | 38 | using namespace google; | ||
269 | 39 | using namespace drizzled; | ||
270 | 40 | |||
271 | 41 | #define TABLEPROTOTESTER_EXT ".TBT" | ||
272 | 42 | |||
273 | 43 | static const char *TableProtoTesterCursor_exts[] = { | ||
274 | 44 | NULL | ||
275 | 45 | }; | ||
276 | 46 | |||
277 | 47 | class TableProtoTesterEngine : public drizzled::plugin::StorageEngine | ||
278 | 48 | { | ||
279 | 49 | public: | ||
280 | 50 | TableProtoTesterEngine(const string &name_arg) | ||
281 | 51 | : drizzled::plugin::StorageEngine(name_arg, | ||
282 | 52 | HTON_NULL_IN_KEY | | ||
283 | 53 | HTON_CAN_INDEX_BLOBS | | ||
284 | 54 | HTON_SKIP_STORE_LOCK | | ||
285 | 55 | HTON_AUTO_PART_KEY | | ||
286 | 56 | HTON_HAS_DATA_DICTIONARY) | ||
287 | 57 | { | ||
288 | 58 | table_definition_ext= TABLEPROTOTESTER_EXT; | ||
289 | 59 | } | ||
290 | 60 | |||
291 | 61 | virtual Cursor *create(TableShare &table, | ||
292 | 62 | drizzled::memory::Root *mem_root) | ||
293 | 63 | { | ||
294 | 64 | return new (mem_root) TableProtoTesterCursor(*this, table); | ||
295 | 65 | } | ||
296 | 66 | |||
297 | 67 | const char **bas_ext() const { | ||
298 | 68 | return TableProtoTesterCursor_exts; | ||
299 | 69 | } | ||
300 | 70 | |||
301 | 71 | int doCreateTable(Session*, | ||
302 | 72 | const char *, | ||
303 | 73 | Table&, | ||
304 | 74 | drizzled::message::Table&); | ||
305 | 75 | |||
306 | 76 | int doDropTable(Session&, const string table_name); | ||
307 | 77 | |||
308 | 78 | int doGetTableDefinition(Session& session, | ||
309 | 79 | const char* path, | ||
310 | 80 | const char *db, | ||
311 | 81 | const char *table_name, | ||
312 | 82 | const bool is_tmp, | ||
313 | 83 | drizzled::message::Table *table_proto); | ||
314 | 84 | |||
315 | 85 | void doGetTableNames(drizzled::CachedDirectory &directory, | ||
316 | 86 | string&, set<string>& set_of_names) | ||
317 | 87 | { | ||
318 | 88 | (void)directory; | ||
319 | 89 | set_of_names.insert("t1"); | ||
320 | 90 | |||
321 | 91 | } | ||
322 | 92 | |||
323 | 93 | /* The following defines can be increased if necessary */ | ||
324 | 94 | uint32_t max_supported_keys() const { return 64; } | ||
325 | 95 | uint32_t max_supported_key_length() const { return 1000; } | ||
326 | 96 | uint32_t max_supported_key_part_length() const { return 1000; } | ||
327 | 97 | |||
328 | 98 | uint32_t index_flags(enum ha_key_alg) const | ||
329 | 99 | { | ||
330 | 100 | return (HA_READ_NEXT | | ||
331 | 101 | HA_READ_PREV | | ||
332 | 102 | HA_READ_RANGE | | ||
333 | 103 | HA_READ_ORDER | | ||
334 | 104 | HA_KEYREAD_ONLY); | ||
335 | 105 | } | ||
336 | 106 | |||
337 | 107 | }; | ||
338 | 108 | |||
339 | 109 | TableProtoTesterCursor::TableProtoTesterCursor(drizzled::plugin::StorageEngine &engine_arg, | ||
340 | 110 | TableShare &table_arg) | ||
341 | 111 | :Cursor(engine_arg, table_arg) | ||
342 | 112 | { } | ||
343 | 113 | |||
344 | 114 | int TableProtoTesterCursor::open(const char *, int, uint32_t) | ||
345 | 115 | { | ||
346 | 116 | return(0); | ||
347 | 117 | } | ||
348 | 118 | |||
349 | 119 | int TableProtoTesterCursor::close(void) | ||
350 | 120 | { | ||
351 | 121 | return 0; | ||
352 | 122 | } | ||
353 | 123 | |||
354 | 124 | int TableProtoTesterEngine::doCreateTable(Session*, const char *, | ||
355 | 125 | Table&, | ||
356 | 126 | drizzled::message::Table&) | ||
357 | 127 | { | ||
358 | 128 | return EEXIST; | ||
359 | 129 | } | ||
360 | 130 | |||
361 | 131 | |||
362 | 132 | int TableProtoTesterEngine::doDropTable(Session&, const string) | ||
363 | 133 | { | ||
364 | 134 | return EPERM; | ||
365 | 135 | } | ||
366 | 136 | |||
367 | 137 | static void fill_table1(message::Table *table) | ||
368 | 138 | { | ||
369 | 139 | message::Table::Field *field; | ||
370 | 140 | message::Table::TableOptions *tableopts; | ||
371 | 141 | |||
372 | 142 | table->set_name("t1"); | ||
373 | 143 | table->set_type(message::Table::INTERNAL); | ||
374 | 144 | |||
375 | 145 | tableopts= table->mutable_options(); | ||
376 | 146 | tableopts->set_comment("Table without a StorageEngine message"); | ||
377 | 147 | |||
378 | 148 | { | ||
379 | 149 | field= table->add_field(); | ||
380 | 150 | field->set_name("number"); | ||
381 | 151 | field->set_type(message::Table::Field::INTEGER); | ||
382 | 152 | } | ||
383 | 153 | |||
384 | 154 | } | ||
385 | 155 | int TableProtoTesterEngine::doGetTableDefinition(Session&, | ||
386 | 156 | const char* path, | ||
387 | 157 | const char *, | ||
388 | 158 | const char *, | ||
389 | 159 | const bool, | ||
390 | 160 | drizzled::message::Table *table_proto) | ||
391 | 161 | { | ||
392 | 162 | if (strcmp(path, "./test/t1") == 0) | ||
393 | 163 | { | ||
394 | 164 | if (table_proto) | ||
395 | 165 | fill_table1(table_proto); | ||
396 | 166 | return EEXIST; | ||
397 | 167 | } | ||
398 | 168 | return ENOENT; | ||
399 | 169 | } | ||
400 | 170 | |||
401 | 171 | const char *TableProtoTesterCursor::index_type(uint32_t) | ||
402 | 172 | { | ||
403 | 173 | return("BTREE"); | ||
404 | 174 | } | ||
405 | 175 | |||
406 | 176 | int TableProtoTesterCursor::write_row(unsigned char *) | ||
407 | 177 | { | ||
408 | 178 | return(table->next_number_field ? update_auto_increment() : 0); | ||
409 | 179 | } | ||
410 | 180 | |||
411 | 181 | int TableProtoTesterCursor::rnd_init(bool) | ||
412 | 182 | { | ||
413 | 183 | return(0); | ||
414 | 184 | } | ||
415 | 185 | |||
416 | 186 | |||
417 | 187 | int TableProtoTesterCursor::rnd_next(unsigned char *) | ||
418 | 188 | { | ||
419 | 189 | return(HA_ERR_END_OF_FILE); | ||
420 | 190 | } | ||
421 | 191 | |||
422 | 192 | |||
423 | 193 | int TableProtoTesterCursor::rnd_pos(unsigned char *, unsigned char *) | ||
424 | 194 | { | ||
425 | 195 | assert(0); | ||
426 | 196 | return(0); | ||
427 | 197 | } | ||
428 | 198 | |||
429 | 199 | |||
430 | 200 | void TableProtoTesterCursor::position(const unsigned char *) | ||
431 | 201 | { | ||
432 | 202 | assert(0); | ||
433 | 203 | return; | ||
434 | 204 | } | ||
435 | 205 | |||
436 | 206 | |||
437 | 207 | int TableProtoTesterCursor::info(uint32_t flag) | ||
438 | 208 | { | ||
439 | 209 | memset(&stats, 0, sizeof(stats)); | ||
440 | 210 | if (flag & HA_STATUS_AUTO) | ||
441 | 211 | stats.auto_increment_value= 1; | ||
442 | 212 | return(0); | ||
443 | 213 | } | ||
444 | 214 | |||
445 | 215 | |||
446 | 216 | int TableProtoTesterCursor::index_read_map(unsigned char *, const unsigned char *, | ||
447 | 217 | key_part_map, enum ha_rkey_function) | ||
448 | 218 | { | ||
449 | 219 | return(HA_ERR_END_OF_FILE); | ||
450 | 220 | } | ||
451 | 221 | |||
452 | 222 | |||
453 | 223 | int TableProtoTesterCursor::index_read_idx_map(unsigned char *, uint32_t, const unsigned char *, | ||
454 | 224 | key_part_map, enum ha_rkey_function) | ||
455 | 225 | { | ||
456 | 226 | return(HA_ERR_END_OF_FILE); | ||
457 | 227 | } | ||
458 | 228 | |||
459 | 229 | |||
460 | 230 | int TableProtoTesterCursor::index_read_last_map(unsigned char *, const unsigned char *, key_part_map) | ||
461 | 231 | { | ||
462 | 232 | return(HA_ERR_END_OF_FILE); | ||
463 | 233 | } | ||
464 | 234 | |||
465 | 235 | |||
466 | 236 | int TableProtoTesterCursor::index_next(unsigned char *) | ||
467 | 237 | { | ||
468 | 238 | return(HA_ERR_END_OF_FILE); | ||
469 | 239 | } | ||
470 | 240 | |||
471 | 241 | |||
472 | 242 | int TableProtoTesterCursor::index_prev(unsigned char *) | ||
473 | 243 | { | ||
474 | 244 | return(HA_ERR_END_OF_FILE); | ||
475 | 245 | } | ||
476 | 246 | |||
477 | 247 | |||
478 | 248 | int TableProtoTesterCursor::index_first(unsigned char *) | ||
479 | 249 | { | ||
480 | 250 | return(HA_ERR_END_OF_FILE); | ||
481 | 251 | } | ||
482 | 252 | |||
483 | 253 | |||
484 | 254 | int TableProtoTesterCursor::index_last(unsigned char *) | ||
485 | 255 | { | ||
486 | 256 | return(HA_ERR_END_OF_FILE); | ||
487 | 257 | } | ||
488 | 258 | |||
489 | 259 | static drizzled::plugin::StorageEngine *tableprototester_engine= NULL; | ||
490 | 260 | |||
491 | 261 | static int tableprototester_init(drizzled::plugin::Registry ®istry) | ||
492 | 262 | { | ||
493 | 263 | |||
494 | 264 | tableprototester_engine= new TableProtoTesterEngine("TABLEPROTOTESTER"); | ||
495 | 265 | registry.add(tableprototester_engine); | ||
496 | 266 | |||
497 | 267 | return 0; | ||
498 | 268 | } | ||
499 | 269 | |||
500 | 270 | static int tableprototester_fini(drizzled::plugin::Registry ®istry) | ||
501 | 271 | { | ||
502 | 272 | registry.remove(tableprototester_engine); | ||
503 | 273 | delete tableprototester_engine; | ||
504 | 274 | |||
505 | 275 | return 0; | ||
506 | 276 | } | ||
507 | 277 | |||
508 | 278 | DRIZZLE_DECLARE_PLUGIN | ||
509 | 279 | { | ||
510 | 280 | DRIZZLE_VERSION_ID, | ||
511 | 281 | "TABLEPROTOTESTER", | ||
512 | 282 | "1.0", | ||
513 | 283 | "Stewart Smith", | ||
514 | 284 | "Used to test rest of server with various table proto messages", | ||
515 | 285 | PLUGIN_LICENSE_GPL, | ||
516 | 286 | tableprototester_init, /* Plugin Init */ | ||
517 | 287 | tableprototester_fini, /* Plugin Deinit */ | ||
518 | 288 | NULL, /* status variables */ | ||
519 | 289 | NULL, /* system variables */ | ||
520 | 290 | NULL /* config options */ | ||
521 | 291 | } | ||
522 | 292 | DRIZZLE_DECLARE_PLUGIN_END; | ||
523 | 0 | 293 | ||
524 | === added file 'plugin/tableprototester/tableprototester.h' | |||
525 | --- plugin/tableprototester/tableprototester.h 1970-01-01 00:00:00 +0000 | |||
526 | +++ plugin/tableprototester/tableprototester.h 2010-02-08 01:35:22 +0000 | |||
527 | @@ -0,0 +1,58 @@ | |||
528 | 1 | /* | ||
529 | 2 | Copyright (C) 2010 Stewart Smith | ||
530 | 3 | |||
531 | 4 | This program is free software; you can redistribute it and/or | ||
532 | 5 | modify it under the terms of the GNU General Public License | ||
533 | 6 | as published by the Free Software Foundation; either version 2 | ||
534 | 7 | of the License, or (at your option) any later version. | ||
535 | 8 | |||
536 | 9 | This program is distributed in the hope that it will be useful, | ||
537 | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
538 | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
539 | 12 | GNU General Public License for more details. | ||
540 | 13 | |||
541 | 14 | You should have received a copy of the GNU General Public License | ||
542 | 15 | along with this program; if not, write to the Free Software | ||
543 | 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
544 | 17 | */ | ||
545 | 18 | |||
546 | 19 | #ifndef PLUGIN_TABLEPROTOTESTER_TABLEPROTOTESTER_H | ||
547 | 20 | #define PLUGIN_TABLEPROTOTESTER_TABLEPROTOTESTER_H | ||
548 | 21 | |||
549 | 22 | #include <drizzled/cursor.h> | ||
550 | 23 | |||
551 | 24 | class TableProtoTesterCursor: public drizzled::Cursor | ||
552 | 25 | { | ||
553 | 26 | public: | ||
554 | 27 | TableProtoTesterCursor(drizzled::plugin::StorageEngine &engine, drizzled::TableShare &table_arg); | ||
555 | 28 | ~TableProtoTesterCursor() | ||
556 | 29 | {} | ||
557 | 30 | |||
558 | 31 | /* | ||
559 | 32 | The name of the index type that will be used for display | ||
560 | 33 | don't implement this method unless you really have indexes | ||
561 | 34 | */ | ||
562 | 35 | const char *index_type(uint32_t key_number); | ||
563 | 36 | uint32_t index_flags(uint32_t inx) const; | ||
564 | 37 | int open(const char *name, int mode, uint32_t test_if_locked); | ||
565 | 38 | int close(void); | ||
566 | 39 | int write_row(unsigned char * buf); | ||
567 | 40 | int rnd_init(bool scan); | ||
568 | 41 | int rnd_next(unsigned char *buf); | ||
569 | 42 | int rnd_pos(unsigned char * buf, unsigned char *pos); | ||
570 | 43 | |||
571 | 44 | int index_read_map(unsigned char * buf, const unsigned char * key, drizzled::key_part_map keypart_map, | ||
572 | 45 | drizzled::ha_rkey_function find_flag); | ||
573 | 46 | int index_read_idx_map(unsigned char * buf, uint32_t idx, const unsigned char * key, | ||
574 | 47 | drizzled::key_part_map keypart_map, | ||
575 | 48 | drizzled::ha_rkey_function find_flag); | ||
576 | 49 | int index_read_last_map(unsigned char * buf, const unsigned char * key, drizzled::key_part_map keypart_map); | ||
577 | 50 | int index_next(unsigned char * buf); | ||
578 | 51 | int index_prev(unsigned char * buf); | ||
579 | 52 | int index_first(unsigned char * buf); | ||
580 | 53 | int index_last(unsigned char * buf); | ||
581 | 54 | void position(const unsigned char *record); | ||
582 | 55 | int info(uint32_t flag); | ||
583 | 56 | }; | ||
584 | 57 | |||
585 | 58 | #endif /* PLUGIN_TABLEPROTOTESTER_TABLEPROTOTESTER_H */ | ||
586 | 0 | 59 | ||
587 | === added directory 'plugin/tableprototester/tests' | |||
588 | === added directory 'plugin/tableprototester/tests/r' | |||
589 | === added file 'plugin/tableprototester/tests/r/basic.result' | |||
590 | --- plugin/tableprototester/tests/r/basic.result 1970-01-01 00:00:00 +0000 | |||
591 | +++ plugin/tableprototester/tests/r/basic.result 2010-02-08 01:35:22 +0000 | |||
592 | @@ -0,0 +1,3 @@ | |||
593 | 1 | SHOW TABLES; | ||
594 | 2 | Tables_in_test | ||
595 | 3 | t1 | ||
596 | 0 | 4 | ||
597 | === added file 'plugin/tableprototester/tests/r/drop_table.result' | |||
598 | --- plugin/tableprototester/tests/r/drop_table.result 1970-01-01 00:00:00 +0000 | |||
599 | +++ plugin/tableprototester/tests/r/drop_table.result 2010-02-08 01:35:22 +0000 | |||
600 | @@ -0,0 +1,2 @@ | |||
601 | 1 | DROP TABLE t1; | ||
602 | 2 | ERROR HY000: Got error 17 from storage engine | ||
603 | 0 | 3 | ||
604 | === added file 'plugin/tableprototester/tests/r/missing_engine.result' | |||
605 | --- plugin/tableprototester/tests/r/missing_engine.result 1970-01-01 00:00:00 +0000 | |||
606 | +++ plugin/tableprototester/tests/r/missing_engine.result 2010-02-08 01:35:22 +0000 | |||
607 | @@ -0,0 +1,5 @@ | |||
608 | 1 | SHOW TABLES; | ||
609 | 2 | Tables_in_test | ||
610 | 3 | t1 | ||
611 | 4 | SHOW CREATE TABLE t1; | ||
612 | 5 | ERROR HY000: Corrupt or invalid table definition: engine | ||
613 | 0 | 6 | ||
614 | === added directory 'plugin/tableprototester/tests/t' | |||
615 | === added file 'plugin/tableprototester/tests/t/basic-master.opt' | |||
616 | --- plugin/tableprototester/tests/t/basic-master.opt 1970-01-01 00:00:00 +0000 | |||
617 | +++ plugin/tableprototester/tests/t/basic-master.opt 2010-02-08 01:35:22 +0000 | |||
618 | @@ -0,0 +1,1 @@ | |||
619 | 1 | --plugin_add=tableprototester | ||
620 | 0 | 2 | ||
621 | === added file 'plugin/tableprototester/tests/t/basic.test' | |||
622 | --- plugin/tableprototester/tests/t/basic.test 1970-01-01 00:00:00 +0000 | |||
623 | +++ plugin/tableprototester/tests/t/basic.test 2010-02-08 01:35:22 +0000 | |||
624 | @@ -0,0 +1,1 @@ | |||
625 | 1 | SHOW TABLES; | ||
626 | 0 | 2 | ||
627 | === added file 'plugin/tableprototester/tests/t/drop_table-master.opt' | |||
628 | --- plugin/tableprototester/tests/t/drop_table-master.opt 1970-01-01 00:00:00 +0000 | |||
629 | +++ plugin/tableprototester/tests/t/drop_table-master.opt 2010-02-08 01:35:22 +0000 | |||
630 | @@ -0,0 +1,1 @@ | |||
631 | 1 | --plugin_add=tableprototester | ||
632 | 0 | 2 | ||
633 | === added file 'plugin/tableprototester/tests/t/drop_table.test' | |||
634 | --- plugin/tableprototester/tests/t/drop_table.test 1970-01-01 00:00:00 +0000 | |||
635 | +++ plugin/tableprototester/tests/t/drop_table.test 2010-02-08 01:35:22 +0000 | |||
636 | @@ -0,0 +1,2 @@ | |||
637 | 1 | --error 1030 | ||
638 | 2 | DROP TABLE t1; | ||
639 | 0 | 3 | ||
640 | === added file 'plugin/tableprototester/tests/t/missing_engine-master.opt' | |||
641 | --- plugin/tableprototester/tests/t/missing_engine-master.opt 1970-01-01 00:00:00 +0000 | |||
642 | +++ plugin/tableprototester/tests/t/missing_engine-master.opt 2010-02-08 01:35:22 +0000 | |||
643 | @@ -0,0 +1,1 @@ | |||
644 | 1 | --plugin_add=tableprototester | ||
645 | 0 | 2 | ||
646 | === added file 'plugin/tableprototester/tests/t/missing_engine.test' | |||
647 | --- plugin/tableprototester/tests/t/missing_engine.test 1970-01-01 00:00:00 +0000 | |||
648 | +++ plugin/tableprototester/tests/t/missing_engine.test 2010-02-08 01:35:22 +0000 | |||
649 | @@ -0,0 +1,5 @@ | |||
650 | 1 | |||
651 | 2 | SHOW TABLES; | ||
652 | 3 | |||
653 | 4 | --error 1693 | ||
654 | 5 | SHOW CREATE TABLE t1; |
Fix error reporting on bad table protobuf messages.
Also introduce testing of this.
We use a storage engine that presents tables and definitions to test server
functions such as parse_table_proto() instead of writing the proto out to a
file as some versions of the protobuf lib won't let you write out a proto
message that's missing required fields but within the server, it's possible
to get a message that is missing these fields.
We load this plugin ONLY for the test suite. It is NEVER designed to be used
by end users *at all*.