Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RAD-2620: Fixing issue when trying to deserialize a Blob object. #320

Open
wants to merge 1 commit into
base: 4.5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions SQL console/RELEASE-NOTES
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
*Version 4.5.1*
* Fixing issue when trying to deserialize a Blob object.

*Version 4.5.0*
* Upgraded for Mango 4.5.0

Expand Down
24 changes: 18 additions & 6 deletions SQL console/src/com/serotonin/m2m2/db/dao/SqlConsole.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.sql.Blob;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.LinkedList;
Expand All @@ -17,6 +18,7 @@
import org.springframework.stereotype.Component;

import com.infiniteautomation.mango.rest.latest.SqlQueryResult;
import com.serotonin.ShouldNeverHappenException;
import com.serotonin.db.spring.ExtendedJdbcTemplate;
import com.serotonin.util.SerializationHelper;

Expand Down Expand Up @@ -50,12 +52,7 @@ public SqlQueryResult query(String sqlString, String serializedDataMsg) {
row.add(rs.getString(i + 1));
else if (meta.getColumnType(i + 1) == Types.LONGVARBINARY
|| meta.getColumnType(i + 1) == Types.BLOB) {
Blob blob = rs.getBlob(i + 1);
Object o;
if (blob == null)
o = null;
else
o = SerializationHelper.readObjectInContext(blob.getBinaryStream());
Object o = readObjectFromBlob(rs.getBlob(i + 1));
row.add(serializedDataMsg + "(" + o + ")");
} else
row.add(rs.getObject(i + 1));
Expand All @@ -68,4 +65,19 @@ else if (meta.getColumnType(i + 1) == Types.LONGVARBINARY
return result;
});
}

private static Object readObjectFromBlob(Blob blob) throws SQLException {
Object o;

if (blob == null) {
o = null;
} else {
try {
o = SerializationHelper.readObjectInContext(blob.getBinaryStream());
} catch (ShouldNeverHappenException e) {
o = "BLOB";
}
}
return o;
}
}