[comp.sys.mac.apps] 4D Importing and Exporting Data

dragon@hubcap.clemson.edu (Michael E. Quattlebaum) (11/22/90)

I am helping with the development of a database for many users around
the country.  As you might imagine, we have several test sites where
we have people evaluating the database.  Now that most of the bugs are
out we are ready to ship the final version.  Along with this version 
has to go some data from the national clearinghouse to be merged with
their existing data.  No problem.  I can set up a procedure that exports
data and imports it so that they can do this easily.  The problem comes
with indexed fields.  Some of the data they have is likely to have the
same values for indexed fields (and thus 4D will not write that record).
I was wondering if anyone has any creative solutions to this problem.
Please respond via e-mail and I will summarize responses to the net.

Thanks in advance.

Michael Quattlebaum
Internet: dragon@hubcap.clemson.edu
AppleLink: ST0673

bmartin@uhccux.uhcc.Hawaii.Edu (Brian Martin) (11/25/90)

In article <11775@hubcap.clemson.edu> dragon@hubcap.clemson.edu (Michael E. Quattlebaum) writes:
> ... Some of the data they have is likely to have the
>same values for indexed fields (and thus 4D will not write that record).

Michael,

You have the "unique" attribute set for the indexed field. When you attempt
to add a record which contains a vlaue for that field which duplicates a
value already stored in another record, 4D rejects the attempted write,
which is as it should be.

The unique attribute should only be assigned to fields which are primary or
alternate keys for the record, i.e., the field uniquely identifies the
record in the file.

If you are indeed trying to import duplicate records, as when you would
update existing employee records with new sales information, then you need
a custom import routine.

The code off the top of my head would be something like:

$docref:=open document ("ImportFile")
Default file ([Employees])
receive packet ($docref; vEmpNum; FS)
receive packet ($docref; vSales; FS)
receive packet ($docref; vTerritory; RS)
while (OK=1)
  search ([Employees]EmpNum=vEmpNum)
  if (Records in selection=0)
     Create record
     [Employees]EmpNum:=vEmpNum
  end if
  [Employees]Sales:=vSales
  [Employees]Territory:=vTerritory
  Save record
  receive packet ($docref; vEmpNum; FS)
  receive packet ($docref; vSales; FS)
  receive packet ($docref; vTerritory; RS)
end while
close document ($docref)

Here, RS is the record separator that you define, and FS is the field
separator that you define.

Best regards,
    Brian K. Martin, M.D.
    Martin Information Systems, Ltd.
    1103 9th Avenue, Suite 203
    Honolulu, Hawai`i 96816-2403
    Voice (808) 733-2003
    Fax (808) 733-2011

INTERNET: martin@medix.pegasus.com, bmartin@uhccux.uhcc.hawaii.edu
ARPA: uhccux!bmartin@nosc.MIL
UUCP: {uunet,dcdwest,ucbvax}!ucsd!nosc!uhccux!bmartin