Tarantool development patches archive
 help / color / mirror / Atom feed
From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org
Cc: Nikita Pettik <korablev@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH v2 1/3] sql: introduce pragma sql_default_engine
Date: Mon, 2 Jul 2018 11:46:05 +0300	[thread overview]
Message-ID: <4a811b1f-78fd-9e8d-8388-2859ccf87bfe@tarantool.org> (raw)
In-Reply-To: <3AA22731-F304-4173-BE6D-B5AAF7AF6BC9@tarantool.org>

Hi!  Thank you for review.

> These inputs leads to segfault:
Thank you for this scenarios.

> Also, it reproduces with:
> pragma sql_default_engine 1
> pragma sql_default_engine ‘memtx’ 
I've included this in tests.

> Moreover, simple ‘pragma’ command displays list of available pragmas and
> their statuses. Lets add ’sql_default_engine’ to that list.
Ok, good idea.

========================================

diff --git a/src/box/sql/pragma.c b/src/box/sql/pragma.c
index 7a25db6..31581b1 100644
--- a/src/box/sql/pragma.c
+++ b/src/box/sql/pragma.c
@@ -219,13 +219,30 @@ pragmaLocate(const char *zName)
 	}								       \
 } while (0)
 
+#define PRINT_STR_PRAGMA(pragma_name, str_value) do {			       \
+	int nCoolSpaces = 30 - strlen(pragma_name);			       \
+	printf("%s %*c --  '%s' \n", pragma_name, nCoolSpaces, ' ', str_value);\
+} while (0)
+
 static void
 printActivePragmas(struct session *user_session)
 {
 	int i;
 	for (i = 0; i < ArraySize(aPragmaName); ++i) {
-		if (aPragmaName[i].ePragTyp == PragTyp_FLAG)
-			PRINT_PRAGMA(aPragmaName[i].zName, aPragmaName[i].iArg);
+		switch (aPragmaName[i].ePragTyp) {
+			case PragTyp_FLAG:
+				PRINT_PRAGMA(aPragmaName[i].zName, aPragmaName[i].iArg);
+				break;
+			case PragTyp_DEFAULT_ENGINE: {
+				const char *engine_name =
+					sql_storage_engine_strs[
+						current_session()->
+							sql_default_engine];
+				PRINT_STR_PRAGMA(aPragmaName[i].zName,
+						 engine_name);
+				break;
+			}
+		}
 	}
 
 	printf("Other available pragmas: \n");
@@ -244,6 +261,11 @@ printActivePragmas(struct session *user_session)
 static int
 sql_default_engine_set(const char *engine_name)
 {
+	if (engine_name == NULL) {
+		diag_set(ClientError, ER_ILLEGAL_PARAMS,
+			 "'sql_default_engine' was not specified");
+		return -1;
+	}
 	enum sql_storage_engine engine =
 		STR2ENUM(sql_storage_engine, engine_name);
 	if (engine == sql_storage_engine_MAX) {

diff --git a/test/sql-tap/gh-2367-pragma.test.lua b/test/sql-tap/gh-2367-pragma.test.lua
index 6d2e73d..c0792c9 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(4)
+test:plan(7)
 
 test:do_catchsql_test(
 	"pragma-1.3",
@@ -38,4 +38,28 @@ test:do_catchsql_test(
 	0
 })
 
+test:do_catchsql_test(
+	"pragma-2.4",
+	[[
+		pragma sql_default_engine;
+	]], {
+	1, 'Illegal parameters, \'sql_default_engine\' was not specified'
+})
+
+test:do_catchsql_test(
+	"pragma-2.5",
+	[[
+		pragma sql_default_engine 'memtx';
+	]], {
+	1, 'near \"\'memtx\'\": syntax error'
+})
+
+test:do_catchsql_test(
+	"pragma-2.5",
+	[[
+		pragma sql_default_engine 1;
+	]], {
+	1, 'near \"1\": syntax error'
+})
+
 test:finish_test()

  reply	other threads:[~2018-07-02  8:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-28 16:19 [tarantool-patches] [PATCH v2 0/3] sql: default engine pragma Kirill Shcherbatov
2018-06-28 16:19 ` [tarantool-patches] [PATCH v2 1/3] sql: introduce pragma sql_default_engine Kirill Shcherbatov
2018-06-29 14:00   ` [tarantool-patches] " n.pettik
2018-07-02  8:46     ` Kirill Shcherbatov [this message]
2018-07-02 10:23       ` n.pettik
2018-06-28 16:19 ` [tarantool-patches] [PATCH v2 2/3] sql: fix SQL Count for vinyl engine Kirill Shcherbatov
2018-06-28 16:19 ` [tarantool-patches] [PATCH v2 3/3] sql: enable multi-engine tests for SQL Kirill Shcherbatov
2018-06-29 14:14   ` [tarantool-patches] " n.pettik
2018-07-02  8:46     ` Kirill Shcherbatov
2018-07-03  8:04 ` [tarantool-patches] Re: [PATCH v2 0/3] sql: default engine pragma 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=4a811b1f-78fd-9e8d-8388-2859ccf87bfe@tarantool.org \
    --to=kshcherbatov@tarantool.org \
    --cc=korablev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH v2 1/3] sql: introduce pragma 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