Page 1 of 1

Can't call locate() using a UInt64 key value

Posted: 01.03.2010, 17:29
by skydvrz
This code never finds the requested record, even if the record exists:

Code: Select all

PROCEDURE TMainForm.ActivateOffender(OID : UInt64);
BEGIN
    ejDM.dsOffender.DataSet.Locate('id', OID, []);
END;
The reason is that ZVariant has no case for UInt64 values. It can handle In64 though.

I modified DecodeVariant like so, and Locate() started to work again:

Code: Select all

{**
  Decodes a standard variant value into custom variant.
  @param Value a standard variant value to be decoded.
  @returns an decoded custom variant.
}
function DecodeVariant(const Value: Variant): TZVariant;
begin
  case VarType(Value) of
    varSmallint, varInteger, varByte:
      DefVarManager.SetAsInteger(Result, Integer(Value));
    varBoolean: DefVarManager.SetAsBoolean(Result, Value);
    varString:
      DefVarManager.SetAsString(Result, Value);
   {$IFDEF DELPHI12_UP}
   varUString:
      DefVarManager.SetAsUnicodeString(Result, Value);
   {$ENDIF}
    varSingle, varDouble, varCurrency:
      DefVarManager.SetAsFloat(Result, Value);
    varUnknown: DefVarManager.SetAsInterface(Result, Value);
    varOleStr:
      DefVarManager.SetAsUnicodeString(Result, Value);
    varDate: DefVarManager.SetAsDateTime(Result, Value);
    varShortInt, varWord, varLongWord:
      DefVarManager.SetAsInteger(Result, Value);
    varInt64,varUInt64: // KGM - added varUInt64 case
      DefVarManager.SetAsInteger(Result, Value);
  else
    DefVarManager.SetNull(Result);
  end;
end;
Note that my fix will fail if the UInt64 value exceeds $7FFFFFFFFFFFFFFF

so... a more elegant fix is probably necessary, but at least DecodeVariant will stop setting my ^&#@$!! value to NULL! :shock:

MySQL uses unsigned 64 bit Ints for autoincrement fields.

Best regards,

Kevin G. McCoy

Posted: 03.03.2010, 23:19
by mdaems
I applied your change in Testing branch. I had to add

Code: Select all

{$IFDEF BDS5_UP},varUInt64{$ENDIF}
.

Mark

Posted: 04.03.2010, 16:58
by skydvrz
Thanks Mark!