forked from pgjdbc/pgjdbc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DatabaseMetaDataTest.java
97 lines (77 loc) · 2.58 KB
/
DatabaseMetaDataTest.java
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
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* Copyright (c) 2007, PostgreSQL Global Development Group
* See the LICENSE file in the project root for more information.
*/
package org.postgresql.test.jdbc4;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.postgresql.core.ServerVersion;
import org.postgresql.test.TestUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
public class DatabaseMetaDataTest {
private Connection _conn;
@Before
public void setUp() throws Exception {
_conn = TestUtil.openDB();
TestUtil.dropSequence(_conn, "sercoltest_a_seq");
TestUtil.createTable(_conn, "sercoltest", "a serial, b int");
}
@After
public void tearDown() throws Exception {
TestUtil.dropSequence(_conn, "sercoltest_a_seq");
TestUtil.dropTable(_conn, "sercoltest");
TestUtil.closeDB(_conn);
}
@Test
public void testGetClientInfoProperties() throws Exception {
DatabaseMetaData dbmd = _conn.getMetaData();
ResultSet rs = dbmd.getClientInfoProperties();
if (!TestUtil.haveMinimumServerVersion(_conn, ServerVersion.v9_0)) {
assertTrue(!rs.next());
return;
}
assertTrue(rs.next());
assertEquals("ApplicationName", rs.getString("NAME"));
}
@Test
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());
}
@Test
public void testGetSchemas() throws SQLException {
DatabaseMetaData dbmd = _conn.getMetaData();
ResultSet rs = dbmd.getSchemas("", "publ%");
assertTrue(rs.next());
assertEquals("public", rs.getString("TABLE_SCHEM"));
assertNull(rs.getString("TABLE_CATALOG"));
assertTrue(!rs.next());
}
@Test
public void testSortedDataTypes() throws SQLException {
// https://github.com/pgjdbc/pgjdbc/issues/716
DatabaseMetaData dbmd = _conn.getMetaData();
ResultSet rs = dbmd.getTypeInfo();
int lastType = Integer.MIN_VALUE;
while (rs.next()) {
int type = rs.getInt("DATA_TYPE");
assertTrue(lastType <= type);
lastType = type;
}
rs.close();
}
}