覆盖字符串的引号消失了C ++

时间:2018-03-21 10:53:17

标签: c++ database sqlite

我尝试用引号覆盖字符串,以便将其放入SQL记录

int pictureId = picture.getId();
std::string pictureName = "\'" + picture.getName() + "\'";
std::string picturePath = "\'" + picture.getPath() + "\'";
std::string pictureCreationTime = "\'" + picture.getCreationDate() + "\'";

std::string TRY = "Insert Into Pictures(Id, Name, Location, Creation_Date, 
Album_id) Values(" + std::to_string(picture.getId()) + ',' + 
picture.getName() + "," + picture.getPath() + ',' + 
picture.getCreationDate() + ',' + '1' + ");";

res = sqlite3_exec(db, TRY.c_str(), nullptr, nullptr, &errMessage);

行后

std::string TRY = "Insert Into Pictures(Id, Name, Location, Creation_Date, 
Album_id) Values(" + std::to_string(picture.getId()) + ',' + 
picture.getName() + "," + picture.getPath() + ',' + 
picture.getCreationDate() + ',' + '1' + ");";

报价消失了 为报价而言,我能做些什么不会消失

1 个答案:

答案 0 :(得分:1)

单引号会在您说使用picture.getName()导致问题的行上消失,而不是使用您使用单引号创建的pictureName字符串。

int pictureId = picture.getId();
std::string pictureName = "\'" + picture.getName() + "\'";
std::string picturePath = "\'" + picture.getPath() + "\'";
std::string pictureCreationTime = "\'" + picture.getCreationDate() + "\'";

std::string TRY = "Insert Into Pictures(Id, Name, Location, Creation_Date, 
Album_id) Values(" + std::to_string(pictureId ) + ',' + 
pictureName  + "," + picturePath + ',' + 
pictureCreationTime + ',' + '1' + ");";