c++ - 如何将 std::set 中的值流式传输到 MySQL C++ 连接器 setBlob() 中?

标签 c++ mysql mysql-connector istream

在 C++ 中: 我有一个 std::set of integers

在 MySQL 中: 我有一个带有 blob 列的表


我想将整数流式传输到 blob 列中,但我不确定该怎么做

编辑: 忘了提到我需要确保整数被打包为小端 DWORD

最佳答案

我不熟悉你正在使用的 MySQL 库,但如果它使用的是 istream,那么它看起来像这样:

void PutInt(istream &stream, int value)
{
  uint8_t byte[4];

  // converting to little-endian 32bits (DWORD size)
  byte[0] = value; 
  byte[1] = value >> 8;
  byte[2] = value >> 16;
  byte[3] = value >> 24;

  // write to stream
  for (int i = 0 ;i < 4; i++)
    stream>>byte[i];
}

void PutSet(istream &stream, std::set<int> &some_set)
{
  std::set<int>::iterator it;

  for (it = some_set.begin(); it != some_set.end(); it ++)
    PutInt(stream,(*it));
}

关于c++ - 如何将 std::set 中的值流式传输到 MySQL C++ 连接器 setBlob() 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5424892/

相关文章:

c++ - 如何使用 include <algorithm> 中的 STL max 用于用户定义的数据类型

c++ - 使用 "cout"在 Windows 对话框中显示消息 - C++

php - 语法错误或访问冲突 : 1055 Expression #17 in group by

c++ - Jenkins 测试报告分析器与 catch 的集成

c++ - 如何使用户定义的空默认构造函数表现得像编译器定义的空构造函数

mysql - Delphi dbexpress MySQL查询格式

mysql - SQL-连接表并检查是否存在不工作/语法不正确的内容

mysql - 编译 MariaDB Connector v1.0.5 和/或 Mysql Connection v 5.3.4

c# - 无法从 Visual Studio 2015 RC 中的 MySQL 数据库更新 EntityFramework 模型

c# - Mysql - 非常奇怪的行为 : query works locally, 但对于某些人来说不是在远程服务器上