|
@@ -100,15 +100,16 @@ type
|
|
end;
|
|
end;
|
|
TRecordsUpdateBuffer = array of TRecUpdateBuffer;
|
|
TRecordsUpdateBuffer = array of TRecUpdateBuffer;
|
|
|
|
|
|
- TCompareFunc = function(subValue, aValue: pointer; options: TLocateOptions): int64;
|
|
|
|
|
|
+ TCompareFunc = function(subValue, aValue: pointer; size: integer; options: TLocateOptions): int64;
|
|
|
|
|
|
TDBCompareRec = record
|
|
TDBCompareRec = record
|
|
- Comparefunc : TCompareFunc;
|
|
|
|
|
|
+ CompareFunc : TCompareFunc;
|
|
Off1,Off2 : PtrInt;
|
|
Off1,Off2 : PtrInt;
|
|
FieldInd1,
|
|
FieldInd1,
|
|
FieldInd2 : longint;
|
|
FieldInd2 : longint;
|
|
NullBOff1,
|
|
NullBOff1,
|
|
NullBOff2 : PtrInt;
|
|
NullBOff2 : PtrInt;
|
|
|
|
+ Size : integer;
|
|
Options : TLocateOptions;
|
|
Options : TLocateOptions;
|
|
Desc : Boolean;
|
|
Desc : Boolean;
|
|
end;
|
|
end;
|
|
@@ -682,7 +683,7 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function DBCompareText(subValue, aValue: pointer; options: TLocateOptions): LargeInt;
|
|
|
|
|
|
+function DBCompareText(subValue, aValue: pointer; size: integer; options: TLocateOptions): LargeInt;
|
|
begin
|
|
begin
|
|
if [loCaseInsensitive,loPartialKey]=options then
|
|
if [loCaseInsensitive,loPartialKey]=options then
|
|
Result := AnsiStrLIComp(pchar(subValue),pchar(aValue),length(pchar(subValue)))
|
|
Result := AnsiStrLIComp(pchar(subValue),pchar(aValue),length(pchar(subValue)))
|
|
@@ -694,7 +695,7 @@ begin
|
|
Result := AnsiCompareStr(pchar(subValue),pchar(aValue));
|
|
Result := AnsiCompareStr(pchar(subValue),pchar(aValue));
|
|
end;
|
|
end;
|
|
|
|
|
|
-function DBCompareWideText(subValue, aValue: pointer; options: TLocateOptions): LargeInt;
|
|
|
|
|
|
+function DBCompareWideText(subValue, aValue: pointer; size: integer; options: TLocateOptions): LargeInt;
|
|
begin
|
|
begin
|
|
if [loCaseInsensitive,loPartialKey]=options then
|
|
if [loCaseInsensitive,loPartialKey]=options then
|
|
Result := WideCompareText(pwidechar(subValue),LeftStr(pwidechar(aValue), Length(pwidechar(subValue))))
|
|
Result := WideCompareText(pwidechar(subValue),LeftStr(pwidechar(aValue), Length(pwidechar(subValue))))
|
|
@@ -706,25 +707,25 @@ begin
|
|
Result := WideCompareStr(pwidechar(subValue),pwidechar(aValue));
|
|
Result := WideCompareStr(pwidechar(subValue),pwidechar(aValue));
|
|
end;
|
|
end;
|
|
|
|
|
|
-function DBCompareByte(subValue, aValue: pointer; options: TLocateOptions): LargeInt;
|
|
|
|
|
|
+function DBCompareByte(subValue, aValue: pointer; size: integer; options: TLocateOptions): LargeInt;
|
|
|
|
|
|
begin
|
|
begin
|
|
Result := PByte(subValue)^-PByte(aValue)^;
|
|
Result := PByte(subValue)^-PByte(aValue)^;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function DBCompareSmallInt(subValue, aValue: pointer; options: TLocateOptions): LargeInt;
|
|
|
|
|
|
+function DBCompareSmallInt(subValue, aValue: pointer; size: integer; options: TLocateOptions): LargeInt;
|
|
|
|
|
|
begin
|
|
begin
|
|
Result := PSmallInt(subValue)^-PSmallInt(aValue)^;
|
|
Result := PSmallInt(subValue)^-PSmallInt(aValue)^;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function DBCompareInt(subValue, aValue: pointer; options: TLocateOptions): LargeInt;
|
|
|
|
|
|
+function DBCompareInt(subValue, aValue: pointer; size: integer; options: TLocateOptions): LargeInt;
|
|
|
|
|
|
begin
|
|
begin
|
|
Result := PInteger(subValue)^-PInteger(aValue)^;
|
|
Result := PInteger(subValue)^-PInteger(aValue)^;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function DBCompareLargeInt(subValue, aValue: pointer; options: TLocateOptions): LargeInt;
|
|
|
|
|
|
+function DBCompareLargeInt(subValue, aValue: pointer; size: integer; options: TLocateOptions): LargeInt;
|
|
|
|
|
|
begin
|
|
begin
|
|
// A simple subtraction doesn't work, since it could be that the result
|
|
// A simple subtraction doesn't work, since it could be that the result
|
|
@@ -737,13 +738,13 @@ begin
|
|
result := 0;
|
|
result := 0;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function DBCompareWord(subValue, aValue: pointer; options: TLocateOptions): LargeInt;
|
|
|
|
|
|
+function DBCompareWord(subValue, aValue: pointer; size: integer; options: TLocateOptions): LargeInt;
|
|
|
|
|
|
begin
|
|
begin
|
|
Result := PWord(subValue)^-PWord(aValue)^;
|
|
Result := PWord(subValue)^-PWord(aValue)^;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function DBCompareQWord(subValue, aValue: pointer; options: TLocateOptions): LargeInt;
|
|
|
|
|
|
+function DBCompareQWord(subValue, aValue: pointer; size: integer; options: TLocateOptions): LargeInt;
|
|
|
|
|
|
begin
|
|
begin
|
|
// A simple subtraction doesn't work, since it could be that the result
|
|
// A simple subtraction doesn't work, since it could be that the result
|
|
@@ -756,7 +757,7 @@ begin
|
|
result := 0;
|
|
result := 0;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function DBCompareDouble(subValue, aValue: pointer; options: TLocateOptions): LargeInt;
|
|
|
|
|
|
+function DBCompareDouble(subValue, aValue: pointer; size: integer; options: TLocateOptions): LargeInt;
|
|
begin
|
|
begin
|
|
// A simple subtraction doesn't work, since it could be that the result
|
|
// A simple subtraction doesn't work, since it could be that the result
|
|
// doesn't fit into a LargeInt
|
|
// doesn't fit into a LargeInt
|
|
@@ -768,11 +769,31 @@ begin
|
|
result := 0;
|
|
result := 0;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function DBCompareBCD(subValue, aValue: pointer; options: TLocateOptions): LargeInt;
|
|
|
|
|
|
+function DBCompareBCD(subValue, aValue: pointer; size: integer; options: TLocateOptions): LargeInt;
|
|
begin
|
|
begin
|
|
result:=BCDCompare(PBCD(subValue)^, PBCD(aValue)^);
|
|
result:=BCDCompare(PBCD(subValue)^, PBCD(aValue)^);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+function DBCompareBytes(subValue, aValue: pointer; size: integer; options: TLocateOptions): LargeInt;
|
|
|
|
+begin
|
|
|
|
+ Result := CompareByte(subValue^, aValue^, size);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function DBCompareVarBytes(subValue, aValue: pointer; size: integer; options: TLocateOptions): LargeInt;
|
|
|
|
+var len1, len2: LongInt;
|
|
|
|
+begin
|
|
|
|
+ len1 := PWord(subValue)^;
|
|
|
|
+ len2 := PWord(aValue)^;
|
|
|
|
+ inc(subValue, sizeof(Word));
|
|
|
|
+ inc(aValue, sizeof(Word));
|
|
|
|
+ if len1 > len2 then
|
|
|
|
+ Result := CompareByte(subValue^, aValue^, len2)
|
|
|
|
+ else
|
|
|
|
+ Result := CompareByte(subValue^, aValue^, len1);
|
|
|
|
+ if Result = 0 then
|
|
|
|
+ Result := len1 - len2;
|
|
|
|
+end;
|
|
|
|
+
|
|
procedure unSetFieldIsNull(NullMask : pbyte;x : longint); //inline;
|
|
procedure unSetFieldIsNull(NullMask : pbyte;x : longint); //inline;
|
|
begin
|
|
begin
|
|
NullMask[x div 8] := (NullMask[x div 8]) and not (1 shl (x mod 8));
|
|
NullMask[x div 8] := (NullMask[x div 8]) and not (1 shl (x mod 8));
|
|
@@ -797,13 +818,13 @@ begin
|
|
IsNull1:=GetFieldIsNull(rec1+NullBOff1,FieldInd1);
|
|
IsNull1:=GetFieldIsNull(rec1+NullBOff1,FieldInd1);
|
|
IsNull2:=GetFieldIsNull(rec2+NullBOff2,FieldInd2);
|
|
IsNull2:=GetFieldIsNull(rec2+NullBOff2,FieldInd2);
|
|
if IsNull1 and IsNull2 then
|
|
if IsNull1 and IsNull2 then
|
|
- result := 0
|
|
|
|
|
|
+ Result := 0
|
|
else if IsNull1 then
|
|
else if IsNull1 then
|
|
- result := -1
|
|
|
|
|
|
+ Result := -1
|
|
else if IsNull2 then
|
|
else if IsNull2 then
|
|
- result := 1
|
|
|
|
|
|
+ Result := 1
|
|
else
|
|
else
|
|
- Result := Comparefunc(Rec1+Off1,Rec2+Off2,Options);
|
|
|
|
|
|
+ Result := CompareFunc(Rec1+Off1, Rec2+Off2, Size, Options);
|
|
|
|
|
|
if Result <> 0 then
|
|
if Result <> 0 then
|
|
begin
|
|
begin
|
|
@@ -1742,18 +1763,20 @@ begin
|
|
AField := TField(AFields[i]);
|
|
AField := TField(AFields[i]);
|
|
|
|
|
|
case AField.DataType of
|
|
case AField.DataType of
|
|
- ftString, ftFixedChar : ACompareRec.Comparefunc := @DBCompareText;
|
|
|
|
- ftWideString, ftFixedWideChar: ACompareRec.Comparefunc := @DBCompareWideText;
|
|
|
|
- ftSmallint : ACompareRec.Comparefunc := @DBCompareSmallInt;
|
|
|
|
- ftInteger, ftBCD, ftAutoInc : ACompareRec.Comparefunc :=
|
|
|
|
|
|
+ ftString, ftFixedChar : ACompareRec.CompareFunc := @DBCompareText;
|
|
|
|
+ ftWideString, ftFixedWideChar: ACompareRec.CompareFunc := @DBCompareWideText;
|
|
|
|
+ ftSmallint : ACompareRec.CompareFunc := @DBCompareSmallInt;
|
|
|
|
+ ftInteger, ftBCD, ftAutoInc : ACompareRec.CompareFunc :=
|
|
@DBCompareInt;
|
|
@DBCompareInt;
|
|
- ftWord : ACompareRec.Comparefunc := @DBCompareWord;
|
|
|
|
- ftBoolean : ACompareRec.Comparefunc := @DBCompareByte;
|
|
|
|
- ftFloat, ftCurrency : ACompareRec.Comparefunc := @DBCompareDouble;
|
|
|
|
- ftDateTime, ftDate, ftTime : ACompareRec.Comparefunc :=
|
|
|
|
|
|
+ ftWord : ACompareRec.CompareFunc := @DBCompareWord;
|
|
|
|
+ ftBoolean : ACompareRec.CompareFunc := @DBCompareByte;
|
|
|
|
+ ftFloat, ftCurrency : ACompareRec.CompareFunc := @DBCompareDouble;
|
|
|
|
+ ftDateTime, ftDate, ftTime : ACompareRec.CompareFunc :=
|
|
@DBCompareDouble;
|
|
@DBCompareDouble;
|
|
- ftLargeint : ACompareRec.Comparefunc := @DBCompareLargeInt;
|
|
|
|
- ftFmtBCD : ACompareRec.Comparefunc := @DBCompareBCD;
|
|
|
|
|
|
+ ftLargeint : ACompareRec.CompareFunc := @DBCompareLargeInt;
|
|
|
|
+ ftFmtBCD : ACompareRec.CompareFunc := @DBCompareBCD;
|
|
|
|
+ ftBytes : ACompareRec.CompareFunc := @DBCompareBytes;
|
|
|
|
+ ftVarBytes : ACompareRec.CompareFunc := @DBCompareVarBytes;
|
|
else
|
|
else
|
|
DatabaseErrorFmt(SErrIndexBasedOnInvField, [AField.FieldName,Fieldtypenames[AField.DataType]]);
|
|
DatabaseErrorFmt(SErrIndexBasedOnInvField, [AField.FieldName,Fieldtypenames[AField.DataType]]);
|
|
end;
|
|
end;
|
|
@@ -1764,6 +1787,8 @@ begin
|
|
ACompareRec.FieldInd1:=AField.FieldNo-1;
|
|
ACompareRec.FieldInd1:=AField.FieldNo-1;
|
|
ACompareRec.FieldInd2:=ACompareRec.FieldInd1;
|
|
ACompareRec.FieldInd2:=ACompareRec.FieldInd1;
|
|
|
|
|
|
|
|
+ ACompareRec.Size:=GetFieldSize(FieldDefs[ACompareRec.FieldInd1]);
|
|
|
|
+
|
|
ACompareRec.NullBOff1:=BufferOffset;
|
|
ACompareRec.NullBOff1:=BufferOffset;
|
|
ACompareRec.NullBOff2:=ACompareRec.NullBOff1;
|
|
ACompareRec.NullBOff2:=ACompareRec.NullBOff1;
|
|
|
|
|