提交 bd27766a authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 7365295e
......@@ -35,7 +35,8 @@ Hypersonic SQL or HSQLDB. H2 is built from scratch.
<h3>Version 1.0 (Current)</h3>
<h3>Version 1.0 / 2007-TODO</h3><ul>
<li>
<li>It was possible to drop the sequence of a temporary tables with DROP ALL OBJECTS, resulting in a null pointer exception afterwards.
<li>Prepard statements with non-constant functions such as CURRENT_TIMESTAMP() did not get re-evaluated if the result of the function changed. Fixed.
<li>The (relative or absolute) directory where the script files are stored or read can now be changed using the system property h2.scriptDirectory
<li>Client trace files now created in the directory 'trace.db' and no longer the application directory.
This can be changed using the system property h2.clientTraceDirectory.
......
......@@ -111,7 +111,7 @@ public class CreateTable extends SchemaCommand {
Column c = (Column) columns.get(i);
if(c.getAutoIncrement()) {
int objId = getObjectId(true, true);
c.convertAutoIncrementToSequence(session, getSchema(), objId);
c.convertAutoIncrementToSequence(session, getSchema(), objId, temporary);
}
Sequence seq = c.getSequence();
if(seq != null) {
......
......@@ -66,6 +66,7 @@ public class DropDatabase extends DefineCommand {
db.removeSchemaObject(session, t);
}
}
session.findLocalTempTable(null);
list = db.getAllSchemaObjects(DbObject.SEQUENCE);
// maybe constraints and triggers on system tables will be allowed in the future
list.addAll(db.getAllSchemaObjects(DbObject.CONSTRAINT));
......
......@@ -1398,6 +1398,9 @@ public class Function extends Expression implements FunctionCall {
}
public boolean isEverything(ExpressionVisitor visitor) {
if(visitor.type == ExpressionVisitor.DETERMINISTIC && !info.isDeterministic) {
return false;
}
for (int i = 0; i < args.length; i++) {
Expression e = args[i];
if (e != null && !e.isEverything(visitor)) {
......
......@@ -74,7 +74,7 @@ public class Sequence extends SchemaObject {
value += increment;
return v;
}
public void flush() throws SQLException {
// can not use the session, because it must be committed immediately
// otherwise other threads can not access the sys table.
......
......@@ -208,7 +208,7 @@ public class Column {
}
}
public void convertAutoIncrementToSequence(Session session, Schema schema, int id) throws SQLException {
public void convertAutoIncrementToSequence(Session session, Schema schema, int id, boolean temporary) throws SQLException {
if(!getAutoIncrement()) {
throw Message.getInternalError();
}
......@@ -225,7 +225,9 @@ public class Column {
Sequence sequence = new Sequence(schema, id, sequenceName, true);
sequence.setStartValue(start);
sequence.setIncrement(increment);
session.getDatabase().addSchemaObject(session, sequence);
if(!temporary) {
session.getDatabase().addSchemaObject(session, sequence);
}
setAutoIncrement(false, 0, 0);
SequenceValue seq = new SequenceValue(sequence);
setDefaultExpression(session, seq);
......
......@@ -144,7 +144,9 @@ public abstract class Table extends SchemaObject {
while(sequences != null && sequences.size() > 0) {
Sequence sequence = (Sequence)sequences.get(0);
sequences.remove(0);
database.removeSchemaObject(session, sequence);
if(!getTemporary()) {
database.removeSchemaObject(session, sequence);
}
}
ObjectArray rights = database.getAllRights();
for(int i=0; i<rights.size(); i++) {
......
......@@ -87,18 +87,9 @@ java -Xmx512m -Xrunhprof:cpu=samples,depth=8 org.h2.tools.RunScript -url jdbc:h2
TestAll test = new TestAll();
test.printSystem();
// here is a difference in behavior between the 9-24-2006 H2.jar and the later jars.
// Or it simply could be I didn't see a feature change in the docs.
// In my code, this statement in 9-24 works:
// SELECT ID FROM EVE_ALARMS WHERE TIME_ESCALATE = true AND ACTIVE = true AND current_timestamp() > NEXT_TIME_ESCALATION
// in latest versions, the query returns zero rows.
// Most of my queries are preparedStatements that are prepared once at process startup.
// Things I have tested:
// 1. Run the query in the H2 console. SUCCESS
// 2. Generate a preparedStatement each time it is needed. SUCCESS
// 3. Generate a preparedStatement, save the statement to a instance variable for reuse. FAIL
// There are several queries that use current_timestamp, but I think the cache is saving the original time value, ie not recalculating. This may be because there are no parameters set in the statement. The other queries that use current_timestamp have parameters that must be set, which I thinking causes the time value to be recalculated.
// I will try and put together a simple test case this week. Unless this a configuration issue and I need to RTFM. :)
// Expression.isConstant is not really needed?
// test: use fixed amount of disk space
// append errors from all programs atomically to errors.txt (use nio file lock mechanism)
// ftp client
......
......@@ -5,6 +5,8 @@
package org.h2.test;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.Reader;
import java.sql.Connection;
import java.sql.DriverManager;
......@@ -17,6 +19,8 @@ import java.text.SimpleDateFormat;
import java.util.Properties;
import org.h2.jdbc.JdbcConnection;
import org.h2.message.TraceSystem;
import org.h2.store.FileLock;
import org.h2.tools.DeleteDbFiles;
/**
......@@ -55,8 +59,7 @@ public abstract class TestBase {
test();
println("done ");
} catch(Exception e) {
println("FAIL " + e.toString());
e.printStackTrace();
fail("FAIL " + e.toString(), e);
if(config.stopOnError) {
throw new Error("ERROR");
}
......@@ -206,6 +209,32 @@ public abstract class TestBase {
throw new Exception(string);
}
protected void fail(String s, Throwable e) {
println(s);
logError(s, e);
}
public static void logError(String s, Throwable e) {
if(e==null) {
e = new Exception(s);
}
System.out.println("ERROR: " + s + " " + e.toString() + " ------------------------------");
e.printStackTrace();
try {
TraceSystem ts = new TraceSystem(null);
FileLock lock = new FileLock(ts, 1000);
lock.lock("error.lock", false);
FileWriter fw = new FileWriter("ERROR.txt", true);
PrintWriter pw = new PrintWriter(fw);
e.printStackTrace(pw);
pw.close();
fw.close();
lock.unlock();
} catch(Throwable t) {
t.printStackTrace();
}
}
protected void println(String s) {
printlnWithTime(s);
}
......@@ -520,8 +549,7 @@ public abstract class TestBase {
protected void checkNotGeneralException(SQLException e) throws Exception {
if(e!=null && e.getSQLState().startsWith("HY000")) {
e.printStackTrace();
error("Unexpected General error: " + e.toString());
TestBase.logError("Unexpected General error", e);
}
}
......
......@@ -253,7 +253,7 @@ class Database {
ResultSet rs = prep.executeQuery();
// time = System.currentTimeMillis() - time;
// if(time > 100) {
// new Error("time="+time).printStackTrace();
// System.out.println("time="+time);
// }
executedStatements++;
return rs;
......
......@@ -4,8 +4,10 @@
*/
package org.h2.test.cases;
import java.sql.*;
import java.util.Random;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
/*
del *.db
......@@ -15,41 +17,16 @@ java org.h2.test.cases.TestConnect
public class TestConnect {
public static void main(String[] args) throws Exception {
Class.forName("org.h2.Driver");
long time = System.currentTimeMillis();
String url = "jdbc:h2:test;LOG=2;STORAGE=TEXT;DATABASE_EVENT_LISTENER='org.h2.samples.ShowProgress'";
String url = "jdbc:h2:test";
Connection conn = DriverManager.getConnection(url, "sa", "sa");
time = System.currentTimeMillis() - time;
System.out.println("connected in " + time);
ResultSet rs = conn.getMetaData().getTables(null, null, "TEST", null);
Random random = new Random(1);
if(!rs.next()) {
conn.createStatement().execute("CREATE TABLE TEST(ID IDENTITY, NAME VARCHAR)");
PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST(NAME) VALUES(space(2000))");
// PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST(NAME) VALUES(space(20000))");
int len = 5000;
for(int i=0; i<len; i++) {
long t2 = System.currentTimeMillis();
if(t2 - time > 1000) {
System.out.println("Inserting " + i + " of " + len);
time = t2;
}
prep.executeUpdate();
}
prep = conn.prepareStatement("UPDATE TEST SET NAME = space(2000) WHERE ID=?");
for(int i=0; i<len; i++) {
long t2 = System.currentTimeMillis();
if(t2 - time > 1000) {
System.out.println("Updating " + i + " of " + len);
time = t2;
}
prep.setInt(1, random.nextInt(len));
prep.executeUpdate();
}
// @LOOP 50000 UPDATE TEST SET NAME=space(20000) WHERE ID=?/*RND*/;
Thread.sleep(2000);
Runtime.getRuntime().halt(0);
}
PreparedStatement prep = conn.prepareStatement("SELECT CURRENT_TIMESTAMP()");
ResultSet rs = prep.executeQuery();
rs.next();
System.out.println(rs.getString(1));
Thread.sleep(50);
rs = prep.executeQuery();
rs.next();
System.out.println(rs.getString(1));
conn.close();
}
......
......@@ -92,7 +92,7 @@ public class TestBigDb extends TestBase {
}
}
} catch(OutOfMemoryError e) {
e.printStackTrace();
TestBase.logError("memory", e);
conn.close();
throw e;
}
......
......@@ -153,7 +153,7 @@ public class TestCases extends TestBase {
try {
ResultSet rs = stat.executeQuery("SELECT MAX(T.ID) FROM TEST T, TEST, TEST, TEST, TEST, TEST, TEST, TEST, TEST, TEST, TEST");
rs.next();
new Error("query was too quick; result: " + rs.getInt(1)).printStackTrace();
TestBase.logError("query was too quick; result: " + rs.getInt(1), null);
} catch(SQLException e) {
// ok
}
......
......@@ -96,8 +96,8 @@ public class TestCsv extends TestBase {
for(int i=0; i<len; i++) {
stat.execute("INSERT INTO TEST(NAME) VALUES('Ruebezahl')");
}
Csv.getInstance().write(conn, BASE_DIR + "/test.csv", "SELECT * FROM TEST", "UTF8");
ResultSet rs = Csv.getInstance().read(BASE_DIR + "/test.csv", null, "UTF8");
Csv.getInstance().write(conn, BASE_DIR + "/testRW.csv", "SELECT * FROM TEST", "UTF8");
ResultSet rs = Csv.getInstance().read(BASE_DIR + "/testRW.csv", null, "UTF8");
// stat.execute("CREATE ALIAS CSVREAD FOR \"org.h2.tools.Csv.read\"");
ResultSetMetaData meta = rs.getMetaData();
check(2, meta.getColumnCount());
......@@ -107,6 +107,7 @@ public class TestCsv extends TestBase {
check(rs.getString("NAME"), "Ruebezahl");
}
checkFalse(rs.next());
rs.close();
conn.close();
}
......
......@@ -229,7 +229,7 @@ public class TestFunctions extends TestBase {
public static int root(int value) {
if (value < 0) {
new Exception("function called but should not").printStackTrace();
TestBase.logError("function called but should not", null);
}
return (int) Math.sqrt(value);
}
......
......@@ -47,7 +47,7 @@ public class TestListener extends TestBase implements DatabaseEventListener {
}
public void exceptionThrown(SQLException e) {
e.printStackTrace();
TestBase.logError("exceptionThrown", e);
}
public void setProgress(int state, String name, int current, int max) {
......@@ -68,7 +68,7 @@ public class TestListener extends TestBase implements DatabaseEventListener {
stateName = "Recover";
break;
default:
new Error("unknownn state: " + state).printStackTrace();
TestBase.logError("unknownn state: " + state, null);
stateName = "? " + name;
}
try {
......
......@@ -52,7 +52,7 @@ public class TestMultiConn extends TestBase implements DatabaseEventListener {
s3.execute("INSERT INTO TEST2 VALUES(4)");
conn3.commit();
} catch(SQLException e) {
e.printStackTrace();
TestBase.logError("insert", e);
}
}
});
......@@ -64,7 +64,7 @@ public class TestMultiConn extends TestBase implements DatabaseEventListener {
s2.execute("INSERT INTO TEST1 VALUES(5)");
conn2.commit();
} catch(SQLException e) {
e.printStackTrace();
TestBase.logError("insert", e);
}
}
});
......@@ -101,7 +101,7 @@ public class TestMultiConn extends TestBase implements DatabaseEventListener {
Connection c1 = getConnection("multiConn;DATABASE_EVENT_LISTENER='"+listener+"';file_lock=socket");
c1.close();
} catch(Exception e) {
e.printStackTrace();
TestBase.logError("connect", e);
}
}
};
......@@ -126,7 +126,7 @@ public class TestMultiConn extends TestBase implements DatabaseEventListener {
Thread.sleep(wait);
wait = 0;
} catch (InterruptedException e) {
e.printStackTrace();
TestBase.logError("sleep", e);
}
}
}
......
......@@ -78,8 +78,7 @@ public class TestMultiThread extends TestBase implements Runnable {
}
conn.close();
} catch(Exception e) {
e.printStackTrace();
System.exit(0);
logError("multi", e);
}
}
......
......@@ -76,8 +76,7 @@ public class TestOpenClose extends TestBase implements DatabaseEventListener {
prep.execute();
conn.close();
} catch(Throwable e) {
// e.printStackTrace();
System.out.println("FAIL: " + e.toString());
TestBase.logError("insert", e);
}
}
};
......
......@@ -21,6 +21,7 @@ public class TestOptimizations extends TestBase {
if(config.networked) {
return;
}
testQueryCacheTimestamp();
testQueryCacheSpeed();
testQueryCache(true);
testQueryCache(false);
......@@ -29,6 +30,21 @@ public class TestOptimizations extends TestBase {
testMinMaxCountOptimization(false);
}
private void testQueryCacheTimestamp() throws Exception {
deleteDb("optimizations");
Connection conn=getConnection("optimizations");
PreparedStatement prep = conn.prepareStatement("SELECT CURRENT_TIMESTAMP()");
ResultSet rs = prep.executeQuery();
rs.next();
String a = rs.getString(1);
Thread.sleep(50);
rs = prep.executeQuery();
rs.next();
String b = rs.getString(1);
checkFalse(a.equals(b));
conn.close();
}
private void testQueryCacheSpeed() throws Exception {
deleteDb("optimizations");
Connection conn=getConnection("optimizations");
......
......@@ -77,7 +77,7 @@ public class TestPowerOff extends TestBase {
conn.close();
} catch(SQLException e) {
if(!e.getSQLState().equals("90098")) {
e.printStackTrace();
TestBase.logError("power", e);
}
}
}
......@@ -228,8 +228,6 @@ public class TestPowerOff extends TestBase {
} else {
throw e;
}
//log("error="+e);
// e.printStackTrace();
}
return state;
}
......
......@@ -325,11 +325,11 @@ public class TestScript extends TestBase {
errors.append("\ngot: ");
errors.append(s);
errors.append("\n");
if(e!=null) {
e.printStackTrace();
if(e != null) {
TestBase.logError("script", e);
}
if(failFast) {
new Exception(errors.toString()).printStackTrace();
TestBase.logError(errors.toString(), null);
conn.close();
System.exit(1);
}
......
command=cmd /c "del /s /q /f *.* 2> nul | rmdir /s /q data dataCrash dataIndex dataJoin dataScript dataSynth trace.db org 2> nul"
\ No newline at end of file
command=cmd /c "del /s /q /f *.* 2> nul | rmdir /s /q data dataCrash dataIndex dataJoin dataScript dataSynth trace.db org 2> nul | rmdir /s /q data 2> nul"
\ No newline at end of file
......@@ -29,7 +29,7 @@ public class TestCancel extends TestBase {
} catch (SQLException e) {
// ignore errors on closed statements
} catch(Exception e) {
e.printStackTrace();
TestBase.logError("sleep", e);
}
}
}
......
......@@ -9,6 +9,8 @@ import java.io.StringWriter;
import java.sql.*;
import java.util.*;
import org.h2.test.TestBase;
class Result implements Comparable {
static final int SUCCESS=0, BOOLEAN=1, INT=2, EXCEPTION=3, RESULTSET=4;
private int type;
......@@ -62,8 +64,7 @@ class Result implements Comparable {
} catch(SQLException e) {
// type = EXCEPTION;
// exception = e;
e.printStackTrace();
throw new Error("error reading result set");
TestBase.logError("error reading result set", e);
}
}
......
......@@ -70,7 +70,7 @@ public class TestBtreeIndex extends TestBase {
if(e.getSQLState().equals("23001")) {
// ignore
} else {
e.printStackTrace();
TestBase.logError("error", e);
break;
}
}
......@@ -85,7 +85,7 @@ public class TestBtreeIndex extends TestBase {
}
count -= deleted;
} catch(SQLException e) {
e.printStackTrace();
TestBase.logError("error", e);
break;
}
} else {
......@@ -98,7 +98,7 @@ public class TestBtreeIndex extends TestBase {
}
count -= deleted;
} catch(SQLException e) {
e.printStackTrace();
TestBase.logError("error", e);
break;
}
}
......
......@@ -202,8 +202,7 @@ public class TestCrashAPI extends TestBase {
StringWriter writer = new StringWriter();
t.printStackTrace(new PrintWriter(writer));
String s = writer.toString();
System.out.println("new TestCrashAPI().init(test).testCase("+seed+"); // Bug " + s.hashCode()+" seed="+seed+" id=" + id + " callCount=" + callCount+" openCount="+openCount + " " + t.getMessage());
t.printStackTrace();
TestBase.logError("new TestCrashAPI().init(test).testCase("+seed+"); // Bug " + s.hashCode()+" seed="+seed+" id=" + id + " callCount=" + callCount+" openCount="+openCount + " " + t.getMessage(), t);
}
private Object callRandom(int seed, int id, int objectId, Object o, Method m) throws Exception {
......@@ -217,9 +216,9 @@ public class TestCrashAPI extends TestBase {
callCount++;
result = m.invoke(o, params);
} catch (IllegalArgumentException e) {
e.printStackTrace();
TestBase.logError("error", e);
} catch (IllegalAccessException e) {
e.printStackTrace();
TestBase.logError("error", e);
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
printIfBad(seed, id, objectId, t);
......
......@@ -246,7 +246,6 @@ public class TestJoin extends TestBase {
s = "updateCount: " + stat.getUpdateCount();
}
} catch(SQLException e) {
// e.printStackTrace();
s = "exception";
}
if(i==0) {
......
......@@ -10,6 +10,7 @@ import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.Random;
import org.h2.test.TestBase;
import org.h2.tools.FileBase;
public class TestKillProcess {
......@@ -58,7 +59,7 @@ public class TestKillProcess {
}
}
} catch(Throwable e) {
e.printStackTrace();
TestBase.logError("error", e);
}
}
......
......@@ -7,6 +7,8 @@ package org.h2.test.synth;
import java.sql.SQLException;
import java.util.Random;
import org.h2.test.TestBase;
abstract class TestMultiThread extends Thread {
TestMulti base;
......@@ -29,8 +31,7 @@ abstract class TestMultiThread extends Thread {
}
end();
} catch(Throwable e) {
e.printStackTrace();
System.out.println("FAIL: " + e.toString());
TestBase.logError("error", e);
}
}
......
......@@ -27,10 +27,8 @@ public class TestRandomSQL extends TestBase {
private void processException(String sql, SQLException e) {
if(e.getSQLState().equals("HY000")) {
System.out.println("new TestRandomSQL().init(test).testCase("+seed+"); // FAIL: " + e.toString());
e.printStackTrace();
TestBase.logError("new TestRandomSQL().init(test).testCase("+seed+"); // FAIL: " + e.toString(), e);
if(exitOnError) {
new Error(sql, e).printStackTrace();
System.exit(0);
}
}
......
......@@ -103,7 +103,7 @@ public class TestSynth extends TestBase {
add(Command.getCreateTable(this, table));
add(Command.getCreateIndex(this, table.newRandomIndex()));
}
for(int i=0; i<400; i++) {
for(int i=0; i<2000; i++) {
addRandomCommands();
}
// for (int i = 0; i < 20; i++) {
......@@ -165,7 +165,7 @@ public class TestSynth extends TestBase {
} catch(Error e) {
if(showError) {
e.printStackTrace();
TestBase.logError("synth", e);
}
System.out.println("new TestSynth().init(test).testCase(" + seed+"); // id="+id +" " + e.toString());
if(stopImmediately) {
......@@ -262,8 +262,7 @@ public class TestSynth extends TestBase {
printTime("TestSynth " + i);
testRun(i);
} catch (Error e) {
System.out.println(e.toString());
e.printStackTrace();
TestBase.logError("error", e);
System.exit(0);
}
BASE_DIR = "data";
......
......@@ -145,7 +145,7 @@ public class TestThreads extends TestBase implements Runnable {
}
conn.close();
} catch(Exception e) {
e.printStackTrace();
TestBase.logError("error", e);
}
}
......
......@@ -103,7 +103,7 @@ public class TestExit extends TestBase implements DatabaseEventListener {
try {
getClosedFile().createNewFile();
} catch(IOException e) {
e.printStackTrace();
TestBase.logError("error", e);
}
}
......
......@@ -96,7 +96,6 @@ public class TestFileLock extends TestBase implements Runnable {
}
} catch (Exception e) {
// log(id+" cannot lock: " + e);
// e.printStackTrace();
}
try {
Thread.sleep(wait + (int) (Math.random() * wait));
......
......@@ -49,8 +49,7 @@ public class TestSampleApps extends TestBase {
try {
m.invoke(null, new Object[]{args});
} catch(Throwable e) {
System.out.print("EXCEPTION");
e.printStackTrace();
TestBase.logError("error", e);
}
out.flush();
System.setOut(oldOut);
......
......@@ -68,7 +68,7 @@ public class TestStringCache extends TestBase {
try {
check(a, b);
} catch (Exception e) {
e.printStackTrace();
TestBase.logError("error", e);
}
if(a != null && a == b && a.length()>0) {
throw new Error("a=" + System.identityHashCode(a) + " b=" + System.identityHashCode(b));
......@@ -83,7 +83,7 @@ public class TestStringCache extends TestBase {
try {
check(a, b);
} catch (Exception e) {
e.printStackTrace();
TestBase.logError("error", e);
}
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论