From 8f4fa2966a0398658721eba1390ef2054dffb56c Mon Sep 17 00:00:00 2001 From: cxl Date: Wed, 8 Oct 2014 12:00:06 +0000 Subject: [PATCH] CtrlLib: ValueMap ArrayCtrl::GetMap git-svn-id: svn://ultimatepp.org/upp/trunk@7760 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CtrlLib/ArrayCtrl.cpp | 11 +++++++++++ uppsrc/CtrlLib/ArrayCtrl.h | 1 + uppsrc/CtrlLib/src.tpp/ArrayCtrl$en-us.tpp | 6 ++++++ uppsrc/Sql/SqlStatement.cpp | 11 +++++++++-- uppsrc/Sql/Sqlexp.h | 9 ++++++--- 5 files changed, 33 insertions(+), 5 deletions(-) diff --git a/uppsrc/CtrlLib/ArrayCtrl.cpp b/uppsrc/CtrlLib/ArrayCtrl.cpp index 0f4d5760b..69a6e5670 100644 --- a/uppsrc/CtrlLib/ArrayCtrl.cpp +++ b/uppsrc/CtrlLib/ArrayCtrl.cpp @@ -1952,6 +1952,17 @@ void ArrayCtrl::AddMap(const ValueMap& m) SetMap(array.GetCount(), m); } +ValueMap ArrayCtrl::GetMap(int i) const +{ + ValueMap m; + for(int j = 0; j < GetIndexCount(); j++) { + String id = ~GetId(j); + if(id.GetCount()) + m(id, Get(i, j)); + } + return m; +} + void ArrayCtrl::SetArray(int i, const ValueArray& va) { Set(i, va.Get()); diff --git a/uppsrc/CtrlLib/ArrayCtrl.h b/uppsrc/CtrlLib/ArrayCtrl.h index 31be6d812..625b9ff39 100644 --- a/uppsrc/CtrlLib/ArrayCtrl.h +++ b/uppsrc/CtrlLib/ArrayCtrl.h @@ -467,6 +467,7 @@ public: void SetMap(int i, const ValueMap& m); void AddMap(const ValueMap& m); + ValueMap GetMap(int i) const; void SetArray(int i, const ValueArray& va); void AddArray(const ValueArray& va); diff --git a/uppsrc/CtrlLib/src.tpp/ArrayCtrl$en-us.tpp b/uppsrc/CtrlLib/src.tpp/ArrayCtrl$en-us.tpp index aa7b336c1..732b56efb 100644 --- a/uppsrc/CtrlLib/src.tpp/ArrayCtrl$en-us.tpp +++ b/uppsrc/CtrlLib/src.tpp/ArrayCtrl$en-us.tpp @@ -1832,6 +1832,12 @@ that are not found are ignored, those found are assigned correspoding map values.&] [s3; &] [s4;%- &] +[s5;:ArrayCtrl`:`:GetMap`(int`)const:%- [_^ValueMap^ ValueMap]_[* GetMap]([@(0.0.255) int]_ +[*@3 i])_[@(0.0.255) const]&] +[s2; Returns row as map of row Ids to row values. Only non`-empty +row Ids are added.&] +[s3; &] +[s4;%- &] [s5;:ArrayCtrl`:`:Add`(const Value`&`[`,const Value`&`]`.`.`.`):%- [@(0.0.255) void]_[* A dd]([@(0.0.255) const]_[_^Value^ Value][@(0.0.255) `&]_`[, [@(0.0.255) const]_[_^Value^ Val ue][@(0.0.255) `&]_`]...)&] diff --git a/uppsrc/Sql/SqlStatement.cpp b/uppsrc/Sql/SqlStatement.cpp index 42796a932..08e286ef6 100644 --- a/uppsrc/Sql/SqlStatement.cpp +++ b/uppsrc/Sql/SqlStatement.cpp @@ -145,6 +145,7 @@ SqlSelect& SqlSelect::Hint(const char *hint) SqlSelect& SqlSelect::Get() { text = "select " + text + SqlCase(ORACLE, " from DUAL")(""); + valid = true; return *this; } @@ -153,6 +154,7 @@ SqlSelect& SqlSelect::From(const SqlSet& table) { return Get(); String ts = table(SqlSet::SETOP + 1); text = "select " + text + " from " + ts; + valid = true; tables << ',' << Filter(ts, CharFilterNotWhitespace); on = false; return *this; @@ -161,6 +163,7 @@ SqlSelect& SqlSelect::From(const SqlSet& table) { SqlSelect& SqlSelect::From(const SqlId& table) { const String& t1 = table.ToString(); text = String().Cat() << "select " << text << " from \t" << t1 << '\t'; + valid = true; tables << ',' << t1; on = false; return *this; @@ -170,6 +173,7 @@ SqlSelect& SqlSelect::From(const SqlId& table1, const SqlId& table2) { const String& t1 = table1.ToString(); const String& t2 = table2.ToString(); text = String().Cat() << "select " << text << " from \t" << t1 << "\t, \t" << t2 << '\t'; + valid = true; tables << ',' << t1 << ',' << t2; on = false; return *this; @@ -180,6 +184,7 @@ SqlSelect& SqlSelect::From(const SqlId& table1, const SqlId& table2, const SqlId const String& t2 = table2.ToString(); const String& t3 = table3.ToString(); text = String().Cat() << "select " << text << " from \t" << t1 << "\t, \t" << t2 << "\t, \t" << t3 << '\t'; + valid = true; tables << ',' << t1 << ',' << t2 << ',' << t3; on = false; return *this; @@ -267,7 +272,7 @@ SqlSet SqlSelect::AsTable(const SqlId& tab) const SqlSelect::SqlSelect(Fields f) { - on = false; + valid = on = false; SqlSet set(f); text = ~set; } @@ -276,7 +281,7 @@ SqlSelect::SqlSelect(Fields f) #define E__QSqlSelectF(I) \ SqlSelect::SqlSelect(__List##I(E__SqlVal)) { \ - on = false; \ + valid = on = false; \ SqlSet set; \ __List##I(E__SCat); \ text = ~set; \ @@ -368,6 +373,8 @@ SqlDelete& SqlDelete::Where(const SqlBool& b) { return *this; } +// ------------------------------- + void SqlInsert::Column(const SqlId& column, SqlVal val) { set1.Cat(column); set2.Cat(val); diff --git a/uppsrc/Sql/Sqlexp.h b/uppsrc/Sql/Sqlexp.h index 9f79cc863..970b0a8ae 100644 --- a/uppsrc/Sql/Sqlexp.h +++ b/uppsrc/Sql/Sqlexp.h @@ -538,7 +538,7 @@ public: class SqlSelect { String text; String tables; - bool on; + bool on, valid; SqlSelect& InnerJoin0(const String& table); SqlSelect& LeftJoin0(const String& table); @@ -600,10 +600,13 @@ public: operator SqlStatement() const { return SqlStatement(text); } SqlVal AsValue() const; SqlSet AsTable(const SqlId& tab) const; + + void Set(const SqlSet& s) { text = ~s; on = valid = false; } + bool IsValid() const { return valid; } SqlSelect(Fields f); - SqlSelect(const SqlSet& s) { text = ~s; on = false; } - SqlSelect() { on = false; } + SqlSelect(const SqlSet& s) { Set(s); } + SqlSelect() { on = valid = false; } #define E__QSelect(I) SqlSelect(__List##I(E__SqlVal)); __Expand(E__QSelect); #undef E__QSelect