hankinsoft / SQLPro

SQLPro bug & features tracking.
100 stars 26 forks source link

Feature request: Add a generic data export screen in addition to the current "Copy selected as" options #984

Closed GaryMeyers1 closed 1 month ago

GaryMeyers1 commented 1 month ago

I had a situation where I wanted to delete many records from a table. When I wrote the query that would detect the records to delete, I ran it and selected the desired columns vertically in the query result grid. The current right click menu has various ways to copy those values to the clipboard (Copy selected as insert, Copy selected as update, etc.). However, I wanted to create delete commands but that option is not supported. I ended up using the "Copy selected as insert -> Batch" command and then edited the text into delete commands.

Original export:

INSERT INTO Table1 (ID, Data1, Data2) VALUES (399, 31320, 25343008), (839, 39014, 2177175), (993, 39548, 5574729), (1058, 39548, 24895484), (1060, 39548, 30084164)

What I manually changed them into:

delete from Table1 where ID != 399 and Data1 = 31320 and Data2 = 25343008; delete from Table1 where ID != 839 and Data1 = 39014 and Data2 = 2177175; delete from Table1 where ID != 993 and Data1 = 39548 and Data2 = 5574729; delete from Table1 where ID != 1058 and Data1 = 39548 and Data2 = 24895484; delete from Table1 where ID != 1060 and Data1 = 39548 and Data2 = 30084164;

I couldn't find an editor that would let me make changes to just a selected column of text, so the editing process very tedious. I couldn't detect the difference between the comma after the ID column (399//,// 31320, 25343008) and the comma after the Data1 column (399, 31320//,// 25343008) so I had to skip every other comma in my time-consuming editing process.

It would have been a huge help if SQLPro could detect that I was exporting three columns and then showed a generic screen where I could say what to do with the values. In my case, this would have looked like

Text before column 1: delete from Table1 where ID != Text before column 2: and Data1 = Text before column 3: and Data2 = Text after column 3: ;

If creating a flexible screen that supports any number of columns would be too difficult, a single dialog that is repeatedly shown for each column would also work, with one final show for what should go after the last column. I think this feature would be a welcome addition to the current "Copy selected as" commands because it might be rare that the copy commands are exactly what the user wants to do, which was true in my case.

Environment (please complete the following information):

Requests will be closed until environmental details are provided.

hankinsoft commented 1 month ago

Hello, This is most likely not something I will add unless I receive additional requests for such a feature. As a workaround you could try running a query to generate the statements you want such as:

SELECT 'DELETE FROM actor WHERE actor_id = ' || actor_id || ';'
FROM actor
LIMIT 50;

This example run on the sample sakila database will create delete statements for actors 1-50 which can then be copied from the results grid and run as needed.

GaryMeyers1 commented 1 month ago

I know about the technique of putting literals in a select statement but I didn't remember the || operator. Since SQLPro condescendingly warns the user about various things such as

Do you really want to truncate the table ‘Table1’? Truncating a table will remove all of the contents. Once the data has been removed, it cannot be recovered. The following query will be executed: 1 DELETE FROM Table1;

I figured that you were gearing SQLPro toward beginner users.