Skip to content

Commit aeee0fc

Browse files
authored
Merge pull request #58 from jumpserver/pr@v3@fix_query_bug
fix: 修复导出数据到 csv , 当字段中存在逗号时造成的错行问题
2 parents 05f89bb + 96d3c1a commit aeee0fc

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

backend/framework/src/main/java/org/jumpserver/chen/framework/console/dataview/DataView.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.jumpserver.chen.framework.session.SessionManager;
1515
import org.jumpserver.chen.framework.ws.io.PacketIO;
1616

17+
import java.io.BufferedWriter;
1718
import java.io.IOException;
1819
import java.nio.file.Files;
1920
import java.sql.SQLException;
@@ -125,6 +126,15 @@ private void fullData(SQLQueryResult result) {
125126
}
126127
}
127128

129+
private static void writeString(BufferedWriter writer, Object object) throws IOException {
130+
var str = object.toString();
131+
132+
if (str.contains(",")) {
133+
str = "\"" + str + "\"";
134+
}
135+
writer.write(str);
136+
}
137+
128138
public void export(String scope) throws SQLException {
129139
var session = SessionManager.getCurrentSession();
130140

@@ -144,7 +154,7 @@ public void export(String scope) throws SQLException {
144154

145155
if (scope.equals("current")) {
146156
for (Field field : this.data.getFields()) {
147-
writer.write(field.getName());
157+
writeString(writer, field.getName());
148158
writer.write(",");
149159
}
150160
writer.newLine();
@@ -155,7 +165,7 @@ public void export(String scope) throws SQLException {
155165
writer.write("NULL");
156166
writer.write(",");
157167
} else {
158-
writer.write(row.get(field.getName()).toString());
168+
writeString(writer, row.get(field.getName()));
159169
writer.write(",");
160170
}
161171
}

backend/modules/src/main/java/org.jumpserver.chen.modules/postgresql/PostgresqlActuator.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ public List<String> getSchemas() throws SQLException {
3333

3434
@Override
3535
public void changeSchema(String schema) throws SQLException {
36-
this.execute(SQL.of("SET SEARCH_PATH TO ?;", schema));
36+
this.execute(SQL.of("SET SEARCH_PATH TO '?';", schema));
3737
}
3838

3939
@Override
4040
public SQLExecutePlan createPlan(String schema, String table, SQLQueryParams sqlQueryParams) throws SQLException {
41-
var sql = SQL.of("select * from ?.?", schema, table);
41+
var sql = SQL.of("select * from \"?\".\"?\"", schema, table);
4242
return this.createPlan(sql, sqlQueryParams);
4343
}
4444
}

0 commit comments

Comments
 (0)