提交 bbf4df6f authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Pass Mode to convert() methods in all DML commands

上级 6092aecf
...@@ -14,6 +14,7 @@ import org.h2.command.Command; ...@@ -14,6 +14,7 @@ import org.h2.command.Command;
import org.h2.command.CommandInterface; import org.h2.command.CommandInterface;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.engine.GeneratedKeys; import org.h2.engine.GeneratedKeys;
import org.h2.engine.Mode;
import org.h2.engine.Right; import org.h2.engine.Right;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.engine.UndoLogRecord; import org.h2.engine.UndoLogRecord;
...@@ -151,6 +152,7 @@ public class Insert extends Prepared implements ResultTarget { ...@@ -151,6 +152,7 @@ public class Insert extends Prepared implements ResultTarget {
generatedKeys.initialize(table); generatedKeys.initialize(table);
int listSize = list.size(); int listSize = list.size();
if (listSize > 0) { if (listSize > 0) {
Mode mode = session.getDatabase().getMode();
int columnLen = columns.length; int columnLen = columns.length;
for (int x = 0; x < listSize; x++) { for (int x = 0; x < listSize; x++) {
session.startStatementWithinTransaction(); session.startStatementWithinTransaction();
...@@ -166,7 +168,7 @@ public class Insert extends Prepared implements ResultTarget { ...@@ -166,7 +168,7 @@ public class Insert extends Prepared implements ResultTarget {
// e can be null (DEFAULT) // e can be null (DEFAULT)
e = e.optimize(session); e = e.optimize(session);
try { try {
Value v = c.convert(e.getValue(session), session.getDatabase().getMode()); Value v = c.convert(e.getValue(session), mode);
newRow.setValue(index, v); newRow.setValue(index, v);
if (e instanceof SequenceValue) { if (e instanceof SequenceValue) {
generatedKeys.add(c); generatedKeys.add(c);
...@@ -239,11 +241,12 @@ public class Insert extends Prepared implements ResultTarget { ...@@ -239,11 +241,12 @@ public class Insert extends Prepared implements ResultTarget {
private Row addRowImpl(Value[] values) { private Row addRowImpl(Value[] values) {
Row newRow = table.getTemplateRow(); Row newRow = table.getTemplateRow();
setCurrentRowNumber(++rowNumber); setCurrentRowNumber(++rowNumber);
Mode mode = session.getDatabase().getMode();
for (int j = 0, len = columns.length; j < len; j++) { for (int j = 0, len = columns.length; j < len; j++) {
Column c = columns[j]; Column c = columns[j];
int index = c.getColumnId(); int index = c.getColumnId();
try { try {
Value v = c.convert(values[j], session.getDatabase().getMode()); Value v = c.convert(values[j], mode);
newRow.setValue(index, v); newRow.setValue(index, v);
} catch (DbException ex) { } catch (DbException ex) {
throw setRow(ex, rowNumber, getSQL(values)); throw setRow(ex, rowNumber, getSQL(values));
......
...@@ -13,6 +13,7 @@ import org.h2.command.Command; ...@@ -13,6 +13,7 @@ import org.h2.command.Command;
import org.h2.command.CommandInterface; import org.h2.command.CommandInterface;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.engine.GeneratedKeys; import org.h2.engine.GeneratedKeys;
import org.h2.engine.Mode;
import org.h2.engine.Right; import org.h2.engine.Right;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.engine.UndoLogRecord; import org.h2.engine.UndoLogRecord;
...@@ -88,6 +89,7 @@ public class Merge extends Prepared { ...@@ -88,6 +89,7 @@ public class Merge extends Prepared {
session.getUser().checkRight(targetTable, Right.UPDATE); session.getUser().checkRight(targetTable, Right.UPDATE);
setCurrentRowNumber(0); setCurrentRowNumber(0);
GeneratedKeys generatedKeys = session.getGeneratedKeys(); GeneratedKeys generatedKeys = session.getGeneratedKeys();
Mode mode = session.getDatabase().getMode();
if (!valuesExpressionList.isEmpty()) { if (!valuesExpressionList.isEmpty()) {
// process values in list // process values in list
count = 0; count = 0;
...@@ -104,7 +106,7 @@ public class Merge extends Prepared { ...@@ -104,7 +106,7 @@ public class Merge extends Prepared {
if (e != null) { if (e != null) {
// e can be null (DEFAULT) // e can be null (DEFAULT)
try { try {
Value v = c.convert(e.getValue(session)); Value v = c.convert(e.getValue(session), mode);
newRow.setValue(index, v); newRow.setValue(index, v);
if (e instanceof SequenceValue) { if (e instanceof SequenceValue) {
generatedKeys.add(c); generatedKeys.add(c);
...@@ -134,7 +136,7 @@ public class Merge extends Prepared { ...@@ -134,7 +136,7 @@ public class Merge extends Prepared {
Column c = columns[j]; Column c = columns[j];
int index = c.getColumnId(); int index = c.getColumnId();
try { try {
Value v = c.convert(r[j]); Value v = c.convert(r[j], mode);
newRow.setValue(index, v); newRow.setValue(index, v);
} catch (DbException ex) { } catch (DbException ex) {
throw setRow(ex, count, getSQL(r)); throw setRow(ex, count, getSQL(r));
......
...@@ -12,6 +12,7 @@ import org.h2.api.Trigger; ...@@ -12,6 +12,7 @@ import org.h2.api.Trigger;
import org.h2.command.Command; import org.h2.command.Command;
import org.h2.command.CommandInterface; import org.h2.command.CommandInterface;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.engine.Mode;
import org.h2.engine.Right; import org.h2.engine.Right;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.engine.UndoLogRecord; import org.h2.engine.UndoLogRecord;
...@@ -82,6 +83,7 @@ public class Replace extends Prepared { ...@@ -82,6 +83,7 @@ public class Replace extends Prepared {
session.getUser().checkRight(table, Right.INSERT); session.getUser().checkRight(table, Right.INSERT);
session.getUser().checkRight(table, Right.UPDATE); session.getUser().checkRight(table, Right.UPDATE);
setCurrentRowNumber(0); setCurrentRowNumber(0);
Mode mode = session.getDatabase().getMode();
if (!list.isEmpty()) { if (!list.isEmpty()) {
count = 0; count = 0;
for (int x = 0, size = list.size(); x < size; x++) { for (int x = 0, size = list.size(); x < size; x++) {
...@@ -95,7 +97,7 @@ public class Replace extends Prepared { ...@@ -95,7 +97,7 @@ public class Replace extends Prepared {
if (e != null) { if (e != null) {
// e can be null (DEFAULT) // e can be null (DEFAULT)
try { try {
Value v = c.convert(e.getValue(session)); Value v = c.convert(e.getValue(session), mode);
newRow.setValue(index, v); newRow.setValue(index, v);
} catch (DbException ex) { } catch (DbException ex) {
throw setRow(ex, count, getSQL(expr)); throw setRow(ex, count, getSQL(expr));
...@@ -119,7 +121,7 @@ public class Replace extends Prepared { ...@@ -119,7 +121,7 @@ public class Replace extends Prepared {
Column c = columns[j]; Column c = columns[j];
int index = c.getColumnId(); int index = c.getColumnId();
try { try {
Value v = c.convert(r[j]); Value v = c.convert(r[j], mode);
newRow.setValue(index, v); newRow.setValue(index, v);
} catch (DbException ex) { } catch (DbException ex) {
throw setRow(ex, count, getSQL(r)); throw setRow(ex, count, getSQL(r));
......
...@@ -131,7 +131,7 @@ public class Update extends Prepared { ...@@ -131,7 +131,7 @@ public class Update extends Prepared {
} else if (newExpr == ValueExpression.getDefault()) { } else if (newExpr == ValueExpression.getDefault()) {
newValue = table.getDefaultValue(session, column); newValue = table.getDefaultValue(session, column);
} else { } else {
newValue = column.convert(newExpr.getValue(session)); newValue = column.convert(newExpr.getValue(session), session.getDatabase().getMode());
} }
newRow.setValue(i, newValue); newRow.setValue(i, newValue);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论