Skip to content

Implement :ED #146

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 5 commits into from
Oct 13, 2022
Merged

Implement :ED #146

merged 5 commits into from
Oct 13, 2022

Conversation

shueybubbles
Copy link
Collaborator

:ed is a system command

e:\git\go-sqlcmd\cmd\sqlcmd>sqlcmd -S davidshi-2019 -X
1> ed
Sqlcmd: Error: ED and !!<command> commands, startup script, and environment variables are disabled.

Also, preserve blank lines from input.

Pre-fix:

e:\git\go-sqlcmd\cmd\sqlcmd>.\sqlcmd
1> select 100
2>
2>
2>
2>
2> select 200
3> :list
select 100
select 200
3>

ODBC:

e:\git\go-sqlcmd\cmd\sqlcmd>"C:\Program Files\Microsoft SQL Server\110\Tools\Binn\SQLCMD.EXE"
1> select 100
2>
3>
4>
5>
6> select 200
7> :list
select 100




select 200
7>

With Fix:

e:\git\go-sqlcmd\cmd\sqlcmd>.\sqlcmd
1> select 100
2>
3>
4>
5>
6> select 200
7> :list
select 100




select 200
7>

Copy link
Contributor

@apoorvdeshmukh apoorvdeshmukh left a comment

Choose a reason for hiding this comment

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

Should we be disabling ed command if it is not an interactive session?
It's unlikely that one would have ed in their sql script but should we be throwing error if that's the case?

@shueybubbles
Copy link
Collaborator Author

Should we be disabling ed command if it is not an interactive session? It's unlikely that one would have ed in their sql script but should we be throwing error if that's the case?

The odbc sqlcmd allows ed during non-interactive runs.

@shueybubbles
Copy link
Collaborator Author

Remember, sqlcmdeditor can be set to run some tool that automatically makes changes to the content of the file without any user input. So you could use it to run a perl or awk script etc.

@shueybubbles
Copy link
Collaborator Author

@apoorvdeshmukh or @stuartpa do you have a working Linux or WSL instance to test this with? My WSL got broken with the Win11 upgrade.

@apoorvdeshmukh
Copy link
Contributor

@apoorvdeshmukh or @stuartpa do you have a working Linux or WSL instance to test this with? My WSL got broken with the Win11 upgrade.

I have WSL instance. Will test this.

@apoorvdeshmukh
Copy link
Contributor

On windows I do not see the interactive session being terminated after execution of SQL commands mentioned in editor via ed

git\go-sqlcmd>.\sqlcmd.exe
1> ed
1> select @@version
2> go
                                                                                                                        

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Microsoft SQL Server 2019 (RTM-GDR) (KB5014356) - 15.0.2095.3 (X64)
        Apr 29 2022 18:00:13
        Copyright (C) 2019 Microsoft Corporation
        Developer Edition (64-bit) on Windows 10 Enterprise 10.0 <X64> (Build 22621: ) (Hypervisor)


(1 row affected)
1>

On WSL I see this getting terminated and there are some whitespace characters thrown

~/git/go-sqlcmd$ ./sqlcmd -S192.168.192.1 -Usa
Password:
1> ed
Vim: Warning: Input is not from a terminal
1> select @@version
                   2> go


                                            ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                                Microsoft SQL Server 2019 (RTM-GDR) (KB5014356) - 15.0.2095.3 (X64)
                                                                                                                                        Apr 29 2022 18:00:13
                                                                                                                                                                Copyright (C) 2019 Microsoft Corporation
                                                                                                                                                                                                                Developer Edition (64-bit) on Windows 10 Enterprise 10.0 <X64> (Build 22621: ) (Hypervisor)


                                                                                            (1 row affected)
                                                                                                            1> ~/git/go-sqlcmd$

@shueybubbles shueybubbles merged commit 553f5a1 into main Oct 13, 2022
@shueybubbles shueybubbles deleted the shueybubbles/edcommand branch October 13, 2022 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants