|
Home > Archive > Programming with dBASE > February 2006 > append from .csv file
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
append from .csv file
|
|
|
| This had been covered, but the "article has expired", so I must ask. I
have a file with a .csv extension that contains a line of data which is:
"a","b","cde","fghi", etc
I have a table, and I issue append from mycsvfile.csv delimited. Only
the first item shows up, without the quotes. I copied to a text file,
same result. I allowed 40 bytes for the field in my table.
What am I doing wrong here??
Thanks,
Glenn Fausel
| |
| Tom Preston 2006-02-17, 8:23 pm |
| In article <y20R5uANGHA.2016@news-server>, gfausel@aol.com says...
> This had been covered, but the "article has expired", so I must ask. I
> have a file with a .csv extension that contains a line of data which is:
> "a","b","cde","fghi", etc
>
> I have a table, and I issue append from mycsvfile.csv delimited. Only
> the first item shows up, without the quotes. I copied to a text file,
> same result. I allowed 40 bytes for the field in my table.
>
> What am I doing wrong here??
>
> Thanks,
>
> Glenn Fausel
>
Hi Glenn,
Try...
append from mycsvfile.csv type delimited for true
| |
|
| Tom Preston wrote:
> In article <y20R5uANGHA.2016@news-server>, gfausel@aol.com says...
>
>
> Hi Glenn,
>
> Try...
> append from mycsvfile.csv type delimited for true
Thanks Tom, but it gave me a capability not supported error message.
Glenn
| |
| Mervyn Bick 2006-02-18, 3:23 am |
| On Fri, 17 Feb 2006 23:40:59 +0200, Glenn <gfausel@aol.com> wrote:
> This had been covered, but the "article has expired", so I must ask. I
> have a file with a .csv extension that contains a line of data which is:
> "a","b","cde","fghi", etc
>
> I have a table, and I issue append from mycsvfile.csv delimited. Only
> the first item shows up, without the quotes. I copied to a text file,
> same result. I allowed 40 bytes for the field in my table.
I don't know if I am misreading your post but if you only have one field
in the .dbf table, no matter how long it is (provided it is not too short
<g> ), you will only get the first "a" from each record in the .csv file.
If you have four character type fields in the .dbf table the .dbf record
should have "a" in the first field, "b" in the second field (all without
the quote marks) and so on.
If what you want to do is have the entire "a","b","cde","fghi", etc in
one one field per record in the .dbf file complete with commas and quote
marks you will have to tackle this differently. You will have to read a
line at a time from the .csv file into a variable using the file class
gets() method, append a blank row to the .dbf file and then replace the
field with the variable.
Mervyn
| |
| Ivar B. Jessen 2006-02-18, 7:23 am |
| On Fri, 17 Feb 2006 16:40:59 -0500, in dbase.programming,
Subject: append from .csv file,
Message-ID: <y20R5uANGHA.2016@news-server>,
Glenn <gfausel@aol.com> wrote:
>This had been covered, but the "article has expired", so I must ask. I
>have a file with a .csv extension that contains a line of data which is:
>"a","b","cde","fghi", etc
>
>I have a table, and I issue append from mycsvfile.csv delimited. Only
>the first item shows up, without the quotes. I copied to a text file,
>same result. I allowed 40 bytes for the field in my table.
Glenn,
You could use the file class to read in each line from the csv file or you could
use the custom data module "Text Table.dmd" in the samples directory.
To try the dmd do the following from the command pane:
1) copy "Text Table.dmd" to a new dmd to avoid altering the original and to
avoid the space in the file name.
copy file ":samples:Text Table.dmd" to :samples:TextTable.dmd
2) Give TextTable.dmd a parameter.
modi comm:samples:TextTab
le.dmd
In the source editor comment out the first define and add a parameter after the
class statement as indicated,
*#define TEXT_TABLE "Text Table.txt" // <---
#include <vdbase.h>
#define NAVIGATE_NEXT 1
#define NAVIGATE_FIRST 2
#define NAVIGATE_LAST 3
#define STATE_CLOSED 0
#define STATE_EDIT 2
#define STATE_APPEND 3
** END HEADER -- do not remove this line
//
// Generated on 01/20/98
//
class TextTableDataModule of DATAMODULE
parameters TEXT_TABLE // <---
Save TextTable.dmd and close source editor, then run the code below my signature
to import a csv file of the type you use into a table.
It is probably much easier to use the file class for import, but as you are not
afraid of proposing use of code that is more convoluted than neccessary the
method outlined here might interest you <g>
Ivar B. Jessen
//-----
close tables
if file("glenn.dbf")
drop table glenn
endif
// Create table to import csv file into
create table glenn(fName char(41))
// Create a csv file
if not file("glenn.csv")
f = new file()
f.create("glenn.csv")
f.open("glenn.csv", "W")
f.puts(["a","b","cde","fghi","a","b","cde","fghi"])
f.puts(["b","a","edc","ihfg","b","a","edc","ihfg"])
f.close()
endif
// Instantiate the modified data module
set proc to :samples:TextTable.dmd additive
tt = new TextTableDataModule(
"glenn.csv")
// Import the csv file
use glenn
tt.rowset.first()
do while not tt.rowset.eof
append blank
replace fName with tt.rowset.fields[1].value
tt.rowset.next()
enddo
// Display result
goto top
browse
//-----
| |
|
| > This had been covered, but the "article has expired", so I must ask. I
> have a file with a .csv extension that contains a line of data which is:
> "a","b","cde","fghi", etc
>
> I have a table, and I issue append from mycsvfile.csv delimited. Only the
> first item shows up, without the quotes. I copied to a text file, same
> result. I allowed 40 bytes for the field in my table.
If you want to put all the data from each line in to one field with quotes
and commas then do the following.
Make sure the field is large enough to hold one line of data.
append from mycsvfile.csv type sdf
| |
|
| Mervyn Bick wrote:
> On Fri, 17 Feb 2006 23:40:59 +0200, Glenn <gfausel@aol.com> wrote:
>
>
>
> I don't know if I am misreading your post but if you only have one
> field in the .dbf table, no matter how long it is (provided it is not
> too short <g> ), you will only get the first "a" from each record in the
> .csv file. If you have four character type fields in the .dbf table
> the .dbf record should have "a" in the first field, "b" in the second
> field (all without the quote marks) and so on.
>
> If what you want to do is have the entire "a","b","cde","fghi", etc in
> one one field per record in the .dbf file complete with commas and
> quote marks you will have to tackle this differently. You will have to
> read a line at a time from the .csv file into a variable using the file
> class gets() method, append a blank row to the .dbf file and then
> replace the field with the variable.
>
> Mervyn
thanks to all. I was expecting the same results as append from myfile
sdf which would place each item in a new row. I used the gets() and got
one item in each row, then used CREATE FROM to get the desired table.
Glenn
|
|
|
|
|