File: DatabaseMetaDataTest.java

package info (click to toggle)
libpgjava 9.2-1002-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,308 kB
  • ctags: 4,503
  • sloc: java: 37,623; xml: 3,376; makefile: 22; sh: 10
file content (84 lines) | stat: -rw-r--r-- 2,367 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*-------------------------------------------------------------------------
*
* Copyright (c) 2007-2011, PostgreSQL Global Development Group
*
*
*-------------------------------------------------------------------------
*/
package org.postgresql.test.jdbc4;

import org.postgresql.test.TestUtil;
import junit.framework.TestCase;
import java.sql.*;

public class DatabaseMetaDataTest extends TestCase
{

    private Connection _conn;

    public DatabaseMetaDataTest(String name)
    {
        super(name);
    }

    protected void setUp() throws Exception
    {
        _conn = TestUtil.openDB();
        TestUtil.dropSequence(_conn, "sercoltest_a_seq");
        TestUtil.createTable(_conn, "sercoltest", "a serial, b int");
    }

    protected void tearDown() throws Exception
    {
        TestUtil.dropSequence(_conn, "sercoltest_a_seq");
        TestUtil.dropTable(_conn, "sercoltest");
        TestUtil.closeDB( _conn );
    }

    public void testGetClientInfoProperties() throws Exception
    {
        DatabaseMetaData dbmd = _conn.getMetaData();

        ResultSet rs = dbmd.getClientInfoProperties();
        if (!TestUtil.haveMinimumServerVersion(_conn, "9.0")) {
            assertTrue( !rs.next() );
            return;
        }

        assertTrue(rs.next());
        assertEquals("ApplicationName", rs.getString("NAME"));
    }

    public void testGetColumnsForAutoIncrement() throws Exception
    {
        DatabaseMetaData dbmd = _conn.getMetaData();

        ResultSet rs = dbmd.getColumns("%","%","sercoltest", "%");
        assertTrue( rs.next() );
        assertEquals("a", rs.getString("COLUMN_NAME"));
        assertEquals("YES", rs.getString("IS_AUTOINCREMENT"));

        assertTrue( rs.next() );
        assertEquals("b", rs.getString("COLUMN_NAME"));
        assertEquals("NO", rs.getString("IS_AUTOINCREMENT"));

        assertTrue( !rs.next() );
    }

    public void testGetSchemas() throws SQLException
    {
        DatabaseMetaData dbmd = _conn.getMetaData();

        ResultSet rs = dbmd.getSchemas("", "publ%");

        if (!TestUtil.haveMinimumServerVersion(_conn, "7.3")) {
            assertTrue(!rs.next());
            return;
        }

        assertTrue(rs.next());
        assertEquals("public", rs.getString("TABLE_SCHEM"));
        assertNull(rs.getString("TABLE_CATALOG"));
        assertTrue(!rs.next());
    }
}