FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour CSV to DBF
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: CSV to DBF
Posted: Thu Aug 29, 2013 01:03 AM

Try APPEND FROM ..... SDF

Regards



G. N. Rao.

Hyderabad, India
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: CSV to DBF
Posted: Thu Aug 29, 2013 05:24 AM

Or,

append from ... delimited with chr(32)

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 301
Joined: Fri Jun 01, 2007 09:07 AM
Re: CSV to DBF
Posted: Thu Aug 29, 2013 07:32 AM

Or
you can still use my function and have more control
I use it with years

Regards,

Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: CSV to DBF
Posted: Thu Aug 29, 2013 04:04 PM
Mr Nages and all,

I made this test

Code (fw): Select all Collapse
#include "fivewin.ch"
#include "xbrowse.ch"
#include "hbcompat.ch"

REQUEST DBFCDX


function Main()

csvfile:=".\2013.txt"

Create_Db()

   USE WIN4LI.DBF NEW ALIAS DST

APPEND FROM ".\2013.txt"  SDF



REturn Nil 



Function Create_Db()
  //-------------------------------------//
DBCREATE('LI.DBF',{{'CONCORSO','N',004,000},;
         {'DATA','D',008,000},;
                   {'TIME','C',005,000},;
                   {'ESTRA1','N',002,000},;
                   {'ESTRA2','N',002,000},;
                   {'ESTRA3','N',002,000},;
                   {'ESTRA4','N',002,000},;
                   {'ESTRA5','N',002,000},;
                   {'ESTRA6','N',002,000},;
                   {'ESTRA7','N',002,000},;
                   {'ESTRA8','N',002,000},;
                   {'ESTRA9','N',002,000},;
                   {'ESTRA10','N',002,000},;
                   {'NUMERONE','N',002,000}}, 'DBFCDX') 

  close all
      use &('LI') new
      select LI
      if FILE('wIN4LI.DBF')
         delete file &('wIN4LI.cdx')
         append from &('WIN4LI')
         dbcommitall()
         close all
         delete file &('WIN4LI.dbf')
      endif
      close all
      rename &('LI.dbf') to &('WIN4LI.dbf')

  //-------------------------------------//
      Return nil





the problem is it not run ok as you can see here :




there is not the date and the time is wrong
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: CSV to DBF
Posted: Thu Aug 29, 2013 04:27 PM

Silvio

APPEND FROM .... converts dates ONLY of the source data is in YYYYMMDD format.

In your case you have to create the field as character field with length 10.
After importing you have to copy to other file converting date with CTOD()

Or you can adopt my earlier logic with needed changes. Change the field delimiter from ";" to " "

Regards



G. N. Rao.

Hyderabad, India
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: CSV to DBF
Posted: Thu Aug 29, 2013 04:36 PM

I tried with your logic func but it not run

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: CSV to DBF
Posted: Thu Aug 29, 2013 05:20 PM
Silvio
Because you asked, I shall post suitable code in my next post. But I want to advise that in most cases it is preferable to use APPEND FROM ...SDF or DELIMITED depending on the type of text file.

This is fast, very reliable and works precisely as documented. Important thing is we should be clear of what is the documented behavior and use it accordingly.

Even in your first case, I would prefer to first import using APPEND FROM ..DELIMITED and then in a second pass convert the dates. I provided the code only as a variation.
Regards



G. N. Rao.

Hyderabad, India
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: CSV to DBF
Posted: Fri Aug 30, 2013 07:40 PM

Thank you, I thought it was easy to convert these types of files

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com

Continue the discussion