提交 4b0fe6a5 authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 f89dd431
...@@ -161,6 +161,7 @@ ...@@ -161,6 +161,7 @@
<fileset dir="src/docsrc" includes="index.html"/> <fileset dir="src/docsrc" includes="index.html"/>
<fileset dir="src/docsrc" includes="html/**/*" excludes="**/*.jsp" /> <fileset dir="src/docsrc" includes="html/**/*" excludes="**/*.jsp" />
</copy> </copy>
<java classname="org.h2.tools.code.CheckPackageHtml" classpath="bin"/>
<java classname="org.h2.tools.code.CheckTextFiles" classpath="bin"/> <java classname="org.h2.tools.code.CheckTextFiles" classpath="bin"/>
<java classname="org.h2.tools.doc.GenerateDoc" classpath="bin"> <java classname="org.h2.tools.doc.GenerateDoc" classpath="bin">
<arg line="-in src/docsrc/html -out docs/html"/> <arg line="-in src/docsrc/html -out docs/html"/>
...@@ -259,8 +260,9 @@ ...@@ -259,8 +260,9 @@
<target name="javadocImpl" depends="javadoc"> <target name="javadocImpl" depends="javadoc">
<mkdir dir="docs/javadocImpl"/> <mkdir dir="docs/javadocImpl"/>
<javadoc <javadoc
sourcepath="src/main" sourcepath="src/main;src/test;src/tools"
packagenames="org.h2.*" packagenames="org.h2.*"
excludepackagenames="org.h2.tools.doclet"
classpath="${path.lucene.jar};${path.servlet.jar}" classpath="${path.lucene.jar};${path.servlet.jar}"
destDir="docs/javadocImpl" destDir="docs/javadocImpl"
/> />
......
...@@ -3904,7 +3904,10 @@ public class Parser { ...@@ -3904,7 +3904,10 @@ public class Parser {
private ScriptCommand parseScript() throws SQLException { private ScriptCommand parseScript() throws SQLException {
ScriptCommand command = new ScriptCommand(session); ScriptCommand command = new ScriptCommand(session);
boolean data = true, passwords = true, settings = true, dropTables = false; boolean data = true, passwords = true, settings = true, dropTables = false, simple = false;
if (readIf("SIMPLE")) {
simple = true;
}
if (readIf("NODATA")) { if (readIf("NODATA")) {
data = false; data = false;
} }
...@@ -3925,6 +3928,7 @@ public class Parser { ...@@ -3925,6 +3928,7 @@ public class Parser {
command.setPasswords(passwords); command.setPasswords(passwords);
command.setSettings(settings); command.setSettings(settings);
command.setDrop(dropTables); command.setDrop(dropTables);
command.setSimple(simple);
if (readIf("TO")) { if (readIf("TO")) {
command.setFileName(readString()); command.setFileName(readString());
if (readIf("COMPRESSION")) { if (readIf("COMPRESSION")) {
......
...@@ -66,6 +66,7 @@ public class ScriptCommand extends ScriptBase { ...@@ -66,6 +66,7 @@ public class ScriptCommand extends ScriptBase {
private boolean data; private boolean data;
private boolean settings; private boolean settings;
private boolean drop; private boolean drop;
private boolean simple;
private LocalResult result; private LocalResult result;
private byte[] lineSeparator; private byte[] lineSeparator;
private byte[] buffer; private byte[] buffer;
...@@ -242,11 +243,20 @@ public class ScriptCommand extends ScriptBase { ...@@ -242,11 +243,20 @@ public class ScriptCommand extends ScriptBase {
} }
buff.append(Parser.quoteIdentifier(columns[j].getName())); buff.append(Parser.quoteIdentifier(columns[j].getName()));
} }
buff.append(") VALUES("); buff.append(") VALUES");
if (!simple) {
buff.append('\n');
}
buff.append('(');
String ins = buff.toString(); String ins = buff.toString();
buff = null;
while (cursor.next()) { while (cursor.next()) {
Row row = cursor.get(); Row row = cursor.get();
buff = new StringBuffer(ins); if (buff == null) {
buff = new StringBuffer(ins);
} else {
buff.append(",\n(");
}
for (int j = 0; j < row.getColumnCount(); j++) { for (int j = 0; j < row.getColumnCount(); j++) {
if (j > 0) { if (j > 0) {
buff.append(", "); buff.append(", ");
...@@ -268,6 +278,12 @@ public class ScriptCommand extends ScriptBase { ...@@ -268,6 +278,12 @@ public class ScriptCommand extends ScriptBase {
} }
} }
buff.append(")"); buff.append(")");
if (simple || buff.length() > Constants.IO_BUFFER_SIZE) {
add(buff.toString(), true);
buff = null;
}
}
if (buff != null) {
add(buff.toString(), true); add(buff.toString(), true);
} }
} }
...@@ -479,4 +495,8 @@ public class ScriptCommand extends ScriptBase { ...@@ -479,4 +495,8 @@ public class ScriptCommand extends ScriptBase {
} }
} }
public void setSimple(boolean simple) {
this.simple = simple;
}
} }
...@@ -103,12 +103,13 @@ RUNSCRIPT FROM 'backup' ...@@ -103,12 +103,13 @@ RUNSCRIPT FROM 'backup'
" "
"Commands (DML)","SCRIPT"," "Commands (DML)","SCRIPT","
SCRIPT [NODATA] [NOPASSWORDS] [NOSETTINGS] [DROP] [BLOCKSIZE blockSizeInt] SCRIPT [SIMPLE] [NODATA] [NOPASSWORDS] [NOSETTINGS] [DROP] [BLOCKSIZE blockSizeInt]
[TO fileNameString [TO fileNameString
[COMPRESSION {DEFLATE|LZF|ZIP|GZIP}] [COMPRESSION {DEFLATE|LZF|ZIP|GZIP}]
[CIPHER cipher PASSWORD string]] [CIPHER cipher PASSWORD string]]
"," ","
Creates a SQL script with or without the insert statements. Creates a SQL script with or without the insert statements.
The simple format does not use multi-row insert statements.
If no file name is specified, the script is returned as a result set. If no file name is specified, the script is returned as a result set.
This command can be used to create a backup of the database. This command can be used to create a backup of the database.
If the DROP option is specified, drop statements are created for tables, views, and sequences. If the DROP option is specified, drop statements are created for tables, views, and sequences.
......
...@@ -6,6 +6,7 @@ package org.h2.samples; ...@@ -6,6 +6,7 @@ package org.h2.samples;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import org.h2.tools.Script; import org.h2.tools.Script;
...@@ -18,6 +19,7 @@ import org.h2.tools.RunScript; ...@@ -18,6 +19,7 @@ import org.h2.tools.RunScript;
* using this script. * using this script.
*/ */
public class Compact { public class Compact {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
DeleteDbFiles.execute("data", "test", true); DeleteDbFiles.execute("data", "test", true);
Class.forName("org.h2.Driver"); Class.forName("org.h2.Driver");
...@@ -26,14 +28,20 @@ public class Compact { ...@@ -26,14 +28,20 @@ public class Compact {
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)"); stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)");
stat.execute("INSERT INTO TEST VALUES(1, 'Hello'), (2, 'World');"); stat.execute("INSERT INTO TEST VALUES(1, 'Hello'), (2, 'World');");
conn.close(); conn.close();
System.out.println("Compacting..."); System.out.println("Compacting...");
compact("data", "test", "sa", ""); compact("data", "test", "sa", "");
System.out.println("Done."); System.out.println("Done.");
} }
public static void compact(String dir, String dbName, String user, String password) throws Exception { /**
* Utility method to compact a database.
*
* @param dir the directory
* @param dbName the database name
* @param user the user name
* @param password the password
*/
public static void compact(String dir, String dbName, String user, String password) throws SQLException {
String url = "jdbc:h2:" + dir + "/" + dbName; String url = "jdbc:h2:" + dir + "/" + dbName;
String file = "data/test.sql"; String file = "data/test.sql";
Script.execute(url, user, password, file); Script.execute(url, user, password, file);
......
...@@ -6,6 +6,7 @@ package org.h2.samples; ...@@ -6,6 +6,7 @@ package org.h2.samples;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.ResultSetMetaData; import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Types; import java.sql.Types;
import org.h2.tools.Csv; import org.h2.tools.Csv;
...@@ -17,12 +18,16 @@ import org.h2.tools.SimpleResultSet; ...@@ -17,12 +18,16 @@ import org.h2.tools.SimpleResultSet;
* how to use the tool to read such files. * how to use the tool to read such files.
*/ */
public class CsvSample { public class CsvSample {
public static void main(String[] args) throws Exception {
public static void main(String[] args) throws SQLException {
CsvSample.write(); CsvSample.write();
CsvSample.read(); CsvSample.read();
} }
static void write() throws Exception { /**
* Write a CSV file.
*/
static void write() throws SQLException {
SimpleResultSet rs = new SimpleResultSet(); SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("NAME", Types.VARCHAR, 255, 0); rs.addColumn("NAME", Types.VARCHAR, 255, 0);
rs.addColumn("EMAIL", Types.VARCHAR, 255, 0); rs.addColumn("EMAIL", Types.VARCHAR, 255, 0);
...@@ -32,7 +37,10 @@ public class CsvSample { ...@@ -32,7 +37,10 @@ public class CsvSample {
Csv.getInstance().write("data/test.csv", rs, null); Csv.getInstance().write("data/test.csv", rs, null);
} }
static void read() throws Exception { /**
* Read a CSV file.
*/
static void read() throws SQLException {
ResultSet rs = Csv.getInstance().read("data/test.csv", null, null); ResultSet rs = Csv.getInstance().read("data/test.csv", null, null);
ResultSetMetaData meta = rs.getMetaData(); ResultSetMetaData meta = rs.getMetaData();
while (rs.next()) { while (rs.next()) {
......
...@@ -35,18 +35,37 @@ public class FileFunctions { ...@@ -35,18 +35,37 @@ public class FileFunctions {
conn.close(); conn.close();
} }
/**
* Read a String from a file. The default encoding for this platform is used.
*
* @param fileName the file name
* @return the text
*/
public static String readTextFile(String fileName) throws IOException { public static String readTextFile(String fileName) throws IOException {
byte[] buff = readFile(fileName); byte[] buff = readFile(fileName);
String s = new String(buff); String s = new String(buff);
return s; return s;
} }
/**
* Read a String from a file using the specified encoding.
*
* @param fileName the file name
* @param encoding the encoding
* @return the text
*/
public static String readTextFileWithEncoding(String fileName, String encoding) throws IOException { public static String readTextFileWithEncoding(String fileName, String encoding) throws IOException {
byte[] buff = readFile(fileName); byte[] buff = readFile(fileName);
String s = new String(buff, encoding); String s = new String(buff, encoding);
return s; return s;
} }
/**
* Read a file into a byte array.
*
* @param fileName the file name
* @return the byte array
*/
public static byte[] readFile(String fileName) throws IOException { public static byte[] readFile(String fileName) throws IOException {
RandomAccessFile file = new RandomAccessFile(fileName, "r"); RandomAccessFile file = new RandomAccessFile(fileName, "r");
try { try {
......
...@@ -37,14 +37,32 @@ public class Function { ...@@ -37,14 +37,32 @@ public class Function {
conn.close(); conn.close();
} }
/**
* Check if a value is a prime number.
*
* @param value the value
* @return true if it is a prime number
*/
public static boolean isPrime(int value) { public static boolean isPrime(int value) {
return new BigInteger(String.valueOf(value)).isProbablePrime(100); return new BigInteger(String.valueOf(value)).isProbablePrime(100);
} }
/**
* Execute a query.
*
* @param conn the connection
* @param sql the SQL statement
* @return the result set
*/
public static ResultSet query(Connection conn, String sql) throws SQLException { public static ResultSet query(Connection conn, String sql) throws SQLException {
return conn.createStatement().executeQuery(sql); return conn.createStatement().executeQuery(sql);
} }
/**
* Creates a simple result set with one row.
*
* @return the result set
*/
public static ResultSet simpleResultSet() throws SQLException { public static ResultSet simpleResultSet() throws SQLException {
SimpleResultSet rs = new SimpleResultSet(); SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("ID", Types.INTEGER, 10, 0); rs.addColumn("ID", Types.INTEGER, 10, 0);
......
...@@ -74,8 +74,13 @@ public class FunctionMultiReturn { ...@@ -74,8 +74,13 @@ public class FunctionMultiReturn {
} }
/** /**
* Convert polar coordinates to cartesian coordinates.
* The function may be called twice, once to retrieve the result columns (with null parameters), * The function may be called twice, once to retrieve the result columns (with null parameters),
* and the second time to return the data. * and the second time to return the data.
*
* @param r the distance from the point 0/0
* @param alpha the angle
* @return a result set with two columns: x and y
*/ */
public static ResultSet polar2Cartesian(Double r, Double alpha) throws SQLException { public static ResultSet polar2Cartesian(Double r, Double alpha) throws SQLException {
SimpleResultSet rs = new SimpleResultSet(); SimpleResultSet rs = new SimpleResultSet();
...@@ -90,8 +95,13 @@ public class FunctionMultiReturn { ...@@ -90,8 +95,13 @@ public class FunctionMultiReturn {
} }
/** /**
* Convert polar coordinates to cartesian coordinates.
* The function may be called twice, once to retrieve the result columns (with null parameters), * The function may be called twice, once to retrieve the result columns (with null parameters),
* and the second time to return the data. * and the second time to return the data.
*
* @param r the distance from the point 0/0
* @param alpha the angle
* @return an array two values: x and y
*/ */
public static Object[] polar2CartesianArray(Double r, Double alpha) throws SQLException { public static Object[] polar2CartesianArray(Double r, Double alpha) throws SQLException {
double x = r.doubleValue() * Math.cos(alpha.doubleValue()); double x = r.doubleValue() * Math.cos(alpha.doubleValue());
...@@ -99,6 +109,15 @@ public class FunctionMultiReturn { ...@@ -99,6 +109,15 @@ public class FunctionMultiReturn {
return new Object[]{new Double(x), new Double(y)}; return new Object[]{new Double(x), new Double(y)};
} }
/**
* Convert a set of polar coordinates to cartesian coordinates.
* The function may be called twice, once to retrieve the result columns (with null parameters),
* and the second time to return the data.
*
* @param conn the connection
* @param query the query
* @return a result set with the coodinates
*/
public static ResultSet polar2CartesianSet(Connection conn, String query) throws SQLException { public static ResultSet polar2CartesianSet(Connection conn, String query) throws SQLException {
SimpleResultSet result = new SimpleResultSet(); SimpleResultSet result = new SimpleResultSet();
result.addColumn("R", Types.DOUBLE, 0, 0); result.addColumn("R", Types.DOUBLE, 0, 0);
......
...@@ -23,6 +23,9 @@ public class InitDatabaseFromJar { ...@@ -23,6 +23,9 @@ public class InitDatabaseFromJar {
new InitDatabaseFromJar().initDb(); new InitDatabaseFromJar().initDb();
} }
/**
* Create a script from a new database.
*/
private void createScript() throws Exception { private void createScript() throws Exception {
Class.forName("org.h2.Driver"); Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:mem:test"); Connection conn = DriverManager.getConnection("jdbc:h2:mem:test");
...@@ -33,6 +36,9 @@ public class InitDatabaseFromJar { ...@@ -33,6 +36,9 @@ public class InitDatabaseFromJar {
conn.close(); conn.close();
} }
/**
* Initialize a database from a SQL script file.
*/
void initDb() throws Exception { void initDb() throws Exception {
Class.forName("org.h2.Driver"); Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:mem:test"); Connection conn = DriverManager.getConnection("jdbc:h2:mem:test");
......
...@@ -16,6 +16,7 @@ import org.h2.tools.Server; ...@@ -16,6 +16,7 @@ import org.h2.tools.Server;
* the server mode supports remote connections. * the server mode supports remote connections.
*/ */
public class MixedMode { public class MixedMode {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
// start the server, allows to access the database remotly // start the server, allows to access the database remotly
......
...@@ -21,6 +21,7 @@ import org.h2.util.StringUtils; ...@@ -21,6 +21,7 @@ import org.h2.util.StringUtils;
* from a simple SQL script. A textual representation of the data is created as well. * from a simple SQL script. A textual representation of the data is created as well.
*/ */
public class Newsfeed { public class Newsfeed {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
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", "");
...@@ -42,6 +43,12 @@ public class Newsfeed { ...@@ -42,6 +43,12 @@ public class Newsfeed {
conn.close(); conn.close();
} }
/**
* Convert HTML text to plain text.
*
* @param html the html text
* @return the plain text
*/
private static String convertHtml2Text(String html) { private static String convertHtml2Text(String html) {
String s = html; String s = html;
s = StringUtils.replaceAll(s, "<b>", ""); s = StringUtils.replaceAll(s, "<b>", "");
......
...@@ -38,6 +38,14 @@ public class SQLInjection { ...@@ -38,6 +38,14 @@ public class SQLInjection {
// "jdbc:derby:test3;create=true", "sa", "sa"); // "jdbc:derby:test3;create=true", "sa", "sa");
} }
/**
* Run the test against the specified database.
*
* @param driver the JDBC driver name
* @param url the database URL
* @param user the user name
* @param password the password
*/
void run(String driver, String url, String user, String password) throws Exception { void run(String driver, String url, String user, String password) throws Exception {
Class.forName(driver); Class.forName(driver);
conn = DriverManager.getConnection(url, user, password); conn = DriverManager.getConnection(url, user, password);
...@@ -106,6 +114,9 @@ public class SQLInjection { ...@@ -106,6 +114,9 @@ public class SQLInjection {
conn.close(); conn.close();
} }
/**
* Simulate a login using an insecure method.
*/
void loginByNameInsecure() throws Exception { void loginByNameInsecure() throws Exception {
System.out.println("Insecure Systems Inc. - login"); System.out.println("Insecure Systems Inc. - login");
String name = input("Name?"); String name = input("Name?");
...@@ -119,6 +130,15 @@ public class SQLInjection { ...@@ -119,6 +130,15 @@ public class SQLInjection {
} }
} }
/**
* Utility method to get a user record given the user name and password.
* This method is secure.
*
* @param conn the database connection
* @param userName the user name
* @param password the password
* @return a result set with the user record if the password matches
*/
public static ResultSet getUser(Connection conn, String userName, String password) throws Exception { public static ResultSet getUser(Connection conn, String userName, String password) throws Exception {
PreparedStatement prep = conn.prepareStatement( PreparedStatement prep = conn.prepareStatement(
"SELECT * FROM USERS WHERE NAME=? AND PASSWORD=?"); "SELECT * FROM USERS WHERE NAME=? AND PASSWORD=?");
...@@ -127,6 +147,15 @@ public class SQLInjection { ...@@ -127,6 +147,15 @@ public class SQLInjection {
return prep.executeQuery(); return prep.executeQuery();
} }
/**
* Utility method to change a password of a user.
* This method is secure, except that the old password is not checked.
*
* @param conn the database connection
* @param userName the user name
* @param password the password
* @return the new password
*/
public static String changePassword(Connection conn, String userName, String password) throws Exception { public static String changePassword(Connection conn, String userName, String password) throws Exception {
PreparedStatement prep = conn.prepareStatement( PreparedStatement prep = conn.prepareStatement(
"UPDATE USERS SET PASSWORD=? WHERE NAME=?"); "UPDATE USERS SET PASSWORD=? WHERE NAME=?");
...@@ -136,6 +165,10 @@ public class SQLInjection { ...@@ -136,6 +165,10 @@ public class SQLInjection {
return password; return password;
} }
/**
* Simulate a login using an insecure method.
* A stored procedure is used here.
*/
void loginStoredProcedureInsecure() throws Exception { void loginStoredProcedureInsecure() throws Exception {
System.out.println("Insecure Systems Inc. - login using a stored procedure"); System.out.println("Insecure Systems Inc. - login using a stored procedure");
stat.execute("CREATE ALIAS IF NOT EXISTS " + stat.execute("CREATE ALIAS IF NOT EXISTS " +
...@@ -153,6 +186,9 @@ public class SQLInjection { ...@@ -153,6 +186,9 @@ public class SQLInjection {
} }
} }
/**
* Simulate a login using a secure method.
*/
void loginByNameSecure() throws Exception { void loginByNameSecure() throws Exception {
System.out.println("Secure Systems Inc. - login using placeholders"); System.out.println("Secure Systems Inc. - login using placeholders");
String name = input("Name?"); String name = input("Name?");
...@@ -170,6 +206,9 @@ public class SQLInjection { ...@@ -170,6 +206,9 @@ public class SQLInjection {
} }
} }
/**
* Sample code to limit access only to specific rows.
*/
void limitRowAccess() throws Exception { void limitRowAccess() throws Exception {
System.out.println("Secure Systems Inc. - limit row access"); System.out.println("Secure Systems Inc. - limit row access");
stat.execute("DROP TABLE IF EXISTS SESSION_USER"); stat.execute("DROP TABLE IF EXISTS SESSION_USER");
...@@ -185,6 +224,9 @@ public class SQLInjection { ...@@ -185,6 +224,9 @@ public class SQLInjection {
} }
} }
/**
* Simulate a login using an insecure method.
*/
void loginByIdInsecure() throws Exception { void loginByIdInsecure() throws Exception {
System.out.println("Half Secure Systems Inc. - login by id"); System.out.println("Half Secure Systems Inc. - login by id");
String id = input("User ID?"); String id = input("User ID?");
...@@ -205,6 +247,9 @@ public class SQLInjection { ...@@ -205,6 +247,9 @@ public class SQLInjection {
} }
} }
/**
* Simulate a login using a secure method.
*/
void loginByIdSecure() throws Exception { void loginByIdSecure() throws Exception {
System.out.println("Secure Systems Inc. - login by id"); System.out.println("Secure Systems Inc. - login by id");
String id = input("User ID?"); String id = input("User ID?");
...@@ -226,6 +271,12 @@ public class SQLInjection { ...@@ -226,6 +271,12 @@ public class SQLInjection {
} }
} }
/**
* List active items.
* The method uses the hard coded value '1', and therefore the database
* can not verify if the SQL statement was constructed with user
* input or not.
*/
void listActiveItems() throws Exception { void listActiveItems() throws Exception {
System.out.println("Half Secure Systems Inc. - list active items"); System.out.println("Half Secure Systems Inc. - list active items");
ResultSet rs = stat.executeQuery( ResultSet rs = stat.executeQuery(
...@@ -235,6 +286,11 @@ public class SQLInjection { ...@@ -235,6 +286,11 @@ public class SQLInjection {
} }
} }
/**
* List active items.
* The method uses a constant, and therefore the database
* knows it does not contain user input.
*/
void listActiveItemsUsingConstants() throws Exception { void listActiveItemsUsingConstants() throws Exception {
System.out.println("Secure Systems Inc. - list active items"); System.out.println("Secure Systems Inc. - list active items");
ResultSet rs = stat.executeQuery( ResultSet rs = stat.executeQuery(
...@@ -244,6 +300,11 @@ public class SQLInjection { ...@@ -244,6 +300,11 @@ public class SQLInjection {
} }
} }
/**
* List items using a specified sort order.
* The method is not secure as user input is used to construct the
* SQL statement.
*/
void listItemsSortedInsecure() throws Exception { void listItemsSortedInsecure() throws Exception {
System.out.println("Insecure Systems Inc. - list items"); System.out.println("Insecure Systems Inc. - list items");
String order = input("order (id, name)?"); String order = input("order (id, name)?");
...@@ -258,6 +319,11 @@ public class SQLInjection { ...@@ -258,6 +319,11 @@ public class SQLInjection {
} }
} }
/**
* List items using a specified sort order.
* The method is secure as the user input is validated before use.
* However the database has no chance to verify this.
*/
void listItemsSortedSecure() throws Exception { void listItemsSortedSecure() throws Exception {
System.out.println("Secure Systems Inc. - list items"); System.out.println("Secure Systems Inc. - list items");
String order = input("order (id, name)?"); String order = input("order (id, name)?");
...@@ -275,6 +341,10 @@ public class SQLInjection { ...@@ -275,6 +341,10 @@ public class SQLInjection {
} }
} }
/**
* List items using a specified sort order.
* The method is secure as a parameterized statement is used.
*/
void listItemsSortedSecureParam() throws Exception { void listItemsSortedSecureParam() throws Exception {
System.out.println("Secure Systems Inc. - list items"); System.out.println("Secure Systems Inc. - list items");
String order = input("order (1, 2, -1, -2)?"); String order = input("order (1, 2, -1, -2)?");
...@@ -291,6 +361,11 @@ public class SQLInjection { ...@@ -291,6 +361,11 @@ public class SQLInjection {
} }
} }
/**
* This method creates a one way hash from the password
* (using a random salt), and stores this information instead of the
* password.
*/
void storePasswordHashWithSalt() throws Exception { void storePasswordHashWithSalt() throws Exception {
System.out.println("Very Secure Systems Inc. - login"); System.out.println("Very Secure Systems Inc. - login");
stat.execute("DROP TABLE IF EXISTS USERS2"); stat.execute("DROP TABLE IF EXISTS USERS2");
...@@ -322,10 +397,15 @@ public class SQLInjection { ...@@ -322,10 +397,15 @@ public class SQLInjection {
stat.execute("SET ALLOW_LITERALS ALL"); stat.execute("SET ALLOW_LITERALS ALL");
} }
/**
* Utility method to get user input from the command line.
*
* @param prompt the prompt
* @return the user input
*/
String input(String prompt) throws Exception { String input(String prompt) throws Exception {
System.out.print(prompt); System.out.print(prompt);
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); return new BufferedReader(new InputStreamReader(System.in)).readLine();
return reader.readLine();
} }
} }
...@@ -16,6 +16,7 @@ import java.util.Properties; ...@@ -16,6 +16,7 @@ import java.util.Properties;
* (both database passwords, and account passwords). * (both database passwords, and account passwords).
*/ */
public class SecurePassword { public class SecurePassword {
public static void main(String[] argv) throws Exception { public static void main(String[] argv) throws Exception {
Class.forName("org.h2.Driver"); Class.forName("org.h2.Driver");
......
...@@ -22,6 +22,9 @@ public class ShowProgress implements DatabaseEventListener { ...@@ -22,6 +22,9 @@ public class ShowProgress implements DatabaseEventListener {
private long last, start; private long last, start;
/**
* Create a new instance of this class, and start the timer.
*/
public ShowProgress() { public ShowProgress() {
start = last = System.currentTimeMillis(); start = last = System.currentTimeMillis();
} }
...@@ -30,6 +33,9 @@ public class ShowProgress implements DatabaseEventListener { ...@@ -30,6 +33,9 @@ public class ShowProgress implements DatabaseEventListener {
new ShowProgress().test(); new ShowProgress().test();
} }
/**
* Run the progress test.
*/
void test() throws Exception { void test() throws Exception {
Class.forName("org.h2.Driver"); Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:test;LOG=2", "sa", ""); Connection conn = DriverManager.getConnection("jdbc:h2:test;LOG=2", "sa", "");
...@@ -69,15 +75,34 @@ public class ShowProgress implements DatabaseEventListener { ...@@ -69,15 +75,34 @@ public class ShowProgress implements DatabaseEventListener {
} }
/**
* This method is called by the database if disk space is low.
*
* @param stillAvailable the number of bytes still available
*/
public void diskSpaceIsLow(long stillAvailable) throws SQLException { public void diskSpaceIsLow(long stillAvailable) throws SQLException {
System.out.println("diskSpaceIsLow stillAvailable="+stillAvailable); System.out.println("diskSpaceIsLow stillAvailable="+stillAvailable);
} }
/**
* This method is called if an exception occurs in the database.
*
* @param e the exception
* @param sql the SQL statement
*/
public void exceptionThrown(SQLException e, String sql) { public void exceptionThrown(SQLException e, String sql) {
System.out.println("Error executing " + sql); System.out.println("Error executing " + sql);
e.printStackTrace(); e.printStackTrace();
} }
/**
* This method is called when opening the database to notify about the progress.
*
* @param state the current state
* @param name the object name (depends on the state)
* @param current the current progress
* @param max the 100% mark
*/
public void setProgress(int state, String name, int current, int max) { public void setProgress(int state, String name, int current, int max) {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
if (time < last + 5000) { if (time < last + 5000) {
...@@ -104,14 +129,25 @@ public class ShowProgress implements DatabaseEventListener { ...@@ -104,14 +129,25 @@ public class ShowProgress implements DatabaseEventListener {
+ (time - start) + " ms"); + (time - start) + " ms");
} }
/**
* This method is called when the database is closed.
*/
public void closingDatabase() { public void closingDatabase() {
System.out.println("Closing the database"); System.out.println("Closing the database");
} }
/**
* This method is called just after creating the instance.
*
* @param url the database URL
*/
public void init(String url) { public void init(String url) {
System.out.println("Initializing the event listener for database " + url); System.out.println("Initializing the event listener for database " + url);
} }
/**
* This method is called when the database is open.
*/
public void opened() { public void opened() {
} }
......
...@@ -9,6 +9,7 @@ package org.h2.samples; ...@@ -9,6 +9,7 @@ package org.h2.samples;
* if it is running. * if it is running.
*/ */
public class ShutdownServer { public class ShutdownServer {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
org.h2.tools.Server.shutdownTcpServer("tcp://localhost:9094", "", false); org.h2.tools.Server.shutdownTcpServer("tcp://localhost:9094", "", false);
} }
......
...@@ -42,12 +42,33 @@ public class TriggerSample { ...@@ -42,12 +42,33 @@ public class TriggerSample {
conn.close(); conn.close();
} }
/**
* This class is a simple trigger implementation.
*/
public static class MyTrigger implements Trigger { public static class MyTrigger implements Trigger {
/**
* Initializes the trigger.
*
* @param conn a connection to the database
* @param schemaName the name of the schema
* @param triggerName the name of the trigger used in the CREATE TRIGGER statement
* @param tableName the name of the table
* @param before whether the fire method is called before or after the operation is performed
* @param type the operation type: INSERT, UPDATE, or DELETE
*/
public void init(Connection conn, String schemaName, String triggerName, String tableName, boolean before, int type) { public void init(Connection conn, String schemaName, String triggerName, String tableName, boolean before, int type) {
// System.out.println("Initializing trigger " + triggerName + " for table " + tableName); // System.out.println("Initializing trigger " + triggerName + " for table " + tableName);
} }
/**
* This method is called for each triggered action.
*
* @param conn a connection to the database
* @param oldRow the old row, or null if no old row is available (for INSERT)
* @param newRow the new row, or null if no new row is available (for DELETE)
* @throws SQLException if the operation must be undone
*/
public void fire(Connection conn, public void fire(Connection conn,
Object[] oldRow, Object[] newRow) Object[] oldRow, Object[] newRow)
throws SQLException { throws SQLException {
......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
Standalone sample applications.
</body></html>
\ No newline at end of file
...@@ -113,11 +113,6 @@ import org.h2.util.StringUtils; ...@@ -113,11 +113,6 @@ import org.h2.util.StringUtils;
*/ */
public class TestAll { public class TestAll {
// Snippets to run test code:
// java -cp .;%H2DRIVERS% org.h2.test.TestAll
// java -Xrunhprof:cpu=samples,depth=8 org.h2.test.TestAll
// java -Xrunhprof:heap=sites,depth=8 org.h2.test.TestAll
/* /*
Random test: Random test:
...@@ -154,9 +149,19 @@ java org.h2.test.TestAll timer ...@@ -154,9 +149,19 @@ java org.h2.test.TestAll timer
/* /*
add tests with select distinct type (code coverage) (code coverage: limit, sample-size)
add tests with select distinct type
staging.trace.db.gz
allow queries as well in batch updates
CALL syntax should probably work for regular executeUpdate as well.
http://java.sun.com/j2se/1.4.2/docs/guide/jdbc/getstart/callablestatement.html#1000220
documentation: package.html -Djboss.bind.address=<ip_address>
-Dh2.bindAddress=...
documentation: package.html: write test (enforce one package.html where there is a .java file)
write to the db file what version was used to create a database write to the db file what version was used to create a database
...@@ -296,7 +301,8 @@ Features of H2 ...@@ -296,7 +301,8 @@ Features of H2
} else if ("all".equals(args[0])) { } else if ("all".equals(args[0])) {
test.testEverything(); test.testEverything();
} else if ("codeCoverage".equals(args[0])) { } else if ("codeCoverage".equals(args[0])) {
test.testCodeCoverage(); test.codeCoverage = true;
test.runTests();
} else if ("multiThread".equals(args[0])) { } else if ("multiThread".equals(args[0])) {
new TestMulti().runTest(test); new TestMulti().runTest(test);
} else if ("halt".equals(args[0])) { } else if ("halt".equals(args[0])) {
...@@ -310,49 +316,10 @@ Features of H2 ...@@ -310,49 +316,10 @@ Features of H2
System.out.println("done (" + (System.currentTimeMillis() - time) + " ms)"); System.out.println("done (" + (System.currentTimeMillis() - time) + " ms)");
} }
void runTests() throws Exception { /**
* Run all tests in all possible combinations.
// TODO test set lock_mode=0, 1; max_trace_file_size; modes; collation; assert */
// TODO test shutdown immediately private void testEverything() throws Exception {
// smallLog = big = networked = memory = ssl = textStorage = diskResult = deleteIndex = traceSystemOut = false;
// logMode = 1; traceLevelFile = throttle = 0;
// deleteIndex = textStorage = true;
// cipher = null;
// codeCoverage = true;
// memory = true;
// new TestSpeed().runTest(this);
// new TestSpeed().runTest(this);
// new TestSpeed().runTest(this);
// new TestSpeed().runTest(this);
// smallLog = big = networked = memory = ssl = textStorage = diskResult = deleteIndex = traceSystemOut = diskUndo = false;
// traceLevelFile = throttle = 0;
// big = true;
// memory = false;
//
testQuick();
testCombination();
}
void testCodeCoverage() throws Exception {
this.codeCoverage = true;
runTests();
}
void testQuick() throws Exception {
smallLog = big = networked = memory = ssl = textStorage = diskResult = deleteIndex = traceSystemOut = diskUndo = false;
traceLevelFile = throttle = 0;
logMode = 1;
cipher = null;
testAll();
}
void testEverything() throws Exception {
for (int c = 0; c < 3; c++) { for (int c = 0; c < 3; c++) {
if (c == 0) { if (c == 0) {
cipher = null; cipher = null;
...@@ -373,20 +340,30 @@ Features of H2 ...@@ -373,20 +340,30 @@ Features of H2
for (logMode = 0; logMode < 3; logMode++) { for (logMode = 0; logMode < 3; logMode++) {
traceLevelFile = logMode; traceLevelFile = logMode;
TestBase.printTime("cipher:" + cipher +" a:" +a+" logMode:"+logMode); TestBase.printTime("cipher:" + cipher +" a:" +a+" logMode:"+logMode);
testAll(); test();
} }
} }
} }
} }
void testCombination() throws Exception { /**
* Run the tests with a number of different settings.
*/
private void runTests() throws Exception {
smallLog = big = networked = memory = ssl = textStorage = diskResult = deleteIndex = traceSystemOut = diskUndo = false;
traceLevelFile = throttle = 0;
logMode = 1;
cipher = null;
test();
smallLog = big = networked = memory = ssl = textStorage = diskResult = deleteIndex = traceSystemOut = false; smallLog = big = networked = memory = ssl = textStorage = diskResult = deleteIndex = traceSystemOut = false;
traceLevelFile = throttle = 0; traceLevelFile = throttle = 0;
logMode = 1; logMode = 1;
cipher = null; cipher = null;
mvcc = false; mvcc = false;
cache2Q = false; cache2Q = false;
testAll(); test();
diskUndo = false; diskUndo = false;
smallLog = false; smallLog = false;
...@@ -401,7 +378,7 @@ Features of H2 ...@@ -401,7 +378,7 @@ Features of H2
cipher = null; cipher = null;
mvcc = false; mvcc = false;
cache2Q = false; cache2Q = false;
testAll(); test();
big = false; big = false;
smallLog = false; smallLog = false;
...@@ -418,7 +395,7 @@ Features of H2 ...@@ -418,7 +395,7 @@ Features of H2
cipher = null; cipher = null;
mvcc = false; mvcc = false;
cache2Q = false; cache2Q = false;
testAll(); test();
diskUndo = true; diskUndo = true;
smallLog = false; smallLog = false;
...@@ -433,7 +410,7 @@ Features of H2 ...@@ -433,7 +410,7 @@ Features of H2
cipher = "XTEA"; cipher = "XTEA";
mvcc = false; mvcc = false;
cache2Q = false; cache2Q = false;
testAll(); test();
diskUndo = false; diskUndo = false;
big = true; big = true;
...@@ -451,7 +428,7 @@ Features of H2 ...@@ -451,7 +428,7 @@ Features of H2
cipher = null; cipher = null;
mvcc = false; mvcc = false;
cache2Q = false; cache2Q = false;
testAll(); test();
big = true; big = true;
smallLog = true; smallLog = true;
...@@ -468,7 +445,7 @@ Features of H2 ...@@ -468,7 +445,7 @@ Features of H2
cipher = null; cipher = null;
mvcc = false; mvcc = false;
cache2Q = true; cache2Q = true;
testAll(); test();
big = true; big = true;
smallLog = false; smallLog = false;
...@@ -485,7 +462,7 @@ Features of H2 ...@@ -485,7 +462,7 @@ Features of H2
cipher = "AES"; cipher = "AES";
mvcc = false; mvcc = false;
cache2Q = false; cache2Q = false;
testAll(); test();
smallLog = big = networked = memory = ssl = textStorage = diskResult = deleteIndex = traceSystemOut = false; smallLog = big = networked = memory = ssl = textStorage = diskResult = deleteIndex = traceSystemOut = false;
traceLevelFile = throttle = 0; traceLevelFile = throttle = 0;
...@@ -493,48 +470,16 @@ Features of H2 ...@@ -493,48 +470,16 @@ Features of H2
cipher = null; cipher = null;
mvcc = true; mvcc = true;
cache2Q = false; cache2Q = false;
testAll(); test();
memory = true; memory = true;
testAll(); test();
} }
void testAll() throws Exception { /**
DeleteDbFiles.execute(TestBase.baseDir, null, true); * Run all tests with the current settings.
testDatabase(); */
testUnit(); private void test() throws Exception {
DeleteDbFiles.execute(TestBase.baseDir, null, true);
}
void testUnit() {
new TestBitField().runTest(this);
new TestCompress().runTest(this);
new TestDataPage().runTest(this);
new TestDate().runTest(this);
new TestExit().runTest(this);
new TestFile().runTest(this);
new TestFileLock().runTest(this);
new TestFtp().runTest(this);
new TestFileSystem().runTest(this);
new TestIntArray().runTest(this);
new TestIntIntHashMap().runTest(this);
new TestMultiThreadedKernel().runTest(this);
new TestOverflow().runTest(this);
new TestPattern().runTest(this);
new TestReader().runTest(this);
new TestSampleApps().runTest(this);
new TestScriptReader().runTest(this);
new TestSecurity().runTest(this);
new TestStreams().runTest(this);
new TestStringCache().runTest(this);
new TestStringUtils().runTest(this);
new TestTools().runTest(this);
new TestValue().runTest(this);
new TestValueHashMap().runTest(this);
}
void testDatabase() throws Exception {
System.out.println("test big:"+big+" net:"+networked+" cipher:"+cipher+" memory:"+memory+" log:"+logMode+" diskResult:"+diskResult + " mvcc:" + mvcc); System.out.println("test big:"+big+" net:"+networked+" cipher:"+cipher+" memory:"+memory+" log:"+logMode+" diskResult:"+diskResult + " mvcc:" + mvcc);
beforeTest(); beforeTest();
...@@ -611,10 +556,37 @@ Features of H2 ...@@ -611,10 +556,37 @@ Features of H2
new TestRandomSQL().runTest(this); new TestRandomSQL().runTest(this);
new TestKillRestart().runTest(this); new TestKillRestart().runTest(this);
// unit
new TestBitField().runTest(this);
new TestCompress().runTest(this);
new TestDataPage().runTest(this);
new TestDate().runTest(this);
new TestExit().runTest(this);
new TestFile().runTest(this);
new TestFileLock().runTest(this);
new TestFtp().runTest(this);
new TestFileSystem().runTest(this);
new TestIntArray().runTest(this);
new TestIntIntHashMap().runTest(this);
new TestMultiThreadedKernel().runTest(this);
new TestOverflow().runTest(this);
new TestPattern().runTest(this);
new TestReader().runTest(this);
new TestSampleApps().runTest(this);
new TestScriptReader().runTest(this);
new TestSecurity().runTest(this);
new TestStreams().runTest(this);
new TestStringCache().runTest(this);
new TestStringUtils().runTest(this);
new TestTools().runTest(this);
new TestValue().runTest(this);
new TestValueHashMap().runTest(this);
afterTest(); afterTest();
} }
public void beforeTest() throws SQLException { public void beforeTest() throws SQLException {
DeleteDbFiles.execute(TestBase.baseDir, null, true);
FileSystemDisk.getInstance().deleteRecursive("trace.db"); FileSystemDisk.getInstance().deleteRecursive("trace.db");
if (networked) { if (networked) {
TcpServer.logInternalErrors = true; TcpServer.logInternalErrors = true;
...@@ -634,6 +606,7 @@ Features of H2 ...@@ -634,6 +606,7 @@ Features of H2
if (networked && server != null) { if (networked && server != null) {
server.stop(); server.stop();
} }
DeleteDbFiles.execute(TestBase.baseDir, null, true);
} }
private void printSystem() { private void printSystem() {
......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
The implementation of the benchmark application.
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
A standalone code coverage tool.
</body></html>
\ No newline at end of file
...@@ -11,6 +11,9 @@ import java.sql.Statement; ...@@ -11,6 +11,9 @@ import java.sql.Statement;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/**
* Tests if prepared statements are re-compiled when required.
*/
public class TestAutoRecompile extends TestBase { public class TestAutoRecompile extends TestBase {
public void test() throws Exception { public void test() throws Exception {
......
...@@ -10,6 +10,9 @@ import java.sql.Statement; ...@@ -10,6 +10,9 @@ import java.sql.Statement;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.tools.Restore; import org.h2.tools.Restore;
/**
* Test for the BACKUP SQL statement.
*/
public class TestBackup extends TestBase { public class TestBackup extends TestBase {
public void test() throws Exception { public void test() throws Exception {
......
...@@ -13,6 +13,9 @@ import java.sql.Statement; ...@@ -13,6 +13,9 @@ import java.sql.Statement;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/**
* Test for batch updates.
*/
public class TestBatchUpdates extends TestBase { public class TestBatchUpdates extends TestBase {
static final String COFFEE_UPDATE = "UPDATE TEST SET PRICE=PRICE*20 WHERE TYPE_ID=?"; static final String COFFEE_UPDATE = "UPDATE TEST SET PRICE=PRICE*20 WHERE TYPE_ID=?";
......
...@@ -12,6 +12,9 @@ import java.sql.Statement; ...@@ -12,6 +12,9 @@ import java.sql.Statement;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.util.MemoryUtils; import org.h2.util.MemoryUtils;
/**
* Test for big databases.
*/
public class TestBigDb extends TestBase { public class TestBigDb extends TestBase {
public void test() throws Exception { public void test() throws Exception {
......
...@@ -13,6 +13,9 @@ import java.util.ArrayList; ...@@ -13,6 +13,9 @@ import java.util.ArrayList;
import org.h2.store.FileLister; import org.h2.store.FileLister;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/**
* Test for big result sets.
*/
public class TestBigResult extends TestBase { public class TestBigResult extends TestBase {
public void test() throws Exception { public void test() throws Exception {
if (config.memory) { if (config.memory) {
......
...@@ -18,6 +18,9 @@ import java.util.Random; ...@@ -18,6 +18,9 @@ import java.util.Random;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/**
* Various test cases.
*/
public class TestCases extends TestBase { public class TestCases extends TestBase {
public void test() throws Exception { public void test() throws Exception {
......
...@@ -9,6 +9,9 @@ import java.sql.Statement; ...@@ -9,6 +9,9 @@ import java.sql.Statement;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/**
* Tests the CHECKPOINT SQL statement.
*/
public class TestCheckpoint extends TestBase { public class TestCheckpoint extends TestBase {
public void test() throws Exception { public void test() throws Exception {
......
...@@ -16,6 +16,9 @@ import org.h2.tools.CreateCluster; ...@@ -16,6 +16,9 @@ import org.h2.tools.CreateCluster;
import org.h2.tools.DeleteDbFiles; import org.h2.tools.DeleteDbFiles;
import org.h2.tools.Server; import org.h2.tools.Server;
/**
* Test for the cluster feature.
*/
public class TestCluster extends TestBase { public class TestCluster extends TestBase {
public void test() throws Exception { public void test() throws Exception {
...@@ -41,7 +44,7 @@ public class TestCluster extends TestBase { ...@@ -41,7 +44,7 @@ public class TestCluster extends TestBase {
prep.setString(2, "Data" + i); prep.setString(2, "Data" + i);
prep.executeUpdate(); prep.executeUpdate();
} }
check(conn, len); check(conn, len);
conn.close(); conn.close();
CreateCluster.main(new String[] { "-urlSource", "jdbc:h2:file:" + baseDir + "/node1/test", "-urlTarget", CreateCluster.main(new String[] { "-urlSource", "jdbc:h2:file:" + baseDir + "/node1/test", "-urlTarget",
...@@ -77,21 +80,21 @@ public class TestCluster extends TestBase { ...@@ -77,21 +80,21 @@ public class TestCluster extends TestBase {
stat = conn.createStatement(); stat = conn.createStatement();
check(conn, len); check(conn, len);
conn.close(); conn.close();
// disable the cluster // disable the cluster
conn = DriverManager.getConnection("jdbc:h2:tcp://localhost:9091/test;CLUSTER=''", "sa", ""); conn = DriverManager.getConnection("jdbc:h2:tcp://localhost:9091/test;CLUSTER=''", "sa", "");
conn.close(); conn.close();
n1.stop(); n1.stop();
// re-create the cluster // re-create the cluster
DeleteDbFiles.main(new String[] { "-dir", baseDir + "/node2", "-quiet" }); DeleteDbFiles.main(new String[] { "-dir", baseDir + "/node2", "-quiet" });
CreateCluster.main(new String[] { "-urlSource", "jdbc:h2:file:" + baseDir + "/node1/test", "-urlTarget", CreateCluster.main(new String[] { "-urlSource", "jdbc:h2:file:" + baseDir + "/node1/test", "-urlTarget",
"jdbc:h2:file:" + baseDir + "/node2/test", "-user", "sa", "-serverlist", "jdbc:h2:file:" + baseDir + "/node2/test", "-user", "sa", "-serverlist",
"localhost:9091,localhost:9092" }); "localhost:9091,localhost:9092" });
n1 = org.h2.tools.Server.createTcpServer( n1 = org.h2.tools.Server.createTcpServer(
new String[] { "-tcpPort", "9091", "-baseDir", baseDir + "/node1" }).start(); new String[] { "-tcpPort", "9091", "-baseDir", baseDir + "/node1" }).start();
n2 = org.h2.tools.Server.createTcpServer( n2 = org.h2.tools.Server.createTcpServer(
new String[] { "-tcpPort", "9092", "-baseDir", baseDir + "/node2" }).start(); new String[] { "-tcpPort", "9092", "-baseDir", baseDir + "/node2" }).start();
conn = DriverManager.getConnection("jdbc:h2:tcp://localhost:9091,localhost:9092/test", "sa", ""); conn = DriverManager.getConnection("jdbc:h2:tcp://localhost:9091,localhost:9092/test", "sa", "");
stat = conn.createStatement(); stat = conn.createStatement();
......
...@@ -10,6 +10,9 @@ import java.sql.Statement; ...@@ -10,6 +10,9 @@ import java.sql.Statement;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/**
* Tests the compatibility with other databases.
*/
public class TestCompatibility extends TestBase { public class TestCompatibility extends TestBase {
private Connection conn; private Connection conn;
......
...@@ -20,6 +20,9 @@ import org.h2.tools.Csv; ...@@ -20,6 +20,9 @@ import org.h2.tools.Csv;
import org.h2.util.IOUtils; import org.h2.util.IOUtils;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
/**
* CSVREAD and CSVWRITE tests.
*/
public class TestCsv extends TestBase { public class TestCsv extends TestBase {
public void test() throws Exception { public void test() throws Exception {
......
...@@ -10,6 +10,9 @@ import java.sql.Statement; ...@@ -10,6 +10,9 @@ import java.sql.Statement;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/**
* Test for the exclusive mode.
*/
public class TestExclusive extends TestBase { public class TestExclusive extends TestBase {
public void test() throws Exception { public void test() throws Exception {
......
...@@ -12,6 +12,9 @@ import java.util.StringTokenizer; ...@@ -12,6 +12,9 @@ import java.util.StringTokenizer;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/**
* Fulltext search tests.
*/
public class TestFullText extends TestBase { public class TestFullText extends TestBase {
public void test() throws Exception { public void test() throws Exception {
......
...@@ -20,6 +20,9 @@ import org.h2.api.AggregateFunction; ...@@ -20,6 +20,9 @@ import org.h2.api.AggregateFunction;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.tools.SimpleResultSet; import org.h2.tools.SimpleResultSet;
/**
* Tests for user defined functions and aggregates.
*/
public class TestFunctions extends TestBase { public class TestFunctions extends TestBase {
private Statement stat; private Statement stat;
...@@ -28,9 +31,9 @@ public class TestFunctions extends TestBase { ...@@ -28,9 +31,9 @@ public class TestFunctions extends TestBase {
testAggregate(); testAggregate();
testFunctions(); testFunctions();
} }
public static class MedianString implements AggregateFunction { public static class MedianString implements AggregateFunction {
private ArrayList list = new ArrayList(); private ArrayList list = new ArrayList();
public void add(Object value) throws SQLException { public void add(Object value) throws SQLException {
...@@ -47,9 +50,9 @@ public class TestFunctions extends TestBase { ...@@ -47,9 +50,9 @@ public class TestFunctions extends TestBase {
public void init(Connection conn) throws SQLException { public void init(Connection conn) throws SQLException {
} }
} }
private void testAggregate() throws Exception { private void testAggregate() throws Exception {
deleteDb("functions"); deleteDb("functions");
Connection conn = getConnection("functions"); Connection conn = getConnection("functions");
...@@ -60,11 +63,11 @@ public class TestFunctions extends TestBase { ...@@ -60,11 +63,11 @@ public class TestFunctions extends TestBase {
rs.next(); rs.next();
check("5", rs.getString(1)); check("5", rs.getString(1));
conn.close(); conn.close();
if (config.memory) { if (config.memory) {
return; return;
} }
conn = getConnection("functions"); conn = getConnection("functions");
stat = conn.createStatement(); stat = conn.createStatement();
rs = stat.executeQuery("SELECT MEDIAN(X) FROM SYSTEM_RANGE(1, 9)"); rs = stat.executeQuery("SELECT MEDIAN(X) FROM SYSTEM_RANGE(1, 9)");
...@@ -85,7 +88,7 @@ public class TestFunctions extends TestBase { ...@@ -85,7 +88,7 @@ public class TestFunctions extends TestBase {
stat.execute("DROP AGGREGATE IF EXISTS MEDIAN"); stat.execute("DROP AGGREGATE IF EXISTS MEDIAN");
conn.close(); conn.close();
} }
private void testFunctions() throws Exception { private void testFunctions() throws Exception {
deleteDb("functions"); deleteDb("functions");
Connection conn = getConnection("functions"); Connection conn = getConnection("functions");
......
...@@ -13,6 +13,9 @@ import java.util.Random; ...@@ -13,6 +13,9 @@ import java.util.Random;
import org.h2.result.SortOrder; import org.h2.result.SortOrder;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/**
* Index tests.
*/
public class TestIndex extends TestBase { public class TestIndex extends TestBase {
Connection conn; Connection conn;
...@@ -30,7 +33,7 @@ public class TestIndex extends TestBase { ...@@ -30,7 +33,7 @@ public class TestIndex extends TestBase {
public void test() throws Exception { public void test() throws Exception {
testDescIndex(); testDescIndex();
if (config.networked && config.big) { if (config.networked && config.big) {
return; return;
} }
...@@ -70,7 +73,7 @@ public class TestIndex extends TestBase { ...@@ -70,7 +73,7 @@ public class TestIndex extends TestBase {
conn.close(); conn.close();
} }
void testDescIndex() throws Exception { void testDescIndex() throws Exception {
if (config.memory) { if (config.memory) {
return; return;
......
...@@ -15,6 +15,9 @@ import java.sql.Timestamp; ...@@ -15,6 +15,9 @@ import java.sql.Timestamp;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/**
* Tests the linked table feature (CREATE LINKED TABLE).
*/
public class TestLinkedTable extends TestBase { public class TestLinkedTable extends TestBase {
public void test() throws Exception { public void test() throws Exception {
...@@ -26,7 +29,7 @@ public class TestLinkedTable extends TestBase { ...@@ -26,7 +29,7 @@ public class TestLinkedTable extends TestBase {
testLinkTable(); testLinkTable();
testLinkTwoTables(); testLinkTwoTables();
} }
// this is not a bug, it is the documented behavior // this is not a bug, it is the documented behavior
// private void testLinkAutoAdd() throws Exception { // private void testLinkAutoAdd() throws Exception {
// Class.forName("org.h2.Driver"); // Class.forName("org.h2.Driver");
...@@ -42,7 +45,7 @@ public class TestLinkedTable extends TestBase { ...@@ -42,7 +45,7 @@ public class TestLinkedTable extends TestBase {
// ca.close(); // ca.close();
// cb.close(); // cb.close();
// } // }
private void testLinkOtherSchema() throws Exception { private void testLinkOtherSchema() throws Exception {
Class.forName("org.h2.Driver"); Class.forName("org.h2.Driver");
Connection ca = DriverManager.getConnection("jdbc:h2:mem:one", "sa", "sa"); Connection ca = DriverManager.getConnection("jdbc:h2:mem:one", "sa", "sa");
...@@ -59,7 +62,7 @@ public class TestLinkedTable extends TestBase { ...@@ -59,7 +62,7 @@ public class TestLinkedTable extends TestBase {
ca.close(); ca.close();
cb.close(); cb.close();
} }
private void testLinkTwoTables() throws Exception { private void testLinkTwoTables() throws Exception {
Class.forName("org.h2.Driver"); Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:mem:one", "sa", "sa"); Connection conn = DriverManager.getConnection("jdbc:h2:mem:one", "sa", "sa");
...@@ -131,7 +134,7 @@ public class TestLinkedTable extends TestBase { ...@@ -131,7 +134,7 @@ public class TestLinkedTable extends TestBase {
stat2.executeUpdate("UPDATE TEST_LINK_DI SET ID=ID+1"); stat2.executeUpdate("UPDATE TEST_LINK_DI SET ID=ID+1");
stat2.executeUpdate("UPDATE TEST_LINK_U SET NAME=NAME || ID"); stat2.executeUpdate("UPDATE TEST_LINK_U SET NAME=NAME || ID");
ResultSet rs; ResultSet rs;
rs = stat2.executeQuery("SELECT * FROM TEST_LINK_DI ORDER BY ID"); rs = stat2.executeQuery("SELECT * FROM TEST_LINK_DI ORDER BY ID");
rs.next(); rs.next();
check(rs.getInt(1), 2); check(rs.getInt(1), 2);
...@@ -140,7 +143,7 @@ public class TestLinkedTable extends TestBase { ...@@ -140,7 +143,7 @@ public class TestLinkedTable extends TestBase {
check(rs.getInt(1), 3); check(rs.getInt(1), 3);
check(rs.getString(2), "World3"); check(rs.getString(2), "World3");
checkFalse(rs.next()); checkFalse(rs.next());
rs = stat2.executeQuery("SELECT * FROM TEST_LINK_U ORDER BY ID"); rs = stat2.executeQuery("SELECT * FROM TEST_LINK_U ORDER BY ID");
rs.next(); rs.next();
check(rs.getInt(1), 2); check(rs.getInt(1), 2);
......
...@@ -14,6 +14,9 @@ import org.h2.api.DatabaseEventListener; ...@@ -14,6 +14,9 @@ import org.h2.api.DatabaseEventListener;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.util.JdbcUtils; import org.h2.util.JdbcUtils;
/**
* Tests the DatabaseEventListener.
*/
public class TestListener extends TestBase implements DatabaseEventListener { public class TestListener extends TestBase implements DatabaseEventListener {
private long last, start; private long last, start;
...@@ -85,7 +88,7 @@ public class TestListener extends TestBase implements DatabaseEventListener { ...@@ -85,7 +88,7 @@ public class TestListener extends TestBase implements DatabaseEventListener {
if (url.toUpperCase().indexOf("CIPHER") >= 0) { if (url.toUpperCase().indexOf("CIPHER") >= 0) {
return; return;
} }
Connection conn = null; Connection conn = null;
try { try {
conn = DriverManager.getConnection(url, getUser(), getPassword()); conn = DriverManager.getConnection(url, getUser(), getPassword());
conn.createStatement().execute("DROP TABLE TEST2"); conn.createStatement().execute("DROP TABLE TEST2");
...@@ -105,7 +108,7 @@ public class TestListener extends TestBase implements DatabaseEventListener { ...@@ -105,7 +108,7 @@ public class TestListener extends TestBase implements DatabaseEventListener {
if (url.toUpperCase().indexOf("CIPHER") >= 0) { if (url.toUpperCase().indexOf("CIPHER") >= 0) {
return; return;
} }
Connection conn = null; Connection conn = null;
try { try {
conn = DriverManager.getConnection(url, getUser(), getPassword()); conn = DriverManager.getConnection(url, getUser(), getPassword());
conn.createStatement().execute("CREATE TABLE IF NOT EXISTS TEST2(ID INT)"); conn.createStatement().execute("CREATE TABLE IF NOT EXISTS TEST2(ID INT)");
......
/* /*
* Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html). * Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group * Initial Developer: H2 Group
*/ */
package org.h2.test.db; package org.h2.test.db;
...@@ -26,9 +26,8 @@ import org.h2.util.IOUtils; ...@@ -26,9 +26,8 @@ import org.h2.util.IOUtils;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
/** /**
* @author Thomas * Tests LOB and CLOB data types.
*/ */
public class TestLob extends TestBase { public class TestLob extends TestBase {
public void test() throws Exception { public void test() throws Exception {
......
...@@ -6,6 +6,9 @@ package org.h2.test.db; ...@@ -6,6 +6,9 @@ package org.h2.test.db;
import java.io.Serializable; import java.io.Serializable;
/**
* A utility class for TestLob.
*/
class TestLobObject implements Serializable { class TestLobObject implements Serializable {
private static final long serialVersionUID = 904356179316518715L; private static final long serialVersionUID = 904356179316518715L;
String data; String data;
......
...@@ -13,6 +13,9 @@ import java.util.ArrayList; ...@@ -13,6 +13,9 @@ import java.util.ArrayList;
import org.h2.store.FileLister; import org.h2.store.FileLister;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/**
* Tests the database transaction log file.
*/
public class TestLogFile extends TestBase { public class TestLogFile extends TestBase {
private Connection conn; private Connection conn;
......
...@@ -12,6 +12,9 @@ import java.util.Random; ...@@ -12,6 +12,9 @@ import java.util.Random;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/**
* Tests the memory usage of the cache.
*/
public class TestMemoryUsage extends TestBase { public class TestMemoryUsage extends TestBase {
private Connection conn; private Connection conn;
......
/* /*
* Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html). * Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group * Initial Developer: H2 Group
*/ */
package org.h2.test.db; package org.h2.test.db;
...@@ -13,9 +13,8 @@ import org.h2.api.DatabaseEventListener; ...@@ -13,9 +13,8 @@ import org.h2.api.DatabaseEventListener;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/** /**
* @author Thomas * Multi-connection tests.
*/ */
public class TestMultiConn extends TestBase implements DatabaseEventListener { public class TestMultiConn extends TestBase implements DatabaseEventListener {
public void test() throws Exception { public void test() throws Exception {
...@@ -175,8 +174,8 @@ public class TestMultiConn extends TestBase implements DatabaseEventListener { ...@@ -175,8 +174,8 @@ public class TestMultiConn extends TestBase implements DatabaseEventListener {
public void init(String url) { public void init(String url) {
} }
public void opened() { public void opened() {
} }
} }
...@@ -13,6 +13,9 @@ import java.util.Random; ...@@ -13,6 +13,9 @@ import java.util.Random;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.tools.MultiDimension; import org.h2.tools.MultiDimension;
/**
* Tests the multi-dimension index tool.
*/
public class TestMultiDimension extends TestBase { public class TestMultiDimension extends TestBase {
public void test() throws Exception { public void test() throws Exception {
......
...@@ -13,6 +13,9 @@ import java.util.Random; ...@@ -13,6 +13,9 @@ import java.util.Random;
import org.h2.test.TestAll; import org.h2.test.TestAll;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/**
* Multi-threaded tests.
*/
public class TestMultiThread extends TestBase implements Runnable { public class TestMultiThread extends TestBase implements Runnable {
private boolean stop; private boolean stop;
......
...@@ -15,6 +15,9 @@ import org.h2.api.DatabaseEventListener; ...@@ -15,6 +15,9 @@ import org.h2.api.DatabaseEventListener;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.tools.Restore; import org.h2.tools.Restore;
/**
* Tests opening and closing a database.
*/
public class TestOpenClose extends TestBase implements DatabaseEventListener { public class TestOpenClose extends TestBase implements DatabaseEventListener {
int nextId = 10; int nextId = 10;
...@@ -171,8 +174,8 @@ public class TestOpenClose extends TestBase implements DatabaseEventListener { ...@@ -171,8 +174,8 @@ public class TestOpenClose extends TestBase implements DatabaseEventListener {
public void init(String url) { public void init(String url) {
} }
public void opened() { public void opened() {
} }
} }
...@@ -15,12 +15,16 @@ import java.util.TreeSet; ...@@ -15,12 +15,16 @@ import java.util.TreeSet;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/**
* Test various optimizations (query cache, optimization for MIN(..), and MAX(..)).
*/
public class TestOptimizations extends TestBase { public class TestOptimizations extends TestBase {
public void test() throws Exception { public void test() throws Exception {
if (config.networked) { if (config.networked) {
return; return;
} }
testDistinctOptimization();
testQueryCacheTimestamp(); testQueryCacheTimestamp();
testQueryCacheSpeed(); testQueryCacheSpeed();
testQueryCache(true); testQueryCache(true);
...@@ -30,6 +34,45 @@ public class TestOptimizations extends TestBase { ...@@ -30,6 +34,45 @@ public class TestOptimizations extends TestBase {
testMinMaxCountOptimization(false); testMinMaxCountOptimization(false);
} }
private void testDistinctOptimization() throws Exception {
deleteDb("optimizations");
Connection conn = getConnection("optimizations");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR, TYPE INT)");
stat.execute("CREATE INDEX IDX_TEST_TYPE ON TEST(TYPE)");
Random random = new Random(1);
int len = getSize(10000, 100000);
int[] groupCount = new int[10];
PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST VALUES(?, ?, ?)");
for (int i = 0; i < len; i++) {
prep.setInt(1, i);
prep.setString(2, "Hello World");
int type = random.nextInt(10);
groupCount[type]++;
prep.setInt(3, type);
prep.execute();
}
ResultSet rs;
rs = stat.executeQuery("SELECT TYPE, COUNT(*) FROM TEST GROUP BY TYPE ORDER BY TYPE");
for (int i = 0; rs.next(); i++) {
check(i, rs.getInt(1));
check(groupCount[i], rs.getInt(2));
}
checkFalse(rs.next());
rs = stat.executeQuery("SELECT DISTINCT TYPE FROM TEST ORDER BY TYPE");
for (int i = 0; rs.next(); i++) {
check(i, rs.getInt(1));
}
checkFalse(rs.next());
stat.execute("ANALYZE");
rs = stat.executeQuery("SELECT DISTINCT TYPE FROM TEST ORDER BY TYPE");
for (int i = 0; rs.next(); i++) {
check(i, rs.getInt(1));
}
checkFalse(rs.next());
conn.close();
}
private void testQueryCacheTimestamp() throws Exception { private void testQueryCacheTimestamp() throws Exception {
deleteDb("optimizations"); deleteDb("optimizations");
Connection conn = getConnection("optimizations"); Connection conn = getConnection("optimizations");
......
...@@ -21,6 +21,9 @@ import org.h2.test.TestBase; ...@@ -21,6 +21,9 @@ import org.h2.test.TestBase;
import org.h2.util.FileUtils; import org.h2.util.FileUtils;
import org.h2.util.JdbcUtils; import org.h2.util.JdbcUtils;
/**
* Tests simulated power off conditions.
*/
public class TestPowerOff extends TestBase { public class TestPowerOff extends TestBase {
private String dbName = "powerOff"; private String dbName = "powerOff";
......
...@@ -14,6 +14,9 @@ import java.util.ArrayList; ...@@ -14,6 +14,9 @@ import java.util.ArrayList;
import org.h2.store.FileLister; import org.h2.store.FileLister;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/**
* Test for the read-only database feature.
*/
public class TestReadOnly extends TestBase { public class TestReadOnly extends TestBase {
public void test() throws Exception { public void test() throws Exception {
......
...@@ -12,16 +12,19 @@ import java.sql.Statement; ...@@ -12,16 +12,19 @@ import java.sql.Statement;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/**
* Access rights tests.
*/
public class TestRights extends TestBase { public class TestRights extends TestBase {
private Statement stat; private Statement stat;
public void test() throws Exception { public void test() throws Exception {
// testLowerCaseUser(); // testLowerCaseUser();
testSchemaRenameUser(); testSchemaRenameUser();
testAccessRights(); testAccessRights();
} }
// public void testLowerCaseUser() throws Exception { // public void testLowerCaseUser() throws Exception {
// Documentation: For compatibility, only unquoted or uppercase user names are allowed. // Documentation: For compatibility, only unquoted or uppercase user names are allowed.
// deleteDb("rights"); // deleteDb("rights");
...@@ -68,7 +71,7 @@ public class TestRights extends TestBase { ...@@ -68,7 +71,7 @@ public class TestRights extends TestBase {
stat.execute("drop user test1"); stat.execute("drop user test1");
conn.close(); conn.close();
} }
public void testAccessRights() throws Exception { public void testAccessRights() throws Exception {
if (config.memory) { if (config.memory) {
return; return;
......
...@@ -11,6 +11,9 @@ import java.sql.Statement; ...@@ -11,6 +11,9 @@ import java.sql.Statement;
import org.h2.api.Trigger; import org.h2.api.Trigger;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/**
* Tests the RUNSCRIPT SQL statement.
*/
public class TestRunscript extends TestBase implements Trigger { public class TestRunscript extends TestBase implements Trigger {
public void test() throws Exception { public void test() throws Exception {
......
...@@ -12,6 +12,9 @@ import java.sql.Statement; ...@@ -12,6 +12,9 @@ import java.sql.Statement;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/**
* Tests the ALLOW_LITERALS feature (protection against SQL injection).
*/
public class TestSQLInjection extends TestBase { public class TestSQLInjection extends TestBase {
Connection conn; Connection conn;
......
...@@ -23,6 +23,9 @@ import org.h2.test.TestAll; ...@@ -23,6 +23,9 @@ import org.h2.test.TestAll;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
/**
* This test runs a SQL script file and compares the output with the expected output.
*/
public class TestScript extends TestBase { public class TestScript extends TestBase {
private boolean failFast; private boolean failFast;
......
...@@ -14,6 +14,9 @@ import java.sql.SQLException; ...@@ -14,6 +14,9 @@ import java.sql.SQLException;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.util.ScriptReader; import org.h2.util.ScriptReader;
/**
* This test runs a simple SQL script file and compares the output with the expected output.
*/
public class TestScriptSimple extends TestBase { public class TestScriptSimple extends TestBase {
private Connection conn; private Connection conn;
......
...@@ -10,13 +10,16 @@ import java.sql.Statement; ...@@ -10,13 +10,16 @@ import java.sql.Statement;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/**
* Tests the sequence feature of this database.
*/
public class TestSequence extends TestBase { public class TestSequence extends TestBase {
public void test() throws Exception { public void test() throws Exception {
testCache(); testCache();
testTwo(); testTwo();
} }
private void testCache() throws Exception { private void testCache() throws Exception {
if (config.memory) { if (config.memory) {
return; return;
...@@ -41,7 +44,7 @@ public class TestSequence extends TestBase { ...@@ -41,7 +44,7 @@ public class TestSequence extends TestBase {
checkFalse(rs.next()); checkFalse(rs.next());
conn.close(); conn.close();
} }
private void testTwo() throws Exception { private void testTwo() throws Exception {
deleteDb("sequence"); deleteDb("sequence");
Connection conn = getConnection("sequence"); Connection conn = getConnection("sequence");
......
...@@ -11,6 +11,9 @@ import java.sql.Statement; ...@@ -11,6 +11,9 @@ import java.sql.Statement;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/**
* Tests the meta data tables information_schema.locks and sessions.
*/
public class TestSessionsLocks extends TestBase { public class TestSessionsLocks extends TestBase {
public void test() throws Exception { public void test() throws Exception {
......
...@@ -10,6 +10,9 @@ import java.sql.Statement; ...@@ -10,6 +10,9 @@ import java.sql.Statement;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/**
* Tests if disk space is reused after deleting many rows.
*/
public class TestSpaceReuse extends TestBase { public class TestSpaceReuse extends TestBase {
public void test() throws Exception { public void test() throws Exception {
......
/* /*
* Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html). * Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group * Initial Developer: H2 Group
*/ */
package org.h2.test.db; package org.h2.test.db;
...@@ -11,9 +11,8 @@ import java.sql.Statement; ...@@ -11,9 +11,8 @@ import java.sql.Statement;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/** /**
* @author Thomas * Various small performance tests.
*/ */
public class TestSpeed extends TestBase { public class TestSpeed extends TestBase {
// java -cp .;..\..\hsqldb\lib\hsqldb.jar -Xrunhprof:heap=sites,depth=6 // java -cp .;..\..\hsqldb\lib\hsqldb.jar -Xrunhprof:heap=sites,depth=6
...@@ -59,7 +58,7 @@ public class TestSpeed extends TestBase { ...@@ -59,7 +58,7 @@ public class TestSpeed extends TestBase {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
// for(int i=1; i<8000; i*=2) { // for(int i=1; i<8000; i*=2) {
// stat.execute("INSERT INTO TEST_A SELECT ID+"+i+", NAME FROM TEST_A"); // stat.execute("INSERT INTO TEST_A SELECT ID+"+i+", NAME FROM TEST_A");
// //
// // stat.execute("INSERT INTO TEST_A VALUES("+i+", 'Hello')"); // // stat.execute("INSERT INTO TEST_A VALUES("+i+", 'Hello')");
// } // }
// for(int i=0; i<4; i++) { // for(int i=0; i<4; i++) {
...@@ -71,7 +70,7 @@ public class TestSpeed extends TestBase { ...@@ -71,7 +70,7 @@ public class TestSpeed extends TestBase {
// } // }
// System.out.println(System.currentTimeMillis()-time); // System.out.println(System.currentTimeMillis()-time);
// //
// stat.execute("CREATE TABLE TEST_B(ID INT PRIMARY KEY, NAME // stat.execute("CREATE TABLE TEST_B(ID INT PRIMARY KEY, NAME
// VARCHAR(255))"); // VARCHAR(255))");
// for(int i=0; i<80000; i++) { // for(int i=0; i<80000; i++) {
...@@ -82,7 +81,7 @@ public class TestSpeed extends TestBase { ...@@ -82,7 +81,7 @@ public class TestSpeed extends TestBase {
// System.exit(0); // System.exit(0);
// int testParser; // int testParser;
// java -Xrunhprof:cpu=samples,depth=8 -cp . org.h2.test.TestAll // java -Xrunhprof:cpu=samples,depth=8 -cp . org.h2.test.TestAll
// //
// stat.execute("CREATE TABLE TEST(ID INT)"); // stat.execute("CREATE TABLE TEST(ID INT)");
// stat.execute("INSERT INTO TEST VALUES(1)"); // stat.execute("INSERT INTO TEST VALUES(1)");
// ResultSet rs = stat.executeQuery("SELECT ID OTHER_ID FROM TEST"); // ResultSet rs = stat.executeQuery("SELECT ID OTHER_ID FROM TEST");
......
...@@ -11,6 +11,9 @@ import java.sql.Statement; ...@@ -11,6 +11,9 @@ import java.sql.Statement;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/**
* Temporary table tests.
*/
public class TestTempTables extends TestBase { public class TestTempTables extends TestBase {
public void test() throws Exception { public void test() throws Exception {
......
...@@ -15,6 +15,9 @@ import java.util.Vector; ...@@ -15,6 +15,9 @@ import java.util.Vector;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/**
* Transactional tests, including transaction isolation tests, and tests related to savepoints.
*/
public class TestTransaction extends TestBase { public class TestTransaction extends TestBase {
public void test() throws Exception { public void test() throws Exception {
...@@ -22,9 +25,9 @@ public class TestTransaction extends TestBase { ...@@ -22,9 +25,9 @@ public class TestTransaction extends TestBase {
testSavepoint(); testSavepoint();
testIsolation(); testIsolation();
} }
private void testReferential() throws Exception { private void testReferential() throws Exception {
deleteDb("transaction"); deleteDb("transaction");
Connection c1 = getConnection("transaction"); Connection c1 = getConnection("transaction");
c1.setAutoCommit(false); c1.setAutoCommit(false);
Statement s1 = c1.createStatement(); Statement s1 = c1.createStatement();
...@@ -43,7 +46,7 @@ public class TestTransaction extends TestBase { ...@@ -43,7 +46,7 @@ public class TestTransaction extends TestBase {
checkNotGeneralException(e); checkNotGeneralException(e);
} }
c2.commit(); c2.commit();
c1.rollback(); c1.rollback();
c1.close(); c1.close();
c2.close(); c2.close();
} }
......
...@@ -15,9 +15,8 @@ import org.h2.api.Trigger; ...@@ -15,9 +15,8 @@ import org.h2.api.Trigger;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/** /**
* @author Thomas * Tests for trigger and constraints.
*/ */
public class TestTriggersConstraints extends TestBase implements Trigger { public class TestTriggersConstraints extends TestBase implements Trigger {
private static boolean mustNotCallTrigger; private static boolean mustNotCallTrigger;
......
...@@ -11,6 +11,9 @@ import java.util.ArrayList; ...@@ -11,6 +11,9 @@ import java.util.ArrayList;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/**
* Tests for the two-phase-commit feature.
*/
public class TestTwoPhaseCommit extends TestBase { public class TestTwoPhaseCommit extends TestBase {
public void test() throws Exception { public void test() throws Exception {
if (config.memory || config.networked || config.logMode == 0) { if (config.memory || config.networked || config.logMode == 0) {
......
...@@ -10,6 +10,9 @@ import java.sql.Statement; ...@@ -10,6 +10,9 @@ import java.sql.Statement;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/**
* Test for views.
*/
public class TestView extends TestBase { public class TestView extends TestBase {
public void test() throws Exception { public void test() throws Exception {
......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
Database tests. Most tests are on the SQL level.
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
JDBC API tests.
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
Tests related to distributed transactions.
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
Multi version concurrency tests.
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
High level test classes.
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
Multi version concurrency tests.
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
This package contains server tests.
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
Synthetic tests using random operations or statements.
</body></html>
\ No newline at end of file
...@@ -993,7 +993,7 @@ script nopasswords nosettings blocksize 10; ...@@ -993,7 +993,7 @@ script nopasswords nosettings blocksize 10;
> DROP ALIAS IF EXISTS SYSTEM_COMBINE_BLOB; > DROP ALIAS IF EXISTS SYSTEM_COMBINE_BLOB;
> DROP ALIAS IF EXISTS SYSTEM_COMBINE_CLOB; > DROP ALIAS IF EXISTS SYSTEM_COMBINE_CLOB;
> DROP TABLE IF EXISTS SYSTEM_LOB_STREAM; > DROP TABLE IF EXISTS SYSTEM_LOB_STREAM;
> INSERT INTO PUBLIC.TEST(ID, DATA) VALUES(1, SYSTEM_COMBINE_CLOB(0)); > INSERT INTO PUBLIC.TEST(ID, DATA) VALUES (1, SYSTEM_COMBINE_CLOB(0));
> INSERT INTO SYSTEM_LOB_STREAM VALUES(0, 0, 'abc ', NULL); > INSERT INTO SYSTEM_LOB_STREAM VALUES(0, 0, 'abc ', NULL);
> INSERT INTO SYSTEM_LOB_STREAM VALUES(0, 1, ' ', NULL); > INSERT INTO SYSTEM_LOB_STREAM VALUES(0, 1, ' ', NULL);
> INSERT INTO SYSTEM_LOB_STREAM VALUES(0, 2, ' ', NULL); > INSERT INTO SYSTEM_LOB_STREAM VALUES(0, 2, ' ', NULL);
...@@ -2862,7 +2862,7 @@ script NOPASSWORDS NOSETTINGS drop; ...@@ -2862,7 +2862,7 @@ script NOPASSWORDS NOSETTINGS drop;
> CREATE PRIMARY KEY ON PUBLIC.TEST(I); > CREATE PRIMARY KEY ON PUBLIC.TEST(I);
> CREATE USER IF NOT EXISTS SA PASSWORD '' ADMIN; > CREATE USER IF NOT EXISTS SA PASSWORD '' ADMIN;
> DROP TABLE IF EXISTS PUBLIC.TEST; > DROP TABLE IF EXISTS PUBLIC.TEST;
> INSERT INTO PUBLIC.TEST(I, NAME, Y) VALUES(1, 'Hello', 2); > INSERT INTO PUBLIC.TEST(I, NAME, Y) VALUES (1, 'Hello', 2);
> rows: 8 > rows: 8
INSERT INTO TEST(i, name) VALUES(2, 'World'); INSERT INTO TEST(i, name) VALUES(2, 'World');
...@@ -3888,7 +3888,7 @@ insert into test values(1, '', ''); ...@@ -3888,7 +3888,7 @@ insert into test values(1, '', '');
insert into test values(2, 'Cafe', X'cafe'); insert into test values(2, 'Cafe', X'cafe');
> update count: 1 > update count: 1
script nopasswords nosettings; script simple nopasswords nosettings;
> SCRIPT > SCRIPT
> ------------------------------------------------------------------------------- > -------------------------------------------------------------------------------
> -- 3 = SELECT COUNT(*) FROM PUBLIC.TEST; > -- 3 = SELECT COUNT(*) FROM PUBLIC.TEST;
...@@ -4422,7 +4422,7 @@ SELECT * FROM TEST_SEQ ORDER BY ID; ...@@ -4422,7 +4422,7 @@ SELECT * FROM TEST_SEQ ORDER BY ID;
> 20 20 > 20 20
> rows (ordered): 4 > rows (ordered): 4
SCRIPT NOPASSWORDS NOSETTINGS; SCRIPT SIMPLE NOPASSWORDS NOSETTINGS;
> SCRIPT > SCRIPT
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ > ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> -- 1 = SELECT COUNT(*) FROM PUBLIC.TEST; > -- 1 = SELECT COUNT(*) FROM PUBLIC.TEST;
...@@ -4464,7 +4464,7 @@ SCRIPT NOPASSWORDS NOSETTINGS; ...@@ -4464,7 +4464,7 @@ SCRIPT NOPASSWORDS NOSETTINGS;
> CREATE MEMORY TABLE PUBLIC.TEST( ID INT NOT NULL, CREATEDATE VARCHAR(255) DEFAULT '2001-01-01' NOT NULL, MODIFY_DATE TIMESTAMP ); > CREATE MEMORY TABLE PUBLIC.TEST( ID INT NOT NULL, CREATEDATE VARCHAR(255) DEFAULT '2001-01-01' NOT NULL, MODIFY_DATE TIMESTAMP );
> CREATE PRIMARY KEY ON PUBLIC.TEST(ID); > CREATE PRIMARY KEY ON PUBLIC.TEST(ID);
> CREATE USER IF NOT EXISTS SA PASSWORD '' ADMIN; > CREATE USER IF NOT EXISTS SA PASSWORD '' ADMIN;
> INSERT INTO PUBLIC.TEST(ID, CREATEDATE, MODIFY_DATE) VALUES(1, '2001-01-01', NULL); > INSERT INTO PUBLIC.TEST(ID, CREATEDATE, MODIFY_DATE) VALUES (1, '2001-01-01', NULL);
> rows: 5 > rows: 5
ALTER TABLE TEST ADD NAME VARCHAR(255) NULL BEFORE CREATEDATE; ALTER TABLE TEST ADD NAME VARCHAR(255) NULL BEFORE CREATEDATE;
...@@ -4477,7 +4477,7 @@ SCRIPT NOPASSWORDS NOSETTINGS; ...@@ -4477,7 +4477,7 @@ SCRIPT NOPASSWORDS NOSETTINGS;
> CREATE MEMORY TABLE PUBLIC.TEST( ID INT NOT NULL, NAME VARCHAR(255), CREATEDATE VARCHAR(255) DEFAULT '2001-01-01' NOT NULL, MODIFY_DATE TIMESTAMP ); > CREATE MEMORY TABLE PUBLIC.TEST( ID INT NOT NULL, NAME VARCHAR(255), CREATEDATE VARCHAR(255) DEFAULT '2001-01-01' NOT NULL, MODIFY_DATE TIMESTAMP );
> CREATE PRIMARY KEY ON PUBLIC.TEST(ID); > CREATE PRIMARY KEY ON PUBLIC.TEST(ID);
> CREATE USER IF NOT EXISTS SA PASSWORD '' ADMIN; > CREATE USER IF NOT EXISTS SA PASSWORD '' ADMIN;
> INSERT INTO PUBLIC.TEST(ID, NAME, CREATEDATE, MODIFY_DATE) VALUES(1, NULL, '2001-01-01', NULL); > INSERT INTO PUBLIC.TEST(ID, NAME, CREATEDATE, MODIFY_DATE) VALUES (1, NULL, '2001-01-01', NULL);
> rows: 5 > rows: 5
UPDATE TEST SET NAME = 'Hi'; UPDATE TEST SET NAME = 'Hi';
...@@ -6044,7 +6044,7 @@ CAST(XT AS TIMESTAMP) D2TS, CAST(XD AS TIMESTAMP) D2TS FROM TEST; ...@@ -6044,7 +6044,7 @@ CAST(XT AS TIMESTAMP) D2TS, CAST(XD AS TIMESTAMP) D2TS FROM TEST;
> null null null null null null null > null null null null null null null
> rows: 4 > rows: 4
SCRIPT NOPASSWORDS NOSETTINGS; SCRIPT SIMPLE NOPASSWORDS NOSETTINGS;
> SCRIPT > SCRIPT
> ---------------------------------------------------------------------------------------------------------------------------------- > ----------------------------------------------------------------------------------------------------------------------------------
> -- 4 = SELECT COUNT(*) FROM PUBLIC.TEST; > -- 4 = SELECT COUNT(*) FROM PUBLIC.TEST;
...@@ -7146,7 +7146,7 @@ SCRIPT NOPASSWORDS NOSETTINGS; ...@@ -7146,7 +7146,7 @@ SCRIPT NOPASSWORDS NOSETTINGS;
> CREATE PRIMARY KEY ON PUBLIC.A_TEST(A_INT); > CREATE PRIMARY KEY ON PUBLIC.A_TEST(A_INT);
> CREATE PRIMARY KEY ON PUBLIC.B_TEST(B_INT); > CREATE PRIMARY KEY ON PUBLIC.B_TEST(B_INT);
> CREATE USER IF NOT EXISTS SA PASSWORD '' ADMIN; > CREATE USER IF NOT EXISTS SA PASSWORD '' ADMIN;
> INSERT INTO PUBLIC.B_TEST(B_INT, B_VARCHAR) VALUES(-1, 'XX'); > INSERT INTO PUBLIC.B_TEST(B_INT, B_VARCHAR) VALUES (-1, 'XX');
> rows: 14 > rows: 14
DROP TABLE A_TEST; DROP TABLE A_TEST;
...@@ -7231,7 +7231,7 @@ SELECT * FROM CHILD; ...@@ -7231,7 +7231,7 @@ SELECT * FROM CHILD;
> 201 null null Johann > 201 null null Johann
> rows: 4 > rows: 4
SCRIPT NOPASSWORDS NOSETTINGS; SCRIPT SIMPLE NOPASSWORDS NOSETTINGS;
> SCRIPT > SCRIPT
> ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- > ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> -- 1 = SELECT COUNT(*) FROM PUBLIC.FAMILY; > -- 1 = SELECT COUNT(*) FROM PUBLIC.FAMILY;
...@@ -7256,7 +7256,7 @@ SCRIPT NOPASSWORDS NOSETTINGS; ...@@ -7256,7 +7256,7 @@ SCRIPT NOPASSWORDS NOSETTINGS;
ALTER TABLE CHILD DROP CONSTRAINT PARENT_CHILD; ALTER TABLE CHILD DROP CONSTRAINT PARENT_CHILD;
> ok > ok
SCRIPT NOPASSWORDS NOSETTINGS; SCRIPT SIMPLE NOPASSWORDS NOSETTINGS;
> SCRIPT > SCRIPT
> -------------------------------------------------------------------------------------------------------------------------- > --------------------------------------------------------------------------------------------------------------------------
> -- 1 = SELECT COUNT(*) FROM PUBLIC.FAMILY; > -- 1 = SELECT COUNT(*) FROM PUBLIC.FAMILY;
...@@ -7568,12 +7568,12 @@ INSERT INTO TEST VALUES(2, STRINGDECODE('abcsond\344rzeich\344 ') || char(22222) ...@@ -7568,12 +7568,12 @@ INSERT INTO TEST VALUES(2, STRINGDECODE('abcsond\344rzeich\344 ') || char(22222)
script nopasswords nosettings; script nopasswords nosettings;
> SCRIPT > SCRIPT
> ------------------------------------------------------------------------------------------------------------------------------------------------------------ > -------------------------------------------------------------------------------------------------------------------------------------------------------------
> -- 1 = SELECT COUNT(*) FROM PUBLIC.TEST; > -- 1 = SELECT COUNT(*) FROM PUBLIC.TEST;
> CREATE MEMORY TABLE PUBLIC.TEST( ID INT NOT NULL, NAME VARCHAR(255) ); > CREATE MEMORY TABLE PUBLIC.TEST( ID INT NOT NULL, NAME VARCHAR(255) );
> CREATE PRIMARY KEY ON PUBLIC.TEST(ID); > CREATE PRIMARY KEY ON PUBLIC.TEST(ID);
> CREATE USER IF NOT EXISTS SA PASSWORD '' ADMIN; > CREATE USER IF NOT EXISTS SA PASSWORD '' ADMIN;
> INSERT INTO PUBLIC.TEST(ID, NAME) VALUES(2, STRINGDECODE('abcsond\u00e4rzeich\u00e4 \u56ce \u00f6\u00e4\u00fc\u00d6\u00c4\u00dc\u00e9\u00e8\u00e0\u00f1!')); > INSERT INTO PUBLIC.TEST(ID, NAME) VALUES (2, STRINGDECODE('abcsond\u00e4rzeich\u00e4 \u56ce \u00f6\u00e4\u00fc\u00d6\u00c4\u00dc\u00e9\u00e8\u00e0\u00f1!'));
> rows: 5 > rows: 5
call STRINGENCODE(STRINGDECODE('abcsond\344rzeich\344 \u56ce \366\344\374\326\304\334\351\350\340\361!')); call STRINGENCODE(STRINGDECODE('abcsond\344rzeich\344 \u56ce \366\344\374\326\304\334\351\350\340\361!'));
......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
A player to interpret and execute Java statements in a trace file.
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
Unit tests that don't start the database (in most cases).
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
Security tools.
</body></html>
\ No newline at end of file
package org.h2.tools.code;
import java.io.File;
/**
* This tool checks that for each .java file there is a package.html file.
*/
public class CheckPackageHtml {
private boolean hasError;
public static void main(String[] args) throws Exception {
new CheckPackageHtml().run();
}
void run() throws Exception {
String baseDir = "src";
check(new File(baseDir));
if (hasError) {
throw new Exception("Errors found");
}
}
private int check(File file) throws Exception {
String name = file.getName();
if (file.isDirectory()) {
if (name.equals("CVS") || name.equals(".svn")) {
return 0;
}
File[] list = file.listFiles();
boolean foundPackageHtml = false, foundJava = false;
for (int i = 0; i < list.length; i++) {
int type = check(list[i]);
if (type == 1) {
foundJava = true;
} else if (type == 2) {
foundPackageHtml = true;
}
}
if (foundJava && !foundPackageHtml) {
System.out.println("No package.html file, but a Java file found at: " + file.getAbsolutePath());
hasError = true;
}
} else {
if (name.endsWith(".java")) {
return 1;
} else if (name.equals("package.html")) {
return 2;
}
}
return 0;
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
Source code checking classes.
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
Tools to build the documentation.
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
A Javadoc doclet to build nicer and smaller API Javadoc HTML files.
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
Internationalization tools.
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
A Javadoc indexing mechanism.
</body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2007 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;">
A tool to redirect and interpret PostgreSQL network protocol packets.
</body></html>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论