>Hi all,
>
>I have the following program. Every time, when I run there is an error message: "Uniqueness of index key "cross_key" is violated" then I check the db, I find one record is add but the key fields(CROSS_ID, CURM_D) are null.
>
>set exac on
>sele pc_quota
>set order to cross_key
>if findrecord == .F.
> allocat_array(1,1) = '01/2001'
>endif
>
>i =1
>count_u =0
>count_new =0
>j = alen(allocat_array,1)
>if messagebox('Are you sure to update?',4,'Confirm message') = 6
> for y = 1 to totalmonth +1
> txt_d = 'txt_d' + allt(str(y))
> txt_q = 'txt_q' + allt(str(y))
>
> select pc_quota
> scan for thisform.&txt_d..value == allocat_array(i,1) and cross_id == crossid
> if found()
> replace curm_quo with allt(thisform.&txt_q..value )
> count_u = count_u+1
> i=i+1
> else
> append blank
> replace cross_id with crossid
> replace curm_d with thisform.&txt_d..value
> replace curm_quo with thisform.&txt_q..value
> count_new = count_new+1
> endif
> endscan
> if i>j
> i=1
> endif
>
> endfor
>
Hi Linda,
I think (CROSS_ID, CURM_D) set up cross_key. In your code in scan for ...endscan loop there is a :
if found()
I couldn't see any code that would set it to .t. (seek, locate, find, indexseek()). It'd always be .f. causing else part to execute. cross_Id would match crossid and only chance that primary key wouldn't be violated would depend on curm_d value (thisform.&txt_d..value).
Scan for thisform.&txt_d..value == allocat_array(i,1) and cross_id == crossid
thisform.&txt_d..value == allocat_array(i,1) is not a table value dependant expression. It would be either .t. or .f. for a allocat_array member and actually you'd be either saying :
Scan for .f. and cross_id == crossid
causing scan..endscan do nothing or :
Scan for .t. and cross_id == crossid
causing all cross_id == crossid records be scanned.
I suggest comment scan...endscan loop and temporarily put :
luVal = thisform.&txt_d..value
messagebox('Txt_d :'+trans(luVal)+chr(13)+;
'Array :'+trans(allocat_array(i,1))+chr(13)+;
'Equality : '+iif(luVal == allocat_array(i,1),'Yes','No'))
if luVal == allocat_array(i,1)
browse for cross_id == crossid
endif
To see if you're really operating on intended records.
Also it'd be better to use :
insert into pc_quota ;
(cross_id, curm_d, curm_quo) ;
values ;
(crossid, thisform.&txt_d..value, thisform.&txt_q..value)
instead of append blank+replace series. Append blank, if buffering is not used and a prior empty key value might immediately cause an index violation.
Cetin