2022-06-07 16:20 1、executeSql更改adBSTR为adVarChar,解决值宽度问题 2、导入文件函数添加存在检测,防止产生主键重复

This commit is contained in:
zyx 2022-07-07 16:21:37 +08:00
parent 3c613ad5ef
commit b90b852560
2 changed files with 20 additions and 14 deletions

View File

@ -15,7 +15,7 @@ _RecordsetPtr executeSql(_ConnectionPtr connection, const char* sql, vector<stri
size_t size = v->size();
for (size_t i = 0; i < size; i++)
{
_ParameterPtr p = command->CreateParameter("var" + i, adBSTR, adParamInput, sizeof((*v)[i].c_str()), (*v)[i].c_str());
_ParameterPtr p = command->CreateParameter("var" + i, adVarChar, adParamInput, sizeof((*v)[i]), (*v)[i].c_str());
command->Parameters->Append(p);
}
return command->Execute(NULL, NULL, long(0));

View File

@ -861,6 +861,7 @@ void importStudentData(_ConnectionPtr connection) {
Student* student = new Student();
while (!inFile.eof()) {
inFile >> title[0] >> title[1] >> title[2] >> title[3] >> title[4];
if (getStudentById(connection, title[0]) == NULL) {
student->setId(title[0]);
student->setName(title[1]);
student->setSex(title[2]);
@ -868,6 +869,7 @@ void importStudentData(_ConnectionPtr connection) {
student->setStatus(title[4]);
addStudent(connection, *student);
}
}
printf("成功导入student.txt文件!\n");
inFile.close();
}
@ -889,10 +891,12 @@ void importCourseData(_ConnectionPtr connection) {
Course* course = new Course();
while (!inFile.eof()) {
inFile >> title[0] >> title[1];
if (getCourseById(connection, title[0]) == NULL) {
course->setId(title[0]);
course->setName(title[1]);
addCourse(connection, *course);
}
}
printf("成功导入course.txt文件!\n");
inFile.close();
}
@ -914,11 +918,13 @@ void importGradeData(_ConnectionPtr connection) {
Grade* grade = new Grade();
while (!inFile.eof()) {
inFile >> title[0] >> title[1] >> title[2];
if (getOnesGrade(connection, title[0], title[1]) == NULL) {
grade->setStuId(title[0]);
grade->setCourseId(title[1]);
grade->setGrade(title[2]);
addGrade(connection, *grade);
}
}
printf("成功导入grade.txt文件!\n");
inFile.close();
}