[Tarantool-patches] [PATCH v5 48/52] sql: introduce mem_get_bool()

imeevma at tarantool.org imeevma at tarantool.org
Sat Apr 10 00:08:21 MSK 2021


This patch introduces mem_get_bool(). This function is used to receive
boolean value from MEM. If value of MEM is not boolean, it is
converted to boolean if possible. MEM is not changed.

Part of #5818
---
 src/box/sql/func.c    |  5 +++--
 src/box/sql/mem.c     | 30 ++++++++++--------------------
 src/box/sql/mem.h     | 13 ++++++++-----
 src/box/sql/sqlInt.h  |  3 ---
 src/box/sql/vdbeapi.c |  6 ------
 5 files changed, 21 insertions(+), 36 deletions(-)

diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index aeab06e2a..6a6970647 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -1130,8 +1130,9 @@ quoteFunc(sql_context * context, int argc, sql_value ** argv)
 			break;
 		}
 	case MP_BOOL: {
-		sql_result_text(context,
-				SQL_TOKEN_BOOLEAN(sql_value_boolean(argv[0])),
+		bool b;
+		mem_get_bool(argv[0], &b);
+		sql_result_text(context, SQL_TOKEN_BOOLEAN(b),
 				-1, SQL_TRANSIENT);
 		break;
 	}
diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
index 930c44bec..6f787f7cc 100644
--- a/src/box/sql/mem.c
+++ b/src/box/sql/mem.c
@@ -1313,6 +1313,16 @@ mem_get_double(const struct Mem *mem, double *d)
 	return -1;
 }
 
+int
+mem_get_bool(const struct Mem *mem, bool *b)
+{
+	if ((mem->flags & MEM_Bool) != 0) {
+		*b = mem->u.b;
+		return 0;
+	}
+	return -1;
+}
+
 int
 mem_copy(struct Mem *to, const struct Mem *from)
 {
@@ -2477,16 +2487,6 @@ releaseMemArray(Mem * p, int N)
 	}
 }
 
-int
-mem_value_bool(const struct Mem *mem, bool *b)
-{
-	if ((mem->flags  & MEM_Bool) != 0) {
-		*b = mem->u.b;
-		return 0;
-	}
-	return -1;
-}
-
 /**************************** sql_value_  ******************************
  * The following routines extract information from a Mem or sql_value
  * structure.
@@ -2513,16 +2513,6 @@ sql_value_bytes(sql_value * pVal)
 	return sqlValueBytes(pVal);
 }
 
-bool
-sql_value_boolean(sql_value *val)
-{
-	bool b = false;
-	int rc = mem_value_bool((struct Mem *) val, &b);
-	assert(rc == 0);
-	(void) rc;
-	return b;
-}
-
 const unsigned char *
 sql_value_text(sql_value * pVal)
 {
diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h
index 34b0b3f13..e48e8788c 100644
--- a/src/box/sql/mem.h
+++ b/src/box/sql/mem.h
@@ -560,6 +560,14 @@ mem_get_uint(const struct Mem *mem, uint64_t *u);
 int
 mem_get_double(const struct Mem *mem, double *d);
 
+/**
+ * Return value for MEM of BOOLEAN type. For MEM of all other types convert
+ * value of the MEM to BOOLEAN if possible and return converted value. Original
+ * MEM is not changed.
+ */
+int
+mem_get_bool(const struct Mem *mem, bool *b);
+
 /**
  * Simple type to str convertor. It is used to simplify
  * error reporting.
@@ -612,17 +620,12 @@ releaseMemArray(Mem * p, int N);
 
 /** Getters. */
 
-int
-mem_value_bool(const struct Mem *mem, bool *b);
 const void *
 sql_value_blob(struct Mem *);
 
 int
 sql_value_bytes(struct Mem *);
 
-bool
-sql_value_boolean(struct Mem *val);
-
 const unsigned char *
 sql_value_text(struct Mem *);
 
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 3f6fa1722..df9469941 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -442,9 +442,6 @@ sql_column_bytes(sql_stmt *, int iCol);
 int
 sql_column_bytes16(sql_stmt *, int iCol);
 
-bool
-sql_column_boolean(struct sql_stmt *stmt, int column);
-
 const unsigned char *
 sql_column_text(sql_stmt *,
 		    int iCol);
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index b1a9aed6e..1d3c23a70 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -484,12 +484,6 @@ sql_column_bytes(sql_stmt * pStmt, int i)
 	return sql_value_bytes(columnMem(pStmt, i));
 }
 
-bool
-sql_column_boolean(struct sql_stmt *stmt, int i)
-{
-	return sql_value_boolean(columnMem(stmt, i));
-}
-
 const unsigned char *
 sql_column_text(sql_stmt * pStmt, int i)
 {
-- 
2.25.1



More information about the Tarantool-patches mailing list