From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 7F8F62E5ED for ; Thu, 23 May 2019 06:19:43 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LLMUCDdHK4WB for ; Thu, 23 May 2019 06:19:43 -0400 (EDT) Received: from smtp36.i.mail.ru (smtp36.i.mail.ru [94.100.177.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id A89B52E416 for ; Thu, 23 May 2019 06:19:42 -0400 (EDT) From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v5 1/6] sql: introduce a new method to bind a pointer Date: Thu, 23 May 2019 13:19:34 +0300 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org, v.shpilevoy@tarantool.org Cc: Kirill Shcherbatov A new sql_bind_ptr routine allows to bing a generic pointer to VDBE variable. This change is required to pass a tuple_fetcher representing a new tuple to the check constraint VDBE. Needed for #3961 --- src/box/sql/sqlInt.h | 12 ++++++++++++ src/box/sql/vdbeInt.h | 8 ++++++++ src/box/sql/vdbeapi.c | 12 ++++++++++++ src/box/sql/vdbemem.c | 8 ++++++++ 4 files changed, 40 insertions(+) diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h index e33d7d95b..7212553f6 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -923,6 +923,18 @@ int sql_bind_zeroblob64(sql_stmt *, int, sql_uint64); +/** + * Perform pointer parameter binding for the prepared sql + * statement. + * @param stmt Prepared statement. + * @param i Index of the variable to be binded. + * @param ptr Pointer value to use. + * @retval 0 On Success. + * @retval Not 0 otherwise. + */ +int +sql_bind_ptr(struct sql_stmt *stmt, int i, void *ptr); + int sql_stmt_busy(sql_stmt *); diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h index 86fd92da1..240283927 100644 --- a/src/box/sql/vdbeInt.h +++ b/src/box/sql/vdbeInt.h @@ -501,6 +501,14 @@ void sqlVdbeMemSetInt64(Mem *, i64); void mem_set_bool(struct Mem *mem, bool value); +/** + * Set VDBE memory register with given pointer as a data. + * @param mem VDBE memory register to update. + * @param ptr Pointer to use. + */ +void +mem_set_ptr(struct Mem *mem, void *ptr); + void sqlVdbeMemSetDouble(Mem *, double); void sqlVdbeMemInit(Mem *, sql *, u32); void sqlVdbeMemSetNull(Mem *); diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c index e480ae720..198c2a9d7 100644 --- a/src/box/sql/vdbeapi.c +++ b/src/box/sql/vdbeapi.c @@ -1392,6 +1392,18 @@ sql_bind_null(sql_stmt * pStmt, int i) return rc; } +int +sql_bind_ptr(struct sql_stmt *stmt, int i, void *ptr) +{ + struct Vdbe *p = (struct Vdbe *) stmt; + int rc = vdbeUnbind(p, i); + if (rc == SQL_OK) { + rc = sql_bind_type(p, i, "BLOB"); + mem_set_ptr(&p->aVar[i - 1], ptr); + } + return rc; +} + int sql_bind_text(sql_stmt * pStmt, int i, const char *zData, int nData, void (*xDel) (void *) diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c index f73ea0a71..382d8ae56 100644 --- a/src/box/sql/vdbemem.c +++ b/src/box/sql/vdbemem.c @@ -749,6 +749,14 @@ sqlValueSetNull(sql_value * p) sqlVdbeMemSetNull((Mem *) p); } +void +mem_set_ptr(struct Mem *mem, void *ptr) +{ + sqlVdbeMemRelease(mem); + mem->flags = MEM_Ptr; + mem->u.p = ptr; +} + /* * Delete any previous value and set the value to be a BLOB of length * n containing all zeros. -- 2.21.0