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

--no commit message

--no commit message
上级 5dd5c94a
差异被折叠。
差异被折叠。
...@@ -3350,16 +3350,14 @@ public class Parser { ...@@ -3350,16 +3350,14 @@ public class Parser {
command.setSequenceName(sequenceName); command.setSequenceName(sequenceName);
if (readIf("START")) { if (readIf("START")) {
readIf("WITH"); readIf("WITH");
long start = readLong(); command.setStartWith(readExpression());
command.setStartWith(start);
} }
if (readIf("INCREMENT")) { if (readIf("INCREMENT")) {
readIf("BY"); readIf("BY");
long increment = readLong(); command.setIncrement(readExpression());
command.setIncrement(increment);
} }
if (readIf("CACHE")) { if (readIf("CACHE")) {
command.setCacheSize(readLong()); command.setCacheSize(readExpression());
} }
if (readIf("BELONGS_TO_TABLE")) { if (readIf("BELONGS_TO_TABLE")) {
command.setBelongsToTable(true); command.setBelongsToTable(true);
...@@ -3632,13 +3630,11 @@ public class Parser { ...@@ -3632,13 +3630,11 @@ public class Parser {
command.setSequence(getSchema().getSequence(sequenceName)); command.setSequence(getSchema().getSequence(sequenceName));
if (readIf("RESTART")) { if (readIf("RESTART")) {
read("WITH"); read("WITH");
long start = readLong(); command.setStartWith(readExpression());
command.setStartWith(start);
} }
if (readIf("INCREMENT")) { if (readIf("INCREMENT")) {
read("BY"); read("BY");
long increment = readLong(); command.setIncrement(readExpression());
command.setIncrement(increment);
} }
return command; return command;
} }
...@@ -4106,7 +4102,7 @@ public class Parser { ...@@ -4106,7 +4102,7 @@ public class Parser {
} }
} else if (readIf("RESTART")) { } else if (readIf("RESTART")) {
readIf("WITH"); readIf("WITH");
long start = readLong(); Expression start = readExpression();
AlterTableAlterColumn command = new AlterTableAlterColumn(session, table.getSchema()); AlterTableAlterColumn command = new AlterTableAlterColumn(session, table.getSchema());
command.setTable(table); command.setTable(table);
command.setType(AlterTableAlterColumn.RESTART); command.setType(AlterTableAlterColumn.RESTART);
...@@ -4114,12 +4110,11 @@ public class Parser { ...@@ -4114,12 +4110,11 @@ public class Parser {
command.setStartWith(start); command.setStartWith(start);
return command; return command;
} else if (readIf("SELECTIVITY")) { } else if (readIf("SELECTIVITY")) {
int selectivity = getPositiveInt();
AlterTableAlterColumn command = new AlterTableAlterColumn(session, table.getSchema()); AlterTableAlterColumn command = new AlterTableAlterColumn(session, table.getSchema());
command.setTable(table); command.setTable(table);
command.setType(AlterTableAlterColumn.SELECTIVITY); command.setType(AlterTableAlterColumn.SELECTIVITY);
command.setOldColumn(column); command.setOldColumn(column);
command.setStartWith(selectivity); command.setStartWith(readExpression());
return command; return command;
} else { } else {
Column newColumn = parseColumnForTable(columnName); Column newColumn = parseColumnForTable(columnName);
......
...@@ -9,6 +9,7 @@ import java.sql.SQLException; ...@@ -9,6 +9,7 @@ import java.sql.SQLException;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.expression.Expression;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.schema.Sequence; import org.h2.schema.Sequence;
...@@ -19,10 +20,8 @@ import org.h2.schema.Sequence; ...@@ -19,10 +20,8 @@ import org.h2.schema.Sequence;
public class AlterSequence extends DefineCommand { public class AlterSequence extends DefineCommand {
private Sequence sequence; private Sequence sequence;
private boolean newStart; private Expression start;
private long start; private Expression increment;
private boolean newIncrement;
private long increment;
public AlterSequence(Session session) { public AlterSequence(Session session) {
super(session); super(session);
...@@ -32,16 +31,11 @@ public class AlterSequence extends DefineCommand { ...@@ -32,16 +31,11 @@ public class AlterSequence extends DefineCommand {
this.sequence = sequence; this.sequence = sequence;
} }
public void setStartWith(long start) { public void setStartWith(Expression start) {
newStart = true;
this.start = start; this.start = start;
} }
public void setIncrement(long increment) throws SQLException { public void setIncrement(Expression increment) throws SQLException {
newIncrement = true;
if (increment == 0) {
throw Message.getSQLException(ErrorCode.INVALID_VALUE_2, new String[] { "0", "INCREMENT" });
}
this.increment = increment; this.increment = increment;
} }
...@@ -49,11 +43,16 @@ public class AlterSequence extends DefineCommand { ...@@ -49,11 +43,16 @@ public class AlterSequence extends DefineCommand {
// TODO rights: what are the rights required for a sequence? // TODO rights: what are the rights required for a sequence?
session.commit(true); session.commit(true);
Database db = session.getDatabase(); Database db = session.getDatabase();
if (newStart) { if (start != null) {
sequence.setStartValue(start); long startValue = start.optimize(session).getValue(session).getLong();
sequence.setStartValue(startValue);
} }
if (newIncrement) { if (increment != null) {
sequence.setIncrement(increment); long incrementValue = increment.optimize(session).getValue(session).getLong();
if (incrementValue == 0) {
throw Message.getSQLException(ErrorCode.INVALID_VALUE_2, new String[] { "0", "INCREMENT" });
}
sequence.setIncrement(incrementValue);
} }
db.update(session, sequence); db.update(session, sequence);
return 0; return 0;
......
...@@ -47,7 +47,7 @@ public class AlterTableAlterColumn extends SchemaCommand { ...@@ -47,7 +47,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
private Column newColumn; private Column newColumn;
private int type; private int type;
private Expression defaultExpression; private Expression defaultExpression;
private long newStart; private Expression newStart;
private String addBefore; private String addBefore;
public AlterTableAlterColumn(Session session, Schema schema) { public AlterTableAlterColumn(Session session, Schema schema) {
...@@ -105,7 +105,8 @@ public class AlterTableAlterColumn extends SchemaCommand { ...@@ -105,7 +105,8 @@ public class AlterTableAlterColumn extends SchemaCommand {
if (sequence == null) { if (sequence == null) {
throw Message.getSQLException(ErrorCode.SEQUENCE_NOT_FOUND_1, oldColumn.getSQL()); throw Message.getSQLException(ErrorCode.SEQUENCE_NOT_FOUND_1, oldColumn.getSQL());
} }
sequence.setStartValue(newStart); long value = newStart.optimize(session).getValue(session).getLong();
sequence.setStartValue(value);
db.update(session, sequence); db.update(session, sequence);
break; break;
} }
...@@ -143,7 +144,8 @@ public class AlterTableAlterColumn extends SchemaCommand { ...@@ -143,7 +144,8 @@ public class AlterTableAlterColumn extends SchemaCommand {
break; break;
} }
case SELECTIVITY: { case SELECTIVITY: {
oldColumn.setSelectivity((int) newStart); int value = newStart.optimize(session).getValue(session).getInt();
oldColumn.setSelectivity(value);
db.update(session, table); db.update(session, table);
break; break;
} }
...@@ -400,7 +402,7 @@ public class AlterTableAlterColumn extends SchemaCommand { ...@@ -400,7 +402,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
this.type = type; this.type = type;
} }
public void setStartWith(long start) { public void setStartWith(Expression start) {
newStart = start; newStart = start;
} }
......
...@@ -9,6 +9,7 @@ import java.sql.SQLException; ...@@ -9,6 +9,7 @@ import java.sql.SQLException;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.expression.Expression;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.schema.Schema; import org.h2.schema.Schema;
import org.h2.schema.Sequence; import org.h2.schema.Sequence;
...@@ -21,9 +22,9 @@ public class CreateSequence extends SchemaCommand { ...@@ -21,9 +22,9 @@ public class CreateSequence extends SchemaCommand {
private String sequenceName; private String sequenceName;
private boolean ifNotExists; private boolean ifNotExists;
private long start = 1; private Expression start;
private long increment = 1; private Expression increment;
private long cacheSize = Sequence.DEFAULT_CACHE_SIZE; private Expression cacheSize;
private boolean belongsToTable; private boolean belongsToTable;
public CreateSequence(Session session, Schema schema) { public CreateSequence(Session session, Schema schema) {
...@@ -49,18 +50,26 @@ public class CreateSequence extends SchemaCommand { ...@@ -49,18 +50,26 @@ public class CreateSequence extends SchemaCommand {
} }
int id = getObjectId(false, true); int id = getObjectId(false, true);
Sequence sequence = new Sequence(getSchema(), id, sequenceName, belongsToTable); Sequence sequence = new Sequence(getSchema(), id, sequenceName, belongsToTable);
sequence.setStartValue(start); sequence.setStartValue(getLong(start, 1));
sequence.setIncrement(increment); sequence.setIncrement(getLong(increment, 1));
sequence.setCacheSize(cacheSize); sequence.setCacheSize(getLong(cacheSize, Sequence.DEFAULT_CACHE_SIZE));
db.addSchemaObject(session, sequence); db.addSchemaObject(session, sequence);
return 0; return 0;
} }
public void setStartWith(long start) { private long getLong(Expression expr, long defaultValue) throws SQLException {
if (expr == null) {
return defaultValue;
} else {
return expr.optimize(session).getValue(session).getLong();
}
}
public void setStartWith(Expression start) {
this.start = start; this.start = start;
} }
public void setIncrement(long increment) { public void setIncrement(Expression increment) {
this.increment = increment; this.increment = increment;
} }
...@@ -68,7 +77,7 @@ public class CreateSequence extends SchemaCommand { ...@@ -68,7 +77,7 @@ public class CreateSequence extends SchemaCommand {
this.belongsToTable = belongsToTable; this.belongsToTable = belongsToTable;
} }
public void setCacheSize(long cacheSize) { public void setCacheSize(Expression cacheSize) {
this.cacheSize = cacheSize; this.cacheSize = cacheSize;
} }
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
*/ */
package org.h2.constant; package org.h2.constant;
/** /**
* This class defines the error codes used for SQL exceptions. * This class defines the error codes used for SQL exceptions.
*/ */
...@@ -272,7 +271,8 @@ public class ErrorCode { ...@@ -272,7 +271,8 @@ public class ErrorCode {
/** /**
* The error with code <code>50100</code> is thrown when * The error with code <code>50100</code> is thrown when
* calling an unsupported JDBC method. * calling an unsupported JDBC method. See the stack trace
* for details.
*/ */
public static final int FEATURE_NOT_SUPPORTED = 50100; public static final int FEATURE_NOT_SUPPORTED = 50100;
...@@ -744,10 +744,37 @@ public class ErrorCode { ...@@ -744,10 +744,37 @@ public class ErrorCode {
*/ */
public static final int TRIGGER_NOT_FOUND_1 = 90042; public static final int TRIGGER_NOT_FOUND_1 = 90042;
private int test; /**
* The error with code <code>90043</code> is thrown when
* there is an error initializing the trigger, for example because the
* class does not implement the Trigger interface.
* See the root cause for details.
* Example:
* <pre>
* CREATE TABLE TEST(ID INT);
* CREATE TRIGGER TRIGGER_A AFTER INSERT ON TEST
* CALL "java.lang.String";
* </pre>
*/
public static final int ERROR_CREATING_TRIGGER_OBJECT_3 = 90043; public static final int ERROR_CREATING_TRIGGER_OBJECT_3 = 90043;
/**
* The error with code <code>90044</code> is thrown when
* an exception or error occured while calling the triggers fire method.
* See the root cause for details.
*/
public static final int ERROR_EXECUTING_TRIGGER_3 = 90044; public static final int ERROR_EXECUTING_TRIGGER_3 = 90044;
/**
* The error with code <code>90045</code> is thrown when
* trying to create a constraint if an object with this name already exists.
* Example:
* <pre>
* CREATE TABLE TEST(ID INT NOT NULL);
* ALTER TABLE TEST ADD CONSTRAINT PK PRIMARY KEY(ID);
* ALTER TABLE TEST ADD CONSTRAINT PK PRIMARY KEY(ID);
* </pre>
*/
public static final int CONSTRAINT_ALREADY_EXISTS_1 = 90045; public static final int CONSTRAINT_ALREADY_EXISTS_1 = 90045;
/** /**
...@@ -766,6 +793,12 @@ public class ErrorCode { ...@@ -766,6 +793,12 @@ public class ErrorCode {
* trying to connect to a TCP server with an incompatible client. * trying to connect to a TCP server with an incompatible client.
*/ */
public static final int DRIVER_VERSION_ERROR_2 = 90047; public static final int DRIVER_VERSION_ERROR_2 = 90047;
/**
* The error with code <code>90048</code> is thrown when
* the file header of a database files (*.db) does not match the
* expected version, or if it is corrupted.
*/
public static final int FILE_VERSION_ERROR_1 = 90048; public static final int FILE_VERSION_ERROR_1 = 90048;
/** /**
...@@ -850,7 +883,19 @@ public class ErrorCode { ...@@ -850,7 +883,19 @@ public class ErrorCode {
* </pre> * </pre>
*/ */
public static final int INVALID_USE_OF_AGGREGATE_FUNCTION_1 = 90054; public static final int INVALID_USE_OF_AGGREGATE_FUNCTION_1 = 90054;
/**
* The error with code <code>90055</code> is thrown when
* trying to open a database with an unsupported cipher algorithm.
* Supported are AES and XTEA.
* Example:
* <pre>
* jdbc:h2:test;CIPHER=DES
* </pre>
*/
public static final int UNSUPPORTED_CIPHER = 90055; public static final int UNSUPPORTED_CIPHER = 90055;
private int todo;
public static final int NO_DEFAULT_SET_1 = 90056; public static final int NO_DEFAULT_SET_1 = 90056;
/** /**
...@@ -1090,7 +1135,20 @@ public class ErrorCode { ...@@ -1090,7 +1135,20 @@ public class ErrorCode {
public static final int CONSTANT_NOT_FOUND_1 = 90115; public static final int CONSTANT_NOT_FOUND_1 = 90115;
public static final int LITERALS_ARE_NOT_ALLOWED = 90116; public static final int LITERALS_ARE_NOT_ALLOWED = 90116;
private int importantTodo; /**
* The error with code <code>90117</code> is thrown when
* trying to connect to a TCP server from another machine, if remote
* connections are not allowed. To allow remote connections,
* start the TCP server using the option -tcpAllowOthers true as in:
* <pre>
* java org.h2.tools.Server -tcp -tcpAllowOthers true
* </pre>
* Or, when starting the server from an application, use:
* <pre>
* Server server = Server.createTcpServer(new String[] { "-tcpAllowOthers", "true" });
server.start();
* </pre>
*/
public static final int REMOTE_CONNECTION_NOT_ALLOWED = 90117; public static final int REMOTE_CONNECTION_NOT_ALLOWED = 90117;
/** /**
...@@ -1131,6 +1189,22 @@ public class ErrorCode { ...@@ -1131,6 +1189,22 @@ public class ErrorCode {
public static final int RESULT_SET_NOT_UPDATABLE = 90127; public static final int RESULT_SET_NOT_UPDATABLE = 90127;
public static final int RESULT_SET_NOT_SCROLLABLE = 90128; public static final int RESULT_SET_NOT_SCROLLABLE = 90128;
public static final int TRANSACTION_NOT_FOUND_1 = 90129; public static final int TRANSACTION_NOT_FOUND_1 = 90129;
/**
* The error with code <code>90130</code> is thrown when
* an execute method of PreparedStatement was called with a SQL statement.
* This is not allowed according to the JDBC specification. Instead, use
* an execute method of Statement. Example:
* <pre>
* PreparedStatement prep = conn.prepareStatement("SELECT * FROM TEST");
* prep.execute("DELETE FROM TEST");
* </pre>
* Correct:
* <pre>
* Statement stat = conn.createStatement();
* stat.execute("DELETE FROM TEST");
* </pre>
*/
public static final int METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT = 90130; public static final int METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT = 90130;
public static final int CONCURRENT_UPDATE_1 = 90131; public static final int CONCURRENT_UPDATE_1 = 90131;
public static final int AGGREGATE_NOT_FOUND_1 = 90132; public static final int AGGREGATE_NOT_FOUND_1 = 90132;
......
...@@ -323,6 +323,12 @@ private int test; ...@@ -323,6 +323,12 @@ private int test;
*/ */
public static final boolean TRACE_IO = getBooleanSetting("h2.traceIO", false); public static final boolean TRACE_IO = getBooleanSetting("h2.traceIO", false);
/**
* System property <code>h2.largeResultBufferSize</code> (default: 4096).<br />
* Buffer size for large result sets. Set this value to 0 to disable the buffer.
*/
public static final int LARGE_RESULT_BUFFER_SIZE = getIntSetting("h2.largeResultBufferSize", 4 * 1024);
private static String baseDir = getStringSetting("h2.baseDir", null); private static String baseDir = getStringSetting("h2.baseDir", null);
private static boolean getBooleanSetting(String name, boolean defaultValue) { private static boolean getBooleanSetting(String name, boolean defaultValue) {
......
...@@ -113,7 +113,9 @@ public class ConnectionInfo { ...@@ -113,7 +113,9 @@ public class ConnectionInfo {
public void setBaseDir(String dir) { public void setBaseDir(String dir) {
if (persistent) { if (persistent) {
name = dir + SysProperties.FILE_SEPARATOR + name; if (!name.startsWith("~")) {
name = dir + SysProperties.FILE_SEPARATOR + name;
}
} }
} }
......
...@@ -1352,6 +1352,8 @@ public class Database implements DataHandler { ...@@ -1352,6 +1352,8 @@ public class Database implements DataHandler {
return ClassUtils.loadUserClass(className); return ClassUtils.loadUserClass(className);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
throw Message.getSQLException(ErrorCode.CLASS_NOT_FOUND_1, new String[] { className }, e); throw Message.getSQLException(ErrorCode.CLASS_NOT_FOUND_1, new String[] { className }, e);
} catch (NoClassDefFoundError e) {
throw Message.getSQLException(ErrorCode.CLASS_NOT_FOUND_1, new String[] { className }, e);
} }
} }
......
...@@ -173,6 +173,16 @@ public class BtreeIndex extends BaseIndex implements RecordReader { ...@@ -173,6 +173,16 @@ public class BtreeIndex extends BaseIndex implements RecordReader {
rowCount++; rowCount++;
} }
SearchRow getSearchRow(Row row) {
SearchRow r = table.getTemplateSimpleRow(columns.length == 1);
r.setPos(row.getPos());
for (int j = 0; j < columns.length; j++) {
int idx = columns[j].getColumnId();
r.setValue(idx, row.getValue(idx));
}
return r;
}
public void remove(Session session, Row row) throws SQLException { public void remove(Session session, Row row) throws SQLException {
setChanged(session); setChanged(session);
if (rowCount == 1) { if (rowCount == 1) {
......
...@@ -75,7 +75,9 @@ public class BtreeLeaf extends BtreePage { ...@@ -75,7 +75,9 @@ public class BtreeLeaf extends BtreePage {
} }
index.deletePage(session, this); index.deletePage(session, this);
int at = l; int at = l;
pageData.add(at, newRow); // safe memory
SearchRow row = index.getSearchRow(newRow);
pageData.add(at, row);
updateRealByteCount(true, newRow); updateRealByteCount(true, newRow);
int splitPoint = getSplitPoint(); int splitPoint = getSplitPoint();
if (splitPoint == 0) { if (splitPoint == 0) {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
*/ */
package org.h2.result; package org.h2.result;
import java.io.ByteArrayOutputStream;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
...@@ -62,6 +63,9 @@ class ResultDiskBuffer { ...@@ -62,6 +63,9 @@ class ResultDiskBuffer {
} }
DataPage buff = rowBuff; DataPage buff = rowBuff;
long start = file.getFilePointer(); long start = file.getFilePointer();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int bufferLen = 0;
int maxBufferSize = SysProperties.LARGE_RESULT_BUFFER_SIZE;
for (int i = 0; i < rows.size(); i++) { for (int i = 0; i < rows.size(); i++) {
buff.reset(); buff.reset();
buff.writeInt(0); buff.writeInt(0);
...@@ -73,7 +77,22 @@ class ResultDiskBuffer { ...@@ -73,7 +77,22 @@ class ResultDiskBuffer {
int len = buff.length(); int len = buff.length();
buff.setInt(0, len); buff.setInt(0, len);
buff.updateChecksum(); buff.updateChecksum();
file.write(buff.getBytes(), 0, len); if (maxBufferSize > 0) {
buffer.write(buff.getBytes(), 0, len);
bufferLen += len;
if (bufferLen > maxBufferSize) {
byte[] data = buffer.toByteArray();
buffer.reset();
file.write(data, 0, data.length);
bufferLen = 0;
}
} else {
file.write(buff.getBytes(), 0, len);
}
}
if (bufferLen > 0) {
byte[] data = buffer.toByteArray();
file.write(data, 0, data.length);
} }
if (sort != null) { if (sort != null) {
ResultDiskTape tape = new ResultDiskTape(); ResultDiskTape tape = new ResultDiskTape();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论