Modifying the query of a recordset and xBrowse

Modifying the query of a recordset and xBrowse

Postby Rick Lipkin » Thu Jun 14, 2012 7:32 pm

To All

I have defined an xBrowse with an empty recordset ( oRsInv .. where Repair number = 0 ) on a sql query due to the huge number of records in the table.

Code: Select all  Expand view  RUN

REDEFINE xBROWSE oLbxB1           ;
         RECORDSET oRsInv            ;
         COLUMNS "REPAIR NUMBER",    ;
                 "TRANSACTION TYPE", ;
                 "INVOICED DATE",    ;
                 "TOTAL",            ;
                 "BALANCE"           ;
         COLSIZES 70,80,80,70,70     ;
         HEADERS "Invoice #",        ;
                 "Type",             ;
                 "Date",             ;
                 "Total",            ;
                 "Balance"           ;
         ID 139 of oCust2            ;
         AUTOCOLS LINES CELL
 


Is there a way to keep the record set object and browse active ( without killing the listbox ) if I want to go back in and close() the current recordset ( oRsInv:CLose() ) and re-issue the same recordset object ( same columns, new query ) with a different Repair Number = 12345 and possibly just refresh the xBrowse Object ( oLbxB1:ReFresh() ) with the new ( same object ) recordset ?

Thanks
Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Modifying the query of a recordset and xBrowse ( solved )

Postby Rick Lipkin » Thu Jun 14, 2012 8:28 pm

To All

FYI .. I have answered my own question .. basically I trapped a double click from my invoice listbox, then passed the recordset and listbox object of the xBrowse I am updating .. and to my surprise, this code worked.

Rick Lipkin
Code: Select all  Expand view  RUN

// invoices

   REDEFINE xBROWSE oLbxB1           ;
         RECORDSET oRsInv            ;
         COLUMNS "REPAIR NUMBER",    ;
                 "TRANSACTION TYPE", ;
                 "INVOICED DATE",    ;
                 "TOTAL",            ;
                 "BALANCE"           ;
         COLSIZES 70,80,80,70,70     ;
         HEADERS "Invoice #",        ;
                 "Type",             ;
                 "Date",             ;
                 "Total",            ;
                 "Balance"           ;
         ID 139 of oCust2            ;
         AUTOCOLS LINES CELL

   oLbxB1:nMarqueeStyle := MARQSTYLE_HIGHLROW
   
   // trap double click on Invoice line
   oLbxB1:bLDblClick := { |nRow,nCol | _PayUpDt( oRsInv, oRsPay, oLbxB2) }

  // payments
   REDEFINE xBROWSE oLbxB2           ;
         RECORDSET oRsPay            ;
         COLUMNS "INVOICE NUMBER",   ;
                 "DATE COLLECTED",   ;
                 "PAYMENT METHOD",   ;
                 "PAYMENT AMOUNT"    ;
         COLSIZES 80,80,80,80        ;
         HEADERS "Invoice",          ;
                 "Date",             ;
                 "Pymt Meth",        ;
                 "Amount"            ;
         ID 140 of oCust2            ;
         AUTOCOLS LINES CELL

   oLbxB2:nMarqueeStyle := MARQSTYLE_HIGHLROW
...
...
...
//-----------------------
Static Func _PayUpDt( oRsInv, oRsPay, oLbxB2)

Local cSql,oErr,nRepairNumber

nRepairNumber := oRsInv:Fields("Repair Number"):Value

oRsPay:Close()

*oLbxB2:bKeyCount := { || 0 } // kills off the listbox
*oLbxB2:bKeyNo    := { || 0 }  // do not use

// payments

cSql := "SELECT "
cSql += "p.[Payment Number] AS pn, "
cSql += "d.Counter, "
cSql += "d.[Payment Method], "
cSql += "d.[Payment Amount], "
cSql += "d.Reference, "
cSql += "d.[Customer ID], "
cSql += "d.[Date Collected], "
cSql += "d.[Card Number], "
cSql += "d.[Card Name], "
cSql += "d.[Check Number], "
cSql += "d.Deposit, "
cSql += "d.Depositted, "
cSql += "d.User, "
cSql += "d.Computer, "
cSql += "d.Void, "
cSql += "p.[Invoice Number], "
cSql += "p.Amount "
cSql += "FROM [Payment Details] AS p "
cSql += "LEFT JOIN Payments AS d ON p.[Payment Number] = d.Counter "
cSql += "Where p.[Invoice Number] = "+ltrim(str(nRepairNumber))

// do not have to re-create the recordset .. just re-use

*oRsPay := TOleAuto():New( "ADODB.Recordset" )
*oRsPay:CursorType     := 1        // opendkeyset
*oRsPay:CursorLocation := 3        // local cache
*oRsPay:LockType       := 3        // lockoportunistic

TRY
   oRsPay:Open( cSQL,xCONNECT )
CATCH oErr
   MsgInfo( "Error in Opening PAYMENTS table" )
   RETURN(.t.)
END TRY

oLbxB2:ReFresh()

Return(nil)



 
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Modifying the query of a recordset and xBrowse

Postby nageswaragunupudi » Fri Jun 15, 2012 5:28 am

XBrowse safely works
(1) ReQuery the same recordset
OR
(2) Create new Recset ( ofcourse with exactly the same fields ) say oNewRs
and then :-
oOldRs := oBrw:oRs
oBrw:oRs := oNewRs
oOldRs:Close()
oBrw:GoTop()
oBrw:Refresh()
Regards

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

Re: Modifying the query of a recordset and xBrowse

Postby Rick Lipkin » Fri Jun 15, 2012 12:32 pm

Rao

Do you see any potential problems with the way I re-used the same recordset object ?? All I did was close the recordset oRs:Close() .. so the object still retained it's creation parameters, so instead of starting and re-creating the same object .. I just re-issued oRs:Open(...) command with the same fields, just different command parameters ?

Thanks
Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Modifying the query of a recordset and xBrowse

Postby Armando » Fri Jun 15, 2012 2:24 pm

Rick:

My five cents, that's the same way I do that, my app is working since 2007 and not problem at all.

Code: Select all  Expand view  RUN

/*
* --------------------------------------------------------------------------*
* --------------------------------------------------------------------------*
*/

STATIC FUNCTION FilHdr(nAmo,oBrw,aGets)
oRsHdr:Close()

oRsHdr:Source :=    "SELECT " +;
                            "hdrndc.*," +;
                            "cliente.cli_nom " +;
                        "FROM " +;
                            "hdrndc," +;
                            "cliente " +;
                        "WHERE " +;
                            "hdrndc.hdr_cli = cliente.cli_cli " +;
                        "AND " +;
                            "YEAR(HDR_FDE) = '" + STR(nAmo,4,0) + "' " +;
                        "ORDER BY " +;
                            "hdr_ndc"

oRsHdr:Open()
oRsHdr:Refresh()
oBrw:Refresh()
aGets[1]:oJump  := oBrw
RETURN(.T.)
 


Regards
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
Armando
 
Posts: 3229
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

Re: Modifying the query of a recordset and xBrowse

Postby Rick Lipkin » Fri Jun 15, 2012 3:23 pm

Armando

Thanks .. I appreciate your response.

Rick
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Modifying the query of a recordset and xBrowse

Postby Enrico Maria Giordano » Sat Jun 16, 2012 10:23 am

Rick Lipkin wrote:Rao

Do you see any potential problems with the way I re-used the same recordset object ?? All I did was close the recordset oRs:Close() .. so the object still retained it's creation parameters, so instead of starting and re-creating the same object .. I just re-issued oRs:Open(...) command with the same fields, just different command parameters ?

Thanks
Rick Lipkin


No, no problems in reusing oRs as many times as you need.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Modifying the query of a recordset and xBrowse

Postby Massimo Linossi » Thu Jun 21, 2012 9:35 am

Hi.
Very interesting topic.
I want to ask if there is a possibility to make the same with a normal listbox, or TsBrowse.
I have a lot of places in a big procedure and to change all of them with xbrowse would be really hard.
Thanks a lot.
Massimo.
User avatar
Massimo Linossi
 
Posts: 498
Joined: Mon Oct 17, 2005 10:38 am
Location: Italy

Re: Modifying the query of a recordset and xBrowse

Postby Enrico Maria Giordano » Thu Jun 21, 2012 10:11 am

Yes, you can reuse the same variable after the object has been destroyed. But I don't think you will have any real benefits.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Modifying the query of a recordset and xBrowse

Postby leandro » Thu May 28, 2015 4:34 pm

Armando Muchas Gracias....

Funciono Perfecto :D
Saludos
LEANDRO AREVALO
Bogotá (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Embarcadero C++ 7.60 for Win32 ] [ FiveWin 23.07 ] [ xHarbour 1.3.0 Intl. (SimpLex) (Build 20230914) ]
User avatar
leandro
 
Posts: 1676
Joined: Wed Oct 26, 2005 2:49 pm
Location: Colombia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 44 guests