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 4810D68F4F; Tue, 23 Mar 2021 13:00:50 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4810D68F4F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1616493650; bh=Z5Cw/6cIVpPx3+Fp5crlc8KQaRLZivWQvjh86UolSjs=; h=To:Cc:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=I828iPoNLZAr7/pEDQlZXq3WStWPQ4Xn12JWnqE9KbbLC52HtLs6nJzGdu3F4QHdX c2W5oKPRebsnyexiCtnQEJGv3RFO9OoSj0/PA/k5d2Uej78qU0V+tmHT5g6BKLZ/nI +l9rYlt4poOubTgSSoVy2uwzJ8b6heOtK0n898Q4= Received: from smtp3.mail.ru (smtp3.mail.ru [94.100.179.58]) (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 AD29C68F6A for ; Tue, 23 Mar 2021 12:36:53 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org AD29C68F6A Received: by smtp3.mail.ru with esmtpa (envelope-from ) id 1lOdT2-0007cY-TW; Tue, 23 Mar 2021 12:36:53 +0300 To: v.shpilevoy@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Tue, 23 Mar 2021 12:36:52 +0300 Message-Id: <92aa7f0028c320067de4761114c9b01baebe7be9.1616491731.git.imeevma@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD95D6E7CC48CB1F5F145AC670795810553045AFCF1215FE694182A05F5380850401835A5846E025FDAEA4DC6E5F61BE4D3EB8187204270084885845E10E952F8AB X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7922D113DFDC6D5A3EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637C59BB75D821356298638F802B75D45FF914D58D5BE9E6BC131B5C99E7648C95C686AF563A045C75E8022A2908E29B07EA48065E65E9D9FD1A471835C12D1D9774AD6D5ED66289B5278DA827A17800CE71AE4D56B06699BBC9FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C3E478A468B35FE767117882F4460429728AD0CFFFB425014E868A13BD56FB6657D81D268191BDAD3DC09775C1D3CA48CF85267523C8841599BA3038C0950A5D36C8A9BA7A39EFB766EC990983EF5C0329BA3038C0950A5D36D5E8D9A59859A8B66316AFC85B8DFF1976E601842F6C81A1F004C906525384307823802FF610243DF43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B3BBE47FD9DD3FB59A8DF7F3B2552694A57739F23D657EF2B13377AFFFEAFD26923F8577A6DFFEA7CD1D040B6C1ECEA3F93EC92FD9297F6715571747095F342E857739F23D657EF2BD5E8D9A59859A8B6A1DCCEB63E2F10FB089D37D7C0E48F6C5571747095F342E857739F23D657EF2B6825BDBE14D8E70227F01F88B6EF2528BD9CCCA9EDD067B1EDA766A37F9254B7 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C686AF563A045C75E8022A2908E29B07EA48065E65E9D9FD19C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34505665BFD4C707050D9C4DAD17B30655629D02AFA02AE8CE0898499F201E4483C7FC5EC639DA76471D7E09C32AA3244C54E70EF7DE1E213B07615C90F6E9772CE646F07CC2D4F3D8FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojWJZv20R+6Uic4atT2LZ5sg== X-Mailru-Sender: 5C3750E245F362008BC1685FEC6306ED92921461B754BA7FEA4DC6E5F61BE4D3EFC4EB6826DC22485105BD0848736F9966FEC6BF5C9C28D97E07721503EA2E00ED97202A5A4E92BF7402F9BA4338D657ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v4 52/53] sql: introduce mem_get_binary() 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: Mergen Imeev via Tarantool-patches Reply-To: imeevma@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" This patch introduces mem_get_binary() which is used to receive binary value from MEM. Part of #5818 --- src/box/sql/func.c | 31 ++++++++++++++++++++++--------- src/box/sql/mem.c | 35 +++++++++++++---------------------- src/box/sql/mem.h | 6 +++--- src/box/sql/sqlInt.h | 3 --- src/box/sql/vdbeapi.c | 7 ------- 5 files changed, 38 insertions(+), 44 deletions(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index 78f4ec3b5..199f3abef 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -72,6 +72,19 @@ mem_get_ustr(struct Mem *mem) return (const unsigned char *)str; } +static const void * +mem_get_blob(struct Mem *mem) +{ + const char *s; + if (!mem_is_varstring(mem) && mem_convert_to_string(mem) != 0) + return NULL; + if (ExpandBlob(mem) != 0) + return NULL; + if (mem_get_binary(mem, &s) != 0) + return NULL; + return (const void *)s; +} + /* * Return the collating function associated with a function. */ @@ -154,7 +167,7 @@ port_vdbemem_dump_lua(struct port *base, struct lua_State *L, bool is_flat) case MP_BIN: case MP_ARRAY: case MP_MAP: - lua_pushlstring(L, sql_value_blob(param), + lua_pushlstring(L, mem_get_blob(param), (size_t) sql_value_bytes(param)); break; case MP_NIL: @@ -218,7 +231,7 @@ port_vdbemem_get_msgpack(struct port *base, uint32_t *size) case MP_ARRAY: case MP_MAP: { mpstream_encode_binl(&stream, sql_value_bytes(param)); - mpstream_memcpy(&stream, sql_value_blob(param), + mpstream_memcpy(&stream, mem_get_blob(param), sql_value_bytes(param)); break; } @@ -641,8 +654,8 @@ position_func(struct sql_context *context, int argc, struct Mem **argv) const unsigned char *haystack_str; const unsigned char *needle_str; if (haystack_type == MP_BIN) { - needle_str = sql_value_blob(needle); - haystack_str = sql_value_blob(haystack); + needle_str = mem_get_blob(needle); + haystack_str = mem_get_blob(haystack); assert(needle_str != NULL); assert(haystack_str != NULL || n_haystack_bytes == 0); /* @@ -785,7 +798,7 @@ substrFunc(sql_context * context, int argc, sql_value ** argv) mem_get_integer(argv[1], &p1, &unused); if (p0type == MP_BIN) { len = sql_value_bytes(argv[0]); - z = sql_value_blob(argv[0]); + z = mem_get_blob(argv[0]); if (z == 0) return; assert(len == sql_value_bytes(argv[0])); @@ -1420,9 +1433,9 @@ quoteFunc(sql_context * context, int argc, sql_value ** argv) case MP_ARRAY: case MP_MAP: { char *zText = 0; - char const *zBlob = sql_value_blob(argv[0]); + char const *zBlob = mem_get_blob(argv[0]); int nBlob = sql_value_bytes(argv[0]); - assert(zBlob == sql_value_blob(argv[0])); /* No encoding change */ + assert(zBlob == mem_get_blob(argv[0])); /* No encoding change */ zText = (char *)contextMalloc(context, (2 * (i64) nBlob) + 4); @@ -1556,9 +1569,9 @@ hexFunc(sql_context * context, int argc, sql_value ** argv) char *zHex, *z; assert(argc == 1); UNUSED_PARAMETER(argc); - pBlob = sql_value_blob(argv[0]); + pBlob = mem_get_blob(argv[0]); n = sql_value_bytes(argv[0]); - assert(pBlob == sql_value_blob(argv[0])); /* No encoding change */ + assert(pBlob == mem_get_blob(argv[0])); /* No encoding change */ z = zHex = contextMalloc(context, ((i64) n) * 2 + 1); if (zHex) { for (i = 0; i < n; i++, pBlob++) { diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index efd3e4677..bed9ae64a 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -1328,6 +1328,19 @@ mem_get_string0(const struct Mem *mem, const char **s) return 0; } +int +mem_get_binary(const struct Mem *mem, const char **s) +{ + if ((mem->flags & MEM_Str) != 0) { + *s = mem->n > 0 ? mem->z : NULL; + return 0; + } + if ((mem->flags & MEM_Blob) == 0 || (mem->flags & MEM_Zero) != 0) + return -1; + *s = mem->z; + return 0; +} + int mem_copy(struct Mem *to, const struct Mem *from) { @@ -2434,28 +2447,6 @@ releaseMemArray(Mem * p, int N) } } -/**************************** sql_value_ ****************************** - * The following routines extract information from a Mem or sql_value - * structure. - */ -const void * -sql_value_blob(sql_value * pVal) -{ - Mem *p = (Mem *) pVal; - if (p->flags & (MEM_Blob | MEM_Str)) { - if (ExpandBlob(p) != 0) { - assert(p->flags == MEM_Null && p->z == 0); - return 0; - } - p->flags |= MEM_Blob; - return p->n ? p->z : 0; - } else { - if (mem_convert_to_string(pVal) != 0) - return NULL; - return pVal->z; - } -} - int sql_value_bytes(sql_value * pVal) { diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h index fb2385541..8af924d43 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -360,6 +360,9 @@ mem_get_boolean(const struct Mem *mem, bool *b); int mem_get_string0(const struct Mem *mem, const char **s); +int +mem_get_binary(const struct Mem *mem, const char **s); + /** * Simple type to str convertor. It is used to simplify * error reporting. @@ -435,9 +438,6 @@ releaseMemArray(Mem * p, int N); /** Getters. */ -const void * -sql_value_blob(struct Mem *); - int sql_value_bytes(struct Mem *); diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h index 2f995ffc6..9dfd0e4cc 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -433,9 +433,6 @@ sql_stmt_compile(const char *sql, int bytes_count, struct Vdbe *re_prepared, int sql_step(sql_stmt *); -const void * -sql_column_blob(sql_stmt *, int iCol); - int sql_column_bytes(sql_stmt *, int iCol); diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c index 465284567..e76170965 100644 --- a/src/box/sql/vdbeapi.c +++ b/src/box/sql/vdbeapi.c @@ -471,13 +471,6 @@ columnMem(sql_stmt * pStmt, int i) * The following routines are used to access elements of the current row * in the result set. */ -const void * -sql_column_blob(sql_stmt * pStmt, int i) -{ - const void *val; - val = sql_value_blob(columnMem(pStmt, i)); - return val; -} int sql_column_bytes(sql_stmt * pStmt, int i) -- 2.25.1