Sql: Fixed issues with S_* and BOOL

git-svn-id: svn://ultimatepp.org/upp/trunk@6550 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2013-11-13 13:16:09 +00:00
parent 61deebcc78
commit bc71850e47
4 changed files with 16 additions and 6 deletions

View file

@ -2,8 +2,9 @@
NAMESPACE_UPP
void S_info_maker::Field(const char *name, Ref f)
void S_info_maker::Field(const char *name, Ref f, bool *b)
{
if(b) f = Ref(*b);
info.column.Add(name, MakeTuple((byte *)f.GetVoidPtr() - (byte *)s, f.GetManager()));
}
@ -38,7 +39,13 @@ ValueMap S_info::Get(const void *s) const
void S_info::Set(const void *s, int i, const Value& v) const
{
GetRef(s, i) = v;
Ref f = GetRef(s, i);
if(f.Is<bool>() && IsString(v)) {
String h = v;
f = !(h == "0" || IsNull(h));
}
else
f = v;
}
void S_info::Set(const void *s, const SqlId& id, const Value& v) const

View file

@ -24,9 +24,11 @@ void FieldOperator::Field(Ref f) {}
void FieldOperator::Field(const char *name, Ref f) { Field(f); }
void FieldOperator::Field(const char *name, Ref f, bool *b) { Field(name, f); }
FieldOperator& FieldOperator::operator()(const char *name, bool& b) {
String x = BoolToSql(b);
Field(name, x);
Field(name, x, &b);
b = SqlToBool(x);
return *this;
}

View file

@ -159,7 +159,7 @@ struct S_info_maker : FieldOperator {
S_info& info;
void *s;
virtual void Field(const char *name, Ref f);
virtual void Field(const char *name, Ref f, bool *b);
S_info_maker(S_info& f, void *s) : info(f), s(s) {}
};

View file

@ -23,9 +23,10 @@ struct FieldOperator {
virtual void Field(Ref f);
virtual void Field(const char *name, Ref f);
virtual void Field(const char *name, Ref f, bool *b); // Ugly fix to resolve bool issue with S_info creation
FieldOperator& operator()(const char *name, Ref f) { Field(name, f); return *this; }
FieldOperator& operator()(const String& name, Ref f) { Field(name, f); return *this; }
FieldOperator& operator()(const char *name, Ref f) { Field(name, f, NULL); return *this; }
FieldOperator& operator()(const String& name, Ref f) { Field(name, f, NULL); return *this; }
FieldOperator& operator()(Id id, Ref f) { Field(~id, f); return *this; }
FieldOperator& operator()(const char *name, bool& b);
FieldOperator& operator()(const String& name, bool& b) { return (*this)(~name, b); }