First unit test implemented!
[emufront] / src / db / dbfilepath.cpp
index cc37e94..b75ef52 100644 (file)
@@ -31,13 +31,14 @@ DbFilePath::DbFilePath(QObject *parent) : DbQueryModelManager(parent)
     dbSetup = new DbSetup(this);
 }
 
+/* Throws EmuFrontException */
 EmuFrontObject* DbFilePath::recordToDataObject(const QSqlRecord *rec)
 {
     int id = rec->value(FilePath_Id).toInt();
     QString fpath = rec->value(FilePath_Name).toString();
     int setupId = rec->value(FilePath_SetupId).toInt();
     int fileType = rec->value(FilePath_FileTypeId).toInt();
-    Setup *sup = dynamic_cast<Setup*>(dbSetup->getDataObject(setupId));
+    Setup *sup = dynamic_cast<Setup*>(dbSetup->getDataObject(setupId)); /* Throws EmuFrontException */
        // TODO
     //int lastScanned = 0;
     return new FilePathObject(id, fpath, fileType, sup);
@@ -63,6 +64,18 @@ bool DbFilePath::updateDataObjectToModel(const EmuFrontObject *ob)
     return ret;
 }
 
+bool DbFilePath::setScanned(const EmuFrontObject *ob)
+{
+    QSqlQuery q;
+    q.prepare("UPDATE filepath SET lastscanned=:lastscanned WHERE id=:id");
+    q.bindValue(":lastscanned", getCurrentTimeStamp());
+    q.bindValue(":id", ob->getId());
+    bool ret = q.exec();
+    if (ret) resetModel();
+    return ret;
+}
+
+/* Returns id of inserted data item after succesful insert, -1 if insert failed */
 int DbFilePath::insertDataObjectToModel(const EmuFrontObject *ob)
 {
     const FilePathObject *fpo = dynamic_cast<const FilePathObject*>(ob);
@@ -99,9 +112,10 @@ bool DbFilePath::deleteDataObject(int id) const
 
 QString DbFilePath::constructSelect(QString where) const
 {
-    return QString("SELECT filepath.id AS FilePathId, "
+    return QString("SELECT "
+            "filepath.id AS FilePathId, "
             "filepath.name AS Name, "
-            "filepath.lastscanned AS LastScanned, "
+            "datetime(filepath.lastscanned, 'unixepoch') AS LastScanned, "
             "setup.id AS SetupId, "
             "platform.name || ' ' || mediatype.name AS SetupName, "
             "filepath.filetypeid "