21#ifndef SWQ_H_INCLUDED_
22#define SWQ_H_INCLUDED_
35#if defined(_WIN32) && !defined(strcasecmp)
36#define strcasecmp stricmp
40#define SZ_OGR_NULL "__OGR_NULL__"
93#define SWQ_IS_INTEGER(x) ((x) == SWQ_INTEGER || (x) == SWQ_INTEGER64)
107struct CPL_UNSTABLE_API swq_evaluation_context
109 bool bUTF8Strings =
false;
112typedef swq_expr_node *(*swq_field_fetcher)(swq_expr_node *op,
113 void *record_handle);
114typedef swq_expr_node *(*swq_op_evaluator)(
115 swq_expr_node *op, swq_expr_node **sub_field_values,
116 const swq_evaluation_context &sContext);
117typedef swq_field_type (*swq_op_checker)(
118 swq_expr_node *op,
int bAllowMismatchTypeOnFieldComparison);
120class swq_custom_func_registrar;
122class CPL_UNSTABLE_API swq_expr_node
124 swq_expr_node *Evaluate(swq_field_fetcher pfnFetcher,
void *record,
125 const swq_evaluation_context &sContext,
131 swq_expr_node(
const swq_expr_node &);
132 swq_expr_node(swq_expr_node &&);
134 swq_expr_node &operator=(
const swq_expr_node &);
135 swq_expr_node &operator=(swq_expr_node &&);
137 bool operator==(
const swq_expr_node &)
const;
139 explicit swq_expr_node(
const char *);
140 explicit swq_expr_node(
int);
141 explicit swq_expr_node(
GIntBig);
142 explicit swq_expr_node(
double);
144 explicit swq_expr_node(swq_op);
148 void MarkAsTimestamp();
149 CPLString UnparseOperationFromUnparsedSubExpr(
char **apszSubExpr);
150 char *Unparse(swq_field_list *,
char chColumnQuote);
151 void Dump(FILE *fp,
int depth);
152 swq_field_type Check(swq_field_list *,
int bAllowFieldsInSecondaryTables,
153 int bAllowMismatchTypeOnFieldComparison,
154 swq_custom_func_registrar *poCustomFuncRegistrar,
156 swq_expr_node *Evaluate(swq_field_fetcher pfnFetcher,
void *record,
157 const swq_evaluation_context &sContext);
158 swq_expr_node *Clone();
160 void ReplaceBetweenByGEAndLERecurse();
161 void PushNotOperationDownToStack();
163 swq_node_type eNodeType = SNT_CONSTANT;
164 swq_field_type field_type = SWQ_INTEGER;
167 void PushSubExpression(swq_expr_node *);
168 void ReverseSubExpressions();
169 swq_op nOperation = SWQ_OR;
170 int nSubExprCount = 0;
171 swq_expr_node **papoSubExpr =
nullptr;
176 char *table_name =
nullptr;
181 double float_value = 0.0;
187 char *string_value =
nullptr;
197 swq_op_evaluator pfnEvaluator;
198 swq_op_checker pfnChecker;
201class CPL_UNSTABLE_API swq_op_registrar
204 static const swq_operation *GetOperator(
const char *);
205 static const swq_operation *GetOperator(swq_op eOperation);
208class CPL_UNSTABLE_API swq_custom_func_registrar
211 virtual ~swq_custom_func_registrar()
215 virtual const swq_operation *GetOperator(
const char *) = 0;
225class CPL_UNSTABLE_API swq_field_list
230 swq_field_type *types;
235 swq_table_def *table_defs;
238class CPL_UNSTABLE_API swq_parse_context
242 : nStartToken(0), pszInput(nullptr), pszNext(nullptr),
243 pszLastValid(nullptr), bAcceptCustomFuncs(FALSE), poRoot(nullptr),
249 const char *pszInput;
251 const char *pszLastValid;
252 int bAcceptCustomFuncs;
254 swq_expr_node *poRoot;
256 swq_select *poCurSelect;
263int CPL_UNSTABLE_API swqparse(swq_parse_context *context);
264int CPL_UNSTABLE_API swqlex(swq_expr_node **ppNode, swq_parse_context *context);
265void CPL_UNSTABLE_API swqerror(swq_parse_context *context,
const char *msg);
267int CPL_UNSTABLE_API swq_identify_field(
const char *table_name,
269 swq_field_list *field_list,
270 swq_field_type *this_type,
274swq_expr_compile(
const char *where_clause,
int field_count,
char **field_list,
275 swq_field_type *field_types,
int bCheck,
276 swq_custom_func_registrar *poCustomFuncRegistrar,
277 swq_expr_node **expr_root);
280swq_expr_compile2(
const char *where_clause, swq_field_list *field_list,
281 int bCheck, swq_custom_func_registrar *poCustomFuncRegistrar,
282 swq_expr_node **expr_root);
287int CPL_UNSTABLE_API swq_test_like(
const char *input,
const char *pattern);
289swq_expr_node CPL_UNSTABLE_API *
290SWQGeneralEvaluator(swq_expr_node *, swq_expr_node **,
291 const swq_evaluation_context &sContext);
292swq_field_type CPL_UNSTABLE_API
293SWQGeneralChecker(swq_expr_node *node,
int bAllowMismatchTypeOnFieldComparison);
294swq_expr_node CPL_UNSTABLE_API *
295SWQCastEvaluator(swq_expr_node *, swq_expr_node **,
296 const swq_evaluation_context &sContext);
297swq_field_type CPL_UNSTABLE_API
298SWQCastChecker(swq_expr_node *node,
int bAllowMismatchTypeOnFieldComparison);
299const char CPL_UNSTABLE_API *SWQFieldTypeToString(swq_field_type field_type);
303#define SWQP_ALLOW_UNDEFINED_COL_FUNCS 0x01
305#define SWQM_SUMMARY_RECORD 1
306#define SWQM_RECORDSET 2
307#define SWQM_DISTINCT_LIST 3
315 SWQCF_COUNT = SWQ_COUNT,
322 swq_col_func col_func;
328 swq_field_type field_type;
329 swq_field_type target_type;
339class CPL_UNSTABLE_API swq_summary
345 swq_field_type eType;
347 Comparator() : bSortAsc(true), eType(SWQ_STRING)
356 std::vector<CPLString> oVectorDistinctValues{};
357 std::set<CPLString, Comparator> oSetDistinctValues{};
377 swq_expr_node *poExpr;
380class CPL_UNSTABLE_API swq_select_parse_options
383 swq_custom_func_registrar *poCustomFuncRegistrar;
384 int bAllowFieldsInSecondaryTablesInWhere;
385 int bAddSecondaryTablesGeometryFields;
386 int bAlwaysPrefixWithTableName;
387 int bAllowDistinctOnGeometryField;
388 int bAllowDistinctOnMultipleFields;
390 swq_select_parse_options()
391 : poCustomFuncRegistrar(nullptr),
392 bAllowFieldsInSecondaryTablesInWhere(FALSE),
393 bAddSecondaryTablesGeometryFields(FALSE),
394 bAlwaysPrefixWithTableName(FALSE),
395 bAllowDistinctOnGeometryField(FALSE),
396 bAllowDistinctOnMultipleFields(FALSE)
401class CPL_UNSTABLE_API swq_select
413 char *raw_select =
nullptr;
415 int PushField(swq_expr_node *poExpr,
const char *pszAlias =
nullptr,
416 int distinct_flag = FALSE);
418 int PushExcludeField(swq_expr_node *poExpr);
420 int result_columns()
const
422 return static_cast<int>(column_defs.size());
425 std::vector<swq_col_def> column_defs{};
426 std::vector<swq_summary> column_summary{};
428 int PushTableDef(
const char *pszDataSource,
const char *pszTableName,
429 const char *pszAlias);
431 swq_table_def *table_defs =
nullptr;
433 void PushJoin(
int iSecondaryTable, swq_expr_node *poExpr);
435 swq_join_def *join_defs =
nullptr;
437 swq_expr_node *where_expr =
nullptr;
439 void PushOrderBy(
const char *pszTableName,
const char *pszFieldName,
442 swq_order_def *order_defs =
nullptr;
447 void SetOffset(
GIntBig nOffset);
450 swq_select *poOtherSelect =
nullptr;
451 void PushUnionAll(swq_select *poOtherSelectIn);
453 CPLErr preparse(
const char *select_statement,
454 int bAcceptCustomFuncs = FALSE);
455 CPLErr expand_wildcard(swq_field_list *field_list,
456 int bAlwaysPrefixWithTableName);
457 CPLErr parse(swq_field_list *field_list,
458 swq_select_parse_options *poParseOptions);
462 bool bExcludedGeometry =
false;
465 bool IsFieldExcluded(
int src_index,
const char *table,
const char *field);
471 std::map<int, std::list<swq_col_def>> m_exclude_fields{};
474const char CPL_UNSTABLE_API *swq_select_summarize(swq_select *select_info,
478int CPL_UNSTABLE_API swq_is_reserved_keyword(
const char *pszStr);
480char CPL_UNSTABLE_API *OGRHStoreGetValue(
const char *pszHStore,
481 const char *pszSearchedKey);
483#ifdef GDAL_COMPILATION
484void swq_fixup(swq_parse_context *psParseContext);
485swq_expr_node *swq_create_and_or_or(swq_op op, swq_expr_node *left,
486 swq_expr_node *right);
487int swq_test_like(
const char *input,
const char *pattern,
char chEscape,
488 bool insensitive,
bool bUTF8Strings);
Convenient string class based on std::string.
Definition cpl_string.h:320
Abstract base class for all geometry classes.
Definition ogr_geometry.h:377
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:1042
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition cpl_port.h:215
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:821
OGRwkbGeometryType
List of well known binary geometry types.
Definition ogr_core.h:416