Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 41237ae1
authored
Jun 04, 2020
by
Pablo Soares
Committed by
GitHub
Jun 04, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(mssql): set correct scale for float (#12340)
1 parent
5c733ef7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
16 deletions
lib/dialects/mssql/query.js
test/unit/dialects/mssql/query.test.js
lib/dialects/mssql/query.js
View file @
41237ae
...
@@ -9,6 +9,13 @@ const { logger } = require('../../utils/logger');
...
@@ -9,6 +9,13 @@ const { logger } = require('../../utils/logger');
const
debug
=
logger
.
debugContext
(
'sql:mssql'
);
const
debug
=
logger
.
debugContext
(
'sql:mssql'
);
function
getScale
(
aNum
)
{
if
(
!
Number
.
isFinite
(
aNum
))
return
0
;
let
e
=
1
;
while
(
Math
.
round
(
aNum
*
e
)
/
e
!==
aNum
)
e
*=
10
;
return
Math
.
log10
(
e
);
}
class
Query
extends
AbstractQuery
{
class
Query
extends
AbstractQuery
{
getInsertIdField
()
{
getInsertIdField
()
{
return
'id'
;
return
'id'
;
...
@@ -27,7 +34,7 @@ class Query extends AbstractQuery {
...
@@ -27,7 +34,7 @@ class Query extends AbstractQuery {
}
else
{
}
else
{
paramType
.
type
=
TYPES
.
Numeric
;
paramType
.
type
=
TYPES
.
Numeric
;
//Default to a reasonable numeric precision/scale pending more sophisticated logic
//Default to a reasonable numeric precision/scale pending more sophisticated logic
paramType
.
typeOptions
=
{
precision
:
30
,
scale
:
15
};
paramType
.
typeOptions
=
{
precision
:
30
,
scale
:
getScale
(
value
)
};
}
}
}
}
if
(
Buffer
.
isBuffer
(
value
))
{
if
(
Buffer
.
isBuffer
(
value
))
{
...
...
test/unit/dialects/mssql/query.test.js
View file @
41237ae
...
@@ -15,18 +15,22 @@ let sandbox, query;
...
@@ -15,18 +15,22 @@ let sandbox, query;
if
(
dialect
===
'mssql'
)
{
if
(
dialect
===
'mssql'
)
{
describe
(
'[MSSQL Specific] Query'
,
()
=>
{
describe
(
'[MSSQL Specific] Query'
,
()
=>
{
describe
(
'beginTransaction'
,
()
=>
{
beforeEach
(()
=>
{
beforeEach
(()
=>
{
sandbox
=
sinon
.
createSandbox
();
sandbox
=
sinon
.
createSandbox
();
const
options
=
{
const
options
=
{
transaction
:
{
name
:
'transactionName'
},
transaction
:
{
name
:
'transactionName'
},
isolationLevel
:
'REPEATABLE_READ'
,
isolationLevel
:
'REPEATABLE_READ'
,
logging
:
false
logging
:
false
};
};
sandbox
.
stub
(
connectionStub
,
'beginTransaction'
).
callsArg
(
0
);
sandbox
.
stub
(
connectionStub
,
'beginTransaction'
).
callsArg
(
0
);
query
=
new
Query
(
connectionStub
,
sequelize
,
options
);
query
=
new
Query
(
connectionStub
,
sequelize
,
options
);
});
});
afterEach
(()
=>
{
sandbox
.
restore
();
});
describe
(
'beginTransaction'
,
()
=>
{
it
(
'should call beginTransaction with correct arguments'
,
()
=>
{
it
(
'should call beginTransaction with correct arguments'
,
()
=>
{
return
query
.
_run
(
connectionStub
,
'BEGIN TRANSACTION'
)
return
query
.
_run
(
connectionStub
,
'BEGIN TRANSACTION'
)
.
then
(()
=>
{
.
then
(()
=>
{
...
@@ -35,10 +39,6 @@ if (dialect === 'mssql') {
...
@@ -35,10 +39,6 @@ if (dialect === 'mssql') {
expect
(
connectionStub
.
beginTransaction
.
args
[
0
][
2
]).
to
.
equal
(
tediousIsolationLevel
.
REPEATABLE_READ
);
expect
(
connectionStub
.
beginTransaction
.
args
[
0
][
2
]).
to
.
equal
(
tediousIsolationLevel
.
REPEATABLE_READ
);
});
});
});
});
afterEach
(()
=>
{
sandbox
.
restore
();
});
});
});
describe
(
'formatBindParameters'
,
()
=>
{
describe
(
'formatBindParameters'
,
()
=>
{
...
@@ -64,5 +64,25 @@ if (dialect === 'mssql') {
...
@@ -64,5 +64,25 @@ if (dialect === 'mssql') {
expect
(
result
[
0
]).
to
.
equal
(
expected
);
expect
(
result
[
0
]).
to
.
equal
(
expected
);
});
});
});
});
describe
(
'getSQLTypeFromJsType'
,
()
=>
{
const
TYPES
=
tedious
.
TYPES
;
it
(
'should return correct parameter type'
,
()
=>
{
expect
(
query
.
getSQLTypeFromJsType
(
2147483647
,
TYPES
)).
to
.
eql
({
type
:
TYPES
.
Int
,
typeOptions
:
{}
});
expect
(
query
.
getSQLTypeFromJsType
(
-
2147483648
,
TYPES
)).
to
.
eql
({
type
:
TYPES
.
Int
,
typeOptions
:
{}
});
expect
(
query
.
getSQLTypeFromJsType
(
2147483648
,
TYPES
)).
to
.
eql
({
type
:
TYPES
.
BigInt
,
typeOptions
:
{}
});
expect
(
query
.
getSQLTypeFromJsType
(
-
2147483649
,
TYPES
)).
to
.
eql
({
type
:
TYPES
.
BigInt
,
typeOptions
:
{}
});
expect
(
query
.
getSQLTypeFromJsType
(
Buffer
.
from
(
'abc'
),
TYPES
)).
to
.
eql
({
type
:
TYPES
.
VarBinary
,
typeOptions
:
{}
});
});
it
(
'should return parameter type correct scale for float'
,
()
=>
{
expect
(
query
.
getSQLTypeFromJsType
(
1.23
,
TYPES
)).
to
.
eql
({
type
:
TYPES
.
Numeric
,
typeOptions
:
{
precision
:
30
,
scale
:
2
}
});
expect
(
query
.
getSQLTypeFromJsType
(
0.30000000000000004
,
TYPES
)).
to
.
eql
({
type
:
TYPES
.
Numeric
,
typeOptions
:
{
precision
:
30
,
scale
:
17
}
});
expect
(
query
.
getSQLTypeFromJsType
(
2.5
e
-
15
,
TYPES
)).
to
.
eql
({
type
:
TYPES
.
Numeric
,
typeOptions
:
{
precision
:
30
,
scale
:
16
}
});
});
});
});
});
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment