hansva commented on code in PR #9354:
URL: https://github.com/apache/hop/pull/9354#discussion_r4537003367
##########
plugins/databases/mysql/src/main/java/org/apache/hop/workflow/actions/mysqlbulkfile/ActionMysqlBulkFile.java:
##########
@@ -312,7 +319,9 @@ public Result execute(Result previousResult, int nr) {
+ realTablename
+ " "
+ limitNbrLignes
- + " LOCK IN SHARE MODE";
+ // MySQL 8+ rejects HIGH_PRIORITY combined with a
locking clause
+ // (error 3569, "Table appears in multiple locking
clauses").
+ + (isHighPriority() ? "" : " LOCK IN SHARE MODE");
Review Comment:
This ties row locking to the High Priority checkbox: checked (the default)
drops `LOCK IN SHARE MODE`, unchecked adds it. So every existing workflow with
the default High Priority=Y silently switches from a share-locked read to a
plain consistent read after upgrading, and an InnoDB user who wants the share
lock has to turn off HIGH_PRIORITY, an option that does nothing on InnoDB. I'd
rather not couple the two: e.g. drop the redundant `LOCK IN SHARE MODE`, or
only emit one clause based on what the server/engine accepts.
If the coupling stays, it's only documented in the .adoc; the
`ActionMysqlBulkFile.HighPriority.Tooltip` in the dialog still only describes
HIGH_PRIORITY, so a GUI user can't see that the checkbox also switches locking.
##########
plugins/databases/mysql/src/main/java/org/apache/hop/workflow/actions/mysqlbulkfile/ActionMysqlBulkFile.java:
##########
@@ -312,7 +319,9 @@ public Result execute(Result previousResult, int nr) {
+ realTablename
Review Comment:
Not new in this PR, but since we're touching this statement: `realFilename`
(line 311) is put into the `INTO OUTFILE '...'` literal without escaping, while
the separator, enclosure and line terminator all go through `Const.replace(...,
"'", "''")`. A filename like `/var/lib/mysql-files/o'brien.txt` breaks the SQL,
and a crafted variable value could inject extra clauses.
##########
plugins/databases/mysql/src/main/java/org/apache/hop/workflow/actions/mysqlbulkfile/ActionMysqlBulkFile.java:
##########
@@ -223,6 +223,13 @@ public Result execute(Result previousResult, int nr) {
if (connection != null) {
Review Comment:
Since this is still a `connection != null` check, an empty connection name
(an empty `<connection/>` tag loads as `""`) now goes to the new
ConnectionNotFound branch and logs `Database connection [] could not be found.`
instead of the existing 'No database connection is defined' message, which
makes that branch effectively dead. `Utils.isEmpty(connection)` would fix that.
##########
plugins/databases/mysql/src/test/java/org/apache/hop/workflow/actions/mysqlbulkfile/ActionMysqlBulkFileExecuteTest.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hop.workflow.actions.mysqlbulkfile;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockConstruction;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.nio.file.Path;
+import java.sql.PreparedStatement;
+import org.apache.hop.core.HopEnvironment;
+import org.apache.hop.core.Result;
+import org.apache.hop.core.database.Database;
+import org.apache.hop.core.database.DatabaseMeta;
+import org.apache.hop.core.exception.HopException;
+import org.apache.hop.junit.rules.RestoreHopEngineEnvironmentExtension;
+import org.apache.hop.workflow.WorkflowMeta;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.junit.jupiter.api.io.TempDir;
+import org.mockito.ArgumentCaptor;
+import org.mockito.MockedConstruction;
+
+/** Issue #9166: High Priority export statement and a connection that does not
exist. */
+class ActionMysqlBulkFileExecuteTest {
+ @RegisterExtension
+ static RestoreHopEngineEnvironmentExtension env = new
RestoreHopEngineEnvironmentExtension();
+
+ @TempDir Path tempDir;
+
+ @BeforeAll
+ static void setUpBeforeClass() throws HopException {
+ HopEnvironment.init();
+ }
+
+ /** MySQL 8+ rejects HIGH_PRIORITY together with a locking clause (error
3569). */
+ @Test
+ void highPriorityHasNoLockingClause() throws Exception {
+ String sql = runAndCaptureSql(true);
+
+ assertTrue(sql.startsWith("SELECT HIGH_PRIORITY * INTO OUTFILE '"), sql);
+ assertFalse(sql.contains("LOCK IN SHARE MODE"), sql);
+ }
+
+ @Test
+ void withoutHighPriorityTheRowsAreLockedInShareMode() throws Exception {
+ String sql = runAndCaptureSql(false);
+
+ assertTrue(sql.startsWith("SELECT * INTO OUTFILE '"), sql);
Review Comment:
This asserts the exact whitespace of the generated SQL (`"SELECT * INTO
OUTFILE '"` with two spaces), so a harmless cleanup of the SQL builder (e.g.
not adding the space when `strHighPriority` is empty) would fail it. Checking
for the presence/absence of `HIGH_PRIORITY` and `LOCK IN SHARE MODE` would test
what matters.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]