Mercurial > hg > monetdb-java
comparison tests/JDBC_API_Tester.java @ 923:3b29fb3f537a
Improve construction of SQL query in showTblContents()
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Wed, 31 Jul 2024 20:43:29 +0200 (8 months ago) |
parents | e54a9fc65e0c |
children | 4dfdb62e3e9d |
comparison
equal
deleted
inserted
replaced
922:e54a9fc65e0c | 923:3b29fb3f537a |
---|---|
7266 ); | 7266 ); |
7267 } | 7267 } |
7268 | 7268 |
7269 // some private utility methods for showing table content and params meta data | 7269 // some private utility methods for showing table content and params meta data |
7270 private void showTblContents(String tblnm) { | 7270 private void showTblContents(String tblnm) { |
7271 final String query = "SELECT * FROM \"" + tblnm + "\""; | |
7271 Statement stmt = null; | 7272 Statement stmt = null; |
7272 ResultSet rs = null; | 7273 ResultSet rs = null; |
7273 try { | 7274 try { |
7274 stmt = con.createStatement(); | 7275 stmt = con.createStatement(); |
7275 rs = stmt.executeQuery("SELECT * FROM " + tblnm); | 7276 rs = stmt.executeQuery(query); |
7276 if (rs != null) { | 7277 if (rs != null) { |
7277 ResultSetMetaData rsmd = rs.getMetaData(); | 7278 ResultSetMetaData rsmd = rs.getMetaData(); |
7278 sb.append("Table ").append(tblnm).append(" has ").append(rsmd.getColumnCount()).append(" columns:\n"); | 7279 sb.append("Table ").append(tblnm).append(" has ").append(rsmd.getColumnCount()).append(" columns:\n"); |
7279 for (int col = 1; col <= rsmd.getColumnCount(); col++) { | 7280 for (int col = 1; col <= rsmd.getColumnCount(); col++) { |
7280 sb.append("\t").append(rsmd.getColumnLabel(col)); | 7281 sb.append("\t").append(rsmd.getColumnLabel(col)); |
7285 sb.append("\t").append(rs.getString(col)); | 7286 sb.append("\t").append(rs.getString(col)); |
7286 } | 7287 } |
7287 sb.append("\n"); | 7288 sb.append("\n"); |
7288 } | 7289 } |
7289 } else | 7290 } else |
7290 sb.append("failed to execute query: SELECT * FROM ").append(tblnm).append("\n"); | 7291 sb.append("failed to execute query: ").append(query).append("\n"); |
7291 } catch (SQLException e) { | 7292 } catch (SQLException e) { |
7292 sb.append("showContents failed: ").append(e.getMessage()).append("\n"); | 7293 sb.append("showContents failed: ").append(e.getMessage()).append("\n"); |
7293 } | 7294 } |
7294 closeStmtResSet(stmt, rs); | 7295 closeStmtResSet(stmt, rs); |
7295 } | 7296 } |
7383 pos = max_pos; | 7384 pos = max_pos; |
7384 } | 7385 } |
7385 } | 7386 } |
7386 } | 7387 } |
7387 System.err.println(); | 7388 System.err.println(); |
7388 System.err.println("---- Full Output: ---------------------------"); | 7389 System.err.println("---- Full Output: ------------"); |
7389 System.err.println(sb); | 7390 System.err.println(sb); |
7390 System.err.println("---- END --------------------------------------"); | 7391 System.err.println("---- END ---------------------"); |
7391 System.err.println("---- Expected Output: -------------------------"); | 7392 System.err.println("---- Expected Output: --------"); |
7392 System.err.println(expected); | 7393 System.err.println(expected); |
7393 System.err.println("---- END --------------------------------------"); | 7394 System.err.println("---- END ---------------------"); |
7394 System.err.println(); | 7395 System.err.println(); |
7395 } | 7396 } |
7396 if (sb.length() > sbInitLen) { | 7397 if (sb.length() > sbInitLen) { |
7397 System.err.println("Test '" + testname | 7398 System.err.println("Test '" + testname |
7398 + "' produced output > " + sbInitLen | 7399 + "' produced output > " + sbInitLen |