InformationType Object
30 | *
31 | * @return Name of Information Type
32 | */
33 | public String getName() {
34 | return name;
35 | }
36 |
37 | /**
38 | * Returns the ID for this InformationType object
39 | *
40 | * @return ID of Information Type
41 | */
42 | public String getId() {
43 | return id;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/test/java/com/microsoft/sqlserver/testframework/AbstractParentWrapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
3 | * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
4 | */
5 |
6 | package com.microsoft.sqlserver.testframework;
7 |
8 | /**
9 | * Stores the parent class. For connection parent is null; for Statement, Connection is parent; for ResultSet, Statement
10 | * is parent
11 | */
12 | public abstract class AbstractParentWrapper {
13 | static final int ENGINE_EDITION_FOR_SQL_AZURE = 5;
14 | static final int ENGINE_EDITION_FOR_SQL_AZURE_DW = 6;
15 |
16 | AbstractParentWrapper parent = null;
17 | Object internal = null;
18 | String name = null;
19 |
20 | AbstractParentWrapper(AbstractParentWrapper parent, Object internal, String name) {
21 | this.parent = parent;
22 | this.internal = internal;
23 | this.name = name;
24 | }
25 |
26 | void setInternal(Object internal) {
27 | this.internal = internal;
28 | }
29 |
30 | public Object product() {
31 | return internal;
32 | }
33 |
34 | public AbstractParentWrapper parent() {
35 | return parent;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/test/java/com/microsoft/sqlserver/testframework/DBCoercion.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Microsoft JDBC Driver for SQL Server Copyright(c) 2016 Microsoft Corporation All rights reserved. This program is
3 | * made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
4 | */
5 | package com.microsoft.sqlserver.testframework;
6 |
7 | import java.util.BitSet;
8 |
9 |
10 | public class DBCoercion {
11 | Class> type = null;
12 | protected BitSet flags = new BitSet();
13 | protected String name = null;
14 |
15 | /**
16 | *
17 | * @param type
18 | */
19 | public DBCoercion(Class> type) {
20 | this(type, new int[] {DBConstants.GET_COERCION});
21 | }
22 |
23 | /**
24 | *
25 | * @param type
26 | * @param tempflags
27 | */
28 | public DBCoercion(Class> type, int[] tempflags) {
29 | name = type.toString();
30 | this.type = type;
31 | for (int tempflag : tempflags)
32 | flags.set(tempflag);
33 | }
34 |
35 | /**
36 | * @return type
37 | */
38 | public Class> type() {
39 | return type;
40 | }
41 |
42 | /**
43 | * @return
44 | */
45 | public BitSet flags() {
46 | return flags;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerEncryptionAlgorithm.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
3 | * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
4 | */
5 |
6 | package com.microsoft.sqlserver.jdbc;
7 |
8 | /*
9 | * Abstract base class for all AE encryption algorithms. It exposes two functions 1. encryptData - This function is used
10 | * by the driver under the covers to transparently encrypt AE enabled column data. 2. decryptData - This function is
11 | * used by the driver under the covers to transparently decrypt AE enabled column data.
12 | */
13 | abstract class SQLServerEncryptionAlgorithm {
14 |
15 | /**
16 | * Perform encryption of the plain text
17 | *
18 | * @param plainText
19 | * data to be encrypted
20 | * @return cipher text after encryption
21 | */
22 | abstract byte[] encryptData(byte[] plainText) throws SQLServerException;
23 |
24 | /**
25 | * Decrypt cipher text to plain text
26 | *
27 | * @param cipherText
28 | * data to be decrypted
29 | * @return plain text after decryption
30 | */
31 | abstract byte[] decryptData(byte[] cipherText) throws SQLServerException;
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSymmetricKey.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
3 | * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
4 | */
5 |
6 | package com.microsoft.sqlserver.jdbc;
7 |
8 | /**
9 | *
10 | * Base class which represents Symmetric key
11 | *
12 | */
13 | class SQLServerSymmetricKey {
14 | private byte[] rootKey;
15 |
16 | SQLServerSymmetricKey(byte[] rootKey) throws SQLServerException {
17 | if (null == rootKey) {
18 | throw new SQLServerException(this, SQLServerException.getErrString("R_NullColumnEncryptionKey"), null, 0,
19 | false);
20 | } else if (0 == rootKey.length) {
21 | throw new SQLServerException(this, SQLServerException.getErrString("R_EmptyColumnEncryptionKey"), null, 0,
22 | false);
23 | }
24 | this.rootKey = rootKey;
25 | }
26 |
27 | byte[] getRootKey() {
28 | return rootKey;
29 | }
30 |
31 | int length() {
32 | return rootKey.length;
33 | }
34 |
35 | void zeroOutKey() {
36 | for (int i = 0; i < rootKey.length; i++) {
37 | rootKey[i] = (byte) 0;
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/microsoft/sqlserver/jdbc/dataclassification/InformationType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
3 | * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
4 | */
5 |
6 | package com.microsoft.sqlserver.jdbc.dataclassification;
7 |
8 | /**
9 | * Represents the Data Classification Information Types as received from SQL Server for the active resultSet
10 | */
11 | public class InformationType {
12 | private String name;
13 | private String id;
14 |
15 | /**
16 | * Constructs a InformationType
17 | *
18 | * @param name
19 | * Name of Information Type
20 | * @param id
21 | * ID of Information Type
22 | */
23 | public InformationType(String name, String id) {
24 | this.name = name;
25 | this.id = id;
26 | }
27 |
28 | /**
29 | * Returns the name of this InformationType Object
30 | *
31 | * @return Name of Information Type
32 | */
33 | public String getName() {
34 | return name;
35 | }
36 |
37 | /**
38 | * Returns the ID for this InformationType object
39 | *
40 | * @return ID of Information Type
41 | */
42 | public String getId() {
43 | return id;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/microsoft/sqlserver/jdbc/spatialdatatypes/WKBLinearRing.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
3 | * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
4 | */
5 |
6 | package com.microsoft.sqlserver.jdbc.spatialdatatypes;
7 |
8 | /**
9 | * Represents the internal makings of a WKB Linear Ring.
10 | *
11 | */
12 | public class WKBLinearRing {
13 | private final int numPoints;
14 | private final WKBPoint[] wkbPoints;
15 |
16 | /**
17 | * Creates a WKB Linear Ring object
18 | *
19 | * @param numPoints
20 | * num points
21 | * @param wkbPoints
22 | * wkb points
23 | */
24 | public WKBLinearRing(int numPoints, WKBPoint[] wkbPoints) {
25 | this.numPoints = numPoints;
26 | this.wkbPoints = wkbPoints;
27 | }
28 |
29 | /**
30 | * Returns the number of points.
31 | *
32 | * @return int number of points.
33 | */
34 | public int getNumPoints() {
35 | return numPoints;
36 | }
37 |
38 | /**
39 | * Returns the WKB points.
40 | *
41 | * @return WKBPoint[] the WKB points.
42 | */
43 | public WKBPoint[] getWkbPoints() {
44 | return wkbPoints;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/test/resources/BulkCopyCSVTestInput.csv:
--------------------------------------------------------------------------------
1 | bit,tinyint,smallint,int,bigint,float(53),real,decimal(18-6),numeric(18-4),money(20-4),smallmoney(20-4),char(11),nchar(10),varchar(50),nvarchar(10),binary(5),varbinary(25),date,datetime,datetime2(7),smalldatetime,datetimeoffset(7),time(16-7)
2 | 1,2,-32768,0,0,-1.78E307,-3.4E38,22.335600,22.3356,-922337203685477.5808,-214748.3648,a5()b,௵ஷஇமண,test to test csv files,ࢨहश,6163686974,6163686974,1922-11-02,2004-05-23 14:25:10.487,2007-05-02 19:58:47.1234567,2004-05-23 14:25:00.0,2025-12-10 12:32:10.1234567 +01:00,12:23:48.1234567
3 | ,,,,,,,,,,,,,,,,,,,,,,
4 | 0,5,32767,1,12,-2.23E-308,-1.18E-38,33.552695,33.5526,922337203685477.5807,0.0000,what!,ৡਐਲ,123 norma black street,Ӧ NӦ,5445535455,54455354,9999-12-31,9999-12-31 23:59:59.997,9999-12-31 23:59:59.9999999,2079-06-06 23:59:00.0,9999-12-31 23:59:00.0000000 +00:00,23:59:59.9990000
5 | 0,255,0,-2147483648,-9223372036854775808,2.23E-308,0.0,33.503288,33.5032,0.0000,1.0011,no way,Ӧ NӦ,baker street Mr.Homls,àĂ,303C2D3988,303C2D39,0001-01-01,1973-01-01 00:00:00.0,0001-01-01 00:00:00.0000000,1900-01-01 00:00:00.0,0001-01-01 00:00:00.0000000 +00:00,00:00:00.0000000
6 | 1,5,0,2147483647,9223372036854775807,12.0,3.4E38,33.000501,33.0005,1.0001,214748.3647,l l l l l |,Ȣʗʘ,test to test csv files,௵ஷஇமண,7E7D7A7B20,7E7D7A7B,2017-04-18,2014-10-11 20:13:12.123,2017-10-12 09:38:17.7654321,2014-10-11 20:13:00.0,2017-01-06 10:52:20.7654321 +03:00,18:02:16.7654321
7 |
--------------------------------------------------------------------------------
/src/main/java/com/microsoft/sqlserver/jdbc/dataclassification/ColumnSensitivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
3 | * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
4 | */
5 |
6 | package com.microsoft.sqlserver.jdbc.dataclassification;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 |
12 | /**
13 | * Represents the Data Classification Sensitivity Information for columns as configured in Database.
14 | */
15 | public class ColumnSensitivity {
16 | private ListColumnSensitivity
30 | * information
31 | *
32 | * @return sensitivityProperties for this Class Object
33 | */
34 | public List14 | * {@link Weigher} is a simple interface for determining how many units of capacity an entry consumes. Depending on which concrete Weigher class is 15 | * used, an entry may consume a different amount of space within the cache. The {@link Weighers} class provides utility methods for obtaining the most 16 | * common kinds of implementations. 17 | *
18 | * {@link EvictionListener} provides the ability to be notified when an entry is evicted from the map. An eviction occurs when the entry was 19 | * automatically removed due to the map exceeding a capacity threshold. It is not called when an entry was explicitly removed. 20 | *
21 | * The {@link ConcurrentLinkedHashMap} class supplies an efficient, scalable, thread-safe, bounded map. As with the
22 | * Java Collections Framework the "Concurrent" prefix is used to indicate that the map is not governed by a single exclusion lock.
23 | *
24 | * @see http://code.google.com/p/concurrentlinkedhashmap/
25 | */
26 | package mssql.googlecode.concurrentlinkedhashmap;
27 |
--------------------------------------------------------------------------------
/src/samples/alwaysencrypted/pom.xml:
--------------------------------------------------------------------------------
1 |
57 |
--------------------------------------------------------------------------------
/src/test/java/com/microsoft/sqlserver/testframework/sqlType/SqlFloat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
3 | * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
4 | */
5 |
6 | package com.microsoft.sqlserver.testframework.sqlType;
7 |
8 | import java.sql.JDBCType;
9 | import java.util.concurrent.ThreadLocalRandom;
10 |
11 |
12 | public class SqlFloat extends SqlType {
13 |
14 | // called from real
15 | SqlFloat(String name, JDBCType jdbctype, int precision, Object min, Object max, Object nullvalue,
16 | VariableLengthType variableLengthType, Class type) {
17 | super(name, jdbctype, precision, 0, min, max, nullvalue, variableLengthType, type);
18 | generatePrecision();
19 | }
20 |
21 | public SqlFloat() {
22 | super("float", JDBCType.DOUBLE, 53, 0, SqlTypeValue.FLOAT.minValue, SqlTypeValue.FLOAT.maxValue,
23 | SqlTypeValue.FLOAT.nullValue, VariableLengthType.Precision, Double.class);
24 | generatePrecision();
25 | }
26 |
27 | public Object createdata() {
28 | // for float in SQL Server, any precision <=24 is considered as real so the value must be within
29 | // SqlTypeValue.REAL.minValue/maxValue however this needs to be bounded for nextDouble origin and bound params
30 | if (precision > 24) {
31 | minvalue = ((Double) minvalue < Double.MIN_VALUE) ? Double.MIN_VALUE : minvalue;
32 | maxvalue = ((Double) maxvalue > Double.MAX_VALUE) ? Double.MAX_VALUE : maxvalue;
33 | return ThreadLocalRandom.current().nextDouble(((Double) minvalue), ((Double) maxvalue));
34 | } else {
35 |
36 | return ThreadLocalRandom.current().nextDouble((Float) SqlTypeValue.REAL.minValue,
37 | (Float) SqlTypeValue.REAL.maxValue);
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/test/java/com/microsoft/sqlserver/testframework/PrepUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Microsoft JDBC Driver for SQL Server Copyright(c) 2016 Microsoft Corporation All rights reserved. This program is
3 | * made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
4 | */
5 | package com.microsoft.sqlserver.testframework;
6 |
7 | import java.sql.DriverManager;
8 | import java.sql.SQLException;
9 | import java.util.Properties;
10 |
11 | import com.microsoft.sqlserver.jdbc.SQLServerConnection;
12 |
13 |
14 | /**
15 | * Utility Class for Tests. This will contains methods like Create Table, Drop Table, Initialize connection, create
16 | * statement etc. logger settings etc.
17 | *
18 | * TODO : We can delete PrepUtil & move getConnection method in {@link DBEngine}
19 | *
20 | * @since 6.1.2
21 | */
22 | public class PrepUtil {
23 |
24 | private PrepUtil() {
25 | // Just hide to restrict constructor invocation.
26 | }
27 |
28 | /**
29 | * It will create {@link SQLServerConnection} TODO : Think of AE functionality on off etc.
30 | *
31 | * @param connectionString
32 | * @param info
33 | * @return {@link SQLServerConnection}
34 | * @throws SQLException
35 | * @throws ClassNotFoundException
36 | */
37 | public static SQLServerConnection getConnection(String connectionString, Properties info) throws SQLException {
38 | return (SQLServerConnection) DriverManager.getConnection(connectionString, info);
39 | }
40 |
41 | /**
42 | * It will create {@link SQLServerConnection}
43 | *
44 | * @param connectionString
45 | * @return {@link SQLServerConnection}
46 | * @throws SQLException
47 | * @throws ClassNotFoundException
48 | */
49 | public static SQLServerConnection getConnection(String connectionString) throws SQLException {
50 | return getConnection(connectionString, null);
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/com/microsoft/sqlserver/jdbc/spatialdatatypes/Shape.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
3 | * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
4 | */
5 |
6 | package com.microsoft.sqlserver.jdbc.spatialdatatypes;
7 |
8 | /**
9 | * Represents the internal makings of a Shape.
10 | *
11 | */
12 | public class Shape {
13 | private int parentOffset;
14 | private int figureOffset;
15 | private byte openGISType;
16 |
17 | /**
18 | * Creates a Shape object
19 | *
20 | * @param parentOffset
21 | * parent offset
22 | * @param figureOffset
23 | * figure offset
24 | * @param openGISType
25 | * open GIS type
26 | */
27 | public Shape(int parentOffset, int figureOffset, byte openGISType) {
28 | this.parentOffset = parentOffset;
29 | this.figureOffset = figureOffset;
30 | this.openGISType = openGISType;
31 | }
32 |
33 | /**
34 | * Returns the parentOffset value.
35 | *
36 | * @return int parentOffset value.
37 | */
38 | public int getParentOffset() {
39 | return parentOffset;
40 | }
41 |
42 | /**
43 | * Returns the figureOffset value.
44 | *
45 | * @return int figureOffset value.
46 | */
47 | public int getFigureOffset() {
48 | return figureOffset;
49 | }
50 |
51 | /**
52 | * Returns the openGISType value.
53 | *
54 | * @return byte openGISType value.
55 | */
56 | public byte getOpenGISType() {
57 | return openGISType;
58 | }
59 |
60 | /**
61 | * Sets the figureOffset value.
62 | *
63 | * @param fo
64 | * figureOffset value.
65 | */
66 | public void setFigureOffset(int fo) {
67 | figureOffset = fo;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/test/java/com/microsoft/sqlserver/testframework/DBConstants.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.sqlserver.testframework;
2 |
3 | import java.sql.ResultSet;
4 |
5 |
6 | public class DBConstants {
7 |
8 | // Coercion Flags
9 | public static final int GET_COERCION = 1;
10 | public static final int UPDATE_COERCION = 2;
11 | public static final int SET_COERCION = 3;
12 | public static final int SETOBJECT_COERCION = 4;
13 | public static final int REG_COERCION = 5;
14 | public static final int GETPARAM_COERCION = 6;
15 | public static final int UPDATEOBJECT_COERCION = 7;
16 | public static final int ALL_COERCION = 8;
17 | public static final int STREAM_COERCION = 9;
18 | public static final int CHAR_COERCION = 10;
19 | public static final int NCHAR_COERCION = 11;
20 | public static final int ASCII_COERCION = 12;
21 |
22 | // ResultSet Flags
23 | public static final int RESULTSET_TYPE_DYNAMIC = ResultSet.TYPE_SCROLL_SENSITIVE + 1;
24 | public static final int RESULTSET_CONCUR_OPTIMISTIC = ResultSet.CONCUR_UPDATABLE + 2;
25 | public static final int RESULTSET_TYPE_CURSOR_FORWARDONLY = ResultSet.TYPE_FORWARD_ONLY + 1001;
26 | public static final int RESULTSET_TYPE_FORWARD_ONLY = ResultSet.TYPE_FORWARD_ONLY;
27 | public static final int RESULTSET_CONCUR_READ_ONLY = ResultSet.CONCUR_READ_ONLY;
28 | public static final int RESULTSET_TYPE_SCROLL_INSENSITIVE = ResultSet.TYPE_SCROLL_INSENSITIVE;
29 | public static final int RESULTSET_TYPE_SCROLL_SENSITIVE = ResultSet.TYPE_SCROLL_SENSITIVE;
30 | public static final int RESULTSET_CONCUR_UPDATABLE = ResultSet.CONCUR_UPDATABLE;
31 | public static final int RESULTSET_TYPE_DIRECT_FORWARDONLY = ResultSet.TYPE_FORWARD_ONLY + 1000;
32 |
33 | // Statement Flags
34 | public static final int STATEMENT = 0;
35 | public static final int PREPAREDSTATEMENT = 1;
36 | public static final int CALLABLESTATEMENT = 2;
37 | public static final int ALL_STATEMENTS = 3;
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/com/microsoft/sqlserver/jdbc/StreamTabName.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
3 | * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
4 | */
5 |
6 | package com.microsoft.sqlserver.jdbc;
7 |
8 | /**
9 | * StreamTabName interprets the data stream from a TABNAME TDS token
10 | *
11 | */
12 |
13 | final class StreamTabName extends StreamPacket {
14 | private TDSReader tdsReader;
15 | private TDSReaderMark tableNamesMark;
16 |
17 | StreamTabName() {
18 | super(TDS.TDS_TABNAME);
19 | }
20 |
21 | void setFromTDS(TDSReader tdsReader) throws SQLServerException {
22 | if (TDS.TDS_TABNAME != tdsReader.readUnsignedByte())
23 | assert false : "Not a TABNAME token";
24 |
25 | this.tdsReader = tdsReader;
26 | int tokenLength = tdsReader.readUnsignedShort();
27 | tableNamesMark = tdsReader.mark();
28 | tdsReader.skip(tokenLength);
29 | }
30 |
31 | void applyTo(Column[] columns, int numTables) throws SQLServerException {
32 | TDSReaderMark currentMark = tdsReader.mark();
33 | tdsReader.reset(tableNamesMark);
34 |
35 | // Read in all of the multi-part table names. The number of table
36 | // names to expect is determined in advance. It is computed as a side
37 | // effect of processing the COLINFO token that preceds this TABNAME token.
38 | SQLIdentifier[] tableNames = new SQLIdentifier[numTables];
39 | for (int i = 0; i < numTables; i++)
40 | tableNames[i] = tdsReader.readSQLIdentifier();
41 |
42 | // Apply the table names to their appropriate columns
43 | for (Column col : columns) {
44 | if (col.getTableNum() > 0)
45 | col.setTableName(tableNames[col.getTableNum() - 1]);
46 | }
47 |
48 | tdsReader.reset(currentMark);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/samples/dataclassification/pom.xml:
--------------------------------------------------------------------------------
1 |
59 |
--------------------------------------------------------------------------------
/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerWarning.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
3 | * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
4 | */
5 | package com.microsoft.sqlserver.jdbc;
6 |
7 | import java.sql.SQLWarning;
8 |
9 |
10 | /**
11 | * Holds information about SQL Server messages that is considered as Informational Messages (normally if SQL Server Severity is at 10)
12 | *
13 | * Instead of just holding the SQL Server message (like a normal SQLWarning, it also holds all the 14 | * SQL Servers extended information, like: ErrorSeverity, ServerName, ProcName etc 15 | *
16 | * This enables client to print out extra information about the message.
17 | * Like: In what procedure was the message produced.
18 | */
19 | public class SQLServerWarning extends SQLWarning {
20 | private static final long serialVersionUID = -5212432397705929142L;
21 |
22 | /** SQL server error */
23 | private SQLServerError sqlServerError;
24 |
25 | /**
26 | * Create a SQLWarning from an SQLServerError object
27 | *
28 | * @param sqlServerError
29 | * SQL Server error
30 | */
31 | public SQLServerWarning(SQLServerError sqlServerError) {
32 | super(sqlServerError.getErrorMessage(), SQLServerException.generateStateCode(null,
33 | sqlServerError.getErrorNumber(), sqlServerError.getErrorState()), sqlServerError.getErrorNumber(),
34 | null);
35 |
36 | this.sqlServerError = sqlServerError;
37 | }
38 |
39 | /**
40 | * Returns SQLServerError object containing detailed info about exception as received from SQL Server. This API
41 | * returns null if no server error has occurred.
42 | *
43 | * @return SQLServerError
44 | */
45 | public SQLServerError getSQLServerError() {
46 | return sqlServerError;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/test/java/com/microsoft/sqlserver/jdbc/ssl/trustmanager/TrustManagerWithConstructorArg.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
3 | * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
4 | */
5 |
6 | package com.microsoft.sqlserver.jdbc.ssl.trustmanager;
7 |
8 | import java.io.IOException;
9 | import java.security.GeneralSecurityException;
10 | import java.security.cert.CertificateException;
11 | import java.security.cert.X509Certificate;
12 |
13 | import javax.net.ssl.X509TrustManager;
14 |
15 |
16 | /**
17 | * This class implements an X509TrustManager that always accepts the X509Certificate chain offered to it.
18 | *
19 | * The constructor argument certToTrust is a dummy string used to test trustManagerConstructorArg.
20 | *
21 | */
22 |
23 | public class TrustManagerWithConstructorArg implements X509TrustManager {
24 | X509Certificate cert;
25 | X509TrustManager trustManager;
26 |
27 | public TrustManagerWithConstructorArg(String certToTrust) throws IOException, GeneralSecurityException {
28 | trustManager = new X509TrustManager() {
29 | @Override
30 | public X509Certificate[] getAcceptedIssuers() {
31 | return null;
32 | }
33 |
34 | @Override
35 | public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {}
36 |
37 | @Override
38 | public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {}
39 | };
40 | }
41 |
42 | @Override
43 | public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {}
44 |
45 | @Override
46 | public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {}
47 |
48 | @Override
49 | public X509Certificate[] getAcceptedIssuers() {
50 | return null;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/com/microsoft/sqlserver/jdbc/XMLTDSHeader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
3 | * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
4 | */
5 |
6 | package com.microsoft.sqlserver.jdbc;
7 |
8 | /**
9 | * XMLTDSHeader is helper class used to read and write the XML TDS header from a TDS stream.
10 | *
11 | * Typical XML headers ->
12 | *
13 | * XML with schema.
14 | *
15 | * F1 01 <- SCHEMA_PRESENT=1 03|54 00 44 00 53 00 <- DBNAME (1 byte length in UNICODE chars) 03|64 00 62 00 6F 00 <-
16 | * OWNING_SCHEMA (1 byte length in UNICODE chars) 09 00|53 00 68 00 69 00 70 00 4F 00 72 00 64 00 65 00 72 00 <-
17 | * XML_SCHEMA_COLLECTION (2 byte length in UNICODE chars)
18 | *
19 | * XML without any schema (this is common as well).
20 | *
21 | * F1 00 <- SCHEMA_PRESENT=0
22 | *
23 | */
24 |
25 | final class XMLTDSHeader {
26 | @SuppressWarnings("unused")
27 | private final String databaseName; // Database name where XML schema resides.
28 | @SuppressWarnings("unused")
29 | private final String owningSchema; // Owner of XML schema (like dbo for example).
30 | @SuppressWarnings("unused")
31 | private final String xmlSchemaCollection; // Name of XML schema collection.
32 |
33 | XMLTDSHeader(TDSReader tdsReader) throws SQLServerException {
34 | // Check schema present byte.
35 | if (0 != tdsReader.readUnsignedByte()) {
36 | // Ok, we have a schema present, process it.
37 | databaseName = tdsReader.readUnicodeString(tdsReader.readUnsignedByte());
38 | owningSchema = tdsReader.readUnicodeString(tdsReader.readUnsignedByte());
39 | xmlSchemaCollection = tdsReader.readUnicodeString(tdsReader.readUnsignedShort());
40 | } else {
41 | xmlSchemaCollection = null;
42 | owningSchema = null;
43 | databaseName = null;
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/test/java/com/microsoft/sqlserver/testframework/DBCallableStatement.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Microsoft JDBC Driver for SQL Server Copyright(c) 2016 Microsoft Corporation All rights reserved. This program is
3 | * made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
4 | */
5 | package com.microsoft.sqlserver.testframework;
6 |
7 | import java.sql.CallableStatement;
8 | import java.sql.Connection;
9 | import java.sql.PreparedStatement;
10 | import java.sql.SQLException;
11 |
12 |
13 | /**
14 | * Wrapper class CallableStatement
15 | *
16 | */
17 | public class DBCallableStatement extends AbstractParentWrapper {
18 |
19 | PreparedStatement cstmt = null;
20 |
21 | /**
22 | *
23 | */
24 | public DBCallableStatement(DBConnection dbconnection) {
25 | super(dbconnection, null, "preparedStatement");
26 | }
27 |
28 | /**
29 | * @param parent
30 | * @param internal
31 | * @param name
32 | */
33 | DBCallableStatement(AbstractParentWrapper parent, Object internal, String name) {
34 | super(parent, internal, name);
35 | }
36 |
37 | DBCallableStatement prepareCall(String query) throws SQLException {
38 | cstmt = ((Connection) parent().product()).prepareCall(query);
39 | setInternal(cstmt);
40 | return this;
41 | }
42 |
43 | /**
44 | *
45 | * @param x
46 | * @param y
47 | * @param z
48 | * @throws SQLException
49 | */
50 | public void registerOutParameter(String x, int y, int z) throws SQLException {
51 | // product
52 | ((CallableStatement) product()).registerOutParameter(x, y, z);
53 | }
54 |
55 | /**
56 | *
57 | * @param index
58 | * @param sqltype
59 | * @throws SQLException
60 | */
61 | public void registerOutParameter(int index, int sqltype) throws SQLException {
62 | ((CallableStatement) product()).registerOutParameter(index, sqltype);
63 |
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/mssql/googlecode/concurrentlinkedhashmap/EvictionListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Google Inc. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | * Unless required by applicable law or agreed to in writing, software
8 | * distributed under the License is distributed on an "AS IS" BASIS,
9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | * See the License for the specific language governing permissions and
11 | * limitations under the License.
12 | */
13 | package mssql.googlecode.concurrentlinkedhashmap;
14 |
15 | /**
16 | * A listener registered for notification when an entry is evicted. An instance
17 | * may be called concurrently by multiple threads to process entries. An
18 | * implementation should avoid performing blocking calls or synchronizing on
19 | * shared resources.
20 | *
21 | * The listener is invoked by {@link ConcurrentLinkedHashMap} on a caller's
22 | * thread and will not block other threads from operating on the map. An
23 | * implementation should be aware that the caller's thread will not expect
24 | * long execution times or failures as a side effect of the listener being
25 | * notified. Execution safety and a fast turn around time can be achieved by
26 | * performing the operation asynchronously, such as by submitting a task to an
27 | * {@link java.util.concurrent.ExecutorService}.
28 | *
29 | * @author ben.manes@gmail.com (Ben Manes)
30 | * @see
31 | * http://code.google.com/p/concurrentlinkedhashmap/
32 | */
33 | public interface EvictionListener
18 | * Response buffering controls the driver's buffering of responses from SQL Server.
19 | *
20 | * Possible values are:
21 | *
22 | * "full" - Fully buffer the response at execution time.
23 | *
24 | * "adaptive" - Data Pipe adaptive buffering
25 | *
26 | * @param value
27 | * A String that contains the response buffering mode. The valid mode can be one of the following
28 | * case-insensitive Strings: full or adaptive.
29 | * @throws SQLServerException
30 | * If there are any errors in setting the response buffering mode.
31 | */
32 | void setResponseBuffering(String value) throws SQLServerException;
33 |
34 | /**
35 | * Returns the response buffering mode for this SQLServerStatement object.
36 | *
37 | * @return A String that contains a lower-case full or adaptive.
38 | * @throws SQLServerException
39 | * If there are any errors in retrieving the response buffering mode.
40 | */
41 | String getResponseBuffering() throws SQLServerException;
42 |
43 | /**
44 | * Returns the
15 | * The API javadoc for JDBC API methods that this class implements are not repeated here. Please see Sun's JDBC API
16 | * interfaces javadoc for those details.
17 | */
18 |
19 | public final class SQLServerSavepoint implements ISQLServerSavepoint {
20 | /**
21 | * Always update serialVersionUID when prompted.
22 | */
23 | private static final long serialVersionUID = 1857415943191289598L;
24 |
25 | /** sName */
26 | private final String sName;
27 |
28 | /** nID */
29 | private final int nId;
30 |
31 | /** connection */
32 | private final SQLServerConnection con;
33 |
34 | /**
35 | * Constructs a SQLServerSavepoint.
36 | *
37 | * @param con
38 | * the connection
39 | * @param sName
40 | * the savepoint name
41 | */
42 | public SQLServerSavepoint(SQLServerConnection con, String sName) {
43 | this.con = con;
44 | if (sName == null) {
45 | nId = con.getNextSavepointId();
46 | this.sName = null;
47 | } else {
48 | this.sName = sName;
49 | nId = 0;
50 | }
51 | }
52 |
53 | @Override
54 | public String getSavepointName() throws SQLServerException {
55 | if (sName == null)
56 | SQLServerException.makeFromDriverError(con, null, SQLServerException.getErrString("R_savepointNotNamed"),
57 | null, false);
58 | return sName;
59 | }
60 |
61 | @Override
62 | public String getLabel() {
63 | if (sName == null)
64 | return "S" + nId;
65 | else
66 | return sName;
67 | }
68 |
69 | @Override
70 | public boolean isNamed() {
71 | return sName != null;
72 | }
73 |
74 | @Override
75 | public int getSavepointId() throws SQLServerException {
76 | if (sName != null) {
77 | MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_savepointNamed"));
78 | Object[] msgArgs = {sName};
79 | SQLServerException.makeFromDriverError(con, null, form.format(msgArgs), null, false);
80 | }
81 | return nId;
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerBulkData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
3 | * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
4 | */
5 |
6 | package com.microsoft.sqlserver.jdbc;
7 |
8 | import java.io.Serializable;
9 | import java.sql.SQLException;
10 |
11 |
12 | /**
13 | * Provides an interface used to create classes that read in data from any source (such as a file) and allows a
14 | * SQLServerBulkCopy class to write the data to SQL Server tables.
15 | */
16 | public interface ISQLServerBulkData extends Serializable {
17 |
18 | /**
19 | * Returns the ordinals for each of the columns represented in this data record.
20 | *
21 | * @return Set of ordinals for the columns.
22 | */
23 | java.util.SetSensitivityProperty Object
47 | *
48 | * @return label
49 | */
50 | public Label getLabel() {
51 | return label;
52 | }
53 |
54 | /**
55 | * Returns the information type data for this SensitivityProperty Object
56 | *
57 | * @return informationType
58 | */
59 | public InformationType getInformationType() {
60 | return informationType;
61 | }
62 |
63 | /**
64 | * Returns the sensitivity rank for this SensitivityProperty Object
65 | *
66 | * @return sensitivityRank
67 | */
68 | public int getSensitivityRank() {
69 | return sensitivityRank;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/com/microsoft/sqlserver/jdbc/ServerPortPlaceHolder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
3 | * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
4 | */
5 |
6 | package com.microsoft.sqlserver.jdbc;
7 |
8 | import java.io.Serializable;
9 |
10 |
11 | /**
12 | * A simple readonly placeholder class to store the current server info. We need this class so during a connection open
13 | * we can keep a copy of the current failover info stable This is also used to keep the standalone primary server
14 | * connection information.
15 | */
16 | final class ServerPortPlaceHolder implements Serializable {
17 | /**
18 | * Always update serialVersionUID when prompted.
19 | */
20 | private static final long serialVersionUID = 7393779415545731523L;
21 |
22 | private final String serverName;
23 | private final String parsedServerName;
24 | private final String fullServerName;
25 | private final int port;
26 | private final String instanceName;
27 | private final boolean checkLink;
28 | private final transient SQLServerConnectionSecurityManager securityManager;
29 |
30 | ServerPortPlaceHolder(String name, int conPort, String instance, boolean fLink) {
31 | serverName = name;
32 |
33 | // serverName without named instance
34 | int px = serverName.indexOf('\\');
35 | parsedServerName = (px >= 0) ? serverName.substring(0, px) : serverName;
36 |
37 | // serverName with named instance
38 | fullServerName = (null != instance) ? (serverName + "\\" + instance) : serverName;
39 |
40 | port = conPort;
41 | instanceName = instance;
42 | checkLink = fLink;
43 | securityManager = new SQLServerConnectionSecurityManager(serverName, port);
44 | doSecurityCheck();
45 | }
46 |
47 | // accessors
48 | int getPortNumber() {
49 | return port;
50 | }
51 |
52 | String getServerName() {
53 | return serverName;
54 | }
55 |
56 | String getInstanceName() {
57 | return instanceName;
58 | }
59 |
60 | String getParsedServerName() {
61 | return parsedServerName;
62 | }
63 |
64 | String getFullServerName() {
65 | return fullServerName;
66 | }
67 |
68 | void doSecurityCheck() {
69 | securityManager.checkConnect();
70 | if (checkLink)
71 | securityManager.checkLink();
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SparseTest.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.sqlserver.jdbc.datatypes;
2 |
3 | import static org.junit.jupiter.api.Assertions.assertEquals;
4 |
5 | import java.sql.Connection;
6 | import java.sql.ResultSet;
7 | import java.sql.Statement;
8 |
9 | import org.junit.jupiter.api.BeforeAll;
10 | import org.junit.jupiter.api.Tag;
11 | import org.junit.jupiter.api.Test;
12 | import org.junit.platform.runner.JUnitPlatform;
13 | import org.junit.runner.RunWith;
14 |
15 | import com.microsoft.sqlserver.jdbc.RandomUtil;
16 | import com.microsoft.sqlserver.jdbc.TestUtils;
17 | import com.microsoft.sqlserver.testframework.AbstractSQLGenerator;
18 | import com.microsoft.sqlserver.testframework.AbstractTest;
19 | import com.microsoft.sqlserver.testframework.Constants;
20 |
21 |
22 | @RunWith(JUnitPlatform.class)
23 | public class SparseTest extends AbstractTest {
24 | final static String tableName = RandomUtil.getIdentifier("SparseTestTable");
25 | final static String escapedTableName = AbstractSQLGenerator.escapeIdentifier(tableName);
26 |
27 | @BeforeAll
28 | public static void setupTests() throws Exception {
29 | setConnection();
30 | }
31 |
32 | @Test
33 | @Tag(Constants.xAzureSQLDW)
34 | public void testSparse() throws Exception {
35 | try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) {
36 |
37 | // Create the test table
38 | TestUtils.dropTableIfExists(escapedTableName, stmt);
39 |
40 | StringBuilder bd = new StringBuilder();
41 | bd.append("create table " + escapedTableName + " (col1 int, col2 varbinary(max)");
42 | for (int i = 3; i <= 1024; i++) {
43 | bd.append(", col" + i + " varchar(20) SPARSE NULL");
44 | }
45 | bd.append(")");
46 | String query = bd.toString();
47 |
48 | stmt.executeUpdate(query);
49 |
50 | stmt.executeUpdate("insert into " + escapedTableName + " (col1, col2, col1023)values(1, 0x45, 'yo')");
51 |
52 | try (ResultSet rs = stmt.executeQuery("Select * from " + escapedTableName)) {
53 | rs.next();
54 | assertEquals("yo", rs.getString("col1023"));
55 | assertEquals(1, rs.getInt("col1"));
56 | assertEquals(0x45, rs.getBytes("col2")[0]);
57 | }
58 | } finally {
59 | try (Statement stmt = connection.createStatement()) {
60 | TestUtils.dropTableIfExists(escapedTableName, stmt);
61 | }
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerStatement.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
3 | * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
4 | */
5 |
6 | package com.microsoft.sqlserver.jdbc;
7 |
8 | import java.io.Serializable;
9 |
10 |
11 | /**
12 | * Provides an interface to the {@link SQLServerStatement} class.
13 | */
14 | public interface ISQLServerStatement extends java.sql.Statement, Serializable {
15 | /**
16 | * Sets the response buffering mode for this SQLServerStatement object to case-insensitive String full or adaptive.
17 | * cancelQueryTimeout property set on this SQLServerStatement object.
45 | *
46 | * @return cancelQueryTimeout Time duration in seconds.
47 | * @throws SQLServerException
48 | * if any error occurs
49 | */
50 | int getCancelQueryTimeout() throws SQLServerException;
51 |
52 | /**
53 | * Sets the cancelQueryTimeout property on this SQLServerStatement object to cancel
54 | * queryTimeout set on Connection or Statement level.
55 | *
56 | * @param seconds
57 | * Time duration in seconds.
58 | * @throws SQLServerException
59 | * if any error occurs
60 | */
61 | void setCancelQueryTimeout(int seconds) throws SQLServerException;
62 | }
63 |
--------------------------------------------------------------------------------
/src/test/java/com/microsoft/sqlserver/jdbc/connection/ClientProcessIdTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
3 | * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
4 | */
5 | package com.microsoft.sqlserver.jdbc.connection;
6 |
7 | import static org.junit.jupiter.api.Assertions.assertEquals;
8 | import static org.junit.jupiter.api.Assertions.assertTrue;
9 |
10 | import java.sql.Connection;
11 | import java.sql.ResultSet;
12 | import java.sql.SQLException;
13 | import java.sql.Statement;
14 |
15 | import com.microsoft.sqlserver.jdbc.TestUtils;
16 | import org.junit.jupiter.api.BeforeAll;
17 | import org.junit.jupiter.api.Tag;
18 | import org.junit.jupiter.api.Test;
19 | import org.junit.platform.runner.JUnitPlatform;
20 | import org.junit.runner.RunWith;
21 |
22 | import com.microsoft.sqlserver.jdbc.SQLServerDataSource;
23 | import com.microsoft.sqlserver.testframework.AbstractTest;
24 | import com.microsoft.sqlserver.testframework.Constants;
25 |
26 |
27 | /*
28 | * This test is for validating that client process ID gets registered with the server when available to the driver.
29 | */
30 | @RunWith(JUnitPlatform.class)
31 | @Tag(Constants.xAzureSQLDW)
32 | public class ClientProcessIdTest extends AbstractTest {
33 |
34 | @BeforeAll
35 | public static void setupTests() throws Exception {
36 | setConnection();
37 | }
38 |
39 | private static int pid = 0;
40 |
41 | static {
42 | long pidLong = 0;
43 | try {
44 | pidLong = ProcessHandle.current().pid();
45 | } catch (NoClassDefFoundError e) { // ProcessHandle is Java 9+
46 | }
47 | pid = (pidLong > Integer.MAX_VALUE) ? 0 : (int) pidLong;
48 | }
49 |
50 | @Test
51 | @Tag(Constants.xAzureSQLDW)
52 | @Tag(Constants.xJDBC42)
53 | public void testClientProcessId() throws SQLException {
54 | SQLServerDataSource ds = new SQLServerDataSource();
55 | ds.setURL(connectionString);
56 | String sqlSelect = "select host_process_id from sys.dm_exec_sessions where session_id = @@SPID";
57 |
58 | try (Connection con = ds.getConnection(); Statement stmt = con.createStatement()) {
59 | try (ResultSet rs = stmt.executeQuery(sqlSelect)) {
60 | if (rs.next()) {
61 | assertEquals(pid, rs.getInt(1));
62 | } else {
63 | assertTrue(false, "Expected row of data was not found.");
64 | }
65 | }
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSavepoint.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
3 | * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
4 | */
5 |
6 | package com.microsoft.sqlserver.jdbc;
7 |
8 | import java.text.MessageFormat;
9 |
10 |
11 | /**
12 | * Provides an implementation of JDBC Interface java.sql.Savepoint. A savepoint is checkpoint to which a transaction can
13 | * be rolled back. Savepoints are defined relative to a connection.F
14 | *