JD.
JD.

Reputation: 15541

Storing a value in a datetime field using a unique number

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.

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

Upvotes: 0

Views: 336

Answers (1)

Numenor
Numenor

Reputation: 1706

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)

Upvotes: 8

Related Questions