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

#include <fakedbfs/dbspecdata.h>
#include <fakedbfs/fdbfsregex.h>

Go to the source code of this file.

Classes

struct  operands_t
struct  Inst
struct  Result
struct  query_t
struct  qreg_t

Defines

#define HAVE_QUERY_H   1
#define OP_BEGINQ   0x1
#define OP_SETCAT   0x2
#define OP_BEGIN_GRP   0x3
#define OP_CLOSE_GRP   0x4
#define OPL_AND   0x5
#define OPL_OR   0x6
#define OPL_NOT   0x7
#define OPL_EQUAL   0x8
#define OP_COLNAME   0x9
#define OP_STRING   0xA
#define OP_INT   0xB
#define OP_UINT   0xC
#define OP_VOID   0xD
#define OP_FLOAT   0xE
#define OP_PUSH   0xF
#define OP_POP   0x10
#define OP_ENDQ   0x11
#define OP_SELCN   0x12
#define OP_REGEXP   0x13
#define OP_NULL   0x14
#define OPL_NEQU   0x15
#define OPL_GTHAN   0x16
#define OPL_LTHAN   0x17
#define OPL_GTHEQU   0x18
#define OPL_LTHEQU   0x19
#define OP_NOTREGEXP   0x1A
#define USED_O1   0x1
#define USED_O2   0x2
#define USED_O3   0x4
#define US_DYNA   0x8
#define US_FILE   0xF
#define Q_FINISHED   0x1
#define Q_NEXT   0x2
#define Q_INST_AFTER_END   0x3
#define Q_UNBALANCED_GROUP   0x4
#define Q_INVALID_O1   0x5
#define Q_INVALID_O2   0x6
#define Q_INVALID_O3   0x7
#define Q_STEP_ON_UNINIT   0x8
#define Q_MISSING_OPERAND   0x9
#define Q_CATALOGUE_NOT_SET   0xA
#define Q_OPERATION_WITHOUT_OPERANDS   0xB
#define Q_DOUBLE_OPERAND   0xC
#define Q_FDBFS_ERROR   0xD
#define Q_NO_COLUMNS   0xE
#define Q_NO_SUCH_CAT   0xF
#define Q_NO_SUCH_CELEM   0x10
#define Q_STACK_FULL   0x11
#define Q_UNKNOWNSTATE   0xFF

Typedefs

typedef Inst inst_t
typedef Result result_t

Enumerations

enum  estate { init = 0, more, finished }

Functions

query_tfdbfs_query_new (fdbfs_t *f, size_t stacksize)
 Create new query object.
void fdbfs_query_destroy (query_t *q)
 Destroy query.
int fdbfs_query_qi (query_t *q, int opcode, int op1, unsigned int op2, void *op3, int used)
 Queue instruction.
int fdbfs_query_qne (query_t *q)
 Query next or execute.
int fdbfs_query_step (query_t *q)
 Step currently-running query.
int fdbfs_query_init_exec (query_t *q)
 Initialise and execute a query.
int fdbfs_query_spush (query_t *q, int o1, unsigned int o2, void *o3, int used)
 Push a cell to the query stack.
int fdbfs_query_spop (query_t *q, operands_t *bf)
 Pop cell off stack.
int fdbfs_query_pop1 (query_t *q, int *o1)
 Pop O1.
int fdbfs_query_pop2 (query_t *q, unsigned int *o2)
 Pop O2.
int fdbfs_query_pop3 (query_t *q, void **o3)
 Pop O3.
int fdbfs_query_push1 (query_t *q, int o1)
 Push O1.
int fdbfs_query_push2 (query_t *q, unsigned int o2)
 Push O2.
int fdbfs_query_push3 (query_t *q, void *o3)
 Push O3.
qreg_tfdbfs_qreg_compile (const char *regex, int case_insens, char **errmsg)
 Create and compile new qreg object.
void fdbfs_qreg_destroy (qreg_t *q)
 Destroy qreg object.
void * fdbfs_query_read_file (fdbfs_t *f, const char *fn)
 Read file.
int fdbfs_query_parse (query_t *q, const char *qstr)
 Parse a query.
int fdbfs_query_qtok (char **cp, int *tval, Toke *toke, char *ctok)
 Tokeinse query.
void fdbfs_db_regex_func (sqlite3_context *ctx, int i, sqlite3_value **sqval)
 SQLite regex func. For internal use only.
const char * fdbfs_query_error (int rc)
 Get description for error code.


Define Documentation

#define HAVE_QUERY_H   1
 

#define OP_BEGIN_GRP   0x3
 

#define OP_BEGINQ   0x1
 

#define OP_CLOSE_GRP   0x4
 

#define OP_COLNAME   0x9
 

#define OP_ENDQ   0x11
 

#define OP_FLOAT   0xE
 

#define OP_INT   0xB
 

#define OP_NOTREGEXP   0x1A
 

#define OP_NULL   0x14
 

#define OP_POP   0x10
 

#define OP_PUSH   0xF
 

#define OP_REGEXP   0x13
 

#define OP_SELCN   0x12
 

#define OP_SETCAT   0x2
 

#define OP_STRING   0xA
 

#define OP_UINT   0xC
 

#define OP_VOID   0xD
 

#define OPL_AND   0x5
 

#define OPL_EQUAL   0x8
 

#define OPL_GTHAN   0x16
 

#define OPL_GTHEQU   0x18
 

#define OPL_LTHAN   0x17
 

#define OPL_LTHEQU   0x19
 

#define OPL_NEQU   0x15
 

#define OPL_NOT   0x7
 

#define OPL_OR   0x6
 

#define Q_CATALOGUE_NOT_SET   0xA
 

#define Q_DOUBLE_OPERAND   0xC
 

#define Q_FDBFS_ERROR   0xD
 

#define Q_FINISHED   0x1
 

#define Q_INST_AFTER_END   0x3
 

#define Q_INVALID_O1   0x5
 

#define Q_INVALID_O2   0x6
 

#define Q_INVALID_O3   0x7
 

#define Q_MISSING_OPERAND   0x9
 

#define Q_NEXT   0x2
 

#define Q_NO_COLUMNS   0xE
 

#define Q_NO_SUCH_CAT   0xF
 

#define Q_NO_SUCH_CELEM   0x10
 

#define Q_OPERATION_WITHOUT_OPERANDS   0xB
 

#define Q_STACK_FULL   0x11
 

#define Q_STEP_ON_UNINIT   0x8
 

#define Q_UNBALANCED_GROUP   0x4
 

#define Q_UNKNOWNSTATE   0xFF
 

#define US_DYNA   0x8
 

#define US_FILE   0xF
 

#define USED_O1   0x1
 

#define USED_O2   0x2
 

#define USED_O3   0x4
 


Typedef Documentation

typedef struct Inst inst_t
 

typedef struct Result result_t
 


Enumeration Type Documentation

enum estate
 

Enumerator:
init 
more 
finished 


Function Documentation

void fdbfs_db_regex_func sqlite3_context *  ctx,
int  i,
sqlite3_value **  sqval
 

SQLite regex func. For internal use only.

qreg_t* fdbfs_qreg_compile const char *  regex,
int  case_insens,
char **  errmsg
 

Create and compile new qreg object.

Parameters:
regex Regex to compile.
case_insens 1 if case-insensitive matching will occur, 0 otherwise.
[out] errmsg Set to error message on error; must free().
Returns:
New qreg object, NULL on error.

void fdbfs_qreg_destroy qreg_t q  ) 
 

Destroy qreg object.

Parameters:
q qreg to destroy.

void fdbfs_query_destroy query_t q  ) 
 

Destroy query.

Parameters:
q Query to destroy.

const char* fdbfs_query_error int  rc  ) 
 

Get description for error code.

Parameters:
rc The error code from the various VM control functions.
Returns:
A human-readable string containing the error message.

int fdbfs_query_init_exec query_t q  ) 
 

Initialise and execute a query.

This must be called before the query can be stepped. This also steps the query once.

Parameters:
q Query to initialise and execute.
Returns:
Various.

query_t* fdbfs_query_new fdbfs_t f,
size_t  stacksize
 

Create new query object.

Creates a new query object with the specified stacksize.

Parameters:
f Instance of fakedbfs to link to.
stacksize If non-zero, number of elements to allocate for stack. Otherwise, DEFAULT_STACK_SIZE.
Returns:
New query object, or NULL on error.

int fdbfs_query_parse query_t q,
const char *  qstr
 

Parse a query.

Converts a query (as defined by the query grammar) into a usable instruction list for the VM. Applications usually call this directly.

Parameters:
q Query to operate on.
qstr String to parse.
Returns:
0 on error.

int fdbfs_query_pop1 query_t q,
int *  o1
 

Pop O1.

Parameters:
q Query to operate on.
[out] o1 Place to store O1.
Return values:
1 Normal.
0 Stack underflow.

int fdbfs_query_pop2 query_t q,
unsigned int *  o2
 

Pop O2.

Parameters:
q Query to operate on.
[out] o2 Place to store O2.
Return values:
1 Normal.
0 Stack underflow.

int fdbfs_query_pop3 query_t q,
void **  o3
 

Pop O3.

Parameters:
q Query to operate on.
[out] o3 Place to store O3.
Return values:
1 Normal.
0 Stack underflow.
US_DYNA Free the data, please (free(o3)).

int fdbfs_query_push1 query_t q,
int  o1
 

Push O1.

Parameters:
q Query to operate on.
o1 Data to push.
Returns:
Same as fdbfs_query_spush().

int fdbfs_query_push2 query_t q,
unsigned int  o2
 

Push O2.

Parameters:
q Query to operate on.
o2 Data to push.
Returns:
Same as fdbfs_query_spush().

int fdbfs_query_push3 query_t q,
void *  o3
 

Push O3.

Parameters:
q Query to operate on.
o3 Data to push.
Returns:
Same as fdbfs_query_spush().

int fdbfs_query_qi query_t q,
int  opcode,
int  op1,
unsigned int  op2,
void *  op3,
int  used
 

Queue instruction.

fdbfs_query_qi() queues an instruction of the specified opcode and operands into the query object for later execution by the VM.

Parameters:
q Query to operate on.
opcode Opcode of the instruction.
op1 O1 of the instruction.
op2 O2 of the instruction.
op3 O3 of the instruction.
used Used flags.
Returns:
Non-zero on success.

int fdbfs_query_qne query_t q  ) 
 

Query next or execute.

This is cleaner than calling fdbfs_query_init_exec() or fdbfs_query_step(). It decides what needs to be done based on the execution state of the query. Use it.

Parameters:
q Query to control.
Return values:
Q_FINISHED Query finished executing; reset before running again.
Q_UNKNOWNSTATE Something is royally fucked up. The VM is in a hopeless state of confusion.
Returns:
Same as fdbfs_query_init_exec() and fdbfs_query_step().

int fdbfs_query_qtok char **  cp,
int *  tval,
Toke toke,
char *  ctok
 

Tokeinse query.

Parameters:
[in,out] cp Pointer to string. Next token will be set here each call.
[out] tval Value of current token.
[out] toke Token data.
[out] ctok Buffer for current token...must point to a buffer of at least 512 bytes.
Returns:
0 on error.

void* fdbfs_query_read_file fdbfs_t f,
const char *  fn
 

Read file.

Read the specified file and return a pointer to (usually mmaped) data in it. This isn't really used very much; also we must add support to get the length of data.

Parameters:
f Instance of fakedbfs to use.
fn Filename to read.
Returns:
Pointer to data, or NULL on error.

int fdbfs_query_spop query_t q,
operands_t bf
 

Pop cell off stack.

Parameters:
q Query to operate on.
[out] bf Place to store popped data.
Return values:
1 Normal.
0 Stack underflow.

int fdbfs_query_spush query_t q,
int  o1,
unsigned int  o2,
void *  o3,
int  used
 

Push a cell to the query stack.

Parameters:
q Query to operate on.
o1 Value of o1.
o2 Value of o2.
o3 Value of o3.
used Used flags for this cell.
See also:
USED_O1

USED_O2

USED_O3

US_DYNA

US_FILE

Return values:
1 Normal.
0 No more space on stack.

int fdbfs_query_step query_t q  ) 
 

Step currently-running query.

Steps query, pushes fields_t of current result to stack.

Parameters:
q Query to step.
Returns:
Various.
See also:
query.h


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