views:

140

answers:

3

Suppose I have a collection of C++ objects in memory and would like to query them using an SQL statement. I’m willing to implement some type of interface to expose the objects’ properties like columns of a database row. Is there a library available to accomplish this? In essence, I’m trying to accomplish something like LINQ without using the .NET platform.

A: 

I have also been searching for something of this sort, but it seems the SQLlite is the closest I can find.

Extrakun
+2  A: 

C++ objects are not the same thing as SQL tables.

If you want to use SQL syntax to query the objects, you will first need to map/persist them into a table structure (ORM, object-relational-mapping). There are a number of fine ORM solutions out there besides Linq.

Once you have your objects represented in SQL tables, you should look to the SQL engine to do the heavy lifting. Most SQL platforms can be configured to keep a table mostly or always in memory.

As an alternative, you might consider a system specifically designed to cache objects. On Linux, memcached is a leading choice.

Eric J.
I have used SQLite for some projects successfully. MySQL also has completely in-memory table types.
Eric J.
A: 

There is a pitfall between the object world and entity-relational data (ER). Its called Object-relational impedance mismatch. Basicaly it means You need to "map" object concepts to relational database concepts which is called Object-relational mapping (ORM).

Example for Polymorphism: a derived class is not an ER concept so you need to say for example all attributes from all object belonging to the same class will be stored in the same table with all the "parents" attributes OR a derived class (object) will be stored in the same table as the abstract class from which it is derived from.

It would be probably best to use a comunity supported ORM, but when the motives are right your company can benefit having your own ORM solution.

In our company we developed our own ORM solution (started 6 years ago so it was written in c++ and the modeller was a windows desktop application). But now we would probably use ADO.NET Entity Framework (LINQ's "big" brother) or another supported ORM

Erv