提交 280c7a28 authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 b6686049
...@@ -9,11 +9,11 @@ package org.h2.samples; ...@@ -9,11 +9,11 @@ package org.h2.samples;
import java.math.BigInteger; import java.math.BigInteger;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.sql.Types; import java.sql.Types;
import org.h2.tools.SimpleResultSet; import org.h2.tools.SimpleResultSet;
/** /**
...@@ -32,6 +32,8 @@ public class Function { ...@@ -32,6 +32,8 @@ public class Function {
Class.forName("org.h2.Driver"); Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:mem:", "sa", ""); Connection conn = DriverManager.getConnection("jdbc:h2:mem:", "sa", "");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
// Using a custom Java function
stat.execute("CREATE ALIAS IS_PRIME FOR \"org.h2.samples.Function.isPrime\" "); stat.execute("CREATE ALIAS IS_PRIME FOR \"org.h2.samples.Function.isPrime\" ");
ResultSet rs; ResultSet rs;
rs = stat.executeQuery("SELECT IS_PRIME(X), X FROM SYSTEM_RANGE(1, 20) ORDER BY X"); rs = stat.executeQuery("SELECT IS_PRIME(X), X FROM SYSTEM_RANGE(1, 20) ORDER BY X");
...@@ -42,6 +44,22 @@ public class Function { ...@@ -42,6 +44,22 @@ public class Function {
System.out.println(x + " is prime"); System.out.println(x + " is prime");
} }
} }
// Calling the built-in 'table' function
stat.execute("CREATE TABLE TEST(ID INT) AS " +
"SELECT X FROM SYSTEM_RANGE(1, 100)");
PreparedStatement prep;
prep = conn.prepareStatement("SELECT * FROM TABLE(X INT=?, O INT=?) J " +
"INNER JOIN TEST T ON J.X=T.ID ORDER BY J.O");
prep.setObject(1,
new Integer[] { new Integer(30), new Integer(20) });
prep.setObject(2,
new Integer[] { new Integer(1), new Integer(2) });
ResultSet rs2 = prep.executeQuery();
while (rs2.next()) {
System.out.println(rs2.getInt(1));
}
conn.close(); conn.close();
} }
......
...@@ -283,7 +283,12 @@ java org.h2.test.TestAll timer ...@@ -283,7 +283,12 @@ java org.h2.test.TestAll timer
/* /*
arc line breaks in grammar (specially select)
test performance with log=2
maybe make log=2 the default option
TRANSACTION_ID()
select 1 from dual a where 1 in(select 1 from dual b select 1 from dual a where 1 in(select 1 from dual b
where 1 in(select 1 from dual c where a.x=1)); where 1 in(select 1 from dual c where a.x=1));
......
...@@ -49,8 +49,14 @@ public class TestBitField extends TestBase { ...@@ -49,8 +49,14 @@ public class TestBitField extends TestBase {
} }
private void testNextClearBit() { private void testNextClearBit() {
Random random = new Random(1); BitSet set = new BitSet();
BitField field = new BitField(); BitField field = new BitField();
set.set(0, 640);
field.setRange(0, 640, true);
assertEquals(set.nextClearBit(0), field.nextClearBit(0));
Random random = new Random(1);
field = new BitField();
field.setRange(0, 500, true); field.setRange(0, 500, true);
for (int i = 0; i < 100000; i++) { for (int i = 0; i < 100000; i++) {
int a = random.nextInt(120); int a = random.nextInt(120);
......
...@@ -7,7 +7,9 @@ ...@@ -7,7 +7,9 @@
package org.h2.test.unit; package org.h2.test.unit;
import java.io.File; import java.io.File;
import java.sql.SQLException;
import org.h2.engine.Constants;
import org.h2.message.TraceSystem; import org.h2.message.TraceSystem;
import org.h2.store.FileLock; import org.h2.store.FileLock;
import org.h2.test.TestBase; import org.h2.test.TestBase;
...@@ -35,11 +37,37 @@ public class TestFileLock extends TestBase implements Runnable { ...@@ -35,11 +37,37 @@ public class TestFileLock extends TestBase implements Runnable {
this.allowSockets = allowSockets; this.allowSockets = allowSockets;
} }
/**
* Run just this test.
*
* @param a ignored
*/
public static void main(String[] a) throws Exception {
TestBase.createCaller().init().test();
}
public void test() throws Exception { public void test() throws Exception {
testSimple();
test(false); test(false);
test(true); test(true);
} }
private void testSimple() throws SQLException {
FileLock lock1 = new FileLock(new TraceSystem(null, false), FILE, Constants.LOCK_SLEEP);
FileLock lock2 = new FileLock(new TraceSystem(null, false), FILE, Constants.LOCK_SLEEP);
lock1.lock(FileLock.LOCK_FILE);
try {
lock2.lock(FileLock.LOCK_FILE);
fail();
} catch (Exception e) {
// expected
}
lock1.unlock();
lock2 = new FileLock(new TraceSystem(null, false), FILE, Constants.LOCK_SLEEP);
lock2.lock(FileLock.LOCK_FILE);
lock2.unlock();
}
private void test(boolean allowSockets) throws Exception { private void test(boolean allowSockets) throws Exception {
int threadCount = getSize(3, 5); int threadCount = getSize(3, 5);
wait = getSize(20, 200); wait = getSize(20, 200);
......
...@@ -17,6 +17,15 @@ import org.h2.value.CompareMode; ...@@ -17,6 +17,15 @@ import org.h2.value.CompareMode;
*/ */
public class TestPattern extends TestBase { public class TestPattern extends TestBase {
/**
* Run just this test.
*
* @param a ignored
*/
public static void main(String[] a) throws Exception {
TestBase.createCaller().init().test();
}
public void test() throws SQLException { public void test() throws SQLException {
CompareMode mode = new CompareMode(null, null, 100); CompareMode mode = new CompareMode(null, null, 100);
CompareLike comp = new CompareLike(mode, null, null, null, false); CompareLike comp = new CompareLike(mode, null, null, null, false);
......
...@@ -20,6 +20,15 @@ import org.h2.util.IOUtils; ...@@ -20,6 +20,15 @@ import org.h2.util.IOUtils;
*/ */
public class TestReader extends TestBase { public class TestReader extends TestBase {
/**
* Run just this test.
*
* @param a ignored
*/
public static void main(String[] a) throws Exception {
TestBase.createCaller().init().test();
}
public void test() throws Exception { public void test() throws Exception {
String s = "\u00ef\u00f6\u00fc"; String s = "\u00ef\u00f6\u00fc";
StringReader r = new StringReader(s); StringReader r = new StringReader(s);
......
...@@ -19,6 +19,15 @@ import org.h2.tools.DeleteDbFiles; ...@@ -19,6 +19,15 @@ import org.h2.tools.DeleteDbFiles;
*/ */
public class TestRecovery extends TestBase { public class TestRecovery extends TestBase {
/**
* Run just this test.
*
* @param a ignored
*/
public static void main(String[] a) throws Exception {
TestBase.createCaller().init().test();
}
public void test() throws SQLException { public void test() throws SQLException {
DeleteDbFiles.execute(baseDir, "recovery", true); DeleteDbFiles.execute(baseDir, "recovery", true);
org.h2.Driver.load(); org.h2.Driver.load();
......
...@@ -20,6 +20,15 @@ import org.h2.util.StringUtils; ...@@ -20,6 +20,15 @@ import org.h2.util.StringUtils;
*/ */
public class TestSampleApps extends TestBase { public class TestSampleApps extends TestBase {
/**
* Run just this test.
*
* @param a ignored
*/
public static void main(String[] a) throws Exception {
TestBase.createCaller().init().test();
}
public void test() throws Exception { public void test() throws Exception {
deleteDb("optimizations"); deleteDb("optimizations");
String url = "jdbc:h2:" + baseDir + "/optimizations"; String url = "jdbc:h2:" + baseDir + "/optimizations";
...@@ -32,7 +41,7 @@ public class TestSampleApps extends TestBase { ...@@ -32,7 +41,7 @@ public class TestSampleApps extends TestBase {
+ "PHONE: +41123456789\n\n" + "NAME: John Jones\n" + "EMAIL: john.jones@abcde.abc\n" + "PHONE: +41123456789\n\n" + "NAME: John Jones\n" + "EMAIL: john.jones@abcde.abc\n"
+ "PHONE: +41976543210\n"); + "PHONE: +41976543210\n");
testApp(org.h2.samples.Function.class, null, testApp(org.h2.samples.Function.class, null,
"2 is prime\n3 is prime\n5 is prime\n7 is prime\n11 is prime\n13 is prime\n17 is prime\n19 is prime"); "2 is prime\n3 is prime\n5 is prime\n7 is prime\n11 is prime\n13 is prime\n17 is prime\n19 is prime\n30\n20");
// Not compatible with PostgreSQL JDBC driver (throws a NullPointerException) // Not compatible with PostgreSQL JDBC driver (throws a NullPointerException)
//testApp(org.h2.samples.SecurePassword.class, null, "Joe"); //testApp(org.h2.samples.SecurePassword.class, null, "Joe");
// TODO test ShowProgress (percent numbers are hardware specific) // TODO test ShowProgress (percent numbers are hardware specific)
......
...@@ -135,7 +135,8 @@ public class GenerateDoc { ...@@ -135,7 +135,8 @@ public class GenerateDoc {
String topic = rs.getString("TOPIC"); String topic = rs.getString("TOPIC");
String syntax = rs.getString("SYNTAX"); String syntax = rs.getString("SYNTAX");
syntax = PageParser.escapeHtml(syntax); syntax = PageParser.escapeHtml(syntax);
syntax = StringUtils.replaceAll(syntax, "<br />", " "); // if enabled, HTML docs get very wide
// syntax = StringUtils.replaceAll(syntax, "<br />", " ");
syntax = bnf.getSyntaxHtml(syntax); syntax = bnf.getSyntaxHtml(syntax);
map.put("syntax", syntax); map.put("syntax", syntax);
String link = topic.toLowerCase(); String link = topic.toLowerCase();
......
...@@ -581,4 +581,4 @@ titles headers grew orchestration social razor finder ranging friend intervals ...@@ -581,4 +581,4 @@ titles headers grew orchestration social razor finder ranging friend intervals
bot jot delicious rife appenders circles spelling cash sky ecm nuxeo poland bot jot delicious rife appenders circles spelling cash sky ecm nuxeo poland
opengeospatial sfs symmetric obsolete failing parenthesis unloading refreshed opengeospatial sfs symmetric obsolete failing parenthesis unloading refreshed
grails reloading slightly accepting deploying conflicting recovered counters grails reloading slightly accepting deploying conflicting recovered counters
versus extracts squirrel misdirected rle looking arc versus extracts squirrel misdirected rle looking arc addressed european
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论