-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtables.h
91 lines (78 loc) · 1.89 KB
/
tables.h
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
#ifndef TABLES_H
#define TABLES_H
#include "dt.h"
// Data Types, Records, and Schemas
typedef enum DataType {
DT_INT = 0,
DT_STRING = 1,
DT_FLOAT = 2,
DT_BOOL = 3
} DataType;
typedef struct Value {
DataType dt;
union v {
int intV;
char *stringV;
float floatV;
bool boolV;
} v;
} Value;
typedef struct RID {
int page;
int slot;
} RID;
typedef struct Record
{
RID id;
char *data;
} Record;
// information of a table schema: its attributes, datatypes,
typedef struct Schema
{
int numAttr;
char **attrNames;
DataType *dataTypes;
int *typeLength;
int *keyAttrs;
int keySize;
} Schema;
// TableData: Management Structure for a Record Manager to handle one relation
typedef struct RM_TableData
{
char *name;
Schema *schema;
void *mgmtData;
} RM_TableData;
#define MAKE_STRING_VALUE(result, value) \
do { \
(result) = (Value *) malloc(sizeof(Value)); \
(result)->dt = DT_STRING; \
(result)->v.stringV = (char *) malloc(strlen(value) + 1); \
strcpy((result)->v.stringV, value); \
} while(0)
#define MAKE_VALUE(result, datatype, value) \
do { \
(result) = (Value *) malloc(sizeof(Value)); \
(result)->dt = datatype; \
switch(datatype) \
{ \
case DT_INT: \
(result)->v.intV = value; \
break; \
case DT_FLOAT: \
(result)->v.floatV = value; \
break; \
case DT_BOOL: \
(result)->v.boolV = value; \
break; \
} \
} while(0)
// debug and read methods
extern Value *stringToValue (char *value);
extern char *serializeTableInfo(RM_TableData *rel);
extern char *serializeTableContent(RM_TableData *rel);
extern char *serializeSchema(Schema *schema);
extern char *serializeRecord(Record *record, Schema *schema);
extern char *serializeAttr(Record *record, Schema *schema, int attrNum);
extern char *serializeValue(Value *val);
#endif