MariaDB (Solved)

MariaDB (Solved)

Postby ctoas » Mon Feb 08, 2021 5:00 pm

Hello.

I'm on my first project using MariaDB, I'm also using FWMaria for access.

I'm not able to change the order of the data

I start like this:
Code: Select all  Expand view  RUN
oRs := oServer:RowSet( "SELECT nome,r_social FROM agenda ORDER BY r_social" )


XBrowse looks like this:
Code: Select all  Expand view  RUN

       @ 0069,0000 XBROWSE oBrwAGENDA OF oDlgAGENDA SIZE 0520,0230 STYLE FLAT PIXEL NOBORDER DATASOURCE oRS//AUTOSORT   
            
        ADD TO oBrwAGENDA DATA oRs:r_social PICTURE "@!" HEADER "Razão Social" WIDTH 520
        ADD TO oBrwAGENDA DATA oRs:nome     PICTURE "@!" HEADER "Nome"         WIDTH 520                 

        oBrwAGENDA:nColDividerStyle := 0          
        oBrwAGENDA:nRowDividerStyle := 0          
        oBrwAGENDA:nMarqueeStyle    := 5
        oBrwAGENDA:lHScroll         := .F.
        oBrwAGENDA:lVScroll         := .T.
        oBrwAGENDA:lRecordSelector  := .F.
        oBrwAGENDA:bKeyChar         := {|nKey|IIF(nKey==VK_RETURN,((OPERACAO_AGENDA(2))),)}
        oBrwAGENDA:bClrSelFocus      := {||{nRGB(000,000,000),nRGB(150,150,150)}}
        oBrwAGENDA:bClrSel           := {||{nRGB(000,000,000),nRGB(150,150,150)}}
        oBrwAGENDA:bClrStd           := {||{CLR_BLUE,IIF(oRS:KeyNo() %2==0,CLR_WHITE,nRGB(232,232,232))}}
        oBrwAGENDA:nHeaderHeight    := 40
        oBrwAGENDA:bClrHeader       := {||{nRGB(000,000,000),nRGB(150,150,150)}}       
        oBrwAGENDA:bSeek            := {|c|.F.}
           
        oBrwAGENDA:aCols[1]:oHeaderFont := ARIAL16B
        oBrwAGENDA:aCols[1]:bLClickHeader := {|r,c,f,o| nil}
        oBrwAGENDA:aCols[2]:oHeaderFont := ARIAL16B  
       
        oBrwAGENDA:CreateFromCode()
 


And I change the order like this:
Code: Select all  Expand view  RUN

    IF nORDEM == 1
        oRs := oServer:RowSet( "SELECT nome,r_social FROM agenda ORDER BY r_social" )
    ELSEIF nORDEM == 2
        oRs := oServer:RowSet( "SELECT nome,r_social FROM agenda ORDER BY nome" )
    ENDIF

   oBrwAGENDA:REFRESH()
 


It turns out that when I start, it loads the data correctly, when I change the order it loads only the first record and multiplies it several times showing in xBrowse.
Where am I going wrong?

Thank you all
Last edited by ctoas on Mon Feb 08, 2021 8:53 pm, edited 1 time in total.
Christiano Augusto Silveira
christiano.silveira@gmail.com

MaxxTech Soluções em TI
http://www.maxxtech.com.br
User avatar
ctoas
 
Posts: 115
Joined: Wed Oct 26, 2005 2:38 pm
Location: São Paulo - Brasil

Re: MariaDB

Postby nageswaragunupudi » Mon Feb 08, 2021 7:27 pm

You do not have to read the RowSet again from the server at all.
FWH library sorts the recordset in the memory itself.
Just write this code:

Code: Select all  Expand view  RUN

oRs:Sort := "r_social"
// or
oRs:Sort := "nome"
// and
oBrw:Refresh()
 


You can use either
Code: Select all  Expand view  RUN

oRs:Sort := "fieldname"
// OR
oRs:SetOrder( "fieldname" )
 


In fact, it is better to leave this sorting work to XBrowse and keep our code simple.

FWH library allows setting filters and sorting in the memory itself and thereby avoiding to re-read the data from the server. The results are not only faster but most importantly reduces un-necessary network traffic which is very important.

To take the best advantage of xbrowse, mention the column names in the xbrowse command itself and avoid using separate code using "ADD COLUMN"

Code: Select all  Expand view  RUN

@ 0069,0000 XBROWSE oBrwAGENDA OF oDlgAGENDA SIZE 0520,0230 STYLE FLAT PIXEL NOBORDER ;
   DATASOURCE oRs ;
   COLUMNS "r_social", "nome" ;
   HEADERS "Razão Social", "Nome" ;
   COLSIZES 520,520 ;
   PICTURES "@!", "@!" ;
   AUTOSORT // This is optional
 

This way of defining xbrowse lets you avail the full capabilities of xbrowse.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10648
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: MariaDB

Postby ctoas » Mon Feb 08, 2021 8:52 pm

Thank you

Worked perfectly
Christiano Augusto Silveira
christiano.silveira@gmail.com

MaxxTech Soluções em TI
http://www.maxxtech.com.br
User avatar
ctoas
 
Posts: 115
Joined: Wed Oct 26, 2005 2:38 pm
Location: São Paulo - Brasil


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 61 guests