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
fix(mssql) insert record failure because of BOOLEAN column type #12090
Conversation
Codecov Report
@@ Coverage Diff @@
## master #12090 +/- ##
=======================================
Coverage 96.15% 96.16%
=======================================
Files 95 95
Lines 9244 9246 +2
=======================================
+ Hits 8889 8891 +2
Misses 355 355
Continue to review full report at Codecov.
|
By your last review, I check your Thanks |
I can't reproduce this issue, are you sure this test case fails without your fix. Also I found 72 cases where we are using BOOLEAN data types, so tests for this case are already there. I tried with latest mssql image and (async () => {
const BooleanTable = sequelize.define(
"BooleanTable",
{
status: {
type: Sequelize.BOOLEAN,
defaultValue: false,
allowNull: false,
},
},
{
freezeTableName: true,
}
);
const value = true;
return BooleanTable.sync({ force: true })
.then(() => {
return BooleanTable.create({
status: value,
});
})
.then(() => BooleanTable.findOne())
.then(r => console.log(r.toJSON()))
})(); tedious deprecated The default value for `config.options.trustServerCertificate` will change from `true` to `false` in the next major version of `tedious`. Set the value to `true` or `false` explicitly to silence this message. lib/dialects/mssql/connection-manager.js:63:26
Executing (default): IF OBJECT_ID('[BooleanTable]', 'U') IS NOT NULL DROP TABLE [BooleanTable];
Executing (default): IF OBJECT_ID('[BooleanTable]', 'U') IS NULL CREATE TABLE [BooleanTable] ([id] INTEGER NOT NULL IDENTITY(1,1) , [status] BIT NOT NULL DEFAULT 0, [createdAt] DATETIMEOFFSET NOT NULL, [updatedAt] DATETIMEOFFSET NOT NULL, PRIMARY KEY ([id]));
Executing (default): EXEC sys.sp_helpindex @objname = N'[BooleanTable]';
Executing (default): INSERT INTO [BooleanTable] ([status],[createdAt],[updatedAt]) OUTPUT INSERTED.[id],INSERTED.[status],INSERTED.[createdAt],INSERTED.[updatedAt] VALUES (@0,@1,@2);
Executing (default): SELECT [id], [status], [createdAt], [updatedAt] FROM [BooleanTable] AS [BooleanTable] ORDER BY [BooleanTable].[id] OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY;
{
id: 1,
status: true,
createdAt: 2020-04-09T16:42:28.432Z,
updatedAt: 2020-04-09T16:42:28.432Z
} |
From the above example, it seems that you may understand the error, you can try the following example: (async () => {
const BooleanTable = sequelize.define(
"BooleanTable",
{
status: {
type: Sequelize.BOOLEAN,
defaultValue: true,
allowNull: false,
},
},
{
freezeTableName: true,
}
);
const value = true;
return BooleanTable.sync({ force: true })
.then(() => {
return BooleanTable.create({
// status: value, // See if it will have defaultValue
});
})
.then(() => BooleanTable.findOne())
.then(r => console.log(r.toJSON()))
})(); |
Yes, for both cases tedious deprecated The default value for `config.options.trustServerCertificate` will change from `true` to `false` in the next major version of `tedious`. Set the value to `true` or `false` explicitly to silence this message. lib/dialects/mssql/connection-manager.js:63:26
{
id: 1,
status: false,
createdAt: 2020-04-13T04:13:04.803Z,
updatedAt: 2020-04-13T04:13:04.803Z
}
tedious deprecated The default value for `config.options.trustServerCertificate` will change from `true` to `false` in the next major version of `tedious`. Set the value to `true` or `false` explicitly to silence this message. lib/dialects/mssql/connection-manager.js:63:26
{
id: 1,
status: true,
createdAt: 2020-04-13T04:13:39.525Z,
updatedAt: 2020-04-13T04:13:39.525Z
} @SensitiveMix Are you suggesting |
@SensitiveMix Based on my test, it also doesn't matter to @sushantdhiman Cloud you tell me the MSSQL server version you tested?
Anyway, according to the Thanks, |
Pull Request check-list
Please make sure to review and check all of these items:
npm run test
ornpm run test-DIALECT
pass with this change (including linting)?Description of change
Hi @sushantdhiman
I reopen an PR to merge to master tree simply.
#12024
This is issue is similar with #11121
The sample code is following
The db query exception:
According to the
tedious
document, we need to set theboolean
type toTYPES.Bit