Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: Nikita Pettik <korablev@tarantool.org>,
	tarantool-patches@freelists.org,
	Kirill Yukhin <kyukhin@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH] sql: bind BLOB value as BLOB not as STRING
Date: Mon, 18 Mar 2019 20:34:43 +0300	[thread overview]
Message-ID: <cf527ad4-e789-8535-f5fc-247be29461c0@tarantool.org> (raw)
In-Reply-To: <20190318010558.15883-1-korablev@tarantool.org>

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
> 

  reply	other threads:[~2019-03-18 17:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-18  1:05 [tarantool-patches] " Nikita Pettik
2019-03-18 17:34 ` Vladislav Shpilevoy [this message]
2019-03-19 13:21 ` [tarantool-patches] " Kirill Yukhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cf527ad4-e789-8535-f5fc-247be29461c0@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=korablev@tarantool.org \
    --cc=kyukhin@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH] sql: bind BLOB value as BLOB not as STRING' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox