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

Support INSERT INTO TEST SET ID = 1, NAME = 'World' (MySQL compatibility).

上级 769aafc5
......@@ -42,8 +42,10 @@ SELECT * FROM (SELECT ID, COUNT(*) FROM TEST
"
"Commands (DML)","INSERT","
INSERT INTO tableName [ ( columnName [,...] ) ]
{ VALUES { ( { DEFAULT | expression } [,...] ) } [,...] | [ DIRECT ] [ SORTED ] select }
INSERT INTO tableName
{ [ ( columnName [,...] ) ]
{ VALUES { ( { DEFAULT | expression } [,...] ) } [,...] | [ DIRECT ] [ SORTED ] select } } |
{ SET { columnName = { DEFAULT | expression } } [,...] }
","
Inserts a new row / new rows into a table.
......@@ -56,7 +58,7 @@ INSERT INTO TEST VALUES(1, 'Hello')
"Commands (DML)","UPDATE","
UPDATE tableName [ [ AS ] newTableAlias ]
SET { columnName= { DEFAULT | expression } } [,...]
SET { columnName = { DEFAULT | expression } } [,...]
[ WHERE expression ]
","
Updates data in a table.
......
......@@ -18,8 +18,9 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>Issue 304: The condition [NOT] IN (SELECT ...) could throw the exception "Unexpected code path" if the subquery contained ORDER BY.
</li><li>ALTER TABLE ALTER ADD / REMOVE /ALTER COLUMN dropped some dependent objects
<ul><li>Support INSERT INTO TEST SET ID = 1, NAME = 'World' (MySQL compatibility).
</li><li>Issue 304: The condition [NOT] IN (SELECT ...) could throw the exception "Unexpected code path" if the subquery contained ORDER BY.
</li><li>ALTER TABLE ALTER ADD / REMOVE /ALTER COLUMN dropped some dependent objects
(access rights, triggers) of views that depend on the modified table.
</li><li>CREATE OR REPLACE VIEW dropped some dependent objects (access rights, triggers)
if the view already existed before.
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -769,13 +769,7 @@ public class Parser {
HashSet<Column> set = New.hashSet();
if (!readIf(")")) {
do {
String id = readColumnIdentifier();
Column column;
if (database.getSettings().rowId && Column.ROWID.equals(id)) {
column = table.getRowIdColumn();
} else {
column = table.getColumn(id);
}
Column column = parseColumn(table);
if (!set.add(column)) {
throw DbException.get(ErrorCode.DUPLICATE_COLUMN_NAME_1, column.getSQL());
}
......@@ -785,6 +779,14 @@ public class Parser {
return columns.toArray(new Column[columns.size()]);
}
private Column parseColumn(Table table) {
String id = readColumnIdentifier();
if (database.getSettings().rowId && Column.ROWID.equals(id)) {
return table.getRowIdColumn();
}
return table.getColumn(id);
}
private boolean readIfMore() {
if (readIf(",")) {
return !readIf(")");
......@@ -940,13 +942,14 @@ public class Parser {
read("INTO");
Table table = readTableOrView();
command.setTable(table);
Column[] columns = null;
if (readIf("(")) {
if (isSelect()) {
command.setQuery(parseSelect());
read(")");
return command;
}
Column[] columns = parseColumnList(table);
columns = parseColumnList(table);
command.setColumns(columns);
}
if (readIf("DIRECT")) {
......@@ -975,6 +978,25 @@ public class Parser {
command.addRow(values.toArray(new Expression[values.size()]));
// the following condition will allow (..),; and (..);
} while (readIf(",") && readIf("("));
} else if (readIf("SET")) {
if (columns != null) {
throw getSyntaxError();
}
ArrayList<Column> columnList = New.arrayList();
ArrayList<Expression> values = New.arrayList();
do {
columnList.add(parseColumn(table));
read("=");
Expression expression;
if (readIf("DEFAULT")) {
expression = ValueExpression.getDefault();
} else {
expression = readExpression();
}
values.add(expression);
} while (readIf(","));
command.setColumns(columnList.toArray(new Column[columnList.size()]));
command.addRow(values.toArray(new Expression[values.size()]));
} else {
command.setQuery(parseSelect());
}
......@@ -2126,7 +2148,7 @@ public class Parser {
case Function.CAST: {
function.setParameter(0, readExpression());
read("AS");
Column type = parseColumn(null);
Column type = parseColumnWithType(null);
function.setDataType(type);
read(")");
break;
......@@ -2134,7 +2156,7 @@ public class Parser {
case Function.CONVERT: {
function.setParameter(0, readExpression());
read(",");
Column type = parseColumn(null);
Column type = parseColumnWithType(null);
function.setDataType(type);
read(")");
break;
......@@ -2223,7 +2245,7 @@ public class Parser {
ArrayList<Column> columns = New.arrayList();
do {
String columnName = readAliasIdentifier();
Column column = parseColumn(columnName);
Column column = parseColumnWithType(columnName);
columns.add(column);
read("=");
function.setParameter(i, readExpression());
......@@ -2584,7 +2606,7 @@ public class Parser {
JavaFunction func = new JavaFunction(f, args);
r = func;
} else {
Column col = parseColumn(null);
Column col = parseColumnWithType(null);
Function function = Function.getFunction(database, "CAST");
function.setDataType(col);
function.setParameter(0, r);
......@@ -3451,7 +3473,7 @@ public class Parser {
parseAutoIncrement(column);
column.setPrimaryKey(true);
} else {
column = parseColumn(columnName);
column = parseColumnWithType(columnName);
}
if (readIf("NOT")) {
read("NULL");
......@@ -3549,7 +3571,7 @@ public class Parser {
return null;
}
private Column parseColumn(String columnName) {
private Column parseColumnWithType(String columnName) {
String original = currentToken;
boolean regular = false;
if (readIf("LONG")) {
......
......@@ -13,13 +13,15 @@ FROM tableExpression [,...] [ WHERE expression ]
","
Selects data from a table or multiple tables."
"Commands (DML)","INSERT","
INSERT INTO tableName [ ( columnName [,...] ) ]
{ VALUES { ( { DEFAULT | expression } [,...] ) } [,...] | [ DIRECT ] [ SORTED ] select }
INSERT INTO tableName
{ [ ( columnName [,...] ) ]
{ VALUES { ( { DEFAULT | expression } [,...] ) } [,...] | [ DIRECT ] [ SORTED ] select } } |
{ SET { columnName = { DEFAULT | expression } } [,...] }
","
Inserts a new row / new rows into a table."
"Commands (DML)","UPDATE","
UPDATE tableName [ [ AS ] newTableAlias ]
SET { columnName= { DEFAULT | expression } } [,...]
SET { columnName = { DEFAULT | expression } } [,...]
[ WHERE expression ]
","
Updates data in a table."
......
......@@ -104,7 +104,8 @@ public class TableView extends Table {
*
* @param session the session
* @param force if exceptions should be ignored
* @return the exception if re-compiling this or any dependent view failed (only when force is disabled)
* @return the exception if re-compiling this or any dependent view failed
* (only when force is disabled)
*/
public DbException recompile(Session session, boolean force) {
try {
......
......@@ -1928,13 +1928,13 @@ drop table d;
create table test(id int, c char(5), v varchar(5));
> ok
insert into test values(1, 'a', 'a');
insert into test set id = 1, c = 'a', v = 'a';
> update count: 1
insert into test values(2, 'a ', 'a ');
insert into test set id = 2, c = 'a ', v = 'a ';
> update count: 1
insert into test values(3, 'abcde ', 'abcde');
insert into test set id = 3, c = 'abcde ', v = 'abcde';
> update count: 1
select distinct length(c) from test order by length(c);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论