Skip to content

Commit

Permalink
#16884 Check that dump writer is set
Browse files Browse the repository at this point in the history
  • Loading branch information
serge-rider committed Jun 26, 2022
1 parent d4393c7 commit 7d62861
Showing 1 changed file with 32 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@
*/
package org.jkiss.dbeaver.tools.sql.task;

import org.jkiss.dbeaver.model.data.DBDDataReceiver;
import org.jkiss.dbeaver.model.exec.*;
import org.jkiss.utils.CommonUtils;

import java.io.IOException;
import java.io.Writer;
import java.util.List;

import org.jkiss.dbeaver.model.data.DBDDataReceiver;
import org.jkiss.dbeaver.model.exec.DBCAttributeMetaData;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.DBCResultSet;
import org.jkiss.dbeaver.model.exec.DBCResultSetMetaData;
import org.jkiss.dbeaver.model.exec.DBCSession;

/**
* SQLScriptDataReceiver
*/
Expand All @@ -40,17 +37,19 @@ public void fetchStart(DBCSession session, DBCResultSet resultSet, long offset,
if (resultSet == null) {
return;
}
DBCResultSetMetaData rsMeta = resultSet.getMeta();
List<DBCAttributeMetaData> attributes = rsMeta.getAttributes();
rowSize = attributes.size();
try {
dumpWriter.append("Columns:\t");
if (dumpWriter != null) {
DBCResultSetMetaData rsMeta = resultSet.getMeta();
List<DBCAttributeMetaData> attributes = rsMeta.getAttributes();
rowSize = attributes.size();
try {
dumpWriter.append("Columns:\t");

for (DBCAttributeMetaData attribute : attributes) {
dumpWriter.append(attribute.getLabel() + "\t");
for (DBCAttributeMetaData attribute : attributes) {
dumpWriter.append(attribute.getLabel() + "\t");
}
} catch (IOException e1) {
throw new DBCException("IOException writing to dumpWriter", e1);
}
} catch (IOException e1) {
throw new DBCException("IOException writing to dumpWriter", e1);
}
}

Expand All @@ -59,26 +58,30 @@ public void fetchRow(DBCSession session, DBCResultSet resultSet) throws DBCExcep
if (resultSet == null) {
return;
}
try {
for (int i = 0; i < rowSize; i++) {
if (resultSet.getAttributeValue(i) != null) {
dumpWriter.append("" + resultSet.getAttributeValue(i).toString() + "\t");
} else {
dumpWriter.append("NULL\t");
if (dumpWriter != null) {
try {
for (int i = 0; i < rowSize; i++) {
if (resultSet.getAttributeValue(i) != null) {
dumpWriter.append(CommonUtils.toString(resultSet.getAttributeValue(i))).append("\t");
} else {
dumpWriter.append("NULL\t");
}
}
dumpWriter.append("\n");
} catch (IOException e) {
throw new DBCException("IOException writing to dumpWriter", e);
}
dumpWriter.append("\n");
} catch (IOException e) {
throw new DBCException("IOException writing to dumpWriter", e);
}
}

@Override
public void fetchEnd(DBCSession session, DBCResultSet resultSet) throws DBCException {
try {
dumpWriter.flush();
} catch (IOException e) {
throw new DBCException("IOException writing to dumpWriter", e);
if (dumpWriter != null) {
try {
dumpWriter.flush();
} catch (IOException e) {
throw new DBCException("IOException writing to dumpWriter", e);
}
}
}

Expand Down

0 comments on commit 7d62861

Please sign in to comment.