public void TestTypes(string context) { //IBM.Data.DB2.DB2Parameter p = null; //p. //new IBM.Data.DB2Types.DB2RowId(); dynamic int64Value = null; dynamic int32Value = null; dynamic int16Value = null; DB2Tools.AfterInitialized(() => { int64Value = DB2Types.DB2Int64.CreateInstance(1); int32Value = DB2Types.DB2Int32.CreateInstance(2); int16Value = DB2Types.DB2Int16.CreateInstance(3); }); using (var conn = new DataConnection(context)) { conn.Select(() => 1); Assert.That(DB2Types.DB2Clob.CreateInstance(conn).IsNull, Is.True); Assert.That(DB2Types.DB2Blob.CreateInstance(conn).IsNull, Is.True); } Assert.That(int64Value.Value, Is.TypeOf <long> ().And.EqualTo(1)); Assert.That(int32Value.Value, Is.TypeOf <int> ().And.EqualTo(2)); Assert.That(int16Value.Value, Is.TypeOf <short> ().And.EqualTo(3)); var decimalValue = DB2Types.DB2Decimal.CreateInstance(4); var decimalValueAsDecimal = DB2Types.DB2DecimalFloat.CreateInstance(5m); var decimalValueAsDouble = DB2Types.DB2DecimalFloat.CreateInstance(6.0); var decimalValueAsLong = DB2Types.DB2DecimalFloat.CreateInstance(7); var realValue = DB2Types.DB2Real.CreateInstance(8); var real370Value = DB2Types.DB2Real370.CreateInstance(9); var stringValue = DB2Types.DB2String.CreateInstance("1"); var clobValue = DB2Types.DB2Clob.CreateInstance("2"); var binaryValue = DB2Types.DB2Binary.CreateInstance(new byte[] { 1 }); var blobValue = DB2Types.DB2Blob.CreateInstance(new byte[] { 2 }); var dateValue = DB2Types.DB2Date.CreateInstance(new DateTime(2000, 1, 1)); var timeValue = DB2Types.DB2Time.CreateInstance(new TimeSpan(1, 1, 1)); if (DB2Types.DB2DateTime.Type != null) { var dateTimeValue1 = DB2Types.DB2DateTime.CreateInstance(new DateTime(2000, 1, 2)); var dateTimeValue2 = DB2Types.DB2DateTime.CreateInstance(new DateTime(2000, 1, 3).Ticks); var timeStampValue = DB2Types.DB2DateTime.CreateInstance(new DateTime(2000, 1, 4)); Assert.That(dateTimeValue1.Value, Is.TypeOf <DateTime>().And.EqualTo(new DateTime(2000, 1, 2))); Assert.That(dateTimeValue2.Value, Is.TypeOf <DateTime>().And.EqualTo(new DateTime(2000, 1, 3))); Assert.That(timeStampValue.Value, Is.TypeOf <DateTime>().And.EqualTo(new DateTime(2000, 1, 4))); } Assert.That(decimalValue.Value, Is.TypeOf <decimal> ().And.EqualTo(4)); Assert.That(decimalValueAsDecimal.Value, Is.TypeOf <decimal> ().And.EqualTo(5)); Assert.That(decimalValueAsDouble.Value, Is.TypeOf <decimal> ().And.EqualTo(6)); Assert.That(decimalValueAsLong.Value, Is.TypeOf <decimal> ().And.EqualTo(7)); Assert.That(realValue.Value, Is.TypeOf <float> ().And.EqualTo(8)); Assert.That(real370Value.Value, Is.TypeOf <double> ().And.EqualTo(9)); Assert.That(stringValue.Value, Is.TypeOf <string> ().And.EqualTo("1")); Assert.That(clobValue.Value, Is.TypeOf <string> ().And.EqualTo("2")); Assert.That(binaryValue.Value, Is.TypeOf <byte[]> ().And.EqualTo(new byte[] { 1 })); Assert.That(blobValue.Value, Is.TypeOf <byte[]> ().And.EqualTo(new byte[] { 2 })); Assert.That(dateValue.Value, Is.TypeOf <DateTime>().And.EqualTo(new DateTime(2000, 1, 1))); Assert.That(timeValue.Value, Is.TypeOf <TimeSpan>().And.EqualTo(new TimeSpan(1, 1, 1))); DB2Tools.AfterInitialized(() => { int64Value = DB2Types.DB2Int64.CreateInstance(); int32Value = DB2Types.DB2Int32.CreateInstance(); int16Value = DB2Types.DB2Int16.CreateInstance(); }); Assert.That(int64Value.IsNull, Is.True); Assert.That(int32Value.IsNull, Is.True); Assert.That(int16Value.IsNull, Is.True); Assert.That(DB2Types.DB2Decimal.CreateInstance().IsNull, Is.True); Assert.That(DB2Types.DB2DecimalFloat.CreateInstance().IsNull, Is.False); Assert.That(DB2Types.DB2Real.CreateInstance().IsNull, Is.True); Assert.That(DB2Types.DB2Real370.CreateInstance().IsNull, Is.True); Assert.That(DB2Types.DB2String.CreateInstance().IsNull, Is.True); Assert.That(DB2Types.DB2Binary.CreateInstance().IsNull, Is.True); Assert.That(DB2Types.DB2Date.CreateInstance().IsNull, Is.True); Assert.That(DB2Types.DB2Time.CreateInstance().IsNull, Is.True); Assert.That(DB2Types.DB2TimeStamp.CreateInstance().IsNull, Is.True); Assert.That(DB2Types.DB2RowId.CreateInstance().IsNull, Is.True); if (DB2Types.DB2DateTime.Type != null) { Assert.That(DB2Types.DB2DateTime.CreateInstance().IsNull, Is.True); } }
/// <summary> /// Configure connection to use specific DB2 provider and connection string. /// </summary> /// <param name="builder">Instance of <see cref="LinqToDbConnectionOptionsBuilder"/>.</param> /// <param name="connectionString">DB2 connection string.</param> /// <param name="version">DB2 server version.</param> /// <returns>The builder instance so calls can be chained.</returns> public static LinqToDbConnectionOptionsBuilder UseDB2(this LinqToDbConnectionOptionsBuilder builder, string connectionString, DB2Version version) { return(builder.UseConnectionString(DB2Tools.GetDataProvider(version), connectionString)); }