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 5F44B2117C for ; Tue, 26 Jun 2018 09:43:47 -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 vSBhAVhOK0zX for ; Tue, 26 Jun 2018 09:43:47 -0400 (EDT) Received: from smtp34.i.mail.ru (smtp34.i.mail.ru [94.100.177.94]) (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 1912D20FC9 for ; Tue, 26 Jun 2018 09:43:47 -0400 (EDT) From: Kirill Yukhin Subject: [tarantool-patches] [PATCH] sql: remove sqlite_ functions from SQL Date: Tue, 26 Jun 2018 16:33:41 +0300 Message-Id: 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: korablev@tarantool.org Cc: tarantool-patches@freelists.org, Kirill Yukhin Branch: https://github.com/tarantool/tarantool/tree/kyukhin/gh-2184-remove-version Issue: https://github.com/tarantool/tarantool/issues/2184 Removed legacy functions: sqlite_version, sqlite_sourceid, sqlite_log. Added version built-in function which returns Tarantool's version. Closes #2184 --- src/box/sql/func.c | 56 ++++++++++++---------------------------------- src/box/sql/main.c | 38 ++----------------------------- src/box/sql/sqliteInt.h | 15 ++----------- test/sql-tap/func.test.lua | 7 ++++-- 4 files changed, 23 insertions(+), 93 deletions(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index c06e3bd..097778a 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -36,6 +36,7 @@ */ #include "sqliteInt.h" #include "vdbeInt.h" +#include "version.h" #include #include #include @@ -530,7 +531,7 @@ ICU_CASE_CONVERT(Upper); * noopFunc will never be called so it doesn't matter what the implementation * is. We might as well use the "version()" function as a substitute. */ -#define noopFunc versionFunc /* Substitute function - never called */ +#define noopFunc sql_func_version /* Substitute function - never called */ /* * Implementation of random(). Return a random integer. @@ -966,47 +967,20 @@ nullifFunc(sqlite3_context * context, int NotUsed, sqlite3_value ** argv) } } -/* - * Implementation of the sqlite_version() function. The result is the version - * of the SQLite library that is running. - */ -static void -versionFunc(sqlite3_context * context, int NotUsed, sqlite3_value ** NotUsed2) -{ - UNUSED_PARAMETER2(NotUsed, NotUsed2); - /* IMP: R-48699-48617 This function is an SQL wrapper around the - * sqlite3_libversion() C-interface. - */ - sqlite3_result_text(context, sqlite3_libversion(), -1, SQLITE_STATIC); -} - -/* - * Implementation of the sqlite_source_id() function. The result is a string - * that identifies the particular version of the source code used to build - * SQLite. - */ -static void -sourceidFunc(sqlite3_context * context, int NotUsed, sqlite3_value ** NotUsed2) -{ - UNUSED_PARAMETER2(NotUsed, NotUsed2); - /* IMP: R-24470-31136 This function is an SQL wrapper around the - * sqlite3_sourceid() C interface. - */ - sqlite3_result_text(context, sqlite3_sourceid(), -1, SQLITE_STATIC); -} - -/* - * Implementation of the sqlite_log() function. This is a wrapper around - * sqlite3_log(). The return value is NULL. The function exists purely for - * its side-effects. +/** + * Implementation of the version() function. The result is the + * version of the Tarantool that is running. + * + * @param context Context being used. + * @param unused1 Unused. + * @param unused2 Unused. */ static void -errlogFunc(sqlite3_context * context, int argc, sqlite3_value ** argv) +sql_func_version(struct sqlite3_context *context, + MAYBE_UNUSED int unused1, + MAYBE_UNUSED sqlite3_value **unused2) { - UNUSED_PARAMETER(argc); - UNUSED_PARAMETER(context); - sqlite3_log(sqlite3_value_int(argv[0]), "%s", - sqlite3_value_text(argv[1])); + sqlite3_result_text(context, tarantool_version(), -1, SQLITE_STATIC); } /* Array for converting from half-bytes (nybbles) into ASCII hex @@ -1871,9 +1845,7 @@ sqlite3RegisterBuiltinFunctions(void) VFUNCTION(random, 0, 0, 0, randomFunc), VFUNCTION(randomblob, 1, 0, 0, randomBlob), FUNCTION(nullif, 2, 0, 1, nullifFunc), - DFUNCTION(sqlite_version, 0, 0, 0, versionFunc), - DFUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc), - FUNCTION(sqlite_log, 2, 0, 0, errlogFunc), + FUNCTION(version, 0, 0, 0, sql_func_version), FUNCTION(quote, 1, 0, 0, quoteFunc), VFUNCTION(changes, 0, 0, 0, changes), VFUNCTION(total_changes, 0, 0, 0, total_changes), diff --git a/src/box/sql/main.c b/src/box/sql/main.c index 0acf7bc..b1d4036 100644 --- a/src/box/sql/main.c +++ b/src/box/sql/main.c @@ -37,6 +37,7 @@ */ #include "sqliteInt.h" #include "vdbeInt.h" +#include "version.h" #include "box/session.h" #ifdef SQLITE_ENABLE_FTS3 @@ -55,41 +56,6 @@ int sqlite3Json1Init(sqlite3 *); int sqlite3Fts5Init(sqlite3 *); #endif -#ifndef SQLITE_AMALGAMATION -/* IMPLEMENTATION-OF: R-46656-45156 The sqlite3_version[] string constant - * contains the text of SQLITE_VERSION macro. - */ -const char sqlite3_version[] = SQLITE_VERSION; -#endif - -/* IMPLEMENTATION-OF: R-53536-42575 The sqlite3_libversion() function returns - * a pointer to the to the sqlite3_version[] string constant. - */ -const char * -sqlite3_libversion(void) -{ - return sqlite3_version; -} - -/* IMPLEMENTATION-OF: R-63124-39300 The sqlite3_sourceid() function returns a - * pointer to a string constant whose value is the same as the - * SQLITE_SOURCE_ID C preprocessor macro. - */ -const char * -sqlite3_sourceid(void) -{ - return SQLITE_SOURCE_ID; -} - -/* IMPLEMENTATION-OF: R-35210-63508 The sqlite3_libversion_number() function - * returns an integer equal to SQLITE_VERSION_NUMBER. - */ -int -sqlite3_libversion_number(void) -{ - return SQLITE_VERSION_NUMBER; -} - #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE) /* * If the following function pointer is not NULL and if @@ -2056,7 +2022,7 @@ static int reportError(int iErr, int lineno, const char *zType) { sqlite3_log(iErr, "%s at line %d of [%.10s]", - zType, lineno, 20 + sqlite3_sourceid()); + zType, lineno, 20 + tarantool_version()); return iErr; } diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h index e7a02dc..2b1b921 100644 --- a/src/box/sql/sqliteInt.h +++ b/src/box/sql/sqliteInt.h @@ -716,12 +716,6 @@ sqlite3_total_changes(sqlite3 *); void * sqlite3_user_data(sqlite3_context *); -const char * -sqlite3_libversion(void); - -const char * -sqlite3_sourceid(void); - void sqlite3_log(int iErrCode, const char *zFormat, ...); @@ -742,10 +736,6 @@ sqlite3_errmsg(sqlite3 *); int sqlite3_initialize(void); -#define SQLITE_VERSION "3.16.2" -#define SQLITE_VERSION_NUMBER 3016002 -#define SQLITE_SOURCE_ID "D 1970-01-01 00:00:00 00000000-0000-0000-0000-000000000000" - int sqlite3_os_end(void); @@ -1809,9 +1799,8 @@ struct FuncDestructor { * * DFUNCTION(zName, nArg, iArg, bNC, xFunc) * Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag and - * adds the SQLITE_FUNC_SLOCHNG flag. Used for date & time functions - * and functions like sqlite_version() that can change, but not during - * a single query. + * adds the SQLITE_FUNC_SLOCHNG flag. Used for date & time functions, + * but not during a single query. * * AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal) * Used to create an aggregate function definition implemented by diff --git a/test/sql-tap/func.test.lua b/test/sql-tap/func.test.lua index fee0ead..03d033d 100755 --- a/test/sql-tap/func.test.lua +++ b/test/sql-tap/func.test.lua @@ -1,6 +1,6 @@ #!/usr/bin/env tarantool test = require("sqltester") -test:plan(14533) +test:plan(14534) --!./tcltestrunner.lua -- 2001 September 15 @@ -2641,6 +2641,9 @@ test:do_execsql_test( -- }) - +test:do_execsql_test( + "func-32", + [[SELECT version()]], + {_TARANTOOL}) test:finish_test() -- 2.16.2