Page 1 of 1

What happened to SQLConfigDataSource_ ?

Posted: Thu Jun 15, 2017 9:20 pm
by Karbon
I'm using 5.44LTS, and cannot use Unicode (for a variety of reasons). 5.1 and 5.2 compiled and used this code just fine but 5.44LTS does not. I've seen several other threads about this but the solution was "use Unicode" -- but I can't in this case.. I'm not entirely sure where the unicode tie-in is, either.. The few other examples I've seen claim to work but do not for me (the ExDatabase update for example)..

Can someone help me get these functions working in 5.44? I'm not the original author of the code below but it served me very well for many years!

Code: Select all

Procedure AddODBCConnection(Driver$,Attributes$)
  While Right(Attributes$,2)<>";;"
    Attributes$+";"
  Wend
  
  ;*LPAttribMem=AllocateMemory((Len(Attributes$)+1)*SizeOf(CHARACTER))
  
  *LPAttribMem=AllocateMemory(Len(Attributes$)*SizeOf(CHARACTER)+SizeOf(CHARACTER))
  
  PokeS(*LPAttribMem,Attributes$,Len(Attributes$))
   
  For l=1 To Len(Attributes$)
    CompilerIf #PB_Compiler_Unicode
      If PeekW(*LPAttribMem + (l-1) * SizeOf(CHARACTER))=Asc(";")
      PokeW(*LPAttribMem + (l-1) * SizeOf(CHARACTER),0)
    EndIf
    CompilerElse
    If PeekB(*LPAttribMem + l -1)=Asc(";")
      PokeB(*LPAttribMem + l -1,0)
    EndIf
    CompilerEndIf
  Next
  
  
  
  result=SQLConfigDataSource_(0,#ODBC_ADD_DSN,Driver$,*LPAttribMem)
  
  FreeMemory(*LPAttribMem)
  
  ProcedureReturn result
  
EndProcedure

Procedure RemoveODBCConnection(Driver$,DSN$)
  DSN$="DSN="+DSN$
  
  While Right(DSN$,2)<>";;"
    DSN$+";"
  Wend
  
  *LPAttribMem=AllocateMemory((Len(DSN$)+1)*SizeOf(CHARACTER))
  
  PokeS(*LPAttribMem,DSN$,Len(DSN$))
  
  For l=1 To Len(DSN$)
    CompilerIf #PB_Compiler_Unicode
    If PeekW(*LPAttribMem + (l-1) * SizeOf(CHARACTER))=Asc(";")
      PokeW(*LPAttribMem + (l-1) * SizeOf(CHARACTER),0)
    EndIf
    CompilerElse
      If PeekB(*LPAttribMem + l -1)=Asc(";")
      PokeB(*LPAttribMem + l -1,0)
    EndIf
    CompilerEndIf
  Next
  
  result=SQLConfigDataSource_(0,#ODBC_REMOVE_DSN,@Driver$,*LPAttribMem)
  
  FreeMemory(*LPAttribMem)
  
  ProcedureReturn result
EndProcedure

Re: What happened to SQLConfigDataSource_ ?

Posted: Thu Jun 15, 2017 11:21 pm
by Fig
#ODBC_ADD_DSN equals 4
#ODBC_REMOVE_DSN equals 3
FYI...

Re: What happened to SQLConfigDataSource_ ?

Posted: Fri Jun 16, 2017 12:28 am
by Karbon
Fig wrote:#ODBC_ADD_DSN equals 4
#ODBC_REMOVE_DSN equals 3
FYI...
ODBC_ADD_DSN should be 1, ODBC_ADD_SYS_DSN should be 4, or at least that's how it's been working for about 14 years in this code.. Likewise REMOVE_DSN is 3, REMOVE_SYS_DSN is 6..

Re: What happened to SQLConfigDataSource_ ?

Posted: Fri Jun 16, 2017 1:12 am
by Fig
On Pb 5.44 Rts, the solely error raised up was about the constants. You solve it by replacing them by their values (Word type).
About the rest of the code, I don't see anything suspicious: it should work if it does before...
The calls looks fine.

Re: What happened to SQLConfigDataSource_ ?

Posted: Fri Jun 16, 2017 1:14 am
by Karbon
Interesting, I get no compilation errors at all but did substitute the values for the constants just to test. Unfortunately no change (SQLConfigDataSource_() just returns zero).

Re: What happened to SQLConfigDataSource_ ?

Posted: Fri Jun 16, 2017 1:24 am
by Karbon
FWIW, this has *something* to do with Unicode, but I'm not seeing it.

Free beer to the first person to spot it!

Re: What happened to SQLConfigDataSource_ ?

Posted: Fri Jun 16, 2017 1:21 pm
by freak
You can try to get some information about why the command fails with the following code. Maybe this points you in the right direction.

Code: Select all

  If result = #False
    ErrorMessage$ = Space(255)
    ErrorCode.l = 0
    SQLInstallerError_(1, @ErrorCode, @ErrorMessage$, 255, #Null)
    Debug ErrorMessage$
  EndIf

Re: What happened to SQLConfigDataSource_ ?

Posted: Fri Jun 16, 2017 2:51 pm
by Karbon
Thanks freak! I should have mentioned that I tried calling SQLInstallerError_() already.. It returns "C" -- yep, just the letter C.