SelectQuery selectObjectQuery(const std::vector<FieldType>& fdatas, const Expr& e) { SelectQuery sel; Split tables; std::set<LITESQL_String> tableSet; for (size_t i = 0; i < fdatas.size(); i++) if (tableSet.find(fdatas[i].table()) == tableSet.end()) { tables.push_back(fdatas[i].table()); tableSet.insert(fdatas[i].table()); } Split tableFilters; tableFilters.resize(tables.size()-1); for (size_t i = 1; i < tables.size(); i++) tableFilters[i-1] = tables[i-1] + LITESQL_L(".id_ = ") + tables[i] + LITESQL_L(".id_"); tableSet.clear(); for (size_t i = 0; i < tables.size(); i++) { sel.source(tables[i]); tableSet.insert(tables[i]); } if (tables.size() > 1) sel.where((e && RawExpr(tableFilters.join(LITESQL_L(" AND ")))).asString()); else sel.where(e.asString()); for (size_t i = 0; i < fdatas.size(); i++) sel.result(fdatas[i].table() + LITESQL_L(".") + fdatas[i].name()); return sel; }
void Persistent::update(Updates& updates) { for (Updates::iterator i = updates.begin(); i != updates.end(); i++) { UpdateQuery uq(i->first); uq.where(RawExpr(LITESQL_L("id_ = '") + toString(oldKey) + LITESQL_L("'"))); bool notEmpty = false; for (std::vector<std::pair<FieldType, LITESQL_String> >::iterator i2 = i->second.begin(); i2 != i->second.end(); i2++) { uq.set(i2->first, i2->second); notEmpty = true; } if (notEmpty) db->query(uq); } }
UpdateQuery& UpdateQuery::where(const Expr& e) { _where = (RawExpr(_where) && e).asString(); return *this; }