File: dbquery.h

package info (click to toggle)
whitedb 0.7.2-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,452 kB
  • ctags: 2,681
  • sloc: ansic: 31,714; python: 790; lex: 359; java: 277; makefile: 172; yacc: 138; sh: 87; sed: 36
file content (142 lines) | stat: -rw-r--r-- 5,308 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* $Id:  $
* $Version: $
*
* Copyright (c) Priit Jrv 2010,2011,2013
*
* This file is part of WhiteDB
*
* WhiteDB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* WhiteDB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WhiteDB.  If not, see <http://www.gnu.org/licenses/>.
*
*/

 /** @file dbcompare.h
 * Public headers for WhiteDB query engine.
 */

#ifndef DEFINED_DBQUERY_H
#define DEFINED_DBQUERY_H
#ifdef _WIN32
#include "../config-w32.h"
#else
#include "../config.h"
#endif

#include "dbdata.h"
#include "dbindex.h"

/* ==== Public macros ==== */

#define WG_COND_EQUAL       0x0001      /** = */
#define WG_COND_NOT_EQUAL   0x0002      /** != */
#define WG_COND_LESSTHAN    0x0004      /** < */
#define WG_COND_GREATER     0x0008      /** > */
#define WG_COND_LTEQUAL     0x0010      /** <= */
#define WG_COND_GTEQUAL     0x0020      /** >= */

#define WG_QTYPE_TTREE      0x01
#define WG_QTYPE_HASH       0x02
#define WG_QTYPE_SCAN       0x04
#define WG_QTYPE_PREFETCH   0x80

/* ====== data structures ======== */

/** Query argument list object */
typedef struct {
  gint column;      /** column (field) number this argument applies to */
  gint cond;        /** condition (equal, less than, etc) */
  gint value;       /** encoded value */
} wg_query_arg;

typedef struct {
  gint key;         /** encoded key */
  gint value;       /** encoded value */
} wg_json_query_arg;

/** Query object */
typedef struct {
  gint qtype;           /** Query type (T-tree, hash, full scan, prefetch) */
  /* Argument list based query is the only one supported at the moment. */
  wg_query_arg *arglist;    /** check each row in result set against these */
  gint argc;                /** number of elements in arglist */
  gint column;              /** index on this column used */
  /* Fields for T-tree query (XXX: some may be re-usable for
   * other types as well) */
  gint curr_offset;
  gint end_offset;
  gint curr_slot;
  gint end_slot;
  gint direction;
  /* Fields for full scan */
  gint curr_record;         /** offset of the current record */
  /* Fields for prefetch */
  void *mpool;              /** storage for row offsets */
  void *curr_page;          /** current page of results */
  gint curr_pidx;           /** current index on page */
  wg_uint res_count;          /** number of rows in results */
} wg_query;

/* ==== Protos ==== */

wg_query *wg_make_query(void *db, void *matchrec, gint reclen,
  wg_query_arg *arglist, gint argc);
#define wg_make_prefetch_query wg_make_query
wg_query *wg_make_query_rc(void *db, void *matchrec, gint reclen,
  wg_query_arg *arglist, gint argc, wg_uint rowlimit);
wg_query *wg_make_json_query(void *db, wg_json_query_arg *arglist, gint argc);
void *wg_fetch(void *db, wg_query *query);
void wg_free_query(void *db, wg_query *query);

gint wg_encode_query_param_null(void *db, char *data);
gint wg_encode_query_param_record(void *db, void *data);
gint wg_encode_query_param_char(void *db, char data);
gint wg_encode_query_param_fixpoint(void *db, double data);
gint wg_encode_query_param_date(void *db, int data);
gint wg_encode_query_param_time(void *db, int data);
gint wg_encode_query_param_var(void *db, gint data);
gint wg_encode_query_param_int(void *db, gint data);
gint wg_encode_query_param_double(void *db, double data);
gint wg_encode_query_param_str(void *db, char *data, char *lang);
gint wg_encode_query_param_xmlliteral(void *db, char *data, char *xsdtype);
gint wg_encode_query_param_uri(void *db, char *data, char *prefix);
gint wg_free_query_param(void* db, gint data);

void *wg_find_record(void *db, gint fieldnr, gint cond, gint data,
    void* lastrecord);
void *wg_find_record_null(void *db, gint fieldnr, gint cond, char *data,
    void* lastrecord);
void *wg_find_record_record(void *db, gint fieldnr, gint cond, void *data,
    void* lastrecord);
void *wg_find_record_char(void *db, gint fieldnr, gint cond, char data,
    void* lastrecord);
void *wg_find_record_fixpoint(void *db, gint fieldnr, gint cond, double data,
    void* lastrecord);
void *wg_find_record_date(void *db, gint fieldnr, gint cond, int data,
    void* lastrecord);
void *wg_find_record_time(void *db, gint fieldnr, gint cond, int data,
    void* lastrecord);
void *wg_find_record_var(void *db, gint fieldnr, gint cond, gint data,
    void* lastrecord);
void *wg_find_record_int(void *db, gint fieldnr, gint cond, int data,
    void* lastrecord);
void *wg_find_record_double(void *db, gint fieldnr, gint cond, double data,
    void* lastrecord);
void *wg_find_record_str(void *db, gint fieldnr, gint cond, char *data,
    void* lastrecord);
void *wg_find_record_xmlliteral(void *db, gint fieldnr, gint cond, char *data,
    char *xsdtype, void* lastrecord);
void *wg_find_record_uri(void *db, gint fieldnr, gint cond, char *data,
    char *prefix, void* lastrecord);

#endif /* DEFINED_DBQUERY_H */