oDbf:Delete() error

oDbf:Delete() error

Postby Silvio.Falconi » Thu Jun 03, 2021 9:09 am

I have two database

I must delete the User and all permission of this user


The user is deleted as you can see here

USERS
Image


The permissions are not deleted ( sometimes two or three records are deleted)

Image


I not understood why


the function to delete is this

Code: Select all  Expand view

Static Function UtBorra(oUtenti,oPermessi,oGrid2,oGrid3,oBtnCambia)
   local cClave:= alltrim(oUtenti:Clave)  
   IF lABC .AND. !oUtenti:EoF()
      IF MsgYesNo("Cancellare i permessi dell'utente "+Alltrim(oUtenti:Nombre)+"?","Confermare!")
         oPermessi:Seek(cClave)
                DO WHILE !oPermessi:EoF()
            IF alltrim(oPermessi:Usuario)==cClave
                  oPermessi:Delete()
            ENDIF
            oPermessi:Skip()
         ENDDO
            oUtenti:Delete()
            oGrid2:GoUp()
            oGrid2:Refresh()
            oGrid2:SetFocus()
          Rinfresca(nMod,oUtenti,oPermessi,oGrid2,oGrid3,oBtnCambia)
      ENDIF
   ELSE
   ENDIF
   oGrid2:SetFocus()
RETURN (NIL)
 


the key and the name of the user is always 8 characters but I put an alltrim () because it can be even less than 8 characters like for example "TEST"

on the oPermessi there is a SetScope
static cKey
cKey:=oUtenti:Clave
oPermessi:setscope(cKey)

I did not understand why sometimes some records are cacenalled and other times none and other times only one,

Another test made this morning
Image



yet putting an xbrowser after the seek makes me see all the modules of that user but then does not delete them all


Any solution ?

a test sample to try the problem
Code: Select all  Expand view

#include "FiveWin.ch"

static cKey,lABC

request dbfcdx
request dbffpt

Function test()

local ctest:="Test"

RddSetDefault( "DBFCDX" )
     oUtenti:= TUtenti():New()
     oModuli:= TModuli():New()
     oPermessi:=TPermessi():New()

     lABC :=.t.

      xbrowser oUtenti
      xbrowser oPermessi

         oPermessi:SetOrder(2)
         cKey:=oUtenti:Clave
        oPermessi:setscope(cKey)
        xbrowser oPermessi

        UtBorra(oUtenti,oPermessi)

           xbrowser oPermessi
return nil


Static Function UtBorra(oUtenti,oPermessi)
   local cClave:= alltrim(oUtenti:Clave)  // può essere meno di 8 caratteri  data errore
   IF lABC .AND. !oUtenti:EoF()
      IF MsgYesNo("Cancellare i permessi dell'utente "+Alltrim(oUtenti:Nombre)+"?","Confermare!")
         oPermessi:Seek(cClave)
         xbrowser oPermessi
         DO WHILE !oPermessi:EoF()
            IF alltrim(oPermessi:Usuario)==cClave
                  oPermessi:Delete()
            ENDIF
            oPermessi:Skip()
         ENDDO
            oUtenti:Delete()
            *oGrid2:GoUp()
            *oGrid2:Refresh()
            *oGrid2:SetFocus()
          *Rinfresca(nMod,oUtenti,oPermessi,oGrid2,oGrid3,oBtnCambia)
      ENDIF
   ELSE
   ENDIF
  * oGrid2:SetFocus()
RETURN (NIL)






CLASS TXData from TDataBase
       DATA cExePath  init cFilePath(GetModuleFileName( GetInstance() ))
     ENDCLASS


CLASS TUtenti from TXData
   METHOD New()
ENDCLASS

METHOD New( lShared ) CLASS TUtenti
   Default lShared := .t.
   ::super:Open(,::cExePath + "Utenti" ,, lShared)
   if ::use()
      ::setOrder(1)
      ::gotop()
   endif
RETURN Self
//----------------------------------------------------------------------moduli
CLASS TModuli from TXData
   METHOD New()
ENDCLASS

METHOD New( lShared ) CLASS TModuli
   Default lShared := .t.
   ::super:Open(,::cExePath + "Moduli" ,, lShared)
   if ::use()
      ::setOrder(1)
      ::gotop()
   endif
RETURN Self
//----------------------------------------------------------------------Permessi
CLASS TPermessi from TXData
   METHOD New()
ENDCLASS

METHOD New( lShared ) CLASS TPermessi
   Default lShared := .t.
   ::super:Open(,::cExePath + "Permessi" ,, lShared)
   if ::use()
      ::setOrder(1)
      ::gotop()
   endif
RETURN Self



 


write to me at silvio[dot]falconi[at]gmail[dot]com if you need the dbfs to test it
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7053
Joined: Thu Oct 18, 2012 7:17 pm

Re: oDbf:Delete() error

Postby nageswaragunupudi » Fri Jun 04, 2021 5:34 am

When you want to delete multiple records for a given condition

oDbf:Lock()
oDbf:Exec( { || DELETE FOR <cond> } )
oDbf:Unlock()
Regards

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

Re: oDbf:Delete() error

Postby Silvio.Falconi » Fri Jun 04, 2021 12:49 pm

Nages,
someone (an american boy) sad me not use lock and unlock (and commit) because
tdatabase make it auto.
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7053
Joined: Thu Oct 18, 2012 7:17 pm

Re: oDbf:Delete() error

Postby nageswaragunupudi » Fri Jun 04, 2021 2:30 pm

Silvio.Falconi wrote:Nages,
someone (an american boy) sad me not use lock and unlock (and commit) because
tdatabase make it auto.


Not FLOCK
Regards

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

Re: oDbf:Delete() error

Postby Silvio.Falconi » Fri Jun 04, 2021 8:24 pm

then

DO WHILE !oPermessi:EoF()
oPermessi:Lock()
oPermessi:Exec( { || DELETE FOR oPermessi:Usuario==oUtenti:Clave } )
oPermessi:Unlock()

oPermessi:Skip()
ENDDO

is it right ?

make me error
source\test.prg(688) Error E0030 Syntax error "syntax error at 'FOR'"
1 error
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7053
Joined: Thu Oct 18, 2012 7:17 pm

Re: oDbf:Delete() error

Postby Marc Venken » Sat Jun 05, 2021 8:48 am

Silvio.Falconi wrote:then

DO WHILE !oPermessi:EoF()
oPermessi:Lock()
oPermessi:Exec( { || DELETE FOR oPermessi:Usuario==oUtenti:Clave } )
oPermessi:Unlock()

oPermessi:Skip()
ENDDO

is it right ?

make me error
source\test.prg(688) Error E0030 Syntax error "syntax error at 'FOR'"
1 error


No, it's not

As i see it, the

oPermessi:Lock() // is actually a Flock and therefore not needed in a loop
oPermessi:Exec( { || DELETE FOR oPermessi:Usuario==oUtenti:Clave } ) // block that run all data inside the exec(), so not in a loop

Only the 3 lines from Mr. Rao seems to be needed.

the <cond> is the tricky part... what code is needed

// other post :

If you want to delete all records where the field INVNUM == nInvoice, i.e., "1234567890128", then:
[code]
Local nInvoice := "1234567890128"

oPartres:Exec( <||
DELETE ALL FOR ALLTRIM(FIIELD->INVNUM) == nInvoice
> )
[code]

viewtopic.php?f=3&t=37616&hilit=delete+for
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1429
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: oDbf:Delete() error

Postby Marc Venken » Sat Jun 05, 2021 8:55 am

Maybe this will do it almost...

Code: Select all  Expand view

nInvoice := "1234567890128"
oPermessi:Lock()

oPermessi:Exec( <|| DELETE ALL FOR ALLTRIM(FIELD->INVNUM) == nInvoice  > )  // here your code

oPermessi:Unlock()

 
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1429
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: oDbf:Delete() error

Postby Silvio.Falconi » Sat Jun 05, 2021 10:28 am

Marc Venken wrote:Maybe this will do it almost...

Code: Select all  Expand view

nInvoice := "1234567890128"
oPermessi:Lock()

oPermessi:Exec( <|| DELETE ALL FOR ALLTRIM(FIELD->INVNUM) == nInvoice  > )  // here your code

oPermessi:Unlock()

 



usuario and clave are 8 cr

DO WHILE !oPermessi:EoF()
oPermessi:Lock()
oPermessi:Exec( { || DELETE FOR alltrim(oPermessi:Usuario)==oUtenti:Clave } )
oPermessi:Unlock()
oPermessi:Skip()
ENDDO

I tried also with oPermessi:Exec( { || DELETE FOR alltrim(FIELD->Usuario)==oUtenti:Clave } )
give me an error on compilation
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7053
Joined: Thu Oct 18, 2012 7:17 pm

Re: oDbf:Delete() error

Postby Silvio.Falconi » Sat Jun 05, 2021 10:53 am

Now run ok

DO WHILE !oPermessi:EoF()
oPermessi:Lock()
oPermessi:Exec( { ||
DELETE FOR ALLTRIM(oPermessi:Usuario)==ALLTRIM(oUtenti:Clave)
} )
oPermessi:Unlock()
oPermessi:Skip()
ENDDO


and it delete all records but only some records because on Permessi dbf there is a filter, it deleted only that record have M = 5 :)
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7053
Joined: Thu Oct 18, 2012 7:17 pm

Re: oDbf:Delete() error

Postby Silvio.Falconi » Sat Jun 05, 2021 11:08 am

Now run ok

Code: Select all  Expand view
Static Function UtBorra(oUtenti,oPermessi,oGrid2,oGrid3,oBtnCambia)
   local cClave:= oUtenti:Clave
      cKey:=(oUtenti:Clave)
   IF lABC .AND. !oUtenti:EoF()
      IF MsgYesNo("Cancellare i permessi dell'utente "+Alltrim(oUtenti:Nombre)+"?","Confermare!")
         oPermessi:Seek(cClave)
         oPermessi:SetScope(cKey)
          DO WHILE !oPermessi:EoF()
             oPermessi:Lock()
             oPermessi:Exec( { ||
             DELETE FOR ALLTRIM(oPermessi:Usuario)==ALLTRIM(oUtenti:Clave)
          } )
            oPermessi:Unlock()
            oPermessi:Skip()
         ENDDO
            oUtenti:Delete()
            oGrid2:GoUp()
            oGrid2:Refresh()
            oGrid2:SetFocus()
          Rinfresca(nMod,oUtenti,oPermessi,oGrid2,oGrid3,oBtnCambia)
      ENDIF
   ELSE
   ENDIF
   oGrid2:SetFocus()
RETURN (NIL)

 
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7053
Joined: Thu Oct 18, 2012 7:17 pm

Re: oDbf:Delete() error

Postby Marc Venken » Sun Jun 06, 2021 8:30 am

Hey Silvio,

Great that you have it working !

Could you please try this function (1 loop less that yours) for my personel curiossity ?
I would like to know if

oPermessi:Exec( { ||
DELETE FOR ALLTRIM(oPermessi:Usuario)==ALLTRIM(oUtenti:Clave)
} )

acts like a dbeval and processes all scopes records...

Code: Select all  Expand view

Static Function UtBorra(oUtenti,oPermessi,oGrid2,oGrid3,oBtnCambia)
   local cClave:= oUtenti:Clave
      cKey:=(oUtenti:Clave)
   IF lABC .AND. !oUtenti:EoF()
      IF MsgYesNo("Cancellare i permessi dell'utente "+Alltrim(oUtenti:Nombre)+"?","Confermare!")
         oPermessi:Seek(cClave)
         oPermessi:SetScope(cKey)
         oPermessi:Lock()
          oPermessi:Exec( { ||
             DELETE FOR ALLTRIM(oPermessi:Usuario)==ALLTRIM(oUtenti:Clave)
          } )
           oPermessi:Unlock()
            oUtenti:Delete()
           oGrid2:GoUp()
           oGrid2:Refresh()
           oGrid2:SetFocus()
          Rinfresca(nMod,oUtenti,oPermessi,oGrid2,oGrid3,oBtnCambia)
      ENDIF
   ELSE
   ENDIF
   oGrid2:SetFocus()
RETURN (NIL)

 
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1429
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: oDbf:Delete() error

Postby nageswaragunupudi » Sun Jun 06, 2021 10:09 am

Code: Select all  Expand view
        oPermessi:Lock()
          oPermessi:Exec( { ||
             DELETE FOR ALLTRIM(Usuario)==ALLTRIM(oUtenti:Clave)
          } )
 


The DELETE FOR statement should be PURE RDD statement,
Regards

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

Re: oDbf:Delete() error

Postby James Bott » Sun Jun 06, 2021 6:30 pm

Maybe try this:

Code: Select all  Expand view

          oPermessi:Lock()
          oPermessi:Exec( { |oUtenti|
             DELETE FOR ALLTRIM(Usuario)==ALLTRIM(oUtenti:Clave)
          } )
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: oDbf:Delete() error

Postby nageswaragunupudi » Sun Jun 06, 2021 7:16 pm

James Bott wrote:Maybe try this:

Code: Select all  Expand view

          oPermessi:Lock()
          oPermessi:Exec( { |oUtenti|
             DELETE FOR ALLTRIM(Usuario)==ALLTRIM(oUtenti:Clave)
          } )


This gives wrong results.
Exec method evaluates the codeblock with Self as parameter.
Code: Select all  Expand view
  METHOD Exec( bBlock )      INLINE ( ::cAlias )->( Eval( bBlock, Self ) )
 

So, the variable oUtenti gets the value of oPermiessi inside this codeblock.
Regards

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

Re: oDbf:Delete() error

Postby Silvio.Falconi » Sun Jun 06, 2021 8:15 pm

Marc Venken wrote:Hey Silvio,


Mark,
on my procedure when I delete a User I must delete all permissions of that user , but when I call ut_borra() function to delete that use I have on Permission dbf a set scope
Now with the new fwh ( april 2021) I can erase that setscope with setscope(nil), then I can delete all the permissions of that user with

Code: Select all  Expand view
DO WHILE !oPermessi:EoF()
             oPermessi:Lock()
             oPermessi:Exec( { ||
             DELETE FOR ALLTRIM(oPermessi:Usuario)==ALLTRIM(oUtenti:Clave)
          } )
            oPermessi:Unlock()
            oPermessi:Skip()
         ENDDO


then I can delete the user with oUtenti:Delete()

before it is not working because need a Flock (1) and I had the setscope on Usuario field ( user) (2)
with these two problems only some records were deleted, but now it seems to work fine


Image


I didn't see the deleted records and I trusted them
I did not see them because the dbf was indexed with condition! Deleted ()
and then there was the scope on the user and on the number of menus (green box)
so if I selected a user in the xbrowse above I could not see the records in the xbrowse that it was below,
I didn't select it because the user had been deleted but his permissions were still in the archive
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7053
Joined: Thu Oct 18, 2012 7:17 pm

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Marc Venken, nageswaragunupudi and 68 guests