use of org.h2.command.dml.Call in project h2database by h2database.
the class TestFunctions method testWhiteSpacesInParameters.
private void testWhiteSpacesInParameters() throws SQLException {
deleteDb("functions");
Connection conn = getConnection("functions");
Statement stat = conn.createStatement();
// with white space
stat.execute("CREATE ALIAS PARSE_INT2 FOR " + "\"java.lang.Integer.parseInt(java.lang.String, int)\"");
ResultSet rs;
rs = stat.executeQuery("CALL PARSE_INT2('473', 10)");
rs.next();
assertEquals(473, rs.getInt(1));
stat.execute("DROP ALIAS PARSE_INT2");
// without white space
stat.execute("CREATE ALIAS PARSE_INT2 FOR " + "\"java.lang.Integer.parseInt(java.lang.String,int)\"");
stat.execute("DROP ALIAS PARSE_INT2");
conn.close();
}
use of org.h2.command.dml.Call in project h2database by h2database.
the class TestLob method testDeadlock.
/**
* Test for issue 315: Java Level Deadlock on Database & Session Objects
*/
private void testDeadlock() throws Exception {
deleteDb("lob");
Connection conn = getConnection("lob");
Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key, name clob)");
stat.execute("insert into test select x, space(10000) from system_range(1, 3)");
final Connection conn2 = getConnection("lob");
Task task = new Task() {
@Override
public void call() throws Exception {
Statement stat = conn2.createStatement();
stat.setFetchSize(1);
for (int i = 0; !stop; i++) {
ResultSet rs = stat.executeQuery("select * from test where id > -" + i);
while (rs.next()) {
// ignore
}
}
}
};
task.execute();
stat.execute("create table test2(id int primary key, name clob)");
for (int i = 0; i < 100; i++) {
stat.execute("delete from test2");
stat.execute("insert into test2 values(1, space(10000 + " + i + "))");
}
task.get();
conn.close();
conn2.close();
}
use of org.h2.command.dml.Call in project h2database by h2database.
the class TestLob method testLobVariable.
private void testLobVariable() throws SQLException {
deleteDb("lob");
Connection conn = reconnect(null);
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT, DATA CLOB)");
stat.execute("INSERT INTO TEST VALUES(1, SPACE(100000))");
stat.execute("SET @TOTAL = SELECT DATA FROM TEST WHERE ID=1");
stat.execute("DROP TABLE TEST");
stat.execute("CALL @TOTAL LIKE '%X'");
stat.execute("CREATE TABLE TEST(ID INT, DATA CLOB)");
stat.execute("INSERT INTO TEST VALUES(1, @TOTAL)");
stat.execute("INSERT INTO TEST VALUES(2, @TOTAL)");
stat.execute("DROP TABLE TEST");
stat.execute("CALL @TOTAL LIKE '%X'");
conn.close();
}
use of org.h2.command.dml.Call in project h2database by h2database.
the class TestLob method testConcurrentCreate.
private void testConcurrentCreate() throws Exception {
deleteDb("lob");
final JdbcConnection conn1 = (JdbcConnection) getConnection("lob");
final JdbcConnection conn2 = (JdbcConnection) getConnection("lob");
conn1.setAutoCommit(false);
conn2.setAutoCommit(false);
final byte[] buffer = new byte[10000];
Task task1 = new Task() {
@Override
public void call() throws Exception {
while (!stop) {
Blob b = conn1.createBlob();
OutputStream out = b.setBinaryStream(1);
out.write(buffer);
out.close();
}
}
};
Task task2 = new Task() {
@Override
public void call() throws Exception {
while (!stop) {
Blob b = conn2.createBlob();
OutputStream out = b.setBinaryStream(1);
out.write(buffer);
out.close();
}
}
};
task1.execute();
task2.execute();
Thread.sleep(1000);
task1.get();
task2.get();
conn1.close();
conn2.close();
}
use of org.h2.command.dml.Call in project h2database by h2database.
the class TestCsv method testNull.
/**
* Test custom NULL string.
*/
private void testNull() throws Exception {
deleteDb("csv");
String fileName = getBaseDir() + "/testNull.csv";
FileUtils.delete(fileName);
OutputStream out = FileUtils.newOutputStream(fileName, false);
String csvContent = "\"A\",\"B\",\"C\",\"D\"\n\\N,\"\",\"\\N\",";
byte[] b = csvContent.getBytes(StandardCharsets.UTF_8);
out.write(b, 0, b.length);
out.close();
Csv csv = new Csv();
csv.setNullString("\\N");
ResultSet rs = csv.read(fileName, null, "UTF8");
ResultSetMetaData meta = rs.getMetaData();
assertEquals(4, meta.getColumnCount());
assertEquals("A", meta.getColumnLabel(1));
assertEquals("B", meta.getColumnLabel(2));
assertEquals("C", meta.getColumnLabel(3));
assertEquals("D", meta.getColumnLabel(4));
assertTrue(rs.next());
assertEquals(null, rs.getString(1));
assertEquals("", rs.getString(2));
// null is never quoted
assertEquals("\\N", rs.getString(3));
// an empty string is always parsed as null
assertEquals(null, rs.getString(4));
assertFalse(rs.next());
Connection conn = getConnection("csv");
Statement stat = conn.createStatement();
stat.execute("call csvwrite('" + fileName + "', 'select NULL as a, '''' as b, ''\\N'' as c, NULL as d', " + "'UTF8', ',', '\"', NULL, '\\N', '\n')");
InputStreamReader reader = new InputStreamReader(FileUtils.newInputStream(fileName));
// on read, an empty string is treated like null,
// but on write a null is always written with the nullString
String data = IOUtils.readStringAndClose(reader, -1);
assertEquals(csvContent + "\\N", data.trim());
conn.close();
FileUtils.delete(fileName);
}
Aggregations