AFAIK,我们都必须通过数据库包装器/管理器(如sqliteman或CppSQLite)对数据库进行编程。通用数据库管理器(包装)
但是,数据库包装是特定于一种类型的数据库,这对程序员不方便,因为在数据库被卡住的情况下需要很多修改。
因此,我想写一个通用的数据库包装,可以与各种数据库接口。
我创建了一个类模板,如下所示。
template<typename T>
class ClsDatabaseManager
{
public:
// Pure Virtual Function
// All derived classes must implements it and forward the call
// appropriate database wrapper
connect(string);
disconnect(string);
Execute(string);
CreateTable(string);
CreateDatabase(string);
private:
T m_table;
T m_database;
};
class sqliteManager : public ClsDatabaseManager<T>
{
// Implement all the function by forward the call
};
因此,我将使用traits根据提供的模板参数获取信息类型。
此模板参数是从此基类派生的类类型,如sqlite,postgresql和mysql。
所以,对我的设计有任何建议或建议。
如何创建通用数据库接口并将调用转发到特定的数据库接口库。
编辑:
什么是ODBC和C++的数据库访问库(索契)之间的不同?
请帮忙。
谢谢。
除了Soci,您还可以检查SQLAPI ++。 SQLAPI ++不是免费的。 – 2010-10-12 12:27:00
感谢您的评论。 – peterwkc 2010-10-14 02:10:57