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

--no commit message

--no commit message
上级 5dd5c94a
差异被折叠。
差异被折叠。
......@@ -3350,16 +3350,14 @@ public class Parser {
command.setSequenceName(sequenceName);
if (readIf("START")) {
readIf("WITH");
long start = readLong();
command.setStartWith(start);
command.setStartWith(readExpression());
}
if (readIf("INCREMENT")) {
readIf("BY");
long increment = readLong();
command.setIncrement(increment);
command.setIncrement(readExpression());
}
if (readIf("CACHE")) {
command.setCacheSize(readLong());
command.setCacheSize(readExpression());
}
if (readIf("BELONGS_TO_TABLE")) {
command.setBelongsToTable(true);
......@@ -3632,13 +3630,11 @@ public class Parser {
command.setSequence(getSchema().getSequence(sequenceName));
if (readIf("RESTART")) {
read("WITH");
long start = readLong();
command.setStartWith(start);
command.setStartWith(readExpression());
}
if (readIf("INCREMENT")) {
read("BY");
long increment = readLong();
command.setIncrement(increment);
command.setIncrement(readExpression());
}
return command;
}
......@@ -4106,7 +4102,7 @@ public class Parser {
}
} else if (readIf("RESTART")) {
readIf("WITH");
long start = readLong();
Expression start = readExpression();
AlterTableAlterColumn command = new AlterTableAlterColumn(session, table.getSchema());
command.setTable(table);
command.setType(AlterTableAlterColumn.RESTART);
......@@ -4114,12 +4110,11 @@ public class Parser {
command.setStartWith(start);
return command;
} else if (readIf("SELECTIVITY")) {
int selectivity = getPositiveInt();
AlterTableAlterColumn command = new AlterTableAlterColumn(session, table.getSchema());
command.setTable(table);
command.setType(AlterTableAlterColumn.SELECTIVITY);
command.setOldColumn(column);
command.setStartWith(selectivity);
command.setStartWith(readExpression());
return command;
} else {
Column newColumn = parseColumnForTable(columnName);
......
......@@ -9,6 +9,7 @@ import java.sql.SQLException;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.expression.Expression;
import org.h2.message.Message;
import org.h2.schema.Sequence;
......@@ -19,10 +20,8 @@ import org.h2.schema.Sequence;
public class AlterSequence extends DefineCommand {
private Sequence sequence;
private boolean newStart;
private long start;
private boolean newIncrement;
private long increment;
private Expression start;
private Expression increment;
public AlterSequence(Session session) {
super(session);
......@@ -32,16 +31,11 @@ public class AlterSequence extends DefineCommand {
this.sequence = sequence;
}
public void setStartWith(long start) {
newStart = true;
public void setStartWith(Expression start) {
this.start = start;
}
public void setIncrement(long increment) throws SQLException {
newIncrement = true;
if (increment == 0) {
throw Message.getSQLException(ErrorCode.INVALID_VALUE_2, new String[] { "0", "INCREMENT" });
}
public void setIncrement(Expression increment) throws SQLException {
this.increment = increment;
}
......@@ -49,11 +43,16 @@ public class AlterSequence extends DefineCommand {
// TODO rights: what are the rights required for a sequence?
session.commit(true);
Database db = session.getDatabase();
if (newStart) {
sequence.setStartValue(start);
if (start != null) {
long startValue = start.optimize(session).getValue(session).getLong();
sequence.setStartValue(startValue);
}
if (newIncrement) {
sequence.setIncrement(increment);
if (increment != null) {
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);
return 0;
......
......@@ -47,7 +47,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
private Column newColumn;
private int type;
private Expression defaultExpression;
private long newStart;
private Expression newStart;
private String addBefore;
public AlterTableAlterColumn(Session session, Schema schema) {
......@@ -105,7 +105,8 @@ public class AlterTableAlterColumn extends SchemaCommand {
if (sequence == null) {
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);
break;
}
......@@ -143,7 +144,8 @@ public class AlterTableAlterColumn extends SchemaCommand {
break;
}
case SELECTIVITY: {
oldColumn.setSelectivity((int) newStart);
int value = newStart.optimize(session).getValue(session).getInt();
oldColumn.setSelectivity(value);
db.update(session, table);
break;
}
......@@ -400,7 +402,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
this.type = type;
}
public void setStartWith(long start) {
public void setStartWith(Expression start) {
newStart = start;
}
......
......@@ -9,6 +9,7 @@ import java.sql.SQLException;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.expression.Expression;
import org.h2.message.Message;
import org.h2.schema.Schema;
import org.h2.schema.Sequence;
......@@ -21,9 +22,9 @@ public class CreateSequence extends SchemaCommand {
private String sequenceName;
private boolean ifNotExists;
private long start = 1;
private long increment = 1;
private long cacheSize = Sequence.DEFAULT_CACHE_SIZE;
private Expression start;
private Expression increment;
private Expression cacheSize;
private boolean belongsToTable;
public CreateSequence(Session session, Schema schema) {
......@@ -49,18 +50,26 @@ public class CreateSequence extends SchemaCommand {
}
int id = getObjectId(false, true);
Sequence sequence = new Sequence(getSchema(), id, sequenceName, belongsToTable);
sequence.setStartValue(start);
sequence.setIncrement(increment);
sequence.setCacheSize(cacheSize);
sequence.setStartValue(getLong(start, 1));
sequence.setIncrement(getLong(increment, 1));
sequence.setCacheSize(getLong(cacheSize, Sequence.DEFAULT_CACHE_SIZE));
db.addSchemaObject(session, sequence);
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;
}
public void setIncrement(long increment) {
public void setIncrement(Expression increment) {
this.increment = increment;
}
......@@ -68,7 +77,7 @@ public class CreateSequence extends SchemaCommand {
this.belongsToTable = belongsToTable;
}
public void setCacheSize(long cacheSize) {
public void setCacheSize(Expression cacheSize) {
this.cacheSize = cacheSize;
}
......
......@@ -4,7 +4,6 @@
*/
package org.h2.constant;
/**
* This class defines the error codes used for SQL exceptions.
*/
......@@ -272,7 +271,8 @@ public class ErrorCode {
/**
* 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;
......@@ -744,10 +744,37 @@ public class ErrorCode {
*/
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;
/**
* 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;
/**
* 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;
/**
......@@ -766,6 +793,12 @@ public class ErrorCode {
* trying to connect to a TCP server with an incompatible client.
*/
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;
/**
......@@ -850,7 +883,19 @@ public class ErrorCode {
* </pre>
*/
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;
private int todo;
public static final int NO_DEFAULT_SET_1 = 90056;
/**
......@@ -1090,7 +1135,20 @@ public class ErrorCode {
public static final int CONSTANT_NOT_FOUND_1 = 90115;
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;
/**
......@@ -1131,6 +1189,22 @@ public class ErrorCode {
public static final int RESULT_SET_NOT_UPDATABLE = 90127;
public static final int RESULT_SET_NOT_SCROLLABLE = 90128;
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 CONCURRENT_UPDATE_1 = 90131;
public static final int AGGREGATE_NOT_FOUND_1 = 90132;
......
......@@ -323,6 +323,12 @@ private int test;
*/
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 boolean getBooleanSetting(String name, boolean defaultValue) {
......
......@@ -113,7 +113,9 @@ public class ConnectionInfo {
public void setBaseDir(String dir) {
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 {
return ClassUtils.loadUserClass(className);
} catch (ClassNotFoundException 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 {
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 {
setChanged(session);
if (rowCount == 1) {
......
......@@ -75,7 +75,9 @@ public class BtreeLeaf extends BtreePage {
}
index.deletePage(session, this);
int at = l;
pageData.add(at, newRow);
// safe memory
SearchRow row = index.getSearchRow(newRow);
pageData.add(at, row);
updateRealByteCount(true, newRow);
int splitPoint = getSplitPoint();
if (splitPoint == 0) {
......
......@@ -4,6 +4,7 @@
*/
package org.h2.result;
import java.io.ByteArrayOutputStream;
import java.sql.SQLException;
import org.h2.constant.SysProperties;
......@@ -62,6 +63,9 @@ class ResultDiskBuffer {
}
DataPage buff = rowBuff;
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++) {
buff.reset();
buff.writeInt(0);
......@@ -73,7 +77,22 @@ class ResultDiskBuffer {
int len = buff.length();
buff.setInt(0, len);
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) {
ResultDiskTape tape = new ResultDiskTape();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论