Tarantool development patches archive
 help / color / mirror / Atom feed
From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org
Cc: v.shpilevoy@tarantool.org,
	Kirill Shcherbatov <kshcherbatov@tarantool.org>
Subject: [tarantool-patches] [PATCH v2 3/3] sql: removed type field in server
Date: Mon, 23 Apr 2018 13:20:30 +0300	[thread overview]
Message-ID: <9e0dab9bb220b06d52a07c9e3c4bf1b14793c4fb.1524478734.git.kshcherbatov@tarantool.org> (raw)
In-Reply-To: <cover.1524478734.git.kshcherbatov@tarantool.org>
In-Reply-To: <cover.1524478734.git.kshcherbatov@tarantool.org>

Needed for #3272.
---
 src/box/sql.c           | 13 +++++++++----
 src/box/sql/build.c     | 12 +++++++-----
 src/box/sql/pragma.c    | 12 ++++++------
 src/box/sql/select.c    |  8 ++++----
 src/box/sql/sqliteInt.h |  2 --
 src/box/sql/util.c      |  9 ---------
 6 files changed, 26 insertions(+), 30 deletions(-)

diff --git a/src/box/sql.c b/src/box/sql.c
index 2edb434..8b05a33 100644
--- a/src/box/sql.c
+++ b/src/box/sql.c
@@ -1430,10 +1430,12 @@ int tarantoolSqlite3MakeTableFormat(Table *pTable, void *buf)
 {
 	struct Column *aCol = pTable->aCol;
 	const struct Enc *enc = get_enc(buf);
+	const struct space_def *def = pTable->def;
+	assert(def != NULL);
 	struct SqliteIndex *pk_idx = sqlite3PrimaryKeyIndex(pTable);
 	int pk_forced_int = -1;
 	char *base = buf, *p;
-	int i, n = pTable->def->field_count;
+	int i, n = def->field_count;
 
 	p = enc->encode_array(base, n);
 
@@ -1441,14 +1443,14 @@ int tarantoolSqlite3MakeTableFormat(Table *pTable, void *buf)
 	 * treat it as strict type, not affinity.  */
 	if (pk_idx && pk_idx->nColumn == 1) {
 		int pk = pk_idx->aiColumn[0];
-		if (pTable->aCol[pk].type == FIELD_TYPE_INTEGER)
+		if (def->fields[pk].type == FIELD_TYPE_INTEGER)
 			pk_forced_int = pk;
 	}
 
 	for (i = 0; i < n; i++) {
 		const char *t;
 		struct coll *coll = aCol[i].coll;
-		struct field_def *field = &pTable->def->fields[i];
+		struct field_def *field = &def->fields[i];
 		const char *zToken = field->default_value;
 		int base_len = 4;
 		if (coll != NULL)
@@ -1521,6 +1523,9 @@ int tarantoolSqlite3MakeTableOpts(Table *pTable, const char *zSql, void *buf)
 int tarantoolSqlite3MakeIdxParts(SqliteIndex *pIndex, void *buf)
 {
 	struct Column *aCol = pIndex->pTable->aCol;
+	struct space_def *def = pIndex->pTable->def;
+	assert(def != NULL);
+
 	const struct Enc *enc = get_enc(buf);
 	struct SqliteIndex *primary_index;
 	char *base = buf, *p;
@@ -1532,7 +1537,7 @@ int tarantoolSqlite3MakeIdxParts(SqliteIndex *pIndex, void *buf)
 	 * treat it as strict type, not affinity.  */
 	if (primary_index->nColumn == 1) {
 		int pk = primary_index->aiColumn[0];
-		if (aCol[pk].type == FIELD_TYPE_INTEGER)
+		if (def->fields[pk].type == FIELD_TYPE_INTEGER)
 			pk_forced_int = pk;
 	}
 
diff --git a/src/box/sql/build.c b/src/box/sql/build.c
index f3e41ce..8c46a72 100644
--- a/src/box/sql/build.c
+++ b/src/box/sql/build.c
@@ -705,7 +705,8 @@ sqlite3AddColumn(Parse * pParse, Token * pName, Token * pType)
 	}
 	pCol = &p->aCol[p->def->field_count];
 	memset(pCol, 0, sizeof(p->aCol[0]));
-	p->def->fields[p->def->field_count].name = z;
+	struct field_def *column_def = &p->def->fields[p->def->field_count];
+	column_def->name = z;
 	if (pType->n == 0) {
 		/* If there is no type specified, columns have the default affinity
 		 * 'BLOB' and type SCALAR.
@@ -713,8 +714,8 @@ sqlite3AddColumn(Parse * pParse, Token * pName, Token * pType)
 		 * specified type, the code below should emit an error.
 		 */
 		pCol->affinity = SQLITE_AFF_BLOB;
-		pCol->type = FIELD_TYPE_SCALAR;
 		pCol->szEst = 1;
+		column_def->type = FIELD_TYPE_SCALAR;
 	} else {
 		/* TODO: convert string of type into runtime
 		 * FIELD_TYPE value for other types.
@@ -723,16 +724,16 @@ sqlite3AddColumn(Parse * pParse, Token * pName, Token * pType)
 		     pType->n == 7) ||
 		    (sqlite3StrNICmp(pType->z, "INT", 3) == 0 &&
 		     pType->n == 3)) {
-			pCol->type = FIELD_TYPE_INTEGER;
 			pCol->affinity = SQLITE_AFF_INTEGER;
+			column_def->type = FIELD_TYPE_INTEGER;
 		} else {
 			zType = sqlite3_malloc(pType->n + 1);
 			memcpy(zType, pType->z, pType->n);
 			zType[pType->n] = 0;
 			sqlite3Dequote(zType);
 			pCol->affinity = sqlite3AffinityType(zType, 0);
-			pCol->type = FIELD_TYPE_SCALAR;
 			sqlite3_free(zType);
+			column_def->type = FIELD_TYPE_SCALAR;
 		}
 	}
 	p->def->field_count++;
@@ -957,9 +958,10 @@ sqlite3AddPrimaryKey(Parse * pParse,	/* Parsing context */
 			}
 		}
 	}
+	assert(pCol == &pTab->aCol[iCol]);
 	if (nTerm == 1
 	    && pCol
-	    && (sqlite3ColumnType(pCol) == FIELD_TYPE_INTEGER)
+	    && (pTab->def->fields[iCol].type == FIELD_TYPE_INTEGER)
 	    && sortOrder != SQLITE_SO_DESC) {
 		assert(autoInc == 0 || autoInc == 1);
 		pTab->iPKey = iCol;
diff --git a/src/box/sql/pragma.c b/src/box/sql/pragma.c
index e93f377..0cf103c 100644
--- a/src/box/sql/pragma.c
+++ b/src/box/sql/pragma.c
@@ -381,13 +381,13 @@ sqlite3Pragma(Parse * pParse, Token * pId,	/* First part of [schema.]id field */
 						space_cache_find(space_id);
 					char *expr_str = space->
 						def->fields[i].default_value;
+					const char *name =
+						pTab->def->fields[i].name;
+					enum field_type type =
+						pTab->def->fields[i].type;
 					sqlite3VdbeMultiLoad(v, 1, "issisi",
-							     i,
-							     pTab->def->fields[i].
-								     name,
-							     field_type_strs[
-							     sqlite3ColumnType
-							     (pCol)],
+							     i, name,
+							     field_type_strs[type],
 							     nullable == 0,
 							     expr_str, k);
 					sqlite3VdbeAddOp2(v, OP_ResultRow, 1,
diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index 116ef31..8ea4c9d 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -1664,12 +1664,12 @@ columnTypeImpl(NameContext * pNC, Expr * pExpr,
 				assert(iCol >= 0 && iCol <
 						    (int)pTab->def->field_count);
 #ifdef SQLITE_ENABLE_COLUMN_METADATA
-				zOrigCol = pTab->aCol[iCol].zName;
-				zType = sqlite3ColumnType(&pTab->aCol[iCol], 0);
+				zOrigCol = pTab->def->fields[iCol].name;
+				zType = pTab->def->fields[iCol].type;
 				estWidth = pTab->aCol[iCol].szEst;
 				zOrigTab = pTab->zName;
 #else
-				column_type = sqlite3ColumnType(&pTab->aCol[iCol]);
+				column_type = pTab->def->fields[iCol].type;
 				estWidth = pTab->aCol[iCol].szEst;
 #endif
 			}
@@ -1937,7 +1937,7 @@ sqlite3SelectAddColumnTypeAndCollation(Parse * pParse,		/* Parsing contexts */
 		type = columnType(&sNC, p, 0, 0, 0, &pCol->szEst);
 		szAll += pCol->szEst;
 		pCol->affinity = sqlite3ExprAffinity(p);
-		pCol->type = type;
+		pTab->def->fields[i].type = type;
 
 		if (pCol->affinity == 0)
 			pCol->affinity = SQLITE_AFF_BLOB;
diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h
index 8e1c135..94d5c80 100644
--- a/src/box/sql/sqliteInt.h
+++ b/src/box/sql/sqliteInt.h
@@ -1867,7 +1867,6 @@ struct Savepoint {
  * of this structure.
  */
 struct Column {
-	enum field_type type;	/* Column type. */
 	/** Collating sequence. */
 	struct coll *coll;
 	/**
@@ -3388,7 +3387,6 @@ int sqlite3IoerrnomemError(int);
  */
 int sqlite3StrICmp(const char *, const char *);
 unsigned sqlite3Strlen30(const char *);
-enum field_type sqlite3ColumnType(Column *);
 #define sqlite3StrNICmp sqlite3_strnicmp
 
 void sqlite3MallocInit(void);
diff --git a/src/box/sql/util.c b/src/box/sql/util.c
index 8c4e7b9..401b215 100644
--- a/src/box/sql/util.c
+++ b/src/box/sql/util.c
@@ -130,15 +130,6 @@ sqlite3Strlen30(const char *z)
 }
 
 /*
- * Return the declared type of a column.
- */
-inline enum field_type
-sqlite3ColumnType(Column * pCol)
-{
-	return pCol->type;
-}
-
-/*
  * Helper function for sqlite3Error() - called rarely.  Broken out into
  * a separate routine to avoid unnecessary register saves on entry to
  * sqlite3Error().
-- 
2.7.4

      parent reply	other threads:[~2018-04-23 10:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-17 15:01 [tarantool-patches] [PATCH v2 1/1] sql: remove ephemeral Expr from AddDefaultValue Kirill Shcherbatov
2018-04-17 18:45 ` [tarantool-patches] " Vladislav Shpilevoy
2018-04-19 12:47 ` [tarantool-patches] [PATCH v2 1/1] sql: remove zName and nColumn from SQL Kirill Shcherbatov
2018-04-19 15:25   ` [tarantool-patches] " Vladislav Shpilevoy
2018-04-23 10:20     ` [tarantool-patches] [PATCH v2 0/3] " Kirill Shcherbatov
2018-04-23 10:20       ` [tarantool-patches] [PATCH v2 1/3] sql: Fixed disgusting code format in sqlite3Pragma Kirill Shcherbatov
2018-04-23 10:20       ` [tarantool-patches] [PATCH v2 2/3] sql: remove zName and nColumn from SQL Kirill Shcherbatov
2018-04-23 10:20       ` Kirill Shcherbatov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9e0dab9bb220b06d52a07c9e3c4bf1b14793c4fb.1524478734.git.kshcherbatov@tarantool.org \
    --to=kshcherbatov@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [tarantool-patches] [PATCH v2 3/3] sql: removed type field in server' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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