Welcome, Guest
Username: Password: Remember me
This public forum is meant for questions and discussions about Visual FoxPro
  • Page:
  • 1

TOPIC:

dbSort test. order confuse 19 Aug 2021 21:09 #19401

  • jpmoschi
  • jpmoschi's Avatar
  • Topic Author


  • Posts: 74
  • Good afternoon guys
    The SortTest function combine sqlexec with dblocate and dbsort. I detected 2 bugs:
    1st) The sort by number is inverted
    2nd) Fail when i sort by char column or when i try to combine fields
    best regards
    Juan
    FUNCTION SortTest AS VOID
        local lresult 
        lresult:= sqlexec(_handle, "select 1 ColN, 'f' ColC union select 6 ColN, 'a' ColC union select 2 ColN, 'e' ColC union select 3 ColN, 'd' ColC union select 4 ColN, 'c' ColC union select 5 n, 'b' c ","sqlresult") >0
        local filenew:= "tmpfile"    
        local cbForCondition := {|| ColN>1}  
        local lseleAct:= select ("sqlresult")
        // 1st step: create a temporary table like a foxpro cursor 
        var aFields := { { "ColN" , "N" , 10 , 0 } ,{ "ColC" , "C" , 1 , 0 }} 
        if lresult
    	    lresult:=  DbCreate( fileNew, AFields)
        endif
        if lresult
    	lresult := DbUseArea(true,,filenew, "AliasNewTable")
            seleNew:= Select()
        endif  
        select sqlresult
        DbLocate(cbforcondition, ,,,)
        do while found()
            (selenew)->DBAppend()
            fieldputSelect(selenew,"ColN",ColN)
            fieldputSelect(selenew,"ColC",ColC)
            DBContinue(lseleAct)
        enddo 
        select AliasNewTable
        ListToConsole("List temp table before sort")
        // 2nd step: order by ColN     
        lresult:= (selenew)->DBSort(filenew+"Ord",  {"ColN"},,,,, )
        IF lresult
            DBCloseArea(selenew)
            lresult:= DbUseArea(true,,filenew+"Ord", "OrderedByColN")
            //USE (filenew) new 
            seleNew:= Select()
        endif 
        ListToConsole("after sort by ColN")
    
        lresult:= (selenew)->DBSort(filenew+"Desc",  {"ColN/D"},,,,, )
        IF lresult
            DBCloseArea(selenew)
            lresult:= DbUseArea(true,,filenew+"Desc", "OrderedByColNDescending")
            seleNew:= Select()
        endif 
        ListToConsole("after sort by ColN descending ")
        
        lresult:= (selenew)->DBSort(filenew+"ColC",  {"ColC"},,,,, )
        IF lresult
            DBCloseArea(selenew)
            lresult:= DbUseArea(true,,filenew+"ColC", "OrderedByColCDescending")
            seleNew:= Select()
        endif 
        ListToConsole("after sort by ColC")
        RETURN
        
    function ListToConsole(ptitle) as void
        ? ptitle
        dbgotop()
        do while !eof()
            ? transform(ColN,"999999") +" " + ColC
            dbskip()
        enddo 
        return

    The output is
    List temp table before sort
    2 e
    3 d
    4 c
    5 b
    6 a
    after sort by ColN
    6 a
    5 b
    4 c
    3 d
    2 e
    after sort by ColN descending
    2 e
    3 d
    4 c
    5 b
    6 a
    System.IndexOutOfRangeException
    HResult=0x80131508
    Message=Índice fuera de los límites de la matriz.
    Source=XSharp.Rdd
    StackTrace:
    at XSharp.RDD.DBF.Sort(DbSortInfo info)
    at XSharp.CoreDb.<>c__DisplayClass106_0.<Sort>b__0()
    at XSharp.CoreDb.Do[T](Func`1 action)
    at XSharp.CoreDb.Sort(UInt32 nDest, _FieldNames fieldNames, ICodeblock uCobFor, ICodeblock uCobWhile, Object nNext, Object nRecno, Boolean lRest, _FieldNames sortNames)
    at XSharp.RT.Functions.DbSort(__Usual[] Xs$Args)
    at ConsoleApplication1.Exe.Functions.<>c__DisplayClass7_0.<SortTest>b__3() in C:\Users\jpmos\Source\repos\X-Sharp\ConsoleApplication1\CodeFileLocateTest.prg:line 76
    at XSharp.RT.Functions.__AreaEval[T](__Usual area, Func`1 action)
    at ConsoleApplication1.Exe.Functions.SortTest(__Usual[] Xs$Args) in C:\Users\jpmos\Source\repos\X-Sharp\ConsoleApplication1\CodeFileLocateTest.prg:line 76
    at ConsoleApplication1.Exe.Functions.Start() in C:\Users\jpmos\Source\repos\X-Sharp\ConsoleApplication1\Program.prg:line 10

    This exception was originally thrown at this call stack:
    [External Code]
    ConsoleApplication1.Exe.Functions.SortTest.AnonymousMethod__3() in CodeFileLocateTest.prg
    [External Code]
    ConsoleApplication1.Exe.Functions.SortTest(XSharp.__Usual[]) in CodeFileLocateTest.prg

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

    dbSort test. order confuse 25 Aug 2021 16:55 #19440

    • Chris
    • Chris's Avatar


  • Posts: 3405
  • Thanks for the report Juan, Robert is looking into it!
    XSharp Development Team
    chris(at)xsharp.eu

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

    dbSort test. order confuse 12 Nov 2021 19:35 #20386

    • jpmoschi
    • jpmoschi's Avatar
    • Topic Author


  • Posts: 74
  • Hello guys, i am reviewing my topics status.
    When i try to exec this in betatester environment occurs the flow error calling the 1st dbsort next to comment // 2nd step: order by

    System.StackOverflowException
    HResult=0x800703E9
    Message=Se produjo una excepción de tipo 'System.StackOverflowException'.

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

    • Page:
    • 1