Make query mode silent for clean piping to pagers

Remove all diagnostic output in query mode - no front matter, timestamps, or metadata. Query results go directly to stdout for seamless piping to visidata/pspg/less.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Paul Trowbridge 2026-01-15 14:05:21 -05:00
parent 6c9b0f96a0
commit 1717c7ee2c

View File

@ -136,12 +136,7 @@ public class jrunner {
// Detect query mode when destination flags are not provided
queryMode = dcu.isEmpty() && dcn.isEmpty() && dcp.isEmpty() && dt.isEmpty();
if (queryMode) {
System.err.println("------------query mode------------------------------------");
System.err.println("source db uri: " + scu);
System.err.println("source db username: " + scn);
System.err.println("output format: " + outputFormat);
} else {
if (!queryMode) {
System.out.println("------------db info---------------------------------------");
System.out.println("source db uri: " + scu);
System.out.println("source db username: " + scn);
@ -165,9 +160,7 @@ public class jrunner {
//-------------------------------------------establish connections-------------------------------------------------
//source database
if (queryMode) {
System.err.println("------------open database connection---------------------");
} else {
if (!queryMode) {
System.out.println("------------open database connections---------------------");
}
try {
@ -177,7 +170,9 @@ public class jrunner {
e.printStackTrace();
System.exit(0);
}
System.out.println(" ✅ source database");
if (!queryMode) {
System.out.println(" ✅ source database");
}
//destination database
if (!queryMode) {
try {
@ -194,7 +189,9 @@ public class jrunner {
stmt = scon.createStatement();
stmt.setFetchSize(10000);
tsStart = Timestamp.from(Instant.now());
System.out.println(tsStart);
if (!queryMode) {
System.out.println(tsStart);
}
rs = stmt.executeQuery(sq);
//while (rs.next()) {
// System.out.println(rs.getString("x"));
@ -208,8 +205,10 @@ public class jrunner {
//---------------------------------------build meta---------------------------------------------------------------
try {
cols = rs.getMetaData().getColumnCount();
System.out.println("------------source metadata-------------------------------");
System.out.println("number of cols: " + cols);
if (!queryMode) {
System.out.println("------------source metadata-------------------------------");
System.out.println("number of cols: " + cols);
}
getv = new String[cols + 1];
dtn = new String[cols + 1];
} catch (SQLException e) {
@ -219,7 +218,9 @@ public class jrunner {
try {
for (int i = 1; i <= cols; i++){
dtn[i] = rs.getMetaData().getColumnTypeName(i);
System.out.println(" * " + rs.getMetaData().getColumnName(i) + ": " + dtn[i]);
if (!queryMode) {
System.out.println(" * " + rs.getMetaData().getColumnName(i) + ": " + dtn[i]);
}
}
} catch (SQLException e) {
e.printStackTrace();
@ -418,15 +419,8 @@ public class jrunner {
outputTSV(rs, cols);
break;
case "table":
System.err.println("Table format not yet implemented, defaulting to CSV");
outputCSV(rs, cols);
break;
case "json":
System.err.println("JSON format not yet implemented, defaulting to CSV");
outputCSV(rs, cols);
break;
default:
System.err.println("Unknown format: " + format + ", defaulting to CSV");
outputCSV(rs, cols);
break;
}