HI friends,

my project is developped in Visual Foxpro 9 SP1 installed on windows
2000 server. more than 100 client of Windows XP are working on it.

all tables in data environment are set optimistic table buffering
except CMS_IDS. Which is used to generate next available id. to get
new id i use the following procedure. e.g. i want to get new book_id
to use in lm_book_master.

fn_room_id = get_new_id("BOOK_ID")

the code to generate get_new_id is..

PROCEDURE get_new_id
PARAMETERS lc_key AS CHARACTER

SELECT cms_ids
FLOCK("CMS_IDS")

LOCAL ln_new_id AS INTEGER

LOCATE FOR lc_key NOOPTIMIZE
IF FOUND()
ln_new_id = last_id + 1
REPLACE last_id WITH ln_new_id
ELSE
ln_new_id = 1
INSERT INTO cms_ids (KEY,last_id) VALUE (lc_key,ln_new_id)
ENDIF
UNLOCK IN cms_ids

RETURN ln_new_id
ENDPROC
************

Now the problem is some time a record exist with BOOK_ID but it
appears as not found and new record will be added with value 1. why
this happen, any suggesstion, soory for my poor english.

RE: Duplicate IDs sometime by Allan

Allan
Mon Jun 18 06:02:00 CDT 2007

hi,

i think your problem is in the use of LOCATE, it should be:

LOCATE FOR KEY = lc_key

also, 'KEY' as a fieldname is ambiguous as it is a VFP reserved word... i
will rename it if i were you... and create an index for it so you can
optimize Locate or Seek...

hope this would help...

allan

"intel4" wrote:

> HI friends,
>
> my project is developped in Visual Foxpro 9 SP1 installed on windows
> 2000 server. more than 100 client of Windows XP are working on it.
>
> all tables in data environment are set optimistic table buffering
> except CMS_IDS. Which is used to generate next available id. to get
> new id i use the following procedure. e.g. i want to get new book_id
> to use in lm_book_master.
>
> fn_room_id = get_new_id("BOOK_ID")
>
> the code to generate get_new_id is..
>
> PROCEDURE get_new_id
> PARAMETERS lc_key AS CHARACTER
>
> SELECT cms_ids
> FLOCK("CMS_IDS")
>
> LOCAL ln_new_id AS INTEGER
>
> LOCATE FOR lc_key NOOPTIMIZE
> IF FOUND()
> ln_new_id = last_id + 1
> REPLACE last_id WITH ln_new_id
> ELSE
> ln_new_id = 1
> INSERT INTO cms_ids (KEY,last_id) VALUE (lc_key,ln_new_id)
> ENDIF
> UNLOCK IN cms_ids
>
> RETURN ln_new_id
> ENDPROC
> ************
>
> Now the problem is some time a record exist with BOOK_ID but it
> appears as not found and new record will be added with value 1. why
> this happen, any suggesstion, soory for my poor english.
>
>

Re: Duplicate IDs sometime by Man-wai

Man-wai
Mon Jun 18 07:08:12 CDT 2007

> LOCATE FOR lc_key NOOPTIMIZE

this one should be:

locate for KEY="BOOK_ID"

> SELECT cms_ids
> FLOCK("CMS_IDS")

You don't need to lock the whole DBF but just the relevant record after
the LOCATE.

Also, you should have error handing. What if RLOCK() failed?


shouldn't it?

--
@~@ Might, Courage, Vision, SINCERITY. http://www.linux-sxs.org
/ v \ Simplicity is Beauty! May the Force and Farce be with you!
/( _ )\ (Xubuntu 7.04) Linux 2.6.21.5
^ ^ 20:05:01 up 9:37 0 users load average: 0.02 0.02 0.00
news://news.3home.net news://news.hkpcug.org news://news.newsgroup.com.hk

Re: Duplicate IDs sometime by intel4

intel4
Mon Jun 18 07:35:18 CDT 2007

ok, actually the sentence is

LOCATE FOR key = lc_key NOOPTIMIZE

it is indexed.

but why foxpro sometime return .f. in found() function after locate
command. this will case to add new record with value 1.


Re: Duplicate IDs sometime by Man-wai

Man-wai
Mon Jun 18 08:26:52 CDT 2007

> but why foxpro sometime return .f. in found() function after locate
> command. this will case to add new record with value 1.

You sure that they are all reading the same file?

--
@~@ Might, Courage, Vision, SINCERITY. http://www.linux-sxs.org
/ v \ Simplicity is Beauty! May the Force and Farce be with you!
/( _ )\ (Xubuntu 7.04) Linux 2.6.21.5
^ ^ 21:26:01 up 10:58 0 users load average: 0.03 0.02 0.00
news://news.3home.net news://news.hkpcug.org news://news.newsgroup.com.hk

Re: Duplicate IDs sometime by Man-wai

Man-wai
Mon Jun 18 08:27:27 CDT 2007

> but why foxpro sometime return .f. in found() function after locate
> command. this will case to add new record with value 1.

And is there a program that delete record from that file?

--
@~@ Might, Courage, Vision, SINCERITY. http://www.linux-sxs.org
/ v \ Simplicity is Beauty! May the Force and Farce be with you!
/( _ )\ (Xubuntu 7.04) Linux 2.6.21.5
^ ^ 21:27:01 up 10:59 0 users load average: 0.01 0.02 0.00
news://news.3home.net news://news.hkpcug.org news://news.newsgroup.com.hk

Re: Duplicate IDs sometime by Man-wai

Man-wai
Mon Jun 18 08:59:57 CDT 2007

>
> And is there a program that delete record from that file?
>

Maybe there is a program error that deleted the wrong record from the
wrong file. Another possibility is caching error.

--
@~@ Might, Courage, Vision, SINCERITY. http://www.linux-sxs.org
/ v \ Simplicity is Beauty! May the Force and Farce be with you!
/( _ )\ (Xubuntu 7.04) Linux 2.6.21.5
^ ^ 21:59:01 up 11:31 0 users load average: 0.16 0.05 0.01
news://news.3home.net news://news.hkpcug.org news://news.newsgroup.com.hk

Re: Duplicate IDs sometime by Beverly

Beverly
Mon Jun 18 10:32:01 CDT 2007

>> LOCATE FOR key = lc_key NOOPTIMIZE <<

unless something has changed in vfp from my experience I don't think you
should be using the above syntax to find an indexed value.

"LOCATE" (at least originally) is a very different process even if it
does use the index nowadays.

set order...
SEEK lc_key
If found() and rock()
...

The other suggestion I would make is after successfully locking the
record and updating it, issue a FLUSH before unlocking it... in the past
I have verified that it's possible for another process to squeeze in
between your unlock and the actual file write.

Beverly Howard




Re: Duplicate IDs sometime by Dan

Dan
Mon Jun 18 10:37:11 CDT 2007

Remember that VFP is case-sensitive.

LOCATE FOR Upper(key) = Upper(lc_key) NOOPTIMIZE


Dan

intel4 wrote:
> ok, actually the sentence is
>
> LOCATE FOR key = lc_key NOOPTIMIZE
>
> it is indexed.
>
> but why foxpro sometime return .f. in found() function after locate
> command. this will case to add new record with value 1.



Re: Duplicate IDs sometime by intel4

intel4
Tue Jun 19 02:37:13 CDT 2007

1. lc_key is passed in upper case.
2. caching of shared folder is turned off.
3. there is no coding to delete orginal record, original record exist
& locate command return .f. in found() function.
3. the CMS_IDS table in unbuffered in data environment.

But problem occures sometime.



Re: Duplicate IDs sometime by Man-wai

Man-wai
Wed Jun 20 02:09:05 CDT 2007

> & locate command return .f. in found() function.
> 3. the CMS_IDS table in unbuffered in data environment.


Mind to tell us the hardware and software configs of the machines
involving in getting the BOOK_ID.

--
iTech Consulting Services Limited
Expert in ePOS (Point-Of-Sales) solutions
Website: http://www.itech.com.hk (IE only)
Tel: (852)2325 3883 Fax: (852)2325 8288

Re: Duplicate IDs sometime by intel4

intel4
Wed Jun 20 08:36:58 CDT 2007

Visual Foxpro 9.0 SP1, crystal report 9 with SP7, windows xp SP2

intel 845 mb, 512 mb ram, d-link nic etc.

any many other configuration found in network.




Re: Duplicate IDs sometime by Man-wai

Man-wai
Wed Jun 20 08:58:19 CDT 2007

> intel 845 mb, 512 mb ram, d-link nic etc.

Dlink NICs?? Could you swap them with 3com or Intel? :)

--
@~@ Might, Courage, Vision, SINCERITY. http://www.linux-sxs.org
/ v \ Simplicity is Beauty! May the Force and Farce be with you!
/( _ )\ (Xubuntu 7.04) Linux 2.6.21.5
^ ^ 21:57:01 up 2 days 11:29 0 users load average: 0.00 0.00 0.00
news://news.3home.net news://news.hkpcug.org news://news.newsgroup.com.hk

Re: Duplicate IDs sometime by Al

Al
Wed Jun 20 09:00:54 CDT 2007

it appears that you do not check if the flock was successful
if it is not, this is just the case you need to avoid
it must be successful to insure no duplicates

al



"intel4" <intel_inside_4@hotmail.com> wrote in message
news:1182156032.095525.33580@a26g2000pre.googlegroups.com...
> HI friends,
>
> my project is developped in Visual Foxpro 9 SP1 installed
> on windows
> 2000 server. more than 100 client of Windows XP are
> working on it.
>
> all tables in data environment are set optimistic table
> buffering
> except CMS_IDS. Which is used to generate next available
> id. to get
> new id i use the following procedure. e.g. i want to get
> new book_id
> to use in lm_book_master.
>
> fn_room_id = get_new_id("BOOK_ID")
>
> the code to generate get_new_id is..
>
> PROCEDURE get_new_id
> PARAMETERS lc_key AS CHARACTER
>
> SELECT cms_ids
> FLOCK("CMS_IDS")
>
> LOCAL ln_new_id AS INTEGER
>
> LOCATE FOR lc_key NOOPTIMIZE
> IF FOUND()
> ln_new_id = last_id + 1
> REPLACE last_id WITH ln_new_id
> ELSE
> ln_new_id = 1
> INSERT INTO cms_ids (KEY,last_id) VALUE (lc_key,ln_new_id)
> ENDIF
> UNLOCK IN cms_ids
>
> RETURN ln_new_id
> ENDPROC
> ************
>
> Now the problem is some time a record exist with BOOK_ID
> but it
> appears as not found and new record will be added with
> value 1. why
> this happen, any suggesstion, soory for my poor english.
>



Re: Duplicate IDs sometime by Man-wai

Man-wai
Wed Jun 20 09:09:56 CDT 2007

> Dlink NICs?? Could you swap them with 3com or Intel? :)
>
Or maybe Realtek which are cheaper.

--
@~@ Might, Courage, Vision, SINCERITY. http://www.linux-sxs.org
/ v \ Simplicity is Beauty! May the Force and Farce be with you!
/( _ )\ (Xubuntu 7.04) Linux 2.6.21.5
^ ^ 22:09:01 up 2 days 11:41 0 users load average: 0.04 0.03 0.00
news://news.3home.net news://news.hkpcug.org news://news.newsgroup.com.hk

Re: Duplicate IDs sometime by Man-wai

Man-wai
Wed Jun 20 09:10:18 CDT 2007

> intel 845 mb, 512 mb ram, d-link nic etc.

Wireless?

--
@~@ Might, Courage, Vision, SINCERITY. http://www.linux-sxs.org
/ v \ Simplicity is Beauty! May the Force and Farce be with you!
/( _ )\ (Xubuntu 7.04) Linux 2.6.21.5
^ ^ 22:09:01 up 2 days 11:41 0 users load average: 0.04 0.03 0.00
news://news.3home.net news://news.hkpcug.org news://news.newsgroup.com.hk

Re: Duplicate IDs sometime by intel4

intel4
Tue Aug 07 05:04:54 CDT 2007

no wireless