Search code examples
c++sqlin-memory-database

C++ SQL project to query internal data structures


I have a 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...

};

The class is part of a server process that takes input and creates instances of this class.

  • ("bmw", "2015", "red", 30000, "DE")
  • ("fiat", "2014", "green", 20000, "IT")
  • ("ford", "2012", "white", 21000, "USA")
  • ("citroen", "2011", green", 15000, "FR")

That instances are my in memory car database. So my question is: Is there any general purpose SQL C++ project that takes as input the car-db and a query string and returns results?

For example "select * from mydata where color=green and price>10000", should return a "pointer" to the second and fourth elements.


Solution

  • If I get your question right you're looking for a relational database supporting in-memory data handling and SQL?

    In this case you should look at SQLite, which implements In-Memory Databases and a decent, reasonably standard-compliant SQL subset. It provides a C-style API out of the box, is well done and widely used.

    For C++ APIs you can look at Qt, if that's an option for your use case, or search for an ORM that fits your requirements. Even implementing your own OO wrapper around a DB handle is an option (been there, done that).