博客來網路書店查詢

書名

博客來網路書店查詢

星期五, 5月 27, 2016

C++與SQLite--刪除資料

int deleteRow()
{
    int rollno;
    cout << " 輸入學號 :" ;
    cin >> rollno ;
    if(cin.fail( ))
    {
      cin.clear( );
      cout<<"學號格式錯了";
      return 0;
    }
    std::stringstream strm;
    strm << "delete from student " << " where roll=" << rollno ;
    string s = strm.str();
    char *str = &s[0];
    //cout << str << endl;
    sqlite3_stmt *statement;
    int result;
    char *query = str;
    {
        if(sqlite3_prepare(dbfile,query,-1,&statement,0)==SQLITE_OK)
        {
            int res=sqlite3_step(statement);
            result=res;
            sqlite3_finalize(statement);
        }
        return result;
    }
    return 0;
}

沒有留言: