From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 66CD0215D1 for ; Mon, 23 Apr 2018 06:20:38 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PeCHWrdhwTve for ; Mon, 23 Apr 2018 06:20:38 -0400 (EDT) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 0EEC2215E1 for ; Mon, 23 Apr 2018 06:20:38 -0400 (EDT) From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v2 3/3] sql: removed type field in server Date: Mon, 23 Apr 2018 13:20:30 +0300 Message-Id: <9e0dab9bb220b06d52a07c9e3c4bf1b14793c4fb.1524478734.git.kshcherbatov@tarantool.org> In-Reply-To: References: In-Reply-To: References: Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: v.shpilevoy@tarantool.org, Kirill Shcherbatov 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