mirror of https://gitee.com/bigwinds/arangodb
250 lines
8.0 KiB
C
250 lines
8.0 KiB
C
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief AST query declarations
|
|
///
|
|
/// @file
|
|
///
|
|
/// DISCLAIMER
|
|
///
|
|
/// Copyright 2010-2012 triagens GmbH, Cologne, Germany
|
|
///
|
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|
/// you may not use this file except in compliance with the License.
|
|
/// You may obtain a copy of the License at
|
|
///
|
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
|
///
|
|
/// Unless required by applicable law or agreed to in writing, software
|
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
/// See the License for the specific language governing permissions and
|
|
/// limitations under the License.
|
|
///
|
|
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
|
///
|
|
/// @author Jan Steemann
|
|
/// @author Copyright 2012, triagens GmbH, Cologne, Germany
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#ifndef TRIAGENS_DURHAM_QL_ASTQUERY
|
|
#define TRIAGENS_DURHAM_QL_ASTQUERY
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <BasicsC/common.h>
|
|
#include <BasicsC/vector.h>
|
|
#include <BasicsC/associative.h>
|
|
#include <BasicsC/hashes.h>
|
|
#include <BasicsC/strings.h>
|
|
|
|
#include "QL/ast-node.h"
|
|
#include "VocBase/vocbase.h"
|
|
|
|
#define QL_QUERY_NAME_LEN 64
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @addtogroup QL
|
|
/// @{
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief Query types
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
typedef enum {
|
|
QLQueryTypeUndefined = 0,
|
|
|
|
QLQueryTypeEmpty,
|
|
QLQueryTypeSelect
|
|
}
|
|
QL_ast_query_type_e;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief SELECT query types
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
typedef enum {
|
|
QLQuerySelectTypeUndefined = 0,
|
|
|
|
QLQuerySelectTypeSimple,
|
|
QLQuerySelectTypeEvaluated
|
|
}
|
|
QL_ast_query_select_type_e;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief WHERE types of a query
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
typedef enum {
|
|
QLQueryWhereTypeUndefined = 0,
|
|
|
|
QLQueryWhereTypeMustEvaluate,
|
|
QLQueryWhereTypeAlwaysTrue,
|
|
QLQueryWhereTypeAlwaysFalse
|
|
}
|
|
QL_ast_query_where_type_e;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief ORDER BY types of a query
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
typedef enum {
|
|
QLQueryOrderTypeUndefined = 0,
|
|
|
|
QLQueryOrderTypeMustEvaluate,
|
|
QLQueryOrderTypeNone
|
|
}
|
|
QL_ast_query_order_type_e;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief SELECT part of a query
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
typedef struct QL_ast_query_select_s {
|
|
QL_ast_node_t *_base;
|
|
}
|
|
QL_ast_query_select_t;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief FROM part of a query
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
typedef struct QL_ast_query_from_s {
|
|
QL_ast_node_t *_base;
|
|
TRI_associative_pointer_t _collections;
|
|
}
|
|
QL_ast_query_from_t;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief WHERE part of a query
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
typedef struct QL_ast_query_where_s {
|
|
QL_ast_node_t *_base;
|
|
QL_ast_query_where_type_e _type;
|
|
}
|
|
QL_ast_query_where_t;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief ORDER part of a query
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
typedef struct QL_ast_query_order_s {
|
|
QL_ast_node_t *_base;
|
|
}
|
|
QL_ast_query_order_t;
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief LIMIT part of a query
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
typedef struct QL_ast_query_limit_s {
|
|
int64_t _offset;
|
|
int64_t _count;
|
|
bool _isUsed;
|
|
}
|
|
QL_ast_query_limit_t;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief Query declaration
|
|
///
|
|
/// A query consists of multiple parts, e.g. the selection part, the from part
|
|
/// containing the referenced collections, an optional where condition, an
|
|
/// optional order part and an optional limit
|
|
///
|
|
/// This struct might change later if further types of queries are introduced
|
|
/// that have different properties.
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
typedef struct QL_ast_query_s {
|
|
QL_ast_query_type_e _type;
|
|
QL_ast_query_select_t _select;
|
|
QL_ast_query_from_t _from;
|
|
QL_ast_query_where_t _where;
|
|
QL_ast_query_order_t _order;
|
|
QL_ast_query_limit_t _limit;
|
|
const TRI_vocbase_t* _vocbase;
|
|
}
|
|
QL_ast_query_t;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief Collection referenced by a query
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
typedef struct QL_ast_query_collection_s {
|
|
char* _name;
|
|
char* _alias;
|
|
bool _isPrimary;
|
|
size_t _refCount;
|
|
}
|
|
QL_ast_query_collection_t;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief Initialize data structures for a query
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void QLAstQueryInit (const TRI_vocbase_t*, QL_ast_query_t*);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief De-allocate data structures for a query
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void QLAstQueryFree (QL_ast_query_t*);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief get the ref count for a collection
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
size_t QLAstQueryGetRefCount (QL_ast_query_t*, const char*);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief Increment ref count for a collection
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void QLAstQueryAddRefCount (QL_ast_query_t*, const char*);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief Check if a collection was defined in a query
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
bool QLAstQueryIsValidAlias (QL_ast_query_t*, const char*);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief Return the collection name for its alias
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
char* QLAstQueryGetCollectionNameForAlias (QL_ast_query_t*, const char*);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief Add a collection to the query
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
bool QLAstQueryAddCollection (QL_ast_query_t*, const char*, const char*);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief get the alias of the primary collection used in the query
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
char* QLAstQueryGetPrimaryAlias (const QL_ast_query_t*);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|
|
|
|
// Local Variables:
|
|
// mode: outline-minor
|
|
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
|
|
// End:
|
|
|