Exemplo n.º 1
0
        // For existing smart playlists that we're loading from the database
        protected SmartPlaylistSource(int dbid, string name, string condition_xml, string order_by, string limit_number, string limit_criterion, PrimarySource parent, int count, bool is_temp) :
            base(generic_name, name, dbid, -1, 0, parent, is_temp)
        {
            ConditionXml = condition_xml;
            QueryOrder   = BansheeQuery.FindOrder(order_by);
            Limit        = BansheeQuery.FindLimit(limit_criterion);
            LimitValue   = new IntegerQueryValue();
            LimitValue.ParseUserQuery(limit_number);
            SavedCount = count;

            SetProperties();
            UpdateDependencies();
        }
        public void QueryValueSql()
        {
            QueryValue qv;

            qv = new DateQueryValue(); qv.ParseUserQuery("2007-03-9");
            Assert.AreEqual(new DateTime(2007, 3, 9), qv.Value);
            Assert.AreEqual("2007-03-09", qv.ToUserQuery());
            Assert.AreEqual("1173420000", qv.ToSql());

            qv = new StringQueryValue(); qv.ParseUserQuery("foo 'bar'");
            Assert.AreEqual("foo 'bar'", qv.Value);
            Assert.AreEqual("foo 'bar'", qv.ToUserQuery());
            Assert.AreEqual("foo bar", qv.ToSql());

            qv = new StringQueryValue(); qv.ParseUserQuery("Foo Baño");
            Assert.AreEqual("Foo Baño", qv.Value);
            Assert.AreEqual("Foo Baño", qv.ToUserQuery());
            Assert.AreEqual("foo bano", qv.ToSql());

            qv = new ExactStringQueryValue(); qv.ParseUserQuery("foo 'bar'");
            Assert.AreEqual("foo 'bar'", qv.Value);
            Assert.AreEqual("foo 'bar'", qv.ToUserQuery());
            Assert.AreEqual("foo ''bar''", qv.ToSql());

            qv = new IntegerQueryValue(); qv.ParseUserQuery("22");
            Assert.AreEqual(22, qv.Value);
            Assert.AreEqual("22", qv.ToUserQuery());
            Assert.AreEqual("22", qv.ToSql());

            qv = new FileSizeQueryValue(); qv.ParseUserQuery("2048 KB");
            Assert.AreEqual(2097152, qv.Value);
            Assert.AreEqual("2.048 KB", qv.ToUserQuery());
            Assert.AreEqual("2097152", qv.ToSql());

            // TODO this will break once an it_IT translation for "days ago" etc is committed
            qv = new RelativeTimeSpanQueryValue(); qv.ParseUserQuery("2 days ago");
            Assert.AreEqual(-172800, qv.Value);
            Assert.AreEqual("2 days ago", qv.ToUserQuery());

            // TODO this will break once an it_IT translation for "minutes" etc is committed
            qv = new TimeSpanQueryValue(); qv.ParseUserQuery("4 minutes");
            Assert.AreEqual(240, qv.Value);
            Assert.AreEqual("4 minutes", qv.ToUserQuery());
            Assert.AreEqual("240000", qv.ToSql());
        }