vscode-database-client icon indicating copy to clipboard operation
vscode-database-client copied to clipboard

[BUG] Dump SQL Server encoding error

Open Drilmo opened this issue 9 months ago • 4 comments

I think there's an encoding error when dumping the structure and the data, in fact in the inserts for the values & I had & on nvarchar which crashed the insert request, I had to apply a replace following the following regex :

(N'(?:[^']|'')&)(amp;)((?:[^']|'')')

And replace with group 1 and 3 to remove the amp;

Drilmo avatar Mar 14 '25 09:03 Drilmo

The single quote ' is not escaped. What other wrong symbols have you encountered? I will fix it in the next version.

cweijan avatar Mar 14 '25 16:03 cweijan

When the value contain & he is exported as & and it not work on insert.

Another problem, when I dump structure and data, in the create table all field names are enclosed in double quotes, but not in insert into, which poses a problem when there are spaces or ' in the field name when inserting into. You'd have to either enclose them in “ or square brackets.

Drilmo avatar Mar 18 '25 08:03 Drilmo

sorry but GitHub changed the value displayed I correct my comment :

When the value contain & he is exported as & and it not work on insert.

Another problem, when I dump structure and data, in the create table all field names are enclosed in double quotes, but not in insert into, which poses a problem when there are spaces or ' in the field name when inserting into. You'd have to either enclose them in “ or square brackets.

Drilmo avatar Apr 10 '25 07:04 Drilmo

Currently, to resolve some problems encountered during dumping, I apply these replacements via regex in the insert section

tools.regex_to_replace_in_file(insert_file, r"([^(N',])'([^,')])", r"\1''\2")
tools.regex_to_replace_in_file(insert_file, r"(N'N)'[^',]", r"\1''")
tools.regex_to_replace_in_file(insert_file, r"(N'(?:[^']|'')*&)(amp;)((?:[^']|'')*')", r"\1\3")

Drilmo avatar Apr 10 '25 08:04 Drilmo