From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 6372625E9F for ; Mon, 2 Jul 2018 09:36:39 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IxXoTSSto1R6 for ; Mon, 2 Jul 2018 09:36:39 -0400 (EDT) Received: from smtp17.mail.ru (smtp17.mail.ru [94.100.176.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id A97FF25672 for ; Mon, 2 Jul 2018 09:36:38 -0400 (EDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: [tarantool-patches] Re: [PATCH v1 1/1] sql: show formated MsgPack BLOB on select From: "n.pettik" In-Reply-To: <3778fd7451fde6e28b3b4c9fcf88fb310a8b50b6.1530534766.git.kshcherbatov@tarantool.org> Date: Mon, 2 Jul 2018 16:36:36 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: <625D5EC7-6D4C-4D9A-9115-DB88773D5979@tarantool.org> References: <3778fd7451fde6e28b3b4c9fcf88fb310a8b50b6.1530534766.git.kshcherbatov@tarantool.org> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: Kirill Shcherbatov > diff --git a/src/box/lua/sql.c b/src/box/lua/sql.c > index e693aea..7a49aac 100644 > --- a/src/box/lua/sql.c > +++ b/src/box/lua/sql.c > @@ -1,5 +1,6 @@ > #include "sql.h" > #include "box/sql.h" > +#include "lua/msgpack.h" >=20 > #include "box/sql/sqliteInt.h" > #include "box/info.h" > @@ -44,8 +45,13 @@ lua_push_row(struct lua_State *L, struct = sqlite3_stmt *stmt) > } > case SQLITE_BLOB: { > const void *blob =3D sqlite3_column_blob(stmt, = i); > - lua_pushlstring(L, blob, > + if (sqlite3_column_subtype(stmt,i) =3D=3D = MSGPACK_SUBTYPE) { > + luamp_decode(L, luaL_msgpack_default, > + (const char **)&blob); > + } else { > + lua_pushlstring(L, blob, > sqlite3_column_bytes(stmt, i)); > + } > break; > } > case SQLITE_NULL: > diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h > index e939663..3854482 100644 > --- a/src/box/sql/sqliteInt.h > +++ b/src/box/sql/sqliteInt.h > @@ -482,6 +482,15 @@ sqlite3_value_double(sqlite3_value *); > int > sqlite3_value_int(sqlite3_value *); >=20 > +/** > + * Get row column subtype. > + * @param stmt row data to process. > + * @param i column index. > + * @retval sqlute3 subtype if any, 0 else. > + */ > +unsigned int > +sqlite3_column_subtype(sqlite3_stmt *stmt, int i); Lets move from sqlite3_ prefixes and use simple sql_ (If you decide to keep this func). > + > sqlite3_int64 > sqlite3_value_int64(sqlite3_value *); >=20 > @@ -672,6 +681,9 @@ enum sql_type { > SQLITE_NULL =3D 5, > }; >=20 > +/** The "subtype" set for MsgPack values.*/ > +#define MSGPACK_SUBTYPE 77 > + > /** > * Structure for internal usage during INSERT/UPDATE > * statements compilation. > diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h > index 0115a0d..1b767a5 100644 > --- a/src/box/sql/vdbeInt.h > +++ b/src/box/sql/vdbeInt.h > @@ -253,8 +253,7 @@ struct Mem { > #define MEM_Zero 0x0000 > #endif >=20 > -/* The "subtype" set for MsgPack values */ > -#define MSGPACK_SUBTYPE 77 /* Ascii for "M" */ > + Redundant empty line. >=20 > /* Return TRUE if Mem X contains dynamically allocated content - = anything > * that needs to be deallocated to avoid a leak. > diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c > index d35338a..d1ae976 100644 > --- a/src/box/sql/vdbeapi.c > +++ b/src/box/sql/vdbeapi.c > @@ -1047,6 +1047,14 @@ sqlite3_column_type(sqlite3_stmt * pStmt, int = i) > return iType; > } >=20 > +unsigned int > +sqlite3_column_subtype(sqlite3_stmt * pStmt, int i) > +{ > + unsigned int type =3D sqlite3_value_subtype(columnMem(pStmt, = i)); > + columnMallocFailure(pStmt); > + return type; > +} Do we really need that call of columnMallocFailure()? It seems to be = useless: firstly, it comes in pair with sqlite3_column_blob() call; secondly, it = is likely to be one of SQLite artefacts. Anyway, you can just inline this function. If = you want to keep it, fix code style (remove extra space :sqlite3_stmt * pStmt, = add struct prefix etc).=20