Skip to content

Keep UTF-8 encoding when importing from the DB #1

@nickolay

Description

@nickolay

Thanks for putting this example up! It was encouraging to see that this approach can work.

One problem: the code that removes SET QUOTED_IDENTIFIERS in the mssql-scripter's output in _importdb.ps1 also changes the file encoding to the default Windows encoding (win-1251 in my case).

I use the following code adapted from StackOverflow instead:

$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding($False)
gci -Path ./Planning/*.sql | ForEach-Object {
  $fn = $_.FullName
  #write-host $fn
  $processed = ( Get-Content -Path $fn ) -replace 'SET.*(ON|OFF)$', ''
  [System.IO.File]::WriteAllLines($fn, $processed, $Utf8NoBomEncoding)
}

I also hope that mssql-scripter can learn not to include the SET statements in the first place - filed microsoft/mssql-scripter#208

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions