提交 9752cf23 authored 作者: Thomas Mueller's avatar Thomas Mueller

Tests

上级 f0ab8c9e
......@@ -25,7 +25,7 @@ public class TestCompatibility extends TestBase {
/**
* Run just this test.
*
*
* @param a ignored
*/
public static void main(String... a) throws Exception {
......
/*
* Copyright 2004-2013 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.test.db;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.util.Arrays;
import org.h2.test.TestBase;
import org.h2.tools.SimpleResultSet;
/**
* Test Oracle compatibility mode.
*/
public class TestCompatibilityOracle extends TestBase {
/**
* Run just this test.
*
* @param s ignored
*/
public static void main(String... s) throws Exception {
TestBase test = TestBase.createCaller().init();
test.test();
}
@Override
public void test() throws Exception {
testTreatEmptyStringsAsNull();
testDecimalScale();
}
private void testTreatEmptyStringsAsNull() throws SQLException {
deleteDb("oracle");
Connection conn = getConnection("oracle;MODE=Oracle");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE A (ID NUMBER, X VARCHAR2(1))");
stat.execute("INSERT INTO A VALUES (1, 'a')");
stat.execute("INSERT INTO A VALUES (2, '')");
stat.execute("INSERT INTO A VALUES (3, ' ')");
assertResult("3", stat, "SELECT COUNT(*) FROM A");
assertResult("1", stat, "SELECT COUNT(*) FROM A WHERE X IS NULL");
assertResult("2", stat, "SELECT COUNT(*) FROM A WHERE TRIM(X) IS NULL");
assertResult("0", stat, "SELECT COUNT(*) FROM A WHERE X = ''");
assertResult(new Object[][] { { 1, "a" }, { 2, null }, { 3, " " } }, stat, "SELECT * FROM A");
assertResult(new Object[][] { { 1, "a" }, { 2, null }, { 3, null } }, stat, "SELECT ID, TRIM(X) FROM A");
stat.execute("CREATE TABLE B (ID NUMBER, X NUMBER)");
stat.execute("INSERT INTO B VALUES (1, '5')");
stat.execute("INSERT INTO B VALUES (2, '')");
assertResult("2", stat, "SELECT COUNT(*) FROM B");
assertResult("1", stat, "SELECT COUNT(*) FROM B WHERE X IS NULL");
assertResult("0", stat, "SELECT COUNT(*) FROM B WHERE X = ''");
assertResult(new Object[][] { { 1, 5 }, { 2, null } }, stat, "SELECT * FROM B");
stat.execute("CREATE TABLE C (ID NUMBER, X TIMESTAMP)");
stat.execute("INSERT INTO C VALUES (1, '1979-11-12')");
stat.execute("INSERT INTO C VALUES (2, '')");
assertResult("2", stat, "SELECT COUNT(*) FROM C");
assertResult("1", stat, "SELECT COUNT(*) FROM C WHERE X IS NULL");
assertResult("0", stat, "SELECT COUNT(*) FROM C WHERE X = ''");
assertResult(new Object[][] { { 1, "1979-11-12 00:00:00.0" }, { 2, null } }, stat, "SELECT * FROM C");
stat.execute("CREATE TABLE D (ID NUMBER, X VARCHAR2(1))");
stat.execute("INSERT INTO D VALUES (1, 'a')");
stat.execute("SET @FOO = ''");
stat.execute("INSERT INTO D VALUES (2, @FOO)");
assertResult("2", stat, "SELECT COUNT(*) FROM D");
assertResult("1", stat, "SELECT COUNT(*) FROM D WHERE X IS NULL");
assertResult("0", stat, "SELECT COUNT(*) FROM D WHERE X = ''");
assertResult(new Object[][] { { 1, "a" }, { 2, null } }, stat, "SELECT * FROM D");
stat.execute("CREATE TABLE E (ID NUMBER, X RAW(1))");
stat.execute("INSERT INTO E VALUES (1, '0A')");
stat.execute("INSERT INTO E VALUES (2, '')");
assertResult("2", stat, "SELECT COUNT(*) FROM E");
assertResult("1", stat, "SELECT COUNT(*) FROM E WHERE X IS NULL");
assertResult("0", stat, "SELECT COUNT(*) FROM E WHERE X = ''");
assertResult(new Object[][] { { 1, new byte[] { 10 } }, { 2, null } }, stat, "SELECT * FROM E");
conn.close();
}
private void testDecimalScale() throws SQLException {
deleteDb("oracle");
Connection conn = getConnection("oracle;MODE=Oracle");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE A (ID NUMBER, X DECIMAL(9,5))");
stat.execute("INSERT INTO A VALUES (1, 2)");
stat.execute("INSERT INTO A VALUES (2, 4.3)");
stat.execute("INSERT INTO A VALUES (3, '6.78')");
assertResult("3", stat, "SELECT COUNT(*) FROM A");
assertResult(new Object[][] { { 1, 2 }, { 2, 4.3 }, { 3, 6.78 } }, stat, "SELECT * FROM A");
conn.close();
}
private void assertResult(Object[][] expectedRowsOfValues, Statement stat, String sql) throws SQLException {
assertResult(newSimpleResultSet(expectedRowsOfValues), stat, sql);
}
private void assertResult(ResultSet expected, Statement stat, String sql) throws SQLException {
ResultSet actual = stat.executeQuery(sql);
int expectedColumnCount = expected.getMetaData().getColumnCount();
assertEquals(expectedColumnCount, actual.getMetaData().getColumnCount());
while (true) {
boolean expectedNext = expected.next();
boolean actualNext = actual.next();
if (!expectedNext && !actualNext) {
return;
}
if (expectedNext != actualNext) {
fail("number of rows in actual and expected results sets does not match");
}
for (int i = 0; i < expectedColumnCount; i++) {
String expectedString = columnResultToString(expected.getObject(i + 1));
String actualString = columnResultToString(actual.getObject(i + 1));
assertEquals(expectedString, actualString);
}
}
}
private static String columnResultToString(Object object) {
if (object == null) {
return null;
}
if (object instanceof Object[]) {
return Arrays.deepToString((Object[]) object);
}
if (object instanceof byte[]) {
return Arrays.toString((byte[]) object);
}
return object.toString();
}
private static SimpleResultSet newSimpleResultSet(Object[][] rowsOfValues) {
SimpleResultSet result = new SimpleResultSet();
for (int i = 0; i < rowsOfValues[0].length; i++) {
result.addColumn(i + "", Types.JAVA_OBJECT, 0, 0);
}
for (int i = 0; i < rowsOfValues.length; i++) {
result.addRow(rowsOfValues[i]);
}
return result;
}
}
/*
* Copyright 2004-2013 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.test.db;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.util.Arrays;
import org.h2.test.TestBase;
import org.h2.tools.SimpleResultSet;
/**
* Test Oracle compatibility mode.
*/
public class TestCompatibilityOracle extends TestBase {
/**
* Run just this test.
*
* @param s ignored
*/
public static void main(String... s) throws Exception {
TestBase test = TestBase.createCaller().init();
test.test();
}
@Override
public void test() throws Exception {
testTreatEmptyStringsAsNull();
testDecimalScale();
}
private void testTreatEmptyStringsAsNull() throws SQLException {
deleteDb("oracle");
Connection conn = getConnection("oracle;MODE=Oracle");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE A (ID NUMBER, X VARCHAR2(1))");
stat.execute("INSERT INTO A VALUES (1, 'a')");
stat.execute("INSERT INTO A VALUES (2, '')");
stat.execute("INSERT INTO A VALUES (3, ' ')");
assertResult("3", stat, "SELECT COUNT(*) FROM A");
assertResult("1", stat, "SELECT COUNT(*) FROM A WHERE X IS NULL");
assertResult("2", stat, "SELECT COUNT(*) FROM A WHERE TRIM(X) IS NULL");
assertResult("0", stat, "SELECT COUNT(*) FROM A WHERE X = ''");
assertResult(new Object[][] { { 1, "a" }, { 2, null }, { 3, " " } }, stat, "SELECT * FROM A");
assertResult(new Object[][] { { 1, "a" }, { 2, null }, { 3, null } }, stat, "SELECT ID, TRIM(X) FROM A");
stat.execute("CREATE TABLE B (ID NUMBER, X NUMBER)");
stat.execute("INSERT INTO B VALUES (1, '5')");
stat.execute("INSERT INTO B VALUES (2, '')");
assertResult("2", stat, "SELECT COUNT(*) FROM B");
assertResult("1", stat, "SELECT COUNT(*) FROM B WHERE X IS NULL");
assertResult("0", stat, "SELECT COUNT(*) FROM B WHERE X = ''");
assertResult(new Object[][] { { 1, 5 }, { 2, null } }, stat, "SELECT * FROM B");
stat.execute("CREATE TABLE C (ID NUMBER, X TIMESTAMP)");
stat.execute("INSERT INTO C VALUES (1, '1979-11-12')");
stat.execute("INSERT INTO C VALUES (2, '')");
assertResult("2", stat, "SELECT COUNT(*) FROM C");
assertResult("1", stat, "SELECT COUNT(*) FROM C WHERE X IS NULL");
assertResult("0", stat, "SELECT COUNT(*) FROM C WHERE X = ''");
assertResult(new Object[][] { { 1, "1979-11-12 00:00:00.0" }, { 2, null } }, stat, "SELECT * FROM C");
stat.execute("CREATE TABLE D (ID NUMBER, X VARCHAR2(1))");
stat.execute("INSERT INTO D VALUES (1, 'a')");
stat.execute("SET @FOO = ''");
stat.execute("INSERT INTO D VALUES (2, @FOO)");
assertResult("2", stat, "SELECT COUNT(*) FROM D");
assertResult("1", stat, "SELECT COUNT(*) FROM D WHERE X IS NULL");
assertResult("0", stat, "SELECT COUNT(*) FROM D WHERE X = ''");
assertResult(new Object[][] { { 1, "a" }, { 2, null } }, stat, "SELECT * FROM D");
stat.execute("CREATE TABLE E (ID NUMBER, X RAW(1))");
stat.execute("INSERT INTO E VALUES (1, '0A')");
stat.execute("INSERT INTO E VALUES (2, '')");
assertResult("2", stat, "SELECT COUNT(*) FROM E");
assertResult("1", stat, "SELECT COUNT(*) FROM E WHERE X IS NULL");
assertResult("0", stat, "SELECT COUNT(*) FROM E WHERE X = ''");
assertResult(new Object[][] { { 1, new byte[] { 10 } }, { 2, null } }, stat, "SELECT * FROM E");
conn.close();
}
private void testDecimalScale() throws SQLException {
deleteDb("oracle");
Connection conn = getConnection("oracle;MODE=Oracle");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE A (ID NUMBER, X DECIMAL(9,5))");
stat.execute("INSERT INTO A VALUES (1, 2)");
stat.execute("INSERT INTO A VALUES (2, 4.3)");
stat.execute("INSERT INTO A VALUES (3, '6.78')");
assertResult("3", stat, "SELECT COUNT(*) FROM A");
assertResult(new Object[][] { { 1, 2 }, { 2, 4.3 }, { 3, 6.78 } }, stat, "SELECT * FROM A");
conn.close();
}
private void assertResult(Object[][] expectedRowsOfValues, Statement stat, String sql) throws SQLException {
assertResult(newSimpleResultSet(expectedRowsOfValues), stat, sql);
}
private void assertResult(ResultSet expected, Statement stat, String sql) throws SQLException {
ResultSet actual = stat.executeQuery(sql);
int expectedColumnCount = expected.getMetaData().getColumnCount();
assertEquals(expectedColumnCount, actual.getMetaData().getColumnCount());
while (true) {
boolean expectedNext = expected.next();
boolean actualNext = actual.next();
if (!expectedNext && !actualNext) {
return;
}
if (expectedNext != actualNext) {
fail("number of rows in actual and expected results sets does not match");
}
for (int i = 0; i < expectedColumnCount; i++) {
String expectedString = columnResultToString(expected.getObject(i + 1));
String actualString = columnResultToString(actual.getObject(i + 1));
assertEquals(expectedString, actualString);
}
}
}
private static String columnResultToString(Object object) {
if (object == null) {
return null;
}
if (object instanceof Object[]) {
return Arrays.deepToString((Object[]) object);
}
if (object instanceof byte[]) {
return Arrays.toString((byte[]) object);
}
return object.toString();
}
private static SimpleResultSet newSimpleResultSet(Object[][] rowsOfValues) {
SimpleResultSet result = new SimpleResultSet();
for (int i = 0; i < rowsOfValues[0].length; i++) {
result.addColumn(i + "", Types.JAVA_OBJECT, 0, 0);
}
for (int i = 0; i < rowsOfValues.length; i++) {
result.addRow(rowsOfValues[i]);
}
return result;
}
}
......@@ -41,7 +41,7 @@ public class TestDrop extends TestBase {
conn.close();
deleteDb("drop");
}
private void testTableDependsOnView() throws SQLException {
stat.execute("drop all objects");
stat.execute("create table a(x int)");
......@@ -60,7 +60,7 @@ public class TestDrop extends TestBase {
stat.execute("CREATE TABLE TEST_SCHEMA.B (B INT AS SELECT A FROM TEST_SCHEMA.A);");
stat.execute("DROP SCHEMA TEST_SCHEMA");
}
private void testInterSchemaDependency() throws SQLException {
stat.execute("drop all objects;");
stat.execute("create schema table_view");
......@@ -70,7 +70,8 @@ public class TestDrop extends TestBase {
stat.execute("set schema public");
stat.execute("create schema test_run");
stat.execute("set schema test_run");
stat.execute("create table test2 (vid int, address varchar(20), constraint a_cons check (vid in (select id from table_view.test1)))");
stat.execute("create table test2 (id int, address varchar(20), " +
"constraint a_cons check (id in (select id from table_view.test1)))");
stat.execute("set schema public");
stat.execute("drop all objects");
}
......
......@@ -19,7 +19,7 @@ public class TestDuplicateKeyUpdate extends TestBase {
/**
* Run just this test.
*
*
* @param a ignored
*/
public static void main(String... a) throws Exception {
......@@ -42,23 +42,31 @@ public class TestDuplicateKeyUpdate extends TestBase {
Statement stat = conn.createStatement();
ResultSet rs;
stat.execute("CREATE TABLE `table_test` (\n" + " `id` bigint(20) NOT NULL ,\n"
+ " `a_text` varchar(254) NOT NULL,\n" + " `some_text` varchar(254) NULL,\n"
+ " PRIMARY KEY (`id`)\n" + ") ;");
stat.execute("CREATE TABLE `table_test` (\n" +
" `id` bigint(20) NOT NULL ,\n" +
" `a_text` varchar(254) NOT NULL,\n" +
" `some_text` varchar(254) NULL,\n" +
" PRIMARY KEY (`id`)\n" +
") ;");
stat.execute("INSERT INTO table_test ( id, a_text, some_text ) VALUES (1, 'aaaaaaaaaa', 'aaaaaaaaaa')");
stat.execute("INSERT INTO table_test ( id, a_text, some_text ) VALUES (2, 'bbbbbbbbbb', 'bbbbbbbbbb')");
stat.execute("INSERT INTO table_test ( id, a_text, some_text ) VALUES (3, 'cccccccccc', 'cccccccccc')");
stat.execute("INSERT INTO table_test ( id, a_text, some_text ) VALUES (4, 'dddddddddd', 'dddddddddd')");
stat.execute("INSERT INTO table_test ( id, a_text, some_text ) VALUES (5, 'eeeeeeeeee', 'eeeeeeeeee')");
stat.execute("INSERT INTO table_test ( id, a_text, some_text ) VALUES " +
"(1, 'aaaaaaaaaa', 'aaaaaaaaaa'), " +
"(2, 'bbbbbbbbbb', 'bbbbbbbbbb'), "+
"(3, 'cccccccccc', 'cccccccccc'), " +
"(4, 'dddddddddd', 'dddddddddd'), " +
"(5, 'eeeeeeeeee', 'eeeeeeeeee')");
stat.execute("INSERT INTO table_test ( id , a_text, some_text ) VALUES (1, 'zzzzzzzzzz', 'abcdefghij') ON DUPLICATE KEY UPDATE some_text='UPDATE'");
stat.execute("INSERT INTO table_test ( id , a_text, some_text ) " +
"VALUES (1, 'zzzzzzzzzz', 'abcdefghij') " +
"ON DUPLICATE KEY UPDATE some_text='UPDATE'");
rs = stat.executeQuery("SELECT some_text FROM table_test where id = 1");
rs.next();
assertEquals("UPDATE", rs.getNString(1));
stat.execute("INSERT INTO table_test ( id , a_text, some_text ) VALUES (3, 'zzzzzzzzzz', 'SOME TEXT') ON DUPLICATE KEY UPDATE some_text=values(some_text)");
stat.execute("INSERT INTO table_test ( id , a_text, some_text ) " +
"VALUES (3, 'zzzzzzzzzz', 'SOME TEXT') " +
"ON DUPLICATE KEY UPDATE some_text=values(some_text)");
rs = stat.executeQuery("SELECT some_text FROM table_test where id = 3");
rs.next();
assertEquals("SOME TEXT", rs.getNString(1));
......@@ -80,36 +88,47 @@ public class TestDuplicateKeyUpdate extends TestBase {
stat.execute("INSERT INTO table_test2 ( a_text, some_text, updatable_text ) VALUES ('d', 'd', '4')");
stat.execute("INSERT INTO table_test2 ( a_text, some_text, updatable_text ) VALUES ('e', 'e', '5')");
stat.execute("INSERT INTO table_test2 ( a_text, some_text ) VALUES ('e', 'e') ON DUPLICATE KEY UPDATE updatable_text='UPDATE'");
stat.execute("INSERT INTO table_test2 ( a_text, some_text ) " +
"VALUES ('e', 'e') ON DUPLICATE KEY UPDATE updatable_text='UPDATE'");
rs = stat.executeQuery("SELECT updatable_text FROM table_test2 where a_text = 'e'");
rs.next();
assertEquals("UPDATE", rs.getNString(1));
stat.execute("INSERT INTO table_test2 (a_text, some_text, updatable_text ) VALUES ('b', 'b', 'jfno') ON DUPLICATE KEY UPDATE updatable_text=values(updatable_text)");
stat.execute("INSERT INTO table_test2 (a_text, some_text, updatable_text ) " +
"VALUES ('b', 'b', 'test') " +
"ON DUPLICATE KEY UPDATE updatable_text=values(updatable_text)");
rs = stat.executeQuery("SELECT updatable_text FROM table_test2 where a_text = 'b'");
rs.next();
assertEquals("jfno", rs.getNString(1));
assertEquals("test", rs.getNString(1));
}
private void testDuplicateCache(Connection conn) throws SQLException {
Statement stat = conn.createStatement();
ResultSet rs;
stat.execute("CREATE TABLE `table_test3` (\n" + " `id` bigint(20) NOT NULL ,\n"
+ " `a_text` varchar(254) NOT NULL,\n" + " `some_text` varchar(254) NULL,\n"
+ " PRIMARY KEY (`id`)\n" + ") ;");
stat.execute("CREATE TABLE `table_test3` (\n" +
" `id` bigint(20) NOT NULL ,\n" +
" `a_text` varchar(254) NOT NULL,\n" +
" `some_text` varchar(254) NULL,\n" +
" PRIMARY KEY (`id`)\n" +
") ;");
stat.execute("INSERT INTO table_test3 ( id, a_text, some_text ) VALUES (1, 'aaaaaaaaaa', 'aaaaaaaaaa')");
stat.execute("INSERT INTO table_test3 ( id, a_text, some_text ) " +
"VALUES (1, 'aaaaaaaaaa', 'aaaaaaaaaa')");
stat.execute("INSERT INTO table_test3 ( id , a_text, some_text ) VALUES (1, 'zzzzzzzzzz', 'SOME TEXT') ON DUPLICATE KEY UPDATE some_text=values(some_text)");
stat.execute("INSERT INTO table_test3 ( id , a_text, some_text ) " +
"VALUES (1, 'zzzzzzzzzz', 'SOME TEXT') " +
"ON DUPLICATE KEY UPDATE some_text=values(some_text)");
rs = stat.executeQuery("SELECT some_text FROM table_test3 where id = 1");
rs.next();
assertEquals("SOME TEXT", rs.getNString(1));
// Execute twice the same query to use the one from cache without
// parsing, caused the values parameter to be seen as ammbiguous
stat.execute("INSERT INTO table_test3 ( id , a_text, some_text ) VALUES (1, 'zzzzzzzzzz', 'SOME TEXT') ON DUPLICATE KEY UPDATE some_text=values(some_text)");
// parsing, caused the values parameter to be seen as ambiguous
stat.execute("INSERT INTO table_test3 ( id , a_text, some_text ) " +
"VALUES (1, 'zzzzzzzzzz', 'SOME TEXT') " +
"ON DUPLICATE KEY UPDATE some_text=values(some_text)");
rs = stat.executeQuery("SELECT some_text FROM table_test3 where id = 1");
rs.next();
assertEquals("SOME TEXT", rs.getNString(1));
......@@ -119,16 +138,24 @@ public class TestDuplicateKeyUpdate extends TestBase {
Statement stat = conn.createStatement();
ResultSet rs;
stat.execute("CREATE TABLE `table_test4` (\n" + " `id` bigint(20) NOT NULL ,\n"
+ " `a_text` varchar(254) NOT NULL,\n" + " `some_value` int(10) NULL,\n" + " PRIMARY KEY (`id`)\n"
+ ") ;");
stat.execute("INSERT INTO table_test4 ( id, a_text, some_value ) VALUES (1, 'aaaaaaaaaa', 5)");
stat.execute("INSERT INTO table_test4 ( id, a_text, some_value ) VALUES (2, 'aaaaaaaaaa', 5)");
stat.execute("INSERT INTO table_test4 ( id , a_text, some_value ) VALUES (1, 'b', 1) ON DUPLICATE KEY UPDATE some_value=some_value + values(some_value)");
stat.execute("INSERT INTO table_test4 ( id , a_text, some_value ) VALUES (1, 'b', 1) ON DUPLICATE KEY UPDATE some_value=some_value + 100");
stat.execute("INSERT INTO table_test4 ( id , a_text, some_value ) VALUES (2, 'b', 1) ON DUPLICATE KEY UPDATE some_value=values(some_value) + 1");
stat.execute("CREATE TABLE `table_test4` (\n" +
" `id` bigint(20) NOT NULL ,\n" +
" `a_text` varchar(254) NOT NULL,\n" +
" `some_value` int(10) NULL,\n" +
" PRIMARY KEY (`id`)\n" +
") ;");
stat.execute("INSERT INTO table_test4 ( id, a_text, some_value ) " +
"VALUES (1, 'aaaaaaaaaa', 5)");
stat.execute("INSERT INTO table_test4 ( id, a_text, some_value ) " +
"VALUES (2, 'aaaaaaaaaa', 5)");
stat.execute("INSERT INTO table_test4 ( id , a_text, some_value ) VALUES (1, 'b', 1) " +
"ON DUPLICATE KEY UPDATE some_value=some_value + values(some_value)");
stat.execute("INSERT INTO table_test4 ( id , a_text, some_value ) VALUES (1, 'b', 1) " +
"ON DUPLICATE KEY UPDATE some_value=some_value + 100");
stat.execute("INSERT INTO table_test4 ( id , a_text, some_value ) VALUES (2, 'b', 1) " +
"ON DUPLICATE KEY UPDATE some_value=values(some_value) + 1");
rs = stat.executeQuery("SELECT some_value FROM table_test4 where id = 1");
rs.next();
assertEquals(106, rs.getInt(1));
......
......@@ -28,6 +28,7 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.Currency;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Properties;
import java.util.TimeZone;
......@@ -702,7 +703,22 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertEquals(2, array.length);
assertEquals(0, ((Integer) array[0]).intValue());
assertEquals("Hello", (String) array[1]);
ResultSet rs2 = a.getResultSet();
assertThrows(ErrorCode.INVALID_VALUE_2, a).getArray(1, -1);
assertThrows(ErrorCode.INVALID_VALUE_2, a).getArray(1, 3);
assertEquals(0, ((Object[]) a.getArray(1, 0)).length);
assertEquals(0, ((Object[]) a.getArray(2, 0)).length);
assertThrows(ErrorCode.INVALID_VALUE_2, a).getArray(0, 0);
assertThrows(ErrorCode.INVALID_VALUE_2, a).getArray(3, 0);
HashMap<String, Class<?>> map = New.hashMap();
assertEquals(0, ((Object[]) a.getArray(1, 0, map)).length);
assertEquals(2, ((Object[]) a.getArray(map)).length);
assertEquals(2, ((Object[]) a.getArray(null)).length);
map.put("x", Object.class);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, a).getArray(1, 0, map);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, a).getArray(map);
ResultSet rs2;
rs2 = a.getResultSet();
rs2.next();
assertEquals(1, rs2.getInt(1));
assertEquals(0, rs2.getInt(2));
......@@ -711,6 +727,36 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertEquals("Hello", rs2.getString(2));
assertFalse(rs.next());
map.clear();
rs2 = a.getResultSet(map);
rs2.next();
assertEquals(1, rs2.getInt(1));
assertEquals(0, rs2.getInt(2));
rs2.next();
assertEquals(2, rs2.getInt(1));
assertEquals("Hello", rs2.getString(2));
assertFalse(rs.next());
rs2 = a.getResultSet(2, 1);
rs2.next();
assertEquals(2, rs2.getInt(1));
assertEquals("Hello", rs2.getString(2));
assertFalse(rs.next());
rs2 = a.getResultSet(1, 1, map);
rs2.next();
assertEquals(1, rs2.getInt(1));
assertEquals(0, rs2.getInt(2));
assertFalse(rs.next());
map.put("x", Object.class);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, a).getResultSet(map);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, a).getResultSet(0, 1, map);
a.free();
assertThrows(ErrorCode.OBJECT_CLOSED, a).getArray();
assertThrows(ErrorCode.OBJECT_CLOSED, a).getResultSet();
stat.execute("CREATE ALIAS ROOT FOR \"" + getClass().getName() + ".root\"");
rs = stat.executeQuery("CALL ROOT(9)");
rs.next();
......@@ -1174,12 +1220,12 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertResult(" 230 ", stat, "SELECT TO_CHAR(230, '999PR') FROM DUAL");
assertResult("230", stat, "SELECT TO_CHAR(230, 'FM999PR') FROM DUAL");
assertResult("0", stat, "SELECT TO_CHAR(0, 'fm999pr') FROM DUAL");
assertResult(" CCXXXVIII", stat, "SELECT TO_CHAR(238, 'RN') FROM DUAL");
assertResult("CCXXXVIII", stat, "SELECT TO_CHAR(238, 'FMRN') FROM DUAL");
assertResult("cxlix", stat, "SELECT TO_CHAR(149, 'FMrN') FROM DUAL");
assertResult(" MCMLXXIX", stat, "SELECT TO_CHAR(1979, 'RN') FROM DUAL;");
assertResult(" xliv", stat, "SELECT TO_CHAR(44, 'rN') FROM DUAL");
assertResult(" mdcclxxvi", stat, "SELECT TO_CHAR(1776, 'rn') FROM DUAL");
assertResult(" XI", stat, "SELECT TO_CHAR(11, 'RN') FROM DUAL");
assertResult("XI", stat, "SELECT TO_CHAR(11, 'FMRN') FROM DUAL");
assertResult("xi", stat, "SELECT TO_CHAR(11, 'FMrN') FROM DUAL");
assertResult(" XI", stat, "SELECT TO_CHAR(11, 'RN') FROM DUAL;");
assertResult(" xi", stat, "SELECT TO_CHAR(11, 'rN') FROM DUAL");
assertResult(" xi", stat, "SELECT TO_CHAR(11, 'rn') FROM DUAL");
assertResult(" +42", stat, "SELECT TO_CHAR(42, 'S999') FROM DUAL");
assertResult(" +42", stat, "SELECT TO_CHAR(42, 's999') FROM DUAL");
assertResult(" 42+", stat, "SELECT TO_CHAR(42, '999S') FROM DUAL");
......
......@@ -1561,7 +1561,7 @@ public class TestLob extends TestBase {
buffer[count] = ch;
}
} else if (ch >= 56192 && ch <= 56319) {
// private high surrogate, no effing clue, so skip it
// private high surrogate: no clue, so skip it
count++;
} else {
buffer[count] = ch;
......
......@@ -213,13 +213,13 @@ public class TestRights extends TestBase {
testTableType(conn, "CACHED");
/* make sure admin can still do it. */
executeSuccess("CREATE USER SCHEMA_CREATOR PASSWORD 'xyz'");
executeSuccess("CREATE SCHEMA SCHEMA_RIGHT_TEST");
executeSuccess("ALTER SCHEMA SCHEMA_RIGHT_TEST RENAME TO SCHEMA_RIGHT_TEST_RENAMED");
executeSuccess("DROP SCHEMA SCHEMA_RIGHT_TEST_RENAMED");
/* create this for tests below */
executeSuccess("CREATE SCHEMA SCHEMA_RIGHT_TEST_EXISTS");
executeSuccess("CREATE TABLE SCHEMA_RIGHT_TEST_EXISTS.TEST_EXISTS(ID INT PRIMARY KEY, NAME VARCHAR)");
......@@ -245,7 +245,7 @@ public class TestRights extends TestBase {
// try and succeed
conn = getConnection("rights;LOG=2", "SCHEMA_CREATOR", getPassword("xyz"));
stat = conn.createStatement();
/* should be able to create a schema and manipulate tables on that schema... */
executeSuccess("CREATE SCHEMA SCHEMA_RIGHT_TEST");
executeSuccess("ALTER SCHEMA SCHEMA_RIGHT_TEST RENAME TO S");
......@@ -262,7 +262,7 @@ public class TestRights extends TestBase {
executeSuccess("INSERT INTO TEST (ID, NAME) VALUES (42, 'Adams')");
executeSuccess("UPDATE TEST Set NAME = 'Douglas'");
executeSuccess("DELETE FROM TEST");
conn.close();
// revoke the right
......
......@@ -109,12 +109,12 @@ public class TestSequence extends TestBase {
stat.execute("create sequence a");
stat.execute("create sequence b start with 7 minvalue 5 maxvalue 9 cycle increment by 2 nocache");
stat.execute("create sequence c start with -4 minvalue -9 maxvalue -3 no cycle increment by -2 cache 3");
if (!config.memory) {
conn.close();
conn = getConnection("sequence");
}
stat = conn.createStatement();
ResultSet rs = stat.executeQuery("select * from information_schema.sequences order by sequence_name");
rs.next();
......@@ -286,12 +286,12 @@ public class TestSequence extends TestBase {
Connection conn = getConnection("sequence");
Statement stat = conn.createStatement();
stat.execute(setupSql);
if (!config.memory) {
conn.close();
conn = getConnection("sequence");
}
stat = conn.createStatement();
for (long value : values) {
assertEquals(value, getNext(stat));
......
......@@ -33,8 +33,8 @@ import org.h2.value.ValueGeometry;
* @author Nicolas Fortin, Atelier SIG, IRSTV FR CNRS 24888
*/
public class TestSpatial extends TestBase {
String url = "spatial";
private String url = "spatial";
/**
* Run just this test.
......@@ -51,15 +51,20 @@ public class TestSpatial extends TestBase {
return;
}
if (DataType.GEOMETRY_CLASS != null) {
deleteDb("spatial");
url = "spatial";
testSpatial();
url = "spatial;MV_STORE=false";
testSpatial();
deleteDb("spatial");
if (!config.mvcc) {
url = "spatial;MV_STORE=false";
testSpatial();
deleteDb("spatial");
}
}
}
private void testSpatial() throws SQLException {
testSpatialValues();
testOverlap();
......@@ -603,7 +608,7 @@ public class TestSpatial extends TestBase {
// expected
}
}
/**
* Check that geometry column type is kept with a table function
*/
......@@ -625,13 +630,20 @@ public class TestSpatial extends TestBase {
}
deleteDb("spatial");
}
/**
* This method is called via reflection from the database.
*
* @param x the x position of the point
* @param y the y position of the point
* @return a result set with this point
*/
public static ResultSet pointTable(double x, double y) {
GeometryFactory factory = new GeometryFactory();
SimpleResultSet srs = new SimpleResultSet();
srs.addColumn("THE_GEOM", Types.JAVA_OBJECT, "GEOMETRY", 0, 0);
srs.addRow(factory.createPoint(new Coordinate(x, y)));
return srs;
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("THE_GEOM", Types.JAVA_OBJECT, "GEOMETRY", 0, 0);
rs.addRow(factory.createPoint(new Coordinate(x, y)));
return rs;
}
}
......@@ -58,7 +58,7 @@ public class TestCallableStatement extends TestBase {
conn.close();
deleteDb("callableStatement");
}
private void testOutParameter(Connection conn) throws SQLException {
conn.createStatement().execute(
"create table test(id identity) as select null");
......@@ -73,7 +73,7 @@ public class TestCallableStatement extends TestBase {
conn.createStatement().execute(
"drop table test");
}
private void testUnsupportedOperations(Connection conn) throws SQLException {
CallableStatement call;
call = conn.prepareCall("select 10 as a");
......@@ -82,18 +82,18 @@ public class TestCallableStatement extends TestBase {
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getRef(1);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getRowId(1);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getSQLXML(1);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getURL("a");
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getObject("a", Collections.<String, Class<?>>emptyMap());
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getRef("a");
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getRowId("a");
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getSQLXML("a");
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).setURL(1, (URL) null);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).setRef(1, (Ref) null);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).setRowId(1, (RowId) null);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).setSQLXML(1, (SQLXML) null);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).setURL("a", (URL) null);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).setRowId("a", (RowId) null);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).setSQLXML("a", (SQLXML) null);
......@@ -120,7 +120,7 @@ public class TestCallableStatement extends TestBase {
call = conn.prepareCall("drop table test");
call.executeUpdate();
}
private void testGetters(Connection conn) throws SQLException {
CallableStatement call;
call = conn.prepareCall("{?=call ?}");
......@@ -141,7 +141,7 @@ public class TestCallableStatement extends TestBase {
call.registerOutParameter(1, Types.DOUBLE);
call.execute();
assertEquals(Math.PI, call.getDouble(1));
call.setBytes(2, new byte[11]);
call.registerOutParameter(1, Types.BINARY);
call.execute();
......@@ -152,7 +152,7 @@ public class TestCallableStatement extends TestBase {
call.registerOutParameter(1, Types.DATE);
call.execute();
assertEquals("2000-01-01", call.getDate(1).toString());
call.setTime(2, java.sql.Time.valueOf("01:02:03"));
call.registerOutParameter(1, Types.TIME);
call.execute();
......@@ -172,7 +172,7 @@ public class TestCallableStatement extends TestBase {
call.registerOutParameter(1, Types.SMALLINT);
call.execute();
assertEquals(123, call.getShort(1));
call.setBigDecimal(2, BigDecimal.TEN);
call.registerOutParameter(1, Types.DECIMAL);
call.execute();
......@@ -237,7 +237,7 @@ public class TestCallableStatement extends TestBase {
call.registerOutParameter(3, Types.TIMESTAMP);
call.registerOutParameter(4, Types.TIMESTAMP);
call.executeUpdate();
assertEquals(t + 1, call.getTimestamp(3).getTime());
assertEquals(t + 1, call.getTimestamp("C").getTime());
......@@ -264,7 +264,7 @@ public class TestCallableStatement extends TestBase {
assertEquals(100, call.getShort("A"));
assertTrue(call.getBoolean(1));
assertTrue(call.getBoolean("A"));
assertEquals("ABC", call.getString(2));
Reader r = call.getCharacterStream(2);
assertEquals("ABC", IOUtils.readStringAndClose(r, -1));
......@@ -277,7 +277,7 @@ public class TestCallableStatement extends TestBase {
assertEquals("ABC", call.getClob("B").getSubString(1, 3));
assertEquals("ABC", call.getNClob(2).getSubString(1, 3));
assertEquals("ABC", call.getNClob("B").getSubString(1, 3));
try {
call.getString(100);
fail("incorrect parameter index value");
......@@ -296,7 +296,7 @@ public class TestCallableStatement extends TestBase {
} catch (SQLException e) {
// expected exception
}
call.setCharacterStream("B", new StringReader("xyz"));
call.executeUpdate();
assertEquals("XYZ", call.getString("B"));
......@@ -315,7 +315,7 @@ public class TestCallableStatement extends TestBase {
call.setAsciiStream("B", new ByteArrayInputStream("xyz-".getBytes("UTF-8")), 3L);
call.executeUpdate();
assertEquals("XYZ", call.getString("B"));
call.setClob("B", new StringReader("xyz"));
call.executeUpdate();
assertEquals("XYZ", call.getString("B"));
......@@ -369,7 +369,7 @@ public class TestCallableStatement extends TestBase {
public static Boolean testClassF(Boolean b) {
return !b;
}
/**
* This method is called via reflection from the database.
*
......@@ -377,6 +377,7 @@ public class TestCallableStatement extends TestBase {
* @param a the value a
* @param b the value b
* @param c the value c
* @param d the value d
* @return a result set
*/
public static ResultSet testCall(Connection conn, int a, String b, Timestamp c, Timestamp d) throws SQLException {
......
......@@ -67,7 +67,7 @@ public class TestLobApi extends TestBase {
stat.execute("drop table test");
conn.close();
}
private void testUnsupportedOperations() throws Exception {
Connection conn = getConnection("lob");
stat = conn.createStatement();
......@@ -88,7 +88,7 @@ public class TestLobApi extends TestBase {
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, clob).position("", 0);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, clob).position((Clob) null, 0);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, clob).getCharacterStream(1, 1);
Blob blob = rs.getBlob(3);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, blob).truncate(0);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, blob).setBytes(1, new byte[0], 0, 0);
......@@ -98,7 +98,7 @@ public class TestLobApi extends TestBase {
assertTrue(blob.toString().endsWith("X'00'"));
blob.free();
assertTrue(blob.toString().endsWith("null"));
stat.execute("drop table test");
conn.close();
}
......@@ -217,26 +217,26 @@ public class TestLobApi extends TestBase {
out.write(data, 0, data.length);
out.close();
stat.execute("delete from test");
PreparedStatement prep = conn.prepareStatement("insert into test values(?, ?)");
prep.setInt(1, 1);
prep.setBlob(2, b);
prep.execute();
prep.setInt(1, 2);
b = conn.createBlob();
b.setBytes(1, data);
prep.setBlob(2, b);
prep.execute();
prep.setInt(1, 3);
prep.setBlob(2, new ByteArrayInputStream(data));
prep.execute();
prep.setInt(1, 4);
prep.setBlob(2, new ByteArrayInputStream(data), -1);
prep.execute();
ResultSet rs;
rs = stat.executeQuery("select * from test");
rs.next();
......@@ -278,17 +278,17 @@ public class TestLobApi extends TestBase {
out.close();
stat.execute("delete from test");
PreparedStatement prep = conn.prepareStatement("insert into test values(?, ?)");
prep.setInt(1, 1);
prep.setClob(2, c);
prep.execute();
c = conn.createClob();
c.setString(1, new String(data));
prep.setInt(1, 2);
prep.setClob(2, c);
prep.execute();
prep.setInt(1, 3);
prep.setCharacterStream(2, new StringReader(new String(data)));
prep.execute();
......@@ -303,7 +303,7 @@ public class TestLobApi extends TestBase {
prep.setInt(1, 5);
prep.setNClob(2, nc);
prep.execute();
prep.setInt(1, 5);
prep.setNClob(2, new StringReader(new String(data)));
prep.execute();
......
......@@ -57,7 +57,7 @@ public class TestMetaData extends TestBase {
testSessionsUncommitted();
testQueryStatistics();
}
private void testUnsupportedOperations() throws SQLException {
Connection conn = getConnection("metaData");
Statement stat = conn.createStatement();
......
......@@ -96,13 +96,13 @@ public class TestPreparedStatement extends TestBase {
testPreparedStatementWithLiteralsNone();
deleteDb("preparedStatement");
}
@SuppressWarnings("deprecation")
private void testUnsupportedOperations(Connection conn) throws Exception {
PreparedStatement prep = conn.prepareStatement("select ? from dual");
assertThrows(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT, prep).
addBatch("select 1");
assertThrows(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT, prep).
executeUpdate("create table test(id int)");
assertThrows(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT, prep).
......@@ -132,12 +132,12 @@ public class TestPreparedStatement extends TestBase {
setUnicodeStream(1, (InputStream) null, 0);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, prep).
setArray(1, (Array) null);
ParameterMetaData meta = prep.getParameterMetaData();
assertTrue(meta.toString(), meta.toString().endsWith("parameterCount=1"));
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, meta).isWrapperFor(Object.class);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, meta).unwrap(Object.class);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, conn).isWrapperFor(Object.class);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, conn).unwrap(Object.class);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, conn).createSQLXML();
......@@ -1034,24 +1034,41 @@ public class TestPreparedStatement extends TestBase {
rs.next();
assertEquals(1, rs.getInt(1));
assertFalse(rs.next());
prep = conn.prepareStatement("INSERT INTO TEST VALUES(NEXT VALUE FOR SEQ)", Statement.RETURN_GENERATED_KEYS);
prep = conn.prepareStatement("INSERT INTO TEST VALUES(NEXT VALUE FOR SEQ)",
Statement.RETURN_GENERATED_KEYS);
prep.execute();
rs = prep.getGeneratedKeys();
rs.next();
assertEquals(2, rs.getInt(1));
assertFalse(rs.next());
prep = conn.prepareStatement("INSERT INTO TEST VALUES(NEXT VALUE FOR SEQ)", new int[] { 1 });
prep = conn.prepareStatement("INSERT INTO TEST VALUES(NEXT VALUE FOR SEQ)",
new int[] { 1 });
prep.execute();
rs = prep.getGeneratedKeys();
rs.next();
assertEquals(3, rs.getInt(1));
assertFalse(rs.next());
prep = conn.prepareStatement("INSERT INTO TEST VALUES(NEXT VALUE FOR SEQ)", new String[] { "ID" });
prep = conn.prepareStatement("INSERT INTO TEST VALUES(NEXT VALUE FOR SEQ)",
new String[] { "ID" });
prep.execute();
rs = prep.getGeneratedKeys();
rs.next();
assertEquals(4, rs.getInt(1));
assertFalse(rs.next());
prep = conn.prepareStatement("INSERT INTO TEST VALUES(NEXT VALUE FOR SEQ)",
ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY,
ResultSet.HOLD_CURSORS_OVER_COMMIT);
prep.execute();
rs = prep.getGeneratedKeys();
rs.next();
assertEquals(5, rs.getInt(1));
assertFalse(rs.next());
stat.execute("DROP TABLE TEST");
}
......
......@@ -101,7 +101,7 @@ public class TestResultSet extends TestBase {
deleteDb("resultSet");
}
@SuppressWarnings("deprecation")
private void testUnsupportedOperations() throws SQLException {
ResultSet rs = stat.executeQuery("select 1 as x from dual");
......@@ -169,12 +169,12 @@ public class TestResultSet extends TestBase {
rs.getNClob("data").getCharacterStream(), -1));
rs = prep.executeQuery();
rs.moveToInsertRow();
rs.updateInt(1, 2);
rs.updateNString(2, "Hello");
rs.insertRow();
rs.moveToInsertRow();
rs.updateInt(1, 3);
rs.updateNString("data", "Hello");
......@@ -182,7 +182,7 @@ public class TestResultSet extends TestBase {
Clob c;
Writer w;
rs.moveToInsertRow();
rs.updateInt(1, 4);
c = conn.createClob();
......@@ -191,7 +191,7 @@ public class TestResultSet extends TestBase {
w.close();
rs.updateClob(2, c);
rs.insertRow();
rs.moveToInsertRow();
rs.updateInt(1, 5);
c = conn.createClob();
......@@ -200,7 +200,7 @@ public class TestResultSet extends TestBase {
w.close();
rs.updateClob("data", c);
rs.insertRow();
InputStream in;
rs.moveToInsertRow();
......@@ -214,7 +214,7 @@ public class TestResultSet extends TestBase {
in = new ByteArrayInputStream("Hello".getBytes("UTF-8"));
rs.updateAsciiStream("data", in);
rs.insertRow();
rs.moveToInsertRow();
rs.updateInt(1, 8);
in = new ByteArrayInputStream("Hello-".getBytes("UTF-8"));
......@@ -243,7 +243,7 @@ public class TestResultSet extends TestBase {
while (rs.next()) {
assertEquals("Hello", rs.getString(2));
}
stat.execute("drop table test");
}
......@@ -1224,7 +1224,7 @@ public class TestResultSet extends TestBase {
Object[] list = (Object[]) rs.getObject(2);
assertEquals(1, ((Integer) list[0]).intValue());
assertEquals(2, ((Integer) list[1]).intValue());
Array array = rs.getArray(2);
Object[] list2 = (Object[]) array.getArray();
assertEquals(1, ((Integer) list2[0]).intValue());
......@@ -1236,7 +1236,7 @@ public class TestResultSet extends TestBase {
list = (Object[]) rs.getObject(2);
assertEquals(11, ((Integer) list[0]).intValue());
assertEquals(12, ((Integer) list[1]).intValue());
array = rs.getArray("VALUE");
list2 = (Object[]) array.getArray();
assertEquals(11, ((Integer) list2[0]).intValue());
......@@ -1246,19 +1246,19 @@ public class TestResultSet extends TestBase {
list2 = (Object[]) array.getArray(Collections.<String, Class<?>>emptyMap());
assertEquals(11, ((Integer) list2[0]).intValue());
assertEquals(Types.NULL, array.getBaseType());
assertEquals("NULL", array.getBaseTypeName());
assertTrue(array.toString().endsWith(": (11, 12)"));
// free
array.free();
assertEquals("null", array.toString());
assertThrows(ErrorCode.OBJECT_CLOSED, array).getBaseType();
assertThrows(ErrorCode.OBJECT_CLOSED, array).getBaseTypeName();
assertThrows(ErrorCode.OBJECT_CLOSED, array).getResultSet();
assertFalse(rs.next());
stat.execute("DROP TABLE TEST");
}
......
......@@ -8,14 +8,19 @@ package org.h2.test.jdbc;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLClientInfoException;
import java.sql.SQLException;
import java.sql.Savepoint;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Properties;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.jdbc.JdbcStatement;
import org.h2.store.fs.FileUtils;
import org.h2.test.TestBase;
import org.h2.util.New;
/**
* Tests for the Statement implementation.
......@@ -47,11 +52,20 @@ public class TestStatement extends TestBase {
conn.close();
deleteDb("statement");
}
private void testUnsupportedOperations() throws Exception {
Statement stat = conn.createStatement();
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, stat).isWrapperFor(Object.class);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, stat).unwrap(Object.class);
conn.setTypeMap(null);
HashMap<String, Class<?>> map = New.hashMap();
conn.setTypeMap(map);
map.put("x", Object.class);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, conn).setTypeMap(map);
assertThrows(SQLClientInfoException.class, conn).setClientInfo("X", "Y");
assertThrows(SQLClientInfoException.class, conn).setClientInfo(new Properties());
}
private void testTraceError() throws Exception {
......@@ -120,6 +134,7 @@ public class TestStatement extends TestBase {
assertTrue(id1 != id2);
stat.execute("UPDATE TEST SET NAME='Hallo' WHERE NAME='Hello'");
Savepoint savepointTest = conn.setSavepoint("Joe's");
assertTrue(savepointTest.toString().endsWith("name=Joe's"));
stat.execute("DELETE FROM TEST");
assertEquals(savepointTest.getSavepointName(), "Joe's");
assertThrows(ErrorCode.SAVEPOINT_IS_NAMED, savepointTest).
......@@ -145,6 +160,10 @@ public class TestStatement extends TestBase {
conn.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, conn.getHoldability());
assertFalse(stat.isPoolable());
stat.setPoolable(true);
assertFalse(stat.isPoolable());
// ignored
stat.setCursorName("x");
// fixed return value
......
......@@ -157,11 +157,11 @@ public class TestUpdatableResultSet extends TestBase {
rs.updateInt(1, 10);
rs.updateRow();
rs.next();
rs.updateString(2, "Welt");
rs.cancelRowUpdates();
rs.updateString(2, "Welt");
rs.updateRow();
rs.beforeFirst();
rs.next();
......@@ -170,11 +170,11 @@ public class TestUpdatableResultSet extends TestBase {
rs.next();
assertEquals(2, rs.getInt(1));
assertEquals("Welt", rs.getString(2));
assertFalse(rs.isClosed());
rs.close();
assertTrue(rs.isClosed());
conn.close();
}
......@@ -386,7 +386,7 @@ public class TestUpdatableResultSet extends TestBase {
rs.updateNClob(15, new StringReader("\u00ef\u00f6\u00fc"));
rs.updateBlob(16, b);
rs.insertRow();
rs.moveToInsertRow();
rs.updateInt("ID", 9);
rs.updateNClob("CL", new StringReader("\u00ef\u00f6\u00fc"), -1);
......@@ -398,7 +398,7 @@ public class TestUpdatableResultSet extends TestBase {
rs.updateNClob(15, new StringReader("\u00ef\u00f6\u00fc"), -1);
rs.updateBlob(16, b);
rs.insertRow();
rs.moveToInsertRow();
rs.updateInt("ID", 11);
rs.updateNCharacterStream("CL", new StringReader("\u00ef\u00f6\u00fc"), -1);
......@@ -486,7 +486,7 @@ public class TestUpdatableResultSet extends TestBase {
assertEquals(new byte[] { (byte) 0xab, 0x12 }, rs.getBytes(16));
}
assertFalse(rs.next());
stat.execute("DROP TABLE TEST");
conn.close();
}
......@@ -502,7 +502,16 @@ public class TestUpdatableResultSet extends TestBase {
for (int i = 0; i < max; i++) {
stat.execute("INSERT INTO TEST VALUES(" + i + ", 'Hello" + i + "')");
}
ResultSet rs = stat.executeQuery("SELECT * FROM TEST");
ResultSet rs;
rs = stat.executeQuery("SELECT * FROM TEST ORDER BY ID");
rs.next();
assertEquals(0, rs.getInt(1));
rs.moveToInsertRow();
rs.updateInt(1, 100);
rs.moveToCurrentRow();
assertEquals(0, rs.getInt(1));
rs = stat.executeQuery("SELECT * FROM TEST");
int j = max;
while (rs.next()) {
int id = rs.getInt(1);
......@@ -521,13 +530,13 @@ public class TestUpdatableResultSet extends TestBase {
assertFalse(rs.rowUpdated());
assertFalse(rs.rowInserted());
assertFalse(rs.rowDeleted());
rs.moveToInsertRow();
rs.updateString(2, "Inserted " + j);
rs.updateInt(1, j);
j += 2;
rs.insertRow();
// the driver does not detect it in any case
assertFalse(rs.rowUpdated());
assertFalse(rs.rowInserted());
......
......@@ -9,15 +9,8 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Statement;
import org.h2.mvstore.Chunk;
import org.h2.mvstore.MVStore;
import org.h2.mvstore.Page;
import org.h2.mvstore.db.TransactionStore;
import org.h2.store.fs.FileUtils;
import org.h2.test.TestBase;
import org.h2.util.Profiler;
import org.h2.value.ValueLong;
import org.h2.value.ValueString;
/**
* Tests performance and helps analyze bottlenecks.
......@@ -42,8 +35,12 @@ public class TestBenchmark extends TestBase {
test(true);
test(false);
}
private void test(boolean mvStore) throws Exception {
;
// TODO this test is currently disabled
FileUtils.deleteRecursive(getBaseDir(), true);
Connection conn;
Statement stat;
......@@ -51,21 +48,19 @@ public class TestBenchmark extends TestBase {
if (mvStore) {
url += ";MV_STORE=TRUE;LOG=0";
}
// 2033 mvstore
// 2313 (2075?) default
url = getURL(url, true);
conn = getConnection(url);
stat = conn.createStatement();
stat.execute("create table test(id bigint primary key, name varchar)");
conn.setAutoCommit(false);
PreparedStatement prep = conn.prepareStatement("insert into test values(?, ?)");
PreparedStatement prep = conn
.prepareStatement("insert into test values(?, ?)");
String data = "Hello World";
int rowCount = 100000;
int readCount = 20* rowCount;
int readCount = 20 * rowCount;
for (int i = 0; i < rowCount; i++) {
prep.setInt(1, i);
prep.setString(2, data);
......@@ -76,44 +71,16 @@ public class TestBenchmark extends TestBase {
}
long start = System.currentTimeMillis();
// Profiler prof = new Profiler();
// prof.sumClasses=true;
// prof.startCollecting();
;
prep = conn.prepareStatement("select * from test where id = ?");
for (int i = 0; i < readCount; i++) {
prep.setInt(1, i % rowCount);
prep.executeQuery();
}
//System.out.println("Transactionstore.counter " + ValueLong.counter);
//System.out.println("count " + Page.writeCount + " avgLen " + (1.0*Page.writeLength/Page.writeCount) + " avgSize " + (1.0*Page.writeSize/Page.writeCount));
//System.out.println(prof.getTop(5));
//System.out.println("ountUnc:" + counterUnc);
//System.out.println("ount:" + counter);
System.out.println((System.currentTimeMillis() - start) + " " + (mvStore ? "mvstore" : "default"));
System.out.println((System.currentTimeMillis() - start) + " "
+ (mvStore ? "mvstore" : "default"));
conn.close();
// MVStore s = new MVStore.Builder().fileName(getBaseDir() + "/mvstore.mv.db").open();
// int count = 0;
// long length = 0;
// for(String k : s.getMetaMap().keyList()) {
// if (k.startsWith("chunk.")) {
// String x = s.getMetaMap().get(k);
// Chunk c = Chunk.fromString(x);
// if (c.length < Integer.MAX_VALUE) {
// count++;
// length += c.length;
// }
// }
// }
// if (count > 0) {
// System.out.println("chunks: " + count + " average length: " + (length / count));
// }
// s.close();
}
}
......@@ -42,7 +42,7 @@ public class TestDataUtils extends TestBase {
testCheckValue();
testPagePos();
}
private static void testWriteBuffer() {
WriteBuffer buff = new WriteBuffer();
buff.put(new byte[1500000]);
......
......@@ -907,7 +907,7 @@ public class TestMVStore extends TestBase {
// close the store (this will persist changes)
s.close();
s = MVStore.open(fileName);
map = s.openMap("data");
assertEquals("Hello World", map.get(1));
......
......@@ -125,7 +125,7 @@ public class TestMVTableEngine extends TestBase {
stat.execute("insert into test select x, space(100) from system_range(1, 1000)");
// this table is kept
if (i < 10) {
stat.execute("create table test" + i + "(id int primary key, data varchar) " +
stat.execute("create table test" + i + "(id int primary key, data varchar) " +
"as select x, space(10) from system_range(1, 100)");
}
// force writing the chunk
......
......@@ -57,7 +57,7 @@ public class TestTransactionStore extends TestBase {
testSingleConnection();
testCompareWithPostgreSQL();
}
private void testRepeatedChange() {
MVStore s;
TransactionStore ts;
......@@ -74,14 +74,14 @@ public class TestTransactionStore extends TestBase {
for (int i = 0; i < 2000; i++) {
map.put(1, i);
}
Transaction tx2 = ts.begin();
TransactionMap<Integer, Integer> map2 = tx2.openMap("data");
assertEquals(-1, map2.get(1).intValue());
s.close();
}
private void testTransactionAge() throws Exception {
MVStore s;
TransactionStore ts;
......
......@@ -38,6 +38,7 @@ public class TestBnf extends TestBase {
deleteDb("bnf");
Connection conn = getConnection("bnf");
try {
testModes(conn);
testProcedures(conn, false);
} finally {
conn.close();
......@@ -49,6 +50,34 @@ public class TestBnf extends TestBase {
conn.close();
}
}
private void testModes(Connection conn) throws Exception {
DbContents dbContents;
dbContents = new DbContents();
dbContents.readContents("jdbc:h2:test", conn);
assertTrue(dbContents.isH2());
dbContents = new DbContents();
dbContents.readContents("jdbc:derby:test", conn);
assertTrue(dbContents.isDerby());
dbContents = new DbContents();
dbContents.readContents("jdbc:firebirdsql:test", conn);
assertTrue(dbContents.isFirebird());
dbContents = new DbContents();
dbContents.readContents("jdbc:sqlserver:test", conn);
assertTrue(dbContents.isMSSQLServer());
dbContents = new DbContents();
dbContents.readContents("jdbc:mysql:test", conn);
assertTrue(dbContents.isMySQL());
dbContents = new DbContents();
dbContents.readContents("jdbc:oracle:test", conn);
assertTrue(dbContents.isOracle());
dbContents = new DbContents();
dbContents.readContents("jdbc:postgresql:test", conn);
assertTrue(dbContents.isPostgreSQL());
dbContents = new DbContents();
dbContents.readContents("jdbc:sqlite:test", conn);
assertTrue(dbContents.isSQLite());
}
private void testProcedures(Connection conn, boolean isMySQLMode) throws Exception {
// Register a procedure and check if it is present in DbContents
......@@ -57,7 +86,7 @@ public class TestBnf extends TestBase {
conn.createStatement().execute("DROP TABLE IF EXISTS TABLE_WITH_STRING_FIELD");
conn.createStatement().execute("CREATE TABLE TABLE_WITH_STRING_FIELD (STRING_FIELD VARCHAR(50), INT_FIELD integer)");
DbContents dbContents = new DbContents();
dbContents.readContents(conn.getMetaData());
dbContents.readContents("jdbc:h2:test", conn);
assertTrue(dbContents.isH2());
assertFalse(dbContents.isDerby());
assertFalse(dbContents.isFirebird());
......
......@@ -44,7 +44,7 @@ public class TestCollation extends TestBase {
// not allowed to change now
assertThrows(ErrorCode.COLLATION_CHANGE_WITH_DATA_TABLE_1, stat).
execute("set collation en");
conn.close();
deleteDb("collation");
}
......
......@@ -31,6 +31,7 @@ import org.h2.mvstore.DataUtils;
import org.h2.mvstore.cache.FilePathCache;
import org.h2.store.fs.FilePath;
import org.h2.store.fs.FilePathEncrypt;
import org.h2.store.fs.FilePathRec;
import org.h2.store.fs.FileUtils;
import org.h2.test.TestBase;
import org.h2.test.utils.AssertThrows;
......@@ -65,6 +66,7 @@ public class TestFileSystem extends TestBase {
testUnsupportedFeatures(getBaseDir());
FilePathZip2.register();
FilePath.register(new FilePathCache());
FilePathRec.register();
testZipFileSystem("zip:");
testZipFileSystem("cache:zip:");
testZipFileSystem("zip2:");
......@@ -85,6 +87,7 @@ public class TestFileSystem extends TestBase {
testFileSystem("memLZF:");
testFileSystem("nioMemFS:");
testFileSystem("nioMemLZF:");
testFileSystem("rec:memFS:");
testUserHome();
try {
testFileSystem("nio:" + getBaseDir() + "/fs");
......
......@@ -48,7 +48,7 @@ public class TestPgServer extends TestBase {
testCancelQuery();
testBinaryTypes();
}
private void testLowerCaseIdentifiers() throws SQLException {
if (!getPgJdbcDriver()) {
return;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论