[tarantool-patches] Re: [PATCH v2 6/6] sql: set column types for EXPLAIN and PRAGMA

n.pettik korablev at tarantool.org
Mon Dec 24 17:02:14 MSK 2018


> -/*
> - * Set result column names for a pragma.
> - */
> +/** Set result column names and types for a pragma. */
> static void
> -setPragmaResultColumnNames(Vdbe * v, /* The query under construction */
> -        const PragmaName * pPragma /* The pragma */
> -    )
> +vdbe_set_pragma_result_columns(struct Vdbe *v, const struct PragmaName *pragma)
> {
> - u8 n = pPragma->nPragCName;
> - sqlite3VdbeSetNumCols(v, n == 0 ? 1 : n);
> - if (n == 0) {
> -   sqlite3VdbeSetColName(v, 0, COLNAME_NAME, pPragma->zName,
> + int n = pragma->nPragCName;
> + assert(n > 0);
> + sqlite3VdbeSetNumCols(v, n);
> + for (int i = 0, j = pragma->iPragCName; i < n; ++i) {
> +   /* Value of j is index of column name in array */
> +   sqlite3VdbeSetColName(v, i, COLNAME_NAME, pragCName[j++],
> +             SQLITE_STATIC);
> +   /* Value of j is index of column type in array */

These two comments are too obvious, lets remove them.

> 
> @@ -473,16 +468,14 @@ sqlite3Pragma(Parse * pParse, Token * pId,  /* First part of [schema.]id field */
>  }
>  /* Register the result column names for pragmas that return results */
>  if ((pPragma->mPragFlg & PragFlg_NoColumns) == 0
> -     && ((pPragma->mPragFlg & PragFlg_NoColumns1) == 0 || zRight == 0)
> -     ) {
> -   setPragmaResultColumnNames(v, pPragma);
> - }
> +     && ((pPragma->mPragFlg & PragFlg_NoColumns1) == 0 || zRight == 0))

Nit: put operator on previous line:

-       if ((pPragma->mPragFlg & PragFlg_NoColumns) == 0
-           && ((pPragma->mPragFlg & PragFlg_NoColumns1) == 0 || zRight == 0))
+       if ((pPragma->mPragFlg & PragFlg_NoColumns) == 0 &&
+           ((pPragma->mPragFlg & PragFlg_NoColumns1) == 0 || zRight == 0))

> ---
> ...
> diff --git a/test/sql/iproto.test.lua b/test/sql/iproto.test.lua
> index 6640903..9f9a382 100644
> --- a/test/sql/iproto.test.lua
> +++ b/test/sql/iproto.test.lua
> @@ -263,10 +263,26 @@ box.sql.execute('DROP TABLE t1')
> 
> cn:close()
> 
> +-- gh-3832: Some statements do not return column type
> +box.sql.execute('CREATE TABLE t1(id INTEGER PRIMARY KEY)')
> +cn = remote.connect(box.cfg.listen)
> +
> +-- PRAGMA:
> +res = cn:execute("PRAGMA table_info(t1)")
> +res.metadata
> +
> +-- EXPLAIN
> +res = cn:execute("EXPLAIN select 1")
> +res.metadata
> +res = cn:execute("EXPLAIN QUERY PLAN select count(*) from t1”)

Nit: uppercase all SQL keywords pls. Otherwise it looks pretty ugly.

Patch itself is OK.





More information about the Tarantool-patches mailing list