Books BookManager::getBooksByAuthor(const std::string& author) { tntdb::Statement sel = _conn.prepare( "select isbn, title, author, price" " from book" " where author like :author"); sel.set("author", '%' + author + '%'); Books books; for (tntdb::Statement::const_iterator cur = sel.begin(); cur != sel.end(); ++cur) { tntdb::Row r = *cur; books.push_back(Book()); Book& book = books.back(); r[0].get(book._isbn); r[1].get(book._title); r[2].get(book._author); r[3].get(book._price); } return books; }
void BookCollection::addDescription(BookDescriptionPtr description) { if (description.isNull()) { return; } AuthorPtr author = description->author(); const std::string &displayName = author->displayName(); const std::string &sortKey = author->sortKey(); std::map<AuthorPtr,Books>::iterator it = myCollection.begin(); for (; it != myCollection.end(); ++it) { AuthorPtr author1 = (*it).first; if ((author1->sortKey() == sortKey) && (author1->displayName() == displayName)) { break; } } if (it != myCollection.end()) { (*it).second.push_back(description); } else { Books books; books.push_back(description); myCollection.insert(std::pair<AuthorPtr,Books>(author, books)); myAuthors.push_back(author); } }