fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: [2.4] AppendDelimited?

[2.3] AppendDelimited? 14 Apr 2020 22:15 #14028

  • FFF's Avatar

  • FFF

  • Topic Author


  • Posts: 956
  • Robert,
    just had a look into source at
    github.com/X-Sharp/XSharpPublic/blob/fea...es_SDK/DBServer1.prg
    Lines 189/190 have:
    IF IsObject(oFSSource) .and. __Usual.ToObject(oFSSource) IS FileSpec  VAR oFS
    				cSource := oFS:FullPath
    Note the "VAR oFS".
    Is this correct code?
    Regards
    Karl (X# 2.5a; Xide 1.25; W8.1/64 German)

    Please Log in or Create an account to join the conversation.

    [2.3] AppendDelimited? 15 Apr 2020 08:58 #14030

  • Chris's Avatar

  • Chris


  • Posts: 1957
  • Hi Karl,

    I was not aware of this syntax that the guys have implemented! Here's a sample:

    FUNCTION Start() AS VOID
    	LOCAL oObject AS OBJECT
    	oObject := 123
    	IF oObject IS INT VAR nInt
    		? nInt * 2
    	END IF
    RETURN

    it just tells the compiler that if the var is indeed of the type we are checking for, to assign it to another var that is now strongly typed.
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    [2.3] AppendDelimited? 15 Apr 2020 09:13 #14031

  • robert's Avatar

  • robert


  • Posts: 1746
  • Chris,
    Correct. I originally wanted to implement it like this:
    IF oObject IS INT nInt
    but you indicated that that was "too much C#" so I added the VAR keyword as you requested:

    IF oObject IS INT VAR nInt
    The compiler emits something like this:
    IF oObject IS INT 
       VAR nInt := (INT) oObject
    - The variable is automatically typed as the type after the IS clause
    - The visibility of the variable is inside the IF branch only
    - Of course you can do a similar check in an ELSEIF for another type

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    [2.3] AppendDelimited? 15 Apr 2020 09:21 #14032

  • FFF's Avatar

  • FFF

  • Topic Author


  • Posts: 956
  • Chris wrote: Hi Karl,
    I was not aware of this syntax that the guys have implemented! Here's a sample:

    FUNCTION Start() AS VOID
    	LOCAL oObject AS OBJECT
    	oObject := 123
    	IF oObject IS INT VAR nInt
    		? nInt * 2
    	END IF
    RETURN
    it just tells the compiler that if the var is indeed of the type we are checking for, to assign it to another var that is now strongly typed.

    Ah, thx. Frankly spoken, i'd like it removed. There's no hint in the syntax what happens behind the scene, especially no assignment...
    As you wrote to my other question: if it would spare a lot of typing...

    The unfortunate thing is, that i now still don't see, why
    FUNCTION csf2dbf() AS LOGIC
    	LOCAL cPfad, cSource, cDbf AS STRING
    	LOCAL lOK := FALSE AS LOGIC
    	LOCAL oDB AS DbServer
    	cPfad:= "C:\DB\"
    	cSource:= "kv_lieferad.csv"
    	cDbf:= "kv_Lieferad.dbf"
    	oDB:= DbServer{cPfad+cDbf}
    ?	lOK := oDB:AppendDelimited(cSource, ",")
    RETURN  lOK
    produces no error, but returns ".F." and the target stays empty ;)
    Regards
    Karl (X# 2.5a; Xide 1.25; W8.1/64 German)

    Please Log in or Create an account to join the conversation.

    Last edit: by FFF.

    [2.3] AppendDelimited? 15 Apr 2020 09:23 #14033

  • robert's Avatar

  • robert


  • Posts: 1746
  • Karl,

    The DELIM and SDF RDDs are not there in the current build (they are mentioned in the "unsupported features" section in the help file). The good news is that I have implemented them and they will be included in the next build.

    And w.r.t. the feature: you do not have to use it.

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    [2.3] AppendDelimited? 15 Apr 2020 09:24 #14034

  • Chris's Avatar

  • Chris


  • Posts: 1957
  • Robert,

    robert wrote: Chris,
    Correct. I originally wanted to implement it like this:

    IF oObject IS INT nInt
    but you indicated that that was "too much C#" so I added the VAR keyword as you requested:


    Ah right, I remember now! And yeah, I agree with myself, the original syntax was way too much c# :)
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    [2.3] AppendDelimited? 15 Apr 2020 09:33 #14035

  • FFF's Avatar

  • FFF

  • Topic Author


  • Posts: 956
  • robert wrote: The DELIM and SDF RDDs are not there in the current build (they are mentioned in the "unsupported features" section in the help file). The good news is that I have implemented them and they will be included in the next build.

    Ah, thx, that explains my problem... Looking forward to see it, yesterday, pls ;)

    And w.r.t. the feature: you do not have to use it.

    Well, that's not the point. One of imho XBase style languages biggest advantages always was its clear readability. For almost anything you don't have to have "arcane" knowlegde to understand, what is written. That is a big value in itself to keep...
    Regards
    Karl (X# 2.5a; Xide 1.25; W8.1/64 German)

    Please Log in or Create an account to join the conversation.

    [2.3] AppendDelimited? 15 Apr 2020 10:15 #14036

  • robert's Avatar

  • robert


  • Posts: 1746
  • Karl,

    FFF wrote:

    And w.r.t. the feature: you do not have to use it.

    Well, that's not the point. One of imho XBase style languages biggest advantages always was its clear readability. For almost anything you don't have to have "arcane" knowlegde to understand, what is written. That is a big value in itself to keep...

    I agree that the language should be readable. In the team Chris is our guardian of readability. He has already used his veto for quite some features and/or syntaxes, believe me.
    But that should not stop us from adding features that make the product more usable or that increase productivity.
    We get requests from users for features like this. Another similar feature that we have added (and that you almost certainly don't like) is declaring and passing an out variable at the same time.
    Since features like this are fairly easy to implement (the underlying Roslyn platform already supports it) we decided to add that.
    So this works now too
    FUNCTION Start AS VOID
    LOCAL strNumber AS STRING
    strNumber := "1234"
    IF Int32.TryParse(strNumber, OUT VAR iResult)
        ? iResult
    ENDIF        
    IF Int32.TryParse(strNumber, OUT iResult2 AS Int32)
        ? iResult2
    ENDIF
    RETURN


    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    Last edit: by robert.

    [2.3] AppendDelimited? 15 Apr 2020 10:36 #14037

  • FFF's Avatar

  • FFF

  • Topic Author


  • Posts: 956
  • robert wrote: (and that you almost certainly don't like) is declaring and passing an out variable at the same time.
    ....

    FUNCTION Start AS VOID
    LOCAL strNumber AS STRING
    strNumber := "1234"
    IF Int32.TryParse(strNumber, OUT VAR iResult)
        ? iResult
    ENDIF        
    IF Int32.TryParse(strNumber, OUT iResult2 AS Int32)
        ? iResult2
    ENDIF
    RETURN

    FTR, no problem with this. With almost no knowldege about coding, i can understand, "i have a string and try to use it as a number"
    I'm not sure i would use it, but one can understand what happens.

    But i agree, it's always a fine line and certainly not easy to decide. Glad you are a balanced team ;)
    Regards
    Karl (X# 2.5a; Xide 1.25; W8.1/64 German)

    Please Log in or Create an account to join the conversation.

    [2.3] AppendDelimited? 15 Apr 2020 16:02 #14040

  • Chris's Avatar

  • Chris


  • Posts: 1957
  • robert wrote: In the team Chris is our guardian of readability.


    :) :D :)
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    Last edit: by Chris.

    [2.3] AppendDelimited? 15 Apr 2020 16:40 #14046

  • lumberjack's Avatar

  • lumberjack


  • Posts: 685
  • Chris wrote:

    robert wrote: In the team Chris is our guardian of readability.


    :) :D :)


    Its all Greek to me... :P
    ______________________
    Johan Nel
    George, South Africa

    Please Log in or Create an account to join the conversation.

    [2.4] AppendDelimited? 22 Apr 2020 21:54 #14146

  • FFF's Avatar

  • FFF

  • Topic Author


  • Posts: 956
  • So, back with 2.4 still using the same mini X#-RT app:
    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\__KV\DB\"
    	cSource:= "kv_lieferad.csv"
    	cDbf:= "kv_Lieferad.dbf"
    	oDB:= DbServer{cPfad+cDbf}
    ?	lOK := oDB:AppendDelimited(cPfad+cSource, ",")
    RETURN  lOK
    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!
    Regards
    Karl (X# 2.5a; Xide 1.25; W8.1/64 German)

    Please Log in or Create an account to join the conversation.

    [2.4] AppendDelimited? 22 Apr 2020 23:08 #14153

  • robert's Avatar

  • robert


  • Posts: 1746
  • Karl,
    Can you mail me the DBF and text file ?
    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    [2.4] AppendDelimited? 23 Apr 2020 09:28 #14160

  • FFF's Avatar

  • FFF

  • Topic Author


  • Posts: 956
  • Sent ;)
    Regards
    Karl (X# 2.5a; Xide 1.25; W8.1/64 German)

    Please Log in or Create an account to join the conversation.

    [2.4] AppendDelimited? 23 Apr 2020 12:02 #14166

  • mainhatten's Avatar

  • mainhatten


  • Posts: 139
  • 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)


    Hi Karl,
    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"
    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 input source as SDF file (which a dbf after Header in essence really is in any case)
    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

    Please Log in or Create an account to join the conversation.

    [2.4] AppendDelimited? 23 Apr 2020 12:23 #14167

  • FFF's Avatar

  • FFF

  • Topic Author


  • Posts: 956
  • 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 ;)
    Regards
    Karl (X# 2.5a; Xide 1.25; W8.1/64 German)

    Please Log in or Create an account to join the conversation.

    [2.4] AppendDelimited? 23 Apr 2020 12:35 #14168

  • robert's Avatar

  • robert


  • Posts: 1746
  • 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
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    [2.4] AppendDelimited? 23 Apr 2020 22:26 #14184

  • FFF's Avatar

  • FFF

  • Topic Author


  • Posts: 956
  • 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...
    Regards
    Karl (X# 2.5a; Xide 1.25; W8.1/64 German)

    Please Log in or Create an account to join the conversation.

    [2.4] AppendDelimited? 23 Apr 2020 22:28 #14185

  • robert's Avatar

  • robert


  • Posts: 1746
  • Karl,
    That's what VO does as well.

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    [2.4] AppendDelimited? 23 Apr 2020 22:38 #14186

  • FFF's Avatar

  • FFF

  • Topic Author


  • Posts: 956
  • robert wrote: Karl,
    That's what VO does as well.

    Really? Never had to try... Then, pls remove this compatibility ;)
    Regards
    Karl (X# 2.5a; Xide 1.25; W8.1/64 German)

    Please Log in or Create an account to join the conversation.

    Last edit: by FFF.
    • Page:
    • 1