1
0
Fork 0

fixed crashes

This commit is contained in:
Jan Steemann 2016-05-04 12:38:44 +02:00
parent 7e2603bdcc
commit 6489bd1364
3 changed files with 27 additions and 12 deletions

View File

@ -976,13 +976,13 @@ AqlValue Functions::ToArray(arangodb::aql::Query* query,
if (value.isArray()) {
// return copy of the original array
return AqlValue(value);
return value.clone();
}
if (value.isNull(true)) {
return AqlValue(arangodb::basics::VelocyPackHelper::EmptyArrayValue());
}
TransactionBuilderLeaser builder(trx);
builder->openArray();
if (value.isBoolean() || value.isNumber() || value.isString()) {
@ -993,7 +993,11 @@ AqlValue Functions::ToArray(arangodb::aql::Query* query,
VPackSlice slice = materializer.slice(value, false);
// return an array with the attribute values
for (auto const& it : VPackObjectIterator(slice, true)) {
builder->add(it.value);
if (it.value.isCustom()) {
builder->add(VPackValue(trx->extractIdString(slice)));
} else {
builder->add(it.value);
}
}
}
builder->close();

View File

@ -286,6 +286,12 @@ Query* Query::clone(QueryPart part, bool withPlan) {
/// @brief add a node to the list of nodes
void Query::addNode(AstNode* node) { _nodes.emplace_back(node); }
void Query::setExecutionTime() {
if (_engine != nullptr) {
_engine->_stats.setExecutionTime(TRI_microtime() - _startTime);
}
}
/// @brief extract a region from the query
std::string Query::extractRegion(int line, int column) const {
@ -571,6 +577,7 @@ QueryResult Query::execute(QueryRegistry* registry) {
options.buildUnindexedArrays = true;
options.buildUnindexedObjects = true;
TRI_ASSERT(_engine != nullptr);
auto resultBuilder = std::make_shared<VPackBuilder>(&options);
try {
resultBuilder->openArray();
@ -655,22 +662,22 @@ QueryResult Query::execute(QueryRegistry* registry) {
return result;
} catch (arangodb::basics::Exception const& ex) {
_engine->_stats.setExecutionTime(TRI_microtime() - _startTime);
setExecutionTime();
cleanupPlanAndEngine(ex.code());
return QueryResult(ex.code(), ex.message() + getStateString());
} catch (std::bad_alloc const&) {
_engine->_stats.setExecutionTime(TRI_microtime() - _startTime);
setExecutionTime();
cleanupPlanAndEngine(TRI_ERROR_OUT_OF_MEMORY);
return QueryResult(
TRI_ERROR_OUT_OF_MEMORY,
TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY) + getStateString());
} catch (std::exception const& ex) {
_engine->_stats.setExecutionTime(TRI_microtime() - _startTime);
setExecutionTime();
cleanupPlanAndEngine(TRI_ERROR_INTERNAL);
return QueryResult(TRI_ERROR_INTERNAL, ex.what() + getStateString());
} catch (...) {
setExecutionTime();
cleanupPlanAndEngine(TRI_ERROR_INTERNAL);
_engine->_stats.setExecutionTime(TRI_microtime() - _startTime);
return QueryResult(TRI_ERROR_INTERNAL,
TRI_errno_string(TRI_ERROR_INTERNAL) + getStateString());
}
@ -726,6 +733,8 @@ QueryResultV8 Query::executeV8(v8::Isolate* isolate, QueryRegistry* registry) {
result.result = v8::Array::New(isolate);
TRI_ASSERT(_engine != nullptr);
// this is the RegisterId our results can be found in
auto const resultRegister = _engine->resultRegister();
AqlItemBlock* value = nullptr;
@ -812,21 +821,21 @@ QueryResultV8 Query::executeV8(v8::Isolate* isolate, QueryRegistry* registry) {
return result;
} catch (arangodb::basics::Exception const& ex) {
_engine->_stats.setExecutionTime(TRI_microtime() - _startTime);
setExecutionTime();
cleanupPlanAndEngine(ex.code());
return QueryResultV8(ex.code(), ex.message() + getStateString());
} catch (std::bad_alloc const&) {
_engine->_stats.setExecutionTime(TRI_microtime() - _startTime);
setExecutionTime();
cleanupPlanAndEngine(TRI_ERROR_OUT_OF_MEMORY);
return QueryResultV8(
TRI_ERROR_OUT_OF_MEMORY,
TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY) + getStateString());
} catch (std::exception const& ex) {
_engine->_stats.setExecutionTime(TRI_microtime() - _startTime);
setExecutionTime();
cleanupPlanAndEngine(TRI_ERROR_INTERNAL);
return QueryResultV8(TRI_ERROR_INTERNAL, ex.what() + getStateString());
} catch (...) {
_engine->_stats.setExecutionTime(TRI_microtime() - _startTime);
setExecutionTime();
cleanupPlanAndEngine(TRI_ERROR_INTERNAL);
return QueryResult(TRI_ERROR_INTERNAL,
TRI_errno_string(TRI_ERROR_INTERNAL) + getStateString());
@ -1080,7 +1089,7 @@ void Query::exitContext() {
/// @brief returns statistics for current query.
void Query::getStats(VPackBuilder& builder) {
if (_engine) {
if (_engine != nullptr) {
_engine->_stats.setExecutionTime(TRI_microtime() - _startTime);
_engine->_stats.toVelocyPack(builder);
} else {

View File

@ -292,6 +292,8 @@ class Query {
private:
/// @brief initializes the query
void init();
void setExecutionTime();
/// @brief log a query
void log();