Skip to content

Copy as SQL WHERE statement: choose leading keyword WHERE / AND / OR (#101) - #102

Open
jbburns wants to merge 1 commit into
squirrel-sql-client:masterfrom
jbburns:claude/copy-as-and-or-2j8kw4
Open

jbburns wants to merge 1 commit into
squirrel-sql-client:masterfrom
jbburns:claude/copy-as-and-or-2j8kw4

Conversation

@jbburns

@jbburns jbburns commented Sep 30, 2026

Copy link
Copy Markdown

For squirrel-sql-client/squirrel-sql-code issue #101.

"Copy as SQL WHERE statement" in the result table's right mouse menu gets a hover submenu to choose the leading keyword: WHERE, AND or OR.

  • Clicking the item copies, as before, using the chosen keyword.
  • Hovering opens the submenu. The current choice is checked.
  • Choosing a keyword checks it, copies right away, saves the choice (Props, so it survives restarts and applies to all result tabs) and renames the item, e.g. to Copy as SQL AND statement.
  • A user-defined shortcut for "Copy as SQL WHERE statement" still works and uses the chosen keyword.

When multiple rows are selected, AND/OR bracket the ORed rows so the snippet stays correct when appended to an existing WHERE clause:

Selection WHERE (unchanged) AND
1 row, 1 col WHERE A=1 AND A=1
1 row, 2 cols WHERE (A=1 AND B='x') AND (A=1 AND B='x')
2 rows, 1 col WHERE A=1 OR A=3 AND (A=1 OR A=3)
2 rows, 2 cols incl. NULL WHERE (A=1 AND B='x')
OR (A=2 AND B is null)
AND ((A=1 AND B='x')
OR (A=2 AND B is null))

Screenshots

Changes

  • TableCopyWhereStatementCommand: new constructor overload taking the leading keyword. The old constructor defaults to WHERE.
  • New fw/gui/action/CopyWhereStatementMenu: a JMenu with checkable WHERE/AND/OR items in a ButtonGroup. It persists the choice and runs the copy when the parent item itself is clicked (a JMenu doesn't run an action on click by itself).
  • TablePopupMenu: adds the menu in place of the old item and refreshes it in showPopupMenu(...), because another result tab may have changed the keyword. A small registerShortcut(...) keeps the action's shortcut working, since a JMenu can't carry an accelerator.
  • fw/gui/action/I18NStrings.properties: two new strings.

Testing

  • ant build succeeds on JDK 21. The versionChecker target's hardcoded source/target 1.7 had to be bumped to 1.8 locally just to build; that change is not part of this PR.
  • Ran the built app against an H2 in-memory database. With ID and NAME selected for two rows, choosing AND copied:
    AND ((ID=1 AND NAME='Alice')
    OR (ID=2 AND NAME='Bob'))
    
    Appended after ... where city is not null and executed, it returned exactly those two rows.
  • After choosing AND, the menu of a new result tab showed "Copy as SQL AND statement" with AND checked. Clicking the parent item copies with the chosen keyword and closes the menu.

Written with AI assistance (Claude Code).

🤖 Generated with Claude Code

https://claude.ai/code/session_01ALfFJ4FbFdmpAezKadmJjG

  The result table's right mouse menu item "Copy as SQL WHERE statement"
  offers a sub menu to choose the leading keyword WHERE, AND or OR.
  The chosen keyword is checked, remembered and shown in the menu item's
  text, e.g. "Copy as SQL AND statement". AND / OR allow to append the
  copied condition to an existing WHERE clause. When multiple rows are
  selected the ORed rows are bracketed, e.g.
  AND ((ID=1 AND NAME='Alice') OR (ID=2 AND NAME='Bob'))

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALfFJ4FbFdmpAezKadmJjG
@jbburns

jbburns commented Sep 30, 2026

Copy link
Copy Markdown
Author
image image image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants