Package org.postgresql.core.v3
Class SimpleParameterList
java.lang.Object
org.postgresql.core.v3.SimpleParameterList
- All Implemented Interfaces:
ParameterList,V3ParameterList
Parameter list for a single-statement V3 query.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final byteprivate final byte[][]private final byte[]private static final byteprivate static final byteprivate static final ObjectMarker object representing NULL; this distinguishes "parameter never set" from "parameter set to null".private static final byteprivate final int[]private final Object[]private intprivate static final byteprivate final TypeTransferModeRegistry -
Constructor Summary
ConstructorsConstructorDescriptionSimpleParameterList(int paramCount, TypeTransferModeRegistry transferModeRegistry) -
Method Summary
Modifier and TypeMethodDescriptionvoidappendAll(ParameterList list) Use this operation to append more parameters to the current list.private voidvoidEnsure that all parameters in this list have been assigned values.voidclear()Unbind all parameter values bound in this list.voidConvert any function output parameters to the correct type (void) and set an ignorable value for it.copy()Perform a shallow copy of this ParameterList, returning a new instance (still suitable for passing to the owning Query).private bytedirection(int index) byte[][]Return the encoding for each parameter.byte[]getFlags()Return the flags for each parameter.intGet the number of IN parameters in this list.intGet the number of OUT parameters in this list.intGet the number of parameters in this list.int[]Return the parameter type information.Return a list of the SimpleParameterList objects that make up this parameter list.(package private) intgetTypeOID(int index) int[]Return the oids of the parameters in this list.(package private) intgetV3Length(int index) Object[]Returns the bound parameter values.(package private) boolean(package private) booleanisBinary(int index) (package private) booleanisNull(int index) private static StringquoteAndCast(String text, String type, boolean standardConformingStrings) Escapes a given text value as a literal, wraps it in single quotes, casts it to the to the given data type, and finally wraps the whole thing in parentheses.voidregisterOutParameter(int index, int sqlType) voidsetBinaryParameter(int index, byte[] value, int oid) Binds given byte[] value to a parameter.voidsetBytea(int index, byte[] data, int offset, int length) Binds a binary bytea value stored as a bytearray to a parameter.voidsetBytea(int index, InputStream stream) Binds a binary bytea value stored as an InputStream.voidsetBytea(int index, InputStream stream, int length) Binds a binary bytea value stored as an InputStream.voidsetBytea(int index, ByteStreamWriter writer) Binds a binary bytea value stored as a ByteStreamWriter.voidsetIntParameter(int index, int value) Binds an integer value to a parameter.voidsetLiteralParameter(int index, String value, int oid) Binds a String value that is an unquoted literal to the server's query parser (for example, a bare integer) to a parameter.voidsetNull(int index, int oid) Binds a SQL NULL value to a parameter.(package private) voidsetResolvedType(int index, int oid) voidsetStringParameter(int index, String value, int oid) Binds a String value that needs to be quoted for the server's parser to understand (for example, a timestamp) to a parameter.voidsetText(int index, InputStream stream) Binds a text value stored as an InputStream that is a valid UTF-8 byte stream.private static <E extends Throwable>
RuntimeExceptionprivate static voidstreamBytea(PGStream pgStream, ByteStreamWriter writer) private static voidstreamBytea(PGStream pgStream, StreamWrapper wrapper) toString()Useful implementation of toString.toString(int index, boolean standardConformingStrings) Return a human-readable representation of a particular parameter in this ParameterList.toString(int index, SqlSerializationContext context) Return the string literal representation of a particular parameter in this ParameterList.(package private) voidwriteV3Value(int index, PGStream pgStream)
-
Field Details
-
IN
private static final byte IN- See Also:
-
OUT
private static final byte OUT- See Also:
-
INOUT
private static final byte INOUT- See Also:
-
TEXT
private static final byte TEXT- See Also:
-
BINARY
private static final byte BINARY- See Also:
-
paramValues
-
paramTypes
private final int[] paramTypes -
flags
private final byte[] flags -
encoded
private final byte[][] encoded -
transferModeRegistry
-
NULL_OBJECT
Marker object representing NULL; this distinguishes "parameter never set" from "parameter set to null". -
pos
private int pos
-
-
Constructor Details
-
SimpleParameterList
SimpleParameterList(int paramCount, TypeTransferModeRegistry transferModeRegistry)
-
-
Method Details
-
registerOutParameter
- Specified by:
registerOutParameterin interfaceParameterList- Throws:
SQLException
-
bind
- Throws:
SQLException
-
getParameterCount
public int getParameterCount()Description copied from interface:ParameterListGet the number of parameters in this list. This value never changes for a particular instance, and might be zero.- Specified by:
getParameterCountin interfaceParameterList- Returns:
- the number of parameters in this list.
-
getOutParameterCount
public int getOutParameterCount()Description copied from interface:ParameterListGet the number of OUT parameters in this list.- Specified by:
getOutParameterCountin interfaceParameterList- Returns:
- the number of OUT parameters in this list
-
getInParameterCount
public int getInParameterCount()Description copied from interface:ParameterListGet the number of IN parameters in this list.- Specified by:
getInParameterCountin interfaceParameterList- Returns:
- the number of IN parameters in this list
-
setIntParameter
Description copied from interface:ParameterListBinds an integer value to a parameter. The type of the parameter is implicitly 'int4'.- Specified by:
setIntParameterin interfaceParameterList- Parameters:
index- the 1-based parameter index to bind.value- the integer value to use.- Throws:
SQLException- on error or ifindexis out of range
-
setLiteralParameter
Description copied from interface:ParameterListBinds a String value that is an unquoted literal to the server's query parser (for example, a bare integer) to a parameter. Associated with the parameter is a typename for the parameter that should correspond to an entry in pg_types.- Specified by:
setLiteralParameterin interfaceParameterList- Parameters:
index- the 1-based parameter index to bind.value- the unquoted literal string to use.oid- the type OID of the parameter, or0to infer the type.- Throws:
SQLException- on error or ifindexis out of range
-
setStringParameter
Description copied from interface:ParameterListBinds a String value that needs to be quoted for the server's parser to understand (for example, a timestamp) to a parameter. Associated with the parameter is a typename for the parameter that should correspond to an entry in pg_types.- Specified by:
setStringParameterin interfaceParameterList- Parameters:
index- the 1-based parameter index to bind.value- the quoted string to use.oid- the type OID of the parameter, or0to infer the type.- Throws:
SQLException- on error or ifindexis out of range
-
setBinaryParameter
Description copied from interface:ParameterListBinds given byte[] value to a parameter. The bytes must already be in correct format matching the OID.- Specified by:
setBinaryParameterin interfaceParameterList- Parameters:
index- the 1-based parameter index to bind.value- the bytes to send.oid- the type OID of the parameter.- Throws:
SQLException- on error or ifindexis out of range
-
setBytea
Description copied from interface:ParameterListBinds a binary bytea value stored as a bytearray to a parameter. The parameter's type is implicitly set to 'bytea'. The bytearray's contains should remain unchanged until query execution has completed.- Specified by:
setByteain interfaceParameterList- Parameters:
index- the 1-based parameter index to bind.data- an array containing the raw data valueoffset- the offset withindataof the start of the parameter data.length- the number of bytes of parameter data withindatato use.- Throws:
SQLException- on error or ifindexis out of range
-
setBytea
Description copied from interface:ParameterListBinds a binary bytea value stored as an InputStream. The parameter's type is implicitly set to 'bytea'. The stream should remain valid until query execution has completed.- Specified by:
setByteain interfaceParameterList- Parameters:
index- the 1-based parameter index to bind.stream- a stream containing the parameter data.length- the number of bytes of parameter data to read fromstream.- Throws:
SQLException- on error or ifindexis out of range
-
setBytea
Description copied from interface:ParameterListBinds a binary bytea value stored as an InputStream. The parameter's type is implicitly set to 'bytea'. The stream should remain valid until query execution has completed.- Specified by:
setByteain interfaceParameterList- Parameters:
index- the 1-based parameter index to bind.stream- a stream containing the parameter data.- Throws:
SQLException- on error or ifindexis out of range
-
setBytea
Description copied from interface:ParameterListBinds a binary bytea value stored as a ByteStreamWriter. The parameter's type is implicitly set to 'bytea'. The stream should remain valid until query execution has completed.- Specified by:
setByteain interfaceParameterList- Parameters:
index- the 1-based parameter index to bind.writer- a writer that can write the bytes for the parameter- Throws:
SQLException- on error or ifindexis out of range
-
setText
Description copied from interface:ParameterListBinds a text value stored as an InputStream that is a valid UTF-8 byte stream. Any byte-order marks (BOM) in the stream are passed to the backend. The parameter's type is implicitly set to 'text'. The stream should remain valid until query execution has completed.- Specified by:
setTextin interfaceParameterList- Parameters:
index- the 1-based parameter index to bind.stream- a stream containing the parameter data.- Throws:
SQLException- on error or ifindexis out of range
-
setNull
Description copied from interface:ParameterListBinds a SQL NULL value to a parameter. Associated with the parameter is a typename for the parameter that should correspond to an entry in pg_types.- Specified by:
setNullin interfaceParameterList- Parameters:
index- the 1-based parameter index to bind.oid- the type OID of the parameter, or0to infer the type.- Throws:
SQLException- on error or ifindexis out of range
-
quoteAndCast
Escapes a given text value as a literal, wraps it in single quotes, casts it to the to the given data type, and finally wraps the whole thing in parentheses.For example, "123" and "int4" becomes "('123'::int)"
The additional parentheses is added to ensure that the surrounding text of where the parameter value is entered does modify the interpretation of the value.
For example if our input SQL is:
SELECT ?bUsing a parameter value of '{}' and type of json we'd get:
test=# SELECT ('{}'::json)b; b ---- {}But without the parentheses the result changes:
test=# SELECT '{}'::jsonb; jsonb ------- {} -
sneakyThrow
- Throws:
E
-
toString
Description copied from interface:ParameterListReturn a human-readable representation of a particular parameter in this ParameterList. If the parameter is not bound or is of type bytea sourced from an InputStream, returns "?". This method will NOT consume InputStreams, instead "?" will be returned.- Specified by:
toStringin interfaceParameterList- Parameters:
index- the 1-based parameter index to bind.standardConformingStrings- true if \ is not an escape character in strings literals- Returns:
- a string representation of the parameter.
-
toString
Description copied from interface:ParameterListReturn the string literal representation of a particular parameter in this ParameterList. If the parameter is not bound, returns "?". This method will consume all InputStreams to produce the result.- Specified by:
toStringin interfaceParameterList- Parameters:
index- the 1-based parameter index to bind.context- specifies configuration for converting the parameters to string- Returns:
- a string representation of the parameter.
-
checkAllParametersSet
Description copied from interface:V3ParameterListEnsure that all parameters in this list have been assigned values. Return silently if all is well, otherwise throw an appropriate exception.- Specified by:
checkAllParametersSetin interfaceV3ParameterList- Throws:
SQLException- if not all parameters are set.
-
convertFunctionOutParameters
public void convertFunctionOutParameters()Description copied from interface:V3ParameterListConvert any function output parameters to the correct type (void) and set an ignorable value for it.- Specified by:
convertFunctionOutParametersin interfaceV3ParameterList
-
streamBytea
- Throws:
IOException
-
streamBytea
- Throws:
IOException
-
getTypeOIDs
public int[] getTypeOIDs()Description copied from interface:ParameterListReturn the oids of the parameters in this list. May be null for a ParameterList that does not support typing of parameters.- Specified by:
getTypeOIDsin interfaceParameterList- Returns:
- oids of the parameters
-
getTypeOID
int getTypeOID(int index) -
hasUnresolvedTypes
boolean hasUnresolvedTypes() -
setResolvedType
void setResolvedType(int index, int oid) -
isNull
boolean isNull(int index) -
isBinary
boolean isBinary(int index) -
direction
private byte direction(int index) -
getV3Length
int getV3Length(int index) -
writeV3Value
- Throws:
IOException
-
copy
Description copied from interface:ParameterListPerform a shallow copy of this ParameterList, returning a new instance (still suitable for passing to the owning Query). If this ParameterList is immutable, copy() may return the same immutable object.- Specified by:
copyin interfaceParameterList- Returns:
- a new ParameterList instance
-
clear
public void clear()Description copied from interface:ParameterListUnbind all parameter values bound in this list.- Specified by:
clearin interfaceParameterList
-
getSubparams
Description copied from interface:V3ParameterListReturn a list of the SimpleParameterList objects that make up this parameter list. If this object is already a SimpleParameterList, returns null (avoids an extra array construction in the common case).- Specified by:
getSubparamsin interfaceV3ParameterList- Returns:
- an array of single-statement parameter lists, or
nullif this object is already a single-statement parameter list.
-
getValues
Description copied from interface:ParameterListReturns the bound parameter values.- Specified by:
getValuesin interfaceParameterList- Returns:
- Object array containing the parameter values.
-
getParamTypes
public int[] getParamTypes()Description copied from interface:V3ParameterListReturn the parameter type information.- Specified by:
getParamTypesin interfaceV3ParameterList- Returns:
- an array of
Oidtype information
-
getFlags
public byte[] getFlags()Description copied from interface:V3ParameterListReturn the flags for each parameter.- Specified by:
getFlagsin interfaceV3ParameterList- Returns:
- an array of bytes used to store flags.
-
getEncoding
public byte[][] getEncoding()Description copied from interface:V3ParameterListReturn the encoding for each parameter.- Specified by:
getEncodingin interfaceV3ParameterList- Returns:
- nested byte array of bytes with encoding information.
-
appendAll
Description copied from interface:ParameterListUse this operation to append more parameters to the current list.- Specified by:
appendAllin interfaceParameterList- Parameters:
list- of parameters to append with.- Throws:
SQLException- fault raised if driver or back end throw an exception
-
toString
Useful implementation of toString.
-