Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH] sql: remove sqlite_ functions from SQL
@ 2018-06-26 13:33 Kirill Yukhin
  2018-06-26 15:17 ` [tarantool-patches] " n.pettik
  0 siblings, 1 reply; 3+ messages in thread
From: Kirill Yukhin @ 2018-06-26 13:33 UTC (permalink / raw)
  To: korablev; +Cc: tarantool-patches, 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 <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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tarantool-patches] Re: [PATCH] sql: remove sqlite_ functions from SQL
  2018-06-26 13:33 [tarantool-patches] [PATCH] sql: remove sqlite_ functions from SQL Kirill Yukhin
@ 2018-06-26 15:17 ` n.pettik
  2018-06-29 10:21   ` Kirill Yukhin
  0 siblings, 1 reply; 3+ messages in thread
From: n.pettik @ 2018-06-26 15:17 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Kirill Yukhin


> On 26 Jun 2018, at 16:33, Kirill Yukhin <kyukhin@tarantool.org> wrote:
> 
> 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
> —

Please, put links to the branch and issue here (after ‘- - -‘).

Also, I have found one mention of sqlite_version():

File: resolve.c, line: 709

/* Date/time functions that use 'now', and other functions like
 * sqlite_version() that might change over time cannot be used
 * in an index.
 */

Lets remove it as well.

Except for this, LGTM.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tarantool-patches] Re: [PATCH] sql: remove sqlite_ functions from SQL
  2018-06-26 15:17 ` [tarantool-patches] " n.pettik
@ 2018-06-29 10:21   ` Kirill Yukhin
  0 siblings, 0 replies; 3+ messages in thread
From: Kirill Yukhin @ 2018-06-29 10:21 UTC (permalink / raw)
  To: n.pettik; +Cc: tarantool-patches

Hello Nikita,
On 26 июн 18:17, n.pettik wrote:
> 
> > On 26 Jun 2018, at 16:33, Kirill Yukhin <kyukhin@tarantool.org> wrote:
> > 
> > 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
> > —
> 
> Please, put links to the branch and issue here (after ‘- - -‘).
Forgot about that, thanks!

> Also, I have found one mention of sqlite_version():
> 
> File: resolve.c, line: 709
Thanks I've fixed that.

Patch merged into 2.0.

--
Thanks, Kirill Yukhin

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-06-29 10:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-26 13:33 [tarantool-patches] [PATCH] sql: remove sqlite_ functions from SQL Kirill Yukhin
2018-06-26 15:17 ` [tarantool-patches] " n.pettik
2018-06-29 10:21   ` Kirill Yukhin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox