mickeypearce/oradew-vscode

Windows econding UTF8 problem

Danieleeee opened this issue · 42 comments

Hi,
I have a package that if I run as a script (f5) does not give errors.
If I only run the final part (Run Selected statement) of the package, where the grants are, I get errors.

image

image

I have similar errors if I don't set the correct econding (utf-8)

Hi, do you use sqlplus or sqlcl?

sqlplus

If you can I suggest you always force encoding on utf-8 with sqlplus.
It is the only one who works correctly.

Take a look at #28 (comment) and followed comments.

It doesn't solve my problem.
There is a bug with running the selection.
I created a file with this code:

GRANT EXECUTE ON CONF_SET_VAL_TIPI_CONN_SVI TO NETAINF;
GRANT EXECUTE ON CONF_SET_VAL_TIPI_CONN_SVI TO SIU;

If I run it with f5 (run as script) it works, with Run Selected Statement, no.
If I delete only one of the two lines, the execution is performed correctly, with both lines not.

It appears that it cannot execute the two selected lines. If I select only one, it works.
The error is as follows:
ORA-00933: SQL command not properly ended
Reported at the end of the first line

Correct. A command like "Run Selected Block as a Script" is missing or a proper parser to compile a multi-statement code.

Hi,
for the problem with utf8 encoding there is no solution (#42 (comment)).
My oracle DB doesn't use utf8 encoding, but sqlplus uses it instead.
I tried to enter this configuration but nothing changes:
"oradew.envVariables": {
"NLS_LANG": "ITALIAN_ITALY.WE8MSWIN1252",
}

Have you tried setting "source.encoding" to "win1252"? Import object again after that to correctly encode it. This is what I use.

the encoding of the file is correctly windows1252, like Oracle configuration.
when launched to DB from sqlplus (f5), UTF8 encoding is always applied and special characters such as this § are not encoded correctly.
are you sure that the parameterization "oradew.envVariables" is taken correctly?

Is there no way to tell sqlplus not to apply UTF8 encoding, but Windows1252?

I am not sure, I thought this was the case with setting nls_lang variable based on a user's comment, but I don't use it. I use win1250 encoded files to run to win1250 DB and it works, but I also have win1250 default lang on my OS system, which I think is the encoding that sqlplus applies. I guess in your case default OS encoding is UTF-8.
What about using UTF-8 encoded files? Is there a way you normally do to run a file with just sqlplus that works for you?

The system language is ITALIAN_ITALY.WE8MSWIN1252
The files are launched correctly on the DB, not by execution error. But if they are then opened, if there are special characters in some comments or strings, they are badly coded.

Hmm. Check also the vscode encoding in which the file is open - in the right bottom corner of status panel.

So you launch with sqlplus a file written with win1250 encoding, on an Oracle DB with NLS_CHARACTERSET = win1250 and the special characters like this "§" are not altered?

That's right, I use many ČŠŽ in comments and other "strange" chars. My Win OS codepage is also 1250. I use sqlcl now but it worked with sqlplus also. Have you tried running files encoded in UTF-8?

it seems the problem is in Oracle's charset, other than UTF8.
what is your Oracle DB NLS_CHARACTERSET?

That shouldn't be the case, my charset on DB is also .WE8MSWIN1250.
Take a look at: https://dba.stackexchange.com/questions/207537/problem-with-charset-on-sqlplus maybe you will got some idea.

It seems a problem related to machines that use Windows.
You should fix this by placing this code before the call to SQLPlus

C:\>chcp 1252
C:\>set NLS_LANG=.WE8MSWIN1252

i verified that by entering those two commands before running sqlplus, everything works fine

In my case just give:
chcp 1252

Can you create a parameter that makes me enter "chcp" before executing the sql code?

#28 (comment)

Take a look at this comment. You create a sql.bat file and then set setting "oradew.cliExecutable": "sql.bat" to execute with parameters through this bat script...

Please let me know if you can make it work. 🤞

ok, thanks.
If anyone wants to implement automatically, these are the two configurations to be given depending on whether you are using windows1252 or UTF8:

- windows1252
chcp 1252
set NLS_LANG = .WE8MSWIN1252
- UTF8
chcp 65001
set NLS_LANG = .UTF8

I created a bat with this but it doesn't work. the plsql instruction appears to be executed in a different session.
bat file:

chcp 1252
set NLS_LANG = .WE8MSWIN1252
sqlplus UTE/PASS@DBNAME @"File.sql"

if I set this bat, Oradew ask me user and password for sqlplus:

chcp 1252
set NLS_LANG = .WE8MSWIN1252
sqlplus

Write
sqlplus %*
As in example so that parameters are passed through...

ok, thanks.
Whit this bat it works:

chcp 1252 
set NLS_LANG=.WE8MSWIN1252
sqlplus %*

without NLS_LANG it doesn't work, even if I set the value inside "oradew.envVariables"

Thanks for your info. This is a workaround to pass variables to executable.

Maybe we can add this solution to documentation or Howto's for others to easly find it, so @Danieleeee if you feel like contributing, please go ahead!

If you are satisfied you can also consider just adding a star to this project. :)

because of you.
star added ;)

Note that this solution does not work in the "compile current file" command, only in "Run ad Script (f5)".
It would be helpful to fix it. It should occur on all Windows machines that have ANSI codepages.

Have you tried setting "source.encoding" to "win1252"? Import object again after that to correctly encode it. This is what I use.

Compile task uses different method. chcp doesn't have any means here as node-oracledb executes always in UTF-8 and doesn't bother about system codepages.
Setting "source.encoding" parameter is here so that oradew first decodes file content from file encoding to UTF-8 before compiling, and encodes it back after importing.
But it doesn't work for you?

the problem is that they are always executed in UTF8.
It gives problems with the code page of the machine, if we are on windows and the file (and Oracle DB) we are executing is not encoded in UTF8.
if you have a windows machine you can give it a try.

I use it all the time and it works as I explained in the comment above. Have you tried exporting existing object from db, then adding some comments and compile again?

No, I'm always working with the same file written in Windows1252.
If I compile it gives problems with the coding, if I run it as a script no because I use the bat with chcp 1252.

Can you send an example file so I can reproduce? And please describe what is that you do, f.ex. compile a specific char in comments and then not expected result on DB, etc...

I can't attach a file.sql so i write it here.

CREATE OR REPLACE PACKAGE TEST_PCK AS

  v_test   varchar2(100):= '§';
 
END TEST_PCK;
/

Put it in a file with windows1252 encoding.
Run the Oradew "Compile Current File" command.
If the DB has Windows1252 encoding, you will not correctly see the '§' character.
Processing is launched from a Windows 10 machine

Strange. NLS_LANG on my DB is .EE8MSWIN1250, I made a file encoded in Windows 1252 exactly as you suggested, compiled, checked on DB and it is '§'.
I have "source.encoding": "win1250", in oradewrc.json file, if I remove that, I get '?' instead of '§' on DB.
I don't have set any environment variables for NLS_LANG with "oradew.envVariables" or anywhere else...

yes, if i use oradewrc.json it works.
Thanks

Last thing, because when I import a package it writes: "CREATE OR REPLACE EDITIONABLE PACKAGE BODY".
how do i delete "EDITIONABLE"?

This has to do with your database configuration - editions. I am not very familiar with this topic.

You can customize object DDL that is imported with oradewrc setting: import.getDdlFunction in a way that you write your own function to import objects...

@Danieleeee , I closed this issue, feel free to open a new one if you have more questions, bugs, etc.