Page 1 of 1

Database import

Posted: Mon Apr 25, 2011 8:21 am
by RDalzell
Hi everybody,

I am unable to import the Test.Txt file into the Test.Dbf

I would prefer to have this as a menu option rather than an external program.

Using xdot, i get 4 empty records appended.

Any help would be appreciated.

Thanks,
Rick

Re: Database import

Posted: Mon Apr 25, 2011 8:39 am
by wkedv
Hi,

The separator between the fields " ~ " is the problem.

This is not a delimiter.

Kurt

Re: Database import

Posted: Mon Apr 25, 2011 8:59 am
by RDalzell
Hi Kurt,

I tried the parameter DELIMITED WITH to no avail.

When using xdot, the fields map properly as long as the delimiter is changed from the defaulted comma to the tilde.

Rick

Re: Database import

Posted: Mon Apr 25, 2011 9:23 am
by rdonnay
Rick -

I'll give it a look and get back to you.

Meanwhile, take a look at \exp19\samples\csv\csvimp.prg.
There is a new one attached. I made some changes recently for Aidan Harland.

I use this utility for importing to a DBF from a CSV file.
It allows for mapping of fields.

BTW - I will be in Glen Ellyn Tuesday thru Friday this week. Flying back home on Saturday.
It would be great if we can find time to get together for dinner one night.

Roger

Re: Database import

Posted: Mon Apr 25, 2011 9:47 am
by rdonnay
Here's program that will do the import:

Code: Select all

#INCLUDE "dcdialog.CH"

FUNCTION Main()

Import( 'Test', 'Test.Txt', '~' )

RETURN nil

* --------------

FUNCTION Import( cDbf, cText, cDelim )

LOCAL nHandle, cLine, aFields, aStru

USE (cDbf)
aStru := (cDbf)->(dbStruct())
nHandle := DC_TxtOpen(cText)

DO WHILE !DC_TxtEof(nHandle)

  cLine := DC_TxtLine( nHandle )
  aFields := DC_TokenArray(cLine,cDelim)
  FormatFields(aFields,aStru)
  IF (cDbf)->(DC_AddRec(5))
    (cDbf)->(Gather(aFields))
    (cDbf)->(dbRUnlock())
  ENDIF
  DC_TxtSkip(nHandle,1)

ENDDO

(cDbf)->(dbCloseArea())
DC_TxtClose(nHandle)

RETURN nil

* ---------

PROC appsys ; return

* ---------

FUNCTION FormatFields( aFields, aStru )

LOCAL i, cType

FOR i := 1 TO Len(aStru)
  cType := aStru[i,2]
  IF cType = 'D'
    aFields[i] := CtoD(aFields[i])
  ELSEIF cType = 'L'
    aFields[i] := Upper(aFields[i])[1] $ 'YT'
  ELSEIF cType = 'N'
    aFields[i] := Val(aFields[i])
  ENDIF
NEXT

RETURN nil

Re: Database import

Posted: Mon Apr 25, 2011 10:38 am
by RDalzell
Thanks Roger,

Next week sounds great, let me know when is best for you, Ruths Chris, Harry Caray's, 94th Aero Squadron and Maggianos are nearby should you have a hankering for some red meat in your diet....

Re: Database import

Posted: Mon Apr 25, 2011 10:53 am
by rdonnay
Not NEXT week, THIS week! Leaving tomorrow!!!

Re: Database import

Posted: Mon Apr 25, 2011 11:43 am
by RDalzell
OK, gee you must be HUNGRY.....

Have a meeting tomorrow evening will leave the remainder of the week for when you are available.

See you soon.

Re: Database import

Posted: Mon Apr 25, 2011 12:26 pm
by rdonnay
Spending the week with lawyers. Gonna learn a lot about depositions.

I'll call you after I find out what the lawyers have in mind first.