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 F0EE76BD03; Sat, 10 Apr 2021 00:10:21 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org F0EE76BD03 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1618002622; bh=5xM2+jBk947sA4bhxwdwLeXfEcS6A3vQzmjlxUqbUyU=; 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=d5ODJmNC2V/kCzmw+nHbgcX05iRZ9zcmh2BOtr50+S/BKGNXvaJgHeZr/g5Y3LSK1 qkxOM3vulGmjoq1vzaxiPMtw92/5NjIoi9fc1omJGzY9t11LWIXC7X8oP6iYVDdT4O RtTBhMGVtodh+aQugFKPfV1cNfVSLxadEib9+EaM= 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 dev.tarantool.org (Postfix) with ESMTPS id 340A16BD03 for ; Sat, 10 Apr 2021 00:08:27 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 340A16BD03 Received: by smtpng2.m.smailru.net with esmtpa (envelope-from ) id 1lUyMc-00044s-6X; Sat, 10 Apr 2021 00:08:26 +0300 To: v.shpilevoy@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Sat, 10 Apr 2021 00:08:25 +0300 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD92FFCB8E6708E748094FADAEB10E66ADA4C48BE3C291E66DA182A05F5380850407B52FDAF4F1C62907EED93207B76E30DB5398CFB92DD3FA30D9FC14D6E10B22C X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7CE4525FFB91B9BBCEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006374D4854EC7C9372F88638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B26E1029423F66B7FDB7C612F4DDE76B9444A6ACC89FD899E7D2E47CDBA5A96583C09775C1D3CA48CF17B107DEF921CE79117882F4460429724CE54428C33FAD30A8DF7F3B2552694AC26CFBAC0749D213D2E47CDBA5A9658378DA827A17800CE767883B903EA3BAEA9FA2833FD35BB23DF004C906525384302BEBFE083D3B9BA73A03B725D353964B0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E735C6EABA9B74D0DA47B5C8C57E37DE458BEDA766A37F9254B7 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2AD77751E876CB595E8F7B195E1C97831E46709FC235F5DF603B6B7CA29D26CC3 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CD0035DD76F8A8A4FDFFD7D20CE496D82BCDACC5E266599209C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3453741B480A6503C3465F142B4A74F77F005E989A93B3A1B431A18877DC59E7AA5799E23DFDA644B71D7E09C32AA3244C00763ED1B8F032C70A03F0F8EDA34E6D30452B15D76AEC14FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojqcJA+pXcDun07Rjsdr5QyQ== X-Mailru-Sender: 689FA8AB762F73936BC43F508A0638226B81A36752DB173F6D5AE0F02553DDE583D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v5 50/52] sql: introduce mem_get_bin() 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" Thank you for the review! My answer and new patch below. On 30.03.2021 02:09, Vladislav Shpilevoy wrote: > Thanks for the patch! > >> 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) > > The same comments as in the previous patch with strings. Also you > use 'binary' term in the other places, not 'blob'. I would propose to > keep it consistent if we want to switch to 'binary' everywhere. > Thanks! Fixed. >> +{ >> + 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; >> +} New patch: commit a3e0cc2e89663b816c476578dce24d05da6fb66b Author: Mergen Imeev Date: Mon Mar 22 11:54:01 2021 +0300 sql: introduce mem_get_bin() This patch introduces mem_get_bin(). This function is used to receive binary value from MEM. If value of MEM is not binary value, it is converted to binary value if possible. MEM is not changed. Part of #5818 diff --git a/src/box/sql/func.c b/src/box/sql/func.c index c1db6f78a..2896a5c31 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -54,6 +54,17 @@ mem_as_ustr(struct Mem *mem) return (const unsigned char *)mem_as_str0(mem); } +static const void * +mem_as_bin(struct Mem *mem) +{ + const char *s; + if (!mem_is_bytes(mem) && mem_to_str(mem) != 0) + return NULL; + if (mem_get_bin(mem, &s) != 0) + return NULL; + return s; +} + /* * Return the collating function associated with a function. */ @@ -306,8 +317,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_as_bin(needle); + haystack_str = mem_as_bin(haystack); assert(needle_str != NULL); assert(haystack_str != NULL || n_haystack_bytes == 0); /* @@ -447,7 +458,7 @@ substrFunc(sql_context * context, int argc, sql_value ** argv) mem_get_int(argv[1], &p1, &unused); if (p0type == MP_BIN) { len = sql_value_bytes(argv[0]); - z = sql_value_blob(argv[0]); + z = mem_as_bin(argv[0]); if (z == 0) return; assert(len == sql_value_bytes(argv[0])); @@ -1082,9 +1093,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_as_bin(argv[0]); int nBlob = sql_value_bytes(argv[0]); - assert(zBlob == sql_value_blob(argv[0])); /* No encoding change */ + assert(zBlob == mem_as_bin(argv[0])); /* No encoding change */ zText = (char *)contextMalloc(context, (2 * (i64) nBlob) + 4); @@ -1218,9 +1229,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_as_bin(argv[0]); n = sql_value_bytes(argv[0]); - assert(pBlob == sql_value_blob(argv[0])); /* No encoding change */ + assert(pBlob == mem_as_bin(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 8c2d09168..2e69f4a80 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -1332,6 +1332,19 @@ mem_get_str0(const struct Mem *mem, const char **s) return 0; } +int +mem_get_bin(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) { @@ -2444,28 +2457,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_to_str(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 5848ae729..e2d0f343e 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -590,6 +590,14 @@ mem_as_str0(struct Mem *mem) return str; } +/** + * Return value for MEM of VARBINARY type. For MEM of all other types convert + * value of the MEM to VARBINARY if possible and return converted value. + * Original MEM is not changed. + */ +int +mem_get_bin(const struct Mem *mem, const char **s); + /** * Simple type to str convertor. It is used to simplify * error reporting. @@ -641,9 +649,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 51613aea3..8a7a87b49 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 c229160b6..19b70a55b 100644 --- a/src/box/sql/vdbeapi.c +++ b/src/box/sql/vdbeapi.c @@ -470,13 +470,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)