protobuf C++ SQLite handle blob data
protobuf C++ SQLite handle blob data
我有一个SQLite数据库,它有一个包含一些BLOB类型的字段的表。 我正在尝试做的是将字段(实际上所有其他字段(从数据库中获取到C++通过 protobuf 发送并接收 protobuf .
我已将 blob 字段定义为.proto
文件中的bytes
例如
message fields{
...
bytes myBlobField = 1;
}
我的 c++ 文件包含
sqlite3_initialize();
rc = sqlite3_open_v2(db_url, &db,SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,NULL);
std::ostringstream oss;
oss << "select * from attribtable ";
std::string query = oss.str();
rc = sqlite3_prepare_v2(db,query.c_str(),-1,&stmt,NULL
while(sqlite3_step(stmt) == SQLITE_ROW){
sqlite3_column_blob(stmt,10) //This is the blob field
}
如何将sqlite3_column_blob(stmt,10)
存储在C++以及如何myBlobField
使用 说reply->set_myblobfield(??)
并在客户端使用
say receive->get_myblobfield()
所以简单来说,我的问题是如何在C++应用程序中通过 protobuf 将从数据库获取的 blobfield 从服务器发送到客户端?
使用此 .proto 文件
syntax = "proto2";
package prototest;
message fields{
required bytes myBlobField = 1;
}
使用带有 Blob 指针的set_myblobfield()
调用和从 SQLite 获取的 Blob 的字节大小来初始化 Blob,然后调用SerializeToOstream()
方法将其写入流或文件。
std::ofstream myoutput("myoutput.bin");
while (sqlite3_step(stmt) == SQLITE_ROW)
{
if (size_t blobSize = sqlite3_column_bytes(stmt, 10))
{
if (const void* blob = sqlite3_column_blob(stmt, 10))
{
prototest::fields myfields;
myfields.set_myblobfield(blob, blobSize);
myfields.SerializeToOstream(&myoutput);
}
}
}
相关文章:
- 尝试通过OCI例程从Oracle获取blob数据,但出现错误:ORA-01008:并非所有变量都绑定
- 如何处理 c++ 中类实现中的"invalid use of non-static data member"?
- 'string.assign(string.data(), 5)' 是明确定义的还是 UB?
- 收到错误"invalid use of non-static data member 'stu::n' "
- C++ 初始化 .data 部分中的变量
- 模式"allocate memory or use existing data"
- boost::asio data owning `ConstBufferSequence`
- WinVerifyTrust 仅在使用文件而不是内存 blob 时才有效
- Python to C++ Data structure API
- 当初始值设定项是基类名时'initializer does not name a non-static data member or base class'错误
- protobuf C++ SQLite handle blob data
- 错误:字段'dateOfBirth'的类型不完整'Poco::Data::Date'
- 将图像魔术 blob 保存到节点缓冲区
- 为什么构造函数 Message(const T&data) 与 Message(T&& data) 冲突,当 T = int&时?
- "thread-safe data"与"thread-safe code/functions"的区别
- 如何找到目标文件 *.o 的 ram rom 使用情况(.bss .text .rodata .data)?
- 这在C++ "It does not own the underlying data, and so is cheap to copy or assign"中意味着什么
- 使用 .data() 将字符数组转换为 std::string 不会转换整个数组
- 给一个图 G 找到此图中的所有节点 blob,以便 node.color 属性 = 特定颜色
- *(int*)&data[18]在这段代码中实际上做了什么?