use of org.h2.command.dml.Insert in project h2database by h2database.
the class TestRecovery method testCompressedAndUncompressed.
private void testCompressedAndUncompressed() throws SQLException {
DeleteDbFiles.execute(getBaseDir(), "recovery", true);
DeleteDbFiles.execute(getBaseDir(), "recovery2", true);
org.h2.Driver.load();
Connection conn = getConnection("recovery");
Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key, data clob)");
stat.execute("insert into test values(1, space(10000))");
stat.execute("set compress_lob lzf");
stat.execute("insert into test values(2, space(10000))");
conn.close();
Recover rec = new Recover();
rec.runTool("-dir", getBaseDir(), "-db", "recovery");
Connection conn2 = getConnection("recovery2");
Statement stat2 = conn2.createStatement();
String name = "recovery.h2.sql";
stat2.execute("runscript from '" + getBaseDir() + "/" + name + "'");
stat2.execute("select * from test");
conn2.close();
conn = getConnection("recovery");
stat = conn.createStatement();
conn2 = getConnection("recovery2");
stat2 = conn2.createStatement();
assertEqualDatabases(stat, stat2);
conn.close();
conn2.close();
DeleteDbFiles.execute(getBaseDir(), "recovery", true);
DeleteDbFiles.execute(getBaseDir(), "recovery2", true);
}
use of org.h2.command.dml.Insert in project h2database by h2database.
the class TestShell method test.
private void test(final boolean commandLineArgs) throws IOException {
PipedInputStream testIn = new PipedInputStream();
PipedOutputStream out = new PipedOutputStream(testIn);
toolOut = new PrintStream(out, true);
out = new PipedOutputStream();
PrintStream testOut = new PrintStream(out, true);
toolIn = new PipedInputStream(out);
Task task = new Task() {
@Override
public void call() throws Exception {
try {
Shell shell = new Shell();
shell.setIn(toolIn);
shell.setOut(toolOut);
shell.setErr(toolOut);
if (commandLineArgs) {
shell.runTool("-url", "jdbc:h2:mem:", "-user", "sa", "-password", "sa");
} else {
shell.runTool();
}
} finally {
toolOut.close();
}
}
};
task.execute();
InputStreamReader reader = new InputStreamReader(testIn);
lineReader = new LineNumberReader(reader);
read("");
read("Welcome to H2 Shell");
read("Exit with");
if (!commandLineArgs) {
read("[Enter]");
testOut.println("jdbc:h2:mem:");
read("URL");
testOut.println("");
read("Driver");
testOut.println("sa");
read("User");
testOut.println("sa");
read("Password");
}
read("Commands are case insensitive");
read("help or ?");
read("list");
read("maxwidth");
read("autocommit");
read("history");
read("quit or exit");
read("");
testOut.println("history");
read("sql> No history");
testOut.println("1");
read("sql> Not found");
testOut.println("select 1 a;");
read("sql> A");
read("1");
read("(1 row,");
testOut.println("history");
read("sql> #1: select 1 a");
read("To re-run a statement, type the number and press and enter");
testOut.println("1");
read("sql> select 1 a");
read("A");
read("1");
read("(1 row,");
testOut.println("select 'x' || space(1000) large, 'y' small;");
read("sql> LARGE");
read("x");
read("(data is partially truncated)");
read("(1 row,");
testOut.println("select x, 's' s from system_range(0, 10001);");
read("sql> X | S");
for (int i = 0; i < 10000; i++) {
read((i + " ").substring(0, 4) + " | s");
}
for (int i = 10000; i <= 10001; i++) {
read((i + " ").substring(0, 5) + " | s");
}
read("(10002 rows,");
testOut.println("select error;");
read("sql> Error:");
if (read("").startsWith("Column \"ERROR\" not found")) {
read("");
}
testOut.println("create table test(id int primary key, name varchar)\n;");
read("sql> ...>");
testOut.println("insert into test values(1, 'Hello');");
read("sql>");
testOut.println("select null n, * from test;");
read("sql> N | ID | NAME");
read("null | 1 | Hello");
read("(1 row,");
// test history
for (int i = 0; i < 30; i++) {
testOut.println("select " + i + " ID from test;");
read("sql> ID");
read("" + i);
read("(1 row,");
}
testOut.println("20");
read("sql> select 10 ID from test");
read("ID");
read("10");
read("(1 row,");
testOut.println("maxwidth");
read("sql> Usage: maxwidth <integer value>");
read("Maximum column width is now 100");
testOut.println("maxwidth 80");
read("sql> Maximum column width is now 80");
testOut.println("autocommit");
read("sql> Usage: autocommit [true|false]");
read("Autocommit is now true");
testOut.println("autocommit false");
read("sql> Autocommit is now false");
testOut.println("autocommit true");
read("sql> Autocommit is now true");
testOut.println("list");
read("sql> Result list mode is now on");
testOut.println("select 1 first, 2 second;");
read("sql> FIRST : 1");
read("SECOND: 2");
read("(1 row, ");
testOut.println("select x from system_range(1, 3);");
read("sql> X: 1");
read("");
read("X: 2");
read("");
read("X: 3");
read("(3 rows, ");
testOut.println("select x, 2 as y from system_range(1, 3) where 1 = 0;");
read("sql> X");
read("Y");
read("(0 rows, ");
testOut.println("list");
read("sql> Result list mode is now off");
testOut.println("help");
read("sql> Commands are case insensitive");
read("help or ?");
read("list");
read("maxwidth");
read("autocommit");
read("history");
read("quit or exit");
read("");
testOut.println("exit");
read("sql>");
task.get();
}
use of org.h2.command.dml.Insert in project h2database by h2database.
the class TestConnectionInfo method testConnectionInfo.
private void testConnectionInfo() {
Properties info = new Properties();
ConnectionInfo connectionInfo = new ConnectionInfo("jdbc:h2:mem:" + getTestName() + ";LOG=2" + ";ACCESS_MODE_DATA=rws" + ";INIT=CREATE this...\\;INSERT that..." + ";IFEXISTS=TRUE", info);
assertEquals("jdbc:h2:mem:" + getTestName(), connectionInfo.getURL());
assertEquals("2", connectionInfo.getProperty("LOG", ""));
assertEquals("rws", connectionInfo.getProperty("ACCESS_MODE_DATA", ""));
assertEquals("CREATE this...;INSERT that...", connectionInfo.getProperty("INIT", ""));
assertEquals("TRUE", connectionInfo.getProperty("IFEXISTS", ""));
assertEquals("undefined", connectionInfo.getProperty("CACHE_TYPE", "undefined"));
}
use of org.h2.command.dml.Insert in project h2database by h2database.
the class TestFileLockSerialized method testCheckpointInUpdateRaceCondition.
/**
* If a checkpoint occurs between beforeWriting and checkWritingAllowed then
* the result of checkWritingAllowed is READ_ONLY, which is wrong.
*
* Also, if a checkpoint started before beforeWriting, and ends between
* between beforeWriting and checkWritingAllowed, then the same error
* occurs.
*/
private void testCheckpointInUpdateRaceCondition() throws Exception {
boolean longRun = false;
deleteDb("fileLockSerialized");
String url = "jdbc:h2:" + getBaseDir() + "/fileLockSerialized;FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE";
Connection conn = getConnection(url);
conn.createStatement().execute("create table test(id int)");
conn.createStatement().execute("insert into test values(1)");
for (int i = 0; i < (longRun ? 10000 : 5); i++) {
Thread.sleep(402);
conn.createStatement().execute("update test set id = " + i);
}
conn.close();
deleteDb("fileLockSerialized");
}
use of org.h2.command.dml.Insert in project h2database by h2database.
the class TestFileLockSerialized method testKillWriter.
private void testKillWriter() throws Exception {
deleteDb("fileLockSerialized");
String url = "jdbc:h2:" + getBaseDir() + "/fileLockSerialized";
String writeUrl = url + ";FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE;WRITE_DELAY=0";
Connection conn = getConnection(writeUrl, "sa", "sa");
Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key)");
((JdbcConnection) conn).setPowerOffCount(1);
assertThrows(ErrorCode.DATABASE_IS_CLOSED, stat).execute("insert into test values(1)");
Connection conn2 = getConnection(writeUrl, "sa", "sa");
Statement stat2 = conn2.createStatement();
stat2.execute("insert into test values(1)");
printResult(stat2, "select * from test");
conn2.close();
assertThrows(ErrorCode.DATABASE_IS_CLOSED, conn).close();
}
Aggregations