- Main Page
- Classes
- Files
- Directories
- Related Pages

- File List
- File Members

# 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_DATE,
    00048     SWQ_TIME,
    00049     SWQ_TIMESTAMP,
    00050     SWQ_OTHER
    00051 } swq_field_type;
    00052
    00053 typedef struct {
    00054     swq_op      operation;
    00055
    00056     /* only for logical expression on subexpression */
    00057     struct swq_node_s  *first_sub_expr;
    00058     struct swq_node_s  *second_sub_expr;
    00059
    00060     /* only for binary field operations */
    00061     int         field_index;
    00062     int         table_index;
    00063     swq_field_type field_type;
    00064     char        *string_value;
    00065     int         int_value;
    00066     double      float_value;
    00067 } swq_field_op;
    00068
    00069 typedef swq_field_op swq_expr;
    00070
    00071 typedef int (*swq_op_evaluator)(swq_field_op *op, void *record_handle);
    00072
    00073 typedef struct {
    00074     char       *data_source;
    00075     char       *table_name;
    00076     char       *table_alias;
    00077 } swq_table_def;
    00078
    00079 typedef struct {
    00080     int count;
    00081     char **names;
    00082     swq_field_type *types;
    00083     int *table_ids;
    00084     int *ids;
    00085
    00086     int table_count;
    00087     swq_table_def *table_defs;
    00088 } swq_field_list;
    00089
    00090 /* Compile an SQL WHERE clause into an internal form.  The field_list is
    00091 ** the list of fields in the target 'table', used to render where into
    00092 ** field numbers instead of names.
    00093 */
    00094 const char *swq_expr_compile( const char *where_clause,
    00095                               int field_count,
    00096                               char **field_list,
    00097                               swq_field_type *field_types,
    00098                               swq_expr **expr );
    00099
    00100 const char *swq_expr_compile2( const char *where_clause,
    00101                                swq_field_list *field_list,
    00102                                swq_expr **expr );
    00103
    00104 /*
    00105 ** Evaluate an expression for a particular record using an application
    00106 ** provided field operation evaluator, and abstract record handle.
    00107 */
    00108 int swq_expr_evaluate( swq_expr *expr, swq_op_evaluator fn_evaluator,
    00109                        void *record_handle );
    00110
    00111 void swq_expr_free( swq_expr * );
    00112
    00113 int swq_test_like( const char *input, const char *pattern );
    00114
    00115
    00116 /****************************************************************************/
    00117
    00118 #define SWQP_ALLOW_UNDEFINED_COL_FUNCS 0x01
    00119
    00120 #define SWQM_SUMMARY_RECORD  1
    00121 #define SWQM_RECORDSET       2
    00122 #define SWQM_DISTINCT_LIST   3
    00123
    00124 typedef enum {
    00125     SWQCF_NONE,
    00126     SWQCF_AVG,
    00127     SWQCF_MIN,
    00128     SWQCF_MAX,
    00129     SWQCF_COUNT,
    00130     SWQCF_SUM,
    00131     SWQCF_CUSTOM
    00132 } swq_col_func;
    00133
    00134 typedef struct {
    00135     swq_col_func col_func;
    00136     char         *col_func_name;
    00137     char         *field_name;
    00138         char         *field_alias;
    00139     int          table_index;
    00140     int          field_index;
    00141     swq_field_type field_type;
    00142     swq_field_type target_type;
    00143     int          field_length;
    00144     int          field_precision;
    00145     int          distinct_flag;
    00146 } swq_col_def;
    00147
    00148 typedef struct {
    00149     int         count;
    00150
    00151     char        **distinct_list;
    00152     double      sum;
    00153     double      min;
    00154     double      max;
    00155 } swq_summary;
    00156
    00157 typedef struct {
    00158     char *field_name;
    00159     int   table_index;
    00160     int   field_index;
    00161     int   ascending_flag;
    00162 } swq_order_def;
    00163
    00164 typedef struct {
    00165     int        secondary_table;
    00166
    00167     char      *primary_field_name;
    00168     int        primary_field;
    00169
    00170     swq_op     op;
    00171
    00172     char      *secondary_field_name;
    00173     int        secondary_field;
    00174 } swq_join_def;
    00175
    00176 typedef struct {
    00177     int         query_mode;
    00178
    00179     char        *raw_select;
    00180
    00181     int         result_columns;
    00182     swq_col_def *column_defs;
    00183     swq_summary *column_summary;
    00184
    00185     int         table_count;
    00186     swq_table_def *table_defs;
    00187
    00188     int         join_count;
    00189     swq_join_def *join_defs;
    00190
    00191     char        *whole_where_clause;
    00192     swq_expr    *where_expr;
    00193
    00194     int         order_specs;
    00195     swq_order_def *order_defs;
    00196 } swq_select;
    00197
    00198 const char *swq_select_preparse( const char *select_statement,
    00199                                  swq_select **select_info );
    00200 const char *swq_select_expand_wildcard( swq_select *select_info,
    00201                                         swq_field_list *field_list );
    00202 const char *swq_select_parse( swq_select *select_info,
    00203                               swq_field_list *field_list,
    00204                               int parse_flags );
    00205 void swq_select_free( swq_select *select_info );
    00206
    00207 const char *swq_reform_command( swq_select *select_info );
    00208 void swq_free( void * );
    00209 void *swq_malloc( int );
    00210
    00211 const char *swq_select_finish_summarize( swq_select *select_info );
    00212 const char *swq_select_summarize( swq_select *select_info,
    00213                                   int dest_column,
    00214                                   const char *value );
    00215
    00216
    00217 #endif /* def _SWQ_H_INCLUDED_ */

Generated for GDAL by 1.5.1.