Package org.postgresql.core
Class Utils
- java.lang.Object
-
- org.postgresql.core.Utils
-
public class Utils extends java.lang.Object
Collection 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 static java.lang.StringBuffer
appendEscapedIdentifier(java.lang.StringBuffer sbuf, java.lang.String value)
Deprecated.useescapeIdentifier(StringBuilder, String)
insteadstatic java.lang.StringBuffer
appendEscapedLiteral(java.lang.StringBuffer sbuf, java.lang.String value, boolean standardConformingStrings)
Deprecated.useescapeLiteral(StringBuilder, String, boolean)
insteadstatic byte[]
encodeUTF8(java.lang.String str)
Encode a string as UTF-8.static java.lang.StringBuilder
escapeIdentifier(java.lang.StringBuilder sbuf, java.lang.String value)
Escape the given identifier value and append it to the string builder sbuf.static java.lang.StringBuilder
escapeLiteral(java.lang.StringBuilder sbuf, java.lang.String value, boolean standardConformingStrings)
Escape the given literal value and append it to the string builder sbuf.static int
parseServerVersionStr(java.lang.String serverVersion)
Deprecated.use specificVersion
instancestatic java.lang.String
toHexString(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
-
encodeUTF8
public static byte[] encodeUTF8(java.lang.String str)
Encode a string as UTF-8.- Parameters:
str
- the string to encode- Returns:
- the UTF-8 representation of
str
-
appendEscapedLiteral
public static java.lang.StringBuffer appendEscapedLiteral(java.lang.StringBuffer sbuf, java.lang.String value, boolean standardConformingStrings) throws java.sql.SQLException
Deprecated.useescapeLiteral(StringBuilder, String, boolean)
insteadEscape the given literal value and append it to the string buffer sbuf. If sbuf is null, a new StringBuffer will be returned. The argument standardConformingStrings defines whether the backend expects standard-conforming string literals or allows backslash escape sequences.- Parameters:
sbuf
- the string buffer to append to; or nullvalue
- the string valuestandardConformingStrings
- if standard conforming strings should be used- Returns:
- the sbuf argument; or a new string buffer for sbuf == null
- Throws:
java.sql.SQLException
- if the string contains a \0 character
-
escapeLiteral
public static java.lang.StringBuilder escapeLiteral(java.lang.StringBuilder sbuf, java.lang.String value, boolean standardConformingStrings) throws java.sql.SQLException
Escape the given literal value and append it to the string builder sbuf. If sbuf is null, a new StringBuilder will be returned. The argument standardConformingStrings defines whether the backend expects standard-conforming string literals or allows backslash escape sequences.- Parameters:
sbuf
- the string builder to append to; or nullvalue
- 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 \0 character
-
appendEscapedIdentifier
public static java.lang.StringBuffer appendEscapedIdentifier(java.lang.StringBuffer sbuf, java.lang.String value) throws java.sql.SQLException
Deprecated.useescapeIdentifier(StringBuilder, String)
insteadEscape the given identifier value and append it to the string buffer sbuf. If sbuf is null, a new StringBuffer will be returned. This method is different from appendEscapedLiteral in that it includes the quoting required for the identifier while appendEscapedLiteral does not.- Parameters:
sbuf
- the string buffer to append to; or nullvalue
- the string value- Returns:
- the sbuf argument; or a new string buffer for sbuf == null
- Throws:
java.sql.SQLException
- if the string contains a \0 character
-
escapeIdentifier
public static java.lang.StringBuilder escapeIdentifier(java.lang.StringBuilder sbuf, java.lang.String value) throws java.sql.SQLException
Escape the given identifier value and append it to the string builder sbuf. If sbuf is null, 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; or nullvalue
- the string value- Returns:
- the sbuf argument; or a new string builder for sbuf == null
- Throws:
java.sql.SQLException
- if the string contains a \0 character
-
parseServerVersionStr
@Deprecated public static int parseServerVersionStr(java.lang.String serverVersion) throws java.lang.NumberFormatException
Deprecated.use specificVersion
instanceAttempt 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 vertion in a XXYYZZ form- Returns:
- server version in number form
- Throws:
java.lang.NumberFormatException
-
-