public class Utils extends Object
Constructor and Description |
---|
Utils() |
Modifier and Type | Method and Description |
---|---|
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)
Create query part.
|
static Socket |
createSocket(UrlParser urlParser,
String host)
Create socket accordingly to options.
|
static byte[] |
encryptPassword(String password,
byte[] seed)
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
|
static String |
escapeString(String value,
boolean noBackslashEscapes)
Escape String.
|
static TimeZone |
getTimeZone(String id)
Get timezone from Id.
|
static String |
nativeSql(String sql,
boolean noBackslashEscapes)
Escape sql String
|
static String |
replaceFunctionParameter(String functionString)
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
|
static Protocol |
retrieveProxy(UrlParser urlParser,
ReentrantLock lock)
Retreive protocol corresponding to the failover options.
|
public static List<String> createQueryParts(String queryString, boolean noBackslashEscapes)
queryString
- query StringnoBackslashEscapes
- must backslash be escaped.public static String escapeString(String value, boolean noBackslashEscapes)
value
- value to escapenoBackslashEscapes
- must backslash be escapedpublic static byte[] encryptPassword(String password, byte[] seed) throws NoSuchAlgorithmException
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
password
- the password to encryptseed
- the seed to useNoSuchAlgorithmException
- if SHA1 is not available on the platform we are usingpublic static byte[] copyWithLength(byte[] orig, int length)
orig
- the original byte arraylength
- how big the resulting byte array will bepublic static byte[] copyRange(byte[] orig, int from, int to)
orig
- the original byte arrayfrom
- index of first byte in original byte array which will be copiedto
- index of last byte in original byte array which will be copied. This can be
outside of the original byte arraypublic static String replaceFunctionParameter(String functionString)
functionString
- - input stringpublic static String nativeSql(String sql, boolean noBackslashEscapes) throws SQLException
sql
- intial sqlnoBackslashEscapes
- must backslash be escapeSQLException
- if escape sequence is incorrect.public static Protocol retrieveProxy(UrlParser urlParser, ReentrantLock lock) throws QueryException, SQLException
urlParser
- urlParser corresponding to connection url string.lock
- lock to handle thread synchronisationQueryException
- if any error occur during connectionSQLException
- if any error occur during connectionpublic static TimeZone getTimeZone(String id) throws SQLException
id
- timezone idSQLException
- if no timezone is found for this Idpublic static Socket createSocket(UrlParser urlParser, String host) throws IOException
urlParser
- urlParserhost
- hostName ( mandatory only for named pipe)IOException
- if connection error occurCopyright © 2016. All rights reserved.