From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 125346EC5B; Tue, 30 Mar 2021 01:59:54 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 125346EC5B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1617058794; bh=ZGYhuCH2c9eOxpoiisnV1dgr5TAe72N+qXBEfychErw=; h=To:Cc:References:Date:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=PgtEKhkZMRZGE2hncergsO41V7JixIs9mLP6lVdk31MCTwUh248oewTDVzPIunCKF dhgalAUS84CQiGGP5LVH22ra0blSvh1E8ZpA1Mu/rzdA3JF1p0Gkc8ZhBdHbhjltwW QooTe04ziIrOYSSzAGI86dIP1kIoEAr7uXHjJVgU= Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 49DF46FFA1 for ; Tue, 30 Mar 2021 01:58:52 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 49DF46FFA1 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1lR0qR-0006Ni-KP; Tue, 30 Mar 2021 01:58:51 +0300 To: imeevma@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org References: <1c4d34e5c3272be804b896ee172809be6bab9932.1616491731.git.imeevma@gmail.com> Message-ID: Date: Tue, 30 Mar 2021 00:58:50 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: <1c4d34e5c3272be804b896ee172809be6bab9932.1616491731.git.imeevma@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9ED7173E37F4E32947A0146560F8BA709498CFB6209D8582A182A05F538085040CBB57721261C51905DEC725BD96FF9187A4FEC581170307FEC93BB827EF75FEE X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE79E25BE5045FD62C0EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637EEA194BB48C104EF8638F802B75D45FF914D58D5BE9E6BC131B5C99E7648C95CE99938B3FD79E1DF1F4B8F28F28A6065CAFB0DB59C52752DA471835C12D1D9774AD6D5ED66289B5278DA827A17800CE7328B01A8D746D8839FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C3CF36E64A7E3F8E58117882F4460429728AD0CFFFB425014E868A13BD56FB6657E2021AF6380DFAD1A18204E546F3947C0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E735444A83B712AC0148C4224003CC83647689D4C264860C145E X-C1DE0DAB: 0D63561A33F958A5A1673B3B88C4E454DCCC512582A416B1793A0B131D154A70D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7502E6951B79FF9A3F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34C75F910DBB8BE8984E74547AEB3CD1BA263E470E62BED41A22CF684B22727141C0D5F14FF4E944B51D7E09C32AA3244C21294FA910FA6760EB5106A8044F9C2951E887DA02A9F7BFFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojljIiQOC84rTcrwNJDgyecQ== X-Mailru-Sender: 689FA8AB762F73936BC43F508A063822101C3AA0E0C25E9927B044C1B672452C3841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v4 08/53] sql: introduce mem_str() X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Thanks for the patch! See 2 comments below. > diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c > index 62338e1db..0ed5e38d4 100644 > --- a/src/box/sql/mem.c > +++ b/src/box/sql/mem.c > @@ -37,6 +37,39 @@ > #include "box/tuple.h" > #include "mpstream/mpstream.h" > > +enum { > + BUF_SIZE = 32, > +}; > + > +const char * > +mem_str(const struct Mem *mem) > +{ > + char buf[BUF_SIZE]; > + switch (mem->flags & MEM_PURE_TYPE_MASK) { > + case MEM_Null: > + return "NULL"; > + case MEM_Str: > + return tt_sprintf("%.*s", mem->n, mem->z); > + case MEM_Int: > + return tt_sprintf("%lld", mem->u.i); > + case MEM_UInt: > + return tt_sprintf("%llu", mem->u.u); > + case MEM_Real: > + sql_snprintf(BUF_SIZE, &buf[0], "%!.15g", mem->u.r); > + return tt_sprintf("%s", buf); > + case MEM_Blob: > + if ((mem->flags & MEM_Subtype) == 0) > + return "varbinary"; > + assert(mem->subtype == SQL_SUBTYPE_MSGPACK); > + return mp_str(mem->z); > + case MEM_Bool: > + return mem->u.b ? "TRUE" : "FALSE"; 1. Why are they capital? > + default: > + break; > + } > + return "unknown"; > +} > diff --git a/src/box/sql/vdbetrace.c b/src/box/sql/vdbetrace.c > index e84bb3192..eceaa953b 100644 > --- a/src/box/sql/vdbetrace.c > +++ b/src/box/sql/vdbetrace.c > @@ -147,33 +145,10 @@ sqlVdbeExpandSql(Vdbe * p, /* The prepared statement being evaluated */ > zRawSql += nToken; > nextIndex = idx + 1; > assert(idx > 0 && idx <= p->nVar); > - pVar = &p->aVar[idx - 1]; > - if (pVar->flags & MEM_Null) { > - sqlStrAccumAppend(&out, "NULL", 4); > - } else if (pVar->flags & MEM_Int) { > - sqlXPrintf(&out, "%lld", pVar->u.i); > - } else if (pVar->flags & MEM_UInt) { > - sqlXPrintf(&out, "%llu", pVar->u.u); > - } else if (pVar->flags & MEM_Real) { > - sqlXPrintf(&out, "%!.15g", pVar->u.r); > - } else if (pVar->flags & MEM_Str) { > - int nOut; /* Number of bytes of the string text to include in output */ > - nOut = pVar->n; > - sqlXPrintf(&out, "'%.*q'", nOut, pVar->z); > - } else if (pVar->flags & MEM_Zero) { > - sqlXPrintf(&out, "zeroblob(%d)", > - pVar->u.nZero); > - } else { > - int nOut; /* Number of bytes of the blob to include in output */ > - assert(pVar->flags & MEM_Blob); > - sqlStrAccumAppend(&out, "x'", 2); > - nOut = pVar->n; > - for (i = 0; i < nOut; i++) { > - sqlXPrintf(&out, "%02x", > - pVar->z[i] & 0xff); > - } > - sqlStrAccumAppend(&out, "'", 1); > - } > + const char *value = mem_str(&p->aVar[idx - 1]); > + uint32_t size = MIN(strlen(value), sizeof(zBase) - 1); 2. strlen() might be called twice because MIN is a macro. > + memcpy(zBase, value, size); > + zBase[size] = '\0'; > } > } > if (out.accError)