Skip to content

Commit ab868a6

Browse files
committed
fixes #540,#526
1 parent 1a1a1aa commit ab868a6

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

nb-configuration.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
Any value defined here will override the pom.xml file value but is only applicable to the current project.
1515
-->
1616
<netbeans.compile.on.save>none</netbeans.compile.on.save>
17-
<com-junichi11-netbeans-changelf.enable>true</com-junichi11-netbeans-changelf.enable>
17+
<com-junichi11-netbeans-changelf.enable>false</com-junichi11-netbeans-changelf.enable>
1818
<com-junichi11-netbeans-changelf.use-project>true</com-junichi11-netbeans-changelf.use-project>
1919
<com-junichi11-netbeans-changelf.lf-kind>LF</com-junichi11-netbeans-changelf.lf-kind>
2020
<com-junichi11-netbeans-changelf.use-global>false</com-junichi11-netbeans-changelf.use-global>

src/main/java/net/sf/jsqlparser/util/deparser/InsertDeParser.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public InsertDeParser() {
5252
* @param expressionVisitor a {@link ExpressionVisitor} to de-parse
5353
* {@link net.sf.jsqlparser.expression.Expression}s. It has to share the same<br>
5454
* StringBuilder (buffer parameter) as this object in order to work
55-
* @param selectVisitor a {@link SelectVisitor} to de-parse
56-
* {@link net.sf.jsqlparser.statement.select.Select}s. It has to share the same<br>
55+
* @param selectVisitor a {@link SelectVisitor} to de-parse {@link net.sf.jsqlparser.statement.select.Select}s. It
56+
* has to share the same<br>
5757
* StringBuilder (buffer parameter) as this object in order to work
5858
* @param buffer the buffer that will be filled with the insert
5959
*/
@@ -81,7 +81,8 @@ public void deParse(Insert insert) {
8181
}
8282
buffer.append("INTO ");
8383

84-
buffer.append(insert.getTable().getFullyQualifiedName());
84+
buffer.append(insert.getTable().toString());
85+
8586
if (insert.getColumns() != null) {
8687
buffer.append(" (");
8788
for (Iterator<Column> iter = insert.getColumns().iterator(); iter.hasNext();) {
@@ -115,7 +116,7 @@ public void deParse(Insert insert) {
115116
buffer.append(")");
116117
}
117118
}
118-
119+
119120
if (insert.isUseSet()) {
120121
buffer.append(" SET ");
121122
for (int i = 0; i < insert.getSetColumns().size(); i++) {

src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,8 @@ Insert Insert():
625625
boolean useSet = false;
626626
List<Column> setColumns = new ArrayList<Column>();
627627
List<Expression> setExpressionList = new ArrayList<Expression>();
628+
String name = null;
629+
boolean useAs = false;
628630
}
629631
{
630632
<K_INSERT>
@@ -634,7 +636,8 @@ Insert Insert():
634636
}]
635637
[<K_IGNORE>{ modifierIgnore = true; }]
636638
[<K_INTO>] table=Table()
637-
639+
640+
[ [<K_AS> { useAs = true; } ] name=RelObjectNameWithoutValue() { table.setAlias(new Alias(name,useAs)); }]
638641

639642
[LOOKAHEAD(2) "(" tableColumn=Column() { columns.add(tableColumn); } ("," tableColumn=Column() { columns.add(tableColumn); } )* ")" ]
640643
(
@@ -940,15 +943,18 @@ Column Column() #Column :
940943
}
941944
}
942945

943-
String RelObjectName() :
946+
/*
947+
Not all names should be allowed for aliases.
948+
*/
949+
String RelObjectNameWithoutValue() :
944950
{ Token tk = null; }
945951
{
946952
(tk=<S_IDENTIFIER> | tk=<S_QUOTED_IDENTIFIER>
947953
| tk=<K_CAST> | tk=<K_DO> | tk=<K_EXTRACT> | tk=<K_FIRST> | tk=<K_FOLLOWING>
948954
| tk=<K_LAST> | tk=<K_MATERIALIZED> | tk=<K_NULLS> | tk=<K_PARTITION> | tk=<K_RANGE>
949-
| tk=<K_ROW> | tk=<K_ROWS> | tk=<K_SIBLINGS> | tk=<K_VALUE> | tk=<K_XML>
955+
| tk=<K_ROW> | tk=<K_ROWS> | tk=<K_SIBLINGS> | tk=<K_XML>
950956
| tk=<K_COLUMN> | tk=<K_REPLACE> | tk=<K_TRUNCATE> | tk=<K_KEY> | tk=<K_ANY>
951-
| tk=<K_OPEN> | tk=<K_OVER> | tk=<K_VALUES> | tk=<K_PERCENT> | tk=<K_PRIOR>
957+
| tk=<K_OPEN> | tk=<K_OVER> | tk=<K_PERCENT> | tk=<K_PRIOR>
952958
| tk=<K_SEPARATOR> | tk=<K_NO> | tk=<K_ACTION> | tk=<K_CASCADE> | tk=<K_END>
953959
| tk=<K_TABLE> | tk=<K_DATETIMELITERAL> | tk=<K_COMMIT> | tk=<K_PRECISION>
954960
| tk=<K_INSERT>
@@ -958,7 +964,21 @@ String RelObjectName() :
958964
}
959965

960966
/*
961-
Extended usage of object names.
967+
Normal names.
968+
*/
969+
String RelObjectName() :
970+
{ Token tk = null; String result = null; }
971+
{
972+
(result = RelObjectNameWithoutValue() | tk=<K_VALUE> | tk=<K_VALUES>)
973+
974+
{
975+
if (tk!=null) result=tk.image;
976+
return result;
977+
}
978+
}
979+
980+
/*
981+
Extended version of object names.
962982
*/
963983
String RelObjectNameExt():
964984
{ Token tk = null;

src/test/java/net/sf/jsqlparser/test/insert/InsertTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,9 @@ public void testInsertSetWithDuplicateEliminationInDeparsing() throws JSQLParser
267267
+ "ON DUPLICATE KEY UPDATE col2 = col2 + 1, col3 = 'saint'");
268268
}
269269

270+
@Test
271+
public void testInsertTableWithAliasIssue526() throws JSQLParserException {
272+
assertSqlCanBeParsedAndDeparsed("INSERT INTO account t (name, addr, phone) SELECT * FROM user");
273+
}
274+
270275
}

0 commit comments

Comments
 (0)