Cheetah -

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Jeff
Messages : 72
Inscription : sam. 13/mai/2006 18:09

Cheetah -

Message par Jeff »

bonjour à tous,

Je m'essaye à la bdd de Cheetah et j'ai un petit problème lorsque je souhaite ajouter des éléments à ma table.

Pgm de création de la 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 = #XDBFALSE ;allow duplicate customer ID's
    
   xdbCreateIndex(IDXname, dbHandle, IndexExpr, Duplicates)

;Open the index
   idxHandle.l = xdbOpenIndex(IDXname, dbHandle)
 
    ; msg.s = "DBFname: " + DBFname + Chr(10) + "dbHandle:" + Str(dbHandle) + Chr(10) + Chr(10) + "IDXname: " + IDXname + Chr(10) + "idxHandle:" + Str(idxHandle)
    ; MessageRequester("", msg, 0)

;Add records to the database and index
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;NOTE: When adding a large number of records it is better to close
;the index, do the appends to the database and then open the
;index and reindex. For a few hundred records there should be no
;performance issues.

; NumRecs.l = 200
;
; msg.s = "Press 'Okay' To create " + Str(NumRecs) + " database and index these records."
; MessageRequester("PureBasic",msg, 0)

; ------------------------------------------------------------------------
; Predefine the field#'s for speed. If you already know the
; which field name corresponds to which field number then
; there is no need to do this. These functions provide
; really fast lookups.
;------------------------------------------------------------------------

  

;
     ; CustIDfield.l = xdbFieldNumber(dbHandle, "CUSTID")
    ; CustNameField.l = xdbFieldNumber(dbHandle,"CUSTNAME")
    ; SalaryField.l = xdbFieldNumber(dbHandle, "SALARY")
   ;
     For x.l =1 To 80

      xdbClearBuffer(dbHandle) ;this will clear the record buffer
      ;NOTE: You must do this step to assure clean information
          
       ; CustID.s = RSet(Trim(Str(x)), 7)
           
       ; xdbAssignField(dbHandle, "", ID_MACHINES_field, RSet("210", 7))
       ; xdbAssignField(dbHandle, "", CONSTRUCTEUR_field, "CHIRON")
       ; xdbAssignField(dbHandle, "", NUMSERIE_field, "NUMSERIE")
       ; xdbAssignField(dbHandle, "", DATEENTREE_field, "01/01/2006")
       ; xdbAssignField(dbHandle, "", TYPE_field, "DZ18")
       ; xdbAssignField(dbHandle, "", COMMENT_field, "Blablablabla")
     ;
        xdbAssignField(dbHandle, "ID_MACHINE" ,0, RSet ( 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" )
    
        xdbAppendRecord(dbHandle)
        
     Next x

      
      ;Add to the end of the database (Append) & add the key to the index.
    xdbAddRecord(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

Et le programme d'ajout d'éléments



;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()

;Open the index
   idxHandle.l = xdbOpenIndex(IDXname, dbHandle)
 
     ; Enregistrement des nouveaux lignes de la Bdd

     For x.l = 70 To 100

      xdbClearBuffer(dbHandle) ;this will clear the record buffer
      ;NOTE: You must do this step to assure clean information
          
        xdbAssignField(dbHandle, "ID_MACHINE" ,0, RSet ( 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
   
    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











                                                                                                         


Je suis sûr que c'est une connerie d'index ou de doublon, mais je sèche depuis une heure.

@Dobro; erix14 ssympa votre coloreur de code :)


Merci de votre aide


JF