public IntPtr MarshalManagedToNative(Charset charset, object value) { DbField field = new DbField(); ParamDsc descriptor = this.BuildDescriptor(charset, value); DbDataType type = TypeHelper.GetTypeFromDsc(descriptor.Type, descriptor.Scale, descriptor.SubType); field.DataType = (short)TypeHelper.GetFbType(type, true); field.SubType = descriptor.SubType; field.DbValue.Value = value; field.Length = descriptor.Length; byte[] buffer = field.DbValue.GetBytes(); descriptor.Data = Marshal.AllocHGlobal(buffer.Length); Marshal.Copy(buffer, 0, descriptor.Data, buffer.Length); return this.MarshalManagedToNative(descriptor); }
public DbValue(StatementBase statement, DbField field, object value) { this.statement = statement; this.field = field; this.value = value ?? DBNull.Value; }
public DbValue(StatementBase statement, DbField field) { this.statement = statement; this.field = field; this.value = field.Value; }
public DbValue(DbField field, object value) { this.field = field; this.value = value ?? DBNull.Value; }
public DbValue(StatementBase statement, DbField field, object value) { this.statement = statement; this.field = field; this.value = (value == null) ? System.DBNull.Value : value; }
public DbValue(DbField field, object value) { this.field = field; this.value = (value == null) ? System.DBNull.Value : value; }
public void Write(DbField param) { try { if (param.DbDataType != DbDataType.Null) { param.FixNull(); switch (param.DbDataType) { case DbDataType.Char: if (param.Charset.IsOctetsCharset) { this.WriteOpaque(param.DbValue.GetBinary(), param.Length); } else { string svalue = param.DbValue.GetString(); if ((param.Length % param.Charset.BytesPerCharacter) == 0 && svalue.Length > param.CharCount) { throw new IscException(new[] { IscCodes.isc_arith_except, IscCodes.isc_string_truncation }); } this.WriteOpaque(param.Charset.GetBytes(svalue), param.Length); } break; case DbDataType.VarChar: if (param.Charset.IsOctetsCharset) { this.WriteOpaque(param.DbValue.GetBinary(), param.Length); } else { string svalue = param.DbValue.GetString(); if ((param.Length % param.Charset.BytesPerCharacter) == 0 && svalue.Length > param.CharCount) { throw new IscException(new[] { IscCodes.isc_arith_except, IscCodes.isc_string_truncation }); } byte[] data = param.Charset.GetBytes(svalue); this.WriteBuffer(data, data.Length); } break; case DbDataType.SmallInt: this.Write(param.DbValue.GetInt16()); break; case DbDataType.Integer: this.Write(param.DbValue.GetInt32()); break; case DbDataType.BigInt: case DbDataType.Array: case DbDataType.Binary: case DbDataType.Text: this.Write(param.DbValue.GetInt64()); break; case DbDataType.Decimal: case DbDataType.Numeric: this.Write( param.DbValue.GetDecimal(), param.DataType, param.NumericScale); break; case DbDataType.Float: this.Write(param.DbValue.GetFloat()); break; case DbDataType.Guid: this.WriteOpaque(param.DbValue.GetGuid().ToByteArray()); break; case DbDataType.Double: this.Write(param.DbValue.GetDouble()); break; case DbDataType.Date: this.Write(param.DbValue.GetDate()); break; case DbDataType.Time: this.Write(param.DbValue.GetTime()); break; case DbDataType.TimeStamp: this.Write(param.DbValue.GetDate()); this.Write(param.DbValue.GetTime()); break; case DbDataType.Boolean: this.Write(Convert.ToBoolean(param.Value)); break; default: throw new IscException("Unknown sql data type: " + param.DataType); } } this.Write(param.NullFlag); } catch (IOException) { throw new IscException(IscCodes.isc_net_write_err); } }
private byte[] GetBytes(DbField field) { if (field.DbValue.IsDBNull()) { int length = field.Length; if (field.SqlType == IscCodes.SQL_VARYING) { // Add two bytes more for store value length length += 2; } return new byte[length]; } switch (field.DbDataType) { case DbDataType.Char: { string svalue = field.DbValue.GetString(); if ((field.Length % field.Charset.BytesPerCharacter) == 0 && svalue.Length > field.CharCount) { throw new IscException(335544321); } byte[] buffer = new byte[field.Length]; for (int i = 0; i < buffer.Length; i++) { buffer[i] = 32; } byte[] bytes = field.Charset.GetBytes(svalue); Buffer.BlockCopy(bytes, 0, buffer, 0, bytes.Length); return buffer; } case DbDataType.VarChar: { string svalue = field.Value.ToString(); if ((field.Length % field.Charset.BytesPerCharacter) == 0 && svalue.Length > field.CharCount) { throw new IscException(335544321); } byte[] sbuffer = field.Charset.GetBytes(svalue); byte[] buffer = new byte[field.Length + 2]; // Copy length Buffer.BlockCopy( BitConverter.GetBytes((short)sbuffer.Length), 0, buffer, 0, 2); // Copy string value Buffer.BlockCopy(sbuffer, 0, buffer, 2, sbuffer.Length); return buffer; } case DbDataType.Numeric: case DbDataType.Decimal: return this.GetNumericBytes(field); case DbDataType.SmallInt: return BitConverter.GetBytes(field.DbValue.GetInt16()); case DbDataType.Integer: return BitConverter.GetBytes(field.DbValue.GetInt32()); case DbDataType.Array: case DbDataType.Binary: case DbDataType.Text: case DbDataType.BigInt: return BitConverter.GetBytes(field.DbValue.GetInt64()); case DbDataType.Float: return BitConverter.GetBytes(field.DbValue.GetFloat()); case DbDataType.Double: return BitConverter.GetBytes(field.DbValue.GetDouble()); case DbDataType.Date: return BitConverter.GetBytes( TypeEncoder.EncodeDate(field.DbValue.GetDateTime())); case DbDataType.Time: return BitConverter.GetBytes( TypeEncoder.EncodeTime(field.DbValue.GetDateTime())); case DbDataType.TimeStamp: byte[] date = BitConverter.GetBytes( TypeEncoder.EncodeDate(field.DbValue.GetDateTime())); byte[] time = BitConverter.GetBytes( TypeEncoder.EncodeTime(field.DbValue.GetDateTime())); byte[] result = new byte[8]; Buffer.BlockCopy(date, 0, result, 0, date.Length); Buffer.BlockCopy(time, 0, result, 4, time.Length); return result; case DbDataType.Guid: return field.DbValue.GetGuid().ToByteArray(); default: throw new NotSupportedException("Unknown data type"); } }
public void Write(DbField param) { Charset innerCharset = (this.charset.Name != "NONE") ? this.charset : param.Charset; param.FixNull(); try { switch (param.DbDataType) { case DbDataType.Char: { string svalue = param.DbValue.GetString(); if ((param.Length % param.Charset.BytesPerCharacter) == 0 && svalue.Length > param.CharCount) { throw new IscException(335544321); } this.WriteOpaque(innerCharset.GetBytes(svalue), param.Length); } break; case DbDataType.VarChar: { string svalue = param.DbValue.GetString().TrimEnd(); if ((param.Length % param.Charset.BytesPerCharacter) == 0 && svalue.Length > param.CharCount) { throw new IscException(335544321); } byte[] data = innerCharset.GetBytes(svalue); this.WriteBuffer(data, data.Length); } break; case DbDataType.SmallInt: this.Write(param.DbValue.GetInt16()); break; case DbDataType.Integer: this.Write(param.DbValue.GetInt32()); break; case DbDataType.BigInt: case DbDataType.Array: case DbDataType.Binary: case DbDataType.Text: this.Write(param.DbValue.GetInt64()); break; case DbDataType.Decimal: case DbDataType.Numeric: this.Write( param.DbValue.GetDecimal(), param.DataType, param.NumericScale); break; case DbDataType.Float: this.Write(param.DbValue.GetFloat()); break; case DbDataType.Guid: this.WriteOpaque(param.DbValue.GetGuid().ToByteArray()); break; case DbDataType.Double: this.Write(param.DbValue.GetDouble()); break; case DbDataType.Date: this.Write(param.DbValue.EncodeDate()); break; case DbDataType.Time: this.Write(param.DbValue.EncodeTime()); break; case DbDataType.TimeStamp: this.Write(param.DbValue.EncodeDate()); this.Write(param.DbValue.EncodeTime()); break; default: throw new IscException("Unknown sql data type: " + param.DataType); } this.Write(param.NullFlag); } catch (IOException) { throw new IscException(IscCodes.isc_net_write_err); } }
public DbValue(StatementBase statement, DbField field, object value) { _statement = statement; _field = field; _value = value ?? DBNull.Value; }
public DbValue(StatementBase statement, DbField field) { _statement = statement; _field = field; _value = field.Value; }
public DbValue(DbField field, object value) { _field = field; _value = value ?? DBNull.Value; }
public void Write(DbField value) { this.outputStream.Write(value); }
public object ReadValue(DbField field) { return this.inputStream.ReadValue(field); }
private byte[] GetNumericBytes(DbField field) { decimal value = field.DbValue.GetDecimal(); object numeric = TypeEncoder.EncodeDecimal(value, field.NumericScale, field.DataType); switch (field.SqlType) { case IscCodes.SQL_SHORT: return BitConverter.GetBytes((short)numeric); case IscCodes.SQL_LONG: return BitConverter.GetBytes((int)numeric); case IscCodes.SQL_INT64: case IscCodes.SQL_QUAD: return BitConverter.GetBytes((long)numeric); case IscCodes.SQL_DOUBLE: return BitConverter.GetBytes(field.DbValue.GetDouble()); default: return null; } }
private object GetValue(ParamDsc descriptor, Charset charset) { DbField field = new DbField(); if (descriptor.Type == dtype_null) { return null; } if (descriptor.Type == IscCodes.dtype_byte) { return null; } DbDataType dbType = TypeHelper.GetTypeFromDsc(descriptor.Type, descriptor.Scale, descriptor.SubType); field.DataType = (short)TypeHelper.GetFbType(dbType, true); field.NumericScale = descriptor.Scale; field.SubType = descriptor.SubType; byte[] data = this.GetBytes(descriptor, field.DataType); field.SetValue(data); return field.Value; }
public object ReadValue(DbField field) { object fieldValue = null; Charset innerCharset = (this.charset.Name != "NONE") ? this.charset : field.Charset; switch (field.DbDataType) { case DbDataType.Char: if (field.Charset.IsOctetsCharset) { fieldValue = this.ReadOpaque(field.Length); } else { string s = this.ReadString(innerCharset, field.Length); if ((field.Length % field.Charset.BytesPerCharacter) == 0 && s.Length > field.CharCount) { fieldValue = s.Substring(0, field.CharCount); } else { fieldValue = s; } } break; case DbDataType.VarChar: if (field.Charset.IsOctetsCharset) { fieldValue = this.ReadBuffer(); } else { fieldValue = this.ReadString(innerCharset); } break; case DbDataType.SmallInt: fieldValue = this.ReadInt16(); break; case DbDataType.Integer: fieldValue = this.ReadInt32(); break; case DbDataType.Array: case DbDataType.Binary: case DbDataType.Text: case DbDataType.BigInt: fieldValue = this.ReadInt64(); break; case DbDataType.Decimal: case DbDataType.Numeric: fieldValue = this.ReadDecimal(field.DataType, field.NumericScale); break; case DbDataType.Float: fieldValue = this.ReadSingle(); break; case DbDataType.Guid: fieldValue = this.ReadGuid(field.Length); break; case DbDataType.Double: fieldValue = this.ReadDouble(); break; case DbDataType.Date: fieldValue = this.ReadDate(); break; case DbDataType.Time: fieldValue = this.ReadTime(); break; case DbDataType.TimeStamp: fieldValue = this.ReadDateTime(); break; } int sqlInd = this.ReadInt32(); if (sqlInd == 0) { return fieldValue; } else if (sqlInd == -1) { return null; } else { throw new IscException("invalid sqlind value: " + sqlInd); } }
public Descriptor(short n) { _version = IscCodes.SQLDA_VERSION1; _count = n; _actualCount = n; _fields = new DbField[n]; for (int i = 0; i < n; i++) { _fields[i] = new DbField(); } }