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 A8C62221FF for ; Mon, 24 Dec 2018 09:02:17 -0500 (EST) 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 ZT28bR2iU1xt for ; Mon, 24 Dec 2018 09:02:17 -0500 (EST) Received: from smtp1.mail.ru (smtp1.mail.ru [94.100.179.111]) (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 5F1E9221D4 for ; Mon, 24 Dec 2018 09:02:17 -0500 (EST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.0 \(3445.100.39\)) Subject: [tarantool-patches] Re: [PATCH v2 6/6] sql: set column types for EXPLAIN and PRAGMA From: "n.pettik" In-Reply-To: Date: Mon, 24 Dec 2018 16:02:14 +0200 Content-Transfer-Encoding: quoted-printable Message-Id: 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: Imeev Mergen > -/* > - * 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 =3D pPragma->nPragCName; > - sqlite3VdbeSetNumCols(v, n =3D=3D 0 ? 1 : n); > - if (n =3D=3D 0) { > - sqlite3VdbeSetColName(v, 0, COLNAME_NAME, pPragma->zName, > + int n =3D pragma->nPragCName; > + assert(n > 0); > + sqlite3VdbeSetNumCols(v, n); > + for (int i =3D 0, j =3D 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. >=20 > @@ -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) =3D=3D 0 > - && ((pPragma->mPragFlg & PragFlg_NoColumns1) =3D=3D 0 || zRight = =3D=3D 0) > - ) { > - setPragmaResultColumnNames(v, pPragma); > - } > + && ((pPragma->mPragFlg & PragFlg_NoColumns1) =3D=3D 0 || zRight = =3D=3D 0)) Nit: put operator on previous line: - if ((pPragma->mPragFlg & PragFlg_NoColumns) =3D=3D 0 - && ((pPragma->mPragFlg & PragFlg_NoColumns1) =3D=3D 0 || = zRight =3D=3D 0)) + if ((pPragma->mPragFlg & PragFlg_NoColumns) =3D=3D 0 && + ((pPragma->mPragFlg & PragFlg_NoColumns1) =3D=3D 0 || zRight = =3D=3D 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') >=20 > cn:close() >=20 > +-- gh-3832: Some statements do not return column type > +box.sql.execute('CREATE TABLE t1(id INTEGER PRIMARY KEY)') > +cn =3D remote.connect(box.cfg.listen) > + > +-- PRAGMA: > +res =3D cn:execute("PRAGMA table_info(t1)") > +res.metadata > + > +-- EXPLAIN > +res =3D cn:execute("EXPLAIN select 1") > +res.metadata > +res =3D cn:execute("EXPLAIN QUERY PLAN select count(*) from t1=E2=80=9D= ) Nit: uppercase all SQL keywords pls. Otherwise it looks pretty ugly. Patch itself is OK.