From: "n.pettik" <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: szudin@tarantool.org
Subject: [tarantool-patches] Re: [PATCH 04/13] sql: support big integers within sql binding
Date: Mon, 25 Mar 2019 18:12:33 +0300 [thread overview]
Message-ID: <7B68C4B8-A53B-483E-AD57-8A746682FD73@tarantool.org> (raw)
In-Reply-To: <c35a1f873c68cc7a593846862956e9e6ec1453a7.1552663061.git.szudin@tarantool.org>
> diff --git a/src/box/execute.c b/src/box/execute.c
> index 7c77df2e5..31b89a75e 100644
> --- a/src/box/execute.c
> +++ b/src/box/execute.c
> @@ -130,13 +130,8 @@ sql_bind_decode(struct sql_bind *bind, int i, const char **packet)
> switch (mp_typeof(**packet)) {
> case MP_UINT: {
> uint64_t n = mp_decode_uint(packet);
> - if (n > INT64_MAX) {
> - diag_set(ClientError, ER_SQL_BIND_VALUE,
> - sql_bind_name(bind), "INTEGER");
> - return -1;
> - }
> bind->i64 = (int64_t) n;
Please, add to bind struct separate member to hold uints.
> - bind->type = SQL_INTEGER;
> + bind->type = (n > INT64_MAX) ? SQL_UNSIGNED : SQL_INTEGER;
> bind->bytes = sizeof(bind->i64);
> break;
> }
> @@ -246,6 +241,7 @@ sql_column_to_messagepack(struct sql_stmt *stmt, int i,
> int type = sql_column_type(stmt, i);
> switch (type) {
> case SQL_INTEGER: {
> + assert(!sql_column_is_unsigned(stmt, i));
> int64_t n = sql_column_int64(stmt, i);
> if (n >= 0)
> size = mp_sizeof_uint(n);
> @@ -260,6 +256,16 @@ sql_column_to_messagepack(struct sql_stmt *stmt, int i,
> mp_encode_int(pos, n);
> break;
> }
> + case SQL_UNSIGNED: {
> + assert(sql_column_is_unsigned(stmt, i));
> + int64_t n = sql_column_int64(stmt, i);
->sql_column_uint64()
> + size = mp_sizeof_uint(n);
> + char *pos = (char *) region_alloc(region, size);
> + if (pos == NULL)
> + goto oom;
> + mp_encode_uint(pos, n);
> + break;
> + }
>
> diff --git a/src/box/lua/lua_sql.c b/src/box/lua/lua_sql.c
> index f5a7b7819..57a3161c7 100644
> --- a/src/box/lua/lua_sql.c
> +++ b/src/box/lua/lua_sql.c
> @@ -60,6 +60,9 @@ lua_sql_call(sql_context *pCtx, int nVal, sql_value **apVal) {
> case SQL_INTEGER:
> luaL_pushint64(L, sql_value_int64(param));
> break;
> + case SQL_UNSIGNED:
> + luaL_pushuint64(L, sql_value_int64(param));
Let’s introduce sql_value_uint64().
> diff --git a/src/box/lua/sql.c b/src/box/lua/sql.c
> index cb2927144..9a35c03aa 100644
> --- a/src/box/lua/sql.c
> +++ b/src/box/lua/sql.c
> @@ -32,10 +32,12 @@ lua_push_row(struct lua_State *L, struct sql_stmt *stmt)
> int type = sql_column_type(stmt, i);
> switch (type) {
> case SQL_INTEGER:
> - if (sql_column_is_unsigned(stmt, i))
> - luaL_pushuint64(L, sql_column_int64(stmt, i));
> - else
> - luaL_pushint64(L, sql_column_int64(stmt, i));
> + assert(!sql_column_is_unsigned(stmt, i));
> + luaL_pushint64(L, sql_column_int64(stmt, i));
> + break;
> + case SQL_UNSIGNED:
> + assert(sql_column_is_unsigned(stmt, i));
> + luaL_pushuint64(L, sql_column_int64(stmt, i));
> break;
> case SQL_FLOAT:
> lua_pushnumber(L, sql_column_double(stmt, i));
> diff --git a/src/box/sql/func.c b/src/box/sql/func.c
> index 21a69aa51..cf65bf2a2 100644
> --- a/src/box/sql/func.c
> +++ b/src/box/sql/func.c
>
> @@ -191,6 +192,11 @@ absFunc(sql_context * context, int argc, sql_value ** argv)
> sql_result_int64(context, iVal);
> break;
> }
> + case SQL_UNSIGNED: {
> + i64 iVal = sql_value_int64(argv[0]);
Replace this with uints once you add sql_value_uint64().
> + sql_result_int64(context, iVal);
The same: lets add sql_result_uint64().
> + break;
> + }
> case SQL_NULL:{
> /* IMP: R-37434-19929 Abs(X) returns NULL if X is NULL. */
> sql_result_null(context);
> diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
> index 92e2f282f..56aa7c681 100644
> --- a/src/box/sql/sqlInt.h
> +++ b/src/box/sql/sqlInt.h
> /**
>
> diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
> index ea398e7d6..8a7f7a12f 100644
> --- a/src/box/sql/vdbe.c
> +++ b/src/box/sql/vdbe.c
> @@ -1439,7 +1439,7 @@ case OP_IntCopy: { /* out2 */
> pIn1 = &aMem[pOp->p1];
> assert((pIn1->flags & MEM_Int)!=0);
> pOut = &aMem[pOp->p2];
> - sqlVdbeMemSetInt64(pOut, pIn1->u.i);
> + sqlVdbeMemSetInt64(pOut, pIn1->u.i, (pIn1->flags & MEM_Unsigned)!=0);
> break;
> }
>
> @@ -1770,7 +1770,7 @@ integer_overflow:
> case OP_CollSeq: {
> assert(pOp->p4type==P4_COLLSEQ || pOp->p4.pColl == NULL);
> if (pOp->p1) {
> - sqlVdbeMemSetInt64(&aMem[pOp->p1], 0);
> + sqlVdbeMemSetInt64(&aMem[pOp->p1], 0, false);
Instead of passing argument indicating signedness, I would
introduce separate function to set vdbe memory with uint value.
> }
> break;
> }
> @@ -5317,7 +5317,7 @@ case OP_AggStep: {
> if (pCtx->skipFlag) {
> assert(pOp[-1].opcode==OP_CollSeq);
> i = pOp[-1].p1;
> - if (i) sqlVdbeMemSetInt64(&aMem[i], 1);
> + if (i) sqlVdbeMemSetInt64(&aMem[i], 1, false);
> }
> break;
> }
> diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h
> index 66b21299a..0375845d9 100644
> --- a/src/box/sql/vdbeInt.h
> +++ b/src/box/sql/vdbeInt.h
> @@ -477,7 +477,7 @@ void sqlVdbeMemShallowCopy(Mem *, const Mem *, int);
> void sqlVdbeMemMove(Mem *, Mem *);
> int sqlVdbeMemNulTerminate(Mem *);
> int sqlVdbeMemSetStr(Mem *, const char *, int, u8, void (*)(void *));
> -void sqlVdbeMemSetInt64(Mem *, i64);
> +void sqlVdbeMemSetInt64(Mem *, i64, bool);
> #ifdef SQL_OMIT_FLOATING_POINT
> #define sqlVdbeMemSetDouble sqlVdbeMemSetInt64
> #else
> diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
> index 02a1b2e0f..2c486552e 100644
> --- a/src/box/sql/vdbeapi.c
> +++ b/src/box/sql/vdbeapi.c
> @@ -279,8 +279,49 @@ sql_value_type(sql_value * pVal)
> SQL_NULL, /* 0x1d */
> SQL_INTEGER, /* 0x1e */
> SQL_NULL, /* 0x1f */
> +
> + SQL_BLOB, /* 0x20 */
> + SQL_NULL, /* 0x21 */
> + SQL_TEXT, /* 0x22 */
> + SQL_NULL, /* 0x23 */
> + SQL_UNSIGNED, /* 0x24 */
> + SQL_NULL, /* 0x25 */
> + SQL_UNSIGNED, /* 0x26 */
> + SQL_NULL, /* 0x27 */
> + SQL_FLOAT, /* 0x28 */
> + SQL_NULL, /* 0x29 */
> + SQL_FLOAT, /* 0x2a */
> + SQL_NULL, /* 0x2b */
> + SQL_INTEGER, /* 0x2c */
> + SQL_NULL, /* 0x2d */
> + SQL_INTEGER, /* 0x2e */
> + SQL_NULL, /* 0x2f */
> + SQL_BLOB, /* 0x30 */
> + SQL_NULL, /* 0x31 */
> + SQL_TEXT, /* 0x32 */
> + SQL_NULL, /* 0x33 */
> + SQL_INTEGER, /* 0x34 */
> + SQL_NULL, /* 0x35 */
> + SQL_INTEGER, /* 0x36 */
> + SQL_NULL, /* 0x37 */
> + SQL_FLOAT, /* 0x38 */
> + SQL_NULL, /* 0x39 */
> + SQL_FLOAT, /* 0x3a */
> + SQL_NULL, /* 0x3b */
> + SQL_INTEGER, /* 0x3c */
> + SQL_NULL, /* 0x3d */
> + SQL_INTEGER, /* 0x3e */
> + SQL_NULL, /* 0x3f */
Looks terrible. Could we rework this mechanism of fetching type?
Soon we are going to add several types more, so the size of array
will become enormous.
> };
> - return aType[pVal->flags & MEM_PURE_TYPE_MASK];
> +
> + assert(MEM_Unsigned == 0x20000);
> + /* compress the unsigned bit with the pure
> + * type bits, to make them applicable for
> + * array indexing.
> + */
> + u32 offset = (pVal->flags >> 12) | (pVal->flags & MEM_PURE_TYPE_MASK);
> + assert(offset < 0x40);
> + return aType[offset];
> }
>
> /* Make a copy of an sql_value object
> @@ -401,13 +442,13 @@ sql_result_error(sql_context * pCtx, const char *z, int n)
>
> void
> @@ -1370,7 +1411,20 @@ sql_bind_int64(sql_stmt * pStmt, int i, sql_int64 iValue)
> rc = vdbeUnbind(p, i);
> if (rc == SQL_OK) {
> rc = sql_bind_type(p, i, "INTEGER");
> - sqlVdbeMemSetInt64(&p->aVar[i - 1], iValue);
> + sqlVdbeMemSetInt64(&p->aVar[i - 1], iValue, false);
> + }
> + return rc;
> +}
> +
> +int
> +sql_bind_uint64(sql_stmt * pStmt, int i, sql_uint64 iValue)
> +{
> + int rc;
> + Vdbe *p = (Vdbe *) pStmt;
> + rc = vdbeUnbind(p, i);
> + if (rc == SQL_OK) {
> + rc = sql_bind_type(p, i, "INTEGER”);
Why integer? I guess it should be unsigned.
> + sqlVdbeMemSetInt64(&p->aVar[i - 1], (u64)iValue, true);
> }
> return rc;
> }
>
next prev parent reply other threads:[~2019-03-25 15:12 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-15 15:45 [PATCH 00/13] sql: support -2^63 .. 2^64-1 integer type Stanislav Zudin
2019-03-15 15:45 ` [PATCH 01/13] sql: Convert big integers from string Stanislav Zudin
2019-03-25 15:10 ` [tarantool-patches] " n.pettik
2019-04-01 20:39 ` Stanislav Zudin
2019-04-02 7:27 ` Konstantin Osipov
2019-03-15 15:45 ` [PATCH 02/13] sql: make VDBE recognize big integers Stanislav Zudin
2019-03-25 15:11 ` [tarantool-patches] " n.pettik
2019-04-01 20:42 ` Stanislav Zudin
2019-04-02 7:38 ` [tarantool-patches] " Konstantin Osipov
2019-03-15 15:45 ` [PATCH 03/13] sql: removes unused function Stanislav Zudin
2019-03-25 15:11 ` [tarantool-patches] " n.pettik
2019-04-01 20:39 ` Stanislav Zudin
2019-03-15 15:45 ` [PATCH 04/13] sql: support big integers within sql binding Stanislav Zudin
2019-03-25 15:12 ` n.pettik [this message]
2019-04-01 20:42 ` [tarantool-patches] " Stanislav Zudin
2019-04-02 7:46 ` Konstantin Osipov
2019-04-02 7:44 ` [tarantool-patches] " Konstantin Osipov
2019-03-15 15:45 ` [PATCH 05/13] sql: removes redundant function Stanislav Zudin
2019-03-25 15:12 ` [tarantool-patches] " n.pettik
2019-03-15 15:45 ` [PATCH 06/13] sql: aux functions to support big integers Stanislav Zudin
2019-03-25 15:13 ` [tarantool-patches] " n.pettik
2019-03-15 15:45 ` [PATCH 07/13] sql: arithmetic functions " Stanislav Zudin
2019-03-25 15:13 ` [tarantool-patches] " n.pettik
2019-04-01 20:43 ` Stanislav Zudin
2019-04-02 7:54 ` Konstantin Osipov
2019-04-02 7:52 ` Konstantin Osipov
2019-03-15 15:45 ` [PATCH 08/13] sql: aggregate sql functions support big int Stanislav Zudin
2019-03-25 15:13 ` [tarantool-patches] " n.pettik
2019-04-01 20:43 ` Stanislav Zudin
2019-04-02 7:57 ` [tarantool-patches] " Konstantin Osipov
2019-03-15 15:45 ` [PATCH 09/13] sql: fixes errors Stanislav Zudin
2019-03-25 15:14 ` [tarantool-patches] " n.pettik
2019-03-15 15:45 ` [PATCH 10/13] sql: fixes an error in sqlSubInt64 Stanislav Zudin
2019-03-25 15:14 ` [tarantool-patches] " n.pettik
2019-03-15 15:45 ` [PATCH 11/13] sql: fixes an error in string to int64 conversion Stanislav Zudin
2019-03-25 15:14 ` [tarantool-patches] " n.pettik
2019-03-15 15:45 ` [PATCH 12/13] sql: fixes an error in uint64 to double casting Stanislav Zudin
2019-03-25 15:15 ` [tarantool-patches] " n.pettik
2019-03-15 15:45 ` [PATCH 13/13] sql: support -2^63 .. 2^64-1 integer type Stanislav Zudin
2019-03-25 15:25 ` [tarantool-patches] " n.pettik
2019-04-01 20:44 ` Stanislav Zudin
2019-03-25 15:10 ` [tarantool-patches] Re: [PATCH 00/13] " n.pettik
2019-04-01 20:38 ` Stanislav Zudin
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=7B68C4B8-A53B-483E-AD57-8A746682FD73@tarantool.org \
--to=korablev@tarantool.org \
--cc=szudin@tarantool.org \
--cc=tarantool-patches@freelists.org \
--subject='[tarantool-patches] Re: [PATCH 04/13] sql: support big integers within sql binding' \
/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