mORMot and Open Source friends
Check-in [9692746f12]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:fix and enhance boolean values parsing from JSON content ("Yes"=true)
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 9692746f128812989fac39efb9d4f9f22cd55ba8
User & Date: abouchez 2013-12-05 15:46:22
Context
2013-12-05
15:49
Fast Memory Manager source locaed in RTL7 sub-folder of the repository upgrade to latest 4.991 revision check-in: decfc2bf8b user: abouchez tags: trunk
15:46
fix and enhance boolean values parsing from JSON content ("Yes"=true) check-in: 9692746f12 user: abouchez tags: trunk
15:46
speed improvement of IdemPropNameU() function check-in: 3e20de5e38 user: abouchez tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to SQLite3/mORMot.pas.

763
764
765
766
767
768
769

770
771
772
773
774
775
776
.....
13117
13118
13119
13120
13121
13122
13123
13124


13125




13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137


13138
13139
13140





13141
13142
13143
13144
13145
13146
13147
    - added TAuthSession.SentHeaders, RemoteIP and ConnectionID properties
    - added process of Variant and WideString types in TSQLRecord properties
    - added JSON serialization of Variant and WideString types in JSONToObject()
      / ObjectToJSON() functions and WriteObject method
    - added TTypeInfo.ClassCreate() method to create a TObject instance from RTTI
    - TEnumType.GetEnumNameValue() will now recognize both 'sllWarning' and
      'Warning' text as a sllWarning item (will enhance JSONToObject() process)

    - implement woHumanReadableFullSetsAsStar and woHumanReadableEnumSetAsComment
      option for JSON serialization and TEnumType.GetEnumNameTrimedAll()
    - added ClassInstanceCreate() function calling any known virtual constructor
    - added GetInterfaceFromEntry() function to speed up interface execution,
      e.g. for TServiceFactoryServer (avoid the RTTI lookup of GetInterface) 
    - added TPropInfo.ClassFromJSON() to properly unserialize TObject properties
    - added TSQLPropInfo.SQLFieldTypeName property
................................................................................
    result := Int32ToUtf8(i);
end;

procedure TSQLPropInfoRTTIEnum.NormalizeValue(var Value: RawUTF8);
var i,err: integer;
begin
  i := GetInteger(pointer(Value),err);
  if err<>0 then // we allow a value stated as text


    i := fEnumType^.GetEnumNameValue(pointer(Value),length(Value)); // -> convert into integer




  if cardinal(i)>cardinal(fEnumType^.MaxValue) then
    Value := '' else  // only set a valid value
    Value := Int32ToUtf8(i);
end;

procedure TSQLPropInfoRTTIEnum.SetValue(Instance: TObject; Value: PUTF8Char; wasString: boolean);
var i,err: integer;
begin
  if Value=nil then
    i := 0 else begin
    i := GetInteger(Value,err);
    if err<>0 then // we allow a value stated as text


      i := fEnumType^.GetEnumNameValue(Value); // -> convert into integer
    if cardinal(i)>cardinal(fEnumType^.MaxValue) then
      i := 0;  // only set a valid value





  end;
  SetOrdProp(Instance,pointer(fPropInfo),i);
end;


{ TSQLPropInfoRTTIChar }







>







 







|
>
>
|
>
>
>
>

|









|
>
>
|
|
|
>
>
>
>
>







763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
.....
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
    - added TAuthSession.SentHeaders, RemoteIP and ConnectionID properties
    - added process of Variant and WideString types in TSQLRecord properties
    - added JSON serialization of Variant and WideString types in JSONToObject()
      / ObjectToJSON() functions and WriteObject method
    - added TTypeInfo.ClassCreate() method to create a TObject instance from RTTI
    - TEnumType.GetEnumNameValue() will now recognize both 'sllWarning' and
      'Warning' text as a sllWarning item (will enhance JSONToObject() process)
    - fix and enhance boolean values parsing from JSON content ("Yes"=true) 
    - implement woHumanReadableFullSetsAsStar and woHumanReadableEnumSetAsComment
      option for JSON serialization and TEnumType.GetEnumNameTrimedAll()
    - added ClassInstanceCreate() function calling any known virtual constructor
    - added GetInterfaceFromEntry() function to speed up interface execution,
      e.g. for TServiceFactoryServer (avoid the RTTI lookup of GetInterface) 
    - added TPropInfo.ClassFromJSON() to properly unserialize TObject properties
    - added TSQLPropInfo.SQLFieldTypeName property
................................................................................
    result := Int32ToUtf8(i);
end;

procedure TSQLPropInfoRTTIEnum.NormalizeValue(var Value: RawUTF8);
var i,err: integer;
begin
  i := GetInteger(pointer(Value),err);
  if err<>0 then  // we allow a value stated as text
    if fSQLFieldType=sftBoolean then
      i := Ord(IdemPropNameU(Value,'TRUE') or IdemPropNameU(Value,'YES')) else
      i := fEnumType^.GetEnumNameValue(pointer(Value),length(Value)) else
    if fSQLFieldType=sftBoolean then // normalize boolean values range to 0,1
      if Boolean(i) then
        i := 1 else
        i := 0;
  if cardinal(i)>cardinal(fEnumType^.MaxValue) then
    Value := '' else // only set a valid value
    Value := Int32ToUtf8(i);
end;

procedure TSQLPropInfoRTTIEnum.SetValue(Instance: TObject; Value: PUTF8Char; wasString: boolean);
var i,err: integer;
begin
  if Value=nil then
    i := 0 else begin
    i := GetInteger(Value,err);
    if err<>0 then begin // we allow a value stated as text
      if fSQLFieldType=sftBoolean then
        i := Ord(IdemPropNameU(Value,'TRUE') or IdemPropNameU(Value,'YES')) else
        i := fEnumType^.GetEnumNameValue(Value); // -> convert into integer
      if cardinal(i)>cardinal(fEnumType^.MaxValue) then
        i := 0;  // only set a valid text value
    end else
    if fSQLFieldType=sftBoolean then // normalize boolean values range to 0,1
      if Boolean(i) then
        i := 1 else
        i := 0;
  end;
  SetOrdProp(Instance,pointer(fPropInfo),i);
end;


{ TSQLPropInfoRTTIChar }