2014-02-13 33 views
0

我正在使用Qt Creator IDE進行純C++編碼。我需要創建一個包含2個成員變量A & B(也添加在表中)的類以及3個公共和私有函數。使用sqlite數據庫的C++類

公共職能:檢查數據庫是否存在,是否存在打開並讀取數據A否否否則從私有調用3個函數。第二個功能是生成一個26個字符的數組並存儲在25位數字中。使用srand()返回它 - getA()。第三個函數是採用sha256散列級聯第二個函數+時間戳 - getB()。私有函數:創建一個sqlite數據庫,初始化一個基本的表結構(char A | char B | blob C)。第3個函數用於生成存儲到數據庫的細節,也可以用於A B. )並且getB()被這個函數調用來生成細節。

CODE:

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()?

+0

我已經創建了成員變量的類中定義的functions.I我堅持與SQLite數據庫的一部分... – AMZZ

+0

感謝Vasim爲編輯... – AMZZ

+1

你堅持什麼? – UldisK

回答