package org.postgresql.core; import java.util.Hashtable; import java.sql.SQLException; /** * This class parses raw error and notice messages from the V3 Protocol into * the various fields they may contain. More information on these fields is * containted in the main PostgreSQL documentation under Internals, * Frontend/Backend Protocol, Error and Notice Message Fields. * * The different fields are separated by an embedded null (0) byte. I'm not * sure how this will handle messages in encodings that allow embedded nulls. * */ class PGErrorMessage { private String severity; private String sqlState; private String message; private String detail; private String hint; private String position; private String where; private String file; private String line; private String routine; public PGErrorMessage(byte rawMessage[], Encoding encoding) throws SQLException { Hashtable fields = split(rawMessage,encoding); severity = (String)fields.get("S"); sqlState = (String)fields.get("C"); message = (String)fields.get("M"); detail = (String)fields.get("D"); hint = (String)fields.get("H"); position = (String)fields.get("P"); where = (String)fields.get("W"); file = (String)fields.get("F"); line = (String)fields.get("L"); routine = (String)fields.get("R"); } public String getSeverity() { return severity; } public String getSQLState() { return sqlState; } public String getMessage() { return message; } public String getDetail() { return detail; } public String getHint() { return hint; } public String getPosition() { return position; } public String getWhere() { return where; } public String getFile() { return file; } public String getLine() { return line; } public String getRoutine() { return routine; } /** * Split the fields in the raw message into their label and content. */ private static Hashtable split(byte message[], Encoding encoding) throws SQLException { Hashtable fields = new Hashtable(); int start = 0; for (int i=0; istart) { byte label[] = new byte[1]; byte content[] = new byte[i-start-1]; label[0] = message[start]; for (int j=start+1; j