Its all Greek to me...Chris wrote:robert wrote:In the team Chris is our guardian of readability.
[2.4] AppendDelimited?
- lumberjack
- Posts: 727
- Joined: Fri Sep 25, 2015 3:11 pm
- Location: South Africa
[2.3] AppendDelimited?
______________________
Johan Nel
Boshof, South Africa
Johan Nel
Boshof, South Africa
[2.4] AppendDelimited?
So, back with 2.4 still using the same mini X#-RT app:
Still compiles fine, returns ".T." but keeps the dbf empty.
I can't find in the help of AppendDelimited any mention that i would have to set to another driver, nor do i see anything in the what's new paragraphs regarding RDD to explain, why i fail...
I changed to an inherited server class to add the AppendDelimited Code from Git, to see if i could find a clue in debugging, but to no avail.
The source looks like:
kdno,adrno,nname,vname,straße,plz,ort,staat
0492,0001,Stump,Rüdiger,Im Tal 21,79136,Rickenbach,D
....
(in reality the fields are right padded with blanks for the required field length)
TIA!
Code: Select all
FUNCTION Start( ) AS VOID
RddSetDefault("dbfcdx")
csf2dbf()
RETURN
FUNCTION csf2dbf() AS LOGIC
LOCAL cPfad, cSource, cDbf AS STRING
LOCAL lOK := FALSE AS LOGIC
LOCAL oDB AS DbServer
cPfad:= "C:S4__KVDB"
cSource:= "kv_lieferad.csv"
cDbf:= "kv_Lieferad.dbf"
oDB:= DbServer{cPfad+cDbf}
? lOK := oDB:AppendDelimited(cPfad+cSource, ",")
RETURN lOK
I can't find in the help of AppendDelimited any mention that i would have to set to another driver, nor do i see anything in the what's new paragraphs regarding RDD to explain, why i fail...
I changed to an inherited server class to add the AppendDelimited Code from Git, to see if i could find a clue in debugging, but to no avail.
The source looks like:
kdno,adrno,nname,vname,straße,plz,ort,staat
0492,0001,Stump,Rüdiger,Im Tal 21,79136,Rickenbach,D
....
(in reality the fields are right padded with blanks for the required field length)
TIA!
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
[2.4] AppendDelimited?
Karl,
Can you mail me the DBF and text file ?
Robert
Can you mail me the DBF and text file ?
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
-
- Posts: 200
- Joined: Wed Oct 09, 2019 6:51 pm
[2.4] AppendDelimited?
Hi Karl,FFF wrote:The source looks like:
kdno,adrno,nname,vname,straße,plz,ort,staat
0492,0001,Stump,Rüdiger,Im Tal 21,79136,Rickenbach,D
....
(in reality the fields are right padded with blanks for the required field length)
not to the code in question, but as a general hint from the embolded part of your post:
if the source is really rightpadded to field len (which for instance is typical for adress brokers), it is MUCH safer to create an input cursor or tmp table with all as txt fields plus "comma fields"
Code: Select all
kdno C(4), comma01 C(1), adrno C(4) ,comma02 C(1), nname C(25),comma03 C(1), vname C(25),comma04 C(1), straße C(45),comma05 C(1), plz C(5) ,comma06 C(1), ort C(40), comma07 C(1), staat C(30)
and in second step select all "real" fields, CASTing val() of the numeric fields to correct data type in result cursor, thereby getting rid of all "comma0x" fields.
Even in Excel-like delimited char fields you will sooner or later run into fields where delimiter is inside the field (or separator, if not delimited) and you have import troubles - not so if importing as SDF.
Yes, results in "reading" data twice, but not a real showstopper in performance time
If source is/has to be really any kind of CSV, try to define/agree on separator/delimter totally out of normal usage: Even | and chr(7) might happen in text given as source (think table header or error notification msg), try to pick safest among control ASCII chars (below dec 32/space), perhaps out of the device control range...
If this a recurring task, both tables usually can be created via fixed routine from data dictionary description given with data from source or parsing first data row typically echoing the field names - then you are in safer SDF waters.
Been there, done that (for a couple of years...): less to worry about.
thomas
[2.4] AppendDelimited?
Thomas,
all valid points, much appreciated. In this case, IIRC, this is the first csv i read for > 10 years, so, no, no recurring task
all valid points, much appreciated. In this case, IIRC, this is the first csv i read for > 10 years, so, no, no recurring task
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
[2.4] AppendDelimited?
Karl,
The problem seems to be that there are actually 3 delimiters involved when reading a text file like this:
1) The (optional) string delimiters around text value (missing in your case)
2) the field delimiters between the fields
3) the record delimiters (CRLF in your case)
The documentation for AppendDelimited() says that the cDelimiter parameter is "The delimiter for fields within a delimited database file. " In my implementation I had not correctly implemented this and used this delimiter for the string values (1).
If you call AppendDelimited() without this parameter then it works. However the field names on the first row are "corrupted". That happens also in VO, because the file has a Byte Order Mark in the beginning (it is UTF8). If you convert the text file to Ansi then it works.
I will see if I can detect this in the RDD system and convert the file on the fly.
Robert
The problem seems to be that there are actually 3 delimiters involved when reading a text file like this:
1) The (optional) string delimiters around text value (missing in your case)
2) the field delimiters between the fields
3) the record delimiters (CRLF in your case)
The documentation for AppendDelimited() says that the cDelimiter parameter is "The delimiter for fields within a delimited database file. " In my implementation I had not correctly implemented this and used this delimiter for the string values (1).
If you call AppendDelimited() without this parameter then it works. However the field names on the first row are "corrupted". That happens also in VO, because the file has a Byte Order Mark in the beginning (it is UTF8). If you convert the text file to Ansi then it works.
I will see if I can detect this in the RDD system and convert the file on the fly.
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
[2.4] AppendDelimited?
Robert,
thx, that did the trick. One additional glitch: the AppendDelimited called without delim param now inserts the fieldnames as values of the first record...
thx, that did the trick. One additional glitch: the AppendDelimited called without delim param now inserts the fieldnames as values of the first record...
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
[2.4] AppendDelimited?
Karl,
That's what VO does as well.
Robert
That's what VO does as well.
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
[2.4] AppendDelimited?
Really? Never had to try... Then, pls remove this compatibilityrobert wrote:Karl,
That's what VO does as well.
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)