Example #1
0
bool TRI_ValueStringAql (TRI_string_buffer_t* const buffer,
                         const TRI_aql_value_t* const value,
                         const TRI_aql_value_type_e type) {
  switch (type) {
    case TRI_AQL_TYPE_FAIL:
      return (TRI_AppendStringStringBuffer(buffer, "fail") == TRI_ERROR_NO_ERROR);

    case TRI_AQL_TYPE_NULL:
      return (TRI_AppendStringStringBuffer(buffer, "null") == TRI_ERROR_NO_ERROR);

    case TRI_AQL_TYPE_BOOL:
      return (TRI_AppendStringStringBuffer(buffer, value->_value._bool ? "true" : "false") == TRI_ERROR_NO_ERROR);

    case TRI_AQL_TYPE_INT:
      return (TRI_AppendInt64StringBuffer(buffer, value->_value._int) == TRI_ERROR_NO_ERROR);

    case TRI_AQL_TYPE_DOUBLE:
      return (TRI_AppendDoubleStringBuffer(buffer, value->_value._double) == TRI_ERROR_NO_ERROR);

    case TRI_AQL_TYPE_STRING: {
      if (TRI_AppendCharStringBuffer(buffer, '"') != TRI_ERROR_NO_ERROR) {
        return false;
      }

      if (TRI_AppendStringStringBuffer(buffer, value->_value._string) != TRI_ERROR_NO_ERROR) {
        return false;
      }

      return (TRI_AppendCharStringBuffer(buffer, '"') == TRI_ERROR_NO_ERROR);
    }
  }

  return false;
}
Example #2
0
bool TRI_ValueJavascriptAql (TRI_string_buffer_t* const buffer,
                             const TRI_aql_value_t* const value,
                             const TRI_aql_value_type_e type) {
  switch (type) {
    case TRI_AQL_TYPE_FAIL:
      return (TRI_AppendStringStringBuffer(buffer, "fail") == TRI_ERROR_NO_ERROR);

    case TRI_AQL_TYPE_NULL:
      return (TRI_AppendStringStringBuffer(buffer, "null") == TRI_ERROR_NO_ERROR);

    case TRI_AQL_TYPE_BOOL:
      return (TRI_AppendStringStringBuffer(buffer, value->_value._bool ? "true" : "false") == TRI_ERROR_NO_ERROR);

    case TRI_AQL_TYPE_INT:
      return (TRI_AppendInt64StringBuffer(buffer, value->_value._int) == TRI_ERROR_NO_ERROR);

    case TRI_AQL_TYPE_DOUBLE:
      return (TRI_AppendDoubleStringBuffer(buffer, value->_value._double) == TRI_ERROR_NO_ERROR);

    case TRI_AQL_TYPE_STRING: {
      char* escapedString;
      size_t outLength;

      if (TRI_AppendCharStringBuffer(buffer, '"') != TRI_ERROR_NO_ERROR) {
        return false;
      }

      escapedString = TRI_EscapeUtf8StringZ(TRI_UNKNOWN_MEM_ZONE,
                                            value->_value._string,
                                            strlen(value->_value._string),
                                            false,
                                            &outLength);
      if (escapedString == NULL) {
        return false;
      }

      if (TRI_AppendStringStringBuffer(buffer, escapedString) != TRI_ERROR_NO_ERROR) {
        TRI_Free(TRI_UNKNOWN_MEM_ZONE, escapedString);

        return false;
      }

      TRI_Free(TRI_UNKNOWN_MEM_ZONE, escapedString);

      return (TRI_AppendCharStringBuffer(buffer, '"') == TRI_ERROR_NO_ERROR);
    }
  }

  return false;
}
int TRI_AppendCsvInt64StringBuffer (TRI_string_buffer_t * self, int64_t i) {
  int res;

  res = TRI_AppendInt64StringBuffer(self, i);

  if (res != TRI_ERROR_NO_ERROR) {
    return res;
  }

  res = Reserve(self, 1);

  if (res != TRI_ERROR_NO_ERROR) {
    return res;
  }

  AppendChar(self, ';');
  return TRI_ERROR_NO_ERROR;
}
Example #4
0
bool TRI_ValueJavascriptAql (TRI_string_buffer_t* const buffer,
                             const TRI_aql_value_t* const value,
                             const TRI_aql_value_type_e type) {
    switch (type) {
    case TRI_AQL_TYPE_FAIL: {
        return (TRI_AppendString2StringBuffer(buffer, "fail", 4) == TRI_ERROR_NO_ERROR);
    }

    case TRI_AQL_TYPE_NULL: {
        return (TRI_AppendString2StringBuffer(buffer, "null", 4) == TRI_ERROR_NO_ERROR);
    }

    case TRI_AQL_TYPE_BOOL: {
        if (value->_value._bool) {
            return (TRI_AppendString2StringBuffer(buffer, "true", 4) == TRI_ERROR_NO_ERROR);
        }
        else {
            return (TRI_AppendString2StringBuffer(buffer, "false", 5) == TRI_ERROR_NO_ERROR);
        }
    }

    case TRI_AQL_TYPE_INT: {
        return (TRI_AppendInt64StringBuffer(buffer, value->_value._int) == TRI_ERROR_NO_ERROR);
    }

    case TRI_AQL_TYPE_DOUBLE: {
        return (TRI_AppendDoubleStringBuffer(buffer, value->_value._double) == TRI_ERROR_NO_ERROR);
    }

    case TRI_AQL_TYPE_STRING: {
        if (TRI_AppendCharStringBuffer(buffer, '"') != TRI_ERROR_NO_ERROR) {
            return false;
        }

        if (TRI_AppendJsonEncodedStringStringBuffer(buffer, value->_value._string, false) != TRI_ERROR_NO_ERROR) {
            return false;
        }

        return (TRI_AppendCharStringBuffer(buffer, '"') == TRI_ERROR_NO_ERROR);
    }
    }

    return false;
}
Example #5
0
void TRI_ConvertQueryJavascript (TRI_query_javascript_converter_t* converter, 
                                 const TRI_query_node_t* const node,
                                 TRI_associative_pointer_t* bindParameters) {
  TRI_query_node_t* lhs;
  TRI_query_node_t* rhs;
  TRI_bind_parameter_t* parameter;
  char* escapedString;
  size_t outLength;

  assert(converter);
  assert(bindParameters);

  if (!node) {
    return;
  }

  lhs = node->_lhs;
  rhs = node->_rhs;

  switch (node->_type) {
    case TRI_QueryNodeValueUndefined:
      TRI_AppendStringStringBuffer(converter->_buffer, "undefined");
      return;
    case TRI_QueryNodeValueNull:
      TRI_AppendStringStringBuffer(converter->_buffer, "null");
      return;
    case TRI_QueryNodeValueBool:
      TRI_AppendStringStringBuffer(converter->_buffer, 
                                   node->_value._boolValue ? "true" : "false");
      return;
    case TRI_QueryNodeValueString:
      TRI_AppendCharStringBuffer(converter->_buffer, '"');
      escapedString = TRI_EscapeUtf8String(
        node->_value._stringValue, 
        strlen(node->_value._stringValue), 
        false, 
        &outLength
      );
      if (escapedString) {
        TRI_AppendStringStringBuffer(converter->_buffer, escapedString);
        TRI_Free(escapedString); 
      }
      TRI_AppendCharStringBuffer(converter->_buffer, '"');
      return;
    case TRI_QueryNodeValueNumberInt:
      TRI_AppendInt64StringBuffer(converter->_buffer, node->_value._intValue);
      return;
    case TRI_QueryNodeValueNumberDouble:
      TRI_AppendDoubleStringBuffer(converter->_buffer, node->_value._doubleValue);
      return;
    case TRI_QueryNodeValueNumberDoubleString:
      TRI_AppendStringStringBuffer(converter->_buffer, node->_value._stringValue);
      return;
    case TRI_QueryNodeValueArray:
      TRI_AppendCharStringBuffer(converter->_buffer, '[');
      TRI_WalkListQueryJavascript(converter, rhs, bindParameters, ',', 0);
      TRI_AppendCharStringBuffer(converter->_buffer, ']');
      return; 
    case TRI_QueryNodeValueDocument:
      TRI_AppendCharStringBuffer(converter->_buffer, '{');
      TRI_WalkListQueryJavascript(converter, rhs, bindParameters, ',', 0);
      TRI_AppendCharStringBuffer(converter->_buffer, '}');
      return; 
    case TRI_QueryNodeValueParameterNamed:
      parameter = (TRI_bind_parameter_t*) 
        TRI_LookupByKeyAssociativePointer(bindParameters, 
                                          node->_value._stringValue);
      assert(parameter);  
      TRI_StringifyJson(converter->_buffer, parameter->_data); 
      return;
    case TRI_QueryNodeValueIdentifier:
      TRI_AppendStringStringBuffer(converter->_buffer, 
                                   node->_value._stringValue);
      return;
    case TRI_QueryNodeValueNamedValue:
      TRI_ConvertQueryJavascript(converter, lhs, bindParameters);
      TRI_AppendCharStringBuffer(converter->_buffer, ':');
      TRI_ConvertQueryJavascript(converter, rhs, bindParameters);
      return;
    case TRI_QueryNodeReferenceCollectionAlias:
      if (!converter->_prefix) {
        TRI_AppendStringStringBuffer(converter->_buffer, "$['");
        TRI_AppendStringStringBuffer(converter->_buffer, 
                                     node->_value._stringValue);
        TRI_AppendStringStringBuffer(converter->_buffer, "']");
      }
      else {
        TRI_AppendStringStringBuffer(converter->_buffer, "$['");
        TRI_AppendStringStringBuffer(converter->_buffer, 
                                     converter->_prefix);
        TRI_AppendStringStringBuffer(converter->_buffer, "'].");
        TRI_AppendStringStringBuffer(converter->_buffer, 
                                     node->_value._stringValue);
      }
      return;
    case TRI_QueryNodeUnaryOperatorPlus:
    case TRI_QueryNodeUnaryOperatorMinus:
    case TRI_QueryNodeUnaryOperatorNot:
      TRI_AppendStringStringBuffer(
        converter->_buffer, 
        TRI_QueryNodeGetUnaryOperatorString(node->_type)
      );
      TRI_ConvertQueryJavascript(converter, lhs, bindParameters);
      return;
    case TRI_QueryNodeBinaryOperatorAnd: 
    case TRI_QueryNodeBinaryOperatorOr: 
    case TRI_QueryNodeBinaryOperatorIdentical: 
    case TRI_QueryNodeBinaryOperatorUnidentical: 
    case TRI_QueryNodeBinaryOperatorEqual: 
    case TRI_QueryNodeBinaryOperatorUnequal: 
    case TRI_QueryNodeBinaryOperatorLess: 
    case TRI_QueryNodeBinaryOperatorGreater: 
    case TRI_QueryNodeBinaryOperatorLessEqual:
    case TRI_QueryNodeBinaryOperatorGreaterEqual:
    case TRI_QueryNodeBinaryOperatorAdd:
    case TRI_QueryNodeBinaryOperatorSubtract:
    case TRI_QueryNodeBinaryOperatorMultiply:
    case TRI_QueryNodeBinaryOperatorDivide:
    case TRI_QueryNodeBinaryOperatorModulus:
    case TRI_QueryNodeBinaryOperatorIn:
      TRI_AppendCharStringBuffer(converter->_buffer, '(');
      TRI_ConvertQueryJavascript(converter, lhs, bindParameters);
      TRI_AppendStringStringBuffer(
        converter->_buffer, 
        TRI_QueryNodeGetBinaryOperatorString(node->_type)
      );
      TRI_ConvertQueryJavascript(converter, rhs, bindParameters);
      TRI_AppendCharStringBuffer(converter->_buffer, ')');
      return;
    case TRI_QueryNodeContainerMemberAccess:
      TRI_ConvertQueryJavascript(converter, lhs, bindParameters);
      TRI_WalkListQueryJavascript(converter, rhs, bindParameters, '.', 1);
      return;
    case TRI_QueryNodeContainerTernarySwitch:
      TRI_ConvertQueryJavascript(converter, lhs, bindParameters);
      TRI_AppendCharStringBuffer(converter->_buffer, ':');
      TRI_ConvertQueryJavascript(converter, rhs, bindParameters);
      return;
    case TRI_QueryNodeControlFunctionCall:
      TRI_ConvertQueryJavascript(converter, lhs, bindParameters);
      TRI_AppendCharStringBuffer(converter->_buffer, '(');
      TRI_WalkListQueryJavascript(converter, rhs, bindParameters, ',', 0);
      TRI_AppendCharStringBuffer(converter->_buffer, ')');
      return;
    case TRI_QueryNodeControlTernary:
      TRI_AppendCharStringBuffer(converter->_buffer, '(');
      TRI_ConvertQueryJavascript(converter, lhs, bindParameters);
      TRI_AppendCharStringBuffer(converter->_buffer, '?');
      TRI_ConvertQueryJavascript(converter, rhs, bindParameters);
      TRI_AppendCharStringBuffer(converter->_buffer, ')');
      return;
    default:
      return;
  }
}