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