-
Notifications
You must be signed in to change notification settings - Fork 0
/
DMR.h
177 lines (148 loc) · 5.36 KB
/
DMR.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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
static int callback(void *NotUsed, int argc, char **argv, char **azColName) {
int i;
for(i = 0; i<argc; i++) {
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
}
printf("\n");
return 0;
}
static int retrive_ae(void *NotUsed, int argc, char **argv, char **azColName) {
int i;
for(i = 0; i<argc; i++) {
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
if (i == 0) aei = argv[i];
if (i == 1) api = argv[i];
if (i == 2) rn = argv[i];
if (i == 3) rr = argv[i];
}
printf(" \n");
return 0;
}
static int retrive_cont(void *NotUsed, int argc, char **argv, char **azColName) {
int i;
for(i = 0; i<argc; i++) {
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
if (i == 0) rn = argv[i];
if (i == 1) _to = argv[i];
if (i == 2) rqi = argv[i];
}
printf(" \n");
return 0;
}
static int retrive_sub(void *NotUsed, int argc, char **argv, char **azColName) {
int i;
for(i = 0; i<argc; i++) {
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
if (i == 0) rn = argv[i];
if (i == 1) rqi = argv[i];
if (i == 2) nu = argv[i];
if (i == 3) net = std::stoi(argv[i]);
if (i == 4) nct = std::stoi(argv[i]);
if (i == 5) _to = argv[i];
}
printf(" \n");
return 0;
}
void CreateTables(sqlite3 *db)
{
int rc;
char *zErrMsg = 0;
char *sql;
// Drop if Exits
sql = "DROP TABLE Registration";
rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
if( rc != SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}
else fprintf(stdout, "Registration Table Dropped successfully\n");
sql = "DROP TABLE Container";
rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
if( rc != SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}
else fprintf(stdout, "Container Table Dropped successfully\n");
sql = "DROP TABLE ContentInstance";
rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
if( rc != SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}
else fprintf(stdout, "ContentInstance Table Dropped successfully\n");
sql = "DROP TABLE Subscription";
rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
if( rc != SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}
else fprintf(stdout, "Subscription Table Dropped successfully\n");
//Create Registration Table
sql = "CREATE TABLE Registration(" \
"aei TEXT PRIMARY KEY NOT NULL," \
"api TEXT NOT NULL," \
"rn TEXT NOT NULL," \
"rr BOOLEAN NOT NULL," \
"ct TEXT NOT NULL," \
"lt TEXT NOT NULL);";
rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
if( rc != SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}
else fprintf(stdout, "Registration Table created successfully\n");
//Create Container Table
sql = "CREATE TABLE Container(" \
"rn TEXT PRIMARY KEY NOT NULL," \
"_to TEXT NOT NULL," \
"rqi TEXT NOT NULL,"\
"ct TEXT NOT NULL," \
"lt TEXT NOT NULL," \
"FOREIGN KEY (_to) REFERENCES Registration(aei) ON DELETE CASCADE);";
rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
if( rc != SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}
else fprintf(stdout, "Container Table created successfully\n");
//Create Content Instance Table
sql = "CREATE TABLE ContentInstance(" \
"rqi TEXT PRIMARY KEY NOT NULL," \
"con TEXT NOT NULL," \
"cnf TEXT NOT NULL," \
"_to TEXT NOT NULL,"\
"ct TEXT NOT NULL," \
"lt TEXT NOT NULL," \
"FOREIGN KEY (_to) REFERENCES Container(rn) ON DELETE CASCADE);";
rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
if( rc != SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}
else fprintf(stdout, "ContentInstance Table created successfully\n");
//Create Subscription Table
sql = "CREATE TABLE Subscription(" \
"rn TEXT PRIMARY KEY NOT NULL," \
"rqi TEXT NOT NULL," \
"nu TEXT NOT NULL," \
"net INT NOT NULL," \
"nct INT NOT NULL," \
"_to TEXT NOT NULL,"\
"ct TEXT NOT NULL," \
"lt TEXT NOT NULL," \
"FOREIGN KEY (_to) REFERENCES Container(rn) ON DELETE CASCADE);";
rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
if( rc != SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}
else fprintf(stdout, "Subscription Table created successfully\n");
sql = "PRAGMA foreign_keys = ON;";
rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
if( rc != SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}
else fprintf(stdout, "Successfully invoked Foreign Keys Pragma\n");
return;
}