Merge lp:~mohyt/drizzle/json_server_table into lp:drizzle

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
Reviewer Review Type Date Requested Status
Stewart Smith Pending
Review via email: mp+181014@code.launchpad.net

Commit message

Added drop table functionality

To post a comment you must log in.
lp:~mohyt/drizzle/json_server_table updated
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
=== modified file 'drizzled/sql_table.cc'
--- drizzled/sql_table.cc 2013-03-03 02:44:39 +0000
+++ drizzled/sql_table.cc 2013-08-22 06:28:00 +0000
@@ -187,7 +187,7 @@
187 {187 {
188 drizzled::error_t local_error;188 drizzled::error_t local_error;
189189
190 /* Generate transaction event ONLY when we successfully drop */ 190 /* Generate transaction event ONLY when we successfully drop */
191 if (plugin::StorageEngine::dropTable(*session, identifier, local_error))191 if (plugin::StorageEngine::dropTable(*session, identifier, local_error))
192 {192 {
193 if (message) // If we have no definition, we don't know if the table should have been replicated193 if (message) // If we have no definition, we don't know if the table should have been replicated
@@ -250,6 +250,149 @@
250 return error;250 return error;
251}251}
252252
253/**
254 * Overloaded function of rm_table_part2().
255 * It takes table identifiers as parameter.
256 * @todo: Handle case for locked table.
257 */
258int rm_table_part2(Session *session, std::vector<identifier::Table> tables_identifiers, bool if_exists,
259 bool drop_temporary)
260{
261 std::vector<identifier::Table>::iterator table;
262 util::string::vector wrong_tables;
263 int error= 0;
264 bool foreign_key_error= false;
265
266 do
267 {
268 //boost::mutex::scoped_lock scopedLock(table::Cache::mutex());
269
270 /*if (not drop_temporary && session->lock_table_names_exclusively(tables))
271 {
272 return 1;
273 }*/
274
275 /* Don't give warnings for not found errors, as we already generate notes */
276 session->no_warnings_for_error= 1;
277
278 for (table= tables_identifiers.begin(); table!=tables_identifiers.end(); ++table)
279 {
280
281 error= session->open_tables.drop_temporary_table(*table);
282
283 switch (error) {
284 case 0:
285 // removed temporary table
286 continue;
287 case -1:
288 error= 1;
289 break;
290 default:
291 // temporary table not found
292 error= 0;
293 }
294
295 if (drop_temporary == false)
296 {
297 abort_locked_tables(session, *table);
298 table::Cache::removeTable(*session, *table, RTFC_WAIT_OTHER_THREAD_FLAG | RTFC_CHECK_KILLED_FLAG);
299 /*
300 If the table was used in lock tables, remember it so that
301 unlock_table_names can free it
302 */
303 drop_locked_tables(session, *table);
304
305 if (session->getKilled())
306 {
307 error= -1;
308 break;
309 }
310 }
311
312 message::table::shared_ptr message= plugin::StorageEngine::getTableMessage(*session, *table, true);
313
314 if (drop_temporary || not plugin::StorageEngine::doesTableExist(*session, *table))
315 {
316 // Table was not found on disk and table can't be created from engine
317 if (if_exists)
318 {
319 push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
320 ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR),
321 table->getTableName().c_str());
322 }
323 else
324 {
325 error= 1;
326 }
327 }
328 else
329 {
330 drizzled::error_t local_error;
331
332 /* Generate transaction event ONLY when we successfully drop */
333 if (plugin::StorageEngine::dropTable(*session, *table, local_error))
334 {
335 if (message) // If we have no definition, we don't know if the table should have been replicated
336 {
337 TransactionServices::dropTable(*session, *table, *message, if_exists);
338 }
339 }
340 else
341 {
342 if (local_error == HA_ERR_NO_SUCH_TABLE and if_exists)
343 {
344 error= 0;
345 session->clear_error();
346 }
347
348 if (local_error == HA_ERR_ROW_IS_REFERENCED)
349 {
350 /* the table is referenced by a foreign key constraint */
351 foreign_key_error= true;
352 }
353 error= local_error;
354 }
355 }
356
357 if (error)
358 {
359 wrong_tables.push_back(table->getTableName());
360 }
361 }
362
363 //tables->unlock_table_names();
364
365 } while (0);
366
367 if (wrong_tables.size())
368 {
369 if (not foreign_key_error)
370 {
371 std::string table_error;
372
373 BOOST_FOREACH(util::string::vector::reference iter, wrong_tables)
374 {
375 table_error+= iter;
376 table_error+= ',';
377 }
378 table_error.resize(table_error.size() -1);
379
380 my_printf_error(ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR), MYF(0),
381 table_error.c_str());
382 }
383 else
384 {
385 my_message(ER_ROW_IS_REFERENCED, ER(ER_ROW_IS_REFERENCED), MYF(0));
386 }
387 error= 1;
388 }
389
390 session->no_warnings_for_error= 0;
391
392 return error;
393}
394
395
253/*396/*
254 Sort keys in the following order:397 Sort keys in the following order:
255 - PRIMARY KEY398 - PRIMARY KEY
@@ -1278,8 +1421,8 @@
1278 already exists, otherwise we just need to find out if a normal table exists (aka it is fine1421 already exists, otherwise we just need to find out if a normal table exists (aka it is fine
1279 to create a table under a temporary table.1422 to create a table under a temporary table.
1280 */1423 */
1281 bool exists= 1424 bool exists=
1282 plugin::StorageEngine::doesTableExist(*session, identifier, 1425 plugin::StorageEngine::doesTableExist(*session, identifier,
1283 identifier.getType() != message::Table::STANDARD );1426 identifier.getType() != message::Table::STANDARD );
12841427
1285 if (exists)1428 if (exists)
@@ -1344,7 +1487,7 @@
1344 }1487 }
1345 }1488 }
13461489
1347 /* 1490 /*
1348 We keep this behind the lock to make sure ordering is correct for a table.1491 We keep this behind the lock to make sure ordering is correct for a table.
1349 This is a very unlikely problem where before we would write out to the1492 This is a very unlikely problem where before we would write out to the
1350 trans log, someone would do a delete/create operation.1493 trans log, someone would do a delete/create operation.
@@ -1607,11 +1750,11 @@
1607 my_error(ER_NOT_SUPPORTED_YET, MYF(0), "ALTER Table");1750 my_error(ER_NOT_SUPPORTED_YET, MYF(0), "ALTER Table");
1608 else if (error)1751 else if (error)
1609 {1752 {
1610 my_error(ER_ERROR_ON_RENAME, MYF(0), 1753 my_error(ER_ERROR_ON_RENAME, MYF(0),
1611 from.isTmp() ? "#sql-temporary" : from.getSQLPath().c_str(), 1754 from.isTmp() ? "#sql-temporary" : from.getSQLPath().c_str(),
1612 to.isTmp() ? "#sql-temporary" : to.getSQLPath().c_str(), error);1755 to.isTmp() ? "#sql-temporary" : to.getSQLPath().c_str(), error);
1613 }1756 }
1614 return error; 1757 return error;
1615}1758}
16161759
16171760
@@ -2080,7 +2223,7 @@
2080 if (not was_created)2223 if (not was_created)
2081 {2224 {
2082 plugin::StorageEngine::dropTable(*session, destination_identifier);2225 plugin::StorageEngine::dropTable(*session, destination_identifier);
2083 } 2226 }
2084 else2227 else
2085 {2228 {
2086 res= false;2229 res= false;
20872230
=== modified file 'drizzled/sql_table.h'
--- drizzled/sql_table.h 2012-07-11 14:06:00 +0000
+++ drizzled/sql_table.h 2013-08-22 06:28:00 +0000
@@ -26,6 +26,7 @@
26#pragma once26#pragma once
2727
28#include <drizzled/base.h>28#include <drizzled/base.h>
29#include <vector>
2930
30namespace drizzled {31namespace drizzled {
3132
@@ -33,6 +34,7 @@
3334
34int rm_table_part2(Session *session, TableList *tables, bool if_exists,35int rm_table_part2(Session *session, TableList *tables, bool if_exists,
35 bool drop_temporary);36 bool drop_temporary);
37int rm_table_part2(Session *session, std::vector<identifier::Table> tables_identifiers, bool if_exists, bool drop_temporary);
36void close_cached_table(Session *session, Table *table);38void close_cached_table(Session *session, Table *table);
3739
38void wait_while_table_is_used(Session *session, Table *table,40void wait_while_table_is_used(Session *session, Table *table,
3941
=== added file 'plugin/json_server/ddl/table.cc'
--- plugin/json_server/ddl/table.cc 1970-01-01 00:00:00 +0000
+++ plugin/json_server/ddl/table.cc 2013-08-22 06:28:00 +0000
@@ -0,0 +1,64 @@
1/* mode: c; c-basic-offset: 2; indent-tabs-mode: nil;
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2011-13 Stewart Smith, Henrik Ingo, Mohit Srivastava
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20/**
21 * @file Implements a class Table to handle various operations related to schema.Also it's copy of drizzled/statement/drop_table.cc
22 */
23#include<plugin/json_server/ddl/table.h>
24#include<drizzled/sql_table.h>
25
26using namespace std;
27using namespace drizzled;
28
29namespace drizzle_plugin{
30namespace json_server{
31
32 bool Table::dropTable()
33 {
34 bool need_waiting=false;
35 if(not _drop_temporary)
36 {
37 if(session().inTransaction())
38 {
39 my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED,MYF(0));
40 return true;
41 }
42
43 if(not(need_waiting=not session().wait_if_global_read_lock(false,true)))
44 return true;
45 }
46
47 vector<identifier::Table> tmp_table_identifier;
48 tmp_table_identifier.push_back(_table_identifier);
49 bool error = rm_table_part2(&session(),tmp_table_identifier,_drop_if_exists,_drop_temporary);
50
51 if(need_waiting)
52 {
53 session().startWaitingGlobalReadLock();
54 }
55
56 if(error)
57 return true;
58
59 session().my_ok();
60
61 return false;
62 }
63}
64}
065
=== added file 'plugin/json_server/ddl/table.h'
--- plugin/json_server/ddl/table.h 1970-01-01 00:00:00 +0000
+++ plugin/json_server/ddl/table.h 2013-08-22 06:28:00 +0000
@@ -0,0 +1,61 @@
1#include <config.h>
2#include <drizzled/session.h>
3#include <drizzled/statement.h>
4
5using namespace std;
6using namespace drizzled;
7namespace drizzle_plugin{
8namespace json_server{
9/**
10 * a class
11 *
12 * To perform various operation related to dable
13 */
14class Table{
15 public:
16 /**
17 * Constructor
18 *
19 * @param in_session a session object.
20 * @param table_identifier a identifier::Table object.
21 */
22 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){}
23 /**
24 * drop a table.
25 *
26 * @return false Success
27 * @return true Failure
28 */
29 bool dropTable();
30 /**
31 * Get a session object
32 *
33 * @return a session object
34 */
35 Session& session() const{
36 return _session;
37 }
38
39 private:
40 /**
41 * Stores a session object.
42 */
43 Session& _session;
44 /**
45 * Stores a identifier::Table object.
46 */
47 identifier::Table _table_identifier;
48 /**
49 * Use for DROP IF EXISTS [TABLE_NAME]
50 */
51 bool _drop_if_exists;
52 /**
53 * Stores whether drop table temporary or not.
54 */
55 bool _drop_temporary;
56
57
58};
59
60}
61}
062
=== modified file 'plugin/json_server/json_server.cc'
--- plugin/json_server/json_server.cc 2013-08-13 04:18:28 +0000
+++ plugin/json_server/json_server.cc 2013-08-22 06:28:00 +0000
@@ -55,13 +55,13 @@
55#include <drizzled/pthread_globals.h>55#include <drizzled/pthread_globals.h>
56#include <boost/bind.hpp>56#include <boost/bind.hpp>
5757
58
59#include <drizzled/version.h>58#include <drizzled/version.h>
60#include <plugin/json_server/json/json.h>59#include <plugin/json_server/json/json.h>
61#include <plugin/json_server/db_access.h>60#include <plugin/json_server/db_access.h>
62#include <plugin/json_server/http_handler.h>61#include <plugin/json_server/http_handler.h>
63#include <plugin/json_server/http_server.h>62#include <plugin/json_server/http_server.h>
64#include <plugin/json_server/ddl/schema.h>63#include <plugin/json_server/ddl/schema.h>
64#include <plugin/json_server/ddl/table.h>
65#include <plugin/json_server/json_handler.h>65#include <plugin/json_server/json_handler.h>
6666
67namespace po= boost::program_options;67namespace po= boost::program_options;
@@ -82,8 +82,8 @@
82string default_table;82string default_table;
83uint32_t max_threads;83uint32_t max_threads;
84uint32_t clone_max_threads=0;84uint32_t clone_max_threads=0;
85bool updateSchema(Session *, set_var* var); 85bool updateSchema(Session *, set_var* var);
86bool updateTable(Session *, set_var* var); 86bool updateTable(Session *, set_var* var);
87void updateMaxThreads(Session *, sql_var_t);87void updateMaxThreads(Session *, sql_var_t);
88static port_constraint port;88static port_constraint port;
8989
@@ -100,6 +100,7 @@
100extern "C" void process_json_req(struct evhttp_request *req, void* );100extern "C" void process_json_req(struct evhttp_request *req, void* );
101extern "C" void process_json_ddl_schema_create_req(struct evhttp_request *req, void* );101extern "C" void process_json_ddl_schema_create_req(struct evhttp_request *req, void* );
102extern "C" void process_json_ddl_schema_drop_req(struct evhttp_request *req, void* );102extern "C" void process_json_ddl_schema_drop_req(struct evhttp_request *req, void* );
103extern "C" void process_json_ddl_table_drop_req(struct evhttp_request *req, void* );
103extern "C" void process_request(struct evhttp_request *req, void* )104extern "C" void process_request(struct evhttp_request *req, void* )
104{105{
105 struct evbuffer *buf = evbuffer_new();106 struct evbuffer *buf = evbuffer_new();
@@ -232,7 +233,7 @@
232233
233 Json::Value root;234 Json::Value root;
234 root["version"]= ::drizzled::version();235 root["version"]= ::drizzled::version();
235 236
236 Json::StyledWriter writer;237 Json::StyledWriter writer;
237 std::string output= writer.write(root);238 std::string output= writer.write(root);
238239
@@ -321,22 +322,22 @@
321322
322/**323/**
323 * Transform a HTTP request for sql transaction and return results based on input json document.324 * Transform a HTTP request for sql transaction and return results based on input json document.
324 * 325 *
325 * @todo allow DBA to set whether to use strict mode for parsing json (should get rid of white space), especially for POST of course.326 * @todo allow DBA to set whether to use strict mode for parsing json (should get rid of white space), especially for POST of course.
326 * 327 *
327 * @param req should contain a "table" parameter in request uri. "query", "_id" and "schema" are optional.328 * @param req should contain a "table" parameter in request uri. "query", "_id" and "schema" are optional.
328 */329 */
329extern "C" void process_json_req(struct evhttp_request *req, void* )330extern "C" void process_json_req(struct evhttp_request *req, void* )
330{331{
331 Json::Value json_out;332 Json::Value json_out;
332 Json::Value json_in; 333 Json::Value json_in;
333 std::string sql;334 std::string sql;
334 const char* schema;335 const char* schema;
335 const char* table;336 const char* table;
336337
337 HttpHandler* handler = new HttpHandler(json_out,json_in,req); 338 HttpHandler* handler = new HttpHandler(json_out,json_in,req);
338 if(!handler->handleRequest())339 if(!handler->handleRequest())
339 { 340 {
340 if(!handler->validate(default_schema,default_table,allow_drop_table))341 if(!handler->validate(default_schema,default_table,allow_drop_table))
341 {342 {
342 json_in= handler->getInputJson();343 json_in= handler->getInputJson();
@@ -349,7 +350,7 @@
349 delete(dbAccess);350 delete(dbAccess);
350 }351 }
351 else352 else
352 { 353 {
353 json_out= handler->getOutputJson();354 json_out= handler->getOutputJson();
354 }355 }
355 }356 }
@@ -367,7 +368,7 @@
367 *368 *
368 * @param req a HTTP request parameter,369 * @param req a HTTP request parameter,
369 *370 *
370 */ 371 */
371372
372extern "C" void process_json_ddl_schema_create_req(struct evhttp_request *req, void* )373extern "C" void process_json_ddl_schema_create_req(struct evhttp_request *req, void* )
373{374{
@@ -405,7 +406,7 @@
405 struct evbuffer *buf = evbuffer_new();406 struct evbuffer *buf = evbuffer_new();
406 if(buf == NULL)407 if(buf == NULL)
407 {408 {
408 return; 409 return;
409 }410 }
410 evbuffer_add(buf, output.c_str(), output.length());411 evbuffer_add(buf, output.c_str(), output.length());
411 evhttp_send_reply( req, http_response_code, http_response_text, buf);412 evhttp_send_reply( req, http_response_code, http_response_text, buf);
@@ -413,7 +414,7 @@
413414
414/**415/**
415* Transform a HTTP Request for create schema and returns results based on the input json.416* Transform a HTTP Request for create schema and returns results based on the input json.
416* 417*
417* @param req a HTTP request parameter.418* @param req a HTTP request parameter.
418*/419*/
419extern "C" void process_json_ddl_schema_drop_req(struct evhttp_request *req, void* )420extern "C" void process_json_ddl_schema_drop_req(struct evhttp_request *req, void* )
@@ -423,7 +424,7 @@
423 drizzled::identifier::user::mptr user_id= identifier::User::make_shared();424 drizzled::identifier::user::mptr user_id= identifier::User::make_shared();
424 _session->main_da().reset_diagnostics_area();425 _session->main_da().reset_diagnostics_area();
425 setCurrentSession(_session.get());426 setCurrentSession(_session.get());
426 427
427 std::string query;428 std::string query;
428 std::string db_name;429 std::string db_name;
429 std::string output;430 std::string output;
@@ -431,7 +432,7 @@
431 Json::Value json_in;432 Json::Value json_in;
432 const char *http_response_text="OK";433 const char *http_response_text="OK";
433 int http_response_code=HTTP_OK;434 int http_response_code=HTTP_OK;
434 435
435 JsonErrorArea _json_error;436 JsonErrorArea _json_error;
436 JsonHandler* _json_handler = new JsonHandler();437 JsonHandler* _json_handler = new JsonHandler();
437438
@@ -454,11 +455,69 @@
454 if(buf == NULL)455 if(buf == NULL)
455 {456 {
456 return;457 return;
457 }458 }
458 evbuffer_add(buf, output.c_str(), output.length());459 evbuffer_add(buf, output.c_str(), output.length());
459 evhttp_send_reply( req, http_response_code, http_response_text, buf);460 evhttp_send_reply( req, http_response_code, http_response_text, buf);
460}461}
461462
463/**
464* Transform a HTTP Request for drop table and returns results based on the input json.
465*
466* @param req a HTTP request parameter.
467*/
468extern "C" void process_json_ddl_table_drop_req(struct evhttp_request *req, void* )
469{
470 drizzled::Session::shared_ptr _session= drizzled::Session::make_shared(drizzled::plugin::Listen::getNullClient(),
471 drizzled::catalog::local());
472 drizzled::identifier::user::mptr user_id= identifier::User::make_shared();
473 _session->main_da().reset_diagnostics_area();
474 setCurrentSession(_session.get());
475
476 std::string query;
477 std::string table_name;
478 std::string schema_name;
479 std::string output;
480 bool if_exists = false;
481 Json::Value json_out;
482 Json::Value json_in;
483 const char *http_response_text="OK";
484 int http_response_code=HTTP_OK;
485
486 JsonErrorArea _json_error;
487 JsonHandler* _json_handler = new JsonHandler();
488
489 _json_handler->generate_input_json(req,_json_error);
490 if(!_json_error.is_jsonerror())
491 {
492 json_in = _json_handler->get_input_json();
493
494 table_name=json_in["query"]["table_name"].asString();
495 schema_name=json_in["query"]["schema_name"].asString();
496 if(!json_in["query"]["if_exists"].empty())
497 {
498 if(strcmp(json_in["query"]["if_exists"].asCString(),"true")==0)
499 {
500 if_exists=true;
501 }
502 }
503 identifier::Table table_identifier(_session->catalog().identifier(),schema_name,table_name);
504 Table *_table= new Table(_session.get(),table_identifier,if_exists,false);
505 _table->dropTable();
506 if(_session->main_da().is_error())
507 {
508 _json_error.set_error(JsonErrorArea::ER_SQL,_session->main_da().sql_errno(),_session->main_da().message());
509 }
510 }
511 _json_handler->generate_output_query(_json_error);
512 output = _json_handler->get_output_query();
513 struct evbuffer *buf = evbuffer_new();
514 if(buf == NULL)
515 {
516 return;
517 }
518 evbuffer_add(buf, output.c_str(), output.length());
519 evhttp_send_reply( req, http_response_code, http_response_text, buf);
520}
462521
463static void shutdown_event(int fd, short, void *arg)522static void shutdown_event(int fd, short, void *arg)
464{523{
@@ -520,18 +579,19 @@
520 sql_perror("evhttp_bind_socket()");579 sql_perror("evhttp_bind_socket()");
521 return false;580 return false;
522 }581 }
523 582
524 // Create Max_thread number of threads.583 // Create Max_thread number of threads.
525 if(not createThreads(max_threads))584 if(not createThreads(max_threads))
526 {585 {
527 return false;586 return false;
528 }587 }
529 588
530 return true;589 return true;
531 }590 }
532591
533 bool createThreads(uint32_t num_threads)592 bool createThreads(uint32_t num_threads)
534 {593 {
594 num_threads=1;
535 for(uint32_t i =0;i<num_threads;i++)595 for(uint32_t i =0;i<num_threads;i++)
536 {596 {
537 if ((base= event_init()) == NULL)597 if ((base= event_init()) == NULL)
@@ -552,7 +612,7 @@
552 return false;612 return false;
553 }613 }
554614
555 // These URLs are available. Bind worker method to each of them. 615 // These URLs are available. Bind worker method to each of them.
556 evhttp_set_cb(httpd, "/", process_root_request, NULL);616 evhttp_set_cb(httpd, "/", process_root_request, NULL);
557 // API 0.1617 // API 0.1
558 evhttp_set_cb(httpd, "/0.1/version", process_api01_version_req, NULL);618 evhttp_set_cb(httpd, "/0.1/version", process_api01_version_req, NULL);
@@ -571,21 +631,19 @@
571 evhttp_set_cb(httpd, "/json", process_json_req, NULL);631 evhttp_set_cb(httpd, "/json", process_json_req, NULL);
572 evhttp_set_cb(httpd,"/json/ddl/schema/create", process_json_ddl_schema_create_req, NULL);632 evhttp_set_cb(httpd,"/json/ddl/schema/create", process_json_ddl_schema_create_req, NULL);
573 evhttp_set_cb(httpd,"/json/ddl/schema/drop", process_json_ddl_schema_drop_req, NULL);633 evhttp_set_cb(httpd,"/json/ddl/schema/drop", process_json_ddl_schema_drop_req, NULL);
574 634 evhttp_set_cb(httpd,"/json/ddl/table/drop", process_json_ddl_table_drop_req, NULL);
575635 event_set(&wakeup_event, wakeup_fd[0], EV_READ | EV_PERSIST, shutdown_event, base);
576 event_set(&wakeup_event, wakeup_fd[0], EV_READ | EV_PERSIST, shutdown_event, base);636 event_base_set(base, &wakeup_event);
577 event_base_set(base, &wakeup_event);637 if (event_add(&wakeup_event, NULL) < 0)
578 if (event_add(&wakeup_event, NULL) < 0)638 {
579 {639 sql_perror("event_add");
580 sql_perror("event_add");640 return false;
581 return false;641 }
582 }642 drizzled::thread_ptr local_thread;
583 drizzled::thread_ptr local_thread;643 local_thread.reset(new boost::thread((boost::bind(&run, base))));
584 local_thread.reset(new boost::thread((boost::bind(&run, base))));644 json_threads.push_back(local_thread);
585 json_threads.push_back(local_thread);645 if (not json_threads[i])
586646 return false;
587 if (not json_threads[i])
588 return false;
589 }647 }
590 return true;648 return true;
591 }649 }
@@ -654,7 +712,7 @@
654712
655static int json_server_init(drizzled::module::Context &context)713static int json_server_init(drizzled::module::Context &context)
656{714{
657 715
658 server = new JsonServer(port);716 server = new JsonServer(port);
659 context.add(server);717 context.add(server);
660 context.registerVariable(new sys_var_constrained_value_readonly<in_port_t>("port", port));718 context.registerVariable(new sys_var_constrained_value_readonly<in_port_t>("port", port));
@@ -662,7 +720,7 @@
662 context.registerVariable(new sys_var_std_string("table", default_table, NULL, &updateTable));720 context.registerVariable(new sys_var_std_string("table", default_table, NULL, &updateTable));
663 context.registerVariable(new sys_var_bool_ptr("allow_drop_table", &allow_drop_table));721 context.registerVariable(new sys_var_bool_ptr("allow_drop_table", &allow_drop_table));
664 context.registerVariable(new sys_var_uint32_t_ptr("max_threads",&max_threads,&updateMaxThreads));722 context.registerVariable(new sys_var_uint32_t_ptr("max_threads",&max_threads,&updateMaxThreads));
665 723
666 clone_max_threads=max_threads;724 clone_max_threads=max_threads;
667725
668726
669727
=== modified file 'plugin/json_server/plugin.ini'
--- plugin/json_server/plugin.ini 2013-07-28 08:33:01 +0000
+++ plugin/json_server/plugin.ini 2013-08-22 06:28:00 +0000
@@ -1,7 +1,7 @@
1[plugin]1[plugin]
2headers=2headers=
3 sql_generator.h3 sql_generator.h
4 sql_executor.h 4 sql_executor.h
5 sql_to_json_generator.h5 sql_to_json_generator.h
6 http_handler.h6 http_handler.h
7 http_server.h7 http_server.h
@@ -9,6 +9,7 @@
9 error.h9 error.h
10 db_access.h10 db_access.h
11 ddl/schema.h11 ddl/schema.h
12 ddl/table.h
12 json/autolink.h13 json/autolink.h
13 json/config.h14 json/config.h
14 json/features.h15 json/features.h
@@ -32,6 +33,7 @@
32 error.cc33 error.cc
33 db_access.cc34 db_access.cc
34 ddl/schema.cc35 ddl/schema.cc
36 ddl/table.cc
35 json/json_reader.cpp37 json/json_reader.cpp
36 json/json_value.cpp38 json/json_value.cpp
37 json/json_writer.cpp39 json/json_writer.cpp
3840
=== modified file 'plugin/json_server/tests/r/basic.result'
--- plugin/json_server/tests/r/basic.result 2013-07-28 08:33:01 +0000
+++ plugin/json_server/tests/r/basic.result 2013-08-22 06:28:00 +0000
@@ -305,3 +305,30 @@
305 "error_type" : "SQL ERROR",305 "error_type" : "SQL ERROR",
306 "sql_state" : "HY000"306 "sql_state" : "HY000"
307}307}
308create schema json;
309create table json.test (a int);
310{
311 "error_message" : "Unknown table 'test'",
312 "error_no" : 1051,
313 "error_type" : "SQL ERROR",
314 "sql_state" : "42S02"
315}
316{
317 "sql_state" : "00000"
318}
319{
320 "error_message" : "Unknown table 'test'",
321 "error_no" : 1051,
322 "error_type" : "SQL ERROR",
323 "sql_state" : "42S02"
324}
325{
326 "sql_state" : "00000"
327}
328{
329 "error_message" : "Unknown table 'test'",
330 "error_no" : 1051,
331 "error_type" : "SQL ERROR",
332 "sql_state" : "42S02"
333}
334drop schema json;
308335
=== modified file 'plugin/json_server/tests/t/basic.test'
--- plugin/json_server/tests/t/basic.test 2013-08-13 04:18:28 +0000
+++ plugin/json_server/tests/t/basic.test 2013-08-22 06:28:00 +0000
@@ -92,3 +92,20 @@
92--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'92--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'
9393
94--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'94--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'
95
96create schema json;
97
98create table json.test (a int);
99
100--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'
101
102--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'
103
104--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'
105
106--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'
107
108--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'
109
110drop schema json;
111

Subscribers

People subscribed via source and target branches