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