Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/133.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 包含字符串的引号消失在C++;_C++_Database_Sqlite - Fatal编程技术网

C++ 包含字符串的引号消失在C++;

C++ 包含字符串的引号消失在C++;,c++,database,sqlite,C++,Database,Sqlite,我尝试用引号覆盖字符串,以便将其放入SQL记录中 int pictureId = picture.getId(); std::string pictureName = "\'" + picture.getName() + "\'"; std::string picturePath = "\'" + picture.getPath() + "\'"; std::string pictureCreationTime = "\'" + picture.getCreationDate() + "\'";

我尝试用引号覆盖字符串,以便将其放入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' + ");";
引号消失了
我该怎么做才能保证引号不会消失

单引号会消失,因为您所说的行会导致问题,您使用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' + ");";

您要求SQL注入。不要转义字符串,请让数据库库为您执行此操作,例如使用参数化请求。谢谢。我不明白为什么我没有注意到。