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__"
88 #define SWQ_IS_INTEGER(x) ((x) == SWQ_INTEGER || (x) == SWQ_INTEGER64)
101 typedef swq_expr_node *(*swq_field_fetcher)( swq_expr_node *op,
102 void *record_handle );
103 typedef swq_expr_node *(*swq_op_evaluator)(swq_expr_node *op,
104 swq_expr_node **sub_field_values );
105 typedef swq_field_type (*swq_op_checker)( swq_expr_node *op,
106 int bAllowMismatchTypeOnFieldComparison );
108 class swq_custom_func_registrar;
110 class CPL_UNSTABLE_API swq_expr_node {
113 swq_expr_node* Evaluate( swq_field_fetcher pfnFetcher,
114 void *record,
int nRecLevel );
118 explicit swq_expr_node(
const char * );
119 explicit swq_expr_node(
int );
120 explicit swq_expr_node(
GIntBig );
121 explicit swq_expr_node(
double );
123 explicit swq_expr_node( swq_op );
127 void MarkAsTimestamp();
128 CPLString UnparseOperationFromUnparsedSubExpr(
char** apszSubExpr);
129 char *Unparse( swq_field_list *,
char chColumnQuote );
130 void Dump( FILE *fp,
int depth );
131 swq_field_type Check( swq_field_list *,
int bAllowFieldsInSecondaryTables,
132 int bAllowMismatchTypeOnFieldComparison,
133 swq_custom_func_registrar* poCustomFuncRegistrar,
135 swq_expr_node* Evaluate( swq_field_fetcher pfnFetcher,
137 swq_expr_node* Clone();
139 void ReplaceBetweenByGEAndLERecurse();
141 swq_node_type eNodeType = SNT_CONSTANT;
142 swq_field_type field_type = SWQ_INTEGER;
145 void PushSubExpression( swq_expr_node * );
146 void ReverseSubExpressions();
147 swq_op nOperation = SWQ_OR;
148 int nSubExprCount = 0;
149 swq_expr_node **papoSubExpr =
nullptr;
154 char *table_name =
nullptr;
159 double float_value = 0.0;
164 char *string_value =
nullptr;
173 swq_op_evaluator pfnEvaluator;
174 swq_op_checker pfnChecker;
177 class CPL_UNSTABLE_API swq_op_registrar {
179 static const swq_operation *GetOperator(
const char * );
180 static const swq_operation *GetOperator( swq_op eOperation );
183 class CPL_UNSTABLE_API swq_custom_func_registrar
186 virtual ~swq_custom_func_registrar() {}
187 virtual const swq_operation *GetOperator(
const char * ) = 0;
196 class CPL_UNSTABLE_API swq_field_list {
200 swq_field_type *types;
205 swq_table_def *table_defs;
208 class CPL_UNSTABLE_API swq_parse_context {
210 swq_parse_context() : nStartToken(0), pszInput(nullptr), pszNext(nullptr),
211 pszLastValid(nullptr), bAcceptCustomFuncs(FALSE),
212 poRoot(nullptr), poCurSelect(nullptr) {}
215 const char *pszInput;
217 const char *pszLastValid;
218 int bAcceptCustomFuncs;
220 swq_expr_node *poRoot;
222 swq_select *poCurSelect;
229 int CPL_UNSTABLE_API swqparse( swq_parse_context *context );
230 int CPL_UNSTABLE_API swqlex( swq_expr_node **ppNode, swq_parse_context *context );
231 void CPL_UNSTABLE_API swqerror( swq_parse_context *context,
const char *msg );
233 int CPL_UNSTABLE_API swq_identify_field(
const char* table_name,
234 const char *token, swq_field_list *field_list,
235 swq_field_type *this_type,
int *table_id );
237 CPLErr CPL_UNSTABLE_API swq_expr_compile(
const char *where_clause,
240 swq_field_type *field_types,
242 swq_custom_func_registrar* poCustomFuncRegistrar,
243 swq_expr_node **expr_root );
245 CPLErr CPL_UNSTABLE_API swq_expr_compile2(
const char *where_clause,
246 swq_field_list *field_list,
248 swq_custom_func_registrar* poCustomFuncRegistrar,
249 swq_expr_node **expr_root );
254 int CPL_UNSTABLE_API swq_test_like(
const char *input,
const char *pattern );
256 swq_expr_node CPL_UNSTABLE_API *SWQGeneralEvaluator( swq_expr_node *, swq_expr_node **);
257 swq_field_type CPL_UNSTABLE_API SWQGeneralChecker( swq_expr_node *node,
int bAllowMismatchTypeOnFieldComparison );
258 swq_expr_node CPL_UNSTABLE_API *SWQCastEvaluator( swq_expr_node *, swq_expr_node **);
259 swq_field_type CPL_UNSTABLE_API SWQCastChecker( swq_expr_node *node,
int bAllowMismatchTypeOnFieldComparison );
260 const char CPL_UNSTABLE_API *SWQFieldTypeToString( swq_field_type field_type );
264 #define SWQP_ALLOW_UNDEFINED_COL_FUNCS 0x01
266 #define SWQM_SUMMARY_RECORD 1
267 #define SWQM_RECORDSET 2
268 #define SWQM_DISTINCT_LIST 3
275 SWQCF_COUNT = SWQ_COUNT,
281 swq_col_func col_func;
287 swq_field_type field_type;
288 swq_field_type target_type;
298 class CPL_UNSTABLE_API swq_summary {
303 swq_field_type eType;
305 Comparator() : bSortAsc(true), eType(SWQ_STRING) {}
312 std::vector<CPLString> oVectorDistinctValues{};
313 std::set<CPLString, Comparator> oSetDistinctValues{};
331 swq_expr_node *poExpr;
334 class CPL_UNSTABLE_API swq_select_parse_options
337 swq_custom_func_registrar* poCustomFuncRegistrar;
338 int bAllowFieldsInSecondaryTablesInWhere;
339 int bAddSecondaryTablesGeometryFields;
340 int bAlwaysPrefixWithTableName;
341 int bAllowDistinctOnGeometryField;
342 int bAllowDistinctOnMultipleFields;
344 swq_select_parse_options(): poCustomFuncRegistrar(nullptr),
345 bAllowFieldsInSecondaryTablesInWhere(FALSE),
346 bAddSecondaryTablesGeometryFields(FALSE),
347 bAlwaysPrefixWithTableName(FALSE),
348 bAllowDistinctOnGeometryField(FALSE),
349 bAllowDistinctOnMultipleFields(FALSE) {}
352 class CPL_UNSTABLE_API swq_select
364 char *raw_select =
nullptr;
366 int PushField( swq_expr_node *poExpr,
const char *pszAlias=
nullptr,
367 int distinct_flag = FALSE );
368 int result_columns = 0;
369 swq_col_def *column_defs =
nullptr;
370 std::vector<swq_summary> column_summary{};
372 int PushTableDef(
const char *pszDataSource,
373 const char *pszTableName,
374 const char *pszAlias );
376 swq_table_def *table_defs =
nullptr;
378 void PushJoin(
int iSecondaryTable, swq_expr_node* poExpr );
380 swq_join_def *join_defs =
nullptr;
382 swq_expr_node *where_expr =
nullptr;
384 void PushOrderBy(
const char* pszTableName,
const char *pszFieldName,
int bAscending );
386 swq_order_def *order_defs =
nullptr;
388 void SetLimit(
GIntBig nLimit );
391 void SetOffset(
GIntBig nOffset );
394 swq_select *poOtherSelect =
nullptr;
395 void PushUnionAll( swq_select* poOtherSelectIn );
397 CPLErr preparse(
const char *select_statement,
398 int bAcceptCustomFuncs = FALSE );
399 CPLErr expand_wildcard( swq_field_list *field_list,
400 int bAlwaysPrefixWithTableName );
401 CPLErr parse( swq_field_list *field_list,
402 swq_select_parse_options* poParseOptions );
408 CPLErr CPL_UNSTABLE_API swq_select_parse( swq_select *select_info,
409 swq_field_list *field_list,
412 const char CPL_UNSTABLE_API *swq_select_summarize( swq_select *select_info,
416 int CPL_UNSTABLE_API swq_is_reserved_keyword(
const char* pszStr);
418 char CPL_UNSTABLE_API *OGRHStoreGetValue(
const char* pszHStore,
419 const char* pszSearchedKey);
421 #ifdef GDAL_COMPILATION
422 void swq_fixup(swq_parse_context* psParseContext);
423 swq_expr_node* swq_create_and_or_or(swq_op op, swq_expr_node* left, swq_expr_node* right);
Convenient string class based on std::string.
Definition: cpl_string.h:333
Abstract base class for all geometry classes.
Definition: ogr_geometry.h:327
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:955
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition: cpl_port.h:244
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:674
OGRwkbGeometryType
List of well known binary geometry types.
Definition: ogr_core.h:346