[tarantool-patches] [PATCH v1 1/4] sql: patch sql_name_from_token to use Parser

Kirill Shcherbatov kshcherbatov at tarantool.org
Fri Feb 15 16:30:48 MSK 2019


The code was refactored so that the sql_name_from_token function
would use the parser object instead of database connection. Also
performed some additional names refactoring in adjacent places.

Needed for #3931
---
 src/box/sql/alter.c   |   2 +-
 src/box/sql/analyze.c |   2 +-
 src/box/sql/build.c   | 162 ++++++++++++++----------------------------
 src/box/sql/delete.c  |   2 +-
 src/box/sql/expr.c    |   2 +-
 src/box/sql/fkey.c    |   4 +-
 src/box/sql/parse.y   |  10 +--
 src/box/sql/pragma.c  |  11 ++-
 src/box/sql/select.c  |   4 +-
 src/box/sql/sqlInt.h  |  81 ++++++++++++++++++++-
 src/box/sql/trigger.c |   4 +-
 11 files changed, 152 insertions(+), 132 deletions(-)

diff --git a/src/box/sql/alter.c b/src/box/sql/alter.c
index d49ebb8df..6d9960156 100644
--- a/src/box/sql/alter.c
+++ b/src/box/sql/alter.c
@@ -43,7 +43,7 @@ sql_alter_table_rename(struct Parse *parse, struct SrcList *src_tab,
 {
 	assert(src_tab->nSrc == 1);
 	struct sql *db = parse->db;
-	char *new_name = sqlNameFromToken(db, new_name_tk);
+	char *new_name = sql_name_from_token(parse, new_name_tk);
 	if (new_name == NULL)
 		goto exit_rename_table;
 	/* Check that new name isn't occupied by another table. */
diff --git a/src/box/sql/analyze.c b/src/box/sql/analyze.c
index 7eabd0c7e..e82dcde0a 100644
--- a/src/box/sql/analyze.c
+++ b/src/box/sql/analyze.c
@@ -1118,7 +1118,7 @@ sqlAnalyze(Parse * pParse, Token * pName)
 		sql_analyze_database(pParse);
 	} else {
 		/* Form 2:  Analyze table named */
-		char *z = sqlNameFromToken(db, pName);
+		char *z = sql_name_from_token(pParse, pName);
 		if (z != NULL) {
 			struct space *sp = space_by_name(z);
 			if (sp != NULL) {
diff --git a/src/box/sql/build.c b/src/box/sql/build.c
index 5dc3d0248..3f4530620 100644
--- a/src/box/sql/build.c
+++ b/src/box/sql/build.c
@@ -294,30 +294,15 @@ sqlDeleteTable(sql * db, Table * pTable)
 	table_delete(db, pTable);
 }
 
-/*
- * Given a token, return a string that consists of the text of that
- * token.  Space to hold the returned string
- * is obtained from sqlMalloc() and must be freed by the calling
- * function.
- *
- * Any quotation marks (ex:  "name", 'name', [name], or `name`) that
- * surround the body of the token are removed.
- *
- * Tokens are often just pointers into the original SQL text and so
- * are not \000 terminated and are not persistent.  The returned string
- * is \000 terminated and is persistent.
- */
 char *
-sqlNameFromToken(sql * db, Token * pName)
+sql_name_from_token(struct Parse *parser, struct Token *name_token)
 {
-	char *zName;
-	if (pName) {
-		zName = sqlDbStrNDup(db, (char *)pName->z, pName->n);
-		sqlNormalizeName(zName);
-	} else {
-		zName = 0;
-	}
-	return zName;
+	if (name_token == NULL || name_token->z == NULL)
+		return NULL;
+	char *name = sqlDbStrNDup(parser->db, (char *)name_token->z,
+				  name_token->n);
+	sqlNormalizeName(name);
+	return name;
 }
 
 /*
@@ -404,7 +389,7 @@ sqlStartTable(Parse *pParse, Token *pName, int noErr)
 		goto cleanup;
 	sqlVdbeCountChanges(v);
 
-	zName = sqlNameFromToken(db, pName);
+	zName = sql_name_from_token(pParse, pName);
 
 	pParse->sNameToken = *pName;
 	if (zName == 0)
@@ -779,7 +764,7 @@ sqlAddCollateType(Parse * pParse, Token * pToken)
 		return;
 	uint32_t i = p->def->field_count - 1;
 	sql *db = pParse->db;
-	char *zColl = sqlNameFromToken(db, pToken);
+	char *zColl = sql_name_from_token(pParse, pToken);
 	if (!zColl)
 		return;
 	uint32_t *coll_id = &p->def->fields[i].coll_id;
@@ -1838,7 +1823,7 @@ sql_create_foreign_key(struct Parse *parse_context, struct SrcList *child,
 		rlist_add_entry(&parse_context->new_fkey, fk, link);
 	}
 	assert(parent != NULL);
-	parent_name = sqlNameFromToken(db, parent);
+	parent_name = sql_name_from_token(parse_context, parent);
 	if (parent_name == NULL)
 		goto exit_create_fk;
 	/*
@@ -1875,10 +1860,12 @@ sql_create_foreign_key(struct Parse *parse_context, struct SrcList *child,
 					       new_tab->def->name);
 		} else {
 			struct Token *cnstr_nm = &parse_context->constraintName;
-			constraint_name = sqlNameFromToken(db, cnstr_nm);
+			constraint_name = sql_name_from_token(parse_context,
+							      cnstr_nm);
 		}
 	} else {
-		constraint_name = sqlNameFromToken(db, constraint);
+		constraint_name =
+			sql_name_from_token(parse_context, constraint);
 	}
 	if (constraint_name == NULL)
 		goto exit_create_fk;
@@ -2011,8 +1998,7 @@ sql_drop_foreign_key(struct Parse *parse_context, struct SrcList *table,
 		parse_context->nErr++;
 		return;
 	}
-	char *constraint_name = sqlNameFromToken(parse_context->db,
-						     constraint);
+	char *constraint_name = sql_name_from_token(parse_context, constraint);
 	if (constraint_name != NULL)
 		vdbe_emit_fkey_drop(parse_context, constraint_name,
 				    child->def->id);
@@ -2282,7 +2268,7 @@ sql_create_index(struct Parse *parse, struct Token *token,
 	 */
 	if (token != NULL) {
 		assert(token->z != NULL);
-		name = sqlNameFromToken(db, token);
+		name = sql_name_from_token(parse, token);
 		if (name == NULL)
 			goto exit_create_index;
 		if (sql_space_index_by_name(space, name) != NULL) {
@@ -2295,10 +2281,11 @@ sql_create_index(struct Parse *parse, struct Token *token,
 		}
 	} else {
 		char *constraint_name = NULL;
-		if (parse->constraintName.z != NULL)
+		if (parse->constraintName.z != NULL) {
 			constraint_name =
-				sqlNameFromToken(db,
-						     &parse->constraintName);
+				sql_name_from_token(parse,
+						    &parse->constraintName);
+		}
 
 	       /*
 		* This naming is temporary. Now it's not
@@ -2539,7 +2526,8 @@ sql_drop_index(struct Parse *parse_context, struct SrcList *index_name_list,
 	/* Never called with prior errors. */
 	assert(parse_context->nErr == 0);
 	assert(table_token != NULL);
-	const char *table_name = sqlNameFromToken(db, table_token);
+	const char *table_name =
+		sql_name_from_token(parse_context, table_token);
 	if (db->mallocFailed) {
 		goto exit_drop_index;
 	}
@@ -2626,30 +2614,25 @@ sqlArrayAllocate(sql * db,	/* Connection to notify of malloc failures */
 	return pArray;
 }
 
-/*
- * Append a new element to the given IdList.  Create a new IdList if
- * need be.
- *
- * A new IdList is returned, or NULL if malloc() fails.
- */
-IdList *
-sqlIdListAppend(sql * db, IdList * pList, Token * pToken)
+struct IdList *
+sql_IdList_append(struct Parse *parser, struct IdList *list,
+		  struct Token *name_token)
 {
+	struct sql *db = parser->db;
 	int i;
-	if (pList == 0) {
-		pList = sqlDbMallocZero(db, sizeof(IdList));
-		if (pList == 0)
-			return 0;
+	if (list == NULL) {
+		list = sqlDbMallocZero(db, sizeof(IdList));
+		if (list == NULL)
+			return NULL;
 	}
-	pList->a = sqlArrayAllocate(db,
-					pList->a,
-					sizeof(pList->a[0]), &pList->nId, &i);
+	list->a = sqlArrayAllocate(db, list->a, sizeof(list->a[0]),
+				   &list->nId, &i);
 	if (i < 0) {
-		sqlIdListDelete(db, pList);
+		sqlIdListDelete(db, list);
 		return 0;
 	}
-	pList->a[i].zName = sqlNameFromToken(db, pToken);
-	return pList;
+	list->a[i].zName = sql_name_from_token(parser, name_token);
+	return list;
 }
 
 /*
@@ -2772,62 +2755,26 @@ sql_alloc_src_list(sql *db)
 	return pList;
 }
 
-/*
- * Append a new table name to the given SrcList.  Create a new SrcList if
- * need be.  A new entry is created in the SrcList even if pTable is NULL.
- *
- * A SrcList is returned, or NULL if there is an OOM error.  The returned
- * SrcList might be the same as the SrcList that was input or it might be
- * a new one.  If an OOM error does occurs, then the prior value of pList
- * that is input to this routine is automatically freed.
- *
- * If pDatabase is not null, it means that the table has an optional
- * database name prefix.  Like this:  "database.table".  The pDatabase
- * points to the table name and the pTable points to the database name.
- * The SrcList.a[].zName field is filled with the table name which might
- * come from pTable (if pDatabase is NULL) or from pDatabase.
- * SrcList.a[].zDatabase is filled with the database name from pTable,
- * or with NULL if no database is specified.
- *
- * In other words, if call like this:
- *
- *         sqlSrcListAppend(D,A,B,0);
- *
- * Then B is a table name and the database name is unspecified.  If called
- * like this:
- *
- *         sqlSrcListAppend(D,A,B,C);
- *
- * Then C is the table name and B is the database name.  If C is defined
- * then so is B.  In other words, we never have a case where:
- *
- *         sqlSrcListAppend(D,A,0,C);
- *
- * Both pTable and pDatabase are assumed to be quoted.  They are dequoted
- * before being added to the SrcList.
- */
-SrcList *
-sqlSrcListAppend(sql * db,	/* Connection to notify of malloc failures */
-		     SrcList * pList,	/* Append to this SrcList. NULL creates a new SrcList */
-		     Token * pTable	/* Table to append */
-    )
+struct SrcList *
+sql_SrcList_append(struct Parse *parser, struct SrcList *list,
+		   struct Token *name_token)
 {
 	struct SrcList_item *pItem;
-	assert(db != 0);
-	if (pList == 0) {
-		pList = sql_alloc_src_list(db);
-		if (pList == 0)
-			return 0;
+	struct sql *db = parser->db;
+	if (list == NULL) {
+		list = sql_alloc_src_list(db);
+		if (list == NULL)
+			return NULL;
 	} else {
-		pList = sqlSrcListEnlarge(db, pList, 1, pList->nSrc);
+		list = sqlSrcListEnlarge(db, list, 1, list->nSrc);
 	}
 	if (db->mallocFailed) {
-		sqlSrcListDelete(db, pList);
+		sqlSrcListDelete(db, list);
 		return 0;
 	}
-	pItem = &pList->a[pList->nSrc - 1];
-	pItem->zName = sqlNameFromToken(db, pTable);
-	return pList;
+	pItem = &list->a[list->nSrc - 1];
+	pItem->zName = sql_name_from_token(parser, name_token);
+	return list;
 }
 
 /*
@@ -2909,15 +2856,14 @@ sqlSrcListAppendFromTerm(Parse * pParse,	/* Parsing context */
 		    );
 		goto append_from_error;
 	}
-	p = sqlSrcListAppend(db, p, pTable);
+	p = sql_SrcList_append(pParse, p, pTable);
 	if (p == 0 || NEVER(p->nSrc == 0)) {
 		goto append_from_error;
 	}
 	pItem = &p->a[p->nSrc - 1];
 	assert(pAlias != 0);
-	if (pAlias->n) {
-		pItem->zAlias = sqlNameFromToken(db, pAlias);
-	}
+	if (pAlias->n != 0)
+		pItem->zAlias = sql_name_from_token(pParse, pAlias);
 	pItem->pSelect = pSubquery;
 	pItem->pOn = pOn;
 	pItem->pUsing = pUsing;
@@ -2951,7 +2897,7 @@ sqlSrcListIndexedBy(Parse * pParse, SrcList * p, Token * pIndexedBy)
 			pItem->fg.notIndexed = 1;
 		} else {
 			pItem->u1.zIndexedBy =
-			    sqlNameFromToken(pParse->db, pIndexedBy);
+			    sql_name_from_token(pParse, pIndexedBy);
 			pItem->fg.isIndexedBy = (pItem->u1.zIndexedBy != 0);
 		}
 	}
@@ -3037,7 +2983,7 @@ sql_transaction_rollback(Parse *pParse)
 void
 sqlSavepoint(Parse * pParse, int op, Token * pName)
 {
-	char *zName = sqlNameFromToken(pParse->db, pName);
+	char *zName = sql_name_from_token(pParse, pName);
 	if (zName) {
 		Vdbe *v = sqlGetVdbe(pParse);
 		if (!v) {
@@ -3131,7 +3077,7 @@ sqlWithAdd(Parse * pParse,	/* Parsing context */
 	/* Check that the CTE name is unique within this WITH clause. If
 	 * not, store an error in the Parse structure.
 	 */
-	zName = sqlNameFromToken(pParse->db, pName);
+	zName = sql_name_from_token(pParse, pName);
 	if (zName && pWith) {
 		int i;
 		for (i = 0; i < pWith->nCte; i++) {
diff --git a/src/box/sql/delete.c b/src/box/sql/delete.c
index 41daa44ee..2b5d820ab 100644
--- a/src/box/sql/delete.c
+++ b/src/box/sql/delete.c
@@ -71,7 +71,7 @@ sql_materialize_view(struct Parse *parse, const char *name, struct Expr *where,
 {
 	struct sql *db = parse->db;
 	where = sqlExprDup(db, where, 0);
-	struct SrcList *from = sqlSrcListAppend(db, NULL, NULL);
+	struct SrcList *from = sql_SrcList_append(parse, NULL, NULL);
 	if (from != NULL) {
 		assert(from->nSrc == 1);
 		from->a[0].zName = sqlDbStrDup(db, name);
diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c
index 4450ac7ee..a6e35df6d 100644
--- a/src/box/sql/expr.c
+++ b/src/box/sql/expr.c
@@ -1583,7 +1583,7 @@ sqlIdListDup(sql * db, IdList * p)
 		return 0;
 	}
 	/* Note that because the size of the allocation for p->a[] is not
-	 * necessarily a power of two, sqlIdListAppend() may not be called
+	 * necessarily a power of two, sql_IdList_append() may not be called
 	 * on the duplicate created by this function.
 	 */
 	for (i = 0; i < p->nId; i++) {
diff --git a/src/box/sql/fkey.c b/src/box/sql/fkey.c
index 32e5b3335..69740b39f 100644
--- a/src/box/sql/fkey.c
+++ b/src/box/sql/fkey.c
@@ -610,7 +610,7 @@ fkey_emit_check(struct Parse *parser, struct Table *tab, int reg_old,
 		 * table. We need the child table as a SrcList for
 		 * sqlWhereBegin().
 		 */
-		struct SrcList *src = sqlSrcListAppend(db, NULL, NULL);
+		struct SrcList *src = sql_SrcList_append(parser, NULL, NULL);
 		if (src == NULL)
 			continue;
 		struct SrcList_item *item = src->a;
@@ -871,7 +871,7 @@ fkey_action_trigger(struct Parse *pParse, struct Table *pTab, struct fkey *fkey,
 			r->on_conflict_action = ON_CONFLICT_ACTION_ABORT;
 		select = sqlSelectNew(pParse,
 					  sql_expr_list_append(db, NULL, r),
-					  sqlSrcListAppend(db, NULL, &err),
+					  sql_SrcList_append(pParse, NULL, &err),
 					  where, NULL, NULL, NULL, 0, NULL,
 					  NULL);
 		where = NULL;
diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y
index 661e69584..4713d0d09 100644
--- a/src/box/sql/parse.y
+++ b/src/box/sql/parse.y
@@ -604,7 +604,7 @@ seltablist(A) ::= stl_prefix(A) LP seltablist(F) RP
 %type fullname {SrcList*}
 %destructor fullname {sqlSrcListDelete(pParse->db, $$);}
 fullname(A) ::= nm(X).  
-   {A = sqlSrcListAppend(pParse->db,0,&X); /*A-overwrites-X*/}
+   {A = sql_SrcList_append(pParse,0,&X); /*A-overwrites-X*/}
 
 %type joinop {int}
 join_nm(A) ::= id(A).
@@ -786,9 +786,9 @@ insert_cmd(A) ::= REPLACE.            {A = ON_CONFLICT_ACTION_REPLACE;}
 idlist_opt(A) ::= .                       {A = 0;}
 idlist_opt(A) ::= LP idlist(X) RP.    {A = X;}
 idlist(A) ::= idlist(A) COMMA nm(Y).
-    {A = sqlIdListAppend(pParse->db,A,&Y);}
+    {A = sql_IdList_append(pParse,A,&Y);}
 idlist(A) ::= nm(Y).
-    {A = sqlIdListAppend(pParse->db,0,&Y); /*A-overwrites-Y*/}
+    {A = sql_IdList_append(pParse,0,&Y); /*A-overwrites-Y*/}
 
 /////////////////////////// Expression Processing /////////////////////////////
 //
@@ -1140,7 +1140,7 @@ expr(A) ::= expr(A) in_op(N) LP select(Y) RP(E).  [IN] {
   A.zEnd = &E.z[E.n];
 }
 expr(A) ::= expr(A) in_op(N) nm(Y) paren_exprlist(E). [IN] {
-  SrcList *pSrc = sqlSrcListAppend(pParse->db, 0,&Y);
+  SrcList *pSrc = sql_SrcList_append(pParse, 0,&Y);
   Select *pSelect = sqlSelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
   if( E )  sqlSrcListFuncArgs(pParse, pSelect ? pSrc : 0, E);
   A.pExpr = sqlPExpr(pParse, TK_IN, A.pExpr, 0);
@@ -1210,7 +1210,7 @@ paren_exprlist(A) ::= LP exprlist(X) RP.  {A = X;}
 //
 cmd ::= createkw(S) uniqueflag(U) INDEX ifnotexists(NE) nm(X)
         ON nm(Y) LP sortlist(Z) RP. {
-  sql_create_index(pParse, &X, sqlSrcListAppend(pParse->db,0,&Y), Z, &S,
+  sql_create_index(pParse, &X, sql_SrcList_append(pParse,0,&Y), Z, &S,
                    SORT_ORDER_ASC, NE, U);
 }
 
diff --git a/src/box/sql/pragma.c b/src/box/sql/pragma.c
index f3e66f506..797224792 100644
--- a/src/box/sql/pragma.c
+++ b/src/box/sql/pragma.c
@@ -436,18 +436,17 @@ sqlPragma(Parse * pParse, Token * pId,	/* First part of [schema.]id field */
 	sqlVdbeRunOnlyOnce(v);
 	pParse->nMem = 2;
 
-	zLeft = sqlNameFromToken(db, pId);
+	zLeft = sql_name_from_token(pParse, pId);
 	if (!zLeft) {
 		printActivePragmas(user_session);
 		return;
 	}
 
-	if (minusFlag) {
+	if (minusFlag)
 		zRight = sqlMPrintf(db, "-%T", pValue);
-	} else {
-		zRight = sqlNameFromToken(db, pValue);
-	}
-	zTable = sqlNameFromToken(db, pValue2);
+	else
+		zRight = sql_name_from_token(pParse, pValue);
+	zTable = sql_name_from_token(pParse, pValue2);
 	db->busyHandler.nBusy = 0;
 
 	/* Locate the pragma in the lookup table */
diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index a6e78d0df..dfd3a375e 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -256,7 +256,7 @@ findRightmost(Select * p)
 
 
 /**
- * Work the same as sqlSrcListAppend(), but before adding to
+ * Work the same as sql_SrcList_append(), but before adding to
  * list provide check on name duplicates: only values with unique
  * names are appended. Moreover, names of tables are not
  * normalized: it is parser's business and in struct Select they
@@ -4112,7 +4112,7 @@ flattenSubquery(Parse * pParse,		/* Parsing context */
 		} else {
 			assert(pParent != p);	/* 2nd and subsequent times through the loop */
 			pSrc = pParent->pSrc =
-			    sqlSrcListAppend(db, 0, 0);
+			    sql_SrcList_append(pParse, 0, 0);
 			if (pSrc == 0) {
 				assert(db->mallocFailed);
 				break;
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 7f17fd84a..498982e01 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -3468,12 +3468,70 @@ void sqlDeleteTable(sql *, Table *);
 void sqlInsert(Parse *, SrcList *, Select *, IdList *,
 		   enum on_conflict_action);
 void *sqlArrayAllocate(sql *, void *, int, int *, int *);
-IdList *sqlIdListAppend(sql *, IdList *, Token *);
+
+/*
+ * Append a new element to the given IdList.  Create a new IdList if
+ * need be.
+ * A new IdList is returned, or NULL if malloc() fails.
+ * @param parser The parse context.
+ * @param list The pointer to existent Id list if exists.
+ * @param name_token The token containing name.
+ * @retval not NULL IdList pointer is returned on success.
+ * @retval NULL otherwise.
+ */
+struct IdList *
+sql_IdList_append(struct Parse *parser, struct IdList *pList,
+		  struct Token *pToken);
+
 int sqlIdListIndex(IdList *, const char *);
 SrcList *sqlSrcListEnlarge(sql *, SrcList *, int, int);
 SrcList *
 sql_alloc_src_list(sql *db);
-SrcList *sqlSrcListAppend(sql *, SrcList *, Token *);
+/*
+ * Append a new table name to the given list.  Create a new
+ * SrcList if need be. A new entry is created in the list even
+ * if name_token is NULL.
+ *
+ * A SrcList is returned, or NULL if there is an OOM error.
+ * The returned SrcList might be the same as the SrcList that was
+ * input or it might be a new one. If an OOM error does occurs,
+ * then the prior value of list that is input to this routine is
+ * automatically freed.
+ *
+ * If pDatabase is not null, it means that the table has an
+ * optional database name prefix. Like this: "database.table".
+ * The pDatabase points to the table name and the pTable points
+ * to the database name. The SrcList.a[].zName field is filled
+ * with the table name which might come from pTable (if pDatabase
+ * is NULL) or from pDatabase.
+ * SrcList.a[].zDatabase is filled with the database name from
+ * name_token, or with NULL if no database is specified.
+ *
+ * In other words, if call like this:
+ *
+ *         sql_SrcList_append(D,A,B,0);
+ *
+ * Then B is a table name and the database name is unspecified.
+ * If called like this:
+ *
+ *         sql_SrcList_append(D,A,B,C);
+ *
+ * Then C is the table name and B is the database name.  If C is
+ * defined then so is B.  In other words, we never have a case
+ * where:
+ *
+ *         sql_SrcList_append(D,A,0,C);
+ *
+ * Both pTable and pDatabase are assumed to be quoted. They are
+ * dequoted before being added to the SrcList.
+ * @param parser Parse context.
+ * @param list Append to this SrcList. NULL creates a new SrcList.
+ * @param name_token Token representing table name.
+ * @retval not NULL SrcList pointer on success, NULL otherwise.
+ */
+struct SrcList *
+sql_SrcList_append(struct Parse *parse, struct SrcList * pList,
+		   struct Token *pTable);
 SrcList *sqlSrcListAppendFromTerm(Parse *, SrcList *, Token *,
 				      Token *, Select *, Expr *, IdList *);
 void sqlSrcListIndexedBy(Parse *, SrcList *, Token *);
@@ -3656,7 +3714,24 @@ int sqlExprCodeExprList(Parse *, ExprList *, int, int, u8);
 void sqlExprIfTrue(Parse *, Expr *, int, int);
 void sqlExprIfFalse(Parse *, Expr *, int, int);
 
-char *sqlNameFromToken(sql *, Token *);
+/*
+ * Given a token, return a string that consists of the text of
+ * that token. Space to hold the returned string is obtained
+ * from sqlMalloc() and must be freed by the calling function.
+ *
+ * Any quotation marks (ex:  "name", 'name', [name], or `name`)
+ * that surround the body of the token are removed.
+ *
+ * Tokens are often just pointers into the original SQL text and
+ * so are not \000 terminated and are not persistent. The returned
+ * string is \000 terminated and is persistent.
+ * @param parser The parse context.
+ * @param name_token The source token with text.
+ * @retval not NULL string pointer on success, NULL otherwise.
+ */
+char *
+sql_name_from_token(struct Parse *parser, struct Token *name_token);
+
 int sqlExprCompare(Expr *, Expr *, int);
 int sqlExprListCompare(ExprList *, ExprList *, int);
 int sqlExprImpliesExpr(Expr *, Expr *, int);
diff --git a/src/box/sql/trigger.c b/src/box/sql/trigger.c
index 8ad4e2ebd..2f54754fa 100644
--- a/src/box/sql/trigger.c
+++ b/src/box/sql/trigger.c
@@ -82,7 +82,7 @@ sql_trigger_begin(struct Parse *parse, struct Token *name, int tr_tm,
 		goto trigger_cleanup;
 	assert(table->nSrc == 1);
 
-	trigger_name = sqlNameFromToken(db, name);
+	trigger_name = sql_name_from_token(parse, name);
 	if (trigger_name == NULL)
 		goto trigger_cleanup;
 
@@ -588,7 +588,7 @@ targetSrcList(Parse * pParse,	/* The parsing context */
 	sql *db = pParse->db;
 	SrcList *pSrc;		/* SrcList to be returned */
 
-	pSrc = sqlSrcListAppend(db, 0, 0);
+	pSrc = sql_SrcList_append(pParse, 0, 0);
 	if (pSrc) {
 		assert(pSrc->nSrc > 0);
 		pSrc->a[pSrc->nSrc - 1].zName =
-- 
2.20.1





More information about the Tarantool-patches mailing list