FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour MARIADB ROWSET BATCH DML OPERATION EXAMPLE
Posts: 76
Joined: Fri Aug 28, 2009 05:25 AM
MARIADB ROWSET BATCH DML OPERATION EXAMPLE
Posted: Sun Sep 10, 2023 04:21 AM

Dear Rao Sir,

May I request to share the example of Maria DB Rowset Batch Operation in which record add / Modify / Delete and finally save the data in batch mode. Thanks in advance..!

Thanks

Shridhar

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: MARIADB ROWSET BATCH DML OPERATION EXAMPLE
Posted: Mon Sep 11, 2023 05:00 AM
Will you please try this?
Code (fw): Select all Collapse
oRs := oCn:RowSet( cSql )
oRs:SetBatchMode( .t. )
XBROWSER oRs FASTEDIT
if oRs:IsBatchEdited()
   if MsgYesNo( "Save Changes?" )
      oRs:SaveBatch()
   else
      oRs:CancelBatch()
   endif
endif
XBROWSER oRs
It is very important that the Primary Key(s) should be included in the rowset.
Regards



G. N. Rao.

Hyderabad, India
Posts: 76
Joined: Fri Aug 28, 2009 05:25 AM
Re: MARIADB ROWSET BATCH DML OPERATION EXAMPLE
Posted: Mon Sep 11, 2023 12:26 PM

Dear Rao Sir ,

Will try and update you. Many thanks...!!

Thanks

Shridhar

Posts: 1067
Joined: Wed Nov 09, 2005 02:17 AM
Re: MARIADB ROWSET BATCH DML OPERATION EXAMPLE
Posted: Mon Sep 11, 2023 08:32 PM

Mr Rao,

What is the differenc between BATCH and TRANSACTION ? Could you explain it to me ?

Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: MARIADB ROWSET BATCH DML OPERATION EXAMPLE
Posted: Tue Sep 12, 2023 01:28 AM
TRANSACTION:
We use this feature when we need to update/insert more than one table and want that either all changes to be written or none.
In other words, we do not want a situation where some tables are updated and some or not due to whatever reasons.

For example we want all these updates to be written
Code (fw): Select all Collapse
aSql := { "UPDATE table1 ... WHERE ... ", ;
          "UPDATE table2 ... WHERE ... ", ;
          ..more.., ;
        }
if WriteAllOrNone( oCn, aSql )
   ? "Written"
else
   ? "fail"
endif
//-------------------------------
function WriteAllOrNone( oCn, aSql )

local cUpdateSql

oCn:BeginTransaction()
for each cUpdateSql IN aSql
   oCn:Execute( cSql )
   if oCn:nError != 0
      oCn:RollBack()
      return .f.
   endif
next
oCn:CommmitTransaction()    

return .t.
BATCH:
Same way as in ADO, we can also use RowSet in BatchMode.
Code (fw): Select all Collapse
oRs := oCn:RowSet( cSql )
oRs:SetBatchMode( .t. )
In this case all changes (add/modify/delete) we make to the RowSet (or RecordSet in ADO) are all made to the RowSet/RecordSet in memory, but not written to the database.
After making all required changes, the we can decide to write all changes to the physical database or discard all changes.
Code (fw): Select all Collapse
oCn:SaveBatch()  // write all changes
oCn:CancelBatch() // discard all changes
This is mostly useful in Master/Child edits like Invoices, Quotations, Vouchers, etc.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1067
Joined: Wed Nov 09, 2005 02:17 AM
Re: MARIADB ROWSET BATCH DML OPERATION EXAMPLE
Posted: Tue Sep 12, 2023 10:26 AM
Thank you ;)
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
Posts: 76
Joined: Fri Aug 28, 2009 05:25 AM
Re: MARIADB ROWSET BATCH DML OPERATION EXAMPLE
Posted: Wed Oct 11, 2023 04:43 AM

Dear Rao Sir ,

As requested , could you please provide code to use extended the feature of XBROWSE , DATAROW & ROWSET.

Thanks

Shridhar

Posts: 1067
Joined: Wed Nov 09, 2005 02:17 AM
Re: MARIADB ROWSET BATCH DML OPERATION EXAMPLE
Posted: Thu Oct 19, 2023 02:06 PM
Do you know if is possible to use Transaction with BEGIN SEQUENC/RECOVER? Something like this:
Code (fw): Select all Collapse
BEGIN SEQUENC
      oCn:BeginTransaction()
         oCn:Insert(...)
         oCn:Insert(...)
         oCn:Insert(...)
     oCn:CommitTransaction()

RECOVER USING oError
      oCn:RollBack()
END SEQUENC
oCn:CommitTransaction() only will be executed it there is no any fail during oCn:Insert().
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil

Continue the discussion