提交 aaba8d61 authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 624fa6ba
...@@ -637,7 +637,7 @@ SQLインジェクションとは ...@@ -637,7 +637,7 @@ SQLインジェクションとは
このデータベースは、ユーザー入力をデータベースに通す時、パラメータの使用を強制する方法を提供しています。 SQLステートメントの組み込まれたリテラルを無効にすることでこれを実行します。 次のステートメントを実行します: このデータベースは、ユーザー入力をデータベースに通す時、パラメータの使用を強制する方法を提供しています。 SQLステートメントの組み込まれたリテラルを無効にすることでこれを実行します。 次のステートメントを実行します:
@advanced_1212_p @advanced_1212_p
その後、文字列リテラルや数値リテラルのSQLステートメントはもう認められません。これは、 WHERE NAME='abc' や WHERE CustomerId=10 といった形のSQLステートメントは失敗するという意味です。 PreparedStatementや上に記載されたパラメータは使用することができます。また、 リテラルの含まれないSQLステートメントと同様に、SQLステートメントを動的に生成したり、 APIステートメントを使用することも可能です。数値リテラルが許可されている二つ目のモードもあります: SET ALLOW_LITERALS NUMBERS 全てのリテラルを許可するには、 SET ALLOW_LITERALS ALL を実行します (これはデフォルトの設定です)。リテラルはadministratorのみによって使用可能、または使用不可になります。 #Afterwards, SQL statements with text and number literals are not allowed any more. That means, SQL statement of the form WHERE NAME='abc' or WHERE CustomerId=10 will fail. It is still possible to use PreparedStatements and parameters as described above. Also, it is still possible to generate SQL statements dynamically, and use the Statement API, as long as the SQL statements do not include literals. There is also a second mode where number literals are allowed: SET ALLOW_LITERALS NUMBERS. To allow all literals, execute SET ALLOW_LITERALS ALL (this is the default setting). Literals can only be enabled or disabled by an administrator.
@advanced_1213_h3 @advanced_1213_h3
定数を使用する 定数を使用する
...@@ -4846,7 +4846,7 @@ H2DRIVERSかCLASSPATHの環境変数に、ドライバのJarファイルの位 ...@@ -4846,7 +4846,7 @@ H2DRIVERSかCLASSPATHの環境変数に、ドライバのJarファイルの位
JDBCを使用してデータベースに接続 JDBCを使用してデータベースに接続
@tutorial_1065_p @tutorial_1065_p
データベースに接続するためにJavaアプリケーションに最初に必要なことは、 データベースドライバをロードし、接続することです。簡単な方法は、次のコードを使用します: #To connect to a database, a Java application first needs to load the database driver, and then get a connection. A simple way to do that is using the following code:
@tutorial_1066_p @tutorial_1066_p
このコードは最初にドライバをロードして (Class.forName())、 接続を開始します (DriverManager.getConnection())。 このドライバの名前は全てのケースにおいて "org.h2.Driver" です。 データベースに認識されるため、データベースのURLは常に jdbc:h2: から始まります。 getConnection() 内の2番目のパラメーターはユーザ名を指しています ('sa' はこの場合、システム管理者を表しています)。3番目のパラメーターはパスワードです。このデータベースでは、ユーザ名は大文字と小文字を区別していませんが、パスワードは大文字と小文字を区別しています。 このコードは最初にドライバをロードして (Class.forName())、 接続を開始します (DriverManager.getConnection())。 このドライバの名前は全てのケースにおいて "org.h2.Driver" です。 データベースに認識されるため、データベースのURLは常に jdbc:h2: から始まります。 getConnection() 内の2番目のパラメーターはユーザ名を指しています ('sa' はこの場合、システム管理者を表しています)。3番目のパラメーターはパスワードです。このデータベースでは、ユーザ名は大文字と小文字を区別していませんが、パスワードは大文字と小文字を区別しています。
......
...@@ -829,9 +829,10 @@ public class Parser { ...@@ -829,9 +829,10 @@ public class Parser {
private TableFilter readTableFilter(boolean fromOuter) throws SQLException { private TableFilter readTableFilter(boolean fromOuter) throws SQLException {
Table table; Table table;
String alias = null;
Schema mainSchema = database.getSchema(Constants.SCHEMA_MAIN); Schema mainSchema = database.getSchema(Constants.SCHEMA_MAIN);
if (readIf("(")) { if (readIf("(")) {
if (isToken("SELECT") || isToken("FROM")) { if (isToken("SELECT") || isToken("FROM") || isToken("(")) {
Query query = parseSelect(); Query query = parseSelect();
Session s; Session s;
if (prepared != null && prepared instanceof CreateView) { if (prepared != null && prepared instanceof CreateView) {
...@@ -840,6 +841,7 @@ public class Parser { ...@@ -840,6 +841,7 @@ public class Parser {
s = session; s = session;
} }
table = TableView.createTempView(s, session.getUser(), query); table = TableView.createTempView(s, session.getUser(), query);
alias = table.getName();
read(")"); read(")");
} else { } else {
TableFilter top = readTableFilter(fromOuter); TableFilter top = readTableFilter(fromOuter);
...@@ -869,7 +871,6 @@ public class Parser { ...@@ -869,7 +871,6 @@ public class Parser {
table = readTableOrView(tableName); table = readTableOrView(tableName);
} }
} }
String alias = null;
if (readIf("AS")) { if (readIf("AS")) {
alias = readAliasIdentifier(); alias = readAliasIdentifier();
} else if (currentTokenType == IDENTIFIER) { } else if (currentTokenType == IDENTIFIER) {
...@@ -1196,9 +1197,7 @@ public class Parser { ...@@ -1196,9 +1197,7 @@ public class Parser {
ExplainPlan command = new ExplainPlan(session); ExplainPlan command = new ExplainPlan(session);
readIf("PLAN"); readIf("PLAN");
readIf("FOR"); readIf("FOR");
if (isToken("SELECT") || isToken("FROM")) { if (isToken("SELECT") || isToken("FROM") || isToken("(")) {
command.setCommand(parseSelect());
} else if (isToken("(")) {
command.setCommand(parseSelect()); command.setCommand(parseSelect());
} else if (readIf("DELETE")) { } else if (readIf("DELETE")) {
command.setCommand(parseDelete()); command.setCommand(parseDelete());
......
...@@ -200,19 +200,24 @@ public class SessionRemote implements SessionInterface, DataHandler { ...@@ -200,19 +200,24 @@ public class SessionRemote implements SessionInterface, DataHandler {
transferList = new ObjectArray(); transferList = new ObjectArray();
// TODO cluster: support at most 2 connections // TODO cluster: support at most 2 connections
boolean switchOffCluster = false; boolean switchOffCluster = false;
for (int i = 0; i < len; i++) { try {
try { for (int i = 0; i < len; i++) {
Transfer trans = initTransfer(ci, databaseName, servers[i]); try {
transferList.add(trans); Transfer trans = initTransfer(ci, databaseName, servers[i]);
} catch (IOException e) { transferList.add(trans);
switchOffCluster = true; } catch (IOException e) {
switchOffCluster = true;
}
} }
checkClosed();
if (switchOffCluster) {
switchOffCluster();
}
switchOffAutoCommitIfCluster();
} catch (SQLException e) {
traceSystem.close();
throw e;
} }
checkClosed();
if (switchOffCluster) {
switchOffCluster();
}
switchOffAutoCommitIfCluster();
} }
private void switchOffCluster() throws SQLException { private void switchOffCluster() throws SQLException {
......
...@@ -39,16 +39,16 @@ import org.h2.util.StringUtils; ...@@ -39,16 +39,16 @@ import org.h2.util.StringUtils;
/** /**
* This class implements the full text search based on Apache Lucene. * This class implements the full text search based on Apache Lucene.
*/ */
public class FullTextLucene public class FullTextLucene
//#ifdef JDK14 //#ifdef JDK14
implements Trigger implements Trigger
//#endif //#endif
{ {
//#ifdef JDK14 //#ifdef JDK14
private static HashMap indexers = new HashMap(); private static HashMap indexers = new HashMap();
private static final String FIELD_DATA = "data"; private static final String FIELD_DATA = "DATA";
private static final String FIELD_QUERY = "query"; private static final String FIELD_QUERY = "QUERY";
private static final String FIELD_COLUMN_PREFIX = "_"; private static final String FIELD_COLUMN_PREFIX = "_";
private static final String TRIGGER_PREFIX = "FTL_"; private static final String TRIGGER_PREFIX = "FTL_";
private static final String SCHEMA = "FTL"; private static final String SCHEMA = "FTL";
...@@ -60,7 +60,7 @@ implements Trigger ...@@ -60,7 +60,7 @@ implements Trigger
private int[] dataTypes; private int[] dataTypes;
private IndexModifier indexer; private IndexModifier indexer;
//#endif //#endif
/** /**
* Create a new full text index for a table and column list. Each table may only have one index at any time. * Create a new full text index for a table and column list. Each table may only have one index at any time.
* *
...@@ -81,7 +81,7 @@ implements Trigger ...@@ -81,7 +81,7 @@ implements Trigger
createTrigger(conn, schema, table); createTrigger(conn, schema, table);
indexExistingRows(conn, schema, table); indexExistingRows(conn, schema, table);
} }
//#endif //#endif
/** /**
* Re-creates the full text index for this database * Re-creates the full text index for this database
...@@ -102,7 +102,7 @@ implements Trigger ...@@ -102,7 +102,7 @@ implements Trigger
indexExistingRows(conn, schema, table); indexExistingRows(conn, schema, table);
} }
} }
//#endif //#endif
/** /**
* Drops all full text indexes from the database. * Drops all full text indexes from the database.
...@@ -116,7 +116,7 @@ implements Trigger ...@@ -116,7 +116,7 @@ implements Trigger
removeAllTriggers(conn); removeAllTriggers(conn);
removeIndexFiles(conn); removeIndexFiles(conn);
} }
//#endif //#endif
/** /**
* Initializes full text search functionality for this database. This adds the following Java functions to the * Initializes full text search functionality for this database. This adds the following Java functions to the
...@@ -147,7 +147,7 @@ implements Trigger ...@@ -147,7 +147,7 @@ implements Trigger
stat.execute("CREATE ALIAS IF NOT EXISTS FTL_REINDEX FOR \"" + FullTextLucene.class.getName() + ".reindex\""); stat.execute("CREATE ALIAS IF NOT EXISTS FTL_REINDEX FOR \"" + FullTextLucene.class.getName() + ".reindex\"");
stat.execute("CREATE ALIAS IF NOT EXISTS FTL_DROP_ALL FOR \"" + FullTextLucene.class.getName() + ".dropAll\""); stat.execute("CREATE ALIAS IF NOT EXISTS FTL_DROP_ALL FOR \"" + FullTextLucene.class.getName() + ".dropAll\"");
} }
//#endif //#endif
/** /**
* INTERNAL * INTERNAL
...@@ -203,7 +203,7 @@ implements Trigger ...@@ -203,7 +203,7 @@ implements Trigger
indexColumns = new int[indexList.size()]; indexColumns = new int[indexList.size()];
setColumns(indexColumns, indexList, columnList); setColumns(indexColumns, indexList, columnList);
} }
//#endif //#endif
/** /**
* INTERNAL * INTERNAL
...@@ -217,7 +217,7 @@ implements Trigger ...@@ -217,7 +217,7 @@ implements Trigger
insert(newRow); insert(newRow);
} }
} }
//#endif //#endif
/** /**
* Searches from the full text index for this database. * Searches from the full text index for this database.
...@@ -262,7 +262,7 @@ implements Trigger ...@@ -262,7 +262,7 @@ implements Trigger
} }
return rs; return rs;
} }
private static void removeAllTriggers(Connection conn) throws SQLException { private static void removeAllTriggers(Connection conn) throws SQLException {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("SELECT * FROM INFORMATION_SCHEMA.TRIGGERS"); ResultSet rs = stat.executeQuery("SELECT * FROM INFORMATION_SCHEMA.TRIGGERS");
...@@ -291,7 +291,7 @@ implements Trigger ...@@ -291,7 +291,7 @@ implements Trigger
} }
FileSystem.getInstance(path).deleteRecursive(path); FileSystem.getInstance(path).deleteRecursive(path);
} }
private String getQuery(Object[] row) throws SQLException { private String getQuery(Object[] row) throws SQLException {
StringBuffer buff = new StringBuffer(); StringBuffer buff = new StringBuffer();
if (schemaName != null) { if (schemaName != null) {
...@@ -462,8 +462,8 @@ implements Trigger ...@@ -462,8 +462,8 @@ implements Trigger
SQLException e2 = new SQLException("FULLTEXT", "Error while indexing document"); SQLException e2 = new SQLException("FULLTEXT", "Error while indexing document");
e2.initCause(e); e2.initCause(e);
return e2; return e2;
} }
private static void createTrigger(Connection conn, String schema, String table) throws SQLException { private static void createTrigger(Connection conn, String schema, String table) throws SQLException {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
String trigger = StringUtils.quoteIdentifier(schema) + "." + StringUtils.quoteIdentifier(TRIGGER_PREFIX + table); String trigger = StringUtils.quoteIdentifier(schema) + "." + StringUtils.quoteIdentifier(TRIGGER_PREFIX + table);
...@@ -494,7 +494,6 @@ implements Trigger ...@@ -494,7 +494,6 @@ implements Trigger
} }
} }
private static IndexModifier getIndexModifier(Connection conn) throws SQLException { private static IndexModifier getIndexModifier(Connection conn) throws SQLException {
try { try {
String path = getIndexPath(conn); String path = getIndexPath(conn);
...@@ -524,7 +523,7 @@ implements Trigger ...@@ -524,7 +523,7 @@ implements Trigger
rs.close(); rs.close();
return path; return path;
} }
private void setColumns(int[] index, ArrayList keys, ArrayList columns) throws SQLException { private void setColumns(int[] index, ArrayList keys, ArrayList columns) throws SQLException {
for (int i = 0; i < keys.size(); i++) { for (int i = 0; i < keys.size(); i++) {
String key = (String) keys.get(i); String key = (String) keys.get(i);
...@@ -541,6 +540,6 @@ implements Trigger ...@@ -541,6 +540,6 @@ implements Trigger
index[i] = found; index[i] = found;
} }
} }
//#endif //#endif
} }
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
package org.h2.fulltext; package org.h2.fulltext;
public class IndexInfo { public class IndexInfo {
long id; int id;
String schemaName; String schemaName;
String tableName; String tableName;
int[] keys; int[] keys;
......
...@@ -19,9 +19,9 @@ import org.h2.util.FileUtils; ...@@ -19,9 +19,9 @@ import org.h2.util.FileUtils;
import org.h2.util.SmallLRUCache; import org.h2.util.SmallLRUCache;
/** /**
* It is possible to write after close was called, but that means for each write the * It is possible to write after close was called, but that means for each write the
* log file will be opened and closed again (which is slower). * log file will be opened and closed again (which is slower).
* *
* @author Thomas * @author Thomas
*/ */
public class TraceSystem { public class TraceSystem {
...@@ -29,7 +29,7 @@ public class TraceSystem { ...@@ -29,7 +29,7 @@ public class TraceSystem {
// TODO log total and free memory from time to time // TODO log total and free memory from time to time
// max file size is currently 64 MB, // max file size is currently 64 MB,
// and then there could be a .old file of the same size // and then there could be a .old file of the same size
private static final int DEFAULT_MAX_FILE_SIZE = 64 * 1024 * 1024; private static final int DEFAULT_MAX_FILE_SIZE = 64 * 1024 * 1024;
public static final int DEFAULT_TRACE_LEVEL_SYSTEM_OUT = OFF; public static final int DEFAULT_TRACE_LEVEL_SYSTEM_OUT = OFF;
...@@ -49,14 +49,14 @@ public class TraceSystem { ...@@ -49,14 +49,14 @@ public class TraceSystem {
private boolean closed; private boolean closed;
private boolean manualEnabling = true; private boolean manualEnabling = true;
private boolean writingErrorLogged; private boolean writingErrorLogged;
public static void traceThrowable(Throwable e) { public static void traceThrowable(Throwable e) {
PrintWriter writer = DriverManager.getLogWriter(); PrintWriter writer = DriverManager.getLogWriter();
if (writer != null) { if (writer != null) {
e.printStackTrace(writer); e.printStackTrace(writer);
} }
} }
public void setManualEnabling(boolean value) { public void setManualEnabling(boolean value) {
this.manualEnabling = value; this.manualEnabling = value;
} }
...@@ -230,10 +230,17 @@ public class TraceSystem { ...@@ -230,10 +230,17 @@ public class TraceSystem {
try { try {
fileWriter.close(); fileWriter.close();
} catch (IOException e) { } catch (IOException e) {
// ignore exception // ignore
} }
fileWriter = null; fileWriter = null;
} }
try {
if (fileName != null && FileUtils.length(fileName) == 0) {
FileUtils.delete(fileName);
}
} catch (SQLException e) {
// ignore
}
} }
public void close() { public void close() {
...@@ -244,7 +251,7 @@ public class TraceSystem { ...@@ -244,7 +251,7 @@ public class TraceSystem {
protected void finalize() { protected void finalize() {
if (!SysProperties.runFinalize) { if (!SysProperties.runFinalize) {
return; return;
} }
close(); close();
} }
......
...@@ -9,6 +9,7 @@ import java.io.IOException; ...@@ -9,6 +9,7 @@ import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.sql.SQLException; import java.sql.SQLException;
...@@ -171,20 +172,7 @@ public class FtpControl extends Thread { ...@@ -171,20 +172,7 @@ public class FtpControl extends Thread {
break; break;
case 'M': case 'M':
if ("MKD".equals(command)) { if ("MKD".equals(command)) {
String fileName = getFileName(param); processMakeDir(param);
boolean ok = false;
if (!readonly) {
try {
fs.mkdirs(fileName);
reply(257, StringUtils.quoteIdentifier(param) + " directory");
ok = true;
} catch (SQLException e) {
server.logError(e);
}
}
if (!ok) {
reply(500, "Failed");
}
} else if ("MODE".equals(command)) { } else if ("MODE".equals(command)) {
if ("S".equals(StringUtils.toUpperEnglish(param))) { if ("S".equals(StringUtils.toUpperEnglish(param))) {
reply(200, "Ok"); reply(200, "Ok");
...@@ -216,6 +204,18 @@ public class FtpControl extends Thread { ...@@ -216,6 +204,18 @@ public class FtpControl extends Thread {
data.start(); data.start();
int port = dataSocket.getLocalPort(); int port = dataSocket.getLocalPort();
reply(227, "Passive Mode (" + serverIpAddress + "," + (port >> 8) + "," + (port & 255) + ")"); reply(227, "Passive Mode (" + serverIpAddress + "," + (port >> 8) + "," + (port & 255) + ")");
} else if ("PORT".equals(command)) {
String[] list = StringUtils.arraySplit(param, ',', true);
String host = list[0] + "." + list[1] + "." + list[2] + "." + list[3];
int port = (Integer.parseInt(list[4]) << 8) | Integer.parseInt(list[5]);
InetAddress address = InetAddress.getByName(host);
if (address.equals(control.getInetAddress())) {
data = new FtpData(server, address, port);
reply(200, "Ok");
} else {
server.log("Port REJECTED:" + address + " expected:" + control.getInetAddress());
reply(550, "Failed");
}
} }
break; break;
case 'R': case 'R':
...@@ -260,16 +260,12 @@ public class FtpControl extends Thread { ...@@ -260,16 +260,12 @@ public class FtpControl extends Thread {
} }
restart = 0; restart = 0;
} else { } else {
processList(param, true); // Firefox compatibility (still not good) processList(param, true); // Firefox compatibility (still
// not good)
// reply(426, "Not a file"); // reply(426, "Not a file");
} }
} else if ("RMD".equals(command)) { } else if ("RMD".equals(command)) {
String fileName = getFileName(param); processRemoveDir(param);
if (!readonly && fs.exists(fileName) && fs.isDirectory(fileName) && fs.tryDelete(fileName)) {
reply(250, "Ok");
} else {
reply(500, "Failed");
}
} else if ("REST".equals(command)) { } else if ("REST".equals(command)) {
try { try {
restart = Integer.parseInt(param); restart = Integer.parseInt(param);
...@@ -328,11 +324,43 @@ public class FtpControl extends Thread { ...@@ -328,11 +324,43 @@ public class FtpControl extends Thread {
} }
} }
break; break;
case 'X':
if ("XMKD".equals(command)) {
processMakeDir(param);
} else if ("XRMD".equals(command)) {
processRemoveDir(param);
}
default: default:
break; break;
} }
} }
void processMakeDir(String param) throws IOException {
String fileName = getFileName(param);
boolean ok = false;
if (!readonly) {
try {
fs.mkdirs(fileName);
reply(257, StringUtils.quoteIdentifier(param) + " directory");
ok = true;
} catch (SQLException e) {
server.logError(e);
}
}
if (!ok) {
reply(500, "Failed");
}
}
void processRemoveDir(String param) throws IOException {
String fileName = getFileName(param);
if (!readonly && fs.exists(fileName) && fs.isDirectory(fileName) && fs.tryDelete(fileName)) {
reply(250, "Ok");
} else {
reply(500, "Failed");
}
}
private String getFileName(String file) { private String getFileName(String file) {
return server.getFileName(file.startsWith("/") ? file : currentDir + file); return server.getFileName(file.startsWith("/") ? file : currentDir + file);
} }
...@@ -353,7 +381,8 @@ public class FtpControl extends Thread { ...@@ -353,7 +381,8 @@ public class FtpControl extends Thread {
String list = server.getDirectoryListing(directory, directories); String list = server.getDirectoryListing(directory, directories);
reply(150, "Starting transfer"); reply(150, "Starting transfer");
server.log(list); server.log(list);
// need to use the current locale (UTF-8 would be wrong for the Windows Explorer) // need to use the current locale (UTF-8 would be wrong for the Windows
// Explorer)
data.send(list.getBytes()); data.send(list.getBytes());
reply(226, "Done"); reply(226, "Done");
} }
......
...@@ -21,6 +21,8 @@ public class FtpData extends Thread { ...@@ -21,6 +21,8 @@ public class FtpData extends Thread {
private InetAddress address; private InetAddress address;
private ServerSocket serverSocket; private ServerSocket serverSocket;
private volatile Socket socket; private volatile Socket socket;
private boolean active;
private int port;
public FtpData(FtpServer server, InetAddress address, ServerSocket serverSocket) throws IOException { public FtpData(FtpServer server, InetAddress address, ServerSocket serverSocket) throws IOException {
this.server = server; this.server = server;
...@@ -28,6 +30,13 @@ public class FtpData extends Thread { ...@@ -28,6 +30,13 @@ public class FtpData extends Thread {
this.serverSocket = serverSocket; this.serverSocket = serverSocket;
} }
public FtpData(FtpServer server, InetAddress address, int port) throws IOException {
this.server = server;
this.address = address;
this.port = port;
active = true;
}
public void run() { public void run() {
try { try {
synchronized (this) { synchronized (this) {
...@@ -46,6 +55,14 @@ public class FtpData extends Thread { ...@@ -46,6 +55,14 @@ public class FtpData extends Thread {
} }
} }
private void connect() throws IOException {
if (active) {
socket = new Socket(address, port);
} else {
waitUntilConnected();
}
}
private void waitUntilConnected() { private void waitUntilConnected() {
while (serverSocket != null && socket == null) { while (serverSocket != null && socket == null) {
try { try {
...@@ -63,7 +80,7 @@ public class FtpData extends Thread { ...@@ -63,7 +80,7 @@ public class FtpData extends Thread {
} }
public synchronized void receive(FileSystem fs, String fileName) throws IOException, SQLException { public synchronized void receive(FileSystem fs, String fileName) throws IOException, SQLException {
waitUntilConnected(); connect();
try { try {
InputStream in = socket.getInputStream(); InputStream in = socket.getInputStream();
OutputStream out = fs.openFileOutputStream(fileName, false); OutputStream out = fs.openFileOutputStream(fileName, false);
...@@ -76,7 +93,7 @@ public class FtpData extends Thread { ...@@ -76,7 +93,7 @@ public class FtpData extends Thread {
} }
public synchronized void send(FileSystem fs, String fileName, long skip) throws IOException { public synchronized void send(FileSystem fs, String fileName, long skip) throws IOException {
waitUntilConnected(); connect();
try { try {
OutputStream out = socket.getOutputStream(); OutputStream out = socket.getOutputStream();
InputStream in = fs.openFileInputStream(fileName); InputStream in = fs.openFileInputStream(fileName);
...@@ -90,7 +107,7 @@ public class FtpData extends Thread { ...@@ -90,7 +107,7 @@ public class FtpData extends Thread {
} }
public synchronized void send(byte[] data) throws IOException { public synchronized void send(byte[] data) throws IOException {
waitUntilConnected(); connect();
try { try {
OutputStream out = socket.getOutputStream(); OutputStream out = socket.getOutputStream();
out.write(data); out.write(data);
......
...@@ -120,7 +120,7 @@ public class FtpServer implements Service { ...@@ -120,7 +120,7 @@ public class FtpServer implements Service {
String getFileName(String path) { String getFileName(String path) {
return root + getPath(path); return root + getPath(path);
} }
String getPath(String path) { String getPath(String path) {
if (path.indexOf("..") > 0) { if (path.indexOf("..") > 0) {
path = "/"; path = "/";
......
...@@ -25,7 +25,7 @@ SELECT * FROM FT_SEARCH('World', 0, 0); ...@@ -25,7 +25,7 @@ SELECT * FROM FT_SEARCH('World', 0, 0);
SELECT * FROM FT_SEARCH('World', 1, 0); SELECT * FROM FT_SEARCH('World', 1, 0);
SELECT * FROM FT_SEARCH('World', 0, 2); SELECT * FROM FT_SEARCH('World', 0, 2);
SELECT * FROM FT_SEARCH('World', 2, 1); SELECT * FROM FT_SEARCH('World', 2, 1);
SELECT * FROM FT_SEARCH('1'); SELECT * FROM FT_SEARCH('1', 0, 0);
CALL FT_DROP_ALL(); CALL FT_DROP_ALL();
SELECT * FROM FT_SEARCH('World', 2, 1); SELECT * FROM FT_SEARCH('World', 2, 1);
CALL FT_DROP_ALL(); CALL FT_DROP_ALL();
......
...@@ -150,37 +150,12 @@ java org.h2.test.TestAll timer ...@@ -150,37 +150,12 @@ java org.h2.test.TestAll timer
/* /*
create table test(id int, name varchar); toString: > the parameters for the prepared statements.
insert into test select x, '' from system_range(1, 10000);
-- fast
update test set name = 'y' where cast(id as varchar) like '1%';
-- slow
update test set name = 'x' where id in (select x from system_range(1, 10000) where cast(x as varchar) like '1%');
drop table test;
Optimize IN(...), IN(select), ID=? OR ID=?: create temp table and use join
Bug:
H2 1.0.62 (2007-11-25) has regressed on this query. Parser syntax error is returned (query is OK for derby, oracle, and earlier H2 versions).
SELECT COUNT(*) FROM (
SELECT TT.id,TT.table_name FROM (
SELECT DISTINCT id, table_name FROM information_schema.tables WHERE id=-8 UNION SELECT DISTINCT id, table_name FROM information_schema.tables WHERE id=-8) AS TT
) AS AWR WHERE AWR.id=-8
Remove the final predicate and the query parses & runs fine:
SELECT COUNT(*) FROM (
SELECT TT.id,TT.table_name FROM (
SELECT DISTINCT id, table_name FROM information_schema.tables WHERE id=-8 UNION SELECT DISTINCT id, table_name FROM information_schema.tables WHERE id=-8) AS TT
) AS AWR
autocomplete only just after meaningful key (ctrl+space, space, bs, interpunctation, ...)
write more tests for the command line tools write more tests for the command line tools
avoid creating thousands of trace.db files
Known Problems: Known Problems:
link to history page, bug page link to history page, bug page
Add a link to the google code bug page Add a link to the google code bug page
......
...@@ -16,86 +16,106 @@ public class TestFullText extends TestBase { ...@@ -16,86 +16,106 @@ public class TestFullText extends TestBase {
if (config.memory) { if (config.memory) {
return; return;
} }
test(false);
String luceneFullTextClassName = "org.h2.fulltext.FullTextLucene";
try {
Class.forName(luceneFullTextClassName);
test(true);
} catch (ClassNotFoundException e) {
this.println("Class not found, not tested: " + luceneFullTextClassName);
// ok
}
}
private void test(boolean lucene) throws Exception {
deleteDb("fullText"); deleteDb("fullText");
Connection conn = getConnection("fullText"); Connection conn = getConnection("fullText");
String prefix = lucene ? "FTL_" : "FT_";
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("CREATE ALIAS IF NOT EXISTS FT_INIT FOR \"org.h2.fulltext.FullText.init\""); String className = lucene ? "FullTextLucene" : "FullText";
stat.execute("CALL FT_INIT()"); stat.execute("CREATE ALIAS IF NOT EXISTS " + prefix + "INIT FOR \"org.h2.fulltext." + className + ".init\"");
stat.execute("CALL " + prefix + "INIT()");
stat.execute("DROP TABLE IF EXISTS TEST"); stat.execute("DROP TABLE IF EXISTS TEST");
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 World')"); stat.execute("INSERT INTO TEST VALUES(1, 'Hello World')");
stat.execute("CALL FT_CREATE_INDEX('PUBLIC', 'TEST', NULL)"); stat.execute("CALL " + prefix + "CREATE_INDEX('PUBLIC', 'TEST', NULL)");
ResultSet rs; ResultSet rs;
rs = stat.executeQuery("SELECT * FROM FT_SEARCH('Hello', 0, 0)"); rs = stat.executeQuery("SELECT * FROM " + prefix + "SEARCH('Hello', 0, 0)");
rs.next(); rs.next();
check(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=1"); check(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=1");
checkFalse(rs.next()); checkFalse(rs.next());
rs = stat.executeQuery("SELECT * FROM FT_SEARCH('Hallo', 0, 0)"); rs = stat.executeQuery("SELECT * FROM " + prefix + "SEARCH('Hallo', 0, 0)");
checkFalse(rs.next()); checkFalse(rs.next());
stat.execute("INSERT INTO TEST VALUES(2, 'Hallo Welt')"); stat.execute("INSERT INTO TEST VALUES(2, 'Hallo Welt')");
rs = stat.executeQuery("SELECT * FROM FT_SEARCH('Hello', 0, 0)"); rs = stat.executeQuery("SELECT * FROM " + prefix + "SEARCH('Hello', 0, 0)");
rs.next(); rs.next();
check(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=1"); check(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=1");
checkFalse(rs.next()); checkFalse(rs.next());
rs = stat.executeQuery("SELECT * FROM FT_SEARCH('Hallo', 0, 0)"); rs = stat.executeQuery("SELECT * FROM " + prefix + "SEARCH('Hallo', 0, 0)");
rs.next(); rs.next();
check(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=2"); check(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=2");
checkFalse(rs.next()); checkFalse(rs.next());
stat.execute("CALL FT_REINDEX()"); stat.execute("CALL " + prefix + "REINDEX()");
rs = stat.executeQuery("SELECT * FROM FT_SEARCH('Hello', 0, 0)"); rs = stat.executeQuery("SELECT * FROM " + prefix + "SEARCH('Hello', 0, 0)");
rs.next(); rs.next();
check(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=1"); check(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=1");
checkFalse(rs.next()); checkFalse(rs.next());
rs = stat.executeQuery("SELECT * FROM FT_SEARCH('Hallo', 0, 0)"); rs = stat.executeQuery("SELECT * FROM " + prefix + "SEARCH('Hallo', 0, 0)");
rs.next(); rs.next();
check(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=2"); check(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=2");
checkFalse(rs.next()); checkFalse(rs.next());
stat.execute("INSERT INTO TEST VALUES(3, 'Hello World')"); stat.execute("INSERT INTO TEST VALUES(3, 'Hello World')");
stat.execute("INSERT INTO TEST VALUES(4, 'Hello World')"); stat.execute("INSERT INTO TEST VALUES(4, 'Hello World')");
stat.execute("INSERT INTO TEST VALUES(5, 'Hello World')"); stat.execute("INSERT INTO TEST VALUES(5, 'Hello World')");
rs = stat.executeQuery("SELECT * FROM FT_SEARCH('World', 0, 0)"); rs = stat.executeQuery("SELECT * FROM " + prefix + "SEARCH('World', 0, 0) ORDER BY QUERY");
rs.next();
check(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=4");
rs.next(); rs.next();
check(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=1"); check(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=1");
rs.next(); rs.next();
check(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=5");
rs.next();
check(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=3"); check(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=3");
checkFalse(rs.next());
rs = stat.executeQuery("SELECT * FROM FT_SEARCH('World', 1, 0)");
rs.next(); rs.next();
check(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=4"); check(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=4");
checkFalse(rs.next());
rs = stat.executeQuery("SELECT * FROM FT_SEARCH('World', 0, 2)");
rs.next(); rs.next();
check(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=5"); check(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=5");
checkFalse(rs.next());
rs = stat.executeQuery("SELECT * FROM " + prefix + "SEARCH('World', 1, 0)");
rs.next(); rs.next();
check(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=3"); check(rs.getString(1).startsWith("\"PUBLIC\".\"TEST\" WHERE \"ID\"="));
checkFalse(rs.next()); checkFalse(rs.next());
rs = stat.executeQuery("SELECT * FROM FT_SEARCH('World', 2, 1)"); rs = stat.executeQuery("SELECT * FROM " + prefix + "SEARCH('World', 0, 2) ORDER BY QUERY");
rs.next(); rs.next();
check(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=1"); check(rs.getString(1).startsWith("\"PUBLIC\".\"TEST\" WHERE \"ID\"="));
rs.next(); rs.next();
check(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=5"); check(rs.getString(1).startsWith("\"PUBLIC\".\"TEST\" WHERE \"ID\"="));
checkFalse(rs.next());
rs = stat.executeQuery("SELECT * FROM " + prefix + "SEARCH('World', 2, 1) ORDER BY QUERY");
rs.next();
check(rs.getString(1).startsWith("\"PUBLIC\".\"TEST\" WHERE \"ID\"="));
rs.next();
check(rs.getString(1).startsWith("\"PUBLIC\".\"TEST\" WHERE \"ID\"="));
checkFalse(rs.next()); checkFalse(rs.next());
rs = stat.executeQuery("SELECT * FROM FT_SEARCH('1', 0, 0)"); rs = stat.executeQuery("SELECT * FROM " + prefix + "SEARCH('1', 0, 0)");
rs.next(); rs.next();
check(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=1"); check(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=1");
checkFalse(rs.next()); checkFalse(rs.next());
stat.execute("CALL FT_DROP_ALL()");
rs = stat.executeQuery("SELECT * FROM FT_SEARCH('World', 2, 1)");
stat.execute("CALL FT_DROP_ALL()");
conn.close(); conn.close();
conn = getConnection("fullText");
stat = conn.createStatement();
rs = stat.executeQuery("SELECT * FROM " + prefix + "SEARCH('World', 0, 0)");
stat.execute("CALL " + prefix + "DROP_ALL()");
rs = stat.executeQuery("SELECT * FROM " + prefix + "SEARCH('World', 2, 1)");
stat.execute("CALL " + prefix + "DROP_ALL()");
conn.close();
} }
} }
select count(*) from (select * from dual union select * from dual) where x = 0;
> 0;
select count(*) from (select * from (select * from dual union select * from dual)) where x = 0;
> 0;
select instr('abcisj','s', -1) from dual; select instr('abcisj','s', -1) from dual;
> 5; > 5;
CREATE TABLE TEST(ID INT); CREATE TABLE TEST(ID INT);
...@@ -30,7 +35,7 @@ SELECT X FROM (SELECT X, X AS "XY" FROM DUAL) WHERE X=1; ...@@ -30,7 +35,7 @@ SELECT X FROM (SELECT X, X AS "XY" FROM DUAL) WHERE X=1;
> 1; > 1;
SELECT X FROM (SELECT X, X AS "X Y" FROM DUAL) WHERE X=1; SELECT X FROM (SELECT X, X AS "X Y" FROM DUAL) WHERE X=1;
> 1; > 1;
SELECT X FROM (SELECT X, X AS "X Y" FROM DUAL AS "D Z") WHERE X=1; SELECT X FROM (SELECT X, X AS "X Y" FROM DUAL AS "D Z") WHERE X=1;
> 1; > 1;
select * from (select x from dual union select convert(x, int) from dual) where x=0; select * from (select x from dual union select convert(x, int) from dual) where x=0;
...@@ -109,7 +114,7 @@ drop table table2; ...@@ -109,7 +114,7 @@ drop table table2;
select case when 1=null then 1 else 2 end; select case when 1=null then 1 else 2 end;
> 2; > 2;
select case (1) when 1 then 1 else 2 end; select case (1) when 1 then 1 else 2 end;
> 1; > 1;
create table test(id int); create table test(id int);
...@@ -146,7 +151,7 @@ select count(*) from A left outer join B on B.AID=A.ID inner join C on C.BID=B.I ...@@ -146,7 +151,7 @@ select count(*) from A left outer join B on B.AID=A.ID inner join C on C.BID=B.I
select count(*) from (A left outer join B on B.AID=A.ID) inner join C on C.BID=B.ID where A.id=1; select count(*) from (A left outer join B on B.AID=A.ID) inner join C on C.BID=B.ID where A.id=1;
> 0; > 0;
drop table a, b, c; drop table a, b, c;
create schema a; create schema a;
create table a.test(id int); create table a.test(id int);
insert into a.test values(1); insert into a.test values(1);
...@@ -177,7 +182,7 @@ select TEST_SCHEMA.TEST_SEQ.CURRVAL; ...@@ -177,7 +182,7 @@ select TEST_SCHEMA.TEST_SEQ.CURRVAL;
select TEST_SCHEMA.TEST_SEQ.nextval; select TEST_SCHEMA.TEST_SEQ.nextval;
> 1; > 1;
drop schema TEST_SCHEMA; drop schema TEST_SCHEMA;
create table test(id int); create table test(id int);
create trigger TEST_TRIGGER before insert on test call "org.h2.test.db.TestTriggersConstraints"; create trigger TEST_TRIGGER before insert on test call "org.h2.test.db.TestTriggersConstraints";
comment on trigger TEST_TRIGGER is 'just testing'; comment on trigger TEST_TRIGGER is 'just testing';
...@@ -238,7 +243,7 @@ select remarks from information_schema.sequences where sequence_name = 'WALK'; ...@@ -238,7 +243,7 @@ select remarks from information_schema.sequences where sequence_name = 'WALK';
> Walker; > Walker;
drop schema tests; drop schema tests;
@reconnect; @reconnect;
create constant abc value 1; create constant abc value 1;
comment on constant abc is 'One'; comment on constant abc is 'One';
select remarks from information_schema.constants where constant_name = 'ABC'; select remarks from information_schema.constants where constant_name = 'ABC';
...@@ -249,7 +254,7 @@ select remarks from information_schema.constants where constant_name = 'ABC'; ...@@ -249,7 +254,7 @@ select remarks from information_schema.constants where constant_name = 'ABC';
drop constant abc; drop constant abc;
drop table test; drop table test;
@reconnect; @reconnect;
create table test(id int); create table test(id int);
alter table test add constraint const1 unique(id); alter table test add constraint const1 unique(id);
create index IDX_ID on test(id); create index IDX_ID on test(id);
......
...@@ -41,7 +41,7 @@ public class PrepareTranslation { ...@@ -41,7 +41,7 @@ public class PrepareTranslation {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
new PrepareTranslation().run(args); new PrepareTranslation().run(args);
} }
private void run(String[] args) throws Exception { private void run(String[] args) throws Exception {
String baseDir = "src/docsrc/textbase"; String baseDir = "src/docsrc/textbase";
prepare(baseDir, "src/main/org/h2/res"); prepare(baseDir, "src/main/org/h2/res");
...@@ -479,7 +479,7 @@ public class PrepareTranslation { ...@@ -479,7 +479,7 @@ public class PrepareTranslation {
System.out.println(trans.getName() + ": key " + key + " not found in translation file; added dummy # 'translation'"); System.out.println(trans.getName() + ": key " + key + " not found in translation file; added dummy # 'translation'");
t = "#" + now; t = "#" + now;
} }
p.put(key, t); p.put(key, t);
} }
// remove keys that don't exist in the main file (deleted or typo in the key) // remove keys that don't exist in the main file (deleted or typo in the key)
it = new ArrayList(p.keySet()).iterator(); it = new ArrayList(p.keySet()).iterator();
...@@ -531,7 +531,7 @@ public class PrepareTranslation { ...@@ -531,7 +531,7 @@ public class PrepareTranslation {
translateChunk(buff, separator, sourceLanguage, targetLanguage, keyMap, results); translateChunk(buff, separator, sourceLanguage, targetLanguage, keyMap, results);
return results; return results;
} }
private void translateChunk(StringBuffer buff, int separator, String source, String target, HashMap keyMap, HashMap results) { private void translateChunk(StringBuffer buff, int separator, String source, String target, HashMap keyMap, HashMap results) {
buff.append(separator); buff.append(separator);
String original = buff.toString(); String original = buff.toString();
...@@ -563,18 +563,15 @@ public class PrepareTranslation { ...@@ -563,18 +563,15 @@ public class PrepareTranslation {
keyMap.clear(); keyMap.clear();
buff.setLength(0); buff.setLength(0);
} }
/** /**
* Translate the text using Google * Translate the text using Google Translate
*/ */
String translate(String text, String sourceLanguage, String targetLanguage) throws Exception { String translate(String text, String sourceLanguage, String targetLanguage) throws Exception {
Thread.sleep(4000); Thread.sleep(4000);
String url = "http://translate.google.com/translate_t?langpair=" + sourceLanguage + "|" + targetLanguage + "&text=" String url = "http://translate.google.com/translate_t?langpair=" + sourceLanguage + "|" + targetLanguage + "&text="
+ URLEncoder.encode(text, "UTF-8"); + URLEncoder.encode(text, "UTF-8");
HttpURLConnection conn = (HttpURLConnection) (new URL(url)).openConnection(); HttpURLConnection conn = (HttpURLConnection) (new URL(url)).openConnection();
// conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)");
int todoTest;
// conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.10) Gecko/20071115 Firefox/2.0.0.10");
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (compatible; Java)"); conn.setRequestProperty("User-Agent", "Mozilla/5.0 (compatible; Java)");
String result = IOUtils.readStringAndClose(IOUtils.getReader(conn.getInputStream()), -1); String result = IOUtils.readStringAndClose(IOUtils.getReader(conn.getInputStream()), -1);
int start = result.indexOf("<div id=result_box"); int start = result.indexOf("<div id=result_box");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论