Cheetah -index problem

Just starting out? Need help? Post your questions and find answers here.
Jeff74
User
User
Posts: 12
Joined: Sun Jun 04, 2006 7:58 pm
Location: France

Cheetah -index problem

Post by Jeff74 »

Hello,

I got a problem with the index mamangement. even if the table is declared with xdbCreateIndex(IDXname, dbHandle, IndexExpr, Duplicates) Duplicated at 0" my record the same field with the same index !

Here is the code I use to create my table



;
;Use the Cheetah Include file
XIncludeFile "CheetahInc.pb"

; Use Cheetah library
  xdbUseDLL()
  xdbActivate( #X1 )
 
;Define the names of the database & index
    DBFname.s = "MACHINES.dbf"
    IDXname.s = "MACHINES.idx"

;Create the database
AllFields.s = "ID_MACHINE,C,7,0;CONSTRUCTE,C,20,0;NUMSERIE,C,50,0;DATEENTREE,D,8,0;TYPE,C,20,0;COMMENT,C,256,0"
xdbCreate(DBFname, AllFields)
 
;Open the database (database must be open prior To creating index)
    dbHandle.l = xdbOpen(DBFname, "" ) ; no encryption = ""
    AnyErrors()

;Create the index (database must be open)
   IndexExpr.s = "UPPER(ID_MACHINE)" ;index is not case sensitive
   Duplicates.l = 0 ; #XDBFALSE ;allow duplicate customer ID's
    
   xdbCreateIndex(IDXname, dbHandle, IndexExpr, Duplicates)

;Open the index
   idxHandle.l = xdbOpenIndex(IDXname, dbHandle)
 
     For x.l =1 To 80

      xdbClearBuffer(dbHandle) ;this will clear the record buffer
      ;NOTE: You must do this step to assure clean information
       
        xdbAssignField(dbHandle, "ID_MACHINE" ,0, RSet ( Trim ( Str (x)), 7))
        xdbAssignField(dbHandle, "CONSTRUCTE" ,0, "CHIRON" )
        xdbAssignField(dbHandle, "NUMSERIE" ,0, "NUMSERIE" )
        xdbAssignField(dbHandle, "DATEENTREE" ,0, "20050101" )
        xdbAssignField(dbHandle, "TYPE" ,0, "DZ18" )
        xdbAssignField(dbHandle, "COMMENT" ,0, "Blablablabla" )
    
        
         ;Add to the end of the database (Append) & add the key to the index.
        xdbAddRecord(dbHandle)
       
        
     Next x
    xdbAppendRecord(dbHandle)
     
    
    FirstRec = xdbRecordCount(dbHandle)
     Debug FirstRec
 
     ;xdbMoveNext(dbHandle, idxHandle)

;Close the database and related index
 xdbClose(dbHandle)
  
;Close any open DLL's
 xdbFreeDLL()
    
;MessageRequester("PureBasic","Database and Index records created.", 0)
End

                                                                                                         


here is the code to insert new elements



;Use the Cheetah Include file
XIncludeFile "CheetahInc.pb"

; Use Cheetah library
  xdbUseDLL()
  xdbActivate( #X1 )
 
;Define the names of the database & index
    DBFname.s = "MACHINES.dbf"
    IDXname.s = "MACHINES.idx"

;Open the database (database must be open prior To creating index)
    dbHandle.l = xdbOpen(DBFname, "" ) ; no encryption = ""
    AnyErrors()

;Create the index (database must be open)
IndexExpr.s = "UPPER(ID_MACHINE)" ;index is not case sensitive
Duplicates.l = 0 ;#XDBTRUE ;allow duplicate customer ID's
xdbCreateIndex(IDXname, dbHandle, IndexExpr, Duplicates)
 
    
;Open the index
   idxHandle.l = xdbOpenIndex(IDXname, dbHandle)
 
     ; Enregistrement des nouveaux lignes de la Bdd

     For x.l = 30 To 150

    
         Debug "x: " + Str (x)
         Debug xdbSeek(dbHandle, idxHandle, RSet ( Trim ( Str (x)), 7))
         Debug "---------------"
        
        xdbClearBuffer(dbHandle) ;this will clear the record buffer
         ;NOTE: You must do this step to assure clean information
    
        xdbAssignField(dbHandle, "ID_MACHINE" ,0, RSet ( Trim ( Str (x)), 7))
        xdbAssignField(dbHandle, "CONSTRUCTE" ,0, "CHIRON" )
        xdbAssignField(dbHandle, "NUMSERIE" ,0, "NUMSERIE" )
        xdbAssignField(dbHandle, "DATEENTREE" ,0, "20030101" )
        xdbAssignField(dbHandle, "TYPE" ,0, "DZ18" )
        xdbAssignField(dbHandle, "COMMENT" ,0, "Blablablabla" )
     
        xdbAddRecord(dbHandle)
         
     Next x
   
    xdbAppendRecord(dbHandle)
    
    FirstRec = xdbRecordCount(dbHandle)
     Debug FirstRec

;Close the database and related index
 xdbClose(dbHandle)
  
;Close any open DLL's
 xdbFreeDLL()
    
;MessageRequester("PureBasic","Database and Index records created.", 0)
End

                                                                                                         



I am sure it is something simple but I don't find the solution since 02 hours. :shock:

Note : I am using PB 4.02 under VISTA.

thanks for your help

Jeff