//*********************************************************** //* This will take a <tag> node and parse out the values. //*********************************************************** void ImportData::processTagNode() { Tag tag; bool tagIsDirty = false; bool atEnd = false; // Loop through until we are at the end of the </tag> while(!atEnd) { if (backup || importTags) { if (reader->isStartElement()) { QString name = reader->name().toString().toLower(); if (name == "guid") { tag.guid = textValue().toStdString(); tag.__isset.guid = true; } if (name == "name") { tag.name = textValue().toStdString(); tag.__isset.name = true; } if (name == "updatesequencenumber") { tag.updateSequenceNum = intValue(); tag.__isset.updateSequenceNum =true; } if (name == "parentguid") { tag.parentGuid = textValue().toStdString(); tag.__isset.parentGuid = true; } if (name == "Dirty") { if (booleanValue()) tagIsDirty = true; else tagIsDirty = false; } } } reader->readNext(); QString endName = reader->name().toString().toLower(); if (endName == "tag" && reader->isEndElement()) atEnd = true; } // We have a good tag, now let's save it to the database TagTable tagTable; QString name(tag.name.c_str()); // Check if we have a tag by this name already. If we // do then we treat this as an update. qint32 lid = tagTable.findByName(name,0); if (lid == 0) lid = tagTable.getLid(tag.guid); if (lid == 0) tagTable.add(0, tag,tagIsDirty, 0); else { tagTable.sync(lid, tag, 0); tagTable.setDirty(lid,tagIsDirty); } return; }
bool NoteTable::updateNoteList(qint32 lid, Note &t, bool isDirty) { NotebookTable notebookTable; qint32 notebookLid = notebookTable.getLid(t.notebookGuid); Notebook notebook; notebookTable.get(notebook, notebookLid); // Now let's update the user table QSqlQuery query; query.prepare("Delete from NoteTable where lid=:lid"); query.bindValue(":lid", lid); query.exec(); query.prepare(QString("Insert into NoteTable (lid, title, author, ") + QString("dateCreated, dateUpdated, dateSubject, dateDeleted, source, sourceUrl, sourceApplication, ") + QString("latitude, longitude, altitude, hasEncryption, hasTodo, isDirty, size, notebook, notebookLid, tags) ") + QString("Values (:lid, :title, :author, ") + QString(":dateCreated, :dateUpdated, :dateSubject, :dateDeleted, :source, :sourceUrl, :sourceApplication, ") + QString(":latitude, :longitude, :altitude, :hasEncryption, :hasTodo, :isDirty, :size, :notebook, :notebookLid, :tags) ")) ; query.bindValue(":lid", lid); if (t.__isset.title) query.bindValue(":title", QString::fromStdString(t.title)); else query.bindValue(":title", ""); if (t.__isset.attributes && t.attributes.__isset.author) query.bindValue(":author", QString::fromStdString(t.attributes.author)); else query.bindValue(":author", ""); if (t.__isset.created) query.bindValue(":dateCreated", QVariant::fromValue(t.created)); else query.bindValue(":dateCreated", 0); if (t.__isset.updated) query.bindValue(":dateUpdated", QVariant::fromValue(t.updated)); else query.bindValue(":dateUpdated", 0); if (t.__isset.attributes && t.attributes.__isset.subjectDate) query.bindValue(":dateSubject", QVariant::fromValue(t.attributes.subjectDate)); else query.bindValue(":dateSubject", 0); if (t.__isset.deleted) query.bindValue(":dateDeleted", QVariant::fromValue(t.deleted)); else query.bindValue(":dateDeleted", 0); if (t.__isset.attributes && t.attributes.__isset.source) query.bindValue(":source", QString::fromStdString(t.attributes.source)); else query.bindValue(":source", ""); if (t.__isset.attributes && t.attributes.__isset.sourceURL) query.bindValue(":sourceUrl", QString::fromStdString(t.attributes.sourceURL)); else query.bindValue(":sourceUrl", ""); if (t.__isset.attributes && t.attributes.__isset.sourceApplication) query.bindValue(":sourceApplication", QString::fromStdString(t.attributes.sourceApplication)); else query.bindValue(":sourceApplication", ""); if (t.__isset.attributes && t.attributes.__isset.latitude) query.bindValue(":latitude", QVariant::fromValue(t.attributes.latitude)); else query.bindValue(":latitude", 0); if (t.__isset.attributes && t.attributes.__isset.longitude) query.bindValue(":longitude", QVariant::fromValue(t.attributes.longitude)); else query.bindValue(":longitude", 0); if (t.__isset.attributes && t.attributes.__isset.altitude) query.bindValue(":altitude", QVariant::fromValue(t.attributes.altitude)); else query.bindValue(":altitude", 0); bool hasEncryption; if (t.content.find("<en-crypt") != string::npos) hasEncryption = true; else hasEncryption = false; query.bindValue(":hasEncryption", hasEncryption); bool hasTodo; if (t.content.find("<en-todo") != string::npos) hasTodo = true; else hasTodo = false; query.bindValue(":hasTodo", hasTodo); query.bindValue(":isDirty", isDirty); qlonglong size = t.content.length(); for (unsigned int i=0; i<t.resources.size(); i++) { size+=t.resources[i].data.size; } query.bindValue(":size", size); query.bindValue(":notebook", QString::fromStdString(notebook.name)); query.bindValue(":notebookLid", notebookLid); QString tagNames; QStringList sortedNames; for (unsigned int i=0; i<t.tagNames.size(); i++) { sortedNames.append(QString::fromStdString(t.tagNames.at(i)).toLower()); } sortedNames.sort(); TagTable tagTable; LinkedNotebookTable linkedTable; qint32 account = 0; notebookLid = notebookTable.getLid(t.notebookGuid); if (linkedTable.exists(notebookLid)) account = notebookLid; for (int i=0; i<sortedNames.size(); i++) { if (i>0) tagNames = tagNames+", "; Tag currentTag; qint32 tagLid = tagTable.findByName(sortedNames[i], account); tagTable.get(currentTag, tagLid); tagNames = tagNames + QString::fromStdString(currentTag.name); } query.bindValue(":tags", tagNames); if (!query.exec()) { QLOG_ERROR() << "Error inserting into NoteTable: " << query.lastError(); return false; } return true; }