cosminadrianpopescu / vim-sql-workbench

SQL For Vim (provides access from VIM to any DBMS, like dbext)
GNU General Public License v3.0
185 stars 13 forks source link

Can't connect to new profiles without restarting VIM #37

Open borisbrodski opened 6 years ago

borisbrodski commented 6 years ago

Reproduction:

  1. Open VIM
  2. Connect to an existing profile
  3. Open SQL Workbench and
    • create new profile
    • save changes
  4. Back in VIM issue "CtrlPClearSWCache"
  5. Open CtrlP with "CtrlPSW"
  6. Select new profile

Result buffer:

=SQL 1
A profile name or connection information is required.
Parameters for WbConnect are:
-profile        The name of the connection profile to connect to 
or
-username              The DB user for the connection
-password              The password for the DB user
-url                   The JDBC URL to connect to
-driver                The driver class to use
-driverJar             The classpath for the driver
-autocommit            Control the autocommit setting
-rollbackOnDisconnect  Issue a rollback before the connection is closed
-emptyStringIsNull     Treat empty strings as null
-trimCharData          Trim values from CHAR columns
Execution time: 0s

In .cache/sql-workbench/tmp/GVIM-__6__:

MYPROFILE> wbconnect -profile="MYNEWPROFILE";wbschemareport types="TABLE,VIEW,MATERIALIZED VIEW,SYNONYM" -file=C:\Users\xxx/.cache/sql-workbench/tmp/GVIM-33 -objects=% -stylesheet=C:\Users\xxx\vimfiles\bundle\vim-sql-workbench\autoload/../resources/wbreport2vim.xslt -xsltOutput=C:\Users\xxx/.cache/sql-workbench/MYNEWPROFILE.vim;exitwbconnect -profile="MYNEWPROFILE";
A profile name or connection information is required.
Parameters for WbConnect are:
-profile        The name of the connection profile to connect to 
or
-username              The DB user for the connection
...

After restarting VIM everything works as expected.

cosminadrianpopescu commented 6 years ago

This is normal. When you connected the first time, an instance of sqlwbconsole.sh was launched and associated with the current buffer.

After you tried to reconnect using the CtrlP plugin, this will check if you already have a connection and not spawn another one. It will use the same and just do WbConnect. So it's normal not to see the new profiles.

If you want to avoid restarting VIM, you need to also do (before CtrlP) SWSqlBufferDisconnect in the current sql buffer. This will terminate the current sqlwbconsole.sh instance and then when you do CtrlP again, it will spawn a new sqlwbconsole.sh process which will see the new profiles.

borisbrodski commented 6 years ago

Thank you for the hint. But may be you could also issue SWSqlBufferDisconnect automatically, if a new connection is requested out of the already connected buffer...

cosminadrianpopescu commented 6 years ago

This is not a good idea. When you do CtrlP is normal and ok to re-use the existing instance. It is much more expensive to re-start the whole instance.

Is the same principle as with the GUI. You won't be re-starting the GUI every time when you need to change the connection.

This being said, I can implement an option for whoever wishes to spawn a new instance of sqlwbconsole.sh from CtrlP which by default will be set to false.