Sql: SqlMassInsert now able to insert ValueMap, SelectAll, new mass loading variants

git-svn-id: svn://ultimatepp.org/upp/trunk@6307 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2013-09-04 10:48:58 +00:00
parent 89372297ac
commit 800a4a3e7f
4 changed files with 34 additions and 0 deletions

View file

@ -26,6 +26,13 @@ SqlMassInsert& SqlMassInsert::operator()(SqlId col, const Value& val)
return *this;
}
SqlMassInsert& SqlMassInsert::operator()(const ValueMap& data)
{
for(int i = 0; i < data.GetCount(); i++)
operator()((String)data.GetKey(i), data.GetValue(i));
return *this;
}
SqlMassInsert& SqlMassInsert::EndRow(SqlBool remove)
{
cache.Top().remove = remove;

View file

@ -590,6 +590,7 @@ SqlSelect operator|(const SqlSelect& s1, const SqlSelect& s2);
SqlSelect operator&(const SqlSelect& s1, const SqlSelect& s2);
SqlSelect operator-(const SqlSelect& s1, const SqlSelect& s2);
inline SqlSelect SelectAll() { return SqlSelect(SqlAll()); }
inline SqlSelect Select(const SqlSet& set) { return SqlSelect(set); }
inline SqlSelect Select(Fields f) { return SqlSelect(f); }

View file

@ -468,6 +468,7 @@ class SqlMassInsert {
public:
SqlMassInsert& operator()(SqlId col, const Value& val);
SqlMassInsert& operator()(const ValueMap& data);
SqlMassInsert& EndRow(SqlBool remove = SqlBool());
void Flush();
bool IsError() const { return error; }
@ -499,6 +500,24 @@ void SqlLoadColumn(T& t, SqlId table, SqlId column, SqlId key = SqlId("ID"))
t.Add(sql[key], sql[column]);
}
template <class T>
void SqlLoadTable(T& t, SqlSelect select, SqlId key = SqlId("ID"))
{
Sql sql;
sql * select;
while(sql.Fetch())
sql.Get(t.Add(sql[key]));
}
template <class T>
void SqlLoadColumn(T& t, SqlSelect select)
{
Sql sql;
sql * select;
while(sql.Fetch())
t.Add(sql[0], sql[1]);
}
template<class K, class V>
void operator*=(VectorMap<K, V>& map, SqlSelect select)
{

View file

@ -27,6 +27,13 @@ Insert][@(0.0.255) `&]_[* operator()]([_^SqlId^ SqlId]_[*@3 col], [@(0.0.255) co
alue][@(0.0.255) `&]_[*@3 val])&]
[s2; Adds a single column to be inserted.&]
[s3; &]
[s4;%- &]
[s5;:SqlMassInsert`:`:operator`(`)`(const ValueMap`&`):%- [_^SqlMassInsert^ SqlMassInse
rt][@(0.0.255) `&]_[* operator()]([@(0.0.255) const]_[_^ValueMap^ ValueMap][@(0.0.255) `&]_
[*@3 data])&]
[s2; Inserts a set of columns defined by key`-value pairs of [%-*@3 data]
(key is the name of column, value is the inserted value).&]
[s3; &]
[s4; &]
[s5;:SqlMassInsert`:`:EndRow`(SqlBool`):%- [_^SqlMassInsert^ SqlMassInsert][@(0.0.255) `&
]_[* EndRow]([_^SqlBool^ SqlBool]_[*@3 remove]_`=_[_^SqlBool^ SqlBool]())&]