SQL Helper Query for C ++

I am looking for a library that will simplify working with SQL in C ++. I know that there are different ORM solutions (for example, listed here ), and I quickly looked through them, but I was probably looking for something else (not exactly ORM), so if you could help ...

I want something that will not encapsulate access to the database, etc., but will act more like a query builder and a binder, and I run the queries myself. I expect this to allow me to simplify SQL processing and, at the same time, have access to run custom queries, without necessarily remaining inside the object model.

At the moment, the closest thing I found is this Database Template Library , which allows you to define a binding as follows:

   boundIOs["INT_VALUE"]    == rowbuf.exampleInt;
   boundIOs["STRING_VALUE"] == rowbuf.exampleStr;

(the column is INT_VALUEbound to the field of the exampleIntobject), and then it launches queries using such bindings, which I find quite convenient and quite flexible at the same time.

I will definitely get to know this library more closely, but maybe you can also offer another library / framework that uses similar ideas and is more popular / mature / supported, etc., or share your experience with this DTL library? Thank.

+3
source share
2 answers

, , , ORM. DTL SQL-, .

0

OTL prety, ORM.

/ .

otl_stream i(50, // buffer size
              "select * from test_tab where f1>=:f<int>" // SELECT statement,
              db // connect object
             ); 
i<<8; // assigning :f = 8

//execute query
while(!i.eof()){ // while not end-of-data
    i>>f1>>f2;
    cout<<"f1="<<f1<<", f2="<<f2<<endl;
}

, ,

otl_stream i(50, // buffer size
              "select * from test_tab where f1>=:f<int> AND f2=:g<int> and f3=:h<int> and f4=:i<int>" // SELECT statement,
              db // connect object
             ); 
i << 8 << 10 << 12 << 42;

//execute query
while(!i.eof()){ // while not end-of-data
    i>>f1>>f2;
    cout<<"f1="<<f1<<", f2="<<f2<<endl;
}

, f1>=:f<int> AND f2=:g<int>. ( typeafe) .

+1
source

Source: https://habr.com/ru/post/1787488/


All Articles