]> ToastFreeware Gitweb - toast/confclerk.git/blobdiff - src/orm/ormrecord.h
This at least partly fixes #42 ("fun with time zones").
[toast/confclerk.git] / src / orm / ormrecord.h
index 054c200e35d4712aabc7b945999bbc160e86f2df..73541e2baa5a78ac1f5e6b17d4c3844deb97a48f 100644 (file)
@@ -1,20 +1,21 @@
 /*
  * Copyright (C) 2010 Ixonos Plc.
+ * Copyright (C) 2011-2012 Philipp Spitzer, gregor herrmann
  *
- * This file is part of fosdem-schedule.
+ * This file is part of ConfClerk.
  *
- * fosdem-schedule is free software: you can redistribute it and/or modify it
+ * ConfClerk is free software: you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the Free
  * Software Foundation, either version 2 of the License, or (at your option)
  * any later version.
  *
- * fosdem-schedule is distributed in the hope that it will be useful, but
+ * ConfClerk is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
  * You should have received a copy of the GNU General Public License along with
- * fosdem-schedule.  If not, see <http://www.gnu.org/licenses/>.
+ * ConfClerk.  If not, see <http://www.gnu.org/licenses/>.
  */
 #ifndef ORMRECORD_H
 #define ORMRECORD_H
@@ -92,8 +93,8 @@ T OrmRecord<T>::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 <typename T>
 void OrmRecord<T>::update(QString col, QVariant value)
@@ -105,7 +106,6 @@ void OrmRecord<T>::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();
 }
 
@@ -150,10 +150,6 @@ QList<T> OrmRecord<T>::load(QSqlQuery query)
             qDebug() << "Error: " << query.lastError().driverText() << "; Type: " << query.lastError().type();
             throw OrmSqlException(query.lastError().text());
         }
-        else
-        {
-            /*qDebug() << "SQL OK";*/
-        }
     }
 
     QList<T> objects;
@@ -161,7 +157,6 @@ QList<T> OrmRecord<T>::load(QSqlQuery query)
     {
         objects << hydrate(query.record());
     }
-    /*qDebug() << "Fetch done";*/
     return objects;
 }
 
@@ -220,7 +215,9 @@ QVariant OrmRecord<T>::convertToDb(QVariant value, QVariant::Type colType)
 {
     if (colType == QVariant::DateTime && value.canConvert<QDateTime>())
     {
-        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;