21#ifndef SWQ_H_INCLUDED_
22#define SWQ_H_INCLUDED_
33#if defined(_WIN32) && !defined(strcasecmp)
34# define strcasecmp stricmp
38#define SZ_OGR_NULL "__OGR_NULL__"
87#define SWQ_IS_INTEGER(x) ((x) == SWQ_INTEGER || (x) == SWQ_INTEGER64)
100typedef swq_expr_node *(*swq_field_fetcher)( swq_expr_node *op,
101 void *record_handle );
102typedef swq_expr_node *(*swq_op_evaluator)(swq_expr_node *op,
103 swq_expr_node **sub_field_values );
104typedef swq_field_type (*swq_op_checker)( swq_expr_node *op,
105 int bAllowMismatchTypeOnFieldComparison );
107class swq_custom_func_registrar;
112 swq_expr_node* Evaluate( swq_field_fetcher pfnFetcher,
113 void *record,
int nRecLevel );
117 explicit swq_expr_node(
const char * );
118 explicit swq_expr_node(
int );
119 explicit swq_expr_node(
GIntBig );
120 explicit swq_expr_node(
double );
122 explicit swq_expr_node( swq_op );
126 void MarkAsTimestamp();
127 CPLString UnparseOperationFromUnparsedSubExpr(
char** apszSubExpr);
128 char *Unparse( swq_field_list *,
char chColumnQuote );
129 void Dump( FILE *fp,
int depth );
130 swq_field_type Check( swq_field_list *,
int bAllowFieldsInSecondaryTables,
131 int bAllowMismatchTypeOnFieldComparison,
132 swq_custom_func_registrar* poCustomFuncRegistrar,
134 swq_expr_node* Evaluate( swq_field_fetcher pfnFetcher,
136 swq_expr_node* Clone();
138 void ReplaceBetweenByGEAndLERecurse();
140 swq_node_type eNodeType = SNT_CONSTANT;
141 swq_field_type field_type = SWQ_INTEGER;
144 void PushSubExpression( swq_expr_node * );
145 void ReverseSubExpressions();
147 int nSubExprCount = 0;
148 swq_expr_node **papoSubExpr =
nullptr;
153 char *table_name =
nullptr;
158 double float_value = 0.0;
163 char *string_value =
nullptr;
172 swq_op_evaluator pfnEvaluator;
173 swq_op_checker pfnChecker;
176class swq_op_registrar {
178 static const swq_operation *GetOperator(
const char * );
179 static const swq_operation *GetOperator( swq_op eOperation );
182class swq_custom_func_registrar
185 virtual ~swq_custom_func_registrar() {}
186 virtual const swq_operation *GetOperator(
const char * ) = 0;
195class swq_field_list {
199 swq_field_type *types;
204 swq_table_def *table_defs;
207class swq_parse_context {
209 swq_parse_context() : nStartToken(0), pszInput(nullptr), pszNext(nullptr),
210 pszLastValid(nullptr), bAcceptCustomFuncs(FALSE),
211 poRoot(nullptr), poCurSelect(nullptr) {}
214 const char *pszInput;
216 const char *pszLastValid;
217 int bAcceptCustomFuncs;
219 swq_expr_node *poRoot;
221 swq_select *poCurSelect;
228int swqparse( swq_parse_context *context );
229int swqlex( swq_expr_node **ppNode, swq_parse_context *context );
230void swqerror( swq_parse_context *context,
const char *msg );
232int swq_identify_field(
const char* table_name,
233 const char *token, swq_field_list *field_list,
234 swq_field_type *this_type,
int *table_id );
236CPLErr swq_expr_compile(
const char *where_clause,
239 swq_field_type *field_types,
241 swq_custom_func_registrar* poCustomFuncRegistrar,
242 swq_expr_node **expr_root );
244CPLErr swq_expr_compile2(
const char *where_clause,
245 swq_field_list *field_list,
247 swq_custom_func_registrar* poCustomFuncRegistrar,
248 swq_expr_node **expr_root );
253int swq_test_like(
const char *input,
const char *pattern );
255swq_expr_node *SWQGeneralEvaluator( swq_expr_node *, swq_expr_node **);
256swq_field_type SWQGeneralChecker( swq_expr_node *node,
int bAllowMismatchTypeOnFieldComparison );
257swq_expr_node *SWQCastEvaluator( swq_expr_node *, swq_expr_node **);
258swq_field_type SWQCastChecker( swq_expr_node *node,
int bAllowMismatchTypeOnFieldComparison );
259const char* SWQFieldTypeToString( swq_field_type field_type );
263#define SWQP_ALLOW_UNDEFINED_COL_FUNCS 0x01
265#define SWQM_SUMMARY_RECORD 1
266#define SWQM_RECORDSET 2
267#define SWQM_DISTINCT_LIST 3
274 SWQCF_COUNT = SWQ_COUNT,
280 swq_col_func col_func;
286 swq_field_type field_type;
287 swq_field_type target_type;
302 swq_field_type eType;
304 Comparator() : bSortAsc(true), eType(SWQ_STRING) {}
311 std::vector<CPLString> oVectorDistinctValues{};
312 std::set<CPLString, Comparator> oSetDistinctValues{};
330 swq_expr_node *poExpr;
333class swq_select_parse_options
336 swq_custom_func_registrar* poCustomFuncRegistrar;
337 int bAllowFieldsInSecondaryTablesInWhere;
338 int bAddSecondaryTablesGeometryFields;
339 int bAlwaysPrefixWithTableName;
340 int bAllowDistinctOnGeometryField;
341 int bAllowDistinctOnMultipleFields;
343 swq_select_parse_options(): poCustomFuncRegistrar(nullptr),
344 bAllowFieldsInSecondaryTablesInWhere(FALSE),
345 bAddSecondaryTablesGeometryFields(FALSE),
346 bAlwaysPrefixWithTableName(FALSE),
347 bAllowDistinctOnGeometryField(FALSE),
348 bAllowDistinctOnMultipleFields(FALSE) {}
363 char *raw_select =
nullptr;
365 int PushField( swq_expr_node *poExpr,
const char *pszAlias=
nullptr,
366 int distinct_flag = FALSE );
367 int result_columns = 0;
368 swq_col_def *column_defs =
nullptr;
369 std::vector<swq_summary> column_summary{};
371 int PushTableDef(
const char *pszDataSource,
372 const char *pszTableName,
373 const char *pszAlias );
375 swq_table_def *table_defs =
nullptr;
377 void PushJoin(
int iSecondaryTable, swq_expr_node* poExpr );
379 swq_join_def *join_defs =
nullptr;
381 swq_expr_node *where_expr =
nullptr;
383 void PushOrderBy(
const char* pszTableName,
const char *pszFieldName,
int bAscending );
385 swq_order_def *order_defs =
nullptr;
387 void SetLimit(
GIntBig nLimit );
390 void SetOffset(
GIntBig nOffset );
393 swq_select *poOtherSelect =
nullptr;
394 void PushUnionAll( swq_select* poOtherSelectIn );
396 CPLErr preparse(
const char *select_statement,
397 int bAcceptCustomFuncs = FALSE );
398 CPLErr expand_wildcard( swq_field_list *field_list,
399 int bAlwaysPrefixWithTableName );
400 CPLErr parse( swq_field_list *field_list,
401 swq_select_parse_options* poParseOptions );
407CPLErr swq_select_parse( swq_select *select_info,
408 swq_field_list *field_list,
411const char *swq_select_summarize( swq_select *select_info,
415int swq_is_reserved_keyword(
const char* pszStr);
417char* OGRHStoreGetValue(
const char* pszHStore,
const char* pszSearchedKey);
Convenient string class based on std::string.
Definition: cpl_string.h:330
Abstract base class for all geometry classes.
Definition: ogr_geometry.h:287
Various convenience functions for CPL.
CPLErr
Error category.
Definition: cpl_error.h:53
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition: cpl_port.h:997
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition: cpl_port.h:248
Various convenience functions for working with strings and string lists.
Core portability services for cross-platform OGR code.
OGRFieldSubType
List of field subtypes.
Definition: ogr_core.h:623
OGRwkbGeometryType
List of well known binary geometry types.
Definition: ogr_core.h:318