达梦DOTNET驱动DM.Provider8.3.1.30495存在空字符串插入变DBNull的问题
达梦数据库的DOTNET驱动DM.Provider,这个版本8.3.1.30495有bug,会把空字符串改成DBNull处理,反编译代码发现Dm.DmSetValue.SetString方法中判断字符串长度==0就设置成DBNull。
解决办法就是 降低版本到8.3.1.28188。
// Dm.DmSetValue
using System;
using System.Globalization;
using Dm.util;
private void SetString(DmParamValue paraVal, string x, int cType, int prec, int scale, byte typeFlag, DmParameterInternal paraInternal)
{
byte[] array = null;
if (x == null || x.Trim().Length <= 0) //注意这里的 x.Trim().Length <= 0 就是它导致的,8.3.1.28188版本没有这个条件
{
SetNull(paraVal);
return;
}
if (typeFlag != 1)
{
array = DmConvertion.GetBytes(x, m_ServerEncoding);
paraVal.SetInValue(array);
paraVal.SetSqlType(2);
paraVal.SetPrec(8188);
paraVal.SetScale(6);
paraInternal.maxValueLen = Math.Max(array.Length, paraInternal.maxValueLen);
return;
}
switch (cType)
{
case 0:
case 1:
case 2:
{
paraVal.m_InValue = DmConvertion.GetBytes(x, m_ServerEncoding);
int num = paraVal.m_InValue.Length;
if (num > 32767)
{
DmError.ThrowDmException(DmErrorDefinition.ECNET_STR_CUT);
}
paraVal.SetInValue();
paraInternal.maxValueLen = Math.Max(num, paraInternal.maxValueLen);
break;
}
case 19:
{
paraVal.m_InValue = DmConvertion.GetBytes(x, m_ServerEncoding);
int num = paraVal.m_InValue.Length;
if (prec < num && prec != 0)
{
DmError.ThrowDmException(DmErrorDefinition.ECNET_STR_CUT);
}
paraVal.SetInValue();
break;
}
case 3:
{
byte b = 0;
string text = x.Trim().ToUpper();
if (text.ToUpper().Equals("FALSE") || text.Equals("0"))
{
b = 0;
}
else if (text.ToUpper().Equals("TRUE") || text.Equals("1"))
{
b = 1;
}
else
{
DmError.ThrowDmException(DmErrorDefinition.ECNET_DATA_CONVERTION_ERROR);
}
SetByte(paraVal, (sbyte)b, cType, prec, scale, typeFlag, paraInternal);
break;
}
case 5:
if (x.Trim().Length > 0)
{
SetByte(paraVal, sbyte.Parse(x, DmConst.invariantCulture), cType, prec, scale, typeFlag, paraInternal);
}
else
{
SetNull(paraVal);
}
break;
case 6:
if (x.Trim().Length > 0)
{
SetShort(paraVal, short.Parse(x, DmConst.invariantCulture), cType, prec, scale, typeFlag, paraInternal);
}
else
{
SetNull(paraVal);
}
break;
case 7:
if (x.Trim().Length > 0)
{
SetInt(paraVal, int.Parse(x, DmConst.invariantCulture), cType, prec, scale, typeFlag, paraInternal);
}
else
{
SetNull(paraVal);
}
break;
case 8:
if (x.Trim().Length > 0)
{
SetLong(paraVal, long.Parse(x, DmConst.invariantCulture), cType, prec, scale, typeFlag, paraInternal);
}
else
{
SetNull(paraVal);
}
break;
case 10:
if (x.Trim().Length > 0)
{
x = ReplaceNumPoint(x);
SetFloat(paraVal, float.Parse(x, DmConst.invariantCulture), cType, prec, scale, typeFlag, paraInternal);
}
else
{
SetNull(paraVal);
}
break;
case 11:
if (x.Trim().Length > 0)
{
x = ReplaceNumPoint(x);
SetDouble(paraVal, double.Parse(x, DmConst.invariantCulture), cType, prec, scale, typeFlag, paraInternal);
}
else
{
SetNull(paraVal);
}
break;
case 9:
case 24:
if (x.Trim().Length > 19)
{
x = ReplaceNumPoint(x);
SetDmDecimal(paraVal, new DmXDec().Parse(x), cType, prec, scale, typeFlag, paraInternal);
}
else if (x.Trim().Length > 0)
{
x = ReplaceNumPoint(x);
SetBigDecimal(paraVal, decimal.Parse(x, NumberStyles.Any, DmConst.invariantCulture), cType, prec, scale, typeFlag, paraInternal);
}
else
{
SetNull(paraVal);
}
break;
case 17:
{
array = (byte[])(object)StringUtil.hexStringToBytes(x);
int num = array.Length;
byte[] array2;
if (prec == num || prec == 0)
{
array2 = array;
}
else
{
array2 = new byte[prec];
if (prec > num)
{
Array.Copy(array, 0, array2, 0, num);
for (int i = num; i < prec; i++)
{
array2[i] = 0;
}
}
else
{
Array.Copy(array, 0, array2, 0, prec);
}
}
paraVal.SetInValue(array2);
break;
}
case 12:
case 18:
{
if (DmSqlType.isComplexType(cType, scale))
{
DmError.ThrowDmException(DmErrorDefinition.ECNET_DATA_CONVERTION_ERROR);
}
array = (byte[])(object)StringUtil.hexStringToBytes(x);
int num = array.Length;
byte[] array2;
if (prec < num && prec != 0)
{
array2 = new byte[prec];
Array.Copy(array, 0, array2, 0, prec);
}
else
{
array2 = array;
}
paraVal.SetInValue(array2);
break;
}
case 14:
{
if (typeFlag != 1)
{
paraVal.SetSqlType(14);
paraVal.SetPrec(3);
paraVal.SetScale(6);
paraInternal.scale = 6;
}
DmDateTime dmDateTime = DmDateTime.valueOf(x, paraInternal, m_Statement.G().Conn);
paraVal.SetInValue(dmDateTime.encode(paraInternal, m_Statement.G().Conn));
break;
}
case 15:
{
if (typeFlag != 1)
{
paraVal.SetSqlType(15);
paraVal.SetPrec(5);
paraVal.SetScale(6);
paraInternal.scale = 6;
}
DmDateTime dmDateTime = DmDateTime.valueOf(x, paraInternal, m_Statement.G().Conn);
paraVal.SetInValue(dmDateTime.encode(paraInternal, m_Statement.G().Conn));
break;
}
case 22:
{
DmDateTime dmDateTime = DmDateTime.valueOf(x, paraInternal, m_Statement.G().Conn);
paraVal.SetInValue(dmDateTime.encode(paraInternal, m_Statement.G().Conn));
break;
}
case 16:
{
DmDateTime dmDateTime = DmDateTime.valueOf(x, paraInternal, m_Statement.G().Conn);
if (typeFlag != 1)
{
paraVal.SetSqlType(16);
paraVal.SetPrec(8);
paraVal.SetScale(6);
paraInternal.scale = 6;
}
paraVal.SetInValue(dmDateTime.encode(paraInternal, m_Statement.G().Conn));
break;
}
case 23:
{
DmDateTime dmDateTime = DmDateTime.valueOf(x, paraInternal, m_Statement.G().Conn);
paraVal.SetInValue(dmDateTime.encode(paraInternal, m_Statement.G().Conn));
break;
}
case 21:
{
int secScale = scale & 0xF;
int leadScale = (scale >> 4) & 0xF;
byte type = (byte)((uint)(scale >> 8) & 0xFu);
if (x.Trim().Length > 0)
{
SetINTERVALDT(paraVal, new DmIntervalDT(x, type, leadScale, secScale), cType, prec, scale, typeFlag, paraInternal);
}
else
{
SetNull(paraVal);
}
break;
}
case 20:
if (x.Trim().Length > 0)
{
SetINTERVALYM(paraVal, new DmIntervalYM(x, scale), cType, prec, scale, typeFlag, paraInternal);
}
else
{
SetNull(paraVal);
}
break;
case 28:
paraVal.SetInValue(DmRowId.valueOf(x).encode(m_Statement.G().Conn));
break;
default:
throw new InvalidCastException();
}
}
作者:Rick Carter
出处:http://pains.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。