Discussion:
databas engine error
(too old to reply)
Alin Rusu
2008-11-18 19:37:12 UTC
Permalink
I made a routine to check if use user left out a field on there import and add it if need be... I works on my system but when I deploy it to a customer, they error on the alter table line.
'name not unique in this context, restemp.DBF'

ALTER TABLE "IMPORT.dbf" ADD ADDRESS3 CHAR(30)



**************************************************
use import excl
x=0
DOIT=0
do while .t.
x=x+1
if field(x)='address3'
store 1 TO DOIT
endif
if x=200
exit
endif
enddo

USE
IF DOIT=0
ALTER TABLE "IMPORT.dbf" ADD ADDRESS3 CHAR(30)

ENDIF
*****************************************************
Mervyn Bick
2008-11-18 21:02:16 UTC
Permalink
Post by Alin Rusu
I made a routine to check if use user left out a field on there import
and add it if need be... I works on my system but when I deploy it to a
customer, they error on the alter table line.
'name not unique in this context, restemp.DBF'
''''''
Post by Alin Rusu
if field(x)='address3'
dBase is not case-sensitive as far as commands and variables go (and of
course properties, events and methods) but string comparisons ARE
case-sensitive. Your table has the fieldname in lower case but it is
possible that your customer has used upper, or mixed, case. Your code
would then not find the field although it is there. ALTER TABLE then
complains about adding a duplicate field name.


if lower(field(x)) = 'address3'
Post by Alin Rusu
store 1 TO DOIT
endif
if x=200
exit
endif
enddo
USE
IF DOIT=0
ALTER TABLE "IMPORT.dbf" ADD ADDRESS3 CHAR(30)
ENDIF
*****************************************************
I don't know what version of dBase you are using but the style of coding
takes me back to the days of dBase II. <g> (It's been a LONG time since
one needed to use .t. although it does still work.) If code works it
isn't wrong but have a look at the following. It is untested but it
should do the job. It is a matter of style but I don't like jumping out
of the middle of a loop. On the other hand, many programmers do this
regularly.


use import exclusive
lAddFld = true
for x = 1 to fldcount()
if lower(field(x)) = 'address3'
lAddFld = false
endif
next
use
if lAddFld
ALTER TABLE "IMPORT.dbf" ADD ADDRESS3 CHAR(30)
endif

Mervyn.

Loading...