Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH] sql: remove SQLite original 'fixing' routine
@ 2018-08-01 21:47 Nikita Pettik
  2018-08-02  8:42 ` [tarantool-patches] " Kirill Yukhin
  0 siblings, 1 reply; 2+ messages in thread
From: Nikita Pettik @ 2018-08-01 21:47 UTC (permalink / raw)
  To: tarantool-patches; +Cc: v.shpilevoy, Nikita Pettik

Now we operate only on one database, so prefixes like 'first_db.table1'
are not applieble to our SQL implementation (at least now).
---
Branch: https://github.com/tarantool/tarantool/commits/np/gh-remove-fixing-routine
Issue: no corresponding issue

 src/box/sql/CMakeLists.txt |   1 -
 src/box/sql/attach.c       | 197 ---------------------------------------------
 src/box/sql/sqliteInt.h    |  20 -----
 src/box/sql/trigger.c      |  11 ---
 4 files changed, 229 deletions(-)
 delete mode 100644 src/box/sql/attach.c

diff --git a/src/box/sql/CMakeLists.txt b/src/box/sql/CMakeLists.txt
index 64887cf49..1f852424a 100644
--- a/src/box/sql/CMakeLists.txt
+++ b/src/box/sql/CMakeLists.txt
@@ -32,7 +32,6 @@ add_library(sql STATIC
     parse.c
     alter.c
     analyze.c
-    attach.c
     cursor.c
     build.c
     callback.c
diff --git a/src/box/sql/attach.c b/src/box/sql/attach.c
deleted file mode 100644
index 59492351c..000000000
--- a/src/box/sql/attach.c
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * Copyright 2010-2017, Tarantool AUTHORS, please see AUTHORS file.
- *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the following
- * conditions are met:
- *
- * 1. Redistributions of source code must retain the above
- *    copyright notice, this list of conditions and the
- *    following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above
- *    copyright notice, this list of conditions and the following
- *    disclaimer in the documentation and/or other materials
- *    provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
- * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * This file contains code used to implement the ATTACH and DETACH commands.
- */
-#include "sqliteInt.h"
-
-/*
- * Initialize a DbFixer structure.  This routine must be called prior
- * to passing the structure to one of the sqliteFixAAAA() routines below.
- */
-void
-sqlite3FixInit(DbFixer * pFix,	/* The fixer to be initialized */
-	       Parse * pParse,	/* Error messages will be written here */
-	       const char *zType,	/* "view", "trigger", or "index" */
-	       const Token * pName	/* Name of the view, trigger, or index */
-    )
-{
-	sqlite3 *db;
-
-	db = pParse->db;
-	pFix->pParse = pParse;
-	pFix->pSchema = db->pSchema;
-	pFix->zType = zType;
-	pFix->pName = pName;
-	pFix->bVarOnly = 0;
-}
-
-/*
- * The following set of routines walk through the parse tree and assign
- * a specific database to all table references where the database name
- * was left unspecified in the original SQL statement.  The pFix structure
- * must have been initialized by a prior call to sqlite3FixInit().
- *
- * These routines are used to make sure that an index, trigger, or
- * view in one database does not refer to objects in a different database.
- * (Exception: indices, triggers, and views in the TEMP database are
- * allowed to refer to anything.)  If a reference is explicitly made
- * to an object in a different database, an error message is added to
- * pParse->zErrMsg and these routines return non-zero.  If everything
- * checks out, these routines return 0.
- */
-int
-sqlite3FixSrcList(DbFixer * pFix,	/* Context of the fixation */
-		  SrcList * pList	/* The Source list to check and modify */
-    )
-{
-	int i;
-	struct SrcList_item *pItem;
-
-	if (NEVER(pList == 0))
-		return 0;
-	for (i = 0, pItem = pList->a; i < pList->nSrc; i++, pItem++) {
-		if (pFix->bVarOnly == 0) {
-			pItem->pSchema = pFix->pSchema;
-		}
-		if (sqlite3FixSelect(pFix, pItem->pSelect))
-			return 1;
-		if (sqlite3FixExpr(pFix, pItem->pOn))
-			return 1;
-	}
-	return 0;
-}
-
-int
-sqlite3FixSelect(DbFixer * pFix,	/* Context of the fixation */
-		 Select * pSelect	/* The SELECT statement to be fixed to one database */
-    )
-{
-	while (pSelect) {
-		if (sqlite3FixExprList(pFix, pSelect->pEList)) {
-			return 1;
-		}
-		if (sqlite3FixSrcList(pFix, pSelect->pSrc)) {
-			return 1;
-		}
-		if (sqlite3FixExpr(pFix, pSelect->pWhere)) {
-			return 1;
-		}
-		if (sqlite3FixExprList(pFix, pSelect->pGroupBy)) {
-			return 1;
-		}
-		if (sqlite3FixExpr(pFix, pSelect->pHaving)) {
-			return 1;
-		}
-		if (sqlite3FixExprList(pFix, pSelect->pOrderBy)) {
-			return 1;
-		}
-		if (sqlite3FixExpr(pFix, pSelect->pLimit)) {
-			return 1;
-		}
-		if (sqlite3FixExpr(pFix, pSelect->pOffset)) {
-			return 1;
-		}
-		pSelect = pSelect->pPrior;
-	}
-	return 0;
-}
-
-int
-sqlite3FixExpr(DbFixer * pFix,	/* Context of the fixation */
-	       Expr * pExpr	/* The expression to be fixed to one database */
-    )
-{
-	while (pExpr) {
-		if (pExpr->op == TK_VARIABLE) {
-			if (pFix->pParse->db->init.busy) {
-				pExpr->op = TK_NULL;
-			} else {
-				sqlite3ErrorMsg(pFix->pParse,
-						"%s cannot use variables",
-						pFix->zType);
-				return 1;
-			}
-		}
-		if (ExprHasProperty(pExpr, EP_TokenOnly | EP_Leaf))
-			break;
-		if (ExprHasProperty(pExpr, EP_xIsSelect)) {
-			if (sqlite3FixSelect(pFix, pExpr->x.pSelect))
-				return 1;
-		} else {
-			if (sqlite3FixExprList(pFix, pExpr->x.pList))
-				return 1;
-		}
-		if (sqlite3FixExpr(pFix, pExpr->pRight)) {
-			return 1;
-		}
-		pExpr = pExpr->pLeft;
-	}
-	return 0;
-}
-
-int
-sqlite3FixExprList(DbFixer * pFix,	/* Context of the fixation */
-		   ExprList * pList	/* The expression to be fixed to one database */
-    )
-{
-	int i;
-	struct ExprList_item *pItem;
-	if (pList == 0)
-		return 0;
-	for (i = 0, pItem = pList->a; i < pList->nExpr; i++, pItem++) {
-		if (sqlite3FixExpr(pFix, pItem->pExpr)) {
-			return 1;
-		}
-	}
-	return 0;
-}
-
-int
-sqlite3FixTriggerStep(DbFixer * pFix,	/* Context of the fixation */
-		      TriggerStep * pStep	/* The trigger step be fixed to one database */
-    )
-{
-	while (pStep) {
-		if (sqlite3FixSelect(pFix, pStep->pSelect)) {
-			return 1;
-		}
-		if (sqlite3FixExpr(pFix, pStep->pWhere)) {
-			return 1;
-		}
-		if (sqlite3FixExprList(pFix, pStep->pExprList)) {
-			return 1;
-		}
-		pStep = pStep->pNext;
-	}
-	return 0;
-}
diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h
index 468b6c639..73c33d9d6 100644
--- a/src/box/sql/sqliteInt.h
+++ b/src/box/sql/sqliteInt.h
@@ -3044,20 +3044,6 @@ struct TriggerStep {
 	TriggerStep *pLast;	/* Last element in link-list. Valid for 1st elem only */
 };
 
-/*
- * The following structure contains information used by the sqliteFix...
- * routines as they walk the parse tree to make database references
- * explicit.
- */
-typedef struct DbFixer DbFixer;
-struct DbFixer {
-	Parse *pParse;		/* The parsing context.  Error messages written here */
-	Schema *pSchema;	/* Fix items to this schema */
-	int bVarOnly;		/* Check for variable references only */
-	const char *zType;	/* Type of the container - used for error messages */
-	const Token *pName;	/* Name of the container - used for error messages */
-};
-
 /*
  * An objected used to accumulate the text of a string where we
  * do not necessarily know how big the string will be in the end.
@@ -4226,12 +4212,6 @@ int sqlite3JoinType(Parse *, Token *, Token *, Token *);
 void sqlite3CreateForeignKey(Parse *, ExprList *, Token *, ExprList *, int);
 void sqlite3DeferForeignKey(Parse *, int);
 void sqlite3Detach(Parse *, Expr *);
-void sqlite3FixInit(DbFixer *, Parse *, const char *, const Token *);
-int sqlite3FixSrcList(DbFixer *, SrcList *);
-int sqlite3FixSelect(DbFixer *, Select *);
-int sqlite3FixExpr(DbFixer *, Expr *);
-int sqlite3FixExprList(DbFixer *, ExprList *);
-int sqlite3FixTriggerStep(DbFixer *, TriggerStep *);
 int sqlite3AtoF(const char *z, double *, int);
 int sqlite3GetInt32(const char *, int *);
 int sqlite3Atoi(const char *);
diff --git a/src/box/sql/trigger.c b/src/box/sql/trigger.c
index 46f7c31e3..a7b84c39f 100644
--- a/src/box/sql/trigger.c
+++ b/src/box/sql/trigger.c
@@ -70,8 +70,6 @@ sql_trigger_begin(struct Parse *parse, struct Token *name, int tr_tm,
 	struct sql_trigger *trigger = NULL;
 	/* The database connection. */
 	struct sqlite3 *db = parse->db;
-	/* State vector for the DB fixer. */
-	struct DbFixer fixdb;
 	/* The name of the Trigger. */
 	char *trigger_name = NULL;
 
@@ -94,9 +92,6 @@ sql_trigger_begin(struct Parse *parse, struct Token *name, int tr_tm,
 	if (db->mallocFailed)
 		goto trigger_cleanup;
 	assert(table->nSrc == 1);
-	sqlite3FixInit(&fixdb, parse, "trigger", name);
-	if (sqlite3FixSrcList(&fixdb, table) != 0)
-		goto trigger_cleanup;
 
 	trigger_name = sqlite3NameFromToken(db, name);
 	if (trigger_name == NULL)
@@ -191,13 +186,7 @@ sql_trigger_finish(struct Parse *parse, struct TriggerStep *step_list,
 
 	/* Trigger name for error reporting. */
 	struct Token trigger_name_token;
-	/* Fixer object. */
-	struct DbFixer fixdb;
 	sqlite3TokenInit(&trigger_name_token, trigger->zName);
-	sqlite3FixInit(&fixdb, parse, "trigger", &trigger_name_token);
-	if (sqlite3FixTriggerStep(&fixdb, trigger->step_list) ||
-	    sqlite3FixExpr(&fixdb, trigger->pWhen))
-		goto triggerfinish_cleanup;
 
 	/*
 	 * Generate byte code to insert a new trigger into
-- 
2.15.1

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

* [tarantool-patches] Re: [PATCH] sql: remove SQLite original 'fixing' routine
  2018-08-01 21:47 [tarantool-patches] [PATCH] sql: remove SQLite original 'fixing' routine Nikita Pettik
@ 2018-08-02  8:42 ` Kirill Yukhin
  0 siblings, 0 replies; 2+ messages in thread
From: Kirill Yukhin @ 2018-08-02  8:42 UTC (permalink / raw)
  To: tarantool-patches; +Cc: v.shpilevoy, Nikita Pettik

Hello,
On 02 авг 00:47, Nikita Pettik wrote:
> Now we operate only on one database, so prefixes like 'first_db.table1'
> are not applieble to our SQL implementation (at least now).
> ---
> Branch: https://github.com/tarantool/tarantool/commits/np/gh-remove-fixing-routine
> Issue: no corresponding issue
Comitted to 2.0 branch as obvious.

--
Regards, Kirill Yukhin

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

end of thread, other threads:[~2018-08-02  8:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-01 21:47 [tarantool-patches] [PATCH] sql: remove SQLite original 'fixing' routine Nikita Pettik
2018-08-02  8:42 ` [tarantool-patches] " Kirill Yukhin

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