Tarantool development patches archive
 help / color / mirror / Atom feed
From: imeevma@tarantool.org
To: v.shpilevoy@tarantool.org, tarantool-patches@freelists.org
Subject: [tarantool-patches] [PATCH v2 3/6] sql: Show currently set sql_default_engine
Date: Sat, 15 Dec 2018 15:01:47 +0300	[thread overview]
Message-ID: <4b7280d1e803f31c73cba874e445f82295bba2a6.1544871594.git.imeevma@gmail.com> (raw)
In-Reply-To: <cover.1544871593.git.imeevma@gmail.com>

After this patch, "PRAGMA sql_default_engine" called without
arguments will return currently set sql_default_engine.

Part of #3832
---
 src/box/sql/pragma.c                 | 18 +++++++++++++-----
 test/sql-tap/gh-2367-pragma.test.lua | 35 +++++++++++++++++++++++++++--------
 2 files changed, 40 insertions(+), 13 deletions(-)

diff --git a/src/box/sql/pragma.c b/src/box/sql/pragma.c
index 1fe5b3e..f34e7b8 100644
--- a/src/box/sql/pragma.c
+++ b/src/box/sql/pragma.c
@@ -600,12 +600,20 @@ sqlite3Pragma(Parse * pParse, Token * pId,	/* First part of [schema.]id field */
 		}
 
 	case PragTyp_DEFAULT_ENGINE: {
-		if (sql_default_engine_set(zRight) != 0) {
-			pParse->rc = SQL_TARANTOOL_ERROR;
-			pParse->nErr++;
-			goto pragma_out;
+		if (zRight == NULL) {
+			const char *engine_name =
+				sql_storage_engine_strs[current_session()->
+							sql_default_engine];
+			sqlite3VdbeLoadString(v, 1, engine_name);
+			sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
+		} else {
+			if (sql_default_engine_set(zRight) != 0) {
+				pParse->rc = SQL_TARANTOOL_ERROR;
+				pParse->nErr++;
+				goto pragma_out;
+			}
+			sqlite3VdbeAddOp0(v, OP_Expire);
 		}
-		sqlite3VdbeAddOp0(v, OP_Expire);
 		break;
 	}
 
diff --git a/test/sql-tap/gh-2367-pragma.test.lua b/test/sql-tap/gh-2367-pragma.test.lua
index c0792c9..90ecd56 100755
--- a/test/sql-tap/gh-2367-pragma.test.lua
+++ b/test/sql-tap/gh-2367-pragma.test.lua
@@ -1,7 +1,7 @@
 #!/usr/bin/env tarantool
 test = require("sqltester")
 
-test:plan(7)
+test:plan(8)
 
 test:do_catchsql_test(
 	"pragma-1.3",
@@ -41,25 +41,44 @@ test:do_catchsql_test(
 test:do_catchsql_test(
 	"pragma-2.4",
 	[[
-		pragma sql_default_engine;
+		pragma sql_default_engine 'memtx';
 	]], {
-	1, 'Illegal parameters, \'sql_default_engine\' was not specified'
+	1, 'near \"\'memtx\'\": syntax error'
 })
 
 test:do_catchsql_test(
 	"pragma-2.5",
 	[[
-		pragma sql_default_engine 'memtx';
+		pragma sql_default_engine 1;
 	]], {
-	1, 'near \"\'memtx\'\": syntax error'
+	1, 'near \"1\": syntax error'
 })
 
+--
+-- gh-3832: Some statements do not return column type
+--
+-- Check that "PRAGMA sql_default_engine" called without arguments
+-- returns currently set sql_default_engine.
 test:do_catchsql_test(
-	"pragma-2.5",
+	"pragma-3.1",
 	[[
-		pragma sql_default_engine 1;
+		pragma sql_default_engine='vinyl';
+		pragma sql_default_engine;
 	]], {
-	1, 'near \"1\": syntax error'
+	-- <pragma-3.1>
+	0, {'vinyl'}
+	-- <pragma-3.1>
+})
+
+test:do_catchsql_test(
+	"pragma-3.2",
+	[[
+		pragma sql_default_engine='memtx';
+		pragma sql_default_engine;
+	]], {
+	-- <pragma-3.2>
+	0, {'memtx'}
+	-- <pragma-3.2>
 })
 
 test:finish_test()
-- 
2.7.4

  parent reply	other threads:[~2018-12-15 12:05 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-15 11:51 [tarantool-patches] [PATCH v2 0/6] sql: set column types for EXPLAIN and PRAGMA imeevma
2018-12-15 11:54 ` [tarantool-patches] [PATCH v2 1/6] sql: remove unnecessary macros from pragma.* imeevma
2018-12-20 20:41   ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-24 14:01   ` n.pettik
2018-12-15 11:56 ` [tarantool-patches] [PATCH v2 2/6] sql: fix "PRAGMA parser_trace" result imeevma
2018-12-24 14:01   ` [tarantool-patches] " n.pettik
2018-12-15 12:01 ` imeevma [this message]
2018-12-24 14:01   ` [tarantool-patches] Re: [PATCH v2 3/6] sql: Show currently set sql_default_engine n.pettik
2018-12-15 12:03 ` [tarantool-patches] [PATCH v2 4/6] sql: fix "PRAGMA case_sensitive_like" result imeevma
2018-12-24 14:01   ` [tarantool-patches] " n.pettik
2018-12-15 12:05 ` [tarantool-patches] [PATCH v2 5/6] sql: 'PRAGMA' result in Tarantool format imeevma
2018-12-24 14:02   ` [tarantool-patches] " n.pettik
2018-12-15 12:08 ` [tarantool-patches] [PATCH v2 6/6] sql: set column types for EXPLAIN and PRAGMA imeevma
2018-12-24 14:02   ` [tarantool-patches] " n.pettik

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=4b7280d1e803f31c73cba874e445f82295bba2a6.1544871594.git.imeevma@gmail.com \
    --to=imeevma@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [tarantool-patches] [PATCH v2 3/6] sql: Show currently set sql_default_engine' \
    /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