Skip to content

Commit

Permalink
fix: use 2d array to represent results (#6)
Browse files Browse the repository at this point in the history
* fix: use 2d array to represent results

Signed-off-by: xxchan <[email protected]>

* 1.0.6

Signed-off-by: xxchan <[email protected]>

Signed-off-by: xxchan <[email protected]>
  • Loading branch information
xxchan authored Dec 30, 2022
1 parent 80fef93 commit 4e522e4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: target/sqllogictest-jdbc-runner-1.0.5-jar-with-dependencies.jar
asset_name: sqllogictest-jdbc-runner-1.0.5-jar-with-dependencies.jar
asset_path: target/sqllogictest-jdbc-runner-1.0.6-jar-with-dependencies.jar
asset_name: sqllogictest-jdbc-runner-1.0.6-jar-with-dependencies.jar
asset_content_type: application/java-archive
- name: Publish release
uses: StuYarrow/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.risingwave.sqllogictest</groupId>
<artifactId>sqllogictest-jdbc-runner</artifactId>
<version>1.0.5</version>
<version>1.0.6</version>

<name>sqllogictest-jdbc-runner</name>
<url>https://github.com/risinglightdb/sqllogictest-rs</url>
Expand Down
29 changes: 15 additions & 14 deletions src/main/java/com/risingwave/sqllogictest/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,64 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Properties;

import com.google.gson.JsonObject;
import com.google.gson.JsonStreamParser;
import com.google.gson.Gson;

public class App
{
private static String handleOne(Statement stmt, String sql) throws SQLException {
var builder = new StringBuilder();
private static ArrayList<ArrayList<String>> handleOne(Statement stmt, String sql) throws SQLException {
var result = new ArrayList<ArrayList<String>>();
if (stmt.execute(sql)) {
try (ResultSet rs = stmt.getResultSet()) {
var colCnt = rs.getMetaData().getColumnCount();
while (rs.next()) {
var arr = new ArrayList<String>();
for (var i = 1; i <= colCnt; i++) {
if (i != 1) {
builder.append(' ');
}
var v = rs.getString(i);
if (v == null) {
builder.append("NULL");
arr.add("NULL");
} else if (v.isEmpty()) {
builder.append("(empty)");
arr.add("(empty)");
} else {
builder.append(v);
arr.add(v);
}
}
builder.append('\n');
result.add(arr);
}
}
}
return builder.toString();
return result;
}

private static void mainLoop(Connection conn) throws Exception {
var parser = new JsonStreamParser(new InputStreamReader(System.in));
var gson = new Gson();
try (var stmt = conn.createStatement()) {
while (parser.hasNext()) {
var ele = parser.next();
var sql = ele.getAsJsonObject().get("sql").getAsString();
try {
var result = handleOne(stmt, sql);
var resultJson = new JsonObject();
resultJson.addProperty("result", result);
System.out.println(resultJson.toString());
resultJson.add("result", gson.toJsonTree(result));
System.out.println(resultJson);
} catch (SQLException e) {
e.printStackTrace();
var resultJson = new JsonObject();
resultJson.addProperty("err", e.getMessage());
System.out.println(resultJson.toString());
System.out.println(resultJson);
}
}
}
}

public static void main(String[] args)
{
var url = args[0];;
var url = args[0];
var props = new Properties();
if (args.length > 1) {
props.setProperty("user", args[1]);
Expand Down

0 comments on commit 4e522e4

Please sign in to comment.