⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testfunctions.java

📁 java 数据库 功能强大 效率高 SmallSQL Database is a free DBMS library for the Java(tm) platform. It runs on
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		a("Timestampdiff(second, null, {t '00:10:11'})" 		, null),
		a("Timestampdiff(second, {t '00:10:11'}, null)" 		, null),
		a("TimestampAdd(year,     1, null)" 		, null),
		a("DayOfWeek({d '2006-02-16'})" 		, new Integer(4)),
		a("DayOfWeek({d '2006-02-19'})" 		, new Integer(7)),
		a("DayOfYear({d '2004-01-01'})" 		, new Integer(1)),
		a("DayOfYear({d '2004-02-29'})" 		, new Integer(60)),
		a("DayOfYear({d '2004-03-01'})" 		, new Integer(61)),
		a("DayOfYear({d '2004-12-31'})" 		, new Integer(366)),
		a("DayOfMonth({d '1904-07-17'})" 		, new Integer(17)),
		a("locate('ae', 'QWAERAE')"		, new Integer(3)),
		a("locate('ae', 'QWAERAE', 3)"	, new Integer(3)),
		a("locate('ae', 'QWAERAE', 4)"	, new Integer(6)),
		a("locate('ae', 'QWAERAE', null)"		, new Integer(3)),
		a("locate(null, 'QWAERAE', 4)"	, null),
		a("locate('ae', null, 4)"	, null),
		a("{d '2004-10-12'}"	, 				java.sql.Date.valueOf("2004-10-12")),
		a("{ts '1999-10-12 15:14:13.123'}"	, 	Timestamp.valueOf("1999-10-12 15:14:13.123")),
		a("{t '15:14:13'}"	, 					Time.valueOf("15:14:13")),
		a("{fn length('abc')}", 				new Integer(3)),
		a("{fn length('abc ')}", 				new Integer(3)),
		a("{fn length(null)}", 					null),
		a("{fn Right('qwertzu', 3)}", 			"tzu"),
		a("{fn Right('qwertzu', 13)}", 			"qwertzu"),
		a("cast( Right('1234', 2) as real)", 	new Float(34)),
		a("cast( Right('1234', 2) as smallint)",new Integer(34)),
		a("cast( Right('1234', 2) as boolean)", Boolean.TRUE),
		a("right(0x1234567890, 2)",				new byte[]{0x78,(byte)0x90}),
		a("right(null, 2)",						null),
        a("left(null, 2)",                      null),
        a("left('abcd', 2)",                    "ab"),
        a("left(0x1234567890, 2)",              new byte[]{0x12,(byte)0x34}),
		a("cast({fn SubString('ab2.3qw', 3, 3)} as double)", 	new Double(2.3)),
		a("subString('qwert', 99, 2)", 		""),
		a("{fn SubString(0x1234567890, 0, 99)}",new byte[]{0x12,0x34,0x56,0x78,(byte)0x90}),
		a("{fn SubString(0x1234567890, 2, 2)}", new byte[]{0x34, 0x56}),
		a("{fn SubString(0x1234567890, 99, 2)}", new byte[]{}),
		a("SubString(null, 99, 2)", 			null),
        a("Insert('abcd', 2, 1, 'qw')",         "aqwcd"),
        a("Insert(0x1234, 2, 0, 0x56)",         new byte[]{0x12,0x56,0x34}),
        a("STUFF(null, 2, 0, 0x56)",         	null),
        a("lcase('Abcd')",                      "abcd"),
        a("ucase('Abcd')",                      "ABCD"),
        a("lcase(null)",                        null),
        a("ucase(null)",                        null),
        a("cast(1 as money) + SubString('a12', 2, 2)",new BigDecimal("13.0000")),
        a("cast(1 as numeric(5,2)) + SubString('a12', 2, 2)",new BigDecimal("13.00")),
        a("cast(1 as BigInt) + SubString('a12', 2, 2)",new Long(13)),
        a("cast(1 as real) + SubString('a12', 2, 2)",new Float(13)),
        a("1   + SubString('a12', 2, 2)",       new Integer(13)),
        a("1.0 + SubString('a12', 2, 2)",       new Double(13)),
        a("concat('abc', 'def')",               "abcdef"),
		a("{fn IfNull(null, 'abc')}", 			"abc"),
		a("{fn IfNull('asd', 'abc')}", 			"asd"),
		a("iif(true, 1, 2)", 					new Integer(1)),
		a("iif(false, 1, 2)", 					new Integer(2)),
		a("CASE aVarchar WHEN 'qwert' THEN 25 WHEN 'asdfg' THEN 26 ELSE null END", new Integer(25)),
		a("CASE WHEN aVarchar='qwert' THEN 'uu' WHEN aVarchar='bb' THEN 'gg' ELSE 'nn' END", "uu"),
		a("{fn Ascii('')}", 			null),
		a("{fn Ascii(null)}", 			null),
		a("Ascii('abc')", 				new Integer(97)),
		a("{fn Char(97)}", 				"a"),
		a("Char(null)", 				null),
        a("$1 + Char(49)",              new BigDecimal("2.0000")),
		a("Exp(null)", 					null),
		a("exp(0)", 					new Double(1)),
		a("log(exp(2.4))", 				new Double(2.4)),
		a("log10(10)", 					new Double(1)),
		a("cos(null)", 					null),
		a("cos(0)", 					new Double(1)),
		a("acos(1)", 					new Double(0)),
		a("sin(0)", 					new Double(0)),
		a("cos(pi())", 					new Double(-1)),
		a("asin(0)", 					new Double(0)),
		a("asin(sin(0.5))",				new Double(0.5)),
		a("tan(0)", 					new Double(0)),
		a("atan(tan(0.5))",				new Double(0.5)),
		a("atan2(0,3)",					new Double(0)),
		a("atan2(0,-3)",				new Double(Math.PI)),
		a("atn2(0,null)",				null),
		a("cot(0)",						new Double(Double.POSITIVE_INFINITY)),
		a("tan(0)", 					new Double(0)),
		a("degrees(pi())", 				new Double(180)),
		a("degrees(radians(50))", 		new Double(50)),
		a("ceiling(123.45)", 			new Double(124)),
		a("ceiling(-123.45)", 			new Double(-123)),
		a("power(2, 3)", 				new Double(8)),
		a("5.0 % 2", 					new Double(1)),
		a("5 % 2", 						new Integer(1)),
		a("mod(5, 2)", 					new Integer(1)),
		a("FLOOR(123.45)", 				new Double(123)),
		a("FLOOR('123.45')", 			new Double(123)),
		a("FLOOR(-123.45)", 			new Double(-124)),
		a("FLOOR($123.45)", 			new BigDecimal("123.0000")),
		a("Rand(0)", 					new Double(0.730967787376657)),
		a("ROUND(748.58, -4)", 			new Double(0)),
		a("ROUND(-748.58, -2)", 		new Double(-700)),
		a("ROUND('748.5876', 2)", 		new Double(748.59)),
        a("round( 1e19, 0)"       , new Double(1e19)),
        a("truncate( -1e19,0)"      , new Double(-1e19)),
		a("Sign('748.5876')", 			new Integer(1)),
		a("Sign(-2)", 					new Integer(-1)),
        a("Sign(2)",                    new Integer(1)),
        a("Sign(0)",                    new Integer(0)),
        a("Sign(-$2)",                  new Integer(-1)),
        a("Sign($2)",                   new Integer(1)),
        a("Sign($0)",                   new Integer(0)),
        a("Sign(cast(-2 as bigint))",   new Integer(-1)),
        a("Sign(cast(2 as bigint))",    new Integer(1)),
        a("Sign(cast(0 as bigint))",    new Integer(0)),
        a("Sign(1.0)",                  new Integer(1)),
		a("Sign(0.0)", 					new Integer(0)),
        a("Sign(-.1)",                  new Integer(-1)),
        a("Sign(cast(0 as numeric(5)))",new Integer(0)),
		a("Sign(null)", 				null),
		a("sqrt(9)", 					new Double(3)),
		a("Truncate(748.58, -4)", 		new Double(0)),
		a("Truncate(-748.58, -2)", 		new Double(-700)),
		a("Truncate('748.5876', 2)", 	new Double(748.58)),
        a("rtrim(null)",                null),
        a("rtrim(0x0012345600)",        new byte[]{0x00,0x12,0x34,0x56}),
        a("rtrim(' abc ')",             " abc"),
        a("ltrim(null)",                null),
        a("ltrim(0x0012345600)",        new byte[]{0x12,0x34,0x56,0x00}),
        a("ltrim(' abc ')",             "abc "),
        a("space(3)",                   "   "),
        a("space(null)",                null),
        a("space(-3)",                  null),
        a("replace('abcabc','bc','4')", "a4a4"),
        a("replace('abcabc','bc',null)",null),
        a("replace('abcabc','','4')",   "abcabc"),
        a("replace(0x123456,0x3456,0x77)", new byte[]{0x12,0x77}),
        a("replace(0x123456,0x,0x77)",  new byte[]{0x12,0x34,0x56}),
        a("replace(0x123456,0x88,0x77)",new byte[]{0x12,0x34,0x56}),
        a("repeat('ab',4)",             "abababab"),
        a("repeat(null,4)",             null),
        a("repeat(0x1234,3)",           new byte[]{0x12,0x34,0x12,0x34,0x12,0x34}),
        a("DIFFERENCE('Green','Greene')",new Integer(4)),
        a("DIFFERENCE('Green',null)",   null),
        a("soundex('Wikipedia')",       "W213"),
        a("0x10 < 0x1020",              Boolean.TRUE),
	};


    private static TestValue a(String function, Object result){
        TestValue value = new TestValue();
        value.function  = function;
        value.result    = result;
        return value;
    }

    TestFunctions(TestValue testValue){
        super(testValue.function);
        this.testValue = testValue;
    }
    

    public void tearDown(){
        try{
            Connection con = AllTests.getConnection();
            Statement st = con.createStatement();
            st.execute("drop table " + table);
            st.close();
        }catch(Throwable e){
            //e.printStackTrace();
        }
    }

    public void setUp(){
        tearDown();
        try{
            Connection con = AllTests.getConnection();
            Statement st = con.createStatement();
            st.execute("create table " + table + "(aInt int, aVarchar varchar(100))");
            st.execute("Insert into " + table + "(aInt, aVarchar) Values(-120,'qwert')");
            st.close();
        }catch(Throwable e){
            e.printStackTrace();
        }
    }

    public void runTest() throws Exception{
		assertEqualsRsValue( testValue.result, "Select " + testValue.function + ",5 from " + table);
        if(!testValue.function.startsWith("Top")){
            assertEqualsRsValue( testValue.result, "Select " + testValue.function + " from " + table + " Group By " + testValue.function);
        }
    }

    public static Test suite() throws Exception{
        TestSuite theSuite = new TestSuite("Functions");
        for(int i=0; i<TESTS.length; i++){
            theSuite.addTest(new TestFunctions( TESTS[i] ) );
        }
        return theSuite;
    }

    private static class TestValue{
        String function;
        Object result;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -