Skip to content
Permalink
Browse files

new VariantVTypeToSQLDBFieldType() and TextToSQLDBFieldType() functions

  • Loading branch information...
Arnaud Bouchez
Arnaud Bouchez committed May 29, 2019
1 parent 27b5eb0 commit 58dbb39730f60ebd31b06bb8608a9405efb81945
Showing with 38 additions and 13 deletions.
  1. +1 −1 SynCommons.pas
  2. +36 −11 SynTable.pas
  3. +1 −1 SynopseCommit.inc
@@ -6416,7 +6416,7 @@ procedure InterfaceArrayDelete(var aInterfaceArray; aItemIndex: PtrInt); overloa


/// helper to retrieve the text of an enumerate item
// - you'd better use RTTI related classes of mORMot.pas unit, e.g. TEnumType
// - see also RTTI related classes of mORMot.pas unit, e.g. TEnumType
function GetEnumName(aTypeInfo: pointer; aIndex: integer): PShortString;

/// helper to retrieve all texts of an enumerate
@@ -818,8 +818,16 @@ function SQLVarLength(const Value: TSQLVar): integer;
procedure VariantToSQLVar(const Input: variant; var temp: RawByteString;
var Output: TSQLVar);

/// guess the correct TSQLDBFieldType from a variant type
function VariantVTypeToSQLDBFieldType(VType: word): TSQLDBFieldType;

/// guess the correct TSQLDBFieldType from a variant value
function VariantTypeToSQLDBFieldType(const V: Variant): TSQLDBFieldType;
{$ifdef HASINLINE}inline;{$endif}

/// guess the correct TSQLDBFieldType from the UTF-8 representation of a value
function TextToSQLDBFieldType(json: PUTF8Char): TSQLDBFieldType;


{$endif NOVARIANTS}

@@ -10697,13 +10705,9 @@ procedure VariantToSQLVar(const Input: variant; var temp: RawByteString;
end;
end;

function VariantTypeToSQLDBFieldType(const V: Variant): TSQLDBFieldType;
var tmp: TVarData;
function VariantVTypeToSQLDBFieldType(VType: word): TSQLDBFieldType;
begin
with TVarData(V) do
case VType of
varEmpty:
result := ftUnknown;
varNull:
result := ftNull;
{$ifndef DELPHI5OROLDER}varShortInt, varWord, varLongWord,{$endif}
@@ -10716,16 +10720,37 @@ function VariantTypeToSQLDBFieldType(const V: Variant): TSQLDBFieldType;
varCurrency:
result := ftCurrency;
varString:
if (VString<>nil) and (PCardinal(VString)^ and $ffffff=JSON_BASE64_MAGIC) then
result := ftBlob else
result := ftUTF8;
else
if SetVariantUnRefSimpleValue(V,tmp) then
result := VariantTypeToSQLDBFieldType(variant(tmp)) else
result := ftUTF8;
else
result := ftUnknown; // includes varEmpty
end;
end;

function VariantTypeToSQLDBFieldType(const V: Variant): TSQLDBFieldType;
var VD: TVarData absolute V;
tmp: TVarData;
begin
result := VariantVTypeToSQLDBFieldType(VD.VType);
case result of
ftUnknown:
if VD.VType=varEmpty then
result := ftUnknown else
if SetVariantUnRefSimpleValue(V,tmp) then
result := VariantTypeToSQLDBFieldType(variant(tmp)) else
result := ftUTF8;
ftUTF8:
if (VD.VString<>nil) and (PCardinal(VD.VString)^ and $ffffff=JSON_BASE64_MAGIC) then
result := ftBlob;
end;
end;

function TextToSQLDBFieldType(json: PUTF8Char): TSQLDBFieldType;
begin
if json=nil then
result := ftNull else
result := VariantVTypeToSQLDBFieldType(TextToVariantNumberType(json));
end;

{$endif NOVARIANTS}

{ TJSONWriter }
@@ -1 +1 @@
'1.18.5231'
'1.18.5232'

0 comments on commit 58dbb39

Please sign in to comment.
You can’t perform that action at this time.