Class TdsData
Implementation notes:
- Version:
- $Id: TdsData.java,v 1.60.2.3 2009-11-05 10:42:18 ickzon Exp $
- Author:
- Mike Hutchinson, Alin Sinpalean, freeTDS project
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
This class implements a descriptor for TDS data types; -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
private static final int
private static final int
(package private) static final int
Default precision for SQL Server 6.5 and 7.(package private) static final int
Default precision for Sybase and SQL Server 2000 and newer.(package private) static final int
Default Decimal Scale.private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
(package private) static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final TdsData.TypeInfo[]
Array of TDS data type descriptors.private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
TdsData()
Private constructor to prevent users creating an actual instance of this class. -
Method Summary
Modifier and TypeMethodDescriptionprivate static boolean
Establish if a String can be converted to a byte based character set.(package private) static void
fillInType
(ColInfo ci) Fill in the TDS native type code and all other fields for aColInfo
instance with the JDBC type set.(package private) static int
getCollation
(ResponseStream in, ColInfo ci) TDS 8 supplies collation information for character data types.private static Object
getDatetimeValue
(ResponseStream in, int type) Get a DATETIME value from the server response stream.private static Object
getMoneyValue
(ResponseStream in, int type) Read a MONEY value from the server response stream.static String
getMSTypeName
(String typeName, int tdsType) For SQL 2005 This routine will modify the meta data to allow the caller to distinguish between varchar(max) and text or varbinary(max) and image or nvarchar(max) and ntext.(package private) static void
getNativeType
(JtdsConnection connection, ParamInfo pi) Retrieve the TDS native type code for the parameter.(package private) static int
getTds5ParamSize
(String charset, boolean isWideChar, ParamInfo pi, boolean useParamNames) Calculate the size of the parameter descriptor array for TDS 5 packets.static int
getTdsVersion
(int rawTdsVersion) Extract the TDS protocol version from the value returned by the server in the LOGINACK packet.private static Object
getVariant
(JtdsConnection connection, ResponseStream in) Read a MSQL 2000 sql_variant data value from the input stream.(package private) static boolean
isCollation
(ColInfo ci) Retrieve the collation status of the column.(package private) static boolean
isCurrency
(ColInfo ci) Retrieve the currency status of the column.(package private) static boolean
isMSSQL2005Plus
(JtdsConnection connection) (package private) static boolean
isSearchable
(ColInfo ci) Retrieve the searchable status of the column.(package private) static boolean
Retrieve the signed status of the column.(package private) static boolean
Determines whether the column is Unicode encoded.(package private) static void
putCollation
(RequestStream out, ParamInfo pi) TDS 8 requires collation information for char data descriptors.private static void
putDateTimeValue
(RequestStream out, DateTime value) Output a java.sql.Date/Time/Timestamp value to the server as a Sybase datetime value.(package private) static Object
readData
(JtdsConnection connection, ResponseStream in, ColInfo ci) Read the TDS data item from the Response Stream.(package private) static int
readType
(ResponseStream in, ColInfo ci) Read the TDS datastream and populate the ColInfo parameter with data type and related information.(package private) static void
setColumnCharset
(ColInfo ci, JtdsConnection connection) Set thecharsetInfo
field ofci
according to the value of itscollation
field.(package private) static void
writeParam
(RequestStream out, CharsetInfo charsetInfo, byte[] collation, ParamInfo pi) Write a parameter to the server request stream.(package private) static void
writeTds5Param
(RequestStream out, CharsetInfo charsetInfo, ParamInfo pi) Write the actual TDS 5 parameter data.(package private) static void
writeTds5ParamFmt
(RequestStream out, String charset, boolean isWideChar, ParamInfo pi, boolean useParamNames) Write a TDS 5 parameter format descriptor.
-
Field Details
-
SYBCHAR
private static final int SYBCHAR- See Also:
-
SYBVARCHAR
private static final int SYBVARCHAR- See Also:
-
SYBINTN
private static final int SYBINTN- See Also:
-
SYBINT1
private static final int SYBINT1- See Also:
-
SYBDATE
private static final int SYBDATE- See Also:
-
SYBTIME
private static final int SYBTIME- See Also:
-
SYBINT2
private static final int SYBINT2- See Also:
-
SYBINT4
private static final int SYBINT4- See Also:
-
SYBINT8
private static final int SYBINT8- See Also:
-
SYBFLT8
private static final int SYBFLT8- See Also:
-
SYBDATETIME
private static final int SYBDATETIME- See Also:
-
SYBBIT
private static final int SYBBIT- See Also:
-
SYBTEXT
private static final int SYBTEXT- See Also:
-
SYBNTEXT
private static final int SYBNTEXT- See Also:
-
SYBIMAGE
private static final int SYBIMAGE- See Also:
-
SYBMONEY4
private static final int SYBMONEY4- See Also:
-
SYBMONEY
private static final int SYBMONEY- See Also:
-
SYBDATETIME4
private static final int SYBDATETIME4- See Also:
-
SYBREAL
private static final int SYBREAL- See Also:
-
SYBBINARY
private static final int SYBBINARY- See Also:
-
SYBVOID
private static final int SYBVOID- See Also:
-
SYBVARBINARY
private static final int SYBVARBINARY- See Also:
-
SYBNVARCHAR
private static final int SYBNVARCHAR- See Also:
-
SYBBITN
private static final int SYBBITN- See Also:
-
SYBNUMERIC
private static final int SYBNUMERIC- See Also:
-
SYBDECIMAL
private static final int SYBDECIMAL- See Also:
-
SYBFLTN
private static final int SYBFLTN- See Also:
-
SYBMONEYN
private static final int SYBMONEYN- See Also:
-
SYBDATETIMN
private static final int SYBDATETIMN- See Also:
-
SYBDATEN
private static final int SYBDATEN- See Also:
-
SYBTIMEN
private static final int SYBTIMEN- See Also:
-
XSYBCHAR
private static final int XSYBCHAR- See Also:
-
XSYBVARCHAR
private static final int XSYBVARCHAR- See Also:
-
XSYBNVARCHAR
private static final int XSYBNVARCHAR- See Also:
-
XSYBNCHAR
private static final int XSYBNCHAR- See Also:
-
XSYBVARBINARY
private static final int XSYBVARBINARY- See Also:
-
XSYBBINARY
private static final int XSYBBINARY- See Also:
-
SYBUNITEXT
private static final int SYBUNITEXT- See Also:
-
SYBLONGBINARY
private static final int SYBLONGBINARY- See Also:
-
SYBSINT1
private static final int SYBSINT1- See Also:
-
SYBUINT2
private static final int SYBUINT2- See Also:
-
SYBUINT4
private static final int SYBUINT4- See Also:
-
SYBUINT8
private static final int SYBUINT8- See Also:
-
SYBUINTN
private static final int SYBUINTN- See Also:
-
SYBUNIQUE
private static final int SYBUNIQUE- See Also:
-
SYBVARIANT
private static final int SYBVARIANT- See Also:
-
SYBSINT8
private static final int SYBSINT8- See Also:
-
XML
private static final int XML- See Also:
-
DATEN
private static final int DATEN- See Also:
-
TIMEN
private static final int TIMEN- See Also:
-
DATETIME2N
private static final int DATETIME2N- See Also:
-
DATETIMEOFFSETN
private static final int DATETIMEOFFSETN- See Also:
-
SYBLONGDATA
static final int SYBLONGDATA- See Also:
-
UDT_CHAR
private static final int UDT_CHAR- See Also:
-
UDT_VARCHAR
private static final int UDT_VARCHAR- See Also:
-
UDT_BINARY
private static final int UDT_BINARY- See Also:
-
UDT_VARBINARY
private static final int UDT_VARBINARY- See Also:
-
UDT_SYSNAME
private static final int UDT_SYSNAME- See Also:
-
UDT_NCHAR
private static final int UDT_NCHAR- See Also:
-
UDT_NVARCHAR
private static final int UDT_NVARCHAR- See Also:
-
UDT_UNICHAR
private static final int UDT_UNICHAR- See Also:
-
UDT_UNIVARCHAR
private static final int UDT_UNIVARCHAR- See Also:
-
UDT_UNITEXT
private static final int UDT_UNITEXT- See Also:
-
UDT_LONGSYSNAME
private static final int UDT_LONGSYSNAME- See Also:
-
UDT_TIMESTAMP
private static final int UDT_TIMESTAMP- See Also:
-
UDT_NEWSYSNAME
private static final int UDT_NEWSYSNAME- See Also:
-
VAR_MAX
private static final int VAR_MAX- See Also:
-
SYB_LONGVAR_MAX
private static final int SYB_LONGVAR_MAX- See Also:
-
MS_LONGVAR_MAX
private static final int MS_LONGVAR_MAX- See Also:
-
SYB_CHUNK_SIZE
private static final int SYB_CHUNK_SIZE- See Also:
-
types
Array of TDS data type descriptors. -
DEFAULT_SCALE
static final int DEFAULT_SCALEDefault Decimal Scale.- See Also:
-
DEFAULT_PRECISION_28
static final int DEFAULT_PRECISION_28Default precision for SQL Server 6.5 and 7.- See Also:
-
DEFAULT_PRECISION_38
static final int DEFAULT_PRECISION_38Default precision for Sybase and SQL Server 2000 and newer.- See Also:
-
-
Constructor Details
-
TdsData
private TdsData()Private constructor to prevent users creating an actual instance of this class.
-
-
Method Details
-
getCollation
TDS 8 supplies collation information for character data types.- Parameters:
in
- the server response streamci
- the column descriptor- Returns:
- the number of bytes read from the stream as an
int
- Throws:
IOException
-
setColumnCharset
Set thecharsetInfo
field ofci
according to the value of itscollation
field.The
Connection
is used to find out whether a specific charset was requested. In this case, the column charset will be ignored.- Parameters:
ci
- theColInfo
instance to updateconnection
- aConnection
instance to check whether it has a fixed charset or not- Throws:
SQLException
- if aCharsetInfo
is not found for this particular column collation
-
readType
Read the TDS datastream and populate the ColInfo parameter with data type and related information.The type infomation conforms to one of the following formats:
- [int1 type] - eg SYBINT4.
- [int1 type] [int1 buffersize] - eg VARCHAR < 256
- [int1 type] [int2 buffersize] - eg VARCHAR > 255.
- [int1 type] [int4 buffersize] [int1 tabnamelen] [int1*n tabname] - eg text.
- [int1 type] [int4 buffersize] - eg sql_variant.
- [int1 type] [int1 buffersize] [int1 precision] [int1 scale] - eg decimal.
- Parameters:
in
- The server response stream.ci
- The ColInfo column descriptor object.- Returns:
- The number of bytes read from the input stream.
- Throws:
IOException
ProtocolException
-
readData
static Object readData(JtdsConnection connection, ResponseStream in, ColInfo ci) throws IOException, ProtocolException Read the TDS data item from the Response Stream.The data size is either implicit in the type for example fixed size integers, or a count field precedes the actual data. The size of the count field varies with the data type.
- Parameters:
connection
- an object reference to the caller of this method; must be aConnection
,Statement
orResultSet
in
- The server ResponseStream.ci
- The ColInfo column descriptor object.- Returns:
- The data item Object or null.
- Throws:
IOException
ProtocolException
-
isSigned
Retrieve the signed status of the column.- Parameters:
ci
- the column meta data- Returns:
true
if the column is a signed numeric.
-
isCollation
Retrieve the collation status of the column. TDS 8.0 character columns include collation information.- Parameters:
ci
- the column meta data- Returns:
true
if the column requires collation data.
-
isCurrency
Retrieve the currency status of the column.- Parameters:
ci
- The column meta data.- Returns:
boolean
true if the column is a currency type.
-
isSearchable
Retrieve the searchable status of the column.- Parameters:
ci
- the column meta data- Returns:
true
if the column is not a text or image type.
-
isUnicode
Determines whether the column is Unicode encoded.- Parameters:
ci
- the column meta data- Returns:
true
if the column is Unicode encoded
-
fillInType
Fill in the TDS native type code and all other fields for aColInfo
instance with the JDBC type set.- Parameters:
ci
- theColInfo
instance- Throws:
SQLException
-
getNativeType
Retrieve the TDS native type code for the parameter.- Parameters:
connection
- the connectionJDBC objectpi
- the parameter descriptor- Throws:
SQLException
-
getTds5ParamSize
static int getTds5ParamSize(String charset, boolean isWideChar, ParamInfo pi, boolean useParamNames) Calculate the size of the parameter descriptor array for TDS 5 packets.- Parameters:
charset
- The encoding character set.isWideChar
- True if multi byte encoding.pi
- The parameter to describe.useParamNames
- True if named parameters should be used.- Returns:
- The size of the parameter descriptor as an
int
.
-
writeTds5ParamFmt
static void writeTds5ParamFmt(RequestStream out, String charset, boolean isWideChar, ParamInfo pi, boolean useParamNames) throws IOException Write a TDS 5 parameter format descriptor.- Parameters:
out
- The server RequestStream.charset
- The encoding character set.isWideChar
- True if multi byte encoding.pi
- The parameter to describe.useParamNames
- True if named parameters should be used.- Throws:
IOException
-
writeTds5Param
static void writeTds5Param(RequestStream out, CharsetInfo charsetInfo, ParamInfo pi) throws IOException, SQLException Write the actual TDS 5 parameter data.- Parameters:
out
- the server RequestStreamcharsetInfo
- the encoding character setpi
- the parameter to output- Throws:
IOException
SQLException
-
putCollation
TDS 8 requires collation information for char data descriptors.- Parameters:
out
- The Server request stream.pi
- The parameter descriptor.- Throws:
IOException
-
writeParam
static void writeParam(RequestStream out, CharsetInfo charsetInfo, byte[] collation, ParamInfo pi) throws IOException Write a parameter to the server request stream.- Parameters:
out
- the server request streamcharsetInfo
- the default character setcollation
- the default SQL Server 2000 collationpi
- the parameter descriptor- Throws:
IOException
-
getDatetimeValue
private static Object getDatetimeValue(ResponseStream in, int type) throws IOException, ProtocolException Get a DATETIME value from the server response stream.- Parameters:
in
- The server response stream.type
- The TDS data type.- Returns:
- The java.sql.Timestamp value or null.
- Throws:
IOException
ProtocolException
-
putDateTimeValue
Output a java.sql.Date/Time/Timestamp value to the server as a Sybase datetime value.- Parameters:
out
- the server request streamvalue
- the date value to write- Throws:
IOException
-
getMoneyValue
private static Object getMoneyValue(ResponseStream in, int type) throws IOException, ProtocolException Read a MONEY value from the server response stream.- Parameters:
in
- The server response stream.type
- The TDS data type.- Returns:
- The java.math.BigDecimal value or null.
- Throws:
IOException
ProtocolException
-
getVariant
private static Object getVariant(JtdsConnection connection, ResponseStream in) throws IOException, ProtocolException Read a MSQL 2000 sql_variant data value from the input stream.SQL_VARIANT has the following structure:
- INT4 total size of data
- INT1 TDS data type (text/image/ntext/sql_variant not allowed)
- INT1 Length of extra type descriptor information
- Optional additional type info required by some types
- byte[0...n] the actual data
- Parameters:
connection
- used to obtain collation/charset informationin
- the server response stream- Returns:
- the SQL_VARIANT data
- Throws:
IOException
ProtocolException
-
getMSTypeName
For SQL 2005 This routine will modify the meta data to allow the caller to distinguish between varchar(max) and text or varbinary(max) and image or nvarchar(max) and ntext.- Parameters:
typeName
- the SQL type returned by sp_columnstdsType
- the TDS type returned by sp_columns- Returns:
- the (possibly) modified SQL type name as a
String
-
getTdsVersion
public static int getTdsVersion(int rawTdsVersion) Extract the TDS protocol version from the value returned by the server in the LOGINACK packet.- Parameters:
rawTdsVersion
- the TDS protocol version as returned by the server- Returns:
- the jTDS internal value for the protocol version (i.e one of the
Driver.TDSXX
values)
-
canEncode
Establish if a String can be converted to a byte based character set.- Parameters:
value
- The String to test.charset
- The server character set in force.- Returns:
boolean
true if string can be converted.
-
isMSSQL2005Plus
-