00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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
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
00070 #define US_FILE 0xF
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
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;
00108 } result_t;
00109
00110 enum estate {
00111 init = 0,
00112 more,
00113 finished
00114 };
00115
00116 typedef struct {
00117 operands_t *stackbase, *top, *csp;
00118 size_t stacksize;
00119 size_t items;
00120 fdbfs_t *f;
00121 inst_t *insthead;
00122 inst_t *lastinst;
00123 short int error;
00124 char *yytext;
00125
00126 short int allcols;
00127 char *catalogue;
00128 enum estate exec_state;
00129 sqlite3_stmt *cst;
00130 struct CatalogueHead *ourcat;
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);
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 );
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