This is an automated email from the ASF dual-hosted git repository.
hansva pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git
The following commit(s) were added to refs/heads/main by this push:
new c4f5837dd5 Bulk load into MSSQL: false with 0 errors on three checks,
Specific c… (#9361)
c4f5837dd5 is described below
commit c4f5837dd5a6b5c682616fe3718a372068f43884
Author: Bart Maertens <[email protected]>
AuthorDate: Thu Nov 12 10:10:06 2026 +0100
Bulk load into MSSQL: false with 0 errors on three checks, Specific c…
(#9361)
* Bulk load into MSSQL: false with 0 errors on three checks, Specific
codepage not used, Start at line dropped, fixes #9167
* Codepage stored as a code and validated, check() reports it, unit tests
for the SQL, review of #9361
---
.../ROOT/pages/workflow/actions/mssqlbulkload.adoc | 10 +-
integration-tests/mssql/0010-bulk-load-options.hwf | 537 +++++++++++++++++++++
.../mssql/main-0010-bulk-load-options-2025.hwf | 98 ++++
.../mssql/main-0011-bulk-load-options-2022.hwf | 98 ++++
.../mssql/metadata/rdbms/not-mssql.json | 27 ++
.../actions/mssqlbulkload/ActionMssqlBulkLoad.java | 81 +++-
.../mssqlbulkload/ActionMssqlBulkLoadDialog.java | 17 +-
.../mssqlbulkload/MssqlBulkLoadCodePage.java | 90 ++++
.../messages/messages_en_US.properties | 4 +-
.../ActionMssqlBulkLoadCheckTest.java | 36 ++
.../ActionMssqlBulkLoadExecuteTest.java | 212 ++++++++
.../mssqlbulkload/MssqlBulkLoadCodePageTest.java | 62 +++
12 files changed, 1240 insertions(+), 32 deletions(-)
diff --git
a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/mssqlbulkload.adoc
b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/mssqlbulkload.adoc
index ebfb2d0de3..bae067a732 100644
---
a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/mssqlbulkload.adoc
+++
b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/mssqlbulkload.adoc
@@ -52,7 +52,7 @@ Contrary to the transform bulk loaders, this action requires
a pre-existing file
|===
|Option|Description
|Codepage|ACP, OEM (default), RAW or Specific. See the NOTE under <<Result>>.
-|Specific codepage|Code page to use when Specific is selected.
+|Specific codepage|Code page to use when Specific is selected: a code page
number such as 65001, or ACP, OEM or RAW.
|Format file|Path to format file.
|Browse|Browse the filesystem to choose a format file.
|Fire triggers|
@@ -80,9 +80,7 @@ What this action passes on to the next action. See
xref:workflow/action-results.
|===
|Result|Value
|True|The file was loaded, with 0 errors.
-|False|The file doesn't exist, the table doesn't exist, *Source File name* is
empty, the connection is unknown or can't be opened, or SQL Server refuses the
load (for example a value that doesn't fit its column). The number of errors is
1.
-
-The action is also false, but with 0 errors, when the connection is not a
Microsoft SQL Server connection, when *Fields terminated by* is empty while
*Data file type* is char or widechar, and when *Error file* exists while *Add
date time* is unchecked. The reason is logged as an error.
+|False|The file doesn't exist, the table doesn't exist, *Source File name* is
empty, the connection is unknown or can't be opened, the connection is not a
Microsoft SQL Server connection, *Fields terminated by* is empty while *Data
file type* is char or widechar, *Codepage* is Specific while *Specific
codepage* is empty or not a code page number, ACP, OEM or RAW, *Error file*
exists while *Add date time* is unchecked, or SQL Server refuses the load (for
example a value that doesn't fit i [...]
|Result files|The source file is added when *Add file to result filenames* is
checked and the load succeeded. Otherwise passed on unchanged.
|Result rows|Passed on unchanged.
|===
@@ -91,6 +89,4 @@ NOTE: SQL Server reads the file, so *Source File name* must
be a path that the d
NOTE: When the load fails on a row, the rows before it can stay in the table:
with the default options, a value that doesn't fit its column on row 2 left row
1 loaded.
-NOTE: SQL Server on Linux only accepts the RAW *Codepage*: the default, OEM,
makes the load fail there. In this version, *Specific* sends the word
`Specific` to SQL Server instead of the value of *Specific codepage*, so the
load fails.
-
-NOTE: When both *Start at line* and *End at line* are set, only *End at line*
is used: the load starts at the first line.
+NOTE: SQL Server on Linux only accepts the RAW *Codepage*: the default, OEM,
makes the load fail there.
diff --git a/integration-tests/mssql/0010-bulk-load-options.hwf
b/integration-tests/mssql/0010-bulk-load-options.hwf
new file mode 100644
index 0000000000..30f02fede9
--- /dev/null
+++ b/integration-tests/mssql/0010-bulk-load-options.hwf
@@ -0,0 +1,537 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+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.
+
+-->
+<workflow>
+ <name>0010-bulk-load-options</name>
+ <name_sync_with_filename>Y</name_sync_with_filename>
+ <description>Bulk load options and the checks that stop a load
(#9167).</description>
+ <extended_description/>
+ <workflow_version/>
+ <created_user>-</created_user>
+ <created_date>2026/11/07 12:00:00.000</created_date>
+ <modified_user>-</modified_user>
+ <modified_date>2026/11/07 12:00:00.000</modified_date>
+ <parameters>
+ </parameters>
+ <actions>
+ <action>
+ <name>Start</name>
+ <description/>
+ <type>SPECIAL</type>
+ <attributes/>
+ <DayOfMonth>1</DayOfMonth>
+ <doNotWaitOnFirstExecution>N</doNotWaitOnFirstExecution>
+ <hour>12</hour>
+ <intervalMinutes>60</intervalMinutes>
+ <intervalSeconds>0</intervalSeconds>
+ <minutes>0</minutes>
+ <repeat>N</repeat>
+ <schedulerType>0</schedulerType>
+ <weekDay>1</weekDay>
+ <parallel>N</parallel>
+ <xloc>80</xloc>
+ <yloc>80</yloc>
+ <attributes_hac/>
+ </action>
+ <action>
+ <name>Create table</name>
+ <description/>
+ <type>SQL</type>
+ <attributes/>
+ <connection>${MSSQL_CONNECTION}</connection>
+ <sendOneStatement>N</sendOneStatement>
+ <sql>DROP TABLE IF EXISTS master.dbo.[bulk-load-options];
+
+CREATE TABLE master.dbo.[bulk-load-options] (
+ Column1 varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
+ Column2 varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
+);</sql>
+ <sqlfromfile>N</sqlfromfile>
+ <useVariableSubstitution>N</useVariableSubstitution>
+ <parallel>N</parallel>
+ <xloc>224</xloc>
+ <yloc>80</yloc>
+ <attributes_hac/>
+ </action>
+ <action>
+ <name>not-mssql is a PostgreSQL connection</name>
+ <description/>
+ <type>EVAL</type>
+ <attributes/>
+ <script>var db =
action.getParentWorkflowMeta().findDatabase("not-mssql", action);
+db != null && String(db.getPluginId()) == "POSTGRESQL";</script>
+ <parallel>N</parallel>
+ <xloc>224</xloc>
+ <yloc>208</yloc>
+ <attributes_hac/>
+ </action>
+ <action>
+ <name>Not a SQL Server connection</name>
+ <description/>
+ <type>MSSQL_BULK_LOAD</type>
+ <attributes/>
+ <adddatetime>N</adddatetime>
+ <addfiletoresult>N</addfiletoresult>
+ <batchsize>0</batchsize>
+ <checkconstraints>N</checkconstraints>
+ <codepage>RAW</codepage>
+ <connection>not-mssql</connection>
+ <datafiletype>char</datafiletype>
+ <endfile>0</endfile>
+ <errorfilename/>
+ <fieldterminator>,</fieldterminator>
+ <filename>/tmp/mssql_bulkload.csv</filename>
+ <firetriggers>N</firetriggers>
+ <formatfilename/>
+ <keepidentity>N</keepidentity>
+ <keepnulls>N</keepnulls>
+ <lineterminated/>
+ <maxerrors>0</maxerrors>
+ <orderby/>
+ <orderdirection>Asc</orderdirection>
+ <rowsperbatch>0</rowsperbatch>
+ <schemaname>dbo</schemaname>
+ <specificcodepage/>
+ <startfile>2</startfile>
+ <tablename>[bulk-load-options]</tablename>
+ <tablock>N</tablock>
+ <truncate>Y</truncate>
+ <parallel>N</parallel>
+ <xloc>400</xloc>
+ <yloc>80</yloc>
+ <attributes_hac/>
+ </action>
+ <action>
+ <name>Not a SQL Server connection: 1 error</name>
+ <description/>
+ <type>EVAL</type>
+ <attributes/>
+ <script>errors == 1;</script>
+ <parallel>N</parallel>
+ <xloc>400</xloc>
+ <yloc>208</yloc>
+ <attributes_hac/>
+ </action>
+ <action>
+ <name>No field terminator</name>
+ <description/>
+ <type>MSSQL_BULK_LOAD</type>
+ <attributes/>
+ <adddatetime>N</adddatetime>
+ <addfiletoresult>N</addfiletoresult>
+ <batchsize>0</batchsize>
+ <checkconstraints>N</checkconstraints>
+ <codepage>RAW</codepage>
+ <connection>${MSSQL_CONNECTION}</connection>
+ <datafiletype>char</datafiletype>
+ <endfile>0</endfile>
+ <errorfilename/>
+ <fieldterminator/>
+ <filename>/tmp/mssql_bulkload.csv</filename>
+ <firetriggers>N</firetriggers>
+ <formatfilename/>
+ <keepidentity>N</keepidentity>
+ <keepnulls>N</keepnulls>
+ <lineterminated/>
+ <maxerrors>0</maxerrors>
+ <orderby/>
+ <orderdirection>Asc</orderdirection>
+ <rowsperbatch>0</rowsperbatch>
+ <schemaname>dbo</schemaname>
+ <specificcodepage/>
+ <startfile>2</startfile>
+ <tablename>[bulk-load-options]</tablename>
+ <tablock>N</tablock>
+ <truncate>Y</truncate>
+ <parallel>N</parallel>
+ <xloc>592</xloc>
+ <yloc>80</yloc>
+ <attributes_hac/>
+ </action>
+ <action>
+ <name>No field terminator: 1 error</name>
+ <description/>
+ <type>EVAL</type>
+ <attributes/>
+ <script>errors == 1;</script>
+ <parallel>N</parallel>
+ <xloc>592</xloc>
+ <yloc>208</yloc>
+ <attributes_hac/>
+ </action>
+ <action>
+ <name>Error file exists</name>
+ <description/>
+ <type>MSSQL_BULK_LOAD</type>
+ <attributes/>
+ <adddatetime>N</adddatetime>
+ <addfiletoresult>N</addfiletoresult>
+ <batchsize>0</batchsize>
+ <checkconstraints>N</checkconstraints>
+ <codepage>RAW</codepage>
+ <connection>${MSSQL_CONNECTION}</connection>
+ <datafiletype>char</datafiletype>
+ <endfile>0</endfile>
+ <errorfilename>/tmp/mssql_bulkload.csv</errorfilename>
+ <fieldterminator>,</fieldterminator>
+ <filename>/tmp/mssql_bulkload.csv</filename>
+ <firetriggers>N</firetriggers>
+ <formatfilename/>
+ <keepidentity>N</keepidentity>
+ <keepnulls>N</keepnulls>
+ <lineterminated/>
+ <maxerrors>0</maxerrors>
+ <orderby/>
+ <orderdirection>Asc</orderdirection>
+ <rowsperbatch>0</rowsperbatch>
+ <schemaname>dbo</schemaname>
+ <specificcodepage/>
+ <startfile>2</startfile>
+ <tablename>[bulk-load-options]</tablename>
+ <tablock>N</tablock>
+ <truncate>Y</truncate>
+ <parallel>N</parallel>
+ <xloc>784</xloc>
+ <yloc>80</yloc>
+ <attributes_hac/>
+ </action>
+ <action>
+ <name>Error file exists: 1 error</name>
+ <description/>
+ <type>EVAL</type>
+ <attributes/>
+ <script>errors == 1;</script>
+ <parallel>N</parallel>
+ <xloc>784</xloc>
+ <yloc>208</yloc>
+ <attributes_hac/>
+ </action>
+ <action>
+ <name>No specific codepage</name>
+ <description/>
+ <type>MSSQL_BULK_LOAD</type>
+ <attributes/>
+ <adddatetime>N</adddatetime>
+ <addfiletoresult>N</addfiletoresult>
+ <batchsize>0</batchsize>
+ <checkconstraints>N</checkconstraints>
+ <codepage>Specific</codepage>
+ <connection>${MSSQL_CONNECTION}</connection>
+ <datafiletype>char</datafiletype>
+ <endfile>0</endfile>
+ <errorfilename/>
+ <fieldterminator>,</fieldterminator>
+ <filename>/tmp/mssql_bulkload.csv</filename>
+ <firetriggers>N</firetriggers>
+ <formatfilename/>
+ <keepidentity>N</keepidentity>
+ <keepnulls>N</keepnulls>
+ <lineterminated/>
+ <maxerrors>0</maxerrors>
+ <orderby/>
+ <orderdirection>Asc</orderdirection>
+ <rowsperbatch>0</rowsperbatch>
+ <schemaname>dbo</schemaname>
+ <specificcodepage/>
+ <startfile>2</startfile>
+ <tablename>[bulk-load-options]</tablename>
+ <tablock>N</tablock>
+ <truncate>Y</truncate>
+ <parallel>N</parallel>
+ <xloc>976</xloc>
+ <yloc>80</yloc>
+ <attributes_hac/>
+ </action>
+ <action>
+ <name>No specific codepage: 1 error</name>
+ <description/>
+ <type>EVAL</type>
+ <attributes/>
+ <script>errors == 1;</script>
+ <parallel>N</parallel>
+ <xloc>976</xloc>
+ <yloc>208</yloc>
+ <attributes_hac/>
+ </action>
+ <action>
+ <name>Specific codepage RAW</name>
+ <description/>
+ <type>MSSQL_BULK_LOAD</type>
+ <attributes/>
+ <adddatetime>N</adddatetime>
+ <addfiletoresult>N</addfiletoresult>
+ <batchsize>0</batchsize>
+ <checkconstraints>N</checkconstraints>
+ <codepage>Specific</codepage>
+ <connection>${MSSQL_CONNECTION}</connection>
+ <datafiletype>char</datafiletype>
+ <endfile>0</endfile>
+ <errorfilename/>
+ <fieldterminator>,</fieldterminator>
+ <filename>/tmp/mssql_bulkload.csv</filename>
+ <firetriggers>N</firetriggers>
+ <formatfilename/>
+ <keepidentity>N</keepidentity>
+ <keepnulls>N</keepnulls>
+ <lineterminated/>
+ <maxerrors>0</maxerrors>
+ <orderby/>
+ <orderdirection>Asc</orderdirection>
+ <rowsperbatch>0</rowsperbatch>
+ <schemaname>dbo</schemaname>
+ <specificcodepage>RAW</specificcodepage>
+ <startfile>2</startfile>
+ <tablename>[bulk-load-options]</tablename>
+ <tablock>N</tablock>
+ <truncate>Y</truncate>
+ <parallel>N</parallel>
+ <xloc>1168</xloc>
+ <yloc>208</yloc>
+ <attributes_hac/>
+ </action>
+ <action>
+ <name>10000 rows</name>
+ <description/>
+ <type>EVAL_TABLE_CONTENT</type>
+ <attributes/>
+ <connection>${MSSQL_CONNECTION}</connection>
+ <schemaname>dbo</schemaname>
+ <tablename>[bulk-load-options]</tablename>
+ <success_condition>rows_count_equal</success_condition>
+ <limit>10000</limit>
+ <is_custom_sql>N</is_custom_sql>
+ <is_usevars>N</is_usevars>
+ <custom_sql/>
+ <add_rows_result>N</add_rows_result>
+ <clear_result_rows>Y</clear_result_rows>
+ <parallel>N</parallel>
+ <xloc>1168</xloc>
+ <yloc>336</yloc>
+ <attributes_hac/>
+ </action>
+ <action>
+ <name>Lines 2 to 3</name>
+ <description/>
+ <type>MSSQL_BULK_LOAD</type>
+ <attributes/>
+ <adddatetime>N</adddatetime>
+ <addfiletoresult>N</addfiletoresult>
+ <batchsize>0</batchsize>
+ <checkconstraints>N</checkconstraints>
+ <codepage>RAW</codepage>
+ <connection>${MSSQL_CONNECTION}</connection>
+ <datafiletype>char</datafiletype>
+ <endfile>3</endfile>
+ <errorfilename/>
+ <fieldterminator>,</fieldterminator>
+ <filename>/tmp/mssql_bulkload.csv</filename>
+ <firetriggers>N</firetriggers>
+ <formatfilename/>
+ <keepidentity>N</keepidentity>
+ <keepnulls>N</keepnulls>
+ <lineterminated/>
+ <maxerrors>0</maxerrors>
+ <orderby/>
+ <orderdirection>Asc</orderdirection>
+ <rowsperbatch>0</rowsperbatch>
+ <schemaname>dbo</schemaname>
+ <specificcodepage/>
+ <startfile>2</startfile>
+ <tablename>[bulk-load-options]</tablename>
+ <tablock>N</tablock>
+ <truncate>Y</truncate>
+ <parallel>N</parallel>
+ <xloc>1360</xloc>
+ <yloc>336</yloc>
+ <attributes_hac/>
+ </action>
+ <action>
+ <name>2 rows</name>
+ <description/>
+ <type>EVAL_TABLE_CONTENT</type>
+ <attributes/>
+ <connection>${MSSQL_CONNECTION}</connection>
+ <schemaname>dbo</schemaname>
+ <tablename>[bulk-load-options]</tablename>
+ <success_condition>rows_count_equal</success_condition>
+ <limit>2</limit>
+ <is_custom_sql>N</is_custom_sql>
+ <is_usevars>N</is_usevars>
+ <custom_sql/>
+ <add_rows_result>N</add_rows_result>
+ <clear_result_rows>Y</clear_result_rows>
+ <parallel>N</parallel>
+ <xloc>1360</xloc>
+ <yloc>464</yloc>
+ <attributes_hac/>
+ </action>
+ <action>
+ <name>Murray and Felix</name>
+ <description/>
+ <type>EVAL_TABLE_CONTENT</type>
+ <attributes/>
+ <connection>${MSSQL_CONNECTION}</connection>
+ <schemaname>dbo</schemaname>
+ <tablename>[bulk-load-options]</tablename>
+ <success_condition>rows_count_equal</success_condition>
+ <limit>2</limit>
+ <is_custom_sql>Y</is_custom_sql>
+ <is_usevars>N</is_usevars>
+ <custom_sql>SELECT * FROM dbo.[bulk-load-options] WHERE Column1 IN
('Murray', 'Felix')</custom_sql>
+ <add_rows_result>N</add_rows_result>
+ <clear_result_rows>Y</clear_result_rows>
+ <parallel>N</parallel>
+ <xloc>1552</xloc>
+ <yloc>464</yloc>
+ <attributes_hac/>
+ </action>
+ <action>
+ <name>Drop table</name>
+ <description/>
+ <type>SQL</type>
+ <attributes/>
+ <connection>${MSSQL_CONNECTION}</connection>
+ <sendOneStatement>N</sendOneStatement>
+ <sql>DROP TABLE master.dbo.[bulk-load-options];</sql>
+ <sqlfromfile>N</sqlfromfile>
+ <useVariableSubstitution>N</useVariableSubstitution>
+ <parallel>N</parallel>
+ <xloc>1744</xloc>
+ <yloc>464</yloc>
+ <attributes_hac/>
+ </action>
+ </actions>
+ <hops>
+ <hop>
+ <from>Start</from>
+ <to>Create table</to>
+ <enabled>Y</enabled>
+ <evaluation>Y</evaluation>
+ <unconditional>Y</unconditional>
+ </hop>
+ <hop>
+ <from>Create table</from>
+ <to>not-mssql is a PostgreSQL connection</to>
+ <enabled>Y</enabled>
+ <evaluation>Y</evaluation>
+ <unconditional>N</unconditional>
+ </hop>
+ <hop>
+ <from>not-mssql is a PostgreSQL connection</from>
+ <to>Not a SQL Server connection</to>
+ <enabled>Y</enabled>
+ <evaluation>Y</evaluation>
+ <unconditional>N</unconditional>
+ </hop>
+ <hop>
+ <from>Not a SQL Server connection</from>
+ <to>Not a SQL Server connection: 1 error</to>
+ <enabled>Y</enabled>
+ <evaluation>N</evaluation>
+ <unconditional>N</unconditional>
+ </hop>
+ <hop>
+ <from>Not a SQL Server connection: 1 error</from>
+ <to>No field terminator</to>
+ <enabled>Y</enabled>
+ <evaluation>Y</evaluation>
+ <unconditional>N</unconditional>
+ </hop>
+ <hop>
+ <from>No field terminator</from>
+ <to>No field terminator: 1 error</to>
+ <enabled>Y</enabled>
+ <evaluation>N</evaluation>
+ <unconditional>N</unconditional>
+ </hop>
+ <hop>
+ <from>No field terminator: 1 error</from>
+ <to>Error file exists</to>
+ <enabled>Y</enabled>
+ <evaluation>Y</evaluation>
+ <unconditional>N</unconditional>
+ </hop>
+ <hop>
+ <from>Error file exists</from>
+ <to>Error file exists: 1 error</to>
+ <enabled>Y</enabled>
+ <evaluation>N</evaluation>
+ <unconditional>N</unconditional>
+ </hop>
+ <hop>
+ <from>Error file exists: 1 error</from>
+ <to>No specific codepage</to>
+ <enabled>Y</enabled>
+ <evaluation>Y</evaluation>
+ <unconditional>N</unconditional>
+ </hop>
+ <hop>
+ <from>No specific codepage</from>
+ <to>No specific codepage: 1 error</to>
+ <enabled>Y</enabled>
+ <evaluation>N</evaluation>
+ <unconditional>N</unconditional>
+ </hop>
+ <hop>
+ <from>No specific codepage: 1 error</from>
+ <to>Specific codepage RAW</to>
+ <enabled>Y</enabled>
+ <evaluation>Y</evaluation>
+ <unconditional>N</unconditional>
+ </hop>
+ <hop>
+ <from>Specific codepage RAW</from>
+ <to>10000 rows</to>
+ <enabled>Y</enabled>
+ <evaluation>Y</evaluation>
+ <unconditional>N</unconditional>
+ </hop>
+ <hop>
+ <from>10000 rows</from>
+ <to>Lines 2 to 3</to>
+ <enabled>Y</enabled>
+ <evaluation>Y</evaluation>
+ <unconditional>N</unconditional>
+ </hop>
+ <hop>
+ <from>Lines 2 to 3</from>
+ <to>2 rows</to>
+ <enabled>Y</enabled>
+ <evaluation>Y</evaluation>
+ <unconditional>N</unconditional>
+ </hop>
+ <hop>
+ <from>2 rows</from>
+ <to>Murray and Felix</to>
+ <enabled>Y</enabled>
+ <evaluation>Y</evaluation>
+ <unconditional>N</unconditional>
+ </hop>
+ <hop>
+ <from>Murray and Felix</from>
+ <to>Drop table</to>
+ <enabled>Y</enabled>
+ <evaluation>Y</evaluation>
+ <unconditional>N</unconditional>
+ </hop>
+ </hops>
+ <notepads>
+ </notepads>
+ <attributes/>
+</workflow>
diff --git a/integration-tests/mssql/main-0010-bulk-load-options-2025.hwf
b/integration-tests/mssql/main-0010-bulk-load-options-2025.hwf
new file mode 100644
index 0000000000..f7b8a48a34
--- /dev/null
+++ b/integration-tests/mssql/main-0010-bulk-load-options-2025.hwf
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+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.
+
+-->
+<workflow>
+ <name>main-0010-bulk-load-options-2025</name>
+ <name_sync_with_filename>Y</name_sync_with_filename>
+ <description>Bulk load options against SQL Server 2025.</description>
+ <extended_description/>
+ <workflow_version/>
+ <created_user>-</created_user>
+ <created_date>2026/11/07 12:00:00.000</created_date>
+ <modified_user>-</modified_user>
+ <modified_date>2026/11/07 12:00:00.000</modified_date>
+ <parameters>
+ <parameter>
+ <name>MSSQL_CONNECTION</name>
+ <default_value>mssql-2025</default_value>
+ <description>Which of the two servers this run is against</description>
+ </parameter>
+ </parameters>
+ <actions>
+ <action>
+ <name>Start</name>
+ <description/>
+ <type>SPECIAL</type>
+ <attributes/>
+ <DayOfMonth>1</DayOfMonth>
+ <doNotWaitOnFirstExecution>N</doNotWaitOnFirstExecution>
+ <hour>12</hour>
+ <intervalMinutes>60</intervalMinutes>
+ <intervalSeconds>0</intervalSeconds>
+ <minutes>0</minutes>
+ <repeat>N</repeat>
+ <schedulerType>0</schedulerType>
+ <weekDay>1</weekDay>
+ <parallel>N</parallel>
+ <xloc>80</xloc>
+ <yloc>80</yloc>
+ <attributes_hac/>
+ </action>
+ <action>
+ <name>0010-bulk-load-options.hwf</name>
+ <description/>
+ <type>WORKFLOW</type>
+ <attributes/>
+ <add_date>N</add_date>
+ <add_time>N</add_time>
+ <clear_files>N</clear_files>
+ <clear_rows>N</clear_rows>
+ <create_parent_folder>N</create_parent_folder>
+ <exec_per_row>N</exec_per_row>
+ <filename>${PROJECT_HOME}/0010-bulk-load-options.hwf</filename>
+ <logext/>
+ <logfile/>
+ <loglevel>Basic</loglevel>
+ <parameters>
+ <pass_all_parameters>Y</pass_all_parameters>
+ </parameters>
+ <params_from_previous>N</params_from_previous>
+ <run_configuration>local</run_configuration>
+ <set_append_logfile>N</set_append_logfile>
+ <set_logfile>N</set_logfile>
+ <wait_until_finished>Y</wait_until_finished>
+ <parallel>N</parallel>
+ <xloc>288</xloc>
+ <yloc>80</yloc>
+ <attributes_hac/>
+ </action>
+ </actions>
+ <hops>
+ <hop>
+ <from>Start</from>
+ <to>0010-bulk-load-options.hwf</to>
+ <enabled>Y</enabled>
+ <evaluation>Y</evaluation>
+ <unconditional>Y</unconditional>
+ </hop>
+ </hops>
+ <notepads>
+ </notepads>
+ <attributes/>
+</workflow>
diff --git a/integration-tests/mssql/main-0011-bulk-load-options-2022.hwf
b/integration-tests/mssql/main-0011-bulk-load-options-2022.hwf
new file mode 100644
index 0000000000..d57493175c
--- /dev/null
+++ b/integration-tests/mssql/main-0011-bulk-load-options-2022.hwf
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+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.
+
+-->
+<workflow>
+ <name>main-0011-bulk-load-options-2022</name>
+ <name_sync_with_filename>Y</name_sync_with_filename>
+ <description>Bulk load options against SQL Server 2022.</description>
+ <extended_description/>
+ <workflow_version/>
+ <created_user>-</created_user>
+ <created_date>2026/11/07 12:00:00.000</created_date>
+ <modified_user>-</modified_user>
+ <modified_date>2026/11/07 12:00:00.000</modified_date>
+ <parameters>
+ <parameter>
+ <name>MSSQL_CONNECTION</name>
+ <default_value>mssql-2022</default_value>
+ <description>Which of the two servers this run is against</description>
+ </parameter>
+ </parameters>
+ <actions>
+ <action>
+ <name>Start</name>
+ <description/>
+ <type>SPECIAL</type>
+ <attributes/>
+ <DayOfMonth>1</DayOfMonth>
+ <doNotWaitOnFirstExecution>N</doNotWaitOnFirstExecution>
+ <hour>12</hour>
+ <intervalMinutes>60</intervalMinutes>
+ <intervalSeconds>0</intervalSeconds>
+ <minutes>0</minutes>
+ <repeat>N</repeat>
+ <schedulerType>0</schedulerType>
+ <weekDay>1</weekDay>
+ <parallel>N</parallel>
+ <xloc>80</xloc>
+ <yloc>80</yloc>
+ <attributes_hac/>
+ </action>
+ <action>
+ <name>0010-bulk-load-options.hwf</name>
+ <description/>
+ <type>WORKFLOW</type>
+ <attributes/>
+ <add_date>N</add_date>
+ <add_time>N</add_time>
+ <clear_files>N</clear_files>
+ <clear_rows>N</clear_rows>
+ <create_parent_folder>N</create_parent_folder>
+ <exec_per_row>N</exec_per_row>
+ <filename>${PROJECT_HOME}/0010-bulk-load-options.hwf</filename>
+ <logext/>
+ <logfile/>
+ <loglevel>Basic</loglevel>
+ <parameters>
+ <pass_all_parameters>Y</pass_all_parameters>
+ </parameters>
+ <params_from_previous>N</params_from_previous>
+ <run_configuration>local</run_configuration>
+ <set_append_logfile>N</set_append_logfile>
+ <set_logfile>N</set_logfile>
+ <wait_until_finished>Y</wait_until_finished>
+ <parallel>N</parallel>
+ <xloc>288</xloc>
+ <yloc>80</yloc>
+ <attributes_hac/>
+ </action>
+ </actions>
+ <hops>
+ <hop>
+ <from>Start</from>
+ <to>0010-bulk-load-options.hwf</to>
+ <enabled>Y</enabled>
+ <evaluation>Y</evaluation>
+ <unconditional>Y</unconditional>
+ </hop>
+ </hops>
+ <notepads>
+ </notepads>
+ <attributes/>
+</workflow>
diff --git a/integration-tests/mssql/metadata/rdbms/not-mssql.json
b/integration-tests/mssql/metadata/rdbms/not-mssql.json
new file mode 100644
index 0000000000..86d5f1dd7a
--- /dev/null
+++ b/integration-tests/mssql/metadata/rdbms/not-mssql.json
@@ -0,0 +1,27 @@
+{
+ "virtualPath": "",
+ "rdbms": {
+ "POSTGRESQL": {
+ "databaseName": "none",
+ "pluginId": "POSTGRESQL",
+ "accessType": 0,
+ "hostname": "never-connected",
+ "password": "Encrypted 2be98afa605d39a8da51ee367d180a4c9",
+ "pluginName": "PostgreSQL",
+ "port": "5432",
+ "attributes": {
+ "SUPPORTS_TIMESTAMP_DATA_TYPE": "Y",
+ "QUOTE_ALL_FIELDS": "N",
+ "SUPPORTS_BOOLEAN_DATA_TYPE": "Y",
+ "FORCE_IDENTIFIERS_TO_LOWERCASE": "N",
+ "PRESERVE_RESERVED_WORD_CASE": "Y",
+ "SQL_CONNECT": "",
+ "FORCE_IDENTIFIERS_TO_UPPERCASE": "N",
+ "PREFERRED_SCHEMA_NAME": ""
+ },
+ "manualUrl": "",
+ "username": "no-user"
+ }
+ },
+ "name": "not-mssql"
+}
diff --git
a/plugins/databases/mssqlnative/src/main/java/org/apache/hop/workflow/actions/mssqlbulkload/ActionMssqlBulkLoad.java
b/plugins/databases/mssqlnative/src/main/java/org/apache/hop/workflow/actions/mssqlbulkload/ActionMssqlBulkLoad.java
index d808d5ec73..30ce97d423 100644
---
a/plugins/databases/mssqlnative/src/main/java/org/apache/hop/workflow/actions/mssqlbulkload/ActionMssqlBulkLoad.java
+++
b/plugins/databases/mssqlnative/src/main/java/org/apache/hop/workflow/actions/mssqlbulkload/ActionMssqlBulkLoad.java
@@ -25,6 +25,7 @@ import lombok.Getter;
import lombok.Setter;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.provider.local.LocalFile;
+import org.apache.hop.core.CheckResult;
import org.apache.hop.core.ICheckResult;
import org.apache.hop.core.Result;
import org.apache.hop.core.ResultFile;
@@ -245,15 +246,20 @@ public class ActionMssqlBulkLoad extends ActionBase {
if (connection != null) {
DatabaseMeta dbMeta = parentWorkflowMeta.findDatabase(connection,
getVariables());
+ if (dbMeta == null) {
+ return fail(
+ result,
+ BaseMessages.getString(
+ PKG, "ActionMssqlBulkLoad.Error.ConnectionNotFound",
resolve(connection)));
+ }
// User has specified a connection, We can continue ...
String pluginId = dbMeta.getPluginId();
if (!("MSSQL".equals(pluginId) || "MSSQLNATIVE".equals(pluginId)))
{
-
- logError(
+ return fail(
+ result,
BaseMessages.getString(
PKG, "ActionMssqlBulkLoad.Error.DbNotMSSQL",
dbMeta.getDatabaseName()));
- return result;
}
try (Database db = new Database(this, this, dbMeta)) {
db.connect();
@@ -274,10 +280,10 @@ public class ActionMssqlBulkLoad extends ActionBase {
String fieldTerminator = getRealFieldTerminator();
if (Utils.isEmpty(fieldTerminator)
&& (dataFileType.equals("char") ||
dataFileType.equals("widechar"))) {
- logError(
+ return fail(
+ result,
BaseMessages.getString(
PKG,
"ActionMssqlBulkLoad.Error.FieldTerminatorMissing"));
- return result;
} else {
if (dataFileType.equals("char") ||
dataFileType.equals("widechar")) {
useFieldSeparator = true;
@@ -285,18 +291,24 @@ public class ActionMssqlBulkLoad extends ActionBase {
}
}
// Check Specific Code page
- if (codePage.equals("Specific")) {
- String realCodePage = resolve(codePage);
- if (specificCodePage.length() < 0) {
- logError(
+ if (MssqlBulkLoadCodePage.lookup(codePage) ==
MssqlBulkLoadCodePage.SPECIFIC) {
+ String realCodePage = resolve(specificCodePage);
+ if (Utils.isEmpty(realCodePage)) {
+ return fail(
+ result,
BaseMessages.getString(
PKG,
"ActionMssqlBulkLoad.Error.SpecificCodePageMissing"));
- return result;
-
- } else {
- useCodepage = "CODEPAGE = '" + realCodePage + "'";
}
- } else {
+ if (!MssqlBulkLoadCodePage.isValidCodePage(realCodePage)) {
+ return fail(
+ result,
+ BaseMessages.getString(
+ PKG,
+
"ActionMssqlBulkLoad.Error.SpecificCodePageInvalid",
+ realCodePage));
+ }
+ useCodepage = "CODEPAGE = '" + realCodePage.trim() + "'";
+ } else if (!Utils.isEmpty(codePage)) {
useCodepage = "CODEPAGE = '" + codePage + "'";
}
@@ -308,9 +320,9 @@ public class ActionMssqlBulkLoad extends ActionBase {
// The error file is created when the command is executed.
An error occurs if
// the file already
// exists.
- logError(
+ return fail(
+ result,
BaseMessages.getString(PKG,
"ActionMssqlBulkLoad.Error.ErrorFileExists"));
- return result;
}
if (addDatetime) {
// Add date time to filename...
@@ -338,7 +350,10 @@ public class ActionMssqlBulkLoad extends ActionBase {
// End file at
if (endFile > 0) {
- takeFirstNbrLines = "LASTROW=" + endFile;
+ if (!takeFirstNbrLines.isEmpty()) {
+ takeFirstNbrLines += ",";
+ }
+ takeFirstNbrLines += "LASTROW=" + endFile;
}
// Truncate table?
@@ -479,6 +494,17 @@ public class ActionMssqlBulkLoad extends ActionBase {
return result;
}
+ /**
+ * Log the reason the load stops and count it as one error, so the action is
never false with 0
+ * errors.
+ */
+ private Result fail(Result result, String message) {
+ result.setResult(false);
+ result.setNrErrors(1);
+ logError(message);
+ return result;
+ }
+
public String getRealLineterminated() {
return resolve(getLineTerminated());
}
@@ -535,5 +561,26 @@ public class ActionMssqlBulkLoad extends ActionBase {
"tableName",
remarks,
AndValidator.putValidators(ActionValidatorUtils.notBlankValidator()));
+
+ if (MssqlBulkLoadCodePage.lookup(codePage) ==
MssqlBulkLoadCodePage.SPECIFIC) {
+ String realCodePage =
+ variables == null ? specificCodePage :
variables.resolve(specificCodePage);
+ if (Utils.isEmpty(realCodePage)) {
+ remarks.add(
+ new CheckResult(
+ ICheckResult.TYPE_RESULT_ERROR,
+ BaseMessages.getString(PKG,
"ActionMssqlBulkLoad.Error.SpecificCodePageMissing"),
+ this));
+ } else if (!realCodePage.contains("${")
+ && !MssqlBulkLoadCodePage.isValidCodePage(realCodePage)) {
+ // A variable that is only set at run time is checked when the action
runs.
+ remarks.add(
+ new CheckResult(
+ ICheckResult.TYPE_RESULT_ERROR,
+ BaseMessages.getString(
+ PKG, "ActionMssqlBulkLoad.Error.SpecificCodePageInvalid",
realCodePage),
+ this));
+ }
+ }
}
}
diff --git
a/plugins/databases/mssqlnative/src/main/java/org/apache/hop/workflow/actions/mssqlbulkload/ActionMssqlBulkLoadDialog.java
b/plugins/databases/mssqlnative/src/main/java/org/apache/hop/workflow/actions/mssqlbulkload/ActionMssqlBulkLoadDialog.java
index 54333afa1f..0768ee0369 100644
---
a/plugins/databases/mssqlnative/src/main/java/org/apache/hop/workflow/actions/mssqlbulkload/ActionMssqlBulkLoadDialog.java
+++
b/plugins/databases/mssqlnative/src/main/java/org/apache/hop/workflow/actions/mssqlbulkload/ActionMssqlBulkLoadDialog.java
@@ -27,6 +27,7 @@ import org.apache.hop.core.row.IRowMeta;
import org.apache.hop.core.util.Utils;
import org.apache.hop.core.variables.IVariables;
import org.apache.hop.i18n.BaseMessages;
+import org.apache.hop.metadata.api.IEnumHasCodeAndDescription;
import org.apache.hop.ui.core.PropsUi;
import org.apache.hop.ui.core.database.dialog.DatabaseExplorerDialog;
import org.apache.hop.ui.core.dialog.BaseDialog;
@@ -465,10 +466,7 @@ public class ActionMssqlBulkLoadDialog extends
ActionDialog {
fdlCodePage.top = new FormAttachment(0, margin);
wlCodePage.setLayoutData(fdlCodePage);
wCodePage = new CCombo(wAdvancedComp, SWT.SINGLE | SWT.READ_ONLY |
SWT.BORDER);
- wCodePage.add("ACP");
- wCodePage.add("OEM");
- wCodePage.add("RAW");
- wCodePage.add(BaseMessages.getString(PKG,
"ActionMssqlBulkLoad.CodePage.Specific"));
+
wCodePage.setItems(IEnumHasCodeAndDescription.getDescriptions(MssqlBulkLoadCodePage.class));
wCodePage.select(0); // +1: starts at -1
PropsUi.setLook(wCodePage);
@@ -1009,7 +1007,7 @@ public class ActionMssqlBulkLoadDialog extends
ActionDialog {
}
private void setCodeType() {
- if (wCodePage.getSelectionIndex() == 3) {
+ if (MssqlBulkLoadCodePage.lookup(wCodePage.getText()) ==
MssqlBulkLoadCodePage.SPECIFIC) {
wSpecificCodePage.setEnabled(true);
wlSpecificCodePage.setEnabled(true);
} else {
@@ -1042,7 +1040,10 @@ public class ActionMssqlBulkLoadDialog extends
ActionDialog {
if (action.getLineTerminated() != null) {
wLineterminated.setText(action.getLineTerminated());
}
- if (action.getCodePage() != null) {
+ MssqlBulkLoadCodePage codePage =
MssqlBulkLoadCodePage.lookup(action.getCodePage());
+ if (codePage != null) {
+ wCodePage.setText(codePage.getDescription());
+ } else if (action.getCodePage() != null) {
wCodePage.setText(action.getCodePage());
} else {
wCodePage.setText("RAW");
@@ -1118,7 +1119,9 @@ public class ActionMssqlBulkLoadDialog extends
ActionDialog {
action.setDataFileType(wDataFiletype.getText());
action.setFieldTerminator(wFieldTerminator.getText());
action.setLineTerminated(wLineterminated.getText());
- action.setCodePage(wCodePage.getText());
+ // Store the code, not the label: the label is translated
+ MssqlBulkLoadCodePage codePage =
MssqlBulkLoadCodePage.lookup(wCodePage.getText());
+ action.setCodePage(codePage == null ? wCodePage.getText() :
codePage.getCode());
action.setSpecificCodePage(wSpecificCodePage.getText());
action.setFormatFileName(wFormatFilename.getText());
action.setFireTriggers(wFireTriggers.getSelection());
diff --git
a/plugins/databases/mssqlnative/src/main/java/org/apache/hop/workflow/actions/mssqlbulkload/MssqlBulkLoadCodePage.java
b/plugins/databases/mssqlnative/src/main/java/org/apache/hop/workflow/actions/mssqlbulkload/MssqlBulkLoadCodePage.java
new file mode 100644
index 0000000000..da7dc90f2d
--- /dev/null
+++
b/plugins/databases/mssqlnative/src/main/java/org/apache/hop/workflow/actions/mssqlbulkload/MssqlBulkLoadCodePage.java
@@ -0,0 +1,90 @@
+/*
+ * 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.mssqlbulkload;
+
+import java.util.List;
+import java.util.regex.Pattern;
+import org.apache.hop.i18n.BaseMessages;
+import org.apache.hop.metadata.api.IEnumHasCodeAndDescription;
+
+/** The CODEPAGE option of the BULK INSERT statement. */
+public enum MssqlBulkLoadCodePage implements IEnumHasCodeAndDescription {
+ ACP("ACP", null),
+ OEM("OEM", null),
+ RAW("RAW", null),
+ /** The value of Specific codepage is sent. "Specific" is the value stored
before #9167. */
+ SPECIFIC("Specific", "ActionMssqlBulkLoad.CodePage.Specific");
+
+ private static final Class<?> PKG = ActionMssqlBulkLoad.class;
+
+ /**
+ * Older dialogs stored the translated label of Specific: fr_FR, es_AR and
pt_BR, it_IT, ja_JP,
+ * zh_CN.
+ */
+ private static final List<String> LEGACY_SPECIFIC_LABELS =
+ List.of("Spécifique", "Específico", "Specifico", "任意", "自定义");
+
+ /** What SQL Server accepts as CODEPAGE: a code page number, ACP, OEM or
RAW. */
+ private static final Pattern VALID_CODE_PAGE =
+ Pattern.compile("\\d+|ACP|OEM|RAW", Pattern.CASE_INSENSITIVE);
+
+ private final String code;
+ private final String descriptionKey;
+
+ MssqlBulkLoadCodePage(String code, String descriptionKey) {
+ this.code = code;
+ this.descriptionKey = descriptionKey;
+ }
+
+ @Override
+ public String getCode() {
+ return code;
+ }
+
+ @Override
+ public String getDescription() {
+ return descriptionKey == null ? code : BaseMessages.getString(PKG,
descriptionKey);
+ }
+
+ /**
+ * Find the code page for a stored value or a label shown in the dialog.
+ *
+ * @return the code page, or null when the value is empty or unknown
+ */
+ public static MssqlBulkLoadCodePage lookup(String value) {
+ if (value == null || value.isEmpty()) {
+ return null;
+ }
+ for (MssqlBulkLoadCodePage codePage : values()) {
+ if (codePage.code.equalsIgnoreCase(value)
+ || codePage.name().equalsIgnoreCase(value)
+ || codePage.getDescription().equalsIgnoreCase(value)) {
+ return codePage;
+ }
+ }
+ if (LEGACY_SPECIFIC_LABELS.contains(value)) {
+ return SPECIFIC;
+ }
+ return null;
+ }
+
+ /** True when SQL Server accepts the value as CODEPAGE, so it can go into
the statement. */
+ public static boolean isValidCodePage(String value) {
+ return value != null && VALID_CODE_PAGE.matcher(value.trim()).matches();
+ }
+}
diff --git
a/plugins/databases/mssqlnative/src/main/resources/org/apache/hop/workflow/actions/mssqlbulkload/messages/messages_en_US.properties
b/plugins/databases/mssqlnative/src/main/resources/org/apache/hop/workflow/actions/mssqlbulkload/messages/messages_en_US.properties
index caeb2b971c..27fa0f15dc 100644
---
a/plugins/databases/mssqlnative/src/main/resources/org/apache/hop/workflow/actions/mssqlbulkload/messages/messages_en_US.properties
+++
b/plugins/databases/mssqlnative/src/main/resources/org/apache/hop/workflow/actions/mssqlbulkload/messages/messages_en_US.properties
@@ -30,12 +30,14 @@ ActionMssqlBulkLoad.DataFileGroup.Group.Label=Data File
ActionMssqlBulkLoad.Description=Load data from a file into a MSSQL table
ActionMssqlBulkLoad.EndFile.Label=End at line
ActionMssqlBulkLoad.EndFile.Tooltip=Consider end of file where specified line
was reached.
+ActionMssqlBulkLoad.Error.ConnectionNotFound=Connection [{0}] does not exist.
ActionMssqlBulkLoad.Error.DbNotMSSQL=Target database {0} is not a MSSQL
Database!
ActionMssqlBulkLoad.Error.ErrorFileExists=Error file already exists!The error
file is created when the command is executed. Please delete it or check ''Add
date time" option!
ActionMssqlBulkLoad.Error.FieldTerminatorMissing=Field terminator is missing!
ActionMssqlBulkLoad.Error.FileNotExists=File [{0}] does not exist!
ActionMssqlBulkLoad.Error.OnlyLocalFileSupported=Only local files are
supported at this time, file [{0}] is not a local file.
-ActionMssqlBulkLoad.Error.SpecificCodePageMissing=Specific code page is
missing! Please specify a value greater than 127 or less than 32.
+ActionMssqlBulkLoad.Error.SpecificCodePageInvalid=Specific codepage [{0}] is
not a code page number, ACP, OEM or RAW.
+ActionMssqlBulkLoad.Error.SpecificCodePageMissing=Specific codepage is empty:
use a code page number, ACP, OEM or RAW.
ActionMssqlBulkLoad.Error.TableNotExists=Table [{0}] does not exist!
ActionMssqlBulkLoad.FieldTerminator.Label=Fields terminated by
ActionMssqlBulkLoad.FieldTerminator.Tooltip=Specifies the field terminator to
be used for char and widechar data files. The default field terminator is \t
(tab character)
diff --git
a/plugins/databases/mssqlnative/src/test/java/org/apache/hop/workflow/actions/mssqlbulkload/ActionMssqlBulkLoadCheckTest.java
b/plugins/databases/mssqlnative/src/test/java/org/apache/hop/workflow/actions/mssqlbulkload/ActionMssqlBulkLoadCheckTest.java
index 3da1ac4c0e..b1d4be4f5f 100644
---
a/plugins/databases/mssqlnative/src/test/java/org/apache/hop/workflow/actions/mssqlbulkload/ActionMssqlBulkLoadCheckTest.java
+++
b/plugins/databases/mssqlnative/src/test/java/org/apache/hop/workflow/actions/mssqlbulkload/ActionMssqlBulkLoadCheckTest.java
@@ -17,6 +17,7 @@
package org.apache.hop.workflow.actions.mssqlbulkload;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.nio.file.Files;
@@ -52,6 +53,41 @@ class ActionMssqlBulkLoadCheckTest {
assertTrue(errors(remarks).isEmpty(), () -> errors(remarks).toString());
}
+ @Test
+ void checkReportsEmptySpecificCodepage() throws Exception {
+ assertEquals(1, errors(checkSpecificCodePage("", new Variables())).size());
+ }
+
+ @Test
+ void checkReportsSpecificCodepageThatIsNotACodepage() throws Exception {
+ assertEquals(1, errors(checkSpecificCodePage("65001'", new
Variables())).size());
+ }
+
+ @Test
+ void checkAcceptsSpecificCodepageNumberOrVariable() throws Exception {
+ Variables variables = new Variables();
+ variables.setVariable("CP", "1252");
+
+ assertTrue(errors(checkSpecificCodePage("65001", variables)).isEmpty());
+ assertTrue(errors(checkSpecificCodePage("${CP}", variables)).isEmpty());
+ // Only known at run time
+ assertTrue(errors(checkSpecificCodePage("${NOT_SET_YET}",
variables)).isEmpty());
+ }
+
+ private List<ICheckResult> checkSpecificCodePage(String specificCodePage,
Variables variables)
+ throws Exception {
+ Path dataFile = Files.writeString(tempDir.resolve("customers.csv"), "a\n");
+ ActionMssqlBulkLoad action = new ActionMssqlBulkLoad();
+ action.setFileName(dataFile.toAbsolutePath().toString());
+ action.setTableName("customers");
+ action.setCodePage("Specific");
+ action.setSpecificCodePage(specificCodePage);
+
+ List<ICheckResult> remarks = new ArrayList<>();
+ action.check(remarks, null, variables, null);
+ return remarks;
+ }
+
private static List<String> errors(List<ICheckResult> remarks) {
List<String> errors = new ArrayList<>();
for (ICheckResult remark : remarks) {
diff --git
a/plugins/databases/mssqlnative/src/test/java/org/apache/hop/workflow/actions/mssqlbulkload/ActionMssqlBulkLoadExecuteTest.java
b/plugins/databases/mssqlnative/src/test/java/org/apache/hop/workflow/actions/mssqlbulkload/ActionMssqlBulkLoadExecuteTest.java
new file mode 100644
index 0000000000..756c348755
--- /dev/null
+++
b/plugins/databases/mssqlnative/src/test/java/org/apache/hop/workflow/actions/mssqlbulkload/ActionMssqlBulkLoadExecuteTest.java
@@ -0,0 +1,212 @@
+/*
+ * 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.mssqlbulkload;
+
+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.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+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 #9167: the BULK INSERT statement and the result of the checks that
stop the load. */
+class ActionMssqlBulkLoadExecuteTest {
+ @RegisterExtension
+ static RestoreHopEngineEnvironmentExtension env = new
RestoreHopEngineEnvironmentExtension();
+
+ @TempDir Path tempDir;
+
+ @BeforeAll
+ static void setUpBeforeClass() throws HopException {
+ HopEnvironment.init();
+ }
+
+ @Test
+ void specificCodepageSendsTheValue() throws Exception {
+ ActionMssqlBulkLoad action = newAction("MSSQLNATIVE");
+ action.setCodePage("Specific");
+ action.setSpecificCodePage("65001");
+
+ String sql = runAndCaptureSql(action);
+
+ assertTrue(sql.contains("CODEPAGE = '65001'"), sql);
+ assertFalse(sql.contains("Specific"), sql);
+ }
+
+ @Test
+ void specificCodepageSavedByATranslatedDialogSendsTheValue() throws
Exception {
+ ActionMssqlBulkLoad action = newAction("MSSQLNATIVE");
+ action.setCodePage("Spécifique");
+ action.setSpecificCodePage("1252");
+
+ String sql = runAndCaptureSql(action);
+
+ assertTrue(sql.contains("CODEPAGE = '1252'"), sql);
+ }
+
+ @Test
+ void specificCodepageFromAVariableSendsTheValue() throws Exception {
+ ActionMssqlBulkLoad action = newAction("MSSQLNATIVE");
+ action.setCodePage("Specific");
+ action.setSpecificCodePage("${CP}");
+ action.setVariable("CP", "raw");
+
+ String sql = runAndCaptureSql(action);
+
+ assertTrue(sql.contains("CODEPAGE = 'raw'"), sql);
+ }
+
+ @Test
+ void otherCodepageIsSentAsIs() throws Exception {
+ ActionMssqlBulkLoad action = newAction("MSSQLNATIVE");
+ action.setCodePage("RAW");
+ action.setSpecificCodePage("65001");
+
+ String sql = runAndCaptureSql(action);
+
+ assertTrue(sql.contains("CODEPAGE = 'RAW'"), sql);
+ assertFalse(sql.contains("65001"), sql);
+ }
+
+ @Test
+ void specificCodepageThatIsNotACodepageIsOneError() throws Exception {
+ ActionMssqlBulkLoad action = newAction("MSSQLNATIVE");
+ action.setCodePage("Specific");
+ action.setSpecificCodePage("${CP}");
+ action.setVariable("CP", "65001', FIRE_TRIGGERS --");
+
+ assertOneErrorWithoutLoad(action);
+ }
+
+ @Test
+ void startAndEndLineAreBothSent() throws Exception {
+ ActionMssqlBulkLoad action = newAction("MSSQLNATIVE");
+ action.setStartFile(2);
+ action.setEndFile(3);
+
+ String sql = runAndCaptureSql(action);
+
+ assertTrue(sql.contains(",FIRSTROW=2,LASTROW=3,"), sql);
+ }
+
+ @Test
+ void notAnMssqlConnectionIsOneError() throws Exception {
+ assertOneErrorWithoutLoad(newAction("MYSQL"));
+ }
+
+ @Test
+ void unknownConnectionIsOneError() throws Exception {
+ ActionMssqlBulkLoad action = newAction("MSSQLNATIVE");
+ action.setConnection("does-not-exist");
+
+ assertOneErrorWithoutLoad(action);
+ }
+
+ @Test
+ void emptyFieldTerminatorIsOneError() throws Exception {
+ ActionMssqlBulkLoad action = newAction("MSSQLNATIVE");
+ action.setFieldTerminator("");
+
+ assertOneErrorWithoutLoad(action);
+ }
+
+ @Test
+ void emptySpecificCodepageIsOneError() throws Exception {
+ ActionMssqlBulkLoad action = newAction("MSSQLNATIVE");
+ action.setCodePage("Specific");
+ action.setSpecificCodePage("");
+
+ assertOneErrorWithoutLoad(action);
+ }
+
+ @Test
+ void existingErrorFileWithoutDateTimeIsOneError() throws Exception {
+ ActionMssqlBulkLoad action = newAction("MSSQLNATIVE");
+ Path errorFile = Files.writeString(tempDir.resolve("errors.txt"), "");
+ action.setErrorFileName(errorFile.toAbsolutePath().toString());
+ action.setAddDatetime(false);
+
+ assertOneErrorWithoutLoad(action);
+ }
+
+ private ActionMssqlBulkLoad newAction(String pluginId) throws Exception {
+ Path dataFile = Files.writeString(tempDir.resolve("customers.csv"),
"1;a\n2;b\n3;c\n");
+ ActionMssqlBulkLoad action = new ActionMssqlBulkLoad("bulkload");
+ action.setFileName(dataFile.toAbsolutePath().toString());
+ action.setTableName("customers");
+ action.setFieldTerminator(";");
+ action.setConnection("mssql");
+
+ DatabaseMeta databaseMeta = mock(DatabaseMeta.class);
+ when(databaseMeta.getPluginId()).thenReturn(pluginId);
+ WorkflowMeta workflowMeta = mock(WorkflowMeta.class);
+ when(workflowMeta.findDatabase(eq("mssql"),
any())).thenReturn(databaseMeta);
+ action.setParentWorkflowMeta(workflowMeta);
+ return action;
+ }
+
+ private static MockedConstruction<Database> mockDatabases() {
+ return mockConstruction(
+ Database.class, (db, context) -> when(db.checkTableExists(any(),
any())).thenReturn(true));
+ }
+
+ private static String runAndCaptureSql(ActionMssqlBulkLoad action) throws
Exception {
+ try (MockedConstruction<Database> databases = mockDatabases()) {
+ Result result = action.execute(new Result(), 0);
+
+ assertTrue(result.getResult());
+ assertEquals(0, result.getNrErrors());
+ ArgumentCaptor<String> sql = ArgumentCaptor.forClass(String.class);
+ verify(databases.constructed().get(0)).execStatement(sql.capture());
+ return sql.getValue();
+ }
+ }
+
+ private static void assertOneErrorWithoutLoad(ActionMssqlBulkLoad action)
throws Exception {
+ try (MockedConstruction<Database> databases = mockDatabases()) {
+ Result result = action.execute(new Result(), 0);
+
+ assertFalse(result.getResult());
+ assertEquals(1, result.getNrErrors());
+ for (Database db : databases.constructed()) {
+ verify(db, never()).execStatement(anyString());
+ }
+ }
+ }
+}
diff --git
a/plugins/databases/mssqlnative/src/test/java/org/apache/hop/workflow/actions/mssqlbulkload/MssqlBulkLoadCodePageTest.java
b/plugins/databases/mssqlnative/src/test/java/org/apache/hop/workflow/actions/mssqlbulkload/MssqlBulkLoadCodePageTest.java
new file mode 100644
index 0000000000..0c6660f05a
--- /dev/null
+++
b/plugins/databases/mssqlnative/src/test/java/org/apache/hop/workflow/actions/mssqlbulkload/MssqlBulkLoadCodePageTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.mssqlbulkload;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.Test;
+
+class MssqlBulkLoadCodePageTest {
+
+ @Test
+ void storedValuesAreFound() {
+ assertEquals(MssqlBulkLoadCodePage.ACP,
MssqlBulkLoadCodePage.lookup("ACP"));
+ assertEquals(MssqlBulkLoadCodePage.OEM,
MssqlBulkLoadCodePage.lookup("OEM"));
+ assertEquals(MssqlBulkLoadCodePage.RAW,
MssqlBulkLoadCodePage.lookup("RAW"));
+ assertEquals(MssqlBulkLoadCodePage.SPECIFIC,
MssqlBulkLoadCodePage.lookup("Specific"));
+ assertEquals(MssqlBulkLoadCodePage.SPECIFIC,
MssqlBulkLoadCodePage.lookup("SPECIFIC"));
+ assertNull(MssqlBulkLoadCodePage.lookup(null));
+ assertNull(MssqlBulkLoadCodePage.lookup(""));
+ }
+
+ @Test
+ void specificIsStoredAsSpecific() {
+ // English projects already store "Specific"
+ assertEquals("Specific", MssqlBulkLoadCodePage.SPECIFIC.getCode());
+ }
+
+ @Test
+ void translatedSpecificLabelsFromOlderDialogsAreFound() {
+ for (String label : new String[] {"Spécifique", "Específico", "Specifico",
"任意", "自定义"}) {
+ assertEquals(MssqlBulkLoadCodePage.SPECIFIC,
MssqlBulkLoadCodePage.lookup(label), label);
+ }
+ }
+
+ @Test
+ void onlyWhatSqlServerAcceptsIsAValidCodePage() {
+ assertTrue(MssqlBulkLoadCodePage.isValidCodePage("65001"));
+ assertTrue(MssqlBulkLoadCodePage.isValidCodePage("raw"));
+ assertTrue(MssqlBulkLoadCodePage.isValidCodePage(" 1252 "));
+ assertFalse(MssqlBulkLoadCodePage.isValidCodePage(null));
+ assertFalse(MssqlBulkLoadCodePage.isValidCodePage("UTF-8"));
+ assertFalse(MssqlBulkLoadCodePage.isValidCodePage("65001', FIRE_TRIGGERS
--"));
+ }
+}