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 2B0BF6B962; Wed, 14 Apr 2021 04:43:12 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2B0BF6B962 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1618364592; bh=COCJyydEZo+xexDD//htjW3gY5tBxVOnhq9fv4zFxQA=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=h8TBtoo0IfffC6Qr8WNIY/+MK2++Cz/QWySvmTXPN+4+05/xm22QZmfp7SoCe84x3 bQIhfmtu9qkepYCks1el7pSLUQcgD6DoOpjn1Sgci29vRGv9W3HwgQ1553BgfFrpVO MEBwCHhF06+A/spsNEtwjFj0kcI9nWmqvHRJXnCc= Received: from smtp45.i.mail.ru (smtp45.i.mail.ru [94.100.177.105]) (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 DD0F16EC5B for ; Wed, 14 Apr 2021 04:43:10 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org DD0F16EC5B Received: by smtp45.i.mail.ru with esmtpa (envelope-from ) id 1lWUYf-0004v4-UV; Wed, 14 Apr 2021 04:43:10 +0300 Date: Wed, 14 Apr 2021 04:43:08 +0300 To: Vladislav Shpilevoy Message-ID: <20210414014308.GA176840@tarantool.org> References: <056987bba3f23e3298201d14728452f3033a166c.1618000037.git.imeevma@gmail.com> <57b42211-19a9-1629-5d91-bc2e729f7dee@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <57b42211-19a9-1629-5d91-bc2e729f7dee@tarantool.org> X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92FFCB8E6708E7480B1C8842CE613979723F2FB4628545A35182A05F53808504044D850101091E65C1AD883644535F3277269E0A669FAB2F00D364D197ADC1A70 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE78981306C6E927004EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637D82ED515D6052E03EA1F7E6F0F101C67CDEEF6D7F21E0D1D9295C2E9FA3191EE1B59CA4C82EFA658FBCBD0393EE3BEBE0483299546B83B62F6B57BC7E64490618DEB871D839B73339E8FC8737B5C22498424CA1AAF98A6958941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B68424CA1AAF98A6958941B15DA834481F9449624AB7ADAF37BA3038C0950A5D3613377AFFFEAFD26923F8577A6DFFEA7C44DC14CD4868D85D7B076A6E789B0E97A8DF7F3B2552694A1E7802607F20496D49FD398EE364050F0AC5B80A05675ACD45B9AC499A3C791CB3661434B16C20AC78D18283394535A9E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B62CFFCC7B69C47339089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2368A440D3B0F6089093C9A16E5BC824A2A04A2ABAA09D25379311020FFC8D4ADB200D727D4285EA2F627C14BA1ED8534 X-C1DE0DAB: 0D63561A33F958A52139F7BC26AD68C38086187623596BD1FCA55DF38AC33D29D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7502E6951B79FF9A3F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3433E9BC74ABA5769FC86EEB3CFF0D6709F64B2E9418D486CFA5BBEC44FC48B058312A73A55C3D2E441D7E09C32AA3244CA2A4BE1F516ABCE72F9856BAAC7DE450F2F5F14F68F1805BFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojnA7/qPBUIXEsom4osDIqAA== X-Mailru-Sender: 5C3750E245F362008BC1685FEC6306EDB233C9D5FB5206BC1AD883644535F327EC9A243AB1C8B1BC5105BD0848736F9966FEC6BF5C9C28D97E07721503EA2E00ED97202A5A4E92BF7402F9BA4338D657ED14614B50AE0675 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v5 49/52] sql: introduce mem_get_str0() and mem_as_str0() 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: Mergen Imeev Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Thank you for the review! My answers, diff and new patch below. On Wed, Apr 14, 2021 at 01:06:09AM +0200, Vladislav Shpilevoy wrote: > Thanks for the discussion! > > See 2 comments below. > > 1. With this getter it is less trivial than with the previous > ones. > > I just realized, that we call mem_as_str() on function arguments. > What if a mem is passed to multiple functions, and one of them > changes it affecting the other functions? What if the same function > is called multiple times during a query? - the first execution > affects the argument for the next executions? Does not look right. > Am I missing something? > > It seems that could be fixed not so hard. > > If the value is already a 0-terminated string, we return it. > If it is a blob or not terminated string, we extended it, add 0, > and return. It does not really change the original value anyway. > Mem.n stays the same, and the first n bytes stay the same. > If it is a number, we can save its string representation to > Mem.z, which is not used for numbers. > > Will it work? > Formally it will work, but I am not sure that it is good idea. Still, I believe that there is no need for this since before this patch such functions as sql_value_text(), valueToText(), sql_value_bytes() and so on actually converted MEM to string. So, what we have done is just a bit refactored these functions. There is no changes in behaviour. So, I expect that there shouldn't be any new problems. Still, there may be some old problems. Also, our function to get string or varbinary length actually do not changes MEM as it was before. > > diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h > > index e48e8788c..5848ae729 100644 > > --- a/src/box/sql/mem.h > > +++ b/src/box/sql/mem.h > > @@ -568,6 +568,28 @@ mem_get_double(const struct Mem *mem, double *d); > > int > > mem_get_bool(const struct Mem *mem, bool *b); > > > > +/** > > + * Return value for MEM of STRING type if MEM contains a NULL-terminated string. > > + * Otherwise convert value of the MEM to NULL-terminated string if possible and > > + * return converted value. Original MEM is not changed. > > + */ > > +int > > +mem_get_str0(const struct Mem *mem, const char **s); > > + > > +/** > > + * Return value for MEM of STRING type if MEM contains NULL-terminated string. > > + * Otherwise convert MEM to MEM of string type that contains NULL-terminated > > + * string and return its value. Return NULL if conversion is impossible. > > + */ > > +static inline const char * > > +mem_as_str0(struct Mem *mem) > > +{ > > + const char *str; > > + if (mem_to_str0(mem) != 0 || mem_get_str0(mem, &str) != 0) > > 2. If mem_to_str0 succeeded, why can't you return mem->z right away? > True, I can. Fixed. > > + return NULL; > > + return str; > > +} Diff: diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h index b16536e6e..8d53fa161 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -850,10 +850,9 @@ mem_get_str0(const struct Mem *mem, const char **s); static inline const char * mem_as_str0(struct Mem *mem) { - const char *str; - if (mem_to_str0(mem) != 0 || mem_get_str0(mem, &str) != 0) + if (mem_to_str0(mem) != 0) return NULL; - return str; + return mem->z; } /** New patch: commit 18a745c61eaeaa2d4b324b5aa13cbe0e80ce9ad7 Author: Mergen Imeev Date: Thu Mar 18 12:41:41 2021 +0300 sql: introduce mem_get_str0() and mem_as_str0() This patch introduces mem_get_str0() and mem_as_str0(). Function mem_get_str0() is used to receive NULL-terminated string from MEM. If value of MEM is not NULL-terminated string, it is converted to NULL-terminated string if possible. MEM is not changed. Function mem_as_str0() is also used to receive NULL-terminated string from MEM, however if MEM does not contain NULL-terminated string it converts MEM to MEM that contains NULL-terminated string and returns its value. Part of #5818 diff --git a/src/box/sql/func.c b/src/box/sql/func.c index 3d8028077..38a7da69f 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -48,6 +48,12 @@ #include "box/coll_id_cache.h" #include "box/schema.h" +static const unsigned char * +mem_as_ustr(struct Mem *mem) +{ + return (const unsigned char *)mem_as_str0(mem); +} + /* * Return the collating function associated with a function. */ @@ -174,7 +180,7 @@ lengthFunc(sql_context * context, int argc, sql_value ** argv) break; } case MP_STR:{ - const unsigned char *z = sql_value_text(argv[0]); + const unsigned char *z = mem_as_ustr(argv[0]); if (z == 0) return; len = sql_utf8_char_count(z, sql_value_bytes(argv[0])); @@ -323,8 +329,8 @@ position_func(struct sql_context *context, int argc, struct Mem **argv) * Character size is equal to * needle char size. */ - haystack_str = sql_value_text(haystack); - needle_str = sql_value_text(needle); + haystack_str = mem_as_ustr(haystack); + needle_str = mem_as_ustr(needle); int n_needle_chars = sql_utf8_char_count(needle_str, n_needle_bytes); @@ -386,8 +392,7 @@ printfFunc(sql_context * context, int argc, sql_value ** argv) int n; sql *db = sql_context_db_handle(context); - if (argc >= 1 - && (zFormat = (const char *)sql_value_text(argv[0])) != 0) { + if (argc >= 1 && (zFormat = mem_as_str0(argv[0])) != NULL) { x.nArg = argc - 1; x.nUsed = 0; x.apArg = argv + 1; @@ -440,7 +445,7 @@ substrFunc(sql_context * context, int argc, sql_value ** argv) return; assert(len == sql_value_bytes(argv[0])); } else { - z = sql_value_text(argv[0]); + z = mem_as_ustr(argv[0]); if (z == 0) return; len = 0; @@ -602,13 +607,13 @@ case_type##ICUFunc(sql_context *context, int argc, sql_value **argv) \ context->is_aborted = true; \ return; \ } \ - z2 = (char *)sql_value_text(argv[0]); \ + z2 = mem_as_str0(argv[0]); \ n = sql_value_bytes(argv[0]); \ /* \ * Verify that the call to _bytes() \ * does not invalidate the _text() pointer. \ */ \ - assert(z2 == (char *)sql_value_text(argv[0])); \ + assert(z2 == mem_as_str0(argv[0])); \ if (!z2) \ return; \ z1 = contextMalloc(context, ((i64) n) + 1); \ @@ -938,8 +943,8 @@ likeFunc(sql_context *context, int argc, sql_value **argv) context->is_aborted = true; return; } - const char *zB = (const char *) sql_value_text(argv[0]); - const char *zA = (const char *) sql_value_text(argv[1]); + const char *zB = mem_as_str0(argv[0]); + const char *zA = mem_as_str0(argv[1]); const char *zB_end = zB + sql_value_bytes(argv[0]); const char *zA_end = zA + sql_value_bytes(argv[1]); @@ -958,7 +963,7 @@ likeFunc(sql_context *context, int argc, sql_value **argv) return; } /* Encoding did not change */ - assert(zB == (const char *) sql_value_text(argv[0])); + assert(zB == mem_as_str0(argv[0])); if (argc == 3) { /* @@ -966,7 +971,7 @@ likeFunc(sql_context *context, int argc, sql_value **argv) * single UTF-8 character. Otherwise, return an * error. */ - const unsigned char *zEsc = sql_value_text(argv[2]); + const unsigned char *zEsc = mem_as_ustr(argv[2]); if (zEsc == 0) return; if (sql_utf8_char_count(zEsc, sql_value_bytes(argv[2])) != 1) { @@ -1095,7 +1100,7 @@ quoteFunc(sql_context * context, int argc, sql_value ** argv) case MP_STR:{ int i, j; u64 n; - const unsigned char *zArg = sql_value_text(argv[0]); + const unsigned char *zArg = mem_as_ustr(argv[0]); char *z; if (zArg == 0) @@ -1141,7 +1146,7 @@ quoteFunc(sql_context * context, int argc, sql_value ** argv) static void unicodeFunc(sql_context * context, int argc, sql_value ** argv) { - const unsigned char *z = sql_value_text(argv[0]); + const unsigned char *z = mem_as_ustr(argv[0]); (void)argc; if (z && z[0]) sql_result_uint(context, sqlUtf8Read(&z)); @@ -1259,12 +1264,12 @@ replaceFunc(sql_context * context, int argc, sql_value ** argv) assert(argc == 3); UNUSED_PARAMETER(argc); - zStr = sql_value_text(argv[0]); + zStr = mem_as_ustr(argv[0]); if (zStr == 0) return; nStr = sql_value_bytes(argv[0]); - assert(zStr == sql_value_text(argv[0])); /* No encoding change */ - zPattern = sql_value_text(argv[1]); + assert(zStr == mem_as_ustr(argv[0])); /* No encoding change */ + zPattern = mem_as_ustr(argv[1]); if (zPattern == 0) { assert(mem_is_null(argv[1]) || sql_context_db_handle(context)->mallocFailed); @@ -1276,12 +1281,12 @@ replaceFunc(sql_context * context, int argc, sql_value ** argv) sql_result_value(context, argv[0]); return; } - assert(zPattern == sql_value_text(argv[1])); /* No encoding change */ - zRep = sql_value_text(argv[2]); + assert(zPattern == mem_as_ustr(argv[1])); /* No encoding change */ + zRep = mem_as_ustr(argv[2]); if (zRep == 0) return; nRep = sql_value_bytes(argv[2]); - assert(zRep == sql_value_text(argv[2])); + assert(zRep == mem_as_ustr(argv[2])); nOut = nStr + 1; assert(nOut < SQL_MAX_LENGTH); zOut = contextMalloc(context, (i64) nOut); @@ -1443,7 +1448,7 @@ trim_func_one_arg(struct sql_context *context, sql_value *arg) else default_trim = (const unsigned char *) " "; int input_str_sz = sql_value_bytes(arg); - const unsigned char *input_str = sql_value_text(arg); + const unsigned char *input_str = mem_as_ustr(arg); uint8_t trim_char_len[1] = { 1 }; trim_procedure(context, TRIM_BOTH, default_trim, trim_char_len, 1, input_str, input_str_sz); @@ -1465,7 +1470,7 @@ trim_func_two_args(struct sql_context *context, sql_value *arg1, sql_value *arg2) { const unsigned char *input_str, *trim_set; - if ((input_str = sql_value_text(arg2)) == NULL) + if ((input_str = mem_as_ustr(arg2)) == NULL) return; int input_str_sz = sql_value_bytes(arg2); @@ -1474,7 +1479,7 @@ trim_func_two_args(struct sql_context *context, sql_value *arg1, trim_procedure(context, mem_get_int_unsafe(arg1), (const unsigned char *) " ", &len_one, 1, input_str, input_str_sz); - } else if ((trim_set = sql_value_text(arg1)) != NULL) { + } else if ((trim_set = mem_as_ustr(arg1)) != NULL) { int trim_set_sz = sql_value_bytes(arg1); uint8_t *char_len; int char_cnt = trim_prepare_char_len(context, trim_set, @@ -1500,8 +1505,8 @@ trim_func_three_args(struct sql_context *context, sql_value *arg1, { assert(sql_value_type(arg1) == MP_INT || sql_value_type(arg1) == MP_UINT); const unsigned char *input_str, *trim_set; - if ((input_str = sql_value_text(arg3)) == NULL || - (trim_set = sql_value_text(arg2)) == NULL) + if ((input_str = mem_as_ustr(arg3)) == NULL || + (trim_set = mem_as_ustr(arg2)) == NULL) return; int trim_set_sz = sql_value_bytes(arg2); @@ -1573,7 +1578,7 @@ soundexFunc(sql_context * context, int argc, sql_value ** argv) context->is_aborted = true; return; } - zIn = (u8 *) sql_value_text(argv[0]); + zIn = (u8 *) mem_as_ustr(argv[0]); if (zIn == 0) zIn = (u8 *) ""; for (i = 0; zIn[i] && !sqlIsalpha(zIn[i]); i++) { @@ -1818,7 +1823,7 @@ groupConcatStep(sql_context * context, int argc, sql_value ** argv) pAccum->mxAlloc = db->aLimit[SQL_LIMIT_LENGTH]; if (!firstTerm) { if (argc == 2) { - zSep = (char *)sql_value_text(argv[1]); + zSep = mem_as_str0(argv[1]); nSep = sql_value_bytes(argv[1]); } else { zSep = ","; @@ -1827,7 +1832,7 @@ groupConcatStep(sql_context * context, int argc, sql_value ** argv) if (zSep) sqlStrAccumAppend(pAccum, zSep, nSep); } - zVal = (char *)sql_value_text(argv[0]); + zVal = mem_as_str0(argv[0]); nVal = sql_value_bytes(argv[0]); if (zVal) sqlStrAccumAppend(pAccum, zVal, nVal); diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index 661764f9c..c73edb21e 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -1134,6 +1134,15 @@ mem_get_bool(const struct Mem *mem, bool *b) return -1; } +int +mem_get_str0(const struct Mem *mem, const char **s) +{ + if ((mem->flags & MEM_Str) == 0 || (mem->flags & MEM_Term) == 0) + return -1; + *s = mem->z; + return 0; +} + int mem_copy(struct Mem *to, const struct Mem *from) { @@ -1777,45 +1786,6 @@ mem_has_msgpack_subtype(struct Mem *mem) mem->subtype == SQL_SUBTYPE_MSGPACK; } -/* - * The pVal argument is known to be a value other than NULL. - * Convert it into a string with encoding enc and return a pointer - * to a zero-terminated version of that string. - */ -static SQL_NOINLINE const void * -valueToText(sql_value * pVal) -{ - assert(pVal != 0); - assert((pVal->flags & (MEM_Null)) == 0); - if ((pVal->flags & (MEM_Blob | MEM_Str)) && - !mem_has_msgpack_subtype(pVal)) { - if (ExpandBlob(pVal)) - return 0; - pVal->flags |= MEM_Str; - sqlVdbeMemNulTerminate(pVal); /* IMP: R-31275-44060 */ - } else { - mem_to_str(pVal); - assert(0 == (1 & SQL_PTR_TO_INT(pVal->z))); - } - return pVal->z; -} - -/* - * It is already known that pMem contains an unterminated string. - * Add the zero terminator. - */ -static SQL_NOINLINE int -vdbeMemAddTerminator(Mem * pMem) -{ - if (sqlVdbeMemGrow(pMem, pMem->n + 2, 1)) { - return -1; - } - pMem->z[pMem->n] = 0; - pMem->z[pMem->n + 1] = 0; - pMem->flags |= MEM_Term; - return 0; -} - /* * Both *pMem1 and *pMem2 contain string values. Compare the two values * using the collation sequence pColl. As usual, return a negative , zero @@ -1917,7 +1887,9 @@ sql_value_type(sql_value *pVal) static SQL_NOINLINE int valueBytes(sql_value * pVal) { - return valueToText(pVal) != 0 ? pVal->n : 0; + if (mem_to_str(pVal) != 0) + return 0; + return pVal->n; } int @@ -2106,21 +2078,6 @@ registerTrace(int iReg, Mem *p) { } #endif -/* - * Make sure the given Mem is \u0000 terminated. - */ -int -sqlVdbeMemNulTerminate(Mem * pMem) -{ - testcase((pMem->flags & (MEM_Term | MEM_Str)) == (MEM_Term | MEM_Str)); - testcase((pMem->flags & (MEM_Term | MEM_Str)) == 0); - if ((pMem->flags & (MEM_Term | MEM_Str)) != MEM_Str) { - return 0; /* Nothing to do */ - } else { - return vdbeMemAddTerminator(pMem); - } -} - /* * If the given Mem* has a zero-filled tail, turn it into an ordinary * blob stored in dynamically allocated space. @@ -2279,7 +2236,9 @@ sql_value_blob(sql_value * pVal) p->flags |= MEM_Blob; return p->n ? p->z : 0; } else { - return sql_value_text(pVal); + if (mem_to_str(pVal) != 0) + return NULL; + return pVal->z; } } @@ -2289,36 +2248,6 @@ sql_value_bytes(sql_value * pVal) return sqlValueBytes(pVal); } -const unsigned char * -sql_value_text(sql_value * pVal) -{ - return (const unsigned char *)sqlValueText(pVal); -} - -/* This function is only available internally, it is not part of the - * external API. It works in a similar way to sql_value_text(), - * except the data returned is in the encoding specified by the second - * parameter, which must be one of SQL_UTF16BE, SQL_UTF16LE or - * SQL_UTF8. - * - * (2006-02-16:) The enc value can be or-ed with SQL_UTF16_ALIGNED. - * If that is the case, then the result must be aligned on an even byte - * boundary. - */ -const void * -sqlValueText(sql_value * pVal) -{ - if (!pVal) - return 0; - if ((pVal->flags & (MEM_Str | MEM_Term)) == (MEM_Str | MEM_Term)) { - return pVal->z; - } - if (pVal->flags & MEM_Null) { - return 0; - } - return valueToText(pVal); -} - /* * Return a pointer to static memory containing an SQL NULL value. */ diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h index b59197e6c..8d53fa161 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -834,6 +834,27 @@ mem_get_bool_unsafe(const struct Mem *mem) return b; } +/** + * Return value for MEM of STRING type if MEM contains a NULL-terminated string. + * Otherwise convert value of the MEM to NULL-terminated string if possible and + * return converted value. Original MEM is not changed. + */ +int +mem_get_str0(const struct Mem *mem, const char **s); + +/** + * Return value for MEM of STRING type if MEM contains NULL-terminated string. + * Otherwise convert MEM to MEM of string type that contains NULL-terminated + * string and return its value. Return NULL if conversion is impossible. + */ +static inline const char * +mem_as_str0(struct Mem *mem) +{ + if (mem_to_str0(mem) != 0) + return NULL; + return mem->z; +} + /** * Simple type to str convertor. It is used to simplify * error reporting. @@ -867,7 +888,6 @@ registerTrace(int iReg, Mem *p); #define memIsValid(M) ((M)->flags & MEM_Undefined)==0 #endif -int sqlVdbeMemNulTerminate(struct Mem *); int sqlVdbeMemExpandBlob(struct Mem *); #define ExpandBlob(P) (((P)->flags&MEM_Zero)?sqlVdbeMemExpandBlob(P):0) @@ -892,11 +912,6 @@ sql_value_blob(struct Mem *); int sql_value_bytes(struct Mem *); -const unsigned char * -sql_value_text(struct Mem *); - -const void *sqlValueText(struct Mem *); - #define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))]) const Mem * diff --git a/src/box/sql/printf.c b/src/box/sql/printf.c index 2f1948ff8..b4ab0d0f9 100644 --- a/src/box/sql/printf.c +++ b/src/box/sql/printf.c @@ -160,7 +160,8 @@ getTextArg(PrintfArguments * p) { if (p->nArg <= p->nUsed) return 0; - return (char *)sql_value_text(p->apArg[p->nUsed++]); + struct Mem *mem = p->apArg[p->nUsed++]; + return (char *)mem_as_str0(mem); } /* diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h index df9469941..51613aea3 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -442,10 +442,6 @@ sql_column_bytes(sql_stmt *, int iCol); int sql_column_bytes16(sql_stmt *, int iCol); -const unsigned char * -sql_column_text(sql_stmt *, - int iCol); - char * sql_result_to_msgpack(struct sql_stmt *stmt, uint32_t *tuple_size, struct region *region); diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c index c75322899..da161e298 100644 --- a/src/box/sql/vdbeapi.c +++ b/src/box/sql/vdbeapi.c @@ -464,12 +464,6 @@ sql_column_bytes(sql_stmt * pStmt, int i) return sql_value_bytes(columnMem(pStmt, i)); } -const unsigned char * -sql_column_text(sql_stmt * pStmt, int i) -{ - return sql_value_text(columnMem(pStmt, i)); -} - char * sql_result_to_msgpack(struct sql_stmt *stmt, uint32_t *tuple_size, struct region *region) diff --git a/src/box/sql/whereexpr.c b/src/box/sql/whereexpr.c index 93de722cb..fe7329ea8 100644 --- a/src/box/sql/whereexpr.c +++ b/src/box/sql/whereexpr.c @@ -312,8 +312,10 @@ like_optimization_is_valid(Parse *pParse, Expr *pExpr, Expr **ppPrefix, pVal = sqlVdbeGetBoundValue(pReprepare, iCol, FIELD_TYPE_SCALAR); - if (pVal != NULL && mem_is_str(pVal)) - z = (char *)sql_value_text(pVal); + if (pVal != NULL && mem_is_str(pVal)) { + if (mem_as_str0(pVal) == NULL) + return -1; + } assert(pRight->op == TK_VARIABLE || pRight->op == TK_REGISTER); } else if (op == TK_STRING) { z = pRight->u.zToken;