dbeaver / dbeaver

Free universal database tool and SQL client
https://dbeaver.io
Apache License 2.0
40.58k stars 3.5k forks source link

SQL Script Executor task dose not applied project or file encoding settings #36069

Open 10sa opened 3 weeks ago

10sa commented 3 weeks ago

Description

Summary

About the Files.newBufferedReader method used in line 191 of the SQLScriptExecuteHandler class, those method always reading file as UTF-8 encoding whatever file.encoding jvm arguement is or project/file settings. (See #javadoc)

By this behavior, Non UTF-8 Encoded script file cannot be run as SQL Script task by next encoding error.

Expected behavior

Run script as DBeaver project settings or file property encodings.

Possible solution

Get encoding from DBeaver project settings or DBeaver file property and using it when read scripts

Logs

2024-10-26 09:02:14.507 - Task 'Test' (1525aebc-108a-44dd-8d66-36c3e80dd52d) started
2024-10-26 09:02:14.507 - SQL Scripts Execute
2024-10-26 09:02:14.507 - org.jkiss.dbeaver.DBException: Error executing script 'Scripts/NonUTF8SQLScript.sql'
    at org.jkiss.dbeaver.tools.sql.task.SQLScriptExecuteHandler.runScripts(SQLScriptExecuteHandler.java:147)
    at org.jkiss.dbeaver.tools.sql.task.SQLScriptExecuteHandler.lambda$0(SQLScriptExecuteHandler.java:96)
    at org.jkiss.dbeaver.registry.task.TaskRunJob.run(TaskRunJob.java:157)
    at org.jkiss.dbeaver.tools.sql.task.SQLScriptExecuteHandler.executeWithSettings(SQLScriptExecuteHandler.java:94)
    at org.jkiss.dbeaver.tools.sql.task.SQLScriptExecuteHandler.executeTask(SQLScriptExecuteHandler.java:75)
    at org.jkiss.dbeaver.registry.task.TaskRunJob.executeTask(TaskRunJob.java:143)
    at org.jkiss.dbeaver.registry.task.TaskRunJob.run(TaskRunJob.java:104)
    at org.jkiss.dbeaver.model.runtime.AbstractJob.run(AbstractJob.java:117)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: java.nio.charset.MalformedInputException: Input length = 1
    at java.base/java.nio.charset.CoderResult.throwException(Unknown Source)
    at java.base/sun.nio.cs.StreamDecoder.implRead(Unknown Source)
    at java.base/sun.nio.cs.StreamDecoder.read(Unknown Source)
    at java.base/java.io.InputStreamReader.read(Unknown Source)
    at java.base/java.io.BufferedReader.fill(Unknown Source)
    at java.base/java.io.BufferedReader.read1(Unknown Source)
    at java.base/java.io.BufferedReader.read(Unknown Source)
    at java.base/java.io.Reader.read(Unknown Source)
    at org.jkiss.utils.IOUtils.readToString(IOUtils.java:281)
    at org.jkiss.dbeaver.tools.sql.task.SQLScriptExecuteHandler.readScriptContents(SQLScriptExecuteHandler.java:192)
    at org.jkiss.dbeaver.tools.sql.task.SQLScriptExecuteHandler.runScripts(SQLScriptExecuteHandler.java:120)
    ... 8 more
2024-10-26 09:02:14.508 - SQL script execute completed
2024-10-26 09:02:14.508 - Task 'Test' (1525aebc-108a-44dd-8d66-36c3e80dd52d) finished with errors in 1 ms

Used SQL Scripts

DBeaver Version

Community Edition 24.2.3

Operating System

No response

Database and driver

No response

Steps to reproduce

  1. Create Non UTF-8 SQL Script
  2. Create SQL Script database task with Non UTF-8 encoded SQL script and run

Additional context

I'm willing to fix this issue myself and post a PR if DBeaver team allowed.

ShadelessFox commented 3 weeks ago

Thanks for the bug report.