Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Append a new record
Message
From
06/02/2002 04:35:07
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
06/02/2002 02:54:48
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00615893
Message ID:
00615907
Views:
16
>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
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform