提交 93e5c6a0 authored 作者: Thomas Mueller's avatar Thomas Mueller

H2 Console: editing result sets is now also working for database other than H2.

上级 dda74919
......@@ -18,7 +18,11 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>Cluster: an open transaction was committed when a cluster node was stopped
<ul><li>H2 Console: editing result sets is now also working for database other than H2,
if they do support updateable result sets. The query must be prefixed with "@edit".
Only limited testing has been done on this feature,
some data types may not work (please provide feedback if you find issues).
</li><li>Cluster: an open transaction was committed when a cluster node was stopped
(because disabling the cluster executes SET CLUSTER '', which committed the transaction).
Transaction are no longer committed when calling SET CLUSTER. Issue 199.
</li><li>Cluster: non-admin users couldn't connect to the cluster and couldn't disable the cluster. Issue 201.
......
......@@ -13,6 +13,7 @@ import java.io.StringReader;
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ParameterMetaData;
......@@ -998,7 +999,8 @@ public class WebApp {
if (!(s.startsWith("@") && s.endsWith("."))) {
buff.append(PageParser.escapeHtml(s + ";")).append("<br />");
}
buff.append(getResult(conn, i + 1, s, size == 1, false)).append("<br />");
boolean forceEdit = s.startsWith("@edit");
buff.append(getResult(conn, i + 1, s, size == 1, forceEdit)).append("<br />");
}
private String editResult() {
......@@ -1671,16 +1673,44 @@ public class WebApp {
return false;
}
private void unescapeData(String d, ResultSet rs, int columnIndex) throws SQLException {
if (d.equals("null")) {
private void unescapeData(String x, ResultSet rs, int columnIndex) throws SQLException {
if (x.equals("null")) {
rs.updateNull(columnIndex);
} else if (d.startsWith("=+")) {
return;
} else if (x.startsWith("=+")) {
// don't update
} else if (d.startsWith("= ")) {
d = d.substring(2);
rs.updateString(columnIndex, d);
} else {
rs.updateString(columnIndex, d);
return;
} else if (x.startsWith("= ")) {
x = x.substring(2);
}
ResultSetMetaData meta = rs.getMetaData();
int type = meta.getColumnType(columnIndex);
if (session.getContents().isH2) {
rs.updateString(columnIndex, x);
return;
}
switch (type) {
case Types.BIGINT:
rs.updateLong(columnIndex, Long.decode(x));
break;
case Types.DECIMAL:
rs.updateBigDecimal(columnIndex, new BigDecimal(x));
break;
case Types.DOUBLE:
case Types.FLOAT:
rs.updateDouble(columnIndex, Double.parseDouble(x));
break;
case Types.REAL:
rs.updateFloat(columnIndex, Float.parseFloat(x));
break;
case Types.INTEGER:
rs.updateInt(columnIndex, Integer.decode(x));
break;
case Types.TINYINT:
rs.updateShort(columnIndex, Short.decode(x));
break;
default:
rs.updateString(columnIndex, x);
}
}
......
MySQL
--------------------------------------------------------------------------------------------------------
Start:
sudo mysqld_safe
Stop:
sudo mysqladmin shutdown
Configuration:
sudo mysql
create database test;
create user 'sa'@'localhost' identified by 'sa';
use test;
grant all on * to 'sa'@'localhost' with grant option;
'TRADITIONAL' is default; ANSI mode can be set using:
SET GLOBAL sql_mode='ANSI';
SELECT @@global.sql_mode
SELECT @@global.sql_mode;
Non-standard escape mechanism:
select 'Joe''s', 'Joe\'s';
......@@ -15,16 +28,6 @@ insert into test values(null);
-- 2 rows even in ANSI mode (correct is 1 row):
select * from test where id=id and 1=1;
Configuration:
create database test;
create user 'sa'@'localhost' identified by 'sa';
use test;
grant all on * to 'sa'@'localhost' with grant option;
Start and Stop:
sudo mysqld_safe
sudo mysqladmin shutdown
MS SQL Server 2005
--------------------------------------------------------------------------------------------------------
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论