Beispiel #1
0
 /// <summary>
 /// Box.
 /// </summary>
 internal static String ToBox(NpgsqlNativeTypeInfo TypeInfo, Object NativeData, Boolean ForExtendedQuery)
 {
     if (NativeData is NpgsqlBox)
     {
         NpgsqlBox box = (NpgsqlBox)NativeData;
         return
             (String.Format(CultureInfo.InvariantCulture, "({0},{1}),({2},{3})", box.LowerLeft.X, box.LowerLeft.Y,
                            box.UpperRight.X, box.UpperRight.Y));
     }
     else
     {
         throw new InvalidCastException("Unable to cast data to Rectangle type");
     }
 }
Beispiel #2
0
        public void Box()
        {
            var expected = new NpgsqlBox(2, 4, 1, 3);
            var cmd = new NpgsqlCommand("SELECT @p1, @p2", Conn);
            var p1 = new NpgsqlParameter("p1", NpgsqlDbType.Box) { Value = expected };
            var p2 = new NpgsqlParameter { ParameterName = "p2", Value = expected };
            Assert.That(p2.NpgsqlDbType, Is.EqualTo(NpgsqlDbType.Box));
            cmd.Parameters.Add(p1);
            cmd.Parameters.Add(p2);
            var reader = cmd.ExecuteReader();
            reader.Read();

            for (var i = 0; i < cmd.Parameters.Count; i++) {
                Assert.That(reader.GetFieldType(i), Is.EqualTo(typeof(NpgsqlBox)));
                Assert.That(reader[i], Is.EqualTo(expected));
            }
        }
        /// <summary>
        /// Box.
        /// </summary>
        internal static String ToBox(NpgsqlNativeTypeInfo TypeInfo, Object NativeData)
        {
            /*if (NativeData.GetType() == typeof(Rectangle)) {
             *  Rectangle       R = (Rectangle)NativeData;
             *  return String.Format(CultureInfo.InvariantCulture, "({0},{1}),({2},{3})", R.Left, R.Top, R.Left + R.Width, R.Top + R.Height);
             * } else if (NativeData.GetType() == typeof(RectangleF)) {
             *  RectangleF      R = (RectangleF)NativeData;
             *  return String.Format(CultureInfo.InvariantCulture, "({0},{1}),({2},{3})", R.Left, R.Top, R.Left + R.Width, R.Top + R.Height);*/

            if (NativeData is NpgsqlBox)
            {
                NpgsqlBox box = (NpgsqlBox)NativeData;
                return(String.Format(CultureInfo.InvariantCulture, "({0},{1}),({2},{3})", box.LowerLeft.X, box.LowerLeft.Y, box.UpperRight.X, box.UpperRight.Y));
            }
            else
            {
                throw new InvalidCastException("Unable to cast data to Rectangle type");
            }
        }
        /// <summary>
        /// Box.
        /// </summary>
        internal static byte[] ToBox(NpgsqlNativeTypeInfo TypeInfo, Object NativeData, Boolean forExtendedQuery, NativeToBackendTypeConverterOptions options, bool arrayElement)
        {
            /*if (NativeData.GetType() == typeof(Rectangle)) {
             *  Rectangle       R = (Rectangle)NativeData;
             *  return String.Format(CultureInfo.InvariantCulture, "({0},{1}),({2},{3})", R.Left, R.Top, R.Left + R.Width, R.Top + R.Height);
             * } else if (NativeData.GetType() == typeof(RectangleF)) {
             *  RectangleF      R = (RectangleF)NativeData;
             *  return String.Format(CultureInfo.InvariantCulture, "({0},{1}),({2},{3})", R.Left, R.Top, R.Left + R.Width, R.Top + R.Height);*/

            if (NativeData is NpgsqlBox)
            {
                NpgsqlBox box = (NpgsqlBox)NativeData;
                return
                    (BackendEncoding.UTF8Encoding.GetBytes(String.Format(CultureInfo.InvariantCulture, "({0},{1}),({2},{3})", box.LowerLeft.X, box.LowerLeft.Y,
                                                                         box.UpperRight.X, box.UpperRight.Y)));
            }
            else
            {
                throw new InvalidCastException("Unable to cast data to Rectangle type");
            }
        }
        public void Box()
        {
            using (var conn = OpenConnection())
            {
                var expected = new NpgsqlBox(2, 4, 1, 3);
                var cmd = new NpgsqlCommand("SELECT @p1, @p2", conn);
                var p1 = new NpgsqlParameter("p1", NpgsqlDbType.Box) {Value = expected};
                var p2 = new NpgsqlParameter {ParameterName = "p2", Value = expected};
                Assert.That(p2.NpgsqlDbType, Is.EqualTo(NpgsqlDbType.Box));
                cmd.Parameters.Add(p1);
                cmd.Parameters.Add(p2);
                using (var reader = cmd.ExecuteReader())
                {
                    reader.Read();

                    for (var i = 0; i < cmd.Parameters.Count; i++)
                    {
                        Assert.That(reader.GetFieldType(i), Is.EqualTo(typeof (NpgsqlBox)));
                        var actual = reader.GetFieldValue<NpgsqlBox>(i);
                        AssertPointsEqual(actual.UpperRight, expected.UpperRight);
                    }
                }
            }
        }