Hasta donde yo sé, la única forma de recuperar caracteres suplementarios de Unicode (por ejemplo, emoji) con ADODB y MySQL Connector/ODBC es recuperarlos como bytes:SELECT CAST(column_name AS BINARY)
- y luego decodificarlos. El siguiente ejemplo es en realidad VBA, pero modificarlo para VBScript es trivial.
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