Menu

#355 Add script support to DatabaseManager[Swing]

open
nobody
None
5
2020-04-13
2020-04-11
No

It seems that DatabaseManager and DatabaseManagerSwing currently have no way to execute more than one line of SQL at a time, which is tedious to impractical for anything beyond a handful of SQL statements. Being able to run an entire script (à la sqltool) directly from DatabaseManager[Swing] would be extremely beneficial here.

It would allow me to quickly create an in-memory database with a handful of tables from a predefined script, run some tests on it in interactive mode and not have to worry about cleaning up when I’m done.

Discussion

  • Fred Toussi

    Fred Toussi - 2020-04-11

    This would be a useful feature. Currently, you can execute a block of statements together but these statements shouldn't reference objects created in the same block.

    The simple implementation is to try to execute the whole block and catch any error thrown, then divide the block and try again, until all the statements are executed. Otherwise, a parser is needed and things become complex.

    So if you have some time, you can give it a try and I could help when necessary to implement this.

     
  • Michael von Glasow

    Nice way of saying “patches welcome” :-> I’ll see what I can do, I have never touched the HSQLDB source code so far.

    Since sqltool should already have most of the backend code we need, my idea would be to borrow most of that code. Then we would just need to hook it up to the user interface in some way. Unless there is some major obstacle to this that I am unaware of…

     
  • Fred Toussi

    Fred Toussi - 2020-04-12

    Thanks. I prefer patches to be coordinated in order to reduce the total effort.
    Using SqlTool shouldn't be difficult and can be done without duplicating any code.
    The script in the code window can be submitted to SqlTool and the result returned in the result window. This could keep things simple. It needs passing the connection URL, username and password to SqlTool. Also needs a menu item as a flag to use SqlTool instead of submitting directly to the database.

     
  • Michael von Glasow

    What if it’s an in-memory database? Wouldn’t that cause SqlTool to open a separate in-memory db if we just pass the connection URL (rather than calling one of SqlTool’s classes and passing the connection instance)?

     
  • Thomas Nijssen

    Thomas Nijssen - 2020-04-12

    Something that SQLite does that may be useful: the parser stops parsing once it reaches the end of a statement (in sqlite3_prepare_v3) and returns the unused part of the statement. Maybe the existing parser can be used for this somehow?

     
  • Fred Toussi

    Fred Toussi - 2020-04-12

    SqlTool is accessed in the same JVM, so connections to an in-memory database URL point to the same database. SqlTool methods are called to connect and execute the SQL.

     
  • Fred Toussi

    Fred Toussi - 2020-04-13

    @Thomas, Re stopping parsing at the end of a statement: This is already done in a way, as multi statements are all parsed and stored in a list before execution. We can implement a variable that shows how many characters were parsed successfully into statements before error occured.

     

Log in to post a comment.