Make sure database models are synchronized before using QSqlTableModel::rowCount()

This is necessary  as the cached model will not  reflect a correct row
count if there are un-fetched rows.
This commit is contained in:
Bill Somerville 2019-01-21 13:35:18 +00:00
parent ff1d3efab4
commit 12b6efb189
2 changed files with 39 additions and 4 deletions

View File

@ -46,10 +46,25 @@ CabrilloLog::impl::impl (Configuration const * configuration)
}
SQL_error_check (dupe_query_, &QSqlQuery::prepare,
"SELECT COUNT(*) FROM cabrillo_log WHERE call = :call AND band = :band");
"SELECT "
" COUNT(*) "
" FROM "
" cabrillo_log "
" WHERE "
" call = :call "
" AND band = :band");
SQL_error_check (export_query_, &QSqlQuery::prepare,
"SELECT frequency, \"when\", exchange_sent, call, exchange_rcvd FROM cabrillo_log ORDER BY \"when\"");
"SELECT "
" frequency"
" , \"when\""
" , exchange_sent"
" , call"
" , exchange_rcvd"
" FROM "
" cabrillo_log "
" ORDER BY "
" \"when\"");
setEditStrategy (QSqlTableModel::OnFieldChange);
setTable ("cabrillo_log");
@ -138,6 +153,8 @@ bool CabrilloLog::dupe (Frequency frequency, QString const& call) const
void CabrilloLog::reset ()
{
// synchronize model
while (m_->canFetchMore ()) m_->fetchMore ();
if (m_->rowCount ())
{
m_->setEditStrategy (QSqlTableModel::OnManualSubmit);

View File

@ -46,10 +46,26 @@ FoxLog::impl::impl (Configuration const * configuration)
}
SQL_error_check (dupe_query_, &QSqlQuery::prepare,
"SELECT COUNT(*) FROM fox_log WHERE call = :call AND band = :band");
"SELECT "
" COUNT(*) "
" FROM "
" fox_log "
" WHERE "
" call = :call "
" AND band = :band");
SQL_error_check (export_query_, &QSqlQuery::prepare,
"SELECT band, \"when\", call, grid, report_sent, report_rcvd FROM fox_log ORDER BY \"when\"");
"SELECT "
" band"
" , \"when\""
" , call"
" , grid"
" , report_sent"
" , report_rcvd "
" FROM "
" fox_log "
" ORDER BY "
" \"when\"");
setEditStrategy (QSqlTableModel::OnFieldChange);
setTable ("fox_log");
@ -141,6 +157,8 @@ bool FoxLog::dupe (QString const& call, QString const& band) const
void FoxLog::reset ()
{
// synchronize model
while (m_->canFetchMore ()) m_->fetchMore ();
if (m_->rowCount ())
{
m_->setEditStrategy (QSqlTableModel::OnManualSubmit);