Tarantool development patches archive
 help / color / mirror / Atom feed
From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org, korablev@tarantool.org
Cc: Kirill Shcherbatov <kshcherbatov@tarantool.org>
Subject: [tarantool-patches] [PATCH v1 3/4] box: exported sql_bind structure and API
Date: Thu, 10 Jan 2019 16:54:49 +0300	[thread overview]
Message-ID: <01f4e54517b44980ced0f655cd5735063f929c40.1547128310.git.kshcherbatov@tarantool.org> (raw)
In-Reply-To: <cover.1547128310.git.kshcherbatov@tarantool.org>

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

  parent reply	other threads:[~2019-01-10 13:54 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-10 13:54 [tarantool-patches] [PATCH v1 0/4] sql: Checks on server side Kirill Shcherbatov
2019-01-10 13:54 ` [tarantool-patches] [PATCH v1 1/4] box: rename space->opts checks to checks_ast Kirill Shcherbatov
2019-01-11 14:05   ` [tarantool-patches] " Konstantin Osipov
2019-01-18 18:00   ` Konstantin Osipov
2019-01-10 13:54 ` [tarantool-patches] [PATCH v1 2/4] sql: disallow use of TYPEOF in Check Kirill Shcherbatov
2019-01-11 14:06   ` [tarantool-patches] " Konstantin Osipov
2019-01-11 14:07   ` Konstantin Osipov
2019-01-18 18:04   ` Konstantin Osipov
2019-01-10 13:54 ` Kirill Shcherbatov [this message]
2019-01-10 13:54 ` [tarantool-patches] [PATCH v1 4/4] sql: make sql checks on server side Kirill Shcherbatov
2019-01-11 14:12   ` [tarantool-patches] " Konstantin Osipov
2019-01-11 14:14   ` Konstantin Osipov
2019-01-18 18:11   ` Konstantin Osipov
2019-01-21 14:47   ` n.pettik

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=01f4e54517b44980ced0f655cd5735063f929c40.1547128310.git.kshcherbatov@tarantool.org \
    --to=kshcherbatov@tarantool.org \
    --cc=korablev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH v1 3/4] box: exported sql_bind structure and API' \
    /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