Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: (add option) restore unsaved queries #140

Closed
penCsharpener opened this Issue Feb 16, 2018 · 33 comments

Comments

Projects
None yet
@penCsharpener
Copy link

commented Feb 16, 2018

Current behavior

  • new queries open in a new tab and have a * when unsaved
  • on closing HeidiSQL user is asked whether to save those queries
  • unsaved queries are lost when restarting HeidiSQL next time

Expected behavior

  • Option for the user to restore unsaved queries next time
  • Notepad++ has it by default, that unsaved tabs are automatically saved and restored
  • also browser have option to restore tabs on next restart
  • if HeidiSQL crashes it won't lose those user queries

Possible solution

  • HeidiSQL could automatically save it's query tabs in %appdata%\HeidiSQL\unsaved Queries
  • if this in enabled HeidiSQL won't ask anymore to save them.

Environment

  • HeidiSQL version:
    9.5.0.5248
  • Operating system:
    Windows 10 1709

Comment

I use those queries for debugging. They are not relevant enough to save them for ever but I'd like them to be there for 1-2 weeks until they aren't relevant anymore.

@penCsharpener

This comment has been minimized.

Copy link
Author

commented Feb 16, 2018

additionally it would be nice to be useful to hit F2 on a query tab to rename it in place (without save file dialog) because Query 1, Query 2, Query 3, Query 4 is hard to tell apart.

I also often have multiple Windows open of HeidiSQL. In that case it could check whether ie. Query 1.sql already exists in the %appdata% folder and iterate the number up until there is no file collision.
When all HeidiSQL Windows are close and a new instance is started, all those unsaved queries would open again in one instance. This could get messy but I guess there is no way around that. That's the time to tidy up.

Thanks for the best SQL-Browser on Windows!

@jcguevara

This comment has been minimized.

Copy link

commented Feb 21, 2018

I think the problem with multiple instances could be partially solved if the unsaved tabs are saved in subfolders by connection name like:
%appdata%HeidiSQL\unsaved Queries\[CONNECTION_NAME]\query_*.sql in my case I'm used to have several instances opened but connected to a different DBs.

@carlosfrutos

This comment has been minimized.

Copy link

commented Apr 10, 2018

Please, remember this enhancement was requested for the first time in 2012:

https://sourceforge.net/p/heidisql/tickets/2991/

A couple of issue-tracker migrations since then...

Thank you for your efforts, guys. I really like HeidiSQL, but I'm scared of using it sometimes because it does not backup your work.

Kind regards

@okneloper

This comment has been minimized.

Copy link

commented Aug 17, 2018

I vote for this as well. Pretty simple (seemingly) change, but a major enhancement to the user experience!

@sloboy

This comment has been minimized.

Copy link

commented Aug 25, 2018

MySql workbench even reopens tabs that were saved but visible when the program is closed and reopened, not just unsaved queries. This is helpful when you are working on a project that needs input from several queries to figure out, but spans multiple days because of phb interruptions :)

@kiltannen

This comment has been minimized.

Copy link

commented Oct 30, 2018

I also would like to see this.

I use Heidi for any MySQL queries I do, and this would be a very nice enhancement.

@ansgarbecker ansgarbecker added this to the v10.1 milestone Jan 3, 2019

@johnnyPescarul

This comment has been minimized.

Copy link

commented Jan 10, 2019

This is a critical feature. I love Heidi and appreciate all great effort, but I would prioritize this over other enhancements.

@Miktarbad

This comment has been minimized.

Copy link

commented Jan 24, 2019

This feature would greatly increase my workflow, since i do not have the time to save every query - but might need them later.

@phiter

This comment has been minimized.

Copy link

commented Feb 2, 2019

Been looking for this as well. My co-worker told me he loves Heidi but this is a feature that is missing and would help him a lot. Hope it gets implemented soon.

@styler2go

This comment has been minimized.

Copy link

commented Feb 15, 2019

I am also looking forward for this feature. Will improve my experience a lot.

@mfaustusi

This comment has been minimized.

Copy link

commented Feb 26, 2019

This would also save those who get frequent crashing of HeidiSQL and lose large queries that they were working on. Often when a crash occurs an exception dialog will popup and sometimes clicking on "continue" will actually close the program, or "continue" won't be available. In either case, trying to copy the query out of the tab before closing the exception box is not possible and unsaved queries are lost. Notepad++ also has this feature and it's saved me countless times.

@penCsharpener

This comment has been minimized.

Copy link
Author

commented Feb 27, 2019

Hi @ansgarbecker, since quite a few people would find this useful can you give us an idea whether you have already been working on this or when we can expect this in a nightly version? Of course you have a bunch of other things in your 10.2 milestone. This is not to rush anything, just informational.

@ansgarbecker

This comment has been minimized.

Copy link
Collaborator

commented Feb 28, 2019

This is one of the most and longest wish from many users, so it will be one of the next feature I am going to implement.

@phiter

This comment has been minimized.

Copy link

commented Feb 28, 2019

Fantastic news, thanks @ansgarbecker !

@ansgarbecker

This comment has been minimized.

Copy link
Collaborator

commented Mar 10, 2019

Notepad++ has this restore-feature, and its preference dialog looks like this:
grafik
While HeidiSQL only has this option:
grafik

So, the approach in Notepad++ is missing the option to ignore unsaved text in a tab without even auto-saving it.

In order not to break this old feature of HeidiSQL, I should add a new "Files" tab to the preferences dialog, containing that old "Prompt to save" checkbox. Additionally, we will have a new checkbox like in Notepad++, labelled "Automatically backup unsaved files". This option applies to tabs left open when exiting HeidiSQL, not to closed tabs, in contrast to the Prompt option.

And finally I think there is no need to even customize the interval for saving these backups, like in Notepad++. Instead, Heidi should save these temporary files every 10 seconds, and only if content was changed.

By the way, is it a good idea to leave out files bigger than let's say 10MB? I'm quite sure such bigger files are normally automatically generated. And it may introduce a performance issue if HeidiSQL e.g. has to save a 5GB file every 10 seconds.

@penCsharpener

This comment has been minimized.

Copy link
Author

commented Mar 10, 2019

10MB sound way too much I find. If I export data as SQL and paste it in a tab, then I don't want that saved.
10kb or 100kb would already be very big queries.
What about putting the file size as another option if you already create a new settings tab? My limit would likely be around 10kb.

@phiter

This comment has been minimized.

Copy link

commented Mar 11, 2019

Yeah I think 10MB is huge for a file. If you want to go full customization, this can be a configurable field where you set max size in kb.

@mfaustusi

This comment has been minimized.

Copy link

commented Mar 11, 2019

To ensure this feature is done right there should be some forethought about being able to recover from a corrupt cache that prevents HeidiSQL from loading properly, such as a command line option to skip loading background-saved queries, or on launch after a crash give the option to skip loading background saved queries that may be preventing it from starting up.

Also, in regards to file size I would assume it would be fairly trivial to compress the queries before saving to disk since SQL text is highly compressible. Very large queries likely have a lot of repeating text and could be reduced in size drastically with most compression algorithms.

@pipanni

This comment has been minimized.

Copy link

commented Mar 12, 2019

I would like this feature very much. I would also like some sushi.

@dig314

This comment has been minimized.

Copy link

commented Mar 12, 2019

I would appreciate this feature.

ansgarbecker added a commit that referenced this issue Mar 17, 2019

Issue #140: add "Files" tab to preferences dialog, move "Prompt for f…
…ile save" checkbox there, and introduce two new checkboxes for restoring opened and unsaved query tab contents (both new yet without functionality in their back)

ansgarbecker added a commit that referenced this issue Apr 7, 2019

Issue #140: Auto-backup unsaved query tab contents to C:\Users\<usern…
…ame>\AppData\Roaming\HeidiSQL\Backups\*.sql, and tab setup in C:\Users\<username>\AppData\Roaming\HeidiSQL\tabs.ini
@ansgarbecker

This comment has been minimized.

Copy link
Collaborator

commented Apr 7, 2019

I think I have most parts of this new feature ready to use. Some translation strings are missing yet, and probably not done enough testing yet. For all who want to test the new auto-restore feature:

  • update to the new nightly build
  • watch out for unsaved query tabs, either after loading a file from harddisk or without a file in the back
  • if you want to know more exactly what's going on:
    • activate Preferences > Logging > "Debug" messages
    • watch the auto-created directory C:\Users\<yourUsername>\AppData\Roaming\HeidiSQL\Backups\
    • watch the new setup file C:\Users\<yourUsername>\AppData\Roaming\HeidiSQL\tabs.ini

The auto-restore feature is activated by default, and can be disabled in Preferences > Files > "Reopen previously used SQL files..."

ansgarbecker added a commit that referenced this issue Apr 8, 2019

Issue #140:
* fix: very last tab backup was not yet done
* tell user about activated auto-restore feature in very last question dialog for saving tab
* add missing translation strings
@ansgarbecker

This comment has been minimized.

Copy link
Collaborator

commented Apr 8, 2019

I think the current implementation is not yet safe against running multiple instances... Please be aware of that if you already use this feature.

@penCsharpener

This comment has been minimized.

Copy link
Author

commented Apr 8, 2019

nothing important should remain unsaved anyway. It can't be worse than before the feature implementation when all the unsaved queries were gone by default.

@okneloper

This comment has been minimized.

Copy link

commented Apr 8, 2019

Not really. Previously it was warning about unsaved queries, and wouldn't close until you save or discard them.
If atm it's closing without prompt and overwriting other queries, that's unsafe indeed. Thanks for flagging @ansgarbecker

ansgarbecker added a commit that referenced this issue Apr 10, 2019

Issue #140: make auto-backup/restore feature stable against running m…
…ultiple application instances:

* use unique date/time with milliseconds as ini sections
* open ini file for each read + write, separately, don't keep it open all the time

ansgarbecker added a commit that referenced this issue Apr 10, 2019

ansgarbecker added a commit that referenced this issue Apr 10, 2019

ansgarbecker added a commit that referenced this issue Apr 10, 2019

@pantantrollo

This comment has been minimized.

Copy link

commented Apr 10, 2019

  • watch the auto-created directory C:\Users\<yourUsername>\AppData\Roaming\HeidiSQL\Backups\
  • watch the new setup file C:\Users\<yourUsername>\AppData\Roaming\HeidiSQL\tabs.ini

Will it also be implemented for the portable version?

@ansgarbecker

This comment has been minimized.

Copy link
Collaborator

commented Apr 11, 2019

The portable is the same executable as the normal version, it just gets flagged via the portable.lock file. But I suppose your question was meant for the directories, which are not "quite portable". Well I did not see the need for it yet, but it may make sense. In the portable version, the tabs.ini could live in the directory with heidisql.exe, and the "Backups" directory could be auto-created as a subfolder of it. Does that make sense?

@pantantrollo

This comment has been minimized.

Copy link

commented Apr 11, 2019

Right, something like that.

The "tabs.ini" that was in the same place as the executable heidiSql.exe (as is its configuration), for any of the versions, portable and installable.

The directory "backups" or that its location could be configured (either via config gui or editing the config file) or failing that, for example if it detects the "portable.lock" or 2portable_settings.txt" file, then create the directirios "backups" in that same place, otherwise, in %appdata%\heidisql (for example)

Thx

ansgarbecker added a commit that referenced this issue Apr 11, 2019

Issue #140: Move code for all remaining common directory paths settin…
…gs to TAppSettings (UserAppData, UserDocuments, Snippets)
@ansgarbecker

This comment has been minimized.

Copy link
Collaborator

commented Apr 12, 2019

done:
[x] prevent file locks when multiple instances access tabs.ini
[x] store tabs.ini and backups folder locally in portable mode

There is still the chance one instance overwrites a backup file from another running instance. So I thought I could add something like this:

  • store current process id to each section in tabs.ini
  • when restoring tabs, check if the process id is running
    • if it's still running: don't restore that tab
    • if it's not running: replace it with the current process id and restore tab

Read: the first instance restores tabs from the previous one. Second and later instances do not restore tabs, but can add new tabs. This way, no tab content gets lost. If you exit 3 instances with let's say 2 tabs, then the next started instance should restore 6 tabs. Or, if 1 of the 3 instances is still running, then 4 tabs get restored.

@3vcloud

This comment has been minimized.

Copy link

commented Apr 12, 2019

This only seems to restore the first tab for me atm

Edit: Looks like the tab restore function needs to be offset by 1 when restoring? I exit with 4 query tabs open (unsaved), then restart HeidiSQL, and I get 3 query tabs back

... and then after trying it again after typing this, it consistently auto-restores. Not going to delete this comment myself just incase this needs looking into

@ansgarbecker

This comment has been minimized.

Copy link
Collaborator

commented Apr 13, 2019

I just tested with a blank setup and the latest build. I can reproduce that if I am very quickly closing HeidSQL, before the 10 seconds timer for storing the tab setup has reached its first end. So I think the call of MainForm.StoreTabs when closing HeidiSQL is not fired for some reason.

=> fixed

ansgarbecker added a commit that referenced this issue Apr 13, 2019

Issue #140:
* store tab setup when application exits, as the TimerStoreTabs interval may not yet be reached
* remember startup value of asRestoreTabs option, which may change while the application runs, which in turn may cause problems when RestoreTabs wasn't called

ansgarbecker added a commit that referenced this issue Apr 13, 2019

Issue #140: Store application process id in each tabs.ini section, an…
…d don't restore tabs from other running processes. If the process no longer runs, restore such tab sections again, so nothing gets lost with multiple running application instances.
@ansgarbecker

This comment has been minimized.

Copy link
Collaborator

commented Apr 13, 2019

Next nightly build should work stable with multiple HeidiSQL instances, each of them managing its own tab setup, writing to the same tabs.ini file. Tabs get restored if no other running instance is using them.

Any more issues here? Please report if you find one.

@okneloper

This comment has been minimized.

Copy link

commented Apr 13, 2019

What an awesome improvement to my day-to-day work! Thanks for taking the time to implement this!

@ansgarbecker

This comment has been minimized.

Copy link
Collaborator

commented Apr 16, 2019

I am closing this issue now, as there are no complaints for some days, and I can also find nothing to change. Please shout if you find more issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.