Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org, imeevma@tarantool.org
Subject: [tarantool-patches] Re: [PATCH v7 3/6] iproto: create port_sql
Date: Wed, 16 Jan 2019 21:25:33 +0300	[thread overview]
Message-ID: <cfd2d0e6-03b3-a7a4-ac0d-e29e045340d6@tarantool.org> (raw)
In-Reply-To: <1a3007030ea54fa81533acbf7421f27a2399c941.1547565887.git.imeevma@gmail.com>

Thanks for the patch! See 2 comments below.

> commit 1a3007030ea54fa81533acbf7421f27a2399c941
> Author: Mergen Imeev <imeevma@gmail.com>
> Date:   Fri Dec 21 14:52:03 2018 +0300
> 
>      iproto: create port_sql
>      
>      This patch creates port_sql implementation for the port. This will
>      allow us to dump sql responses to obuf or to Lua. Also this patch
>      defines methods dump_msgpack() and destroy() of port_sql.
>      
>      Part of #3505
> 
> diff --git a/src/box/execute.c b/src/box/execute.c
> index 38b6cbc..a81f482 100644
> --- a/src/box/execute.c
> +++ b/src/box/execute.c
> @@ -643,7 +672,66 @@ err:
> +/**
> + * Execute prepared SQL statement.
> + *
> + * This function uses region to allocate memory for temporary
> + * objects. After this function, region will be in the same state
> + * in which it was before this function.
> + *
> + * @param db SQL handle.
> + * @param stmt Prepared statement.
> + * @param[out] port Port to store SQL response.

1. It is not [out]. Port should be created before calling this function,
so it is [in][out], that we usually omit.

> + * @param region Region to allocate temporary objects.
> + *
> + * @retval  0 Success.
> + * @retval -1 Error.
> + */
> +static inline int
> +sql_execute(sqlite3 *db, struct sqlite3_stmt *stmt, struct port *port,
> +     struct region *region)
> +{
> + int rc, column_count = sqlite3_column_count(stmt);
> + if (column_count > 0) {
> +   /* Either ROW or DONE or ERROR. */
> +   while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
> +     if (sql_row_to_port(stmt, column_count, region,
> +             port) != 0)
> +       return -1;
> +   }
> +   assert(rc == SQLITE_DONE || rc != SQLITE_OK);
> + } else {
> +   /* No rows. Either DONE or ERROR. */
> +   rc = sqlite3_step(stmt);
> +   assert(rc != SQLITE_ROW && rc != SQLITE_OK);
> + }
> + if (rc != SQLITE_DONE) {
> +   diag_set(ClientError, ER_SQL_EXECUTE, sqlite3_errmsg(db));
> +   return -1;
> + }
> + return 0;
> +}
> diff --git a/src/box/iproto.cc b/src/box/iproto.cc
> index a08c8c5..09e8914 100644
> --- a/src/box/iproto.cc
> +++ b/src/box/iproto.cc
> @@ -1643,9 +1643,11 @@ tx_process_sql(struct cmsg *m)
>    out = msg->connection->tx.p_obuf;
>    struct obuf_svp header_svp;
>    /* Prepare memory for the iproto header. */
> - if (iproto_prepare_header(out, &header_svp, IPROTO_HEADER_LEN) != 0)
> + if (iproto_prepare_header(out, &header_svp, IPROTO_HEADER_LEN) != 0) {
> +   port_destroy(&port);
>      goto error;
> - if (sql_response_dump(&response, out) != 0) {
> + }
> + if (port_dump_msgpack(&port, out) != 0) {

2. port_sql_dump_msgpack destroys port on an error, but port_tuple_dump_msgpack
does not. I think, they should work similar, so port_sql_dump_msgpack does
not destroy the port as well. Lets do it, and add here port_destroy() on an
error. The same about port_dump_lua.

>      obuf_rollback_to_svp(out, &header_svp);
>      goto error;
>    }

  reply	other threads:[~2019-01-16 18:25 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-15 16:10 [tarantool-patches] [PATCH v7 0/6] sql: remove box.sql.execute imeevma
2019-01-15 16:10 ` [tarantool-patches] [PATCH v7 1/6] lua: remove exceptions from function luaL_tofield() imeevma
2019-01-16 18:25   ` [tarantool-patches] " Vladislav Shpilevoy
2019-01-17 11:40     ` Konstantin Osipov
2019-01-17 11:41     ` Konstantin Osipov
2019-01-17 11:38   ` Konstantin Osipov
2019-01-17 13:15     ` Vladislav Shpilevoy
2019-01-15 16:10 ` [tarantool-patches] [PATCH v7 2/6] iproto: move map creation to sql_response_dump() imeevma
2019-01-15 16:10 ` [tarantool-patches] [PATCH v7 3/6] iproto: create port_sql imeevma
2019-01-16 18:25   ` Vladislav Shpilevoy [this message]
2019-01-15 16:10 ` [tarantool-patches] [PATCH v7 4/6] lua: create method dump_lua for port_sql imeevma
2019-01-15 16:10 ` [tarantool-patches] [PATCH v7 5/6] lua: parameter binding for new execute() imeevma
2019-01-15 16:10 ` [tarantool-patches] [PATCH v7 6/6] sql: check new box.sql.execute() imeevma

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=cfd2d0e6-03b3-a7a4-ac0d-e29e045340d6@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=imeevma@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH v7 3/6] iproto: create port_sql' \
    /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