淺談Qt Sqlite 總結(jié)篇
Qt Sqlite是本文介紹的內(nèi)容,SQLite,是一款輕型的數(shù)據(jù)庫(kù),是遵守ACID的關(guān)聯(lián)式數(shù)據(jù)庫(kù)管理系統(tǒng),它的設(shè)計(jì)目標(biāo)是嵌入式的,而且目前已經(jīng)在很多嵌入式產(chǎn)品中使用了它,它占用資源非常的低,在嵌入式設(shè)備中,可能只需要幾百K的內(nèi)存就夠了。它能夠支持Windows/Linux/Unix等等主流的操作系統(tǒng),同時(shí)能夠跟很多程序語(yǔ)言相結(jié)合,比如 Tcl、C#、PHP、Java等,還有ODBC接口,同樣比起Mysql、PostgreSQL這兩款開(kāi)源世界著名的數(shù)據(jù)庫(kù)管理系統(tǒng)來(lái)講,它的處理速度比他們都快。
1.要實(shí)現(xiàn)的功能:一個(gè)表finger_table,有三個(gè)字段,pageId(INTEGER) name(text) is_empty(INTEGER)要找出 is_empty為0的記錄的個(gè)數(shù)
- QSqlQuery query;
- query.prepare("select count(pageId) from finger_table where is_empty = 0 ");//分行寫(xiě)的時(shí)候注意空格不能少
- if(!query.exec())
- {
- qDebug()<< query.lastError().text();
- return;
- }
- if(!query.first())//取出第一條記錄,這個(gè)忘了下面一條query.value(0)是執(zhí)行不了的,
- //會(huì)出現(xiàn)“QSqlQuery::value: not positioned on a valid record”錯(cuò)誤
- {
- qDebug()<<query.lastError().text();
- }
- int num = query.value(0).toInt(&ok);//這個(gè)就可以取得需要的數(shù)據(jù)了
2.表2 table2 有三個(gè)字段 id(INTEGER PRIMARY KEY) name(text) time(text),用QTableView顯示要實(shí)現(xiàn)的功能是刪除 tableview中選中的當(dāng)前行
- QSqlQuery query ;
- query.prepare("delete from login_record "
- "where id = :id ");
- QModelIndex index = this->query_login_view->currentIndex();
- int idnum = this->table_model_login_history->data(this->table_model_login_history->index(index.row(),0)).toInt();
- query.bindValue(":id",idnum);
- if(!query.exec())
- {
- qDebug()<<query.lastError().text();
- return;
- }
小結(jié):關(guān)于淺談Qt Sqlite (總結(jié)篇)的內(nèi)容介紹完了,內(nèi)容不多,希望本文對(duì)你有所幫助!