开发者

Storing a value in a datetime field using a unique number

开发者 https://www.devze.com 2022-12-17 06:39 出处:网络
I have the following scenario and would be grateful for any advice how to resolve this issue. We have a database application which contains a field which is a DateTime field. We have never used this

I have the following scenario and would be grateful for any advice how to resolve this issue.

We have a database application which contains a field which is a DateTime field. We have never used this field in the past but now after a few 100 installs we need to use this field but have found that it is should not have been a DateTime field.开发者_StackOverflow中文版

We could create scripts to change the database but that would involve way too much work.

The field needs to store a unique value and I was wondering whether given a string I could get a unique number and then store it in the dateTime field (which is a double).

I have found this method:

   function Unc(s: string): UInt64;
   var
     x: Integer;
   begin
     Result := 0;
     for x := 1 to Length(s) do
       Result := Result + ((Ord(s[x])) shl ((x - 1) * 8));
   end;

and the value returned would be assigned to the DateTime field.

Would this work as I am worried by range check errors/integer overflows or is there a better method to do this (rather than doing the scripts which is probably the correct way)?

JD


i would prefer to do the right way and create scripts to change DB, since its not used it should not be a big problem(no data conversion etc)

0

精彩评论

暂无评论...
验证码 换一张
取 消