Sql: Sql now supports fetching ValueMap of row (Fetch or GetRowMap after Fetch)

git-svn-id: svn://ultimatepp.org/upp/trunk@4329 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2011-12-19 18:35:38 +00:00
parent c764ab2006
commit ad58d98f24
2 changed files with 26 additions and 12 deletions

View file

@ -238,12 +238,33 @@ bool Sql::Fetch(__List##I(E__Ref)) { \
}
__Expand(E__FetchF)
bool Sql::Fetch(Vector<Value>& row) {
if(!Fetch()) return false;
Vector<Value> Sql::GetRow() const {
Vector<Value> row;
int n = GetColumns();
row.SetCount(n);
for(int i = 0; i < n; i++)
GetColumn(i, row[i]);
row[i] = (*this)[i];
return row;
}
bool Sql::Fetch(Vector<Value>& row) {
if(!Fetch()) return false;
row = GetRow();
return true;
}
ValueMap Sql::GetRowMap() const
{
ValueMap m;
int n = GetColumns();
for(int i = 0; i < n; i++)
m.Add(GetColumnInfo(i).name, (*this)[i]);
return m;
}
bool Sql::Fetch(ValueMap& row) {
if(!Fetch()) return false;
row = GetRowMap();
return true;
}
@ -304,14 +325,6 @@ Value Sql::operator[](SqlId id) const {
return Value();
}
Vector<Value> Sql::GetRow() const {
Vector<Value> row;
int cn = GetColumns();
for(int i = 0; i < cn; i++)
row.Add((*this)[i]);
return row;
}
Value Sql::Select0(const String& s) {
SetStatement(s);
if(!Run())

View file

@ -136,7 +136,7 @@ public:
__Expand(E__Fetch)
//$+
bool Fetch(Vector<Value>& row);
bool Fetch(ValueMap& row);
bool Fetch(Fields fields);
int GetRowsProcessed() const { return cn->GetRowsProcessed(); }
@ -149,6 +149,7 @@ public:
Value operator[](SqlId colid) const;
const SqlColumnInfo& GetColumnInfo(int i) const { return cn->info[i]; }
Vector<Value> GetRow() const;
ValueMap GetRowMap() const;
operator Vector<Value>() const { return GetRow(); }
void Get(Fields fields);