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 82C5D2CCB3 for ; Thu, 29 Nov 2018 08:10:03 -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 uVnaZNtLpLuk for ; Thu, 29 Nov 2018 08:10:03 -0500 (EST) Received: from smtp52.i.mail.ru (smtp52.i.mail.ru [94.100.177.112]) (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 D053E2BFF6 for ; Thu, 29 Nov 2018 08:09:56 -0500 (EST) From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v1 3/6] box: exported sql_bind structure and API Date: Thu, 29 Nov 2018 16:09:47 +0300 Message-Id: <2e35591161e0c57d15ff6083658bc0aad6bf553e.1543496928.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, v.shpilevoy@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 f88572d22..35833832e 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; @@ -432,16 +397,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 77bfd7913..a48de9319 100644 --- a/src/box/execute.h +++ b/src/box/execute.h @@ -52,6 +52,7 @@ struct obuf; struct region; struct sql_bind; struct xrow_header; +struct sqlite3_stmt; /** EXECUTE request. */ struct sql_request { @@ -137,6 +138,57 @@ int sql_prepare_and_execute(const struct sql_request *request, 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" { */ #include "diag.h" -- 2.19.2