Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion windows/docs/decisions/0004-app-shell.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ On 2026-11-05 the maintainer had the app show what the server prints, PostgreSQL
- Invoking a table or view opens its table tab, or brings the open one forward. The core reads the page (`DatabaseSession.ReadTablePageAsync`, over the core's `read_page`), quoted, ordered, filtered and limited as the engine writes it, on one of the session's pooled connections (amended by 0007).
- A query tab is the SQL editor over the run's results, on its own editor connection opened on first use; a table tab is the results alone, read on the session's pooled connections (0007).
- Run statement (Query menu, Ctrl+Shift+Enter, as on Linux): the core picks the statement the cursor is in, or the last one before it, with the session's own grammar (`DatabaseSession.statement_at`, over `ScriptPlan::statement_at`, in UTF-16 offsets). The editor selects it, so the tab shows which statement ran, and Safe Mode judges that text alone.
- Results: the run's first result set in `DataGridView` (ADR 0003), given to the grid once it has its first rows, or once it ends empty, and grown on each `RowsAppended`. The rows shown stay until then, so a sort or a refresh never shows an empty grid between the two results. A run with more than one set shows a `ComboBox` over the grid, "Result 1 (3)", "Result 2 (50)", as the Linux app labels them, with the count the engine gave or a plus when the row limit cut a set short; picking one shows its rows in arrival order and its count in the status. The pane holds every set of the run until the next run's first set replaces them, unless Settings, Queries, Results kept per run sets a limit (10 to 1,000, as macOS): past it the run keeps its newest sets, lets go of the rest in the core (`QueryRun::release_set`), and its status ends with "N earlier results were dropped.". A dropped set the grid still shows stays until another is picked or the run ends, when the first set kept takes its place. Columns are sized to their content, and a sort or a refresh keeps their widths. Copy and Select All in the Edit menu reach the grid when it had focus last.
- Results: the run's first result set in `DataGridView` (ADR 0003), given to the grid once it has its first rows, or once it ends empty, and grown on each `RowsAppended`. The rows shown stay until then, so a sort or a refresh never shows an empty grid between the two results. A run with more than one set shows a `ComboBox` over the grid, "Result 1 (3)", "Result 2 (50)", as the Linux app labels them, with the count the engine gave or a plus when the row limit cut a set short; picking one shows its rows in arrival order and its count in the status. The pane holds every set of the run until the next run's first set replaces them, unless Settings, Queries, Results kept per run sets a limit (10 to 1,000, as macOS): past it the run keeps its newest sets, lets go of the rest in the core (`QueryRun::release_set`), and its status ends with "N earlier results were dropped.". A dropped set the grid still shows stays until another is picked or the run ends, when the newest set kept takes its place, as macOS shows a run's last result. Columns are sized to their content, and a sort or a refresh keeps their widths. Copy and Select All in the Edit menu reach the grid when it had focus last.
- Messages: a run the server printed something in gets a `SelectorBar`, Results | Messages, over its results. Messages is a read-only monospace `TextBox` with one line per notice, `{severity}: {message}`, as the Linux app prints the same core's notices, set once per batch of events rather than per notice. A run with no rows opens on Messages, one with rows on Results unless Messages was picked while it ran. Past the 10,000 notices the core keeps per run (`NoticeLimitReached`), the text ends with "The output was cut short."
- A header click on a table tab runs the table's query again with the sort: `build_page` writes the ORDER BY, with the row key as the tiebreak, so it orders the whole table, not the rows already read. A row address the engine adds for edits (SQLite's rowid, PostgreSQL's ctid) follows the visible columns and is not shown. An engine that pages in its own order refuses the sort, and the grid keeps the shown one.
- A header click on a query result does what the macOS app does: the result's statement runs again with the column's ORDER BY in place of its own and before its row limit (`DatabaseSession.SortedQuery`, the core's `with_order_by`). The ORDER BY names the column, or gives its position where a name is not unique or not a plain column (core ADR 0007). Only one statement that reads runs again. For a script, a write, SHOW or EXPLAIN, and where the engine takes no position, the core sorts the rows the result holds (`ResultSet.SortedAsync`), as macOS sorts them where they are, and the status says so.
Expand Down
7 changes: 7 additions & 0 deletions windows/src/TablePro.App.Model/RunResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ public RunResult Add(int setIndex, IReadOnlyList<ResultColumn> columns, out RunR
return result;
}

// The set shown stays after the run unless the limit dropped it, when the newest kept takes its place, as on macOS.
public RunResult ShownAtEnd(RunResult shown)
{
ArgumentNullException.ThrowIfNull(shown);
return Dropped == 0 || _results.Contains(shown) ? shown : _results[^1];
}

// The listed set the event changed, or null.
public RunResult? Apply(QueryEvent queryEvent)
{
Expand Down
13 changes: 6 additions & 7 deletions windows/src/TablePro.App/Views/ResultsPane.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ or QueryEvent.ByteLimitReached
break;
case QueryEvent.Finished finished:
Adopt();
ShowFirstKept();
ShowAtEnd(results, heldBy);
LetGoOfLeaving();
_droppedSets = results.Dropped;
RowCount = adopted ? (_picked?.Result.Rows ?? 0) : 0;
Expand Down Expand Up @@ -322,17 +322,16 @@ private void DropSet(List<HeldSet> incoming, HeldSet gone)
gone.Set.Dispose();
}

// At the run's end the first set kept takes the place of a dropped one still shown, as a run shows its first set.
private void ShowFirstKept()
private void ShowAtEnd(RunResults results, Dictionary<RunResult, HeldSet> heldBy)
{
if (_leaving is not { } leaving
|| !ReferenceEquals(leaving, _picked)
|| _held.Find(entry => !ReferenceEquals(entry, leaving)) is not { } first)
if (_picked is not { } picked
|| heldBy.GetValueOrDefault(results.ShownAtEnd(picked.Result)) is not { } shown
|| ReferenceEquals(shown, picked))
{
return;
}

Pick(first);
Pick(shown);
ShowPickedLabel();
}

Expand Down
37 changes: 37 additions & 0 deletions windows/tests/TablePro.App.Model.Tests/RunResultsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,43 @@ public void ExactlyTheLimitDropsNothing()
Assert.Equal(0, results.Dropped);
}

[Fact]
public void PastTheLimitADroppedSetShownGivesWayToTheNewestAndAKeptOneStays()
{
var results = New(kept: 2);
var sets = Enumerable.Range(0, 4).Select(index => results.Add(index, Columns, out _)).ToList();

Assert.Same(sets[3], results.ShownAtEnd(sets[0]));
Assert.Same(sets[3], results.ShownAtEnd(sets[1]));
Assert.Same(sets[2], results.ShownAtEnd(sets[2]));
}

[Fact]
public void ARunWithinTheLimitEndsOnTheSetShown()
{
var unlimited = New();
var first = unlimited.Add(0, Columns, out _);
unlimited.Add(1, Columns, out _);
var limited = New(kept: 2);
var kept = limited.Add(0, Columns, out _);
limited.Add(1, Columns, out _);

Assert.Same(first, unlimited.ShownAtEnd(first));
Assert.Same(kept, limited.ShownAtEnd(kept));
}

// A run with no set, such as an UPDATE, asks while the grid still shows the last run's set.
[Fact]
public void ARunThatDroppedNothingGivesBackASetOfAnotherRun()
{
var earlier = New().Add(0, Columns, out _);
var limited = New(kept: 2);
limited.Add(0, Columns, out _);

Assert.Same(earlier, New(kept: 2).ShownAtEnd(earlier));
Assert.Same(earlier, limited.ShownAtEnd(earlier));
}

// The sets a 10,000-set script leaves held, with the limit at 100.
[Fact]
public void TenThousandSetsWithAHundredKeptHoldAHundred()
Expand Down
6 changes: 4 additions & 2 deletions windows/tests/TablePro.App.UITests/RunStatementTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void EveryResultSetOfARunCanBePicked(string theme)
app.Screenshot("42-result-picker");
}

// Settings keeps two results per run, so the first two go and the status line says so.
// Settings keeps two results per run, so the first two go, the status line says so and the grid shows the newest.
[Theory]
[MemberData(nameof(Themes))]
public void ARunPastTheResultLimitKeepsTheNewestAndSaysHowManyWent(string theme)
Expand All @@ -70,12 +70,14 @@ public void ARunPastTheResultLimitKeepsTheNewestAndSaysHowManyWent(string theme)
VirtualKeyShort.CONTROL,
VirtualKeyShort.ENTER);

Assert.Equal("3", app.WaitForCell(app.Find("ResultsGrid"), 0, 0, value => value == "3"));
Assert.Equal("4", app.WaitForCell(app.Find("ResultsGrid"), 0, 0, value => value == "4"));
var picker = app.Find("ResultPicker").AsComboBox();
picker.Expand();
var listed = picker.Items.Select(item => item.Name).ToArray();
var selected = picker.SelectedItem?.Name;
picker.Collapse();
Assert.Equal<string>(["Result 3 (1)", "Result 4 (1)"], listed);
Assert.Equal("Result 4 (1)", selected);
app.Screenshot("43-result-limit");
}
}
Loading