[patches] [PATCH 0/7] iproto: send SQL column meta on SELECT

v.shpilevoy at tarantool.org v.shpilevoy at tarantool.org
Fri Mar 2 12:09:59 MSK 2018


Diff of an old branch and a new one after fixes.


diff --git a/src/box/execute.c b/src/box/execute.c
index 859bd10ae..638044c87 100644
--- a/src/box/execute.c
+++ b/src/box/execute.c
@@ -537,8 +537,8 @@ static const struct iproto_sql_column_meta_bin iproto_sql_column_meta_bin = {
  * @retval -1 Memory error.
  */
 static inline int
-sql_ephemeral_column_meta_encode(struct obuf *out,
-				 const struct sql_column_meta *column)
+sql_artificial_column_meta_encode(struct obuf *out,
+				  const struct sql_column_meta *column)
 {
 	assert(column->alias != NULL);
 	assert(column->name == NULL);
@@ -632,7 +632,7 @@ sql_get_description(struct sqlite3_stmt *stmt, struct obuf *out,
 		if (column->name != NULL)
 			sql_table_column_meta_encode(out, column);
 		else
-			sql_ephemeral_column_meta_encode(out, column);
+			sql_artificial_column_meta_encode(out, column);
 	}
 	return 0;
 }
diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index 9cda5f3e9..d523df231 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -2650,118 +2650,6 @@ sqlite3_thread_cleanup(void)
 }
 #endif
 
-/*
- * Return meta information about a specific column of a database table.
- * See comment in sqlite3.h (sqlite.h.in) for details.
- */
-int
-sqlite3_table_column_metadata(sqlite3 * db,		/* Connection handle */
-			      const char *zTableName,	/* Table name */
-			      const char *zColumnName,	/* Column name */
-			      char const **pzDataType,	/* OUTPUT: Declared data type */
-			      char const **pzCollSeq,	/* OUTPUT: Collation sequence name */
-			      int *pNotNull,		/* OUTPUT: True if NOT NULL constraint exists */
-			      int *pPrimaryKey,		/* OUTPUT: True if column part of PK */
-			      int *pAutoinc)		/* OUTPUT: True if column is auto-increment */
-{
-	int rc;
-	char *zErrMsg = 0;
-	Table *pTab = 0;
-	Column *pCol = 0;
-	int iCol = 0;
-	char const *zDataType = 0;
-	char const *zCollSeq = 0;
-	int notnull = 0;
-	int primarykey = 0;
-	int autoinc = 0;
-
-#ifdef SQLITE_ENABLE_API_ARMOR
-	if (!sqlite3SafetyCheckOk(db) || zTableName == 0) {
-		return SQLITE_MISUSE_BKPT;
-	}
-#endif
-
-	/* Ensure the database schema has been loaded */
-	sqlite3_mutex_enter(db->mutex);
-	rc = sqlite3Init(db);
-	if (SQLITE_OK != rc) {
-		goto error_out;
-	}
-
-	/* Locate the table in question */
-	pTab = sqlite3FindTable(db, zTableName);
-	if (!pTab || pTab->pSelect) {
-		pTab = 0;
-		goto error_out;
-	}
-
-	/* Find the column for which info is requested */
-	if (zColumnName == 0) {
-		/* Query for existance of table only */
-	} else {
-		for (iCol = 0; iCol < pTab->nCol; iCol++) {
-			pCol = &pTab->aCol[iCol];
-			if (0 == strcmp(pCol->zName, zColumnName)) {
-				break;
-			}
-		}
-		if (iCol == pTab->nCol) {
-				pTab = 0;
-				goto error_out;
-		}
-	}
-
-	/* The following block stores the meta information that will be returned
-	 * to the caller in local variables zDataType, zCollSeq, notnull, primarykey
-	 * and autoinc. At this the table is not a view and the column name
-	 * identified an explicitly declared column.
-	 * Copy meta information from *pCol.
-	 */
-	if (pCol) {
-		zDataType = sqlite3ColumnType(pCol, 0);
-		zCollSeq = pCol->zColl;
-		notnull = table_column_is_nullable(pTab, iCol) == 0;
-		primarykey = (pCol->colFlags & COLFLAG_PRIMKEY) != 0;
-		autoinc = pTab->iPKey == iCol
-		    && (pTab->tabFlags & TF_Autoincrement) != 0;
-	} else {
-		zDataType = "INTEGER";
-		primarykey = 1;
-	}
-	if (!zCollSeq) {
-		zCollSeq = sqlite3StrBINARY;
-	}
-
- error_out:
-	/* Whether the function call succeeded or failed, set the output parameters
-	 * to whatever their local counterparts contain. If an error did occur,
-	 * this has the effect of zeroing all output parameters.
-	 */
-	if (pzDataType)
-		*pzDataType = zDataType;
-	if (pzCollSeq)
-		*pzCollSeq = zCollSeq;
-	if (pNotNull)
-		*pNotNull = notnull;
-	if (pPrimaryKey)
-		*pPrimaryKey = primarykey;
-	if (pAutoinc)
-		*pAutoinc = autoinc;
-
-	if (SQLITE_OK == rc && !pTab) {
-		sqlite3DbFree(db, zErrMsg);
-		zErrMsg =
-		    sqlite3MPrintf(db, "no such table column: %s.%s",
-				   zTableName, zColumnName);
-		rc = SQLITE_ERROR;
-	}
-	sqlite3ErrorWithMsg(db, rc, (zErrMsg ? "%s" : 0), zErrMsg);
-	sqlite3DbFree(db, zErrMsg);
-	rc = sqlite3ApiExit(db, rc);
-	sqlite3_mutex_leave(db->mutex);
-	return rc;
-}
-
 /*
  * Sleep for a little while.  Return the amount of time slept.
  */
diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index 8dad5cb32..6ce1c04f0 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -1705,7 +1705,7 @@ columnType(NameContext *pNC, Expr *pExpr, const struct Table **table,
 	}
 
 	if (table != NULL) {
-		assert(table != NULL && fieldno != NULL);
+		assert(fieldno != NULL);
 		*table = found_table;
 		*fieldno = found_fieldno;
 	}
diff --git a/src/box/sql/sqlite3.h b/src/box/sql/sqlite3.h
index 588935aeb..fd864d419 100644
--- a/src/box/sql/sqlite3.h
+++ b/src/box/sql/sqlite3.h
@@ -5297,69 +5297,6 @@ sqlite3_soft_heap_limit64(sqlite3_int64 N);
 SQLITE_API SQLITE_DEPRECATED
 void sqlite3_soft_heap_limit(int N);
 
-/*
- * CAPI3REF: Extract Metadata About A Column Of A Table
- * METHOD: sqlite3
- *
- * ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
- * information about column C of table T in database D
- * on [database connection] X.)^  ^The sqlite3_table_column_metadata()
- * interface returns SQLITE_OK and fills in the non-NULL pointers in
- * the final five arguments with appropriate values if the specified
- * column exists.  ^The sqlite3_table_column_metadata() interface returns
- * SQLITE_ERROR and if the specified column does not exist.
- * ^If the column-name parameter to sqlite3_table_column_metadata() is a
- * NULL pointer, then this routine simply checks for the existence of the
- * table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it
- * does not.
- *
- * ^The column is identified by the second, third and fourth parameters to
- * this function. ^(The second parameter is either the name of the database
- * (i.e. "main", "temp", or an attached database) containing the specified
- * table or NULL.)^ ^If it is NULL, then all attached databases are searched
- * for the table using the same algorithm used by the database engine to
- * resolve unqualified table references.
- *
- * ^The third and fourth parameters to this function are the table and column
- * name of the desired column, respectively.
- *
- * ^Metadata is returned by writing to the memory locations passed as the 5th
- * and subsequent parameters to this function. ^Any of these arguments may be
- * NULL, in which case the corresponding element of metadata is omitted.
- *
- * ^(<blockquote>
- * <table border="1">
- * <tr><th> Parameter <th> Output<br>Type <th>  Description
- *
- * <tr><td> 5th <td> const char* <td> Data type
- * <tr><td> 6th <td> const char* <td> Name of default collation sequence
- * <tr><td> 7th <td> int         <td> True if column has a NOT NULL constraint
- * <tr><td> 8th <td> int         <td> True if column is part of the PRIMARY KEY
- * <tr><td> 9th <td> int         <td> True if column is [AUTOINCREMENT]
- * </table>
- * </blockquote>)^
- *
- * ^The memory pointed to by the character pointers returned for the
- * declaration type and collation sequence is valid until the next
- * call to any SQLite API function.
- *
- * ^If the specified table is actually a view, an [error code] is returned.
- *
- * ^This function causes all database schemas to be read from disk and
- * parsed, if that has not already been done, and returns an error if
- * any errors are encountered while loading the schema.
-*/
-SQLITE_API int
-sqlite3_table_column_metadata(sqlite3 * db,	/* Connection handle */
-			      const char *zTableName,	/* Table name */
-			      const char *zColumnName,	/* Column name */
-			      char const **pzDataType,	/* OUTPUT: Declared data type */
-			      char const **pzCollSeq,	/* OUTPUT: Collation sequence name */
-			      int *pNotNull,	/* OUTPUT: True if NOT NULL constraint exists */
-			      int *pPrimaryKey,	/* OUTPUT: True if column part of PK */
-			      int *pAutoinc	/* OUTPUT: True if column is auto-increment */
-	);
-
 /*
  * CAPI3REF: A Handle To An Open BLOB
  * KEYWORDS: {BLOB handle} {BLOB handles}
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 9d13a6449..7cc7aa36a 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -2426,16 +2426,22 @@ sqlite3VdbeSetColMeta(Vdbe *p, int idx,
 		if (column->zColl != NULL) {
 			struct coll *coll = coll_by_name(column->zColl,
 							 strlen(column->zColl));
+			/*
+			 * Collation can be not found, if its name
+			 * is BINARY.
+			 */
 			if (coll != NULL) {
 				meta->is_case_sensitive =
 					coll_is_case_sensitive(coll);
 			} else {
+				assert(strcasecmp(column->zColl,
+						  "binary") == 0);
 				meta->is_case_sensitive = true;
 			}
 		} else {
 			meta->is_case_sensitive = true;
 		}
-		if (column->zName == alias) {
+		if (strcmp(column->zName, alias) == 0) {
 			/*
 			 * If a column is selected with no alias,
 			 * then do not copy it twice. Store two
> 




More information about the Tarantool-patches mailing list