Skip to content

Initial version of go-sqlcmd #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Aug 26, 2021
Merged

Initial version of go-sqlcmd #1

merged 27 commits into from
Aug 26, 2021

Conversation

shueybubbles
Copy link
Collaborator

There's a LONG way to go but basic interactive mode with file output is ready for main!

What do we have in this version?

  • Custom batch separator (-c)
  • Windows and SQL auth support (-C, -d, -E, -P, -U)
  • Using environment variables as default values for some command line arguments (eg SQLCMDSERVER, SQLCMDPASSWORD)
  • Output to file (-O)
  • Interactive console mode
  • Multiline comments and quoted strings change the prompt to ~ like this:
1> select 'this is a multiline
2~ string
3~ see?'
4> /* this is a multiline
5~ comment */
  • Screen width limiting when SQLCMDCOLWIDTH > 0
    eg with SQLCMDCOLWIDTH == 10 before running go-sqlcmd:
1> select 'this is a long name is it not' as name
2> go
name


----------
----------
---------
this is a
long name
is it not
  • Go command, including repeat count
  • Out, Error commands to redirect output
  • Quit command

What's obviously missing or broken?

  • Printing of messages. Needs driver support first per Get SQL Server Messages / PRINT command denisenkom/go-mssqldb#221
  • anything related to using system- or user-default time formats. Golang seems to lack any way to query the system for the default format
  • Most commands
  • Variable evaluation
  • Input from files
  • Some SQL types don't render the same as native sqlcmd or even the same as ssms. Varbinary(max) acts differently in all 3.
select convert(varbinary(max), '123456') as mybinary

SSMS: 
mybinary
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
0x313233343536

(1 row affected)

SQLCMD seems to miscalculate column width for varbinary(max) and truncates it based on the column name length.

1> select convert(varbinary(max), '123456') as mybinary
2> go
mybinary
--------
0x313233

go-sqlcmd is not converting the data correctly. It'll need some debugging.

1>  select convert(varbinary(max), '123456') as mybinary
2> go
mybinary                                                                                                                                                                                                                                     
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
0x123456                  

@shueybubbles shueybubbles requested a review from ascarter August 12, 2021 17:13
Copy link
Collaborator

@ascarter ascarter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of structural and style comments. My biggest suggestion is to alter the overall project layout and adapt it to support your future utilities you described.

}

func InvalidFileError(err error, path string) error {
return errors.New(ErrorPrefix + " Error occurred while opening or operating on file " + path + " (Reason: " + err.Error() + ").")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use:

 return fmt.Errorf("%s Error occurred while opening or operating on file %q (Reason: %v).", ErrorPrefix, path, err)

sqlcmd/sqlcmd.go Outdated
var (
ErrExitRequested = errors.New("exit")
ErrNeedPassword = errors.New("need password")
ErrCtrlC = errors.New(sqlcmderrors.WarningPrefix + "The last operation was terminated because the user pressed CTRL+C")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use fmt.Errorf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MVP needed for first public release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants