nestjsx / crud

NestJs CRUD for RESTful APIs
https://github.com/nestjsx/crud/wiki
MIT License
4.04k stars 533 forks source link

'ER_PARSE_ERROR' while retrieving a single element (via API, or after updating/creating one element) #605

Open dokorof opened 4 years ago

dokorof commented 4 years ago

Hi everyone!

I might have detected a bug on the package while using MariaDB.

Every time I try to insert, update or retrieve a single element I get a 500 error. After activating the logging option on my database I noticed that the query builder creates an invalid WHERE clause:

code: 'ER_PARSE_ERROR',
  errno: 1064,
  sqlMessage: 'You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '."id" = 5) LIMIT 25' at line 1',
  sqlState: '42000',
  index: 0,
  sql: 'SELECT `Project`.`id` AS `Project_id`, `Project`.`active` AS `Project_active`, `Project`.`created` AS `Project_created`, `Project`.`updated` AS `Project_updated`, `Project`.`name` AS `Project_name`, `Project`.`key` AS `Project_key` FROM `project` `Project` WHERE ("Project"."id" = 5) LIMIT 25'

I've integrated both the Crud Controller and the TypeOrmCrudService:

@Injectable()
export class ProjectService extends TypeOrmCrudService<Project>{
  constructor(@InjectRepository(Project) projectRepository) {
    super(projectRepository)
  }
}
@Crud({
  model: {
    type: Project
  },
  routes: {
    only: ['getOneBase', 'getManyBase', 'updateOneBase', 'createOneBase'],
    createOneBase: {
      returnShallow: true // Set this to true to avoid that error
    },
    updateOneBase: {
      returnShallow: true // Set this to true to avoid that error
    }
  }
})
@Controller('projects')
export class ProjectController implements CrudController<Project> {
  constructor(public service: ProjectService) {}
}

Let me know if you need more info on this.

Thanks!

nsetyo commented 3 years ago

@dokorof I have exactly this problem, may I know how do you solve this with getOneBase ?

nsetyo commented 3 years ago

Never mind, I found out this bug is already reported before in #401 #531 #545 and change database type to 'mysql' instead of 'mariadb' fix the problem

dokorof commented 3 years ago

I was about to say that @nsetyo . I learned that the hard way. Glad that it got documented here for future reference.

raphaelmollon commented 1 year ago

Never mind, I found out this bug is already reported before in #401 #531 #545 and change database type to 'mysql' instead of 'mariadb' fix the problem

Thanks!