2022-07-06 16:42:53 +08:00
|
|
|
|
/*
|
|
|
|
|
* <EFBFBD>γ̱<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>ʵ<EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
2022-07-03 18:22:02 +08:00
|
|
|
|
#include"CourseDAO.h"
|
|
|
|
|
|
|
|
|
|
void addCourse(_ConnectionPtr connection, Course course) {
|
2022-07-06 16:42:53 +08:00
|
|
|
|
string sql = "insert into course values(?,?)";
|
2022-07-03 18:22:02 +08:00
|
|
|
|
|
2022-07-06 16:42:53 +08:00
|
|
|
|
vector<string>* v = new vector<string>();
|
|
|
|
|
v->push_back(course.getId());
|
|
|
|
|
v->push_back(course.getName());
|
|
|
|
|
|
|
|
|
|
executeSql(connection, sql.c_str(), v);
|
2022-07-03 18:22:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void deleteCourse(_ConnectionPtr connection, string id) {
|
2022-07-06 16:42:53 +08:00
|
|
|
|
string sql = "delete from course where id = ?";
|
|
|
|
|
|
|
|
|
|
vector<string>* v = new vector<string>();
|
|
|
|
|
v->push_back(id);
|
2022-07-03 18:22:02 +08:00
|
|
|
|
|
2022-07-06 16:42:53 +08:00
|
|
|
|
executeSql(connection, sql.c_str(), v);
|
2022-07-03 18:22:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void updateCourseName(_ConnectionPtr connection, string id, string name) {
|
2022-07-06 16:42:53 +08:00
|
|
|
|
string sql = "update course set name = ? where id = ?";
|
|
|
|
|
|
|
|
|
|
vector<string>* v = new vector<string>();
|
|
|
|
|
v->push_back(name);
|
|
|
|
|
v->push_back(id);
|
2022-07-03 18:22:02 +08:00
|
|
|
|
|
2022-07-06 16:42:53 +08:00
|
|
|
|
executeSql(connection, sql.c_str(), v);
|
2022-07-03 18:22:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-04 00:31:52 +08:00
|
|
|
|
Course* getCourseById(_ConnectionPtr connection, string id) {
|
2022-07-06 16:42:53 +08:00
|
|
|
|
string sql = "select * from course where id = ?";
|
|
|
|
|
|
|
|
|
|
vector<string>* v = new vector<string>();
|
|
|
|
|
v->push_back(id);
|
|
|
|
|
|
|
|
|
|
_RecordsetPtr record = executeSql(connection, sql.c_str(), v);
|
2022-07-04 22:17:38 +08:00
|
|
|
|
if (record->BOF == -1) return NULL;//<2F><>¼<EFBFBD><C2BC>Ϊ<EFBFBD><CEAA>
|
2022-07-03 18:22:02 +08:00
|
|
|
|
|
|
|
|
|
Course* course = new Course();
|
|
|
|
|
course->setId((char*)(_bstr_t)record->Fields->GetItem("id")->Value);
|
|
|
|
|
course->setName((char*)(_bstr_t)record->Fields->GetItem("name")->Value);
|
2022-07-04 00:31:52 +08:00
|
|
|
|
return course;
|
2022-07-03 18:22:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-04 00:31:52 +08:00
|
|
|
|
Course* getCourseByName(_ConnectionPtr connection, string name) {
|
2022-07-06 16:42:53 +08:00
|
|
|
|
string sql = "select * from course where name = ?";
|
|
|
|
|
|
|
|
|
|
vector<string>* v = new vector<string>();
|
|
|
|
|
v->push_back(name);
|
|
|
|
|
|
|
|
|
|
_RecordsetPtr record = executeSql(connection, sql.c_str(), v);
|
2022-07-04 22:17:38 +08:00
|
|
|
|
if (record->BOF == -1) return NULL;//<2F><>¼<EFBFBD><C2BC>Ϊ<EFBFBD><CEAA>
|
2022-07-04 00:31:52 +08:00
|
|
|
|
|
|
|
|
|
Course* course = new Course();
|
|
|
|
|
course->setId((char*)(_bstr_t)record->Fields->GetItem("id")->Value);
|
|
|
|
|
course->setName((char*)(_bstr_t)record->Fields->GetItem("name")->Value);
|
|
|
|
|
return course;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<Course>* getAllCourse(_ConnectionPtr connection) {
|
|
|
|
|
string sql = "select * from course";
|
2022-07-06 16:42:53 +08:00
|
|
|
|
_RecordsetPtr record = executeSql(connection, sql.c_str(), NULL);
|
2022-07-04 22:17:38 +08:00
|
|
|
|
if (record->BOF == -1) return NULL;//<2F><>¼<EFBFBD><C2BC>Ϊ<EFBFBD><CEAA>
|
2022-07-03 18:22:02 +08:00
|
|
|
|
|
|
|
|
|
std::vector<Course>* v = new std::vector<Course>();
|
|
|
|
|
Course* course;
|
|
|
|
|
for (; !record->EndOfFile; record->MoveNext()) {
|
|
|
|
|
course = new Course();
|
|
|
|
|
course->setId((char*)(_bstr_t)record->Fields->GetItem("id")->Value);
|
|
|
|
|
course->setName((char*)(_bstr_t)record->Fields->GetItem("name")->Value);
|
|
|
|
|
v->push_back(*course);
|
|
|
|
|
}
|
2022-07-04 00:31:52 +08:00
|
|
|
|
return v;
|
2022-07-03 18:22:02 +08:00
|
|
|
|
}
|