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 {
113 explicit swq_expr_node(
const char * );
114 explicit swq_expr_node(
int );
115 explicit swq_expr_node(
GIntBig );
116 explicit swq_expr_node(
double );
118 explicit swq_expr_node( swq_op );
123 void MarkAsTimestamp();
124 CPLString UnparseOperationFromUnparsedSubExpr(
char** apszSubExpr);
125 char *Unparse( swq_field_list *,
char chColumnQuote );
126 void Dump( FILE *fp,
int depth );
127 swq_field_type Check( swq_field_list *,
int bAllowFieldsInSecondaryTables,
128 int bAllowMismatchTypeOnFieldComparison,
129 swq_custom_func_registrar* poCustomFuncRegistrar );
130 swq_expr_node* Evaluate( swq_field_fetcher pfnFetcher,
132 swq_expr_node* Clone();
134 void ReplaceBetweenByGEAndLERecurse();
136 swq_node_type eNodeType;
137 swq_field_type field_type;
140 void PushSubExpression( swq_expr_node * );
141 void ReverseSubExpressions();
144 swq_expr_node **papoSubExpr;
168 swq_op_evaluator pfnEvaluator;
169 swq_op_checker pfnChecker;
172 class swq_op_registrar {
174 static const swq_operation *GetOperator(
const char * );
175 static const swq_operation *GetOperator( swq_op eOperation );
178 class swq_custom_func_registrar
181 virtual ~swq_custom_func_registrar() {}
182 virtual const swq_operation *GetOperator(
const char * ) = 0;
191 class swq_field_list {
195 swq_field_type *types;
200 swq_table_def *table_defs;
203 class swq_parse_context {
205 swq_parse_context() : nStartToken(0), pszInput(NULL), pszNext(NULL),
206 pszLastValid(NULL), bAcceptCustomFuncs(FALSE),
207 poRoot(NULL), poCurSelect(NULL) {}
210 const char *pszInput;
212 const char *pszLastValid;
213 int bAcceptCustomFuncs;
215 swq_expr_node *poRoot;
217 swq_select *poCurSelect;
224 int swqparse( swq_parse_context *context );
225 int swqlex( swq_expr_node **ppNode, swq_parse_context *context );
226 void swqerror( swq_parse_context *context,
const char *msg );
228 int swq_identify_field(
const char* table_name,
229 const char *token, swq_field_list *field_list,
230 swq_field_type *this_type,
int *table_id );
232 CPLErr swq_expr_compile(
const char *where_clause,
235 swq_field_type *field_types,
237 swq_custom_func_registrar* poCustomFuncRegistrar,
238 swq_expr_node **expr_root );
240 CPLErr swq_expr_compile2(
const char *where_clause,
241 swq_field_list *field_list,
243 swq_custom_func_registrar* poCustomFuncRegistrar,
244 swq_expr_node **expr_root );
249 int swq_test_like(
const char *input,
const char *pattern );
251 swq_expr_node *SWQGeneralEvaluator( swq_expr_node *, swq_expr_node **);
252 swq_field_type SWQGeneralChecker( swq_expr_node *node,
int bAllowMismatchTypeOnFieldComparison );
253 swq_expr_node *SWQCastEvaluator( swq_expr_node *, swq_expr_node **);
254 swq_field_type SWQCastChecker( swq_expr_node *node,
int bAllowMismatchTypeOnFieldComparison );
255 const char* SWQFieldTypeToString( swq_field_type field_type );
259 #define SWQP_ALLOW_UNDEFINED_COL_FUNCS 0x01
261 #define SWQM_SUMMARY_RECORD 1
262 #define SWQM_RECORDSET 2
263 #define SWQM_DISTINCT_LIST 3
270 SWQCF_COUNT = SWQ_COUNT,
276 swq_col_func col_func;
282 swq_field_type field_type;
283 swq_field_type target_type;
298 swq_field_type eType;
300 Comparator() : bSortAsc(true), eType(SWQ_STRING) {}
307 std::vector<CPLString> oVectorDistinctValues;
308 std::set<CPLString, Comparator> oSetDistinctValues;
315 swq_summary() : count(0), sum(0.0), min(0.0), max(0.0) {}
328 swq_expr_node *poExpr;
331 class swq_select_parse_options
334 swq_custom_func_registrar* poCustomFuncRegistrar;
335 int bAllowFieldsInSecondaryTablesInWhere;
336 int bAddSecondaryTablesGeometryFields;
337 int bAlwaysPrefixWithTableName;
338 int bAllowDistinctOnGeometryField;
339 int bAllowDistinctOnMultipleFields;
341 swq_select_parse_options(): poCustomFuncRegistrar(NULL),
342 bAllowFieldsInSecondaryTablesInWhere(FALSE),
343 bAddSecondaryTablesGeometryFields(FALSE),
344 bAlwaysPrefixWithTableName(FALSE),
345 bAllowDistinctOnGeometryField(FALSE),
346 bAllowDistinctOnMultipleFields(FALSE) {}
361 int PushField( swq_expr_node *poExpr,
const char *pszAlias=NULL,
362 int distinct_flag = FALSE );
364 swq_col_def *column_defs;
365 std::vector<swq_summary> column_summary;
367 int PushTableDef(
const char *pszDataSource,
368 const char *pszTableName,
369 const char *pszAlias );
371 swq_table_def *table_defs;
373 void PushJoin(
int iSecondaryTable, swq_expr_node* poExpr );
375 swq_join_def *join_defs;
377 swq_expr_node *where_expr;
379 void PushOrderBy(
const char* pszTableName,
const char *pszFieldName,
int bAscending );
381 swq_order_def *order_defs;
383 void SetLimit(
GIntBig nLimit );
386 void SetOffset(
GIntBig nOffset );
389 swq_select *poOtherSelect;
390 void PushUnionAll( swq_select* poOtherSelectIn );
392 CPLErr preparse(
const char *select_statement,
393 int bAcceptCustomFuncs = FALSE );
394 CPLErr expand_wildcard( swq_field_list *field_list,
395 int bAlwaysPrefixWithTableName );
396 CPLErr parse( swq_field_list *field_list,
397 swq_select_parse_options* poParseOptions );
403 CPLErr swq_select_parse( swq_select *select_info,
404 swq_field_list *field_list,
407 const char *swq_select_summarize( swq_select *select_info,
411 int swq_is_reserved_keyword(
const char* pszStr);
413 char* OGRHStoreGetValue(
const char* pszHStore,
const char* pszSearchedKey);
OGRFieldSubType
Definition: ogr_core.h:612
Convenient string class based on std::string.
Definition: cpl_string.h:338
OGRwkbGeometryType
Definition: ogr_core.h:312
Definition: ogr_geometry.h:118
long long GIntBig
Definition: cpl_port.h:250
CPLErr
Definition: cpl_error.h:52