dalibo / sqlserver2pgsql

Migration tool to convert a Microsoft SQL Server Database into a PostgreSQL database, as automatically as possible
http://dalibo.github.io/sqlserver2pgsql
GNU General Public License v3.0
515 stars 117 forks source link

Opening USE [master] line not understood #154

Closed maresb closed 3 years ago

maresb commented 3 years ago

The first two lines of my MS SQL script are

USE [master]
GO

I'm encountering the following bug:

$ sqlserver2pgsql/sqlserver2pgsql.pl -f db.schema.sql -b output_before_script -a output_after_script -u output_unsure_script

Wide character in die at sqlserver2pgsql/sqlserver2pgsql.pl line 2470, <$file> line 1.
Line <USE [master]
> (1) not understood. This is a bug at sqlserver2pgsql/sqlserver2pgsql.pl line 2470, <$file> line 1.

The error occurs on this line and from what I can tell, the parentheses in this line seem to be preventing the match.

My perl is unfortunately fairly rusty, so I'm not sure how to fix this, or even why I'm getting this error in the first place.

More info:

$ file db.schema.sql && uname -a && perl --version
db.schema.sql: UTF-8 Unicode (with BOM) text, with very long lines
Linux 6a37df95ea7c 5.8.0-50-generic #56~20.04.1-Ubuntu SMP Mon Apr 12 21:46:35 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

This is perl 5, version 30, subversion 0 (v5.30.0) built for x86_64-linux-gnu-thread-multi
(with 50 registered patches, see perl -V for more detail)
...
lisa-ellevation commented 3 years ago

I ran into this when the encoding on my sql file was wrong

maresb commented 3 years ago

Thanks @lisa-ellevation. The script was choking on the UTF-8 BOM. (I generated the .sql script with mssql-scripter).

I wrote a PR with a quick fix.

madtibo commented 3 years ago

Hello @maresb

The MS SQL scripts are usually in UTF-16. It is nice if UTF-8 can be understood as well. Let's review your PR :-)

madtibo commented 3 years ago

Thanks for the ticket and the fix!

bonne soirée