[英]C++ Class with sqlite database
我正在使用帶有純 C++ 編碼的 Qt Creator IDE。 我需要創建一個包含 2 個成員變量 A 和 B(也在表中添加)和 3 個公共和私有函數的類。
公共函數:檢查數據庫是否存在,如果存在則打開並讀取數據A和B,否則從私有調用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 successfully\n";
else
cout<< "failed to create database\n";
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()
?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.