Page 3 of 4

Re: FWH: MySql/MariaDB: RowSet object

PostPosted: Fri May 12, 2017 6:21 pm
by luiz53
METHOD 2 DON´T WORK

nageswaragunupudi wrote:Method 2
--------
oRs := oCn:RowSet( "SELECT * FROM country ?", { "" } )
Later
oRs:ReQuery( { "WHERE name like '%REPLUBICA%' } )
Later
oRs:ReQuery( { "" } )
Later
oRs:ReQuery( { "WHERE age > 40" } )


And so it does not work either
oRs := oCn:RowSet( "SELECT * FROM country ? ORDER BY CODIGO", { "" } )
return EMPTY QUERY (TABLE)


oRs := oCn:RowSet( "SELECT * FROM country ? ORDER BY CODIGO", { "" } )
oRs:REQUERY("WHERE NAME LIKE '%AL%'")

RETURN ERRO
from start: 0 hours 0 mins 3 secs
Error occurred at: 12/05/2017, 15:17:05
Error description: Error BASE/1004 M‚todo nÆo exportado: REQUERY
Args:
[ 1] = U
[ 2] = A { ... } length: 1

Re: FWH: MySql/MariaDB: RowSet object

PostPosted: Fri May 12, 2017 6:43 pm
by nageswaragunupudi
Sorry, this is the correction. We can not have blank where clause

oRs := oCn:RowSet( "SELECT * FROM country ? ORDER BY CODIGO", { "WHERE 1=1" } )
should return full table

oRs:REQUERY( { "WHERE NAME LIKE '%AL%'" } ) // the param should be an array
shows where the where condition is true

This also works:

cSql := "select * from states ? ?"
oRs := oCn:RowSet( cSql, { "WHERE name like '%n%'", "ORDER BY code" } )
xbrowser oRs

oRs:Requery( { "WHERE name like '%y%'", "ORDER BY name" } )
xbrowser ors

But, unless the tables are very large, we recommend using oRs:Filter() and oRs:SetOrder() instead of reading again and again from the server with different where and order by clauses for every change
This reduces burden on network traffic and server.

Re: FWH: MySql/MariaDB: RowSet object

PostPosted: Sat May 13, 2017 1:37 pm
by nageswaragunupudi
These are some examples
Code: Select all  Expand view
 

   oRs := ocn:customer  // Quick way to open rowset

   oRs:SetFilter( "city like '%wark%'" ) // recommended
   xbrowser oRs
   oRs:SetFilter( "'WARK' $ UPPER(CITY)" )  // also works
   xbrowser oRs
   oRs:SetFilter( "CITY LIKE ? AND AGE > ?", { "%y%", 30 } ) // Parametrised filter
   xBrowser oRs
   oRs:ReFilter( { "%EY%", 50 } )  // ReUse the same filter condition
   xBrowser oRs
 

May I know if you are using FWH 17.04?

Re: FWH: MySql/MariaDB: RowSet object

PostPosted: Sat May 13, 2017 1:45 pm
by luiz53
I´M SORRY MR. RAO.

I deleted my post because I found my mistake.

But your new post was a lot of help

FIVEWIN 17.03 !!!


nageswaragunupudi wrote:These are some examples
May I know if you are using FWH 17.04?

Re: FWH: MySql/MariaDB: RowSet object

PostPosted: Mon May 15, 2017 1:36 pm
by luiz53
Does not work the automatic page
what am I doing wrong ???

My table has 100 rows
Shows only 20 rows and when I press down arrow does not show a new page with 20 more rows



Code: Select all  Expand view


::oTable := oCn:RowSet( 'produtos', 20)  // page with 20 rows

DEFINE BRUSH OBRUSH COLOR RGB(220,220,220)

DEFINE DIALOG ::oDlg RESOURCE "_CADASTROS_GERAL_INI" OF ::oDlgFolder BRUSH OBRUSH FONT ::OFONT
   ::ODLG:LTRANSPARENT := .T.
   ::ODLG:LHELPICON    := .F.

   REDEFINE XBROWSE ::oBrw ID 100 OF ::ODLG AUTOSORT

   ADD TO ::oBrw DATA ::oTable:classe
   ADD TO ::oBrw DATA ::oTable:descrica
   ADD TO ::oBrw DATA ::oTable:CST
   ADD TO ::oBrw DATA ::oTable:situacao
   ADD TO ::oBrw DATA ::oTable:aliquota picture "@e 999.99"
   ADD TO ::oBrw DATA ::oTable:redbase  picture "@e 999.99"
   ADD TO ::oBrw DATA ::oTable:aliq_st  picture "@e 999.99"
   ADD TO ::oBrw DATA ::oTable:redb_st  picture "@e 999.99"


   ::oBrw:aCols[1]:cHeader       := "CÓDIGO"
   ::oBrw:aCols[1]:nDataStrAlign := AL_CENTER
   ::oBrw:aCols[1]:nHeadStrAlign := AL_CENTER
   ::oBrw:aCols[1]:nWidth        := 120
   ::oBrw:ACOLS[1]:cOrder        := ::oTable:corder

   ::oBrw:aCols[2]:cHeader       := "DESCRIÇÃO"
   ::oBrw:aCols[2]:nHeadStrAlign := AL_LEFT
   ::oBrw:aCols[2]:nDataStrAlign := AL_LEFT
   ::oBrw:aCols[2]:nWidth        := 420

   ::oBrw:aCols[3]:cHeader       := "CST"
   ::oBrw:aCols[3]:nDataStrAlign := AL_CENTER
   ::oBrw:aCols[3]:nHeadStrAlign := AL_CENTER
   ::oBrw:aCols[3]:nWidth        := 70

   ::oBrw:aCols[4]:cHeader       := "CST"
   ::oBrw:aCols[4]:nDataStrAlign := AL_CENTER
   ::oBrw:aCols[4]:nHeadStrAlign := AL_CENTER
   ::oBrw:aCols[4]:nWidth        := 70

   ::oBrw:aCols[5]:cHeader       := "ALIQUOTA"
   ::oBrw:aCols[5]:nDataStrAlign := AL_RIGHT
   ::oBrw:aCols[5]:nHeadStrAlign := AL_RIGHT
   ::oBrw:aCols[5]:nWidth        := 90

   ::oBrw:aCols[6]:cHeader       := "REB-BASE"
   ::oBrw:aCols[6]:nDataStrAlign := AL_RIGHT
   ::oBrw:aCols[6]:nHeadStrAlign := AL_RIGHT
   ::oBrw:aCols[6]:nWidth        := 90

   ::oBrw:aCols[7]:cHeader       := "ALIQ-ST"
   ::oBrw:aCols[7]:nDataStrAlign := AL_RIGHT
   ::oBrw:aCols[7]:nHeadStrAlign := AL_RIGHT
   ::oBrw:aCols[7]:nWidth        := 90

   ::oBrw:aCols[8]:cHeader       := "REB-ST"
   ::oBrw:aCols[8]:nDataStrAlign := AL_RIGHT
   ::oBrw:aCols[8]:nHeadStrAlign := AL_RIGHT
   ::oBrw:aCols[8]:nWidth        := 90


    FOR EACH oCol IN ::oBrw:aCols
        oCol:bClrFooter := ;
        oCol:bClrHeader := {|| IIF(!Empty(oCol:cOrder), { CLR_BLUE, nRGB(200,200,200) },{ CLR_BLACK, nRGB(240,240,240) }) }
    NEXT

   ::oBrw:lRecordSelector        := .T.
   ::oBrw:lfooter                := .T.
   ::oBrw:lHScroll               := .T.
   ::oBrw:lVScroll               := .T.
   ::oBrw:NHEADERLINES           := 2
   ::oBrw:NDATALINES             := 1
   ::oBrw:NFOOTERLINES           := 1
   ::oBrw:l2007                  := .F.
   ::oBrw:nRowHeight             := 24

   ::oBrw:NMARQUEESTYLE          := 4 //MARQSTYLE_HIGHLROW
   ::oBrw:bClrRowFocus           := { ||  { CLR_BLACK, RGB(185,220,255) } }

   ::oBrw:NCOLDIVIDERSTYLE       := LINESTYLE_BLACK
   ::oBrw:NROWDIVIDERSTYLE       := LINESTYLE_BLACK
   ::oBrw:LCOLDIVIDERCOMPLETE    := .T.


   ::oBrw:bChange                := { || ::Rebuild() }
   ::oBrw:BKEYDOWN               := {|NKEY| ::KEYPRESS( NKEY ) }
   ::oBrw:bLDblClick             := {||     ::KEYPRESS( VK_RETURN )}

   AEval(::oBrw:aCols,{|o| o:bLClickFooter := o:bLClickHeader := Build_CodeBlock_Order(::oTable)})

   ::oBrw:SetODBF( ::oTable )

   ACTIVATE DIALOG ::oDlg NOMODAL

 

Re: FWH: MySql/MariaDB: RowSet object

PostPosted: Mon May 15, 2017 2:22 pm
by nageswaragunupudi
Afer
::oTable := oCn:RowSet( 'produtos', 20) // page with 20 rows
Add
Code: Select all  Expand view

::oTable:lAutoExpand := .t.
 


Please redefine XBROWSE with column syntax to avail all features of xBrowse
Code: Select all  Expand view

Eg:
   REDEFINE XBROWSE ::oBrw ID 100 OF ::ODLG ;
      DATASOURCE ::oTable ;
      COLUMNS "classe", "descrica",  "cst",  "situacao", "aliquota", "redbase",  "aliq_st", "redb_st" ;
      HEADERS "CÓDIGO", "DESCRIÇÃO", "CST",  "SITUACAO", "ALIQUOTA", "REB-BASE", "ALIQ-ST", "REB-ST" ;
      COLSIZES 120, 420, 70, 70, 90, 90, 90, 90 ;
      JUSTIFY AL_CENTER, nil, AL_CENTER, AL_CENTER ;
      AUTOSORT LINES NOBORDER
 

Remove
Code: Select all  Expand view

  ::oBrw:SetODBF( ::oTable )
 

Instead, specify the DATASOURCE in the command itself. That is very important. This tells xbrowse what is the datasource it is handling. That helps xbrowse a lot.

Re: FWH: MySql/MariaDB: RowSet object

PostPosted: Mon May 15, 2017 5:58 pm
by luiz53
HOW TO MAKE PAGINATION WITH FILTER
oRs := oCn:RowSet( 'produtos', 10) //
oRs:setfilter("name $ 'PINEAPPLE')

1 -'AAA PINEAPPLE KG'
2 -BBB PINEAPPLE KG'
3 -'CCC PINEAPPLE KG'
.
.
.
99-'JUICE PINEAPPLE'

RETURN ONLY rows OF PAGE 1

Re: FWH: MySql/MariaDB: RowSet object

PostPosted: Mon May 15, 2017 6:27 pm
by luiz53
how to make REQUERY with pagination

ors := ::oSetup:oServer:RowSet("Select * from produtos ? order by descricao",{"where inactive = 'N'"}, 50) // pagination with 50 **** ERRO DON´T WORK... ***

ors:Requery("where name like '%PINAPPLE% '") // WITH PAGINATION 50

ors:Requery( "where Inactive = 'S' ") // WITH PAGINATION 50

Re: FWH: MySql/MariaDB: RowSet object

PostPosted: Mon May 15, 2017 8:49 pm
by vilian
Hi Luiz,

I think in this case you could use oRs:ReadNext(50)

Re: FWH: MySql/MariaDB: RowSet object

PostPosted: Mon May 15, 2017 11:32 pm
by nageswaragunupudi
luiz53 wrote:HOW TO MAKE PAGINATION WITH FILTER
oRs := oCn:RowSet( 'produtos', 10) //
oRs:setfilter("name $ 'PINEAPPLE')

1 -'AAA PINEAPPLE KG'
2 -BBB PINEAPPLE KG'
3 -'CCC PINEAPPLE KG'
.
.
.
99-'JUICE PINEAPPLE'

RETURN ONLY rows OF PAGE 1

"name $ 'PINEAPPLE'" is case sensitive
"name like 'PINEAPPLE'" is case insensitive. This format may be more useful in real cases.

SetFilter() works only on the records already read.

oRs:ReadNext() reads all remaining records and resets the filter
oRs:ReadNext( n ) reads next n records and resets the filter.

Re: FWH: MySql/MariaDB: RowSet object

PostPosted: Mon May 15, 2017 11:35 pm
by nageswaragunupudi
luiz53 wrote:how to make REQUERY with pagination

ors := ::oSetup:oServer:RowSet("Select * from produtos ? order by descricao",{"where inactive = 'N'"}, 50) // pagination with 50 **** ERRO DON´T WORK... ***

ors:Requery("where name like '%PINAPPLE% '") // WITH PAGINATION 50

ors:Requery( "where Inactive = 'S' ") // WITH PAGINATION 50


oRs := oCn:RowSet( "select * from productos ? order by descricao limit ?", { "where inactive = 'N'", 50 } )
oRs:Requery( "where name like '%PINEAPPLE%'", 100 } )

Except for large tables, it is desirable to avoid where clause and instead use setfilter()

Re: FWH: MySql/MariaDB: RowSet object

PostPosted: Tue May 16, 2017 1:47 pm
by luiz53
MR . RAO
PLEASE look SETWHERE IN TDOLPHIN
I explain :
Through setwhere I can do filter and pages and even order a grid by clicking on the header
VIDEO :
https://www.youtube.com/watch?v=ybPAC1_jm2M

1. HEADER E FOOTER CLICL
************************************************************************************
AEval(::oBrw[1]:aCols,{|o| o:bLClickFooter := o:bLClickHeader := Build_CodeBlock_Order(::oDb_prod)})
************************************************************************************



2. FUNCTION CALLED
**************************************
FUNCTION Build_CodeBlock_Order( oQry )
**************************************

RETURN {| nMRow, nMCol, nFlags, oCol | SetOrderDolphin( oCol, oQry ) }


****************************************
function SetOrderDolphin( oCol, oQry )
****************************************

LOCAL aToken
LOCAL cType, cOrder

aToken := HB_ATokens( oQry:cOrder, " " )

IF Len( aToken ) == 1
AAdd( aToken, "ASC" )
ENDIF

cOrder = AllTrim( Lower( aToken[ 1 ] ) )
cType = aToken[ 2 ]

AEval( oCol:oBrw:aCols, {| o | o:cOrder := " " } )
IF oQry:aStructure[ oCol:nCreationOrder ][ 1 ] == cOrder
IF Upper( cType ) == "ASC"
cType = "DESC"
oCol:cOrder = "D"
ELSE
cType = "ASC"
oCol:cOrder = "A"
ENDIF
ELSE
cOrder = oQry:aStructure[ oCol:nCreationOrder ][ 1 ]
cType = "ASC"
oCol:cOrder = "A"
ENDIF
oQry:SetOrder( cOrder + " " + cType )


oCol:oBrw:Refresh()

RETURN NIL





3. TDOLPHIN SETs
********************************************************************************
METHOD SetNewFilter( nType, cFilter, lRefresh )
METHOD SetWhere( cWhere, lRefresh ) INLINE ::SetNewFilter( SET_WHERE , cWhere , lRefresh )
METHOD SetGroup( cGroup, lRefresh ) INLINE ::SetNewFilter( SET_GROUP , cGroup , lRefresh )
METHOD SetHaving( cHaving, lRefresh ) INLINE ::SetNewFilter( SET_HAVING, cHaving, lRefresh )
METHOD SetOrder( cOrder, lRefresh ) INLINE ::SetNewFilter( SET_ORDER , cOrder , lRefresh )
METHOD SetLimit( cLimit, lRefresh ) INLINE ::SetNewFilter( SET_LIMIT , cLimit , lRefresh )

********************************************************************************



***********************************************************
METHOD SetNewFilter( nType, cFilter, lRefresh ) CLASS TDolphinQry
************************************************************
LOCAL cOldFilter
LOCAL l := .T.

DEFAULT lRefresh TO .T.


SWITCH nType
CASE SET_WHERE
cOldFilter = ::cWhere
::cWhere = cFilter
EXIT
CASE SET_GROUP
cOldFilter = ::cGroup
::cGroup = cFilter
EXIT
CASE SET_HAVING
cOldFilter = ::cHaving
::cHaving = cFilter
EXIT
CASE SET_ORDER
cOldFilter = ::cOrder
::cOrder = cFilter
EXIT
CASE SET_LIMIT
cOldFilter = ::cLimit
IF ValType( cFilter ) == "C"
::cLimit = cFilter
ELSEIF ValType( cFilter ) == "N"
::cLimit = AllTrim( Str( cFilter ) )
ENDIF
EXIT
ENDSWITCH

if ::bOnNewFilter != NIL
// if you want change query, do it here,
// return .F. to skip BuildQuery and call BuildDatas()
// return .T. to call BuildQuery()
// isn't recommended return .T. with Sub-Select
l = Eval( ::bOnNewFilter, Self, nType )
// Convert automatically to logical value
l = ValType( l ) == "L" .and. l
endif
if l

if !empty(::cWhereOld) // LUIZ ANTONIO
IF !::cWhereOld $ ::cWhere
::cWhere := "("+::cWhereOld+")" + if(!empty(::cWhere)," and ("+ ::cWhere+")","")
endif
endif

::cQuery := ::BuildQuery( ::aColumns, ::aTables, ::cWhere, ::cGroup, ::cHaving, ::cOrder, ::cLimit )
else
::BuildDatas( ::cQuery )
endif

IF lRefresh
::LoadQuery( .F. )
ENDIF

RETURN cOldFilter

Re: FWH: MySql/MariaDB: RowSet object

PostPosted: Tue May 16, 2017 3:01 pm
by nageswaragunupudi
Mr Luiz

Very nice video.
We would be glad if you can take the trouble of providing us with a working sample. That would be educative to many of us.
You may please use our demo-server for this purpose
Code: Select all  Expand view

oCn := FW_DemoDB( 5 )
 


After studying the sample we shall suggest how to achieve the same or similar effect with FWHMARIADB.
Thanks in advance.

Re: FWH: MySql/MariaDB: RowSet object

PostPosted: Thu May 18, 2017 12:43 pm
by luiz53
I created an example in tdolphin

FW_DEMODB(“DLP”) – TDOLPHIN

https://www.youtube.com/watch?v=b9zHD-U-j2U&feature=youtu.be

Code: Select all  Expand view

#include "fivewin.ch"

static oRs
static oBrw
static lPesquisa
***************************************************************************
function Main()
***************************************************************************
   local oCn
   local oDlg
   local cWhere
   local ocol
   local osay
   local vSay
   local ofont

   EXTERNAL TDOLPHINSRV

   if ( oCn := FW_DemoDB( 'DLP' ) ) == nil
      return nil
   endif
   lPesquisa   := .f.

   oRs  := TDolphinQry():New("Select servico,"+;
                              "produto,"      +;
                              "barra,"        +;
                              "descricao,"    +;
                              "unidade,"      +;
                              "ncm,"          +;
                              "lucro,"        +;
                              "preco,"        +;
                              "inativa from slbdprod WHERE INATIVA = 'N' OR INATIVA IS NULL order by descricao LIMIT 20", oCn )

   oRs:SetPages(20)
   oRs:bOnChangePage = { || vsay := alltrim(STR(oRs:nCurrentPage))+" / "+alltrim( STR(oRs:nMaxPages)),;
                            oSay:refresh() }



   DEFINE FONT OFONT NAME "TAHOMA"         SIZE 0,-16 BOLD

   DEFINE DIALOG oDlg SIZE 1024,600 PIXEL TRUEPIXEL TITLE "teste slbdprod"


   @ 70,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
     DATASOURCE oRs                                ;
     COLUMNS     "servico", "produto","barra" , "descricao"               ,"unidade" , "ncm"    ,"lucro"               ,"preco","pr_pro"  ;
     HEADERS     "TP"     , "PRODUTO","BARRAS", "DESCRIÇÃO"+CRLF+"PRODUTO","UN"      , "NCM"    ,"MARGEM"+CRLF+"PADRÃO","PREÇO","OFERTA"  ;
     COLSIZES    60       , 70       , 110    , 330                       , 40       , 90       ,80                    ,80      ,80       ;
     LINES NOBORDER

            oBrw:ACOLS[1]:NDATASTRALIGN := AL_CENTER
            oBrw:ACOLS[1]:NHEADSTRALIGN := AL_CENTER
            oBrw:ACOLS[1]:uBarGetVal    := uValBlank( oRs:servico )
            oBrw:ACOLS[1]:cBarGetPic    := "!"

            oBrw:ACOLS[2]:NDATASTRALIGN := AL_CENTER
            oBrw:ACOLS[2]:NHEADSTRALIGN := AL_CENTER
            oBrw:ACOLS[2]:uBarGetVal    := uValBlank( oRs:produto )
            oBrw:ACOLS[2]:cBarGetPic    := "99999"

            oBrw:ACOLS[3]:NDATASTRALIGN := AL_LEFT
            oBrw:ACOLS[3]:NHEADSTRALIGN := AL_LEFT
            oBrw:ACOLS[3]:uBarGetVal    := uValBlank( oRs:barra )
            oBrw:ACOLS[3]:cBarGetPic    := "@!"

            oBrw:ACOLS[4]:NDATASTRALIGN := AL_LEFT
            oBrw:ACOLS[4]:NHEADSTRALIGN := AL_LEFT
            oBrw:ACOLS[4]:cOrder        := oRs:corder
            oBrw:ACOLS[4]:uBarGetVal    := uValBlank( oRs:descricao )
            oBrw:ACOLS[4]:cBarGetPic    := "@!"


            oBrw:ACOLS[5]:NDATASTRALIGN := AL_CENTER
            oBrw:ACOLS[5]:NHEADSTRALIGN := AL_CENTER
            oBrw:ACOLS[5]:uBarGetVal    := uValBlank( oRs:UNIDADE )
            oBrw:ACOLS[5]:cBarGetPic    := "!!"

            oBrw:ACOLS[6]:NDATASTRALIGN := AL_CENTER
            oBrw:ACOLS[6]:NHEADSTRALIGN := AL_CENTER
            oBrw:ACOLS[6]:uBarGetVal    := uValBlank( oRs:NCM )
            oBrw:ACOLS[6]:cBarGetPic    := "@R 9999.99.99"

            oBrw:ACOLS[7]:NDATASTRALIGN := AL_RIGHT
            oBrw:ACOLS[7]:NHEADSTRALIGN := AL_RIGHT
            oBrw:ACOLS[7]:uBarGetVal    := 0
            oBrw:ACOLS[7]:cBarGetPic    := "@E 9999.99"

            oBrw:ACOLS[8]:NDATASTRALIGN := AL_RIGHT
            oBrw:ACOLS[8]:NHEADSTRALIGN := AL_RIGHT
            oBrw:ACOLS[8]:uBarGetVal    := 0
            oBrw:ACOLS[8]:cBarGetPic    := "@E 999,999.99"

            oBrw:ACOLS[9]:NDATASTRALIGN := AL_RIGHT
            oBrw:ACOLS[9]:NHEADSTRALIGN := AL_RIGHT
            oBrw:ACOLS[9]:uBarGetVal    := 0
            oBrw:ACOLS[9]:cBarGetPic    := "@E 999,999.99"

            oBrw:lGetBar                := .F.
            oBrw:bClrEdits              := { || { CLR_BLACK, CLR_YELLOW } }

            oBrw:lRecordSelector        := .T.
            oBrw:lfooter                := .T.
            oBrw:lHScroll               := .F.
            oBrw:lVScroll               := .F.
            oBrw:NHEADERLINES           := 2
            oBrw:NDATALINES             := 1
            oBrw:NFOOTERLINES           := 1
            oBrw:l2007                  := .F.
            oBrw:nRowHeight             := 24

            oBrw:NMARQUEESTYLE          := 4 //MARQSTYLE_HIGHLROW
            oBrw:bClrRowFocus           := { ||  { CLR_BLACK, RGB(185,220,255) } }

            oBrw:NCOLDIVIDERSTYLE       := LINESTYLE_BLACK
            oBrw:NROWDIVIDERSTYLE       := LINESTYLE_BLACK
            oBrw:LCOLDIVIDERCOMPLETE    := .T.

   FOR EACH oCol IN oBrw:aCols
       oCol:bClrFooter    := ;
       oCol:bClrHeader    := {|| IIF(!Empty(oCol:cOrder), { CLR_BLUE, nRGB(200,200,200) },{ CLR_BLACK, nRGB(240,240,240) }) }
//     oCol:bLClickFooter := {|| Build_CodeBlock_Order(oRs) }
   NEXT

   AEval(oBrw:aCols,{|o| o:bLClickFooter := o:bLClickHeader := Build_CodeBlock_Order(oRs)})

   oBrw:CreateFromCode()


   @ 20, 20 BTNBMP PROMPT "SHOW/HIDE"  SIZE 100,30 PIXEL FLAT OF oDlg action showfilter()
   @ 20,130 BTNBMP PROMPT "FILTER"     SIZE 100,30 PIXEL FLAT OF oDlg action setfilter()
   @ 20,240 BTNBMP PROMPT "EXIT"       SIZE 100,30 PIXEL FLAT OF oDlg action odlg:end()

   @ 20,800 SAY oSay VAR vsay OF odlg SIZE 80,20 pixel font OFONT COLOR CLR_BLUE,RGB( 242,244,246 )

   ACTIVATE DIALOG oDlg CENTERED on init eval(oRs:bOnChangePage)


   oRs:end()

   RETURN NIL



return nil
*******************************************************************************
FUNCTION Setfilter()
*******************************************************************************
   local cFilter := ""
   local n, oCol, uVal, cType

   for n := 1 to Len( oBrw:aCols )
       oCol  := oBrw:aCols[ n ]
       if ! Empty( uVal := oCol:uBarGetVal )
          if !Empty( cFilter )
             cFilter  += " AND "
          endif
          cType    := ValType( uVal )
          do case
             case cType == 'C'
                uVal     := Upper( AllTrim( uVal ) )
                cFilter  += oRs:FieldName( n ) + " LIKE '%" + upper(uVal) + "%' "
             otherwise
                cFilter  += oRs:FieldName( n ) + " = " + cValToChar( uVal )
          endcase
       endif
   next

   lPesquisa   := !Empty( cFilter )

   oRs:SetWhere( cFilter ,.t. )
   oRs:FirstPage()

   oBrw:refresh()
   oBrw:Setfocus()

return nil

*******************************************************************************
Function Showfilter()
*******************************************************************************
local n

oBrw:lGetBar := !oBrw:lGetBar

IF !oBrw:lGetBar
   if lPesquisa
      oRs:SetWhere( '' ,.t. )
      oRs:FirstPage()
      lPesquisa := .f.
   endif
   for n := 1 to Len( oBrw:aCols )
      WITH OBJECT oBrw:aCols[ n ]
         if oRs:FieldType( n ) != 'L'
            :uBarGetVal := uValBlank( oRs:fieldGet( n ) )
         endif
      END
   next
ENDIF

oBrw:refresh()
oBrw:Setfocus()

return nil




**************************************
FUNCTION Build_CodeBlock_Order( oQry )
**************************************

RETURN {| nMRow, nMCol, nFlags, oCol | SetOrderDolphin( oCol, oQry ) }


****************************************
function SetOrderDolphin( oCol, oQry )
****************************************

   LOCAL aToken
   LOCAL cType, cOrder

   aToken := HB_ATokens( oQry:cOrder, " " )

   IF Len( aToken ) == 1
      AAdd( aToken, "ASC" )
   ENDIF

   cOrder = AllTrim( Lower( aToken[ 1 ] ) )
   cType = aToken[ 2 ]

   AEval( oCol:oBrw:aCols, {| o | o:cOrder := " " } )
   IF oQry:aStructure[ oCol:nCreationOrder ][ 1 ] == cOrder
      IF Upper( cType ) == "ASC"
         cType = "DESC"
         oCol:cOrder = "D"
      ELSE
         cType = "ASC"
         oCol:cOrder = "A"
      ENDIF
   ELSE
      cOrder = oQry:aStructure[ oCol:nCreationOrder ][ 1 ]
      cType = "ASC"
      oCol:cOrder = "A"
   ENDIF
   oQry:SetOrder( cOrder + " " + cType )

   oCol:oBrw:Refresh()

RETURN NIL

 

Re: FWH: MySql/MariaDB: RowSet object

PostPosted: Thu May 18, 2017 12:48 pm
by nageswaragunupudi
This is a nice sample using Dolphin. We would like users of 17.04 to download, build, execute and try.

As a user ( not as a programmer ) I have these requests:
1) When I change the order, I want to see the same 20 records in the new order. I do not want totally a different set or rows
2) Also when I set filter I want to see the rows matching the filter condition out of the 20 records I saw in the beginning. I do not want a set or different rows.
3) Also when I change the sort order, I want to remain on the same row. I do not want a surprise that the row I am seeing is suddenly changed to something else. it is like pulling the carpet under my feet.

How can we implement this?

Also when I press PgDn and PgUp the page numbers on the top are changing but the data of the new page is not refreshed. Can you fix this issue?

Note: I have increased the dialog height to 650 so that we can see all the 20 rows of the page.