Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ssh_db_query (MySQL): row_count is off by one (counts the wrapper line, not result rows) #45

Description

@technophile77

Summary

ssh_db_query reports row_count one greater than the actual number of rows: 1 row → row_count: 2, 13 rows → 14, and a 0-row result → row_count: 2.

Affected code

src/index.js (v3.5.0), in the db-query handler:

const output = result.stdout.trim();
const lines = output.split('\n');
...
row_count: lines.length,

For MySQL, buildMySQLQueryCommand() wraps results with awk 'BEGIN{print "["} ... END{print "]"}', so output looks like:

[
{"row":1,"data":"..."},
{"row":2,"data":"..."}]

output.split('\n').length counts the leading [ line in addition to the per-row lines, so row_count = actual_rows + 1. It also conflates "lines" with "rows" — it would miscount if any cell value contained a newline.

Reproduction

Any MySQL query returning N rows reports row_count: N+1. A query returning 0 rows reports output: "[\n]" with row_count: 2.

Suggested fix

Derive the count from the actual result rows rather than the cosmetic line count — e.g. count the {"row": entries, JSON.parse the assembled array and use .length, or use MySQL's own row count. Subtracting the wrapper line would fix the off-by-one, but parsing the structured result is more robust.

Version: mcp-ssh-manager 3.5.0.

Related: #44 (query corruption in the same MySQL query path).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions