c++ - POCO::PostgreSQL:如何将 std::vector 支持添加到`Binder::bind`?
问题描述
我想把结构像
struct Person{
int age;
std::string name;
std::vector<std::string> links;
};
进入 psql 表:
CREATE TABLE persons (
age integer,
name text,
links text[]
);
如何将 std::vector 支持添加到 Poco::PostgreSQL 中?
看一下绑定方法:
void Binder::bind(std::size_t /*pos*/, const std::vector<std::string>& /*val*/, Direction /*dir*/)
{
throw NotImplementedException();
}
我知道用于自定义的 TypeHandler,但它只是将原始类型处理到您的类中,例如 int、std::string 等。
template <>
class TypeHandler<struct CustomClass>
{}
解决方案
这是这样做的:
std::vector<Person> persons;
ses << "SELECT NAME FROM NAME", into(persons), now;
您应该阅读 Poco Data 用户指南,因为它包含大量信息并在此处包含您的答案。它还告诉您一些不要做的事情,因此值得一读。
推荐阅读
- git - 无法获取所有 git 分支
- php - 使用 x509 证书登录
- python - Python Pandas 中的距离矩阵
- python - Python 模块导入
- c# - 如何在 C# 中创建泛型方法以返回多个列表
- c# - 从 SQL 数据库中删除未连接的节点
- php - 在 Codeigniter 3 中使用 Google 日历
- rx-java2 - 为什么 IoScheduler 使用 ScheduledExecutorService 且 poolCoreSize 为 1?
- javascript - 在浏览器上,有没有办法以编程方式为 iCal 创建日历事件,而无需创建 .ics 文件并手动下载?
- javascript - 如何在javascript中的多个不同数组中查找值