Page 1 sur 1

Accès à une base Windev

Publié : dim. 04/juin/2006 17:33
par Jeff
Bonjour,

J'essaye d'ouvrir une base Windev Hyper File 7 à partir d'un ODBC. Si j'utilise OPENDATABASEREQUESTER pas de problème mais il est clair que ce n'est pas la solition pour mon economiseur d'ecran...


J'ai fait des recherches sur les différents forums (Fr et Uk), je trouve des solutions pour access utilisant les API mais je n'arrive pas à les convertir pour cas hyper file... http://www.purebasic.fr/english/viewtop ... endatabase

Les paramètres sont quelque peu complexes :cry:

Si quelqu'un à une solution

Merci d'avance

Publié : mar. 06/juin/2006 21:25
par Jeff
J'ai finalement trouvé une solution pour ouvrir la base Hyper File par contre j'ai systématiquement un bug en fin de programme sauf lorsque j'utilise debug.

Ci-après le message d'erreur et code source :

MESSAGE : "L'instruction à "0x10010b87" emploie l'adresse mémoire "0x00000028". La mémoire ne peut être "read".

Code : Tout sélectionner

#ODBC_ADD_DSN                       =   1 ; Add Data source
#ODBC_ADD_SYS_DSN                   =   4 ; Add SYSTEM Data source
#ODBC_CONFIG_DSN                    =   2 ; Configure (edit) Data source
#ODBC_REMOVE_DSN                    =   3 ; Remove Data source
#ODBC_REMOVE_SYS_DSN                =   6 ; Remove SYSTEM Data source
#SQL_SUCCESS                        =   0
#SQL_SUCCESS_WITH_INFO              =   1
#SQL_ERROR                          =  -1
#SQL_NO_DATA                        = 100
#SQL_MAX_MESSAGE_LENGTH             = 512

Procedure.s GetSQLError()
  Protected SQLError.w
  Protected ErrorMSGLen.w
  Protected pfErrorCode.l
  Protected iError.l
  Protected ODBCLib.l
  Errortext$=""
  
  ODBCLib=OpenLibrary(#PB_Any,"ODBCCP32.DLL")
  If ODBCLib
    For SQLError=1 To 8
      pcbErrorMsg=0
      iError=SQLError
      cbErrorMsgMax=#SQL_MAX_MESSAGE_LENGTH
      pfErrorCode=0
      ErrorMSGBuf=AllocateMemory(cbErrorMsgMax)
      If ErrorMSGBuf<>0
        SQLResult=CallFunction(ODBCLib,"SQLInstallerError",iError,@pfErrorCode,ErrorMSGBuf,(cbErrorMsgMax-1),@ErrorMSGLen)
        ;SQLResult=SQLInstallerError_(iError,@pfErrorCode,ErrorMSGBuf,(cbErrorMsgMax-1),@ErrorMSGLen)
        Debug Str(SQLError)+" : Res="+Str(SQLResult)
        Select SQLResult
          Case #SQL_SUCCESS
            Debug "ODBC : SQL SUCCESS"
          Case #SQL_SUCCESS_WITH_INFO
            Debug "ODBC : SQL SUCCESS WITH INFO"
          Case #SQL_NO_DATA
            Debug "ODBC : SQL NO DATA"
          Case #SQL_ERROR
            Debug "ODBC : SQL ERROR"
        EndSelect
        If ErrorMSGLen<>0
          ErrorMsg$=PeekS(ErrorMSGBuf,ErrorMSGLen)
          Errortext$+Str(iError)+"="+ErrorMsg$+Chr(13)
          Debug "ODBC : Fehler "+Str(iError)+"="+ErrorMsg$
        EndIf
        FreeMemory(ErrorMSGBuf)
      EndIf
    Next
    CloseLibrary(ODBCLib)
  EndIf
  If Errortext$<>""
    MessageRequester("SQL Error",Errortext$,#PB_MessageRequester_Ok)
  EndIf
  ProcedureReturn Errortext$
EndProcedure

Procedure.b MakeConnection(Driver$,Attributes$)
  Protected ODBCLib.l
  Debug "ODBC : '"+Attributes$+"'"
  MyMemory=AllocateMemory(Len(Attributes$))
  If MyMemory
    CopyMemory(@Attributes$,MyMemory,Len(Attributes$))
    For l=1 To Len(Attributes$)
      If PeekB(MyMemory+l-1)=Asc(";")
        PokeB(MyMemory+l-1,0)
      EndIf
    Next
    Result=SQLConfigDataSource_(0,#ODBC_ADD_DSN,Driver$,MyMemory)
    If Result=#False
      Debug "ODBC : SQLConfigDataSource fehlgeschlagen"
      GetSQLError()
    EndIf
    FreeMemory(MyMemory)
  EndIf
  ProcedureReturn Result
EndProcedure

If InitDatabase()=#False
  Debug "ODBC : InitDatabase ERREUR"
  End
EndIf

Driver$="Hyper File 7"
SERVER$=" "
DSN$="CLIP_LOCAL"
UID$=" "
PWD$=" "
ATTRIB$="DSN="+DSN$+";"
ATTRIB$+"DATABASE="+DSN$+";"
ATTRIB$+"DESCRIPTION="+DSN$+";"
;ATTRIB$+"DRIVER=C:\WINDOWS\system32\myodbc3.dll;"
ATTRIB$+"PWD="+PWD$+";"
ATTRIB$+"SERVER="+SERVER$+";"
ATTRIB$+"UID="+UID$+";"
ATTRIB$+";"

Debug "----------------------------------------------------"

If MakeConnection(Driver$,ATTRIB$)
  Debug "ODBC : MakeConnection OK"
  If OpenDatabase(1,DSN$,UID$,PWD$)
    Debug "ODBC : OpenDatabase OK"
  Else
    Debug "ODBC : OpenDatabase ERREUR"
  EndIf
Else
  Debug "ODBC : MakeConnection ERREUR"
EndIf 


; Accès à la base et requêtes SQL


Command$=" SELECT TOP 10 DAT, SUM(QTE)"
Command$=Command$+" FROM STOCK WHERE COFA='N_LIV' And ENTSO='E' And CODEEMP='FINIT' "
Command$=Command$+" GROUP BY DAT ORDER BY DAT ASC"
Debug Command$

If OpenWindow(0, 100, 100, 300, 200, "ListIconGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If CreateGadgetList(WindowID(0))
    ListIconGadget(0, 5, 5, 290, 180, "DATE", 100, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
    AddGadgetColumn(0, 1, "QTE ENTREE EN STOCK", 250)
    
    If DatabaseQuery(1, Command$)
      Debug "Requête passée !"
      
      While NextDatabaseRow(1)
        AddGadgetItem(0, -1, Trim(GetDatabaseString(1, 0))+Chr(10)+GetDatabaseString(1, 1))
      Wend
    Else
      Debug "Bad Query !"
    EndIf 
    
    Repeat
      Evenement = WaitWindowEvent()
    Until Evenement = #PB_Event_CloseWindow
  EndIf
EndIf
[/img][/url]