Can't call locate() using a UInt64 key value
Posted: 01.03.2010, 17:29
This code never finds the requested record, even if the record exists:
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:
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!
MySQL uses unsigned 64 bit Ints for autoincrement fields.
Best regards,
Kevin G. McCoy
Code: Select all
PROCEDURE TMainForm.ActivateOffender(OID : UInt64);
BEGIN
ejDM.dsOffender.DataSet.Locate('id', OID, []);
END;
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;
so... a more elegant fix is probably necessary, but at least DecodeVariant will stop setting my ^&#@$!! value to NULL!
MySQL uses unsigned 64 bit Ints for autoincrement fields.
Best regards,
Kevin G. McCoy