[Tarantool-patches] [PATCH v4 50/53] sql: introduce mem_get_boolean()

imeevma at tarantool.org imeevma at tarantool.org
Tue Mar 23 12:36:48 MSK 2021


This patch introduces mem_get_boolean() which is used to receive boolean
value from MEM.

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

diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index 15fb2f14f..d033dae86 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -142,9 +142,12 @@ port_vdbemem_dump_lua(struct port *base, struct lua_State *L, bool is_flat)
 		case MP_NIL:
 			lua_pushnil(L);
 			break;
-		case MP_BOOL:
-			lua_pushboolean(L, sql_value_boolean(param));
+		case MP_BOOL: {
+			bool b;
+			mem_get_boolean(param, &b);
+			lua_pushboolean(L, b);
 			break;
+		}
 		default:
 			unreachable();
 		}
@@ -206,7 +209,9 @@ port_vdbemem_get_msgpack(struct port *base, uint32_t *size)
 			break;
 		}
 		case MP_BOOL: {
-			mpstream_encode_bool(&stream, sql_value_boolean(param));
+			bool b;
+			mem_get_boolean(param, &b);
+			mpstream_encode_bool(&stream, b);
 			break;
 		}
 		default:
@@ -1451,8 +1456,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_boolean(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 8d4f0f92c..90c6ee526 100644
--- a/src/box/sql/mem.c
+++ b/src/box/sql/mem.c
@@ -1309,6 +1309,16 @@ mem_get_double(const struct Mem *mem, double *d)
 	return -1;
 }
 
+int
+mem_get_boolean(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)
 {
@@ -2467,16 +2477,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.
@@ -2503,16 +2503,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 f9d229baf..8015608fa 100644
--- a/src/box/sql/mem.h
+++ b/src/box/sql/mem.h
@@ -354,6 +354,9 @@ mem_get_unsigned(const struct Mem *mem, uint64_t *u);
 int
 mem_get_double(const struct Mem *mem, double *d);
 
+int
+mem_get_boolean(const struct Mem *mem, bool *b);
+
 /**
  * Simple type to str convertor. It is used to simplify
  * error reporting.
@@ -430,17 +433,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 3e2cc4a66..9b4afc3f2 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 9a97b2d77..532677b05 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -485,12 +485,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