提交 59ec5233 authored 作者: Thomas Mueller's avatar Thomas Mueller

Oracle compatibility: empty strings were not converted to NULL when using prepared statements.

上级 d69b5792
......@@ -20,7 +20,8 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>PostgreSQL compatibility: new syntax "create index ... using ...".
<ul><li>Oracle compatibility: empty strings were not converted to NULL when using prepared statements.
</li><li>PostgreSQL compatibility: new syntax "create index ... using ...".
</li><li>There was a bug in DataType.convertToValue when reading a ResultSet from a ResultSet.
</li><li>Pull request #116: Improved concurrency in the trace system.
</li><li>Issue 609: the spatial index did not support NULL.
......
......@@ -14,6 +14,7 @@ import org.h2.table.TableFilter;
import org.h2.value.Value;
import org.h2.value.ValueBoolean;
import org.h2.value.ValueNull;
import org.h2.value.ValueString;
/**
* A parameter of a prepared statement.
......@@ -83,6 +84,11 @@ public class Parameter extends Expression implements ParameterInterface {
@Override
public Expression optimize(Session session) {
if (session.getDatabase().getMode().treatEmptyStringsAsNull) {
if (value != null && value instanceof ValueString) {
value = ValueString.get(value.getString(), true);
}
}
return this;
}
......
......@@ -6,6 +6,7 @@
package org.h2.test.db;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
......@@ -90,6 +91,17 @@ public class TestCompatibilityOracle extends TestBase {
assertResult(new Object[][] { { 1, new byte[] { 10 } }, { 2, null } },
stat, "SELECT * FROM E");
stat.execute("CREATE TABLE F (ID NUMBER, X VARCHAR2(1))");
stat.execute("INSERT INTO F VALUES (1, 'a')");
PreparedStatement prep = conn.prepareStatement(
"INSERT INTO F VALUES (2, ?)");
prep.setString(1, "");
prep.execute();
assertResult("2", stat, "SELECT COUNT(*) FROM F");
assertResult("1", stat, "SELECT COUNT(*) FROM F WHERE X IS NULL");
assertResult("0", stat, "SELECT COUNT(*) FROM F WHERE X = ''");
assertResult(new Object[][]{{1, "a"}, {2, null}}, stat, "SELECT * FROM F");
conn.close();
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论