MySqlDataReader GetBytes 缓冲区问题...
我发现 MySqlDataReader.GetBytes 实现有一个奇怪的怪癖,只是想知道这是否众所周知,因为我似乎在网上找不到任何有关它的文章。
除非我做错了什么?
D .
I've found a curious quirk of the MySqlDataReader.GetBytes implementation and just wondering if this is well known as I can't seem to find any articles about it on the net.
If you follow the code example for the SqlDataReader and apply it to the MySqlDataReader it wont work...unless the number of bytes in the record you are retreiving is exactly divisible by the buffer. So for example if you are on the last iteration of the loop and there is only 100 bytes left but it's trying to read another 1024 bytes then the MySqlDataReader will fail and throw an exception. The SqlDataReader will not.
Unless I'm doing something wrong?
D.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要读取整个缓冲区大小,而只要求至多缓冲区大小,但也最多请求您认为剩下的内容。老实说,您还不如创建一个大小完全正确的缓冲区,而不是固定大小的缓冲区。
但如果你想要一个更小的缓冲区(例如,如果你一次处理一个缓冲区),你可以使用:
Rather than reading the whole buffer size, only ask for at most the buffer size, but also at most what you believe is left. To be honest, you might as well create a buffer of exactly the right size rather than a fixed size one anyway.
But if you wanted a smaller buffer (e.g. if you were processing it a buffer at a time) you could use: