[patches] [PATCH 2/7] sql: remove SQLITE_ENABLE_COLUMN_METADATA and _OMIT_DECLTYPE

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Wed Feb 28 22:36:49 MSK 2018


Remove unused definitions, functions, arguments.

Signed-off-by: Vladislav Shpilevoy <v.shpilevoy at tarantool.org>
---
 src/box/sql/select.c  | 50 +++++--------------------------
 src/box/sql/sqlite3.h | 81 ++++++---------------------------------------------
 src/box/sql/vdbe.h    | 18 +++---------
 src/box/sql/vdbeapi.c | 76 +++++++++++------------------------------------
 4 files changed, 37 insertions(+), 188 deletions(-)

diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index 041e6ca87..660423d76 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -1588,29 +1588,16 @@ generateSortTail(Parse * pParse,	/* Parsing context */
  *   SELECT abc FROM (SELECT col AS abc FROM tbl);
  *
  * The declaration type for any expression other than a column is NULL.
- *
- * This routine has either 3 or 6 parameters depending on whether or not
- * the SQLITE_ENABLE_COLUMN_METADATA compile-time option is used.
  */
-#ifdef SQLITE_ENABLE_COLUMN_METADATA
-#define columnType(A,B,C,D,E,F) columnTypeImpl(A,B,D,E,F)
-#else				/* if !defined(SQLITE_ENABLE_COLUMN_METADATA) */
-#define columnType(A,B,C,D,E,F) columnTypeImpl(A,B,F)
-#endif
 static const char *
-columnTypeImpl(NameContext * pNC, Expr * pExpr,
-#ifdef SQLITE_ENABLE_COLUMN_METADATA
-	       const char **pzOrigTab, const char **pzOrigCol,
-#endif
-	       u8 * pEstWidth)
+columnType(NameContext *pNC, Expr *pExpr, const char **pzOrigTab,
+	   const char **pzOrigCol, u8 *pEstWidth)
 {
 	char const *zType = 0;
 	int j;
 	u8 estWidth = 1;
-#ifdef SQLITE_ENABLE_COLUMN_METADATA
 	char const *zOrigTab = 0;
 	char const *zOrigCol = 0;
-#endif
 
 	assert(pExpr != 0);
 	assert(pNC->pSrcList != 0);
@@ -1680,23 +1667,17 @@ columnTypeImpl(NameContext * pNC, Expr * pExpr,
 					sNC.pNext = pNC;
 					sNC.pParse = pNC->pParse;
 					zType =
-					    columnType(&sNC, p, 0,
-						       &zOrigTab, &zOrigCol,
-						       &estWidth);
+					    columnType(&sNC, p, &zOrigTab,
+						       &zOrigCol, &estWidth);
 				}
 			} else if (pTab->pSchema) {
 				/* A real table */
 				assert(!pS);
 				assert(iCol >= 0 && iCol < pTab->nCol);
-#ifdef SQLITE_ENABLE_COLUMN_METADATA
 				zOrigCol = pTab->aCol[iCol].zName;
 				zType = sqlite3ColumnType(&pTab->aCol[iCol], 0);
 				estWidth = pTab->aCol[iCol].szEst;
 				zOrigTab = pTab->zName;
-#else
-				zType = sqlite3ColumnType(&pTab->aCol[iCol], 0);
-				estWidth = pTab->aCol[iCol].szEst;
-#endif
 			}
 			break;
 		}
@@ -1714,20 +1695,18 @@ columnTypeImpl(NameContext * pNC, Expr * pExpr,
 			sNC.pNext = pNC;
 			sNC.pParse = pNC->pParse;
 			zType =
-			    columnType(&sNC, p, 0, &zOrigTab, &zOrigCol,
+			    columnType(&sNC, p, &zOrigTab, &zOrigCol,
 				       &estWidth);
 			break;
 		}
 #endif
 	}
 
-#ifdef SQLITE_ENABLE_COLUMN_METADATA
 	if (pzOrigTab) {
 		assert(pzOrigTab && pzOrigCol);
 		*pzOrigTab = zOrigTab;
 		*pzOrigCol = zOrigCol;
 	}
-#endif
 	if (pEstWidth)
 		*pEstWidth = estWidth;
 	return zType;
@@ -1742,7 +1721,6 @@ generateColumnTypes(Parse * pParse,	/* Parser context */
 		    SrcList * pTabList,	/* List of tables */
 		    ExprList * pEList)	/* Expressions defining the result set */
 {
-#ifndef SQLITE_OMIT_DECLTYPE
 	Vdbe *v = pParse->pVdbe;
 	int i;
 	NameContext sNC;
@@ -1751,29 +1729,15 @@ generateColumnTypes(Parse * pParse,	/* Parser context */
 	for (i = 0; i < pEList->nExpr; i++) {
 		Expr *p = pEList->a[i].pExpr;
 		const char *zType;
-#ifdef SQLITE_ENABLE_COLUMN_METADATA
-		const char *zOrigDb = 0;
 		const char *zOrigTab = 0;
 		const char *zOrigCol = 0;
-		zType = columnType(&sNC, p, &zOrigDb, &zOrigTab, &zOrigCol, 0);
+		zType = columnType(&sNC, p, &zOrigTab, &zOrigCol, 0);
 
-		/* The vdbe must make its own copy of the column-type and other
-		 * column specific strings, in case the schema is reset before this
-		 * virtual machine is deleted.
-		 */
-		sqlite3VdbeSetColName(v, i, COLNAME_DATABASE, zOrigDb,
-				      SQLITE_TRANSIENT);
 		sqlite3VdbeSetColName(v, i, COLNAME_TABLE, zOrigTab,
 				      SQLITE_TRANSIENT);
 		sqlite3VdbeSetColName(v, i, COLNAME_COLUMN, zOrigCol,
 				      SQLITE_TRANSIENT);
-#else
-		zType = columnType(&sNC, p, 0, 0, 0, 0);
-#endif
-		sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType,
-				      SQLITE_TRANSIENT);
 	}
-#endif				/* !defined(SQLITE_OMIT_DECLTYPE) */
 }
 
 /*
@@ -2005,7 +1969,7 @@ sqlite3SelectAddColumnTypeAndCollation(Parse * pParse,		/* Parsing contexts */
 		const char *zType;
 		int n, m;
 		p = a[i].pExpr;
-		zType = columnType(&sNC, p, 0, 0, 0, &pCol->szEst);
+		zType = columnType(&sNC, p, 0, 0, &pCol->szEst);
 		szAll += pCol->szEst;
 		pCol->affinity = sqlite3ExprAffinity(p);
 		if (zType && (m = sqlite3Strlen30(zType)) > 0) {
diff --git a/src/box/sql/sqlite3.h b/src/box/sql/sqlite3.h
index f9821454a..ab0c8761a 100644
--- a/src/box/sql/sqlite3.h
+++ b/src/box/sql/sqlite3.h
@@ -3900,21 +3900,19 @@ sqlite3_column_name(sqlite3_stmt *, int N);
  * CAPI3REF: Source Of Data In A Query Result
  * METHOD: sqlite3_stmt
  *
- * ^These routines provide a means to determine the database, table, and
- * table column that is the origin of a particular result column in
- * [SELECT] statement.
- * ^The name of the database or table or column can be returned as
- * either a UTF-8 or UTF-16 string.  ^The _database_ routines return
- * the database name, the _table_ routines return the table name, and
- * the origin_ routines return the column name.
- * ^The returned string is valid until the [prepared statement] is destroyed
- * using [sqlite3_finalize()] or until the statement is automatically
+ * ^These routines provide a means to determine the table and
+ * table column that is the origin of a particular result column
+ * in [SELECT] statement.
+ * The _table_ routines return the table name, and the origin_
+ * routines return the column name. ^The returned string is valid
+ * until the [prepared statement] is destroyed using
+ * [sqlite3_finalize()] or until the statement is automatically
  * reprepared by the first call to [sqlite3_step()] for a particular run
  * or until the same information is requested
  * again in a different encoding.
  *
  * ^The names returned are the original un-aliased names of the
- * database, table, and column.
+ * table and column.
  *
  * ^The first argument to these interfaces is a [prepared statement].
  * ^These functions return information about the Nth result column returned by
@@ -3926,64 +3924,13 @@ sqlite3_column_name(sqlite3_stmt *, int N);
  * NULL.  ^These routine might also return NULL if a memory allocation error
  * occurs.  ^Otherwise, they return the name of the attached database, table,
  * or column that query result column was extracted from.
- *
- * ^As with all other SQLite APIs, those whose names end with "16" return
- * UTF-16 encoded strings and the other functions return UTF-8.
- *
- * ^These APIs are only available if the library was compiled with the
- * [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol.
- *
- * If two or more threads call one or more of these routines against the same
- * prepared statement and column at the same time then the results are
- * undefined.
- *
- * If two or more threads call one or more
- * [sqlite3_column_database_name | column metadata interfaces]
- * for the same [prepared statement] and result column
- * at the same time then the results are undefined.
-*/
-SQLITE_API const char *
-sqlite3_column_database_name(sqlite3_stmt *,
-			     int);
+ */
 SQLITE_API const char *
 sqlite3_column_table_name(sqlite3_stmt *, int);
 
 SQLITE_API const char *
 sqlite3_column_origin_name(sqlite3_stmt *, int);
 
-/*
- * CAPI3REF: Declared Datatype Of A Query Result
- * METHOD: sqlite3_stmt
- *
- * ^(The first parameter is a [prepared statement].
- * If this statement is a [SELECT] statement and the Nth column of the
- * returned result set of that [SELECT] is a table column (not an
- * expression or subquery) then the declared type of the table
- * column is returned.)^  ^If the Nth column of the result set is an
- * expression or subquery, then a NULL pointer is returned.
- * ^The returned string is always UTF-8 encoded.
- *
- * ^(For example, given the database schema:
- *
- * CREATE TABLE t1(c1 VARIANT);
- *
- * and the following statement to be compiled:
- *
- * SELECT c1 + 1, c1 FROM t1;
- *
- * this routine would return the string "VARIANT" for the second result
- * column (i==1), and a NULL pointer for the first result column (i==0).)^
- *
- * ^SQLite uses dynamic run-time typing.  ^So just because a column
- * is declared to contain a particular type does not mean that the
- * data stored in that column is of the declared type.  SQLite is
- * strongly typed, but the typing is dynamic not static.  ^Type
- * is associated with individual values, not with the containers
- * used to hold those values.
-*/
-SQLITE_API const char *
-sqlite3_column_decltype(sqlite3_stmt *, int);
-
 /*
  * CAPI3REF: Evaluate An SQL Statement
  * METHOD: sqlite3_stmt
@@ -5468,16 +5415,6 @@ sqlite3_table_column_metadata(sqlite3 * db,	/* Connection handle */
 			      int *pAutoinc	/* OUTPUT: True if column is auto-increment */
 	);
 
-SQLITE_API int
-sqlite3_table_column_metadata(sqlite3 * db,
-			      const char *zTableName,
-			      const char *zColumnName,
-			      char const **pzDataType,
-			      char const **pzCollSeq,
-			      int *pNotNull,
-			      int *pPrimaryKey,
-			      int *pAutoinc);
-
 /*
  * CAPI3REF: A Handle To An Open BLOB
  * KEYWORDS: {BLOB handle} {BLOB handles}
diff --git a/src/box/sql/vdbe.h b/src/box/sql/vdbe.h
index 5c40e3f72..e66e4f9bf 100644
--- a/src/box/sql/vdbe.h
+++ b/src/box/sql/vdbe.h
@@ -155,23 +155,13 @@ typedef struct VdbeOpList VdbeOpList;
 #define P5_ConstraintFK      4
 
 /*
- * The Vdbe.aColName array contains 5n Mem structures, where n is the
+ * The Vdbe.aColName array contains 3n Mem structures, where n is the
  * number of columns of data returned by the statement.
  */
 #define COLNAME_NAME     0
-#define COLNAME_DECLTYPE 1
-#define COLNAME_DATABASE 2
-#define COLNAME_TABLE    3
-#define COLNAME_COLUMN   4
-#ifdef SQLITE_ENABLE_COLUMN_METADATA
-#define COLNAME_N        5	/* Number of COLNAME_xxx symbols */
-#else
-#ifdef SQLITE_OMIT_DECLTYPE
-#define COLNAME_N      1	/* Store only the name */
-#else
-#define COLNAME_N      2	/* Store the name and decltype */
-#endif
-#endif
+#define COLNAME_TABLE    1
+#define COLNAME_COLUMN   2
+#define COLNAME_N        3	/* Number of COLNAME_xxx symbols */
 
 /*
  * The following macro converts a relative address in the p2 field
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index 46622bff3..d995a534b 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -1134,51 +1134,48 @@ sqlite3_column_type(sqlite3_stmt * pStmt, int i)
 }
 
 /*
- * Convert the N-th element of pStmt->pColName[] into a string using
- * xFunc() then return that string.  If N is out of range, return 0.
+ * Get the N-th element of pStmt->pColName[]. If N is out of
+ * range, return NULL.
  *
  * There are up to 5 names for each column.  useType determines which
  * name is returned.  Here are the names:
  *
  *    0      The column name as it should be displayed for output
- *    1      The datatype name for the column
- *    2      The name of the database that the column derives from
- *    3      The name of the table that the column derives from
- *    4      The name of the table column that the result column derives from
+ *    1      The name of the table that the column derives from
+ *    2      The name of the table column that the result column derives from
  *
  * If the result is not a simple column reference (if it is an expression
- * or a constant) then useTypes 2, 3, and 4 return NULL.
+ * or a constant) then useTypes 3 and 4 return NULL.
  */
-static const void *
-columnName(sqlite3_stmt * pStmt,
-	   int N, const void *(*xFunc) (Mem *), int useType)
+static const char *
+columnName(sqlite3_stmt *pStmt, int N, int useType)
 {
-	const void *ret;
+	const char *ret;
 	Vdbe *p;
 	int n;
 	sqlite3 *db;
 #ifdef SQLITE_ENABLE_API_ARMOR
-	if (pStmt == 0) {
+	if (pStmt == NULL) {
 		(void)SQLITE_MISUSE_BKPT;
-		return 0;
+		return NULL;
 	}
 #endif
-	ret = 0;
+	ret = NULL;
 	p = (Vdbe *) pStmt;
 	db = p->db;
-	assert(db != 0);
+	assert(db != NULL);
 	n = sqlite3_column_count(pStmt);
 	if (N < n && N >= 0) {
 		N += useType * n;
 		sqlite3_mutex_enter(db->mutex);
 		assert(db->mallocFailed == 0);
-		ret = xFunc(&p->aColName[N]);
+		ret = (const char *) sqlite3_value_text(&p->aColName[N]);
 		/* A malloc may have failed inside of the xFunc() call. If this
 		 * is the case, clear the mallocFailed flag and return NULL.
 		 */
 		if (db->mallocFailed) {
 			sqlite3OomClear(db);
-			ret = 0;
+			ret = NULL;
 		}
 		sqlite3_mutex_leave(db->mutex);
 	}
@@ -1192,43 +1189,7 @@ columnName(sqlite3_stmt * pStmt,
 const char *
 sqlite3_column_name(sqlite3_stmt * pStmt, int N)
 {
-	return columnName(pStmt, N, (const void *(*)(Mem *))sqlite3_value_text,
-			  COLNAME_NAME);
-}
-
-/*
- * Constraint:  If you have ENABLE_COLUMN_METADATA then you must
- * not define OMIT_DECLTYPE.
- */
-#if defined(SQLITE_OMIT_DECLTYPE) && defined(SQLITE_ENABLE_COLUMN_METADATA)
-#error "Must not define both SQLITE_OMIT_DECLTYPE \
-         and SQLITE_ENABLE_COLUMN_METADATA"
-#endif
-
-#ifndef SQLITE_OMIT_DECLTYPE
-/*
- * Return the column declaration type (if applicable) of the 'i'th column
- * of the result set of SQL statement pStmt.
- */
-const char *
-sqlite3_column_decltype(sqlite3_stmt * pStmt, int N)
-{
-	return columnName(pStmt, N, (const void *(*)(Mem *))sqlite3_value_text,
-			  COLNAME_DECLTYPE);
-}
-#endif				/* SQLITE_OMIT_DECLTYPE */
-
-#ifdef SQLITE_ENABLE_COLUMN_METADATA
-/*
- * Return the name of the database from which a result column derives.
- * NULL is returned if the result column is an expression or constant or
- * anything else which is not an unambiguous reference to a database column.
- */
-const char *
-sqlite3_column_database_name(sqlite3_stmt * pStmt, int N)
-{
-	return columnName(pStmt, N, (const void *(*)(Mem *))sqlite3_value_text,
-			  COLNAME_DATABASE);
+	return columnName(pStmt, N, COLNAME_NAME);
 }
 
 /*
@@ -1239,8 +1200,7 @@ sqlite3_column_database_name(sqlite3_stmt * pStmt, int N)
 const char *
 sqlite3_column_table_name(sqlite3_stmt * pStmt, int N)
 {
-	return columnName(pStmt, N, (const void *(*)(Mem *))sqlite3_value_text,
-			  COLNAME_TABLE);
+	return columnName(pStmt, N, COLNAME_TABLE);
 }
 
 /*
@@ -1251,10 +1211,8 @@ sqlite3_column_table_name(sqlite3_stmt * pStmt, int N)
 const char *
 sqlite3_column_origin_name(sqlite3_stmt * pStmt, int N)
 {
-	return columnName(pStmt, N, (const void *(*)(Mem *))sqlite3_value_text,
-			  COLNAME_COLUMN);
+	return columnName(pStmt, N, COLNAME_COLUMN);
 }
-#endif				/* SQLITE_ENABLE_COLUMN_METADATA */
 
 /******************************* sqlite3_bind_  **************************
  *
-- 
2.14.3 (Apple Git-98)




More information about the Tarantool-patches mailing list