提交 7365295e authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 71ec2fd8
......@@ -628,7 +628,7 @@ custom certificates are supported as well.
<br /><a name="uuid"></a>
<h2>Universally Unique Identifiers (UUID)</h2>
This database supports the UUIDs, and function to create new value using
This database supports UUIDs. Also upported is a function to create new UUIDs using
a cryptographically strong pseudo random number generator.
With random UUIDs, the chance of two having the same value can be calculated
using the probability theory. See also 'Birthday Paradox'.
......@@ -695,6 +695,8 @@ INFORMATION_SCHEMA.SETTINGS
<tr><td>h2.objectCache</td><td>true</td><td>Cache commonly used objects (integers, strings)</td></tr>
<tr><td>h2.objectCacheSize</td><td>1024</td><td>Size of object cache</td></tr>
<tr><td>h2.objectCacheMaxPerElementSize</td><td>4096</td><td>Maximum size of an object in the cache</td></tr>
<tr><td>h2.clientTraceDirectory</td><td>trace.db/</td><td>Directory where the trace files of the JDBC client are stored (only for client / server)</td></tr>
<tr><td>h2.scriptDirectory</td><td></td><td>Relative or absolute directory where the script files are stored to or read from</td></tr>
</table>
<br /><a name="glossary_links"></a>
......
......@@ -35,6 +35,10 @@ 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>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.
<li>In some situations the log file got corrupt if the process was terminated while the database was opening.
<li>Using ;RECOVER=1 in the database URL threw a syntax exception. Fixed.
<li>If a CLOB or BLOB was deleted in a transaction and the database crashed before the transaction was committed or rolled back,
......@@ -1336,8 +1340,6 @@ Hypersonic SQL or HSQLDB. H2 is built from scratch.
<h3>Highest Priority</h3>
<ul>
<li>Improve the documentation
<li>Add a migration guide (list differences between databases)
<li>Improve test code coverage
<li>More fuzz tests
<li>Test very large databases and LOBs (up to 256 GB)
......@@ -1369,7 +1371,7 @@ Hypersonic SQL or HSQLDB. H2 is built from scratch.
<li>Fix right outer joins
<li>Full outer joins
<li>Index organized tables: CREATE TABLE...(...) ORGANIZATION INDEX
<li>Long running queries / errors / trace system table.
<li>Long running queries / errors / trace system table
<li>Migrate database tool (also from other database engines)
<li>Shutdown compact
<li>Optimization of distinct with index: select distinct name from test
......@@ -1389,6 +1391,7 @@ Hypersonic SQL or HSQLDB. H2 is built from scratch.
<ul>
<li>Support OSGi: http://oscar-osgi.sourceforge.net, http://incubator.apache.org/felix/index.html
<li>Connection pool manager
<li>Add a migration guide (list differences between databases)
<li>Support VALUES(1), (2); SELECT * FROM (VALUES (1), (1), (1), (1), (2)) AS myTable (c1) (Derby)
<li>Optimization: automatic index creation suggestion using the trace file?
<li>Compression performance: don't allocate buffers, compress / expand in to out buffer
......@@ -1423,6 +1426,7 @@ Hypersonic SQL or HSQLDB. H2 is built from scratch.
<li>Web server classloader: override findResource / getResourceFrom
<li>Cost for embedded temporary view is calculated wrong, if result is constant
<li>Comparison: pluggable sort order: natural sort
<li>Count index range query (count(*) where id between 10 and 20)
<li>Eclipse plugin
<li>iReport to support H2
<li>Implement CallableStatement
......@@ -1467,7 +1471,6 @@ Hypersonic SQL or HSQLDB. H2 is built from scratch.
<li>Functional tables should accept parameters from other tables (see FunctionMultiReturn)
SELECT * FROM TEST T, P2C(T.A, T.R)
<li>Custom class loader to reload functions on demand
<li>Count index range query (count where id between 10 and 20)
<li>Test http://mysql-je.sourceforge.net/
<li>Close all files when closing the database (including LOB files that are open on the client side)
<li>Test Connection Pool http://jakarta.apache.org/commons/dbcp
......@@ -1607,6 +1610,10 @@ Hypersonic SQL or HSQLDB. H2 is built from scratch.
<li>Public interface for functions (not public static)
<li>Index usage for IN(...), IN_ARRAY(..), and IN_ARRAY_RANGES(..); support ARRAY in JDBC API (variable size)
<li>Change LOB mechanism (less files, keep index of lob files, point to files and row, delete unused files earlier)
<li>Autocomplete: if I type the name of a table that does not exist (should say: syntax not supported)
<li>Autocomplete: schema support: "Other Grammar","Table Expression","{[schemaName.]tableName | (select)} [[AS] newTableAlias]
<li>Functions: options readonly, deterministic
<li>Document FTP server, including -ftpTask option to execute / kill remote processes
</ul>
<h3>Not Planned</h3>
......
......@@ -27,6 +27,8 @@ Tutorial
CSV (Comma Separated Values) Support</a><br />
<a href="#upgrade_backup_restore">
Upgrade, Backup, and Restore</a><br />
<a href="#openoffice">
Using OpenOffice Base</a><br />
<br /><a name="tutorial_starting_h2_console"></a>
<h2>Starting and Using the H2 Console</h2>
......@@ -425,5 +427,19 @@ SQL script files may contain references to other script files, in the form of
RUNSCRIPT commands. However, when using the server mode, the references script files
need to be available on the server side.
<br /><a name="openoffice"></a>
<h2>Using OpenOffice Base</h2>
OpenOffice.org Base supports database access over the JDBC API. To connect to a H2 database
using OpenOffice Base, you first need to add the JDBC driver to OpenOffice.
The steps to connect to a H2 database are:
<ul>
<li>Stop OpenOffice, including the autostart
<li>Copy h2.jar into the directory &lt;OpenOffice&gt;\program\classes
<li>Start OpenOffice Base
<li>Connect to an existing database, select JDBC, [Next]
<li>Example datasource URL: jdbc:h2:c:/temp/test
<li>JDBC driver class: org.h2.Driver
</ul>
Now you can access the database stored in the directory C:/temp.
</div></td></tr></table></body></html>
\ No newline at end of file
......@@ -60,7 +60,10 @@ public class ScriptBase extends Prepared implements DataHandler {
}
public void setFileName(String fileName) {
this.fileName = fileName;
if(fileName == null || fileName.trim().length() == 0) {
fileName = "script.sql";
}
this.fileName = Constants.SCRIPT_DIRECTORY + fileName;
}
public boolean isTransactional() {
......
......@@ -233,6 +233,8 @@ public class Constants {
public static final boolean OBJECT_CACHE = getBooleanSetting("h2.objectCache", true);
public static final int OBJECT_CACHE_SIZE = getIntSetting("h2.objectCacheSize", 1024);
public static final int OBJECT_CACHE_MAX_PER_ELEMENT_SIZE = getIntSetting("h2.objectCacheMaxPerElementSize", 4096);
public static final String CLIENT_TRACE_DIRECTORY = getStringSetting("h2.clientTraceDirectory", "trace.db/");
public static String SCRIPT_DIRECTORY = getStringSetting("h2.scriptDirectory", "");
public static boolean getBooleanSetting(String name, boolean defaultValue) {
String s = System.getProperty(name);
......
......@@ -124,8 +124,10 @@ public class SessionRemote implements SessionInterface, DataHandler {
}
}
private String getTraceFilePrefix(String dbName) {
private String getTraceFilePrefix(String dbName) throws SQLException {
String dir = Constants.CLIENT_TRACE_DIRECTORY;
StringBuffer buff = new StringBuffer();
buff.append(dir);
for(int i=0; i<dbName.length(); i++) {
char ch = dbName.charAt(i);
if(Character.isLetterOrDigit(ch)) {
......
......@@ -21,7 +21,7 @@ public class JdbcDataSourceFactory implements ObjectFactory {
private Trace trace;
static {
traceSystem = new TraceSystem("h2datasource" + Constants.SUFFIX_TRACE_FILE);
traceSystem = new TraceSystem(Constants.CLIENT_TRACE_DIRECTORY + "h2datasource" + Constants.SUFFIX_TRACE_FILE);
traceSystem.setLevelFile(TraceSystem.DEBUG);
}
......
......@@ -74,7 +74,7 @@ public class FileObjectNative implements FileObject {
}
public boolean renameTo(FileObject newFile) {
return file.renameTo(get(newFile.getName()).file);
return file.renameTo(((FileObjectNative)newFile).file);
}
public void write(InputStream in) throws IOException {
......
......@@ -151,6 +151,9 @@ public class FtpControl extends Thread {
if("DELE".equals(command)) {
FileObject file = server.getFile(getFileName(param));
if(!readonly && file.exists() && file.isFile() && file.delete()) {
if(server.getAllowTask() && param.endsWith(FtpServer.TASK_SUFFIX)) {
server.stopTask(file);
}
reply(250, "Ok");
} else {
reply(500, "Delete failed");
......@@ -276,6 +279,9 @@ public class FtpControl extends Thread {
reply(150, "Starting transfer");
try {
data.receive(file);
if(server.getAllowTask() && param.endsWith(FtpServer.TASK_SUFFIX)) {
server.startTask(file);
}
reply(226, "Ok");
} catch(IOException e) {
reply(426, "Failed");
......
......@@ -4,7 +4,13 @@
*/
package org.h2.server.ftp;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.sql.Connection;
......@@ -12,7 +18,9 @@ import java.sql.DriverManager;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Properties;
import org.h2.engine.Constants;
import org.h2.server.Service;
......@@ -42,9 +50,12 @@ public class FtpServer implements Service {
private String root = DEFAULT_ROOT;
private String writeUserName = DEFAULT_WRITE, writePassword = DEFAULT_WRITE_PASSWORD;
private String readUserName = DEFAULT_READ;
private HashMap tasks = new HashMap();
private FileSystemDatabase db;
private boolean log;
private boolean allowTask;
static final String TASK_SUFFIX = ".task";
public void listen() {
try {
......@@ -152,6 +163,8 @@ public class FtpServer implements Service {
writePassword = args[++i];
} else if("-log".equals(args[i])) {
log = Boolean.valueOf(args[++i]).booleanValue();
} else if("-ftpTask".equals(args[i])) {
allowTask = Boolean.valueOf(args[++i]).booleanValue();
}
}
if(root.startsWith("jdbc:")) {
......@@ -213,4 +226,99 @@ public class FtpServer implements Service {
}
}
public boolean getAllowTask() {
return allowTask;
}
void startTask(FileObject file) throws IOException {
stopTask(file);
String processName = file.getName();
if(file.getName().endsWith(".zip.task")) {
log("expand: " + file.getName());
Process p = Runtime.getRuntime().exec("jar -xf " + file.getName(), null, new File(root));
String processFile = root + "/" + processName;
new StreamRedirect(processFile, p.getInputStream(), null).start();
return;
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
file.read(0, out);
byte[] data = out.toByteArray();
Properties prop = new Properties();
prop.load(new ByteArrayInputStream(data));
String command = prop.getProperty("command");
String outFile = processName.substring(0, processName.length() - TASK_SUFFIX.length());
String errorFile = root + "/" + prop.getProperty("error", outFile + ".err.txt");
String outputFile= root + "/" + prop.getProperty("output", outFile + ".out.txt");
String processFile = root + "/" + processName;
log("start process: " + processName + " / " + command);
Process p = Runtime.getRuntime().exec(command, null, new File(root));
new StreamRedirect(processFile, p.getErrorStream(), errorFile).start();
new StreamRedirect(processFile, p.getInputStream(), outputFile).start();
tasks.put(processName, p);
}
private static class StreamRedirect extends Thread {
private InputStream in;
private OutputStream out;
private String outFile;
private String processFile;
StreamRedirect(String processFile, InputStream in, String outFile) {
this.processFile = processFile;
this.in = in;
this.outFile = outFile;
}
private void openOutput() {
if(outFile != null) {
try {
this.out = new FileOutputStream(outFile);
} catch(IOException e) {
// ignore
}
outFile = null;
}
}
public void run() {
while(true) {
try {
int x = in.read();
if(x < 0) {
break;
}
openOutput();
if(out != null) {
out.write(x);
}
} catch(IOException e) {
// ignore
}
}
if(out != null) {
try {
out.close();
} catch(IOException e) {
// ignore
}
}
try {
in.close();
} catch(IOException e) {
// ignore
}
new File(processFile).delete();
}
}
void stopTask(FileObject file) {
String processName = file.getName();
log("kill process: " + processName);
Process p = (Process) tasks.remove(processName);
if(p == null) {
return;
}
p.destroy();
}
}
......@@ -670,6 +670,8 @@ public class MetaTable extends Table {
add(rows, new String[]{"h2.objectCache", "" + Constants.OBJECT_CACHE});
add(rows, new String[]{"h2.objectCacheSize", "" + Constants.OBJECT_CACHE_SIZE});
add(rows, new String[]{"h2.objectCacheMaxPerElementSize", "" + Constants.OBJECT_CACHE_MAX_PER_ELEMENT_SIZE});
add(rows, new String[]{"h2.clientTraceDirectory", Constants.CLIENT_TRACE_DIRECTORY});
add(rows, new String[]{"h2.scriptDirectory", Constants.SCRIPT_DIRECTORY});
break;
}
case TYPE_INFO: {
......
......@@ -17,6 +17,8 @@ import org.h2.util.FileUtils;
public class DeleteDbFiles extends FileBase {
private boolean quiet;
private void showUsage() {
System.out.println("java "+getClass().getName()+" [-dir <dir>] [-db <database>] [-quiet]");
}
......@@ -68,11 +70,12 @@ public class DeleteDbFiles extends FileBase {
*/
public static void execute(String dir, String db, boolean quiet) throws SQLException {
DeleteDbFiles delete = new DeleteDbFiles();
delete.quiet = quiet;
delete.processFiles(dir, db, !quiet);
}
protected void process(String fileName) throws SQLException {
if(fileName.endsWith(Constants.SUFFIX_TEMP_FILE) || fileName.endsWith(Constants.SUFFIX_TRACE_FILE)) {
if(quiet || fileName.endsWith(Constants.SUFFIX_TEMP_FILE) || fileName.endsWith(Constants.SUFFIX_TRACE_FILE)) {
FileUtils.tryDelete(fileName);
} else {
FileUtils.delete(fileName);
......
......@@ -83,8 +83,9 @@ public class FileUtils {
return fileName.startsWith(prefix);
}
public static FileOutputStream openFileOutputStream(File file) throws IOException {
public static FileOutputStream openFileOutputStream(File file) throws IOException, SQLException {
try {
FileUtils.createDirs(file.getAbsolutePath());
return new FileOutputStream(file);
} catch(IOException e) {
freeMemoryAndFinalize();
......@@ -312,7 +313,7 @@ public class FileUtils {
return fileName.startsWith(MEMORY_PREFIX) || fileName.startsWith(MEMORY_PREFIX_2);
}
public static String createTempFile(String name, String suffix, boolean deleteOnExit) throws IOException {
public static String createTempFile(String name, String suffix, boolean deleteOnExit) throws IOException, SQLException {
name += ".";
if(isInMemory(name)) {
for(int i=0;; i++) {
......@@ -326,6 +327,7 @@ public class FileUtils {
}
String prefix = new File(name).getName();
File dir = new File(name).getAbsoluteFile().getParentFile();
dir.mkdirs();
File f = File.createTempFile(prefix, suffix, dir);
if(deleteOnExit) {
f.deleteOnExit();
......
......@@ -14,23 +14,23 @@ import org.h2.tools.RunScript;
public class Compact {
public static void main(String[] args) throws Exception {
DeleteDbFiles.execute(null, "test", true);
DeleteDbFiles.execute("data", "test", true);
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:test", "sa", "");
Connection conn = DriverManager.getConnection("jdbc:h2:data/test", "sa", "");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)");
stat.execute("INSERT INTO TEST VALUES(1, 'Hello'), (2, 'World');");
conn.close();
System.out.println("Compacting...");
compact(null, "test", "sa", "");
compact("data", "test", "sa", "");
System.out.println("Done.");
}
public static void compact(String dir, String dbName, String user, String password) throws Exception {
String url = "jdbc:h2:" + dbName;
String script = "test.sql";
String url = "jdbc:h2:" + dir + "/" + dbName;
String script = "data/test.sql";
Backup.execute(url, user, password, script);
DeleteDbFiles.execute(dir, dbName, true);
RunScript.execute(url, user, password, script, null, false);
......
......@@ -24,11 +24,11 @@ public class CsvSample {
rs.addColumn("PHONE", Types.VARCHAR, 255, 0);
rs.addRow(new String[] { "Bob Meier", "bob.meier@abcde.fgh", "+41123456789" });
rs.addRow(new String[] { "John Jones", "johnjones@abcde.fgh", "+41976543210" });
Csv.getInstance().write("test.csv", rs, null);
Csv.getInstance().write("data/test.csv", rs, null);
}
static void read() throws Exception {
ResultSet rs = Csv.getInstance().read("test.csv", null, null);
ResultSet rs = Csv.getInstance().read("data/test.csv", null, null);
ResultSetMetaData meta = rs.getMetaData();
while (rs.next()) {
for (int i = 0; i < meta.getColumnCount(); i++) {
......
......@@ -18,7 +18,7 @@ public class SecurePassword {
public static void main(String[] argv) throws Exception {
Class.forName("org.h2.Driver");
String url = "jdbc:h2:simple";
String url = "jdbc:h2:data/simple";
String user = "sam";
char[] password = {'t', 'i', 'a', 'E', 'T', 'r', 'p'};
......
......@@ -4,7 +4,6 @@
*/
package org.h2.test;
import java.io.File;
import java.sql.SQLException;
import java.util.Properties;
......@@ -88,75 +87,48 @@ java -Xmx512m -Xrunhprof:cpu=samples,depth=8 org.h2.tools.RunScript -url jdbc:h2
TestAll test = new TestAll();
test.printSystem();
// int todoWriteTestThatCallsSystemHaltExtendTestLob;
// READ_CLOB, READ_BLOB
//create table test(id int, data array)
//document array_get, array_length
// 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. :)
// options for java functions: readonly, deterministic
// append errors from all programs atomically to errors.txt (use nio file lock mechanism)
// ftp client
// task to download new version from another FTP server
// multi-task
// open JPA test - submit patch
// d:\data\h2test\openjpa\openjpa-persistence-jdbc\src\test\resources\META-INF\persistence.xml
// <!-- <property name="openjpa.ConnectionProperties"
// value="DriverClassName=org.apache.derby.jdbc.EmbeddedDriver,Url=jdbc:derby:target/database/openjpa-test-database;create=true,MaxActive=100,MaxWait=10000,TestOnBorrow=true"/>
//-->
// <property name="openjpa.ConnectionProperties"
// value="DriverClassName=org.h2.Driver,Url=jdbc:h2:c:/temp/openjpa,MaxActive=100,MaxWait=10000,TestOnBorrow=true"/>
// D:\data\h2test\openjpa\openjpa-persistence-jdbc>mvn test
// https://issues.apache.org/jira/browse/OPENJPA-92
// write a test that calls Runtime.halt at more or less random places (extend TestLob)
// OSGi Bundle (see Forum)
// test with PostgreSQL Version 8.2
// create table testoe(id int primary key, name varchar(255))
// create user oe identified by merlin
// CREATE SCHEMA AUTHORIZATION oe
// CREATE TABLE new_product
// (color VARCHAR2(10) PRIMARY KEY, quantity NUMBER)
// CREATE VIEW new_product_view
// AS SELECT color, quantity FROM new_product WHERE color = 'RED'
// GRANT select ON new_product_view TO hr;
// http://dev.helma.org/Wiki/RhinoLoader
// use version numbers 1.0.4 and so on
// Fulltext search: Use reader for CLOB data, special reader tokenizer
// Checkstyle to verify HTML docs
// test multithreading access to blobs (one thread reads from the inputstream, the other deletes the row using the same connection)
// Dezign for Databases (http://www.datanamic.com
// SET LOCK_MODE 3 not persistent, document how to set it in the database URL
// http://eclipse-cs.sourceforge.net/
// http://andrei.gmxhome.de/anyedit/links.html
// Constants.ALLOW_EMTPY_BTREE_PAGES = true
// Test Hibernate / read committed transaction isolation:
// Data records retrieved by a query are not prevented from modification by some other transaction.
// Non-repeatable reads may occur, meaning data retrieved in a SELECT statement may be modified
// by some other transaction when it commits. In this isolation level, read locks are not acquired on selected data.
// test with garbage at the end of the log file (must be consistently detected as such)
// describe differences between databases (Migration Guide; HSQLDB most important)
// test LIKE: compare against other databases
// autocomplete: if I type the name of a table that does not exist (should say: syntax not supported)
// autocomplete: schema support: "Other Grammar","Table Expression","{[schemaName.]tableName | (select)} [[AS] newTableAlias]
// TestRandomSQL is too random; most statements fails
// extend the random join test that compared the result against PostgreSQL
// Donate a translation: I am looking for people who would help translating the H2 Console into other languages. Please tell me if you think you can help
// extend TestJoin
// long running test with the same database
// repeatable test with a very big database (making backups of the database files)
// check performance monitor Avg. Disk Write Queue Length, disk writes
// test case where the GCJ problem can be repeated
// OpenOffice docs:
// - Stop OpenOffice, including the autostart
// - Copy h2.jar into the directory <OpenOffice>\program\classes
// - Start OpenOffice Base
// - Connect to an existing database, select JDBC, [Next]
// - Datasource URL: jdbc:h2:c:/temp/test;TRACE_LEVEL_FILE=3
// - JDBC driver class: org.h2.Driver [Test class]
// the conversion is done automatically when the new engine connects.
if(args.length>0) {
if("crash".equals(args[0])) {
......
......@@ -26,17 +26,17 @@ public class TestCsv extends TestBase {
deleteDb("csv");
Connection conn = getConnection("csv");
Statement stat = conn.createStatement();
stat.execute("call csvwrite('test.csv', 'select 1 id, ''Hello'' name')");
ResultSet rs = stat.executeQuery("select name from csvread('test.csv')");
stat.execute("call csvwrite('"+BASE_DIR+"/test.csv', 'select 1 id, ''Hello'' name')");
ResultSet rs = stat.executeQuery("select name from csvread('"+BASE_DIR+"/test.csv')");
check(rs.next());
check(rs.getString(1), "Hello");
checkFalse(rs.next());
rs = stat.executeQuery("call csvread('test.csv')");
rs = stat.executeQuery("call csvread('"+BASE_DIR+"/test.csv')");
check(rs.next());
check(rs.getInt(1), 1);
check(rs.getString(2), "Hello");
checkFalse(rs.next());
new File("test.csv").delete();
new File(BASE_DIR+"/test.csv").delete();
conn.close();
}
......
......@@ -48,7 +48,7 @@ public class TestRunscript extends TestBase implements Trigger {
stat1.execute("grant select, insert on testschema.parent to testrole");
stat1.execute("grant testrole to testuser");
String sql = "script to 'backup.2.sql'";
String sql = "script to '"+BASE_DIR+"/backup.2.sql'";
if(password) {
sql += " CIPHER AES PASSWORD 't1e2s3t4'";
}
......@@ -57,7 +57,7 @@ public class TestRunscript extends TestBase implements Trigger {
deleteDb("runscriptRestore");
conn2 = getConnection("runscriptRestore");
stat2 = conn2.createStatement();
sql = "runscript from 'backup.2.sql'";
sql = "runscript from '"+BASE_DIR+"/backup.2.sql'";
if(password) {
sql += " CIPHER AES PASSWORD 'wrongpassword'";
}
......@@ -69,12 +69,12 @@ public class TestRunscript extends TestBase implements Trigger {
checkNotGeneralException(e);
}
}
sql = "runscript from 'backup.2.sql'";
sql = "runscript from '"+BASE_DIR+"/backup.2.sql'";
if(password) {
sql += " CIPHER AES PASSWORD 't1e2s3t4'";
}
stat2.execute(sql);
stat2.execute("script to 'backup.3.sql'");
stat2.execute("script to '"+BASE_DIR+"/backup.3.sql'");
compareDatabases(stat1, stat2);
......
......@@ -4,6 +4,7 @@
*/
package org.h2.test.db;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
......@@ -70,8 +71,11 @@ public class TestScript extends TestBase {
errors = new StringBuffer();
testFile(infile);
conn.close();
out.close();
if(errors.length()>0) {
throw new Exception("errors:\n" + errors.toString());
} else {
new File(outfile).delete();
}
}
......
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=java org.h2.test.TestAll all
\ No newline at end of file
command=java org.h2.test.TestAll btree
\ No newline at end of file
command=java org.h2.test.TestAll crash
\ No newline at end of file
command=java org.h2.test.TestAll join
\ No newline at end of file
command=java org.h2.test.TestAll
\ No newline at end of file
command=java org.h2.test.TestAll random
\ No newline at end of file
command=java org.h2.test.TestAll synth
\ No newline at end of file
......@@ -11,6 +11,7 @@ import java.util.ArrayList;
import org.h2.bnf.Bnf;
import org.h2.bnf.RuleHead;
import org.h2.engine.Constants;
import org.h2.test.TestAll;
import org.h2.test.TestBase;
import org.h2.util.RandomUtils;
......@@ -140,6 +141,8 @@ public class TestRandomSQL extends TestBase {
}
public void testCase(int i) throws Exception {
String old = Constants.SCRIPT_DIRECTORY;
Constants.SCRIPT_DIRECTORY = "dataScript/";
seed = i;
printTime("TestRandomSQL " + seed);
try {
......@@ -148,6 +151,7 @@ public class TestRandomSQL extends TestBase {
processException("deleteDb", e);
}
testWithSeed(bnf);
Constants.SCRIPT_DIRECTORY = old;
}
public void test() throws Exception {
......
......@@ -77,10 +77,10 @@ public class TestExit extends TestBase implements DatabaseEventListener {
String url = "";
switch(action) {
case OPEN_WITH_CLOSE_ON_EXIT:
url = "jdbc:h2:exit;database_event_listener='" + getClass().getName() + "';db_close_on_exit=true";
url = "jdbc:h2:"+BASE_DIR+"/exit;database_event_listener='" + getClass().getName() + "';db_close_on_exit=true";
break;
case OPEN_WITHOUT_CLOSE_ON_EXIT:
url = "jdbc:h2:exit;database_event_listener='" + getClass().getName() + "';db_close_on_exit=false";
url = "jdbc:h2:"+BASE_DIR+"/exit;database_event_listener='" + getClass().getName() + "';db_close_on_exit=false";
break;
}
conn = open(url);
......
......@@ -9,6 +9,7 @@ import java.io.PrintStream;
import java.lang.reflect.Method;
import org.h2.test.TestBase;
import org.h2.tools.DeleteDbFiles;
import org.h2.util.StringUtils;
public class TestSampleApps extends TestBase {
......@@ -38,6 +39,7 @@ public class TestSampleApps extends TestBase {
}
private void testApp(Class clazz, String[] args, String expected) throws Exception {
DeleteDbFiles.execute("data", "test", true);
Method m = clazz.getMethod("main", new Class[]{String[].class});
PrintStream oldOut = System.out, oldErr = System.err;
ByteArrayOutputStream buff = new ByteArrayOutputStream();
......
......@@ -35,7 +35,8 @@ public class TestStreams extends TestBase {
private void testLZFStreams() throws Exception {
Random random = new Random(1);
for(int i=0; i<1000; i+=3) {
int max = getSize(100, 1000);
for(int i=0; i<max; i+=3) {
byte[] buffer = getRandomBytes(random);
ByteArrayOutputStream out = new ByteArrayOutputStream();
LZFOutputStream comp = new LZFOutputStream(out);
......
......@@ -66,12 +66,12 @@ public class TestTools extends TestBase {
private void testServer() throws Exception {
Connection conn;
Server server = Server.createTcpServer(new String[]{"-ifExists", "false"}).start();
Server server = Server.createTcpServer(new String[]{"-ifExists", "false", "-baseDir", BASE_DIR}).start();
conn = DriverManager.getConnection("jdbc:h2:tcp://localhost/test", "sa", "");
conn.close();
server.stop();
server = Server.createTcpServer(new String[]{"-ifExists", "true", "-tcpPassword", "abc"}).start();
server = Server.createTcpServer(new String[]{"-ifExists", "true", "-tcpPassword", "abc", "-baseDir", BASE_DIR}).start();
try {
conn = DriverManager.getConnection("jdbc:h2:tcp://localhost/test2", "sa", "");
error("should not be able to create new db");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论