Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH v1 1/1] lua: make semicolon as default SQL terminator
@ 2018-06-19 15:26 Kirill Shcherbatov
  2018-06-22 15:04 ` [tarantool-patches] " Vladislav Shpilevoy
  0 siblings, 1 reply; 2+ messages in thread
From: Kirill Shcherbatov @ 2018-06-19 15:26 UTC (permalink / raw)
  To: tarantool-patches; +Cc: v.shpilevoy, Kirill Shcherbatov

Branch: http://github.com/tarantool/tarantool/tree/kshch/gh-2125-semi-terminator
Issue: https://github.com/tarantool/tarantool/issues/2125

Now semicolon sets as a default terminator on entering
"set language sql".

Resolves #2125.
---
 src/box/lua/console.lua | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/box/lua/console.lua b/src/box/lua/console.lua
index e7cb50a..31e220f 100644
--- a/src/box/lua/console.lua
+++ b/src/box/lua/console.lua
@@ -67,6 +67,7 @@ local function set_language(storage, value)
         local msg = 'Invalid language "%s", supported languages: lua and sql.'
         return error(msg:format(value))
     end
+    set_delimiter(storage, value == 'sql' and ';' or nil)
     storage.language = value
     return true
 end
@@ -316,7 +317,11 @@ local function local_read(self)
                 break
             end
         elseif #buf >= #delim and buf:sub(#buf - #delim + 1) == delim then
-            buf = buf:sub(0, #buf - #delim)
+            local sub_len = #buf - #delim
+            if box.session.language == 'sql' and delim == ';' then
+                sub_len = sub_len + 1
+            end
+            buf = buf:sub(0, sub_len)
             break
         end
         buf = buf.."\n"
@@ -354,8 +359,12 @@ local function client_read(self)
         -- Escape sequence to close current connection (like SSH)
         return nil
     end
-    -- remove trailing delimiter
-    return buf:sub(1, -#delim-1)
+    -- remove trailing delimiter if it is not SQL ;
+    if box.session.language == 'sql' and delim == ';' then
+        return buf
+    else
+        return buf:sub(1, -#delim-1)
+    end
 end
 
 --
-- 
2.7.4

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [tarantool-patches] Re: [PATCH v1 1/1] lua: make semicolon as default SQL terminator
  2018-06-19 15:26 [tarantool-patches] [PATCH v1 1/1] lua: make semicolon as default SQL terminator Kirill Shcherbatov
@ 2018-06-22 15:04 ` Vladislav Shpilevoy
  0 siblings, 0 replies; 2+ messages in thread
From: Vladislav Shpilevoy @ 2018-06-22 15:04 UTC (permalink / raw)
  To: Kirill Shcherbatov, tarantool-patches

Hello. Thanks for the patch! See 6 comments below.

On 19/06/2018 18:26, Kirill Shcherbatov wrote:
> Branch: http://github.com/tarantool/tarantool/tree/kshch/gh-2125-semi-terminator
> Issue: https://github.com/tarantool/tarantool/issues/2125
> 
> Now semicolon sets as a default terminator on entering
> "set language sql".
> 
> Resolves #2125.
> ---
>   src/box/lua/console.lua | 15 ++++++++++++---
>   1 file changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/src/box/lua/console.lua b/src/box/lua/console.lua
> index e7cb50a..31e220f 100644
> --- a/src/box/lua/console.lua
> +++ b/src/box/lua/console.lua
> @@ -67,6 +67,7 @@ local function set_language(storage, value)
>           local msg = 'Invalid language "%s", supported languages: lua and sql.'
>           return error(msg:format(value))
>       end
> +    set_delimiter(storage, value == 'sql' and ';' or nil)

1. Why do you set delimiter to '' (nil), when a language is not sql?
set_delimiter(storage, nil) is not a no op call.

2. I have done this:

\set delimiter ;
\set language sql
\set language lua

And now the ';' has been lost, but I had set it.

>       storage.language = value
>       return true
>   end
> @@ -316,7 +317,11 @@ local function local_read(self)
>                   break
>               end
>           elseif #buf >= #delim and buf:sub(#buf - #delim + 1) == delim then
> -            buf = buf:sub(0, #buf - #delim)
> +            local sub_len = #buf - #delim

3. If you want to save sub_len, then please, do it for the line above as well.

elseif #buf >= #delim then
     local sub_len = ...
     if  buf:sub(sub_len + 1) == delim then
         ...

> +            if box.session.language == 'sql' and delim == ';' then

4. I have this:
tarantool> \set language sql
---
- true
...

tarantool> \set delimiter #
---
...

tarantool> select 100#
---
- - [100]
...

tarantool> select 100

Here I used history, and '#' was cut.

> +                sub_len = sub_len + 1
> +            end
> +            buf = buf:sub(0, sub_len)
>               break
>           end
>           buf = buf.."\n"
> @@ -354,8 +359,12 @@ local function client_read(self)
>           -- Escape sequence to close current connection (like SSH)
>           return nil
>       end
> -    -- remove trailing delimiter
> -    return buf:sub(1, -#delim-1)
> +    -- remove trailing delimiter if it is not SQL ;
> +    if box.session.language == 'sql' and delim == ';' then

5. Same.

> +        return buf> +    else
> +        return buf:sub(1, -#delim-1)
> +    end
>   end
>   
>   --
> 

6. I have tried to do

     select 'a;
     bc';

and expected the result would be
---
- - ['a

       bc']
...

but got this:

tarantool> select 'a;
---
- error: 'unrecognized token: "''a"'
...


Please, check that it works/does not work other DBMSes.
(It is not the same as ';' in CREATE TRIGGER. Here ';' is a part
of string).

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-06-22 15:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-19 15:26 [tarantool-patches] [PATCH v1 1/1] lua: make semicolon as default SQL terminator Kirill Shcherbatov
2018-06-22 15:04 ` [tarantool-patches] " Vladislav Shpilevoy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox