Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[CONJ-438] insert query that contain table / column that contain SELE…
…CT keyword can be rewritten
- Loading branch information
Showing
2 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/test/java/org/mariadb/jdbc/internal/util/dao/ClientPrepareResultTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package org.mariadb.jdbc.internal.util.dao; | ||
|
|
||
| import static org.junit.Assert.*; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| public class ClientPrepareResultTest { | ||
|
|
||
| /** | ||
| * SELECT query cannot be rewritable. | ||
| */ | ||
| @Test | ||
| public void selectQuery() { | ||
| //SELECT query cannot be rewritable | ||
| assertFalse(ClientPrepareResult.rewritableParts("SELECT * FROM MyTable", true).isQueryMultiValuesRewritable()); | ||
| assertFalse(ClientPrepareResult.rewritableParts("SELECT\n * FROM MyTable", true).isQueryMultiValuesRewritable()); | ||
| } | ||
|
|
||
| /** | ||
| * INSERT FROM SELECT are not be rewritable. | ||
| */ | ||
| @Test | ||
| public void insertSelectQuery() { | ||
| assertFalse(ClientPrepareResult.rewritableParts("INSERT INTO MyTable (a) SELECT * FROM seq_1_to_1000", true).isQueryMultiValuesRewritable()); | ||
| assertFalse(ClientPrepareResult.rewritableParts("INSERT INTO MyTable (a)SELECT * FROM seq_1_to_1000", true).isQueryMultiValuesRewritable()); | ||
| assertFalse(ClientPrepareResult.rewritableParts("INSERT INTO MyTable (a) (SELECT * FROM seq_1_to_1000)", true).isQueryMultiValuesRewritable()); | ||
| assertFalse(ClientPrepareResult.rewritableParts("INSERT INTO MyTable (a) SELECT\n * FROM seq_1_to_1000", true).isQueryMultiValuesRewritable()); | ||
| } | ||
|
|
||
| /** | ||
| * Insert query that contain table/column name with select keyword, or select in comment can be rewritten | ||
| */ | ||
| @Test | ||
| public void rewritableThatContainSelectQuery() { | ||
| //but 'SELECT' keyword in column/table name can be rewritable | ||
| assertTrue(ClientPrepareResult.rewritableParts("INSERT INTO TABLE_SELECT ", true).isQueryMultiValuesRewritable()); | ||
| assertTrue(ClientPrepareResult.rewritableParts("INSERT INTO TABLE_SELECT", true).isQueryMultiValuesRewritable()); | ||
| assertTrue(ClientPrepareResult.rewritableParts("INSERT INTO SELECT_TABLE", true).isQueryMultiValuesRewritable()); | ||
| assertTrue(ClientPrepareResult.rewritableParts("INSERT INTO `TABLE SELECT `", true).isQueryMultiValuesRewritable()); | ||
| assertTrue(ClientPrepareResult.rewritableParts("INSERT INTO TABLE /* SELECT in comment */ ", true).isQueryMultiValuesRewritable()); | ||
| assertTrue(ClientPrepareResult.rewritableParts("INSERT INTO TABLE //SELECT", true).isQueryMultiValuesRewritable()); | ||
|
|
||
| } | ||
| } |