Merge lp:~mohyt/drizzle/json_server_table into lp:drizzle
- json_server_table
- Merge into 7.2
Proposed by
Mohit Srivastava
Status: | Needs review |
---|---|
Proposed branch: | lp:~mohyt/drizzle/json_server_table |
Merge into: | lp:drizzle |
Diff against target: |
738 lines (+423/-49) 8 files modified
drizzled/sql_table.cc (+151/-8) drizzled/sql_table.h (+2/-0) plugin/json_server/ddl/table.cc (+64/-0) plugin/json_server/ddl/table.h (+61/-0) plugin/json_server/json_server.cc (+98/-40) plugin/json_server/plugin.ini (+3/-1) plugin/json_server/tests/r/basic.result (+27/-0) plugin/json_server/tests/t/basic.test (+17/-0) |
To merge this branch: | bzr merge lp:~mohyt/drizzle/json_server_table |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Stewart Smith | Pending | ||
Review via email: mp+181014@code.launchpad.net |
Commit message
Added drop table functionality
Description of the change
To post a comment you must log in.
- 2644. By Mohit Srivastava
-
Updating Copyright year
- 2645. By Mohit Srivastava
-
Now able to drop table if exists.
Similar to:
DROP TABLE IF_EXISTS [TABLE_NAME]
Unmerged revisions
- 2645. By Mohit Srivastava
-
Now able to drop table if exists.
Similar to:
DROP TABLE IF_EXISTS [TABLE_NAME] - 2644. By Mohit Srivastava
-
Updating Copyright year
- 2643. By Mohit Srivastava
-
Adding functionality of table drop.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'drizzled/sql_table.cc' |
2 | --- drizzled/sql_table.cc 2013-03-03 02:44:39 +0000 |
3 | +++ drizzled/sql_table.cc 2013-08-22 06:28:00 +0000 |
4 | @@ -187,7 +187,7 @@ |
5 | { |
6 | drizzled::error_t local_error; |
7 | |
8 | - /* Generate transaction event ONLY when we successfully drop */ |
9 | + /* Generate transaction event ONLY when we successfully drop */ |
10 | if (plugin::StorageEngine::dropTable(*session, identifier, local_error)) |
11 | { |
12 | if (message) // If we have no definition, we don't know if the table should have been replicated |
13 | @@ -250,6 +250,149 @@ |
14 | return error; |
15 | } |
16 | |
17 | +/** |
18 | + * Overloaded function of rm_table_part2(). |
19 | + * It takes table identifiers as parameter. |
20 | + * @todo: Handle case for locked table. |
21 | + */ |
22 | +int rm_table_part2(Session *session, std::vector<identifier::Table> tables_identifiers, bool if_exists, |
23 | + bool drop_temporary) |
24 | +{ |
25 | + std::vector<identifier::Table>::iterator table; |
26 | + util::string::vector wrong_tables; |
27 | + int error= 0; |
28 | + bool foreign_key_error= false; |
29 | + |
30 | + do |
31 | + { |
32 | + //boost::mutex::scoped_lock scopedLock(table::Cache::mutex()); |
33 | + |
34 | + /*if (not drop_temporary && session->lock_table_names_exclusively(tables)) |
35 | + { |
36 | + return 1; |
37 | + }*/ |
38 | + |
39 | + /* Don't give warnings for not found errors, as we already generate notes */ |
40 | + session->no_warnings_for_error= 1; |
41 | + |
42 | + for (table= tables_identifiers.begin(); table!=tables_identifiers.end(); ++table) |
43 | + { |
44 | + |
45 | + error= session->open_tables.drop_temporary_table(*table); |
46 | + |
47 | + switch (error) { |
48 | + case 0: |
49 | + // removed temporary table |
50 | + continue; |
51 | + case -1: |
52 | + error= 1; |
53 | + break; |
54 | + default: |
55 | + // temporary table not found |
56 | + error= 0; |
57 | + } |
58 | + |
59 | + if (drop_temporary == false) |
60 | + { |
61 | + abort_locked_tables(session, *table); |
62 | + table::Cache::removeTable(*session, *table, RTFC_WAIT_OTHER_THREAD_FLAG | RTFC_CHECK_KILLED_FLAG); |
63 | + /* |
64 | + If the table was used in lock tables, remember it so that |
65 | + unlock_table_names can free it |
66 | + */ |
67 | + drop_locked_tables(session, *table); |
68 | + |
69 | + if (session->getKilled()) |
70 | + { |
71 | + error= -1; |
72 | + break; |
73 | + } |
74 | + } |
75 | + |
76 | + message::table::shared_ptr message= plugin::StorageEngine::getTableMessage(*session, *table, true); |
77 | + |
78 | + if (drop_temporary || not plugin::StorageEngine::doesTableExist(*session, *table)) |
79 | + { |
80 | + // Table was not found on disk and table can't be created from engine |
81 | + if (if_exists) |
82 | + { |
83 | + push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE, |
84 | + ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR), |
85 | + table->getTableName().c_str()); |
86 | + } |
87 | + else |
88 | + { |
89 | + error= 1; |
90 | + } |
91 | + } |
92 | + else |
93 | + { |
94 | + drizzled::error_t local_error; |
95 | + |
96 | + /* Generate transaction event ONLY when we successfully drop */ |
97 | + if (plugin::StorageEngine::dropTable(*session, *table, local_error)) |
98 | + { |
99 | + if (message) // If we have no definition, we don't know if the table should have been replicated |
100 | + { |
101 | + TransactionServices::dropTable(*session, *table, *message, if_exists); |
102 | + } |
103 | + } |
104 | + else |
105 | + { |
106 | + if (local_error == HA_ERR_NO_SUCH_TABLE and if_exists) |
107 | + { |
108 | + error= 0; |
109 | + session->clear_error(); |
110 | + } |
111 | + |
112 | + if (local_error == HA_ERR_ROW_IS_REFERENCED) |
113 | + { |
114 | + /* the table is referenced by a foreign key constraint */ |
115 | + foreign_key_error= true; |
116 | + } |
117 | + error= local_error; |
118 | + } |
119 | + } |
120 | + |
121 | + if (error) |
122 | + { |
123 | + wrong_tables.push_back(table->getTableName()); |
124 | + } |
125 | + } |
126 | + |
127 | + //tables->unlock_table_names(); |
128 | + |
129 | + } while (0); |
130 | + |
131 | + if (wrong_tables.size()) |
132 | + { |
133 | + if (not foreign_key_error) |
134 | + { |
135 | + std::string table_error; |
136 | + |
137 | + BOOST_FOREACH(util::string::vector::reference iter, wrong_tables) |
138 | + { |
139 | + table_error+= iter; |
140 | + table_error+= ','; |
141 | + } |
142 | + table_error.resize(table_error.size() -1); |
143 | + |
144 | + my_printf_error(ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR), MYF(0), |
145 | + table_error.c_str()); |
146 | + } |
147 | + else |
148 | + { |
149 | + my_message(ER_ROW_IS_REFERENCED, ER(ER_ROW_IS_REFERENCED), MYF(0)); |
150 | + } |
151 | + error= 1; |
152 | + } |
153 | + |
154 | + session->no_warnings_for_error= 0; |
155 | + |
156 | + return error; |
157 | +} |
158 | + |
159 | + |
160 | /* |
161 | Sort keys in the following order: |
162 | - PRIMARY KEY |
163 | @@ -1278,8 +1421,8 @@ |
164 | already exists, otherwise we just need to find out if a normal table exists (aka it is fine |
165 | to create a table under a temporary table. |
166 | */ |
167 | - bool exists= |
168 | - plugin::StorageEngine::doesTableExist(*session, identifier, |
169 | + bool exists= |
170 | + plugin::StorageEngine::doesTableExist(*session, identifier, |
171 | identifier.getType() != message::Table::STANDARD ); |
172 | |
173 | if (exists) |
174 | @@ -1344,7 +1487,7 @@ |
175 | } |
176 | } |
177 | |
178 | - /* |
179 | + /* |
180 | We keep this behind the lock to make sure ordering is correct for a table. |
181 | This is a very unlikely problem where before we would write out to the |
182 | trans log, someone would do a delete/create operation. |
183 | @@ -1607,11 +1750,11 @@ |
184 | my_error(ER_NOT_SUPPORTED_YET, MYF(0), "ALTER Table"); |
185 | else if (error) |
186 | { |
187 | - my_error(ER_ERROR_ON_RENAME, MYF(0), |
188 | - from.isTmp() ? "#sql-temporary" : from.getSQLPath().c_str(), |
189 | + my_error(ER_ERROR_ON_RENAME, MYF(0), |
190 | + from.isTmp() ? "#sql-temporary" : from.getSQLPath().c_str(), |
191 | to.isTmp() ? "#sql-temporary" : to.getSQLPath().c_str(), error); |
192 | } |
193 | - return error; |
194 | + return error; |
195 | } |
196 | |
197 | |
198 | @@ -2080,7 +2223,7 @@ |
199 | if (not was_created) |
200 | { |
201 | plugin::StorageEngine::dropTable(*session, destination_identifier); |
202 | - } |
203 | + } |
204 | else |
205 | { |
206 | res= false; |
207 | |
208 | === modified file 'drizzled/sql_table.h' |
209 | --- drizzled/sql_table.h 2012-07-11 14:06:00 +0000 |
210 | +++ drizzled/sql_table.h 2013-08-22 06:28:00 +0000 |
211 | @@ -26,6 +26,7 @@ |
212 | #pragma once |
213 | |
214 | #include <drizzled/base.h> |
215 | +#include <vector> |
216 | |
217 | namespace drizzled { |
218 | |
219 | @@ -33,6 +34,7 @@ |
220 | |
221 | int rm_table_part2(Session *session, TableList *tables, bool if_exists, |
222 | bool drop_temporary); |
223 | +int rm_table_part2(Session *session, std::vector<identifier::Table> tables_identifiers, bool if_exists, bool drop_temporary); |
224 | void close_cached_table(Session *session, Table *table); |
225 | |
226 | void wait_while_table_is_used(Session *session, Table *table, |
227 | |
228 | === added file 'plugin/json_server/ddl/table.cc' |
229 | --- plugin/json_server/ddl/table.cc 1970-01-01 00:00:00 +0000 |
230 | +++ plugin/json_server/ddl/table.cc 2013-08-22 06:28:00 +0000 |
231 | @@ -0,0 +1,64 @@ |
232 | +/* mode: c; c-basic-offset: 2; indent-tabs-mode: nil; |
233 | + * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
234 | + * |
235 | + * Copyright (C) 2011-13 Stewart Smith, Henrik Ingo, Mohit Srivastava |
236 | + * |
237 | + * This program is free software; you can redistribute it and/or modify |
238 | + * it under the terms of the GNU General Public License as published by |
239 | + * the Free Software Foundation; either version 2 of the License, or |
240 | + * (at your option) any later version. |
241 | + * |
242 | + * This program is distributed in the hope that it will be useful, |
243 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
244 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
245 | + * GNU General Public License for more details. |
246 | + * |
247 | + * You should have received a copy of the GNU General Public License |
248 | + * along with this program; if not, write to the Free Software |
249 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
250 | + */ |
251 | +/** |
252 | + * @file Implements a class Table to handle various operations related to schema.Also it's copy of drizzled/statement/drop_table.cc |
253 | + */ |
254 | +#include<plugin/json_server/ddl/table.h> |
255 | +#include<drizzled/sql_table.h> |
256 | + |
257 | +using namespace std; |
258 | +using namespace drizzled; |
259 | + |
260 | +namespace drizzle_plugin{ |
261 | +namespace json_server{ |
262 | + |
263 | + bool Table::dropTable() |
264 | + { |
265 | + bool need_waiting=false; |
266 | + if(not _drop_temporary) |
267 | + { |
268 | + if(session().inTransaction()) |
269 | + { |
270 | + my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED,MYF(0)); |
271 | + return true; |
272 | + } |
273 | + |
274 | + if(not(need_waiting=not session().wait_if_global_read_lock(false,true))) |
275 | + return true; |
276 | + } |
277 | + |
278 | + vector<identifier::Table> tmp_table_identifier; |
279 | + tmp_table_identifier.push_back(_table_identifier); |
280 | + bool error = rm_table_part2(&session(),tmp_table_identifier,_drop_if_exists,_drop_temporary); |
281 | + |
282 | + if(need_waiting) |
283 | + { |
284 | + session().startWaitingGlobalReadLock(); |
285 | + } |
286 | + |
287 | + if(error) |
288 | + return true; |
289 | + |
290 | + session().my_ok(); |
291 | + |
292 | + return false; |
293 | + } |
294 | +} |
295 | +} |
296 | |
297 | === added file 'plugin/json_server/ddl/table.h' |
298 | --- plugin/json_server/ddl/table.h 1970-01-01 00:00:00 +0000 |
299 | +++ plugin/json_server/ddl/table.h 2013-08-22 06:28:00 +0000 |
300 | @@ -0,0 +1,61 @@ |
301 | +#include <config.h> |
302 | +#include <drizzled/session.h> |
303 | +#include <drizzled/statement.h> |
304 | + |
305 | +using namespace std; |
306 | +using namespace drizzled; |
307 | +namespace drizzle_plugin{ |
308 | +namespace json_server{ |
309 | +/** |
310 | + * a class |
311 | + * |
312 | + * To perform various operation related to dable |
313 | + */ |
314 | +class Table{ |
315 | + public: |
316 | + /** |
317 | + * Constructor |
318 | + * |
319 | + * @param in_session a session object. |
320 | + * @param table_identifier a identifier::Table object. |
321 | + */ |
322 | + Table(Session *in_session,identifier::Table table_identifier,bool if_exists,bool drop_temporary):_session(*in_session),_table_identifier(table_identifier),_drop_if_exists(if_exists),_drop_temporary(drop_temporary){} |
323 | + /** |
324 | + * drop a table. |
325 | + * |
326 | + * @return false Success |
327 | + * @return true Failure |
328 | + */ |
329 | + bool dropTable(); |
330 | + /** |
331 | + * Get a session object |
332 | + * |
333 | + * @return a session object |
334 | + */ |
335 | + Session& session() const{ |
336 | + return _session; |
337 | + } |
338 | + |
339 | + private: |
340 | + /** |
341 | + * Stores a session object. |
342 | + */ |
343 | + Session& _session; |
344 | + /** |
345 | + * Stores a identifier::Table object. |
346 | + */ |
347 | + identifier::Table _table_identifier; |
348 | + /** |
349 | + * Use for DROP IF EXISTS [TABLE_NAME] |
350 | + */ |
351 | + bool _drop_if_exists; |
352 | + /** |
353 | + * Stores whether drop table temporary or not. |
354 | + */ |
355 | + bool _drop_temporary; |
356 | + |
357 | + |
358 | +}; |
359 | + |
360 | +} |
361 | +} |
362 | |
363 | === modified file 'plugin/json_server/json_server.cc' |
364 | --- plugin/json_server/json_server.cc 2013-08-13 04:18:28 +0000 |
365 | +++ plugin/json_server/json_server.cc 2013-08-22 06:28:00 +0000 |
366 | @@ -55,13 +55,13 @@ |
367 | #include <drizzled/pthread_globals.h> |
368 | #include <boost/bind.hpp> |
369 | |
370 | - |
371 | #include <drizzled/version.h> |
372 | #include <plugin/json_server/json/json.h> |
373 | #include <plugin/json_server/db_access.h> |
374 | #include <plugin/json_server/http_handler.h> |
375 | #include <plugin/json_server/http_server.h> |
376 | #include <plugin/json_server/ddl/schema.h> |
377 | +#include <plugin/json_server/ddl/table.h> |
378 | #include <plugin/json_server/json_handler.h> |
379 | |
380 | namespace po= boost::program_options; |
381 | @@ -82,8 +82,8 @@ |
382 | string default_table; |
383 | uint32_t max_threads; |
384 | uint32_t clone_max_threads=0; |
385 | -bool updateSchema(Session *, set_var* var); |
386 | -bool updateTable(Session *, set_var* var); |
387 | +bool updateSchema(Session *, set_var* var); |
388 | +bool updateTable(Session *, set_var* var); |
389 | void updateMaxThreads(Session *, sql_var_t); |
390 | static port_constraint port; |
391 | |
392 | @@ -100,6 +100,7 @@ |
393 | extern "C" void process_json_req(struct evhttp_request *req, void* ); |
394 | extern "C" void process_json_ddl_schema_create_req(struct evhttp_request *req, void* ); |
395 | extern "C" void process_json_ddl_schema_drop_req(struct evhttp_request *req, void* ); |
396 | +extern "C" void process_json_ddl_table_drop_req(struct evhttp_request *req, void* ); |
397 | extern "C" void process_request(struct evhttp_request *req, void* ) |
398 | { |
399 | struct evbuffer *buf = evbuffer_new(); |
400 | @@ -232,7 +233,7 @@ |
401 | |
402 | Json::Value root; |
403 | root["version"]= ::drizzled::version(); |
404 | - |
405 | + |
406 | Json::StyledWriter writer; |
407 | std::string output= writer.write(root); |
408 | |
409 | @@ -321,22 +322,22 @@ |
410 | |
411 | /** |
412 | * Transform a HTTP request for sql transaction and return results based on input json document. |
413 | - * |
414 | + * |
415 | * @todo allow DBA to set whether to use strict mode for parsing json (should get rid of white space), especially for POST of course. |
416 | - * |
417 | + * |
418 | * @param req should contain a "table" parameter in request uri. "query", "_id" and "schema" are optional. |
419 | */ |
420 | extern "C" void process_json_req(struct evhttp_request *req, void* ) |
421 | { |
422 | Json::Value json_out; |
423 | - Json::Value json_in; |
424 | + Json::Value json_in; |
425 | std::string sql; |
426 | const char* schema; |
427 | const char* table; |
428 | |
429 | - HttpHandler* handler = new HttpHandler(json_out,json_in,req); |
430 | + HttpHandler* handler = new HttpHandler(json_out,json_in,req); |
431 | if(!handler->handleRequest()) |
432 | - { |
433 | + { |
434 | if(!handler->validate(default_schema,default_table,allow_drop_table)) |
435 | { |
436 | json_in= handler->getInputJson(); |
437 | @@ -349,7 +350,7 @@ |
438 | delete(dbAccess); |
439 | } |
440 | else |
441 | - { |
442 | + { |
443 | json_out= handler->getOutputJson(); |
444 | } |
445 | } |
446 | @@ -367,7 +368,7 @@ |
447 | * |
448 | * @param req a HTTP request parameter, |
449 | * |
450 | - */ |
451 | + */ |
452 | |
453 | extern "C" void process_json_ddl_schema_create_req(struct evhttp_request *req, void* ) |
454 | { |
455 | @@ -405,7 +406,7 @@ |
456 | struct evbuffer *buf = evbuffer_new(); |
457 | if(buf == NULL) |
458 | { |
459 | - return; |
460 | + return; |
461 | } |
462 | evbuffer_add(buf, output.c_str(), output.length()); |
463 | evhttp_send_reply( req, http_response_code, http_response_text, buf); |
464 | @@ -413,7 +414,7 @@ |
465 | |
466 | /** |
467 | * Transform a HTTP Request for create schema and returns results based on the input json. |
468 | -* |
469 | +* |
470 | * @param req a HTTP request parameter. |
471 | */ |
472 | extern "C" void process_json_ddl_schema_drop_req(struct evhttp_request *req, void* ) |
473 | @@ -423,7 +424,7 @@ |
474 | drizzled::identifier::user::mptr user_id= identifier::User::make_shared(); |
475 | _session->main_da().reset_diagnostics_area(); |
476 | setCurrentSession(_session.get()); |
477 | - |
478 | + |
479 | std::string query; |
480 | std::string db_name; |
481 | std::string output; |
482 | @@ -431,7 +432,7 @@ |
483 | Json::Value json_in; |
484 | const char *http_response_text="OK"; |
485 | int http_response_code=HTTP_OK; |
486 | - |
487 | + |
488 | JsonErrorArea _json_error; |
489 | JsonHandler* _json_handler = new JsonHandler(); |
490 | |
491 | @@ -454,11 +455,69 @@ |
492 | if(buf == NULL) |
493 | { |
494 | return; |
495 | - } |
496 | - evbuffer_add(buf, output.c_str(), output.length()); |
497 | - evhttp_send_reply( req, http_response_code, http_response_text, buf); |
498 | -} |
499 | - |
500 | + } |
501 | + evbuffer_add(buf, output.c_str(), output.length()); |
502 | + evhttp_send_reply( req, http_response_code, http_response_text, buf); |
503 | +} |
504 | + |
505 | +/** |
506 | +* Transform a HTTP Request for drop table and returns results based on the input json. |
507 | +* |
508 | +* @param req a HTTP request parameter. |
509 | +*/ |
510 | +extern "C" void process_json_ddl_table_drop_req(struct evhttp_request *req, void* ) |
511 | +{ |
512 | + drizzled::Session::shared_ptr _session= drizzled::Session::make_shared(drizzled::plugin::Listen::getNullClient(), |
513 | + drizzled::catalog::local()); |
514 | + drizzled::identifier::user::mptr user_id= identifier::User::make_shared(); |
515 | + _session->main_da().reset_diagnostics_area(); |
516 | + setCurrentSession(_session.get()); |
517 | + |
518 | + std::string query; |
519 | + std::string table_name; |
520 | + std::string schema_name; |
521 | + std::string output; |
522 | + bool if_exists = false; |
523 | + Json::Value json_out; |
524 | + Json::Value json_in; |
525 | + const char *http_response_text="OK"; |
526 | + int http_response_code=HTTP_OK; |
527 | + |
528 | + JsonErrorArea _json_error; |
529 | + JsonHandler* _json_handler = new JsonHandler(); |
530 | + |
531 | + _json_handler->generate_input_json(req,_json_error); |
532 | + if(!_json_error.is_jsonerror()) |
533 | + { |
534 | + json_in = _json_handler->get_input_json(); |
535 | + |
536 | + table_name=json_in["query"]["table_name"].asString(); |
537 | + schema_name=json_in["query"]["schema_name"].asString(); |
538 | + if(!json_in["query"]["if_exists"].empty()) |
539 | + { |
540 | + if(strcmp(json_in["query"]["if_exists"].asCString(),"true")==0) |
541 | + { |
542 | + if_exists=true; |
543 | + } |
544 | + } |
545 | + identifier::Table table_identifier(_session->catalog().identifier(),schema_name,table_name); |
546 | + Table *_table= new Table(_session.get(),table_identifier,if_exists,false); |
547 | + _table->dropTable(); |
548 | + if(_session->main_da().is_error()) |
549 | + { |
550 | + _json_error.set_error(JsonErrorArea::ER_SQL,_session->main_da().sql_errno(),_session->main_da().message()); |
551 | + } |
552 | + } |
553 | + _json_handler->generate_output_query(_json_error); |
554 | + output = _json_handler->get_output_query(); |
555 | + struct evbuffer *buf = evbuffer_new(); |
556 | + if(buf == NULL) |
557 | + { |
558 | + return; |
559 | + } |
560 | + evbuffer_add(buf, output.c_str(), output.length()); |
561 | + evhttp_send_reply( req, http_response_code, http_response_text, buf); |
562 | +} |
563 | |
564 | static void shutdown_event(int fd, short, void *arg) |
565 | { |
566 | @@ -520,18 +579,19 @@ |
567 | sql_perror("evhttp_bind_socket()"); |
568 | return false; |
569 | } |
570 | - |
571 | + |
572 | // Create Max_thread number of threads. |
573 | if(not createThreads(max_threads)) |
574 | { |
575 | return false; |
576 | } |
577 | - |
578 | + |
579 | return true; |
580 | } |
581 | |
582 | bool createThreads(uint32_t num_threads) |
583 | { |
584 | + num_threads=1; |
585 | for(uint32_t i =0;i<num_threads;i++) |
586 | { |
587 | if ((base= event_init()) == NULL) |
588 | @@ -552,7 +612,7 @@ |
589 | return false; |
590 | } |
591 | |
592 | - // These URLs are available. Bind worker method to each of them. |
593 | + // These URLs are available. Bind worker method to each of them. |
594 | evhttp_set_cb(httpd, "/", process_root_request, NULL); |
595 | // API 0.1 |
596 | evhttp_set_cb(httpd, "/0.1/version", process_api01_version_req, NULL); |
597 | @@ -571,21 +631,19 @@ |
598 | evhttp_set_cb(httpd, "/json", process_json_req, NULL); |
599 | evhttp_set_cb(httpd,"/json/ddl/schema/create", process_json_ddl_schema_create_req, NULL); |
600 | evhttp_set_cb(httpd,"/json/ddl/schema/drop", process_json_ddl_schema_drop_req, NULL); |
601 | - |
602 | - |
603 | - event_set(&wakeup_event, wakeup_fd[0], EV_READ | EV_PERSIST, shutdown_event, base); |
604 | - event_base_set(base, &wakeup_event); |
605 | - if (event_add(&wakeup_event, NULL) < 0) |
606 | - { |
607 | - sql_perror("event_add"); |
608 | - return false; |
609 | - } |
610 | - drizzled::thread_ptr local_thread; |
611 | - local_thread.reset(new boost::thread((boost::bind(&run, base)))); |
612 | - json_threads.push_back(local_thread); |
613 | - |
614 | - if (not json_threads[i]) |
615 | - return false; |
616 | + evhttp_set_cb(httpd,"/json/ddl/table/drop", process_json_ddl_table_drop_req, NULL); |
617 | + event_set(&wakeup_event, wakeup_fd[0], EV_READ | EV_PERSIST, shutdown_event, base); |
618 | + event_base_set(base, &wakeup_event); |
619 | + if (event_add(&wakeup_event, NULL) < 0) |
620 | + { |
621 | + sql_perror("event_add"); |
622 | + return false; |
623 | + } |
624 | + drizzled::thread_ptr local_thread; |
625 | + local_thread.reset(new boost::thread((boost::bind(&run, base)))); |
626 | + json_threads.push_back(local_thread); |
627 | + if (not json_threads[i]) |
628 | + return false; |
629 | } |
630 | return true; |
631 | } |
632 | @@ -654,7 +712,7 @@ |
633 | |
634 | static int json_server_init(drizzled::module::Context &context) |
635 | { |
636 | - |
637 | + |
638 | server = new JsonServer(port); |
639 | context.add(server); |
640 | context.registerVariable(new sys_var_constrained_value_readonly<in_port_t>("port", port)); |
641 | @@ -662,7 +720,7 @@ |
642 | context.registerVariable(new sys_var_std_string("table", default_table, NULL, &updateTable)); |
643 | context.registerVariable(new sys_var_bool_ptr("allow_drop_table", &allow_drop_table)); |
644 | context.registerVariable(new sys_var_uint32_t_ptr("max_threads",&max_threads,&updateMaxThreads)); |
645 | - |
646 | + |
647 | clone_max_threads=max_threads; |
648 | |
649 | |
650 | |
651 | === modified file 'plugin/json_server/plugin.ini' |
652 | --- plugin/json_server/plugin.ini 2013-07-28 08:33:01 +0000 |
653 | +++ plugin/json_server/plugin.ini 2013-08-22 06:28:00 +0000 |
654 | @@ -1,7 +1,7 @@ |
655 | [plugin] |
656 | headers= |
657 | sql_generator.h |
658 | - sql_executor.h |
659 | + sql_executor.h |
660 | sql_to_json_generator.h |
661 | http_handler.h |
662 | http_server.h |
663 | @@ -9,6 +9,7 @@ |
664 | error.h |
665 | db_access.h |
666 | ddl/schema.h |
667 | + ddl/table.h |
668 | json/autolink.h |
669 | json/config.h |
670 | json/features.h |
671 | @@ -32,6 +33,7 @@ |
672 | error.cc |
673 | db_access.cc |
674 | ddl/schema.cc |
675 | + ddl/table.cc |
676 | json/json_reader.cpp |
677 | json/json_value.cpp |
678 | json/json_writer.cpp |
679 | |
680 | === modified file 'plugin/json_server/tests/r/basic.result' |
681 | --- plugin/json_server/tests/r/basic.result 2013-07-28 08:33:01 +0000 |
682 | +++ plugin/json_server/tests/r/basic.result 2013-08-22 06:28:00 +0000 |
683 | @@ -305,3 +305,30 @@ |
684 | "error_type" : "SQL ERROR", |
685 | "sql_state" : "HY000" |
686 | } |
687 | +create schema json; |
688 | +create table json.test (a int); |
689 | +{ |
690 | + "error_message" : "Unknown table 'test'", |
691 | + "error_no" : 1051, |
692 | + "error_type" : "SQL ERROR", |
693 | + "sql_state" : "42S02" |
694 | +} |
695 | +{ |
696 | + "sql_state" : "00000" |
697 | +} |
698 | +{ |
699 | + "error_message" : "Unknown table 'test'", |
700 | + "error_no" : 1051, |
701 | + "error_type" : "SQL ERROR", |
702 | + "sql_state" : "42S02" |
703 | +} |
704 | +{ |
705 | + "sql_state" : "00000" |
706 | +} |
707 | +{ |
708 | + "error_message" : "Unknown table 'test'", |
709 | + "error_no" : 1051, |
710 | + "error_type" : "SQL ERROR", |
711 | + "sql_state" : "42S02" |
712 | +} |
713 | +drop schema json; |
714 | |
715 | === modified file 'plugin/json_server/tests/t/basic.test' |
716 | --- plugin/json_server/tests/t/basic.test 2013-08-13 04:18:28 +0000 |
717 | +++ plugin/json_server/tests/t/basic.test 2013-08-22 06:28:00 +0000 |
718 | @@ -92,3 +92,20 @@ |
719 | --exec curl -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"query":{"name":"json"}}' 'http://localhost:$JSON_SERVER_PORT/json/ddl/schema/drop' |
720 | |
721 | --exec curl -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"query":{"name":"json"}}' 'http://localhost:$JSON_SERVER_PORT/json/ddl/schema/drop' |
722 | + |
723 | +create schema json; |
724 | + |
725 | +create table json.test (a int); |
726 | + |
727 | +--exec curl -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"query":{"schema_name":"json_test","table_name":"test"}}' 'http://localhost:$JSON_SERVER_PORT/json/ddl/table/drop' |
728 | + |
729 | +--exec curl -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"query":{"schema_name":"json","table_name":"test"}}' 'http://localhost:$JSON_SERVER_PORT/json/ddl/table/drop' |
730 | + |
731 | +--exec curl -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"query":{"schema_name":"json","table_name":"test"}}' 'http://localhost:$JSON_SERVER_PORT/json/ddl/table/drop' |
732 | + |
733 | +--exec curl -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"query":{"schema_name":"json","table_name":"test","if_exists":"true"}}' 'http://localhost:$JSON_SERVER_PORT/json/ddl/table/drop' |
734 | + |
735 | +--exec curl -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"query":{"schema_name":"json","table_name":"test","if_exists":"false"}}' 'http://localhost:$JSON_SERVER_PORT/json/ddl/table/drop' |
736 | + |
737 | +drop schema json; |
738 | + |