mirror of https://gitee.com/bigwinds/arangodb
add native implementation of the FAIL aql function (#5232)
This commit is contained in:
parent
b4dcad9662
commit
ba278a64c9
|
@ -325,7 +325,7 @@ void AqlFunctionFeature::addDateFunctions() {
|
||||||
|
|
||||||
void AqlFunctionFeature::addMiscFunctions() {
|
void AqlFunctionFeature::addMiscFunctions() {
|
||||||
// misc functions
|
// misc functions
|
||||||
add({"FAIL", "|.", false, true, true });
|
add({"FAIL", "|.", false, true, true, &Functions::Fail});
|
||||||
add({"PASSTHRU", ".", false, false, true, &Functions::Passthru});
|
add({"PASSTHRU", ".", false, false, true, &Functions::Passthru});
|
||||||
addAlias("NOOPT", "PASSTHRU");
|
addAlias("NOOPT", "PASSTHRU");
|
||||||
add({"V8", ".", true, false, true });
|
add({"V8", ".", true, false, true });
|
||||||
|
|
|
@ -5887,3 +5887,24 @@ AqlValue Functions::Warn(arangodb::aql::Query* query, transaction::Methods* trx,
|
||||||
}
|
}
|
||||||
return AqlValue(AqlValueHintBool(true));
|
return AqlValue(AqlValueHintBool(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AqlValue Functions::Fail(arangodb::aql::Query* query, transaction::Methods* trx,
|
||||||
|
VPackFunctionParameters const& parameters) {
|
||||||
|
static char const* AFN = "FAIL";
|
||||||
|
ValidateParameters(parameters, AFN, 0, 1);
|
||||||
|
if (parameters.size() == 0) {
|
||||||
|
THROW_ARANGO_EXCEPTION_PARAMS(TRI_ERROR_QUERY_FAIL_CALLED, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
AqlValue value = ExtractFunctionParameterValue(parameters, 0);
|
||||||
|
|
||||||
|
if (! value.isString()) {
|
||||||
|
THROW_ARANGO_EXCEPTION_PARAMS(TRI_ERROR_QUERY_FAIL_CALLED, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
AqlValueMaterializer materializer(trx);
|
||||||
|
VPackValueLength l;
|
||||||
|
char const* msg = materializer.slice(value, false).getString(l);
|
||||||
|
|
||||||
|
THROW_ARANGO_EXCEPTION_PARAMS(TRI_ERROR_QUERY_FAIL_CALLED, msg);
|
||||||
|
}
|
||||||
|
|
|
@ -476,6 +476,8 @@ struct Functions {
|
||||||
VPackFunctionParameters const&);
|
VPackFunctionParameters const&);
|
||||||
static AqlValue Warn(arangodb::aql::Query*, transaction::Methods*,
|
static AqlValue Warn(arangodb::aql::Query*, transaction::Methods*,
|
||||||
VPackFunctionParameters const&);
|
VPackFunctionParameters const&);
|
||||||
|
static AqlValue Fail(arangodb::aql::Query*, transaction::Methods*,
|
||||||
|
VPackFunctionParameters const&);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ var helper = require("@arangodb/aql-helper");
|
||||||
var getQueryResults = helper.getQueryResults;
|
var getQueryResults = helper.getQueryResults;
|
||||||
var assertQueryError = helper.assertQueryError;
|
var assertQueryError = helper.assertQueryError;
|
||||||
var assertQueryWarningAndNull = helper.assertQueryWarningAndNull;
|
var assertQueryWarningAndNull = helper.assertQueryWarningAndNull;
|
||||||
|
var internal = require('internal');
|
||||||
|
|
||||||
var sortObj = function (obj) {
|
var sortObj = function (obj) {
|
||||||
var result = { };
|
var result = { };
|
||||||
|
@ -86,7 +87,70 @@ function ahuacatlFunctionsTestSuite () {
|
||||||
tearDownAll : function () {
|
tearDownAll : function () {
|
||||||
db._drop(collectionName);
|
db._drop(collectionName);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief test first function
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
testFail : function () {
|
||||||
|
try {
|
||||||
|
db._query("RETURN FAIL()");
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
catch(err) {
|
||||||
|
var expected = internal.errors.ERROR_QUERY_FAIL_CALLED.code;
|
||||||
|
assertEqual(expected, err.errorNum);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief test first function
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
testFailInt : function () {
|
||||||
|
try {
|
||||||
|
db._query("RETURN FAIL(1234)");
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
catch(err) {
|
||||||
|
var expected = internal.errors.ERROR_QUERY_FAIL_CALLED.code;
|
||||||
|
assertEqual(expected, err.errorNum);
|
||||||
|
assertTrue(err.errorMessage.search("1234") === -1);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief test first function
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
testFailObj : function () {
|
||||||
|
try {
|
||||||
|
db._query("RETURN FAIL({})");
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
catch(err) {
|
||||||
|
var expected = internal.errors.ERROR_QUERY_FAIL_CALLED.code;
|
||||||
|
assertEqual(expected, err.errorNum);
|
||||||
|
assertTrue(err.errorMessage.search("{}") === -1);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief test first function
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
testFailMessage : function () {
|
||||||
|
try {
|
||||||
|
db._query("RETURN FAIL('bla')");
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
catch(err) {
|
||||||
|
var expected = internal.errors.ERROR_QUERY_FAIL_CALLED.code;
|
||||||
|
assertEqual(expected, err.errorNum);
|
||||||
|
assertTrue(err.errorMessage.search("bla") !== -1);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief test first function
|
/// @brief test first function
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Reference in New Issue