UseODBCDatabase Unicode Bug

Post bugreports for the Mac OSX version here
User avatar
mk-soft
Addict
Addict
Posts: 2975
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

UseODBCDatabase Unicode Bug

Post by mk-soft »

The database thing hasn't worked for a long time.
But have now found the error...

On MacOS the type for string is probably size of wchar_t = 4

Thus no database functions function with Unicode.

Code: Select all

;-TOP

UseODBCDatabase()

; -----------------------------------------------------------------------------

Import ""
  PB_OpenDatabase(Database, *db, *User, *Pass, Flags) As "_PB_OpenDatabase2"
  PB_DatabaseUpdate(Database, *Query) As "_PB_DatabaseUpdate"
EndImport

; -----------------------------------------------------------------------------

Structure ArrayOfByte
  b.b[0]
EndStructure

Structure ArrayOfLong
  l.l[0]
EndStructure

Procedure text_to_utf32(String.s) 
  Protected *text.ArrayOfByte = UTF8(String)
  num_chars = MemorySize(*text);
  *c.ArrayOfLong = AllocateMemory(SizeOf(long) * num_chars);
  i = 0                                                    ;
  
  For n = 0 To num_chars - 1
    If ((*text\b[i] & %10000000) = 0) ;{
                                       ;// 1 byte code point, ASCII
      *c\l[n] = (*text\b[i] & %01111111) ;
      i + 1                            ;
                                       ;}
    ElseIf ((*text\b[i] & %11100000) = %11000000) ;{
                                                   ;// 2 byte code point
      *c\l[n] = (*text\b[i] & %00011111) << 6 | (*text\b[i + 1] & %00111111);
      i + 2                                                               ;
                                                                          ;}
    ElseIf ((*text\b[i] & %11110000) = %11100000)                        ;{
                                                                          ;// 3 byte code point
      *c\l[n] = (*text\b[i] & %00001111) << 12 | (*text\b[i + 1] & %00111111) << 6 | (*text\b[i + 2] & %00111111);
      i + 3                                                                                                    ;
                                                                                                               ;}
    Else                                                                                                       ;{
                                                                                                               ;// 4 byte code point
      *c\l[n] = (*text\b[i] & %00000111) << 18 | (*text\b[i + 1] & %00111111) << 12 | (*text\b[i + 2] & %00111111) << 6 | (*text\b[i + 3] & %00111111);
      i + 4                                                                                                                                         ;
    EndIf                                                                                                                                           ;}
  Next                                                                                                                                              ;}
  
  FreeMemory(*text)
  
  ProcedureReturn *c;
  
EndProcedure

; -----------------------------------------------------------------------------

Procedure MyOpenDatabase(ID, Database.s, User.s, Pass.s , Flags = #PB_Database_ODBC)
  Protected result
  Protected *dbname, *uid, *pwd
  
  *dbname = text_to_utf32(Database)
  *uid = text_to_utf32(User)
  *pwd = text_to_utf32(Pass)
  
  result = PB_OpenDatabase(ID, *dbname, *uid, *pwd, Flags)
  ;result = OpenDatabase(ID, dbname, uid, pwd, Flags)
  
  FreeMemory(*dbname)
  FreeMemory(*uid)
  FreeMemory(*pwd)
  
  ProcedureReturn result
EndProcedure

Global.s database, user, pass

database = "myodbc-v53-x64-unicode"
;database = "myodbc-v53-x64-ansi"
user = "developer"
pass = "purebasic"

If MyOpenDatabase(0, database, user, pass)
  Debug "Open database ok !"
  CloseDatabase(0)
Else
  Debug "Can't open database !"
EndIf
With Unicode
[000000.000559]
PureBasic.1 10F6A65C0 ENTER SQLConnectW
SQLHDBC 0x10041e9c0
SQLWCHAR * 0x10041daa0
SQLSMALLINT -3 (SQL_NTS)
SQLWCHAR * 0x10041dae0
SQLSMALLINT -3 (SQL_NTS)
SQLWCHAR * 0x7fff5dde7e50
| **** |
SQLSMALLINT -3 (SQL_NTS)

[000000.001087]
PureBasic.1 10F6A65C0 EXIT SQLConnectW with return code -1 (SQL_ERROR)
SQLHDBC 0x10041e9c0
SQLWCHAR * 0x10041daa0
SQLSMALLINT -3 (SQL_NTS)
SQLWCHAR * 0x10041dae0
SQLSMALLINT -3 (SQL_NTS)
SQLWCHAR * 0x7fff5dde7e50
SQLSMALLINT -3 (SQL_NTS)
With UTF32
[000000.000529]
PureBasic.1 10F1B75C0 ENTER SQLConnectW
SQLHDBC 0x100247530
SQLWCHAR * 0x100229518
| myodbc-v53-x64-unicode |
SQLSMALLINT -3 (SQL_NTS)
SQLWCHAR * 0x100245178
| developer |
SQLSMALLINT -3 (SQL_NTS)
SQLWCHAR * 0x7fff5dde7e50
| **** |
SQLSMALLINT -3 (SQL_NTS)

[000000.038242]
PureBasic.1 10F1B75C0 EXIT SQLConnectW with return code 0 (SQL_SUCCESS)
SQLHDBC 0x100247530
SQLWCHAR * 0x100229518
SQLSMALLINT -3 (SQL_NTS)
SQLWCHAR * 0x100245178
SQLSMALLINT -3 (SQL_NTS)
SQLWCHAR * 0x7fff5dde7e50
SQLSMALLINT -3 (SQL_NTS)
Please repair database function :(
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace
User avatar
mk-soft
Addict
Addict
Posts: 2975
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: UseODBCDatabase Unicode Bug

Post by mk-soft »

Remember :wink:

Perhaps change to unixODBC or as Options
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace
Mindphazer
Enthusiast
Enthusiast
Posts: 167
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: UseODBCDatabase Unicode Bug

Post by Mindphazer »

I'd love to see this bug fixed...
I'm stuck on PB 5.46, the last version that has a "Create unicode executable" option that can be unchecked....
MacBook Pro M1 13" Retina - 8 Gb - OSX 11.2 - Iphone 12 - iPad at home
...and unfortunately... Windows at work...
User avatar
mk-soft
Addict
Addict
Posts: 2975
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: UseODBCDatabase Unicode Bug

Post by mk-soft »

Workaround over own myodbca.dylib... (ASCII to Unicode)

Link: https://www.purebasic.fr/german/viewtop ... 73#p350773

or over my webspace -> mycodes -> pb5 -> odbc
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace
Mindphazer
Enthusiast
Enthusiast
Posts: 167
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: UseODBCDatabase Unicode Bug

Post by Mindphazer »

Thanks !
I will take a look
MacBook Pro M1 13" Retina - 8 Gb - OSX 11.2 - Iphone 12 - iPad at home
...and unfortunately... Windows at work...
Mindphazer
Enthusiast
Enthusiast
Posts: 167
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: UseODBCDatabase Unicode Bug

Post by Mindphazer »

Hello mk-soft
I have tested your workaround, it works fine, so i will use it until Fred repairs the problem !!

Thanks a lot !

Best regards
MacBook Pro M1 13" Retina - 8 Gb - OSX 11.2 - Iphone 12 - iPad at home
...and unfortunately... Windows at work...
Mindphazer
Enthusiast
Enthusiast
Posts: 167
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: UseODBCDatabase Unicode Bug

Post by Mindphazer »

Hello mk-soft
I have a strange behaviour with your workaround :
Executed from the IDE, it works well
But, once compiled as a stand alone application, this one crashes

I'm on Mac OS Big Sur, and on a MacBookPro M1, not sure if that's the reason why !
MacBook Pro M1 13" Retina - 8 Gb - OSX 11.2 - Iphone 12 - iPad at home
...and unfortunately... Windows at work...
User avatar
mk-soft
Addict
Addict
Posts: 2975
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: UseODBCDatabase Unicode Bug

Post by mk-soft »

Mindphazer wrote: Fri Apr 30, 2021 3:36 pm Hello mk-soft
I have a strange behaviour with your workaround :
Executed from the IDE, it works well
But, once compiled as a stand alone application, this one crashes

I'm on Mac OS Big Sur, and on a MacBookPro M1, not sure if that's the reason why !
I don't think it's the M1 processor, as the program runs with debugger.

Either it is a "DEBUG" before a function,
or it doesn't find the DyLib and doesn't query the success of loading the lib.

I put the DyLib into the app with my tool MyAppData.

Link: PB-IDE Tool MyAppData

HW: Mac Mini 2018 (Intel I7)
OS: Big Sur v11.1
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace
Mindphazer
Enthusiast
Enthusiast
Posts: 167
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: UseODBCDatabase Unicode Bug

Post by Mindphazer »

That's it. I put the dylib inside my app, and it works
I should have thought about that, sorry !!

Thanks a lot
MacBook Pro M1 13" Retina - 8 Gb - OSX 11.2 - Iphone 12 - iPad at home
...and unfortunately... Windows at work...
Post Reply