// Library // // Douglas Thrift // // $Id$ #include #include #include "Library.hpp" Library::Library(const _R& connection) : connection(connection) { connection->Execute(_B("UPDATE files SET live = FALSE")); } _L Library::GetFolders() const { _R roots(connection->Execute(_B("SELECT DISTINCT root FROM files WHERE live = TRUE ORDER By root"))); _L folders; while (roots->MoveNext()) folders.InsertLast(GetFolder(roots->GetString(_B("root")))); return folders; } _L Library::GetFiles(const _L& bys, const _L& items) const { if (bys.IsEmpty() || ext::Contains(bys, By::LAST) || bys.GetSize() != items.GetSize()) return _L(); _S statement_; statement_ << _B("SELECT path FROM files WHERE live = TRUE "); _foreach (const _L, by, bys) statement_ << _B("AND ") << by << _B(" = ? "); _rforeach (const _L, by, bys) statement_ << _B(by + 1 == _set.End() ? "ORDER BY " : ", ") << *by; _R statement(connection->Parse(statement_)); _foreach (const _L, item, items) statement->Set(_index, *item); _R paths(statement->Execute()); _L files; while (paths->MoveNext()) files.InsertLast(GetFile(paths->GetString(_B("path")))); return files; } _L Library::GetItems(_L bys, _L items) const { if (bys.IsEmpty() || ext::Contains(bys, By::LAST) || bys.GetSize() - 1 != items.GetSize()) return _L(); _S statement_; By by(bys.Last()); statement_ << _B("SELECT DISTINCT ") << by << _B(" FROM files WHERE live = TRUE "); bys.RemoveLast(); _foreach (const _L, by_, bys) statement_ << _B("AND ") << *by_ << _B(" = ? "); statement_ << _B("ORDER BY ") << by; _rforeach (const _L, by_, bys) statement_ << _B(", ") << *by_; _R statement(connection->Parse(statement_)); _foreach (const _L, item, items) statement->Set(_index, *item); _R items_(statement->Execute()); items.Clear(); while (items_->MoveNext()) items.InsertLast(items_->GetString(by)); return items; }