C++ SQL 项目查询内部数据结构

C++ SQL project to query internal data structures

我有一个 C++ class:

class Car {

 string name; //name of the car
 int year; // year it was made
 string color; //an int representing color
 int price;  // how much does it cost
 string country; // country of origin
 etc...

};

class 是接受输入并创建此 class 实例的服务器进程的一部分。

那个实例是我的内存汽车数据库。所以我的问题是: 是否有任何通用 SQL C++ 项目将 car-db 和查询字符串以及 returns 结果作为输入?

比如"select * from mydata where color=green and price>10000",应该return一个"pointer"到第二个和第四个元素。

如果我答对了你的问题,你正在寻找支持内存中数据处理的关系数据库和 SQL?

在这种情况下,您应该看看 SQLite, which implements In-Memory Databases and a decent, reasonably standard-compliant SQL subset. It provides a C-style API 开箱即用,做得很好并且被广泛使用。

对于 C++ API,您可以查看符合您要求的 Qt, if that's an option for your use case, or search for an ORM。甚至围绕 DB 句柄实现您自己的 OO 包装器也是一种选择(去过那里,做过)。