// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // ! This script is provided "as is" by Applied Maths. ! // ! You are free to use and modify this script for your own needs. ! // ! Redistribution or reproduction of the script is prohibited. ! // ! DISCLAIMER: ! // ! Improper use of scripts may corrupt your database. ! // ! Running this script is entirely at your own responsibility. ! // ! Applied Maths accepts no lialibility for any consequences ! // ! resulting from its use. ! // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DIALOG dlg,dlg2; string fieldlst,fieldname,errorlist,st; string oldkey,newkey,expername,experID; integer i,j,ok; for i=1 to DbGetFieldCount do fieldlst=fieldlst+DbGetFieldName(i)+" "; DlgAddText(dlg,"Select the field to use as key:",15,15,150,15); DlgAddList(dlg,fieldlst,fieldname,15,35,150,150,"LIST"); st="WARNING: Use this script with care. If the field is not suited for usage as a key, it may corrupt your database."; st=st+"Make a backup of your database before running this script"; DlgAddText(dlg,st,15,180,150,90); while length(fieldname)<=0 do if not(DlgShow(dlg,"Copy field to key",280,300)) then stop; setbusy("Processed 0"); for i=1 to DbGetEntryCount do { if floor(i/5)=i/5 then setbusy("Processed "+str(i,0,0)); oldkey=DbGetEntryKey(i); newkey=DbGetField(oldkey,fieldname); ok=1; if length(newkey)=0 then { errorlist=errorlist+oldkey+" -> "+newkey+" : new key has zero length~n"; ok=0; } if ok then { if DbIsKeyPresent(newkey) then { errorlist=errorlist+oldkey+" -> "+newkey+" : new key is already present in the database~n"; ok=0; } } if ok then { for j=1 to DbGetExperCount do { expername=DbGetExperName(j); experID=DbGetEntryLink(newkey,expername); if length(experID)>0 then { errorlist=errorlist+oldkey+" -> "+newkey+" : new key is already used for experiment "+expername+"~n"; ok=0; } } if ok then DbSetEntryKey(oldkey,newkey,1); } } setbusy(""); if length(errorlist)=0 then { message("Conversion successfully completed!"); stop; } DlgAddText(dlg2,"The following problems were encountered:",15,15,300,15); DlgAddEdit(dlg2,errorlist,15,35,400,300); DlgShow(dlg2,"Error report",440,460);