Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix codacy issues + pr return
  • Loading branch information
OlivierCavadenti committed Nov 1, 2021
commit bee50e47258af2cdea3740b82b970511e2fca81e
9 changes: 4 additions & 5 deletions src/main/java/net/sf/jsqlparser/statement/delete/Delete.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import net.sf.jsqlparser.statement.select.OrderByElement;
import net.sf.jsqlparser.statement.select.PlainSelect;
import net.sf.jsqlparser.statement.select.WithItem;
import net.sf.jsqlparser.statement.update.Update;
import net.sf.jsqlparser.statement.update.UpdateModifierPriority;

public class Delete implements Statement {

Expand All @@ -42,13 +40,14 @@ public class Delete implements Statement {
private Limit limit;
private List<OrderByElement> orderByElements;
private boolean hasFrom = true;
public List<WithItem> getWithItemsList() {
return withItemsList;
}
private DeleteModifierPriority modifierPriority;
private boolean modifierIgnore;
private boolean modifierQuick;

public List<WithItem> getWithItemsList() {
return withItemsList;
}

public void setWithItemsList(List<WithItem> withItemsList) {
this.withItemsList = withItemsList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import net.sf.jsqlparser.schema.Table;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.StatementVisitor;
import net.sf.jsqlparser.statement.insert.InsertModifierPriority;
import net.sf.jsqlparser.statement.select.*;

@SuppressWarnings({"PMD.CyclomaticComplexity"})
Expand Down
4 changes: 2 additions & 2 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ Update Update( List<WithItem> with ):
<K_UPDATE> { update.setOracleHint(getOracleHint()); }
[(tk = <K_LOW_PRIORITY>)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pardon me, I do not understand that line: would the token not always be "LOW_PRIORITY" and so modifierPriority = UpdateModifierPriority.LOW_PRIORITY?

Why would we not write this as

[ <K_LOW_PRIORITY> { modifierPriority = UpdateModifierPriority.LOW_PRIORITY; } ]

Am I missing something please?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fix that ok. I copy the logic from INSERT priority but they have more values...

Copy link
Copy Markdown
Contributor

@manticore-projects manticore-projects Nov 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, I was not verbose enough. You can replace:

[(tk = <K_LOW_PRIORITY>)
    {if (tk!=null)
        modifierPriority = DeleteModifierPriority.LOW_PRIORITY;
    }]

with a simple

[ <K_LOW_PRIORITY> { modifierPriority = UpdateModifierPriority.LOW_PRIORITY; } ]

Just showing the possibilities, you can leave as it is and let the compiler do the work.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My fault sry ^^. Do I need something in this PR regarding your comment here ? #1382 (comment)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I need something in this PR regarding your comment here ? #1382 (comment)

No, you did good.
I just used your contribution as an example, why we need to work on the Reserved Keyword Management in general and it is not certain, if @wumpz will like my idea. If he does, then your new token QUICK will be handled automatically. If he does not, we can add it any time later to the Allowed Keywords.

Managing Reserved Keywords in a JavaCC Grammar is a bit weird and not straight forward.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok no problem, thanks for the review anyway.

{if (tk!=null)
modifierPriority = UpdateModifierPriority.valueOf(tk.image.toUpperCase());
modifierPriority = UpdateModifierPriority.LOW_PRIORITY;
}]
[<K_IGNORE>{ modifierIgnore = true; }]
table=TableWithAlias() startJoins=JoinsList()
Expand Down Expand Up @@ -1499,7 +1499,7 @@ Delete Delete( List<WithItem> with ):
<K_DELETE> { delete.setOracleHint(getOracleHint()); }
[(tk = <K_LOW_PRIORITY>)
{if (tk!=null)
modifierPriority = DeleteModifierPriority.valueOf(tk.image.toUpperCase());
modifierPriority = DeleteModifierPriority.LOW_PRIORITY;
}]
[<K_QUICK>{ modifierQuick = true; }]
[<K_IGNORE>{ modifierIgnore = true; }]
Expand Down
14 changes: 7 additions & 7 deletions src/test/java/net/sf/jsqlparser/statement/delete/DeleteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,39 +143,39 @@ public void testUsing() throws JSQLParserException {
@Test
public void testDeleteLowPriority() throws JSQLParserException {
String stmt = "DELETE LOW_PRIORITY FROM tablename";
Delete delete = (Delete)assertSqlCanBeParsedAndDeparsed(stmt);
Delete delete = (Delete) assertSqlCanBeParsedAndDeparsed(stmt);
assertEquals(delete.getModifierPriority(), DeleteModifierPriority.LOW_PRIORITY);
}

@Test
public void testDeleteQuickModifier() throws JSQLParserException {
String stmt = "DELETE QUICK FROM tablename";
Delete delete = (Delete)assertSqlCanBeParsedAndDeparsed(stmt);
Delete delete = (Delete) assertSqlCanBeParsedAndDeparsed(stmt);
assertTrue(delete.isModifierQuick());
String stmt2 = "DELETE FROM tablename";
Delete delete2 = (Delete)assertSqlCanBeParsedAndDeparsed(stmt2);
Delete delete2 = (Delete) assertSqlCanBeParsedAndDeparsed(stmt2);
assertFalse(delete2.isModifierQuick());
}

@Test
public void testDeleteIgnoreModifier() throws JSQLParserException {
String stmt = "DELETE IGNORE FROM tablename";
Delete delete = (Delete)assertSqlCanBeParsedAndDeparsed(stmt);
Delete delete = (Delete) assertSqlCanBeParsedAndDeparsed(stmt);
assertTrue(delete.isModifierIgnore());
String stmt2 = "DELETE FROM tablename";
Delete delete2 = (Delete)assertSqlCanBeParsedAndDeparsed(stmt2);
Delete delete2 = (Delete) assertSqlCanBeParsedAndDeparsed(stmt2);
assertFalse(delete2.isModifierIgnore());
}

@Test
public void testDeleteMultipleModifiers() throws JSQLParserException {
String stmt = "DELETE LOW_PRIORITY QUICK FROM tablename";
Delete delete = (Delete)assertSqlCanBeParsedAndDeparsed(stmt);
Delete delete = (Delete) assertSqlCanBeParsedAndDeparsed(stmt);
assertEquals(delete.getModifierPriority(), DeleteModifierPriority.LOW_PRIORITY);
assertTrue(delete.isModifierQuick());

String stmt2 = "DELETE LOW_PRIORITY QUICK IGNORE FROM tablename";
Delete delete2 = (Delete)assertSqlCanBeParsedAndDeparsed(stmt2);
Delete delete2 = (Delete) assertSqlCanBeParsedAndDeparsed(stmt2);
assertEquals(delete2.getModifierPriority(), DeleteModifierPriority.LOW_PRIORITY);
assertTrue(delete2.isModifierIgnore());
assertTrue(delete2.isModifierQuick());
Expand Down