带有sqlite数据库的C++类
C++ Class with sqlite database
我使用的是纯c++编码的Qt创建者IDE。我需要创建一个包含2个成员变量a&B(也添加在表中)和3个公共和私人功能。
公共函数:检查数据库是否存在,如果存在则打开并读取数据A&B从private调用这3个函数。第二个函数是生成一个26个字符的数组并存储在25位数字中。使用srand()
返回它-getA()
。第三个函数是采用sha256散列串接第二个函数+时间戳-getB()
。
私有函数:创建一个sqlite数据库,初始化一个基本的表结构(char a|char B|blob C)。第三个函数是生成详细信息,存储到数据库和a&B.从该函数调用getA()
和getB()
以生成详细信息。
代码:
class Init {
char AppID[50];
char AppCode[50];
//create sqlite database
int DbInit() {
sqlite3 *db;
if(sqlite3_open("Init.db", &db))
cout<<"opened database successfullyn";
else
cout<< "failed to create databasen";
return 0;
}
//initialize table
int tableGen() {
string query = "CREATE TABLE tableInit(AppID TEXT(25), AppCode TEXT(60),Cert BLOB)";
sqlite3_stmt *stmnt;
cout<< "creating table statement"<<endl;
sqlite3_prepare(db, query.c_str() , query.size(), &stmnt, NULL );
if(sqlite3_step(stmnt) !=SQLITE_DONE)
cout<< "didnt create table"<<endl;
}
//generate details to store to database and also into member functions.
int AppGen() {
both getappid and get appcode is called to generate details.
}
public:
Init() {}
//check whether database exists if exists read data else call the private functions .
bool start() {
int rc = sqlite3_open("Init.db", &db, SQLITE_OPEN_READONLY);
if(rc = SQLITE_OK) {
sqlite3_stmt *statement;
sqlite3_prepare(db,"SELECT AppID,AppCode FROM tableInit",-1,&statement,0);
sqlite3_step(statement);
}
else
Init::DbInit();
Init::tablegen();
Init::AppGen();
}
// generate appid
int GetAppID() {
generate a 25 digit number and store it in an array using rand()
}
//take sha256 hash concating appid + time-stamp
int getcode() {
}
如何定义appgen()
、appid()
和code()
?
我认为这个示例会有所帮助http://www.tutorialspoint.com/sqlite/sqlite_c_cpp.htm
相关文章:
- 查询SQLite数据库中的日期
- 有没有一种方法可以创建一个带有哈希表的数据库,该哈希表具有恒定时间查找功能
- 如何在ArangoDb AQL查询中指定数据库
- 从数据库实时显示QT c++中的数据
- 使用 pqxx 将 std::vector 存储在 postgresql 中,并从数据库中检索它
- 无法在C++中建立与MySQL数据库的连接
- 将类实现到数据库程序中
- 连接 dockerized 模型和 dockerized 数据库时出现"无法 SQLConnect"错误
- C++应用程序 MySQL odbc 数据库连接错误:在引发"otl_tmpl_exception<>"实例后终止调用
- 调试编译的服务器在数据库打开时崩溃
- C++变量mysql_query到数据库
- LMDB:在有限的内存系统中打开大型数据库
- 如何在多个线程中创建 QSql数据库连接时防止名称冲突
- 以只读模式打开数据库时SQLITE_CANTOPEN错误
- 如何使用SQLite将数据库中的值导出为C / C++中的字符串或字符?
- 如何在Qt中从数据库中检索二进制数据?
- 如何从网站获取数据并将其传输到数据库?
- 在装有 CLion 的 Mac 上使用 C++ 连接到 MySQL 数据库时出现问题
- Qt5 从 MySQL 数据库中选择数据
- 当我不需要数据库中的所有值时,如何部分初始化 c++ 对象?