views:

159

answers:

1

Hi,

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

+8  A: 

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)

Numenor
Agreed. How is it "way too much work" to drop an unused column and add a new one, but not too much work to design a conversion routine and make sure it's got proper safety checks?!?
Mason Wheeler
We are using bold for delphi and I did not want to generate the model, then store it in our evolving application as it would have meant more testing. I was trying to find a quick solution.
JD
Looks like I will have to do it the correct way because I cannot guarantee the value obtained (unique number) can be stored in a database field in Firebird or SQL server. Thanks for the input.
JD
Ironic that someone using model-driven-development architecture still finds it difficult to handle model revision changes. No disrespect to JD, but I find it lowers my confidence in all "model driven development" nirvana ideas. I know Bold is now past End of Life for support purposes, but there are no real living MDD tools/component sets for native win32 Delphi anymore, are there?
Warren P
@Warren it depends if you want to call ORM an MDD. hcOPF looks promising: http://www.delphifeeds.com/go/s/64747
Jeroen Pluimers
I'm using Bold and have no such problems. Database evolution runs on app startup if needed and that's about it, it just works.
Daniel Maurić
@Warren: It is not that I have no confidence in MDD, it was just that I was trying to find an alternative/quick solution. In fact the evolution scripts generated by Bold were correct and in the past we have hardly ever had to tweak any of the scripts. We are currently using ECO V for a very large application and it has been nothing but a bliss to work with. As for win32 Delphi, Bold is the only one out there that I know of. Give ECO a go and I am sure you will appreciate MDD more.
JD