void NoteBook::update(NoteBookUpdates updates) { if (guid.isEmpty()) { if (!updates.contains(T_GUID)) return; guid = updates[T_GUID].toString(); editField(T_GUID); } if (updates.contains(T_NAME)) { name = updates[T_NAME].toString(); editField(T_NAME); } if (updates.contains(T_DEFAULT)) { defaultNotebook = updates[T_DEFAULT].toBool(); editField(T_DEFAULT); } if (updates.contains(T_CREATED)) { serviceCreated = updates[T_CREATED].toDateTime(); editField(T_CREATED); } if (updates.contains(T_UPDATED)) { serviceUpdated = updates[T_UPDATED].toDateTime(); editField(T_UPDATED); } if (updates.contains(T_STACK)) { stack = updates[T_STACK].toString(); editField(T_STACK); } toSQL(); }
// ---------------------------------------------------------------------------- int main(int argc, char * argv[]) { std::fstream fs; fs.open("Project2Data.txt"); ProdInfo pi; // The current product info that is being dealt with. while (!fs.eof()) { StringVect lines; pi.Reset(); // Read the head lines. if (read_n_lines(fs, HEAD_LINES, lines) != HEAD_LINES) { // We run out of lines. Just break. std::cerr << "Not enough head lines." << std::endl; break; } // Parse the lines. StringPair sp; split_to_pair(rm_carriage(lines[0]), sp); pi.id = trim(sp.second); split_to_pair(rm_carriage(lines[1]), sp); pi.asin = trim(sp.second); split_to_pair(rm_carriage(lines[2]), sp); pi.title = trim(sp.second); split_to_pair(rm_carriage(lines[3]), sp); pi.group = trim(sp.second); // Read the categories. split_to_pair(lines[4], sp); int category_count = str_to_int(trim(sp.second)); if (read_n_lines(fs, category_count, lines) != category_count) { // We run out of lines. Just break. std::cerr << "Not enough category lines." << std::endl; break; } for (size_t i = 0; i < lines.size(); ++i) { pi.categories.push_back(trim(rm_carriage(lines[i]))); } // Write the product info into a SQL statement. std::cout << toSQL(pi) << std::endl; // Skip the blank lines. read_n_lines(fs, SEP_LINES, lines); } fs.close(); return 0; }
QString NoteBook::createNewNotebook(QString notebookName) { guid = newGUID("notebooks", "guid"); name = notebookName; stack = ""; serviceCreated = QDateTime::currentDateTime(); serviceUpdated = QDateTime::currentDateTime(); editField(T_GUID); editField(T_NAME); editField(T_STACK); editField(T_CREATED); editField(T_UPDATED); toSQL(); return guid; }
String IDbConnection::sql_remove(const String &table, const String &f1, const String &v1, const String &f2, const String &v2) const { return _S("delete from ") + escape(table) + _S(" where ") + escape(f1) + _S(" = ") + toSQL(v1) + _S(" and ") + escape(f2) + _S(" = ") + toSQL(v2); }
String IDbConnection::sql_remove(const String &table, const String &field, const String &value) const { return _S("delete from ") + escape(table) + _S(" where ") + escape(field) + _S(" = ") + toSQL(value); }
void NoteBook::sync() { qDebug() << "NoteBook::sync()"; bool ok; QByteArray result = EdamProtocol::GetInstance()->getNetworkManager()->postData(EdamProtocol::GetInstance()->getNoteStoreUri(), createPushContentPost(), ok); if (!ok) return; TBinaryProtocol *bin = new TBinaryProtocol(result); QString name; TMessageType messageType; qint32 seqid; bin->readMessageBegin(name, messageType, seqid); if (messageType == T_EXCEPTION){ qDebug() << "Error:" << "checkVersion failed: unknown result"; return; } qDebug() << name << messageType << seqid; hash data = bin->readField(); delete bin; if (!data.contains(0)) { qDebug() << "KLAIDA!" << data.keys(); } if (name.toLower() == "createnotebook") { QString oldGuid = guid; loadFromData(data[0].value<hash>()); QSqlQuery query; query.prepare("UPDATE notes SET notebookGuid=:notebookGuid WHERE notebookGuid=:oldGuid"); query.bindValue(":notebookGuid", guid); query.bindValue(":oldGuid", oldGuid); query.exec(); query.clear(); query.prepare("UPDATE syncStatus SET value=:guid WHERE option=:option AND value=:oldGuid"); query.bindValue(":guid", QString("notebook@%1").arg(guid)); query.bindValue(":oldGuid", QString("notebook@%1").arg(oldGuid)); query.bindValue(":option", "selNotebook"); query.exec(); query.clear(); query.prepare("DELETE FROM notebooks WHERE guid=:oldGuid"); query.bindValue(":oldGuid", oldGuid); query.exec(); } else updateSequenceNum = data[0].toInt(); toSQL(); if (updateSequenceNum > 0) EdamProtocol::GetInstance()->getSyncEngine()->updateUSN(updateSequenceNum); QSqlQuery query; query.prepare("DELETE FROM notebookUpdates WHERE guid=:guid"); query.bindValue(":guid", guid); query.exec(); }