[DONE] [PR1.878] Problem with Unicode and Threadsafe

TailBite specific forum

Moderators: gnozal, ABBKlaus, lexvictory

User avatar
mk-soft
Always Here
Always Here
Posts: 5405
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

[DONE] [PR1.878] Problem with Unicode and Threadsafe

Post by mk-soft »

Hi,

i can´t compile a stable version from ExDatabase at Unicode and Threadsafe for PB4.30.
I become no tablesname and tablestype.

Source

Code: Select all

;-TOP
; Kommentar     : ExDatabase Lib for Purebasic
; Author 1      : Siegfried Rings
; Author 2      : ts-soft
; Author 3      : mk-soft (Michael Kastner)
; Author 4      : 
; Datei         : PBOSL_ExDatabase.pb
; Version       : 1.09 (PB4.20)
; Erstellt      : 01.03.2007
; Geändert      : 01.06.2008
; 
; Compilermode  :
;
; ***************************************************************************************

; ExDatabase Lib for Purebasic
;
; -----------------------------------------------------------------------------
;     (c) 2004-2005 Siegfried Rings
;     (c) 2007 New functions by mk-soft, ts-soft and german-forum
;
;     This library is free software; you can redistribute it and/or
;     modify it under the terms of the GNU Lesser General Public
;     License as published by the Free Software Foundation; either
;     version 2.1 of the License, Or (at your option) any later version.
;
;     This library is distributed in the hope that it will be useful,
;     but WITHOUT ANY WARRANTY; without even the implied warranty of
;     MERCHANTABILITY Or FITNESS For A PARTICULAR PURPOSE.  See the GNU
;     Lesser General Public License For more details.
; -----------------------------------------------------------------------------

;EnableExplicit

#ODBC_ADD_DSN                       = 1; // Add data source
#ODBC_CONFIG_DSN                    = 2; // Configure (edit) Data source
#ODBC_REMOVE_DSN                    = 3; // Remove data source
#ODBC_ADD_SYS_DSN                   = 4; // add a system DSN
#ODBC_CONFIG_SYS_DSN                = 5; // Configure a system DSN
#ODBC_REMOVE_SYS_DSN                = 6; // remove a system DSN
#ODBC_REMOVE_DEFAULT_DSN            = 7; // remove the default DSN

#SQL_SUCCESS                        =   0
#SQL_SUCCESS_WITH_INFO              =   1
#SQL_ERROR                          =  -1
#SQL_NO_DATA                        = 100
#SQL_MAX_MESSAGE_LENGTH             = 512
#SQL_MAX_DSN_LENGTH                 =  32

#ODBC_ERROR_GENERAL_ERR             =   1
#ODBC_ERROR_INVALID_BUFF_LEN        =   2
#ODBC_ERROR_INVALID_HWND            =   3
#ODBC_ERROR_INVALID_STR             =   4
#ODBC_ERROR_INVALID_REQUEST_TYPE    =   5
#ODBC_ERROR_COMPONENT_NOT_FOUND     =   6
#ODBC_ERROR_INVALID_NAME            =   7
#ODBC_ERROR_INVALID_KEYWORD_VALUE   =   8
#ODBC_ERROR_INVALID_DSN             =   9
#ODBC_ERROR_INVALID_INF             =  10
#ODBC_ERROR_REQUEST_FAILED          =  11
#ODBC_ERROR_INVALID_PATH            =  12
#ODBC_ERROR_LOAD_LIB_FAILED         =  13
#ODBC_ERROR_INVALID_PARAM_SEQUENCE  =  14
#ODBC_ERROR_INVALID_LOG_FILE        =  15
#ODBC_ERROR_USER_CANCELED           =  16
#ODBC_ERROR_USAGE_UPDATE_FAILED     =  17
#ODBC_ERROR_CREATE_DSN_FAILED       =  18
#ODBC_ERROR_WRITING_SYSINFO_FAILED  =  19
#ODBC_ERROR_REMOVE_DSN_FAILED       =  20
#ODBC_ERROR_OUT_OF_MEM              =  21
#ODBC_ERROR_OUTPUT_STRING_TRUNCATED =  22

#SQL_NTS                            =  -3
#SQL_DROP                           =   1

#MAX_DATA                           = 100

; ***************************************************************************************

Global Handle.l ;for Opened sql base
Global MemHandle.l
Global MemHandle2.l

; ***************************************************************************************

Structure direxec
   rc.l                               ; RETCODE rc;        // ODBC return code
   henv.l                             ; HENV henv;         // Environment   
   hdbc.l                             ; HDBC hdbc;         // Connection handle
   hstmt.l                            ; HSTMT hstmt;       // Statement handle
   szData.s{#MAX_DATA}                ; unsigned char szData[MAX_DATA];   // Returned data storage
   cbData.l                           ; SDWORD cbData;     // Output length of data
   chr_ds_name.s{#SQL_MAX_DSN_LENGTH} ; unsigned char chr_ds_name[SQL_MAX_DSN_LENGTH];   // Data source name
EndStructure

Global x.direxec

; ***************************************************************************************

Macro MYSQLSUCCESS(rc)
  ((rc=#SQL_SUCCESS) Or (rc=#SQL_SUCCESS_WITH_INFO))
EndMacro

; ***************************************************************************************

Declare sqlconn(dsn.s, user.s, pass.s)
Declare sqldisconn()

; ***************************************************************************************

ProcedureDLL.s GetSQLInstallerError()
  
  Protected iError.l, ErrorMSGLen.l, cbErrorMsgMax, pfErrorCode.l, SQLResult.l
  Protected *ErrorMSGBuf
  Protected Errortext.s, ErrorMsg.s
  
  cbErrorMsgMax=#SQL_MAX_MESSAGE_LENGTH
  *ErrorMSGBuf=AllocateMemory(cbErrorMsgMax+1)
  If *ErrorMSGBuf = 0
    ProcedureReturn "Error AllocateMemory!"
  EndIf
    
  For iError=1 To 8
    SQLResult = SQLInstallerError_(iError, @pfErrorCode, *ErrorMSGBuf, cbErrorMsgMax, @ErrorMSGLen)
    If SQLResult = #SQL_SUCCESS Or SQLResult = #SQL_SUCCESS_WITH_INFO
      ErrorMsg = PeekS(*ErrorMSGBuf, ErrorMSGLen)
      Errortext + Str(iError) + ". " + ErrorMsg + #LF$
    EndIf
  Next
  
  FreeMemory(*ErrorMSGBuf)
  
  ProcedureReturn Errortext
EndProcedure

; ***************************************************************************************

Procedure.s TrimEx(String.s, Chr.s)
  While Right(String, 1) = Chr
    String = Left(String, Len(String) - 1)
  Wend
  While Left(String, 1) = Chr
    String = Mid(String, 2, Len(String))
  Wend
  ProcedureReturn String
EndProcedure

; ***************************************************************************************

ProcedureDLL ExDatabase_Init()
  MemHandle = GlobalAlloc_(#GMEM_FIXED, 1024)
  MemHandle2 = GlobalAlloc_(#GMEM_FIXED, 4*4)
EndProcedure

; ***************************************************************************************

ProcedureDLL ExDatabase_End()
  If Memhandle
    GlobalFree_(memhandle)
  EndIf
  If Memhandle2
    GlobalFree_(memhandle2)
  EndIf
  If x\hstmt
    sqldisconn()
  EndIf
EndProcedure

; ***************************************************************************************

ProcedureDLL ExamineTables2(DSN.s, USER.s, PASS.s);Start examine the database for tables
  Protected res.l
  
  Handle = sqlconn(dsn,user,pass)
  If Handle
    res = SQLTables_(Handle, 0, 0, 0, 0, 0, 0, 0, 0) & $FFFF
    If res = 0 Or res = 1 ;SQL_SUCCESS or #SQL_SUCCESS_WITH_INFO
      SQLBindCol_(Handle, 1, 1, MemHandle, 256, MemHandle2)
      SQLBindCol_(Handle, 2, 1, MemHandle + 256, 256, MemHandle2 + 4)
      SQLBindCol_(Handle, 3, 1, MemHandle + 512, 256, MemHandle2 + 8)
      SQLBindCol_(Handle, 4, 1, MemHandle + 768, 256, MemHandle2 + 12)
    EndIf
  EndIf
  ProcedureReturn Handle
EndProcedure

; ***************************************************************************************

ProcedureDLL ExamineTables(DSN.s);Start examine the database for tables
  ProcedureReturn ExamineTables2(DSN.s, "", "")
EndProcedure

; ***************************************************************************************

ProcedureDLL NextTable();get next (or first) table-information
  Protected Result.l

  If (Handle <> 0) And (Memhandle <> 0) And (memhandle2 <> 0)
    Result = SQLFetch_(Handle)
    If Result & $FFFF = 0
      ProcedureReturn 1
    Else
      sqldisconn()
      Handle = 0
      ProcedureReturn 0
    EndIf

  EndIf

EndProcedure

; ***************************************************************************************

ProcedureDLL.s GetTableName();Get the Tablename
  ProcedureReturn Trim(PeekS(MemHandle + 512, 128, #PB_Ascii))
EndProcedure

; ***************************************************************************************

ProcedureDLL.s GetTableType();Get the Tabletype
  ProcedureReturn Trim(PeekS(MemHandle + 768, 128, #PB_Ascii))
EndProcedure

; ***************************************************************************************

Procedure.s Add_DSN(odbc_type.l, databasename.s, user.s, pass.s, driver.s, attributes.s)
  
  Protected dsn.s, name.s, prefix.s, server.s, serverport.s, type.s, strDriver.s, strAttributes.s
  Protected L.l, result.l, len
  Protected *buffer.Character
  
  ; Drivertype wählen
  type = GetExtensionPart(databasename)
  
  ; Prefix erzeugen
  prefix = ProgramFilename()
  prefix = GetFilePart(prefix)
  prefix = Left(prefix, Len(prefix) - (Len(type) + 1))
  
  ; Databasename erzeugen
  name = GetFilePart(databasename)
  name = Left(name, Len(name) - (Len(type) + 1))
  dsn = prefix + "_" + UCase(name)
  dsn = Left(dsn, #SQL_MAX_DSN_LENGTH)
  
  ; Datenbanktreiber auswählen
  Select UCase(type)
    Case "MYSQL"
      strDriver = "MySQL ODBC 3.51 Driver"
    Case "MSSQL"
      strDriver = "SQL Server"
    Case "MDB"
      strDriver = "Microsoft Access Driver (*.mdb)"
    Case "XLS"
      strDriver = "Microsoft Excel Driver (*.xls)"
    Case "DBF"
      strDriver = "Microsoft dBase Driver (*.dbf)"
    Case "TXT", "CSV"
      strDriver = "Microsoft Text Driver (*.txt; *.csv)"
    Case "FDB"
      strDriver = "Firebird/InterBase(r) driver"
    Case "SQLITE"
      strDriver = "SQLite ODBC Driver"
    Case "SQLITE3"
      strDriver = "SQLite3 ODBC Driver"
  EndSelect
  ; Driver wechseln
  If driver
    strDriver = driver
  EndIf
  ; Attributes erstellen
  Select UCase(type)
    Case "MYSQL"
      server = GetPathPart(databasename)
      server = TrimEx(server, "\")
      serverport = StringField(server, 2, ":")
      server = StringField(server, 1, ":")
      If server = ""
        server = "localhost"
      EndIf
      strAttributes.s = "Server=" + server
      strAttributes.s + ";Description=" + name
      strAttributes.s + ";DSN=" + dsn
      strAttributes.s + ";DATABASE=" + name
      strAttributes.s + ";UID=" + user
      strAttributes.s + ";PWD=" + pass
      If serverport
        strAttributes.s + ";PORT=" + serverport
      EndIf
      strAttributes.s + ";"
      If attributes
        strAttributes.s + attributes +";"
      EndIf
    Case "MSSQL"
      server = GetPathPart(databasename)
      server = TrimEx(server, "\")
      If server = ""
        server = "(local)\SQLEXPRESS"
      EndIf
      strAttributes.s = "DSN=" + dsn
      strAttributes.s + ";DESCRIPTION=" + name
      strAttributes.s + ";SERVER=" + server
      strAttributes.s + ";NETWORK=DBMSSOCN"
      strAttributes.s + ";DATABASE=" + name
      ;strAttributes.s + ";Trusted_Connection=Yes"
      strAttributes.s + ";"
      If attributes
        strAttributes.s + attributes +";"
      EndIf
    Case "MDB", "XLS"
      strAttributes.s = "Server=APServer;Description=" + name
      strAttributes.s + ";DSN=" + dsn
      strAttributes.s + ";DBQ=" + databasename
      strAttributes.s + ";UID=" + user
      strAttributes.s + ";PWD=" + pass
      strAttributes.s + ";"
    Case "DBF", "TXT", "CSV"
      strAttributes.s = "Server=APServer;Description=" + name
      strAttributes.s + ";DSN=" + dsn
      strAttributes.s + ";DBQ=" + GetPathPart(databasename)
      strAttributes.s + ";UID=" + user
      strAttributes.s + ";PWD=" + pass
      strAttributes.s + ";"
      If attributes
        strAttributes.s + attributes +";"
      EndIf
    Case "FDB"
      strAttributes.s + "DSN=" + dsn
      strAttributes.s + ";DESCRIPTION=" + name
      strAttributes.s + ";DATABASE=" + databasename
      strAttributes.s + ";UID=" + user
      strAttributes.s + ";PWD=" + pass
      strAttributes.s + ";"
      If attributes
        strAttributes.s + attributes +";"
      EndIf
    Case "SQLITE"
      strAttributes.s + "DSN=" + dsn
      strAttributes.s + ";DATABASE=" + Left(databasename, Len(databasename) - 7)
      strAttributes.s + ";"
      If attributes
        strAttributes.s + attributes +";"
      EndIf
    Case "SQLITE3"
      strAttributes.s + "DSN=" + dsn
      strAttributes.s + ";DATABASE=" + Left(databasename, Len(databasename) - 8)
      strAttributes.s + ";"
      If attributes
        strAttributes.s + attributes +";"
      EndIf
    Default
      strAttributes.s = "DSN=" + dsn
      strAttributes.s + ";DESCRIPTION=" + name
      strAttributes.s + ";"
      strAttributes.s = attributes
      strAttributes.s + ";"
  EndSelect
  
  *buffer = @strAttributes
  len = Len(strAttributes) - 1
  For L = 0 To len
    If *buffer\c = ';'
      *buffer\c = 0
    EndIf
    *buffer + SizeOf(Character)
  Next L
  
  result = SQLConfigDataSource_(0, odbc_type, strDriver, strAttributes)
   
  If result
    ProcedureReturn dsn
  Else
    ProcedureReturn ""
  EndIf

EndProcedure

; ***************************************************************************************

ProcedureDLL.s AddDSN4(databasename.s, user.s, pass.s, driver.s, attributes.s)
  ProcedureReturn Add_DSN(#ODBC_ADD_DSN ,databasename.s, user.s, pass.s, driver.s, attributes)
EndProcedure

; ***************************************************************************************

ProcedureDLL.s AddDSN3(databasename.s, user.s, pass.s, driver.s)
  ProcedureReturn Add_DSN(#ODBC_ADD_DSN ,databasename.s, user.s, pass.s, driver.s, "")
EndProcedure

; ***************************************************************************************

ProcedureDLL.s AddDSN2(databasename.s, user.s, pass.s)
  ProcedureReturn Add_DSN(#ODBC_ADD_DSN ,databasename.s, user.s, pass.s, "", "")
EndProcedure

; ***************************************************************************************

ProcedureDLL.s AddDSN(databasename.s);Make a User DSN Connection
  ProcedureReturn Add_DSN(#ODBC_ADD_DSN ,databasename.s, "", "", "", "")
EndProcedure

; ***************************************************************************************

ProcedureDLL.s AddSystemDSN4(databasename.s, user.s, pass.s, driver.s, attributes.s)
  ProcedureReturn Add_DSN(#ODBC_ADD_SYS_DSN ,databasename.s, user.s, pass.s, driver.s, attributes.s)
EndProcedure

; ***************************************************************************************

ProcedureDLL.s AddSystemDSN3(databasename.s, user.s, pass.s, driver.s)
  ProcedureReturn Add_DSN(#ODBC_ADD_SYS_DSN ,databasename.s, user.s, pass.s, driver.s, "")
EndProcedure

; ***************************************************************************************

ProcedureDLL.s AddSystemDSN2(databasename.s, user.s, pass.s)
  ProcedureReturn Add_DSN(#ODBC_ADD_SYS_DSN ,databasename.s, user.s, pass.s, "", "")
EndProcedure

; ***************************************************************************************

ProcedureDLL.s AddSystemDSN(databasename.s);Make a System DSN Connection
  ProcedureReturn Add_DSN(#ODBC_ADD_SYS_DSN ,databasename.s, "", "", "", "")
EndProcedure

; ***************************************************************************************

Procedure Remove_DSN(odbc_type, databasename.s, driver.s)
  
  Protected dsn.s, name.s, prefix.s, type.s, strDriver.s, strAttributes.s
  Protected L.l, result.l, len.l
  Protected *buffer.Character
 
  ; Drivertype wählen
  type = GetExtensionPart(databasename)
  
  ; Prefix erzeugen
  prefix = ProgramFilename()
  prefix = GetFilePart(prefix)
  prefix = Left(prefix, Len(prefix) - (Len(type) + 1))
  
  ; Databasename erzeugen
  name = GetFilePart(databasename)
  name = Left(name, Len(name) - (Len(type) + 1))
  dsn = prefix + "_" + UCase(name)
  dsn = Left(dsn, #SQL_MAX_DSN_LENGTH)
  
  ; Datenbanktreiber auswählen
  Select UCase(type)
    Case "MYSQL"
      strDriver.s = "MySQL ODBC 3.51 Driver"
    Case "MSSQL"
      strDriver = "SQL Server"
    Case "MDB"
      strDriver = "Microsoft Access Driver (*.mdb)"
    Case "XLS"
      strDriver = "Microsoft Excel Driver (*.xls)"
    Case "DBF"
      strDriver = "Microsoft dBase Driver (*.dbf)"
    Case "TXT", "CSV"
      strDriver = "Microsoft Text Driver (*.txt; *.csv)"
    Case "FDB"
      strDriver = "Firebird/InterBase(r) driver"
    Case "SQLITE"
      strDriver = "SQLite ODBC Driver"
    Case "SQLITE3"
      strDriver = "SQLite3 ODBC Driver"
  EndSelect
  ; Driver wechseln
  If driver
    strDriver = driver
  EndIf
  ; Attributes zustellen
  strAttributes = "DSN=" + dsn + ";"
 
  *buffer = @strAttributes
  len = Len(strAttributes) - 1
  For L = 0 To len
    If *buffer\c = ';'
      *buffer\c = 0
    EndIf
    *buffer + SizeOf(Character)
  Next L
 
  result = SQLConfigDataSource_(0, odbc_type, strDriver, strAttributes)   ; Call the function you need from the ODBC library with the right details
 
  ProcedureReturn result

EndProcedure

; ***************************************************************************************

ProcedureDLL RemoveDSN2(databasename.s, driver.s)
  ProcedureReturn Remove_DSN(#ODBC_REMOVE_DSN, databasename, driver)
EndProcedure

; ***************************************************************************************

ProcedureDLL RemoveDSN(databasename.s);Delete a User DSN Connection
  ProcedureReturn Remove_DSN(#ODBC_REMOVE_DSN, databasename, "")
EndProcedure

; ***************************************************************************************

ProcedureDLL RemoveSystemDSN2(databasename.s, driver.s)
  ProcedureReturn Remove_DSN(#ODBC_REMOVE_SYS_DSN, databasename, driver)
EndProcedure

; ***************************************************************************************

ProcedureDLL RemoveSystemDSN(databasename.s);Delete a System DSN Connection
  ProcedureReturn Remove_DSN(#ODBC_REMOVE_SYS_DSN, databasename, "")
EndProcedure

; ***************************************************************************************

ProcedureDLL RepairMDB2(databasename.s, user.s, pass.s)
  Protected name.s, strDriver.s, strAttributes.s, L.l, result.l
  Protected *buffer.Character, len.l
  
  name = GetFilePart(databasename)
  name = Left(name, Len(name) - (Len(GetExtensionPart(name)) + 1))

  strDriver = "Microsoft Access Driver (*.mdb)"
  strAttributes + "REPAIR_DB=" + #DQUOTE$ + databasename + #DQUOTE$
  strAttributes + ";UID=" + user
  strAttributes + ";PWD=" + pass + ";"

  *buffer = @strAttributes
  len = Len(strAttributes) - 1
  For L = 0 To len
    If *buffer\c = ';'
      *buffer\c = 0
    EndIf
    *buffer + SizeOf(Character)
  Next L
 
  result = SQLConfigDataSource_(0, #ODBC_ADD_DSN, strDriver, strAttributes)   ; Call the function you need from the ODBC library with the right details

  ProcedureReturn result
  
EndProcedure

; ***************************************************************************************

ProcedureDLL RepairMDB(databasename.s);Repair a Access Database
  ProcedureReturn RepairMDB2(databasename, "", "")
EndProcedure

; ***************************************************************************************

ProcedureDLL CompactMDB2(databasename.s, user.s, pass.s)
  
  Protected strDriver.s, strAttributes.s, L.l, result.l
  Protected *buffer.Character, len.l
  
  strDriver = "Microsoft Access Driver (*.mdb)"
  strAttributes + "COMPACT_DB=" + #DQUOTE$ + databasename + #DQUOTE$ + " " + #DQUOTE$ + databasename + #DQUOTE$+ " General"
  strAttributes + ";UID=" + user
  strAttributes + ";PWD=" + pass + ";"
  
  *buffer = @strAttributes
  len = Len(strAttributes) - 1
  For L = 0 To len
    If *buffer\c = ';'
      *buffer\c = 0
    EndIf
    *buffer + SizeOf(Character)
  Next L
  
  result = SQLConfigDataSource_(0, #ODBC_ADD_DSN, strDriver, strAttributes)   ; Call the function you need from the ODBC library with the right details
  
  ProcedureReturn result
  
EndProcedure

; ***************************************************************************************

ProcedureDLL CompactMDB(databasename.s);Compact a Access Database
  ProcedureReturn CompactMDB2(databasename, "", "")
EndProcedure

; ***************************************************************************************

ProcedureDLL CreateEmptyMDB2(databasename.s, user.s, pass.s)
  Protected strDriver.s, strAttributes.s, L.l, result.l
  Protected *buffer.Character, len.l
  
  If FileSize(databasename) > 0
    DeleteFile(databasename)
  EndIf
 
  strDriver = "Microsoft Access Driver (*.mdb)"
  strAttributes + "CREATE_DB=" + #DQUOTE$ + databasename + #DQUOTE$ + " General"
  strAttributes + ";UID=" + user
  strAttributes + ";PWD=" + pass + ";"
  
  *buffer = @strAttributes
  len = Len(strAttributes) - 1
  For L = 0 To len
    If *buffer\c = ';'
      *buffer\c = 0
    EndIf
    *buffer + SizeOf(Character)
  Next L

  result = SQLConfigDataSource_(0, #ODBC_ADD_DSN, strDriver, strAttributes)   ; Call the function you need from the ODBC library with the right details

  ProcedureReturn result
  
EndProcedure

; ***************************************************************************************

ProcedureDLL CreateEmptyMDB(databasename.s);Create a Empty Access Database
  ProcedureReturn CreateEmptyMDB2(databasename, "", "")
EndProcedure
 
; ***************************************************************************************

; ***************************************************************************************

; // Allocate environment handle, allocate connection handle,
; // connect To Data source, And allocate statement handle.

Procedure sqlconn(dsn.s, user.s, pass.s)

  With x
    ; Vorhandene verbindung trennen
    If \hstmt
      sqldisconn()
    EndIf
    \chr_ds_name = dsn
    SQLAllocEnv_(@\henv);
    SQLAllocConnect_(\henv,@\hdbc);
    \rc=SQLConnect_(\hdbc,@\chr_ds_name,#SQL_NTS,user,Len(user),pass,Len(pass));
    \rc & $FFFF
    ;// Deallocate handles, display error message, And exit.
    If Not(MYSQLSUCCESS(\rc))
      SQLFreeEnv_(\henv);
      SQLFreeConnect_(\hdbc);
      \henv = 0
      \hdbc = 0
      ProcedureReturn 0
    EndIf

    \rc = SQLAllocStmt_(\hdbc,@\hstmt);
    \rc & $FFFF
    If Not(MYSQLSUCCESS(\rc))
      SQLFreeEnv_(\henv);
      SQLFreeConnect_(\hdbc);
      \henv  = 0
      \hdbc  = 0
      \hstmt = 0
      ProcedureReturn 0
    Else
      ProcedureReturn \hstmt
    EndIf

  EndWith
  
EndProcedure
  
; ***************************************************************************************

; // Free the statement handle, disconnect, free the connection handle, And
; // free the environment handle.

Procedure sqldisconn()

  With x
    SQLFreeStmt_(\hstmt,#SQL_DROP);
    SQLDisconnect_(\hdbc);
    SQLFreeConnect_(\hdbc);
    SQLFreeEnv_(\henv);
    \hstmt = 0
    \hdbc  = 0
    \henv  = 0
  EndWith

EndProcedure

; ***************************************************************************************
GT :cry:
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Post by ABBKlaus »

Do you have a snippet that i can play with it ?
User avatar
mk-soft
Always Here
Always Here
Posts: 5405
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Post by mk-soft »

Link to forum http://www.purebasic.fr/german/viewtopi ... e&start=10

PBOSL http://pbosl.purearea.net/

test code

Code: Select all

Define.s temp
Define.s dbName = "information_schema.mysql" ; MySQL Schema
Define.s dsn =  AddSystemDSN(dbName) ; DSN hinzufügen
Debug "DSN: " + dsn
Debug GetSQLInstallerError()

If ExamineTables(dsn, "user", "user")
  Debug "Tabellen in Database:"
  Debug ""
  While NextTable()
    
    temp.s = GetTableName() + "  <--  " + GetTableType()
    Debug temp
  Wend
  Debug "" : Debug ""

Else

EndIf
  
RemoveSystemDSN(dbName)
GT
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Post by ABBKlaus »

it seems to work if i put a UseODBCDatabase() at the top of the lib.
I tested in UserLibUnicodeThreadSafe mode with this snipped :

Code: Select all

;XIncludeFile "ExDatabase.pb"
;ExDatabase_Init()

Define.s temp 
Define.s dbName = "DSN-Connect_MDB.mdb" 
Define.s dsn =  AddDSN(dbName) ; DSN hinzufügen 
Debug "DSN: " + dsn 
Debug GetSQLInstallerError() 

If ExamineTables(dsn)
  Debug "Tabellen in Database:" 
  Debug "" 
  While NextTable() 
    
    temp.s = GetTableName() + "  <--  " + GetTableType() 
    Debug temp 
  Wend 
  Debug "" : Debug "" 

Else 

EndIf 
  
RemoveDSN(dbName) 
User avatar
mk-soft
Always Here
Always Here
Posts: 5405
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Post by mk-soft »

It´s now ok, but i don´t anderstand why i use UseODBCDataBase on the top of the lib.

Thank´s

Michael
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Post by ABBKlaus »

found the problem :

Code: Select all

\rc=SQLConnect_(\hdbc,@\chr_ds_name,#SQL_NTS,user,Len(user),pass,Len(pass));
should be :

Code: Select all

\rc=SQLConnect_(\hdbc,@\chr_ds_name,Len(\chr_ds_name),user,Len(user),pass,Len(pass));
This was the logfile of the compiled lib :

Code: Select all

PureBasic_Compi 33c-f40	ENTER SQLAllocEnv 
		HENV *              00421864

PureBasic_Compi 33c-f40	EXIT  SQLAllocEnv  with return code 0 (SQL_SUCCESS)
		HENV *              0x00421864 ( 0x003a1c18)

PureBasic_Compi 33c-f40	ENTER SQLAllocConnect 
		HENV                003A1C18
		HDBC *              00421868

PureBasic_Compi 33c-f40	EXIT  SQLAllocConnect  with return code 0 (SQL_SUCCESS)
		HENV                003A1C18
		HDBC *              0x00421868 ( 0x003a1cc0)

PureBasic_Compi 33c-f40	ENTER SQLConnectW 
		HDBC                003A1CC0
		WCHAR *             0x003A1DC8 [      -3] "PureBasic_Compilation0_DSN-CONNE\ 1\ 0"
		SWORD                       -3 
		WCHAR *             0x745D4EC8 [      -3] "******\ 0"
		SWORD                       -3 
		WCHAR *             0x745D4EC8 [      -3] "******\ 0"
		SWORD                       -3 

PureBasic_Compi 33c-f40	EXIT  SQLConnectW  with return code -1 (SQL_ERROR)
		HDBC                003A1CC0
		WCHAR *             0x003A1DC8 [      -3] "PureBasic_Compilation0_DSN-CONNE\ 1\ 0"
		SWORD                       -3 
		WCHAR *             0x745D4EC8 [      -3] "******\ 0"
		SWORD                       -3 
		WCHAR *             0x745D4EC8 [      -3] "******\ 0"
		SWORD                       -3 

		DIAG [S1090] [Microsoft][ODBC Driver Manager] Ungültige Zeichenfolgen- oder Pufferlänge (0) 

PureBasic_Compi 33c-f40	ENTER SQLFreeEnv 
		HENV                003A1C18

PureBasic_Compi 33c-f40	EXIT  SQLFreeEnv  with return code -1 (SQL_ERROR)
		HENV                003A1C18

		DIAG [S1010] [Microsoft][ODBC Driver Manager] Fehler in der Funktionsreihenfolge (0) 

PureBasic_Compi 33c-f40	ENTER SQLFreeConnect 
		HDBC                003A1CC0

PureBasic_Compi 33c-f40	EXIT  SQLFreeConnect  with return code 0 (SQL_SUCCESS)
		HDBC                003A1CC0
And the Logfile for the PB-Code:

Code: Select all

PureBasic_Compi 8e4-8dc	ENTER SQLAllocEnv 
		HENV *              00425F6C

PureBasic_Compi 8e4-8dc	EXIT  SQLAllocEnv  with return code 0 (SQL_SUCCESS)
		HENV *              0x00425F6C ( 0x003a1c18)

PureBasic_Compi 8e4-8dc	ENTER SQLAllocConnect 
		HENV                003A1C18
		HDBC *              00425F70

PureBasic_Compi 8e4-8dc	EXIT  SQLAllocConnect  with return code 0 (SQL_SUCCESS)
		HENV                003A1C18
		HDBC *              0x00425F70 ( 0x003a1cc0)

PureBasic_Compi 8e4-8dc	ENTER SQLConnectW 
		HDBC                003A1CC0
		WCHAR *             0x003A1DC8 [      -3] "PureBasic_Compilation0_DSN-CONNE\ 0"
		SWORD                       -3 
		WCHAR *             0x745D4EC8 [      -3] "******\ 0"
		SWORD                       -3 
		WCHAR *             0x745D4EC8 [      -3] "******\ 0"
		SWORD                       -3 

PureBasic_Compi 8e4-8dc	EXIT  SQLConnectW  with return code 0 (SQL_SUCCESS)
		HDBC                003A1CC0
		WCHAR *             0x003A1DC8 [      -3] "PureBasic_Compilation0_DSN-CONNE\ 0"
		SWORD                       -3 
		WCHAR *             0x745D4EC8 [      -3] "******\ 0"
		SWORD                       -3 
		WCHAR *             0x745D4EC8 [      -3] "******\ 0"
		SWORD                       -3 

PureBasic_Compi 8e4-8dc	ENTER SQLAllocStmt 
		HDBC                003A1CC0
		HSTMT *             00425F74

PureBasic_Compi 8e4-8dc	EXIT  SQLAllocStmt  with return code 0 (SQL_SUCCESS)
		HDBC                003A1CC0
		HSTMT *             0x00425F74 ( 0x003a22e8)

PureBasic_Compi 8e4-8dc	ENTER SQLTablesW 
		HSTMT               003A22E8
		WCHAR *             0x00000000 
		SWORD                        0 
		WCHAR *             0x00000000 
		SWORD                        0 
		WCHAR *             0x00000000 
		SWORD                        0 
		WCHAR *             0x00000000 
		SWORD                        0 

PureBasic_Compi 8e4-8dc	EXIT  SQLTablesW  with return code 0 (SQL_SUCCESS)
		HSTMT               003A22E8
		WCHAR *             0x00000000 
		SWORD                        0 
		WCHAR *             0x00000000 
		SWORD                        0 
		WCHAR *             0x00000000 
		SWORD                        0 
		WCHAR *             0x00000000 
		SWORD                        0 

PureBasic_Compi 8e4-8dc	ENTER SQLBindCol 
		HSTMT               003A22E8
		UWORD                        1 
		SWORD                        1 <SQL_C_CHAR>
		PTR                0x00156778
		SQLLEN                   256
		SQLLEN *            0x00156B80

PureBasic_Compi 8e4-8dc	EXIT  SQLBindCol  with return code 0 (SQL_SUCCESS)
		HSTMT               003A22E8
		UWORD                        1 
		SWORD                        1 <SQL_C_CHAR>
		PTR                0x00156778
		SQLLEN                   256
		SQLLEN *            0x00156B80 (1406824)

PureBasic_Compi 8e4-8dc	ENTER SQLBindCol 
		HSTMT               003A22E8
		UWORD                        2 
		SWORD                        1 <SQL_C_CHAR>
		PTR                0x00156878
		SQLLEN                   256
		SQLLEN *            0x00156B84

PureBasic_Compi 8e4-8dc	EXIT  SQLBindCol  with return code 0 (SQL_SUCCESS)
		HSTMT               003A22E8
		UWORD                        2 
		SWORD                        1 <SQL_C_CHAR>
		PTR                0x00156878
		SQLLEN                   256
		SQLLEN *            0x00156B84 (1376632)

PureBasic_Compi 8e4-8dc	ENTER SQLBindCol 
		HSTMT               003A22E8
		UWORD                        3 
		SWORD                        1 <SQL_C_CHAR>
		PTR                0x00156978
		SQLLEN                   256
		SQLLEN *            0x00156B88

PureBasic_Compi 8e4-8dc	EXIT  SQLBindCol  with return code 0 (SQL_SUCCESS)
		HSTMT               003A22E8
		UWORD                        3 
		SWORD                        1 <SQL_C_CHAR>
		PTR                0x00156978
		SQLLEN                   256
		SQLLEN *            0x00156B88 (0)

PureBasic_Compi 8e4-8dc	ENTER SQLBindCol 
		HSTMT               003A22E8
		UWORD                        4 
		SWORD                        1 <SQL_C_CHAR>
		PTR                0x00156A78
		SQLLEN                   256
		SQLLEN *            0x00156B8C

PureBasic_Compi 8e4-8dc	EXIT  SQLBindCol  with return code 0 (SQL_SUCCESS)
		HSTMT               003A22E8
		UWORD                        4 
		SWORD                        1 <SQL_C_CHAR>
		PTR                0x00156A78
		SQLLEN                   256
		SQLLEN *            0x00156B8C (0)

PureBasic_Compi 8e4-8dc	ENTER SQLFetch 
		HSTMT               003A22E8

PureBasic_Compi 8e4-8dc	EXIT  SQLFetch  with return code 0 (SQL_SUCCESS)
		HSTMT               003A22E8

PureBasic_Compi 8e4-8dc	ENTER SQLFetch 
		HSTMT               003A22E8

PureBasic_Compi 8e4-8dc	EXIT  SQLFetch  with return code 0 (SQL_SUCCESS)
		HSTMT               003A22E8

PureBasic_Compi 8e4-8dc	ENTER SQLFetch 
		HSTMT               003A22E8

PureBasic_Compi 8e4-8dc	EXIT  SQLFetch  with return code 0 (SQL_SUCCESS)
		HSTMT               003A22E8

PureBasic_Compi 8e4-8dc	ENTER SQLFetch 
		HSTMT               003A22E8

PureBasic_Compi 8e4-8dc	EXIT  SQLFetch  with return code 0 (SQL_SUCCESS)
		HSTMT               003A22E8

PureBasic_Compi 8e4-8dc	ENTER SQLFetch 
		HSTMT               003A22E8

PureBasic_Compi 8e4-8dc	EXIT  SQLFetch  with return code 0 (SQL_SUCCESS)
		HSTMT               003A22E8

PureBasic_Compi 8e4-8dc	ENTER SQLFetch 
		HSTMT               003A22E8

PureBasic_Compi 8e4-8dc	EXIT  SQLFetch  with return code 0 (SQL_SUCCESS)
		HSTMT               003A22E8

PureBasic_Compi 8e4-8dc	ENTER SQLFetch 
		HSTMT               003A22E8

PureBasic_Compi 8e4-8dc	EXIT  SQLFetch  with return code 0 (SQL_SUCCESS)
		HSTMT               003A22E8

PureBasic_Compi 8e4-8dc	ENTER SQLFetch 
		HSTMT               003A22E8

PureBasic_Compi 8e4-8dc	EXIT  SQLFetch  with return code 0 (SQL_SUCCESS)
		HSTMT               003A22E8

PureBasic_Compi 8e4-8dc	ENTER SQLFetch 
		HSTMT               003A22E8

PureBasic_Compi 8e4-8dc	EXIT  SQLFetch  with return code 100 (SQL_NO_DATA_FOUND)
		HSTMT               003A22E8

PureBasic_Compi 8e4-8dc	ENTER SQLFreeStmt 
		HSTMT               003A22E8
		UWORD                        1 <SQL_DROP>

PureBasic_Compi 8e4-8dc	EXIT  SQLFreeStmt  with return code 0 (SQL_SUCCESS)
		HSTMT               003A22E8
		UWORD                        1 <SQL_DROP>

PureBasic_Compi 8e4-8dc	ENTER SQLDisconnect 
		HDBC                003A1CC0

PureBasic_Compi 8e4-8dc	EXIT  SQLDisconnect  with return code 0 (SQL_SUCCESS)
		HDBC                003A1CC0

PureBasic_Compi 8e4-8dc	ENTER SQLFreeConnect 
		HDBC                003A1CC0

PureBasic_Compi 8e4-8dc	EXIT  SQLFreeConnect  with return code 0 (SQL_SUCCESS)
		HDBC                003A1CC0

PureBasic_Compi 8e4-8dc	ENTER SQLFreeEnv 
		HENV                003A1C18

PureBasic_Compi 8e4-8dc	EXIT  SQLFreeEnv  with return code 0 (SQL_SUCCESS)
		HENV                003A1C18
User avatar
mk-soft
Always Here
Always Here
Posts: 5405
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Post by mk-soft »

Thanks,

Now LIB is running without UseODBCDatabase. New Version v1.11 is available
http://home.arcor.de/m_kastner/MyDownlo ... taBase.zip

How to find the logflies?

GT :wink:
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Post by ABBKlaus »

mk-soft wrote:How to find the logflies?
open control panel -> Administrative-tools -> Datasources (ODBC) -> Tracing

or you can launch it through this : %SystemRoot%\system32\odbcad32.exe

Image
User avatar
mk-soft
Always Here
Always Here
Posts: 5405
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Post by mk-soft »

Thanks :D
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply