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 B4F1928B6F for ; Fri, 22 Mar 2019 06:50:36 -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 RjJOygrsSmyt for ; Fri, 22 Mar 2019 06:50:36 -0400 (EDT) Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (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 479B228C24 for ; Fri, 22 Mar 2019 06:50:36 -0400 (EDT) From: imeevma@tarantool.org Subject: [tarantool-patches] [PATCH v9 1/7] sql: add column name to SQL change counter Date: Fri, 22 Mar 2019 13:50:33 +0300 Message-Id: <91377288d30073890542a444ae00dfe00200971d.1553251042.git.imeevma@gmail.com> 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: v.shpilevoy@tarantool.org Cc: tarantool-patches@freelists.org Currently, if the count_changes pragma is enabled, the INSERT, REPLACE and UPDATE statements will return the number of changes at execution time. This patch sets an INTEGER type for this result. Follow up #3832 Needed from #3505 --- src/box/sql/delete.c | 2 ++ src/box/sql/insert.c | 2 ++ src/box/sql/update.c | 2 ++ test/sql/iproto.result | 31 +++++++++++++++++++++++++++++++ test/sql/iproto.test.lua | 8 ++++++++ 5 files changed, 45 insertions(+) diff --git a/src/box/sql/delete.c b/src/box/sql/delete.c index f4d0334..eb1c8aa 100644 --- a/src/box/sql/delete.c +++ b/src/box/sql/delete.c @@ -422,6 +422,8 @@ sql_table_delete_from(struct Parse *parse, struct SrcList *tab_list, sqlVdbeSetNumCols(v, 1); sqlVdbeSetColName(v, 0, COLNAME_NAME, "rows deleted", SQL_STATIC); + sqlVdbeSetColName(v, 0, COLNAME_DECLTYPE, "INTEGER", + SQL_STATIC); } delete_from_cleanup: diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c index 6f7f020..654b282 100644 --- a/src/box/sql/insert.c +++ b/src/box/sql/insert.c @@ -788,6 +788,8 @@ sqlInsert(Parse * pParse, /* Parser context */ sqlVdbeSetNumCols(v, 1); sqlVdbeSetColName(v, 0, COLNAME_NAME, "rows inserted", SQL_STATIC); + sqlVdbeSetColName(v, 0, COLNAME_DECLTYPE, "INTEGER", + SQL_STATIC); } insert_cleanup: diff --git a/src/box/sql/update.c b/src/box/sql/update.c index 05ceeb4..82de09c 100644 --- a/src/box/sql/update.c +++ b/src/box/sql/update.c @@ -530,6 +530,8 @@ sqlUpdate(Parse * pParse, /* The parser context */ sqlVdbeSetNumCols(v, 1); sqlVdbeSetColName(v, 0, COLNAME_NAME, "rows updated", SQL_STATIC); + sqlVdbeSetColName(v, 0, COLNAME_DECLTYPE, "INTEGER", + SQL_STATIC); } update_cleanup: diff --git a/test/sql/iproto.result b/test/sql/iproto.result index 938aea9..c700a80 100644 --- a/test/sql/iproto.result +++ b/test/sql/iproto.result @@ -942,6 +942,37 @@ res.metadata - name: detail type: TEXT ... +-- When pragma count_changes is on, statements INSERT, REPLACE and +-- UPDATE returns number of changed columns. Make sure that this +-- result has a column type. +cn:execute("PRAGMA count_changes = 1;") +--- +- rowcount: 0 +... +cn:execute("INSERT INTO t1 VALUES (1), (2), (3);") +--- +- metadata: + - name: rows inserted + type: INTEGER + rows: + - [3] +... +cn:execute("REPLACE INTO t1 VALUES (2), (3), (4), (5);") +--- +- metadata: + - name: rows inserted + type: INTEGER + rows: + - [4] +... +cn:execute("UPDATE t1 SET id = id + 100 WHERE id > 10;") +--- +- metadata: + - name: rows updated + type: INTEGER + rows: + - [0] +... cn:close() --- ... diff --git a/test/sql/iproto.test.lua b/test/sql/iproto.test.lua index fbdc5a2..3b36cc3 100644 --- a/test/sql/iproto.test.lua +++ b/test/sql/iproto.test.lua @@ -289,6 +289,14 @@ res.metadata res = cn:execute("EXPLAIN QUERY PLAN SELECT COUNT(*) FROM t1") res.metadata +-- When pragma count_changes is on, statements INSERT, REPLACE and +-- UPDATE returns number of changed columns. Make sure that this +-- result has a column type. +cn:execute("PRAGMA count_changes = 1;") +cn:execute("INSERT INTO t1 VALUES (1), (2), (3);") +cn:execute("REPLACE INTO t1 VALUES (2), (3), (4), (5);") +cn:execute("UPDATE t1 SET id = id + 100 WHERE id > 10;") + cn:close() box.sql.execute('DROP TABLE t1') -- 2.7.4