/home/dcp1990/prog/fakedbfs/include/fakedbfs/query.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2005, Dan Ponte
00003  *
00004  * query.h - query opcodes and such
00005  * 
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 4. Neither the name of the University nor the names of its contributors
00015  *    may be used to endorse or promote products derived from this software
00016  *    without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
00019  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
00022  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00023  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00024  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00025  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00026  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00027  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00028  * SUCH DAMAGE.
00029  */
00030 /* $Amigan: fakedbfs/include/fakedbfs/query.h,v 1.19 2006/04/19 19:58:22 dcp1990 Exp $ */
00031 #ifndef HAVE_QUERY_H
00032 #define HAVE_QUERY_H 1
00033 #ifndef HAVE_DBSPECDATA_H
00034 #include <fakedbfs/dbspecdata.h>
00035 #endif
00036 #include <fakedbfs/fdbfsregex.h>
00037 
00038 /* See doc/QUERY_OPCODES for how these are used */
00039 #define OP_BEGINQ       0x1
00040 #define OP_SETCAT       0x2
00041 #define OP_BEGIN_GRP    0x3
00042 #define OP_CLOSE_GRP    0x4
00043 #define OPL_AND         0x5
00044 #define OPL_OR          0x6
00045 #define OPL_NOT         0x7
00046 #define OPL_EQUAL       0x8
00047 #define OP_COLNAME      0x9
00048 #define OP_STRING       0xA
00049 #define OP_INT          0xB
00050 #define OP_UINT         0xC
00051 #define OP_VOID         0xD
00052 #define OP_FLOAT        0xE
00053 #define OP_PUSH         0xF
00054 #define OP_POP          0x10
00055 #define OP_ENDQ         0x11
00056 #define OP_SELCN        0x12
00057 #define OP_REGEXP       0x13
00058 #define OP_NULL         0x14
00059 #define OPL_NEQU        0x15
00060 #define OPL_GTHAN       0x16
00061 #define OPL_LTHAN       0x17
00062 #define OPL_GTHEQU      0x18
00063 #define OPL_LTHEQU      0x19
00064 #define OP_NOTREGEXP    0x1A
00065 
00066 #define USED_O1         0x1
00067 #define USED_O2         0x2
00068 #define USED_O3         0x4
00069 #define US_DYNA         0x8 /* free free(3) o3 if set */
00070 #define US_FILE         0xF /* mmap or whatever */
00071 
00072 #define Q_FINISHED 0x1
00073 #define Q_NEXT 0x2
00074 #define Q_INST_AFTER_END 0x3
00075 #define Q_UNBALANCED_GROUP 0x4
00076 #define Q_INVALID_O1 0x5
00077 #define Q_INVALID_O2 0x6
00078 #define Q_INVALID_O3 0x7
00079 #define Q_STEP_ON_UNINIT 0x8
00080 #define Q_MISSING_OPERAND 0x9
00081 #define Q_CATALOGUE_NOT_SET 0xA
00082 #define Q_OPERATION_WITHOUT_OPERANDS 0xB
00083 #define Q_DOUBLE_OPERAND 0xC
00084 #define Q_FDBFS_ERROR 0xD /* check q->f->error.emsg */
00085 #define Q_NO_COLUMNS 0xE
00086 #define Q_NO_SUCH_CAT 0xF
00087 #define Q_NO_SUCH_CELEM 0x10
00088 #define Q_STACK_FULL 0x11
00089 #define Q_UNKNOWNSTATE 0xFF
00090 
00091 typedef struct {
00092         int o1;
00093         unsigned int o2;
00094         void *o3;
00095         int used;
00096 } operands_t;
00097 
00098 typedef struct Inst {
00099         int opcode;
00100         operands_t ops;
00101         struct Inst *next;
00102         struct Inst *last;
00103 } inst_t;
00104 
00105 typedef struct Result {
00106         struct Field *fld;
00107         struct Result *next; /* for your convenience; none of libfakedbfs' functions use this */
00108 } result_t;
00109 
00110 enum estate {
00111         init = 0, /* not started yet */
00112         more, /* more rows waiting */
00113         finished /* done; reset state and set to init */
00114 };
00115 
00116 typedef struct {
00117         operands_t *stackbase, *top, *csp;
00118         size_t stacksize; /* int number of elements, not bytes */
00119         size_t items;
00120         fdbfs_t *f;
00121         inst_t *insthead;
00122         inst_t *lastinst;
00123         short int error;
00124         char *yytext;
00125         /* state info */
00126         short int allcols;
00127         char *catalogue;
00128         enum estate exec_state;
00129         sqlite3_stmt *cst;
00130         struct CatalogueHead *ourcat; /* our paticular one */
00131         struct CatalogueHead *cath;
00132         struct EnumHead *enumh;
00133 } query_t;
00134 
00135 typedef struct {
00136         freg_t *re;
00137         char *colname;
00138         char *tregex;
00139 } qreg_t;
00140 
00149 query_t* fdbfs_query_new(fdbfs_t *f, size_t stacksize);
00150 
00156 void fdbfs_query_destroy(query_t *q);
00157 
00170 int fdbfs_query_qi(query_t *q, int opcode, int op1, unsigned int op2, void *op3, int used);
00171 
00182 int fdbfs_query_qne(query_t *q);
00183 
00192 int fdbfs_query_step(query_t *q);
00193 
00201 int fdbfs_query_init_exec(query_t *q);
00202 
00203 
00220 int fdbfs_query_spush(query_t *q, int o1, unsigned int o2, void *o3, int used);
00221 
00230 int fdbfs_query_spop(query_t *q, operands_t *bf);
00231 
00240 int fdbfs_query_pop1(query_t *q, int *o1);
00241 
00250 int fdbfs_query_pop2(query_t *q, unsigned int *o2);
00251 
00261 int fdbfs_query_pop3(query_t *q, void **o3);
00262 
00270 int fdbfs_query_push1(query_t *q, int o1);
00271 
00279 int fdbfs_query_push2(query_t *q, unsigned int o2);
00280 
00288 int fdbfs_query_push3(query_t *q, void *o3); /* we could use macros for push*(), but oh well */
00289 
00298 qreg_t* fdbfs_qreg_compile(const char *regex, int case_insens, char **errmsg);
00299 
00305 void fdbfs_qreg_destroy(qreg_t *q);
00306 
00316 void* fdbfs_query_read_file(fdbfs_t *f, const char *fn);
00317 
00327 int fdbfs_query_parse(query_t *q, const char *qstr);
00328 
00338 int fdbfs_query_qtok(char **cp, int *tval, Toke *toke, char *ctok /* MUST be a buffer at least 512b long */);
00339 
00343 void fdbfs_db_regex_func(sqlite3_context *ctx, int i, sqlite3_value **sqval);
00344 
00351 const char* fdbfs_query_error(int rc);
00352 
00353 #endif

Generated on Wed Apr 19 16:26:23 2006 for fakedbfs by  doxygen 1.4.6