org.mariadb.jdbc.internal.common

## Class Utils

- java.lang.Object
- - org.mariadb.jdbc.internal.common.Utils

    public class Utils
    extends Object

### Constructor Summary

Constructors
Constructor and Description
`Utils()`

### Method Summary

All Methods Static Methods Concrete Methods
`static byte[]` `copyRange(byte[] orig, int from, int to)` Copies from original byte array to a new byte array.
`static byte[]` `copyWithLength(byte[] orig, int length)` Copies the original byte array content to a new byte array.
`static List<String>` `createQueryParts(String queryString, boolean noBackslashEscapes)`
`static byte[]` `encryptPassword(String password, byte[] seed)` encrypts a password protocol for authentication is like this: 1.
`static String` `escapeString(String s, boolean noBackslashEscapes)`
`static String` `nativeSQL(String sql, boolean noBackslashEscapes)`
`static String` `replaceFunctionParameter(String s)` Helper function to replace function parameters in escaped string.
`static void` `setUrlParameter(String parameter, Properties info)` Adds the parsed parameter to the properties object.
`static void` `setUrlParameters(String urlParameters, Properties info)` Parses the parameters string and sets the corresponding properties in the properties object.

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

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

### Constructor Detail

#### Utils

    public Utils()

### Method Detail

#### createQueryParts

    public static List<String> createQueryParts(String queryString,
                                                boolean noBackslashEscapes)

#### escapeString

    public static String escapeString(String s,
                                      boolean noBackslashEscapes)

#### encryptPassword

    public static byte[] encryptPassword(String password,
                                         byte[] seed)
                                  throws NoSuchAlgorithmException

encrypts a password protocol for authentication is like this: 1. mysql server sends a random array of bytes (the seed) 2. client makes a sha1 digest of the password 3. client hashes the output of 2 4. client digests the seed 5. client updates the digest with the output from 3 6. an xor of the output of 5 and 2 is sent to server 7. server does the same thing and verifies that the scrambled passwords match

Parameters:
  `password` - the password to encrypt
  `seed` - the seed to use
Returns:
  a scrambled password
Throws:
  `NoSuchAlgorithmException` - if SHA1 is not available on the platform we are using

#### copyWithLength

    public static byte[] copyWithLength(byte[] orig,
                                        int length)

Copies the original byte array content to a new byte array. The resulting byte array is always "length" size. If length is smaller than the original byte array, the resulting byte array is truncated. If length is bigger than the original byte array, the resulting byte array is filled with zero bytes.

Parameters:
  `orig` - the original byte array
  `length` - how big the resulting byte array will be
Returns:
  the copied byte array

#### copyRange

    public static byte[] copyRange(byte[] orig,
                                   int from,
                                   int to)

Copies from original byte array to a new byte array. The resulting byte array is always "to-from" size.

Parameters:
  `orig` - the original byte array
  `from` - index of first byte in original byte array which will be copied
  `to` - index of last byte in original byte array which will be copied. This can be outside of the original byte array
Returns:
  resulting array

#### replaceFunctionParameter

    public static String replaceFunctionParameter(String s)

Helper function to replace function parameters in escaped string. 3 functions are handles : - CONVERT(value, type) , we replace SQL_XXX types with XXX, i.e SQL_INTEGER with INTEGER - TIMESTAMPDIFF(type, ...) or TIMESTAMPADD(type, ...) , we replace SQL_TSI_XXX in type with XXX, i.e SQL_TSI_HOUR with HOUR

Parameters:
  `s` - - input string
Returns:
  unescaped string

#### nativeSQL

    public static String nativeSQL(String sql,
                                   boolean noBackslashEscapes)
                            throws SQLException

Throws:
  `SQLException`

#### setUrlParameter

    public static void setUrlParameter(String parameter,
                                       Properties info)

Adds the parsed parameter to the properties object.

Parameters:
  `parameter` - a key=value pair
  `info` - the properties object

#### setUrlParameters

    public static void setUrlParameters(String urlParameters,
                                        Properties info)

Parses the parameters string and sets the corresponding properties in the properties object.

Parameters:
  `urlParameters` - the parameters string
  `info` - the properties object