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 0569C29914 for ; Mon, 18 Mar 2019 13:34:47 -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 wTAJZSnSEQ0p for ; Mon, 18 Mar 2019 13:34:46 -0400 (EDT) Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (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 3CA67297AD for ; Mon, 18 Mar 2019 13:34:46 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH] sql: bind BLOB value as BLOB not as STRING References: <20190318010558.15883-1-korablev@tarantool.org> From: Vladislav Shpilevoy Message-ID: Date: Mon, 18 Mar 2019 20:34:43 +0300 MIME-Version: 1.0 In-Reply-To: <20190318010558.15883-1-korablev@tarantool.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit 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: Nikita Pettik , tarantool-patches@freelists.org, Kirill Yukhin LGTM. On 18/03/2019 04:05, Nikita Pettik wrote: > It is obvious that BLOB (that is value encoded in msgpack with MP_BIN > format) values must be bound as BLOBs, not as strings. Unfortunately, > they were bound as strings, which lead to wrong resulting type > calculations after execution of SQL statement. > --- > Branch: https://github.com/tarantool/tarantool/tree/np/blob-type-binding-fix > > Note that no test case is provided since there is not way to > force MP_BIN format using facilities of our testing framework. > Originally, bug was found in Java connector. > > src/box/sql/vdbeapi.c | 21 +++++++++++++++------ > 1 file changed, 15 insertions(+), 6 deletions(-) > > diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c > index d7e89073e..be5c9dff9 100644 > --- a/src/box/sql/vdbeapi.c > +++ b/src/box/sql/vdbeapi.c > @@ -1313,11 +1313,20 @@ sql_bind_blob(sql_stmt * pStmt, > int i, const void *zData, int nData, void (*xDel) (void *) > ) > { > -#ifdef SQL_ENABLE_API_ARMOR > - if (nData < 0) > - return SQL_MISUSE; > -#endif > - return bindText(pStmt, i, zData, nData, xDel); > + struct Vdbe *p = (Vdbe *) pStmt; > + int rc = vdbeUnbind(p, i); > + if (rc == SQL_OK) { > + if (zData != 0) { > + struct Mem *var = &p->aVar[i - 1]; > + rc = sqlVdbeMemSetStr(var, zData, nData, 0, xDel); > + if (rc == SQL_OK) > + rc = sql_bind_type(p, i, "BLOB"); > + rc = sqlApiExit(p->db, rc); > + } > + } else if (xDel != SQL_STATIC && xDel != SQL_TRANSIENT) { > + xDel((void *)zData); > + } > + return rc; > } > > int > @@ -1331,7 +1340,7 @@ sql_bind_blob64(sql_stmt * pStmt, > if (nData > 0x7fffffff) { > return invokeValueDestructor(zData, xDel, 0); > } else { > - return bindText(pStmt, i, zData, (int)nData, xDel); > + return sql_bind_blob(pStmt, i, zData, (int)nData, xDel); > } > } > > -- > 2.15.1 >