SAS/StudentDAOImpl.cpp

107 lines
3.5 KiB
C++
Raw Normal View History

/*
* ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>ʵ<EFBFBD><EFBFBD>
*/
2022-07-03 18:22:02 +08:00
#include"StudentDAO.h"
void addStudent(_ConnectionPtr connection, Student student) {
string sql = "insert into student values(?,?,?,?,?)";
2022-07-03 18:22:02 +08:00
vector<string>* v = new vector<string>();
v->push_back(student.getId());
v->push_back(student.getName());
v->push_back(student.getSex());
v->push_back(student.getStuClass());
v->push_back(student.getStatus());
executeSql(connection, sql.c_str(), v);
2022-07-03 18:22:02 +08:00
}
void deleteStudent(_ConnectionPtr connection, string id) {
string sql = "delete from student where id = ?";
vector<string>* v = new vector<string>();
v->push_back(id);
2022-07-03 18:22:02 +08:00
executeSql(connection, sql.c_str(), v);
2022-07-03 18:22:02 +08:00
}
void updateStudentClass(_ConnectionPtr connection, string id, string stuClass) {
string sql = "update student set stuClass = ? where id = ?";
vector<string>* v = new vector<string>();
v->push_back(stuClass);
v->push_back(id);
2022-07-03 18:22:02 +08:00
executeSql(connection, sql.c_str(), v);
2022-07-03 18:22:02 +08:00
}
void updateStudentStatus(_ConnectionPtr connection, string id, string status) {
string sql = "update student set status = ? where id = ?'";
2022-07-03 18:22:02 +08:00
vector<string>* v = new vector<string>();
v->push_back(status);
v->push_back(id);
executeSql(connection, sql.c_str(), v);
2022-07-03 18:22:02 +08:00
}
2022-07-04 00:31:52 +08:00
Student* getStudentById(_ConnectionPtr connection, string id) {
string sql = "select * from student where id = ?";
vector<string>* v = new vector<string>();
v->push_back(id);
_RecordsetPtr record = executeSql(connection, sql.c_str(), v);
if (record->BOF == -1) return NULL;//<2F><>¼<EFBFBD><C2BC>Ϊ<EFBFBD><CEAA>
2022-07-03 18:22:02 +08:00
Student *student = new Student();
student->setId((char*)(_bstr_t)record->Fields->GetItem("id")->Value);
student->setName((char*)(_bstr_t)record->Fields->GetItem("name")->Value);
student->setSex((char*)(_bstr_t)record->Fields->GetItem("sex")->Value);
student->setStuClass((char*)(_bstr_t)record->Fields->GetItem("stuClass")->Value);
student->setStatus((char*)(_bstr_t)record->Fields->GetItem("status")->Value);
2022-07-04 00:31:52 +08:00
return student;
2022-07-03 18:22:02 +08:00
}
2022-07-04 00:31:52 +08:00
std::vector<Student>* getStudentByName(_ConnectionPtr connection, string name) {
string sql = "select * from student where name = ?";
vector<string>* v = new vector<string>();
v->push_back(name);
_RecordsetPtr record = executeSql(connection, sql.c_str(), v);
if (record->BOF == -1) return NULL;//<2F><>¼<EFBFBD><C2BC>Ϊ<EFBFBD><CEAA>
2022-07-03 18:22:02 +08:00
std::vector<Student> *vs = new std::vector<Student>();
2022-07-03 18:22:02 +08:00
Student* student;
for (; !record->EndOfFile; record->MoveNext()) {
student = new Student();
student->setId((char*)(_bstr_t)record->Fields->GetItem("id")->Value);
student->setName((char*)(_bstr_t)record->Fields->GetItem("name")->Value);
student->setSex((char*)(_bstr_t)record->Fields->GetItem("sex")->Value);
student->setStuClass((char*)(_bstr_t)record->Fields->GetItem("stuClass")->Value);
student->setStatus((char*)(_bstr_t)record->Fields->GetItem("status")->Value);
vs->push_back(*student);
2022-07-03 18:22:02 +08:00
}
return vs;
2022-07-04 00:31:52 +08:00
}
std::vector<Student>* getAllStudent(_ConnectionPtr connection) {
string sql = "select * from student";
_RecordsetPtr record = executeSql(connection, sql.c_str(), NULL);
if (record->BOF == -1) return NULL;//<2F><>¼<EFBFBD><C2BC>Ϊ<EFBFBD><CEAA>
2022-07-04 00:31:52 +08:00
std::vector<Student>* v = new std::vector<Student>();
Student* student;
for (; !record->EndOfFile; record->MoveNext()) {
student = new Student();
student->setId((char*)(_bstr_t)record->Fields->GetItem("id")->Value);
student->setName((char*)(_bstr_t)record->Fields->GetItem("name")->Value);
student->setSex((char*)(_bstr_t)record->Fields->GetItem("sex")->Value);
student->setStuClass((char*)(_bstr_t)record->Fields->GetItem("stuClass")->Value);
student->setStatus((char*)(_bstr_t)record->Fields->GetItem("status")->Value);
v->push_back(*student);
}
return v;
2022-07-03 18:22:02 +08:00
}