-
Notifications
You must be signed in to change notification settings - Fork 3
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
Calling stored procedures with variables and then selecting causes parsing errors from MySQL side? #697
Comments
Figured out the method with two queries doesn't works because of queries going asynchronously where But it still doesn't explain why it doesn't accept both of them in one query string |
Can you create minimal reproduction in a cloneable git repository? |
Just made one here https://github.com/fagirton/nest-mysql-procedures-multiline-bug |
I checked the repository, you have to add the SQL otherwise it gives error, in the this point here: for example: async runQuery(dto: dtoQuery) {
const data = await this.connection.query('SELECT * FROM table_name', [dto.query]);
return JSON.stringify(Object.assign([{}], data));
} Here you can find an example tutorial if you find it useful: https://dev.to/tony133/mysql-module-for-nestjs-8x-framework-5gh9. My package is a wrapper of the You can also just use the mysql2 package if it's easier for you 🙂 |
I used a simple calcUserRep procedure with user_id In parameter and reputation Out parameter.
The code in service.ts is also very straightforward, it takes string from dto and runs it as query:
However, a single query with CALL and SELECT operators throws error in MySQL:
The query:
CALL calcUserRep(1, @rep); SELECT @rep;
The error:
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT @rep' at line 1
Inside MySQL Workbench under the same user the query works perfectly.
I also tried running two separate
this.connection.query()
methods, but seems like MySQL doesn't remember variables between the two.Is this made by design or this is a bug? And how I can workaround this?
My software: nestjs-mysql 0.0.14, nest 10.3.8
The text was updated successfully, but these errors were encountered: