-
Notifications
You must be signed in to change notification settings - Fork 3
Remove RoutineName, fix and test rowcount #30
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -417,7 +417,7 @@ func (d *Document) parseCreate(s *Scanner, createCountInBatch int) (result Creat | |
| // point we copy the rest until the batch ends; *but* track dependencies | ||
| // + some other details mentioned below | ||
|
|
||
| firstAs := true | ||
| //firstAs := true // See comment below on rowcount | ||
|
|
||
| tailloop: | ||
| for { | ||
|
|
@@ -473,18 +473,41 @@ tailloop: | |
| case tt == ReservedWordToken && s.Token() == "as": | ||
| CopyToken(s, &result.Body) | ||
| NextTokenCopyingWhitespace(s, &result.Body) | ||
| if firstAs { | ||
| // Add the `RoutineName` token as a convenience, so that we can refer to the procedure/function name | ||
| // from inside the procedure (for example, when logging) | ||
| if result.CreateType == "procedure" { | ||
| procNameToken := Unparsed{ | ||
| Type: OtherToken, | ||
| RawValue: fmt.Sprintf(templateRoutineName, strings.Trim(result.QuotedName.Value, "[]")), | ||
| /* | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leaving as a comment because the idea of having |
||
| TODO: Fix and re-enable | ||
| This code add RoutineName for convenience. So: | ||
|
|
||
| create procedure [code@5420c0269aaf].Test as | ||
| begin | ||
| select 1 | ||
| end | ||
| go | ||
|
|
||
| becomes: | ||
|
|
||
| create procedure [code@5420c0269aaf].Test as | ||
| declare @RoutineName nvarchar(128) | ||
| set @RoutineName = 'Test' | ||
| begin | ||
| select 1 | ||
| end | ||
| go | ||
|
|
||
| However, for some very strange reason, @@rowcount is 1 with the first version, | ||
theophanemayaud marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| and it is 2 with the second version. | ||
| if firstAs { | ||
| // Add the `RoutineName` token as a convenience, so that we can refer to the procedure/function name | ||
| // from inside the procedure (for example, when logging) | ||
| if result.CreateType == "procedure" { | ||
| procNameToken := Unparsed{ | ||
| Type: OtherToken, | ||
| RawValue: fmt.Sprintf(templateRoutineName, strings.Trim(result.QuotedName.Value, "[]")), | ||
| } | ||
| result.Body = append(result.Body, procNameToken) | ||
| } | ||
| result.Body = append(result.Body, procNameToken) | ||
| firstAs = false | ||
| } | ||
| firstAs = false | ||
| } | ||
| */ | ||
|
|
||
| default: | ||
| CopyToken(s, &result.Body) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package sqltest | ||
|
|
||
| import ( | ||
| "embed" | ||
|
|
||
| "github.com/vippsas/sqlcode" | ||
| ) | ||
|
|
||
| //go:embed *.sql | ||
| var sqlfs embed.FS | ||
|
|
||
| var SQL = sqlcode.MustInclude( | ||
| sqlcode.Options{}, | ||
| sqlfs, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package sqltest | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func Test_RowsAffected(t *testing.T) { | ||
| fixture := NewFixture() | ||
| defer fixture.Teardown() | ||
| fixture.RunMigrationFile("../migrations/0001.sqlcode.sql") | ||
|
|
||
| ctx := context.Background() | ||
|
|
||
| require.NoError(t, SQL.EnsureUploaded(ctx, fixture.DB)) | ||
| patched := SQL.Patch(`[code].Test`) | ||
|
|
||
| res, err := fixture.DB.ExecContext(ctx, patched) | ||
| require.NoError(t, err) | ||
| rowsAffected, err := res.RowsAffected() | ||
| require.NoError(t, err) | ||
| assert.Equal(t, int64(1), rowsAffected) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| create procedure [code].Test as | ||
| begin | ||
| select 1 | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
alter userby itself is not valid SQL. I'm not sure why it was here in the first place. My feeling is that this file was never properly tested/migrated before.