27 #ifndef CORE_METADATA_DB_H 28 #define CORE_METADATA_DB_H 73 void init(
const std::vector<MDLabel> &labelsVector);
84 int n,
int part,
size_t mdSize,
88 size_t n,
size_t part,
105 const std::vector<MDLabel> &labelsLeft,
106 const std::vector<MDLabel> &labelsRight,
114 void _clear(
bool onlyData=
false);
117 const std::vector<MDLabel> *desiredLabels)
override;
123 const std::vector<MDLabel> *desiredLabels,
bool firstTime)
override;
145 MetaDataDb(
const std::vector<MDLabel> &labelsVector);
175 void clear()
override;
197 void writeText(
const FileName fn,
const std::vector<MDLabel>* desiredLabels)
const override;
235 bool getRowValues(
size_t id, std::vector<MDObject> &values)
const override;
248 return MetaData::getColumnValues<T>(label);
277 std::unique_ptr<MDRow>
getRow(
size_t id)
override;
278 std::unique_ptr<const MDRow>
getRow(
size_t id)
const override;
285 bool getAllRows(std::vector<MDRowSql> &rows)
const;
297 void addRows(
const std::vector<MDRowSql> &rows);
303 size_t size()
const override;
345 void importObjects(
const MetaData &md,
const std::vector<size_t> &objectsToAdd,
bool doClear=
true)
override;
358 void removeObjects(
const std::vector<size_t> &toRemove)
override;
373 void addIndex(
const std::vector<MDLabel> &desiredLabels)
const;
375 void removeIndex(
const std::vector<MDLabel> &desiredLabels);
403 void findObjects(std::vector<size_t> &objectsOut,
const MDQuery &query)
const override;
404 void findObjects(std::vector<size_t> &objectsOut,
int limit = -1)
const override;
417 void _writeRows(std::ostream &os)
const override;
437 const std::vector<MDLabel> *desiredLabels= NULL,
439 bool decomposeStack=
true);
445 const std::vector<MDLabel> *desiredLabels= NULL,
447 bool decomposeStack=
true);
454 void read(
const FileName &inFile,
const std::vector<MDLabel> *desiredLabels = NULL,
bool decomposeStack=
true)
override;
496 const std::vector<MDLabel> &operateLabels,
const std::vector<MDLabel> &resultLabels);
499 const std::vector<MDLabel> &groupByLabels,
583 void join2(
const MetaDataDb &mdInLeft,
const MetaDataDb &mdInRight,
const std::vector<MDLabel> &labelsLeft,
const std::vector<MDLabel> &labelsRight,
639 void sort(
MetaDataDb &MDin,
const String &sortLabel,
bool asc=
true,
int limit=-1,
int offset=0);
652 void split(
size_t n, std::vector<MetaDataDb> &results,
661 size_t n,
size_t part,
683 template <
bool IsConst>
688 std::vector<size_t> _ids;
690 bool _finalized =
false;
694 : _mdd(mdd), _i(_i) {
695 mdd.myMDSql->selectObjects(_ids);
696 if (this->_i >= _ids.size())
699 _mdd.initGetRow(
false);
701 _mdd.execGetRow(this->_row);
702 this->_row.set_id(this->_ids[this->_i]);
703 if (this->_i+1 == _ids.size()) {
704 _mdd.finalizeGetRow();
711 _mdd.finalizeGetRow();
714 std::unique_ptr<MDBaseRowIterator<IsConst>>
clone()
override {
715 return memoryUtils::make_unique<MDDbRowIterator<IsConst>>(_mdd, _i);
719 if (this->_i >= _ids.size())
724 if (this->_i >= _ids.size())
727 this->_mdd.execGetRow(this->_row);
728 this->_row.set_id(this->_ids[this->_i]);
730 if (this->_i == _ids.size()) {
731 _mdd.finalizeGetRow();
739 return this->_i == dri->_i;
747 return {memoryUtils::make_unique<MDDbRowIterator<false>>(*
this, 0)};
750 return {memoryUtils::make_unique<MDDbRowIterator<false>>(*
this, this->
size())};
754 return {memoryUtils::make_unique<MDDbRowIterator<true>>(*
this, 0)};
757 return {memoryUtils::make_unique<MDDbRowIterator<true>>(*
this, this->
size())};
761 template <
bool IsConst>
767 std::vector<size_t> _ids;
772 : _mdd(mdd), _last(last), _pQuery(pQuery) {
773 mdd.
myMDSql->selectObjects(_ids, pQuery);
774 _i = last ? this->_ids.size() : 0;
780 return this->_i == dri->_i;
788 std::unique_ptr<MDBaseIdIterator<IsConst>>
clone()
override {
789 return memoryUtils::make_unique<MDDbIdIterator<IsConst>>(_mdd, _last, _pQuery);
794 return {memoryUtils::make_unique<MDDbIdIterator<false>>(*this)};
798 return {memoryUtils::make_unique<MDDbIdIterator<false>>(*
this,
true)};
802 return {memoryUtils::make_unique<MDDbIdIterator<true>>(*this)};
806 return {memoryUtils::make_unique<MDDbIdIterator<true>>(*
this,
true)};
824 const std::vector<MDLabel> &newLabel)
override;
850 myMDSql->tableName(myMDSql->tableId),
basic_istream< char, std::char_traits< char > > istream
static bool select(size_t rowId, sqlite3 *db, const std::string &table, std::vector< MDObject > &values)