Passing Autumn

The same 3 years, and some people from students to as the MVP, and I was in place, then the code to show off the autumn wind, a little sad, a little cool!

公告信息
Content is very powerful ~ ~ ~ ~ ~ ~ Do not look outside the invasion not as sharp and brother, I felt kind of sense of loss ~ ~ ~

MySql Blob图片类型存储Bug解决:索引超出了数组界限错误

有网友提取以下问题:


CYQ.Data框架测试:mysql数据库测试(保存blob类型的数据会出问题) ,

针对mysql数据库做测试:发现更新blog字段,总是保存System.Byte[]

经本地测试,发现对 DbType.Binary 类型的参数赋size值时,抛出异常:索引超出了数组界限

其实是无意发现的,调试时不小心拉过了赋值突然才发现。

看一段小代码:

 DbParameter para = _fac.CreateParameter();
            para.ParameterName = parameterName;
            para.Value = value == null ? DBNull.Value : value;
            para.DbType = dbType;

            if (dbType != DbType.Binary && size > -1)//mysql不能设定长度,否则会报索引超出了数组界限错误。
            {
                switch (dbType)
                {
                    case DbType.AnsiString:
                    case DbType.AnsiStringFixedLength:
                    case DbType.StringFixedLength:
                        para.Size = size;
                        break;
                    default:
                        para.Size = size / 2;// 
                        break;
                }
            }
            para.Direction = direction;

在对多数据库支持时,我们产生了一个参数,然后赋参数名,参数值,参数类型,参数大小和参数指向。

而Mysql竟然在对Size赋值的问题处理上有些Bug。

经过测试,其实数据库类型对Size的赋值是正常的,唯Mysql有问题,只能说Mysql的Dll在处理的时候有点不小心。

Autumn Park is QBlog the official site, created by the passing autumn, based on the framework data layers developed cyqdata support multi-user, multi-language, multi-database (access, mssql, oracle), directory level url and other powerful blog system
新浪微博粉丝精灵,刷粉丝、刷评论、刷转发、企业商家微博营销必备工具"

2013/2/27 15:08:41 | Other | |

  • 发表评论