dbSort test. order confuse

This forum is meant for questions about the Visual FoxPro Language support in X#.

Post Reply
jpmoschi
Posts: 76
Joined: Thu May 21, 2020 3:45 pm

dbSort test. order confuse

Post by jpmoschi »

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

Code: Select all

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:UsersjpmosSourcereposX-SharpConsoleApplication1CodeFileLocateTest.prg:line 76
at XSharp.RT.Functions.__AreaEval[T](__Usual area, Func`1 action)
at ConsoleApplication1.Exe.Functions.SortTest(__Usual[] Xs$Args) in C:UsersjpmosSourcereposX-SharpConsoleApplication1CodeFileLocateTest.prg:line 76
at ConsoleApplication1.Exe.Functions.Start() in C:UsersjpmosSourcereposX-SharpConsoleApplication1Program.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
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

dbSort test. order confuse

Post by Chris »

Thanks for the report Juan, Robert is looking into it!
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
jpmoschi
Posts: 76
Joined: Thu May 21, 2020 3:45 pm

dbSort test. order confuse

Post by jpmoschi »

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'.
Post Reply