-
Notifications
You must be signed in to change notification settings - Fork 13
/
catalog.cpp
56 lines (47 loc) · 1.37 KB
/
catalog.cpp
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
#include "catalog.h"
#include "global.h"
#include "helper.h"
void
Catalog::init(const char * table_name, int field_cnt) {
this->table_name = table_name;
this->field_cnt = 0;
this->_columns = new Column [field_cnt];
this->tuple_size = 0;
}
void Catalog::add_col(char * col_name, uint64_t size, char * type) {
_columns[field_cnt].size = size;
strcpy(_columns[field_cnt].type, type);
strcpy(_columns[field_cnt].name, col_name);
_columns[field_cnt].id = field_cnt;
_columns[field_cnt].index = tuple_size;
tuple_size += size;
field_cnt ++;
}
uint64_t Catalog::get_field_id(const char * name) {
UInt32 i;
for (i = 0; i < field_cnt; i++) {
if (strcmp(name, _columns[i].name) == 0)
break;
}
assert (i < field_cnt);
return i;
}
char * Catalog::get_field_type(uint64_t id) {
return _columns[id].type;
}
char * Catalog::get_field_name(uint64_t id) {
return _columns[id].name;
}
char * Catalog::get_field_type(char * name) {
return get_field_type( get_field_id(name) );
}
uint64_t Catalog::get_field_index(char * name) {
return get_field_index( get_field_id(name) );
}
void Catalog::print_schema() {
printf("\n[Catalog] %s\n", table_name);
for (UInt32 i = 0; i < field_cnt; i++) {
printf("\t%s\t%s\t%ld\n", get_field_name(i),
get_field_type(i), get_field_size(i));
}
}