The problem of ten was fixed
Hooray!!!!!
This commit is contained in:
parent
3a61512ae9
commit
d6b7af2244
@ -161,12 +161,23 @@ void MainWindow::deleteRecord()
|
|||||||
int MainWindow::getRecordsCount(){
|
int MainWindow::getRecordsCount(){
|
||||||
query->clear();
|
query->clear();
|
||||||
qDebug() << "query->clear();";
|
qDebug() << "query->clear();";
|
||||||
query->prepare("SELECT MAX(r.id) AS 'number_of_records' FROM records AS 'r';");
|
query->prepare("SELECT * FROM records");
|
||||||
query->exec();
|
query->exec();
|
||||||
|
QSqlRecord rec = query->record();
|
||||||
query->next();
|
query->next();
|
||||||
QString count = QString::number(query->value(0).toInt() + 1);
|
|
||||||
|
|
||||||
return count.toInt();
|
int max = query->value(rec.indexOf("id")).toInt();
|
||||||
|
int cur = max;
|
||||||
|
while(query->next())
|
||||||
|
{
|
||||||
|
cur = query->value(rec.indexOf("id")).toInt();
|
||||||
|
if(max < cur)
|
||||||
|
{
|
||||||
|
max = cur;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
qDebug() << "max" << max;
|
||||||
|
return max;
|
||||||
}
|
}
|
||||||
void MainWindow::connectToDatabase(const QString &dbName)
|
void MainWindow::connectToDatabase(const QString &dbName)
|
||||||
{
|
{
|
||||||
@ -347,10 +358,10 @@ void MainWindow::addRecordSlot(Record *r)
|
|||||||
// qDebug() << "id: " << getRecordsCount();
|
// qDebug() << "id: " << getRecordsCount();
|
||||||
|
|
||||||
qDebug() << "id here:";
|
qDebug() << "id here:";
|
||||||
r->setId(ui->tableViewRecords->model()->rowCount() + 1);
|
// r->setId(ui->tableViewRecords->model()->rowCount() + 1);
|
||||||
// r->setId(ui->tableViewRecords->selectionModel()->selection().indexes().at(0).row());
|
// r->setId(ui->tableViewRecords->selectionModel()->selection().indexes().at(0).row());
|
||||||
qDebug() << "id here:";
|
qDebug() << "id here:";
|
||||||
|
r->setId(getRecordsCount()+1);
|
||||||
putRecord(r);
|
putRecord(r);
|
||||||
qDebug() << "id here:";
|
qDebug() << "id here:";
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user