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 87A5E24515 for ; Thu, 10 Jan 2019 08:54:55 -0500 (EST) 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 JHe2CFz4QSWR for ; Thu, 10 Jan 2019 08:54:55 -0500 (EST) Received: from smtp55.i.mail.ru (smtp55.i.mail.ru [217.69.128.35]) (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 96C512463F for ; Thu, 10 Jan 2019 08:54:54 -0500 (EST) From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v1 3/4] box: exported sql_bind structure and API Date: Thu, 10 Jan 2019 16:54:49 +0300 Message-Id: <01f4e54517b44980ced0f655cd5735063f929c40.1547128310.git.kshcherbatov@tarantool.org> 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, korablev@tarantool.org Cc: Kirill Shcherbatov We need exprort sql_bind structure, sql_bind_decode and sql_bind_column routines to make SQL Vars bindings for Vdbe code outside of execute module, preparing Checks stmt for execution. Need for #3691 --- src/box/execute.c | 48 ++----------------------------------------- src/box/execute.h | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 46 deletions(-) diff --git a/src/box/execute.c b/src/box/execute.c index 7fff5fdff..9498b99be 100644 --- a/src/box/execute.c +++ b/src/box/execute.c @@ -57,31 +57,6 @@ const char *sql_info_key_strs[] = { "row count", }; -/** - * Name and value of an SQL prepared statement parameter. - * @todo: merge with sqlite3_value. - */ -struct sql_bind { - /** Bind name. NULL for ordinal binds. */ - const char *name; - /** Length of the @name. */ - uint32_t name_len; - /** Ordinal position of the bind, for ordinal binds. */ - uint32_t pos; - - /** Byte length of the value. */ - uint32_t bytes; - /** SQL type of the value. */ - uint8_t type; - /** Bind value. */ - union { - double d; - int64_t i64; - /** For string or blob. */ - const char *s; - }; -}; - /** * Return a string name of a parameter marker. * @param Bind to get name. @@ -96,17 +71,7 @@ sql_bind_name(const struct sql_bind *bind) return tt_sprintf("%d", (int) bind->pos); } -/** - * Decode a single bind column from the binary protocol packet. - * @param[out] bind Bind to decode to. - * @param i Ordinal bind number. - * @param packet MessagePack encoded parameter value. Either - * scalar or map: {string_name: scalar_value}. - * - * @retval 0 Success. - * @retval -1 Memory or client error. - */ -static inline int +int sql_bind_decode(struct sql_bind *bind, int i, const char **packet) { bind->pos = i + 1; @@ -363,16 +328,7 @@ error: return -1; } -/** - * Bind SQL parameter value to its position. - * @param stmt Prepared statement. - * @param p Parameter value. - * @param pos Ordinal bind position. - * - * @retval 0 Success. - * @retval -1 SQL error. - */ -static inline int +int sql_bind_column(struct sqlite3_stmt *stmt, const struct sql_bind *p, uint32_t pos) { diff --git a/src/box/execute.h b/src/box/execute.h index 9c1bc4f05..e0b730407 100644 --- a/src/box/execute.h +++ b/src/box/execute.h @@ -51,6 +51,7 @@ extern const char *sql_info_key_strs[]; struct obuf; struct region; struct sql_bind; +struct sqlite3_stmt; /** Response on EXECUTE request. */ struct sql_response { @@ -132,6 +133,57 @@ sql_prepare_and_execute(const char *sql, int len, const struct sql_bind *bind, uint32_t bind_count, struct sql_response *response, struct region *region); +/** + * Name and value of an SQL prepared statement parameter. + * @todo: merge with sqlite3_value. + */ +struct sql_bind { + /** Bind name. NULL for ordinal binds. */ + const char *name; + /** Length of the @name. */ + uint32_t name_len; + /** Ordinal position of the bind, for ordinal binds. */ + uint32_t pos; + + /** Byte length of the value. */ + uint32_t bytes; + /** SQL type of the value. */ + uint8_t type; + /** Bind value. */ + union { + double d; + int64_t i64; + /** For string or blob. */ + const char *s; + }; +}; + +/** + * Decode a single bind column from the binary protocol packet. + * @param[out] bind Bind to decode to. + * @param i Ordinal bind number. + * @param packet MessagePack encoded parameter value. Either + * scalar or map: {string_name: scalar_value}. + * + * @retval 0 Success. + * @retval -1 Memory or client error. + */ +int +sql_bind_decode(struct sql_bind *bind, int i, const char **packet); + +/** + * Bind SQL parameter value to its position. + * @param stmt Prepared statement. + * @param p Parameter value. + * @param pos Ordinal bind position. + * + * @retval 0 Success. + * @retval -1 SQL error. + */ +int +sql_bind_column(struct sqlite3_stmt *stmt, const struct sql_bind *p, + uint32_t pos); + #if defined(__cplusplus) } /* extern "C" { */ #endif -- 2.19.2