-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqueries.sql
277 lines (183 loc) · 5.1 KB
/
queries.sql
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/**
The main tbale for storing team information
**/
CREATE TABLE team
(
id int NOT NULL AUTO_INCREMENT,
tname varchar(255) NOT NULL UNIQUE,
cname varchar(255) NOT NULL,
email varchar(40) NOT NULL UNIQUE,
mno varchar(12) NOT NULL UNIQUE,
pass varchar(12) NOT NULL ,
lang varchar(10) NOT NULL,
status int NOT NULL DEFAULT 1,
PRIMARY KEY (ID)
);
ALTER TABLE team AUTO_INCREMENT=1000;
/**
table team:
status 1 team enabled(default)
status 0 team disabled
status 2 team blocked
**/
/**
EXAMPLE
**/
INSERT INTO team (tname,cname,email,mno,pass,lang) VALUES('ATM','TKM','name@gmail','7560881699','banana','cpp');
/**
Table where the questions are stored
questions are in HTML format as a BLOB
each languge should have a question
**/
CREATE TABLE questions
(
testid int NOT NULL AUTO_INCREMENT UNIQUE,
tlevel int NOT NULL ,
qno int NOT NULL,
lang varchar(10) NOT NULL,
quest BLOB NOT NULL,
dvalues BLOB ,
maxscore int NOT NULL,
PRIMARY KEY (tlevel,qno,lang)
);
/**
maxscore contains maximum score allowed for the question
dvalues can be used as the default values that should be present inside code editor when question is opened for the first time .
it can also be the code that needs debugging
**/
/**
All the CORRECT(succesful) submissions by the team are recorded here
**/
CREATE TABLE correct
(
subid int NOT NULL AUTO_INCREMENT UNIQUE,
tlevel int NOT NULL,
qno int NOT NULL,
teamid int NOT NULL,
status int NOT NULL,
time int(12) NOT NULL,
code BLOB,
lang varchar(10),
diff int NOT NULL,
PRIMARY KEY (tlevel,qno,teamid)
);
/**
time is time of submission in unix timestamp
diff contains the number of lines different from the default values in the corresponding question table and submitted code
the status will always be 2
**/
/**
TODO the following table not yet impemented in php
**/
CREATE TABLE testcase
(
testid int NOT NULL AUTO_INCREMENT UNIQUE,
tlevel int NOT NULL ,
qno int NOT NULL,
ncase int NOT NULL,
tinput BLOB NOT NULL,
toutput BLOB NOT NULL,
PRIMARY KEY (tlevel,qno,ncase)
);
/**
this helps to control php pages
we can enable and disable pages here
**/
CREATE TABLE pagecontrol
(
lcontrolid int NOT NULL AUTO_INCREMENT UNIQUE,
page varchar(40) NOT NULL UNIQUE,
status int NOT NULL,
PRIMARY KEY (page)
);
/**
status 0 enbaled
status 1 disabled
**/
/**
All submissions by the team are recorded here
**/
CREATE TABLE sublog
(
sublogid int NOT NULL AUTO_INCREMENT UNIQUE,
tlevel int NOT NULL,
qno int NOT NULL,
teamid int NOT NULL,
code BLOB,
status int NOT NULL,
time int(12) NOT NULL,
lang varchar(12),
diff int NOT NULL,
PRIMARY KEY (sublogid)
);
/**
status 0 -Compilation error
status 1-Compiled sucessfully but failed to pass testcases
status 2 -Compiled sucessfully and passed all test cases a copy willl present inside the correct table
**/
ALTER TABLE testcase AUTO_INCREMENT=5000;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '1234' WITH GRANT OPTION
/** To record the starting time of levels
whenever a user a starts a level it is recorded here.
this starting time used for all time calculation related to the team for the current level.
IE whenever a submission is made the submission is compared with the starting time
**/
CREATE TABLE levelstart
(
logid int NOT NULL AUTO_INCREMENT UNIQUE,
tlevel int NOT NULL ,
teamid int NOT NULL,
startt int NOT NULL,
PRIMARY KEY (teamid,tlevel)
);
/**
startt is unix timestamp
**/
/** to enable and disable level add rules
the following table allows to enable and disable levels
only if levels are then a team can start a level
**/
CREATE TABLE levels
(
tlevel int NOT NULL UNIQUE ,
qstns int NOT NULL,
status int NOT NULL,
type varchar(20),
totaltime int NOT NULL,
PRIMARY KEY (tlevel)
);
/**
type can be coding,debug
totalatime is in seconds
no of question of this level can be obtained from questions table
status
00 disabled
01 enabled
**/
/** the following table contain data code used by the user(NOT SUBMITTED CODE)
IE code typed inside the online code editor is stored inside this table
this table is updated when user switches questions or at every 15 seconds
this helps in monitoring current code developments by the user
**/
CREATE TABLE sync
(
tlevel int NOT NULL ,
qno int NOT NULL,
teamid int NOT NULL,
dat BLOB,
PRIMARY KEY (teamid,tlevel,qno)
);
/**
JUNK QUERIES
ALTER TABLE testcase AUTO_INCREMENT=5000;
CREATE TABLE
teamname
tlevel
compiled
correct
INSERT INTO testcase (tlevel,qno,tinput,toutput) values(1,1,'aaaaa','bbbb');
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '1234' WITH GRANT OPTION;
INSERT INTO questions (tlevel,qno,quest,dvalues,maxscore) values(2,3,"252525dgsds","5325",56);
INSERT INTO `answers` (teamid, stageid, questionid, ans,time) VALUES('{$_SESSION['teamid']}', '{$_SESSION['stage']}', '{$_SESSION['questionid']}', '" . $mysqli->real_escape_string ( $_POST ['ans'] ) . "','{$t}')
ON DUPLICATE KEY UPDATE teamid = VALUES(teamid), stageid = VALUES(stageid), questionid = VALUES(questionid), ans = VALUES(ans), time = VALUES(time)" );
**/