mysql1_dart
mysql1_dart copied to clipboard
Utf8 decoding error.
No clue what to do... lib seems very unreliable. I'm running a
INSERT IGNORE INTO product () VALUES ()
for 8000 records... it fails using connection::query(), works fine in queryMulti(), so i thought it would be the length of the query string... my sweet spot was 315 records at a time in a single query... max query length at 39100 characters. Otherwise, same exception.
After truncate the product table, i was able to run the query() with the 8k products without errors... I just don't understand how the buffer.readString() gets corrupted on particular cases. This is the exception:
[SEVERE] FormatException: Bad UTF-8 encoding 0xb8 (at offset 0) #0 _Utf8Decoder.convert (dart:convert/utf.dart:530:13)
#1 Utf8Decoder.convert (dart:convert/utf.dart:327:13)
#2 Utf8Codec.decode (dart:convert/utf.dart:59:56)
#3 Buffer.readString (package:mysql1/src/buffer.dart:178:21)
#4 Buffer.readStringToEnd (package:mysql1/src/buffer.dart:172:31)
#5 new OkPacket (package:mysql1/src/handlers/ok_packet.dart:21:23)
#6 Handler.checkResponse (package:mysql1/src/handlers/handler.dart:80:28)
#7 QueryStreamHandler.processResponse (package:mysql1/src/query/query_stream_handler.dart:49:18)
#8 ReqRespConnection._handleData (package:mysql1/src/single_connection.dart:329:31)###
Right after posting the issue... I saw that utf8.decode() has a malformed param. Seems to fix the error:
// buffer.dart (line 178)
String s = utf8.decode(_list.sublist(_readPos, _readPos + length),allowMalformed: true);
Please, keep updating the package... is currently the only solution available for Dart.
The docs don't mention the encoding of this field so it is possible that we should not be trying to decode utf at all.
https://dev.mysql.com/doc/internals/en/describing-packets.html#type-string.EOF
This field is only used for display so I think your fix is fine. Please submit a PR.