org.mariadb.jdbc.internal.query

## Class MariaDbClientParameterizeQuery

- java.lang.Object
- - org.mariadb.jdbc.internal.query.MariaDbClientParameterizeQuery

All Implemented Interfaces:
  ParameterizeQuery, Query

    public class MariaDbClientParameterizeQuery
    extends Object
    implements ParameterizeQuery

Client Parameterize query implementation. Example part : INSERT INTO MultiTestt3_dupp(col1, pkey,col2,col3,col4) VALUES (9, ?, 5, ?, 8) ON DUPLICATE KEY UPDATE pkey=pkey+10

1. queryParts array : [ "INSERT INTO MultiTestt3_dupp(col1, pkey,col2,col3,col4) VALUES (9, ", ", 5, ", ", 8) ON DUPLICATE KEY UPDATE pkey=pkey+10"]
2. rewriteFirstPart : "9, "
3. rewriteRepeatLastPart : ", 8"
4. rewriteNotRepeatLastPart : " ON DUPLICATE KEY UPDATE pkey=pkey+10"

if "allowMultiQueries" option active : Query will be rewritten as : queryParts[0]+parameter[0]+...queryParts[x]+parameter[x]+queryParts[x+1] + ";" + new query... "INSERT INTO MultiTestt3_dupp(col1, pkey,col2,col3,col4) VALUES (9, "+parameter0+", 5, "+parameter1+", 8) ON DUPLICATE KEY UPDATE pkey=pkey+10"

if "rewriteBatchedStatements" option active : Query will be rewritten as : - queryParts[0]+parameter[0]+...queryParts[x]+parameter[x] + ... "("+rewriteFirstPart+parameter[0]+...queryParts[x] +parameter[x]-rewriteNotRepeatLastPart+")"+rewriteNotRepeatLastPart for the example "INSERT INTO MultiTestt3_dupp(col1, pkey,col2,col3,col4) VALUES (9, "+parameter0+", 5, "+parameter1+", 8)"+"("+"9, "+ secondParameter0+", 5, "+secondParameter1"+", 8"+")"+" ON DUPLICATE KEY UPDATE pkey=pkey+10"

### Constructor Summary

Constructors
Constructor and Description
`MariaDbClientParameterizeQuery(String query, boolean noBackslashEscapes, int rewriteOffset)` Constructor.

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `clearParameters()` clears the parameters.
`MariaDbClientParameterizeQuery` `cloneQuery()` Clone query to avoid recreating parts.
`int` `getParamCount()` get the number of parameters in this query.
`ParameterHolder[]` `getParameters()`
`byte[][]` `getQueryPartsArray()`
`int` `getQuerySize()` Return estimated query length.
`byte[]` `getRewriteFirstPart()` Return first identical length of all queries.
`void` `setParameter(int position, ParameterHolder parameter)` Set a parameter to query.
`String` `toString()` toString implementation.
`void` `validate()` Validate that all parameters are set.
`void` `writeFirstRewritePart(OutputStream os)` Write first common part into buffer.
`void` `writeLastRewritePart(OutputStream os)` Write last common part into buffer.
`int` `writeLastRewritePartLength()` Will return identical last part length.
`void` `writeTo(OutputStream os)` Write whole query to buffer.
`void` `writeToRewritablePart(OutputStream os, int rewriteOffset)` Write rewritable specific part of the query.
`int` `writeToRewritablePartLength(int rewriteOffset)` Will return rewrite part length.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### MariaDbClientParameterizeQuery

    public MariaDbClientParameterizeQuery(String query,
                                          boolean noBackslashEscapes,
                                          int rewriteOffset)

Constructor.

Parameters:
  `query` - query string
  `noBackslashEscapes` - must backSlash be escaped
  `rewriteOffset` - first common part index

### Method Detail

#### getQuerySize

    public int getQuerySize()
                     throws IOException

Return estimated query length.

Specified by:
  `getQuerySize` in interface `Query`
Returns:
  length
Throws:
  `IOException` - if parameter approximated length launched exception (stream reading)

#### getRewriteFirstPart

    public byte[] getRewriteFirstPart()

Return first identical length of all queries.

Specified by:
  `getRewriteFirstPart` in interface `ParameterizeQuery`
Returns:
  length

#### cloneQuery

    public MariaDbClientParameterizeQuery cloneQuery()

Clone query to avoid recreating parts.

Returns:
  a clone version.

#### setParameter

    public void setParameter(int position,
                             ParameterHolder parameter)
                      throws SQLException

Set a parameter to query.

Specified by:
  `setParameter` in interface `ParameterizeQuery`
Parameters:
  `position` - the position to set it at
  `parameter` - the parameter to set
Throws:
  `SQLException` - if position is incorrect

#### getParameters

    public ParameterHolder[] getParameters()

Specified by:
  `getParameters` in interface `ParameterizeQuery`

#### clearParameters

    public void clearParameters()

Description copied from interface: `ParameterizeQuery`
clears the parameters.

Specified by:
  `clearParameters` in interface `ParameterizeQuery`

#### validate

    public void validate()
                  throws QueryException

Validate that all parameters are set.

Specified by:
  `validate` in interface `Query`
Throws:
  `QueryException` - if any parameter is missing

#### writeTo

    public void writeTo(OutputStream os)
                 throws IOException

Write whole query to buffer.

Specified by:
  `writeTo` in interface `Query`
Parameters:
  `os` - outputStream
Throws:
  `IOException` - if any error occur during buffer writing

#### writeFirstRewritePart

    public void writeFirstRewritePart(OutputStream os)
                               throws IOException

Write first common part into buffer.

Specified by:
  `writeFirstRewritePart` in interface `Query`
Parameters:
  `os` - outputStream
Throws:
  `IOException` - if any error occur during buffer writing

#### writeLastRewritePart

    public void writeLastRewritePart(OutputStream os)
                              throws IOException

Write last common part into buffer.

Specified by:
  `writeLastRewritePart` in interface `Query`
Parameters:
  `os` - outputStream
Throws:
  `IOException` - if any error occur during buffer writing

#### writeLastRewritePartLength

    public int writeLastRewritePartLength()

Will return identical last part length.

Specified by:
  `writeLastRewritePartLength` in interface `Query`
Returns:
  length

#### writeToRewritablePart

    public void writeToRewritablePart(OutputStream os,
                                      int rewriteOffset)
                               throws IOException

Write rewritable specific part of the query.

Specified by:
  `writeToRewritablePart` in interface `Query`
Parameters:
  `os` - outputStream
  `rewriteOffset` - for compatibility (not used)
Throws:
  `IOException` - if any error occur during writing into buffer.

#### writeToRewritablePartLength

    public int writeToRewritablePartLength(int rewriteOffset)
                                    throws IOException

Will return rewrite part length.

Specified by:
  `writeToRewritablePartLength` in interface `Query`
Parameters:
  `rewriteOffset` - the index position of content change between queries.
Returns:
  length
Throws:
  `IOException` - if parameter approximate length return exception

#### getQueryPartsArray

    public byte[][] getQueryPartsArray()

Specified by:
  `getQueryPartsArray` in interface `ParameterizeQuery`

#### getParamCount

    public int getParamCount()

Description copied from interface: `ParameterizeQuery`
get the number of parameters in this query.

Specified by:
  `getParamCount` in interface `ParameterizeQuery`
Returns:
  number of parameters

#### toString

    public String toString()

toString implementation. Display current sql string.

Overrides:
  `toString` in class `Object`
Returns:
  current sql String.