├── META-INF └── services │ └── java.sql.Driver ├── .gitattributes ├── src ├── test │ ├── resources │ │ ├── BulkCopyCSVTestInputWithVector.csv │ │ ├── BulkCopyCSVTestInputComputeColumn.csv │ │ ├── BulkCopyCSVTestInputWithMultipleVectorColumn.csv │ │ ├── BulkCopyCSVTestWithMultipleVectorColumnWithPipeDelimiter.csv │ │ ├── BulkCopyCSVTestInputWithJson.csv │ │ ├── BulkCopyCSVSendTemporalDataTypesAsStringForBulkCopy2.csv │ │ ├── BulkCopyCSVSendTemporalDataTypesAsStringForBulkCopy.csv │ │ ├── BulkCopyCSVTestInputDelimiterEscape.csv │ │ ├── BulkCopyCSVTestInputDelimiterEscapeNoNewLineAtEnd.csv │ │ ├── BulkCopyCSVTestInputNoColumnName.csv │ │ └── BulkCopyCSVTestInput.csv │ └── java │ │ └── com │ │ └── microsoft │ │ └── sqlserver │ │ ├── testframework │ │ ├── sqlType │ │ │ ├── SqlNumeric.java │ │ │ ├── SqlVarChar.java │ │ │ ├── SqlNVarChar.java │ │ │ ├── SqlMoney.java │ │ │ ├── SqlSmallMoney.java │ │ │ ├── SqlJson.java │ │ │ ├── SqlNumber.java │ │ │ ├── VariableLengthType.java │ │ │ ├── SqlBit.java │ │ │ ├── SqlReal.java │ │ │ ├── SqlBigInt.java │ │ │ ├── SqlInt.java │ │ │ ├── SqlTinyInt.java │ │ │ ├── SqlSmallInt.java │ │ │ ├── SqlVarBinaryMax.java │ │ │ ├── SqlVarCharMax.java │ │ │ ├── SqlNChar.java │ │ │ ├── SqlDate.java │ │ │ ├── SqlNVarCharMax.java │ │ │ ├── SqlBinary.java │ │ │ ├── SqlSmallDateTime.java │ │ │ ├── SqlFloat.java │ │ │ ├── SqlTypeValue.java │ │ │ ├── SqlDateTime.java │ │ │ ├── SqlTime.java │ │ │ └── SqlDateTime2.java │ │ ├── DBCoercions.java │ │ ├── vectorJsonTest.java │ │ ├── AzureDB.java │ │ ├── DBItems.java │ │ ├── AbstractParentWrapper.java │ │ ├── DBCoercion.java │ │ ├── DBResultSetTypes.java │ │ ├── DummyKeyStoreProvider.java │ │ ├── PrepUtil.java │ │ ├── DBConstants.java │ │ └── DBCallableStatement.java │ │ └── jdbc │ │ ├── ssl │ │ └── trustmanager │ │ │ ├── PermissiveTrustManager.java │ │ │ ├── InvalidTrustManager.java │ │ │ └── TrustManagerWithConstructorArg.java │ │ ├── SharedTimerTest.java │ │ ├── bulkCopy │ │ └── BulkCopyTestSetUp.java │ │ ├── connection │ │ ├── XADataSourceTest.java │ │ ├── ConnectionWrapper43Test.java │ │ └── ClientProcessIdTest.java │ │ ├── ParserUtils.java │ │ ├── ActivityIDTest.java │ │ └── datatypes │ │ └── SparseTest.java ├── main │ └── java │ │ ├── mssql │ │ └── googlecode │ │ │ ├── cityhash │ │ │ ├── NOTICE │ │ │ └── package-info.java │ │ │ └── concurrentlinkedhashmap │ │ │ ├── NOTICE │ │ │ ├── Linked.java │ │ │ ├── Weigher.java │ │ │ ├── EntryWeigher.java │ │ │ ├── package-info.java │ │ │ └── EvictionListener.java │ │ └── com │ │ └── microsoft │ │ └── sqlserver │ │ └── jdbc │ │ ├── ReconnectListener.java │ │ ├── SQLServerAccessTokenCallback.java │ │ ├── SQLServerSortOrder.java │ │ ├── StreamPacket.java │ │ ├── ICounter.java │ │ ├── SQLJdbcVersion.java │ │ ├── StreamSSPI.java │ │ ├── StreamRetStatus.java │ │ ├── PerformanceActivity.java │ │ ├── spatialdatatypes │ │ ├── Segment.java │ │ ├── WKBPoint.java │ │ ├── WKBLinearRing.java │ │ ├── Figure.java │ │ ├── Point.java │ │ └── Shape.java │ │ ├── ParsedSQLMetadata.java │ │ ├── ISQLServerResultSetMetaData.java │ │ ├── SQLServerKeyVaultAuthenticationCallback.java │ │ ├── ISQLServerSavepoint.java │ │ ├── SQLServerBouncyCastleLoader.java │ │ ├── SQLServerEncryptionAlgorithmFactory.java │ │ ├── SQLServerLob.java │ │ ├── dataclassification │ │ ├── Label.java │ │ ├── InformationType.java │ │ ├── ColumnSensitivity.java │ │ └── SensitivityProperty.java │ │ ├── SQLServerEncryptionAlgorithm.java │ │ ├── SQLServerSymmetricKey.java │ │ ├── SQLServerEncryptionType.java │ │ ├── StreamLoginAck.java │ │ ├── PerformanceLogCallback.java │ │ ├── SQLServerStatementColumnEncryptionSetting.java │ │ ├── ISQLServerDataRecord.java │ │ ├── SQLServerJdbc42.java │ │ ├── StreamRetValue.java │ │ ├── dns │ │ └── DNSKerberosLocator.java │ │ ├── StreamTabName.java │ │ ├── SQLServerWarning.java │ │ ├── XMLTDSHeader.java │ │ ├── SQLServerNClob.java │ │ ├── SQLServerJdbc43.java │ │ ├── SQLServerConnection43.java │ │ ├── MaxResultBufferCounter.java │ │ ├── UDTTDSHeader.java │ │ ├── StringUtils.java │ │ ├── StreamColInfo.java │ │ ├── SqlAuthenticationToken.java │ │ ├── osgi │ │ └── Activator.java │ │ ├── ScopeTokenCache.java │ │ ├── ServerPortPlaceHolder.java │ │ ├── ISQLServerStatement.java │ │ ├── SQLServerSavepoint.java │ │ └── ISQLServerBulkData.java └── samples │ ├── sparse │ └── pom.xml │ ├── alwaysencrypted │ └── pom.xml │ ├── dataclassification │ └── pom.xml │ ├── connections │ └── pom.xml │ ├── constrained │ └── pom.xml │ ├── azureactivedirectoryauthentication │ └── pom.xml │ ├── datatypes │ └── pom.xml │ ├── resultsets │ └── pom.xml │ └── adaptive │ └── pom.xml ├── .github ├── PULL_REQUEST_TEMPLATE │ ├── release.md │ ├── improvements.md │ ├── feature.md │ ├── other.md │ ├── bug_fix.md │ └── pr-template.md ├── ISSUE_TEMPLATE │ ├── question.md │ ├── feature-request.md │ └── bug_report.md └── workflows │ └── codeql.yml ├── CODE_OF_CONDUCT.md ├── .checkstyle ├── LICENSE ├── CONTRIBUTING.md ├── maven-version-rules.xml └── SECURITY.md /META-INF/services/java.sql.Driver: -------------------------------------------------------------------------------- 1 | com.microsoft.sqlserver.jdbc.SQLServerDriver 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * -text 3 | -------------------------------------------------------------------------------- /src/test/resources/BulkCopyCSVTestInputWithVector.csv: -------------------------------------------------------------------------------- 1 | id,vectorCol 2 | 1,"[1.0,2.0,3.0]" 3 | 2,"[4.0,5.0,6.0]" 4 | 3,"NULL" -------------------------------------------------------------------------------- /src/test/resources/BulkCopyCSVTestInputComputeColumn.csv: -------------------------------------------------------------------------------- 1 | NAME,AGE,CAL_COL,ORIGINAL,LAST_COL 2 | John Doe,30,12345.67,Original,Last 3 | Jane Smith,25,54321.00,Original,Last 4 | -------------------------------------------------------------------------------- /src/test/resources/BulkCopyCSVTestInputWithMultipleVectorColumn.csv: -------------------------------------------------------------------------------- 1 | vectorCol1,vectorCol2 2 | "NULL","NULL" 3 | "[1.0,2.0,3.0]","[1.0,2.0,3.0]" 4 | "[3.0,4.0,5.0]","[6.0,7.0,8.0]" -------------------------------------------------------------------------------- /src/test/resources/BulkCopyCSVTestWithMultipleVectorColumnWithPipeDelimiter.csv: -------------------------------------------------------------------------------- 1 | vectorCol1|vectorCol2 2 | "NULL"|"NULL" 3 | "[1.0,2.0,3.0]"|"[1.0,2.0,3.0]" 4 | "[3.0,4.0,5.0]"|"[6.0,7.0,8.0]" -------------------------------------------------------------------------------- /src/test/resources/BulkCopyCSVTestInputWithJson.csv: -------------------------------------------------------------------------------- 1 | 0,testing,"{""age"": 25, ""address"": {""pincode"": 123456, ""state"": ""NY""}}" 2 | 1,test },"{""age"": 25, ""city"": ""Los Angeles""}" 3 | 0,test {0},"{""age"": 40, ""city"": ""Chicago""}" -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE/release.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Release 3 | about: Push changes for release preparations 4 | title: "Release | " 5 | 6 | --- 7 | 8 | ## Brief Description 9 | 10 | -------------------------------------------------------------------------------- /src/main/java/mssql/googlecode/cityhash/NOTICE: -------------------------------------------------------------------------------- 1 | CityHash 2 | Copyright 2012, tamtam180 3 | 4 | More information: http://google-opensource.blogspot.jp/2011/04/introducing-cityhash.html 5 | By Geoff Pike and Jyrki Alakuijala, Software Engineering Team, Google 6 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE/improvements.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Improvements 3 | about: Improve driver's performance/code quality 4 | title: "Improvement | " 5 | 6 | --- 7 | 8 | ## Brief Description 9 | 10 | -------------------------------------------------------------------------------- /src/test/resources/BulkCopyCSVSendTemporalDataTypesAsStringForBulkCopy2.csv: -------------------------------------------------------------------------------- 1 | int,date,datetime,datetime2,time,datetimeoffset,smalldatetime,money,smallmoney 2 | 1,0001-01-01,1753-01-01 00:00:00,0001-01-01 00:00:00,00:00:00,2025-12-10 12:32:10,1900-01-01 06:56:00,100.2523,100.2523 -------------------------------------------------------------------------------- /src/main/java/mssql/googlecode/concurrentlinkedhashmap/NOTICE: -------------------------------------------------------------------------------- 1 | ConcurrentLinkedHashMap 2 | Copyright 2008, Ben Manes 3 | Copyright 2010, Google Inc. 4 | 5 | Some alternate data structures provided by JSR-166e 6 | from http://gee.cs.oswego.edu/dl/concurrency-interest/. 7 | Written by Doug Lea and released as Public Domain. 8 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question 3 | about: Ask a question 4 | title: "[QUESTION]" 5 | labels: question 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Question 11 | 12 | 13 | ## Relevant Issues and Pull Requests 14 | 15 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE/feature.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature 3 | about: Propose a new feature to the driver 4 | title: "Feature | " 5 | 6 | --- 7 | 8 | ## Brief Description 9 | 10 | 11 | 12 | ### Fixes existing GitHub issue 13 | 14 | 15 | ## New Public APIs 16 | 17 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE/other.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Other 3 | about: Propose a custom change to the project source code. 4 | title: "Other | " 5 | 6 | --- 7 | 8 | ## Brief Description 9 | 10 | 11 | 12 | ### Fixes existing GitHub issue 13 | 14 | 15 | ## New Public APIs 16 | 17 | -------------------------------------------------------------------------------- /src/test/resources/BulkCopyCSVSendTemporalDataTypesAsStringForBulkCopy.csv: -------------------------------------------------------------------------------- 1 | int,date,datetime,datetime2,time,datetimeoffset,smalldatetime,money,smallmoney 2 | ,,,,,,,, 3 | 1,0001-01-01,1753-01-01 00:00:00.0,0001-01-01 00:00:00.0000000,00:00:00.0000000,2025-12-10 12:32:10.1234567 +01:15,1900-01-01 06:56:00.0,100.2523,100.2523 4 | 2,9999-12-31,9999-12-31 23:59:59.997,9999-12-31 23:59:59.9999999,23:59:59.0000000,1234-12-12 23:59:59.1234567 -03:00,2020-04-28 06:54:00.0,-922337203685477.5808,-214748.3648 5 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE/bug_fix.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Fix 3 | about: Fix for a driver issue 4 | title: "Fix | " 5 | 6 | --- 7 | 8 | ## Problem description 9 | 10 | 11 | ### Fixes existing GitHub issue 12 | 13 | 14 | ## Fix Description 15 | 16 | 17 | ## New Public APIs 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/sqlType/SqlNumeric.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 | 10 | 11 | public class SqlNumeric extends SqlDecimal { 12 | 13 | public SqlNumeric() { 14 | super("numeric", JDBCType.NUMERIC); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/sqlType/SqlVarChar.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 | 10 | 11 | public class SqlVarChar extends SqlChar { 12 | 13 | public SqlVarChar() { 14 | super("varchar", JDBCType.VARCHAR, 4000); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/sqlType/SqlNVarChar.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 | 10 | 11 | public class SqlNVarChar extends SqlNChar { 12 | 13 | public SqlNVarChar() { 14 | super("nvarchar", JDBCType.NVARCHAR, 2000); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/sqlType/SqlMoney.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 | public class SqlMoney extends SqlDecimal { 9 | 10 | public SqlMoney() { 11 | super("money", 19, 4, SqlTypeValue.MONEY.minValue, SqlTypeValue.MONEY.maxValue, VariableLengthType.Fixed); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/test/resources/BulkCopyCSVTestInputDelimiterEscape.csv: -------------------------------------------------------------------------------- 1 | 1@"test"@ " test"""@ "no@split" @ testNoQuote@ 2 | 2@""@ ""@ ""@ ""@ 3 | 3@""""@ "test""test"@ "test@"" test"@ ""@ 4 | 4@testNoQuote @ testSpaceAround @ " testSpaceInside "@ " testSpaceQuote"" "@ 5 | 5@""@ ""@ ""@ " testSpaceInside "@ 6 | 6@1997@Ford@E350@E63@ 7 | 7@"1997"@"Ford"@"E350"@"E63"@ 8 | 8@1997@Ford@E350@"Super@ luxurious truck"@ 9 | 9@1997@Ford@E350@"Super@ ""luxurious"" truck"@ 10 | 10@1997@ "Ford" @E350@ "E63"@ 11 | 11@1997@Ford@E350@" Super luxurious truck "@ 12 | 12@1997@"F 13 | o 14 | r 15 | d"@"E350"@"""Super"" ""luxurious"" ""truck"""@ 16 | -------------------------------------------------------------------------------- /src/test/resources/BulkCopyCSVTestInputDelimiterEscapeNoNewLineAtEnd.csv: -------------------------------------------------------------------------------- 1 | 1@"test"@ " test"""@ "no@split" @ testNoQuote@ 2 | 2@""@ ""@ ""@ ""@ 3 | 3@""""@ "test""test"@ "test@"" test"@ ""@ 4 | 4@testNoQuote @ testSpaceAround @ " testSpaceInside "@ " testSpaceQuote"" "@ 5 | 5@""@ ""@ ""@ " testSpaceInside "@ 6 | 6@1997@Ford@E350@E63@ 7 | 7@"1997"@"Ford"@"E350"@"E63"@ 8 | 8@1997@Ford@E350@"Super@ luxurious truck"@ 9 | 9@1997@Ford@E350@"Super@ ""luxurious"" truck"@ 10 | 10@1997@ "Ford" @E350@ "E63"@ 11 | 11@1997@Ford@E350@" Super luxurious truck "@ 12 | 12@1997@"F 13 | o 14 | r 15 | d"@"E350"@"""Super"" ""luxurious"" ""truck"""@ -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/sqlType/SqlSmallMoney.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 | public class SqlSmallMoney extends SqlDecimal { 9 | 10 | public SqlSmallMoney() { 11 | super("smallmoney", 10, 4, SqlTypeValue.SMALLMONEY.minValue, SqlTypeValue.SMALLMONEY.maxValue, 12 | VariableLengthType.Fixed); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/ReconnectListener.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 | /** 8 | * This functional interface represents a listener which is called before a reconnect of {@link SQLServerConnection}. 9 | */ 10 | @FunctionalInterface 11 | public interface ReconnectListener { 12 | 13 | /** 14 | * called before reconnect 15 | */ 16 | void beforeReconnect(); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /.checkstyle: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/SQLServerAccessTokenCallback.java: -------------------------------------------------------------------------------- 1 | package com.microsoft.sqlserver.jdbc; 2 | 3 | /** 4 | * Provides SqlAuthenticationToken callback to be implemented by client code. 5 | */ 6 | public interface SQLServerAccessTokenCallback { 7 | 8 | /** 9 | * For an example of callback usage, look under the project's code samples. 10 | * 11 | * Returns the access token for the authentication request 12 | * 13 | * @param stsurl 14 | * - Security token service URL. 15 | * @param spn 16 | * - Service principal name. 17 | * 18 | * @return Returns a {@link SqlAuthenticationToken}. 19 | */ 20 | SqlAuthenticationToken getAccessToken(String spn, String stsurl); 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/DBCoercions.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.ArrayList; 8 | 9 | 10 | /** 11 | * DBCoercions 12 | * 13 | */ 14 | public class DBCoercions extends DBItems { 15 | 16 | /** 17 | * constructor 18 | */ 19 | public DBCoercions() { 20 | coercionsList = new ArrayList<>(); 21 | } 22 | 23 | public DBCoercions(DBCoercion coercion) { 24 | this.add(coercion); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/sqlType/SqlJson.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 | public class SqlJson extends SqlType { 9 | 10 | public SqlJson() { 11 | super("json", microsoft.sql.Types.JSON, 0, 0, SqlTypeValue.JSON.minValue, SqlTypeValue.JSON.maxValue, 12 | SqlTypeValue.JSON.nullValue, VariableLengthType.Fixed, String.class); 13 | } 14 | 15 | @Override 16 | public Object createdata() { 17 | return "{}"; 18 | } 19 | } -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSortOrder.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 | * Specifies the sorting order 11 | * 12 | */ 13 | public enum SQLServerSortOrder { 14 | /** ascending order */ 15 | ASCENDING(0), 16 | /** descending order */ 17 | DESCENDING(1), 18 | /** unspecified order */ 19 | UNSPECIFIED(-1); 20 | 21 | final int value; 22 | 23 | SQLServerSortOrder(int sortOrderVal) { 24 | value = sortOrderVal; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/sqlType/SqlNumber.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 | 10 | 11 | public abstract class SqlNumber extends SqlType { 12 | SqlNumber(String name, JDBCType jdbctype, int precision, int scale, Object min, Object max, Object nullvalue, 13 | VariableLengthType variableLengthType, Class type) { 14 | super(name, jdbctype, precision, scale, min, max, nullvalue, VariableLengthType.Fixed, type); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/sqlType/VariableLengthType.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 | /** 9 | * Used to identify if the SQL type is of fixed length, or has Precision or Scale 10 | */ 11 | public enum VariableLengthType { 12 | Fixed, // primitive types with fixed Length 13 | Precision, // variable length type that just has precision char/varchar 14 | Scale, // variable length type with scale and precision 15 | ScaleOnly, // variable length type with just scale like Time 16 | Variable 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/StreamPacket.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 | * Common interface for all TDS packet types 10 | * 11 | */ 12 | abstract class StreamPacket { 13 | int packetType; 14 | 15 | final int getTokenType() { 16 | return packetType; 17 | } 18 | 19 | StreamPacket() { 20 | this.packetType = 0; 21 | } 22 | 23 | StreamPacket(int packetType) { 24 | this.packetType = packetType; 25 | } 26 | 27 | abstract void setFromTDS(TDSReader tdsReader) throws SQLServerException; 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/ICounter.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 | * Interface for MaxResultBufferCounter 10 | */ 11 | interface ICounter { 12 | 13 | /** 14 | * Increases the state of Counter 15 | * 16 | * @param bytes 17 | * Number of bytes to increase state 18 | * @throws SQLServerException 19 | * Exception is thrown, when limit of Counter is exceeded 20 | */ 21 | void increaseCounter(long bytes) throws SQLServerException; 22 | 23 | /** 24 | * Resets the state of Counter 25 | */ 26 | void resetCounter(); 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/vectorJsonTest.java: -------------------------------------------------------------------------------- 1 | package com.microsoft.sqlserver.testframework; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | import org.junit.jupiter.api.Tag; 9 | 10 | /* 11 | * Custom annotation to run vector and json tests on supported SQL Server versions 12 | * Currently, vector and json feature is supported to run on SQL Server 2025 and Azure SQL DB 13 | */ 14 | @Target({ElementType.METHOD, ElementType.TYPE}) 15 | @Retention(RetentionPolicy.RUNTIME) 16 | @Tag(Constants.xSQLv11) 17 | @Tag(Constants.xSQLv12) 18 | @Tag(Constants.xSQLv14) 19 | @Tag(Constants.xSQLv15) 20 | @Tag(Constants.xSQLv16) 21 | @Tag(Constants.xAzureSQLDW) 22 | @Tag(Constants.xAzureSQLMI) 23 | public @interface vectorJsonTest {} 24 | -------------------------------------------------------------------------------- /src/main/java/mssql/googlecode/concurrentlinkedhashmap/Linked.java: -------------------------------------------------------------------------------- 1 | package mssql.googlecode.concurrentlinkedhashmap; 2 | 3 | import java.util.Deque; 4 | 5 | 6 | /** 7 | * An element that is linked on the {@link Deque}. 8 | */ 9 | interface Linked> { 10 | 11 | /** 12 | * Retrieves the previous element or null if either the element is 13 | * unlinked or the first element on the deque. 14 | */ 15 | T getPrevious(); 16 | 17 | /** Sets the previous element or null if there is no link. */ 18 | void setPrevious(T prev); 19 | 20 | /** 21 | * Retrieves the next element or null if either the element is 22 | * unlinked or the last element on the deque. 23 | */ 24 | T getNext(); 25 | 26 | /** Sets the next element or null if there is no link. */ 27 | void setNext(T next); 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/sqlType/SqlBit.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 SqlBit extends SqlType { 13 | 14 | public SqlBit() { 15 | super("bit", JDBCType.BIT, 1, 0, SqlTypeValue.BIT.minValue, SqlTypeValue.BIT.maxValue, 16 | SqlTypeValue.BIT.nullValue, VariableLengthType.Fixed, Boolean.class); 17 | } 18 | 19 | public Object createdata() { 20 | return ((0 == ThreadLocalRandom.current().nextInt(2)) ? minvalue : maxvalue); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/SQLJdbcVersion.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 | final class SQLJdbcVersion { 9 | static final int MAJOR = 13; 10 | static final int MINOR = 3; 11 | static final int PATCH = 0; 12 | static final int BUILD = 0; 13 | /* 14 | * Used to load mssql-jdbc_auth DLL. 15 | * 1. Set to "-preview" for preview release. 16 | * 2. Set to "" (empty String) for official release. 17 | */ 18 | static final String RELEASE_EXT = "-preview"; 19 | 20 | private SQLJdbcVersion() { 21 | throw new UnsupportedOperationException(SQLServerException.getErrString("R_notSupported")); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/sqlType/SqlReal.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 SqlReal extends SqlFloat { 13 | 14 | public SqlReal() { 15 | super("real", JDBCType.REAL, 24, SqlTypeValue.REAL.minValue, SqlTypeValue.REAL.maxValue, 16 | SqlTypeValue.REAL.nullValue, VariableLengthType.Fixed, Float.class); 17 | } 18 | 19 | @Override 20 | public Object createdata() { 21 | return (float) ThreadLocalRandom.current().nextDouble((Float) minvalue, (Float) maxvalue); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/StreamSSPI.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 | * StreamSSPi represents a TDS SSPI processing. 10 | * 11 | */ 12 | 13 | final class StreamSSPI extends StreamPacket { 14 | byte[] sspiBlob; 15 | 16 | StreamSSPI() { 17 | super(TDS.TDS_SSPI); 18 | } 19 | 20 | void setFromTDS(TDSReader tdsReader) throws SQLServerException { 21 | if (TDS.TDS_SSPI != tdsReader.readUnsignedByte()) 22 | assert false; 23 | int blobLength = tdsReader.readUnsignedShort(); 24 | sspiBlob = new byte[blobLength]; 25 | tdsReader.readBytes(sspiBlob, 0, blobLength); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/StreamRetStatus.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 | * StreamRetStatus represents a TDS return status. 10 | * 11 | */ 12 | final class StreamRetStatus extends StreamPacket { 13 | /** the returned status */ 14 | private int status; 15 | 16 | final int getStatus() { 17 | return status; 18 | } 19 | 20 | StreamRetStatus() { 21 | super(TDS.TDS_RET_STAT); 22 | } 23 | 24 | void setFromTDS(TDSReader tdsReader) throws SQLServerException { 25 | if (TDS.TDS_RET_STAT != tdsReader.readUnsignedByte()) 26 | assert false; 27 | status = tdsReader.readInt(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/PerformanceActivity.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 | * Enum representing different performance activities. 10 | */ 11 | public enum PerformanceActivity { 12 | CONNECTION("Connection"), 13 | TOKEN_ACQUISITION("Token acquisition"), 14 | LOGIN("Login"), 15 | PRELOGIN("Prelogin"); 16 | 17 | private final String activity; 18 | 19 | PerformanceActivity(String activity) { 20 | this.activity = activity; 21 | } 22 | 23 | public String activity() { 24 | return activity; 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return activity; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/sqlType/SqlBigInt.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 SqlBigInt extends SqlNumber { 13 | 14 | public SqlBigInt() { 15 | super("bigint", JDBCType.BIGINT, 19, 0, SqlTypeValue.BIGINT.minValue, SqlTypeValue.BIGINT.maxValue, 16 | SqlTypeValue.BIGINT.nullValue, VariableLengthType.Fixed, Long.class); 17 | flags.set(PRIMITIVE); 18 | 19 | } 20 | 21 | public Object createdata() { 22 | return ThreadLocalRandom.current().nextLong(Long.MIN_VALUE, Long.MAX_VALUE); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/sqlType/SqlInt.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 SqlInt extends SqlNumber { 13 | 14 | public SqlInt() { 15 | super("int", JDBCType.INTEGER, 10, 0, SqlTypeValue.INTEGER.minValue, SqlTypeValue.INTEGER.maxValue, 16 | SqlTypeValue.INTEGER.nullValue, VariableLengthType.Fixed, Integer.class); 17 | 18 | } 19 | 20 | public Object createdata() { 21 | // TODO: include max value 22 | return ThreadLocalRandom.current().nextInt(Integer.MIN_VALUE, Integer.MAX_VALUE); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/sqlType/SqlTinyInt.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 SqlTinyInt extends SqlNumber { 13 | 14 | public SqlTinyInt() { 15 | super("tinyint", JDBCType.TINYINT, 3, 0, SqlTypeValue.TINYINT.minValue, SqlTypeValue.TINYINT.maxValue, 16 | SqlTypeValue.TINYINT.nullValue, VariableLengthType.Fixed, Byte.class); 17 | } 18 | 19 | public Object createdata() { 20 | // TODO: include max value 21 | return (short) ThreadLocalRandom.current().nextInt((short) minvalue, ((short) maxvalue)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/spatialdatatypes/Segment.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 Segment. 10 | * 11 | */ 12 | public class Segment { 13 | private byte segmentType; 14 | 15 | /** 16 | * Creates a Segment object 17 | * 18 | * @param segmentType 19 | * segment type 20 | */ 21 | public Segment(byte segmentType) { 22 | this.segmentType = segmentType; 23 | } 24 | 25 | /** 26 | * Returns the segmentType value. 27 | * 28 | * @return byte segmentType value. 29 | */ 30 | public byte getSegmentType() { 31 | return segmentType; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/sqlType/SqlSmallInt.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 SqlSmallInt extends SqlNumber { 13 | 14 | public SqlSmallInt() { 15 | super("smallint", JDBCType.SMALLINT, 5, 0, SqlTypeValue.SMALLINT.minValue, SqlTypeValue.SMALLINT.maxValue, 16 | SqlTypeValue.SMALLINT.nullValue, VariableLengthType.Fixed, Short.class); 17 | 18 | } 19 | 20 | public Object createdata() { 21 | // TODO: include max value 22 | return (short) ThreadLocalRandom.current().nextInt(Short.MIN_VALUE, Short.MAX_VALUE); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/ParsedSQLMetadata.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 | * Used for caching of meta data from parsed SQL text. 10 | */ 11 | final class ParsedSQLCacheItem { 12 | /** The SQL text AFTER processing. */ 13 | String processedSQL; 14 | int[] parameterPositions; 15 | String procedureName; 16 | boolean bReturnValueSyntax; 17 | 18 | ParsedSQLCacheItem(String processedSQL, int[] parameterPositions, String procedureName, 19 | boolean bReturnValueSyntax) { 20 | this.processedSQL = processedSQL; 21 | this.parameterPositions = parameterPositions; 22 | this.procedureName = procedureName; 23 | this.bReturnValueSyntax = bReturnValueSyntax; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/AzureDB.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 | import java.lang.annotation.ElementType; 9 | import java.lang.annotation.Retention; 10 | import java.lang.annotation.RetentionPolicy; 11 | import java.lang.annotation.Target; 12 | 13 | import org.junit.jupiter.api.Tag; 14 | 15 | /* 16 | * Custom annotation to run tests only on Azure DBs 17 | */ 18 | @Target({ElementType.METHOD, ElementType.TYPE}) 19 | @Retention(RetentionPolicy.RUNTIME) 20 | @Tag(Constants.xSQLv11) 21 | @Tag(Constants.xSQLv12) 22 | @Tag(Constants.xSQLv14) 23 | @Tag(Constants.xSQLv15) 24 | @Tag(Constants.xSQLv16) 25 | @Tag(Constants.xSQLv17) 26 | @Tag(Constants.xAzureSQLDW) 27 | @Tag(Constants.xAzureSQLMI) 28 | public @interface AzureDB {} 29 | -------------------------------------------------------------------------------- /src/main/java/mssql/googlecode/cityhash/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 tamtam180 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a 5 | * copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 10 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations 11 | * under the License. 12 | * 13 | * @author tamtam180 - kirscheless at gmail.com 14 | * @see http://google-opensource.blogspot.jp/2011/04/introducing-cityhash.html 16 | * @see http://code.google.com/p/cityhash/ 17 | */ 18 | package mssql.googlecode.cityhash; 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), 3 | to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 4 | and / or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions : 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 9 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 10 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 11 | IN THE SOFTWARE. 12 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | - **DO** report each issue as a new issue (but check first if it's already been reported) 2 | - **DO** respect Issue Templates and provide detailed information. It will make the process to reproduce the issue and provide a fix faster. 3 | - **DO** provide a minimal repro app demonstrating the problem in isolation will greatly speed up the process of identifying and fixing problems. 4 | - **DO** follow our [coding guidelines](coding-guidelines.md) when working on a Pull Request. 5 | - **DO** follow our [coding best practices](coding-best-practices.md) when working on a Pull Request. 6 | - **DO** follow our [review process](review-process.md) when reviwing a Pull Request. 7 | - **DO** give priority to the current style of the project or file you're changing even if it diverges from the general guidelines. 8 | - **DO** consider cross-platform compatibility and supportability for all supported SQL and Azure Servers and client configurations. 9 | - **DO** include tests when adding new features. When fixing bugs, start with adding a test that highlights how the current behavior is broken. -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerResultSetMetaData.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.ResultSetMetaData; 10 | 11 | 12 | /** 13 | * Provides an interface to the{@link SQLServerResultSetMetaData} class. 14 | */ 15 | public interface ISQLServerResultSetMetaData extends ResultSetMetaData, Serializable { 16 | 17 | /** 18 | * Returns if the column is a SQLServer SparseColumnSet. 19 | * 20 | * @param column 21 | * The column number 22 | * @return true if a column in a result set is a sparse column set, otherwise false. 23 | * @throws SQLServerException 24 | * when an error occurs 25 | */ 26 | boolean isSparseColumnSet(int column) throws SQLServerException; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/DBItems.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 | import java.util.ArrayList; 9 | 10 | 11 | /** 12 | * Each sqlType has a list of coercions associate with it 13 | * 14 | */ 15 | public class DBItems { 16 | protected ArrayList coercionsList; 17 | 18 | public DBItems() { 19 | 20 | } 21 | 22 | public DBCoercion find(Class type) { 23 | for (DBCoercion item : coercionsList) { 24 | if (item.type() == type) 25 | return item; 26 | } 27 | return null; 28 | } 29 | 30 | /** 31 | * 32 | * @param item 33 | * @return 34 | */ 35 | public boolean add(DBCoercion item) { 36 | return coercionsList.add(item); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/SQLServerKeyVaultAuthenticationCallback.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 | * Provides a callback delegate which is to be implemented by the client code 10 | * 11 | */ 12 | public interface SQLServerKeyVaultAuthenticationCallback { 13 | 14 | /** 15 | * Returns the acesss token of the authentication request 16 | * 17 | * @param authority 18 | * - Identifier of the authority, a URL. 19 | * @param resource 20 | * - Identifier of the target resource that is the recipient of the requested token, a URL. 21 | * @param scope 22 | * - The scope of the authentication request. 23 | * @return access token 24 | */ 25 | String getAccessToken(String authority, String resource, String scope); 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/jdbc/ssl/trustmanager/PermissiveTrustManager.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.security.cert.CertificateException; 9 | import java.security.cert.X509Certificate; 10 | 11 | import javax.net.ssl.X509TrustManager; 12 | 13 | 14 | /** 15 | * This class implements an X509TrustManager that always accepts the X509Certificate chain offered to it. 16 | */ 17 | 18 | public final class PermissiveTrustManager implements X509TrustManager { 19 | public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {} 20 | 21 | public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {} 22 | 23 | public X509Certificate[] getAcceptedIssuers() { 24 | return new X509Certificate[0]; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature-request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature Request 3 | about: Suggest an idea for this project 4 | title: "[FEATURE REQUEST]" 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Is your feature request related to a problem? If so, please give a short summary of the problem and how the feature would resolve it 11 | 12 | 13 | ## Describe the preferred solution 14 | 15 | 16 | ## Describe alternatives you've considered 17 | 18 | 19 | ## Additional context 20 | 21 | 22 | ## Reference Documentations/Specifications 23 | 24 | 25 | 26 | ## Reference Implementation 27 | 28 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/jdbc/ssl/trustmanager/InvalidTrustManager.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.security.cert.CertificateException; 9 | import java.security.cert.X509Certificate; 10 | 11 | 12 | /** 13 | * This class does not implement X509TrustManager and the connection must fail when it is specified by the 14 | * trustManagerClass property 15 | * 16 | */ 17 | public final class InvalidTrustManager { 18 | public InvalidTrustManager() {} 19 | 20 | public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { 21 | 22 | } 23 | 24 | public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {} 25 | 26 | public X509Certificate[] getAcceptedIssuers() { 27 | return new X509Certificate[0]; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerSavepoint.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.Savepoint; 10 | 11 | 12 | /** 13 | * Provides an interface to the {@link SQLServerSavepoint} class. 14 | */ 15 | public interface ISQLServerSavepoint extends Savepoint, Serializable { 16 | 17 | /** 18 | * Returns the savepoint name 19 | * 20 | * @return the name of savepoint 21 | */ 22 | String getSavepointName() throws SQLServerException; 23 | 24 | /** 25 | * Returns the savepoint label 26 | * 27 | * @return the label for Savepoint 28 | */ 29 | String getLabel(); 30 | 31 | /** 32 | * Returns if the savepoint label is null 33 | * 34 | * @return true is the savepoint is named. Otherwise, false. 35 | */ 36 | boolean isNamed(); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBouncyCastleLoader.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.security.Provider; 9 | import java.security.Security; 10 | 11 | 12 | /* 13 | * Class that is meant to statically load the BouncyCastle Provider for JDK 8. Hides the call so JDK 11/13 don't have to include the dependency. 14 | * Also loads BouncyCastle provider for PKCS1 private key parsing. 15 | */ 16 | class SQLServerBouncyCastleLoader { 17 | private SQLServerBouncyCastleLoader() { 18 | throw new UnsupportedOperationException(SQLServerException.getErrString("R_notSupported")); 19 | } 20 | 21 | static void loadBouncyCastle() { 22 | Provider p = new org.bouncycastle.jce.provider.BouncyCastleProvider(); 23 | if (null == Security.getProvider(p.getName())) { 24 | Security.addProvider(p); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/resources/BulkCopyCSVTestInputNoColumnName.csv: -------------------------------------------------------------------------------- 1 | 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 2 | ,,,,,,,,,,,,,,,,,,,,,, 3 | 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 4 | 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 5 | 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 6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Driver version 11 | Provide the JDBC driver version (e.g. 10.2.0). 12 | 13 | ## SQL Server version 14 | Provide the output of executing `SELECT @@VERSION` on your target SQL Server. 15 | 16 | ## Client Operating System 17 | Provide the Operating System the client application is running on. 18 | 19 | ## JAVA/JVM version 20 | Provide the JAVA/JVM version (e.g. java version "1.8.0"). 21 | 22 | ## Table schema 23 | Provide the table schema to repro the issue. 24 | 25 | ## Problem description 26 | Provide full details of the problem. 27 | ## Expected behavior 28 | A clear and concise description of what you expected to happen. 29 | ## Actual behavior 30 | Output of what you actually see. 31 | ## Error message/stack trace 32 | Complete error message and stack trace. 33 | ## Any other details that can be helpful 34 | Add any other context about the problem here. 35 | 36 | ## JDBC trace logs 37 | Provide the JDBC driver trace logs. Instructions can be found here: https://docs.microsoft.com/sql/connect/jdbc/tracing-driver-operation 38 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/sqlType/SqlVarBinaryMax.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.testframework.sqlType; 6 | 7 | import java.sql.Blob; 8 | import java.sql.JDBCType; 9 | 10 | import com.microsoft.sqlserver.testframework.DBCoercion; 11 | import com.microsoft.sqlserver.testframework.DBConstants; 12 | 13 | 14 | public class SqlVarBinaryMax extends SqlVarBinary { 15 | 16 | public SqlVarBinaryMax() { 17 | super(); 18 | name = "varbinary(max)"; 19 | jdbctype = JDBCType.LONGVARBINARY; 20 | variableLengthType = variableLengthType.Variable; 21 | coercions.add(new DBCoercion(Blob.class, 22 | new int[] {DBConstants.GET_COERCION, DBConstants.UPDATE_COERCION, DBConstants.UPDATEOBJECT_COERCION, 23 | DBConstants.SET_COERCION, DBConstants.SETOBJECT_COERCION, DBConstants.GETPARAM_COERCION, 24 | DBConstants.REG_COERCION})); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/SQLServerEncryptionAlgorithmFactory.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 | * Abstract base class for all the encryption algorithm factory classes. 11 | * 12 | */ 13 | abstract class SQLServerEncryptionAlgorithmFactory { 14 | 15 | /** 16 | * 17 | * @param columnEncryptionKey 18 | * key which will be used in encryption/decryption 19 | * @param encryptionType 20 | * specifies kind of encryption 21 | * @param encryptionAlgorithm 22 | * name of encryption algorithm 23 | * @return created SQLServerEncryptionAlgorithm instance 24 | * @throws SQLServerException 25 | * when an error occurs 26 | */ 27 | abstract SQLServerEncryptionAlgorithm create(SQLServerSymmetricKey columnEncryptionKey, 28 | SQLServerEncryptionType encryptionType, String encryptionAlgorithm) throws SQLServerException; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/sqlType/SqlVarCharMax.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.testframework.sqlType; 6 | 7 | import java.sql.Clob; 8 | import java.sql.JDBCType; 9 | 10 | import com.microsoft.sqlserver.testframework.DBCoercion; 11 | import com.microsoft.sqlserver.testframework.DBConstants; 12 | 13 | 14 | public class SqlVarCharMax extends SqlVarChar { 15 | 16 | public SqlVarCharMax() { 17 | super(); 18 | name = "varchar(max)"; 19 | jdbctype = JDBCType.LONGVARCHAR; 20 | variableLengthType = VariableLengthType.Variable; 21 | coercions.add(new DBCoercion(Clob.class, 22 | new int[] {DBConstants.GET_COERCION, DBConstants.UPDATE_COERCION, DBConstants.UPDATEOBJECT_COERCION, 23 | DBConstants.SET_COERCION, DBConstants.SETOBJECT_COERCION, DBConstants.GETPARAM_COERCION, 24 | DBConstants.REG_COERCION, DBConstants.CHAR_COERCION})); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/spatialdatatypes/WKBPoint.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 Point. 10 | * 11 | */ 12 | public class WKBPoint { 13 | private final double x; 14 | private final double y; 15 | 16 | /** 17 | * Creates a WKB Point object 18 | * 19 | * @param x 20 | * x value 21 | * @param y 22 | * y value 23 | */ 24 | public WKBPoint(double x, double y) { 25 | this.x = x; 26 | this.y = y; 27 | } 28 | 29 | /** 30 | * Returns the x coordinate value. 31 | * 32 | * @return double x coordinate value. 33 | */ 34 | public double getX() { 35 | return x; 36 | } 37 | 38 | /** 39 | * Returns the y coordinate value. 40 | * 41 | * @return double y coordinate value. 42 | */ 43 | public double getY() { 44 | return y; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/sqlType/SqlNChar.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 SqlNChar extends SqlChar { 13 | private static String normalCharSet = "1234567890-=!@#$%^&*()_+qwertyuiop[]\\asdfghjkl;zxcvbnm,./QWERTYUIOP{}|ASDFGHJKL:\"ZXCVBNM<>?"; 14 | 15 | SqlNChar(String name, JDBCType jdbctype, int precision) { 16 | super(name, jdbctype, precision); 17 | } 18 | 19 | public SqlNChar() { 20 | this("nchar", JDBCType.NCHAR, 1000); 21 | } 22 | 23 | public Object createdata() { 24 | int dataLength = ThreadLocalRandom.current().nextInt(precision); 25 | return generateCharTypes(dataLength); 26 | } 27 | 28 | private static String generateCharTypes(int columnLength) { 29 | String charSet = normalCharSet; 30 | return buildCharOrNChar(columnLength, charSet); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE/pr-template.md: -------------------------------------------------------------------------------- 1 | ## Description 2 | 3 | Provide a summary of the changes being introduced. Important topics to cover 4 | include: 5 | 6 | - Description of the functionality. 7 | - API changes, backwards compatibility, deprecations, etc. 8 | - Documentation, localization. 9 | - Bug fixes. 10 | - Code hygiene, refactoring, improvements. 11 | - Engineering processes (CI, pipelines, test coverage) 12 | 13 | High quality descriptions will lead to a smoother review experience. 14 | 15 | ## Issues 16 | 17 | Link to any relevant issues, bugs, or discussions (e.g., "Closes \#123", "Fixes 18 | issue \#456"). 19 | 20 | ## Testing 21 | 22 | Describe the automated tests (unit, integration) you created or modified. 23 | Provide justification for any gap in automated testing. 24 | List any manual testing steps that were performed to ensure the changes work. 25 | Mention a link to successful test runs in ADO 26 | 27 | ## Guidelines 28 | 29 | Please review the contribution guidelines before submitting a pull request: 30 | 31 | - [Contributing](/CONTRIBUTING.md) 32 | - [Code of Conduct](/CODE_OF_CONDUCT.md) 33 | - [Best Practices](/coding-best-practices.md) 34 | - [Coding Guidelines](/coding-guidelines.md) 35 | - [Review Process](/review-process.md) -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/SQLServerLob.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.io.Serializable; 8 | import java.sql.SQLException; 9 | 10 | 11 | /** 12 | * SQL Server Lob abstract class 13 | */ 14 | abstract class SQLServerLob implements Serializable { 15 | 16 | /** 17 | * Always update serialVersionUID when prompted. 18 | */ 19 | private static final long serialVersionUID = -6444654924359581662L; 20 | 21 | /** 22 | * Provides functionality for the result set to maintain blobs it has created. 23 | * 24 | * @throws SQLException 25 | */ 26 | abstract void fillFromStream() throws SQLException; 27 | 28 | boolean delayLoadingLob = true; 29 | 30 | /** 31 | * Provides functionality for the result set to set whether to load the LOB objects fully. Setting this property to 32 | * TRUE will cause LOBs to be loaded into memory. The default behavior is FALSE. 33 | */ 34 | void setDelayLoadingLob() { 35 | delayLoadingLob = false; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/dataclassification/Label.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 Labels as received from SQL Server for the active resultSet 10 | */ 11 | public class Label { 12 | private String name; 13 | private String id; 14 | 15 | /** 16 | * Constructs a Label 17 | * 18 | * @param name 19 | * Name of Label 20 | * @param id 21 | * ID of Label 22 | */ 23 | public Label(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/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 List sensitivityProperties; 17 | 18 | /** 19 | * Constructs a ColumnSensitivity 20 | * 21 | * @param sensitivityProperties 22 | * List of sensitivity properties as received from SQL Server 23 | */ 24 | public ColumnSensitivity(List sensitivityProperties) { 25 | this.sensitivityProperties = new ArrayList<>(sensitivityProperties); 26 | } 27 | 28 | /** 29 | * Returns the list of sensitivity properties as received from Server for this ColumnSensitivity 30 | * information 31 | * 32 | * @return sensitivityProperties for this Class Object 33 | */ 34 | public List getSensitivityProperties() { 35 | return sensitivityProperties; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/sqlType/SqlDate.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 static org.junit.jupiter.api.Assertions.fail; 9 | 10 | import java.sql.Date; 11 | import java.sql.JDBCType; 12 | import java.text.ParseException; 13 | import java.text.SimpleDateFormat; 14 | import java.util.concurrent.ThreadLocalRandom; 15 | 16 | 17 | public class SqlDate extends SqlDateTime { 18 | 19 | static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); 20 | 21 | public SqlDate() { 22 | super("date", JDBCType.DATE, null, null); 23 | type = java.sql.Date.class; 24 | try { 25 | minvalue = new Date(dateFormat.parse((String) SqlTypeValue.DATE.minValue).getTime()); 26 | maxvalue = new Date(dateFormat.parse((String) SqlTypeValue.DATE.maxValue).getTime()); 27 | } catch (ParseException ex) { 28 | fail(ex.getMessage()); 29 | } 30 | } 31 | 32 | public Object createdata() { 33 | return new Date(ThreadLocalRandom.current().nextLong(((Date) minvalue).getTime(), ((Date) maxvalue).getTime())); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/mssql/googlecode/concurrentlinkedhashmap/Weigher.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 class that can determine the weight of a value. The total weight threshold 17 | * is used to determine when an eviction is required. 18 | * 19 | * @author ben.manes@gmail.com (Ben Manes) 20 | * @see 21 | * http://code.google.com/p/concurrentlinkedhashmap/ 22 | */ 23 | public interface Weigher { 24 | 25 | /** 26 | * Measures an object's weight to determine how many units of capacity that 27 | * the value consumes. A value must consume a minimum of one unit. 28 | * 29 | * @param value 30 | * the object to weigh 31 | * @return the object's weight 32 | */ 33 | int weightOf(V value); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/SQLServerEncryptionType.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 | * 13 | * Encryption types supported 14 | * 15 | */ 16 | enum SQLServerEncryptionType { 17 | DETERMINISTIC((byte) 1), 18 | RANDOMIZED((byte) 2), 19 | PLAINTEXT((byte) 0); 20 | 21 | final byte value; 22 | private static final SQLServerEncryptionType[] VALUES = values(); 23 | 24 | SQLServerEncryptionType(byte val) { 25 | this.value = val; 26 | } 27 | 28 | byte getValue() { 29 | return this.value; 30 | } 31 | 32 | static SQLServerEncryptionType of(byte val) throws SQLServerException { 33 | for (SQLServerEncryptionType type : VALUES) 34 | if (val == type.value) 35 | return type; 36 | 37 | // Invalid type. 38 | MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_unknownColumnEncryptionType")); 39 | Object[] msgArgs = {val}; 40 | SQLServerException.makeFromDriverError(null, null, form.format(msgArgs), null, true); 41 | 42 | // Make the compiler happy. 43 | return null; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /maven-version-rules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | (?i).*Alpha(?:-?\d+)? 6 | (?i).*Beta(?:-?\d+)? 7 | (?i).*-B(?:-?\d+)? 8 | (?i).*RC(?:-?\d+)? 9 | (?i).*EA(?:-?\d+)? 10 | (?i).*SNAPSHOT(?:-?\d+)? 11 | 12 | (?i).*M(?:-?\d+)? 13 | 14 | 15 | 16 | 17 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/main/java/mssql/googlecode/concurrentlinkedhashmap/EntryWeigher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 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 class that can determine the weight of an entry. The total weight threshold 17 | * is used to determine when an eviction is required. 18 | * 19 | * @author ben.manes@gmail.com (Ben Manes) 20 | * @see 21 | * http://code.google.com/p/concurrentlinkedhashmap/ 22 | */ 23 | public interface EntryWeigher { 24 | 25 | /** 26 | * Measures an entry's weight to determine how many units of capacity that 27 | * the key and value consumes. An entry must consume a minimum of one unit. 28 | * 29 | * @param key 30 | * the key to weigh 31 | * @param value 32 | * the value to weigh 33 | * @return the entry's weight 34 | */ 35 | int weightOf(K key, V value); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/StreamLoginAck.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 | * StreamLoginAck represents a TDS login ack. 10 | * 11 | */ 12 | 13 | final class StreamLoginAck extends StreamPacket { 14 | String sSQLServerVersion; 15 | int tdsVersion; 16 | 17 | StreamLoginAck() { 18 | super(TDS.TDS_LOGIN_ACK); 19 | } 20 | 21 | void setFromTDS(TDSReader tdsReader) throws SQLServerException { 22 | if (TDS.TDS_LOGIN_ACK != tdsReader.readUnsignedByte()) 23 | assert false; 24 | tdsReader.readUnsignedShort(); // length of this token stream 25 | tdsReader.readUnsignedByte(); // SQL version accepted by the server 26 | tdsVersion = tdsReader.readIntBigEndian(); // TDS version accepted by the server 27 | tdsReader.readUnicodeString(tdsReader.readUnsignedByte()); // Program name 28 | int serverMajorVersion = tdsReader.readUnsignedByte(); 29 | int serverMinorVersion = tdsReader.readUnsignedByte(); 30 | int serverBuildNumber = (tdsReader.readUnsignedByte() << 8) | tdsReader.readUnsignedByte(); 31 | 32 | sSQLServerVersion = serverMajorVersion + "." + ((serverMinorVersion <= 9) ? "0" : "") + serverMinorVersion + "." 33 | + serverBuildNumber; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/PerformanceLogCallback.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 | * Callback interface for publishing performance logs. 10 | */ 11 | public interface PerformanceLogCallback { 12 | 13 | /** 14 | * Publish performance log for connection-level activities. 15 | * @param activity The type of activity being logged. 16 | * @param connectionId The ID of the connection. 17 | * @param durationMs The duration of the operation in milliseconds. 18 | * @param exception An exception, if an error occurred. 19 | */ 20 | void publish(PerformanceActivity activity, int connectionId, long durationMs, Exception exception) throws Exception; 21 | 22 | /** 23 | * Publish performance log for statement-level activities. 24 | * @param activity The type of activity being logged. 25 | * @param connectionId The ID of the connection. 26 | * @param statementId The ID of the statement (if applicable). 27 | * @param durationMs The duration of the operation in milliseconds. 28 | * @param exception An exception, if an error occurred. 29 | */ 30 | void publish(PerformanceActivity activity, int connectionId, int statementId, long durationMs, Exception exception) throws Exception; 31 | 32 | } -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/SQLServerStatementColumnEncryptionSetting.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 | * Specifies how data will be sent and received when reading and writing encrypted columns. Depending on your specific 10 | * query, performance impact may be reduced by bypassing the Always Encrypted driver processing when non-encrypted 11 | * columns are being used. Note that these settings cannot be used to bypass encryption and gain access to plaintext 12 | * data. 13 | */ 14 | public enum SQLServerStatementColumnEncryptionSetting { 15 | /** 16 | * if "Column Encryption Setting=Enabled" in the connection string, use Enabled. Otherwise, maps to Disabled. 17 | */ 18 | USE_CONNECTION_SETTING, 19 | 20 | /** 21 | * Enables TCE for the command. Overrides the connection level setting for this command. 22 | */ 23 | ENABLED, 24 | 25 | /** 26 | * Parameters will not be encrypted, only the ResultSet will be decrypted. This is an optimization for queries that 27 | * do not pass any encrypted input parameters. Overrides the connection level setting for this command. 28 | */ 29 | RESULTSET_ONLY, 30 | 31 | /** 32 | * Disables TCE for the command.Overrides the connection level setting for this command. 33 | */ 34 | DISABLED, 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/sqlType/SqlNVarCharMax.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.testframework.sqlType; 6 | 7 | import java.sql.Clob; 8 | import java.sql.JDBCType; 9 | import java.sql.NClob; 10 | 11 | import com.microsoft.sqlserver.testframework.DBCoercion; 12 | import com.microsoft.sqlserver.testframework.DBConstants; 13 | 14 | 15 | public class SqlNVarCharMax extends SqlNVarChar { 16 | 17 | public SqlNVarCharMax() { 18 | super(); 19 | name = "nvarchar(max)"; 20 | jdbctype = JDBCType.LONGNVARCHAR; 21 | variableLengthType = VariableLengthType.Variable; 22 | 23 | coercions.add(new DBCoercion(Clob.class, 24 | new int[] {DBConstants.GET_COERCION, DBConstants.UPDATE_COERCION, DBConstants.UPDATEOBJECT_COERCION, 25 | DBConstants.SET_COERCION, DBConstants.SETOBJECT_COERCION, DBConstants.GETPARAM_COERCION, 26 | DBConstants.REG_COERCION, DBConstants.CHAR_COERCION})); 27 | coercions.add(new DBCoercion(NClob.class, 28 | new int[] {DBConstants.GET_COERCION, DBConstants.UPDATE_COERCION, DBConstants.UPDATEOBJECT_COERCION, 29 | DBConstants.SET_COERCION, DBConstants.SETOBJECT_COERCION, DBConstants.GETPARAM_COERCION, 30 | DBConstants.REG_COERCION, DBConstants.NCHAR_COERCION})); 31 | 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/jdbc/SharedTimerTest.java: -------------------------------------------------------------------------------- 1 | package com.microsoft.sqlserver.jdbc; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertFalse; 4 | 5 | import java.util.ArrayList; 6 | import java.util.concurrent.CompletableFuture; 7 | import java.util.concurrent.ExecutionException; 8 | import java.util.concurrent.ExecutorService; 9 | import java.util.concurrent.Executors; 10 | import java.util.concurrent.TimeUnit; 11 | import java.util.concurrent.TimeoutException; 12 | 13 | import org.junit.jupiter.api.Test; 14 | 15 | 16 | class SharedTimerTest { 17 | 18 | @Test 19 | void getTimer() throws InterruptedException, ExecutionException, TimeoutException { 20 | final int iterations = 500; 21 | ExecutorService executor = Executors.newFixedThreadPool(2); 22 | 23 | try { 24 | ArrayList> futures = new ArrayList<>(iterations); 25 | for (int i = 0; i < iterations; i++) { 26 | futures.add(CompletableFuture.runAsync(() -> SharedTimer.getTimer().removeRef(), executor)); 27 | } 28 | 29 | CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).get(2, TimeUnit.MINUTES); 30 | } finally { 31 | executor.shutdown(); 32 | // 5000ms wait time for the AzureDB connection to close, need full test in the 33 | // test lab for the exact time 34 | if (!executor.awaitTermination(5000, TimeUnit.MILLISECONDS)) { 35 | executor.shutdownNow(); 36 | } 37 | } 38 | 39 | assertFalse(SharedTimer.isRunning(), TestResource.getResource("R_sharedTimerStopOnNoRef")); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/sqlType/SqlBinary.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 | /** 13 | * Contains name, jdbctype, precision, scale for binary data type 14 | */ 15 | public class SqlBinary extends SqlType { 16 | 17 | /** 18 | * set JDBCType and precision for SqlBinary 19 | */ 20 | public SqlBinary() { 21 | this("binary", JDBCType.BINARY, 2000); 22 | } 23 | 24 | /** 25 | * 26 | * @param name 27 | * binary or varbinary 28 | * @param jdbctype 29 | * @param precision 30 | */ 31 | SqlBinary(String name, JDBCType jdbctype, int precision) { 32 | super(name, jdbctype, precision, 0, SqlTypeValue.BINARY.minValue, SqlTypeValue.BINARY.maxValue, 33 | SqlTypeValue.BINARY.nullValue, VariableLengthType.Precision, byte[].class); 34 | flags.set(FIXED); 35 | generatePrecision(); 36 | } 37 | 38 | /** 39 | * create random data for binary and varbinary column 40 | */ 41 | public Object createdata() { 42 | int dataLength = ThreadLocalRandom.current().nextInt(precision); 43 | byte[] bytes = new byte[dataLength]; 44 | ThreadLocalRandom.current().nextBytes(bytes); 45 | return bytes; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/spatialdatatypes/Figure.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 Figure. 10 | * 11 | */ 12 | public class Figure { 13 | private byte figuresAttribute; 14 | private int pointOffset; 15 | 16 | /** 17 | * Creates a Figure object 18 | * 19 | * @param figuresAttribute 20 | * figures attribute 21 | * @param pointOffset 22 | * points offset 23 | */ 24 | public Figure(byte figuresAttribute, int pointOffset) { 25 | this.figuresAttribute = figuresAttribute; 26 | this.pointOffset = pointOffset; 27 | } 28 | 29 | /** 30 | * Returns the figuresAttribute value. 31 | * 32 | * @return byte figuresAttribute value. 33 | */ 34 | public byte getFiguresAttribute() { 35 | return figuresAttribute; 36 | } 37 | 38 | /** 39 | * Returns the pointOffset value. 40 | * 41 | * @return int pointOffset value. 42 | */ 43 | public int getPointOffset() { 44 | return pointOffset; 45 | } 46 | 47 | /** 48 | * Sets the figuresAttribute value. 49 | * 50 | * @param fa 51 | * figuresAttribute value. 52 | */ 53 | public void setFiguresAttribute(byte fa) { 54 | figuresAttribute = fa; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/DBResultSetTypes.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.testframework; 6 | 7 | /** 8 | * @author Microsoft 9 | * 10 | */ 11 | 12 | public enum DBResultSetTypes { 13 | 14 | TYPE_FORWARD_ONLY_CONCUR_READ_ONLY(DBConstants.RESULTSET_TYPE_FORWARD_ONLY, DBConstants.RESULTSET_CONCUR_READ_ONLY), 15 | TYPE_SCROLL_INSENSITIVE_CONCUR_READ_ONLY(DBConstants.RESULTSET_TYPE_SCROLL_INSENSITIVE, DBConstants.RESULTSET_CONCUR_READ_ONLY), 16 | TYPE_SCROLL_SENSITIVE_CONCUR_READ_ONLY(DBConstants.RESULTSET_TYPE_SCROLL_SENSITIVE, DBConstants.RESULTSET_CONCUR_READ_ONLY), 17 | TYPE_FORWARD_ONLY_CONCUR_UPDATABLE(DBConstants.RESULTSET_TYPE_FORWARD_ONLY, DBConstants.RESULTSET_CONCUR_UPDATABLE), 18 | TYPE_SCROLL_SENSITIVE_CONCUR_UPDATABLE(DBConstants.RESULTSET_TYPE_SCROLL_SENSITIVE, DBConstants.RESULTSET_CONCUR_UPDATABLE), 19 | TYPE_DYNAMIC_CONCUR_OPTIMISTIC(DBConstants.RESULTSET_TYPE_DYNAMIC, DBConstants.RESULTSET_CONCUR_OPTIMISTIC), 20 | TYPE_CURSOR_FORWARDONLY_CONCUR_UPDATABLE(DBConstants.RESULTSET_TYPE_CURSOR_FORWARDONLY, DBConstants.RESULTSET_CONCUR_READ_ONLY),; 21 | 22 | public int resultsetCursor; 23 | public int resultSetConcurrency; 24 | 25 | DBResultSetTypes(int resultSetCursor, int resultSetConcurrency) { 26 | this.resultsetCursor = resultSetCursor; 27 | this.resultSetConcurrency = resultSetConcurrency; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerDataRecord.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 | * Provides an interface to create classes that read in data from any source (such as a file) and allow a structured 10 | * type to be sent to SQL Server tables. 11 | */ 12 | public interface ISQLServerDataRecord { 13 | /** 14 | * Returns the column meta data. 15 | * 16 | * @param column 17 | * the first column is 1, the second is 2, and so on 18 | * @return SQLServerMetaData of column 19 | */ 20 | SQLServerMetaData getColumnMetaData(int column); 21 | 22 | /** 23 | * Returns the column count. 24 | * 25 | * @return Set of ordinals for the columns. 26 | */ 27 | int getColumnCount(); 28 | 29 | /** 30 | * Returns the data for the current row as an array of Objects. 31 | * 32 | * Each Object must match the Java language Type that is used to represent the indicated JDBC data type for the 33 | * given column. For more information, see 'Understanding the JDBC Driver Data Types' for the appropriate mappings. 34 | * 35 | * @return The data for the row. 36 | */ 37 | Object[] getRowData(); 38 | 39 | /** 40 | * Advances to the next data row. 41 | * 42 | * @return True if rows are available; false if there are no more rows 43 | */ 44 | boolean next(); 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/sqlType/SqlSmallDateTime.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 static org.junit.jupiter.api.Assertions.fail; 9 | 10 | import java.sql.JDBCType; 11 | import java.sql.Timestamp; 12 | import java.text.ParseException; 13 | import java.text.SimpleDateFormat; 14 | import java.util.concurrent.ThreadLocalRandom; 15 | 16 | 17 | public class SqlSmallDateTime extends SqlDateTime { 18 | static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss"); 19 | 20 | public SqlSmallDateTime() { 21 | super("smalldatetime", JDBCType.TIMESTAMP, null, null); 22 | try { 23 | minvalue = new Timestamp(dateFormat.parse((String) SqlTypeValue.SMALLDATETIME.minValue).getTime()); 24 | maxvalue = new Timestamp(dateFormat.parse((String) SqlTypeValue.SMALLDATETIME.maxValue).getTime()); 25 | } catch (ParseException ex) { 26 | fail(ex.getMessage()); 27 | } 28 | } 29 | 30 | public Object createdata() { 31 | Timestamp smallDateTime = new Timestamp(ThreadLocalRandom.current().nextLong(((Timestamp) minvalue).getTime(), 32 | ((Timestamp) maxvalue).getTime())); 33 | // remove the random nanosecond value if any 34 | smallDateTime.setNanos(0); 35 | return smallDateTime.toString().substring(0, 19);// ignore the nano second portion 36 | // return smallDateTime; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/SQLServerJdbc42.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.sql.BatchUpdateException; 9 | 10 | 11 | /** 12 | * Shims for JDBC 4.2 JAR. 13 | * 14 | * JDBC 4.2 public methods should always check the SQLServerJdbcVersion first to make sure that they are not operable in 15 | * any earlier driver version. That is, they should throw an exception, be a no-op, or whatever. 16 | */ 17 | 18 | final class DriverJDBCVersion { 19 | // The 4.2 driver is compliant to JDBC 4.2. 20 | static final int MAJOR = 4; 21 | static final int MINOR = 2; 22 | 23 | private DriverJDBCVersion() { 24 | throw new UnsupportedOperationException(SQLServerException.getErrString("R_notSupported")); 25 | } 26 | 27 | static final boolean checkSupportsJDBC43() { 28 | return false; 29 | } 30 | 31 | static final void throwBatchUpdateException(SQLServerException lastError, 32 | long[] updateCounts) throws BatchUpdateException { 33 | throw new BatchUpdateException(lastError.getMessage(), lastError.getSQLState(), lastError.getErrorCode(), 34 | updateCounts, new Throwable(lastError.getMessage())); 35 | } 36 | 37 | static SQLServerConnection getSQLServerConnection(String parentInfo) throws SQLServerException { 38 | return new SQLServerConnection(parentInfo); 39 | } 40 | 41 | /** Client process ID sent during login */ 42 | private static int pid = 0; 43 | 44 | static int getProcessId() { 45 | return pid; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/DummyKeyStoreProvider.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 com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionKeyStoreProvider; 8 | import com.microsoft.sqlserver.jdbc.SQLServerException; 9 | 10 | 11 | /** 12 | * DummyKeyStoreProvider Class for Tests. 13 | * 14 | */ 15 | public class DummyKeyStoreProvider extends SQLServerColumnEncryptionKeyStoreProvider { 16 | public String name = "DUMMY_PROVIDER"; 17 | 18 | public void setName(String name) { 19 | this.name = name; 20 | } 21 | 22 | public String getName() { 23 | return this.name; 24 | } 25 | 26 | @Override 27 | public byte[] decryptColumnEncryptionKey(String masterKeyPath, String encryptionAlgorithm, 28 | byte[] encryptedColumnEncryptionKey) throws SQLServerException { 29 | // Not implemented 30 | throw new UnsupportedOperationException(); 31 | } 32 | 33 | @Override 34 | public byte[] encryptColumnEncryptionKey(String masterKeyPath, String encryptionAlgorithm, 35 | byte[] columnEncryptionKey) throws SQLServerException { 36 | // Not implemented 37 | throw new UnsupportedOperationException(); 38 | } 39 | 40 | @Override 41 | public boolean verifyColumnMasterKeyMetadata(String masterKeyPath, boolean allowEnclaveComputations, 42 | byte[] signature) throws SQLServerException { 43 | // Not implemented 44 | throw new UnsupportedOperationException(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/StreamRetValue.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 | * StreamRetValue represents a TDS return value. 10 | */ 11 | final class StreamRetValue extends StreamPacket { 12 | @SuppressWarnings("unused") 13 | private String paramName; 14 | 15 | /* 16 | * TDS 7.2: Indicates ordinal position of the OUTPUT parameter in the original RPC call TDS 7.1: Indicates the 17 | * length of the return value 18 | */ 19 | private int ordinalOrLength; 20 | 21 | int getOrdinalOrLength() { 22 | return ordinalOrLength; 23 | } 24 | 25 | int getStatus() { 26 | return status; 27 | } 28 | 29 | /* 30 | * Status: 0x01 if the return value is an OUTPUT parameter of a stored procedure 0x02 if the return value is from a 31 | * User Defined Function 32 | */ 33 | @SuppressWarnings("unused") 34 | private int status; 35 | 36 | StreamRetValue() { 37 | super(TDS.TDS_RETURN_VALUE); 38 | } 39 | 40 | void setFromTDS(TDSReader tdsReader) throws SQLServerException { 41 | if (TDS.TDS_RETURN_VALUE != tdsReader.readUnsignedByte()) 42 | assert false; 43 | ordinalOrLength = tdsReader.readUnsignedShort(); 44 | paramName = tdsReader.readUnicodeString(tdsReader.readUnsignedByte()); 45 | status = tdsReader.readUnsignedByte(); 46 | } 47 | 48 | CryptoMetadata getCryptoMetadata(TDSReader tdsReader) throws SQLServerException { 49 | return (new StreamColumns()).readCryptoMetadata(tdsReader); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/samples/sparse/pom.xml: -------------------------------------------------------------------------------- 1 | 56 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/spatialdatatypes/Point.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 Point. 10 | * 11 | */ 12 | public class Point { 13 | private final double x; 14 | private final double y; 15 | private final double z; 16 | private final double m; 17 | 18 | /** 19 | * Creates a Point object 20 | * 21 | * @param x 22 | * x value 23 | * @param y 24 | * y value 25 | * @param z 26 | * z value 27 | * @param m 28 | * m value 29 | */ 30 | public Point(double x, double y, double z, double m) { 31 | this.x = x; 32 | this.y = y; 33 | this.z = z; 34 | this.m = m; 35 | } 36 | 37 | /** 38 | * Returns the x coordinate value. 39 | * 40 | * @return double x coordinate value. 41 | */ 42 | public double getX() { 43 | return x; 44 | } 45 | 46 | /** 47 | * Returns the y coordinate value. 48 | * 49 | * @return double y coordinate value. 50 | */ 51 | public double getY() { 52 | return y; 53 | } 54 | 55 | /** 56 | * Returns the z (elevation) value. 57 | * 58 | * @return double z value. 59 | */ 60 | public double getZ() { 61 | return z; 62 | } 63 | 64 | /** 65 | * Returns the m (measure) value. 66 | * 67 | * @return double m value. 68 | */ 69 | public double getM() { 70 | return m; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/dns/DNSKerberosLocator.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.dns; 6 | 7 | import java.util.Set; 8 | 9 | import javax.naming.NameNotFoundException; 10 | import javax.naming.NamingException; 11 | 12 | 13 | /** 14 | * Represents a DNS Kerberos Locator 15 | */ 16 | public final class DNSKerberosLocator { 17 | 18 | private DNSKerberosLocator() {} 19 | 20 | /** 21 | * Returns whether a realm is valid by retrieving the KDC list in DNS SRV records. 22 | * This will only work if DNS lookup is setup properly or the realms are properly defined in krb5 config file. 23 | * Otherwise this will fail since the realm cannot be found. 24 | * 25 | * @param realmName 26 | * the realm to test 27 | * @return true if realm is valid, false otherwise 28 | * @throws NamingException 29 | * if DNS failed, so realm existence cannot be determined 30 | */ 31 | public static boolean isRealmValid(String realmName) throws NamingException { 32 | if (realmName == null || realmName.length() < 2) { 33 | return false; 34 | } 35 | if (realmName.charAt(0) == ('.')) { 36 | realmName = realmName.substring(1); 37 | } 38 | try { 39 | Set records = DNSUtilities.findSrvRecords("_kerberos._udp." + realmName); 40 | return !records.isEmpty(); 41 | } catch (NameNotFoundException wrongDomainException) { 42 | // config error - domain controller cannot be located via DNS 43 | return false; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/mssql/googlecode/concurrentlinkedhashmap/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Google Inc. All Rights Reserved. 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a 4 | * copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 7 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations 8 | * under the License. 9 | */ 10 | 11 | /** 12 | * This package contains an implementation of a bounded {@link java.util.concurrent.ConcurrentMap} data structure. 13 | *

14 | * {@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 { 34 | 35 | /** 36 | * A call-back notification that the entry was evicted. 37 | * 38 | * @param key 39 | * the entry's key 40 | * @param value 41 | * the entry's value 42 | */ 43 | void onEviction(K key, V value); 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/SQLServerNClob.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.InputStream; 9 | import java.sql.NClob; 10 | import java.sql.SQLException; 11 | import java.util.logging.Logger; 12 | 13 | 14 | /** 15 | * Represents a National Character Set LOB object and implements java.sql.NClob. 16 | */ 17 | public final class SQLServerNClob extends SQLServerClobBase implements NClob { 18 | 19 | /** 20 | * Always refresh SerialVersionUID when prompted 21 | */ 22 | private static final long serialVersionUID = 3593610902551842327L; 23 | 24 | // Loggers should be class static to avoid lock contention with multiple 25 | // threads 26 | private static final Logger logger = Logger.getLogger("com.microsoft.sqlserver.jdbc.internals.SQLServerNClob"); 27 | 28 | SQLServerNClob(SQLServerConnection connection) { 29 | super(connection, "", connection.getDatabaseCollation(), logger, null); 30 | this.setDefaultCharset(java.nio.charset.StandardCharsets.UTF_16LE); 31 | } 32 | 33 | SQLServerNClob(BaseInputStream stream, TypeInfo typeInfo) { 34 | super(null, stream, typeInfo.getSQLCollation(), logger, typeInfo); 35 | this.setDefaultCharset(java.nio.charset.StandardCharsets.UTF_16LE); 36 | } 37 | 38 | @Override 39 | public InputStream getAsciiStream() throws SQLException { 40 | // NClobs are mapped to Nvarchar(max), and are always UTF-16 encoded. This API expects a US_ASCII stream. 41 | // It's not possible to modify the stream without loading it into memory. Users should use getCharacterStream. 42 | this.fillFromStream(); 43 | return super.getAsciiStream(); 44 | } 45 | 46 | @Override 47 | final JDBCType getJdbcType() { 48 | return JDBCType.NCLOB; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyTestSetUp.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.bulkCopy; 6 | 7 | import java.sql.SQLException; 8 | 9 | import com.microsoft.sqlserver.jdbc.TestUtils; 10 | import org.junit.jupiter.api.AfterAll; 11 | import org.junit.jupiter.api.BeforeAll; 12 | import org.junit.platform.runner.JUnitPlatform; 13 | import org.junit.runner.RunWith; 14 | 15 | import com.microsoft.sqlserver.testframework.AbstractTest; 16 | import com.microsoft.sqlserver.testframework.DBConnection; 17 | import com.microsoft.sqlserver.testframework.DBPreparedStatement; 18 | import com.microsoft.sqlserver.testframework.DBStatement; 19 | import com.microsoft.sqlserver.testframework.DBTable;; 20 | 21 | 22 | /** 23 | * Create and drop source table needed for testing bulk copy 24 | */ 25 | @RunWith(JUnitPlatform.class) 26 | public class BulkCopyTestSetUp extends AbstractTest { 27 | 28 | static DBTable sourceTable; 29 | 30 | /** 31 | * Create source table needed for testing bulk copy 32 | * 33 | * @throws SQLException 34 | */ 35 | @BeforeAll 36 | public static void setUpSourceTable() throws Exception { 37 | setConnection(); 38 | 39 | try (DBConnection con = new DBConnection(connectionString); DBStatement stmt = con.createStatement(); 40 | DBPreparedStatement pstmt = new DBPreparedStatement(con);) { 41 | sourceTable = new DBTable(true); 42 | stmt.createTable(sourceTable); 43 | pstmt.populateTable(sourceTable); 44 | } 45 | } 46 | 47 | /** 48 | * drop source table after testing bulk copy 49 | * 50 | * @throws SQLException 51 | */ 52 | @AfterAll 53 | public static void dropSourceTable() throws SQLException { 54 | try (DBConnection con = new DBConnection(connectionString); DBStatement stmt = con.createStatement()) { 55 | stmt.dropTable(sourceTable); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/SQLServerJdbc43.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.sql.BatchUpdateException; 9 | 10 | 11 | /** 12 | * Shims for JDBC 4.3 JAR. 13 | * 14 | * JDBC 4.3 public methods should always check the SQLServerJdbcVersion first to make sure that they are not operable in 15 | * any earlier driver version. That is, they should throw an exception, be a no-op, or whatever. 16 | */ 17 | 18 | final class DriverJDBCVersion { 19 | // The 4.3 driver is compliant to JDBC 4.3. 20 | static final int MAJOR = 4; 21 | static final int MINOR = 3; 22 | 23 | private DriverJDBCVersion() { 24 | throw new UnsupportedOperationException(SQLServerException.getErrString("R_notSupported")); 25 | } 26 | 27 | static final boolean checkSupportsJDBC43() { 28 | return true; 29 | } 30 | 31 | static final void throwBatchUpdateException(SQLServerException lastError, 32 | long[] updateCounts) throws BatchUpdateException { 33 | throw new BatchUpdateException(lastError.getMessage(), lastError.getSQLState(), lastError.getErrorCode(), 34 | updateCounts, new Throwable(lastError.getMessage())); 35 | } 36 | 37 | private static double jvmVersion = Double.parseDouble(Util.SYSTEM_SPEC_VERSION); 38 | 39 | static SQLServerConnection getSQLServerConnection(String parentInfo) throws SQLServerException { 40 | return jvmVersion >= 9 ? new SQLServerConnection43(parentInfo) : new SQLServerConnection(parentInfo); 41 | } 42 | 43 | /** Client process ID sent during login */ 44 | private static int pid = 0; 45 | 46 | static { 47 | long pidLong = 0; 48 | try { 49 | pidLong = ProcessHandle.current().pid(); 50 | } catch (NoClassDefFoundError e) { // ProcessHandle is Java 9+ 51 | } 52 | pid = (pidLong > Integer.MAX_VALUE) ? 0 : (int) pidLong; 53 | } 54 | 55 | static int getProcessId() { 56 | return pid; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection43.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.sql.SQLException; 9 | import java.sql.ShardingKey; 10 | 11 | 12 | /** 13 | * Extends {@link SQLServerConnection43} and implements {@link ISQLServerConnection43} with methods introduced in JDBC 14 | * 4.3 Specifications. This class is used by the driver when initializing a class with with JDBC 4.3 Specs supported 15 | * JVM. 16 | */ 17 | public class SQLServerConnection43 extends SQLServerConnection implements ISQLServerConnection43 { 18 | 19 | /** 20 | * Always refresh SerialVersionUID when prompted. 21 | */ 22 | private static final long serialVersionUID = -6904163521498951547L; 23 | 24 | SQLServerConnection43(String parentInfo) throws SQLServerException { 25 | super(parentInfo); 26 | } 27 | 28 | @Override 29 | public void beginRequest() throws SQLException { 30 | beginRequestInternal(); 31 | } 32 | 33 | @Override 34 | public void endRequest() throws SQLException { 35 | endRequestInternal(); 36 | } 37 | 38 | @Override 39 | public void setShardingKey(ShardingKey shardingKey) throws SQLException { 40 | SQLServerException.throwFeatureNotSupportedException(); 41 | } 42 | 43 | @Override 44 | public void setShardingKey(ShardingKey shardingKey, ShardingKey superShardingKey) throws SQLException { 45 | SQLServerException.throwFeatureNotSupportedException(); 46 | } 47 | 48 | @Override 49 | public boolean setShardingKeyIfValid(ShardingKey shardingKey, int timeout) throws SQLException { 50 | SQLServerException.throwFeatureNotSupportedException(); 51 | return false; 52 | } 53 | 54 | @Override 55 | public boolean setShardingKeyIfValid(ShardingKey shardingKey, ShardingKey superShardingKey, 56 | int timeout) throws SQLException { 57 | SQLServerException.throwFeatureNotSupportedException(); 58 | return false; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/MaxResultBufferCounter.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 | import java.util.logging.Level; 10 | import java.util.logging.Logger; 11 | 12 | 13 | /** 14 | * Implementation of ICounter for 'maxResultBuffer' property. 15 | */ 16 | public class MaxResultBufferCounter implements ICounter { 17 | 18 | private final Logger logger = Logger.getLogger("com.microsoft.sqlserver.jdbc.MaxResultBufferCounter"); 19 | 20 | private long counter = 0; 21 | private final long maxResultBuffer; 22 | 23 | /** 24 | * Creates a MaxResultBufferCounter with the given max results buffer 25 | * 26 | * @param maxResultBuffer 27 | * max result buffer 28 | */ 29 | public MaxResultBufferCounter(long maxResultBuffer) { 30 | this.maxResultBuffer = maxResultBuffer; 31 | } 32 | 33 | public void increaseCounter(long bytes) throws SQLServerException { 34 | if (maxResultBuffer > 0) { 35 | counter += bytes; 36 | checkForMaxResultBufferOverflow(counter); 37 | } 38 | } 39 | 40 | public void resetCounter() { 41 | counter = 0; 42 | } 43 | 44 | private void checkForMaxResultBufferOverflow(long number) throws SQLServerException { 45 | if (number > maxResultBuffer) { 46 | if (logger.isLoggable(Level.SEVERE)) { 47 | logger.log(Level.SEVERE, SQLServerException.getErrString("R_maxResultBufferPropertyExceeded"), 48 | new Object[] {number, maxResultBuffer}); 49 | } 50 | throwExceededMaxResultBufferException(counter, maxResultBuffer); 51 | } 52 | } 53 | 54 | private void throwExceededMaxResultBufferException(Object... arguments) throws SQLServerException { 55 | MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_maxResultBufferPropertyExceeded")); 56 | throw new SQLServerException(form.format(arguments), null); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/sqlType/SqlTypeValue.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.math.BigDecimal; 9 | 10 | 11 | /* 12 | * Maps SQL type to its minimum, maximum and null value temporal min/max values used are not DATEFORMAT dependent as in 13 | * https://msdn.microsoft.com/en-us/library/ms180878.aspx 14 | */ 15 | enum SqlTypeValue { 16 | // minValue // maxValue // nullValue 17 | BIGINT(Long.MIN_VALUE, Long.MAX_VALUE, 0L), 18 | INTEGER(Integer.MIN_VALUE, Integer.MAX_VALUE, 0), 19 | SMALLINT(Short.MIN_VALUE, Short.MAX_VALUE, (short) 0), 20 | TINYINT((short) 0, (short) 255, (short) 0), 21 | BIT(0, 1, null), 22 | DECIMAL(new BigDecimal("-1.0E38").add(new BigDecimal("1")), new BigDecimal("1.0E38") 23 | .subtract(new BigDecimal("1")), null), 24 | MONEY(new BigDecimal("-922337203685477.5808"), new BigDecimal("+922337203685477.5807"), null), 25 | SMALLMONEY(new BigDecimal("-214748.3648"), new BigDecimal("214748.3647"), null), 26 | FLOAT(-1.79E308, +1.79E308, 0d), 27 | REAL((float) -3.4E38, (float) +3.4E38, 0f), 28 | CHAR(null, null, null), // CHAR used by char, nchar, varchar, nvarchar 29 | BINARY(null, null, null), 30 | DATETIME("17530101T00:00:00.000", "99991231T23:59:59.997", null), 31 | DATE("00010101", "99991231", null), 32 | TIME("00:00:00.0000000", "23:59:59.9999999", null), 33 | SMALLDATETIME("19000101T00:00:00", "20790606T23:59:59", null), 34 | DATETIME2("00010101T00:00:00.0000000", "99991231T23:59:59.9999999", null), 35 | DATETIMEOFFSET("0001-01-01 00:00:00", "9999-12-31 23:59:59", null), 36 | JSON(null, null, null),; 37 | 38 | Object minValue; 39 | Object maxValue; 40 | Object nullValue; 41 | 42 | static final int MAX_DECIMAL_PRECISION = 38; 43 | 44 | SqlTypeValue(Object minValue, Object maxValue, Object nullValue) { 45 | this.minValue = minValue; 46 | this.maxValue = maxValue; 47 | this.nullValue = nullValue; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/UDTTDSHeader.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 | * UDTTDSHeader is helper class used to read and write the UDT TDS 7.2x header from a TDS stream. 10 | * 11 | * Typical UDT header-> 12 | * 13 | * UDT header with schema/type/assembly information 14 | * 15 | * F0 21 00 <- MaxLen (2 byte length) 03|54 00 44 00 53 00 <- DB_NAME (1 byte length in UNICODE chars) 03|64 00 62 00 6F 16 | * 00 <- SCHEMA_NAME (1 byte length in UNICODE chars) 12|4D 00 79 00 43 00 68 00 75 00 6E 00 6B 00 79 <- TYPE_NAME (1 17 | * byte length in UNICODE chars) 00 46 00 75 00 6E 00 6B 00 79 00 54 00 79 00 70 00 65 00 32 00 63 00|4D 00 79 00 43 00 18 | * 68 00 75 00 6E 00 6B 00 <- ASSEMBLY_QUALIFIED_NAME (2 byte length in UNICODE chars) 79 00 46 00 75 00 6E 00 6B 00 79 19 | * 00 54 00 79 00 70 00 65 00 32 00 2C 00 20 00 53 00 71 00 6C 00 20 | * 21 | */ 22 | 23 | final class UDTTDSHeader { 24 | private final int maxLen; // MaxLen read from UDT type (not used when writing). 25 | @SuppressWarnings("unused") 26 | private final String databaseName; // Database name where UDT type resides. 27 | @SuppressWarnings("unused") 28 | private final String schemaName; // Schema where UDT resides. 29 | private final String typeName; // Type name of UDT. 30 | @SuppressWarnings("unused") 31 | private final String assemblyQualifiedName; // Assembly qualified name of UDT. 32 | 33 | UDTTDSHeader(TDSReader tdsReader) throws SQLServerException { 34 | maxLen = tdsReader.readUnsignedShort(); 35 | databaseName = tdsReader.readUnicodeString(tdsReader.readUnsignedByte()); 36 | schemaName = tdsReader.readUnicodeString(tdsReader.readUnsignedByte()); 37 | typeName = tdsReader.readUnicodeString(tdsReader.readUnsignedByte()); 38 | assemblyQualifiedName = tdsReader.readUnicodeString(tdsReader.readUnsignedShort()); 39 | } 40 | 41 | int getMaxLen() { 42 | return maxLen; 43 | } 44 | 45 | String getTypeName() { 46 | return typeName; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/jdbc/connection/XADataSourceTest.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.connection; 7 | 8 | import java.sql.Connection; 9 | 10 | import javax.sql.XAConnection; 11 | 12 | import com.microsoft.sqlserver.jdbc.TestUtils; 13 | import org.junit.jupiter.api.BeforeAll; 14 | import org.junit.jupiter.api.Tag; 15 | import org.junit.jupiter.api.Test; 16 | import org.junit.platform.runner.JUnitPlatform; 17 | import org.junit.runner.RunWith; 18 | 19 | import com.microsoft.sqlserver.jdbc.SQLServerDataSource; 20 | import com.microsoft.sqlserver.jdbc.SQLServerXADataSource; 21 | import com.microsoft.sqlserver.testframework.AbstractTest; 22 | import com.microsoft.sqlserver.testframework.Constants; 23 | 24 | 25 | @RunWith(JUnitPlatform.class) 26 | @Tag(Constants.reqExternalSetup) 27 | public class XADataSourceTest extends AbstractTest { 28 | private static String connectionUrlSSL = connectionString; 29 | 30 | @BeforeAll 31 | public static void setupTests() throws Exception { 32 | setConnection(); 33 | } 34 | 35 | /** 36 | * Tests XA connection with PKCS12 truststore that is password protected. 37 | * 38 | * Only re-populate the truststore if need arises in the future. TestUtils.createTrustStore() can be used to create 39 | * the truststore. 40 | * 41 | * @throws Exception 42 | */ 43 | @Tag(Constants.xAzureSQLDB) 44 | @Tag(Constants.xAzureSQLDW) 45 | @Test 46 | public void testPKCS12() throws Exception { 47 | org.junit.Assume.assumeTrue(System.getProperty("os.name").startsWith("Windows")); 48 | 49 | SQLServerXADataSource ds = new SQLServerXADataSource(); 50 | 51 | String trustStore = System.getProperty("pkcs12_truststore"); 52 | String url = connectionUrlSSL + "trustStore=" + trustStore + ";"; 53 | ds.setURL(url); 54 | ds.setTrustStorePassword(System.getProperty("pkcs12_truststore_password")); 55 | XAConnection connection = ds.getXAConnection(); 56 | connection.close(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/StringUtils.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 | * Provides a utility class for Strings. 10 | * 11 | * @since 6.1.2 12 | */ 13 | public class StringUtils { 14 | 15 | /** 16 | * string containing a space 17 | */ 18 | public static final String SPACE = " "; 19 | 20 | /** 21 | * empty string 22 | */ 23 | public static final String EMPTY = ""; 24 | 25 | /** 26 | * Developer should not create {@code StringUtils} instance in standard programming. Instead, the class should be 27 | * used as {@code StringUtils.isEmpty("String")} 28 | */ 29 | private StringUtils() { 30 | // Hiding constructor. 31 | } 32 | 33 | /** 34 | * Returns if String is null 35 | * 36 | * @param charSequence 37 | * {@link CharSequence} Can provide null 38 | * @return {@link Boolean} if provided char sequence is null or empty / blank 39 | * @since 6.1.2 40 | */ 41 | public static boolean isEmpty(final CharSequence charSequence) { 42 | return charSequence == null || charSequence.length() == 0; 43 | } 44 | 45 | /** 46 | * Returns if String is numeric or not. 47 | * 48 | * @param str 49 | * {@link String} 50 | * @return {@link Boolean} if provided String is numeric or not. 51 | */ 52 | public static boolean isNumeric(final String str) { 53 | return !isEmpty(str) && str.matches("\\d+(\\.\\d+)?"); 54 | } 55 | 56 | /** 57 | * Returns if string is integer or not 58 | * 59 | * @param str 60 | * {@link String} 61 | * @return {@link Boolean} if provided String is Integer or not. 62 | */ 63 | public static boolean isInteger(final String str) { 64 | try { 65 | Integer.parseInt(str); 66 | return true; 67 | } catch (NumberFormatException e) { 68 | // Nothing. this is not integer. 69 | } 70 | return false; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/StreamColInfo.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 | * StreamColInfo interprets the data stream from a COLINFO TDS token 10 | */ 11 | 12 | final class StreamColInfo extends StreamPacket { 13 | private TDSReader tdsReader; 14 | private TDSReaderMark colInfoMark; 15 | 16 | StreamColInfo() { 17 | super(TDS.TDS_COLINFO); 18 | } 19 | 20 | void setFromTDS(TDSReader tdsReader) throws SQLServerException { 21 | if (TDS.TDS_COLINFO != tdsReader.readUnsignedByte()) 22 | assert false : "Not a COLINFO token"; 23 | 24 | this.tdsReader = tdsReader; 25 | int tokenLength = tdsReader.readUnsignedShort(); 26 | colInfoMark = tdsReader.mark(); 27 | tdsReader.skip(tokenLength); 28 | } 29 | 30 | int applyTo(Column[] columns) throws SQLServerException { 31 | int numTables = 0; 32 | 33 | // Read and apply the column info for each column 34 | TDSReaderMark currentMark = tdsReader.mark(); 35 | tdsReader.reset(colInfoMark); 36 | for (Column col : columns) { 37 | // Ignore the column number, per TDS spec. 38 | // Column info is returned for each column, ascending by column index, 39 | // so iterating through the column info is sufficient. 40 | tdsReader.readUnsignedByte(); 41 | 42 | // Set the column's table number, keeping track of the maximum table number 43 | // representing the number of tables encountered. 44 | col.setTableNum(tdsReader.readUnsignedByte()); 45 | if (col.getTableNum() > numTables) 46 | numTables = col.getTableNum(); 47 | 48 | // Set the other column info 49 | col.setInfoStatus(tdsReader.readUnsignedByte()); 50 | if (col.hasDifferentName()) 51 | col.setBaseColumnName(tdsReader.readUnicodeString(tdsReader.readUnsignedByte())); 52 | } 53 | 54 | tdsReader.reset(currentMark); 55 | return numTables; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/samples/connections/pom.xml: -------------------------------------------------------------------------------- 1 | 72 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/sqlType/SqlDateTime.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 static org.junit.jupiter.api.Assertions.fail; 9 | 10 | import java.sql.JDBCType; 11 | import java.sql.Timestamp; 12 | import java.text.ParseException; 13 | import java.text.SimpleDateFormat; 14 | import java.util.Random; 15 | import java.util.concurrent.ThreadLocalRandom; 16 | 17 | 18 | public class SqlDateTime extends SqlType { 19 | 20 | static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss.SSS"); 21 | 22 | public SqlDateTime() { 23 | this("datetime", JDBCType.TIMESTAMP, null, null); 24 | try { 25 | minvalue = new Timestamp(dateFormat.parse((String) SqlTypeValue.DATETIME.minValue).getTime()); 26 | maxvalue = new Timestamp(dateFormat.parse((String) SqlTypeValue.DATETIME.maxValue).getTime()); 27 | } catch (ParseException ex) { 28 | fail(ex.getMessage()); 29 | } 30 | } 31 | 32 | SqlDateTime(String name, JDBCType jdbctype, Object min, Object max) { 33 | super(name, jdbctype, 0, 0, min, max, SqlTypeValue.DATETIME.nullValue, VariableLengthType.Fixed, 34 | java.sql.Timestamp.class); 35 | } 36 | 37 | public Object createdata() { 38 | return new Timestamp(ThreadLocalRandom.current().nextLong(((Timestamp) minvalue).getTime(), 39 | ((Timestamp) maxvalue).getTime())); 40 | } 41 | 42 | protected int generateRandomInt(int length) { 43 | Random rnd = new Random(); 44 | int power = (int) Math.pow(10, length - 1); 45 | 46 | // Example of how this works: 47 | // if length is 3, then we add 100 + random number between 0~899, so that we get a random number between 48 | // 100~999. 49 | int randomNumeric; 50 | if (length <= 0) { 51 | randomNumeric = 0; 52 | } else if (length == 1) { 53 | randomNumeric = rnd.nextInt(10); 54 | } else { 55 | randomNumeric = power + rnd.nextInt((int) (9 * power)); 56 | } 57 | 58 | return randomNumeric; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/SqlAuthenticationToken.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.util.Date; 10 | 11 | 12 | /** 13 | * Provides an implementation of a SqlAuthenticationToken 14 | */ 15 | public class SqlAuthenticationToken implements Serializable { 16 | 17 | /** Always update serialVersionUID when prompted **/ 18 | private static final long serialVersionUID = -1343105491285383937L; 19 | 20 | /** The token expiration date. **/ 21 | private final Date expiresOn; 22 | 23 | /** The access token string. **/ 24 | private final String accessToken; 25 | 26 | /** 27 | * Constructs a SqlAuthentication token. 28 | * 29 | * @param accessToken 30 | * The access token string. 31 | * @param expiresOn 32 | * The expiration date in milliseconds since the unix epoch. 33 | */ 34 | public SqlAuthenticationToken(String accessToken, long expiresOn) { 35 | this.accessToken = accessToken; 36 | this.expiresOn = new Date(expiresOn); 37 | } 38 | 39 | /** 40 | * Constructs a SqlAuthentication token. 41 | * 42 | * @param accessToken 43 | * The access token string. 44 | * @param expiresOn 45 | * The expiration date. 46 | */ 47 | public SqlAuthenticationToken(String accessToken, Date expiresOn) { 48 | this.accessToken = accessToken; 49 | this.expiresOn = expiresOn; 50 | } 51 | 52 | /** 53 | * Returns the expiration date of the token. 54 | * 55 | * @return The token expiration date. 56 | */ 57 | public Date getExpiresOn() { 58 | return expiresOn; 59 | } 60 | 61 | /** 62 | * Returns the access token string. 63 | * 64 | * @return The access token. 65 | */ 66 | public String getAccessToken() { 67 | return accessToken; 68 | } 69 | 70 | public String toString() { 71 | return "accessToken hashCode: " + accessToken.hashCode() + " expiresOn: " + expiresOn.toInstant().toString(); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/osgi/Activator.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.osgi; 6 | 7 | import java.util.Dictionary; 8 | import java.util.Hashtable; 9 | 10 | import org.osgi.framework.BundleActivator; 11 | import org.osgi.framework.BundleContext; 12 | import org.osgi.framework.ServiceRegistration; 13 | import org.osgi.service.jdbc.DataSourceFactory; 14 | 15 | import com.microsoft.sqlserver.jdbc.SQLServerDriver; 16 | 17 | 18 | /** 19 | * Allows plugins to register the driver as an OSGI Framework service. 20 | * 21 | */ 22 | public class Activator implements BundleActivator { 23 | 24 | private ServiceRegistration service; 25 | 26 | /** 27 | * default constructor 28 | */ 29 | public Activator() { 30 | // default constructor 31 | } 32 | 33 | @Override 34 | public void start(BundleContext context) throws Exception { 35 | Dictionary properties = new Hashtable<>(); 36 | SQLServerDriver driver = new SQLServerDriver(); 37 | properties.put(DataSourceFactory.OSGI_JDBC_DRIVER_CLASS, driver.getClass().getName()); 38 | properties.put(DataSourceFactory.OSGI_JDBC_DRIVER_NAME, "Microsoft JDBC Driver for SQL Server"); 39 | properties.put(DataSourceFactory.OSGI_JDBC_DRIVER_VERSION, 40 | driver.getMajorVersion() + "." + driver.getMinorVersion()); 41 | properties.put(DataSourceFactory.OSGI_JDBC_CAPABILITY, 42 | new String[] {DataSourceFactory.OSGI_JDBC_CAPABILITY_DRIVER, 43 | DataSourceFactory.OSGI_JDBC_CAPABILITY_DATASOURCE, 44 | DataSourceFactory.OSGI_JDBC_CAPABILITY_CONNECTIONPOOLDATASOURCE, 45 | DataSourceFactory.OSGI_JDBC_CAPABILITY_XADATASOURCE}); 46 | service = context.registerService(DataSourceFactory.class, new SQLServerDataSourceFactory(), properties); 47 | SQLServerDriver.register(); 48 | } 49 | 50 | @Override 51 | public void stop(BundleContext context) throws Exception { 52 | if (service != null) { 53 | service.unregister(); 54 | } 55 | SQLServerDriver.deregister(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/jdbc/ParserUtils.java: -------------------------------------------------------------------------------- 1 | package com.microsoft.sqlserver.jdbc; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import java.io.ByteArrayInputStream; 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | import java.nio.charset.StandardCharsets; 9 | import java.util.ArrayList; 10 | 11 | import org.antlr.v4.runtime.CharStreams; 12 | import org.antlr.v4.runtime.Token; 13 | 14 | 15 | public class ParserUtils { 16 | 17 | private static String getTableName(String s) { 18 | try { 19 | return new SQLServerFMTQuery(s).constructTableTargets(); 20 | } catch (SQLServerException e) { 21 | return e.getLocalizedMessage(); 22 | } 23 | } 24 | 25 | private static String getCTE(String s) { 26 | InputStream stream = new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8)); 27 | SQLServerLexer lexer = null; 28 | try { 29 | lexer = new SQLServerLexer(CharStreams.fromStream(stream)); 30 | invokeANTLRMethods(lexer); 31 | ArrayList tokenList = (ArrayList) lexer.getAllTokens(); 32 | SQLServerTokenIterator iter = new SQLServerTokenIterator(tokenList); 33 | return SQLServerParser.getCTE(iter); 34 | } catch (IOException | SQLServerException e) { 35 | return e.getLocalizedMessage(); 36 | } 37 | } 38 | 39 | public static void compareTableName(String tsql, String expected) { 40 | // Verbose to make debugging more friendly 41 | String extractedTableName = ParserUtils.getTableName(tsql).trim(); 42 | assertEquals(expected, extractedTableName); 43 | } 44 | 45 | public static void compareCommonTableExpression(String tsql, String expected) { 46 | // Verbose to make debugging more friendly 47 | String extractedTableName = ParserUtils.getCTE(tsql).trim(); 48 | assertEquals(expected, extractedTableName); 49 | } 50 | 51 | @SuppressWarnings("deprecation") 52 | private static void invokeANTLRMethods(SQLServerLexer s) { 53 | s.getTokenNames(); 54 | s.getVocabulary(); 55 | s.getGrammarFileName(); 56 | s.getRuleNames(); 57 | s.getSerializedATN(); 58 | s.getChannelNames(); 59 | s.getModeNames(); 60 | s.getATN(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/jdbc/ActivityIDTest.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 static org.junit.Assert.assertFalse; 8 | import static org.junit.jupiter.api.Assertions.assertEquals; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | import java.util.UUID; 13 | 14 | import org.junit.jupiter.api.Test; 15 | import org.junit.platform.runner.JUnitPlatform; 16 | import org.junit.runner.RunWith; 17 | 18 | import com.microsoft.sqlserver.testframework.AbstractTest; 19 | 20 | 21 | @RunWith(JUnitPlatform.class) 22 | public class ActivityIDTest extends AbstractTest { 23 | 24 | @Test 25 | public void testActivityID() throws Exception { 26 | int numThreads = 20; 27 | List usedIds = new ArrayList(numThreads); 28 | 29 | for (int i = 0; i < numThreads; i++) { 30 | MyThread t = new MyThread(usedIds); 31 | t.start(); 32 | t.join(); 33 | usedIds.add(t.getUUID()); 34 | } 35 | } 36 | 37 | public class MyThread extends Thread { 38 | 39 | public MyThread(List usedIdsIn) { 40 | usedIds = usedIdsIn; 41 | } 42 | 43 | private List usedIds; 44 | private ActivityId id; 45 | 46 | public UUID getUUID() { 47 | return id.getId(); 48 | } 49 | 50 | public void run() { 51 | id = ActivityCorrelator.getCurrent(); 52 | UUID uuid = id.getId(); 53 | assertFalse("UUID should be unique across threads.", usedIds.contains(id.getId())); 54 | assertEquals(1L, id.getSequence(), "First sequence should be 1."); 55 | id = ActivityCorrelator.getNext(); 56 | assertEquals(uuid, id.getId(), "UUID should remain the same for the same thread."); 57 | assertEquals(2L, id.getSequence(), "Second sequence should be 2."); 58 | id = ActivityCorrelator.getNext(); 59 | assertEquals(3L, id.getSequence(), "Third sequence should be 3."); 60 | assertEquals(uuid, id.getId(), "UUID should remain the same for the same thread."); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /.github/workflows/codeql.yml: -------------------------------------------------------------------------------- 1 | name: "CodeQL" 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | branches: [ "main" ] 7 | pull_request: 8 | # The branches below must be a subset of the branches above 9 | branches: [ "main" ] 10 | 11 | jobs: 12 | analyze: 13 | name: Analyze 14 | runs-on: ubuntu-latest 15 | permissions: 16 | actions: read 17 | contents: read 18 | security-events: write 19 | 20 | strategy: 21 | fail-fast: false 22 | matrix: 23 | language: [ 'java' ] 24 | 25 | steps: 26 | - name: Checkout repository 27 | uses: actions/checkout@v4 28 | 29 | # Initializes the CodeQL tools for scanning. 30 | - name: Initialize CodeQL 31 | uses: github/codeql-action/init@v3 32 | with: 33 | languages: ${{ matrix.language }} 34 | # If you wish to specify custom queries, you can do so here or in a config file. 35 | # By default, queries listed here will override any specified in a config file. 36 | # Prefix the list here with "+" to use these queries and those in the config file. 37 | 38 | # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs 39 | # queries: security-extended,security-and-quality 40 | 41 | # Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java). 42 | # If this step fails, then you should remove it and run the build manually (see below) 43 | #- name: Autobuild 44 | # uses: github/codeql-action/autobuild@v3 45 | 46 | # ℹ️ Command-line programs to run using the OS shell. 47 | # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun 48 | 49 | # If the Autobuild fails above, remove it and uncomment the following three lines. 50 | # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. 51 | 52 | # - run: | 53 | # echo "Run, Build Application using script" 54 | # ./location_of_script_within_repo/buildscript.sh 55 | 56 | - run: mvn install -Pjre11 -Denforcer.skip -Dmaven.javadoc.skip -DskipTests -Dmaven.test.skip.exec 57 | 58 | - name: Perform CodeQL Analysis 59 | uses: github/codeql-action/analyze@v3 60 | with: 61 | category: "/language:${{matrix.language}}" 62 | -------------------------------------------------------------------------------- /src/samples/constrained/pom.xml: -------------------------------------------------------------------------------- 1 | 59 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/ScopeTokenCache.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 com.azure.core.credential.AccessToken; 8 | import com.azure.core.credential.TokenRequestContext; 9 | import java.util.concurrent.atomic.AtomicBoolean; 10 | import java.util.function.Function; 11 | import reactor.core.publisher.FluxSink; 12 | import reactor.core.publisher.Mono; 13 | import reactor.core.publisher.ReplayProcessor; 14 | 15 | 16 | /** 17 | * A token cache that supports caching a token and refreshing it. 18 | */ 19 | class ScopeTokenCache { 20 | 21 | private final AtomicBoolean wip; 22 | private AccessToken cache; 23 | @SuppressWarnings("deprecation") 24 | private final ReplayProcessor emitterProcessor = ReplayProcessor.create(1); 25 | @SuppressWarnings("deprecation") 26 | private final FluxSink sink = emitterProcessor.sink(FluxSink.OverflowStrategy.BUFFER); 27 | private final Function> getNew; 28 | private TokenRequestContext request; 29 | 30 | /** 31 | * Creates an instance of RefreshableTokenCredential with default scheme "Bearer". 32 | * 33 | * @param getNew 34 | * a method to get a new token 35 | */ 36 | ScopeTokenCache(Function> getNew) { 37 | this.wip = new AtomicBoolean(false); 38 | this.getNew = getNew; 39 | } 40 | 41 | void setRequest(TokenRequestContext request) { 42 | this.request = request; 43 | } 44 | 45 | /** 46 | * Asynchronously get a token from either the cache or replenish the cache with a new token. 47 | * 48 | * @return a Publisher that emits an AccessToken 49 | */ 50 | Mono getToken() { 51 | if (cache != null && !cache.isExpired()) { 52 | return Mono.just(cache); 53 | } 54 | return Mono.defer(() -> { 55 | if (!wip.getAndSet(true)) { 56 | return getNew.apply(request).doOnNext(ac -> cache = ac).doOnNext(sink::next).doOnError(sink::error) 57 | .doOnTerminate(() -> wip.set(false)); 58 | } else { 59 | return emitterProcessor.next(); 60 | } 61 | }); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/sqlType/SqlTime.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 static org.junit.jupiter.api.Assertions.fail; 9 | 10 | import java.sql.JDBCType; 11 | import java.sql.Time; 12 | import java.text.ParseException; 13 | import java.text.SimpleDateFormat; 14 | import java.time.format.DateTimeFormatter; 15 | import java.time.format.DateTimeFormatterBuilder; 16 | import java.time.format.ResolverStyle; 17 | import java.time.temporal.ChronoField; 18 | import java.util.concurrent.ThreadLocalRandom; 19 | 20 | 21 | public class SqlTime extends SqlDateTime { 22 | 23 | static SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss.SSSSSSS"); 24 | static String basePattern = "HH:mm:ss"; 25 | static DateTimeFormatter formatter; 26 | 27 | public SqlTime() { 28 | super("time", JDBCType.TIME, null, null); 29 | type = java.sql.Time.class; 30 | try { 31 | minvalue = new Time(dateFormat.parse((String) SqlTypeValue.TIME.minValue).getTime()); 32 | maxvalue = new Time(dateFormat.parse((String) SqlTypeValue.TIME.maxValue).getTime()); 33 | } catch (ParseException ex) { 34 | fail(ex.getMessage()); 35 | } 36 | this.scale = 7; 37 | this.variableLengthType = VariableLengthType.ScaleOnly; 38 | generateScale(); 39 | 40 | formatter = new DateTimeFormatterBuilder().appendPattern(basePattern) 41 | .appendFraction(ChronoField.NANO_OF_SECOND, 0, this.scale, true).toFormatter(); 42 | formatter = formatter.withResolverStyle(ResolverStyle.STRICT); 43 | 44 | } 45 | 46 | public Object createdata() { 47 | Time temp = new Time( 48 | ThreadLocalRandom.current().nextLong(((Time) minvalue).getTime(), ((Time) maxvalue).getTime())); 49 | String timeNano = temp.toString(); 50 | return timeNano; 51 | 52 | // can pass String rather than converting to loacTime, but leaving it 53 | // unchanged for now to handle prepared statements 54 | /* 55 | * converting string '20:53:44.9' to LocalTime results in 20:53:44.900, this extra scale causes failure 56 | */ 57 | // return LocalTime.parse(timeNano, formatter); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/testframework/sqlType/SqlDateTime2.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 static org.junit.jupiter.api.Assertions.fail; 9 | 10 | import java.sql.JDBCType; 11 | import java.sql.Timestamp; 12 | import java.text.ParseException; 13 | import java.text.SimpleDateFormat; 14 | import java.time.format.DateTimeFormatter; 15 | import java.time.format.DateTimeFormatterBuilder; 16 | import java.time.format.ResolverStyle; 17 | import java.time.temporal.ChronoField; 18 | import java.util.concurrent.ThreadLocalRandom; 19 | 20 | 21 | public class SqlDateTime2 extends SqlDateTime { 22 | 23 | static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss.SSSSSSS"); 24 | static String basePattern = "yyyy-MM-dd HH:mm:ss"; 25 | static DateTimeFormatter formatter; 26 | 27 | public SqlDateTime2() { 28 | super("datetime2", JDBCType.TIMESTAMP, null, null); 29 | try { 30 | minvalue = new Timestamp(dateFormat.parse((String) SqlTypeValue.DATETIME2.minValue).getTime()); 31 | maxvalue = new Timestamp(dateFormat.parse((String) SqlTypeValue.DATETIME2.maxValue).getTime()); 32 | } catch (ParseException ex) { 33 | fail(ex.getMessage()); 34 | } 35 | this.precision = 7; 36 | this.variableLengthType = VariableLengthType.Precision; 37 | generatePrecision(); 38 | formatter = new DateTimeFormatterBuilder().appendPattern(basePattern) 39 | .appendFraction(ChronoField.NANO_OF_SECOND, 0, this.precision, true).toFormatter(); 40 | formatter = formatter.withResolverStyle(ResolverStyle.STRICT); 41 | } 42 | 43 | public Object createdata() { 44 | Timestamp temp = new Timestamp(ThreadLocalRandom.current().nextLong(((Timestamp) minvalue).getTime(), 45 | ((Timestamp) maxvalue).getTime())); 46 | temp.setNanos(0); 47 | String timeNano = temp.toString().substring(0, temp.toString().length() - 1) 48 | + generateRandomInt(this.precision); 49 | return timeNano; 50 | // can pass string rather than converting to LocalDateTime, but leaving 51 | // it unchanged for now to handle prepared statements 52 | // return LocalDateTime.parse(timeNano, formatter); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionWrapper43Test.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.assertTrue; 8 | 9 | import java.sql.Connection; 10 | import java.sql.DatabaseMetaData; 11 | import java.sql.SQLException; 12 | 13 | import com.microsoft.sqlserver.jdbc.TestUtils; 14 | import org.junit.jupiter.api.AfterAll; 15 | import org.junit.jupiter.api.BeforeAll; 16 | import org.junit.jupiter.api.Test; 17 | import org.junit.platform.runner.JUnitPlatform; 18 | import org.junit.runner.RunWith; 19 | 20 | import com.microsoft.sqlserver.jdbc.SQLServerConnection; 21 | import com.microsoft.sqlserver.jdbc.SQLServerConnection43; 22 | import com.microsoft.sqlserver.testframework.AbstractTest; 23 | 24 | 25 | /** 26 | * Test ConnectionWrapper43Test class 27 | * 28 | */ 29 | @RunWith(JUnitPlatform.class) 30 | public class ConnectionWrapper43Test extends AbstractTest { 31 | static Connection connection = null; 32 | double javaVersion = Double.parseDouble(System.getProperty("java.specification.version")); 33 | static int major; 34 | static int minor; 35 | 36 | /** 37 | * Tests creation of SQLServerConnection43Test object 38 | * 39 | * @throws SQLException 40 | */ 41 | @Test 42 | public void SQLServerConnection43Test() throws SQLException { 43 | try { 44 | if (1.8d <= javaVersion && 4 == major && 2 == minor) { 45 | assertTrue(connection instanceof SQLServerConnection); 46 | } else { 47 | assertTrue(connection instanceof SQLServerConnection43); 48 | } 49 | } finally { 50 | if (null != connection) { 51 | connection.close(); 52 | } 53 | } 54 | } 55 | 56 | @BeforeAll 57 | public static void setupConnection() throws Exception { 58 | setConnection(); 59 | 60 | connection = getConnection(); 61 | 62 | DatabaseMetaData metadata = connection.getMetaData(); 63 | major = metadata.getJDBCMajorVersion(); 64 | minor = metadata.getJDBCMinorVersion(); 65 | } 66 | 67 | @AfterAll 68 | public static void terminateVariation() throws SQLException { 69 | if (null != connection) { 70 | connection.close(); 71 | } 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/samples/azureactivedirectoryauthentication/pom.xml: -------------------------------------------------------------------------------- 1 | 72 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/sqlserver/jdbc/dataclassification/SensitivityProperty.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 Sensitivity Property as received from SQL Server for the active resultSet 10 | */ 11 | public class SensitivityProperty { 12 | private Label label; 13 | private InformationType informationType; 14 | private int sensitivityRank; 15 | 16 | /** 17 | * Constructs a SensitivityProperty 18 | * 19 | * @param label 20 | * Label as received from SQL Server for this SensitivityProperty 21 | * @param informationType 22 | * InformationType as received from SQL Server for this SensitivityProperty 23 | */ 24 | public SensitivityProperty(Label label, InformationType informationType) { 25 | this.label = label; 26 | this.informationType = informationType; 27 | } 28 | 29 | /** 30 | * Constructs a SensitivityProperty 31 | * 32 | * @param label 33 | * Label as received from SQL Server for this SensitivityProperty 34 | * @param informationType 35 | * InformationType as received from SQL Server for this SensitivityProperty 36 | * @param sensitivityRank 37 | * sensitivity rank as received from SQL Server for this SensitivityProperty 38 | */ 39 | public SensitivityProperty(Label label, InformationType informationType, int sensitivityRank) { 40 | this.label = label; 41 | this.informationType = informationType; 42 | this.sensitivityRank = sensitivityRank; 43 | } 44 | 45 | /** 46 | * Returns the label data for this SensitivityProperty 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 | *

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 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 | *

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.Set getColumnOrdinals(); 24 | 25 | /** 26 | * Returns the name of the given column. 27 | * 28 | * @param column 29 | * Column ordinal 30 | * @return Name of the column 31 | */ 32 | String getColumnName(int column); 33 | 34 | /** 35 | * Returns the JDBC data type of the given column. 36 | * 37 | * @param column 38 | * Column ordinal 39 | * @return JDBC data type of the column 40 | */ 41 | int getColumnType(int column); 42 | 43 | /** 44 | * Returns the precision for the given column. 45 | * 46 | * @param column 47 | * Column ordinal 48 | * @return Precision of the column 49 | */ 50 | int getPrecision(int column); 51 | 52 | /** 53 | * Returns the scale for the given column. 54 | * 55 | * @param column 56 | * Column ordinal 57 | * @return Scale of the column 58 | */ 59 | int getScale(int column); 60 | 61 | /** 62 | * Returns the data for the current row as an array of Objects. 63 | * 64 | * Each Object must match the Java language Type that is used to represent the indicated JDBC data type for the 65 | * given column. For more information, see 'Understanding the JDBC Driver Data Types' for the appropriate mappings. 66 | * 67 | * @return The data for the row. 68 | * @throws SQLServerException 69 | * If there are any errors in obtaining the data. 70 | */ 71 | Object[] getRowData() throws SQLException; 72 | 73 | /** 74 | * Advances to the next data row. 75 | * 76 | * @return True if rows are available; false if there are no more rows 77 | * @throws SQLServerException 78 | * If there are any errors in advancing to the next row. 79 | */ 80 | boolean next() throws SQLException; 81 | } 82 | -------------------------------------------------------------------------------- /src/samples/datatypes/pom.xml: -------------------------------------------------------------------------------- 1 | 89 | -------------------------------------------------------------------------------- /src/samples/resultsets/pom.xml: -------------------------------------------------------------------------------- 1 | 88 | -------------------------------------------------------------------------------- /src/samples/adaptive/pom.xml: -------------------------------------------------------------------------------- 1 | 89 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Security 4 | 5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/). 6 | 7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | **Please do not report security vulnerabilities through public GitHub issues.** 12 | 13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report). 14 | 15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey). 16 | 17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc). 18 | 19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: 20 | 21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) 22 | * Full paths of source file(s) related to the manifestation of the issue 23 | * The location of the affected source code (tag/branch/commit or direct URL) 24 | * Any special configuration required to reproduce the issue 25 | * Step-by-step instructions to reproduce the issue 26 | * Proof-of-concept or exploit code (if possible) 27 | * Impact of the issue, including how an attacker might exploit the issue 28 | 29 | This information will help us triage your report more quickly. 30 | 31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs. 32 | 33 | ## Preferred Languages 34 | 35 | We prefer all communications to be in English. 36 | 37 | ## Policy 38 | 39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd). 40 | 41 | 42 | --------------------------------------------------------------------------------