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__"
91#define SWQ_IS_INTEGER(x) ((x) == SWQ_INTEGER || (x) == SWQ_INTEGER64)
105typedef swq_expr_node *(*swq_field_fetcher)(swq_expr_node *op,
106 void *record_handle);
107typedef swq_expr_node *(*swq_op_evaluator)(swq_expr_node *op,
108 swq_expr_node **sub_field_values);
109typedef swq_field_type (*swq_op_checker)(
110 swq_expr_node *op,
int bAllowMismatchTypeOnFieldComparison);
112class swq_custom_func_registrar;
114class CPL_UNSTABLE_API swq_expr_node
118 swq_expr_node *Evaluate(swq_field_fetcher pfnFetcher,
void *record,
124 explicit swq_expr_node(
const char *);
125 explicit swq_expr_node(
int);
126 explicit swq_expr_node(
GIntBig);
127 explicit swq_expr_node(
double);
129 explicit swq_expr_node(swq_op);
133 void MarkAsTimestamp();
134 CPLString UnparseOperationFromUnparsedSubExpr(
char **apszSubExpr);
135 char *Unparse(swq_field_list *,
char chColumnQuote);
136 void Dump(FILE *fp,
int depth);
137 swq_field_type Check(swq_field_list *,
int bAllowFieldsInSecondaryTables,
138 int bAllowMismatchTypeOnFieldComparison,
139 swq_custom_func_registrar *poCustomFuncRegistrar,
141 swq_expr_node *Evaluate(swq_field_fetcher pfnFetcher,
void *record);
142 swq_expr_node *Clone();
144 void ReplaceBetweenByGEAndLERecurse();
146 swq_node_type eNodeType = SNT_CONSTANT;
147 swq_field_type field_type = SWQ_INTEGER;
150 void PushSubExpression(swq_expr_node *);
151 void ReverseSubExpressions();
152 swq_op nOperation = SWQ_OR;
153 int nSubExprCount = 0;
154 swq_expr_node **papoSubExpr =
nullptr;
159 char *table_name =
nullptr;
164 double float_value = 0.0;
170 char *string_value =
nullptr;
180 swq_op_evaluator pfnEvaluator;
181 swq_op_checker pfnChecker;
184class CPL_UNSTABLE_API swq_op_registrar
187 static const swq_operation *GetOperator(
const char *);
188 static const swq_operation *GetOperator(swq_op eOperation);
191class CPL_UNSTABLE_API swq_custom_func_registrar
194 virtual ~swq_custom_func_registrar()
197 virtual const swq_operation *GetOperator(
const char *) = 0;
207class CPL_UNSTABLE_API swq_field_list
212 swq_field_type *types;
217 swq_table_def *table_defs;
220class CPL_UNSTABLE_API swq_parse_context
224 : nStartToken(0), pszInput(nullptr), pszNext(nullptr),
225 pszLastValid(nullptr), bAcceptCustomFuncs(FALSE), poRoot(nullptr),
231 const char *pszInput;
233 const char *pszLastValid;
234 int bAcceptCustomFuncs;
236 swq_expr_node *poRoot;
238 swq_select *poCurSelect;
245int CPL_UNSTABLE_API swqparse(swq_parse_context *context);
246int CPL_UNSTABLE_API swqlex(swq_expr_node **ppNode, swq_parse_context *context);
247void CPL_UNSTABLE_API swqerror(swq_parse_context *context,
const char *msg);
249int CPL_UNSTABLE_API swq_identify_field(
const char *table_name,
251 swq_field_list *field_list,
252 swq_field_type *this_type,
256swq_expr_compile(
const char *where_clause,
int field_count,
char **field_list,
257 swq_field_type *field_types,
int bCheck,
258 swq_custom_func_registrar *poCustomFuncRegistrar,
259 swq_expr_node **expr_root);
262swq_expr_compile2(
const char *where_clause, swq_field_list *field_list,
263 int bCheck, swq_custom_func_registrar *poCustomFuncRegistrar,
264 swq_expr_node **expr_root);
269int CPL_UNSTABLE_API swq_test_like(
const char *input,
const char *pattern);
271swq_expr_node CPL_UNSTABLE_API *SWQGeneralEvaluator(swq_expr_node *,
273swq_field_type CPL_UNSTABLE_API
274SWQGeneralChecker(swq_expr_node *node,
int bAllowMismatchTypeOnFieldComparison);
275swq_expr_node CPL_UNSTABLE_API *SWQCastEvaluator(swq_expr_node *,
277swq_field_type CPL_UNSTABLE_API
278SWQCastChecker(swq_expr_node *node,
int bAllowMismatchTypeOnFieldComparison);
279const char CPL_UNSTABLE_API *SWQFieldTypeToString(swq_field_type field_type);
283#define SWQP_ALLOW_UNDEFINED_COL_FUNCS 0x01
285#define SWQM_SUMMARY_RECORD 1
286#define SWQM_RECORDSET 2
287#define SWQM_DISTINCT_LIST 3
295 SWQCF_COUNT = SWQ_COUNT,
302 swq_col_func col_func;
308 swq_field_type field_type;
309 swq_field_type target_type;
319class CPL_UNSTABLE_API swq_summary
325 swq_field_type eType;
327 Comparator() : bSortAsc(true), eType(SWQ_STRING)
336 std::vector<CPLString> oVectorDistinctValues{};
337 std::set<CPLString, Comparator> oSetDistinctValues{};
357 swq_expr_node *poExpr;
360class CPL_UNSTABLE_API swq_select_parse_options
363 swq_custom_func_registrar *poCustomFuncRegistrar;
364 int bAllowFieldsInSecondaryTablesInWhere;
365 int bAddSecondaryTablesGeometryFields;
366 int bAlwaysPrefixWithTableName;
367 int bAllowDistinctOnGeometryField;
368 int bAllowDistinctOnMultipleFields;
370 swq_select_parse_options()
371 : poCustomFuncRegistrar(nullptr),
372 bAllowFieldsInSecondaryTablesInWhere(FALSE),
373 bAddSecondaryTablesGeometryFields(FALSE),
374 bAlwaysPrefixWithTableName(FALSE),
375 bAllowDistinctOnGeometryField(FALSE),
376 bAllowDistinctOnMultipleFields(FALSE)
381class CPL_UNSTABLE_API swq_select
393 char *raw_select =
nullptr;
395 int PushField(swq_expr_node *poExpr,
const char *pszAlias =
nullptr,
396 int distinct_flag = FALSE);
397 int result_columns = 0;
398 swq_col_def *column_defs =
nullptr;
399 std::vector<swq_summary> column_summary{};
401 int PushTableDef(
const char *pszDataSource,
const char *pszTableName,
402 const char *pszAlias);
404 swq_table_def *table_defs =
nullptr;
406 void PushJoin(
int iSecondaryTable, swq_expr_node *poExpr);
408 swq_join_def *join_defs =
nullptr;
410 swq_expr_node *where_expr =
nullptr;
412 void PushOrderBy(
const char *pszTableName,
const char *pszFieldName,
415 swq_order_def *order_defs =
nullptr;
420 void SetOffset(
GIntBig nOffset);
423 swq_select *poOtherSelect =
nullptr;
424 void PushUnionAll(swq_select *poOtherSelectIn);
426 CPLErr preparse(
const char *select_statement,
427 int bAcceptCustomFuncs = FALSE);
428 CPLErr expand_wildcard(swq_field_list *field_list,
429 int bAlwaysPrefixWithTableName);
430 CPLErr parse(swq_field_list *field_list,
431 swq_select_parse_options *poParseOptions);
437CPLErr CPL_UNSTABLE_API swq_select_parse(swq_select *select_info,
438 swq_field_list *field_list,
441const char CPL_UNSTABLE_API *swq_select_summarize(swq_select *select_info,
445int CPL_UNSTABLE_API swq_is_reserved_keyword(
const char *pszStr);
447char CPL_UNSTABLE_API *OGRHStoreGetValue(
const char *pszHStore,
448 const char *pszSearchedKey);
450#ifdef GDAL_COMPILATION
451void swq_fixup(swq_parse_context *psParseContext);
452swq_expr_node *swq_create_and_or_or(swq_op op, swq_expr_node *left,
453 swq_expr_node *right);
Convenient string class based on std::string.
Definition cpl_string.h:312
Abstract base class for all geometry classes.
Definition ogr_geometry.h:335
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:1049
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition cpl_port.h:233
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:800
OGRwkbGeometryType
List of well known binary geometry types.
Definition ogr_core.h:407