-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquery_handler.js
118 lines (114 loc) · 3.54 KB
/
query_handler.js
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
var mysql = require('mysql');
function mysql_real_escape_string (str) {
return str.replace(/[\0\x08\x09\x1a\n\r"'\\\%]/g, function (char) {
switch (char) {
case "\0":
return "\\0";
case "\x08":
return "\\b";
case "\x09":
return "\\t";
case "\x1a":
return "\\z";
case "\n":
return "\\n";
case "\r":
return "\\r";
case "\"":
case "'":
case "\\":
case "%":
return "\\"+char; // prepends a backslash to backslash, percent,
// and double/single quotes
}
});
}
//querying
exports.querydb = function(inputrow, callback) {
var connection = mysql.createConnection({
host : 'localhost',
user : 'hackathon',
password : 'password',
database : 'bclass',
});
connection.connect();
var values = '';
if (typeof(inputrow.dept) != null && inputrow.dept != undefined) {
values += ' dept = "' + mysql_real_escape_string(inputrow.dept) + '"';
}
if (typeof(inputrow.title) != null && inputrow.title != undefined) {
if(values != '') {
values += ' AND';
}
values += ' title = "'+ mysql_real_escape_string(inputrow.title) + '"';
}
if (typeof(inputrow.courseno) != null && inputrow.courseno != undefined) {
if(values != '') {
values += ' AND';
}
values += ' courseno = "'+ mysql_real_escape_string(inputrow.courseno) + '"';
}
if (typeof(inputrow.sectionno) != null && inputrow.sectionno != undefined) {
if(values != '') {
values += ' AND';
}
values += ' sectionno = "'+ mysql_real_escape_string(inputrow.sectionno) + '"';
}
if (typeof(inputrow.controlno) != null && inputrow.controlno != undefined) {
if(values != '') {
values += ' AND';
}
values += ' controlno = "'+ mysql_real_escape_string(inputrow.controlno) + '"';
}
if (typeof(inputrow.time) != null && inputrow.time != undefined) {
if(values != '') {
values += ' AND';
}
values += ' time = "'+ mysql_real_escape_string(inputrow.time) + '"';
}
if (typeof(inputrow.room) != null && inputrow.room != undefined) {
if(values != '') {
values += ' AND';
}
values += ' room = "'+ mysql_real_escape_string(inputrow.room) + '"';
}
if (typeof(inputrow.units) != null && inputrow.units != undefined) {
if(values != '') {
values += ' AND';
}
values += ' units = "'+ mysql_real_escape_string(inputrow.units) + '"';
}
if (typeof(inputrow.instructor) != null && inputrow.instructor != undefined) {
if(values != '') {
values += ' AND';
}
values += ' instructor = "'+ mysql_real_escape_string(inputrow.instructor) + '"';
}
if (typeof(inputrow.examgroup) != null && inputrow.examgroup != undefined) {
if(values != '') {
values += ' AND';
}
values += ' examgroup = "'+ mysql_real_escape_string(inputrow.examgroup) + '"';
}
if (typeof(inputrow.restrictions) != null && inputrow.restrictions != undefined) {
if(values != '') {
values += ' AND';
}
values += ' restrictions = "'+ mysql_real_escape_string(inputrow.restrictions) + '"';
}
if (typeof(inputrow.note) != null && inputrow.note != undefined) {
if(values != '') {
values += ' AND';
}
values += ' note = "' + mysql_real_escape_string(inputrow.note) + '"';
}
values+=';';
connection.query('SELECT * FROM courses WHERE'+ values, function(err, rows, fields) {
if (err) {
callback("There was a probem with your input.");
} else {
callback(rows);
}
});
connection.end();
};