0

How do I run multiple queries for a delete:

@Delete(
            """DELETE FROM punch_attachment WHERE tablename = '${tableName}' AND recordid = #{id};
            DELETE FROM punch_tagged_item WHERE table_name = '${tableName}' AND record_id = #{id};
            DELETE FROM ${tableName} WHERE id = #{id};"""
    )

This gives a syntax error

So does this:

@Delete(value = [
            "DELETE FROM punch_attachment WHERE tablename = '${tableName}' AND recordid = #{id};",
            "DELETE FROM punch_tagged_item WHERE table_name = '${tableName}' AND record_id = #{id};",
            "DELETE FROM ${tableName} WHERE id = #{id};"
        ]
    )
    override fun delete(id: Long): Int

Basically, I need my dao to do all 3 of these when deleting an item. How do I do it? Here's the 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 'DELETE FROM punch_tagged_item WHERE table_name = 'punch_item' AND record_id = 11' at line 1

If I paste this error into a query console, it works fine. There is not a syntax error here. It has to do with the multiple queries...

I do not want to create a service to compose this, nor do I want a DB procedure to do this.

1
  • Did you enable allowMultiQueries? Commented May 21 at 14:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.