O ile mi wiadomo, jedynym sposobem pobrania dodatkowych znaków Unicode (np. emoji) za pomocą ADODB i MySQL Connector/ODBC jest pobranie ich jako bajtów — SELECT CAST(column_name AS BINARY)
— a potem je rozszyfrować. Poniższy przykład to w rzeczywistości VBA, ale dostosowanie go do VBScript jest trywialne.
Option Explicit
Sub demo_retrieve_utf8mb4_value()
Dim conn As New ADODB.Connection
conn.Open _
"DRIVER=MySQL ODBC 8.0 Unicode Driver;" & _
"SERVER=localhost;PORT=3307;" & _
"UID=root;PWD=(whatever);" & _
"DATABASE=mydb;" & _
"charset=utf8mb4;"
Dim rst As New ADODB.Recordset
rst.Open "SELECT CAST(emoji AS BINARY) FROM emoji_tbl WHERE id=1", conn
Dim s As Variant
s = decode_utf8(rst.Fields(0).Value)
'
' do stuff with the string value
End Sub
Private Function decode_utf8(field_value As Variant) As Variant
If IsNull(field_value) Then
decode_utf8 = Null
Else
Dim strm As New ADODB.Stream
With strm
.Type = adTypeBinary
.Open
.Write field_value
.Flush
.Position = 0
.Type = adTypeText
.Charset = "UTF-8"
decode_utf8 = .ReadText
.Close
End With
Set strm = Nothing
End If
End Function