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) 100 typedef swq_expr_node *(*swq_field_fetcher)( swq_expr_node *op,
101 void *record_handle );
102 typedef swq_expr_node *(*swq_op_evaluator)(swq_expr_node *op,
103 swq_expr_node **sub_field_values );
104 typedef swq_field_type (*swq_op_checker)( swq_expr_node *op,
105 int bAllowMismatchTypeOnFieldComparison );
107 class swq_custom_func_registrar;
109 class swq_expr_node {
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 );
133 swq_expr_node* Evaluate( swq_field_fetcher pfnFetcher,
135 swq_expr_node* Clone();
137 void ReplaceBetweenByGEAndLERecurse();
139 swq_node_type eNodeType = SNT_CONSTANT;
140 swq_field_type field_type = SWQ_INTEGER;
143 void PushSubExpression( swq_expr_node * );
144 void ReverseSubExpressions();
146 int nSubExprCount = 0;
147 swq_expr_node **papoSubExpr =
nullptr;
152 char *table_name =
nullptr;
157 double float_value = 0.0;
162 char *string_value =
nullptr;
171 swq_op_evaluator pfnEvaluator;
172 swq_op_checker pfnChecker;
175 class swq_op_registrar {
177 static const swq_operation *GetOperator(
const char * );
178 static const swq_operation *GetOperator( swq_op eOperation );
181 class swq_custom_func_registrar
184 virtual ~swq_custom_func_registrar() {}
185 virtual const swq_operation *GetOperator(
const char * ) = 0;
194 class swq_field_list {
198 swq_field_type *types;
203 swq_table_def *table_defs;
206 class swq_parse_context {
208 swq_parse_context() : nStartToken(0), pszInput(nullptr), pszNext(nullptr),
209 pszLastValid(nullptr), bAcceptCustomFuncs(FALSE),
210 poRoot(nullptr), poCurSelect(nullptr) {}
213 const char *pszInput;
215 const char *pszLastValid;
216 int bAcceptCustomFuncs;
218 swq_expr_node *poRoot;
220 swq_select *poCurSelect;
227 int swqparse( swq_parse_context *context );
228 int swqlex( swq_expr_node **ppNode, swq_parse_context *context );
229 void swqerror( swq_parse_context *context,
const char *msg );
231 int swq_identify_field(
const char* table_name,
232 const char *token, swq_field_list *field_list,
233 swq_field_type *this_type,
int *table_id );
235 CPLErr swq_expr_compile(
const char *where_clause,
238 swq_field_type *field_types,
240 swq_custom_func_registrar* poCustomFuncRegistrar,
241 swq_expr_node **expr_root );
243 CPLErr swq_expr_compile2(
const char *where_clause,
244 swq_field_list *field_list,
246 swq_custom_func_registrar* poCustomFuncRegistrar,
247 swq_expr_node **expr_root );
252 int swq_test_like(
const char *input,
const char *pattern );
254 swq_expr_node *SWQGeneralEvaluator( swq_expr_node *, swq_expr_node **);
255 swq_field_type SWQGeneralChecker( swq_expr_node *node,
int bAllowMismatchTypeOnFieldComparison );
256 swq_expr_node *SWQCastEvaluator( swq_expr_node *, swq_expr_node **);
257 swq_field_type SWQCastChecker( swq_expr_node *node,
int bAllowMismatchTypeOnFieldComparison );
258 const char* SWQFieldTypeToString( swq_field_type field_type );
262 #define SWQP_ALLOW_UNDEFINED_COL_FUNCS 0x01 264 #define SWQM_SUMMARY_RECORD 1 265 #define SWQM_RECORDSET 2 266 #define SWQM_DISTINCT_LIST 3 273 SWQCF_COUNT = SWQ_COUNT,
279 swq_col_func col_func;
285 swq_field_type field_type;
286 swq_field_type target_type;
301 swq_field_type eType;
303 Comparator() : bSortAsc(true), eType(SWQ_STRING) {}
310 std::vector<CPLString> oVectorDistinctValues{};
311 std::set<CPLString, Comparator> oSetDistinctValues{};
329 swq_expr_node *poExpr;
332 class swq_select_parse_options
335 swq_custom_func_registrar* poCustomFuncRegistrar;
336 int bAllowFieldsInSecondaryTablesInWhere;
337 int bAddSecondaryTablesGeometryFields;
338 int bAlwaysPrefixWithTableName;
339 int bAllowDistinctOnGeometryField;
340 int bAllowDistinctOnMultipleFields;
342 swq_select_parse_options(): poCustomFuncRegistrar(nullptr),
343 bAllowFieldsInSecondaryTablesInWhere(FALSE),
344 bAddSecondaryTablesGeometryFields(FALSE),
345 bAlwaysPrefixWithTableName(FALSE),
346 bAllowDistinctOnGeometryField(FALSE),
347 bAllowDistinctOnMultipleFields(FALSE) {}
362 char *raw_select =
nullptr;
364 int PushField( swq_expr_node *poExpr,
const char *pszAlias=
nullptr,
365 int distinct_flag = FALSE );
366 int result_columns = 0;
367 swq_col_def *column_defs =
nullptr;
368 std::vector<swq_summary> column_summary{};
370 int PushTableDef(
const char *pszDataSource,
371 const char *pszTableName,
372 const char *pszAlias );
374 swq_table_def *table_defs =
nullptr;
376 void PushJoin(
int iSecondaryTable, swq_expr_node* poExpr );
378 swq_join_def *join_defs =
nullptr;
380 swq_expr_node *where_expr =
nullptr;
382 void PushOrderBy(
const char* pszTableName,
const char *pszFieldName,
int bAscending );
384 swq_order_def *order_defs =
nullptr;
386 void SetLimit(
GIntBig nLimit );
389 void SetOffset(
GIntBig nOffset );
392 swq_select *poOtherSelect =
nullptr;
393 void PushUnionAll( swq_select* poOtherSelectIn );
395 CPLErr preparse(
const char *select_statement,
396 int bAcceptCustomFuncs = FALSE );
397 CPLErr expand_wildcard( swq_field_list *field_list,
398 int bAlwaysPrefixWithTableName );
399 CPLErr parse( swq_field_list *field_list,
400 swq_select_parse_options* poParseOptions );
406 CPLErr swq_select_parse( swq_select *select_info,
407 swq_field_list *field_list,
410 const char *swq_select_summarize( swq_select *select_info,
414 int swq_is_reserved_keyword(
const char* pszStr);
416 char* OGRHStoreGetValue(
const char* pszHStore,
const char* pszSearchedKey);
OGRFieldSubType
List of field subtypes.
Definition: ogr_core.h:622
Convenient string class based on std::string.
Definition: cpl_string.h:329
Various convenience functions for working with strings and string lists.
OGRwkbGeometryType
List of well known binary geometry types.
Definition: ogr_core.h:317
Abstract base class for all geometry classes.
Definition: ogr_geometry.h:286
Core portability services for cross-platform OGR code.
Various convenience functions for CPL.
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition: cpl_port.h:248
CPLErr
Error category.
Definition: cpl_error.h:52
#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:989