Tarantool development patches archive
 help / color / mirror / Atom feed
From: Nikita Pettik <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: v.shpilevoy@tarantool.org, Nikita Pettik <korablev@tarantool.org>
Subject: [tarantool-patches] [PATCH 3/4] sql: allow SAVEPOINT statement outside transaction
Date: Thu,  3 May 2018 21:49:24 +0300	[thread overview]
Message-ID: <b69afda201a1200b1bdbb3ba22bd9b570397c788.1525368399.git.korablev@tarantool.org> (raw)
In-Reply-To: <cover.1525368399.git.korablev@tarantool.org>
In-Reply-To: <cover.1525368399.git.korablev@tarantool.org>

Before this patch, usage of SAVEPOINT statement outside transaction or
inside transaction started in Lua, led to assertion fault.
Now, failed assert is substituted with checks to test transaction status.

Closes #3313
---
 src/box/sql/vdbe.c                               |  8 +++++-
 test/sql/gh-3313-savepoints-outside-txn.result   | 32 ++++++++++++++++++++++++
 test/sql/gh-3313-savepoints-outside-txn.test.lua | 18 +++++++++++++
 3 files changed, 57 insertions(+), 1 deletion(-)
 create mode 100644 test/sql/gh-3313-savepoints-outside-txn.result
 create mode 100644 test/sql/gh-3313-savepoints-outside-txn.test.lua

diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 1192fc399..6ea04901c 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -2867,7 +2867,13 @@ case OP_Savepoint: {
 	Savepoint *pTmp;
 	struct sql_txn *psql_txn = p->psql_txn;
 
-	assert(psql_txn);
+	if (psql_txn == NULL) {
+		assert(!box_txn());
+		sqlite3VdbeError(p, "cannot process savepoint: "
+				    "there is no active transaction");
+		rc = SQLITE_ERROR;
+		goto abort_due_to_error;
+	}
 	p1 = pOp->p1;
 	zName = pOp->p4.z;
 
diff --git a/test/sql/gh-3313-savepoints-outside-txn.result b/test/sql/gh-3313-savepoints-outside-txn.result
new file mode 100644
index 000000000..702d3e815
--- /dev/null
+++ b/test/sql/gh-3313-savepoints-outside-txn.result
@@ -0,0 +1,32 @@
+test_run = require('test_run').new()
+---
+...
+test_run:cmd("setopt delimiter ';'") 
+---
+- true
+...
+-- These tests check that SQL savepoints properly work outside
+-- transactions as well as inside transactions started in Lua.
+--
+-- box.cfg()
+box.sql.execute('SAVEPOINT t1;');
+---
+- error: 'cannot process savepoint: there is no active transaction'
+...
+box.sql.execute('RELEASE SAVEPOINT t1;');
+---
+- error: 'cannot process savepoint: there is no active transaction'
+...
+box.sql.execute('ROLLBACK TO SAVEPOINT t1;');
+---
+- error: 'cannot process savepoint: there is no active transaction'
+...
+box.begin() box.sql.execute('SAVEPOINT t1;') box.sql.execute('RELEASE SAVEPOINT t1;') box.commit();
+---
+...
+box.begin() box.sql.execute('SAVEPOINT t1;') box.sql.execute('ROLLBACK TO t1;') box.commit();
+---
+...
+box.begin() box.sql.execute('SAVEPOINT t1;') box.commit();
+---
+...
diff --git a/test/sql/gh-3313-savepoints-outside-txn.test.lua b/test/sql/gh-3313-savepoints-outside-txn.test.lua
new file mode 100644
index 000000000..61dd9a86b
--- /dev/null
+++ b/test/sql/gh-3313-savepoints-outside-txn.test.lua
@@ -0,0 +1,18 @@
+test_run = require('test_run').new()
+test_run:cmd("setopt delimiter ';'") 
+
+-- These tests check that SQL savepoints properly work outside
+-- transactions as well as inside transactions started in Lua.
+--
+
+-- box.cfg()
+
+box.sql.execute('SAVEPOINT t1;');
+box.sql.execute('RELEASE SAVEPOINT t1;');
+box.sql.execute('ROLLBACK TO SAVEPOINT t1;');
+
+box.begin() box.sql.execute('SAVEPOINT t1;') box.sql.execute('RELEASE SAVEPOINT t1;') box.commit();
+
+box.begin() box.sql.execute('SAVEPOINT t1;') box.sql.execute('ROLLBACK TO t1;') box.commit();
+
+box.begin() box.sql.execute('SAVEPOINT t1;') box.commit();
-- 
2.15.1

  parent reply	other threads:[~2018-05-03 18:49 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-03 18:49 [tarantool-patches] [PATCH 0/4] Rework SQL transaction processing Nikita Pettik
2018-05-03 18:49 ` [tarantool-patches] [PATCH 1/4] sql: remove OP_AutoCommit opcode Nikita Pettik
2018-05-04 14:12   ` [tarantool-patches] " Vladislav Shpilevoy
2018-05-05 19:14     ` n.pettik
2018-05-03 18:49 ` [tarantool-patches] [PATCH 2/4] sql: allow transitive Lua <-> SQL transactions Nikita Pettik
2018-05-04 14:12   ` [tarantool-patches] " Vladislav Shpilevoy
2018-05-05 19:14     ` n.pettik
2018-05-03 18:49 ` Nikita Pettik [this message]
2018-05-04 14:12   ` [tarantool-patches] Re: [PATCH 3/4] sql: allow SAVEPOINT statement outside transaction Vladislav Shpilevoy
2018-05-05 19:15     ` n.pettik
2018-05-03 18:49 ` [tarantool-patches] [PATCH 4/4] sql: fix SAVEPOINT RELEASE statement Nikita Pettik
2018-05-04 14:12   ` [tarantool-patches] " Vladislav Shpilevoy
2018-05-05 19:16     ` n.pettik
2018-05-07 13:31 ` [tarantool-patches] Re: [PATCH 0/4] Rework SQL transaction processing Vladislav Shpilevoy
2018-05-11  7:17   ` Kirill Yukhin
2018-05-11 10:08   ` Kirill Yukhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b69afda201a1200b1bdbb3ba22bd9b570397c788.1525368399.git.korablev@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [tarantool-patches] [PATCH 3/4] sql: allow SAVEPOINT statement outside transaction' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox