提交 6ab81676 authored 作者: Thomas Mueller's avatar Thomas Mueller

Local variable declaration hides another field or variable.

上级 893cca19
...@@ -825,8 +825,8 @@ public class Parser { ...@@ -825,8 +825,8 @@ public class Parser {
return prepare(session, buff.toString(), paramValues); return prepare(session, buff.toString(), paramValues);
} }
private Prepared prepare(Session session, String sql, ObjectArray paramValues) throws SQLException { private Prepared prepare(Session s, String sql, ObjectArray paramValues) throws SQLException {
Prepared prep = session.prepare(sql); Prepared prep = s.prepare(sql);
ObjectArray params = prep.getParameters(); ObjectArray params = prep.getParameters();
for (int i = 0; params != null && i < params.size(); i++) { for (int i = 0; params != null && i < params.size(); i++) {
Parameter p = (Parameter) params.get(i); Parameter p = (Parameter) params.get(i);
...@@ -4177,7 +4177,7 @@ public class Parser { ...@@ -4177,7 +4177,7 @@ public class Parser {
private RunScriptCommand parseRunScript() throws SQLException { private RunScriptCommand parseRunScript() throws SQLException {
RunScriptCommand command = new RunScriptCommand(session); RunScriptCommand command = new RunScriptCommand(session);
read("FROM"); read("FROM");
command.setFile(readExpression()); command.setFileNameExpr(readExpression());
if (readIf("COMPRESSION")) { if (readIf("COMPRESSION")) {
command.setCompressionAlgorithm(readUniqueIdentifier()); command.setCompressionAlgorithm(readUniqueIdentifier());
} }
...@@ -4221,7 +4221,7 @@ public class Parser { ...@@ -4221,7 +4221,7 @@ public class Parser {
command.setDrop(dropTables); command.setDrop(dropTables);
command.setSimple(simple); command.setSimple(simple);
if (readIf("TO")) { if (readIf("TO")) {
command.setFile(readExpression()); command.setFileNameExpr(readExpression());
if (readIf("COMPRESSION")) { if (readIf("COMPRESSION")) {
command.setCompressionAlgorithm(readUniqueIdentifier()); command.setCompressionAlgorithm(readUniqueIdentifier());
} }
......
...@@ -299,9 +299,9 @@ public class AlterTableAddConstraint extends SchemaCommand { ...@@ -299,9 +299,9 @@ public class AlterTableAddConstraint extends SchemaCommand {
private Index getIndex(Table t, IndexColumn[] cols) { private Index getIndex(Table t, IndexColumn[] cols) {
ObjectArray list = t.getIndexes(); ObjectArray list = t.getIndexes();
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
Index idx = (Index) list.get(i); Index existingIndex = (Index) list.get(i);
if (canUseIndex(idx, t, cols)) { if (canUseIndex(existingIndex, t, cols)) {
return idx; return existingIndex;
} }
} }
return null; return null;
...@@ -329,12 +329,12 @@ public class AlterTableAddConstraint extends SchemaCommand { ...@@ -329,12 +329,12 @@ public class AlterTableAddConstraint extends SchemaCommand {
return true; return true;
} }
private boolean canUseIndex(Index index, Table table, IndexColumn[] cols) { private boolean canUseIndex(Index existingIndex, Table table, IndexColumn[] cols) {
if (index.getTable() != table || index.getCreateSQL() == null) { if (existingIndex.getTable() != table || existingIndex.getCreateSQL() == null) {
// can't use the scan index or index of another table // can't use the scan index or index of another table
return false; return false;
} }
Column[] indexCols = index.getColumns(); Column[] indexCols = existingIndex.getColumns();
if (indexCols.length < cols.length) { if (indexCols.length < cols.length) {
return false; return false;
} }
...@@ -343,7 +343,7 @@ public class AlterTableAddConstraint extends SchemaCommand { ...@@ -343,7 +343,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
// but not all columns of the index need to be part of the list // but not all columns of the index need to be part of the list
// holes are not allowed (index=a,b,c & list=a,b is ok; but list=a,c // holes are not allowed (index=a,b,c & list=a,b is ok; but list=a,c
// is not) // is not)
int idx = index.getColumnIndex(cols[j].column); int idx = existingIndex.getColumnIndex(cols[j].column);
if (idx < 0 || idx >= cols.length) { if (idx < 0 || idx >= cols.length) {
return false; return false;
} }
......
...@@ -39,18 +39,18 @@ import org.h2.util.ObjectArray; ...@@ -39,18 +39,18 @@ import org.h2.util.ObjectArray;
*/ */
public class BackupCommand extends Prepared { public class BackupCommand extends Prepared {
private Expression fileName; private Expression fileNameExpr;
public BackupCommand(Session session) { public BackupCommand(Session session) {
super(session); super(session);
} }
public void setFileName(Expression fileName) { public void setFileName(Expression fileName) {
this.fileName = fileName; this.fileNameExpr = fileName;
} }
public int update() throws SQLException { public int update() throws SQLException {
String name = fileName.getValue(session).getString(); String name = fileNameExpr.getValue(session).getString();
session.getUser().checkAdmin(); session.getUser().checkAdmin();
backupTo(name); backupTo(name);
return 0; return 0;
......
...@@ -38,12 +38,12 @@ public abstract class Query extends Prepared { ...@@ -38,12 +38,12 @@ public abstract class Query extends Prepared {
/** /**
* The limit expression as specified in the LIMIT or TOP clause. * The limit expression as specified in the LIMIT or TOP clause.
*/ */
protected Expression limit; protected Expression limitExpr;
/** /**
* The offset expression as specified in the LIMIT .. OFFSET clause. * The offset expression as specified in the LIMIT .. OFFSET clause.
*/ */
protected Expression offset; protected Expression offsetExpr;
/** /**
* The sample size * The sample size
...@@ -154,10 +154,10 @@ public abstract class Query extends Prepared { ...@@ -154,10 +154,10 @@ public abstract class Query extends Prepared {
* Get the alias (or column name) of the first column. * Get the alias (or column name) of the first column.
* This is used to convert IN(SELECT ...) queries to inner joins. * This is used to convert IN(SELECT ...) queries to inner joins.
* *
* @param session the session * @param s the session
* @return the alias or column name * @return the alias or column name
*/ */
public abstract String getFirstColumnAlias(Session session); public abstract String getFirstColumnAlias(Session s);
/** /**
* Check if this expression and all sub-expressions can fulfill a criteria. * Check if this expression and all sub-expressions can fulfill a criteria.
...@@ -171,9 +171,9 @@ public abstract class Query extends Prepared { ...@@ -171,9 +171,9 @@ public abstract class Query extends Prepared {
/** /**
* Update all aggregate function values. * Update all aggregate function values.
* *
* @param session the session * @param s the session
*/ */
public abstract void updateAggregate(Session session) throws SQLException; public abstract void updateAggregate(Session s) throws SQLException;
public boolean isQuery() { public boolean isQuery() {
return true; return true;
...@@ -183,9 +183,9 @@ public abstract class Query extends Prepared { ...@@ -183,9 +183,9 @@ public abstract class Query extends Prepared {
return true; return true;
} }
private boolean sameResultAsLast(Session session, Value[] params, Value[] lastParams, long lastEvaluated) private boolean sameResultAsLast(Session s, Value[] params, Value[] lastParams, long lastEval)
throws SQLException { throws SQLException {
Database db = session.getDatabase(); Database db = s.getDatabase();
for (int i = 0; i < params.length; i++) { for (int i = 0; i < params.length; i++) {
if (!db.areEqual(lastParams[i], params[i])) { if (!db.areEqual(lastParams[i], params[i])) {
return false; return false;
...@@ -194,7 +194,7 @@ public abstract class Query extends Prepared { ...@@ -194,7 +194,7 @@ public abstract class Query extends Prepared {
if (!isEverything(ExpressionVisitor.DETERMINISTIC) || !isEverything(ExpressionVisitor.INDEPENDENT)) { if (!isEverything(ExpressionVisitor.DETERMINISTIC) || !isEverything(ExpressionVisitor.INDEPENDENT)) {
return false; return false;
} }
if (db.getModificationDataId() > lastEvaluated && getMaxDataModificationId() > lastEvaluated) { if (db.getModificationDataId() > lastEval && getMaxDataModificationId() > lastEval) {
return false; return false;
} }
return true; return true;
...@@ -376,11 +376,11 @@ public abstract class Query extends Prepared { ...@@ -376,11 +376,11 @@ public abstract class Query extends Prepared {
} }
public void setOffset(Expression offset) { public void setOffset(Expression offset) {
this.offset = offset; this.offsetExpr = offset;
} }
public void setLimit(Expression limit) { public void setLimit(Expression limit) {
this.limit = limit; this.limitExpr = limit;
} }
/** /**
......
...@@ -52,7 +52,7 @@ public abstract class ScriptBase extends Prepared implements DataHandler { ...@@ -52,7 +52,7 @@ public abstract class ScriptBase extends Prepared implements DataHandler {
/** /**
* The file name (if set). * The file name (if set).
*/ */
private Expression file; private Expression fileNameExpr;
private String fileName; private String fileName;
private String cipher; private String cipher;
...@@ -77,13 +77,13 @@ public abstract class ScriptBase extends Prepared implements DataHandler { ...@@ -77,13 +77,13 @@ public abstract class ScriptBase extends Prepared implements DataHandler {
key = sha.getKeyPasswordHash("script", password); key = sha.getKeyPasswordHash("script", password);
} }
public void setFile(Expression file) { public void setFileNameExpr(Expression file) {
this.file = file; this.fileNameExpr = file;
} }
protected String getFileName() throws SQLException { protected String getFileName() throws SQLException {
if (file != null && fileName == null) { if (fileNameExpr != null && fileName == null) {
fileName = file.optimize(session).getValue(session).getString(); fileName = fileNameExpr.optimize(session).getValue(session).getString();
if (fileName == null || fileName.trim().length() == 0) { if (fileName == null || fileName.trim().length() == 0) {
fileName = "script.sql"; fileName = "script.sql";
} }
...@@ -100,17 +100,17 @@ public abstract class ScriptBase extends Prepared implements DataHandler { ...@@ -100,17 +100,17 @@ public abstract class ScriptBase extends Prepared implements DataHandler {
* Delete the target file. * Delete the target file.
*/ */
void deleteStore() throws SQLException { void deleteStore() throws SQLException {
String fileName = getFileName(); String file = getFileName();
if (fileName != null) { if (file != null) {
FileUtils.delete(fileName); FileUtils.delete(file);
} }
} }
private void initStore() throws SQLException { private void initStore() throws SQLException {
Database db = session.getDatabase(); Database db = session.getDatabase();
// script files are always in text format // script files are always in text format
String fileName = getFileName(); String file = getFileName();
store = FileStore.open(db, fileName, "rw", cipher, key); store = FileStore.open(db, file, "rw", cipher, key);
store.setCheckedWriting(false); store.setCheckedWriting(false);
store.init(); store.init();
} }
...@@ -119,8 +119,8 @@ public abstract class ScriptBase extends Prepared implements DataHandler { ...@@ -119,8 +119,8 @@ public abstract class ScriptBase extends Prepared implements DataHandler {
* Open the output stream. * Open the output stream.
*/ */
void openOutput() throws SQLException { void openOutput() throws SQLException {
String fileName = getFileName(); String file = getFileName();
if (fileName == null) { if (file == null) {
return; return;
} }
if (isEncrypted()) { if (isEncrypted()) {
...@@ -129,7 +129,7 @@ public abstract class ScriptBase extends Prepared implements DataHandler { ...@@ -129,7 +129,7 @@ public abstract class ScriptBase extends Prepared implements DataHandler {
// always use a big buffer, otherwise end-of-block is written a lot // always use a big buffer, otherwise end-of-block is written a lot
out = new BufferedOutputStream(out, Constants.IO_BUFFER_SIZE_COMPRESS); out = new BufferedOutputStream(out, Constants.IO_BUFFER_SIZE_COMPRESS);
} else { } else {
OutputStream o = FileUtils.openFileOutputStream(fileName, false); OutputStream o = FileUtils.openFileOutputStream(file, false);
out = new BufferedOutputStream(o, Constants.IO_BUFFER_SIZE); out = new BufferedOutputStream(o, Constants.IO_BUFFER_SIZE);
out = CompressTool.wrapOutputStream(out, compressionAlgorithm, Constants.SCRIPT_SQL); out = CompressTool.wrapOutputStream(out, compressionAlgorithm, Constants.SCRIPT_SQL);
} }
...@@ -139,8 +139,8 @@ public abstract class ScriptBase extends Prepared implements DataHandler { ...@@ -139,8 +139,8 @@ public abstract class ScriptBase extends Prepared implements DataHandler {
* Open the input stream. * Open the input stream.
*/ */
void openInput() throws SQLException { void openInput() throws SQLException {
String fileName = getFileName(); String file = getFileName();
if (fileName == null) { if (file == null) {
return; return;
} }
if (isEncrypted()) { if (isEncrypted()) {
...@@ -149,14 +149,14 @@ public abstract class ScriptBase extends Prepared implements DataHandler { ...@@ -149,14 +149,14 @@ public abstract class ScriptBase extends Prepared implements DataHandler {
} else { } else {
InputStream inStream; InputStream inStream;
try { try {
inStream = FileUtils.openFileInputStream(fileName); inStream = FileUtils.openFileInputStream(file);
} catch (IOException e) { } catch (IOException e) {
throw Message.convertIOException(e, fileName); throw Message.convertIOException(e, file);
} }
in = new BufferedInputStream(inStream, Constants.IO_BUFFER_SIZE); in = new BufferedInputStream(inStream, Constants.IO_BUFFER_SIZE);
in = CompressTool.wrapInputStream(in, compressionAlgorithm, Constants.SCRIPT_SQL); in = CompressTool.wrapInputStream(in, compressionAlgorithm, Constants.SCRIPT_SQL);
if (in == null) { if (in == null) {
throw Message.getSQLException(ErrorCode.FILE_NOT_FOUND_1, Constants.SCRIPT_SQL + " in " + fileName); throw Message.getSQLException(ErrorCode.FILE_NOT_FOUND_1, Constants.SCRIPT_SQL + " in " + file);
} }
} }
} }
......
...@@ -102,9 +102,9 @@ public class ScriptCommand extends ScriptBase { ...@@ -102,9 +102,9 @@ public class ScriptCommand extends ScriptBase {
} }
public LocalResult queryMeta() throws SQLException { public LocalResult queryMeta() throws SQLException {
LocalResult result = createResult(); LocalResult r = createResult();
result.done(); r.done();
return result; return r;
} }
private LocalResult createResult() { private LocalResult createResult() {
...@@ -125,9 +125,9 @@ public class ScriptCommand extends ScriptBase { ...@@ -125,9 +125,9 @@ public class ScriptCommand extends ScriptBase {
} }
Database db = session.getDatabase(); Database db = session.getDatabase();
if (settings) { if (settings) {
ObjectArray settings = db.getAllSettings(); ObjectArray settingList = db.getAllSettings();
for (int i = 0; i < settings.size(); i++) { for (int i = 0; i < settingList.size(); i++) {
Setting setting = (Setting) settings.get(i); Setting setting = (Setting) settingList.get(i);
if (setting.getName().equals(SetTypes.getTypeName(SetTypes.CREATE_BUILD))) { if (setting.getName().equals(SetTypes.getTypeName(SetTypes.CREATE_BUILD))) {
// don't add CREATE_BUILD to the script // don't add CREATE_BUILD to the script
// (it is only set when creating the database) // (it is only set when creating the database)
...@@ -356,12 +356,12 @@ public class ScriptCommand extends ScriptBase { ...@@ -356,12 +356,12 @@ public class ScriptCommand extends ScriptBase {
switch (v.getType()) { switch (v.getType()) {
case Value.BLOB: { case Value.BLOB: {
byte[] bytes = new byte[lobBlockSize]; byte[] bytes = new byte[lobBlockSize];
InputStream in = v.getInputStream(); InputStream input = v.getInputStream();
try { try {
for (int i = 0;; i++) { for (int i = 0;; i++) {
StringBuffer buff = new StringBuffer(lobBlockSize * 2); StringBuffer buff = new StringBuffer(lobBlockSize * 2);
buff.append("INSERT INTO SYSTEM_LOB_STREAM VALUES(" + id + ", " + i + ", NULL, '"); buff.append("INSERT INTO SYSTEM_LOB_STREAM VALUES(" + id + ", " + i + ", NULL, '");
int len = IOUtils.readFully(in, bytes, 0, lobBlockSize); int len = IOUtils.readFully(input, bytes, 0, lobBlockSize);
if (len <= 0) { if (len <= 0) {
break; break;
} }
...@@ -371,18 +371,18 @@ public class ScriptCommand extends ScriptBase { ...@@ -371,18 +371,18 @@ public class ScriptCommand extends ScriptBase {
add(sql, true); add(sql, true);
} }
} finally { } finally {
IOUtils.closeSilently(in); IOUtils.closeSilently(input);
} }
break; break;
} }
case Value.CLOB: { case Value.CLOB: {
char[] chars = new char[lobBlockSize]; char[] chars = new char[lobBlockSize];
Reader in = v.getReader(); Reader reader = v.getReader();
try { try {
for (int i = 0;; i++) { for (int i = 0;; i++) {
StringBuffer buff = new StringBuffer(lobBlockSize * 2); StringBuffer buff = new StringBuffer(lobBlockSize * 2);
buff.append("INSERT INTO SYSTEM_LOB_STREAM VALUES(" + id + ", " + i + ", "); buff.append("INSERT INTO SYSTEM_LOB_STREAM VALUES(" + id + ", " + i + ", ");
int len = IOUtils.readFully(in, chars, lobBlockSize); int len = IOUtils.readFully(reader, chars, lobBlockSize);
if (len < 0) { if (len < 0) {
break; break;
} }
...@@ -392,7 +392,7 @@ public class ScriptCommand extends ScriptBase { ...@@ -392,7 +392,7 @@ public class ScriptCommand extends ScriptBase {
add(sql, true); add(sql, true);
} }
} finally { } finally {
IOUtils.closeSilently(in); IOUtils.closeSilently(reader);
} }
break; break;
} }
......
...@@ -444,10 +444,10 @@ public class Select extends Query { ...@@ -444,10 +444,10 @@ public class Select extends Query {
} }
private void queryDistinct(LocalResult result, long limitRows) throws SQLException { private void queryDistinct(LocalResult result, long limitRows) throws SQLException {
if (limitRows != 0 && offset != null) { if (limitRows != 0 && offsetExpr != null) {
// limitRows must be long, otherwise we get an int overflow // limitRows must be long, otherwise we get an int overflow
// if limitRows is at or near Integer.MAX_VALUE // if limitRows is at or near Integer.MAX_VALUE
limitRows += offset.getValue(session).getInt(); limitRows += offsetExpr.getValue(session).getInt();
} }
int rowNumber = 0; int rowNumber = 0;
setCurrentRowNumber(0); setCurrentRowNumber(0);
...@@ -481,10 +481,10 @@ public class Select extends Query { ...@@ -481,10 +481,10 @@ public class Select extends Query {
} }
private void queryFlat(int columnCount, LocalResult result, long limitRows) throws SQLException { private void queryFlat(int columnCount, LocalResult result, long limitRows) throws SQLException {
if (limitRows != 0 && offset != null) { if (limitRows != 0 && offsetExpr != null) {
// limitRows must be long, otherwise we get an int overflow // limitRows must be long, otherwise we get an int overflow
// if limitRows is at or near Integer.MAX_VALUE // if limitRows is at or near Integer.MAX_VALUE
limitRows += offset.getValue(session).getInt(); limitRows += offsetExpr.getValue(session).getInt();
} }
int rowNumber = 0; int rowNumber = 0;
setCurrentRowNumber(0); setCurrentRowNumber(0);
...@@ -526,8 +526,8 @@ public class Select extends Query { ...@@ -526,8 +526,8 @@ public class Select extends Query {
protected LocalResult queryWithoutCache(int maxRows) throws SQLException { protected LocalResult queryWithoutCache(int maxRows) throws SQLException {
int limitRows = maxRows; int limitRows = maxRows;
if (limit != null) { if (limitExpr != null) {
int l = limit.getValue(session).getInt(); int l = limitExpr.getValue(session).getInt();
if (limitRows == 0) { if (limitRows == 0) {
limitRows = l; limitRows = l;
} else { } else {
...@@ -558,8 +558,8 @@ public class Select extends Query { ...@@ -558,8 +558,8 @@ public class Select extends Query {
} else { } else {
queryFlat(columnCount, result, limitRows); queryFlat(columnCount, result, limitRows);
} }
if (offset != null) { if (offsetExpr != null) {
result.setOffset(offset.getValue(session).getInt()); result.setOffset(offsetExpr.getValue(session).getInt());
} }
if (limitRows != 0) { if (limitRows != 0) {
result.setLimit(limitRows); result.setLimit(limitRows);
...@@ -810,7 +810,7 @@ public class Select extends Query { ...@@ -810,7 +810,7 @@ public class Select extends Query {
Optimizer optimizer = new Optimizer(topArray, condition, session); Optimizer optimizer = new Optimizer(topArray, condition, session);
optimizer.optimize(); optimizer.optimize();
topTableFilter = optimizer.getTopFilter(); topTableFilter = optimizer.getTopFilter();
double cost = optimizer.getCost(); double planCost = optimizer.getCost();
TableFilter f = topTableFilter; TableFilter f = topTableFilter;
while (f != null) { while (f != null) {
...@@ -849,7 +849,7 @@ public class Select extends Query { ...@@ -849,7 +849,7 @@ public class Select extends Query {
f = f.getJoin(); f = f.getJoin();
} }
topTableFilter.prepare(); topTableFilter.prepare();
return cost; return planCost;
} }
public String getPlanSQL() { public String getPlanSQL() {
...@@ -939,12 +939,12 @@ public class Select extends Query { ...@@ -939,12 +939,12 @@ public class Select extends Query {
buff.append(StringUtils.unEnclose(o.getSQL())); buff.append(StringUtils.unEnclose(o.getSQL()));
} }
} }
if (limit != null) { if (limitExpr != null) {
buff.append("\nLIMIT "); buff.append("\nLIMIT ");
buff.append(StringUtils.unEnclose(limit.getSQL())); buff.append(StringUtils.unEnclose(limitExpr.getSQL()));
if (offset != null) { if (offsetExpr != null) {
buff.append(" OFFSET "); buff.append(" OFFSET ");
buff.append(StringUtils.unEnclose(offset.getSQL())); buff.append(StringUtils.unEnclose(offsetExpr.getSQL()));
} }
} }
if (isForUpdate) { if (isForUpdate) {
...@@ -1057,16 +1057,16 @@ public class Select extends Query { ...@@ -1057,16 +1057,16 @@ public class Select extends Query {
} }
} }
public void updateAggregate(Session session) throws SQLException { public void updateAggregate(Session s) throws SQLException {
for (int i = 0; i < expressions.size(); i++) { for (int i = 0; i < expressions.size(); i++) {
Expression e = (Expression) expressions.get(i); Expression e = (Expression) expressions.get(i);
e.updateAggregate(session); e.updateAggregate(s);
} }
if (condition != null) { if (condition != null) {
condition.updateAggregate(session); condition.updateAggregate(s);
} }
if (having != null) { if (having != null) {
having.updateAggregate(session); having.updateAggregate(s);
} }
} }
...@@ -1120,7 +1120,7 @@ public class Select extends Query { ...@@ -1120,7 +1120,7 @@ public class Select extends Query {
return isEverything(ExpressionVisitor.READONLY); return isEverything(ExpressionVisitor.READONLY);
} }
public String getFirstColumnAlias(Session session) { public String getFirstColumnAlias(Session s) {
if (SysProperties.CHECK) { if (SysProperties.CHECK) {
if (visibleColumnCount > 1) { if (visibleColumnCount > 1) {
Message.throwInternalError("" + visibleColumnCount); Message.throwInternalError("" + visibleColumnCount);
...@@ -1130,8 +1130,8 @@ public class Select extends Query { ...@@ -1130,8 +1130,8 @@ public class Select extends Query {
if (expr instanceof Alias) { if (expr instanceof Alias) {
return expr.getAlias(); return expr.getAlias();
} }
Mode mode = session.getDatabase().getMode(); Mode mode = s.getDatabase().getMode();
String name = session.getNextSystemIdentifier(getSQL()); String name = s.getNextSystemIdentifier(getSQL());
expr = new Alias(expr, name, mode.aliasColumnName); expr = new Alias(expr, name, mode.aliasColumnName);
expressions.set(0, expr); expressions.set(0, expr);
return expr.getAlias(); return expr.getAlias();
......
...@@ -92,19 +92,19 @@ public class SelectUnion extends Query { ...@@ -92,19 +92,19 @@ public class SelectUnion extends Query {
} }
public LocalResult queryMeta() throws SQLException { public LocalResult queryMeta() throws SQLException {
ObjectArray expressions = left.getExpressions(); ObjectArray leftExpressions = left.getExpressions();
int columnCount = left.getColumnCount(); int columnCount = left.getColumnCount();
LocalResult result = new LocalResult(session, expressions, columnCount); LocalResult result = new LocalResult(session, leftExpressions, columnCount);
result.done(); result.done();
return result; return result;
} }
protected LocalResult queryWithoutCache(int maxrows) throws SQLException { protected LocalResult queryWithoutCache(int maxrows) throws SQLException {
if (maxrows != 0) { if (maxrows != 0) {
if (limit != null) { if (limitExpr != null) {
maxrows = Math.min(limit.getValue(session).getInt(), maxrows); maxrows = Math.min(limitExpr.getValue(session).getInt(), maxrows);
} }
limit = ValueExpression.get(ValueInt.get(maxrows)); limitExpr = ValueExpression.get(ValueInt.get(maxrows));
} }
int columnCount = left.getColumnCount(); int columnCount = left.getColumnCount();
LocalResult result = new LocalResult(session, expressions, columnCount); LocalResult result = new LocalResult(session, expressions, columnCount);
...@@ -171,11 +171,11 @@ public class SelectUnion extends Query { ...@@ -171,11 +171,11 @@ public class SelectUnion extends Query {
default: default:
Message.throwInternalError("type=" + unionType); Message.throwInternalError("type=" + unionType);
} }
if (offset != null) { if (offsetExpr != null) {
result.setOffset(offset.getValue(session).getInt()); result.setOffset(offsetExpr.getValue(session).getInt());
} }
if (limit != null) { if (limitExpr != null) {
result.setLimit(limit.getValue(session).getInt()); result.setLimit(limitExpr.getValue(session).getInt());
} }
result.done(); result.done();
return result; return result;
...@@ -323,12 +323,12 @@ public class SelectUnion extends Query { ...@@ -323,12 +323,12 @@ public class SelectUnion extends Query {
buff.append(" ORDER BY "); buff.append(" ORDER BY ");
buff.append(sort.getSQL(exprList, exprList.length)); buff.append(sort.getSQL(exprList, exprList.length));
} }
if (limit != null) { if (limitExpr != null) {
buff.append(" LIMIT "); buff.append(" LIMIT ");
buff.append(StringUtils.unEnclose(limit.getSQL())); buff.append(StringUtils.unEnclose(limitExpr.getSQL()));
if (offset != null) { if (offsetExpr != null) {
buff.append(" OFFSET "); buff.append(" OFFSET ");
buff.append(StringUtils.unEnclose(offset.getSQL())); buff.append(StringUtils.unEnclose(offsetExpr.getSQL()));
} }
} }
if (isForUpdate) { if (isForUpdate) {
...@@ -350,12 +350,12 @@ public class SelectUnion extends Query { ...@@ -350,12 +350,12 @@ public class SelectUnion extends Query {
return left.isReadOnly() && right.isReadOnly(); return left.isReadOnly() && right.isReadOnly();
} }
public void updateAggregate(Session session) throws SQLException { public void updateAggregate(Session s) throws SQLException {
left.updateAggregate(session); left.updateAggregate(s);
right.updateAggregate(session); right.updateAggregate(s);
} }
public String getFirstColumnAlias(Session session) { public String getFirstColumnAlias(Session s) {
return null; return null;
} }
......
...@@ -45,10 +45,10 @@ public class ConstraintCheck extends Constraint { ...@@ -45,10 +45,10 @@ public class ConstraintCheck extends Constraint {
this.expr = expr; this.expr = expr;
} }
public String getCreateSQLForCopy(Table table, String quotedName) { public String getCreateSQLForCopy(Table forTable, String quotedName) {
StringBuffer buff = new StringBuffer(); StringBuffer buff = new StringBuffer();
buff.append("ALTER TABLE "); buff.append("ALTER TABLE ");
buff.append(table.getSQL()); buff.append(forTable.getSQL());
buff.append(" ADD CONSTRAINT "); buff.append(" ADD CONSTRAINT ");
buff.append(quotedName); buff.append(quotedName);
if (comment != null) { if (comment != null) {
......
...@@ -93,27 +93,27 @@ public class ConstraintReferential extends Constraint { ...@@ -93,27 +93,27 @@ public class ConstraintReferential extends Constraint {
/** /**
* Create the SQL statement of this object so a copy of the table can be made. * Create the SQL statement of this object so a copy of the table can be made.
* *
* @param table the table to create the object for * @param forTable the table to create the object for
* @param quotedName the name of this object (quoted if necessary) * @param quotedName the name of this object (quoted if necessary)
* @return the SQL statement * @return the SQL statement
*/ */
public String getCreateSQLForCopy(Table table, String quotedName) { public String getCreateSQLForCopy(Table forTable, String quotedName) {
return getCreateSQLForCopy(table, refTable, quotedName, true); return getCreateSQLForCopy(forTable, refTable, quotedName, true);
} }
/** /**
* Create the SQL statement of this object so a copy of the table can be made. * Create the SQL statement of this object so a copy of the table can be made.
* *
* @param table the table to create the object for * @param forTable the table to create the object for
* @param refTable the referenced table * @param forRefTable the referenced table
* @param quotedName the name of this object (quoted if necessary) * @param quotedName the name of this object (quoted if necessary)
* @param internalIndex add the index name to the statement * @param internalIndex add the index name to the statement
* @return the SQL statement * @return the SQL statement
*/ */
public String getCreateSQLForCopy(Table table, Table refTable, String quotedName, boolean internalIndex) { public String getCreateSQLForCopy(Table forTable, Table forRefTable, String quotedName, boolean internalIndex) {
StringBuffer buff = new StringBuffer(); StringBuffer buff = new StringBuffer();
buff.append("ALTER TABLE "); buff.append("ALTER TABLE ");
String mainTable = table.getSQL(); String mainTable = forTable.getSQL();
buff.append(mainTable); buff.append(mainTable);
buff.append(" ADD CONSTRAINT "); buff.append(" ADD CONSTRAINT ");
buff.append(quotedName); buff.append(quotedName);
...@@ -131,7 +131,7 @@ public class ConstraintReferential extends Constraint { ...@@ -131,7 +131,7 @@ public class ConstraintReferential extends Constraint {
buff.append(cols[i].getSQL()); buff.append(cols[i].getSQL());
} }
buff.append(")"); buff.append(")");
if (internalIndex && indexOwner && table == this.table) { if (internalIndex && indexOwner && forTable == this.table) {
buff.append(" INDEX "); buff.append(" INDEX ");
buff.append(index.getSQL()); buff.append(index.getSQL());
} }
...@@ -139,9 +139,9 @@ public class ConstraintReferential extends Constraint { ...@@ -139,9 +139,9 @@ public class ConstraintReferential extends Constraint {
String quotedRefTable; String quotedRefTable;
if (this.table == this.refTable) { if (this.table == this.refTable) {
// self-referencing constraints: need to use new table // self-referencing constraints: need to use new table
quotedRefTable = table.getSQL(); quotedRefTable = forTable.getSQL();
} else { } else {
quotedRefTable = refTable.getSQL(); quotedRefTable = forRefTable.getSQL();
} }
buff.append(quotedRefTable); buff.append(quotedRefTable);
buff.append("("); buff.append("(");
...@@ -152,7 +152,7 @@ public class ConstraintReferential extends Constraint { ...@@ -152,7 +152,7 @@ public class ConstraintReferential extends Constraint {
buff.append(refCols[i].getSQL()); buff.append(refCols[i].getSQL());
} }
buff.append(")"); buff.append(")");
if (internalIndex && refIndexOwner && table == this.table) { if (internalIndex && refIndexOwner && forTable == this.table) {
buff.append(" INDEX "); buff.append(" INDEX ");
buff.append(refIndex.getSQL()); buff.append(refIndex.getSQL());
} }
...@@ -349,16 +349,16 @@ public class ConstraintReferential extends Constraint { ...@@ -349,16 +349,16 @@ public class ConstraintReferential extends Constraint {
} }
} }
private boolean found(Session session, Index index, SearchRow check, Row excluding) throws SQLException { private boolean found(Session session, Index searchIndex, SearchRow check, Row excluding) throws SQLException {
index.getTable().lock(session, false, false); searchIndex.getTable().lock(session, false, false);
Cursor cursor = index.find(session, check, check); Cursor cursor = searchIndex.find(session, check, check);
while (cursor.next()) { while (cursor.next()) {
SearchRow found; SearchRow found;
found = cursor.getSearchRow(); found = cursor.getSearchRow();
if (excluding != null && found.getPos() == excluding.getPos()) { if (excluding != null && found.getPos() == excluding.getPos()) {
continue; continue;
} }
Column[] cols = index.getColumns(); Column[] cols = searchIndex.getColumns();
boolean allEqual = true; boolean allEqual = true;
for (int i = 0; i < columns.length && i < cols.length; i++) { for (int i = 0; i < columns.length && i < cols.length; i++) {
int idx = cols[i].getColumnId(); int idx = cols[i].getColumnId();
......
...@@ -37,14 +37,14 @@ public class ConstraintUnique extends Constraint { ...@@ -37,14 +37,14 @@ public class ConstraintUnique extends Constraint {
return primaryKey ? Constraint.PRIMARY_KEY : Constraint.UNIQUE; return primaryKey ? Constraint.PRIMARY_KEY : Constraint.UNIQUE;
} }
public String getCreateSQLForCopy(Table table, String quotedName) { public String getCreateSQLForCopy(Table forTable, String quotedName) {
return getCreateSQLForCopy(table, quotedName, true); return getCreateSQLForCopy(forTable, quotedName, true);
} }
private String getCreateSQLForCopy(Table table, String quotedName, boolean internalIndex) { private String getCreateSQLForCopy(Table forTable, String quotedName, boolean internalIndex) {
StringBuffer buff = new StringBuffer(); StringBuffer buff = new StringBuffer();
buff.append("ALTER TABLE "); buff.append("ALTER TABLE ");
buff.append(table.getSQL()); buff.append(forTable.getSQL());
buff.append(" ADD CONSTRAINT "); buff.append(" ADD CONSTRAINT ");
buff.append(quotedName); buff.append(quotedName);
if (comment != null) { if (comment != null) {
...@@ -61,7 +61,7 @@ public class ConstraintUnique extends Constraint { ...@@ -61,7 +61,7 @@ public class ConstraintUnique extends Constraint {
buff.append(Parser.quoteIdentifier(columns[i].column.getName())); buff.append(Parser.quoteIdentifier(columns[i].column.getName()));
} }
buff.append(')'); buff.append(')');
if (internalIndex && indexOwner && table == this.table) { if (internalIndex && indexOwner && forTable == this.table) {
buff.append(" INDEX "); buff.append(" INDEX ");
buff.append(index.getSQL()); buff.append(index.getSQL());
} }
......
...@@ -158,11 +158,6 @@ public class Constants { ...@@ -158,11 +158,6 @@ public class Constants {
*/ */
public static final char DEFAULT_ESCAPE_CHAR = '\\'; public static final char DEFAULT_ESCAPE_CHAR = '\\';
/**
* The default port number of the FTP server.
*/
public static final int DEFAULT_FTP_PORT = 8021;
/** /**
* If the HTTP server should allow connections from other computers by * If the HTTP server should allow connections from other computers by
* default. * default.
...@@ -170,8 +165,8 @@ public class Constants { ...@@ -170,8 +165,8 @@ public class Constants {
public static final boolean DEFAULT_HTTP_ALLOW_OTHERS = false; public static final boolean DEFAULT_HTTP_ALLOW_OTHERS = false;
/** /**
* The default port number of the HTTP server (for the H2 Console). This * The default port number of the HTTP server (for the H2 Console).
* value is also in the documentation. * This value is also in the documentation and in the Server javadoc.
*/ */
public static final int DEFAULT_HTTP_PORT = 8082; public static final int DEFAULT_HTTP_PORT = 8082;
......
...@@ -201,9 +201,9 @@ public class Database implements DataHandler { ...@@ -201,9 +201,9 @@ public class Database implements DataHandler {
setEventListenerClass(listener); setEventListenerClass(listener);
} }
} }
String log = ci.getProperty(SetTypes.LOG, null); String logSetting = ci.getProperty(SetTypes.LOG, null);
if (log != null) { if (logSetting != null) {
this.logIndexChanges = "2".equals(log); this.logIndexChanges = "2".equals(logSetting);
} }
String ignoreSummary = ci.getProperty("RECOVER", null); String ignoreSummary = ci.getProperty("RECOVER", null);
if (ignoreSummary != null) { if (ignoreSummary != null) {
...@@ -437,11 +437,11 @@ public class Database implements DataHandler { ...@@ -437,11 +437,11 @@ public class Database implements DataHandler {
return traceSystem.getTrace(module); return traceSystem.getTrace(module);
} }
public FileStore openFile(String name, String mode, boolean mustExist) throws SQLException { public FileStore openFile(String name, String openMode, boolean mustExist) throws SQLException {
if (mustExist && !FileUtils.exists(name)) { if (mustExist && !FileUtils.exists(name)) {
throw Message.getSQLException(ErrorCode.FILE_NOT_FOUND_1, name); throw Message.getSQLException(ErrorCode.FILE_NOT_FOUND_1, name);
} }
FileStore store = FileStore.open(this, name, mode, cipher, filePasswordHash); FileStore store = FileStore.open(this, name, openMode, cipher, filePasswordHash);
try { try {
store.init(); store.init();
} catch (SQLException e) { } catch (SQLException e) {
...@@ -454,15 +454,15 @@ public class Database implements DataHandler { ...@@ -454,15 +454,15 @@ public class Database implements DataHandler {
/** /**
* Check if the file password hash is correct. * Check if the file password hash is correct.
* *
* @param cipher the cipher algorithm * @param testCipher the cipher algorithm
* @param hash the hash code * @param testHash the hash code
* @return true if the cipher algorithm and the password match * @return true if the cipher algorithm and the password match
*/ */
public boolean validateFilePasswordHash(String cipher, byte[] hash) throws SQLException { public boolean validateFilePasswordHash(String testCipher, byte[] testHash) throws SQLException {
if (!StringUtils.equals(cipher, this.cipher)) { if (!StringUtils.equals(testCipher, this.cipher)) {
return false; return false;
} }
return ByteUtils.compareSecure(hash, filePasswordHash); return ByteUtils.compareSecure(testHash, filePasswordHash);
} }
private void openFileData() throws SQLException { private void openFileData() throws SQLException {
......
...@@ -42,17 +42,17 @@ public abstract class DbObjectBase implements DbObject { ...@@ -42,17 +42,17 @@ public abstract class DbObjectBase implements DbObject {
/** /**
* Initialize some attributes of this object. * Initialize some attributes of this object.
* *
* @param database the database * @param db the database
* @param id the object id * @param objectId the object id
* @param name the name * @param name the name
* @param traceModule the trace module name * @param traceModule the trace module name
*/ */
protected void initDbObjectBase(Database database, int id, String name, String traceModule) { protected void initDbObjectBase(Database db, int objectId, String name, String traceModule) {
this.database = database; this.database = db;
this.trace = database.getTrace(traceModule); this.trace = db.getTrace(traceModule);
this.id = id; this.id = objectId;
this.objectName = name; this.objectName = name;
this.modificationId = database.getModificationMetaId(); this.modificationId = db.getModificationMetaId();
} }
/** /**
......
...@@ -531,8 +531,8 @@ public class Session extends SessionWithState { ...@@ -531,8 +531,8 @@ public class Session extends SessionWithState {
savepoints.keySet().toArray(names); savepoints.keySet().toArray(names);
for (int i = 0; i < names.length; i++) { for (int i = 0; i < names.length; i++) {
String name = names[i]; String name = names[i];
Integer id = (Integer) savepoints.get(names[i]); Integer savepointIndex = (Integer) savepoints.get(names[i]);
if (id.intValue() > index) { if (savepointIndex.intValue() > index) {
savepoints.remove(name); savepoints.remove(name);
} }
} }
...@@ -749,11 +749,11 @@ public class Session extends SessionWithState { ...@@ -749,11 +749,11 @@ public class Session extends SessionWithState {
if (savepoints == null) { if (savepoints == null) {
throw Message.getSQLException(ErrorCode.SAVEPOINT_IS_INVALID_1, name); throw Message.getSQLException(ErrorCode.SAVEPOINT_IS_INVALID_1, name);
} }
Integer id = (Integer) savepoints.get(name); Integer savepointIndex = (Integer) savepoints.get(name);
if (id == null) { if (savepointIndex == null) {
throw Message.getSQLException(ErrorCode.SAVEPOINT_IS_INVALID_1, name); throw Message.getSQLException(ErrorCode.SAVEPOINT_IS_INVALID_1, name);
} }
int i = id.intValue(); int i = savepointIndex.intValue();
rollbackTo(i, false); rollbackTo(i, false);
} }
...@@ -943,11 +943,11 @@ public class Session extends SessionWithState { ...@@ -943,11 +943,11 @@ public class Session extends SessionWithState {
* @return the new identifier * @return the new identifier
*/ */
public String getNextSystemIdentifier(String sql) { public String getNextSystemIdentifier(String sql) {
String id; String identifier;
do { do {
id = SYSTEM_IDENTIFIER_PREFIX + systemIdentifier++; identifier = SYSTEM_IDENTIFIER_PREFIX + systemIdentifier++;
} while (sql.indexOf(id) >= 0); } while (sql.indexOf(identifier) >= 0);
return id; return identifier;
} }
/** /**
......
...@@ -229,12 +229,12 @@ class AggregateData { ...@@ -229,12 +229,12 @@ class AggregateData {
return v == null ? ValueNull.INSTANCE : v.convertTo(dataType); return v == null ? ValueNull.INSTANCE : v.convertTo(dataType);
} }
private Value divide(Value a, long count) throws SQLException { private Value divide(Value a, long by) throws SQLException {
if (count == 0) { if (by == 0) {
return ValueNull.INSTANCE; return ValueNull.INSTANCE;
} }
int type = Value.getHigherOrder(a.getType(), Value.LONG); int type = Value.getHigherOrder(a.getType(), Value.LONG);
Value b = ValueLong.get(count).convertTo(type); Value b = ValueLong.get(by).convertTo(type);
a = a.convertTo(type).divide(b); a = a.convertTo(type).divide(b);
return a; return a;
} }
......
...@@ -264,17 +264,17 @@ public class CompareLike extends Condition { ...@@ -264,17 +264,17 @@ public class CompareLike extends Condition {
/** /**
* Test if the value matches the pattern. * Test if the value matches the pattern.
* *
* @param pattern the pattern * @param testPattern the pattern
* @param value the value * @param value the value
* @param escape the escape character * @param escapeChar the escape character
* @return true if the value matches * @return true if the value matches
*/ */
public boolean test(String pattern, String value, char escape) throws SQLException { public boolean test(String testPattern, String value, char escapeChar) throws SQLException {
initPattern(pattern, escape); initPattern(testPattern, escapeChar);
return compareAt(value, 0, 0, value.length()); return compareAt(value, 0, 0, value.length());
} }
private void initPattern(String p, char escape) throws SQLException { private void initPattern(String p, char escapeChar) throws SQLException {
if (regexp) { if (regexp) {
patternString = p; patternString = p;
try { try {
...@@ -301,12 +301,12 @@ public class CompareLike extends Condition { ...@@ -301,12 +301,12 @@ public class CompareLike extends Condition {
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
char c = p.charAt(i); char c = p.charAt(i);
int type; int type;
if (escape == c) { if (escapeChar == c) {
if (i >= len - 1) { if (i >= len - 1) {
throw Message.getSQLException(ErrorCode.LIKE_ESCAPE_ERROR_1, StringUtils.addAsterisk(p, i)); throw Message.getSQLException(ErrorCode.LIKE_ESCAPE_ERROR_1, StringUtils.addAsterisk(p, i));
} }
c = p.charAt(++i); c = p.charAt(++i);
if (c != '_' && c != '%' && c != escape) { if (c != '_' && c != '%' && c != escapeChar) {
throw Message.getSQLException(ErrorCode.LIKE_ESCAPE_ERROR_1, StringUtils.addAsterisk(p, i)); throw Message.getSQLException(ErrorCode.LIKE_ESCAPE_ERROR_1, StringUtils.addAsterisk(p, i));
} }
type = MATCH; type = MATCH;
......
...@@ -117,14 +117,14 @@ public class Comparison extends Condition { ...@@ -117,14 +117,14 @@ public class Comparison extends Condition {
return "(" + sql + ")"; return "(" + sql + ")";
} }
private Expression getCast(Expression expr, int dataType, long precision, int scale, int displaySize, Session session) private Expression getCast(Expression expr, int targetDataType, long precision, int scale, int displaySize, Session session)
throws SQLException { throws SQLException {
if (expr == ValueExpression.getNull()) { if (expr == ValueExpression.getNull()) {
return expr; return expr;
} }
Function function = Function.getFunction(session.getDatabase(), "CAST"); Function function = Function.getFunction(session.getDatabase(), "CAST");
function.setParameter(0, expr); function.setParameter(0, expr);
function.setDataType(dataType, precision, scale, displaySize); function.setDataType(targetDataType, precision, scale, displaySize);
function.doneWithParameters(); function.doneWithParameters();
return function.optimize(session); return function.optimize(session);
} }
...@@ -448,12 +448,12 @@ public class Comparison extends Condition { ...@@ -448,12 +448,12 @@ public class Comparison extends Condition {
/** /**
* Get the left or the right sub-expression of this condition. * Get the left or the right sub-expression of this condition.
* *
* @param left true to get the left sub-expression, false to get the right * @param getLeft true to get the left sub-expression, false to get the right
* sub-expression. * sub-expression.
* @return the sub-expression * @return the sub-expression
*/ */
public Expression getExpression(boolean left) { public Expression getExpression(boolean getLeft) {
return left ? this.left : right; return getLeft ? this.left : right;
} }
} }
...@@ -253,12 +253,12 @@ public class ConditionAndOr extends Condition { ...@@ -253,12 +253,12 @@ public class ConditionAndOr extends Condition {
/** /**
* Get the left or the right sub-expression of this condition. * Get the left or the right sub-expression of this condition.
* *
* @param left true to get the left sub-expression, false to get the right * @param getLeft true to get the left sub-expression, false to get the right
* sub-expression. * sub-expression.
* @return the sub-expression * @return the sub-expression
*/ */
public Expression getExpression(boolean left) { public Expression getExpression(boolean getLeft) {
return left ? this.left : right; return getLeft ? this.left : right;
} }
} }
...@@ -233,7 +233,7 @@ public class FullTextLucene extends FullText { ...@@ -233,7 +233,7 @@ public class FullTextLucene extends FullText {
/** /**
* Get the index modifier for the given connection. * Get the index modifier for the given connection.
* *
* @param conn the connection * @param conn the connection
* @return the index modifier * @return the index modifier
*/ */
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论