diff --git a/uppsrc/Core/Value.cpp b/uppsrc/Core/Value.cpp index 2c6b712ff..eadfcb0f2 100644 --- a/uppsrc/Core/Value.cpp +++ b/uppsrc/Core/Value.cpp @@ -617,65 +617,6 @@ const Value& ValueMap::operator[](const Value& key) const // ---------------------------------- -#ifdef _MULTITHREADED -struct IdList : public ArrayIndex { - IdList() { Add(String()); } -}; - -ArrayIndex& Id::Ids() { - return Single(); -} - -static StaticCriticalSection s_ids; - -void Id::Set(const String& s) { - CriticalSection::Lock __(s_ids); - ndx = Ids().FindAdd(s); -} - -const String& Id::AsString(int n) { - static thread__ const String *h[1024]; - if(n < 1024) { - if(!h[n]) { - CriticalSection::Lock __(s_ids); - h[n] = &Ids()[n]; - } - return *h[n]; - } - CriticalSection::Lock __(s_ids); - return Ids()[n]; -} - -Id Id::Find(const String& s) { - CriticalSection::Lock __(s_ids); - int i = Ids().Find(s); - if(i < 0) return Id(); - return Id(i); -} -#else -struct IdList : public Index { - IdList() { Add(String()); } -}; - -Index& Id::Ids() { - return Single(); -} - -void Id::Set(const String& s) { - ndx = Ids().FindAdd(s); -} - -const String& Id::AsString(int n) { - return Ids()[n]; -} - -Id Id::Find(const String& s) { - int i = Ids().Find(s); - if(i < 0) return Id(); - return Id(i); -} -#endif - int StdValueCompare(const Value& a, const Value& b, int language) { LTIMING("StdValueCompare"); diff --git a/uppsrc/Core/Value.h b/uppsrc/Core/Value.h index 9ac3a7cc3..fe547660a 100644 --- a/uppsrc/Core/Value.h +++ b/uppsrc/Core/Value.h @@ -2,37 +2,23 @@ class Value; class Id : Moveable { - int ndx; - -#ifdef _MULTITHREADED - static ArrayIndex& Ids(); -#else - static Index& Ids(); -#endif - void Set(const String& s); + String id; public: - static Id Find(const String& s); - static const String& AsString(int n); + const String& ToString() const { return id; } + dword GetHashValue() const { return UPP::GetHashValue(id); } + bool IsNull() const { return UPP::IsNull(id); } - int AsNdx() const { return ndx; } - String ToString() const { return AsString(ndx); } - dword GetHashValue() const { return ndx; } - bool IsNull() const { return ndx == 0; } + operator const String&() const { return ToString(); } + const String& operator~() const { return ToString(); } + bool operator==(const Id& b) const { return id == b.id; } + bool operator!=(const Id& b) const { return id != b.id; } - void Serialize(Stream& s); + operator bool() const { return id.GetCount(); } - operator String() const { return ToString(); } - String operator~() const { return ToString(); } - bool operator==(Id b) const { return ndx == b.ndx; } - bool operator!=(Id b) const { return ndx != b.ndx; } - - operator bool() const { return ndx; } - - Id() { ndx = 0; } - Id(const String& s) { Set(s); } - Id(const char *s) { Set(s); } - explicit Id(int n) { ASSERT(n >= 0 && n < Ids().GetCount()); ndx = n; } + Id() {} + Id(const String& s) { id = s; } + Id(const char *s) { id = s; } }; template<> inline bool IsNull(const Date& d) { return d.year == -32768; } diff --git a/uppsrc/CtrlLib/ArrayCtrl.cpp b/uppsrc/CtrlLib/ArrayCtrl.cpp index 6a5c997af..1c3d14aad 100644 --- a/uppsrc/CtrlLib/ArrayCtrl.cpp +++ b/uppsrc/CtrlLib/ArrayCtrl.cpp @@ -295,7 +295,7 @@ const Display& ArrayCtrl::GetDisplay(int j) int ArrayCtrl::Pos(int pos) const { if(pos >= 0) return pos; - pos = idx.Find(Id(-pos)); + pos = idx.Find(id_ndx[-pos]); ASSERT(pos >= 0); return pos; } @@ -341,7 +341,7 @@ Value ArrayCtrl::Get(int ii) const { return Get0(cursor, ii); } -Value ArrayCtrl::Get(Id id) const { +Value ArrayCtrl::Get(const Id& id) const { return Get(GetPos(id)); } @@ -349,7 +349,7 @@ Value ArrayCtrl::GetOriginal(int ii) const { return Get0(cursor, ii); } -Value ArrayCtrl::GetOriginal(Id id) const { +Value ArrayCtrl::GetOriginal(const Id& id) const { return GetOriginal(GetPos(id)); } @@ -380,7 +380,7 @@ bool ArrayCtrl::IsModified(int ii) const { return false; } -bool ArrayCtrl::IsModified(Id id) const { +bool ArrayCtrl::IsModified(const Id& id) const { return IsModified(GetPos(id)); } @@ -441,7 +441,7 @@ void ArrayCtrl::Set(int ii, const Value& v) { RefreshRow(cursor); } -void ArrayCtrl::Set(Id id, const Value& v) { +void ArrayCtrl::Set(const Id& id, const Value& v) { Set(GetPos(id), v); } @@ -468,7 +468,7 @@ void ArrayCtrl::Set(int i, int ii, const Value& v) AfterSet(i); } -void ArrayCtrl::Set(int i, Id id, const Value& v) { +void ArrayCtrl::Set(int i, const Id& id, const Value& v) { Set(i, GetPos(id), v); } @@ -476,7 +476,7 @@ Value ArrayCtrl::Get(int i, int ii) const { return i == cursor ? Get(ii) : Get0(i, ii); } -Value ArrayCtrl::Get(int i, Id id) const { +Value ArrayCtrl::Get(int i, const Id& id) const { return Get(i, GetPos(id)); } @@ -941,11 +941,11 @@ ArrayCtrl::IdInfo& ArrayCtrl::IndexInfo(int i) { return idx[i]; } -ArrayCtrl::IdInfo& ArrayCtrl::IndexInfo(Id id) { +ArrayCtrl::IdInfo& ArrayCtrl::IndexInfo(const Id& id) { return idx.Get(id); } -ArrayCtrl::IdInfo& ArrayCtrl::AddIndex(Id id) { +ArrayCtrl::IdInfo& ArrayCtrl::AddIndex(const Id& id) { return idx.Add(id); } @@ -953,7 +953,7 @@ ArrayCtrl::IdInfo& ArrayCtrl::AddIndex() { return idx.Add(Id()); } -ArrayCtrl::IdInfo& ArrayCtrl::SetId(int i, Id id) { +ArrayCtrl::IdInfo& ArrayCtrl::SetId(int i, const Id& id) { while(idx.GetCount() < i + 1) idx.Add(Id()); idx.SetKey(i, id); @@ -965,7 +965,7 @@ ArrayCtrl::Column& ArrayCtrl::AddColumn(const char *text, int w) { return AddColumnAt(idx.GetCount() - 1, text, w); } -ArrayCtrl::Column& ArrayCtrl::AddColumn(Id id, const char *text, int w) { +ArrayCtrl::Column& ArrayCtrl::AddColumn(const Id& id, const char *text, int w) { AddIndex(id); return AddColumnAt(idx.GetCount() - 1, text, w); } @@ -981,7 +981,7 @@ ArrayCtrl::Column& ArrayCtrl::AddColumnAt(int pos, const char *text, int w) { return m; } -ArrayCtrl::Column& ArrayCtrl::AddColumnAt(Id id, const char *text, int w) { +ArrayCtrl::Column& ArrayCtrl::AddColumnAt(const Id& id, const char *text, int w) { header.Add(text, w); Column& m = column.Add(); m.arrayctrl = this; @@ -1012,7 +1012,7 @@ int ArrayCtrl::FindColumnWithPos(int pos) const return -1; } -int ArrayCtrl::FindColumnWithId(Id id) const +int ArrayCtrl::FindColumnWithId(const Id& id) const { return FindColumnWithPos(GetPos(id)); } @@ -1023,7 +1023,7 @@ ArrayCtrl::IdInfo& ArrayCtrl::AddCtrl(Ctrl& ctrl) { return f; } -ArrayCtrl::IdInfo& ArrayCtrl::AddCtrl(Id id, Ctrl& ctrl) { +ArrayCtrl::IdInfo& ArrayCtrl::AddCtrl(const Id& id, Ctrl& ctrl) { IdInfo& f = AddIndex(id); AddCtrlAt(idx.GetCount() - 1, ctrl); return f; @@ -1037,8 +1037,8 @@ void ArrayCtrl::AddCtrlAt(int ii, Ctrl& ctrl) { ctrl <<= Null; } -void ArrayCtrl::AddCtrlAt(Id id, Ctrl& ctrl) { - AddCtrlAt(-id.AsNdx(), ctrl); +void ArrayCtrl::AddCtrlAt(const Id& id, Ctrl& ctrl) { + AddCtrlAt(-AsNdx(id), ctrl); } void ArrayCtrl::AddRowNumCtrl(Ctrl& ctrl) { @@ -2180,7 +2180,7 @@ int ArrayCtrl::Find(const Value& v, int ii, int i) const { return -1; } -int ArrayCtrl::Find(const Value& v, Id id, int i) const { +int ArrayCtrl::Find(const Value& v, const Id& id, int i) const { return Find(v, GetPos(id), i); } @@ -2191,7 +2191,7 @@ bool ArrayCtrl::FindSetCursor(const Value& val, int ii, int i) { return true; } -bool ArrayCtrl::FindSetCursor(const Value& val, Id id, int i) { +bool ArrayCtrl::FindSetCursor(const Value& val, const Id& id, int i) { return FindSetCursor(val, idx.Find(id), i); } @@ -2396,7 +2396,7 @@ void ArrayCtrl::Sort(int ii, int (*compare)(const Value& v1, const Value& v2)) { Sort(io); } -void ArrayCtrl::Sort(Id id, int (*compare)(const Value& v1, const Value& v2)) { +void ArrayCtrl::Sort(const Id& id, int (*compare)(const Value& v1, const Value& v2)) { Sort(idx.Find(id), compare); } @@ -2868,7 +2868,7 @@ ArrayCtrl::Column& ArrayOption::AddColumn(ArrayCtrl& ac, const char *text, int w return AddColumn(ac, Id(), text, w).NoClickEdit(); } -ArrayCtrl::Column& ArrayOption::AddColumn(ArrayCtrl& ac, Id id, const char *text, int w) +ArrayCtrl::Column& ArrayOption::AddColumn(ArrayCtrl& ac, const Id& id, const char *text, int w) { Connect(ac, ac.GetIndexCount()); return ac.AddColumn(id, text, w).SetDisplay(*this).InsertValue(f).NoClickEdit(); diff --git a/uppsrc/CtrlLib/ArrayCtrl.h b/uppsrc/CtrlLib/ArrayCtrl.h index e8688bab4..7d5d11912 100644 --- a/uppsrc/CtrlLib/ArrayCtrl.h +++ b/uppsrc/CtrlLib/ArrayCtrl.h @@ -84,8 +84,8 @@ public: public: Column& Add(int _pos) { pos.Add(_pos); return *this; } - Column& Add(Id id) { pos.Add(-id.AsNdx()); return *this; } - Column& AddIndex(Id id) { arrayctrl->AddIndex(id); return Add(id); } + Column& Add(const Id& id) { pos.Add(-arrayctrl->AsNdx(id)); return *this; } + Column& AddIndex(const Id& id) { arrayctrl->AddIndex(id); return Add(id); } Column& AddIndex() { Add(arrayctrl->GetIndexCount()); arrayctrl->AddIndex(); return *this; } Column& SetConvert(const Convert& c); @@ -191,6 +191,7 @@ private: const Order *columnsortsecondary; int min_visible_line, max_visible_line; int ctrl_low, ctrl_high; + Index id_ndx; int keypos; int cursor; @@ -307,6 +308,8 @@ private: void SyncInfo(); void SortA(); void SortB(const Vector& o); + + int AsNdx(const String& id) { return id_ndx.FindAdd(id); } public: // temporary (TRC 06/07/28) // will be removed! Ctrl& SetCtrl(int i, int j, Ctrl *newctrl) { return SetCtrl(i, j, newctrl, true, true); } @@ -345,34 +348,34 @@ public: Callback WhenSelection; IdInfo& IndexInfo(int ii); - IdInfo& IndexInfo(Id id); - IdInfo& AddIndex(Id id); + IdInfo& IndexInfo(const Id& id); + IdInfo& AddIndex(const Id& id); IdInfo& AddIndex(); int GetIndexCount() const { return idx.GetCount(); } Id GetId(int ii) const { return idx.GetKey(ii); } - int GetPos(Id id) const { return idx.Find(id); } - IdInfo& SetId(int ii, Id id); - IdInfo& AddKey(Id id) { ASSERT(idx.GetCount() == 0); return AddIndex(id); } + int GetPos(const Id& id) const { return idx.Find(id); } + IdInfo& SetId(int ii, const Id& id); + IdInfo& AddKey(const Id& id) { ASSERT(idx.GetCount() == 0); return AddIndex(id); } IdInfo& AddKey() { ASSERT(idx.GetCount() == 0); return AddIndex(); } Id GetKeyId() const { return idx.GetKey(0); } Column& AddColumn(const char *text = NULL, int w = 0); - Column& AddColumn(Id id, const char *text, int w = 0); + Column& AddColumn(const Id& id, const char *text, int w = 0); Column& AddColumnAt(int ii, const char *text, int w = 0); - Column& AddColumnAt(Id id, const char *text, int w = 0); + Column& AddColumnAt(const Id& id, const char *text, int w = 0); Column& AddRowNumColumn(const char *text, int w = 0); int GetColumnCount() const { return column.GetCount(); } int FindColumnWithPos(int pos) const; - int FindColumnWithId(Id id) const; + int FindColumnWithId(const Id& id) const; Column& ColumnAt(int i) { return column[i]; } - Column& ColumnAt(Id id) { return column[FindColumnWithId(id)]; } + Column& ColumnAt(const Id& id) { return column[FindColumnWithId(id)]; } HeaderCtrl::Column& HeaderTab(int i) { return header.Tab(i); } - HeaderCtrl::Column& HeaderTab(Id id) { return header.Tab(FindColumnWithId(id)); } + HeaderCtrl::Column& HeaderTab(const Id& id) { return header.Tab(FindColumnWithId(id)); } const Column& ColumnAt(int i) const { return column[i]; } - const Column& ColumnAt(Id id) const { return column[FindColumnWithId(id)]; } + const Column& ColumnAt(const Id& id) const { return column[FindColumnWithId(id)]; } const HeaderCtrl::Column& HeaderTab(int i) const { return header.Tab(i); } - const HeaderCtrl::Column& HeaderTab(Id id) const { return header.Tab(FindColumnWithId(id)); } + const HeaderCtrl::Column& HeaderTab(const Id& id) const { return header.Tab(FindColumnWithId(id)); } const HeaderCtrl& HeaderObject() const { return header; } HeaderCtrl& HeaderObject() { return header; } @@ -381,9 +384,9 @@ public: void SerializeSettings(Stream& s); IdInfo& AddCtrl(Ctrl& ctrl); - IdInfo& AddCtrl(Id id, Ctrl& ctrl); + IdInfo& AddCtrl(const Id& id, Ctrl& ctrl); void AddCtrlAt(int ii, Ctrl& ctrl); - void AddCtrlAt(Id id, Ctrl& ctrl); + void AddCtrlAt(const Id& id, Ctrl& ctrl); void AddRowNumCtrl(Ctrl& ctrl); void SetCount(int c); @@ -392,20 +395,20 @@ public: void Clear(); void Shrink(); Value Get(int i, int ii) const; - Value Get(int i, Id id) const; + Value Get(int i, const Id& id) const; void Set(int i, int ii, const Value& v); - void Set(int i, Id id, const Value& v); + void Set(int i, const Id& id, const Value& v); Value Get(int ii) const; - Value Get(Id id) const; + Value Get(const Id& id) const; Value GetOriginal(int ii) const; - Value GetOriginal(Id id) const; + Value GetOriginal(const Id& id) const; bool IsModified(int ii) const; - bool IsModified(Id id) const; + bool IsModified(const Id& id) const; Value GetKey() const; Value GetOriginalKey() const; void Set(int ii, const Value& v); - void Set(Id id, const Value& v); + void Set(const Id& id, const Value& v); Value GetColumn(int row, int col) const; Value GetConvertedColumn(int row, int col) const; @@ -478,10 +481,10 @@ public: void SwapDown(); int Find(const Value& v, int ii = 0, int from = 0) const; - int Find(const Value& v, Id id, int from = 0) const; + int Find(const Value& v, const Id& id, int from = 0) const; bool FindSetCursor(const Value& val, int ii = 0, int from = 0); - bool FindSetCursor(const Value& val, Id id, int from = 0); + bool FindSetCursor(const Value& val, const Id& id, int from = 0); void Sort(const ArrayCtrl::Order& order); void Sort(int from, int count, const ArrayCtrl::Order& order); @@ -490,7 +493,7 @@ public: int (*compare)(const Vector& v1, const Vector& v2)); void Sort(int ii, int (*compare)(const Value& v1, const Value& v2) = StdValueCompare); - void Sort(Id id, int (*compare)(const Value& v1, const Value& v2) + void Sort(const Id& id, int (*compare)(const Value& v1, const Value& v2) = StdValueCompare); void Sort() { Sort(0); } @@ -649,12 +652,12 @@ public: virtual void Paint(Draw& w, const Rect& r, const Value& q, Color ink, Color paper, dword style) const; void Connect(ArrayCtrl& ac, int ii = 0); - void Connect(ArrayCtrl& ac, Id id) { Connect(ac, ac.GetPos(id)); } + void Connect(ArrayCtrl& ac, const Id& id) { Connect(ac, ac.GetPos(id)); } void Disconnect(); ArrayCtrl::Column& AddColumn(ArrayCtrl& ac, const char *text = NULL, int w = 0); - ArrayCtrl::Column& AddColumn(ArrayCtrl& ac, Id id, const char *text, int w = 0); + ArrayCtrl::Column& AddColumn(ArrayCtrl& ac, const Id& id, const char *text, int w = 0); ArrayOption& TrueFalse(Value _t, Value _f) { t = _t; f = _f; return *this; } Value GetFalse() const { return f; } diff --git a/uppsrc/CtrlLib/src.tpp/ArrayCtrl$en-us.tpp b/uppsrc/CtrlLib/src.tpp/ArrayCtrl$en-us.tpp index 5bd68d48e..7ec977ef7 100644 --- a/uppsrc/CtrlLib/src.tpp/ArrayCtrl$en-us.tpp +++ b/uppsrc/CtrlLib/src.tpp/ArrayCtrl$en-us.tpp @@ -1261,16 +1261,16 @@ array index (column in the source data matrix).&] [s7; [*/ Return value]-|IdInfo reference for the given index&] [s3; &] [s4;%- &] -[s5;:ArrayCtrl`:`:IndexInfo`(Id`):%- [_^ArrayCtrl`:`:IdInfo^ IdInfo][@(0.0.255) `&]_[* Inde -xInfo]([_^Id^ Id]_[*@3 id])&] +[s5;:ArrayCtrl`:`:IndexInfo`(const Id`&`):%- [_^ArrayCtrl`:`:IdInfo^ IdInfo][@(0.0.255) `& +]_[* IndexInfo]([@(0.0.255) const ][_^Id^ Id]`&_[*@3 id])&] [s2; Returns a reference to the [* IdInfo] structure describing a given array index.&] [s7; [%-*C@3 id]-|the [* Id] index identifier&] [s7; [*/ Return value]-|IdInfo reference for the given index&] [s3; &] [s4;%- &] -[s5;:ArrayCtrl`:`:AddIndex`(Id`):%- [_^ArrayCtrl`:`:IdInfo^ IdInfo][@(0.0.255) `&]_[* AddIn -dex]([_^Id^ Id]_[*@3 id])&] +[s5;:ArrayCtrl`:`:AddIndex`(const Id`&`):%- [_^ArrayCtrl`:`:IdInfo^ IdInfo][@(0.0.255) `& +]_[* AddIndex]([@(0.0.255) const] [_^Id^ Id]`&_[*@3 id])&] [s2; Adds a new index to the array and assign it a given [* Id] identifier.&] [s7; [%-*C@3 id]-|new index identifier&] [s7; [*/ Return value]-|A reference to the [* IdInfo ]structure describing @@ -1300,16 +1300,16 @@ ordinal number).&] no identifier&] [s3; &] [s4;%- &] -[s5;:ArrayCtrl`:`:GetPos`(Id`)const:%- [@(0.0.255) int]_[* GetPos]([_^Id^ Id]_[*@3 id])_[@(0.0.255) c -onst]&] +[s5;:ArrayCtrl`:`:GetPos`(const Id`&`)const:%- [@(0.0.255) int]_[* GetPos]([@(0.0.255) cons +t ][_^Id^ Id]`&_[*@3 id])_[@(0.0.255) const]&] [s2; Returns the zero`-based positional number of the array index with a given identifier.&] [s7; [%-*C@3 id]-|array index identifier&] [s7; [*/ Return value]-|zero`-based index number, `-1 when not found&] [s3; &] [s4;%- &] -[s5;:ArrayCtrl`:`:SetId`(int`,Id`):%- [_^ArrayCtrl`:`:IdInfo^ IdInfo][@(0.0.255) `&]_[* Set -Id]([@(0.0.255) int]_[*@3 ii], [_^Id^ Id]_[*@3 id])&] +[s5;:ArrayCtrl`:`:SetId`(int`,const Id`&`):%- [_^ArrayCtrl`:`:IdInfo^ IdInfo][@(0.0.255) `& +]_[* SetId]([@(0.0.255) int]_[*@3 ii], [@(0.0.255) const ][_^Id^ Id]`&_[*@3 id])&] [s2; Sets the identifier for a given array index. This can be used to set or modify the identifier for a previously added index.&] [s7; [%-*C@3 ii]-|zero`-based ordinal number of the index to set the @@ -1320,8 +1320,8 @@ for the [/ ii]`-th index. The reference can be used to set additional properties of the altered index.&] [s3; &] [s4;%- &] -[s5;:ArrayCtrl`:`:AddKey`(Id`):%- [_^ArrayCtrl`:`:IdInfo^ IdInfo][@(0.0.255) `&]_[* AddKey]( -[_^Id^ Id]_[*@3 id])&] +[s5;:ArrayCtrl`:`:AddKey`(const Id`&`):%- [_^ArrayCtrl`:`:IdInfo^ IdInfo][@(0.0.255) `&]_ +[* AddKey]([@(0.0.255) const ][_^Id^ Id]`&_[*@3 id])&] [s2; Adds a [/ primary key] index to the table. The [/ primary key] is just another name for the first index (index with ordinal number 0). This is just a handy convention often used for SQL`-based @@ -1363,9 +1363,9 @@ the newly added column. This can be used to set additional properties for the newly added column and the corresponding header tab.&] [s3; &] [s4;%- &] -[s5;:ArrayCtrl`:`:AddColumn`(Id`,const char`*`,int`):%- [_^ArrayCtrl`:`:Column^ Column][@(0.0.255) `& -]_[* AddColumn]([_^Id^ Id]_[*@3 id], [@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 text], -[@(0.0.255) int]_[*@3 w]_`=_[@3 0])&] +[s5;:ArrayCtrl`:`:AddColumn`(const Id`&`,const char`*`,int`):%- [_^ArrayCtrl`:`:Column^ C +olumn][@(0.0.255) `&]_[* AddColumn]([@(0.0.255) const ][_^Id^ Id]`&_[*@3 id], +[@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 text], [@(0.0.255) int]_[*@3 w]_`=_[@3 0])&] [s2; Adds a new column`-index pair to the table. This is equivalent to the above two`-parameter version but, in addition, the method sets the [* Id] identifier for the newly created index.&] @@ -1389,9 +1389,9 @@ source for this column&] the newly added array column.&] [s3; &] [s4;%- &] -[s5;:ArrayCtrl`:`:AddColumnAt`(Id`,const char`*`,int`):%- [_^ArrayCtrl`:`:Column^ Colum -n][@(0.0.255) `&]_[* AddColumnAt]([_^Id^ Id]_[*@3 id], [@(0.0.255) const]_[@(0.0.255) char]_`* -[*@3 text], [@(0.0.255) int]_[*@3 w]_`=_[@3 0])&] +[s5;:ArrayCtrl`:`:AddColumnAt`(const Id`&`,const char`*`,int`):%- [_^ArrayCtrl`:`:Column^ C +olumn][@(0.0.255) `&]_[* AddColumnAt]([@(0.0.255) const ][_^Id^ Id]`&_[*@3 id], +[@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 text], [@(0.0.255) int]_[*@3 w]_`=_[@3 0])&] [s2; Adds a new column to the table and binds it to a given source data index.&] [s7; [%-*C@3 id]-|identifier of the index to use as source for the newly @@ -1443,8 +1443,9 @@ the controls.&] the newly added index&] [s3; &] [s4;%- &] -[s5;:ArrayCtrl`:`:AddCtrl`(Id`,Ctrl`&`):%- [_^ArrayCtrl`:`:IdInfo^ IdInfo][@(0.0.255) `&]_ -[* AddCtrl]([_^Id^ Id]_[*@3 id], [_^Ctrl^ Ctrl][@(0.0.255) `&]_[*@3 ctrl])&] +[s5;:ArrayCtrl`:`:AddCtrl`(const Id`&`,Ctrl`&`):%- [_^ArrayCtrl`:`:IdInfo^ IdInfo][@(0.0.255) `& +]_[* AddCtrl]([@(0.0.255) const ][_^Id^ Id]`&_[*@3 id], [_^Ctrl^ Ctrl][@(0.0.255) `&]_[*@3 ctrl +])&] [s2; Adds a new index`-control pair to the table. This is identical to the above version with the only difference that the newly added index is assigned an [* Id] identifier at the same time.&] @@ -1465,8 +1466,8 @@ this control&] index&] [s3; &] [s4;%- &] -[s5;:ArrayCtrl`:`:AddCtrlAt`(Id`,Ctrl`&`):%- [@(0.0.255) void]_[* AddCtrlAt]([_^Id^ Id]_[*@3 i -d], [_^Ctrl^ Ctrl][@(0.0.255) `&]_[*@3 ctrl])&] +[s5;:ArrayCtrl`:`:AddCtrlAt`(const Id`&`,Ctrl`&`):%- [@(0.0.255) void]_[* AddCtrlAt]([@(0.0.255) c +onst ][_^Id^ Id]`&_[*@3 id], [_^Ctrl^ Ctrl][@(0.0.255) `&]_[*@3 ctrl])&] [s2; Adds a new control to the table and binds it to the index with given identifier.&] [s7; [%-*C@3 id]-|identifier of the index to bind to this control&] @@ -1502,8 +1503,8 @@ data index.&] index as its source, `-1 when not found&] [s3; &] [s4;%- &] -[s5;:ArrayCtrl`:`:FindColumnWithId`(Id`)const:%- [@(0.0.255) int]_[* FindColumnWithId]([_^Id^ I -d]_[*@3 id])_[@(0.0.255) const]&] +[s5;:ArrayCtrl`:`:FindColumnWithId`(const Id`&`)const:%- [@(0.0.255) int]_[* FindColumnWi +thId]([@(0.0.255) const ][_^Id^ Id]`&_[*@3 id])_[@(0.0.255) const]&] [s2; Returns the zero`-based index of a column based on its source data index.&] [s7; [%-*C@3 id]-|source index identifier&] @@ -1519,8 +1520,8 @@ mnAt]([@(0.0.255) int]_[*@3 i])&] the given column&] [s3; &] [s4;%- &] -[s5;:ArrayCtrl`:`:ColumnAt`(Id`):%- [_^ArrayCtrl`:`:Column^ Column][@(0.0.255) `&]_[* Colum -nAt]([_^Id^ Id]_[*@3 id])&] +[s5;:ArrayCtrl`:`:ColumnAt`(const Id`&`):%- [_^ArrayCtrl`:`:Column^ Column][@(0.0.255) `& +]_[* ColumnAt]([@(0.0.255) const ][_^Id^ Id]`&_[*@3 id])&] [s2; Returns the [* Column] structure describing a given column.&] [s7; [%-*C@3 i]-|zero`-based column index&] [s7; [*/ Return value]-|a constant reference to the [* Column] structure @@ -1537,8 +1538,9 @@ it can be used to query properties for the column.&] the given column&] [s3; &] [s4;%- &] -[s5;:ArrayCtrl`:`:ColumnAt`(Id`)const:%- [@(0.0.255) const]_[_^ArrayCtrl`:`:Column^ Colum -n][@(0.0.255) `&]_[* ColumnAt]([_^Id^ Id]_[*@3 id])_[@(0.0.255) const]&] +[s5;:ArrayCtrl`:`:ColumnAt`(const Id`&`)const:%- [@(0.0.255) const]_[_^ArrayCtrl`:`:Column^ C +olumn][@(0.0.255) `&]_[* ColumnAt]([@(0.0.255) const ][_^Id^ Id]`&_[*@3 id])_[@(0.0.255) cons +t]&] [s2; Returns a constant reference to the [* Column] structure describing a column with given source index. This is the constant version of the above method; it can be used to query properties for the @@ -1573,16 +1575,17 @@ This can be used to set additional properties of the header column title etc.)&] [s3; &] [s4;%- &] -[s5;:ArrayCtrl`:`:HeaderTab`(Id`):%- [_^HeaderCtrl`:`:Column^ HeaderCtrl`::Column][@(0.0.255) `& -]_[* HeaderTab]([_^Id^ Id]_[*@3 id])&] +[s5;:ArrayCtrl`:`:HeaderTab`(const Id`&`):%- [_^HeaderCtrl`:`:Column^ HeaderCtrl`::Colum +n][@(0.0.255) `&]_[* HeaderTab]([@(0.0.255) const ][_^Id^ Id]`&_[*@3 id])&] [s2; Returns the [* HeaderCtrl`::Column] descriptive structure for the column bound to a given source index.&] [s7; [%-*C@3 id]-|identifier of the index used as source for the column&] [s7; [*/ Return value]-|a reference to the [* HeaderCtrl`::Column] structure&] [s3; &] [s4;%- &] -[s5;:ArrayCtrl`:`:HeaderTab`(Id`)const:%- [@(0.0.255) const]_[_^HeaderCtrl`:`:Column^ Hea -derCtrl`::Column][@(0.0.255) `&]_[* HeaderTab]([_^Id^ Id]_[*@3 id])_[@(0.0.255) const]&] +[s5;:ArrayCtrl`:`:HeaderTab`(const Id`&`)const:%- [@(0.0.255) const]_[_^HeaderCtrl`:`:Column^ H +eaderCtrl`::Column][@(0.0.255) `&]_[* HeaderTab]([@(0.0.255) const ][_^Id^ Id]`&_[*@3 id])_[@(0.0.255) c +onst]&] [s2; Returns a constant reference to the [* HeaderCtrl`::Column] descriptive structure for the column bound to a given source index.&] [s7; [%-*C@3 id]-|identifier of the index used as source for the column&] @@ -1785,8 +1788,8 @@ the minimum required memory space.&] matrix&] [s3; &] [s4;%- &] -[s5;:ArrayCtrl`:`:Get`(int`,Id`)const:%- [_^Value^ Value]_[* Get]([@(0.0.255) int]_[*@3 i], -[_^Id^ Id]_[*@3 id])_[@(0.0.255) const]&] +[s5;:ArrayCtrl`:`:Get`(int`,const Id`&`)const:%- [_^Value^ Value]_[* Get]([@(0.0.255) int]_ +[*@3 i], [@(0.0.255) const ][_^Id^ Id]`&_[*@3 id])_[@(0.0.255) const]&] [s2; Returns the value at a given location in the source data matrix. In this version, the source indices are addressed by their identifiers.&] [s7; [%-*C@3 i]-|zero`-based row number&] @@ -1808,8 +1811,8 @@ the function fails with an [* ASSERT].&] [s7; [*/ Return value]-|value at a given location in the cursor row&] [s3; &] [s4;%- &] -[s5;:ArrayCtrl`:`:Get`(Id`)const:%- [_^Value^ Value]_[* Get]([_^Id^ Id]_[*@3 id])_[@(0.0.255) c -onst]&] +[s5;:ArrayCtrl`:`:Get`(const Id`&`)const:%- [_^Value^ Value]_[* Get]([@(0.0.255) const +][_^Id^ Id]`&_[*@3 id])_[@(0.0.255) const]&] [s2; Returns the value of a given source index at the currently active cursor row. This is equivalent to [* Get(GetCursor(), id)].&] [s7; [%-*C@3 id]-|source index identifier&] @@ -1826,8 +1829,8 @@ took place.&] [s7; [*/ Return value]-|value at the given location in the cursor row&] [s3; &] [s4;%- &] -[s5;:ArrayCtrl`:`:GetOriginal`(Id`)const:%- [_^Value^ Value]_[* GetOriginal]([_^Id^ Id]_[*@3 i -d])_[@(0.0.255) const]&] +[s5;:ArrayCtrl`:`:GetOriginal`(const Id`&`)const:%- [_^Value^ Value]_[* GetOriginal]([@(0.0.255) c +onst ][_^Id^ Id]`&_[*@3 id])_[@(0.0.255) const]&] [s2; Returns the `'original`' value (i.e., without any editing changed applied) of a given source index at the currently active cursor row.&] @@ -1859,8 +1862,9 @@ nt]_[*@3 i], [@(0.0.255) int]_[*@3 ii], [@(0.0.255) const]_[_^Value^ Value][@(0. [s7; [%-*C@3 v]-|value to set to the given cell&] [s3; &] [s4;%- &] -[s5;:ArrayCtrl`:`:Set`(int`,Id`,const Value`&`):%- [@(0.0.255) void]_[* Set]([@(0.0.255) in -t]_[*@3 i], [_^Id^ Id]_[*@3 id], [@(0.0.255) const]_[_^Value^ Value][@(0.0.255) `&]_[*@3 v])&] +[s5;:ArrayCtrl`:`:Set`(int`,const Id`&`,const Value`&`):%- [@(0.0.255) void]_[* Set]([@(0.0.255) i +nt]_[*@3 i], [@(0.0.255) const ][_^Id^ Id]`&_[*@3 id], [@(0.0.255) const]_[_^Value^ Value][@(0.0.255) `& +]_[*@3 v])&] [s2; Sets the value at a given location in the source data matrix. &] [s7; [%-*C@3 i]-|zero`-based row number&] @@ -1877,8 +1881,8 @@ the value in the appropriate editor control.&] [s7; [%-*C@3 v]-|value to set&] [s3; &] [s4;%- &] -[s5;:ArrayCtrl`:`:Set`(Id`,const Value`&`):%- [@(0.0.255) void]_[* Set]([_^Id^ Id]_[*@3 id], -[@(0.0.255) const]_[_^Value^ Value][@(0.0.255) `&]_[*@3 v])&] +[s5;:ArrayCtrl`:`:Set`(const Id`&`,const Value`&`):%- [@(0.0.255) void]_[* Set]([@(0.0.255) c +onst ][_^Id^ Id]`&_[*@3 id], [@(0.0.255) const]_[_^Value^ Value][@(0.0.255) `&]_[*@3 v])&] [s2; Modifies the value at a given location in the cursor row. This overloaded version uses the [* Id] identifier to address the relevant index.&] @@ -2052,9 +2056,10 @@ is less than the second parameter ([/ v2]) according to the desired ordering.&] [s3; &] [s4;%- &] -[s5;:ArrayCtrl`:`:Sort`(Id`,int`(`*`)`(const Value`&v1`,const Value`&v2`)`):%- [@(0.0.255) v -oid]_[* Sort]([_^Id^ Id]_[*@3 id], [@(0.0.255) int]_(`*[*@3 compare])([@(0.0.255) const]_Valu -e[@(0.0.255) `&]_v1, [@(0.0.255) const]_Value[@(0.0.255) `&]_v2)_`=_StdValueCompare)&] +[s5;:ArrayCtrl`:`:Sort`(const Id`&`,int`(`*`)`(const Value`&v1`,const Value`&v2`)`):%- [@(0.0.255) v +oid]_[* Sort]([@(0.0.255) const ][_^Id^ Id]`&_[*@3 id], [@(0.0.255) int]_(`*[*@3 compare])([@(0.0.255) c +onst]_Value[@(0.0.255) `&]_v1, [@(0.0.255) const]_Value[@(0.0.255) `&]_v2)_`=_StdValueC +ompare)&] [s2; Sorts the array rows according to the given ordering predicate for the source index with a given identifier. When not explicitly specified, the [* StdValueCompare] function is used as the default @@ -2299,9 +2304,9 @@ search&] none&] [s3; &] [s4;%- &] -[s5;:ArrayCtrl`:`:Find`(const Value`&`,Id`,int`)const:%- [@(0.0.255) int]_[* Find]([@(0.0.255) c -onst]_[_^Value^ Value][@(0.0.255) `&]_[*@3 v], [_^Id^ Id]_[*@3 id], [@(0.0.255) int]_[*@3 from]_ -`=_[@3 0])_[@(0.0.255) const]&] +[s5;:ArrayCtrl`:`:Find`(const Value`&`,const Id`&`,int`)const:%- [@(0.0.255) int]_[* Find +]([@(0.0.255) const]_[_^Value^ Value][@(0.0.255) `&]_[*@3 v], [@(0.0.255) const +][_^Id^ Id]`&_[*@3 id], [@(0.0.255) int]_[*@3 from]_`=_[@3 0])_[@(0.0.255) const]&] [s2; Locates the row (using linear search beginning at the row [/ from]) in which the source index value identified by [/ id] equals [/ val]. If such a row is found, the function returns its zero`-based @@ -2328,9 +2333,9 @@ search&] none&] [s3; &] [s4;%- &] -[s5;:ArrayCtrl`:`:FindSetCursor`(const Value`&`,Id`,int`):%- [@(0.0.255) bool]_[* FindSet -Cursor]([@(0.0.255) const]_[_^Value^ Value][@(0.0.255) `&]_[*@3 val], -[_^Id^ Id]_[*@3 id], [@(0.0.255) int]_[*@3 from]_`=_[@3 0])&] +[s5;:ArrayCtrl`:`:FindSetCursor`(const Value`&`,const Id`&`,int`):%- [@(0.0.255) bool]_ +[* FindSetCursor]([@(0.0.255) const]_[_^Value^ Value][@(0.0.255) `&]_[*@3 val], +[@(0.0.255) const ][_^Id^ Id]`&_[*@3 id], [@(0.0.255) int]_[*@3 from]_`=_[@3 0])&] [s2; Locates the row (using linear search beginning at the row [/ from]) in which the source index value identified by [/ id] equals [/ val]. If such a row is found, the [* SetCursor] is called automatically @@ -2363,8 +2368,8 @@ t]_[*@3 ii])_[@(0.0.255) const]&] `= the index is in its original state&] [s3; &] [s4;%- &] -[s5;:ArrayCtrl`:`:IsModified`(Id`)const:%- [@(0.0.255) bool]_[* IsModified]([_^Id^ Id]_[*@3 i -d])_[@(0.0.255) const]&] +[s5;:ArrayCtrl`:`:IsModified`(const Id`&`)const:%- [@(0.0.255) bool]_[* IsModified]([@(0.0.255) c +onst ][_^Id^ Id]`&_[*@3 id])_[@(0.0.255) const]&] [s2; Checks a source index in the currently edited array row for changes.&] [s7; [%-*C@3 id]-|source index identifier&] @@ -2652,19 +2657,20 @@ some of which are also settable via ArrayCtrl methods.&] [s2; Adds another source data index to the list of source indices used as the data for the given output column.&] [s7; [%-*C@3 `_pos]-|zero`-based ordinal number of the source index&] -[s7; [*/ Return value]-|[* `*this]&] +[s7; [*/ Return value]-|[* `*this].&] [s3; &] [s4;%- &] -[s5;:ArrayCtrl`:`:Column`:`:Add`(Id`):%- [_^ArrayCtrl`:`:Column^ Column][@(0.0.255) `&]_[* A -dd]([_^Id^ Id]_[*@3 id])&] +[s5;:ArrayCtrl`:`:Column`:`:Add`(const Id`&`):%- [_^ArrayCtrl`:`:Column^ Column][@(0.0.255) `& +]_[* Add](const [_^Id^ Id]`&_[*@3 id])&] [s2; Adds another source data index to the list of source indices used as the data for the given output column.&] [s7; [%-*C@3 id]-|the [* Id] identifier of the source index&] [s7; [*/ Return value]-|[* `*this]&] [s3; &] +[s3; &] [s4;%- &] -[s5;:ArrayCtrl`:`:Column`:`:AddIndex`(Id`):%- [_^ArrayCtrl`:`:Column^ Column][@(0.0.255) `& -]_[* AddIndex]([_^Id^ Id]_[*@3 id])&] +[s5;:ArrayCtrl`:`:Column`:`:AddIndex`(const Id`&`):%- [_^ArrayCtrl`:`:Column^ Column][@(0.0.255) `& +]_[* AddIndex]([@(0.0.255) const]_[_^Id^ Id][@(0.0.255) `&]_[*@3 id])&] [s2; Adds another source index to the array and adds it to the list of source indices bound to this output column. The newly created index is assigned the given identifier.&] diff --git a/uppsrc/RichText/ParaData.cpp b/uppsrc/RichText/ParaData.cpp index 77914f1f8..0a7cb5b73 100644 --- a/uppsrc/RichText/ParaData.cpp +++ b/uppsrc/RichText/ParaData.cpp @@ -306,8 +306,9 @@ void RichPara::PackParts(Stream& out, const RichPara::CharFormat& chrstyle, cf = p.format; if(p.field) { out.Put(FIELD); - out.Put32(p.field.AsNdx()); - String s = p.fieldparam; + String s = ~p.field; + out % s; + s = p.fieldparam; out % s; StringStream oout; CharFormat subf = cf; @@ -522,7 +523,9 @@ void RichPara::UnpackParts(Stream& in, const RichPara::CharFormat& chrstyle, } in.Get(); Part& p = part.Top(); - p.field = Id(in.Get32()); + String id; + in % id; + p.field = id; in % p.fieldparam; String s; in % s; diff --git a/uppsrc/Sql/Sql.cpp b/uppsrc/Sql/Sql.cpp index 460412d2b..c410f692e 100644 --- a/uppsrc/Sql/Sql.cpp +++ b/uppsrc/Sql/Sql.cpp @@ -684,7 +684,7 @@ Vector SqlSession::EnumColumns(String database, String table) if(!IsNull(database)) full_name << '.'; full_name << table; - if(cursor.Execute(Select(SqlAll()).From(SqlSet(SqlCol(full_name))).Where(none))) { + if(cursor.Execute(Select(SqlAll()).From(SqlSet(SqlId(full_name))).Where(none))) { info.SetCount(cursor.GetColumns()); for(int i = 0; i < info.GetCount(); i++) info[i] = cursor.GetColumnInfo(i); diff --git a/uppsrc/Sql/SqlBool.cpp b/uppsrc/Sql/SqlBool.cpp index 7bd029aa2..1f7add422 100644 --- a/uppsrc/Sql/SqlBool.cpp +++ b/uppsrc/Sql/SqlBool.cpp @@ -87,7 +87,7 @@ SqlBool NotNull(const SqlVal& a) { } SqlBool SqlFirstRow() { - return SqlCol("ROWNUM") == 1; + return SqlId("ROWNUM") == 1; } SqlBool Like(const SqlVal& a, const SqlVal& b, bool cs) { @@ -136,11 +136,11 @@ SqlBool NotExists(const SqlSet& set) { } SqlBool LeftJoin(SqlVal v1, SqlVal v2) { - return SqlCol(~v1 + "(+)") == v2; + return SqlId(~v1 + "(+)") == v2; } SqlBool RightJoin(SqlVal v1, SqlVal v2) { - return v1 == SqlCol(~v2 + "(+)"); + return v1 == SqlId(~v2 + "(+)"); } SqlBool Join(SqlId tab1, SqlId tab2, SqlId key) { @@ -148,11 +148,11 @@ SqlBool Join(SqlId tab1, SqlId tab2, SqlId key) { } SqlBool LeftJoin(SqlId tab1, SqlId tab2, SqlId key) { - return SqlCol(~key.Of(tab1) + "(+)") == key.Of(tab2); + return SqlId(~key.Of(tab1) + "(+)") == key.Of(tab2); } SqlBool RightJoin(SqlId tab1, SqlId tab2, SqlId key) { - return key.Of(tab1) == SqlCol(~key.Of(tab2) + "(+)"); + return key.Of(tab1) == SqlId(~key.Of(tab2) + "(+)"); } END_UPP_NAMESPACE diff --git a/uppsrc/Sql/SqlSet.cpp b/uppsrc/Sql/SqlSet.cpp index d5c99a9f2..01ded37cf 100644 --- a/uppsrc/Sql/SqlSet.cpp +++ b/uppsrc/Sql/SqlSet.cpp @@ -83,7 +83,7 @@ struct FieldSqlSet : FieldOperator { SqlSet *set; virtual void Field(const char *name, Ref) { - set->Cat(SqlCol(name)); + set->Cat(SqlId(name)); } }; diff --git a/uppsrc/Sql/SqlStatement.cpp b/uppsrc/Sql/SqlStatement.cpp index 079fa3815..196ea244b 100644 --- a/uppsrc/Sql/SqlStatement.cpp +++ b/uppsrc/Sql/SqlStatement.cpp @@ -144,7 +144,7 @@ SqlSelect& SqlSelect::From(const SqlSet& table) { return *this; } -SqlSelect& SqlSelect::From(SqlId table) { +SqlSelect& SqlSelect::From(const SqlId& table) { String t1 = ~table; text = "select " + text + " from " + t1; tables << ',' << t1; @@ -152,16 +152,7 @@ SqlSelect& SqlSelect::From(SqlId table) { return *this; } -SqlSelect& SqlSelect::From(SqlCol table) -{ - String t1 = ~table; - text = "select " + text + " from " + t1; - tables << ',' << t1; - on = false; - return *this; -} - -SqlSelect& SqlSelect::From(SqlId table1, SqlId table2) { +SqlSelect& SqlSelect::From(const SqlId& table1, const SqlId& table2) { String t1 = ~table1; String t2 = ~table2; text = "select " + text + " from " + t1 + ", " + t2; @@ -170,26 +161,7 @@ SqlSelect& SqlSelect::From(SqlId table1, SqlId table2) { return *this; } -SqlSelect& SqlSelect::From(SqlCol table1, SqlCol table2) { - String t1 = ~table1; - String t2 = ~table2; - text = "select " + text + " from " + t1 + ", " + t2; - tables << ',' << t1 << ',' << t2; - on = false; - return *this; -} - -SqlSelect& SqlSelect::From(SqlId table1, SqlId table2, SqlId table3) { - String t1 = ~table1; - String t2 = ~table2; - String t3 = ~table3; - text = "select " + text + " from " + t1 + ", " + t2 + ", " + t3; - tables << ',' << t1 << ',' << t2 << ',' << t3; - on = false; - return *this; -} - -SqlSelect& SqlSelect::From(SqlCol table1, SqlCol table2, SqlCol table3) { +SqlSelect& SqlSelect::From(const SqlId& table1, const SqlId& table2, const SqlId& table3) { String t1 = ~table1; String t2 = ~table2; String t3 = ~table3; @@ -227,7 +199,7 @@ SqlSelect& SqlSelect::FullJoin0(const String& table) { return *this; } -SqlSelect& SqlSelect::InnerJoinRef(SqlId table) +SqlSelect& SqlSelect::InnerJoinRef(const SqlId& table) { InnerJoin(table); On(FindSchJoin(tables)); @@ -235,7 +207,7 @@ SqlSelect& SqlSelect::InnerJoinRef(SqlId table) return *this; } -SqlSelect& SqlSelect::LeftJoinRef(SqlId table) +SqlSelect& SqlSelect::LeftJoinRef(const SqlId& table) { LeftJoin(table); On(FindSchJoin(tables)); @@ -243,7 +215,7 @@ SqlSelect& SqlSelect::LeftJoinRef(SqlId table) return *this; } -SqlSelect& SqlSelect::RightJoinRef(SqlId table) +SqlSelect& SqlSelect::RightJoinRef(const SqlId& table) { RightJoin(table); On(FindSchJoin(tables)); @@ -251,7 +223,7 @@ SqlSelect& SqlSelect::RightJoinRef(SqlId table) return *this; } -SqlSelect& SqlSelect::FullJoinRef(SqlId table) +SqlSelect& SqlSelect::FullJoinRef(const SqlId& table) { FullJoin(table); On(FindSchJoin(tables)); @@ -270,7 +242,7 @@ SqlVal SqlSelect::AsValue() const return SqlVal(String("(").Cat() << text << ")", SqlVal::LOW); } -SqlSelect SqlSelect::AsTable(SqlId tab) const +SqlSelect SqlSelect::AsTable(const SqlId& tab) const { SqlSelect h; h.text = String("(").Cat() << text << ") as " << ~tab; @@ -315,7 +287,7 @@ SqlDelete& SqlDelete::Where(const SqlBool& b) { return *this; } -void SqlInsert::Column(SqlId column, SqlVal val) { +void SqlInsert::Column(const SqlId& column, SqlVal val) { set1.Cat(column); set2.Cat(val); if(keycolumn.IsNull()) keycolumn = column; @@ -336,7 +308,7 @@ SqlInsert::operator SqlStatement() const { return SqlStatement(s); } -SqlInsert& SqlInsert::From(SqlId from) { +SqlInsert& SqlInsert::From(const SqlId& from) { return From(SqlSet(from)); } @@ -402,7 +374,7 @@ SqlUpdate::operator SqlStatement() const { return SqlStatement(stmt); } -void SqlUpdate::Column(SqlId column, SqlVal val) { +void SqlUpdate::Column(const SqlId& column, SqlVal val) { set.Cat(SqlVal(SqlVal(column), " = ", val, SqlS::COMP)); } diff --git a/uppsrc/Sql/SqlVal.cpp b/uppsrc/Sql/SqlVal.cpp index 7ffa8f6af..04bad4cd1 100644 --- a/uppsrc/Sql/SqlVal.cpp +++ b/uppsrc/Sql/SqlVal.cpp @@ -2,43 +2,38 @@ NAMESPACE_UPP -SqlCol SqlCol::As(const char *as) const -{ - return name + SqlCase(MSSQL | PGSQL, " as ")(" ") + as; -} - -SqlCol SqlId::Of(const char *of) const +SqlId SqlId::Of(const char *of) const { return of + ('.' + ToString()); } -SqlCol SqlId::Of(SqlId id) const +SqlId SqlId::Of(SqlId id) const { return id.IsNull() ? ToString() : id.ToString() + '.' + ToString(); } -SqlCol SqlId::operator[](const SqlId& id) const +SqlId SqlId::operator[](const SqlId& id) const { return id.IsNull() ? ToString() : ToString() + '.' + id.ToString(); } -SqlCol SqlId::As(const char *as) const +SqlId SqlId::As(const char *as) const { return id.IsNull() ? ToString() : ToString() + SqlCase(MSSQL | PGSQL, " as ")(" ") + as; } -SqlCol SqlId::operator()(SqlId p) { +SqlId SqlId::operator()(SqlId p) { String x; PutOf0(x, p); return x; } -SqlCol SqlId::operator [] (int i) const +SqlId SqlId::operator [] (int i) const { return ToString() + FormatInt(i); } -SqlCol SqlId::operator&(const SqlId& s) const +SqlId SqlId::operator&(const SqlId& s) const { return ToString() + "$" + s.ToString(); } @@ -142,7 +137,7 @@ SqlVal::SqlVal(const Nuller&) { SetNull(); } -SqlVal::SqlVal(SqlId id) { +SqlVal::SqlVal(const SqlId& id) { SetHigh(id.ToString()); } @@ -151,18 +146,6 @@ SqlVal::SqlVal(const SqlId& (*id)()) SetHigh((*id)().ToString()); } -SqlVal::SqlVal(SqlCol id) { - SetHigh(id.ToString()); -} -/* -SqlVal::SqlVal(const SqlSelect& x) { - SetHigh('(' + ((SqlStatement) x).GetText() + ')'); -} - -SqlVal::SqlVal(const SqlBool& x) { - SetHigh(~x); -} -*/ SqlVal::SqlVal(const Case& x) { SetHigh(~x); } @@ -255,7 +238,7 @@ SqlVal Count(const SqlSet& exp) SqlVal SqlAll() { - return SqlCol("*"); + return SqlId("*"); } SqlVal SqlCountRows() @@ -407,18 +390,18 @@ SqlVal Coalesce(const SqlVal& exp1, const SqlVal& exp2, const SqlVal& exp3, cons return SqlFunc("coalesce", exp1, exp2, exp3, exp4); } -SqlVal Prior(SqlId a) { +SqlVal Prior(const SqlId& a) { return SqlVal("prior " + ~a, SqlS::UNARY); } -SqlVal NextVal(SqlId a) { +SqlVal NextVal(const SqlId& a) { return SqlVal(SqlCase (PGSQL, "nextval('" + ~a + "')") (~a + ".NEXTVAL") , SqlS::HIGH); } -SqlVal CurrVal(SqlId a) { +SqlVal CurrVal(const SqlId& a) { return SqlVal(SqlCase (PGSQL, "currval('" + ~a + "')") (~a + ".CURRVAL") @@ -427,16 +410,16 @@ SqlVal CurrVal(SqlId a) { SqlVal SqlRowNum() { - return SqlCol("ROWNUM"); + return SqlId("ROWNUM"); } SqlVal SqlArg() { - return SqlCol("?"); + return SqlId("?"); } -SqlVal OuterJoin(SqlCol col) +SqlVal OuterJoin(const SqlId& col) { - return SqlCol(~col + "(+)"); + return SqlId(~col + "(+)"); } SqlVal SqlBinary(const char *s, int l) diff --git a/uppsrc/Sql/Sqlexp.h b/uppsrc/Sql/Sqlexp.h index 658214c57..e484ac3f9 100644 --- a/uppsrc/Sql/Sqlexp.h +++ b/uppsrc/Sql/Sqlexp.h @@ -84,17 +84,6 @@ String SqlFormat(const Value& x); String SqlFormatBinary(const char *s, int l); String SqlFormatBinary(const String& x); -class SqlCol : Moveable { - String name; -public: - String ToString() const { return name; } - const String& operator~() const { return name; } - - SqlCol As(const char *as) const; - - SqlCol(const String& name) : name(name) {} -}; - class SqlId : Moveable { protected: Id id; @@ -104,29 +93,29 @@ private: void PutOf(String& s, const SqlId& b); public: - bool IsEqual(SqlId b) const { return id == b.id; } - bool IsEqual(Id b) const { return id == b; } - bool IsNull() const { return id.IsNull(); } + bool IsEqual(const SqlId& b) const { return id == b.id; } + bool IsEqual(const Id& b) const { return id == b; } + bool IsNull() const { return id.IsNull(); } - operator Id() const { return id; } - String ToString() const { return id.ToString(); } - String operator~() const { return ToString(); } + operator const Id&() const { return id; } + const String& ToString() const { return id.ToString(); } + String operator~() const { return ToString(); } - SqlCol Of(SqlId id) const; - SqlCol Of(const char *of) const; - SqlCol As(const char *as) const; - SqlCol As(SqlId id) const { return As(~~id); } - SqlCol operator[](int i) const; - SqlCol operator&(const SqlId& s) const; - SqlCol operator[](const SqlId& id) const; + SqlId Of(SqlId id) const; + SqlId Of(const char *of) const; + SqlId As(const char *as) const; + SqlId As(SqlId id) const { return As(~~id); } + SqlId operator[](int i) const; + SqlId operator&(const SqlId& s) const; + SqlId operator[](const SqlId& id) const; - SqlCol operator()(SqlId p); + SqlId operator()(SqlId p); //$ SqlId operator()(SqlId p, SqlId p1, ...); #define E__PutSqlId(I) PutOf(x, p##I) -#define E__SqlId(I) SqlId p##I +#define E__SqlId(I) const SqlId& p##I #define E__Of(I) \ - SqlCol operator()(SqlId p, __List##I(E__SqlId)) { \ + SqlId operator()(const SqlId& p, __List##I(E__SqlId)) { \ String x; \ PutOf0(x, p); \ __List##I(E__PutSqlId); \ @@ -140,9 +129,11 @@ __Expand(E__Of) SqlId() {} SqlId(const char *s) : id(s) {} SqlId(const String& s) : id(s) {} - SqlId(Id id) : id(id) {} + SqlId(const Id& id) : id(id) {} }; +typedef SqlId SqlCol; // Deprecated + #define SQLID(x) const UPP::SqlId x(#x); #define SQL_ID(n, x) const UPP::SqlId n(#x); @@ -210,11 +201,8 @@ public: SqlVal(Time x); SqlVal(const Value& x); SqlVal(const Nuller&); - SqlVal(SqlId id); + SqlVal(const SqlId& id); SqlVal(const SqlId& (*id)()); - SqlVal(SqlCol id); -// SqlVal(const SqlSelect& x); -// SqlVal(const SqlBool& x); SqlVal(const Case& x); }; @@ -282,31 +270,25 @@ SqlVal Cast(const char* type, const SqlId& a); SqlVal SqlNvl(const SqlVal& a); inline SqlVal Nvl(const SqlVal& a) { return SqlNvl(SqlVal(a)); } -inline SqlVal Nvl(const SqlCol& a) { return SqlNvl(SqlVal(a)); } inline SqlVal Nvl(const SqlId& a) { return SqlNvl(SqlVal(a)); } SqlVal SqlNvl(const SqlVal& a, const SqlVal& b); inline SqlVal Nvl(const SqlVal& a, const SqlVal& b) { return SqlNvl(SqlVal(a), SqlVal(b)); } -inline SqlVal Nvl(const SqlVal& a, const SqlCol& b) { return SqlNvl(SqlVal(a), SqlVal(b)); } inline SqlVal Nvl(const SqlVal& a, const SqlId& b) { return SqlNvl(SqlVal(a), SqlVal(b)); } -inline SqlVal Nvl(const SqlCol& a, const SqlVal& b) { return SqlNvl(SqlVal(a), SqlVal(b)); } -inline SqlVal Nvl(const SqlCol& a, const SqlCol& b) { return SqlNvl(SqlVal(a), SqlVal(b)); } -inline SqlVal Nvl(const SqlCol& a, const SqlId& b) { return SqlNvl(SqlVal(a), SqlVal(b)); } inline SqlVal Nvl(const SqlId& a, const SqlVal& b) { return SqlNvl(SqlVal(a), SqlVal(b)); } -inline SqlVal Nvl(const SqlId& a, const SqlCol& b) { return SqlNvl(SqlVal(a), SqlVal(b)); } inline SqlVal Nvl(const SqlId& a, const SqlId& b) { return SqlNvl(SqlVal(a), SqlVal(b)); } SqlVal Coalesce(const SqlVal& exp1, const SqlVal& exp2); SqlVal Coalesce(const SqlVal& exp1, const SqlVal& exp2, const SqlVal& exp3); SqlVal Coalesce(const SqlVal& exp1, const SqlVal& exp2, const SqlVal& exp3, const SqlVal& exp4); -SqlVal Prior(SqlId a); +SqlVal Prior(const SqlId& a); -SqlVal NextVal(SqlId a); -SqlVal CurrVal(SqlId a); -SqlVal OuterJoin(SqlCol col); +SqlVal NextVal(const SqlId& a); +SqlVal CurrVal(const SqlId& a); +SqlVal OuterJoin(const SqlId& col); //Oracle only, deprecated -inline SqlVal operator++(SqlId a) { return NextVal(a); } +inline SqlVal operator++(const SqlId& a) { return NextVal(a); } SqlVal SqlRowNum(); @@ -360,7 +342,6 @@ SqlBool NotNull(const SqlVal& a); inline SqlBool IsNull(const SqlId& a) { return SqlIsNull(a); } inline SqlBool IsNull(const SqlVal& a) { return SqlIsNull(a); } -inline SqlBool IsNull(const SqlCol& a) { return SqlIsNull(a); } SqlBool Like(const SqlVal& a, const SqlVal& b, bool casesensitive = true); SqlBool NotLike(const SqlVal& a, const SqlVal& b, bool casesensitive = true); @@ -375,14 +356,14 @@ SqlBool NotExists(const SqlSet& set); SqlBool LikeUpperAscii(const SqlVal& a, const SqlVal& b); -SqlBool LeftJoin(SqlVal v1, SqlVal v2); -SqlBool RightJoin(SqlVal v1, SqlVal v2); +SqlBool LeftJoin(SqlVal v1, SqlVal v2); // Deprecated +SqlBool RightJoin(SqlVal v1, SqlVal v2); // Deprecated -SqlBool Join(SqlId tab1, SqlId tab2, SqlId key); -SqlBool LeftJoin(SqlId tab1, SqlId tab2, SqlId key); -SqlBool RightJoin(SqlId tab1, SqlId tab2, SqlId key); +SqlBool Join(SqlId tab1, SqlId tab2, SqlId key); // Deprecated +SqlBool LeftJoin(SqlId tab1, SqlId tab2, SqlId key); // Deprecated +SqlBool RightJoin(SqlId tab1, SqlId tab2, SqlId key); // Deprecated -SqlBool SqlFirstRow(); +SqlBool SqlFirstRow(); // Oracle specific inline SqlBool operator==(const SqlVal& a, const SqlSet& b) { return In(a, b); } inline SqlBool operator!=(const SqlVal& a, const SqlSet& b) { return NotIn(a, b); } @@ -504,32 +485,25 @@ public: SqlSelect& Get(); SqlSelect& From(const SqlSet& set); - SqlSelect& From(SqlId table); - SqlSelect& From(SqlCol table); - SqlSelect& From(SqlId table1, SqlId table2); - SqlSelect& From(SqlCol table1, SqlCol table2); - SqlSelect& From(SqlId table1, SqlId table2, SqlId table3); - SqlSelect& From(SqlCol table1, SqlCol table2, SqlCol table3); + SqlSelect& From(const SqlId& table); + SqlSelect& From(const SqlId& table1, const SqlId& table2); + SqlSelect& From(const SqlId& table1, const SqlId& table2, const SqlId& table3); SqlSelect& From(const SqlVal& a) { return From(SqlSet(a)); } - SqlSelect& InnerJoin(SqlId table) { return InnerJoin0(~table); } - SqlSelect& LeftJoin(SqlId table) { return LeftJoin0(~table); } - SqlSelect& RightJoin(SqlId table) { return RightJoin0(~table); } - SqlSelect& FullJoin(SqlId table) { return FullJoin0(~table); } - SqlSelect& InnerJoin(SqlCol table) { return InnerJoin0(~table); } - SqlSelect& LeftJoin(SqlCol table) { return LeftJoin0(~table); } - SqlSelect& RightJoin(SqlCol table) { return RightJoin0(~table); } - SqlSelect& FullJoin(SqlCol table) { return FullJoin0(~table); } + SqlSelect& InnerJoin(const SqlId& table) { return InnerJoin0(~table); } + SqlSelect& LeftJoin(const SqlId& table) { return LeftJoin0(~table); } + SqlSelect& RightJoin(const SqlId& table) { return RightJoin0(~table); } + SqlSelect& FullJoin(const SqlId& table) { return FullJoin0(~table); } SqlSelect& InnerJoin(const SqlSet& set) { return InnerJoin0(~set(SqlSet::SET)); } SqlSelect& LeftJoin(const SqlSet& set) { return LeftJoin0(~set(SqlSet::SET)); } SqlSelect& RightJoin(const SqlSet& set) { return RightJoin0(~set(SqlSet::SET)); } SqlSelect& FullJoin(const SqlSet& set) { return FullJoin0(~set(SqlSet::SET)); } - SqlSelect& InnerJoinRef(SqlId table); - SqlSelect& LeftJoinRef(SqlId table); - SqlSelect& RightJoinRef(SqlId table); - SqlSelect& FullJoinRef(SqlId table); + SqlSelect& InnerJoinRef(const SqlId& table); + SqlSelect& LeftJoinRef(const SqlId& table); + SqlSelect& RightJoinRef(const SqlId& table); + SqlSelect& FullJoinRef(const SqlId& table); SqlSelect& Where(const SqlBool& exp); SqlSelect& On(const SqlBool& exp); @@ -554,7 +528,7 @@ public: operator SqlSet() const { return SqlSet(text, SqlSet::SETOP); } operator SqlStatement() const { return SqlStatement(text); } SqlVal AsValue() const; - SqlSelect AsTable(SqlId tab) const; + SqlSelect AsTable(const SqlId& tab) const; SqlSelect(Fields f); SqlSelect(const SqlSet& s) { text = ~s; on = false; } @@ -620,12 +594,12 @@ class SqlInsert { SqlBool where; public: - void Column(SqlId column, SqlVal val); - void Column(SqlId column) { Column(column, column); } - SqlInsert& operator()(SqlId column, SqlVal val) { Column(column, val); return *this; } - SqlInsert& operator()(SqlId column) { Column(column, column); return *this; } + void Column(const SqlId& column, SqlVal val); + void Column(const SqlId& column) { Column(column, column); } + SqlInsert& operator()(const SqlId& column, SqlVal val) { Column(column, val); return *this; } + SqlInsert& operator()(const SqlId& column) { Column(column, column); return *this; } SqlInsert& operator()(Fields f, bool nokey = false); - SqlInsert& From(SqlId from); + SqlInsert& From(const SqlId& from); SqlInsert& From(SqlSet _from) { from = _from; return *this; } SqlInsert& From(SqlVal from) { return From(SqlSet(from)); } SqlInsert& Where(SqlBool w) { where = w; return *this; } @@ -637,8 +611,9 @@ public: operator SqlStatement() const; operator bool() const { return !set1.IsEmpty(); } - SqlInsert(SqlId table) : table(table) {} - SqlInsert(SqlId table, SqlSet set1, SqlSet set2) : table(table), set1(set1), set2(set2) {} + SqlInsert(const SqlId& table) : table(table) {} + SqlInsert(const SqlId& table, const SqlSet& set1, const SqlSet& set2) + : table(table), set1(set1), set2(set2) {} SqlInsert(Fields f, bool nokey = false); //Deprecated!!! @@ -650,7 +625,7 @@ public: Value Fetch() const { return SqlStatement(*this).Fetch(); } }; -inline SqlInsert Insert(SqlId table) { return SqlInsert(table); } +inline SqlInsert Insert(const SqlId& table) { return SqlInsert(table); } inline SqlInsert Insert(Fields f) { return SqlInsert(f); } inline SqlInsert InsertNoKey(Fields f) { return SqlInsert(f, true); } @@ -660,9 +635,9 @@ class SqlUpdate { SqlBool where; public: - void Column(SqlId column, SqlVal val); + void Column(const SqlId& column, SqlVal val); void Column(const SqlSet& cols, const SqlSet& val); - SqlUpdate& operator()(SqlId column, SqlVal val) { Column(column, val); return *this; } + SqlUpdate& operator()(const SqlId& column, SqlVal val) { Column(column, val); return *this; } SqlUpdate& operator()(const SqlSet& cols, const SqlSet& val) { Column(cols, val); return *this; } SqlUpdate& operator()(Fields f); SqlUpdate& Where(SqlBool w) { where = w; return *this; } @@ -671,7 +646,7 @@ public: operator bool() const { return !set.IsEmpty(); } - SqlUpdate(SqlId table) : table(table) {} + SqlUpdate(const SqlId& table) : table(table) {} SqlUpdate(Fields f); //Deprecated!!! @@ -683,5 +658,5 @@ public: Value Fetch() const { return SqlStatement(*this).Fetch(); } }; -inline SqlUpdate Update(SqlId table) { return SqlUpdate(table); } +inline SqlUpdate Update(const SqlId& table) { return SqlUpdate(table); } inline SqlUpdate Update(Fields f) { return SqlUpdate(f); } diff --git a/uppsrc/Sql/util_td.cpp b/uppsrc/Sql/util_td.cpp index 0d428a81f..40779510f 100644 --- a/uppsrc/Sql/util_td.cpp +++ b/uppsrc/Sql/util_td.cpp @@ -3,13 +3,13 @@ NAMESPACE_UPP void td_scalar(SqlSet& set, const String& prefix, const char *x) { - set.Cat(SqlCol(prefix + x)); + set.Cat(SqlId(prefix + x)); } void td_array(SqlSet& set, const String& prefix, const char *x, int cnt) { String name = prefix + x; for(int i = 0; i < cnt; i++) - set.Cat(SqlCol(name + Format("%d", i))); + set.Cat(SqlId(name + Format("%d", i))); } void td_var(SqlSet& set, const String& prefix, const char *x, SqlSet (*f)(const String&)) { diff --git a/uppsrc/TSql/dict.cpp b/uppsrc/TSql/dict.cpp index a101dd4d1..43a1666ea 100644 --- a/uppsrc/TSql/dict.cpp +++ b/uppsrc/TSql/dict.cpp @@ -165,7 +165,7 @@ void SqlUserRights::Sync() SqlId OWNER("OWNER"); SqlId TABLE_NAME("TABLE_NAME"); SqlId PRIVILEGE("PRIVILEGE"); - Select(SqlCol("OWNER, TABLE_NAME, " + Select(SqlId("OWNER, TABLE_NAME, " "SUM(distinct DECODE(PRIVILEGE, 'SELECT', 1, 'UPDATE', 2, " "'INSERT', 4, 'DELETE', 8, 0))")) .From(Select(OWNER, TABLE_NAME, PRIVILEGE).From(SqlId("USER_TAB_PRIVS")) | @@ -219,7 +219,7 @@ void SqlIndex::Open(String ind, String own, SqlSession& session) { SqlBool exp = SqlId("INDEX_NAME") == ind; if(!IsNull(own)) - exp &= SqlCol("OWNER") == own; + exp &= SqlId("OWNER") == own; Sql cursor(session); Select(SqlId("OWNER"), SqlId("INDEX_NAME"), SqlId("TABLE_OWNER"), SqlId("TABLE_NAME")) .From(SqlId("ALL_INDEXES")) diff --git a/uppsrc/TSql/init b/uppsrc/TSql/init index 22c25517e..8a03800fc 100644 --- a/uppsrc/TSql/init +++ b/uppsrc/TSql/init @@ -2,7 +2,7 @@ #define _TSql_icpp_init_stub #include "Sql/init" #include "TCore/init" -#define BLITZ_INDEX__ F3BB9158B36A73CCE79A422B64471481A +#define BLITZ_INDEX__ F118798ccfac1d6c5db6791de84b29726 #include "TSql_init.icpp" #undef BLITZ_INDEX__ #endif diff --git a/uppsrc/TSql/util.cpp b/uppsrc/TSql/util.cpp index a2bf3ff46..c48fd14a4 100644 --- a/uppsrc/TSql/util.cpp +++ b/uppsrc/TSql/util.cpp @@ -48,7 +48,7 @@ class SelectColumns : public FieldOperator public: virtual void Field(const char *name, Ref f) { - columns.Cat(SqlCol(name)); + columns.Cat(SqlId(name)); } public: @@ -121,7 +121,7 @@ public: virtual void Field(const char *name, Ref f) { - if(Id::Find(name) == column) + if(name == ~column) value = f; } @@ -136,7 +136,7 @@ public: virtual void Field(const char *name, Ref f) { - if(Id::Find(name) == column) + if(name == ~column) ref = f; } @@ -199,7 +199,7 @@ String SchemaTableName(const String& table) SqlVal SchemaTable(const SqlVal& table) { - return SqlCol(SchemaTableName(~table)); + return SqlId(SchemaTableName(~table)); } String GetInsertString(Fields nf, bool optimize) @@ -602,7 +602,7 @@ SqlVal Alias(const SqlVal& value, const SqlVal& alias) { if(~value == ~alias) return value; - return SqlCol(~value + SqlCase(MSSQL, " as ")(" ") + ~alias); + return SqlId(~value + SqlCase(MSSQL, " as ")(" ") + ~alias); } SqlVal SchemaAlias(const SqlVal& table, const SqlVal& alias) @@ -664,7 +664,7 @@ SqlVal GetCsVal(const SqlVal& val) SqlVal GetCs(const char* col) { - return GetCsVal(SqlCol(col)); + return GetCsVal(SqlId(col)); } SqlVal GetCsAsciiVal(const SqlVal& val) @@ -674,7 +674,7 @@ SqlVal GetCsAsciiVal(const SqlVal& val) SqlVal GetCsAscii(const char* col) { - return GetCsAsciiVal(SqlCol(col)); + return GetCsAsciiVal(SqlId(col)); } SqlBool LikeSmartWild(const SqlVal& exp, const String& text)