示例#1
0
        public void TestDateTime()
        {
            CheckSelect("SELECT #2007-07-11 16:30:00#");
            CheckSelect("SELECT TIMESTAMP '2007-07-11 16:30:00'",
                        "SELECT #2007-07-11 16:30:00#");

            IStatement statement = Factory.CreateStatement(
                "select * from inventory where (article=@x) and (modate>@last)");

            Assert.IsNotNull(statement);

            DateTime      dateTime = new DateTime(2007, 7, 11, 16, 30, 0);
            MAccessTailor tailor   = new MAccessTailor();

            tailor.AddDate("@LAST", dateTime);
            statement.Traverse(tailor);

            StringBuilder expected = new StringBuilder();

            expected.Append("SELECT *\r\nFROM inventory\r\n");
            expected.Append("WHERE (article = @x) AND ");
            expected.Append("(modate > #2007-07-11 16:30:00#)");
            Assert.AreEqual(expected.ToString(), TestUtil.Stringify(statement));

            CheckSelect("SELECT GETDATE()", "SELECT Now()");
            CheckSelect("SELECT Now()", "SELECT Now()");
            CheckSelect("SELECT sysdate", "SELECT Now()");
        }
示例#2
0
        public string TailorCommand()
        {
            bool hasParsePotential = HasCommandText();

            if ((!hasParsePotential && (m_statement == null)) ||
                m_tailored)
            {
                return(m_inner.CommandText);
            }

            if (m_inner.CommandType != CommandType.Text)
            {
                m_tailored = true;
                return(m_inner.CommandText);
            }

            IStatement statement = hasParsePotential ? CondParse() : m_statement;

            if (statement != null)
            {
                IVisitor      tailor       = Factory.CreateTailor(m_databaseProvider);
                MAccessTailor accessTailor = tailor as MAccessTailor;
                if (accessTailor != null)
                {
                    List <string> dates = new List <string>();
                    foreach (DbParameter dbParameter in m_inner.Parameters)
                    {
                        if (dbParameter.Value is DateTime)
                        {
                            string name = dbParameter.ParameterName;
                            accessTailor.AddDate(name,
                                                 (DateTime)(dbParameter.Value));
                            dates.Add(name);
                        }
                    }

                    foreach (string dateName in dates)
                    {
                        m_inner.Parameters.RemoveAt(dateName);
                    }
                }

                statement.Traverse(tailor);

                Stringifier stringifier = new Stringifier();
                statement.Traverse(stringifier);
                m_inner.CommandText = stringifier.ToSql();

                m_statement = statement;
            }

            m_tailored = true;
            return(m_inner.CommandText);
        }