swq.h

00001 /******************************************************************************
00002  *
00003  * Component: OGDI Driver Support Library
00004  * Purpose: Generic SQL WHERE Expression Evaluator Declarations.
00005  * Author: Frank Warmerdam <warmerdam@pobox.com>
00006  * 
00007  ******************************************************************************
00008  * Copyright (C) 2001 Information Interoperability Institute (3i)
00009  * Permission to use, copy, modify and distribute this software and
00010  * its documentation for any purpose and without fee is hereby granted,
00011  * provided that the above copyright notice appear in all copies, that
00012  * both the copyright notice and this permission notice appear in
00013  * supporting documentation, and that the name of 3i not be used 
00014  * in advertising or publicity pertaining to distribution of the software 
00015  * without specific, written prior permission.  3i makes no
00016  * representations about the suitability of this software for any purpose.
00017  * It is provided "as is" without express or implied warranty.
00018  ****************************************************************************/
00019 
00020 #ifndef _SWQ_H_INCLUDED_
00021 #define _SWQ_H_INCLUDED_
00022 
00023 typedef enum {
00024     SWQ_OR,
00025     SWQ_AND,
00026     SWQ_NOT,
00027     SWQ_EQ,
00028     SWQ_NE,
00029     SWQ_GE,
00030     SWQ_LE,
00031     SWQ_LT,
00032     SWQ_GT,
00033     SWQ_LIKE,
00034     SWQ_NOTLIKE,
00035     SWQ_ISNULL,
00036     SWQ_ISNOTNULL,
00037     SWQ_IN,
00038     SWQ_NOTIN,
00039     SWQ_UNKNOWN
00040 } swq_op;
00041 
00042 typedef enum {
00043     SWQ_INTEGER,
00044     SWQ_FLOAT,
00045     SWQ_STRING, 
00046     SWQ_BOOLEAN,
00047     SWQ_OTHER
00048 } swq_field_type;
00049 
00050 typedef struct {
00051     swq_op      operation;
00052 
00053     /* only for logical expression on subexpression */
00054     struct swq_node_s  *first_sub_expr;
00055     struct swq_node_s  *second_sub_expr;
00056 
00057     /* only for binary field operations */
00058     int         field_index;
00059     int         table_index;
00060     swq_field_type field_type;
00061     char        *string_value;
00062     int         int_value;
00063     double      float_value;
00064 } swq_field_op;
00065 
00066 typedef swq_field_op swq_expr;
00067 
00068 typedef int (*swq_op_evaluator)(swq_field_op *op, void *record_handle);
00069 
00070 typedef struct {
00071     char       *data_source;
00072     char       *table_name;
00073     char       *table_alias;
00074 } swq_table_def;
00075 
00076 typedef struct {
00077     int count;
00078     char **names;
00079     swq_field_type *types;
00080     int *table_ids;
00081     int *ids;
00082 
00083     int table_count;
00084     swq_table_def *table_defs;
00085 } swq_field_list;
00086 
00087 /* Compile an SQL WHERE clause into an internal form.  The field_list is
00088 ** the list of fields in the target 'table', used to render where into 
00089 ** field numbers instead of names. 
00090 */
00091 const char *swq_expr_compile( const char *where_clause, 
00092                               int field_count,
00093                               char **field_list,
00094                               swq_field_type *field_types,
00095                               swq_expr **expr );
00096 
00097 const char *swq_expr_compile2( const char *where_clause, 
00098                                swq_field_list *field_list, 
00099                                swq_expr **expr );
00100 
00101 /*
00102 ** Evaluate an expression for a particular record using an application
00103 ** provided field operation evaluator, and abstract record handle. 
00104 */
00105 int swq_expr_evaluate( swq_expr *expr, swq_op_evaluator fn_evaluator,
00106                        void *record_handle );
00107 
00108 void swq_expr_free( swq_expr * );
00109 
00110 int swq_test_like( const char *input, const char *pattern );
00111 
00112 
00113 /****************************************************************************/
00114 
00115 #define SWQP_ALLOW_UNDEFINED_COL_FUNCS 0x01
00116 
00117 #define SWQM_SUMMARY_RECORD  1
00118 #define SWQM_RECORDSET       2
00119 #define SWQM_DISTINCT_LIST   3
00120 
00121 typedef enum {
00122     SWQCF_NONE,
00123     SWQCF_AVG,
00124     SWQCF_MIN,
00125     SWQCF_MAX,
00126     SWQCF_COUNT,
00127     SWQCF_SUM,
00128     SWQCF_CUSTOM
00129 } swq_col_func;
00130 
00131 typedef struct {
00132     swq_col_func col_func;
00133     char         *col_func_name;
00134     char         *field_name;
00135     int          table_index;
00136     int          field_index;
00137     swq_field_type field_type;
00138     int          distinct_flag;
00139 } swq_col_def;
00140 
00141 typedef struct {
00142     int         count;
00143     
00144     char        **distinct_list;
00145     double      sum;
00146     double      min;
00147     double      max;
00148 } swq_summary;
00149 
00150 typedef struct {
00151     char *field_name;
00152     int   table_index;
00153     int   field_index;
00154     int   ascending_flag;
00155 } swq_order_def;
00156 
00157 typedef struct {
00158     int        secondary_table;
00159 
00160     char      *primary_field_name;
00161     int        primary_field;
00162 
00163     swq_op     op;
00164 
00165     char      *secondary_field_name;
00166     int        secondary_field;
00167 } swq_join_def;
00168 
00169 typedef struct {
00170     int         query_mode;
00171 
00172     char        *raw_select;
00173 
00174     int         result_columns;
00175     swq_col_def *column_defs;
00176     swq_summary *column_summary;
00177 
00178     int         table_count;
00179     swq_table_def *table_defs;
00180 
00181     int         join_count;
00182     swq_join_def *join_defs;
00183 
00184     char        *whole_where_clause;
00185     swq_expr    *where_expr;
00186 
00187     int         order_specs;
00188     swq_order_def *order_defs;    
00189 } swq_select;
00190 
00191 const char *swq_select_preparse( const char *select_statement, 
00192                                  swq_select **select_info );
00193 const char *swq_select_expand_wildcard( swq_select *select_info,
00194                                         swq_field_list *field_list );
00195 const char *swq_select_parse( swq_select *select_info,
00196                               swq_field_list *field_list,
00197                               int parse_flags );
00198 void swq_select_free( swq_select *select_info );
00199 
00200 const char *swq_reform_command( swq_select *select_info );
00201 void swq_free( void * );
00202 void *swq_malloc( int );
00203 
00204 const char *swq_select_finish_summarize( swq_select *select_info );
00205 const char *swq_select_summarize( swq_select *select_info, 
00206                                   int dest_column, 
00207                                   const char *value );
00208 
00209 
00210 #endif /* def _SWQ_H_INCLUDED_ */

Generated for GDAL by doxygen 1.4.7.