Package org.postgresql.core
Class Utils
- java.lang.Object
-
- org.postgresql.core.Utils
-
public class Utils extends java.lang.ObjectCollection of utilities used by the protocol-level code.
-
-
Constructor Summary
Constructors Constructor Description Utils()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private static voiddoAppendEscapedIdentifier(java.lang.Appendable sbuf, java.lang.String value)Common part for appendEscapedIdentifier.private static voiddoAppendEscapedLiteral(java.lang.Appendable sbuf, java.lang.String value, boolean standardConformingStrings)Common part forescapeLiteral(StringBuilder, String, boolean).static java.lang.StringBuilderescapeIdentifier(java.lang.StringBuilder sbuf, java.lang.String value)Escape the given identifiervalueand append it to the string buildersbuf.static java.lang.StringBuilderescapeLiteral(java.lang.StringBuilder sbuf, java.lang.String value, boolean standardConformingStrings)Escape the given literalvalueand append it to the string buildersbuf.static intparseServerVersionStr(java.lang.String serverVersion)Deprecated.use specificVersioninstancestatic java.lang.StringtoHexString(byte[] data)Turn a bytearray into a printable form, representing each byte in hex.
-
-
-
Method Detail
-
toHexString
public static java.lang.String toHexString(byte[] data)
Turn a bytearray into a printable form, representing each byte in hex.- Parameters:
data- the bytearray to stringize- Returns:
- a hex-encoded printable representation of
data
-
escapeLiteral
public static java.lang.StringBuilder escapeLiteral(java.lang.StringBuilder sbuf, java.lang.String value, boolean standardConformingStrings) throws java.sql.SQLExceptionEscape the given literalvalueand append it to the string buildersbuf. Ifsbufisnull, a new StringBuilder will be returned. The argumentstandardConformingStringsdefines whether the backend expects standard-conforming string literals or allows backslash escape sequences.- Parameters:
sbuf- the string builder to append to; ornullvalue- the string valuestandardConformingStrings- if standard conforming strings should be used- Returns:
- the sbuf argument; or a new string builder for sbuf == null
- Throws:
java.sql.SQLException- if the string contains a\0character
-
doAppendEscapedLiteral
private static void doAppendEscapedLiteral(java.lang.Appendable sbuf, java.lang.String value, boolean standardConformingStrings) throws java.sql.SQLExceptionCommon part forescapeLiteral(StringBuilder, String, boolean).- Parameters:
sbuf- Either StringBuffer or StringBuilder as we do not expect any IOException to be thrownvalue- value to appendstandardConformingStrings- if standard conforming strings should be used- Throws:
java.sql.SQLException
-
escapeIdentifier
public static java.lang.StringBuilder escapeIdentifier(java.lang.StringBuilder sbuf, java.lang.String value) throws java.sql.SQLExceptionEscape the given identifiervalueand append it to the string buildersbuf. Ifsbufisnull, a new StringBuilder will be returned. This method is different from appendEscapedLiteral in that it includes the quoting required for the identifier whileescapeLiteral(StringBuilder, String, boolean)does not.- Parameters:
sbuf- the string builder to append to; ornullvalue- the string value- Returns:
- the sbuf argument; or a new string builder for sbuf == null
- Throws:
java.sql.SQLException- if the string contains a\0character
-
doAppendEscapedIdentifier
private static void doAppendEscapedIdentifier(java.lang.Appendable sbuf, java.lang.String value) throws java.sql.SQLExceptionCommon part for appendEscapedIdentifier.- Parameters:
sbuf- Either StringBuffer or StringBuilder as we do not expect any IOException to be thrown.value- value to append- Throws:
java.sql.SQLException
-
parseServerVersionStr
@Deprecated public static int parseServerVersionStr(java.lang.String serverVersion) throws java.lang.NumberFormatExceptionDeprecated.use specificVersioninstanceAttempt to parse the server version string into an XXYYZZ form version number.
Returns 0 if the version could not be parsed.
Returns minor version 0 if the minor version could not be determined, e.g. devel or beta releases.
If a single major part like 90400 is passed, it's assumed to be a pre-parsed version and returned verbatim. (Anything equal to or greater than 10000 is presumed to be this form).
The yy or zz version parts may be larger than 99. A NumberFormatException is thrown if a version part is out of range.
- Parameters:
serverVersion- server version in a XXYYZZ form- Returns:
- server version in number form
- Throws:
java.lang.NumberFormatException
-
-