Groonga 3.0.9 Source Code Document
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
groonga
lib
db.h
Go to the documentation of this file.
1
/* -*- c-basic-offset: 2 -*- */
2
/* Copyright(C) 2009-2013 Brazil
3
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Lesser General Public
6
License version 2.1 as published by the Free Software Foundation.
7
8
This library is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
Lesser General Public License for more details.
12
13
You should have received a copy of the GNU Lesser General Public
14
License along with this library; if not, write to the Free Software
15
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
*/
17
#ifndef GRN_DB_H
18
#define GRN_DB_H
19
20
#ifndef GROONGA_IN_H
21
#include "
groonga_in.h
"
22
#endif
/* GROONGA_IN_H */
23
24
#ifndef GRN_CTX_H
25
#include "
ctx.h
"
26
#endif
/* GRN_CTX_H */
27
28
#ifndef GRN_STORE_H
29
#include "
store.h
"
30
#endif
/* GRN_STORE_H */
31
32
#ifdef __cplusplus
33
extern
"C"
{
34
#endif
35
36
#define GRN_DB_DELIMITER '.'
37
#define GRN_DB_PSEUDO_COLUMN_PREFIX '_'
38
39
#define GRN_N_RESERVED_TYPES 256
40
41
typedef
struct
{
42
int
score
;
43
int
n_subrecs
;
44
int
subrecs[1];
45
}
grn_rset_recinfo
;
46
47
typedef
struct
{
48
grn_id
rid
;
49
uint32_t
sid
;
50
uint32_t
pos
;
51
}
grn_rset_posinfo
;
52
53
#define GRN_RSET_UTIL_BIT (0x80000000)
54
55
#define GRN_RSET_SCORE_SIZE (sizeof(int))
56
57
#define GRN_RSET_N_SUBRECS(ri) ((ri)->n_subrecs & ~GRN_RSET_UTIL_BIT)
58
59
#define GRN_RSET_SUBRECS_CMP(a,b,dir) (((a) - (b))*(dir))
60
#define GRN_RSET_SUBRECS_NTH(subrecs,size,n) \
61
((int *)((byte *)subrecs + n * (size + GRN_RSET_SCORE_SIZE)))
62
#define GRN_RSET_SUBRECS_COPY(subrecs,size,n,src) \
63
(memcpy(GRN_RSET_SUBRECS_NTH(subrecs, size, n), src, size + GRN_RSET_SCORE_SIZE))
64
65
typedef
struct
_grn_db
grn_db
;
66
typedef
struct
_grn_proc
grn_proc
;
67
68
struct
_grn_db
{
69
grn_db_obj
obj
;
70
grn_obj
*
keys
;
71
grn_ja
*
specs
;
72
grn_tiny_array
values
;
73
grn_critical_section
lock
;
74
};
75
76
typedef
struct
{
77
grn_obj_header
header
;
78
grn_id
range
;
79
}
grn_obj_spec
;
80
81
GRN_API
grn_rc
grn_db_close
(
grn_ctx
*ctx,
grn_obj
*db);
82
83
grn_obj
*
grn_db_keys
(
grn_obj
*s);
84
85
uint32_t
grn_db_lastmod
(
grn_obj
*s);
86
87
grn_rc
_grn_table_delete_by_id
(
grn_ctx
*ctx,
grn_obj
*table,
grn_id
id
,
88
grn_table_delete_optarg
*optarg);
89
90
grn_id
grn_table_get_v
(
grn_ctx
*ctx,
grn_obj
*table,
const
void
*key,
int
key_size,
91
void
**value);
92
grn_id
grn_table_add_v
(
grn_ctx
*ctx,
grn_obj
*table,
const
void
*key,
int
key_size,
93
void
**value,
int
*added);
94
GRN_API
grn_rc
grn_table_get_info
(
grn_ctx
*ctx,
grn_obj
*table,
grn_obj_flags
*flags,
95
grn_encoding
*encoding,
grn_obj
**tokenizer,
96
grn_obj
**normalizer);
97
const
char
*
_grn_table_key
(
grn_ctx
*ctx,
grn_obj
*table,
grn_id
id
, uint32_t *key_size);
98
99
grn_rc
grn_table_search
(
grn_ctx
*ctx,
grn_obj
*table,
100
const
void
*key, uint32_t key_size,
101
grn_operator
mode,
grn_obj
*res,
grn_operator
op);
102
103
grn_id
grn_table_next
(
grn_ctx
*ctx,
grn_obj
*table,
grn_id
id
);
104
105
int
grn_table_get_key2
(
grn_ctx
*ctx,
grn_obj
*table,
grn_id
id
,
grn_obj
*bulk);
106
107
grn_table_cursor
*
grn_table_cursor_open_by_id
(
grn_ctx
*ctx,
grn_obj
*table,
108
grn_id
min,
grn_id
max,
int
flags);
109
110
void
grn_table_add_subrec
(
grn_obj
*table,
grn_rset_recinfo
*ri,
int
score,
111
grn_rset_posinfo
*pi,
int
dir);
112
113
grn_obj
*
grn_obj_graft
(
grn_ctx
*ctx,
grn_obj
*obj);
114
115
grn_rc
grn_column_name_
(
grn_ctx
*ctx,
grn_obj
*obj,
grn_obj
*buf);
116
117
118
typedef
enum
{
119
PROC_INIT
= 0,
120
PROC_NEXT
,
121
PROC_FIN
122
}
grn_proc_phase
;
123
124
struct
_grn_type
{
125
grn_db_obj
obj
;
126
};
127
128
#define GRN_TABLE_SORT_GEO (0x02<<0)
129
130
#define GRN_OBJ_TMP_OBJECT 0x80000000
131
132
#define GRN_DB_OBJP(obj) \
133
(obj &&\
134
((GRN_SNIP == ((grn_db_obj *)obj)->header.type) ||\
135
((GRN_CURSOR_TABLE_HASH_KEY <= ((grn_db_obj *)obj)->header.type) &&\
136
(((grn_db_obj *)obj)->header.type <= GRN_COLUMN_INDEX))))
137
138
#define GRN_OBJ_TABLEP(obj) \
139
(obj &&\
140
(GRN_TABLE_HASH_KEY <= ((grn_db_obj *)obj)->header.type) &&\
141
(((grn_db_obj *)obj)->header.type <= GRN_DB))
142
143
typedef
grn_rc
grn_selector_func
(
grn_ctx
*ctx,
grn_obj
*table,
grn_obj
*
index
,
144
int
nargs,
grn_obj
**args,
145
grn_obj
*res,
grn_operator
op);
146
147
typedef
struct
_grn_proc_ctx
grn_proc_ctx
;
148
149
struct
_grn_proc_ctx
{
150
grn_user_data
user_data
;
151
grn_proc
*
proc
;
152
grn_obj
*
caller
;
153
// grn_obj *obj;
154
grn_hook
*
hooks
;
155
grn_hook
*
currh
;
156
grn_proc_phase
phase
;
157
unsigned
short
nargs
;
158
unsigned
short
offset
;
159
grn_user_data
data
[16];
160
};
161
162
struct
_grn_proc
{
163
grn_db_obj
obj
;
164
grn_obj
name_buf
;
165
grn_expr_var
*
vars
;
166
uint32_t
nvars
;
167
/* -- compatible with grn_expr -- */
168
grn_proc_type
type
;
169
grn_proc_func
*
funcs
[3];
170
171
grn_selector_func
*
selector
;
172
173
grn_id
module
;
174
// uint32_t nargs;
175
// uint32_t nresults;
176
// grn_obj results[16];
177
};
178
179
#define GRN_PROC_GET_VAR(name) (grn_proc_get_var(ctx, user_data, name, strlen(name)))
180
#define GRN_PROC_GET_VAR_BY_OFFSET(offset) (grn_proc_get_var_by_offset(ctx, user_data, offset))
181
#define GRN_PROC_GET_OR_ADD_VAR(name) (grn_proc_get_or_add_var(ctx, user_data, name, strlen(name)))
182
#define GRN_PROC_ALLOC(domain, flags) (grn_proc_alloc(ctx, user_data, domain, flags))
183
184
grn_obj
*
grn_proc_get_var
(
grn_ctx
*ctx,
grn_user_data
*user_data,
185
const
char
*name,
unsigned
int
name_size);
186
187
GRN_API
grn_obj
*
grn_proc_get_var_by_offset
(
grn_ctx
*ctx,
grn_user_data
*user_data,
188
unsigned
int
offset);
189
GRN_API
grn_obj
*
grn_proc_get_or_add_var
(
grn_ctx
*ctx,
grn_user_data
*user_data,
190
const
char
*name,
unsigned
int
name_size);
191
192
GRN_API
grn_obj
*
grn_proc_alloc
(
grn_ctx
*ctx,
grn_user_data
*user_data,
193
grn_id
domain,
grn_obj_flags
flags);
194
195
grn_rc
grn_proc_set_selector
(
grn_ctx
*ctx,
grn_obj
*proc,
196
grn_selector_func
selector);
197
198
GRN_API
grn_rc
grn_proc_call
(
grn_ctx
*ctx,
grn_obj
*proc,
199
int
nargs,
grn_obj
*caller);
200
201
grn_obj
*
grn_expr_get_or_add_var
(
grn_ctx
*ctx,
grn_obj
*expr,
202
const
char
*name,
unsigned
int
name_size);
203
204
205
typedef
struct
_grn_accessor
grn_accessor
;
206
207
struct
_grn_accessor
{
208
grn_obj_header
header
;
209
grn_id
range
;
210
/* -- compatible with grn_db_obj -- */
211
uint8_t
action
;
212
int
offset
;
213
grn_obj
*
obj
;
214
grn_accessor
*
next
;
215
};
216
217
enum
{
218
GRN_ACCESSOR_VOID
= 0,
219
GRN_ACCESSOR_GET_ID
,
220
GRN_ACCESSOR_GET_KEY
,
221
GRN_ACCESSOR_GET_VALUE
,
222
GRN_ACCESSOR_GET_SCORE
,
223
GRN_ACCESSOR_GET_NSUBRECS
,
224
GRN_ACCESSOR_GET_COLUMN_VALUE
,
225
GRN_ACCESSOR_GET_DB_OBJ
,
226
GRN_ACCESSOR_LOOKUP
,
227
GRN_ACCESSOR_FUNCALL
228
};
229
230
#define DB_OBJ(obj) ((grn_db_obj *)obj)
231
232
GRN_API
const
char
*
grn_obj_get_value_
(
grn_ctx
*ctx,
grn_obj
*obj,
grn_id
id
, uint32_t *size);
233
234
/* vector */
235
236
/*
237
typedef struct _grn_vector grn_vector;
238
239
struct _grn_vector {
240
grn_obj str;
241
uint32_t *offsets;
242
int n_entries;
243
};
244
245
const char *grn_vector_fetch(grn_ctx *ctx, grn_obj *vector, int i, unsigned int *size);
246
int grn_vector_delimit(grn_ctx *ctx, grn_obj *vector);
247
int grn_vector_size(grn_ctx *ctx, grn_obj *vector);
248
*/
249
250
unsigned
int
grn_vector_pop_element
(
grn_ctx
*ctx,
grn_obj
*vector,
251
const
char
**str,
unsigned
int
*weight,
grn_id
*domain);
252
253
grn_rc
grn_vector_delimit
(
grn_ctx
*ctx,
grn_obj
*v,
unsigned
int
weight,
grn_id
domain);
254
grn_rc
grn_vector_decode
(
grn_ctx
*ctx,
grn_obj
*v,
const
char
*data, uint32_t data_size);
255
256
257
grn_rc
grn_db_init_builtin_types
(
grn_ctx
*ctx);
258
259
/* flag value used for grn_obj.header.flags */
260
261
#define GRN_OBJ_CUSTOM_NAME (0x01<<12)
/* db_obj which has custom name */
262
263
#define GRN_OBJ_RESOLVE(ctx,obj) \
264
(((obj)->header.type != GRN_PTR)\
265
? (obj)\
266
: GRN_PTR_VALUE(obj)\
267
? GRN_PTR_VALUE(obj)\
268
: grn_ctx_at((ctx), (obj)->header.domain))
269
270
/* expr */
271
272
typedef
struct
_grn_expr
grn_expr
;
273
274
#define GRN_EXPR_CODE_RELATIONAL_EXPRESSION (0x01)
275
276
typedef
struct
{
277
grn_obj
*
value
;
278
int32_t
nargs
;
279
grn_operator
op
;
280
uint8_t
flags
;
281
int32_t
modify
;
282
}
grn_expr_code
;
283
284
struct
_grn_expr
{
285
grn_db_obj
obj
;
286
grn_obj
name_buf
;
287
grn_expr_var
*
vars
;
288
uint32_t
nvars
;
289
/* -- compatible with grn_proc -- */
290
291
uint16_t
cacheable
;
292
uint16_t
taintable
;
293
grn_obj
*
consts
;
294
grn_obj
*
values
;
295
grn_expr_code
*
codes
;
296
uint32_t
nconsts
;
297
uint32_t
values_curr
;
298
uint32_t
values_tail
;
299
uint32_t
values_size
;
300
uint32_t
codes_curr
;
301
uint32_t
codes_size
;
302
303
grn_obj
objs
;
304
grn_obj
dfi
;
305
grn_expr_code
*
code0
;
306
};
307
308
GRN_API
grn_rc
grn_expr_clear_vars
(
grn_ctx
*ctx,
grn_obj
*expr);
309
310
grn_rc
grn_expr_parser_close
(
grn_ctx
*ctx);
311
GRN_API
grn_rc
grn_obj_cast
(
grn_ctx
*ctx,
grn_obj
*src,
grn_obj
*dest,
grn_bool
addp);
312
321
GRN_API
grn_obj
*
grn_table_open
(
grn_ctx
*ctx,
322
const
char
*name,
unsigned
int
name_size,
323
const
char
*path);
324
335
grn_obj
*
grn_column_open
(
grn_ctx
*ctx,
grn_obj
*table,
336
const
char
*name,
unsigned
int
name_size,
337
const
char
*path,
grn_obj
*
type
);
338
346
grn_rc
grn_obj_path_rename
(
grn_ctx
*ctx,
const
char
*old_path,
const
char
*new_path);
347
348
grn_rc
grn_db_check_name
(
grn_ctx
*ctx,
const
char
*name,
unsigned
int
name_size);
349
#define GRN_DB_CHECK_NAME_ERR(error_context, name, name_size) \
350
ERR(GRN_INVALID_ARGUMENT,\
351
"%s name can't start with '%c' and contains only 0-9, A-Z, a-z, #, @, - or _: <%.*s>",\
352
error_context, GRN_DB_PSEUDO_COLUMN_PREFIX, name_size, name)
353
354
#define GRN_DB_P(s) ((s) && ((grn_db *)s)->obj.header.type == GRN_DB)
355
#define GRN_DB_PERSISTENT_P(s) (((grn_db *)s)->specs)
356
357
#define GRN_OBJ_GET_VALUE_IMD (0xffffffffU)
358
359
grn_rc
grn_db_obj_init
(
grn_ctx
*ctx,
grn_obj
*db,
grn_id
id
,
grn_db_obj
*obj);
360
361
#define GRN_ACCESSORP(obj) \
362
((obj) && (((grn_obj *)(obj))->header.type == GRN_ACCESSOR))
363
364
#define GRN_TRUEP(ctx, v, result) do {\
365
switch (v->header.type) { \
366
case GRN_BULK : \
367
switch (v->header.domain) { \
368
case GRN_DB_BOOL : \
369
result = GRN_BOOL_VALUE(v); \
370
break; \
371
case GRN_DB_INT32 : \
372
result = GRN_INT32_VALUE(v) != 0; \
373
break; \
374
case GRN_DB_UINT32 : \
375
result = GRN_UINT32_VALUE(v) != 0; \
376
break; \
377
case GRN_DB_FLOAT : \
378
{ \
379
double float_value; \
380
float_value = GRN_FLOAT_VALUE(v); \
381
result = (float_value < -DBL_EPSILON || \
382
DBL_EPSILON < float_value); \
383
} \
384
break; \
385
case GRN_DB_SHORT_TEXT : \
386
case GRN_DB_TEXT : \
387
case GRN_DB_LONG_TEXT : \
388
result = GRN_TEXT_LEN(v) != 0; \
389
break; \
390
default : \
391
result = GRN_FALSE; \
392
break; \
393
} \
394
break; \
395
case GRN_VECTOR : \
396
result = GRN_TRUE; \
397
break; \
398
default : \
399
result = GRN_FALSE; \
400
break; \
401
} \
402
} while (0)
403
404
grn_id
grn_obj_register
(
grn_ctx
*ctx,
grn_obj
*db,
const
char
*name,
unsigned
int
name_size);
405
int
grn_obj_is_persistent
(
grn_ctx
*ctx,
grn_obj
*obj);
406
void
grn_obj_spec_save
(
grn_ctx
*ctx,
grn_db_obj
*obj);
407
408
grn_rc
grn_obj_reinit_for
(
grn_ctx
*ctx,
grn_obj
*obj,
grn_obj
*domain_obj);
409
410
#define GRN_UINT32_POP(obj,value) do {\
411
if (GRN_BULK_VSIZE(obj) >= sizeof(uint32_t)) {\
412
GRN_BULK_INCR_LEN((obj), -(sizeof(uint32_t)));\
413
value = *(uint32_t *)(GRN_BULK_CURR(obj));\
414
} else {\
415
value = 0;\
416
}\
417
} while (0)
418
419
void
grn_expr_pack
(
grn_ctx
*ctx,
grn_obj
*buf,
grn_obj
*expr);
420
GRN_API
grn_rc
grn_expr_inspect
(
grn_ctx
*ctx,
grn_obj
*buf,
grn_obj
*expr);
421
grn_obj
*
grn_expr_open
(
grn_ctx
*ctx,
grn_obj_spec
*spec,
const
uint8_t *p,
const
uint8_t *pe);
422
423
#define KEY_NAME "_key"
424
#define ID_NAME "_id"
425
426
GRN_API
void
grn_load_
(
grn_ctx
*ctx,
grn_content_type
input_type,
427
const
char
*table,
unsigned
int
table_len,
428
const
char
*columns,
unsigned
int
columns_len,
429
const
char
*values,
unsigned
int
values_len,
430
const
char
*ifexists,
unsigned
int
ifexists_len,
431
const
char
*each,
unsigned
int
each_len,
432
uint32_t emit_level);
433
434
GRN_API
grn_rc
grn_table_group_with_range_gap
(
grn_ctx
*ctx,
grn_obj
*table,
435
grn_table_sort_key
*group_key,
436
grn_obj
*result_set,
437
uint32_t range_gap);
438
439
GRN_API
grn_rc
grn_column_filter
(
grn_ctx
*ctx,
grn_obj
*column,
440
grn_operator
op,
441
grn_obj
*value,
grn_obj
*result_set,
442
grn_operator
set_op);
443
444
grn_rc
grn_accessor_resolve
(
grn_ctx
*ctx,
grn_obj
*accessor,
int
deep,
445
grn_obj
*base_res,
grn_obj
*res,
grn_operator
op,
446
grn_search_optarg
*optarg);
447
448
#ifdef __cplusplus
449
}
450
#endif
451
452
#endif
/* GRN_DB_H */
Generated on Sun Nov 10 2013 09:49:02 for Groonga 3.0.9 Source Code Document by
1.8.1.2