Ejemplo n.º 1
0
        public void TestFormats()
        {
            IngresDate idate;

            idate = new IngresDate(new DateTime(2011, 12, 21, 11, 28, 08));
            var fmt1 = string.Format("{0:dd.MM.yyyy}", idate);
            var fmt2 = string.Format("{0:dd.MM.yyyy hh:mm:ss}", idate);

            Assert.AreEqual <string>("21.12.2011", fmt1);
            Assert.AreEqual <string>("21.12.2011 11:28:08", fmt2);
        }
Ejemplo n.º 2
0
        public void TestImplicitConversions()
        {
            var        now      = DateTime.Now;
            IngresDate idateNow = now;

            Assert.AreEqual(idateNow, now);

            var        interval  = DateTime.Now - now;
            IngresDate iinterval = interval;

            Assert.AreEqual(iinterval, interval);
        }
Ejemplo n.º 3
0
        private string FormatDateTime(DateTime value)
        {
            var ingresDate = IngresDate.Create(value);

            if (ingresDate.IngresDateKind == IngresDateKind.DateTime)
            {
                var localValue = ingresDate.Kind == DateTimeKind.Utc ? ingresDate.ToLocalTime() : ingresDate;
                if (localValue.IsDate)
                {
                    return(IngresDate.Format(localValue));
                }
            }
            return(IngresDate.Format(ingresDate));
        }
Ejemplo n.º 4
0
 public string FormatIngresDate()
 {
     if (Value == null)
     {
         return("");
     }
     if (Value.GetType() == typeof(DateTime))
     {
         return(IngresDate.Format((DateTime)Value));
     }
     if (Value.GetType() == typeof(TimeSpan))
     {
         return(IngresDate.Format((TimeSpan)Value));
     }
     if (Value.GetType() == typeof(IngresDate))
     {
         return(IngresDate.Format((IngresDate)Value));
     }
     return("");
 }
Ejemplo n.º 5
0
        public void TestSerializeIngresDate()
        {
            var        iDate = new IngresDate(new DateTime(2011, 12, 21, 11, 28, 08));
            IngresDate iDate2;

            var        iEmptyDate = IngresDate.Empty;
            IngresDate iEmptyDate2;

            var        iInterval = new IngresDate(new TimeSpan(13, 48, 14));
            IngresDate iInterval2;

            var formatter = new BinaryFormatter();

            using (var stream = new MemoryStream())
            {
                formatter.Serialize(stream, iDate);
                stream.Seek(0, SeekOrigin.Begin);
                iDate2 = (IngresDate)formatter.Deserialize(stream);
            }

            using (var stream = new MemoryStream())
            {
                formatter.Serialize(stream, iEmptyDate);
                stream.Seek(0, SeekOrigin.Begin);
                iEmptyDate2 = (IngresDate)formatter.Deserialize(stream);
            }

            using (var stream = new MemoryStream())
            {
                formatter.Serialize(stream, iInterval);
                stream.Seek(0, SeekOrigin.Begin);
                iInterval2 = (IngresDate)formatter.Deserialize(stream);
            }

            Assert.AreEqual <IngresDate>(iDate, iDate2);
            Assert.AreEqual <IngresDate>(iEmptyDate, iEmptyDate2);
            Assert.AreEqual <IngresDate>(iInterval, iInterval2);
        }
Ejemplo n.º 6
0
            private void ChangeParameters()
            {
                var paramMap = _oldParameters.ToDictionary(x => x.ParameterName, x => x);

                _command.Parameters.Clear();
                var paramNo = 0;
                var sql     = new StringBuilder();

                foreach (var part in ParseSql(_command.CommandText))
                {
                    if (part.Type == "Parameter")
                    {
                        DbParameter param;
                        if (paramMap.TryGetValue(part.Value, out param) || paramMap.TryGetValue(part.Lexeme, out param))
                        {
                            var addParam    = true;
                            var placeholder = "?";

                            param = (DbParameter)((ICloneable)param).Clone();
                            param.ParameterName = string.Format("p{0}", paramNo);
                            if (param.Value is IngresDate || param.Value is DateTime || param.Value is TimeSpan)
                            {
                                var ingresDate = IngresDate.Create(param.Value);
                                if (ingresDate.IngresDateKind == IngresDateKind.DateTime)
                                {
                                    var localValue = ingresDate.Kind == DateTimeKind.Utc ? ingresDate.ToLocalTime() : ingresDate;
                                    if (localValue.IsDate)
                                    {
                                        placeholder = IngresDate.Format(localValue);
                                        addParam    = false;
                                    }
                                }
                                else
                                {
                                    placeholder = IngresDate.Format(ingresDate);
                                    addParam    = false;
                                }
                            }
                            else if (param.Value is int || param.Value is short || param.Value is long)
                            {
                                placeholder = param.Value.ToString();
                                addParam    = false;
                            }

                            if (addParam)
                            {
                                _command.Parameters.Add(param);
                                paramNo += 1;
                            }
                            sql.Append(placeholder);
                        }
                        else
                        {
                            sql.Append(part.Lexeme);
                        }
                    }
                    else if (part.Type == "CatalogTable")
                    {
                        CatalogTables.Add(part.Value);
                        sql.Append("session.");
                        sql.Append(part.Value);
                    }
                    else
                    {
                        sql.Append(part.Lexeme);
                    }
                }
                _command.CommandText = sql.ToString();
            }
Ejemplo n.º 7
0
        private void TestIngresDateTest2(DateTime?value, TimeSpan expected)
        {
            var actual = IngresDate.ToTimeSpan(GetTestIngresDateTest2(value));

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 8
0
        private void TestIngresDateTest2(string value, DateTime expected)
        {
            var actual = IngresDate.ToDateTime(GetTestIngresDateTest2(value));

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 9
0
 private string FormatTimeSpan(TimeSpan value)
 {
     return(IngresDate.Format(IngresDate.Create(value)));
 }