microsoft / go-sqlcmd

The new sqlcmd, CLI for SQL Server and Azure SQL (winget install sqlcmd / sqlcmd create mssql / sqlcmd open ads)
https://learn.microsoft.com/sql/tools/sqlcmd/go-sqlcmd-utility
MIT License
323 stars 56 forks source link

Can't handle long strings #437

Closed CaledoniaProject closed 11 months ago

CaledoniaProject commented 11 months ago

What should I do with bufio.scanner: token too long? Can you use a unbuffered reader?

shueybubbles commented 11 months ago

Can you please provide the steps to reproduce the issue? Is it with interactive mode or from an input file or both?

CaledoniaProject commented 11 months ago

I just run sqlcmd -S XXX -C -i XXX.sql and it prints tons of bufio error. The ubuntu sqlcmd binary package does not suffer from this.

shueybubbles commented 11 months ago

For any size of xxx.sql? Or for a certain batch size inside the file? What OS and sqlcmd version combination are you using?

CaledoniaProject commented 11 months ago

I have completely no idea, because you're not printing the line number. I also think you don't have to know the size of the SQL file.

  1. You're using a fixed buffer size: https://github.com/microsoft/go-sqlcmd/blob/main/pkg/sqlcmd/sqlcmd.go#L42
  2. The solution is easily found on stackoverflow: https://stackoverflow.com/questions/21124327

If you want to produce the issue, you could create a large blob, e.g 100MB to test it. My input file is exported from a SQLServer. I believe that line is longer than your buffer size, unless there's a line number in the error output, I have no idea which line is the problem. But looks like at least 1000 lines is longer than that.

shueybubbles commented 11 months ago

thx for the pointer, we'll take a look