Skip to content

'Execute current line' in 3.11.0-beta1 #1632

Closed

Description

@maklyn

I tried searching for similar issues but everything I could find was marked 'Closed' and considered fixed in previous versions. Sorry if I have missed something

Seeing some weird behaviour with the 'Execute current line' and 'Shift-F5' commands that I'm hoping you can help me figure out.

In 3.10.1 if I had multiple statements on separate lines with semi-colons I could put the cursor on query 1 and 'Execute current line' to only run that statement.
In 3.11.0-beta1 I'm getting two different behaviours depending on the structure of query 1

  • Query 1 is only a single line with semi-colon (example: select * from table;) executes that query but then proceeds to execute next statement as well
  • Query 1 is split into multiple lines results in an error unless cursor is on first line of statement. Considering that I'm likely to be on the last line of the query (as that is what I have just typed) when I'm executing the line it seems weird that I have to move the cursor back to the first line before executing. Previous versions were able to find the start of the query properly.

Am I missing something?
Appreciate any help

2018-11-28 09_27_23-window

2018-11-28 09_26_56-window

Activity

  1. justinclift commented on Nov 28, 2018

    @justinclift
    Member

    Oops, that does sound like a bug. We've been adjusting the query parser in the Execute SQL tab, trying to improve it. Guess it still needs more work!

    @mgrojo This sounds like your kind of thing?

  2. added
    bugConfirmed bugs or reports that are very likely to be bugs.
    on Nov 28, 2018
  3. chrisjlocke commented on Nov 28, 2018

    @chrisjlocke
    Member

    Just tested this, and its rather weird. So I entered this into a 'Execute SQL' tab.

    select * 
    from 
    symptomsAssigned;
    
    select *
    from 
    symptoms;
    
    select * 
    from 
    symptomsAssigned;
    
    select *
    from 
    symptoms;
    

    If the cursor is placed on line 1, 'Execute current line' works. If the cursor is placed on line 2 or line 3, an error occurs.

    image

    image

    This error does not occur on any other line. All works fine.
    If lines 1-3 are removed, then the error now occurs on the NEW line 3 and 4

    image

    with all following lines working fine. So its the first query it has issues with.

    @maklyn - it errors for you on line 2. If you duplicated that query after line 5, and try running it on line 6/7 and see if it works for you? Just to confirm....
    ie, so you'd have this:

    select count(*) from catalogEntry where partnumber in
    (select partNumber from salesCatalogEntry);
    
    select partNumber from salesCatalogEntry where partNumber in
    (select partNumber from catalogEntryAttributeDictionaryAttributeRelationship);
    
    select count(*) from catalogEntry where partnumber in
    (select partNumber from salesCatalogEntry);
    

    Ignoring the first query, 'execute current line' should work on the third query (lines 7 and 8)

  4. chrisjlocke commented on Nov 28, 2018

    @chrisjlocke
    Member

    Setting line 1 to be just ; (ie, an empty query) seems to resolve this issue - all queries now work... :confusedFace: ....

    image

  5. chrisjlocke commented on Nov 28, 2018

    @chrisjlocke
    Member

    Spoke too soon. No it doesn't. Using the above 'hack', if the cursor is on line 4, then query 2 is executed, not query 1. This is still the case if a blank line is inserted between lines 1 and 2.

  6. maklyn commented on Nov 28, 2018

    @maklyn
    Author

    @chrisjlocke
    Duplicated the query as you mentioned and I can run the query from lines 7 and 8.
    It does look like it is only the first query that cannot be split into multiple lines. Doesn't seem to matter how many lines the first query spans

    But if the cursor is on the last line of a query it will execute both the current query and the following.
    Example:

    1 select * from table1;
    2 select *
    3 from table2;
    4 select * from table3;
    

    Cursor on line 1 executes query 1 and then query 2
    Cursor on line 2 executes only query 2
    Cursor on line 3 executes query 2 and then query 3

    Working with large databases that take some time to process you actually get the result of the first query then it updates to show results of the next

  7. justinclift commented on Nov 28, 2018

    @justinclift
    Member

    Heh Heh Heh. It's probably some weird side effect from our new-fangled multi-threaded query handling code then. Oops.

  8. MKleusberg commented on Nov 28, 2018

    @MKleusberg
    Member

    I somehow didn't manage to reproduce your first issue (executing all statements), @maklyn. Is there anything I need to keep in mind in order to trigger it?

    As for the other issues, I hope I can add a bit of clarity by explaining how the Execute Current Line button proceeds. In a first step we're assuming the statement to execute starts at the beginning of the currently selected line. However, in a second step we check if there is any semicolon before that position. If so, we move the start position to just after this semicolon. That's why this works:

    SELECT *
    FROM test1;
    
    SELECT *
    FROM test2; -- Cursor on this line

    However, if we don't find a semicolon, we don't adjust the start position. That's why this doesn't work:

    SELECT *
    FROM test1; -- Cursor on this line
    
    SELECT *
    FROM test2;

    As far as I know we do that for a single reason: Some users don't use semicolons, and by accidentally clicking the Execute Current Line button they would execute the first statement. Not sure if that's a good reason, so we might want to change that.

    However, that behaviour is highly problematic in general because the code to find the last semicolon doesn't work very well. It doesn't take quotes or comments into account and so leads to even more confusing results in these cases. So we might want to drop the adjusting code entirely. That doesn't solve your exact issue, but at least makes this far more consistent and easier to understand.

    When executing a single line, we set the end position to the end of the current line. So if a line contains multiple statements, all of them are executed:

    SELECT 1;SELECT 2;  -- Cursor here. Two statements executed.
    
    SELECT 3;

    If the last statement of that line consists of multiple lines, it is fully executed anyway. This time we can use SQLite to determine the end of the statement. So no problems with quotes or comments here.

    SELECT 1;SELECT -- Cursor here. Does same as above.
    2;
    
    SELECT 3;

    @justinclift The multi-threading shouldn't really affect this. The code to determine the start and the end position of the statements to execute didn't change in there. Also, we didn't merge it yet 😉

  9. maklyn commented on Nov 30, 2018

    @maklyn
    Author

    @MKleusberg
    OK, that does explain why the first query can't be split into multiple lines. Has this been changed recently for 3.11? Don't seem to get this limitation when using 3.10

    Can't figure out if I'm doing anything special to execute multiple statements. I've tried it again with the sample 'chinook.db' at http://www.sqlitetutorial.net/sqlite-sample-database/

    select * from artists; select * from       <-- cursor here returns artists + albums
    albums;                                    <-- cursor here returns artists + albums + customers
    
    select * from customers;                   <-- cursor here returns customers
    

    Using Win 10 Pro, not sure if that should affect anything though

  10. T1mL3arn commented on Nov 19, 2019

    @T1mL3arn

    Found the same bug, wanted to make an issue, and it is already here. Thanks @MKleusberg for clarification how the Execute current line works.

    What if meaning of execute current line will be changed to execute current query ?

  11. self-assigned this
    on Jan 4, 2020
  12. mgrojo commented on Jan 4, 2020

    @mgrojo
    Member

    @MKleusberg
    OK, that does explain why the first query can't be split into multiple lines. Has this been changed recently for 3.11? Don't seem to get this limitation when using 3.10

    Can't figure out if I'm doing anything special to execute multiple statements. I've tried it again with the sample 'chinook.db' at http://www.sqlitetutorial.net/sqlite-sample-database/

    select * from artists; select * from       <-- cursor here returns artists + albums
    albums;                                    <-- cursor here returns artists + albums + customers
    
    select * from customers;                   <-- cursor here returns customers
    

    Using Win 10 Pro, not sure if that should affect anything though

    Apart from the points to take into account when using the "Execute Current Line" function, as @MKleusberg pointed out, this particular case was indeed a bug in 3.11, and one that we weren't aware of (in spite of more than one report, sorry) because in Linux or MacOS is not reproduced.

    Could you confirm that it is working as expected in the tomorrow's nightly build?

  13. mgrojo commented on Jun 21, 2020

    @mgrojo
    Member

    @maklyn We have just released version 3.12.0 which includes the fix for this issue, so I'll close it now. If you think there is still some problem, you are free to reopen it or open a new one.

  14. added this to the 3.12.0 - Next release milestone on Jun 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugConfirmed bugs or reports that are very likely to be bugs.

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions