From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 8932923428 for ; Mon, 2 Jul 2018 04:46:08 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id adcp1YTvCkHS for ; Mon, 2 Jul 2018 04:46:08 -0400 (EDT) Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 489E021A8A for ; Mon, 2 Jul 2018 04:46:08 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH v2 1/3] sql: introduce pragma sql_default_engine References: <6271c2d9b369110fac3586e662b8838bec242d72.1530202680.git.kshcherbatov@tarantool.org> <3AA22731-F304-4173-BE6D-B5AAF7AF6BC9@tarantool.org> From: Kirill Shcherbatov Message-ID: <4a811b1f-78fd-9e8d-8388-2859ccf87bfe@tarantool.org> Date: Mon, 2 Jul 2018 11:46:05 +0300 MIME-Version: 1.0 In-Reply-To: <3AA22731-F304-4173-BE6D-B5AAF7AF6BC9@tarantool.org> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: Nikita Pettik 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()