PureBasic Forum
https://www.purebasic.fr/english/

[Done] Problem with SQLConnect_() in PB5.61 (5.60 is fine)
https://www.purebasic.fr/english/viewtopic.php?f=4&t=69924
Page 1 of 1

Author:  mikejs [ Wed Jan 10, 2018 3:07 pm ]
Post subject:  [Done] Problem with SQLConnect_() in PB5.61 (5.60 is fine)

Just run into an issue with some existing code where the Windows API call SQLConnect_() fails to connect to the database for code compiled with 5.61 x64.

Reverting to 5.60, and everything is fine, compiler options unchanged. Install 5.61 again, and the problem is back.

The code is this kind of thing:

Code:
retCode.w = SQLConnect_(*thisDBC\hDbc, @dbName$, Len(dbName$), @dbUser$, Len(dbUser$), @dbPass$, Len(dbPass$))


(It's derived from the code here: viewtopic.php?f=5&t=43322 )

When it works, you get a sensible return code and can proceed as normal. When it fails, you get #SQL_ERROR (-1) as the return code, but nothing else particularly useful. GetLastError_() usually returns "The operation completed successfully."

As the problem can be consistently reproduced or fixed by going back and forth between 5.60 and 5.61, and 5.61 is only supposed to be a bug fix release, I don't think there's anything amiss with the code.

Any known issues with 5.61 or things that might cause this kind of change in behaviour?

Author:  mk-soft [ Thu Jan 11, 2018 11:12 am ]
Post subject:  Re: Problem with SQLConnect_() in PB5.61 (5.60 is fine)

Show this bug report...

viewtopic.php?f=4&t=69462#p514276

Author:  mikejs [ Thu Jan 11, 2018 11:29 am ]
Post subject:  Re: Problem with SQLConnect_() in PB5.61 (5.60 is fine)

mk-soft wrote:
Show this bug report...

viewtopic.php?f=4&t=69462#p514276

Yes, that looks like the same kind of thing.

So "Fixed" means will be working again in 5.62? I've gone back to 5.60 for the time being.

Author:  mikejs [ Tue Feb 06, 2018 11:14 am ]
Post subject:  Re: Problem with SQLConnect_() in PB5.61 & 5.62 (5.60 is fin

Looks like this is not resolved in 5.62.

Going back to 5.60 again...

Author:  mk-soft [ Sun Feb 11, 2018 3:34 pm ]
Post subject:  Re: Problem with SQLConnect_() in PB5.61 (5.60 is fine)

Confirm bug v5.62

ASM Output
Code:
extrn SQLAllocConnect
extrn SQLAllocEnv
extrn SQLAllocStmt
extrn SQLBindCol
extrn SQLConfigDataSourceW
extrn SQLConnect <- Bug
extrn SQLDisconnect
extrn SQLFetch
extrn SQLFreeConnect
extrn SQLFreeEnv
extrn SQLFreeStmt
extrn SQLInstallerErrorW
extrn SQLTables <- Bug


Workaround
Code:
; -----------------------------------------------------------------------------
; Bugfix ASCII, Unicode PB v5.4x and PB v5.6x
; By mk-soft version v1.02

Import "odbccp32.lib"
  CompilerIf #PB_Compiler_Unicode
    CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
      SQLInstallerError(iError, *pfErrorCode, *ErrorMSGBuf, cbErrorMsgMax, *ErrorMSGLen) As "_SQLInstallerErrorW@20"
      SQLConfigDataSource(Handle, Type, strDriver.s, *strAttribtues) As "_SQLConfigDataSourceW@16"
    CompilerElse
      SQLInstallerError(iError, *pfErrorCode, *ErrorMSGBuf, cbErrorMsgMax, *ErrorMSGLen) As "SQLInstallerErrorW"
      SQLConfigDataSource(Handle, Type, strDriver.s, *strAttribtues) As "SQLConfigDataSourceW"
    CompilerEndIf
  CompilerElse
    SQLInstallerError(iError, *pfErrorCode, *ErrorMSGBuf, cbErrorMsgMax, *ErrorMSGLen)
    SQLConfigDataSource(Handle, Type, strDriver.s, *strAttribtues)
  CompilerEndIf
EndImport

Import "odbc32.lib"
  CompilerIf #PB_Compiler_Unicode
    CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
      SQLConnect(ConnectionHandle, ServerName.s, NameLength1, UserName.s, NameLength2, Authentication.s, NameLength3) As "_SQLConnectW@28"
      SQLTables(StatementHandle, *CatalogName, NameLength1, *SchemaName, NameLength2, *TableName, NameLength3, *TableType, NameLength4) As "_SQLTablesW@36"
    CompilerElse
      SQLConnect(ConnectionHandle, ServerName.s, NameLength1, UserName.s, NameLength2, Authentication.s, NameLength3) As "SQLConnectW"
      SQLTables(StatementHandle, *CatalogName, NameLength1, *SchemaName, NameLength2, *TableName, NameLength3, *TableType, NameLength4) As "SQLTablesW"
    CompilerEndIf
  CompilerElse
    SQLConnect(ConnectionHandle, ServerName.s, NameLength1, UserName.s, NameLength2, Authentication.s, NameLength3)
    SQLTables(StatementHandle, *CatalogName, NameLength1, *SchemaName, NameLength2, *TableName, NameLength3, *TableType, NameLength4)
  CompilerEndIf 
EndImport
; -----------------------------------------------------------------------------

Author:  mikejs [ Tue Nov 27, 2018 12:06 pm ]
Post subject:  Re: Problem with SQLConnect_() in PB5.61+ (5.60 is fine)

Looks like this is still not resolved in the latest 5.70 Beta (3).

Code compiled with 5.60 contains a reference to SQLConnectW. In later versions, including 5.70 Beta 3, it's just SQLConnect.

Author:  Fred [ Mon Dec 10, 2018 8:23 pm ]
Post subject:  Re: Problem with SQLConnect_() in PB5.61 (5.60 is fine)

Fixed.

Author:  mikejs [ Mon Dec 17, 2018 1:15 pm ]
Post subject:  Re: [Done] Problem with SQLConnect_() in PB5.61 (5.60 is fin

Just tried it with 5.70 Beta 4, and it's still coming out wrong there (SQLConnect appears in the resulting binary - should be SQLConnectW).

Was this fix included in Beta 4?

Author:  Fred [ Mon Dec 17, 2018 2:35 pm ]
Post subject:  Re: [Done] Problem with SQLConnect_() in PB5.61 (5.60 is fin

I will check but I guess it should be in beta 4.

Author:  mikejs [ Fri Jan 04, 2019 11:28 am ]
Post subject:  Re: Problem with SQLConnect_() in PB5.61 (5.60 is fine)

Sorry - this is still not right in the 5.70 release version. The compiled code contains a reference to SQLConnect (no W on the end), and fails to connect to the DB. With 5.60, the reference is SQLConnectW and it works fine.

(Edit: Now using mk-soft's workaround above, which seems to work fine - up to now I'd stuck with 5.60, but there are other things in 5.70 that are useful...)

Author:  Fred [ Wed Apr 10, 2019 8:08 pm ]
Post subject:  Re: Problem with SQLConnect_() in PB5.61 (5.60 is fine)

Fixed.

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/