Skip to content

Commit

Permalink
DNET-124, DNET-328
Browse files Browse the repository at this point in the history
  • Loading branch information
cincuranet committed Jun 30, 2010
1 parent 073e57f commit d61e7d0
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 27 deletions.
Expand Up @@ -673,8 +673,7 @@ public void Write(DbField param)
if ((param.Length % param.Charset.BytesPerCharacter) == 0 &&
svalue.Length > param.CharCount)
{
//throw new IscException(IscCodes.isc_arith_except);
svalue = svalue.Substring(0, param.CharCount);
throw new IscException(new[] { IscCodes.isc_arith_except, IscCodes.isc_string_truncation });
}

this.WriteOpaque(param.Charset.GetBytes(svalue), param.Length);
Expand All @@ -693,8 +692,7 @@ public void Write(DbField param)
if ((param.Length % param.Charset.BytesPerCharacter) == 0 &&
svalue.Length > param.CharCount)
{
//throw new IscException(IscCodes.isc_arith_except);
svalue = svalue.Substring(0, param.CharCount);
throw new IscException(new[] { IscCodes.isc_arith_except, IscCodes.isc_string_truncation });
}

byte[] data = param.Charset.GetBytes(svalue);
Expand Down
8 changes: 4 additions & 4 deletions NETProvider/source/FirebirdSql/Data/Common/DbValue.cs
Expand Up @@ -223,8 +223,8 @@ public byte[] GetBytes()

if ((this.Field.Length % this.Field.Charset.BytesPerCharacter) == 0 &&
svalue.Length > this.Field.CharCount)
{
throw new IscException(IscCodes.isc_arith_except);
{
throw new IscException(new[] { IscCodes.isc_arith_except, IscCodes.isc_string_truncation });
}

byte[] buffer = new byte[this.Field.Length];
Expand All @@ -251,8 +251,8 @@ public byte[] GetBytes()

if ((this.Field.Length % this.Field.Charset.BytesPerCharacter) == 0 &&
svalue.Length > this.Field.CharCount)
{
throw new IscException(IscCodes.isc_arith_except);
{
throw new IscException(new[] { IscCodes.isc_arith_except, IscCodes.isc_string_truncation });
}

byte[] sbuffer = this.Field.Charset.GetBytes(svalue);
Expand Down
24 changes: 12 additions & 12 deletions NETProvider/source/FirebirdSql/Data/FirebirdClient/FbCommand.cs
Expand Up @@ -942,7 +942,7 @@ private bool BuildParameterDescriptor(Descriptor descriptor, FbParameter paramet
Charset charset = this.connection.InnerConnection.Database.Charset;

// Check the parameter character set
if (parameter.Charset == FbCharset.Octets && !(parameter.Value is byte[]))
if (parameter.Charset == FbCharset.Octets && !(parameter.InternalValue is byte[]))
{
throw new InvalidOperationException("Value for char octets fields should be a byte array");
}
Expand Down Expand Up @@ -1047,7 +1047,7 @@ private void UpdateParameterValues()

if (index != -1)
{
if (this.Parameters[index].Value == DBNull.Value || this.Parameters[index].Value == null)
if (this.Parameters[index].InternalValue == DBNull.Value || this.Parameters[index].InternalValue == null)
{
this.statement.Parameters[i].NullFlag = -1;
this.statement.Parameters[i].Value = DBNull.Value;
Expand All @@ -1067,18 +1067,18 @@ private void UpdateParameterValues()
case DbDataType.Binary:
{
BlobBase blob = this.statement.CreateBlob();
blob.Write((byte[])this.Parameters[index].Value);
blob.Write((byte[])this.Parameters[index].InternalValue);
this.statement.Parameters[i].Value = blob.Id;
}
break;

case DbDataType.Text:
{
BlobBase blob = this.statement.CreateBlob();
if (this.Parameters[index].Value.GetType() == typeof(byte[]))
blob.Write((byte[])this.Parameters[index].Value);
if (this.Parameters[index].InternalValue.GetType() == typeof(byte[]))
blob.Write((byte[])this.Parameters[index].InternalValue);
else
blob.Write((string)this.Parameters[index].Value);
blob.Write((string)this.Parameters[index].InternalValue);
this.statement.Parameters[i].Value = blob.Id;
}
break;
Expand All @@ -1099,22 +1099,22 @@ private void UpdateParameterValues()
}

this.statement.Parameters[i].ArrayHandle.Handle = 0;
this.statement.Parameters[i].ArrayHandle.Write((System.Array)this.Parameters[index].Value);
this.statement.Parameters[i].ArrayHandle.Write((System.Array)this.Parameters[index].InternalValue);
this.statement.Parameters[i].Value = this.statement.Parameters[i].ArrayHandle.Handle;
}
break;

case DbDataType.Guid:
if (!(this.Parameters[index].Value is Guid) &&
!(this.Parameters[index].Value is byte[]))
if (!(this.Parameters[index].InternalValue is Guid) &&
!(this.Parameters[index].InternalValue is byte[]))
{
throw new InvalidOperationException("Incorrect Guid value.");
}
this.statement.Parameters[i].Value = this.Parameters[index].Value;
this.statement.Parameters[i].Value = this.Parameters[index].InternalValue;
break;

default:
this.statement.Parameters[i].Value = this.Parameters[index].Value;
this.statement.Parameters[i].Value = this.Parameters[index].InternalValue;
break;
}
}
Expand All @@ -1133,7 +1133,7 @@ private void Prepare(bool returnsSet)
if (this.parameters != null)
foreach (FbParameter item in this.parameters)
{
System.Diagnostics.Debug.WriteLine(string.Format("Name:{0} \t Type:{1} \t Value:{2}", item.InternalParameterName, item.FbDbType, item.Value));
System.Diagnostics.Debug.WriteLine(string.Format("Name:{0} \t Type:{1} \t Value:{2}", item.InternalParameterName, item.FbDbType, item.InternalValue));
}
#endif

Expand Down
30 changes: 23 additions & 7 deletions NETProvider/source/FirebirdSql/Data/FirebirdClient/FbParameter.cs
Expand Up @@ -48,7 +48,6 @@ public sealed class FbParameter : DbParameter, ICloneable
private object value;
private string parameterName;
private string sourceColumn;
private bool isTypeSet;

#endregion

Expand All @@ -73,6 +72,7 @@ public override int Size
set
{
this.size = value;
this.IsSizeSet = true;

// Hack for Clob parameters
if (value == 2147483647 &&
Expand Down Expand Up @@ -148,7 +148,7 @@ public FbDbType FbDbType
set
{
this.fbDbType = value;
this.isTypeSet = true;
this.IsTypeSet = true;
}
}

Expand All @@ -174,7 +174,7 @@ public override object Value

this.value = value;

if (!this.isTypeSet)
if (!this.IsTypeSet)
{
this.SetFbDbType(value);
}
Expand Down Expand Up @@ -235,18 +235,34 @@ internal string InternalParameterName
{
get
{
if (!String.IsNullOrEmpty(this.parameterName) && !this.parameterName.StartsWith("@"))
if (!string.IsNullOrEmpty(this.parameterName) && !this.parameterName.StartsWith("@"))
{
return String.Format("@{0}", this.ParameterName);
return string.Format("@{0}", this.ParameterName);
}

return this.ParameterName;
}
}

internal bool IsTypeSet
internal bool IsTypeSet { get; private set; }

internal bool IsSizeSet { get; private set; }

internal object InternalValue
{
get { return this.isTypeSet; }
get
{
if (this.IsSizeSet)
{
string svalue = (this.value as string);
if (svalue != null)
return svalue.Substring(0, Math.Min(this.size, svalue.Length));
else
return this.value;
}

return this.value;
}
}

#endregion
Expand Down

0 comments on commit d61e7d0

Please sign in to comment.