When calling SQLGetData to read a variable length TEXT utf8mb4 field as SQL_C_WCHAR, if the text contains utf-8 4 bytes character (UTF-16 surrogate pair) and it falls at the end of the buffer so only one half can fit, the successive calls to the function return the same content, making an indefinite loop.
For example, if the field contains Unicode codes 'a', 0xD83D, 0xDE18, and 'd', and the buffer is 6 bytes (3 wchar_t's), the function puts 'a' and high surrogate 0xD83D and 0 into the buffer, returns SQL_SUCCESS_WITH_INFO with SQL state , but the successive calls do not advance but keep returning the same results.
The significant lines of code are as follows:
NOTE: While typing this description, this web site reported an exception when the above sample text contained real character, like 'a<smiley>d'. No need to mention that I had to retype the whole text from scratch. Obviously, all MySQL flavours are simple plagued with bugs when it comes to handling 4-byte utf8 characters! That is the reason why I cannot provide here the exact sample string. Here it is in UTF-8 bytes: 61 F0 9F 98 98 64.