Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

zhevron
Copy link
Contributor

@zhevron zhevron commented May 22, 2019

With the MSSQL driver recently merged in, I'm getting errors when running against my MSSQL 2017 instance:

try lock failed in line 0: EXEC sp_getapplock @Resource = ?, @LockMode = 'Update', @LockOwner = 'Session', @LockTimeout = 0 (details: mssql: Incorrect syntax near '?'.)

MSSQL uses @pN syntax for parameters instead of ?.

Copy link
Member

@dhui dhui left a comment

Choose a reason for hiding this comment

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

Thanks for reporting the issue and providing a fix!

Looks like only @pN and named parameters are officially supported now. ? replacement is deprecated.
References:

Could you add tests to prevent a regression?

@zhevron
Copy link
Contributor Author

zhevron commented May 22, 2019

My poor Windows PC with docker-machine isn't too fond of running the tests. I'll fire up a VM and look into it!

@zhevron
Copy link
Contributor Author

zhevron commented May 22, 2019

The existing tests will catch regressions here. They were passing because the connection was opened with the deprecated 'mssql' driver instead of the 'sqlserver' one. The 'mssql' driver still uses ? parameters and is not recommended to use.

If the driver is inadvertently changed back to 'mssql', the tests will fail because it can't handle the @pN notations and the lock tests fail.

@coveralls
Copy link

coveralls commented May 22, 2019

Pull Request Test Coverage Report for Build 421

  • 15 of 15 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.06%) to 51.626%

Totals Coverage Status
Change from base Build 415: -0.06%
Covered Lines: 778
Relevant Lines: 1507

💛 - Coveralls

Copy link
Member

@dhui dhui left a comment

Choose a reason for hiding this comment

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

Thanks for investigating!

The existing tests will catch regressions here. They were passing because the connection was opened with the deprecated 'mssql' driver instead of the 'sqlserver' one. The 'mssql' driver still uses ? parameters and is not recommended to use.

If the driver is inadvertently changed back to 'mssql', the tests will fail because it can't handle the @pn notations and the lock tests fail.

Uggghhhh, different behavior based on the driver name is quite annoying...
Could you update the tests to test against both driver names using t.Run() (e.g. subtests)?

@zhevron
Copy link
Contributor Author

zhevron commented May 22, 2019

@dhui You're right. Because of WithInstance, we can't force the end user to use the sqlserver driver. As far as I can tell, that leaves us with two options:

  1. Add support for both sqlserver and mssql drivers with different SQL statements. I'm thinking config option.
  2. Add a notice that only the sqlserver driver is supported. mssql is deprecated already anyway. This would prevent legacy applications from adopting the library though.

Which would you think is better? I'm leaning towards option 1 currently. Can always remove the support once the upstream driver removes their support.

Copy link
Member

@dhui dhui left a comment

Choose a reason for hiding this comment

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

I'm actually leaning towards option 2 since we just added support for MS SQL Server. e.g. we don't need to support older versions yet. Any users using mssql would have to migrate their app to use sqlserver.

I think we should:

  1. Document support for only sqlserver in both the DB driver README and the WithInstance() docs.
  2. Register DB driver with only sqlserver to reduce the potential for confusion. e.g. remove database.Register("mssql", &db)

@zhevron
Copy link
Contributor Author

zhevron commented May 23, 2019

Not sure what's going on with the tests here. Repeatedly seeing this error on unrelated tests:

dktest.go:54: Error parsing image pull response: context deadline exceeded

followed by

dktest.go:182: Failed to run image: mcr.microsoft.com/mssql/server:2019-latest error: Error: No such image: mcr.microsoft.com/mssql/server:2019-latest

for all the database images.

@dhui
Copy link
Member

dhui commented May 24, 2019

Looks like MCR or TravisCI were being slow.
We could up the image pull timeout to 5m in mssql_test.go.

@dhui
Copy link
Member

dhui commented May 24, 2019

@zhevron I'm also thinking that we should rename the driver to sqlserver to also reduce confusion. Thoughts?

@zhevron
Copy link
Contributor Author

zhevron commented May 24, 2019

@dhui I think it's clearer which vendor it is with the driver name remaining as mssql, but I can also see the case for renaming it since that's what the upstream driver did. Since the sqlserver name is the future for that library, I would agree a name change here is warranted. I'll get it done.

As for the tests, it was happening to several of the database drivers, so increasing the timeout in mssql_test.go won't do much. I saw it with postgres and several others too. Let's just see if whoever was experiencing problems sorts it out first.

Copy link
Member

@dhui dhui left a comment

Choose a reason for hiding this comment

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

Thanks for doing the rename! Supporting only a single driver kept testing more simple.

Just one comment needs to be updated.

SchemaName string
}

// MSSQL connection
Copy link
Member

Choose a reason for hiding this comment

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

Comment needs to be updated as well

@dhui dhui merged commit 8437fe6 into golang-migrate:master May 27, 2019
@zhevron zhevron deleted the mssql-params branch May 28, 2019 05:46
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.

3 participants