提交 49ec7d34 authored 作者: Thomas Mueller's avatar Thomas Mueller

The pseudo-column "_ROWID_" now supports insert, update, and merge (only enabled…

The pseudo-column "_ROWID_" now supports insert, update, and merge (only enabled for version 1.3.x).
上级 eded0362
......@@ -10,6 +10,7 @@ import org.h2.engine.Constants;
import org.h2.store.Data;
import org.h2.util.StatementBuilder;
import org.h2.value.Value;
import org.h2.value.ValueLong;
/**
* Represents a row in a table.
......@@ -69,7 +70,7 @@ public class Row implements SearchRow {
}
public Value getValue(int i) {
return data[i];
return i == -1 ? ValueLong.get(key) : data[i];
}
/**
......@@ -87,8 +88,12 @@ public class Row implements SearchRow {
}
public void setValue(int i, Value v) {
if (i == -1) {
this.key = v.getLong();
} else {
data[i] = v;
}
}
public boolean isEmpty() {
return data == null;
......
......@@ -225,8 +225,4 @@ public class FunctionTable extends Table {
return false;
}
public boolean hasRowIdColumn() {
return false;
}
}
......@@ -1794,8 +1794,4 @@ public class MetaTable extends Table {
return false;
}
public boolean hasRowIdColumn() {
return false;
}
}
......@@ -173,8 +173,4 @@ public class RangeTable extends Table {
return false;
}
public boolean hasRowIdColumn() {
return false;
}
}
......@@ -62,6 +62,7 @@ public class RegularTable extends TableBase {
private PageDataIndex mainIndex;
private int changesSinceAnalyze;
private int nextAnalyze;
private Column rowIdColumn;
/**
* True if one thread ever was waiting to lock this table. This is to avoid
......@@ -728,8 +729,12 @@ public class RegularTable extends TableBase {
return true;
}
public boolean hasRowIdColumn() {
return true;
public Column getRowIdColumn() {
if (rowIdColumn == null) {
rowIdColumn = new Column(Column.ROWID, Value.LONG);
rowIdColumn.setTable(this, -1);
}
return rowIdColumn;
}
}
......@@ -277,13 +277,6 @@ public abstract class Table extends SchemaObjectBase {
*/
public abstract boolean canDrop();
/**
* Check if this table has a row id column.
*
* @return true if it has
*/
public abstract boolean hasRowIdColumn();
/**
* Get the row count for this table.
*
......@@ -299,6 +292,15 @@ public abstract class Table extends SchemaObjectBase {
*/
public abstract long getRowCountApproximation();
/**
* Get the row id column if this table has one.
*
* @return the row id column, or null
*/
public Column getRowIdColumn() {
return null;
}
public String getCreateSQLForCopy(Table table, String quotedName) {
throw DbException.throwInternalError();
}
......
......@@ -835,10 +835,8 @@ public class TableFilter implements ColumnResolver {
}
public Column getRowIdColumn() {
if (table.hasRowIdColumn() && session.getDatabase().getSettings().rowId) {
Column col = new Column(Column.ROWID, Value.LONG);
col.setTable(table, -1);
return col;
if (session.getDatabase().getSettings().rowId) {
return table.getRowIdColumn();
}
return null;
}
......
......@@ -610,8 +610,4 @@ public class TableLink extends Table {
return null;
}
public boolean hasRowIdColumn() {
return false;
}
}
......@@ -408,8 +408,4 @@ public class TableView extends Table {
return tableExpression;
}
public boolean hasRowIdColumn() {
return false;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论