Código: Selecionar todos
Error DBFCDX/1022 Lock requiredJosmar
Moderador: Moderadores

Código: Selecionar todos
Error DBFCDX/1022 Lock required

Código: Selecionar todos
*-> Abro o arquivo cliente através dessa rotina
IF !ABRECLI()
ALERT("NAO CONSEGUI ABRIR")
ENDIF
*-> Essas são as funções de rede que estou utilizando
FUNCTION ABRECLI
IF USA("CLIENTES",.T.,.F.)
IF(!FILE("CLIENTE.CDX"))
_FECHA()
INDEX ON COD_CLI TAG CLIENT_1 TO CLIENTE
INDEX ON NOM_CLI TAG CLIENT_2 TO CLIENTE
_ABRE()
ENDIF
DBSETINDEX("CLIENTE")
ELSE
MENSAGEM( "Troca de n¡vel mal sucedida", 3 )
RETURN .F.
ENDIF
RETURN .T.
FUNCTION USA(ARQUIVO,SH,RO)
IF SH
USE &ARQUIVO SHARED NEW
ELSE
USE &ARQUIVO EXCLUSIVE NEW
ENDIF
IF !NETERR()
memory(0)
RETURN .T.
ELSE
RETURN .F.
ENDIF
FUNCTION _FECHA
LOCAL WDBF
WDBF = ALIAS()
CLOSE &WDBF
USA(WDBF,.F.,.F.)
RETURN
FUNCTION _ABRE
LOCAL WDBF
WDBF = ALIAS()
CLOSE &WDBF
USA(WDBF,.T.,.F.)
RETURN

Código: Selecionar todos
CLIENTES->( RLock(), CLIENTES->razaosocial := crazaosocial, DbCommit(), DbUnLock() )

Código: Selecionar todos
FUNCTION SALVAR_1
CLIENTES->(RLOCK(),CLIENTES->COD_CLI := M->COD_CLI,DBCOMMIT(),DBUNLOCK())
CLIENTES->(RLOCK(),CLIENTES->NOM_CLI := M->NOM_CLI,DBCOMMIT(),DBUNLOCK())
CLIENTES->(RLOCK(),CLIENTES->DAT_CLI := M->DAT_CLI,DBCOMMIT(),DBUNLOCK())
CLIENTES->(RLOCK(),CLIENTES->V_CLI := M->V_CLI,DBCOMMIT(),DBUNLOCK())
CLIENTES->(RLOCK(),CLIENTES->OBS_CLI := M->OBS_CLI,DBCOMMIT(),DBUNLOCK())

Código: Selecionar todos
CLIENTES->( DbAppend() )
If .Not. NetErr() // conseguiu inserir e deixou o registro travado...
CLIENTES->cod := nCod
CLIENTES->razao := cRazao
// demais campos
CLIENTES->( DbCommit(), DbUnLock() )
Else
Alert( "Falha ao incluir novo cliente." )
EndifCódigo: Selecionar todos
If CLIENTES->( Rlock() ) // conseguiu travar o registro...
CLIENTES->razao := cRazao
// demais campos
CLIENTES->( DbCommit(), DbUnLock() )
Else
Alert( "Falha ao alterar cliente." )
EndifCódigo: Selecionar todos
/***
*
* Locks.prg
*
* Sample networking functions to supplant the use of USE,
* FLOCK(), RLOCK() and APPEND BLANK by adding additional
* functionality
*
* Copyright (c) 1993, Computer Associates International Inc.
* All rights reserved.
*
* NOTE: Compile with /a /m /n /w options
*
*/
#include "Common.ch"
#define NET_WAIT 0.5 // Seconds to wait between between retries
#define NET_SECS 2 // Number of seconds to continue retry
/***
*
* AddRec( [<nWaitSeconds>] ) --> lSuccess
*
* Attempt to APPEND BLANK with optional retry
*
* Parameter:
* nWaitSeconds - Optional time in seconds to retry operation, defaults
* to NET_SECS
*
* Returns:
* True (.T.) if successful, false (.F.) if not
*
*/
FUNCTION AddRec( nWaitSeconds )
LOCAL lForever // Retry forever?
DEFAULT nWaitSeconds TO NET_SECS
APPEND BLANK
IF !NETERR()
RETURN ( .T. ) // NOTE
ENDIF
lForever := ( nWaitSeconds == 0 )
// Keep trying as long as our time's not up
DO WHILE ( lForever .OR. ( nWaitSeconds > 0 ) )
APPEND BLANK
IF !NETERR()
RETURN ( .T. ) // NOTE
ENDIF
INKEY( NET_WAIT ) // Wait NET_WAIT seconds (defined above)
nWaitSeconds -= NET_WAIT
ENDDO
RETURN ( .F. ) // Not locked
/***
*
* FilLock( [<nWaitSeconds>] ) --> lSuccess
*
* Attempt to FLOCK() with optional retry
*
* Parameter:
* nWaitSeconds - Optional time in seconds to retry operation, defaults
* to NET_SECS
*
* Returns:
* True if successful, false if not
*
*/
FUNCTION FilLock( nSeconds )
LOCAL lForever // Retry forever?
DEFAULT nSeconds TO NET_SECS
IF FLOCK()
RETURN ( .T. ) // NOTE
ENDIF
lForever := ( nSeconds == 0 )
// Keep trying until our time's up
DO WHILE ( lForever .OR. ( nSeconds > 0 ) )
INKEY( NET_WAIT ) // Wait NET_WAIT seconds
nSeconds -= NET_WAIT
IF FLOCK()
RETURN ( .T. ) // NOTE
ENDIF
ENDDO
RETURN ( .F. ) // Not locked
/***
*
* NetUse( <cDatabase>, <lOpenMode>, [<nWaitSeconds>] ) --> lSuccess
*
* Attempt to USE a database file with optional retry
*
* Parameters:
* cDatabase - Database file to open
* lOpenMode - Sharing mode: True indicates EXCLUSIVE, false
* indicates SHARED
* nWaitSeconds - Optional time in seconds to retry operation, defaults
* to NET_SECS
*
* Returns:
* True if successfull, false if not
*
*/
FUNCTION NetUse( cDatabase, lOpenMode, nSeconds )
LOCAL lForever // Retry forever?
DEFAULT nSeconds TO NET_SECS
lForever := ( nSeconds == 0 )
// Keep trying as long as our time's not up
DO WHILE ( lForever .OR. ( nSeconds > 0 ) )
// lOpenMode determines the mode files are opened in
IF lOpenMode
USE ( cDatabase ) EXCLUSIVE
ELSE
USE ( cDatabase ) SHARED
ENDIF
IF !NETERR()
RETURN ( .T. ) // NOTE
ENDIF
INKEY( NET_WAIT ) // Wait
nSeconds -= NET_WAIT
ENDDO
RETURN ( .F. ) // USE fails
/***
*
* RecLock( [<nWaitSeconds>] ) --> lSuccess
*
* Attempt to RLOCK() with optional retry
*
* Parameter:
* nWaitSeconds - Optional time in seconds to retry operation, defaults
* to NET_SECS
*
* Returns:
* True if successful, false if not
*
*/
FUNCTION RecLock( nSeconds )
LOCAL lForever // Retry forever?
DEFAULT nSeconds TO NET_SECS
IF RLOCK()
RETURN ( .T. ) // NOTE
ENDIF
lForever := ( nSeconds == 0 )
DO WHILE ( lForever .OR. ( nSeconds > 0 ) )
IF RLOCK()
RETURN ( .T. ) // NOTE
ENDIF
INKEY( NET_WAIT ) // Wait 1/2 second
nSeconds -= NET_WAIT
ENDDO
RETURN ( .F. ) // Not locked