sqlite에 대한 좋은 OO C ++ 래퍼는 무엇입니까
sqlite에 대한 좋은 객체 지향 C ++ (C와 반대) 래퍼를 찾고 싶습니다. 사람들은 무엇을 추천합니까? 여러 가지 제안 사항이있는 경우 투표를 위해 별도의 회신에 넣으십시오. 또한 제안한 포장지에 대한 경험이 있는지, 그리고 어떻게 사용했는지 알려주십시오.
이것은 정말로 반대 투표를 초대하지만 여기에 있습니다 ...
C ++에서 직접 sqlite를 사용하고 추가 된 C ++ 추상화 레이어로 값이 표시되지 않습니다. 있는 그대로 매우 훌륭하고 효율적입니다.
C ++의 데이터베이스를위한 또 다른 좋은 래퍼는 SOCI 입니다. OO는 아니지만 더 현대적인 C ++입니다.
Oracle, PostgreSQL 및 MySQL을 지원합니다. SQLite는 백엔드는 CVS에 있습니다 .
나는이 게시물을 읽고 답변에 언급 된 라이브러리 중 일부를 시도했지만
그들 중 어느 것도 나를 위해 충분히 쉬웠습니다 (저는 게으른 프로그래머입니다!).
그래서 나는 내 자신의 래퍼를 썼다 : sqlite modern cpp
database db("dbfile.db");
// executes the query and creates a 'user' table if not exists
db << "create table if not exists user ("
" age int,"
" name text,"
" weight real"
");";
// inserts a new user and binds the values to '?' marks
db << "insert into user (age,name,weight) values (?,?,?);"
<< 20
<< "bob"
<< 83.0;
// slects from table user on a condition ( age > 18 ) and executes
// the lambda for every row returned .
db << "select age,name,weight from user where age > ? ;"
<< 18
>> [&](int age, string name, double weight) {
cout << age << ' ' << name << ' ' << weight << endl;
};
// selects the count(*) of table user
int count = 0;
db << "select count(*) from user" >> count;
즐기세요!
한동안 업데이트되지 않았지만 Mac OS GCC 4.3에서 컴파일 및 실행되는 것이 있습니다. 또한 MIT 라이선스에 따라 출시되었으므로 문제없이 상용 프로젝트에 사용할 수 있습니다. http://code.google.com/p/sqlite3pp/
사용법이 향상되고 매우 깨끗합니다.
sqlite3pp::database db("test.db");
sqlite3pp::transaction xct(db);
{
sqlite3pp::command cmd(db, "INSERT INTO contacts (name, phone) VALUES (:user, :phone)");
cmd.bind(":user", "Mike");
cmd.bind(":phone", "555-1234");
cmd.execute();
}
xct.rollback();
참조 : http://code.google.com/p/sqlite3pp/wiki/UsagePage
Qt 사용-전체 디자인에 잘 맞는 SQLite에 대한 훌륭한 바인딩이 있습니다.
나는 또한 내가 찾을 수있는 것에 만족하지 않았다. 이제 다음과 같이 작성할 수 있습니다.
class Person {
public:
Person() {}
static SqlTable<Person>& table() {
static SqlTable<Person> tab = SqlTable<Person>::sqlTable("Person",
SqlColumn<Person>("Firstname", makeAttr(&Reservation::firstname)),
SqlColumn<Person>("Lastname", makeAttr(&Reservation::lastname)),
SqlColumn<Person>("Age", makeAttr(&Reservation::age)),
return tab;
}
std::string firstname;
std::string lastname;
int age;
};
SqliteDB db("testtable.db");
auto sel(db.select<Person>("Firstname=\"Danny\" and Lastname=\"Zeckzer\""));
std::for_each(sel.first, sel.second, [](const Person& p) {
...
Person me;
db.insert<Person>(me);
...
std::vector<Person> everybody;
db.insert<Person>(everybody.begin(), everybody.end());
The table method is all you need to write as long as you stick to the sqlite3 data types. As everything is a template not much abstraction layer code remains after -O. Natural joins require a result class similar to the Person class. The implementation is a single header with less than 500 lines. License is LGPL. Source
I wasn't pleased with any I could find either, so I wrote my own: sqlite3cc.
Here's a code example:
sqlite::connection db( filename );
sqlite::command c( db, "UPDATE foo SET bar = ? WHERE name = ?" );
c << 123 << name << sqlite::exec;
sqlite::query q( db, "SELECT foo FROM bar" );
for( sqlite::query::iterator i = q.begin(); i != q.end(); i++ )
std::cout << i->column< std::string >( 0 ) << "\n";
http://www.codeproject.com/KB/database/CppSQLite.aspx is just fantastic, it is very easy to port, I had it working on bcb5 (omg) in half an hour or so. It is about as thin as you can get and easy to understand. There are a goodly number of examples that cover just about every thing you need to know. It uses exceptions for error handling - I modified it to provide return codes in a mater of minutes. Only tricky issue is to create your own lib file none are provided.
try
{
CppSQLite3DB db;
db.open(asFileName.c_str());
db.execDML("Update data set hrx = 0");
} // try
catch (...)
{
} // catch
Could not be much simpler than this.....
Everyone have given good advice on what to use: I'll tell you what instrument NOT use.
My experience is terrible.
I'm just doing some reasearch on what orm use, and I'm testing a lot of it.
Weaknesses:
- no documentation
- no explanatory README
- no explanation on prerequisites
- do not compile due to a lot of bug (isn't true, isn't fixed in v0.3.17)
I've used this one http://www.codeproject.com/KB/database/CppSQLite.aspx but I've moved to C#, so there may be newer/better ones now
Perhaps you can take a look at
or
Another simple one is NLDatabase. Disclaimer: I'm the author. Basic usage (and to be honest, you won't get much more than "basic" from this one) looks like this:
#include "NLDatabase.h"
using namespace std;
using namespace NL::DB;
int main(int argc, const char * argv[]) {
Database db( "test.sqlite" );
auto results = db.query("SELECT * FROM test WHERE name <> ?").select("TOM");
for ( auto const & row : results ) {
cout << "column[0]=" << row.column_string( 0 ) << endl;
}
}
And just for fun, open a database, run a query and fetch results all in one line:
for ( auto & row : Database( "test.sqlite" ).query( "SELECT * FROM test").select() ) {
cout << row.column_string( 0 ) << endl;
}
I made one because of the need in our company. https://www.github.com/rubdos/libsqlitepp It's C++11, and header only. Just put the header in your project, include it and link to the C sqlite libraries.
Examples should be somewhere on that git repo too, fairly easy to use.
Oracle/OCI/ODBC Template Library
This library is brilliant.
There are Windows and Linux versions of the library available and I was up and running in minutes.
Do you have successfully ported it for mingw-3.4.5? Will you share the ported version?
Thx.
http://www.codeproject.com/KB/database/CppSQLite.aspx is just fantastic, it is very easy to port, I had it working on bcb5 (omg) in half an hour or so. It is about as thin as you can get and easy to understand. There are a goodly number of examples that cover just about every thing you need to know. It uses exceptions for error handling - I modified it to provide return codes in a mater of minutes. Only tricky issue is to create your own lib file none are provided.
참고URL : https://stackoverflow.com/questions/120295/what-is-a-good-oo-c-wrapper-for-sqlite
'IT Share you' 카테고리의 다른 글
ng-pattern을 사용하여 angularjs에서 이메일 ID를 확인하는 방법 (0) | 2020.12.14 |
---|---|
응답과 함께 http 상태 코드를 반환하는 Curl (0) | 2020.12.14 |
Python의 목록에서 일부 값의 첫 번째와 마지막 색인 찾기 (0) | 2020.12.14 |
jQuery를 설치 하시겠습니까? (0) | 2020.12.14 |
메인 문서의 JavaScript에서 IFrame의 문서 가져 오기 (0) | 2020.12.14 |