mirror of https://gitee.com/bigwinds/arangodb
Implement POST for HTTP API for queries.
This commit is contained in:
parent
cd36c00712
commit
1f74a64b58
|
@ -30,6 +30,7 @@
|
||||||
#include "RestAqlHandler.h"
|
#include "RestAqlHandler.h"
|
||||||
|
|
||||||
#include "Basics/ConditionLocker.h"
|
#include "Basics/ConditionLocker.h"
|
||||||
|
#include "Basics/StringUtils.h"
|
||||||
#include "Rest/HttpRequest.h"
|
#include "Rest/HttpRequest.h"
|
||||||
#include "Rest/HttpResponse.h"
|
#include "Rest/HttpResponse.h"
|
||||||
|
|
||||||
|
@ -38,6 +39,7 @@
|
||||||
#include "GeneralServer/GeneralServerJob.h"
|
#include "GeneralServer/GeneralServerJob.h"
|
||||||
#include "GeneralServer/GeneralServer.h"
|
#include "GeneralServer/GeneralServer.h"
|
||||||
|
|
||||||
|
#include "VocBase/server.h"
|
||||||
#include "V8Server/v8-vocbaseprivate.h"
|
#include "V8Server/v8-vocbaseprivate.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -117,7 +119,7 @@ void RestAqlHandler::createQuery () {
|
||||||
Json options;
|
Json options;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
plan = queryJson.get("plan");
|
plan = queryJson.get("plan").copy();
|
||||||
}
|
}
|
||||||
catch (...) {
|
catch (...) {
|
||||||
generateError(HttpResponse::BAD, TRI_ERROR_INTERNAL,
|
generateError(HttpResponse::BAD, TRI_ERROR_INTERNAL,
|
||||||
|
@ -125,17 +127,46 @@ void RestAqlHandler::createQuery () {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
options = queryJson.get("options");
|
options = queryJson.get("options").copy();
|
||||||
}
|
}
|
||||||
catch (...) {
|
catch (...) {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto query = new Query(vocbase, queryJson, options.steal());
|
std::cout << "plan" << plan.toString() << std::endl;
|
||||||
|
std::cout << "options" << options.toString() << std::endl;
|
||||||
|
|
||||||
|
auto query = new Query(vocbase, plan, options.steal());
|
||||||
|
QueryResult res = query->prepare();
|
||||||
|
if (res.code != TRI_ERROR_NO_ERROR) {
|
||||||
|
generateError(HttpResponse::BAD, TRI_ERROR_QUERY_BAD_JSON_PLAN,
|
||||||
|
res.details);
|
||||||
|
delete query;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now the query is ready to go, store it in the registry and return:
|
||||||
|
double ttl = 3600.0;
|
||||||
|
bool found;
|
||||||
|
char const* ttlstring = _request->header("ttl", found);
|
||||||
|
if (found) {
|
||||||
|
ttl = triagens::basics::StringUtils::doubleDecimal(ttlstring);
|
||||||
|
}
|
||||||
|
QueryId qId = TRI_NewTickServer();
|
||||||
|
try {
|
||||||
|
_queryRegistry->insert(vocbase, qId, query, ttl);
|
||||||
|
}
|
||||||
|
catch (...) {
|
||||||
|
generateError(HttpResponse::BAD, TRI_ERROR_INTERNAL,
|
||||||
|
"could not keep query in registry");
|
||||||
|
delete query;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_response = createResponse(triagens::rest::HttpResponse::OK);
|
_response = createResponse(triagens::rest::HttpResponse::OK);
|
||||||
_response->setContentType("application/json; charset=utf-8");
|
_response->setContentType("application/json; charset=utf-8");
|
||||||
_response->body().appendText("{\"a\":12}");
|
_response->body().appendText("{\"queryId\":");
|
||||||
|
_response->body().appendInteger(qId);
|
||||||
|
_response->body().appendText("}");
|
||||||
}
|
}
|
||||||
|
|
||||||
void RestAqlHandler::deleteQuery () {
|
void RestAqlHandler::deleteQuery () {
|
||||||
|
|
|
@ -175,6 +175,7 @@
|
||||||
"ERROR_QUERY_MODIFY_IN_SUBQUERY" : { "code" : 1574, "message" : "modify operation in subquery" },
|
"ERROR_QUERY_MODIFY_IN_SUBQUERY" : { "code" : 1574, "message" : "modify operation in subquery" },
|
||||||
"ERROR_QUERY_COMPILE_TIME_OPTIONS" : { "code" : 1575, "message" : "query options must be readable at query compile time" },
|
"ERROR_QUERY_COMPILE_TIME_OPTIONS" : { "code" : 1575, "message" : "query options must be readable at query compile time" },
|
||||||
"ERROR_QUERY_EXCEPTION_OPTIONS" : { "code" : 1576, "message" : "query options expected" },
|
"ERROR_QUERY_EXCEPTION_OPTIONS" : { "code" : 1576, "message" : "query options expected" },
|
||||||
|
"ERROR_QUERY_BAD_JSON_PLAN" : { "code" : 1577, "message" : "JSON describing execution plan was bad" },
|
||||||
"ERROR_QUERY_FUNCTION_INVALID_NAME" : { "code" : 1580, "message" : "invalid user function name" },
|
"ERROR_QUERY_FUNCTION_INVALID_NAME" : { "code" : 1580, "message" : "invalid user function name" },
|
||||||
"ERROR_QUERY_FUNCTION_INVALID_CODE" : { "code" : 1581, "message" : "invalid user function code" },
|
"ERROR_QUERY_FUNCTION_INVALID_CODE" : { "code" : 1581, "message" : "invalid user function code" },
|
||||||
"ERROR_QUERY_FUNCTION_NOT_FOUND" : { "code" : 1582, "message" : "user function '%s()' not found" },
|
"ERROR_QUERY_FUNCTION_NOT_FOUND" : { "code" : 1582, "message" : "user function '%s()' not found" },
|
||||||
|
|
|
@ -175,6 +175,7 @@
|
||||||
"ERROR_QUERY_MODIFY_IN_SUBQUERY" : { "code" : 1574, "message" : "modify operation in subquery" },
|
"ERROR_QUERY_MODIFY_IN_SUBQUERY" : { "code" : 1574, "message" : "modify operation in subquery" },
|
||||||
"ERROR_QUERY_COMPILE_TIME_OPTIONS" : { "code" : 1575, "message" : "query options must be readable at query compile time" },
|
"ERROR_QUERY_COMPILE_TIME_OPTIONS" : { "code" : 1575, "message" : "query options must be readable at query compile time" },
|
||||||
"ERROR_QUERY_EXCEPTION_OPTIONS" : { "code" : 1576, "message" : "query options expected" },
|
"ERROR_QUERY_EXCEPTION_OPTIONS" : { "code" : 1576, "message" : "query options expected" },
|
||||||
|
"ERROR_QUERY_BAD_JSON_PLAN" : { "code" : 1577, "message" : "JSON describing execution plan was bad" },
|
||||||
"ERROR_QUERY_FUNCTION_INVALID_NAME" : { "code" : 1580, "message" : "invalid user function name" },
|
"ERROR_QUERY_FUNCTION_INVALID_NAME" : { "code" : 1580, "message" : "invalid user function name" },
|
||||||
"ERROR_QUERY_FUNCTION_INVALID_CODE" : { "code" : 1581, "message" : "invalid user function code" },
|
"ERROR_QUERY_FUNCTION_INVALID_CODE" : { "code" : 1581, "message" : "invalid user function code" },
|
||||||
"ERROR_QUERY_FUNCTION_NOT_FOUND" : { "code" : 1582, "message" : "user function '%s()' not found" },
|
"ERROR_QUERY_FUNCTION_NOT_FOUND" : { "code" : 1582, "message" : "user function '%s()' not found" },
|
||||||
|
|
|
@ -216,6 +216,7 @@ ERROR_QUERY_MULTI_MODIFY,1573,"multi-modify query", "Will be raised when an AQL
|
||||||
ERROR_QUERY_MODIFY_IN_SUBQUERY,1574,"modify operation in subquery", "Will be raised when an AQL query contains a data-modifying operation inside a subquery."
|
ERROR_QUERY_MODIFY_IN_SUBQUERY,1574,"modify operation in subquery", "Will be raised when an AQL query contains a data-modifying operation inside a subquery."
|
||||||
ERROR_QUERY_COMPILE_TIME_OPTIONS,1575,"query options must be readable at query compile time", "Will be raised when an AQL data-modification query contains options that cannot be figured out at query compile time."
|
ERROR_QUERY_COMPILE_TIME_OPTIONS,1575,"query options must be readable at query compile time", "Will be raised when an AQL data-modification query contains options that cannot be figured out at query compile time."
|
||||||
ERROR_QUERY_EXCEPTION_OPTIONS,1576,"query options expected", "Will be raised when an AQL data-modification query contains an invalid options specification."
|
ERROR_QUERY_EXCEPTION_OPTIONS,1576,"query options expected", "Will be raised when an AQL data-modification query contains an invalid options specification."
|
||||||
|
ERROR_QUERY_BAD_JSON_PLAN,1577,"JSON describing execution plan was bad", "Will be raised when an HTTP API for a query got an invalid JSON object."
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
## AQL user functions
|
## AQL user functions
|
||||||
|
|
|
@ -171,6 +171,7 @@ void TRI_InitialiseErrorMessages (void) {
|
||||||
REG_ERROR(ERROR_QUERY_MODIFY_IN_SUBQUERY, "modify operation in subquery");
|
REG_ERROR(ERROR_QUERY_MODIFY_IN_SUBQUERY, "modify operation in subquery");
|
||||||
REG_ERROR(ERROR_QUERY_COMPILE_TIME_OPTIONS, "query options must be readable at query compile time");
|
REG_ERROR(ERROR_QUERY_COMPILE_TIME_OPTIONS, "query options must be readable at query compile time");
|
||||||
REG_ERROR(ERROR_QUERY_EXCEPTION_OPTIONS, "query options expected");
|
REG_ERROR(ERROR_QUERY_EXCEPTION_OPTIONS, "query options expected");
|
||||||
|
REG_ERROR(ERROR_QUERY_BAD_JSON_PLAN, "JSON describing execution plan was bad");
|
||||||
REG_ERROR(ERROR_QUERY_FUNCTION_INVALID_NAME, "invalid user function name");
|
REG_ERROR(ERROR_QUERY_FUNCTION_INVALID_NAME, "invalid user function name");
|
||||||
REG_ERROR(ERROR_QUERY_FUNCTION_INVALID_CODE, "invalid user function code");
|
REG_ERROR(ERROR_QUERY_FUNCTION_INVALID_CODE, "invalid user function code");
|
||||||
REG_ERROR(ERROR_QUERY_FUNCTION_NOT_FOUND, "user function '%s()' not found");
|
REG_ERROR(ERROR_QUERY_FUNCTION_NOT_FOUND, "user function '%s()' not found");
|
||||||
|
|
|
@ -421,6 +421,8 @@
|
||||||
/// - 1576: @LIT{query options expected}
|
/// - 1576: @LIT{query options expected}
|
||||||
/// "Will be raised when an AQL data-modification query contains an invalid
|
/// "Will be raised when an AQL data-modification query contains an invalid
|
||||||
/// options specification."
|
/// options specification."
|
||||||
|
/// - 1577: @LIT{JSON describing execution plan was bad}
|
||||||
|
/// "Will be raised when an HTTP API for a query got an invalid JSON object."
|
||||||
/// - 1580: @LIT{invalid user function name}
|
/// - 1580: @LIT{invalid user function name}
|
||||||
/// Will be raised when a user function with an invalid name is registered.
|
/// Will be raised when a user function with an invalid name is registered.
|
||||||
/// - 1581: @LIT{invalid user function code}
|
/// - 1581: @LIT{invalid user function code}
|
||||||
|
@ -2315,6 +2317,16 @@ void TRI_InitialiseErrorMessages (void);
|
||||||
|
|
||||||
#define TRI_ERROR_QUERY_EXCEPTION_OPTIONS (1576)
|
#define TRI_ERROR_QUERY_EXCEPTION_OPTIONS (1576)
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief 1577: ERROR_QUERY_BAD_JSON_PLAN
|
||||||
|
///
|
||||||
|
/// JSON describing execution plan was bad
|
||||||
|
///
|
||||||
|
/// "Will be raised when an HTTP API for a query got an invalid JSON object."
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#define TRI_ERROR_QUERY_BAD_JSON_PLAN (1577)
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief 1580: ERROR_QUERY_FUNCTION_INVALID_NAME
|
/// @brief 1580: ERROR_QUERY_FUNCTION_INVALID_NAME
|
||||||
///
|
///
|
||||||
|
|
Loading…
Reference in New Issue