X-Git-Url: https://git.toastfreeware.priv.at/toast/confclerk.git/blobdiff_plain/cf385cd48bf81614855d79a85853bc2d9b990c02..080dc7d603d45ba0662aa731418993ddd45b5fe8:/src/orm/ormrecord.h diff --git a/src/orm/ormrecord.h b/src/orm/ormrecord.h index 4f5828d..32a4d5e 100644 --- a/src/orm/ormrecord.h +++ b/src/orm/ormrecord.h @@ -1,6 +1,6 @@ /* * Copyright (C) 2010 Ixonos Plc. - * Copyright (C) 2011 Philipp Spitzer, gregor herrmann + * Copyright (C) 2011-2024 Philipp Spitzer, gregor herrmann, Stefan Stahl * * This file is part of ConfClerk. * @@ -27,12 +27,13 @@ #include #include #include +#include -class OrmException +class OrmException: public std::runtime_error { public: - OrmException(const QString& text) : mText(text) {} - virtual ~OrmException(){} + OrmException(const QString& text) : std::runtime_error(text.toStdString()), mText(text) {} + virtual ~OrmException() throw() {} virtual const QString& text() const { return mText; } private: QString mText; @@ -41,15 +42,15 @@ private: class OrmNoObjectException : public OrmException { public: - OrmNoObjectException() : OrmException("No object exception"){} - ~OrmNoObjectException(){} + OrmNoObjectException() : OrmException("SQL query expects one record but found none."){} + ~OrmNoObjectException() throw() {} }; class OrmSqlException : public OrmException { public: OrmSqlException(const QString& text) : OrmException( QString("Sql error: ") + text ) {} - ~OrmSqlException(){} + ~OrmSqlException() throw() {} }; template @@ -93,8 +94,8 @@ T OrmRecord::hydrate(const QSqlRecord& record) } // updates specified column 'col' -// if the value is not specified as an argument, -// it's taken from the reford itself +// if the value is not specified as an argument, +// it's taken from the record itself // see also: setValue() method for more details template void OrmRecord::update(QString col, QVariant value) @@ -106,7 +107,6 @@ void OrmRecord::update(QString col, QVariant value) else // take 'col' value from the record; see setValue() query.bindValue(":col", convertToDb(this->value(col), this->value(col).type())); query.bindValue(":id", this->value("id")); - //query.bindValue(":id", convertToDb(value("id"), QVariant::Int)); query.exec(); } @@ -216,7 +216,9 @@ QVariant OrmRecord::convertToDb(QVariant value, QVariant::Type colType) { if (colType == QVariant::DateTime && value.canConvert()) { - return value.toDateTime().toTime_t(); + QDateTime dateTime = value.toDateTime(); + dateTime.setTimeSpec(Qt::UTC); // this is to avoid that dateTime.toTime_t changes the time depending on the local time zone + return dateTime.toTime_t(); } return value;