Skip to content
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

Add option to set DateFirst #503

Merged
merged 9 commits into from
Feb 27, 2017

Conversation

edwardsmit
Copy link
Contributor

DATEFIRST is set to the default value of 7, but there is no way to override this setting.
As I'm having the need to set this to an other value I created this PR.
I did not find any rules for PR's, so let me know when you need additional code in order to merge this PR.

@tvrprasad
Copy link
Contributor

@edwardsmit Not sure if this belongs as a global option. You can set this in your SQL, right?
SET DATEFIRST 7;
https://msdn.microsoft.com/en-us/library/ms181598.aspx

@edwardsmit
Copy link
Contributor Author

@tvrprasad Yes you can, but I find that rather tedious tiresome.
It's up to the client to set this, SSMS does this for you based on your locale, so you won't have to set it explicitly in each of your scripts. I think it's preferable to make sure that your client, once set, uses the exact desired DateFirst throughout wether you're using a single connection or create a connection for every call. Now you have to add boilerplate code where a simple option-config would suffice.

@tvrprasad
Copy link
Contributor

tvrprasad commented Feb 15, 2017 via email

@edwardsmit
Copy link
Contributor Author

@tvrprasad Added the tests

@arthurschreiber
Copy link
Collaborator

#508 also contains this option, but does not contain the tests from this.

@edwardsmit
Copy link
Contributor Author

@arthurschreiber Maybe @ariskemper can pull the test into his PR?

test.done()

# Test that the DATEFIRST setting can be changed via an optional configuration
exports.testDatefirstDefault = (test) ->
Copy link
Contributor

Choose a reason for hiding this comment

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

Test name duplicated. Needs to be renamed, perhaps testDatafirstNotDefault.
And yes, makes sense for @ariskemper to grab this test and merge into his PR.

Thanks for putting this together!

Copy link
Contributor

Choose a reason for hiding this comment

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

Since these tests are identical, these can be refactored as below:

function testDateFirstImpl(test, dateFirstSetting)
..... Implementation here. ....

exports.testDateFirstDefault = (test) ->
    testDateFirstImpl(test, undefined)

exports.testDateFirstNonDefault = (test) ->
    testDateFirstImpl(test, 3)

@edwardsmit
Copy link
Contributor Author

@tvrprasad Refactored tests

@@ -126,6 +128,10 @@ class Connection extends EventEmitter {
this.config.options.database = config.options.database;
}

if (config.options.datefirst != undefined) {
this.config.options.datefirst = config.options.datefirst;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a range check here. You can follow the pattern for 'port' config option.
Please add a test. You can follow the pattern for 'badPort' test.
Sorry for not catching this sooner. Thanks.

@tvrprasad
Copy link
Contributor

@edwardsmit I just merged changes from #501 by @carlosman for enableArithAbort that includes tests. Please rebase.

@edwardsmit
Copy link
Contributor Author

@tvrprasad 🔔


request.on('row', (columns) ->
dateFirst = columns[0].value
test.strictEqual(dateFirst, dateFirst || 7)
Copy link
Contributor

Choose a reason for hiding this comment

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

Change variable to name something different than the parameter passed to the function, say datefirstReturned. As it stands, you're comparing the variable to itself.

Nit: I suggest changing parameter name from 'dateFirst' to 'datefirst' for consistency.

@edwardsmit
Copy link
Contributor Author

@tvrprasad 🛎

Copy link
Contributor

@tvrprasad tvrprasad left a comment

Choose a reason for hiding this comment

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

lgtm
Thanks for the contribution!

@tvrprasad tvrprasad merged commit 10ca705 into tediousjs:master Feb 27, 2017
@edwardsmit
Copy link
Contributor Author

@tvrprasad Thanks for merging. Do you have a release planned in the near future so that I can use this in my projects?

@tvrprasad
Copy link
Contributor

Stay tuned to this - #477
Hopefully soon.

tvrprasad added a commit to tvrprasad/tedious that referenced this pull request Mar 2, 2017
This creeped in PR tediousjs#503.
Curiously enough the unit tests added as part of the CL caught the bug
when I ran tests on my machine whereas they succeeded on AppVeyor. The
difference is that I happened to have a 'port' config value set in my
local setup whereas AppVeyor did not. Just a freak coincidence that this
would trigger the bug.
tvrprasad pushed a commit to tvrprasad/tedious that referenced this pull request May 18, 2017
dateFormat, enableAnsiNull, enableAnsiPadding, enableAnsiWarnings,
enableConcatNullYeldsNull, enableCursorCloseOnCommit,
enableImplicitTransactions, enableNumericRoundabort, enableQuotedIdentifier,
language.

Relates to tediousjs#507 tediousjs#506 tediousjs#501 tediousjs#503

This is a cleaned up merged version of tediousjs#508.
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