mirror of https://gitee.com/bigwinds/arangodb
allow dynamic parameters in DOCUMENT()
This commit is contained in:
parent
83866ba58b
commit
e190076c29
|
@ -146,7 +146,7 @@ static const char* NormalizeName (const TRI_aql_function_t* const function) {
|
||||||
/// @brief check the type of an argument for a function call
|
/// @brief check the type of an argument for a function call
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static bool CheckArgumentType (TRI_aql_node_t* parameter,
|
static bool CheckArgumentType (TRI_aql_node_t const* parameter,
|
||||||
const param_t* const allowed) {
|
const param_t* const allowed) {
|
||||||
param_t found = InitParam();
|
param_t found = InitParam();
|
||||||
|
|
||||||
|
@ -200,6 +200,16 @@ static bool CheckArgumentType (TRI_aql_node_t* parameter,
|
||||||
found._collection = true;
|
found._collection = true;
|
||||||
found._list = true; // a collection is a list of documents
|
found._list = true; // a collection is a list of documents
|
||||||
}
|
}
|
||||||
|
else if (parameter->_type == TRI_AQL_NODE_ATTRIBUTE_ACCESS ||
|
||||||
|
parameter->_type == TRI_AQL_NODE_INDEXED) {
|
||||||
|
// value.attribute or value[index]
|
||||||
|
found._null = true;
|
||||||
|
found._bool = true;
|
||||||
|
found._number = true;
|
||||||
|
found._string = true;
|
||||||
|
found._list = true;
|
||||||
|
found._array = true;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
// we cannot yet determine the type of the parameter
|
// we cannot yet determine the type of the parameter
|
||||||
// this is the case if the argument is an expression, a function call etc.
|
// this is the case if the argument is an expression, a function call etc.
|
||||||
|
@ -669,7 +679,7 @@ TRI_associative_pointer_t* TRI_CreateFunctionsAql (void) {
|
||||||
REGISTER_FUNCTION("ATTRIBUTES", "ATTRIBUTES", true, false, "a|b,b", NULL);
|
REGISTER_FUNCTION("ATTRIBUTES", "ATTRIBUTES", true, false, "a|b,b", NULL);
|
||||||
REGISTER_FUNCTION("MERGE", "MERGE", true, false, "a,a|+", NULL);
|
REGISTER_FUNCTION("MERGE", "MERGE", true, false, "a,a|+", NULL);
|
||||||
REGISTER_FUNCTION("MERGE_RECURSIVE", "MERGE_RECURSIVE", true, false, "a,a|+", NULL);
|
REGISTER_FUNCTION("MERGE_RECURSIVE", "MERGE_RECURSIVE", true, false, "a,a|+", NULL);
|
||||||
REGISTER_FUNCTION("DOCUMENT", "DOCUMENT", false, false, "hsl|sl", NULL);
|
REGISTER_FUNCTION("DOCUMENT", "DOCUMENT", false, false, "h.|.", NULL);
|
||||||
REGISTER_FUNCTION("MATCHES", "MATCHES", true, false, ".,l|b", NULL);
|
REGISTER_FUNCTION("MATCHES", "MATCHES", true, false, ".,l|b", NULL);
|
||||||
REGISTER_FUNCTION("UNSET", "UNSET", true, false, "a,sl|+", NULL);
|
REGISTER_FUNCTION("UNSET", "UNSET", true, false, "a,sl|+", NULL);
|
||||||
REGISTER_FUNCTION("KEEP", "KEEP", true, false, "a,sl|+", NULL);
|
REGISTER_FUNCTION("KEEP", "KEEP", true, false, "a,sl|+", NULL);
|
||||||
|
@ -840,10 +850,11 @@ bool TRI_ConvertParameterFunctionAql (const TRI_aql_function_t* const function,
|
||||||
size_t i;
|
size_t i;
|
||||||
bool foundArg = false;
|
bool foundArg = false;
|
||||||
|
|
||||||
assert(function);
|
assert(function != NULL);
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
pattern = function->_argPattern;
|
pattern = function->_argPattern;
|
||||||
|
|
||||||
while ((c = *pattern++)) {
|
while ((c = *pattern++)) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '|':
|
case '|':
|
||||||
|
|
|
@ -1873,6 +1873,10 @@ function STRING_SUBSTRING (value, offset, count) {
|
||||||
ARG_CHECK(value, TYPEWEIGHT_STRING, "SUBSTRING");
|
ARG_CHECK(value, TYPEWEIGHT_STRING, "SUBSTRING");
|
||||||
ARG_CHECK(offset, TYPEWEIGHT_NUMBER, "SUBSTRING");
|
ARG_CHECK(offset, TYPEWEIGHT_NUMBER, "SUBSTRING");
|
||||||
|
|
||||||
|
if (count !== undefined) {
|
||||||
|
ARG_CHECK(count, TYPEWEIGHT_NUMBER, "SUBSTRING");
|
||||||
|
}
|
||||||
|
|
||||||
return value.substr(offset, count);
|
return value.substr(offset, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1888,6 +1892,11 @@ function STRING_CONTAINS (value, search, returnIndex) {
|
||||||
ARG_CHECK(value, TYPEWEIGHT_STRING, "CONTAINS");
|
ARG_CHECK(value, TYPEWEIGHT_STRING, "CONTAINS");
|
||||||
ARG_CHECK(search, TYPEWEIGHT_STRING, "CONTAINS");
|
ARG_CHECK(search, TYPEWEIGHT_STRING, "CONTAINS");
|
||||||
|
|
||||||
|
if (returnIndex !== undefined) {
|
||||||
|
ARG_CHECK(returnIndex, TYPEWEIGHT_BOOL, "CONTAINS");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var result;
|
var result;
|
||||||
if (search.length === 0) {
|
if (search.length === 0) {
|
||||||
result = -1;
|
result = -1;
|
||||||
|
|
|
@ -1760,6 +1760,16 @@ function ahuacatlFunctionsTestSuite () {
|
||||||
actual = getQueryResults("RETURN DOCUMENT(\"" + d2._id + "\")");
|
actual = getQueryResults("RETURN DOCUMENT(\"" + d2._id + "\")");
|
||||||
assertEqual(expected, actual);
|
assertEqual(expected, actual);
|
||||||
|
|
||||||
|
// test with bind parameter
|
||||||
|
expected = [ { title: "nada", value : 123 } ];
|
||||||
|
actual = getQueryResults("RETURN DOCUMENT(@id)", { id: d2._id });
|
||||||
|
assertEqual(expected, actual);
|
||||||
|
|
||||||
|
// test dynamic parameter
|
||||||
|
expected = [ { title: "nada", value : 123 }, { title: "123", value: 456 } ];
|
||||||
|
actual = getQueryResults("FOR d IN @@cn SORT d.value RETURN DOCUMENT(d._id)", { "@cn" : cn });
|
||||||
|
assertEqual(expected, actual);
|
||||||
|
|
||||||
internal.db._drop(cn);
|
internal.db._drop(cn);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue