[Tarantool-patches] [PATCH v1 11/21] sql: refactor ROW_COUNT() function
imeevma at tarantool.org
imeevma at tarantool.org
Thu Nov 11 13:49:09 MSK 2021
Part of #4145
---
src/box/sql/func.c | 12 +++++++++++-
src/box/sql/main.c | 10 ----------
src/box/sql/sqlInt.h | 8 +-------
3 files changed, 12 insertions(+), 18 deletions(-)
diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index c5428d87b..014fd9af2 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -988,6 +988,16 @@ func_round(struct sql_context *ctx, int argc, struct Mem *argv)
return mem_set_double(res, (double)(int64_t)(d + delta));
}
+/** Implementation of the ROW_COUNT() function. */
+static void
+func_row_count(struct sql_context *ctx, int argc, struct Mem *argv)
+{
+ (void)argc;
+ (void)argv;
+ assert(sql_get()->nChange >= 0);
+ return mem_set_uint(ctx->pOut, sql_get()->nChange);
+}
+
static const unsigned char *
mem_as_ustr(struct Mem *mem)
{
@@ -1869,7 +1879,7 @@ static struct sql_func_definition definitions[] = {
{"ROUND", 1, {FIELD_TYPE_DOUBLE}, FIELD_TYPE_DOUBLE, func_round, NULL},
{"ROUND", 2, {FIELD_TYPE_DOUBLE, FIELD_TYPE_INTEGER}, FIELD_TYPE_DOUBLE,
func_round, NULL},
- {"ROW_COUNT", 0, {}, FIELD_TYPE_INTEGER, sql_row_count, NULL},
+ {"ROW_COUNT", 0, {}, FIELD_TYPE_INTEGER, func_row_count, NULL},
{"SOUNDEX", 1, {FIELD_TYPE_STRING}, FIELD_TYPE_STRING, soundexFunc,
NULL},
{"SUBSTR", 2, {FIELD_TYPE_STRING, FIELD_TYPE_INTEGER},
diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index a4247c760..ae872aaa1 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -220,16 +220,6 @@ setupLookaside(sql * db, void *pBuf, int sz, int cnt)
return 0;
}
-void
-sql_row_count(struct sql_context *context, int argc, struct Mem *argv)
-{
- (void)argc;
- (void)argv;
- sql *db = sql_context_db_handle(context);
- assert(db->nChange >= 0);
- sql_result_uint(context, db->nChange);
-}
-
/*
* Close all open savepoints.
* This procedure is trivial as savepoints are allocated on the "region" and
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 9361775b1..c8f711ed2 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -470,12 +470,6 @@ enum sql_subtype {
void
sql_randomness(int N, void *P);
-/**
- * Return the number of affected rows in the last SQL statement.
- */
-void
-sql_row_count(struct sql_context *context, int argc, struct Mem *argv);
-
int
sql_column_count(sql_stmt * pStmt);
@@ -1065,7 +1059,7 @@ struct sql {
u8 dfltLockMode; /* Default locking-mode for attached dbs */
u8 mTrace; /* zero or more sql_TRACE flags */
u32 magic; /* Magic number for detect library misuse */
- /** Value returned by sql_row_count(). */
+ /** Value returned by ROW_COUNT(). */
int nChange;
int aLimit[SQL_N_LIMIT]; /* Limits */
int nMaxSorterMmap; /* Maximum size of regions mapped by sorter */
--
2.25.1
More information about the Tarantool-patches
mailing list