提问人:gatcheca 提问时间:2/28/2023 最后编辑:gatcheca 更新时间:2/28/2023 访问量:104
如何在 SQL C++ 中插入 blob 数据
how to insert blob data in sql c++
问:
我是 C++ 的新手。我正在尝试在sql xampp phpmyadmin中插入bmp图像加载blob图像。
当前故障代码:Blob 图像存储为 .bin 文件,该文件是不可读的错误格式文件。
期望工作:Blob 图像应存储为文件 .txt 应以字符串形式存储 blob 图像,如 BM6 等(每个都有 3 到 4 个字符)。
下面是以错误的文件格式 (.bin) 将 blob 图像 (.bmp) 保存在数据库中的代码,不可读
QPixmap p;
p.load(filename);
string a ="/root/QtApplication_1/file";
string b =boost::lexical_cast<std::string>(counter);
string c = ".bmp";
p.save(("/root/QtApplication_1/file"+boost::lexical_cast<std::string(counter)+".bmp").c_str(),"BMP");
std::string d = a + b + c ;
std::ifstream blob_file;
blob_file.open(d.c_str(),std::ios_base::binary | std::ifstream::in);
driver = get_driver_instance();
con=driver>connect("localhost","","");
con->setSchema("BitmapImagesSchema");
prep_stmt = con->prepareStatement("Insert into bitmapImagesTable(`ID`,`ImageDir`,`ImagesBitMap`) values(?,?,?)");
prep_stmt->setInt(1,counter);
prep_stmt->setString(2,d.c_str());
prep_stmt->setBlob(3,&blob_file);
prep_stmt->executeQuery();
delete prep_stmt;
如何存储为文件 .txt 应该以字符串的形式存储 blob 图像,如 BM6 等(每个都有 3 到 4 个字符)?
这是 blob 数据库,它是 .bin 文件不起作用?
答: 暂无答案
评论