oRsAcc := TOleAuto():New( "ADODB.Recordset" )
oRsAcc:CursorType := 1 // opendkeyset
oRsAcc:CursorLocation := 3 // local cache
oRsAcc:LockType := 3 // lockoportunistic
Function Mcs_RecSet(cConnStr,cSql,lNew)
Local nI := 1
Local oRs //:= CreateObject("ADODB.RecordSet")
Local e := nil
If empty(lNew)
lNew := .f.
ENdif
//Default lNew := FALSE
If lNew = .t.
// -------- standard ADO
oRs := TOleAuto():New( "ADODB.Recordset" )
oRs:CursorType := 1 // opendkeyset
oRs:CursorLocation := 3 // local cache
oRs:LockType := 3 // lockoportunistic
TRY
oRs:Open( cSQL,cConnStr )
CATCH oErr
MsgInfo( "Error in Opening RECORDSET" )
RETURN(.F.)
END TRY
// ---------
// or
// -- using Fw_Ado Wrappers
oRs := FW_OpenRecordSet( cConnStr, cSql, 3, 1 ) // nLockType 3 and nCursorType 1
If empty(oRs)
MsgInfo( "Error opening Recordset)
Return(.f.)
Endif
nageswaragunupudi wrote:CursorLocation
1 adUseNone (Obsolete and does not work)
2. adUseServer (Can not navigate and is not useful for us)
3. adUseClient : This is the only choice we have
LockType:
1. adLockUnspecified (not to be used for new recordsets)
2. adLockReadOnly : This is not what you want when you want to make changes. (Note: This is useful when you read data not to be modified)
3. adLockPessimistic: We need to lock each record for modification. Rarely anybody uses it.
5. adLockBatchOptimistic: Useful. But for more advanced users.
4. adLockOptimistic: This is the only choice we have
CursorType:
0. adOpenForwardOnly : Works only with adUseServer and in anycase this is not what we want
1. adOpenKeyset: Whether we like or not this work only with adUseServer
2. adOpenDynamic: This also does not work with adUseClient
3. adOpenStatic: This is the only choice left to us.
Even if you try to use adOpenKeySet or adOpenDynamc the ADO system will open the recordset with adUseStatic only.
Test:
Try opening a recordset with cursor types 1 or 2. After opening the recordset, try ? oRs:CursorType. The result always is 3 (adOpenStatic)
We are left with these choices only and we have no other choices:
CursorLocation : adUseClient (3)
LockType: adLockOptimistic (4) // If you know how to handle, adLockBatchOptimistic can also be used.
CursorType: adOpenStatic. (3)
Now this also means that trying other values, like adOpenKeyset or adOpenDynamic, has no meaning and is a sheer waste of time.
Horizon wrote:Hi Mr. Rao,
I start to use fwh mariadb functions. not ADO. I could not understand that how to handle multiuser environment in fwh mariadb functions.
I need to lock one record when i enter to press update button. I don't want to enter this record to update purpose for other users. in this situation other user can only view the record.
Is it possible?
Thanks
nageswaragunupudi wrote:Whatsnew.txt
FWH 18.06
- Enhancement to method EditBaseRecord(...)
Added optional new 5th param, lLock (default .f.)
Revised syntax:
EditBaseRecord( [cFieldList], [lNew], [bEdit], [oBrw], [lLock] )
If lLock is set to true, the row is locked for edit and lock is released after edit.
We set .T. to 5th param in EditBaseRecord and this record is locked by another user, is there any error message. If yes, is it possible to set user defined function that is maintained by programmer?
oCn:innodb_lock_wait_timeout := 1 // one second
Secondly, Sometimes I need to modify some fields programaticaly. How can I ensure this record is not locked.
if !oRs:Save()
if oCn:nError == 1205
// other user locked the record
// take suitable action
endif
endif
#include "fivewin.ch"
function Main()
local oCn, oRs, oDlg, oBrw
oCn := FW_DemoDB()
oCn:innodb_lock_wait_timeout := 1
oRs := oCn:RowSet( "states" )
oRs:lShowErrors := .t.
DEFINE DIALOG oDlg SIZE 400,400 PIXEL TRUEPIXEL ;
@ 60,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
DATASOURCE oRs AUTOCOLS CELL LINES NOBORDER FASTEDIT
oBrw:nEditTypes := EDIT_GET
oBrw:CreateFromCode()
@ 10,20 BUTTON "EDIT" SIZE 100,35 PIXEL OF oDlg ;
ACTION oRs:EditBaseRecord( nil, .F., { |oRec| EditDlg( oRec ) }, oBrw, .T. )
ACTIVATE DIALOG oDlg CENTERED
oRs:Close()
oCn:Close()
return nil
//----------------------------------------------------------------------------//
function EditDlg( oRec )
local oDlg, oBtn
local oCn := oRec:uSource:oCn
DEFINE DIALOG oDlg SIZE 360,200 PIXEL TRUEPIXEL
@ 40,20 SAY "Code" GET oRec:Code PICTURE "@!" SIZE 300,24 PIXEL OF oDlg
@ 80,20 SAY "Name" GET oRec:Name SIZE 300,24 PIXEL OF oDlg
@ 120,240 BUTTON oBtn PROMPT "Save" SIZE 100,35 PIXEL OF oDlg ;
ACTION ( If( oRec:Modified(), oRec:Save(), nil ), oDlg:End() )
ACTIVATE DIALOG oDlg CENTERED
return nil
//----------------------------------------------------------------------------//
lSuccess := .f.
oCn:BeginTransaction()
oRsLocked := oCn:RowSet( "SELECT * FROM materials WHERE code = '009' FOR UPDATE" )
if oRsLocked == nil
// locked by other user
oCn:RollBack()
else
if oRsLocked:balance >= nIssueQty
oRsLocked:balance -= nIssueQty
if oRsLocked:Save()
lSuccess := << save other tables also >>
endif
endif
if lSuccess
oCn:CommitTransaction()
else
oCn:RollBack()
endif
oRsLocked:Close()
oRsLocked := nil
endif
oRsOpen := oCn:RowSet( "SELECT * FROM materials WHERE code = '009' " )
if oRsOpen == nil
// Error : There is not any record code='009'
.......
return
endif
oRsLocked := oCn:RowSet( "SELECT * FROM materials WHERE code = '009' FOR UPDATE" )
if oRsLocked == nil
// locked by other user
return
endif
// Go on
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Google [Bot] and 72 guests