forked from 3rd-year-CSE-20/SIS_GUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
course.cpp
97 lines (77 loc) · 1.91 KB
/
course.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
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
#include "course.h"
#include "globalDbObject.h"
#include <QString>
#include <QVector>
#include <QSqlDatabase>
#include <QSql>
#include <QSqlError>
#include <QDir>
#include <QFile>
#include <QDebug>
#include <QSqlQuery>
#include <QString>
#include <QStringList>
#include <QSqlError>
Course::Course() {
this->id = 0;
this->is_saved = false;
this->name = QString("");
}
Course::Course(QString name) {
this->id = 0;
this->is_saved = false;
this->name = name;
}
void Course::setName(QString name) {
this->name = name;
}
QString Course::getName() {
return this->name;
}
QVector<Course> Course::all() {
QSqlQuery query = SQLiteDb.sql_getQuery();
QVector<Course> courses;
Course temp;
query.exec("SELECT * FROM courses");
while(query.next()) {
long long id = query.value(0).toLongLong();
QString name = query.value(1).toString();
temp.setId(id);
temp.setName(name);
temp.setIsSaved(true);
courses.push_back(temp);
}
return courses;
}
Course Course::find(long long id) {
QSqlQuery query = SQLiteDb.sql_getQuery();
query.exec("SELECT * FROM courses WHERE id = " + QString::number(id));
query.next();
QString name = query.value(1).toString();
Course course(name);
course.setId(id);
course.setIsSaved(true);
return course;
}
void Course::setId(long long id) {
this->id = id;
}
long long Course::getId() {
return this->id;
}
void Course::setIsSaved(bool is_saved) {
this->is_saved = is_saved;
}
bool Course::isSaved() {
return this->is_saved;
}
QVector<Course> Course::where(QString column, QString value){
SQLiteDb.sql_select("*", "courses", column + " LIKE '" + value +"%'");
QSqlQuery query = SQLiteDb.sql_getQuery();
QVector<Course> courses;
while (query.next()) {
int id = query.value(0).toInt();
courses.push_back(find(id));
}
return courses;
}