24 #include <plugin/json_server/sql_to_json_generator.h>
27 using namespace drizzled;
29 namespace drizzle_plugin
33 SQLToJsonGenerator::SQLToJsonGenerator(
Json::Value& json_out,
const char* schema,
const char* table,
SQLExecutor* sqlExecutor)
37 _sql_executor=sqlExecutor;
42 void SQLToJsonGenerator::generateSQLErrorJson()
45 _json_out[
"error_type"]=
"sql error";
46 _json_out[
"error_message"]= _exception.getErrorMessage();
47 _json_out[
"error_code"]= _exception.getErrorCode();
48 _json_out[
"internal_sql_query"]= _sql_executor->getSql();
49 _json_out[
"schema"]= _schema;
50 _json_out[
"sqlstate"]= _exception.getSQLState();
51 _json_out[
"table"]= _table;
54 void SQLToJsonGenerator::generateJson(
enum evhttp_cmd_type type)
56 if(type==EVHTTP_REQ_GET)
58 else if(type==EVHTTP_REQ_POST)
60 else if(type==EVHTTP_REQ_DELETE)
64 void SQLToJsonGenerator::generateGetJson()
69 while (_result_set->next())
72 bool got_error =
false;
74 for (
size_t x= 0; x < _result_set->getMetaData().getColumnCount() && got_error ==
false; x++)
77 if (not _result_set->isNull(x))
82 std::string col_name = _result_set->
getColumnInfo(x).col_name;
83 bool r = readrow.
parse(_result_set->getString(x), json_doc);
86 _json_out[
"error_type"]=
"json parse error on row value";
87 _json_out[
"error_internal_sql_column"]=col_name;
89 json_row[col_name]= _result_set->getString(x);
95 json_row[col_name]= json_doc;
100 _json_out[
"result_set"].
append(json_row);
102 _json_out[
"sqlstate"]= exception.getSQLState();
105 void SQLToJsonGenerator::generatePostJson()
108 _json_out[
"sqlstate"]= exception.getSQLState();
111 void SQLToJsonGenerator::generateDeleteJson()
114 _json_out[
"sqlstate"]= exception.getSQLState();
bool parse(const std::string &document, Value &root, bool collectComments=true)
Read a Value from a JSON document.
Configuration passed to reader and writer. This configuration object can be used to force the Reader ...
SendField getColumnInfo(size_t column_number)
Get object that holds column meta data.
Unserialize a JSON document into a Value.
Value & append(const Value &value)
Append value to array at the end.