loopbackio / loopbackio/loopback-next
While updating record by id using repository throwing ROWCOUNT error
@achrinza is already working on this.
Since Apr 5, 2022.
- Dominant language
- TypeScript
- Stars
- 5.1k
- Forks
- 1.1k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 27
Description
Steps to reproduce
my model looks like these
@model({
settings: {
'mssql': {schema: `boim`, table: `test`},
strict: true,
},
})
export class TestModel extends Entity {
@property({
type: 'number',
id: true,
generated:true,
})
id?: number;
@property({
type: 'date',
required: true,
})
date_created: string;
@property({
type: 'date',
})
start_date?: string;
@property({
type: 'date',
})
end_date?: string;
@property({
type: 'string',
})
charge?: string;
@property({
type: 'string',
})
param?: string;
@property({
type: 'string',
})
output?: string;
@property({
type: 'string',
})
response?: string;
@property({
type: 'string',
})
status?: string | null;
@property({
type: 'boolean',
})
working?: boolean;
constructor(data?: Partial<TestModel>) {
super(data);
}
}
export interface TestModelRelations {
// describe navigational properties here
}
export type TestModelWithRelations = TestModel & TestModelRelations;
My repository
export class TestModelRepository extends DefaultCrudRepository<
TestModel,
typeof TestModel.prototype.id,
TestModelRelations
> {
constructor(
@inject('datasources.msSqlDs') dataSource: MsSqlDsDataSource,
) {
super(TestModel, dataSource);
}
}
in my controller
constructor(
@inject(RestBindings.Http.RESPONSE) private response: Response,
@repository(TestModelRepository)
private testModelRepository: TestModelRepository,
) {}
I have generated my application using lb4 cli
Current Behavior
When I use updateById() (e.g. this.testModelRepository.updateById(id,{working:true})), I am getting the Must declare the scalar variable "@@ROWCOUNT" error.
I tried to print the SQL query that is generated by changing debug settings and I got this in the log:
loopback:connector:mssql SQL: UPDATE [boim].[test] SET [working]=@param1 WHERE [id]=@param2;SELECT @@ROWCOUNT as count Parameters: [true,987] +4s
loopback:connector:mssql Result: {"code":"EREQUEST","originalError":{"info":{"name":"ERROR","event":"errorMessage","number":137,"state":1,"class":16,"message":"Must declare the scalar variable \"@@ROWCOUNT\".","serverName":"mydatabase","procName":"","lineNumber":1}},"name":"RequestError","number":137,"lineNumber":1,"state":1,"class":16,"serverName":"mydatabase","procName":"","precedingErrors":[]} undefined +2s
Expected Behavior
Link to reproduction sandbox
Additional information
darwin x64 10.16.3npm ls --prod --depth 0 | grep loopback
├── @loopback/boot@3.1.2
├── @loopback/core@2.13.1
├── @loopback/repository@3.3.0
├── @loopback/rest@9.1.1
├── @loopback/rest-explorer@3.0.5
├── @loopback/service-proxy@3.0.5
├── loopback-connector-mssql@3.8.0
├── loopback-connector-mysql@5.4.4
-->
Related Issues
See Reporting Issues for more tips on writing good issues
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.