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  * $Log: swq.h,v $
00021  * Revision 1.8  2003/03/05 05:08:28  warmerda
00022  * added preliminary support for joins
00023  *
00024  * Revision 1.7  2002/04/29 19:32:47  warmerda
00025  * added swq_select_parse, fix problem with where parsing and sorting code
00026  *
00027  * Revision 1.6  2002/04/25 19:32:06  warmerda
00028  * added swq_select_reform_command
00029  *
00030  * Revision 1.5  2002/04/25 16:06:57  warmerda
00031  * added more general distinct support
00032  *
00033  * Revision 1.4  2002/04/23 20:05:23  warmerda
00034  * added SELECT statement parsing
00035  *
00036  * Revision 1.3  2002/04/19 20:46:06  warmerda
00037  * added [NOT] IN, [NOT] LIKE and IS [NOT] NULL support
00038  *
00039  * Revision 1.2  2001/07/19 18:25:07  warmerda
00040  * expanded tabs
00041  *
00042  * Revision 1.1  2001/06/19 15:46:30  warmerda
00043  * New
00044  *
00045  */
00046 
00047 #ifndef _SWQ_H_INCLUDED_
00048 #define _SWQ_H_INCLUDED_
00049 
00050 typedef enum {
00051     SWQ_OR,
00052     SWQ_AND,
00053     SWQ_NOT,
00054     SWQ_EQ,
00055     SWQ_NE,
00056     SWQ_GE,
00057     SWQ_LE,
00058     SWQ_LT,
00059     SWQ_GT,
00060     SWQ_LIKE,
00061     SWQ_NOTLIKE,
00062     SWQ_ISNULL,
00063     SWQ_ISNOTNULL,
00064     SWQ_IN,
00065     SWQ_NOTIN,
00066     SWQ_UNKNOWN
00067 } swq_op;
00068 
00069 typedef enum {
00070     SWQ_INTEGER,
00071     SWQ_FLOAT,
00072     SWQ_STRING, 
00073     SWQ_BOOLEAN,
00074     SWQ_OTHER
00075 } swq_field_type;
00076 
00077 typedef struct {
00078     swq_op      operation;
00079 
00080     /* only for logical expression on subexpression */
00081     struct swq_node_s  *first_sub_expr;
00082     struct swq_node_s  *second_sub_expr;
00083 
00084     /* only for binary field operations */
00085     int         field_index;
00086     int         table_index;
00087     swq_field_type field_type;
00088     char        *string_value;
00089     int         int_value;
00090     double      float_value;
00091 } swq_field_op;
00092 
00093 typedef swq_field_op swq_expr;
00094 
00095 typedef int (*swq_op_evaluator)(swq_field_op *op, void *record_handle);
00096 
00097 typedef struct {
00098     char       *data_source;
00099     char       *table_name;
00100     char       *table_alias;
00101 } swq_table_def;
00102 
00103 typedef struct {
00104     int count;
00105     char **names;
00106     swq_field_type *types;
00107     int *table_ids;
00108     int *ids;
00109 
00110     int table_count;
00111     swq_table_def *table_defs;
00112 } swq_field_list;
00113 
00114 /* Compile an SQL WHERE clause into an internal form.  The field_list is
00115 ** the list of fields in the target 'table', used to render where into 
00116 ** field numbers instead of names. 
00117 */
00118 const char *swq_expr_compile( const char *where_clause, 
00119                               int field_count,
00120                               char **field_list,
00121                               swq_field_type *field_types,
00122                               swq_expr **expr );
00123 
00124 const char *swq_expr_compile2( const char *where_clause, 
00125                                swq_field_list *field_list, 
00126                                swq_expr **expr );
00127 
00128 /*
00129 ** Evaluate an expression for a particular record using an application
00130 ** provided field operation evaluator, and abstract record handle. 
00131 */
00132 int swq_expr_evaluate( swq_expr *expr, swq_op_evaluator fn_evaluator,
00133                        void *record_handle );
00134 
00135 void swq_expr_free( swq_expr * );
00136 
00137 int swq_test_like( const char *input, const char *pattern );
00138 
00139 
00140 /****************************************************************************/
00141 
00142 #define SWQP_ALLOW_UNDEFINED_COL_FUNCS 0x01
00143 
00144 #define SWQM_SUMMARY_RECORD  1
00145 #define SWQM_RECORDSET       2
00146 #define SWQM_DISTINCT_LIST   3
00147 
00148 typedef enum {
00149     SWQCF_NONE,
00150     SWQCF_AVG,
00151     SWQCF_MIN,
00152     SWQCF_MAX,
00153     SWQCF_COUNT,
00154     SWQCF_SUM,
00155     SWQCF_CUSTOM
00156 } swq_col_func;
00157 
00158 typedef struct {
00159     swq_col_func col_func;
00160     char         *col_func_name;
00161     char         *field_name;
00162     int          table_index;
00163     int          field_index;
00164     swq_field_type field_type;
00165     int          distinct_flag;
00166 } swq_col_def;
00167 
00168 typedef struct {
00169     int         count;
00170     
00171     char        **distinct_list;
00172     double      sum;
00173     double      min;
00174     double      max;
00175 } swq_summary;
00176 
00177 typedef struct {
00178     char *field_name;
00179     int   table_index;
00180     int   field_index;
00181     int   ascending_flag;
00182 } swq_order_def;
00183 
00184 typedef struct {
00185     int        secondary_table;
00186 
00187     char      *primary_field_name;
00188     int        primary_field;
00189 
00190     swq_op     op;
00191 
00192     char      *secondary_field_name;
00193     int        secondary_field;
00194 } swq_join_def;
00195 
00196 typedef struct {
00197     int         query_mode;
00198 
00199     char        *raw_select;
00200 
00201     int         result_columns;
00202     swq_col_def *column_defs;
00203     swq_summary *column_summary;
00204 
00205     int         table_count;
00206     swq_table_def *table_defs;
00207 
00208     int         join_count;
00209     swq_join_def *join_defs;
00210 
00211     char        *whole_where_clause;
00212     swq_expr    *where_expr;
00213 
00214     int         order_specs;
00215     swq_order_def *order_defs;    
00216 } swq_select;
00217 
00218 const char *swq_select_preparse( const char *select_statement, 
00219                                  swq_select **select_info );
00220 const char *swq_select_expand_wildcard( swq_select *select_info,
00221                                         swq_field_list *field_list );
00222 const char *swq_select_parse( swq_select *select_info,
00223                               swq_field_list *field_list,
00224                               int parse_flags );
00225 void swq_select_free( swq_select *select_info );
00226 
00227 const char *swq_reform_command( swq_select *select_info );
00228 void swq_free( void * );
00229 void *swq_malloc( int );
00230 
00231 const char *swq_select_finish_summarize( swq_select *select_info );
00232 const char *swq_select_summarize( swq_select *select_info, 
00233                                   int dest_column, 
00234                                   const char *value );
00235 
00236 
00237 #endif /* def _SWQ_H_INCLUDED_ */

Generated on Mon Jan 9 18:03:31 2006 for OGR by  doxygen 1.4.6