Tarantool development patches archive
 help / color / mirror / Atom feed
From: Kirill Yukhin <kyukhin@tarantool.org>
To: korablev@tarantool.org
Cc: tarantool-patches@freelists.org, Kirill Yukhin <kyukhin@tarantool.org>
Subject: [tarantool-patches] [PATCH] sql: remove sqlite_ functions from SQL
Date: Tue, 26 Jun 2018 16:33:41 +0300	[thread overview]
Message-ID: <bc5989f28ac98fbae1a22172915d49f2c9cb5def.1530020544.git.kyukhin@tarantool.org> (raw)

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 <unicode/ustring.h>
 #include <unicode/ucasemap.h>
 #include <unicode/ucnv.h>
@@ -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(
         -- </func-31.1>
     })
 
-
+test:do_execsql_test(
+    "func-32",
+    [[SELECT version()]],
+    {_TARANTOOL})
 
 test:finish_test()
-- 
2.16.2

             reply	other threads:[~2018-06-26 13:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-26 13:33 Kirill Yukhin [this message]
2018-06-26 15:17 ` [tarantool-patches] " n.pettik
2018-06-29 10:21   ` 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=bc5989f28ac98fbae1a22172915d49f2c9cb5def.1530020544.git.kyukhin@tarantool.org \
    --to=kyukhin@tarantool.org \
    --cc=korablev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH] sql: remove sqlite_ functions from SQL' \
    /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