[Tarantool-patches] [PATCH 5/6] sql: extend result set with autoincrement

Nikita Pettik korablev at tarantool.org
Thu Dec 5 14:51:06 MSK 2019


On 28 Nov 23:41, Vladislav Shpilevoy wrote:
> Thanks for the patch!
> 
> On 27/11/2019 13:15, Nikita Pettik wrote:
> > If result set contains column which features attached sequence
> > (AUTOINCREMENT in terms of SQL) then meta-information will contain
> > corresponding field ('autoicrement' : boolean) in response.
> 
> 1. Please, lets name all booleans values with 'is_' prefix:
> is_autoincrement, IPROTO_FIELD_IS_AUTOINCREMENT.
> 
> > diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h
> > index 0e54e42a5..63afb8777 100644
> > --- a/src/box/sql/vdbeInt.h
> > +++ b/src/box/sql/vdbeInt.h
> > @@ -355,6 +355,8 @@ struct sql_column_metadata {
> >  	 * columns: all other expressions are nullable by default.
> >  	 */
> >  	int8_t nullable : 2;
> > +	/** True if column features autoincrement property. */
> > +	int8_t actoincrement : 1;
> 
> 2. Lets make it bool, and name is_autoincrement.

Both points are fixed:

diff --git a/src/box/execute.c b/src/box/execute.c
index 92f0f8ef7..0f18b3e5f 100644
--- a/src/box/execute.c
+++ b/src/box/execute.c
@@ -286,7 +286,7 @@ metadata_map_sizeof(const char *name, const char *type, const char *coll,
        }
        if (is_autoincrement) {
                members_count++;
-               map_size += mp_sizeof_uint(IPROTO_FIELD_AUTOINCREMENT);
+               map_size += mp_sizeof_uint(IPROTO_FIELD_IS_AUTOINCREMENT);
                map_size += mp_sizeof_bool(true);
        }
        map_size += mp_sizeof_uint(IPROTO_FIELD_NAME);
@@ -355,7 +355,7 @@ sql_get_metadata(struct sql_stmt *stmt, struct obuf *out, int column_count)
                        pos = mp_encode_bool(pos, nullable);
                }
                if (is_autoincrement) {
-                       pos = mp_encode_uint(pos, IPROTO_FIELD_AUTOINCREMENT);
+                       pos = mp_encode_uint(pos, IPROTO_FIELD_IS_AUTOINCREMENT);
                        pos = mp_encode_bool(pos, true);
                }
        }
diff --git a/src/box/iproto_constants.h b/src/box/iproto_constants.h
index abfb279d0..30d1af4cb 100644
--- a/src/box/iproto_constants.h
+++ b/src/box/iproto_constants.h
@@ -133,7 +133,7 @@ enum iproto_metadata_key {
        IPROTO_FIELD_TYPE = 1,
        IPROTO_FIELD_COLL = 2,
        IPROTO_FIELD_IS_NULLABLE = 3,
-       IPROTO_FIELD_AUTOINCREMENT = 4,
+       IPROTO_FIELD_IS_AUTOINCREMENT = 4,
 };
 
 enum iproto_ballot_key {
diff --git a/src/box/lua/execute.c b/src/box/lua/execute.c
index d7dd9432f..86192b728 100644
--- a/src/box/lua/execute.c
+++ b/src/box/lua/execute.c
@@ -47,7 +47,7 @@ lua_sql_get_metadata(struct sql_stmt *stmt, struct lua_State *L,
                }
                if (is_autoincrement) {
                        lua_pushboolean(L, true);
-                       lua_setfield(L, -2, "autoincrement");
+                       lua_setfield(L, -2, "is_autoincrement");
                }
                lua_rawseti(L, -2, i + 1);
        }
diff --git a/src/box/lua/net_box.c b/src/box/lua/net_box.c
index e67c14bed..a312f6cca 100644
--- a/src/box/lua/net_box.c
+++ b/src/box/lua/net_box.c
@@ -656,10 +656,10 @@ decode_metadata_optional(struct lua_State *L, const char **data,
                        lua_pushboolean(L, is_nullable);
                        lua_setfield(L, -2, "is_nullable");
                } else {
-                       assert(key == IPROTO_FIELD_AUTOINCREMENT);
+                       assert(key == IPROTO_FIELD_IS_AUTOINCREMENT);
                        bool autoincrement = mp_decode_bool(data);
                        lua_pushboolean(L, autoincrement);
-                       lua_setfield(L, -2, "autoincrement");
+                       lua_setfield(L, -2, "is_autoincrement");
                }
        }
 }
diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index 22e7d96a5..57991e1b1 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -1844,7 +1844,7 @@ generate_column_metadata(struct Parse *pParse, struct SrcList *pTabList,
                                int afno =
                                        pTabList->a[j].space->sequence_fieldno;
                                if (afno == iCol)
-                                       vdbe_set_metadata_col_autoincrement(v, i);
+                                       vdbe_metadata_set_col_autoincrement(v, i);
                        }
                } else {
                        const char *z = NULL;
diff --git a/src/box/sql/vdbe.h b/src/box/sql/vdbe.h
index e19d4cdfa..da9a311b8 100644
--- a/src/box/sql/vdbe.h
+++ b/src/box/sql/vdbe.h
@@ -261,7 +261,7 @@ void
 vdbe_metadata_set_col_nullability(struct Vdbe *p, int idx, int nullable);
 
 void
-vdbe_set_metadata_col_autoincrement(struct Vdbe *p, int idx);
+vdbe_metadata_set_col_autoincrement(struct Vdbe *p, int idx);
 
 void sqlVdbeCountChanges(Vdbe *);
 sql *sqlVdbeDb(Vdbe *);
diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h
index bccb4feb7..d79635b14 100644
--- a/src/box/sql/vdbeInt.h
+++ b/src/box/sql/vdbeInt.h
@@ -356,7 +356,7 @@ struct sql_column_metadata {
         */
        int8_t nullable : 2;
        /** True if column features autoincrement property. */
-       int8_t actoincrement : 1;
+       bool is_actoincrement;
 };
 
 /*
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index 34d189e00..8b97f7320 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -766,7 +766,7 @@ sql_column_is_autoincrement(sql_stmt *stmt, int n)
 {
        struct Vdbe *p = (struct Vdbe *) stmt;
        assert(n < sql_column_count(stmt) && n >= 0);
-       return p->metadata[n].actoincrement;
+       return p->metadata[n].is_actoincrement;
 }
 
 /******************************* sql_bind_  **************************
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 4a8bba7f7..384e985fb 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -1912,10 +1912,10 @@ vdbe_metadata_set_col_nullability(struct Vdbe *p, int idx, int nullable)
 }
 
 void
-vdbe_set_metadata_col_autoincrement(struct Vdbe *p, int idx)
+vdbe_metadata_set_col_autoincrement(struct Vdbe *p, int idx)
 {
        assert(idx < p->nResColumn);
-       p->metadata[idx].actoincrement = 1;
+       p->metadata[idx].is_actoincrement = 1;
 }



More information about the Tarantool-patches mailing list