Error on MariaDB transaction attempt

251 views Asked by At

I'm trying to perform this transaction on MariaDB 10.1.25 on Fedora 25 and DBeaver as sql editor.

Each query alone works fine, but when wrap them on the transaction block always fails.

BEGIN;
INSERT INTO quality.tb_account (email, password, registration_date, active, screen_name)
      VALUES ('[email protected]', 'password', CURRENT_DATE(), TRUE, 'user11');
INSERT INTO quality.tb_account_roles (account_id, role_id)
      VALUES  (LAST_INSERT_ID(), 1);
COMMIT;

The error is the next one:

SQL Error [1064] [42000]: (conn:2) 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 'INSERT INTO quality.tb_account (email, password, registration_date, active, scre' at line 2
Query is : BEGIN;
INSERT INTO quality.tb_account (email, password, registration_date, active, screen_name) VALUES ('[email protected]', 'password', CURRENT_DATE(), TRUE, 'user11');
INSERT INTO quality.tb_account_roles (account_id, role_id) VALUES (LAST_INSERT_ID(), 1);
COMMIT
  (conn:2) 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 'INSERT INTO quality.tb_account (email, password, registration_date, active, scre' at line 2
Query is : BEGIN;
INSERT INTO quality.tb_account (email, password, registration_date, active, screen_name) VALUES ('[email protected]', 'password', CURRENT_DATE(), TRUE, 'user11');
INSERT INTO quality.tb_account_roles (account_id, role_id) VALUES (LAST_INSERT_ID(), 1);
COMMIT
    org.mariadb.jdbc.internal.util.dao.QueryException: 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 'INSERT INTO quality.tb_account (email, password, registration_date, active, scre' at line 2
Query is : BEGIN;
INSERT INTO quality.tb_account (email, password, registration_date, active, screen_name) VALUES ('[email protected]', 'password', CURRENT_DATE(), TRUE, 'user11');
INSERT INTO quality.tb_account_roles (account_id, role_id) VALUES (LAST_INSERT_ID(), 1);
COMMIT

What am I doing wrong?? Why each query works alone but not together??

1

There are 1 answers

0
Rick James On

You must issue each SQL statement by itself -- do not try to concatenate them together.

Notice that it said "...near 'INSERT..." meaning that it got to the ";" but did not like finding stuff after that.