bool MySqlCtrl::savePatient(RecordTitle* record, double* acr, int* character) { CString save, path; path.Format("picture/%s/%s%s.jpg", record->userName, record->patientName, record->checkTime); save.Format("update patientList set \ acr0 = %.2f ,acr1 = %.2f ,acr2 = %.2f ,acr3 = %.2f ,noise = %.2f ,length0 = %.2f ,length1 = %.2f ,\ character0 = %d ,character1 = %d ,character2 = %d ,local = %d ,path = '%s' \ where doctor = '%s' and patientName = '%s' and checkTime = '%s' ", \ acr[0], acr[1], acr[2], acr[3], acr[4], acr[5], acr[6], \ character[0], character[1], character[2], character[3], character[4], path, \ record->userName, record->patientName, record->checkTime); int nResult = sqlite3_exec(sql, save, NULL, NULL, NULL); if (nResult != 0) { //上传失败 return false; } else { //上传成功 return true; } }这段代码为什么不能正常执行?有bug吗
时间: 2023-07-02 12:10:26 浏览: 54
这段代码是使用了SQLite,但是其中的路径格式字符串和SQL语句格式字符串中存在语法错误。具体来说,路径格式字符串中的反斜杠“\”应该被转义,因为它是一个转义字符,应该写成“\\”,而SQL语句格式字符串中的换行符“\n”也应该被转义,应该写成“\\n”。正确的代码如下:
```
bool MySqlCtrl::savePatient(RecordTitle* record, double* acr, int* character) {
CString save, path;
path.Format("picture/%s/%s%s.jpg", record->userName, record->patientName, record->checkTime);
save.Format("update patientList set acr0 = %.2f, acr1 = %.2f, acr2 = %.2f, acr3 = %.2f, noise = %.2f, length0 = %.2f, length1 = %.2f, character0 = %d, character1 = %d, character2 = %d, local = %d, path = '%s' where doctor = '%s' and patientName = '%s' and checkTime = '%s'",
acr[0], acr[1], acr[2], acr[3], acr[4], acr[5], acr[6],
character[0], character[1], character[2], character[3], character[4], path,
record->userName, record->patientName, record->checkTime);
int nResult = sqlite3_exec(sql, save, NULL, NULL, NULL);
if (nResult != 0) {
//上传失败
return false;
}
else {
//上传成功
return true;
}
}
```
另外,还需要确保SQLite数据库已经正确打开,且`sql`变量已经初始化。如果有其他问题,可以提供更多的信息。