Skip to content

Commit

Permalink
More errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
textbrowser committed Oct 22, 2022
1 parent 6a122bc commit 9dbe0b8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 21 deletions.
29 changes: 24 additions & 5 deletions Source/biblioteq_batch_activities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ void biblioteq_batch_activities::borrow(void)
continue;
}

QString error("");
QString type("");

if(category && category->currentText() == tr("Book"))
Expand All @@ -168,11 +169,20 @@ void biblioteq_batch_activities::borrow(void)
type = "Video Game";

auto available = biblioteq_misc_functions::isItemAvailable
(m_qmain->getDB(), identifier->text(), copyIdentifier->text(), type);
(error,
m_qmain->getDB(),
identifier->text(),
copyIdentifier->text(),
type);

if(!available)
{
results->setText(tr("Item is not available for reservation."));
if(error.isEmpty())
results->setText(tr("Item is not available for reservation."));
else
results->setText
(tr("Item is not available (%1) for reservation.").arg(error));

continue;
}

Expand Down Expand Up @@ -406,9 +416,18 @@ void biblioteq_batch_activities::slotScanBorrowingTimerTimeout(void)
else if(m_ui.scan_type->currentText() == tr("Video Game"))
type = "Video Game";

copyIdentifier->setText
(biblioteq_misc_functions::
getNextCopy(field, m_qmain->getDB(), m_ui.scan->text(), type));
auto ok = true;
auto str(biblioteq_misc_functions::
getNextCopy(field,
ok,
m_qmain->getDB(),
m_ui.scan->text(),
type));

if(ok)
copyIdentifier->setText(str);
else
copyIdentifier->setText(tr("Copy not available (%1).").arg(str));
}

auto fieldItem = m_ui.borrow_table->item
Expand Down
40 changes: 25 additions & 15 deletions Source/biblioteq_misc_functions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,13 @@ QString biblioteq_misc_functions::getMemberName(const QSqlDatabase &db,
}

QString biblioteq_misc_functions::getNextCopy(QString &field,
bool &ok,
const QSqlDatabase &db,
const QString &id,
const QString &type)
{
field = "";
ok = true;

if(type.toLower().contains("grey literature") ||
type.toLower().contains("photo"))
Expand Down Expand Up @@ -446,7 +448,13 @@ QString biblioteq_misc_functions::getNextCopy(QString &field,
return query.value(0).toString();
}

return "";
if(query.lastError().isValid())
{
ok = false;
return query.lastError().text();
}
else
return QObject::tr("QSqlQuery::next() was false.");
}

QString biblioteq_misc_functions::getOID(const QString &idArg,
Expand Down Expand Up @@ -1378,14 +1386,18 @@ bool biblioteq_misc_functions::isGnome(void)
}

bool biblioteq_misc_functions::isItemAvailable
(const QSqlDatabase &db,
(QString &error,
const QSqlDatabase &db,
const QString &id,
const QString &copyId,
const QString &t,
const bool emptyCopyIdAllowed)
{
error = "";

QSqlQuery query(db);
QString querystr("");
auto available = true;
auto type(t.toLower().trimmed());

if(type == "book")
Expand All @@ -1408,9 +1420,7 @@ bool biblioteq_misc_functions::isItemAvailable
if(query.exec())
{
if(query.next())
return query.value(0).toInt() > 0;
else
return true;
available = query.value(0).toInt() > 0;
}
}
else
Expand All @@ -1432,9 +1442,7 @@ bool biblioteq_misc_functions::isItemAvailable
if(query.exec())
{
if(query.next())
return query.value(0).toInt() == 0;
else
return true;
available = query.value(0).toInt() == 0;
}
}
}
Expand All @@ -1461,9 +1469,7 @@ bool biblioteq_misc_functions::isItemAvailable
if(query.exec())
{
if(query.next())
return query.value(0).toInt() > 0;
else
return true;
available = query.value(0).toInt() > 0;
}
}
else
Expand All @@ -1485,14 +1491,18 @@ bool biblioteq_misc_functions::isItemAvailable
if(query.exec())
{
if(query.next())
return query.value(0).toInt() == 0;
else
return true;
available = query.value(0).toInt() == 0;
}
}
}

return false;
if(query.lastError().isValid())
{
available = false;
error = query.lastError().text().trimmed();
}

return available;
}

bool biblioteq_misc_functions::isRequested(const QSqlDatabase &db,
Expand Down
4 changes: 3 additions & 1 deletion Source/biblioteq_misc_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class biblioteq_misc_functions
const QString &,
QString &);
static QString getNextCopy(QString &field,
bool &ok,
const QSqlDatabase &db,
const QString &id,
const QString &type);
Expand Down Expand Up @@ -147,7 +148,8 @@ class biblioteq_misc_functions
QString &);
static bool isGnome(void);
static bool isItemAvailable
(const QSqlDatabase &db,
(QString &error,
const QSqlDatabase &db,
const QString &id,
const QString &copyId,
const QString &t,
Expand Down

0 comments on commit 9dbe0b8

Please sign in to comment.