From c5f00c5ee7e14a474d4f6aaae3389abe09511347 Mon Sep 17 00:00:00 2001 From: Peter Bae Date: Wed, 2 Aug 2017 14:26:27 -0700 Subject: [PATCH 1/5] Junit changes - added CallableStatementTest and PrecisionScaleTest. Removed RandomData inside jdbc.datatypes beacuse it's redundant --- .../jdbc/AlwaysEncrypted/AESetup.java | 1676 ++++++++++- .../CallableStatementTest.java | 2645 +++++++++++++++++ .../JDBCEncryptionDecryptionTest.java | 1389 +-------- .../AlwaysEncrypted/PrecisionScaleTest.java | 554 ++++ .../sqlserver/jdbc/datatypes/RandomData.java | 651 ---- .../datatypes/SQLVariantResultSetTest.java | 1 + .../jdbc/datatypes/TVPWithSqlVariantTest.java | 1 + 7 files changed, 4894 insertions(+), 2023 deletions(-) create mode 100644 src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java create mode 100644 src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java delete mode 100644 src/test/java/com/microsoft/sqlserver/jdbc/datatypes/RandomData.java diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java index b164f004d..5b4058ed5 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java @@ -11,8 +11,14 @@ import java.io.File; import java.io.FileReader; import java.io.IOException; +import java.math.BigDecimal; +import java.sql.Date; import java.sql.DriverManager; +import java.sql.JDBCType; import java.sql.SQLException; +import java.sql.Time; +import java.sql.Timestamp; +import java.util.LinkedList; import java.util.Properties; import javax.xml.bind.DatatypeConverter; @@ -27,13 +33,17 @@ import com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionKeyStoreProvider; import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.jdbc.SQLServerException; +import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement; import com.microsoft.sqlserver.jdbc.SQLServerStatement; import com.microsoft.sqlserver.jdbc.SQLServerStatementColumnEncryptionSetting; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.DBConnection; import com.microsoft.sqlserver.testframework.Utils; +import com.microsoft.sqlserver.testframework.util.RandomData; import com.microsoft.sqlserver.testframework.util.Util; +import microsoft.sql.DateTimeOffset; + import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assumptions.assumeTrue; @@ -52,10 +62,12 @@ public class AESetup extends AbstractTest { static final String cmkName = "JDBC_CMK"; static final String cekName = "JDBC_CEK"; static final String secretstrJks = "password"; - static final String numericTable = "JDBCEncrpytedNumericTable"; static final String charTable = "JDBCEncrpytedCharTable"; static final String binaryTable = "JDBCEncrpytedBinaryTable"; static final String dateTable = "JDBCEncrpytedDateTable"; + static final String numericTable = "JDBCEncrpytedNumericTable"; + static final String scaleDateTable = "JDBCEncrpytedScaleDateTable"; + static final String uid = "171fbe25-4331-4765-a838-b2e3eea3e7ea"; static String filePath = null; @@ -68,6 +80,8 @@ public class AESetup extends AbstractTest { static SQLServerColumnEncryptionKeyStoreProvider storeProvider = null; static SQLServerStatementColumnEncryptionSetting stmtColEncSetting = null; + private static SQLServerPreparedStatement pstmt = null; + /** * Create connection, statement and generate path of resource file * @@ -102,6 +116,21 @@ static void setUpConnection() throws TestAbortedException, Exception { createCEK(storeProvider); } + /** + * Dropping all CMKs and CEKs and any open resources. Technically, dropAll depends on the state of the class so it shouldn't be static, but the + * AfterAll annotation requires it to be static. + * + * @throws SQLServerException + * @throws SQLException + */ + @AfterAll + private static void dropAll() throws SQLServerException, SQLException { + dropTables(stmt); + dropCEK(); + dropCMK(); + Util.close(null, stmt, con); + } + /** * Read the alias from file which is created during creating jks If the jks and alias name in JavaKeyStore.txt does not exists, will not run! * @@ -145,7 +174,7 @@ private static void readFromFile(String inputFile, * * @throws SQLException */ - static void createBinaryTable() throws SQLException { + protected static void createBinaryTable() throws SQLException { String sql = "create table " + binaryTable + " (" + "PlainBinary binary(20) null," + "RandomizedBinary binary(20) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + cekName + ") NULL," @@ -178,7 +207,13 @@ static void createBinaryTable() throws SQLException { + ");"; - stmt.execute(sql); + try { + stmt.execute(sql); + stmt.execute("DBCC FREEPROCCACHE"); + } + catch (SQLException e) { + fail(e.toString()); + } } /** @@ -186,7 +221,7 @@ static void createBinaryTable() throws SQLException { * * @throws SQLException */ - static void createCharTable() throws SQLException { + protected static void createCharTable() throws SQLException { String sql = "create table " + charTable + " (" + "PlainChar char(20) null," + "RandomizedChar char(20) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + cekName + ") NULL," @@ -243,7 +278,13 @@ static void createCharTable() throws SQLException { + ");"; - stmt.execute(sql); + try { + stmt.execute(sql); + stmt.execute("DBCC FREEPROCCACHE"); + } + catch (SQLException e) { + fail(e.toString()); + } } /** @@ -251,7 +292,7 @@ static void createCharTable() throws SQLException { * * @throws SQLException */ - static void createDateTable() throws SQLException { + protected void createDateTable() throws SQLException { String sql = "create table " + dateTable + " (" + "PlainDate date null," + "RandomizedDate date ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + cekName + ") NULL," @@ -290,7 +331,110 @@ static void createDateTable() throws SQLException { + ");"; - stmt.execute(sql); + try { + stmt.execute(sql); + stmt.execute("DBCC FREEPROCCACHE"); + } + catch (SQLException e) { + fail(e.toString()); + } + } + + /** + * Create encrypted table for Date with precision + * + * @throws SQLException + */ + protected void createDatePrecisionTable(int scale) throws SQLException { + String sql = "create table " + dateTable + " (" + // 1 + + "PlainDatetime2 datetime2(" + scale + ") null," + "RandomizedDatetime2 datetime2(" + scale + + ") ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + cekName + + ") NULL," + "DeterministicDatetime2 datetime2(" + scale + + ") ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + cekName + + ") NULL," + + // 4 + + "PlainDatetime2Default datetime2 null," + + "RandomizedDatetime2Default datetime2 ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicDatetime2Default datetime2 ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + // 7 + + "PlainDatetimeoffsetDefault datetimeoffset null," + + "RandomizedDatetimeoffsetDefault datetimeoffset ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicDatetimeoffsetDefault datetimeoffset ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + // 10 + + "PlainTimeDefault time null," + + "RandomizedTimeDefault time ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicTimeDefault time ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + // 13 + + "PlainTime time(" + scale + ") null," + "RandomizedTime time(" + scale + + ") ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + cekName + + ") NULL," + "DeterministicTime time(" + scale + + ") ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + cekName + + ") NULL," + + // 16 + + "PlainDatetimeoffset datetimeoffset(" + scale + ") null," + "RandomizedDatetimeoffset datetimeoffset(" + scale + + ") ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + cekName + + ") NULL," + "DeterministicDatetimeoffset datetimeoffset(" + scale + + ") ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + cekName + + ") NULL," + + + ");"; + + try { + stmt.execute(sql); + stmt.execute("DBCC FREEPROCCACHE"); + } + catch (SQLException e) { + fail(e.toString()); + } + } + + /** + * Create encrypted table for Date with scale + * + * @throws SQLException + */ + protected static void createDateScaleTable() throws SQLException { + String sql = "create table " + scaleDateTable + " (" + + + "PlainDatetime2 datetime2(2) null," + + "RandomizedDatetime2 datetime2(2) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicDatetime2 datetime2(2) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + "PlainTime time(2) null," + + "RandomizedTime time(2) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicTime time(2) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + "PlainDatetimeoffset datetimeoffset(2) null," + + "RandomizedDatetimeoffset datetimeoffset(2) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicDatetimeoffset datetimeoffset(2) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + ");"; + + try { + stmt.execute(sql); + stmt.execute("DBCC FREEPROCCACHE"); + } + catch (SQLException e) { + fail(e.toString()); + } } /** @@ -298,7 +442,7 @@ static void createDateTable() throws SQLException { * * @throws SQLException */ - static void createNumericTable() throws SQLException { + protected static void createNumericTable() throws SQLException { String sql = "create table " + numericTable + " (" + "PlainBit bit null," + "RandomizedBit bit ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + cekName + ") NULL," @@ -406,6 +550,148 @@ static void createNumericTable() throws SQLException { } } + /** + * Create encrypted table for Numeric with precision + * + * @throws SQLException + */ + protected void createNumericPrecisionTable(int floatPrecision, + int precision, + int scale) throws SQLException { + String sql = "create table " + numericTable + " (" + "PlainFloat float(" + floatPrecision + ") null," + "RandomizedFloat float(" + + floatPrecision + + ") ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + cekName + + ") NULL," + "DeterministicFloat float(" + floatPrecision + + ") ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + cekName + + ") NULL," + + + "PlainDecimal decimal(" + precision + "," + scale + ") null," + "RandomizedDecimal decimal(" + precision + "," + scale + + ") ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + cekName + + ") NULL," + "DeterministicDecimal decimal(" + precision + "," + scale + + ") ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + cekName + + ") NULL," + + + "PlainNumeric numeric(" + precision + "," + scale + ") null," + "RandomizedNumeric numeric(" + precision + "," + scale + + ") ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + cekName + + ") NULL," + "DeterministicNumeric numeric(" + precision + "," + scale + + ") ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + cekName + + ") NULL" + + + ");"; + + try { + stmt.execute(sql); + stmt.execute("DBCC FREEPROCCACHE"); + } + catch (SQLException e) { + fail(e.toString()); + } + } + + /** + * Create a list of binary values + * + * @param nullable + */ + protected static LinkedList createbinaryValues(boolean nullable) { + + boolean encrypted = true; + RandomData.returnNull = nullable; + + byte[] binary20 = RandomData.generateBinaryTypes("20", nullable, encrypted); + byte[] varbinary50 = RandomData.generateBinaryTypes("50", nullable, encrypted); + byte[] varbinarymax = RandomData.generateBinaryTypes("max", nullable, encrypted); + byte[] binary512 = RandomData.generateBinaryTypes("512", nullable, encrypted); + byte[] varbinary8000 = RandomData.generateBinaryTypes("8000", nullable, encrypted); + + LinkedList list = new LinkedList<>(); + list.add(binary20); + list.add(varbinary50); + list.add(varbinarymax); + list.add(binary512); + list.add(varbinary8000); + + return list; + } + + /** + * Create a list of char values + * + * @param nullable + */ + protected static String[] createCharValues(boolean nullable) { + + boolean encrypted = true; + String char20 = RandomData.generateCharTypes("20", nullable, encrypted); + String varchar50 = RandomData.generateCharTypes("50", nullable, encrypted); + String varcharmax = RandomData.generateCharTypes("max", nullable, encrypted); + String nchar30 = RandomData.generateNCharTypes("30", nullable, encrypted); + String nvarchar60 = RandomData.generateNCharTypes("60", nullable, encrypted); + String nvarcharmax = RandomData.generateNCharTypes("max", nullable, encrypted); + String varchar8000 = RandomData.generateCharTypes("8000", nullable, encrypted); + String nvarchar4000 = RandomData.generateNCharTypes("4000", nullable, encrypted); + + String[] values = {char20.trim(), varchar50, varcharmax, nchar30, nvarchar60, nvarcharmax, uid, varchar8000, nvarchar4000}; + + return values; + } + + /** + * Create a list of numeric values + * + * @param nullable + */ + protected static String[] createNumericValues(boolean nullable) { + + Boolean boolValue = RandomData.generateBoolean(nullable); + Short tinyIntValue = RandomData.generateTinyint(nullable); + Short smallIntValue = RandomData.generateSmallint(nullable); + Integer intValue = RandomData.generateInt(nullable); + Long bigintValue = RandomData.generateLong(nullable); + Double floatValue = RandomData.generateFloat(24, nullable); + Double floatValuewithPrecision = RandomData.generateFloat(53, nullable); + Float realValue = RandomData.generateReal(nullable); + BigDecimal decimal = RandomData.generateDecimalNumeric(18, 0, nullable); + BigDecimal decimalPrecisionScale = RandomData.generateDecimalNumeric(10, 5, nullable); + BigDecimal numeric = RandomData.generateDecimalNumeric(18, 0, nullable); + BigDecimal numericPrecisionScale = RandomData.generateDecimalNumeric(8, 2, nullable); + BigDecimal smallMoney = RandomData.generateSmallMoney(nullable); + BigDecimal money = RandomData.generateMoney(nullable); + BigDecimal decimalPrecisionScale2 = RandomData.generateDecimalNumeric(28, 4, nullable); + BigDecimal numericPrecisionScale2 = RandomData.generateDecimalNumeric(28, 4, nullable); + + String[] numericValues = {"" + boolValue, "" + tinyIntValue, "" + smallIntValue, "" + intValue, "" + bigintValue, "" + floatValue, + "" + floatValuewithPrecision, "" + realValue, "" + decimal, "" + decimalPrecisionScale, "" + numeric, "" + numericPrecisionScale, + "" + smallMoney, "" + money, "" + decimalPrecisionScale2, "" + numericPrecisionScale2}; + + return numericValues; + } + + /** + * Create a list of temporal values + * + * @param nullable + */ + protected static LinkedList createTemporalTypes(boolean nullable) { + + Date date = RandomData.generateDate(nullable); + Timestamp datetime2 = RandomData.generateDatetime2(7, nullable); + DateTimeOffset datetimeoffset = RandomData.generateDatetimeoffset(7, nullable); + Time time = RandomData.generateTime(7, nullable); + Timestamp datetime = RandomData.generateDatetime(nullable); + Timestamp smalldatetime = RandomData.generateSmalldatetime(nullable); + + LinkedList list = new LinkedList<>(); + list.add(date); + list.add(datetime2); + list.add(datetimeoffset); + list.add(time); + list.add(datetime); + list.add(smalldatetime); + + return list; + } + /** * Create column master key * @@ -427,7 +713,7 @@ private static void createCMK(String keyStoreName, * @param certStore * @throws SQLException */ - static void createCEK(SQLServerColumnEncryptionKeyStoreProvider storeProvider) throws SQLException { + private static void createCEK(SQLServerColumnEncryptionKeyStoreProvider storeProvider) throws SQLException { String letters = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; byte[] valuesDefault = letters.getBytes(); String cekSql = null; @@ -442,34 +728,1372 @@ static void createCEK(SQLServerColumnEncryptionKeyStoreProvider storeProvider) t * * @throws SQLException */ - static void dropTables() throws SQLException { - Utils.dropTableIfExists(numericTable, stmt); - Utils.dropTableIfExists(charTable, stmt); - Utils.dropTableIfExists(binaryTable, stmt); - Utils.dropTableIfExists(dateTable, stmt); + protected static void dropTables(SQLServerStatement statement) throws SQLException { + Utils.dropTableIfExists(numericTable, statement); + Utils.dropTableIfExists(charTable, statement); + Utils.dropTableIfExists(binaryTable, statement); + Utils.dropTableIfExists(dateTable, statement); } /** - * Dropping column encryption key + * Populate binary data. * - * @throws SQLServerException + * @param byteValues * @throws SQLException */ - static void dropCEK() throws SQLServerException, SQLException { - String cekSql = " if exists (SELECT name from sys.column_encryption_keys where name='" + cekName + "')" + " begin" - + " drop column encryption key " + cekName + " end"; - stmt.execute(cekSql); + protected static void populateBinaryNormalCase(LinkedList byteValues) throws SQLException { + String sql = "insert into " + binaryTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); + + // binary20 + for (int i = 1; i <= 3; i++) { + if (null == byteValues) { + pstmt.setBytes(i, null); + } + else { + pstmt.setBytes(i, byteValues.get(0)); + } + } + + // varbinary50 + for (int i = 4; i <= 6; i++) { + if (null == byteValues) { + pstmt.setBytes(i, null); + } + else { + pstmt.setBytes(i, byteValues.get(1)); + } + } + + // varbinary(max) + for (int i = 7; i <= 9; i++) { + if (null == byteValues) { + pstmt.setBytes(i, null); + } + else { + pstmt.setBytes(i, byteValues.get(2)); + } + } + + // binary(512) + for (int i = 10; i <= 12; i++) { + if (null == byteValues) { + pstmt.setBytes(i, null); + } + else { + pstmt.setBytes(i, byteValues.get(3)); + } + } + + // varbinary(8000) + for (int i = 13; i <= 15; i++) { + if (null == byteValues) { + pstmt.setBytes(i, null); + } + else { + pstmt.setBytes(i, byteValues.get(4)); + } + } + + pstmt.execute(); + Util.close(null, pstmt, null); } /** - * Dropping column master key + * Populate binary data using set object. * - * @throws SQLServerException + * @param byteValues * @throws SQLException */ - static void dropCMK() throws SQLServerException, SQLException { - String cekSql = " if exists (SELECT name from sys.column_master_keys where name='" + cmkName + "')" + " begin" + " drop column master key " - + cmkName + " end"; - stmt.execute(cekSql); + protected static void populateBinarySetObject(LinkedList byteValues) throws SQLException { + String sql = "insert into " + binaryTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); + + // binary(20) + for (int i = 1; i <= 3; i++) { + if (null == byteValues) { + pstmt.setObject(i, null, java.sql.Types.BINARY); + } + else { + pstmt.setObject(i, byteValues.get(0)); + } + } + + // varbinary(50) + for (int i = 4; i <= 6; i++) { + if (null == byteValues) { + pstmt.setObject(i, null, java.sql.Types.BINARY); + } + else { + pstmt.setObject(i, byteValues.get(1)); + } + } + + // varbinary(max) + for (int i = 7; i <= 9; i++) { + if (null == byteValues) { + pstmt.setObject(i, null, java.sql.Types.BINARY); + } + else { + pstmt.setObject(i, byteValues.get(2)); + } + } + + // binary(512) + for (int i = 10; i <= 12; i++) { + if (null == byteValues) { + pstmt.setObject(i, null, java.sql.Types.BINARY); + } + else { + pstmt.setObject(i, byteValues.get(3)); + } + } + + // varbinary(8000) + for (int i = 13; i <= 15; i++) { + if (null == byteValues) { + pstmt.setObject(i, null, java.sql.Types.BINARY); + } + else { + pstmt.setObject(i, byteValues.get(4)); + } + } + + pstmt.execute(); + Util.close(null, pstmt, null); + } + + /** + * Populate binary data using set object with JDBC type. + * + * @param byteValues + * @throws SQLException + */ + protected static void populateBinarySetObjectWithJDBCType(LinkedList byteValues) throws SQLException { + String sql = "insert into " + binaryTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); + + // binary(20) + for (int i = 1; i <= 3; i++) { + if (null == byteValues) { + pstmt.setObject(i, null, JDBCType.BINARY); + } + else { + pstmt.setObject(i, byteValues.get(0), JDBCType.BINARY); + } + } + + // varbinary(50) + for (int i = 4; i <= 6; i++) { + if (null == byteValues) { + pstmt.setObject(i, null, JDBCType.VARBINARY); + } + else { + pstmt.setObject(i, byteValues.get(1), JDBCType.VARBINARY); + } + } + + // varbinary(max) + for (int i = 7; i <= 9; i++) { + if (null == byteValues) { + pstmt.setObject(i, null, JDBCType.VARBINARY); + } + else { + pstmt.setObject(i, byteValues.get(2), JDBCType.VARBINARY); + } + } + + // binary(512) + for (int i = 10; i <= 12; i++) { + if (null == byteValues) { + pstmt.setObject(i, null, JDBCType.BINARY); + } + else { + pstmt.setObject(i, byteValues.get(3), JDBCType.BINARY); + } + } + + // varbinary(8000) + for (int i = 13; i <= 15; i++) { + if (null == byteValues) { + pstmt.setObject(i, null, JDBCType.VARBINARY); + } + else { + pstmt.setObject(i, byteValues.get(4), JDBCType.VARBINARY); + } + } + + pstmt.execute(); + Util.close(null, pstmt, null); + } + + /** + * Populate binary data using set null. + * + * @throws SQLException + */ + protected static void populateBinaryNullCase() throws SQLException { + String sql = "insert into " + binaryTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); + + // binary + for (int i = 1; i <= 3; i++) { + pstmt.setNull(i, java.sql.Types.BINARY); + } + + // varbinary, varbinary(max) + for (int i = 4; i <= 9; i++) { + pstmt.setNull(i, java.sql.Types.VARBINARY); + } + + // binary512 + for (int i = 10; i <= 12; i++) { + pstmt.setNull(i, java.sql.Types.BINARY); + } + + // varbinary(8000) + for (int i = 13; i <= 15; i++) { + pstmt.setNull(i, java.sql.Types.VARBINARY); + } + + pstmt.execute(); + Util.close(null, pstmt, null); + } + + /** + * Populate char data. + * + * @param charValues + * @throws SQLException + */ + protected static void populateCharNormalCase(String[] charValues) throws SQLException { + String sql = "insert into " + charTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?" + ")"; + + pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); + + // char + for (int i = 1; i <= 3; i++) { + pstmt.setString(i, charValues[0]); + } + + // varchar + for (int i = 4; i <= 6; i++) { + pstmt.setString(i, charValues[1]); + } + + // varchar(max) + for (int i = 7; i <= 9; i++) { + pstmt.setString(i, charValues[2]); + } + + // nchar + for (int i = 10; i <= 12; i++) { + pstmt.setNString(i, charValues[3]); + } + + // nvarchar + for (int i = 13; i <= 15; i++) { + pstmt.setNString(i, charValues[4]); + } + + // varchar(max) + for (int i = 16; i <= 18; i++) { + pstmt.setNString(i, charValues[5]); + } + + // uniqueidentifier + for (int i = 19; i <= 21; i++) { + if (null == charValues[6]) { + pstmt.setUniqueIdentifier(i, null); + } + else { + pstmt.setUniqueIdentifier(i, uid); + } + } + + // varchar8000 + for (int i = 22; i <= 24; i++) { + pstmt.setString(i, charValues[7]); + } + + // nvarchar4000 + for (int i = 25; i <= 27; i++) { + pstmt.setNString(i, charValues[8]); + } + + pstmt.execute(); + Util.close(null, pstmt, null); + } + + /** + * Populate char data using set object. + * + * @param charValues + * @throws SQLException + */ + protected static void populateCharSetObject(String[] charValues) throws SQLException { + String sql = "insert into " + charTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?" + ")"; + + pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); + + // char + for (int i = 1; i <= 3; i++) { + pstmt.setObject(i, charValues[0]); + } + + // varchar + for (int i = 4; i <= 6; i++) { + pstmt.setObject(i, charValues[1]); + } + + // varchar(max) + for (int i = 7; i <= 9; i++) { + pstmt.setObject(i, charValues[2], java.sql.Types.LONGVARCHAR); + } + + // nchar + for (int i = 10; i <= 12; i++) { + pstmt.setObject(i, charValues[3], java.sql.Types.NCHAR); + } + + // nvarchar + for (int i = 13; i <= 15; i++) { + pstmt.setObject(i, charValues[4], java.sql.Types.NCHAR); + } + + // nvarchar(max) + for (int i = 16; i <= 18; i++) { + pstmt.setObject(i, charValues[5], java.sql.Types.LONGNVARCHAR); + } + + // uniqueidentifier + for (int i = 19; i <= 21; i++) { + pstmt.setObject(i, charValues[6], microsoft.sql.Types.GUID); + } + + // varchar8000 + for (int i = 22; i <= 24; i++) { + pstmt.setObject(i, charValues[7]); + } + + // nvarchar4000 + for (int i = 25; i <= 27; i++) { + pstmt.setObject(i, charValues[8], java.sql.Types.NCHAR); + } + + pstmt.execute(); + Util.close(null, pstmt, null); + } + + /** + * Populate char data using set object with JDBC types. + * + * @param charValues + * @throws SQLException + */ + protected static void populateCharSetObjectWithJDBCTypes(String[] charValues) throws SQLException { + String sql = "insert into " + charTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?" + ")"; + + pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); + + // char + for (int i = 1; i <= 3; i++) { + pstmt.setObject(i, charValues[0], JDBCType.CHAR); + } + + // varchar + for (int i = 4; i <= 6; i++) { + pstmt.setObject(i, charValues[1], JDBCType.VARCHAR); + } + + // varchar(max) + for (int i = 7; i <= 9; i++) { + pstmt.setObject(i, charValues[2], JDBCType.LONGVARCHAR); + } + + // nchar + for (int i = 10; i <= 12; i++) { + pstmt.setObject(i, charValues[3], JDBCType.NCHAR); + } + + // nvarchar + for (int i = 13; i <= 15; i++) { + pstmt.setObject(i, charValues[4], JDBCType.NVARCHAR); + } + + // nvarchar(max) + for (int i = 16; i <= 18; i++) { + pstmt.setObject(i, charValues[5], JDBCType.LONGNVARCHAR); + } + + // uniqueidentifier + for (int i = 19; i <= 21; i++) { + pstmt.setObject(i, charValues[6], microsoft.sql.Types.GUID); + } + + // varchar8000 + for (int i = 22; i <= 24; i++) { + pstmt.setObject(i, charValues[7], JDBCType.VARCHAR); + } + + // vnarchar4000 + for (int i = 25; i <= 27; i++) { + pstmt.setObject(i, charValues[8], JDBCType.NVARCHAR); + } + + pstmt.execute(); + Util.close(null, pstmt, null); + } + + /** + * Populate char data with set null. + * + * @throws SQLException + */ + protected static void populateCharNullCase() throws SQLException { + String sql = "insert into " + charTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?" + ")"; + + pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); + + // char + for (int i = 1; i <= 3; i++) { + pstmt.setNull(i, java.sql.Types.CHAR); + } + + // varchar, varchar(max) + for (int i = 4; i <= 9; i++) { + pstmt.setNull(i, java.sql.Types.VARCHAR); + } + + // nchar + for (int i = 10; i <= 12; i++) { + pstmt.setNull(i, java.sql.Types.NCHAR); + } + + // nvarchar, varchar(max) + for (int i = 13; i <= 18; i++) { + pstmt.setNull(i, java.sql.Types.NVARCHAR); + } + + // uniqueidentifier + for (int i = 19; i <= 21; i++) { + pstmt.setNull(i, microsoft.sql.Types.GUID); + + } + + // varchar8000 + for (int i = 22; i <= 24; i++) { + pstmt.setNull(i, java.sql.Types.VARCHAR); + } + + // nvarchar4000 + for (int i = 25; i <= 27; i++) { + pstmt.setNull(i, java.sql.Types.NVARCHAR); + } + + pstmt.execute(); + Util.close(null, pstmt, null); + } + + /** + * Populate date data. + * + * @param dateValues + * @throws SQLException + */ + protected static void populateDateNormalCase(LinkedList dateValues) throws SQLException { + String sql = "insert into " + dateTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); + + // date + for (int i = 1; i <= 3; i++) { + pstmt.setDate(i, (Date) dateValues.get(0)); + } + + // datetime2 default + for (int i = 4; i <= 6; i++) { + pstmt.setTimestamp(i, (Timestamp) dateValues.get(1)); + } + + // datetimeoffset default + for (int i = 7; i <= 9; i++) { + pstmt.setDateTimeOffset(i, (DateTimeOffset) dateValues.get(2)); + } + + // time default + for (int i = 10; i <= 12; i++) { + pstmt.setTime(i, (Time) dateValues.get(3)); + } + + // datetime + for (int i = 13; i <= 15; i++) { + pstmt.setDateTime(i, (Timestamp) dateValues.get(4)); + } + + // smalldatetime + for (int i = 16; i <= 18; i++) { + pstmt.setSmallDateTime(i, (Timestamp) dateValues.get(5)); + } + + pstmt.execute(); + Util.close(null, pstmt, null); + } + + /** + * Populate date data with scale. + * + * @param dateValues + * @throws SQLException + */ + protected static void populateDateScaleNormalCase(LinkedList dateValues) throws SQLException { + String sql = "insert into " + scaleDateTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); + + // datetime2(2) + for (int i = 1; i <= 3; i++) { + pstmt.setTimestamp(i, (Timestamp) dateValues.get(4), 2); + } + + // time(2) + for (int i = 4; i <= 6; i++) { + pstmt.setTime(i, (Time) dateValues.get(5), 2); + } + + // datetimeoffset(2) + for (int i = 7; i <= 9; i++) { + pstmt.setDateTimeOffset(i, (DateTimeOffset) dateValues.get(6), 2); + } + + pstmt.execute(); + Util.close(null, pstmt, null); + } + + /** + * Populate date data using set object. + * + * @param dateValues + * @param setter + * @throws SQLException + */ + protected static void populateDateSetObject(LinkedList dateValues, + String setter) throws SQLException { + if (setter.equalsIgnoreCase("setwithJDBCType")) { + skipTestForJava7(); + } + + String sql = "insert into " + dateTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); + + // date + for (int i = 1; i <= 3; i++) { + if (setter.equalsIgnoreCase("setwithJavaType")) + pstmt.setObject(i, (Date) dateValues.get(0), java.sql.Types.DATE); + else if (setter.equalsIgnoreCase("setwithJDBCType")) + pstmt.setObject(i, (Date) dateValues.get(0), JDBCType.DATE); + else + pstmt.setObject(i, (Date) dateValues.get(0)); + } + + // datetime2 default + for (int i = 4; i <= 6; i++) { + if (setter.equalsIgnoreCase("setwithJavaType")) + pstmt.setObject(i, (Timestamp) dateValues.get(1), java.sql.Types.TIMESTAMP); + else if (setter.equalsIgnoreCase("setwithJDBCType")) + pstmt.setObject(i, (Timestamp) dateValues.get(1), JDBCType.TIMESTAMP); + else + pstmt.setObject(i, (Timestamp) dateValues.get(1)); + } + + // datetimeoffset default + for (int i = 7; i <= 9; i++) { + if (setter.equalsIgnoreCase("setwithJavaType")) + pstmt.setObject(i, (DateTimeOffset) dateValues.get(2), microsoft.sql.Types.DATETIMEOFFSET); + else if (setter.equalsIgnoreCase("setwithJDBCType")) + pstmt.setObject(i, (DateTimeOffset) dateValues.get(2), microsoft.sql.Types.DATETIMEOFFSET); + else + pstmt.setObject(i, (DateTimeOffset) dateValues.get(2)); + } + + // time default + for (int i = 10; i <= 12; i++) { + if (setter.equalsIgnoreCase("setwithJavaType")) + pstmt.setObject(i, (Time) dateValues.get(3), java.sql.Types.TIME); + else if (setter.equalsIgnoreCase("setwithJDBCType")) + pstmt.setObject(i, (Time) dateValues.get(3), JDBCType.TIME); + else + pstmt.setObject(i, (Time) dateValues.get(3)); + } + + // datetime + for (int i = 13; i <= 15; i++) { + pstmt.setObject(i, (Timestamp) dateValues.get(4), microsoft.sql.Types.DATETIME); + } + + // smalldatetime + for (int i = 16; i <= 18; i++) { + pstmt.setObject(i, (Timestamp) dateValues.get(5), microsoft.sql.Types.SMALLDATETIME); + } + + pstmt.execute(); + Util.close(null, pstmt, null); + } + + /** + * Populate date data with null data. + * + * @throws SQLException + */ + protected void populateDateSetObjectNull() throws SQLException { + String sql = "insert into " + dateTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); + + // date + for (int i = 1; i <= 3; i++) { + pstmt.setObject(i, null, java.sql.Types.DATE); + } + + // datetime2 default + for (int i = 4; i <= 6; i++) { + pstmt.setObject(i, null, java.sql.Types.TIMESTAMP); + } + + // datetimeoffset default + for (int i = 7; i <= 9; i++) { + pstmt.setObject(i, null, microsoft.sql.Types.DATETIMEOFFSET); + } + + // time default + for (int i = 10; i <= 12; i++) { + pstmt.setObject(i, null, java.sql.Types.TIME); + } + + // datetime + for (int i = 13; i <= 15; i++) { + pstmt.setObject(i, null, microsoft.sql.Types.DATETIME); + } + + // smalldatetime + for (int i = 16; i <= 18; i++) { + pstmt.setObject(i, null, microsoft.sql.Types.SMALLDATETIME); + } + + pstmt.execute(); + Util.close(null, pstmt, null); + } + + /** + * Populate date data with set null. + * + * @throws SQLException + */ + protected static void populateDateNullCase() throws SQLException { + String sql = "insert into " + dateTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); + + // date + for (int i = 1; i <= 3; i++) { + pstmt.setNull(i, java.sql.Types.DATE); + } + + // datetime2 default + for (int i = 4; i <= 6; i++) { + pstmt.setNull(i, java.sql.Types.TIMESTAMP); + } + + // datetimeoffset default + for (int i = 7; i <= 9; i++) { + pstmt.setNull(i, microsoft.sql.Types.DATETIMEOFFSET); + } + + // time default + for (int i = 10; i <= 12; i++) { + pstmt.setNull(i, java.sql.Types.TIME); + } + + // datetime + for (int i = 13; i <= 15; i++) { + pstmt.setNull(i, microsoft.sql.Types.DATETIME); + } + + // smalldatetime + for (int i = 16; i <= 18; i++) { + pstmt.setNull(i, microsoft.sql.Types.SMALLDATETIME); + } + + pstmt.execute(); + Util.close(null, pstmt, null); + } + + /** + * Populating the table + * + * @param values + * @throws SQLException + */ + protected static void populateNumeric(String[] values) throws SQLException { + String sql = "insert into " + numericTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); + + // bit + for (int i = 1; i <= 3; i++) { + if (values[0].equalsIgnoreCase("true")) { + pstmt.setBoolean(i, true); + } + else { + pstmt.setBoolean(i, false); + } + } + + // tinyint + for (int i = 4; i <= 6; i++) { + pstmt.setShort(i, Short.valueOf(values[1])); + } + + // smallint + for (int i = 7; i <= 9; i++) { + pstmt.setShort(i, Short.valueOf(values[2])); + } + + // int + for (int i = 10; i <= 12; i++) { + pstmt.setInt(i, Integer.valueOf(values[3])); + } + + // bigint + for (int i = 13; i <= 15; i++) { + pstmt.setLong(i, Long.valueOf(values[4])); + } + + // float default + for (int i = 16; i <= 18; i++) { + pstmt.setDouble(i, Double.valueOf(values[5])); + } + + // float(30) + for (int i = 19; i <= 21; i++) { + pstmt.setDouble(i, Double.valueOf(values[6])); + } + + // real + for (int i = 22; i <= 24; i++) { + pstmt.setFloat(i, Float.valueOf(values[7])); + } + + // decimal default + for (int i = 25; i <= 27; i++) { + if (values[8].equalsIgnoreCase("0")) + pstmt.setBigDecimal(i, new BigDecimal(values[8]), 18, 0); + else + pstmt.setBigDecimal(i, new BigDecimal(values[8])); + } + + // decimal(10,5) + for (int i = 28; i <= 30; i++) { + pstmt.setBigDecimal(i, new BigDecimal(values[9]), 10, 5); + } + + // numeric + for (int i = 31; i <= 33; i++) { + if (values[10].equalsIgnoreCase("0")) + pstmt.setBigDecimal(i, new BigDecimal(values[10]), 18, 0); + else + pstmt.setBigDecimal(i, new BigDecimal(values[10])); + } + + // numeric(8,2) + for (int i = 34; i <= 36; i++) { + pstmt.setBigDecimal(i, new BigDecimal(values[11]), 8, 2); + } + + // small money + for (int i = 37; i <= 39; i++) { + pstmt.setSmallMoney(i, new BigDecimal(values[12])); + } + + // money + for (int i = 40; i <= 42; i++) { + pstmt.setMoney(i, new BigDecimal(values[13])); + } + + // decimal(28,4) + for (int i = 43; i <= 45; i++) { + pstmt.setBigDecimal(i, new BigDecimal(values[14]), 28, 4); + } + + // numeric(28,4) + for (int i = 46; i <= 48; i++) { + pstmt.setBigDecimal(i, new BigDecimal(values[15]), 28, 4); + } + + pstmt.execute(); + Util.close(null, pstmt, null); + } + + /** + * Populate numeric data with set object. + * + * @param values + * @throws SQLException + */ + protected static void populateNumericSetObject(String[] values) throws SQLException { + String sql = "insert into " + numericTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); + + // bit + for (int i = 1; i <= 3; i++) { + if (values[0].equalsIgnoreCase("true")) { + pstmt.setObject(i, true); + } + else { + pstmt.setObject(i, false); + } + } + + // tinyint + for (int i = 4; i <= 6; i++) { + pstmt.setObject(i, Short.valueOf(values[1])); + } + + // smallint + for (int i = 7; i <= 9; i++) { + pstmt.setObject(i, Short.valueOf(values[2])); + } + + // int + for (int i = 10; i <= 12; i++) { + pstmt.setObject(i, Integer.valueOf(values[3])); + } + + // bigint + for (int i = 13; i <= 15; i++) { + pstmt.setObject(i, Long.valueOf(values[4])); + } + + // float default + for (int i = 16; i <= 18; i++) { + pstmt.setObject(i, Double.valueOf(values[5])); + } + + // float(30) + for (int i = 19; i <= 21; i++) { + pstmt.setObject(i, Double.valueOf(values[6])); + } + + // real + for (int i = 22; i <= 24; i++) { + pstmt.setObject(i, Float.valueOf(values[7])); + } + + // decimal default + for (int i = 25; i <= 27; i++) { + if (RandomData.returnZero) + pstmt.setObject(i, new BigDecimal(values[8]), java.sql.Types.DECIMAL, 18, 0); + else + pstmt.setObject(i, new BigDecimal(values[8])); + } + + // decimal(10,5) + for (int i = 28; i <= 30; i++) { + pstmt.setObject(i, new BigDecimal(values[9]), java.sql.Types.DECIMAL, 10, 5); + } + + // numeric + for (int i = 31; i <= 33; i++) { + if (RandomData.returnZero) + pstmt.setObject(i, new BigDecimal(values[10]), java.sql.Types.NUMERIC, 18, 0); + else + pstmt.setObject(i, new BigDecimal(values[10])); + } + + // numeric(8,2) + for (int i = 34; i <= 36; i++) { + pstmt.setObject(i, new BigDecimal(values[11]), java.sql.Types.NUMERIC, 8, 2); + } + + // small money + for (int i = 37; i <= 39; i++) { + pstmt.setObject(i, new BigDecimal(values[12]), microsoft.sql.Types.SMALLMONEY); + } + + // money + for (int i = 40; i <= 42; i++) { + pstmt.setObject(i, new BigDecimal(values[13]), microsoft.sql.Types.MONEY); + } + + // decimal(28,4) + for (int i = 43; i <= 45; i++) { + pstmt.setObject(i, new BigDecimal(values[14]), java.sql.Types.DECIMAL, 28, 4); + } + + // numeric + for (int i = 46; i <= 48; i++) { + pstmt.setObject(i, new BigDecimal(values[15]), java.sql.Types.NUMERIC, 28, 4); + } + + pstmt.execute(); + Util.close(null, pstmt, null); + } + + /** + * Populate numeric data with set object with JDBC type. + * + * @param values + * @throws SQLException + */ + protected static void populateNumericSetObjectWithJDBCTypes(String[] values) throws SQLException { + String sql = "insert into " + numericTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); + + // bit + for (int i = 1; i <= 3; i++) { + if (values[0].equalsIgnoreCase("true")) { + pstmt.setObject(i, true); + } + else { + pstmt.setObject(i, false); + } + } + + // tinyint + for (int i = 4; i <= 6; i++) { + pstmt.setObject(i, Short.valueOf(values[1]), JDBCType.TINYINT); + } + + // smallint + for (int i = 7; i <= 9; i++) { + pstmt.setObject(i, Short.valueOf(values[2]), JDBCType.SMALLINT); + } + + // int + for (int i = 10; i <= 12; i++) { + pstmt.setObject(i, Integer.valueOf(values[3]), JDBCType.INTEGER); + } + + // bigint + for (int i = 13; i <= 15; i++) { + pstmt.setObject(i, Long.valueOf(values[4]), JDBCType.BIGINT); + } + + // float default + for (int i = 16; i <= 18; i++) { + pstmt.setObject(i, Double.valueOf(values[5]), JDBCType.DOUBLE); + } + + // float(30) + for (int i = 19; i <= 21; i++) { + pstmt.setObject(i, Double.valueOf(values[6]), JDBCType.DOUBLE); + } + + // real + for (int i = 22; i <= 24; i++) { + pstmt.setObject(i, Float.valueOf(values[7]), JDBCType.REAL); + } + + // decimal default + for (int i = 25; i <= 27; i++) { + if (RandomData.returnZero) + pstmt.setObject(i, new BigDecimal(values[8]), java.sql.Types.DECIMAL, 18, 0); + else + pstmt.setObject(i, new BigDecimal(values[8])); + } + + // decimal(10,5) + for (int i = 28; i <= 30; i++) { + pstmt.setObject(i, new BigDecimal(values[9]), java.sql.Types.DECIMAL, 10, 5); + } + + // numeric + for (int i = 31; i <= 33; i++) { + if (RandomData.returnZero) + pstmt.setObject(i, new BigDecimal(values[10]), java.sql.Types.NUMERIC, 18, 0); + else + pstmt.setObject(i, new BigDecimal(values[10])); + } + + // numeric(8,2) + for (int i = 34; i <= 36; i++) { + pstmt.setObject(i, new BigDecimal(values[11]), java.sql.Types.NUMERIC, 8, 2); + } + + // small money + for (int i = 37; i <= 39; i++) { + pstmt.setObject(i, new BigDecimal(values[12]), microsoft.sql.Types.SMALLMONEY); + } + + // money + for (int i = 40; i <= 42; i++) { + pstmt.setObject(i, new BigDecimal(values[13]), microsoft.sql.Types.MONEY); + } + + // decimal(28,4) + for (int i = 43; i <= 45; i++) { + pstmt.setObject(i, new BigDecimal(values[14]), java.sql.Types.DECIMAL, 28, 4); + } + + // numeric + for (int i = 46; i <= 48; i++) { + pstmt.setObject(i, new BigDecimal(values[15]), java.sql.Types.NUMERIC, 28, 4); + } + + pstmt.execute(); + Util.close(null, pstmt, null); + } + + /** + * Populate numeric data with set object using null data. + * + * @throws SQLException + */ + protected static void populateNumericSetObjectNull() throws SQLException { + String sql = "insert into " + numericTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); + + // bit + for (int i = 1; i <= 3; i++) { + pstmt.setObject(i, null, java.sql.Types.BIT); + } + + // tinyint + for (int i = 4; i <= 6; i++) { + pstmt.setObject(i, null, java.sql.Types.TINYINT); + } + + // smallint + for (int i = 7; i <= 9; i++) { + pstmt.setObject(i, null, java.sql.Types.SMALLINT); + } + + // int + for (int i = 10; i <= 12; i++) { + pstmt.setObject(i, null, java.sql.Types.INTEGER); + } + + // bigint + for (int i = 13; i <= 15; i++) { + pstmt.setObject(i, null, java.sql.Types.BIGINT); + } + + // float default + for (int i = 16; i <= 18; i++) { + pstmt.setObject(i, null, java.sql.Types.DOUBLE); + } + + // float(30) + for (int i = 19; i <= 21; i++) { + pstmt.setObject(i, null, java.sql.Types.DOUBLE); + } + + // real + for (int i = 22; i <= 24; i++) { + pstmt.setObject(i, null, java.sql.Types.REAL); + } + + // decimal default + for (int i = 25; i <= 27; i++) { + pstmt.setObject(i, null, java.sql.Types.DECIMAL); + } + + // decimal(10,5) + for (int i = 28; i <= 30; i++) { + pstmt.setObject(i, null, java.sql.Types.DECIMAL, 10, 5); + } + + // numeric + for (int i = 31; i <= 33; i++) { + pstmt.setObject(i, null, java.sql.Types.NUMERIC); + } + + // numeric(8,2) + for (int i = 34; i <= 36; i++) { + pstmt.setObject(i, null, java.sql.Types.NUMERIC, 8, 2); + } + + // small money + for (int i = 37; i <= 39; i++) { + pstmt.setObject(i, null, microsoft.sql.Types.SMALLMONEY); + } + + // money + for (int i = 40; i <= 42; i++) { + pstmt.setObject(i, null, microsoft.sql.Types.MONEY); + } + + // decimal(28,4) + for (int i = 43; i <= 45; i++) { + pstmt.setObject(i, null, java.sql.Types.DECIMAL, 28, 4); + } + + // numeric + for (int i = 46; i <= 48; i++) { + pstmt.setObject(i, null, java.sql.Types.NUMERIC, 28, 4); + } + + pstmt.execute(); + Util.close(null, pstmt, null); + } + + /** + * Populate numeric data with set null. + * + * @param values + * @throws SQLException + */ + protected static void populateNumericNullCase(String[] values) throws SQLException { + String sql = "insert into " + numericTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + + + ")"; + + pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); + + // bit + for (int i = 1; i <= 3; i++) { + pstmt.setNull(i, java.sql.Types.BIT); + } + + // tinyint + for (int i = 4; i <= 6; i++) { + pstmt.setNull(i, java.sql.Types.TINYINT); + } + + // smallint + for (int i = 7; i <= 9; i++) { + pstmt.setNull(i, java.sql.Types.SMALLINT); + } + + // int + for (int i = 10; i <= 12; i++) { + pstmt.setNull(i, java.sql.Types.INTEGER); + } + + // bigint + for (int i = 13; i <= 15; i++) { + pstmt.setNull(i, java.sql.Types.BIGINT); + } + + // float default + for (int i = 16; i <= 18; i++) { + pstmt.setNull(i, java.sql.Types.DOUBLE); + } + + // float(30) + for (int i = 19; i <= 21; i++) { + pstmt.setNull(i, java.sql.Types.DOUBLE); + } + + // real + for (int i = 22; i <= 24; i++) { + pstmt.setNull(i, java.sql.Types.REAL); + } + + // decimal default + for (int i = 25; i <= 27; i++) { + pstmt.setBigDecimal(i, null); + } + + // decimal(10,5) + for (int i = 28; i <= 30; i++) { + pstmt.setBigDecimal(i, null, 10, 5); + } + + // numeric + for (int i = 31; i <= 33; i++) { + pstmt.setBigDecimal(i, null); + } + + // numeric(8,2) + for (int i = 34; i <= 36; i++) { + pstmt.setBigDecimal(i, null, 8, 2); + } + + // small money + for (int i = 37; i <= 39; i++) { + pstmt.setSmallMoney(i, null); + } + + // money + for (int i = 40; i <= 42; i++) { + pstmt.setMoney(i, null); + } + + // decimal(28,4) + for (int i = 43; i <= 45; i++) { + pstmt.setBigDecimal(i, null, 28, 4); + } + + // decimal(28,4) + for (int i = 46; i <= 48; i++) { + pstmt.setBigDecimal(i, null, 28, 4); + } + pstmt.execute(); + Util.close(null, pstmt, null); + } + + /** + * Populate numeric data. + * + * @param numericValues + * @throws SQLException + */ + protected static void populateNumericNormalCase(String[] numericValues) throws SQLException { + String sql = "insert into " + numericTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + + + ")"; + + pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); + + // bit + for (int i = 1; i <= 3; i++) { + if (numericValues[0].equalsIgnoreCase("true")) { + pstmt.setBoolean(i, true); + } + else { + pstmt.setBoolean(i, false); + } + } + + // tinyint + for (int i = 4; i <= 6; i++) { + if (1 == Integer.valueOf(numericValues[1])) { + pstmt.setBoolean(i, true); + } + else { + pstmt.setBoolean(i, false); + } + } + + // smallint + for (int i = 7; i <= 9; i++) { + if (numericValues[2].equalsIgnoreCase("255")) { + pstmt.setByte(i, (byte) 255); + } + else { + pstmt.setByte(i, Byte.valueOf(numericValues[2])); + } + } + + // int + for (int i = 10; i <= 12; i++) { + pstmt.setShort(i, Short.valueOf(numericValues[3])); + } + + // bigint + for (int i = 13; i <= 15; i++) { + pstmt.setInt(i, Integer.valueOf(numericValues[4])); + } + + // float default + for (int i = 16; i <= 18; i++) { + pstmt.setDouble(i, Double.valueOf(numericValues[5])); + } + + // float(30) + for (int i = 19; i <= 21; i++) { + pstmt.setDouble(i, Double.valueOf(numericValues[6])); + } + + // real + for (int i = 22; i <= 24; i++) { + pstmt.setFloat(i, Float.valueOf(numericValues[7])); + } + + // decimal default + for (int i = 25; i <= 27; i++) { + pstmt.setBigDecimal(i, new BigDecimal(numericValues[8])); + } + + // decimal(10,5) + for (int i = 28; i <= 30; i++) { + pstmt.setBigDecimal(i, new BigDecimal(numericValues[9]), 10, 5); + } + + // numeric + for (int i = 31; i <= 33; i++) { + pstmt.setBigDecimal(i, new BigDecimal(numericValues[10])); + } + + // numeric(8,2) + for (int i = 34; i <= 36; i++) { + pstmt.setBigDecimal(i, new BigDecimal(numericValues[11]), 8, 2); + } + + // small money + for (int i = 37; i <= 39; i++) { + pstmt.setSmallMoney(i, new BigDecimal(numericValues[12])); + } + + // money + for (int i = 40; i <= 42; i++) { + pstmt.setSmallMoney(i, new BigDecimal(numericValues[13])); + } + + // decimal(28,4) + for (int i = 43; i <= 45; i++) { + pstmt.setBigDecimal(i, new BigDecimal(numericValues[14]), 28, 4); + } + + // numeric + for (int i = 46; i <= 48; i++) { + pstmt.setBigDecimal(i, new BigDecimal(numericValues[15]), 28, 4); + } + + pstmt.execute(); + Util.close(null, pstmt, null); + } + + /** + * Dropping column encryption key + * + * @throws SQLServerException + * @throws SQLException + */ + private static void dropCEK() throws SQLServerException, SQLException { + String cekSql = " if exists (SELECT name from sys.column_encryption_keys where name='" + cekName + "')" + " begin" + + " drop column encryption key " + cekName + " end"; + stmt.execute(cekSql); + } + + /** + * Dropping column master key + * + * @throws SQLServerException + * @throws SQLException + */ + private static void dropCMK() throws SQLServerException, SQLException { + String cekSql = " if exists (SELECT name from sys.column_master_keys where name='" + cmkName + "')" + " begin" + " drop column master key " + + cmkName + " end"; + stmt.execute(cekSql); + } + + /** + * Skip test if the client is using Java 7 or does not support JDBC 4.2. + * + * @throws SQLException + * @throws TestAbortedException + */ + protected static void skipTestForJava7() throws TestAbortedException, SQLException { + assumeTrue(Util.supportJDBC42(con)); // With Java 7, skip tests for JDBCType. } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java new file mode 100644 index 000000000..b9bdcce26 --- /dev/null +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java @@ -0,0 +1,2645 @@ +package com.microsoft.sqlserver.jdbc.AlwaysEncrypted; + +import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.platform.runner.JUnitPlatform; +import org.junit.runner.RunWith; + +import java.math.BigDecimal; +import java.sql.Date; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Time; +import java.sql.Timestamp; +import java.util.LinkedList; + +import com.microsoft.sqlserver.jdbc.SQLServerCallableStatement; +import com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionKeyStoreProvider; +import com.microsoft.sqlserver.jdbc.SQLServerException; +import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement; +import com.microsoft.sqlserver.jdbc.SQLServerResultSet; +import com.microsoft.sqlserver.jdbc.SQLServerStatementColumnEncryptionSetting; +import com.microsoft.sqlserver.testframework.util.RandomData; +import com.microsoft.sqlserver.testframework.util.Util; + +import microsoft.sql.DateTimeOffset; + +@RunWith(JUnitPlatform.class) +public class CallableStatementTest extends AESetup { + + private static SQLServerPreparedStatement pstmt = null; + private static SQLServerCallableStatement callableStatement = null; + + private static String multiStatementsProcedure = "multiStatementsProcedure"; + + private static String inputProcedure = "inputProcedure"; + private static String inputProcedure2 = "inputProcedure2"; + + private static String outputProcedure = "outputProcedure"; + private static String outputProcedure2 = "outputProcedure2"; + private static String outputProcedure3 = "outputProcedure3"; + private static String outputProcedureChar = "outputProcedureChar"; + private static String outputProcedureNumeric = "outputProcedureNumeric"; + private static String outputProcedureBinary = "outputProcedureBinary"; + private static String outputProcedureDate = "outputProcedureDate"; + private static String MixedProcedureDateScale = "outputProcedureDateScale"; + private static String outputProcedureBatch = "outputProcedureBatch"; + private static String outputProcedure4 = "outputProcedure4"; + + private static String inoutProcedure = "inoutProcedure"; + + private static String mixedProcedure = "mixedProcedure"; + private static String mixedProcedure2 = "mixedProcedure2"; + private static String mixedProcedure3 = "mixedProcedure3"; + private static String mixedProcedureNumericPrcisionScale = "mixedProcedureNumericPrcisionScale"; + + private static String table1 = "StoredProcedureTable1"; + private static String table2 = "StoredProcedureTable2"; + private static String table3 = "StoredProcedureTable3"; + private static String table4 = "StoredProcedureTable4"; + private static String table5 = "StoredProcedureTable5"; + private static String table6 = "StoredProcedureTable6"; + + static final String uid = "171fbe25-4331-4765-a838-b2e3eea3e7ea"; + + private static String[] numericValues; + private static LinkedList byteValues; + private static String[] charValues; + private static LinkedList dateValues; + private static boolean nullable = false; + + /** + * Initialize the tables for this class. This method will execute AFTER the parent class (AESetup) finishes initializing. + * + * @throws SQLServerException + * @throws SQLException + */ + @BeforeAll + public static void initCallableStatementTest() throws SQLException { + dropTables(); + + numericValues = createNumericValues(nullable); + byteValues = createbinaryValues(nullable); + dateValues = createTemporalTypesCallableStatement(nullable); + charValues = createCharValues(nullable); + + createTables(); + populateTable3(); + populateTable4(); + + createCharTable(); + createNumericTable(); + createBinaryTable(); + createDateTableCallableStatement(); + populateCharNormalCase(charValues); + populateNumericSetObject(numericValues); + populateBinaryNormalCase(byteValues); + populateDateNormalCase(); + + createDateScaleTable(); + populateDateScaleNormalCase(dateValues); + } + + @AfterAll + private static void dropAll() throws SQLServerException, SQLException { + dropTables(); + } + + @Test + public void testMultiInsertionSelection() throws SQLException { + createMultiInsertionSelection(); + MultiInsertionSelection(); + } + + @Test + public void testInputProcedureNumeric() throws SQLException { + createInputProcedure(); + testInputProcedure("{call " + inputProcedure + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}", numericValues); + } + + @Test + public void testInputProcedureChar() throws SQLException { + createInputProcedure2(); + testInputProcedure2("{call " + inputProcedure2 + "(?,?,?,?,?,?,?,?)}"); + } + + @Test + public void testEncryptedOutputNumericParams() throws SQLException { + createOutputProcedure(); + testOutputProcedureRandomOrder("{call " + outputProcedure + "(?,?,?,?,?,?,?)}", numericValues); + testOutputProcedureInorder("{call " + outputProcedure + "(?,?,?,?,?,?,?)}", numericValues); + testOutputProcedureReverseOrder("{call " + outputProcedure + "(?,?,?,?,?,?,?)}", numericValues); + testOutputProcedureRandomOrder("exec " + outputProcedure + " ?,?,?,?,?,?,?", numericValues); + } + + @Test + public void testUnencryptedAndEncryptedNumericOutputParams() throws SQLException { + createOutputProcedure2(); + testOutputProcedure2RandomOrder("{call " + outputProcedure2 + "(?,?,?,?,?,?,?,?,?,?)}", numericValues); + testOutputProcedure2Inorder("{call " + outputProcedure2 + "(?,?,?,?,?,?,?,?,?,?)}", numericValues); + testOutputProcedure2ReverseOrder("{call " + outputProcedure2 + "(?,?,?,?,?,?,?,?,?,?)}", numericValues); + } + + @Test + public void testEncryptedOutputParamsFromDifferentTables() throws SQLException { + createOutputProcedure3(); + testOutputProcedure3RandomOrder("{call " + outputProcedure3 + "(?,?)}"); + testOutputProcedure3Inorder("{call " + outputProcedure3 + "(?,?)}"); + testOutputProcedure3ReverseOrder("{call " + outputProcedure3 + "(?,?)}"); + } + + @Test + public void testInOutProcedure() throws SQLException { + createInOutProcedure(); + testInOutProcedure("{call " + inoutProcedure + "(?)}"); + testInOutProcedure("exec " + inoutProcedure + " ?"); + } + + @Test + public void testMixedProcedure() throws SQLException { + createMixedProcedure(); + testMixedProcedure("{ ? = call " + mixedProcedure + "(?,?,?)}"); + } + + @Test + public void testUnencryptedAndEncryptedIOParams() throws SQLException { + // unencrypted input and output parameter + // encrypted input and output parameter + createMixedProcedure2(); + testMixedProcedure2RandomOrder("{call " + mixedProcedure2 + "(?,?,?,?)}"); + testMixedProcedure2Inorder("{call " + mixedProcedure2 + "(?,?,?,?)}"); + } + + @Test + public void testUnencryptedIOParams() throws SQLException { + createMixedProcedure3(); + testMixedProcedure3RandomOrder("{call " + mixedProcedure3 + "(?,?,?,?)}"); + testMixedProcedure3Inorder("{call " + mixedProcedure3 + "(?,?,?,?)}"); + testMixedProcedure3ReverseOrder("{call " + mixedProcedure3 + "(?,?,?,?)}"); + } + + @Test + public void testVariousIOParams() throws SQLException { + createMixedProcedureNumericPrcisionScale(); + testMixedProcedureNumericPrcisionScaleInorder("{call " + mixedProcedureNumericPrcisionScale + "(?,?,?,?)}"); + testMixedProcedureNumericPrcisionScaleParameterName("{call " + mixedProcedureNumericPrcisionScale + "(?,?,?,?)}"); + } + + @Test + public void testOutputProcedureChar() throws SQLException { + createOutputProcedureChar(); + testOutputProcedureCharInorder("{call " + outputProcedureChar + "(?,?,?,?,?,?,?,?,?)}"); + testOutputProcedureCharInorderObject("{call " + outputProcedureChar + "(?,?,?,?,?,?,?,?,?)}"); + } + + @Test + public void testOutputProcedureNumeric() throws SQLException { + createOutputProcedureNumeric(); + testOutputProcedureNumericInorder("{call " + outputProcedureNumeric + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}"); + testcoerctionsOutputProcedureNumericInorder("{call " + outputProcedureNumeric + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}"); + } + + @Test + public void testOutputProcedureBinary() throws SQLException { + createOutputProcedureBinary(); + testOutputProcedureBinaryInorder("{call " + outputProcedureBinary + "(?,?,?,?,?)}"); + testOutputProcedureBinaryInorderObject("{call " + outputProcedureBinary + "(?,?,?,?,?)}"); + testOutputProcedureBinaryInorderString("{call " + outputProcedureBinary + "(?,?,?,?,?)}"); + } + + @Test + public void testOutputProcedureDate() throws SQLException { + createOutputProcedureDate(); + testOutputProcedureDateInorder("{call " + outputProcedureDate + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}"); + testOutputProcedureDateInorderObject("{call " + outputProcedureDate + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}"); + } + + @Test + public void testMixedProcedureDateScale() throws SQLException { + createMixedProcedureDateScale(); + testMixedProcedureDateScaleInorder("{call " + MixedProcedureDateScale + "(?,?,?,?,?,?)}"); + testMixedProcedureDateScaleWithParameterName("{call " + MixedProcedureDateScale + "(?,?,?,?,?,?)}"); + } + + @Test + public void testOutputProcedureBatch() throws SQLException { + createOutputProcedureBatch(); + testOutputProcedureBatchInorder("{call " + outputProcedureBatch + "(?,?,?,?)}"); + } + + @Test + public void testOutputProcedure4() throws SQLException { + createOutputProcedure4(); + } + + private static void dropTables() throws SQLException { + stmt.executeUpdate("if object_id('" + table1 + "','U') is not null" + " drop table " + table1); + + stmt.executeUpdate("if object_id('" + table2 + "','U') is not null" + " drop table " + table2); + + stmt.executeUpdate("if object_id('" + table3 + "','U') is not null" + " drop table " + table3); + + stmt.executeUpdate("if object_id('" + table4 + "','U') is not null" + " drop table " + table4); + + stmt.executeUpdate("if object_id('" + charTable + "','U') is not null" + " drop table " + charTable); + + stmt.executeUpdate("if object_id('" + numericTable + "','U') is not null" + " drop table " + numericTable); + + stmt.executeUpdate("if object_id('" + binaryTable + "','U') is not null" + " drop table " + binaryTable); + + stmt.executeUpdate("if object_id('" + dateTable + "','U') is not null" + " drop table " + dateTable); + + stmt.executeUpdate("if object_id('" + table5 + "','U') is not null" + " drop table " + table5); + + stmt.executeUpdate("if object_id('" + table6 + "','U') is not null" + " drop table " + table6); + + stmt.executeUpdate("if object_id('" + scaleDateTable + "','U') is not null" + " drop table " + scaleDateTable); + } + + private static void createTables() throws SQLException { + String sql = "create table " + table1 + " (" + "PlainChar char(20) null," + + "RandomizedChar char(20) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicChar char(20) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + "PlainVarchar varchar(50) null," + + "RandomizedVarchar varchar(50) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicVarchar varchar(50) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL" + ");"; + + try { + stmt.execute(sql); + } + catch (SQLException e) { + fail(e.toString()); + } + + sql = "create table " + table2 + " (" + "PlainChar char(20) null," + + "RandomizedChar char(20) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicChar char(20) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + "PlainVarchar varchar(50) null," + + "RandomizedVarchar varchar(50) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicVarchar varchar(50) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL" + + + ");"; + + try { + stmt.execute(sql); + } + catch (SQLException e) { + fail(e.toString()); + } + + sql = "create table " + table3 + " (" + "PlainBit bit null," + + "RandomizedBit bit ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicBit bit ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + "PlainTinyint tinyint null," + + "RandomizedTinyint tinyint ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicTinyint tinyint ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + "PlainSmallint smallint null," + + "RandomizedSmallint smallint ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicSmallint smallint ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + "PlainInt int null," + + "RandomizedInt int ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicInt int ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + "PlainBigint bigint null," + + "RandomizedBigint bigint ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicBigint bigint ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + "PlainFloatDefault float null," + + "RandomizedFloatDefault float ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicFloatDefault float ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + "PlainFloat float(30) null," + + "RandomizedFloat float(30) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicFloat float(30) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + "PlainReal real null," + + "RandomizedReal real ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicReal real ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + "PlainDecimalDefault decimal(18,0) null," + + "RandomizedDecimalDefault decimal(18,0) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicDecimalDefault decimal(18,0) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + "PlainDecimal decimal(10,5) null," + + "RandomizedDecimal decimal(10,5) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicDecimal decimal(10,5) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + "PlainNumericDefault numeric(18,0) null," + + "RandomizedNumericDefault numeric(18,0) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicNumericDefault numeric(18,0) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + "PlainNumeric numeric(8,2) null," + + "RandomizedNumeric numeric(8,2) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicNumeric numeric(8,2) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + "PlainInt2 int null," + + "RandomizedInt2 int ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicInt2 int ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + "PlainSmallMoney smallmoney null," + + "RandomizedSmallMoney smallmoney ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicSmallMoney smallmoney ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + "PlainMoney money null," + + "RandomizedMoney money ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicMoney money ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + "PlainDecimal2 decimal(28,4) null," + + "RandomizedDecimal2 decimal(28,4) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicDecimal2 decimal(28,4) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + "PlainNumeric2 numeric(28,4) null," + + "RandomizedNumeric2 numeric(28,4) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicNumeric2 numeric(28,4) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + ");"; + + try { + stmt.execute(sql); + } + catch (SQLException e) { + fail(e.toString()); + } + + sql = "create table " + table4 + " (" + "PlainInt int null," + + "RandomizedInt int ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicInt int ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + ");"; + + try { + stmt.execute(sql); + } + catch (SQLException e) { + fail(e.toString()); + } + + sql = "create table " + table5 + " (" + + "c1 int ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "c2 smallint ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "c3 bigint ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + ");"; + + try { + stmt.execute(sql); + } + catch (SQLException e) { + fail(e.toString()); + } + + sql = "create table " + table6 + " (" + + "c1 int ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "c2 smallint ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "c3 bigint ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + ");"; + + try { + stmt.execute(sql); + } + catch (SQLException e) { + fail(e.toString()); + } + } + + private static void populateTable4() throws SQLException { + String sql = "insert into " + table4 + " values( " + "?,?,?" + ")"; + + pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); + + // bit + for (int i = 1; i <= 3; i++) { + pstmt.setInt(i, Integer.parseInt(numericValues[3])); + } + + pstmt.execute(); + } + + private static void populateTable3() throws SQLException { + String sql = "insert into " + table3 + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); + + // bit + for (int i = 1; i <= 3; i++) { + if (numericValues[0].equalsIgnoreCase("true")) { + pstmt.setBoolean(i, true); + } + else { + pstmt.setBoolean(i, false); + } + } + + // tinyint + for (int i = 4; i <= 6; i++) { + pstmt.setShort(i, Short.valueOf(numericValues[1])); + } + + // smallint + for (int i = 7; i <= 9; i++) { + pstmt.setShort(i, Short.parseShort(numericValues[2])); + } + + // int + for (int i = 10; i <= 12; i++) { + pstmt.setInt(i, Integer.parseInt(numericValues[3])); + } + + // bigint + for (int i = 13; i <= 15; i++) { + pstmt.setLong(i, Long.parseLong(numericValues[4])); + } + + // float default + for (int i = 16; i <= 18; i++) { + pstmt.setDouble(i, Double.parseDouble(numericValues[5])); + } + + // float(30) + for (int i = 19; i <= 21; i++) { + pstmt.setDouble(i, Double.parseDouble(numericValues[6])); + } + + // real + for (int i = 22; i <= 24; i++) { + pstmt.setFloat(i, Float.parseFloat(numericValues[7])); + } + + // decimal default + for (int i = 25; i <= 27; i++) { + if (numericValues[8].equalsIgnoreCase("0")) + pstmt.setBigDecimal(i, new BigDecimal(numericValues[8]), 18, 0); + else + pstmt.setBigDecimal(i, new BigDecimal(numericValues[8])); + } + + // decimal(10,5) + for (int i = 28; i <= 30; i++) { + pstmt.setBigDecimal(i, new BigDecimal(numericValues[9]), 10, 5); + } + + // numeric + for (int i = 31; i <= 33; i++) { + if (numericValues[10].equalsIgnoreCase("0")) + pstmt.setBigDecimal(i, new BigDecimal(numericValues[10]), 18, 0); + else + pstmt.setBigDecimal(i, new BigDecimal(numericValues[10])); + } + + // numeric(8,2) + for (int i = 34; i <= 36; i++) { + pstmt.setBigDecimal(i, new BigDecimal(numericValues[11]), 8, 2); + } + + // int2 + for (int i = 37; i <= 39; i++) { + pstmt.setInt(i, Integer.parseInt(numericValues[3])); + } + // smallmoney + for (int i = 40; i <= 42; i++) { + pstmt.setSmallMoney(i, new BigDecimal(numericValues[12])); + } + + // money + for (int i = 43; i <= 45; i++) { + pstmt.setMoney(i, new BigDecimal(numericValues[13])); + } + + // decimal(28,4) + for (int i = 46; i <= 48; i++) { + pstmt.setBigDecimal(i, new BigDecimal(numericValues[14]), 28, 4); + } + + // numeric(28,4) + for (int i = 49; i <= 51; i++) { + pstmt.setBigDecimal(i, new BigDecimal(numericValues[15]), 28, 4); + } + + pstmt.execute(); + } + + private void createMultiInsertionSelection() throws SQLException { + String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + multiStatementsProcedure + + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + multiStatementsProcedure; + stmt.execute(sql); + + sql = "CREATE PROCEDURE " + multiStatementsProcedure + " (@p0 char(20) = null, @p1 char(20) = null, @p2 char(20) = null, " + + "@p3 varchar(50) = null, @p4 varchar(50) = null, @p5 varchar(50) = null)" + " AS" + " INSERT INTO " + table1 + + " values (@p0,@p1,@p2,@p3,@p4,@p5)" + " INSERT INTO " + table2 + " values (@p0,@p1,@p2,@p3,@p4,@p5)" + " SELECT * FROM " + table1 + + " SELECT * FROM " + table2; + stmt.execute(sql); + } + + private void MultiInsertionSelection() throws SQLException { + + try { + String sql = "{call " + multiStatementsProcedure + " (?,?,?,?,?,?)}"; + callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting); + ResultSet rs = null; + + // char, varchar + for (int i = 1; i <= 3; i++) { + callableStatement.setString(i, charValues[0]); + } + + for (int i = 4; i <= 6; i++) { + callableStatement.setString(i, charValues[1]); + } + + boolean results = callableStatement.execute(); + + // skip update count which is given by insertion + while (false == results && (-1) != callableStatement.getUpdateCount()) { + results = callableStatement.getMoreResults(); + } + + while (results) { + rs = callableStatement.getResultSet(); + int numberOfColumns = rs.getMetaData().getColumnCount(); + + while (rs.next()) { + testGetString(rs, numberOfColumns); + } + rs.close(); + results = callableStatement.getMoreResults(); + } + } + catch (SQLException e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void testGetString(ResultSet rs, + int numberOfColumns) throws SQLException { + for (int i = 1; i <= numberOfColumns; i = i + 3) { + + String stringValue1 = "" + rs.getString(i); + String stringValue2 = "" + rs.getString(i + 1); + String stringValue3 = "" + rs.getString(i + 2); + + assertTrue(stringValue1.equalsIgnoreCase(stringValue2) && stringValue2.equalsIgnoreCase(stringValue3), + "Decryption failed with getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 + ".\n"); + + } + } + + private void createInputProcedure() throws SQLException { + String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + inputProcedure + + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + inputProcedure; + stmt.execute(sql); + + sql = "CREATE PROCEDURE " + inputProcedure + " @p0 int, @p1 decimal(18, 0), " + + "@p2 float, @p3 real, @p4 numeric(18, 0), @p5 smallmoney, @p6 money," + + "@p7 bit, @p8 smallint, @p9 bigint, @p10 float(30), @p11 decimal(10,5), @p12 numeric(8,2), " + + "@p13 decimal(28,4), @p14 numeric(28,4) " + " AS" + " SELECT top 1 RandomizedInt FROM " + numericTable + + " where DeterministicInt=@p0 and DeterministicDecimalDefault=@p1 and " + + " DeterministicFloatDefault=@p2 and DeterministicReal=@p3 and DeterministicNumericDefault=@p4 and" + + " DeterministicSmallMoney=@p5 and DeterministicMoney=@p6 and DeterministicBit=@p7 and" + + " DeterministicSmallint=@p8 and DeterministicBigint=@p9 and DeterministicFloat=@p10 and" + + " DeterministicDecimal=@p11 and DeterministicNumeric=@p12 and DeterministicDecimal2=@p13 and" + " DeterministicNumeric2=@p14 "; + + stmt.execute(sql); + } + + private void testInputProcedure(String sql, + String[] values) throws SQLException { + + try { + callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting); + + callableStatement.setInt(1, Integer.parseInt(values[3])); + if (RandomData.returnZero) + callableStatement.setBigDecimal(2, new BigDecimal(values[8]), 18, 0); + else + callableStatement.setBigDecimal(2, new BigDecimal(values[8])); + callableStatement.setDouble(3, Double.parseDouble(values[5])); + callableStatement.setFloat(4, Float.parseFloat(values[7])); + if (RandomData.returnZero) + callableStatement.setBigDecimal(5, new BigDecimal(values[10]), 18, 0); // numeric(18,0) + else + callableStatement.setBigDecimal(5, new BigDecimal(values[10])); // numeric(18,0) + callableStatement.setSmallMoney(6, new BigDecimal(values[12])); + callableStatement.setMoney(7, new BigDecimal(values[13])); + if (values[0].equalsIgnoreCase("true")) + callableStatement.setBoolean(8, true); + else + callableStatement.setBoolean(8, false); + callableStatement.setShort(9, Short.parseShort(values[2])); // smallint + callableStatement.setLong(10, Long.parseLong(values[4])); // bigint + callableStatement.setDouble(11, Double.parseDouble(values[6])); // float30 + callableStatement.setBigDecimal(12, new BigDecimal(values[9]), 10, 5); // decimal(10,5) + callableStatement.setBigDecimal(13, new BigDecimal(values[11]), 8, 2); // numeric(8,2) + callableStatement.setBigDecimal(14, new BigDecimal(values[14]), 28, 4); + callableStatement.setBigDecimal(15, new BigDecimal(values[15]), 28, 4); + + SQLServerResultSet rs = (SQLServerResultSet) callableStatement.executeQuery(); + rs.next(); + + assertEquals(rs.getString(1), values[3], "" + "Test for input parameter fails.\n"); + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void createInputProcedure2() throws SQLException { + String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + inputProcedure2 + + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + inputProcedure2; + stmt.execute(sql); + + sql = "CREATE PROCEDURE " + inputProcedure2 + + " @p0 varchar(50), @p1 uniqueidentifier, @p2 varchar(max), @p3 nchar(30), @p4 nvarchar(60), @p5 nvarchar(max), " + + " @p6 varchar(8000), @p7 nvarchar(4000)" + " AS" + + " SELECT top 1 RandomizedVarchar, DeterministicUniqueidentifier, DeterministicVarcharMax, RandomizedNchar, " + + " DeterministicNvarchar, DeterministicNvarcharMax, DeterministicVarchar8000, RandomizedNvarchar4000 FROM " + charTable + + " where DeterministicVarchar = @p0 and DeterministicUniqueidentifier =@p1"; + + stmt.execute(sql); + } + + private void testInputProcedure2(String sql) throws SQLException { + + try { + callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting); + + callableStatement.setString(1, charValues[1]); + callableStatement.setUniqueIdentifier(2, charValues[6]); + callableStatement.setString(3, charValues[2]); + callableStatement.setNString(4, charValues[3]); + callableStatement.setNString(5, charValues[4]); + callableStatement.setNString(6, charValues[5]); + callableStatement.setString(7, charValues[7]); + callableStatement.setNString(8, charValues[8]); + + SQLServerResultSet rs = (SQLServerResultSet) callableStatement.executeQuery(); + rs.next(); + + assertEquals(rs.getString(1).trim(), charValues[1], "Test for input parameter fails.\n"); + assertEquals(rs.getUniqueIdentifier(2), charValues[6].toUpperCase(), "Test for input parameter fails.\n"); + assertEquals(rs.getString(3).trim(), charValues[2], "Test for input parameter fails.\n"); + assertEquals(rs.getString(4).trim(), charValues[3], "Test for input parameter fails.\n"); + assertEquals(rs.getString(5).trim(), charValues[4], "Test for input parameter fails.\n"); + assertEquals(rs.getString(6).trim(), charValues[5], "Test for input parameter fails.\n"); + assertEquals(rs.getString(7).trim(), charValues[7], "Test for input parameter fails.\n"); + assertEquals(rs.getString(8).trim(), charValues[8], "Test for input parameter fails.\n"); + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void createOutputProcedure3() throws SQLException { + String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + outputProcedure3 + + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + outputProcedure3; + stmt.execute(sql); + + sql = "CREATE PROCEDURE " + outputProcedure3 + " @p0 int OUTPUT, @p1 int OUTPUT " + " AS" + " SELECT top 1 @p0=DeterministicInt FROM " + + table3 + " SELECT top 1 @p1=RandomizedInt FROM " + table4; + + stmt.execute(sql); + } + + private void testOutputProcedure3RandomOrder(String sql) throws SQLException { + + try { + callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting); + + callableStatement.registerOutParameter(1, java.sql.Types.INTEGER); + callableStatement.registerOutParameter(2, java.sql.Types.INTEGER); + + callableStatement.execute(); + + int intValue2 = callableStatement.getInt(2); + assertEquals("" + intValue2, numericValues[3], "Test for output parameter fails.\n"); + + int intValue = callableStatement.getInt(1); + assertEquals("" + intValue, numericValues[3], "Test for output parameter fails.\n"); + + int intValue3 = callableStatement.getInt(2); + assertEquals("" + intValue3, numericValues[3], "Test for output parameter fails.\n"); + + int intValue4 = callableStatement.getInt(2); + assertEquals("" + intValue4, numericValues[3], "Test for output parameter fails.\n"); + + int intValue5 = callableStatement.getInt(1); + assertEquals("" + intValue5, numericValues[3], "Test for output parameter fails.\n"); + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void testOutputProcedure3Inorder(String sql) throws SQLException { + + try { + callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting); + + callableStatement.registerOutParameter(1, java.sql.Types.INTEGER); + callableStatement.registerOutParameter(2, java.sql.Types.INTEGER); + + callableStatement.execute(); + + int intValue = callableStatement.getInt(1); + assertEquals("" + intValue, numericValues[3], "Test for output parameter fails.\n"); + + int intValue2 = callableStatement.getInt(2); + assertEquals("" + intValue2, numericValues[3], "Test for output parameter fails.\n"); + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void testOutputProcedure3ReverseOrder(String sql) throws SQLException { + + try { + callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting); + + callableStatement.registerOutParameter(1, java.sql.Types.INTEGER); + callableStatement.registerOutParameter(2, java.sql.Types.INTEGER); + + callableStatement.execute(); + + int intValue2 = callableStatement.getInt(2); + assertEquals("" + intValue2, numericValues[3], "Test for output parameter fails.\n"); + + int intValue = callableStatement.getInt(1); + assertEquals("" + intValue, numericValues[3], "Test for output parameter fails.\n"); + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void createOutputProcedure2() throws SQLException { + String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + outputProcedure2 + + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + outputProcedure2; + stmt.execute(sql); + + sql = "CREATE PROCEDURE " + outputProcedure2 + + " @p0 int OUTPUT, @p1 int OUTPUT, @p2 smallint OUTPUT, @p3 smallint OUTPUT, @p4 tinyint OUTPUT, @p5 tinyint OUTPUT, @p6 smallmoney OUTPUT," + + " @p7 smallmoney OUTPUT, @p8 money OUTPUT, @p9 money OUTPUT " + " AS" + + " SELECT top 1 @p0=PlainInt, @p1=DeterministicInt, @p2=PlainSmallint," + + " @p3=RandomizedSmallint, @p4=PlainTinyint, @p5=DeterministicTinyint, @p6=DeterministicSmallMoney, @p7=PlainSmallMoney," + + " @p8=PlainMoney, @p9=DeterministicMoney FROM " + table3; + + stmt.execute(sql); + } + + private void testOutputProcedure2RandomOrder(String sql, + String[] values) throws SQLException { + + try { + callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting); + + callableStatement.registerOutParameter(1, java.sql.Types.INTEGER); + callableStatement.registerOutParameter(2, java.sql.Types.INTEGER); + callableStatement.registerOutParameter(3, java.sql.Types.SMALLINT); + callableStatement.registerOutParameter(4, java.sql.Types.SMALLINT); + callableStatement.registerOutParameter(5, java.sql.Types.TINYINT); + callableStatement.registerOutParameter(6, java.sql.Types.TINYINT); + callableStatement.registerOutParameter(7, microsoft.sql.Types.SMALLMONEY); + callableStatement.registerOutParameter(8, microsoft.sql.Types.SMALLMONEY); + callableStatement.registerOutParameter(9, microsoft.sql.Types.MONEY); + callableStatement.registerOutParameter(10, microsoft.sql.Types.MONEY); + + callableStatement.execute(); + + BigDecimal ecnryptedSmallMoney = callableStatement.getSmallMoney(7); + assertEquals("" + ecnryptedSmallMoney, values[12], "Test for output parameter fails.\n"); + + short encryptedSmallint = callableStatement.getShort(4); + assertEquals("" + encryptedSmallint, values[2], "Test for output parameter fails.\n"); + + BigDecimal SmallMoneyValue = callableStatement.getSmallMoney(8); + assertEquals("" + SmallMoneyValue, values[12], "Test for output parameter fails.\n"); + + short encryptedTinyint = callableStatement.getShort(6); + assertEquals("" + encryptedTinyint, values[1], "Test for output parameter fails.\n"); + + short tinyintValue = callableStatement.getShort(5); + assertEquals("" + tinyintValue, values[1], "Test for output parameter fails.\n"); + + BigDecimal encryptedMoneyValue = callableStatement.getMoney(9); + assertEquals("" + encryptedMoneyValue, values[13], "Test for output parameter fails.\n"); + + short smallintValue = callableStatement.getShort(3); + assertEquals("" + smallintValue, values[2], "Test for output parameter fails.\n"); + + int intValue = callableStatement.getInt(1); + assertEquals("" + intValue, values[3], "Test for output parameter fails.\n"); + + BigDecimal encryptedSmallMoney = callableStatement.getMoney(10); + assertEquals("" + encryptedSmallMoney, values[13], "Test for output parameter fails.\n"); + + int encryptedInt = callableStatement.getInt(2); + assertEquals("" + encryptedInt, values[3], "Test for output parameter fails.\n"); + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void testOutputProcedure2Inorder(String sql, + String[] values) throws SQLException { + + try { + callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting); + + callableStatement.registerOutParameter(1, java.sql.Types.INTEGER); + callableStatement.registerOutParameter(2, java.sql.Types.INTEGER); + callableStatement.registerOutParameter(3, java.sql.Types.SMALLINT); + callableStatement.registerOutParameter(4, java.sql.Types.SMALLINT); + callableStatement.registerOutParameter(5, java.sql.Types.TINYINT); + callableStatement.registerOutParameter(6, java.sql.Types.TINYINT); + callableStatement.registerOutParameter(7, microsoft.sql.Types.SMALLMONEY); + callableStatement.registerOutParameter(8, microsoft.sql.Types.SMALLMONEY); + callableStatement.registerOutParameter(9, microsoft.sql.Types.MONEY); + callableStatement.registerOutParameter(10, microsoft.sql.Types.MONEY); + callableStatement.execute(); + + int intValue = callableStatement.getInt(1); + assertEquals("" + intValue, values[3], "Test for output parameter fails.\n"); + + int encryptedInt = callableStatement.getInt(2); + assertEquals("" + encryptedInt, values[3], "Test for output parameter fails.\n"); + + short smallintValue = callableStatement.getShort(3); + assertEquals("" + smallintValue, values[2], "Test for output parameter fails.\n"); + + short encryptedSmallint = callableStatement.getShort(4); + assertEquals("" + encryptedSmallint, values[2], "Test for output parameter fails.\n"); + + short tinyintValue = callableStatement.getShort(5); + assertEquals("" + tinyintValue, values[1], "Test for output parameter fails.\n"); + + short encryptedTinyint = callableStatement.getShort(6); + assertEquals("" + encryptedTinyint, values[1], "Test for output parameter fails.\n"); + + BigDecimal encryptedSmallMoney = callableStatement.getSmallMoney(7); + assertEquals("" + encryptedSmallMoney, values[12], "Test for output parameter fails.\n"); + + BigDecimal SmallMoneyValue = callableStatement.getSmallMoney(8); + assertEquals("" + SmallMoneyValue, values[12], "Test for output parameter fails.\n"); + + BigDecimal MoneyValue = callableStatement.getMoney(9); + assertEquals("" + MoneyValue, values[13], "Test for output parameter fails.\n"); + + BigDecimal encryptedMoney = callableStatement.getMoney(10); + assertEquals("" + encryptedMoney, values[13], "Test for output parameter fails.\n"); + + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void testOutputProcedure2ReverseOrder(String sql, + String[] values) throws SQLException { + + try { + callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting); + + callableStatement.registerOutParameter(1, java.sql.Types.INTEGER); + callableStatement.registerOutParameter(2, java.sql.Types.INTEGER); + callableStatement.registerOutParameter(3, java.sql.Types.SMALLINT); + callableStatement.registerOutParameter(4, java.sql.Types.SMALLINT); + callableStatement.registerOutParameter(5, java.sql.Types.TINYINT); + callableStatement.registerOutParameter(6, java.sql.Types.TINYINT); + callableStatement.registerOutParameter(7, microsoft.sql.Types.SMALLMONEY); + callableStatement.registerOutParameter(8, microsoft.sql.Types.SMALLMONEY); + callableStatement.registerOutParameter(9, microsoft.sql.Types.MONEY); + callableStatement.registerOutParameter(10, microsoft.sql.Types.MONEY); + + callableStatement.execute(); + + BigDecimal encryptedMoney = callableStatement.getMoney(10); + assertEquals("" + encryptedMoney, values[13], "Test for output parameter fails.\n"); + + BigDecimal MoneyValue = callableStatement.getMoney(9); + assertEquals("" + MoneyValue, values[13], "Test for output parameter fails.\n"); + + BigDecimal SmallMoneyValue = callableStatement.getSmallMoney(8); + assertEquals("" + SmallMoneyValue, values[12], "Test for output parameter fails.\n"); + + BigDecimal encryptedSmallMoney = callableStatement.getSmallMoney(7); + assertEquals("" + encryptedSmallMoney, values[12], "Test for output parameter fails.\n"); + + short encryptedTinyint = callableStatement.getShort(6); + assertEquals("" + encryptedTinyint, values[1], "Test for output parameter fails.\n"); + + short tinyintValue = callableStatement.getShort(5); + assertEquals("" + tinyintValue, values[1], "Test for output parameter fails.\n"); + + short encryptedSmallint = callableStatement.getShort(4); + assertEquals("" + encryptedSmallint, values[2], "Test for output parameter fails.\n"); + + short smallintValue = callableStatement.getShort(3); + assertEquals("" + smallintValue, values[2], "Test for output parameter fails.\n"); + + int encryptedInt = callableStatement.getInt(2); + assertEquals("" + encryptedInt, values[3], "Test for output parameter fails.\n"); + + int intValue = callableStatement.getInt(1); + assertEquals("" + intValue, values[3], "Test for output parameter fails.\n"); + + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void createOutputProcedure() throws SQLException { + String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + outputProcedure + + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + outputProcedure; + stmt.execute(sql); + + sql = "CREATE PROCEDURE " + outputProcedure + " @p0 int OUTPUT, @p1 float OUTPUT, @p2 smallint OUTPUT, " + + "@p3 bigint OUTPUT, @p4 tinyint OUTPUT, @p5 smallmoney OUTPUT, @p6 money OUTPUT " + " AS" + + " SELECT top 1 @p0=RandomizedInt, @p1=DeterministicFloatDefault, @p2=RandomizedSmallint," + + " @p3=RandomizedBigint, @p4=DeterministicTinyint, @p5=DeterministicSmallMoney, @p6=DeterministicMoney FROM " + table3; + + stmt.execute(sql); + } + + private void testOutputProcedureRandomOrder(String sql, + String[] values) throws SQLException { + + try { + callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting); + + callableStatement.registerOutParameter(1, java.sql.Types.INTEGER); + callableStatement.registerOutParameter(2, java.sql.Types.DOUBLE); + callableStatement.registerOutParameter(3, java.sql.Types.SMALLINT); + callableStatement.registerOutParameter(4, java.sql.Types.BIGINT); + callableStatement.registerOutParameter(5, java.sql.Types.TINYINT); + callableStatement.registerOutParameter(6, microsoft.sql.Types.SMALLMONEY); + callableStatement.registerOutParameter(7, microsoft.sql.Types.MONEY); + + callableStatement.execute(); + + double floatValue0 = callableStatement.getDouble(2); + assertEquals("" + floatValue0, "" + values[5], "Test for output parameter fails.\n"); + + long bigintValue = callableStatement.getLong(4); + assertEquals("" + bigintValue, values[4], "Test for output parameter fails.\n"); + + short tinyintValue = callableStatement.getShort(5); // tinyint + assertEquals("" + tinyintValue, values[1], "Test for output parameter fails.\n"); + + double floatValue1 = callableStatement.getDouble(2); + assertEquals("" + floatValue1, "" + values[5], "Test for output parameter fails.\n"); + + int intValue2 = callableStatement.getInt(1); + assertEquals("" + intValue2, "" + values[3], "Test for output parameter fails.\n"); + + double floatValue2 = callableStatement.getDouble(2); + assertEquals("" + floatValue2, "" + values[5], "Test for output parameter fails.\n"); + + short shortValue3 = callableStatement.getShort(3); // smallint + assertEquals("" + shortValue3, "" + values[2], "Test for output parameter fails.\n"); + + short shortValue32 = callableStatement.getShort(3); + assertEquals("" + shortValue32, "" + values[2], "Test for output parameter fails.\n"); + + BigDecimal smallmoney1 = callableStatement.getSmallMoney(6); + assertEquals("" + smallmoney1, "" + values[12], "Test for output parameter fails.\n"); + BigDecimal money1 = callableStatement.getMoney(7); + assertEquals("" + money1, "" + values[13], "Test for output parameter fails.\n"); + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void testOutputProcedureInorder(String sql, + String[] values) throws SQLException { + + try { + callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting); + + callableStatement.registerOutParameter(1, java.sql.Types.INTEGER); + callableStatement.registerOutParameter(2, java.sql.Types.DOUBLE); + callableStatement.registerOutParameter(3, java.sql.Types.SMALLINT); + callableStatement.registerOutParameter(4, java.sql.Types.BIGINT); + callableStatement.registerOutParameter(5, java.sql.Types.TINYINT); + callableStatement.registerOutParameter(6, microsoft.sql.Types.SMALLMONEY); + callableStatement.registerOutParameter(7, microsoft.sql.Types.MONEY); + + callableStatement.execute(); + + int intValue2 = callableStatement.getInt(1); + assertEquals("" + intValue2, values[3], "Test for output parameter fails.\n"); + + double floatValue0 = callableStatement.getDouble(2); + assertEquals("" + floatValue0, values[5], "Test for output parameter fails.\n"); + + short shortValue3 = callableStatement.getShort(3); + assertEquals("" + shortValue3, values[2], "Test for output parameter fails.\n"); + + long bigintValue = callableStatement.getLong(4); + assertEquals("" + bigintValue, values[4], "Test for output parameter fails.\n"); + + short tinyintValue = callableStatement.getShort(5); + assertEquals("" + tinyintValue, values[1], "Test for output parameter fails.\n"); + + BigDecimal smallMoney1 = callableStatement.getSmallMoney(6); + assertEquals("" + smallMoney1, values[12], "Test for output parameter fails.\n"); + + BigDecimal money1 = callableStatement.getMoney(7); + assertEquals("" + money1, values[13], "Test for output parameter fails.\n"); + + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void testOutputProcedureReverseOrder(String sql, + String[] values) throws SQLException { + + try { + callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting); + + callableStatement.registerOutParameter(1, java.sql.Types.INTEGER); + callableStatement.registerOutParameter(2, java.sql.Types.DOUBLE); + callableStatement.registerOutParameter(3, java.sql.Types.SMALLINT); + callableStatement.registerOutParameter(4, java.sql.Types.BIGINT); + callableStatement.registerOutParameter(5, java.sql.Types.TINYINT); + callableStatement.registerOutParameter(6, microsoft.sql.Types.SMALLMONEY); + callableStatement.registerOutParameter(7, microsoft.sql.Types.MONEY); + callableStatement.execute(); + + BigDecimal smallMoney1 = callableStatement.getSmallMoney(6); + assertEquals("" + smallMoney1, values[12], "Test for output parameter fails.\n"); + + BigDecimal money1 = callableStatement.getMoney(7); + assertEquals("" + money1, values[13], "Test for output parameter fails.\n"); + + short tinyintValue = callableStatement.getShort(5); + assertEquals("" + tinyintValue, values[1], "Test for output parameter fails.\n"); + + long bigintValue = callableStatement.getLong(4); + assertEquals("" + bigintValue, values[4], "Test for output parameter fails.\n"); + + short shortValue3 = callableStatement.getShort(3); + assertEquals("" + shortValue3, values[2], "Test for output parameter fails.\n"); + + double floatValue0 = callableStatement.getDouble(2); + assertEquals("" + floatValue0, values[5], "Test for output parameter fails.\n"); + + int intValue2 = callableStatement.getInt(1); + assertEquals("" + intValue2, values[3], "Test for output parameter fails.\n"); + + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void createInOutProcedure() throws SQLException { + String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + inoutProcedure + + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + inoutProcedure; + stmt.execute(sql); + + sql = "CREATE PROCEDURE " + inoutProcedure + " @p0 int OUTPUT" + " AS" + " SELECT top 1 @p0=DeterministicInt FROM " + table3 + + " where DeterministicInt=@p0"; + + stmt.execute(sql); + } + + private void testInOutProcedure(String sql) throws SQLException { + + try { + callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting); + + callableStatement.setInt(1, Integer.parseInt(numericValues[3])); + callableStatement.registerOutParameter(1, java.sql.Types.INTEGER); + callableStatement.execute(); + + int intValue = callableStatement.getInt(1); + + assertEquals("" + intValue, numericValues[3], "Test for Inout parameter fails.\n"); + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void createMixedProcedure() throws SQLException { + String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + mixedProcedure + + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + mixedProcedure; + stmt.execute(sql); + + sql = "CREATE PROCEDURE " + mixedProcedure + " @p0 int OUTPUT, @p1 float OUTPUT, @p3 decimal " + " AS" + + " SELECT top 1 @p0=DeterministicInt2, @p1=RandomizedFloatDefault FROM " + table3 + + " where DeterministicInt=@p0 and DeterministicDecimalDefault=@p3" + " return 123"; + + stmt.execute(sql); + } + + private void testMixedProcedure(String sql) throws SQLException { + + try { + callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting); + + callableStatement.registerOutParameter(1, java.sql.Types.INTEGER); + callableStatement.setInt(2, Integer.parseInt(numericValues[3])); + callableStatement.registerOutParameter(2, java.sql.Types.INTEGER); + callableStatement.registerOutParameter(3, java.sql.Types.DOUBLE); + if (RandomData.returnZero) + callableStatement.setBigDecimal(4, new BigDecimal(numericValues[8]), 18, 0); + else + callableStatement.setBigDecimal(4, new BigDecimal(numericValues[8])); + callableStatement.execute(); + + int intValue = callableStatement.getInt(2); + assertEquals("" + intValue, numericValues[3], "Test for Inout parameter fails.\n"); + + double floatValue = callableStatement.getDouble(3); + assertEquals("" + floatValue, numericValues[5], "Test for output parameter fails.\n"); + + int returnedValue = callableStatement.getInt(1); + assertEquals("" + returnedValue, "" + 123, "Test for Inout parameter fails.\n"); + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void createMixedProcedure2() throws SQLException { + String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + mixedProcedure2 + + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + mixedProcedure2; + stmt.execute(sql); + + sql = "CREATE PROCEDURE " + mixedProcedure2 + " @p0 int OUTPUT, @p1 float OUTPUT, @p3 int, @p4 float " + " AS" + + " SELECT top 1 @p0=DeterministicInt, @p1=PlainFloatDefault FROM " + table3 + + " where PlainInt=@p3 and DeterministicFloatDefault=@p4"; + + stmt.execute(sql); + } + + private void testMixedProcedure2RandomOrder(String sql) throws SQLException { + + try { + callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting); + + callableStatement.registerOutParameter(1, java.sql.Types.INTEGER); + callableStatement.registerOutParameter(2, java.sql.Types.FLOAT); + callableStatement.setInt(3, Integer.parseInt(numericValues[3])); + callableStatement.setDouble(4, Double.parseDouble(numericValues[5])); + callableStatement.execute(); + + double floatValue = callableStatement.getDouble(2); + assertEquals("" + floatValue, numericValues[5], "Test for output parameter fails.\n"); + + int intValue = callableStatement.getInt(1); + assertEquals("" + intValue, numericValues[3], "Test for output parameter fails.\n"); + + double floatValue2 = callableStatement.getDouble(2); + assertEquals("" + floatValue2, numericValues[5], "Test for output parameter fails.\n"); + + int intValue2 = callableStatement.getInt(1); + assertEquals("" + intValue2, numericValues[3], "Test for output parameter fails.\n"); + + int intValue3 = callableStatement.getInt(1); + assertEquals("" + intValue3, numericValues[3], "Test for output parameter fails.\n"); + + double floatValue3 = callableStatement.getDouble(2); + assertEquals("" + floatValue3, numericValues[5], "Test for output parameter fails.\n"); + + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void testMixedProcedure2Inorder(String sql) throws SQLException { + + try { + callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting); + + callableStatement.registerOutParameter(1, java.sql.Types.INTEGER); + callableStatement.registerOutParameter(2, java.sql.Types.FLOAT); + callableStatement.setInt(3, Integer.parseInt(numericValues[3])); + callableStatement.setDouble(4, Double.parseDouble(numericValues[5])); + callableStatement.execute(); + + int intValue = callableStatement.getInt(1); + assertEquals("" + intValue, numericValues[3], "Test for output parameter fails.\n"); + + double floatValue = callableStatement.getDouble(2); + assertEquals("" + floatValue, numericValues[5], "Test for output parameter fails.\n"); + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void createMixedProcedure3() throws SQLException { + String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + mixedProcedure3 + + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + mixedProcedure3; + stmt.execute(sql); + + sql = "CREATE PROCEDURE " + mixedProcedure3 + " @p0 bigint OUTPUT, @p1 float OUTPUT, @p2 int OUTPUT, @p3 smallint" + " AS" + + " SELECT top 1 @p0=PlainBigint, @p1=PlainFloatDefault FROM " + table3 + " where PlainInt=@p2 and PlainSmallint=@p3"; + + stmt.execute(sql); + } + + private void testMixedProcedure3RandomOrder(String sql) throws SQLException { + + try { + callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting); + + callableStatement.registerOutParameter(1, java.sql.Types.BIGINT); + callableStatement.registerOutParameter(2, java.sql.Types.FLOAT); + callableStatement.setInt(3, Integer.parseInt(numericValues[3])); + callableStatement.setShort(4, Short.parseShort(numericValues[2])); + callableStatement.execute(); + + double floatValue = callableStatement.getDouble(2); + assertEquals("" + floatValue, numericValues[5], "Test for output parameter fails.\n"); + + long bigintValue = callableStatement.getLong(1); + assertEquals("" + bigintValue, numericValues[4], "Test for output parameter fails.\n"); + + long bigintValue1 = callableStatement.getLong(1); + assertEquals("" + bigintValue1, numericValues[4], "Test for output parameter fails.\n"); + + double floatValue2 = callableStatement.getDouble(2); + assertEquals("" + floatValue2, numericValues[5], "Test for output parameter fails.\n"); + + double floatValue3 = callableStatement.getDouble(2); + assertEquals("" + floatValue3, numericValues[5], "Test for output parameter fails.\n"); + + long bigintValue3 = callableStatement.getLong(1); + assertEquals("" + bigintValue3, numericValues[4], "Test for output parameter fails.\n"); + + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void testMixedProcedure3Inorder(String sql) throws SQLException { + + try { + callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting); + + callableStatement.registerOutParameter(1, java.sql.Types.BIGINT); + callableStatement.registerOutParameter(2, java.sql.Types.FLOAT); + callableStatement.setInt(3, Integer.parseInt(numericValues[3])); + callableStatement.setShort(4, Short.parseShort(numericValues[2])); + callableStatement.execute(); + + long bigintValue = callableStatement.getLong(1); + assertEquals("" + bigintValue, numericValues[4], "Test for output parameter fails.\n"); + + double floatValue = callableStatement.getDouble(2); + assertEquals("" + floatValue, numericValues[5], "Test for output parameter fails.\n"); + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void testMixedProcedure3ReverseOrder(String sql) throws SQLException { + + try { + callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting); + + callableStatement.registerOutParameter(1, java.sql.Types.BIGINT); + callableStatement.registerOutParameter(2, java.sql.Types.FLOAT); + callableStatement.setInt(3, Integer.parseInt(numericValues[3])); + callableStatement.setShort(4, Short.parseShort(numericValues[2])); + callableStatement.execute(); + + double floatValue = callableStatement.getDouble(2); + assertEquals("" + floatValue, numericValues[5], "Test for output parameter fails.\n"); + + long bigintValue = callableStatement.getLong(1); + assertEquals("" + bigintValue, numericValues[4], "Test for output parameter fails.\n"); + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void createMixedProcedureNumericPrcisionScale() throws SQLException { + String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + mixedProcedureNumericPrcisionScale + + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + mixedProcedureNumericPrcisionScale; + stmt.execute(sql); + + sql = "CREATE PROCEDURE " + mixedProcedureNumericPrcisionScale + + " @p1 decimal(18,0) OUTPUT, @p2 decimal(10,5) OUTPUT, @p3 numeric(18, 0) OUTPUT, @p4 numeric(8,2) OUTPUT " + " AS" + + " SELECT top 1 @p1=RandomizedDecimalDefault, @p2=DeterministicDecimal," + + " @p3=RandomizedNumericDefault, @p4=DeterministicNumeric FROM " + table3 + + " where DeterministicDecimal=@p2 and DeterministicNumeric=@p4" + " return 123"; + + stmt.execute(sql); + } + + private void testMixedProcedureNumericPrcisionScaleInorder(String sql) throws SQLException { + + try { + SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting); + + callableStatement.registerOutParameter(1, java.sql.Types.DECIMAL, 18, 0); + callableStatement.registerOutParameter(2, java.sql.Types.DECIMAL, 10, 5); + callableStatement.registerOutParameter(3, java.sql.Types.NUMERIC, 18, 0); + callableStatement.registerOutParameter(4, java.sql.Types.NUMERIC, 8, 2); + callableStatement.setBigDecimal(2, new BigDecimal(numericValues[9]), 10, 5); + callableStatement.setBigDecimal(4, new BigDecimal(numericValues[11]), 8, 2); + callableStatement.execute(); + + BigDecimal value1 = callableStatement.getBigDecimal(1); + assertEquals(value1, new BigDecimal(numericValues[8]), "Test for input output parameter fails.\n"); + + BigDecimal value2 = callableStatement.getBigDecimal(2); + assertEquals(value2, new BigDecimal(numericValues[9]), "Test for input output parameter fails.\n"); + + BigDecimal value3 = callableStatement.getBigDecimal(3); + assertEquals(value3, new BigDecimal(numericValues[10]), "Test for input output parameter fails.\n"); + + BigDecimal value4 = callableStatement.getBigDecimal(4); + assertEquals(value4, new BigDecimal(numericValues[11]), "Test for input output parameter fails.\n"); + + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void testMixedProcedureNumericPrcisionScaleParameterName(String sql) throws SQLException { + + try { + SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting); + + callableStatement.registerOutParameter("p1", java.sql.Types.DECIMAL, 18, 0); + callableStatement.registerOutParameter("p2", java.sql.Types.DECIMAL, 10, 5); + callableStatement.registerOutParameter("p3", java.sql.Types.NUMERIC, 18, 0); + callableStatement.registerOutParameter("p4", java.sql.Types.NUMERIC, 8, 2); + callableStatement.setBigDecimal("p2", new BigDecimal(numericValues[9]), 10, 5); + callableStatement.setBigDecimal("p4", new BigDecimal(numericValues[11]), 8, 2); + callableStatement.execute(); + + BigDecimal value1 = callableStatement.getBigDecimal(1); + assertEquals(value1, new BigDecimal(numericValues[8]), "Test for input output parameter fails.\n"); + + BigDecimal value2 = callableStatement.getBigDecimal(2); + assertEquals(value2, new BigDecimal(numericValues[9]), "Test for input output parameter fails.\n"); + + BigDecimal value3 = callableStatement.getBigDecimal(3); + assertEquals(value3, new BigDecimal(numericValues[10]), "Test for input output parameter fails.\n"); + + BigDecimal value4 = callableStatement.getBigDecimal(4); + assertEquals(value4, new BigDecimal(numericValues[11]), "Test for input output parameter fails.\n"); + + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void createOutputProcedureChar() throws SQLException { + String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + outputProcedureChar + + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + outputProcedureChar; + stmt.execute(sql); + + sql = "CREATE PROCEDURE " + outputProcedureChar + " @p0 char(20) OUTPUT,@p1 varchar(50) OUTPUT,@p2 nchar(30) OUTPUT," + + "@p3 nvarchar(60) OUTPUT, @p4 uniqueidentifier OUTPUT, @p5 varchar(max) OUTPUT, @p6 nvarchar(max) OUTPUT, @p7 varchar(8000) OUTPUT, @p8 nvarchar(4000) OUTPUT" + + " AS" + " SELECT top 1 @p0=DeterministicChar,@p1=RandomizedVarChar,@p2=RandomizedNChar," + + " @p3=DeterministicNVarChar, @p4=DeterministicUniqueidentifier, @p5=DeterministicVarcharMax," + + " @p6=DeterministicNvarcharMax, @p7=DeterministicVarchar8000, @p8=RandomizedNvarchar4000 FROM " + charTable; + + stmt.execute(sql); + } + + private void testOutputProcedureCharInorder(String sql) throws SQLException { + + try (SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting);) { + callableStatement.registerOutParameter(1, java.sql.Types.CHAR, 20, 0); + callableStatement.registerOutParameter(2, java.sql.Types.VARCHAR, 50, 0); + callableStatement.registerOutParameter(3, java.sql.Types.NCHAR, 30, 0); + callableStatement.registerOutParameter(4, java.sql.Types.NVARCHAR, 60, 0); + callableStatement.registerOutParameter(5, microsoft.sql.Types.GUID); + callableStatement.registerOutParameter(6, java.sql.Types.LONGVARCHAR); + callableStatement.registerOutParameter(7, java.sql.Types.LONGNVARCHAR); + callableStatement.registerOutParameter(8, java.sql.Types.VARCHAR, 8000, 0); + callableStatement.registerOutParameter(9, java.sql.Types.NVARCHAR, 4000, 0); + + callableStatement.execute(); + String charValue = callableStatement.getString(1).trim(); + assertEquals(charValue, charValues[0], "Test for output parameter fails.\n"); + + String varcharValue = callableStatement.getString(2).trim(); + assertEquals(varcharValue, charValues[1], "Test for output parameter fails.\n"); + + String ncharValue = callableStatement.getString(3).trim(); + assertEquals(ncharValue, charValues[3], "Test for output parameter fails.\n"); + + String nvarcharValue = callableStatement.getString(4).trim(); + assertEquals(nvarcharValue, charValues[4], "Test for output parameter fails.\n"); + + String uniqueIdentifierValue = callableStatement.getString(5).trim(); + assertEquals(uniqueIdentifierValue.toLowerCase(), charValues[6], "Test for output parameter fails.\n"); + + String varcharValuemax = callableStatement.getString(6).trim(); + assertEquals(varcharValuemax, charValues[2], "Test for output parameter fails.\n"); + + String nvarcharValuemax = callableStatement.getString(7).trim(); + assertEquals(nvarcharValuemax, charValues[5], "Test for output parameter fails.\n"); + + String varcharValue8000 = callableStatement.getString(8).trim(); + assertEquals(varcharValue8000, charValues[7], "Test for output parameter fails.\n"); + + String nvarcharValue4000 = callableStatement.getNString(9).trim(); + assertEquals(nvarcharValue4000, charValues[8], "Test for output parameter fails.\n"); + + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void testOutputProcedureCharInorderObject(String sql) throws SQLException { + + try (SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting);) { + callableStatement.registerOutParameter(1, java.sql.Types.CHAR, 20, 0); + callableStatement.registerOutParameter(2, java.sql.Types.VARCHAR, 50, 0); + callableStatement.registerOutParameter(3, java.sql.Types.NCHAR, 30, 0); + callableStatement.registerOutParameter(4, java.sql.Types.NVARCHAR, 60, 0); + callableStatement.registerOutParameter(5, microsoft.sql.Types.GUID); + callableStatement.registerOutParameter(6, java.sql.Types.LONGVARCHAR); + callableStatement.registerOutParameter(7, java.sql.Types.LONGNVARCHAR); + callableStatement.registerOutParameter(8, java.sql.Types.VARCHAR, 8000, 0); + callableStatement.registerOutParameter(9, java.sql.Types.NVARCHAR, 4000, 0); + + callableStatement.execute(); + + String charValue = (String) callableStatement.getObject(1); + assertEquals(charValue.trim(), charValues[0], "Test for output parameter fails.\n"); + + String varcharValue = (String) callableStatement.getObject(2); + assertEquals(varcharValue.trim(), charValues[1], "Test for output parameter fails.\n"); + + String ncharValue = (String) callableStatement.getObject(3); + assertEquals(ncharValue.trim(), charValues[3], "Test for output parameter fails.\n"); + + String nvarcharValue = (String) callableStatement.getObject(4); + assertEquals(nvarcharValue.trim(), charValues[4], "Test for output parameter fails.\n"); + + String uniqueIdentifierValue = (String) callableStatement.getObject(5); + assertEquals(uniqueIdentifierValue.toLowerCase(), charValues[6], "Test for output parameter fails.\n"); + + String varcharValuemax = (String) callableStatement.getObject(6); + + assertEquals(varcharValuemax, charValues[2], "Test for output parameter fails.\n"); + + String nvarcharValuemax = (String) callableStatement.getObject(7); + + assertEquals(nvarcharValuemax.trim(), charValues[5], "Test for output parameter fails.\n"); + + String varcharValue8000 = (String) callableStatement.getObject(8); + assertEquals(varcharValue8000, charValues[7], "Test for output parameter fails.\n"); + + String nvarcharValue4000 = (String) callableStatement.getObject(9); + assertEquals(nvarcharValue4000, charValues[8], "Test for output parameter fails.\n"); + + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void createOutputProcedureNumeric() throws SQLException { + String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + outputProcedureNumeric + + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + outputProcedureNumeric; + stmt.execute(sql); + + sql = "CREATE PROCEDURE " + outputProcedureNumeric + " @p0 bit OUTPUT, @p1 tinyint OUTPUT, @p2 smallint OUTPUT, @p3 int OUTPUT," + + " @p4 bigint OUTPUT, @p5 float OUTPUT, @p6 float(30) output, @p7 real output, @p8 decimal(18, 0) output, @p9 decimal(10,5) output," + + " @p10 numeric(18, 0) output, @p11 numeric(8,2) output, @p12 smallmoney output, @p13 money output, @p14 decimal(28,4) output, @p15 numeric(28,4) output" + + " AS" + " SELECT top 1 @p0=DeterministicBit, @p1=RandomizedTinyint, @p2=DeterministicSmallint," + + " @p3=RandomizedInt, @p4=DeterministicBigint, @p5=RandomizedFloatDefault, @p6=DeterministicFloat," + + " @p7=RandomizedReal, @p8=DeterministicDecimalDefault, @p9=RandomizedDecimal," + + " @p10=DeterministicNumericDefault, @p11=RandomizedNumeric, @p12=RandomizedSmallMoney, @p13=DeterministicMoney," + + " @p14=DeterministicDecimal2, @p15=DeterministicNumeric2 FROM " + numericTable; + + stmt.execute(sql); + } + + private void testOutputProcedureNumericInorder(String sql) throws SQLException { + + try (SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting)) { + callableStatement.registerOutParameter(1, java.sql.Types.BIT); + callableStatement.registerOutParameter(2, java.sql.Types.TINYINT); + callableStatement.registerOutParameter(3, java.sql.Types.SMALLINT); + callableStatement.registerOutParameter(4, java.sql.Types.INTEGER); + callableStatement.registerOutParameter(5, java.sql.Types.BIGINT); + callableStatement.registerOutParameter(6, java.sql.Types.DOUBLE); + callableStatement.registerOutParameter(7, java.sql.Types.DOUBLE, 30, 0); + callableStatement.registerOutParameter(8, java.sql.Types.REAL); + callableStatement.registerOutParameter(9, java.sql.Types.DECIMAL, 18, 0); + callableStatement.registerOutParameter(10, java.sql.Types.DECIMAL, 10, 5); + callableStatement.registerOutParameter(11, java.sql.Types.NUMERIC, 18, 0); + callableStatement.registerOutParameter(12, java.sql.Types.NUMERIC, 8, 2); + callableStatement.registerOutParameter(13, microsoft.sql.Types.SMALLMONEY); + callableStatement.registerOutParameter(14, microsoft.sql.Types.MONEY); + callableStatement.registerOutParameter(15, java.sql.Types.DECIMAL, 28, 4); + callableStatement.registerOutParameter(16, java.sql.Types.NUMERIC, 28, 4); + + callableStatement.execute(); + + int bitValue = callableStatement.getInt(1); + if (bitValue == 0) + assertEquals("" + false, numericValues[0], "Test for output parameter fails.\n"); + else + assertEquals("" + true, numericValues[0], "Test for output parameter fails.\n"); + + short tinyIntValue = callableStatement.getShort(2); + assertEquals("" + tinyIntValue, numericValues[1], "Test for output parameter fails.\n"); + + short smallIntValue = callableStatement.getShort(3); + assertEquals("" + smallIntValue, numericValues[2], "Test for output parameter fails.\n"); + + int intValue = callableStatement.getInt(4); + assertEquals("" + intValue, numericValues[3], "Test for output parameter fails.\n"); + + long bigintValue = callableStatement.getLong(5); + assertEquals("" + bigintValue, numericValues[4], "Test for output parameter fails.\n"); + + double floatDefault = callableStatement.getDouble(6); + assertEquals("" + floatDefault, numericValues[5], "Test for output parameter fails.\n"); + + double floatValue = callableStatement.getDouble(7); + assertEquals("" + floatValue, numericValues[6], "Test for output parameter fails.\n"); + + float realValue = callableStatement.getFloat(8); + assertEquals("" + realValue, numericValues[7], "Test for output parameter fails.\n"); + + BigDecimal decimalDefault = callableStatement.getBigDecimal(9); + assertEquals(decimalDefault, new BigDecimal(numericValues[8]), "Test for output parameter fails.\n"); + + BigDecimal decimalValue = callableStatement.getBigDecimal(10); + assertEquals(decimalValue, new BigDecimal(numericValues[9]), "Test for output parameter fails.\n"); + + BigDecimal numericDefault = callableStatement.getBigDecimal(11); + assertEquals(numericDefault, new BigDecimal(numericValues[10]), "Test for output parameter fails.\n"); + + BigDecimal numericValue = callableStatement.getBigDecimal(12); + assertEquals(numericValue, new BigDecimal(numericValues[11]), "Test for output parameter fails.\n"); + + BigDecimal smallMoneyValue = callableStatement.getSmallMoney(13); + assertEquals(smallMoneyValue, new BigDecimal(numericValues[12]), "Test for output parameter fails.\n"); + + BigDecimal moneyValue = callableStatement.getMoney(14); + assertEquals(moneyValue, new BigDecimal(numericValues[13]), "Test for output parameter fails.\n"); + + BigDecimal decimalValue2 = callableStatement.getBigDecimal(15); + assertEquals(decimalValue2, new BigDecimal(numericValues[14]), "Test for output parameter fails.\n"); + + BigDecimal numericValue2 = callableStatement.getBigDecimal(16); + assertEquals(numericValue2, new BigDecimal(numericValues[15]), "Test for output parameter fails.\n"); + + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void testcoerctionsOutputProcedureNumericInorder(String sql) throws SQLException { + + try (SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting)) { + callableStatement.registerOutParameter(1, java.sql.Types.BIT); + callableStatement.registerOutParameter(2, java.sql.Types.TINYINT); + callableStatement.registerOutParameter(3, java.sql.Types.SMALLINT); + callableStatement.registerOutParameter(4, java.sql.Types.INTEGER); + callableStatement.registerOutParameter(5, java.sql.Types.BIGINT); + callableStatement.registerOutParameter(6, java.sql.Types.DOUBLE); + callableStatement.registerOutParameter(7, java.sql.Types.DOUBLE, 30, 0); + callableStatement.registerOutParameter(8, java.sql.Types.REAL); + callableStatement.registerOutParameter(9, java.sql.Types.DECIMAL, 18, 0); + callableStatement.registerOutParameter(10, java.sql.Types.DECIMAL, 10, 5); + callableStatement.registerOutParameter(11, java.sql.Types.NUMERIC, 18, 0); + callableStatement.registerOutParameter(12, java.sql.Types.NUMERIC, 8, 2); + callableStatement.registerOutParameter(13, microsoft.sql.Types.SMALLMONEY); + callableStatement.registerOutParameter(14, microsoft.sql.Types.MONEY); + callableStatement.registerOutParameter(15, java.sql.Types.DECIMAL, 28, 4); + callableStatement.registerOutParameter(16, java.sql.Types.NUMERIC, 28, 4); + + callableStatement.execute(); + + Class[] boolean_coercions = {Object.class, Short.class, Integer.class, Long.class, Float.class, Double.class, BigDecimal.class, + String.class}; + for (int i = 0; i < boolean_coercions.length; i++) { + Object value = getxxx(1, boolean_coercions[i], callableStatement); + Object boolVal = null; + if (value.toString().equals("1") || value.equals(true) || value.toString().equals("1.0")) + boolVal = true; + else if (value.toString().equals("0") || value.equals(false) || value.toString().equals("0.0")) + boolVal = false; + assertEquals("" + boolVal, numericValues[0], "Test for output parameter fails.\n"); + } + Class[] tinyint_coercions = {Object.class, Short.class, Integer.class, Long.class, Float.class, Double.class, BigDecimal.class, + String.class}; + for (int i = 0; i < tinyint_coercions.length; i++) { + + Object tinyIntValue = getxxx(2, tinyint_coercions[i], callableStatement); + Object x = createValue(tinyint_coercions[i], 1); + + if (x instanceof String) + assertEquals("" + tinyIntValue, x, "Test for output parameter fails.\n"); + else + assertEquals(tinyIntValue, x, "Test for output parameter fails.\n"); + } + + Class[] smallint_coercions = {Object.class, Short.class, Integer.class, Long.class, Float.class, Double.class, BigDecimal.class, + String.class}; + for (int i = 0; i < smallint_coercions.length; i++) { + Object smallIntValue = getxxx(3, smallint_coercions[i], callableStatement); + Object x = createValue(smallint_coercions[i], 2); + + if (x instanceof String) + assertEquals("" + smallIntValue, x, "Test for output parameter fails.\n"); + else + assertEquals(smallIntValue, x, "Test for output parameter fails.\n"); + } + + Class[] int_coercions = {Object.class, Short.class, Integer.class, Long.class, Float.class, Double.class, BigDecimal.class, String.class}; + for (int i = 0; i < int_coercions.length; i++) { + Object IntValue = getxxx(4, int_coercions[i], callableStatement); + Object x = createValue(int_coercions[i], 3); + if (x != null) { + if (x instanceof String) + assertEquals("" + IntValue, x, "Test for output parameter fails.\n"); + else + assertEquals(IntValue, x, "Test for output parameter fails.\n"); + } + } + + Class[] bigint_coercions = {Object.class, Short.class, Integer.class, Long.class, Float.class, Double.class, BigDecimal.class, + String.class}; + for (int i = 0; i < int_coercions.length; i++) { + Object bigIntValue = getxxx(5, bigint_coercions[i], callableStatement); + Object x = createValue(bigint_coercions[i], 4); + if (x != null) { + if (x instanceof String) + assertEquals("" + bigIntValue, x, "Test for output parameter fails.\n"); + else + assertEquals(bigIntValue, x, "Test for output parameter fails.\n"); + } + } + + Class[] float_coercions = {Object.class, Short.class, Integer.class, Long.class, Float.class, Double.class, BigDecimal.class, + String.class}; + for (int i = 0; i < float_coercions.length; i++) { + Object floatDefaultValue = getxxx(6, float_coercions[i], callableStatement); + Object x = createValue(float_coercions[i], 5); + if (x != null) { + if (x instanceof String) + assertEquals("" + floatDefaultValue, x, "Test for output parameter fails.\n"); + else + assertEquals(floatDefaultValue, x, "Test for output parameter fails.\n"); + } + } + + for (int i = 0; i < float_coercions.length; i++) { + Object floatValue = getxxx(7, float_coercions[i], callableStatement); + Object x = createValue(float_coercions[i], 6); + if (x != null) { + if (x instanceof String) + assertEquals("" + floatValue, x, "Test for output parameter fails.\n"); + else + assertEquals(floatValue, x, "Test for output parameter fails.\n"); + } + } + + Class[] real_coercions = {Object.class, Short.class, Integer.class, Long.class, Float.class, BigDecimal.class, String.class}; + for (int i = 0; i < real_coercions.length; i++) { + + Object realValue = getxxx(8, real_coercions[i], callableStatement); + + Object x = createValue(real_coercions[i], 7); + if (x != null) { + if (x instanceof String) + assertEquals("" + realValue, x, "Test for output parameter fails for Coercion: " + real_coercions[i] + " for real value.\n"); + else + assertEquals(realValue, x, "Test for output parameter fails for Coercion: " + real_coercions[i] + " for real value.\n"); + } + } + + Class[] decimalDefault_coercions = {Object.class, Short.class, Integer.class, Long.class, Float.class, Double.class, BigDecimal.class, + String.class}; + for (int i = 0; i < decimalDefault_coercions.length; i++) { + Object decimalDefaultValue = getxxx(9, decimalDefault_coercions[i], callableStatement); + Object x = createValue(decimalDefault_coercions[i], 8); + if (x != null) { + if (x instanceof String) + assertEquals("" + decimalDefaultValue, x, "Test for output parameter fails.\n"); + else + assertEquals(decimalDefaultValue, x, "Test for output parameter fails.\n"); + } + } + + for (int i = 0; i < decimalDefault_coercions.length; i++) { + Object decimalValue = getxxx(10, decimalDefault_coercions[i], callableStatement); + Object x = createValue(decimalDefault_coercions[i], 9); + if (x != null) { + if (x instanceof String) + assertEquals("" + decimalValue, x, "Test for output parameter fails.\n"); + else + assertEquals(decimalValue, x, "Test for output parameter fails.\n"); + } + } + + for (int i = 0; i < decimalDefault_coercions.length; i++) { + Object numericDefaultValue = getxxx(11, decimalDefault_coercions[i], callableStatement); + Object x = createValue(decimalDefault_coercions[i], 10); + if (x != null) { + if (x instanceof String) + assertEquals("" + numericDefaultValue, x, "Test for output parameter fails.\n"); + else + assertEquals(numericDefaultValue, x, "Test for output parameter fails.\n"); + } + } + + for (int i = 0; i < decimalDefault_coercions.length; i++) { + Object numericValue = getxxx(12, decimalDefault_coercions[i], callableStatement); + Object x = createValue(decimalDefault_coercions[i], 11); + if (x != null) { + if (x instanceof String) + assertEquals("" + numericValue, x, "Test for output parameter fails.\n"); + else + assertEquals(numericValue, x, "Test for output parameter fails.\n"); + } + } + + for (int i = 0; i < decimalDefault_coercions.length; i++) { + Object smallMoneyValue = getxxx(13, decimalDefault_coercions[i], callableStatement); + Object x = createValue(decimalDefault_coercions[i], 12); + if (x != null) { + if (x instanceof String) + assertEquals("" + smallMoneyValue, x, "Test for output parameter fails.\n"); + else + assertEquals(smallMoneyValue, x, "Test for output parameter fails.\n"); + } + } + + for (int i = 0; i < decimalDefault_coercions.length; i++) { + Object moneyValue = getxxx(14, decimalDefault_coercions[i], callableStatement); + Object x = createValue(decimalDefault_coercions[i], 13); + if (x != null) { + if (x instanceof String) + assertEquals("" + moneyValue, x, "Test for output parameter fails.\n"); + else + assertEquals(moneyValue, x, "Test for output parameter fails.\n"); + } + } + for (int i = 0; i < decimalDefault_coercions.length; i++) { + Object decimalValue2 = getxxx(15, decimalDefault_coercions[i], callableStatement); + Object x = createValue(decimalDefault_coercions[i], 14); + if (x != null) { + if (x instanceof String) + assertEquals("" + decimalValue2, x, "Test for output parameter fails.\n"); + else + assertEquals(decimalValue2, x, "Test for output parameter fails.\n"); + } + } + + for (int i = 0; i < decimalDefault_coercions.length; i++) { + Object numericValue1 = getxxx(16, decimalDefault_coercions[i], callableStatement); + Object x = createValue(decimalDefault_coercions[i], 15); + if (x != null) { + if (x instanceof String) + assertEquals("" + numericValue1, x, "Test for output parameter fails.\n"); + else + assertEquals(numericValue1, x, "Test for output parameter fails.\n"); + } + } + + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private Object createValue(Class coercion, + int index) { + try { + if (coercion == Float.class) + return Float.parseFloat(numericValues[index]); + if (coercion == Integer.class) + return Integer.parseInt(numericValues[index]); + if (coercion == String.class || coercion == Boolean.class || coercion == Object.class) + return (numericValues[index]); + if (coercion == Byte.class) + return Byte.parseByte(numericValues[index]); + if (coercion == Short.class) + return Short.parseShort(numericValues[index]); + if (coercion == Long.class) + return Long.parseLong(numericValues[index]); + if (coercion == Double.class) + return Double.parseDouble(numericValues[index]); + if (coercion == BigDecimal.class) + return new BigDecimal(numericValues[index]); + } + catch (java.lang.NumberFormatException e) { + return null; + } + return null; + } + + private Object getxxx(int ordinal, + Class coercion, + SQLServerCallableStatement callableStatement) throws SQLException { + + if (coercion == null || coercion == Object.class) { + return callableStatement.getObject(ordinal); + } + else if (coercion == String.class) { + return callableStatement.getString(ordinal); + } + else if (coercion == Boolean.class) { + return new Boolean(callableStatement.getBoolean(ordinal)); + } + else if (coercion == Byte.class) { + return new Byte(callableStatement.getByte(ordinal)); + } + else if (coercion == Short.class) { + return new Short(callableStatement.getShort(ordinal)); + } + else if (coercion == Integer.class) { + return new Integer(callableStatement.getInt(ordinal)); + } + else if (coercion == Long.class) { + return new Long(callableStatement.getLong(ordinal)); + } + else if (coercion == Float.class) { + return new Float(callableStatement.getFloat(ordinal)); + } + else if (coercion == Double.class) { + return new Double(callableStatement.getDouble(ordinal)); + } + else if (coercion == BigDecimal.class) { + return callableStatement.getBigDecimal(ordinal); + } + else if (coercion == byte[].class) { + return callableStatement.getBytes(ordinal); + } + else if (coercion == java.sql.Date.class) { + return callableStatement.getDate(ordinal); + } + else if (coercion == Time.class) { + return callableStatement.getTime(ordinal); + } + else if (coercion == Timestamp.class) { + return callableStatement.getTimestamp(ordinal); + } + else if (coercion == microsoft.sql.DateTimeOffset.class) { + return callableStatement.getDateTimeOffset(ordinal); + } + else { + // Otherwise + fail("Unhandled type: " + coercion); + } + + return null; + } + + private void createOutputProcedureBinary() throws SQLException { + String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + outputProcedureBinary + + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + outputProcedureBinary; + stmt.execute(sql); + + sql = "CREATE PROCEDURE " + outputProcedureBinary + " @p0 binary(20) OUTPUT,@p1 varbinary(50) OUTPUT,@p2 varbinary(max) OUTPUT," + + " @p3 binary(512) OUTPUT,@p4 varbinary(8000) OUTPUT " + " AS" + + " SELECT top 1 @p0=RandomizedBinary,@p1=DeterministicVarbinary,@p2=DeterministicVarbinaryMax," + + " @p3=DeterministicBinary512,@p4=DeterministicBinary8000 FROM " + binaryTable; + + stmt.execute(sql); + } + + private void testOutputProcedureBinaryInorder(String sql) throws SQLException { + + try (SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting)) { + callableStatement.registerOutParameter(1, java.sql.Types.BINARY, 20, 0); + callableStatement.registerOutParameter(2, java.sql.Types.VARBINARY, 50, 0); + callableStatement.registerOutParameter(3, java.sql.Types.LONGVARBINARY); + callableStatement.registerOutParameter(4, java.sql.Types.BINARY, 512, 0); + callableStatement.registerOutParameter(5, java.sql.Types.VARBINARY, 8000, 0); + callableStatement.execute(); + + byte[] expected = byteValues.get(0); + + byte[] received1 = callableStatement.getBytes(1); + for (int i = 0; i < expected.length; i++) { + assertEquals(received1[i], expected[i], "Test for output parameter fails.\n"); + } + + expected = byteValues.get(1); + byte[] received2 = callableStatement.getBytes(2); + for (int i = 0; i < expected.length; i++) { + assertEquals(received2[i], expected[i], "Test for output parameter fails.\n"); + } + + expected = byteValues.get(2); + byte[] received3 = callableStatement.getBytes(3); + for (int i = 0; i < expected.length; i++) { + assertEquals(received3[i], expected[i], "Test for output parameter fails.\n"); + } + + expected = byteValues.get(3); + byte[] received4 = callableStatement.getBytes(4); + for (int i = 0; i < expected.length; i++) { + assertEquals(received4[i], expected[i], "Test for output parameter fails.\n"); + } + + expected = byteValues.get(4); + byte[] received5 = callableStatement.getBytes(5); + for (int i = 0; i < expected.length; i++) { + assertEquals(received5[i], expected[i], "Test for output parameter fails.\n"); + } + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void testOutputProcedureBinaryInorderObject(String sql) throws SQLException { + + try (SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting)) { + callableStatement.registerOutParameter(1, java.sql.Types.BINARY, 20, 0); + callableStatement.registerOutParameter(2, java.sql.Types.VARBINARY, 50, 0); + callableStatement.registerOutParameter(3, java.sql.Types.LONGVARBINARY); + callableStatement.registerOutParameter(4, java.sql.Types.BINARY, 512, 0); + callableStatement.registerOutParameter(5, java.sql.Types.VARBINARY, 8000, 0); + callableStatement.execute(); + + int index = 1; + for (int i = 0; i < byteValues.size(); i++) { + byte[] expected = null; + if (null != byteValues.get(i)) + expected = byteValues.get(i); + + byte[] binaryValue = (byte[]) callableStatement.getObject(index); + try { + if (null != byteValues.get(i)) { + for (int j = 0; j < expected.length; j++) { + assertEquals(expected[j] == binaryValue[j] && expected[j] == binaryValue[j] && expected[j] == binaryValue[j], true, + "Decryption failed with getObject(): " + binaryValue + ", " + binaryValue + ", " + binaryValue + ".\n"); + } + } + } + catch (Exception e) { + fail(e.toString()); + } + finally { + index++; + } + } + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void testOutputProcedureBinaryInorderString(String sql) throws SQLException { + + try (SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting)) { + callableStatement.registerOutParameter(1, java.sql.Types.BINARY, 20, 0); + callableStatement.registerOutParameter(2, java.sql.Types.VARBINARY, 50, 0); + callableStatement.registerOutParameter(3, java.sql.Types.LONGVARBINARY); + callableStatement.registerOutParameter(4, java.sql.Types.BINARY, 512, 0); + callableStatement.registerOutParameter(5, java.sql.Types.VARBINARY, 8000, 0); + callableStatement.execute(); + + int index = 1; + try { + for (int i = 0; i < byteValues.size(); i++) { + String stringValue1 = ("" + callableStatement.getString(index)).trim(); + + StringBuffer expected = new StringBuffer(); + String expectedStr = null; + + if (null != byteValues.get(i)) { + for (byte b : byteValues.get(i)) { + expected.append(String.format("%02X", b)); + } + expectedStr = "" + expected.toString(); + } + else { + expectedStr = "null"; + } + try { + assertEquals(stringValue1.startsWith(expectedStr), true, + "\nDecryption failed with getString(): " + stringValue1 + ".\nExpected Value: " + expectedStr); + } + catch (Exception e) { + fail(e.toString()); + } + finally { + index++; + } + } + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + } + + protected static void createDateTableCallableStatement() throws SQLException { + String sql = "create table " + dateTable + " (" + "PlainDate date null," + + "RandomizedDate date ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicDate date ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + "PlainDatetime2Default datetime2 null," + + "RandomizedDatetime2Default datetime2 ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicDatetime2Default datetime2 ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + "PlainDatetimeoffsetDefault datetimeoffset null," + + "RandomizedDatetimeoffsetDefault datetimeoffset ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicDatetimeoffsetDefault datetimeoffset ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + "PlainTimeDefault time null," + + "RandomizedTimeDefault time ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicTimeDefault time ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + "PlainDatetime2 datetime2(2) null," + + "RandomizedDatetime2 datetime2(2) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicDatetime2 datetime2(2) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + "PlainTime time(2) null," + + "RandomizedTime time(2) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicTime time(2) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + "PlainDatetimeoffset datetimeoffset(2) null," + + "RandomizedDatetimeoffset datetimeoffset(2) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicDatetimeoffset datetimeoffset(2) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + "PlainDateTime DateTime null," + + "RandomizedDateTime DateTime ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicDateTime DateTime ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + "PlainSmallDatetime smalldatetime null," + + "RandomizedSmallDatetime smalldatetime ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + "DeterministicSmallDatetime smalldatetime ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + cekName + ") NULL," + + + ");"; + + try { + stmt.execute(sql); + stmt.execute("DBCC FREEPROCCACHE"); + } + catch (SQLException e) { + fail(e.toString()); + } + } + + private static LinkedList createTemporalTypesCallableStatement(boolean nullable) { + + Date date = RandomData.generateDate(nullable); + Timestamp datetime2 = RandomData.generateDatetime2(7, nullable); + DateTimeOffset datetimeoffset = RandomData.generateDatetimeoffset(7, nullable); + Time time = RandomData.generateTime(7, nullable); + Timestamp datetime2_2 = RandomData.generateDatetime2(2, nullable); + Time time_2 = RandomData.generateTime(2, nullable); + DateTimeOffset datetimeoffset_2 = RandomData.generateDatetimeoffset(2, nullable); + + Timestamp datetime = RandomData.generateDatetime(nullable); + Timestamp smalldatetime = RandomData.generateSmalldatetime(nullable); + + LinkedList list = new LinkedList<>(); + list.add(date); + list.add(datetime2); + list.add(datetimeoffset); + list.add(time); + list.add(datetime2_2); + list.add(time_2); + list.add(datetimeoffset_2); + list.add(datetime); + list.add(smalldatetime); + + return list; + } + + private static void populateDateNormalCase() throws SQLException { + String sql = "insert into " + dateTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?" + ")"; + + SQLServerPreparedStatement sqlPstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); + + // date + for (int i = 1; i <= 3; i++) { + sqlPstmt.setDate(i, (Date) dateValues.get(0)); + } + + // datetime2 default + for (int i = 4; i <= 6; i++) { + sqlPstmt.setTimestamp(i, (Timestamp) dateValues.get(1)); + } + + // datetimeoffset default + for (int i = 7; i <= 9; i++) { + sqlPstmt.setDateTimeOffset(i, (DateTimeOffset) dateValues.get(2)); + } + + // time default + for (int i = 10; i <= 12; i++) { + sqlPstmt.setTime(i, (Time) dateValues.get(3)); + } + + // datetime2(2) + for (int i = 13; i <= 15; i++) { + sqlPstmt.setTimestamp(i, (Timestamp) dateValues.get(4), 2); + } + + // time(2) + for (int i = 16; i <= 18; i++) { + sqlPstmt.setTime(i, (Time) dateValues.get(5), 2); + } + + // datetimeoffset(2) + for (int i = 19; i <= 21; i++) { + sqlPstmt.setDateTimeOffset(i, (DateTimeOffset) dateValues.get(6), 2); + } + + // datetime() + for (int i = 22; i <= 24; i++) { + sqlPstmt.setDateTime(i, (Timestamp) dateValues.get(7)); + } + + // smalldatetime() + for (int i = 25; i <= 27; i++) { + sqlPstmt.setSmallDateTime(i, (Timestamp) dateValues.get(8)); + } + sqlPstmt.execute(); + } + + private void createOutputProcedureDate() throws SQLException { + String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + outputProcedureDate + + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + outputProcedureDate; + stmt.execute(sql); + + sql = "CREATE PROCEDURE " + outputProcedureDate + " @p0 date OUTPUT, @p01 date OUTPUT, @p1 datetime2 OUTPUT, @p11 datetime2 OUTPUT," + + " @p2 datetimeoffset OUTPUT, @p21 datetimeoffset OUTPUT, @p3 time OUTPUT, @p31 time OUTPUT, @p4 datetime OUTPUT, @p41 datetime OUTPUT," + + " @p5 smalldatetime OUTPUT, @p51 smalldatetime OUTPUT, @p6 datetime2(2) OUTPUT, @p61 datetime2(2) OUTPUT, @p7 time(2) OUTPUT, @p71 time(2) OUTPUT, " + + " @p8 datetimeoffset(2) OUTPUT, @p81 datetimeoffset(2) OUTPUT " + " AS" + + " SELECT top 1 @p0=PlainDate,@p01=RandomizedDate,@p1=PlainDatetime2Default,@p11=RandomizedDatetime2Default," + + " @p2=PlainDatetimeoffsetDefault,@p21=DeterministicDatetimeoffsetDefault," + " @p3=PlainTimeDefault,@p31=DeterministicTimeDefault," + + " @p4=PlainDateTime,@p41=DeterministicDateTime, @p5=PlainSmallDateTime,@p51=RandomizedSmallDateTime, " + + " @p6=PlainDatetime2,@p61=RandomizedDatetime2, @p7=PlainTime,@p71=Deterministictime, " + + " @p8=PlainDatetimeoffset, @p81=RandomizedDatetimeoffset" + " FROM " + dateTable; + + stmt.execute(sql); + } + + private void testOutputProcedureDateInorder(String sql) throws SQLException { + + try (SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting);) { + callableStatement.registerOutParameter(1, java.sql.Types.DATE); + callableStatement.registerOutParameter(2, java.sql.Types.DATE); + callableStatement.registerOutParameter(3, java.sql.Types.TIMESTAMP); + callableStatement.registerOutParameter(4, java.sql.Types.TIMESTAMP); + callableStatement.registerOutParameter(5, microsoft.sql.Types.DATETIMEOFFSET); + callableStatement.registerOutParameter(6, microsoft.sql.Types.DATETIMEOFFSET); + callableStatement.registerOutParameter(7, java.sql.Types.TIME); + callableStatement.registerOutParameter(8, java.sql.Types.TIME); + callableStatement.registerOutParameter(9, microsoft.sql.Types.DATETIME); // datetime + callableStatement.registerOutParameter(10, microsoft.sql.Types.DATETIME); // datetime + callableStatement.registerOutParameter(11, microsoft.sql.Types.SMALLDATETIME); // smalldatetime + callableStatement.registerOutParameter(12, microsoft.sql.Types.SMALLDATETIME); // smalldatetime + callableStatement.registerOutParameter(13, java.sql.Types.TIMESTAMP, 2); + callableStatement.registerOutParameter(14, java.sql.Types.TIMESTAMP, 2); + callableStatement.registerOutParameter(15, java.sql.Types.TIME, 2); + callableStatement.registerOutParameter(16, java.sql.Types.TIME, 2); + callableStatement.registerOutParameter(17, microsoft.sql.Types.DATETIMEOFFSET, 2); + callableStatement.registerOutParameter(18, microsoft.sql.Types.DATETIMEOFFSET, 2); + callableStatement.execute(); + + assertEquals(callableStatement.getDate(1), callableStatement.getDate(2), "Test for output parameter fails.\n"); + + assertEquals(callableStatement.getTimestamp(3), callableStatement.getTimestamp(4), "Test for output parameter fails.\n"); + + assertEquals(callableStatement.getDateTimeOffset(5), callableStatement.getDateTimeOffset(6), "Test for output parameter fails.\n"); + + assertEquals(callableStatement.getTime(7), callableStatement.getTime(8), "Test for output parameter fails.\n"); + assertEquals(callableStatement.getDateTime(9), // actual plain + callableStatement.getDateTime(10), // received expected enc + "Test for output parameter fails.\n"); + assertEquals(callableStatement.getSmallDateTime(11), callableStatement.getSmallDateTime(12), "Test for output parameter fails.\n"); + assertEquals(callableStatement.getTimestamp(13), callableStatement.getTimestamp(14), "Test for output parameter fails.\n"); + assertEquals(callableStatement.getTime(15).getTime(), callableStatement.getTime(16).getTime(), "Test for output parameter fails.\n"); + assertEquals(callableStatement.getDateTimeOffset(17), callableStatement.getDateTimeOffset(18), "Test for output parameter fails.\n"); + + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void testOutputProcedureDateInorderObject(String sql) throws SQLException { + + try (SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting);) { + callableStatement.registerOutParameter(1, java.sql.Types.DATE); + callableStatement.registerOutParameter(2, java.sql.Types.DATE); + callableStatement.registerOutParameter(3, java.sql.Types.TIMESTAMP); + callableStatement.registerOutParameter(4, java.sql.Types.TIMESTAMP); + callableStatement.registerOutParameter(5, microsoft.sql.Types.DATETIMEOFFSET); + callableStatement.registerOutParameter(6, microsoft.sql.Types.DATETIMEOFFSET); + callableStatement.registerOutParameter(7, java.sql.Types.TIME); + callableStatement.registerOutParameter(8, java.sql.Types.TIME); + callableStatement.registerOutParameter(9, microsoft.sql.Types.DATETIME); // datetime + callableStatement.registerOutParameter(10, microsoft.sql.Types.DATETIME); // datetime + callableStatement.registerOutParameter(11, microsoft.sql.Types.SMALLDATETIME); // smalldatetime + callableStatement.registerOutParameter(12, microsoft.sql.Types.SMALLDATETIME); // smalldatetime + callableStatement.registerOutParameter(13, java.sql.Types.TIMESTAMP, 2); + callableStatement.registerOutParameter(14, java.sql.Types.TIMESTAMP, 2); + callableStatement.registerOutParameter(15, java.sql.Types.TIME, 2); + callableStatement.registerOutParameter(16, java.sql.Types.TIME, 2); + callableStatement.registerOutParameter(17, microsoft.sql.Types.DATETIMEOFFSET, 2); + callableStatement.registerOutParameter(18, microsoft.sql.Types.DATETIMEOFFSET, 2); + callableStatement.execute(); + + assertEquals(callableStatement.getObject(1), callableStatement.getObject(2), "Test for output parameter fails.\n"); + + assertEquals(callableStatement.getObject(3), callableStatement.getObject(4), "Test for output parameter fails.\n"); + + assertEquals(callableStatement.getObject(5), callableStatement.getObject(6), "Test for output parameter fails.\n"); + + assertEquals(callableStatement.getObject(7), callableStatement.getObject(8), "Test for output parameter fails.\n"); + assertEquals(callableStatement.getObject(9), // actual plain + callableStatement.getObject(10), // received expected enc + "Test for output parameter fails.\n"); + assertEquals(callableStatement.getObject(11), callableStatement.getObject(12), "Test for output parameter fails.\n"); + assertEquals(callableStatement.getObject(13), callableStatement.getObject(14), "Test for output parameter fails.\n"); + assertEquals(callableStatement.getObject(15), callableStatement.getObject(16), "Test for output parameter fails.\n"); + assertEquals(callableStatement.getObject(17), callableStatement.getObject(18), "Test for output parameter fails.\n"); + + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void createOutputProcedureBatch() throws SQLException { + String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + outputProcedureBatch + + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + outputProcedureBatch; + stmt.execute(sql); + + // If a procedure contains more than one SQL statement, it is considered + // to be a batch of SQL statements. + sql = "CREATE PROCEDURE " + outputProcedureBatch + " @p0 int OUTPUT, @p1 float OUTPUT, @p2 smallint OUTPUT, @p3 smallmoney OUTPUT " + " AS" + + " select top 1 @p0=RandomizedInt FROM " + table3 + " select top 1 @p1=DeterministicFloatDefault FROM " + table3 + + " select top 1 @p2=RandomizedSmallint FROM " + table3 + " select top 1 @p3=DeterministicSmallMoney FROM " + table3; + + stmt.execute(sql); + } + + private void testOutputProcedureBatchInorder(String sql) throws SQLException { + + try { + callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting); + + callableStatement.registerOutParameter(1, java.sql.Types.INTEGER); + callableStatement.registerOutParameter(2, java.sql.Types.DOUBLE); + callableStatement.registerOutParameter(3, java.sql.Types.SMALLINT); + callableStatement.registerOutParameter(4, microsoft.sql.Types.SMALLMONEY); + callableStatement.execute(); + + int intValue2 = callableStatement.getInt(1); + assertEquals("" + intValue2, numericValues[3], "Test for output parameter fails.\n"); + + double floatValue0 = callableStatement.getDouble(2); + assertEquals("" + floatValue0, numericValues[5], "Test for output parameter fails.\n"); + + short shortValue3 = callableStatement.getShort(3); + assertEquals("" + shortValue3, numericValues[2], "Test for output parameter fails.\n"); + + BigDecimal smallmoneyValue = callableStatement.getSmallMoney(4); + assertEquals("" + smallmoneyValue, numericValues[12], "Test for output parameter fails.\n"); + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void createOutputProcedure4() throws SQLException { + String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + outputProcedure4 + + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + outputProcedure4; + stmt.execute(sql); + + sql = "create procedure " + outputProcedure4 + + " @in1 int, @in2 smallint, @in3 bigint, @in4 int, @in5 smallint, @in6 bigint, @out1 int output, @out2 smallint output, @out3 bigint output, @out4 int output, @out5 smallint output, @out6 bigint output" + + " as " + " insert into " + table5 + " values (@in1, @in2, @in3)" + " insert into " + table6 + " values (@in4, @in5, @in6)" + + " select * from " + table5 + " select * from " + table6 + " select @out1 = c1, @out2=c2, @out3=c3 from " + table5 + + " select @out4 = c1, @out5=c2, @out6=c3 from " + table6; + + stmt.execute(sql); + } + + private void createMixedProcedureDateScale() throws SQLException { + String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + MixedProcedureDateScale + + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + MixedProcedureDateScale; + stmt.execute(sql); + + sql = "CREATE PROCEDURE " + MixedProcedureDateScale + " @p1 datetime2(2) OUTPUT, @p2 datetime2(2) OUTPUT," + + " @p3 time(2) OUTPUT, @p4 time(2) OUTPUT, @p5 datetimeoffset(2) OUTPUT, @p6 datetimeoffset(2) OUTPUT " + " AS" + + " SELECT top 1 @p1=DeterministicDatetime2,@p2=RandomizedDatetime2,@p3=DeterministicTime,@p4=RandomizedTime," + + " @p5=DeterministicDatetimeoffset,@p6=RandomizedDatetimeoffset " + " FROM " + scaleDateTable + + " where DeterministicDatetime2 = @p1 and DeterministicTime = @p3 and DeterministicDatetimeoffset=@p5"; + + stmt.execute(sql); + } + + private void testMixedProcedureDateScaleInorder(String sql) throws SQLException { + + try (SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting)) { + callableStatement.registerOutParameter(1, java.sql.Types.TIMESTAMP, 2); + callableStatement.registerOutParameter(2, java.sql.Types.TIMESTAMP, 2); + callableStatement.registerOutParameter(3, java.sql.Types.TIME, 2); + callableStatement.registerOutParameter(4, java.sql.Types.TIME, 2); + callableStatement.registerOutParameter(5, microsoft.sql.Types.DATETIMEOFFSET, 2); + callableStatement.registerOutParameter(6, microsoft.sql.Types.DATETIMEOFFSET, 2); + callableStatement.setTimestamp(1, (Timestamp) dateValues.get(4), 2); + callableStatement.setTime(3, (Time) dateValues.get(5), 2); + callableStatement.setDateTimeOffset(5, (DateTimeOffset) dateValues.get(6), 2); + callableStatement.execute(); + + assertEquals(callableStatement.getTimestamp(1), callableStatement.getTimestamp(2), "Test for output parameter fails.\n"); + + assertEquals(callableStatement.getTime(3), callableStatement.getTime(4), "Test for output parameter fails.\n"); + + assertEquals(callableStatement.getDateTimeOffset(5), callableStatement.getDateTimeOffset(6), "Test for output parameter fails.\n"); + + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } + + private void testMixedProcedureDateScaleWithParameterName(String sql) throws SQLException { + + try (SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting)) { + callableStatement.registerOutParameter("p1", java.sql.Types.TIMESTAMP, 2); + callableStatement.registerOutParameter("p2", java.sql.Types.TIMESTAMP, 2); + callableStatement.registerOutParameter("p3", java.sql.Types.TIME, 2); + callableStatement.registerOutParameter("p4", java.sql.Types.TIME, 2); + callableStatement.registerOutParameter("p5", microsoft.sql.Types.DATETIMEOFFSET, 2); + callableStatement.registerOutParameter("p6", microsoft.sql.Types.DATETIMEOFFSET, 2); + callableStatement.setTimestamp("p1", (Timestamp) dateValues.get(4), 2); + callableStatement.setTime("p3", (Time) dateValues.get(5), 2); + callableStatement.setDateTimeOffset("p5", (DateTimeOffset) dateValues.get(6), 2); + callableStatement.execute(); + + assertEquals(callableStatement.getTimestamp(1), callableStatement.getTimestamp(2), "Test for output parameter fails.\n"); + + assertEquals(callableStatement.getTime(3), callableStatement.getTime(4), "Test for output parameter fails.\n"); + + assertEquals(callableStatement.getDateTimeOffset(5), callableStatement.getDateTimeOffset(6), "Test for output parameter fails.\n"); + + } + catch (Exception e) { + fail(e.toString()); + } + finally { + if (null != callableStatement) { + callableStatement.close(); + } + } + } +} diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java index 2f647ef37..4e47429e9 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java @@ -7,7 +7,6 @@ */ package com.microsoft.sqlserver.jdbc.AlwaysEncrypted; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -42,7 +41,6 @@ */ @RunWith(JUnitPlatform.class) public class JDBCEncryptionDecryptionTest extends AESetup { - private SQLServerPreparedStatement pstmt = null; private boolean nullable = false; private String[] numericValues = null; @@ -63,8 +61,8 @@ public class JDBCEncryptionDecryptionTest extends AESetup { */ @Test public void testCharSpecificSetter() throws SQLException { - charValues = createCharValues(); - dropTables(); + charValues = createCharValues(nullable); + dropTables(stmt); createCharTable(); populateCharNormalCase(charValues); testChar(stmt, charValues); @@ -78,8 +76,8 @@ public void testCharSpecificSetter() throws SQLException { */ @Test public void testCharSetObject() throws SQLException { - charValues = createCharValues(); - dropTables(); + charValues = createCharValues(nullable); + dropTables(stmt); createCharTable(); populateCharSetObject(charValues); testChar(stmt, charValues); @@ -95,8 +93,8 @@ public void testCharSetObject() throws SQLException { public void testCharSetObjectWithJDBCTypes() throws SQLException { skipTestForJava7(); - charValues = createCharValues(); - dropTables(); + charValues = createCharValues(nullable); + dropTables(stmt); createCharTable(); populateCharSetObjectWithJDBCTypes(charValues); testChar(stmt, charValues); @@ -111,7 +109,7 @@ public void testCharSetObjectWithJDBCTypes() throws SQLException { @Test public void testCharSpecificSetterNull() throws SQLException { String[] charValuesNull = {null, null, null, null, null, null, null, null, null}; - dropTables(); + dropTables(stmt); createCharTable(); populateCharNormalCase(charValuesNull); testChar(stmt, charValuesNull); @@ -126,7 +124,7 @@ public void testCharSpecificSetterNull() throws SQLException { @Test public void testCharSetObjectNull() throws SQLException { String[] charValuesNull = {null, null, null, null, null, null, null, null, null}; - dropTables(); + dropTables(stmt); createCharTable(); populateCharSetObject(charValuesNull); testChar(stmt, charValuesNull); @@ -141,7 +139,7 @@ public void testCharSetObjectNull() throws SQLException { @Test public void testCharSetNull() throws SQLException { String[] charValuesNull = {null, null, null, null, null, null, null, null, null}; - dropTables(); + dropTables(stmt); createCharTable(); populateCharNullCase(); testChar(stmt, charValuesNull); @@ -156,7 +154,7 @@ public void testCharSetNull() throws SQLException { @Test public void testBinarySpecificSetter() throws SQLException { LinkedList byteValues = createbinaryValues(false); - dropTables(); + dropTables(stmt); createBinaryTable(); populateBinaryNormalCase(byteValues); testBinary(stmt, byteValues); @@ -171,7 +169,7 @@ public void testBinarySpecificSetter() throws SQLException { @Test public void testBinarySetobject() throws SQLException { byteValuesSetObject = createbinaryValues(false); - dropTables(); + dropTables(stmt); createBinaryTable(); populateBinarySetObject(byteValuesSetObject); testBinary(stmt, byteValuesSetObject); @@ -186,7 +184,7 @@ public void testBinarySetobject() throws SQLException { @Test public void testBinarySetNull() throws SQLException { byteValuesNull = createbinaryValues(true); - dropTables(); + dropTables(stmt); createBinaryTable(); populateBinaryNullCase(); testBinary(stmt, byteValuesNull); @@ -201,7 +199,7 @@ public void testBinarySetNull() throws SQLException { @Test public void testBinarySpecificSetterNull() throws SQLException { byteValuesNull = createbinaryValues(true); - dropTables(); + dropTables(stmt); createBinaryTable(); populateBinaryNormalCase(null); testBinary(stmt, byteValuesNull); @@ -216,7 +214,7 @@ public void testBinarySpecificSetterNull() throws SQLException { @Test public void testBinarysetObjectNull() throws SQLException { byteValuesNull = createbinaryValues(true); - dropTables(); + dropTables(stmt); createBinaryTable(); populateBinarySetObject(null); testBinary(stmt, byteValuesNull); @@ -233,7 +231,7 @@ public void testBinarySetObjectWithJDBCTypes() throws SQLException { skipTestForJava7(); byteValuesSetObject = createbinaryValues(false); - dropTables(); + dropTables(stmt); createBinaryTable(); populateBinarySetObjectWithJDBCType(byteValuesSetObject); testBinary(stmt, byteValuesSetObject); @@ -247,8 +245,8 @@ public void testBinarySetObjectWithJDBCTypes() throws SQLException { */ @Test public void testDateSpecificSetter() throws SQLException { - dateValues = createTemporalTypes(); - dropTables(); + dateValues = createTemporalTypes(nullable); + dropTables(stmt); createDateTable(); populateDateNormalCase(dateValues); testDate(stmt, dateValues); @@ -262,8 +260,8 @@ public void testDateSpecificSetter() throws SQLException { */ @Test public void testDateSetObject() throws SQLException { - dateValues = createTemporalTypes(); - dropTables(); + dateValues = createTemporalTypes(nullable); + dropTables(stmt); createDateTable(); populateDateSetObject(dateValues, ""); testDate(stmt, dateValues); @@ -277,8 +275,8 @@ public void testDateSetObject() throws SQLException { */ @Test public void testDateSetObjectWithJavaType() throws SQLException { - dateValues = createTemporalTypes(); - dropTables(); + dateValues = createTemporalTypes(nullable); + dropTables(stmt); createDateTable(); populateDateSetObject(dateValues, "setwithJavaType"); testDate(stmt, dateValues); @@ -292,8 +290,8 @@ public void testDateSetObjectWithJavaType() throws SQLException { */ @Test public void testDateSetObjectWithJDBCType() throws SQLException { - dateValues = createTemporalTypes(); - dropTables(); + dateValues = createTemporalTypes(nullable); + dropTables(stmt); createDateTable(); populateDateSetObject(dateValues, "setwithJDBCType"); testDate(stmt, dateValues); @@ -308,8 +306,8 @@ public void testDateSetObjectWithJDBCType() throws SQLException { @Test public void testDateSpecificSetterMinMaxValue() throws SQLException { RandomData.returnMinMax = true; - dateValues = createTemporalTypes(); - dropTables(); + dateValues = createTemporalTypes(nullable); + dropTables(stmt); createDateTable(); populateDateNormalCase(dateValues); testDate(stmt, dateValues); @@ -326,8 +324,8 @@ public void testDateSetNull() throws SQLException { RandomData.returnNull = true; nullable = true; - dateValues = createTemporalTypes(); - dropTables(); + dateValues = createTemporalTypes(nullable); + dropTables(stmt); createDateTable(); populateDateNullCase(); testDate(stmt, dateValues); @@ -347,8 +345,8 @@ public void testDateSetObjectNull() throws SQLException { RandomData.returnNull = true; nullable = true; - dateValues = createTemporalTypes(); - dropTables(); + dateValues = createTemporalTypes(nullable); + dropTables(stmt); createDateTable(); populateDateSetObjectNull(); testDate(stmt, dateValues); @@ -365,11 +363,11 @@ public void testDateSetObjectNull() throws SQLException { */ @Test public void testNumericSpecificSetter() throws TestAbortedException, Exception { - numericValues = createNumericValues(); + numericValues = createNumericValues(nullable); numericValues2 = new String[numericValues.length]; System.arraycopy(numericValues, 0, numericValues2, 0, numericValues.length); - dropTables(); + dropTables(stmt); createNumericTable(); populateNumeric(numericValues); testNumeric(stmt, numericValues, false); @@ -383,11 +381,11 @@ public void testNumericSpecificSetter() throws TestAbortedException, Exception { */ @Test public void testNumericSetObject() throws SQLException { - numericValues = createNumericValues(); + numericValues = createNumericValues(nullable); numericValues2 = new String[numericValues.length]; System.arraycopy(numericValues, 0, numericValues2, 0, numericValues.length); - dropTables(); + dropTables(stmt); createNumericTable(); populateNumericSetObject(numericValues); testNumeric(null, numericValues, false); @@ -403,11 +401,11 @@ public void testNumericSetObject() throws SQLException { public void testNumericSetObjectWithJDBCTypes() throws SQLException { skipTestForJava7(); - numericValues = createNumericValues(); + numericValues = createNumericValues(nullable); numericValues2 = new String[numericValues.length]; System.arraycopy(numericValues, 0, numericValues2, 0, numericValues.length); - dropTables(); + dropTables(stmt); createNumericTable(); populateNumericSetObjectWithJDBCTypes(numericValues); testNumeric(stmt, numericValues, false); @@ -428,7 +426,7 @@ public void testNumericSpecificSetterMaxValue() throws SQLException { "999999999999999999", "12345.12345", "999999999999999999", "567812.78", "214748.3647", "922337203685477.5807", "999999999999999999999999.9999", "999999999999999999999999.9999"}; - dropTables(); + dropTables(stmt); createNumericTable(); populateNumeric(numericValuesBoundaryPositive); testNumeric(stmt, numericValuesBoundaryPositive, false); @@ -449,7 +447,7 @@ public void testNumericSpecificSetterMinValue() throws SQLException { "999999999999999999", "12345.12345", "999999999999999999", "567812.78", "-214748.3648", "-922337203685477.5808", "999999999999999999999999.9999", "999999999999999999999999.9999"}; - dropTables(); + dropTables(stmt); createNumericTable(); populateNumeric(numericValuesBoundaryNegtive); testNumeric(stmt, numericValuesBoundaryNegtive, false); @@ -465,11 +463,11 @@ public void testNumericSpecificSetterMinValue() throws SQLException { public void testNumericSpecificSetterNull() throws SQLException { nullable = true; RandomData.returnNull = true; - numericValuesNull = createNumericValues(); + numericValuesNull = createNumericValues(nullable); numericValuesNull2 = new String[numericValuesNull.length]; System.arraycopy(numericValuesNull, 0, numericValuesNull2, 0, numericValuesNull.length); - dropTables(); + dropTables(stmt); createNumericTable(); populateNumericNullCase(numericValuesNull); testNumeric(stmt, numericValuesNull, true); @@ -488,11 +486,11 @@ public void testNumericSpecificSetterNull() throws SQLException { public void testNumericSpecificSetterSetObjectNull() throws SQLException { nullable = true; RandomData.returnNull = true; - numericValuesNull = createNumericValues(); + numericValuesNull = createNumericValues(nullable); numericValuesNull2 = new String[numericValuesNull.length]; System.arraycopy(numericValuesNull, 0, numericValuesNull2, 0, numericValuesNull.length); - dropTables(); + dropTables(stmt); createNumericTable(); populateNumericSetObjectNull(); testNumeric(stmt, numericValuesNull, true); @@ -513,1227 +511,13 @@ public void testNumericNormalization() throws SQLException { "987654321123456789", "567812.78", "7812.7812", "7812.7812", "999999999999999999999999.9999", "999999999999999999999999.9999"}; String[] numericValuesNormalization2 = {"true", "1", "127", "100", "100", "1.123", "1.123", "1.123", "123456789123456789", "12345.12345", "987654321123456789", "567812.78", "7812.7812", "7812.7812", "999999999999999999999999.9999", "999999999999999999999999.9999"}; - dropTables(); + dropTables(stmt); createNumericTable(); - populateNumericNormalization(numericValuesNormalization); + populateNumericNormalCase(numericValuesNormalization); testNumeric(stmt, numericValuesNormalization, false); testNumeric(null, numericValuesNormalization2, false); } - /** - * Dropping all CMKs and CEKs and any open resources. - * - * @throws SQLServerException - * @throws SQLException - */ - @AfterAll - static void dropAll() throws SQLServerException, SQLException { - dropTables(); - dropCEK(); - dropCMK(); - Util.close(null, stmt, connection); - } - - private void populateBinaryNormalCase(LinkedList byteValues) throws SQLException { - String sql = "insert into " + binaryTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; - - pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); - - // binary20 - for (int i = 1; i <= 3; i++) { - if (null == byteValues) { - pstmt.setBytes(i, null); - } - else { - pstmt.setBytes(i, byteValues.get(0)); - } - } - - // varbinary50 - for (int i = 4; i <= 6; i++) { - if (null == byteValues) { - pstmt.setBytes(i, null); - } - else { - pstmt.setBytes(i, byteValues.get(1)); - } - } - - // varbinary(max) - for (int i = 7; i <= 9; i++) { - if (null == byteValues) { - pstmt.setBytes(i, null); - } - else { - pstmt.setBytes(i, byteValues.get(2)); - } - } - - // binary(512) - for (int i = 10; i <= 12; i++) { - if (null == byteValues) { - pstmt.setBytes(i, null); - } - else { - pstmt.setBytes(i, byteValues.get(3)); - } - } - - // varbinary(8000) - for (int i = 13; i <= 15; i++) { - if (null == byteValues) { - pstmt.setBytes(i, null); - } - else { - pstmt.setBytes(i, byteValues.get(4)); - } - } - - pstmt.execute(); - Util.close(null, pstmt, null); - } - - private void populateBinarySetObject(LinkedList byteValues) throws SQLException { - String sql = "insert into " + binaryTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; - - pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); - - // binary(20) - for (int i = 1; i <= 3; i++) { - if (null == byteValues) { - pstmt.setObject(i, null, java.sql.Types.BINARY); - } - else { - pstmt.setObject(i, byteValues.get(0)); - } - } - - // varbinary(50) - for (int i = 4; i <= 6; i++) { - if (null == byteValues) { - pstmt.setObject(i, null, java.sql.Types.BINARY); - } - else { - pstmt.setObject(i, byteValues.get(1)); - } - } - - // varbinary(max) - for (int i = 7; i <= 9; i++) { - if (null == byteValues) { - pstmt.setObject(i, null, java.sql.Types.BINARY); - } - else { - pstmt.setObject(i, byteValues.get(2)); - } - } - - // binary(512) - for (int i = 10; i <= 12; i++) { - if (null == byteValues) { - pstmt.setObject(i, null, java.sql.Types.BINARY); - } - else { - pstmt.setObject(i, byteValues.get(3)); - } - } - - // varbinary(8000) - for (int i = 13; i <= 15; i++) { - if (null == byteValues) { - pstmt.setObject(i, null, java.sql.Types.BINARY); - } - else { - pstmt.setObject(i, byteValues.get(4)); - } - } - - pstmt.execute(); - Util.close(null, pstmt, null); - } - - private void populateBinarySetObjectWithJDBCType(LinkedList byteValues) throws SQLException { - String sql = "insert into " + binaryTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; - - pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); - - // binary(20) - for (int i = 1; i <= 3; i++) { - if (null == byteValues) { - pstmt.setObject(i, null, JDBCType.BINARY); - } - else { - pstmt.setObject(i, byteValues.get(0), JDBCType.BINARY); - } - } - - // varbinary(50) - for (int i = 4; i <= 6; i++) { - if (null == byteValues) { - pstmt.setObject(i, null, JDBCType.VARBINARY); - } - else { - pstmt.setObject(i, byteValues.get(1), JDBCType.VARBINARY); - } - } - - // varbinary(max) - for (int i = 7; i <= 9; i++) { - if (null == byteValues) { - pstmt.setObject(i, null, JDBCType.VARBINARY); - } - else { - pstmt.setObject(i, byteValues.get(2), JDBCType.VARBINARY); - } - } - - // binary(512) - for (int i = 10; i <= 12; i++) { - if (null == byteValues) { - pstmt.setObject(i, null, JDBCType.BINARY); - } - else { - pstmt.setObject(i, byteValues.get(3), JDBCType.BINARY); - } - } - - // varbinary(8000) - for (int i = 13; i <= 15; i++) { - if (null == byteValues) { - pstmt.setObject(i, null, JDBCType.VARBINARY); - } - else { - pstmt.setObject(i, byteValues.get(4), JDBCType.VARBINARY); - } - } - - pstmt.execute(); - Util.close(null, pstmt, null); - } - - private void populateBinaryNullCase() throws SQLException { - String sql = "insert into " + binaryTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; - - pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); - - // binary - for (int i = 1; i <= 3; i++) { - pstmt.setNull(i, java.sql.Types.BINARY); - } - - // varbinary, varbinary(max) - for (int i = 4; i <= 9; i++) { - pstmt.setNull(i, java.sql.Types.VARBINARY); - } - - // binary512 - for (int i = 10; i <= 12; i++) { - pstmt.setNull(i, java.sql.Types.BINARY); - } - - // varbinary(8000) - for (int i = 13; i <= 15; i++) { - pstmt.setNull(i, java.sql.Types.VARBINARY); - } - - pstmt.execute(); - Util.close(null, pstmt, null); - } - - private void populateCharNormalCase(String[] charValues) throws SQLException { - String sql = "insert into " + charTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," - + "?,?,?" + ")"; - - pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); - - // char - for (int i = 1; i <= 3; i++) { - pstmt.setString(i, charValues[0]); - } - - // varchar - for (int i = 4; i <= 6; i++) { - pstmt.setString(i, charValues[1]); - } - - // varchar(max) - for (int i = 7; i <= 9; i++) { - pstmt.setString(i, charValues[2]); - } - - // nchar - for (int i = 10; i <= 12; i++) { - pstmt.setNString(i, charValues[3]); - } - - // nvarchar - for (int i = 13; i <= 15; i++) { - pstmt.setNString(i, charValues[4]); - } - - // varchar(max) - for (int i = 16; i <= 18; i++) { - pstmt.setNString(i, charValues[5]); - } - - // uniqueidentifier - for (int i = 19; i <= 21; i++) { - if (null == charValues[6]) { - pstmt.setUniqueIdentifier(i, null); - } - else { - pstmt.setUniqueIdentifier(i, uid); - } - } - - // varchar8000 - for (int i = 22; i <= 24; i++) { - pstmt.setString(i, charValues[7]); - } - - // nvarchar4000 - for (int i = 25; i <= 27; i++) { - pstmt.setNString(i, charValues[8]); - } - - pstmt.execute(); - Util.close(null, pstmt, null); - } - - private void populateCharSetObject(String[] charValues) throws SQLException { - String sql = "insert into " + charTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," - + "?,?,?" + ")"; - - pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); - - // char - for (int i = 1; i <= 3; i++) { - pstmt.setObject(i, charValues[0]); - } - - // varchar - for (int i = 4; i <= 6; i++) { - pstmt.setObject(i, charValues[1]); - } - - // varchar(max) - for (int i = 7; i <= 9; i++) { - pstmt.setObject(i, charValues[2], java.sql.Types.LONGVARCHAR); - } - - // nchar - for (int i = 10; i <= 12; i++) { - pstmt.setObject(i, charValues[3], java.sql.Types.NCHAR); - } - - // nvarchar - for (int i = 13; i <= 15; i++) { - pstmt.setObject(i, charValues[4], java.sql.Types.NCHAR); - } - - // nvarchar(max) - for (int i = 16; i <= 18; i++) { - pstmt.setObject(i, charValues[5], java.sql.Types.LONGNVARCHAR); - } - - // uniqueidentifier - for (int i = 19; i <= 21; i++) { - pstmt.setObject(i, charValues[6], microsoft.sql.Types.GUID); - } - - // varchar8000 - for (int i = 22; i <= 24; i++) { - pstmt.setObject(i, charValues[7]); - } - - // nvarchar4000 - for (int i = 25; i <= 27; i++) { - pstmt.setObject(i, charValues[8], java.sql.Types.NCHAR); - } - - pstmt.execute(); - Util.close(null, pstmt, null); - } - - private void populateCharSetObjectWithJDBCTypes(String[] charValues) throws SQLException { - String sql = "insert into " + charTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," - + "?,?,?" + ")"; - - pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); - - // char - for (int i = 1; i <= 3; i++) { - pstmt.setObject(i, charValues[0], JDBCType.CHAR); - } - - // varchar - for (int i = 4; i <= 6; i++) { - pstmt.setObject(i, charValues[1], JDBCType.VARCHAR); - } - - // varchar(max) - for (int i = 7; i <= 9; i++) { - pstmt.setObject(i, charValues[2], JDBCType.LONGVARCHAR); - } - - // nchar - for (int i = 10; i <= 12; i++) { - pstmt.setObject(i, charValues[3], JDBCType.NCHAR); - } - - // nvarchar - for (int i = 13; i <= 15; i++) { - pstmt.setObject(i, charValues[4], JDBCType.NVARCHAR); - } - - // nvarchar(max) - for (int i = 16; i <= 18; i++) { - pstmt.setObject(i, charValues[5], JDBCType.LONGNVARCHAR); - } - - // uniqueidentifier - for (int i = 19; i <= 21; i++) { - pstmt.setObject(i, charValues[6], microsoft.sql.Types.GUID); - } - - // varchar8000 - for (int i = 22; i <= 24; i++) { - pstmt.setObject(i, charValues[7], JDBCType.VARCHAR); - } - - // vnarchar4000 - for (int i = 25; i <= 27; i++) { - pstmt.setObject(i, charValues[8], JDBCType.NVARCHAR); - } - - pstmt.execute(); - Util.close(null, pstmt, null); - } - - private void populateCharNullCase() throws SQLException { - String sql = "insert into " + charTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," - + "?,?,?" + ")"; - - pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); - - // char - for (int i = 1; i <= 3; i++) { - pstmt.setNull(i, java.sql.Types.CHAR); - } - - // varchar, varchar(max) - for (int i = 4; i <= 9; i++) { - pstmt.setNull(i, java.sql.Types.VARCHAR); - } - - // nchar - for (int i = 10; i <= 12; i++) { - pstmt.setNull(i, java.sql.Types.NCHAR); - } - - // nvarchar, varchar(max) - for (int i = 13; i <= 18; i++) { - pstmt.setNull(i, java.sql.Types.NVARCHAR); - } - - // uniqueidentifier - for (int i = 19; i <= 21; i++) { - pstmt.setNull(i, microsoft.sql.Types.GUID); - - } - - // varchar8000 - for (int i = 22; i <= 24; i++) { - pstmt.setNull(i, java.sql.Types.VARCHAR); - } - - // nvarchar4000 - for (int i = 25; i <= 27; i++) { - pstmt.setNull(i, java.sql.Types.NVARCHAR); - } - - pstmt.execute(); - Util.close(null, pstmt, null); - } - - private void populateDateNormalCase(LinkedList dateValues) throws SQLException { - String sql = "insert into " + dateTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; - - SQLServerPreparedStatement sqlPstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); - - // date - for (int i = 1; i <= 3; i++) { - sqlPstmt.setDate(i, (Date) dateValues.get(0)); - } - - // datetime2 default - for (int i = 4; i <= 6; i++) { - sqlPstmt.setTimestamp(i, (Timestamp) dateValues.get(1)); - } - - // datetimeoffset default - for (int i = 7; i <= 9; i++) { - sqlPstmt.setDateTimeOffset(i, (DateTimeOffset) dateValues.get(2)); - } - - // time default - for (int i = 10; i <= 12; i++) { - sqlPstmt.setTime(i, (Time) dateValues.get(3)); - } - - // datetime - for (int i = 13; i <= 15; i++) { - sqlPstmt.setDateTime(i, (Timestamp) dateValues.get(4)); - } - - // smalldatetime - for (int i = 16; i <= 18; i++) { - sqlPstmt.setSmallDateTime(i, (Timestamp) dateValues.get(5)); - } - - sqlPstmt.execute(); - Util.close(null, sqlPstmt, null); - } - - private void populateDateSetObject(LinkedList dateValues, - String setter) throws SQLException { - if (setter.equalsIgnoreCase("setwithJDBCType")) { - skipTestForJava7(); - } - - String sql = "insert into " + dateTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; - - SQLServerPreparedStatement sqlPstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); - - // date - for (int i = 1; i <= 3; i++) { - if (setter.equalsIgnoreCase("setwithJavaType")) - sqlPstmt.setObject(i, (Date) dateValues.get(0), java.sql.Types.DATE); - else if (setter.equalsIgnoreCase("setwithJDBCType")) - sqlPstmt.setObject(i, (Date) dateValues.get(0), JDBCType.DATE); - else - sqlPstmt.setObject(i, (Date) dateValues.get(0)); - } - - // datetime2 default - for (int i = 4; i <= 6; i++) { - if (setter.equalsIgnoreCase("setwithJavaType")) - sqlPstmt.setObject(i, (Timestamp) dateValues.get(1), java.sql.Types.TIMESTAMP); - else if (setter.equalsIgnoreCase("setwithJDBCType")) - sqlPstmt.setObject(i, (Timestamp) dateValues.get(1), JDBCType.TIMESTAMP); - else - sqlPstmt.setObject(i, (Timestamp) dateValues.get(1)); - } - - // datetimeoffset default - for (int i = 7; i <= 9; i++) { - if (setter.equalsIgnoreCase("setwithJavaType")) - sqlPstmt.setObject(i, (DateTimeOffset) dateValues.get(2), microsoft.sql.Types.DATETIMEOFFSET); - else if (setter.equalsIgnoreCase("setwithJDBCType")) - sqlPstmt.setObject(i, (DateTimeOffset) dateValues.get(2), microsoft.sql.Types.DATETIMEOFFSET); - else - sqlPstmt.setObject(i, (DateTimeOffset) dateValues.get(2)); - } - - // time default - for (int i = 10; i <= 12; i++) { - if (setter.equalsIgnoreCase("setwithJavaType")) - sqlPstmt.setObject(i, (Time) dateValues.get(3), java.sql.Types.TIME); - else if (setter.equalsIgnoreCase("setwithJDBCType")) - sqlPstmt.setObject(i, (Time) dateValues.get(3), JDBCType.TIME); - else - sqlPstmt.setObject(i, (Time) dateValues.get(3)); - } - - // datetime - for (int i = 13; i <= 15; i++) { - sqlPstmt.setObject(i, (Timestamp) dateValues.get(4), microsoft.sql.Types.DATETIME); - } - - // smalldatetime - for (int i = 16; i <= 18; i++) { - sqlPstmt.setObject(i, (Timestamp) dateValues.get(5), microsoft.sql.Types.SMALLDATETIME); - } - - sqlPstmt.execute(); - Util.close(null, sqlPstmt, null); - } - - private void populateDateSetObjectNull() throws SQLException { - String sql = "insert into " + dateTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; - - SQLServerPreparedStatement sqlPstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); - - // date - for (int i = 1; i <= 3; i++) { - sqlPstmt.setObject(i, null, java.sql.Types.DATE); - } - - // datetime2 default - for (int i = 4; i <= 6; i++) { - sqlPstmt.setObject(i, null, java.sql.Types.TIMESTAMP); - } - - // datetimeoffset default - for (int i = 7; i <= 9; i++) { - sqlPstmt.setObject(i, null, microsoft.sql.Types.DATETIMEOFFSET); - } - - // time default - for (int i = 10; i <= 12; i++) { - sqlPstmt.setObject(i, null, java.sql.Types.TIME); - } - - // datetime - for (int i = 13; i <= 15; i++) { - sqlPstmt.setObject(i, null, microsoft.sql.Types.DATETIME); - } - - // smalldatetime - for (int i = 16; i <= 18; i++) { - sqlPstmt.setObject(i, null, microsoft.sql.Types.SMALLDATETIME); - } - - sqlPstmt.execute(); - Util.close(null, sqlPstmt, null); - } - - private void populateDateNullCase() throws SQLException { - String sql = "insert into " + dateTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; - - SQLServerPreparedStatement sqlPstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); - - // date - for (int i = 1; i <= 3; i++) { - sqlPstmt.setNull(i, java.sql.Types.DATE); - } - - // datetime2 default - for (int i = 4; i <= 6; i++) { - sqlPstmt.setNull(i, java.sql.Types.TIMESTAMP); - } - - // datetimeoffset default - for (int i = 7; i <= 9; i++) { - sqlPstmt.setNull(i, microsoft.sql.Types.DATETIMEOFFSET); - } - - // time default - for (int i = 10; i <= 12; i++) { - sqlPstmt.setNull(i, java.sql.Types.TIME); - } - - // datetime - for (int i = 13; i <= 15; i++) { - sqlPstmt.setNull(i, microsoft.sql.Types.DATETIME); - } - - // smalldatetime - for (int i = 16; i <= 18; i++) { - sqlPstmt.setNull(i, microsoft.sql.Types.SMALLDATETIME); - } - - sqlPstmt.execute(); - Util.close(null, sqlPstmt, null); - } - - /** - * Populating the table - * - * @param values - * @throws SQLException - */ - private void populateNumeric(String[] values) throws SQLException { - String sql = "insert into " + numericTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; - - pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); - - // bit - for (int i = 1; i <= 3; i++) { - if (values[0].equalsIgnoreCase("true")) { - pstmt.setBoolean(i, true); - } - else { - pstmt.setBoolean(i, false); - } - } - - // tinyint - for (int i = 4; i <= 6; i++) { - pstmt.setShort(i, Short.valueOf(values[1])); - } - - // smallint - for (int i = 7; i <= 9; i++) { - pstmt.setShort(i, Short.valueOf(values[2])); - } - - // int - for (int i = 10; i <= 12; i++) { - pstmt.setInt(i, Integer.valueOf(values[3])); - } - - // bigint - for (int i = 13; i <= 15; i++) { - pstmt.setLong(i, Long.valueOf(values[4])); - } - - // float default - for (int i = 16; i <= 18; i++) { - pstmt.setDouble(i, Double.valueOf(values[5])); - } - - // float(30) - for (int i = 19; i <= 21; i++) { - pstmt.setDouble(i, Double.valueOf(values[6])); - } - - // real - for (int i = 22; i <= 24; i++) { - pstmt.setFloat(i, Float.valueOf(values[7])); - } - - // decimal default - for (int i = 25; i <= 27; i++) { - if (values[8].equalsIgnoreCase("0")) - pstmt.setBigDecimal(i, new BigDecimal(values[8]), 18, 0); - else - pstmt.setBigDecimal(i, new BigDecimal(values[8])); - } - - // decimal(10,5) - for (int i = 28; i <= 30; i++) { - pstmt.setBigDecimal(i, new BigDecimal(values[9]), 10, 5); - } - - // numeric - for (int i = 31; i <= 33; i++) { - if (values[10].equalsIgnoreCase("0")) - pstmt.setBigDecimal(i, new BigDecimal(values[10]), 18, 0); - else - pstmt.setBigDecimal(i, new BigDecimal(values[10])); - } - - // numeric(8,2) - for (int i = 34; i <= 36; i++) { - pstmt.setBigDecimal(i, new BigDecimal(values[11]), 8, 2); - } - - // small money - for (int i = 37; i <= 39; i++) { - pstmt.setSmallMoney(i, new BigDecimal(values[12])); - } - - // money - for (int i = 40; i <= 42; i++) { - pstmt.setMoney(i, new BigDecimal(values[13])); - } - - // decimal(28,4) - for (int i = 43; i <= 45; i++) { - pstmt.setBigDecimal(i, new BigDecimal(values[14]), 28, 4); - } - - // numeric(28,4) - for (int i = 46; i <= 48; i++) { - pstmt.setBigDecimal(i, new BigDecimal(values[15]), 28, 4); - } - - pstmt.execute(); - Util.close(null, pstmt, null); - } - - private void populateNumericSetObject(String[] values) throws SQLException { - String sql = "insert into " + numericTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; - - pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); - - // bit - for (int i = 1; i <= 3; i++) { - if (values[0].equalsIgnoreCase("true")) { - pstmt.setObject(i, true); - } - else { - pstmt.setObject(i, false); - } - } - - // tinyint - for (int i = 4; i <= 6; i++) { - pstmt.setObject(i, Short.valueOf(values[1])); - } - - // smallint - for (int i = 7; i <= 9; i++) { - pstmt.setObject(i, Short.valueOf(values[2])); - } - - // int - for (int i = 10; i <= 12; i++) { - pstmt.setObject(i, Integer.valueOf(values[3])); - } - - // bigint - for (int i = 13; i <= 15; i++) { - pstmt.setObject(i, Long.valueOf(values[4])); - } - - // float default - for (int i = 16; i <= 18; i++) { - pstmt.setObject(i, Double.valueOf(values[5])); - } - - // float(30) - for (int i = 19; i <= 21; i++) { - pstmt.setObject(i, Double.valueOf(values[6])); - } - - // real - for (int i = 22; i <= 24; i++) { - pstmt.setObject(i, Float.valueOf(values[7])); - } - - // decimal default - for (int i = 25; i <= 27; i++) { - if (RandomData.returnZero) - pstmt.setObject(i, new BigDecimal(values[8]), java.sql.Types.DECIMAL, 18, 0); - else - pstmt.setObject(i, new BigDecimal(values[8])); - } - - // decimal(10,5) - for (int i = 28; i <= 30; i++) { - pstmt.setObject(i, new BigDecimal(values[9]), java.sql.Types.DECIMAL, 10, 5); - } - - // numeric - for (int i = 31; i <= 33; i++) { - if (RandomData.returnZero) - pstmt.setObject(i, new BigDecimal(values[10]), java.sql.Types.NUMERIC, 18, 0); - else - pstmt.setObject(i, new BigDecimal(values[10])); - } - - // numeric(8,2) - for (int i = 34; i <= 36; i++) { - pstmt.setObject(i, new BigDecimal(values[11]), java.sql.Types.NUMERIC, 8, 2); - } - - // small money - for (int i = 37; i <= 39; i++) { - pstmt.setObject(i, new BigDecimal(values[12]), microsoft.sql.Types.SMALLMONEY); - } - - // money - for (int i = 40; i <= 42; i++) { - pstmt.setObject(i, new BigDecimal(values[13]), microsoft.sql.Types.MONEY); - } - - // decimal(28,4) - for (int i = 43; i <= 45; i++) { - pstmt.setObject(i, new BigDecimal(values[14]), java.sql.Types.DECIMAL, 28, 4); - } - - // numeric - for (int i = 46; i <= 48; i++) { - pstmt.setObject(i, new BigDecimal(values[15]), java.sql.Types.NUMERIC, 28, 4); - } - - pstmt.execute(); - Util.close(null, pstmt, null); - } - - private void populateNumericSetObjectWithJDBCTypes(String[] values) throws SQLException { - String sql = "insert into " + numericTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; - - pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); - - // bit - for (int i = 1; i <= 3; i++) { - if (values[0].equalsIgnoreCase("true")) { - pstmt.setObject(i, true); - } - else { - pstmt.setObject(i, false); - } - } - - // tinyint - for (int i = 4; i <= 6; i++) { - pstmt.setObject(i, Short.valueOf(values[1]), JDBCType.TINYINT); - } - - // smallint - for (int i = 7; i <= 9; i++) { - pstmt.setObject(i, Short.valueOf(values[2]), JDBCType.SMALLINT); - } - - // int - for (int i = 10; i <= 12; i++) { - pstmt.setObject(i, Integer.valueOf(values[3]), JDBCType.INTEGER); - } - - // bigint - for (int i = 13; i <= 15; i++) { - pstmt.setObject(i, Long.valueOf(values[4]), JDBCType.BIGINT); - } - - // float default - for (int i = 16; i <= 18; i++) { - pstmt.setObject(i, Double.valueOf(values[5]), JDBCType.DOUBLE); - } - - // float(30) - for (int i = 19; i <= 21; i++) { - pstmt.setObject(i, Double.valueOf(values[6]), JDBCType.DOUBLE); - } - - // real - for (int i = 22; i <= 24; i++) { - pstmt.setObject(i, Float.valueOf(values[7]), JDBCType.REAL); - } - - // decimal default - for (int i = 25; i <= 27; i++) { - if (RandomData.returnZero) - pstmt.setObject(i, new BigDecimal(values[8]), java.sql.Types.DECIMAL, 18, 0); - else - pstmt.setObject(i, new BigDecimal(values[8])); - } - - // decimal(10,5) - for (int i = 28; i <= 30; i++) { - pstmt.setObject(i, new BigDecimal(values[9]), java.sql.Types.DECIMAL, 10, 5); - } - - // numeric - for (int i = 31; i <= 33; i++) { - if (RandomData.returnZero) - pstmt.setObject(i, new BigDecimal(values[10]), java.sql.Types.NUMERIC, 18, 0); - else - pstmt.setObject(i, new BigDecimal(values[10])); - } - - // numeric(8,2) - for (int i = 34; i <= 36; i++) { - pstmt.setObject(i, new BigDecimal(values[11]), java.sql.Types.NUMERIC, 8, 2); - } - - // small money - for (int i = 37; i <= 39; i++) { - pstmt.setObject(i, new BigDecimal(values[12]), microsoft.sql.Types.SMALLMONEY); - } - - // money - for (int i = 40; i <= 42; i++) { - pstmt.setObject(i, new BigDecimal(values[13]), microsoft.sql.Types.MONEY); - } - - // decimal(28,4) - for (int i = 43; i <= 45; i++) { - pstmt.setObject(i, new BigDecimal(values[14]), java.sql.Types.DECIMAL, 28, 4); - } - - // numeric - for (int i = 46; i <= 48; i++) { - pstmt.setObject(i, new BigDecimal(values[15]), java.sql.Types.NUMERIC, 28, 4); - } - - pstmt.execute(); - Util.close(null, pstmt, null); - } - - private void populateNumericSetObjectNull() throws SQLException { - String sql = "insert into " + numericTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; - - pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); - - // bit - for (int i = 1; i <= 3; i++) { - pstmt.setObject(i, null, java.sql.Types.BIT); - } - - // tinyint - for (int i = 4; i <= 6; i++) { - pstmt.setObject(i, null, java.sql.Types.TINYINT); - } - - // smallint - for (int i = 7; i <= 9; i++) { - pstmt.setObject(i, null, java.sql.Types.SMALLINT); - } - - // int - for (int i = 10; i <= 12; i++) { - pstmt.setObject(i, null, java.sql.Types.INTEGER); - } - - // bigint - for (int i = 13; i <= 15; i++) { - pstmt.setObject(i, null, java.sql.Types.BIGINT); - } - - // float default - for (int i = 16; i <= 18; i++) { - pstmt.setObject(i, null, java.sql.Types.DOUBLE); - } - - // float(30) - for (int i = 19; i <= 21; i++) { - pstmt.setObject(i, null, java.sql.Types.DOUBLE); - } - - // real - for (int i = 22; i <= 24; i++) { - pstmt.setObject(i, null, java.sql.Types.REAL); - } - - // decimal default - for (int i = 25; i <= 27; i++) { - pstmt.setObject(i, null, java.sql.Types.DECIMAL); - } - - // decimal(10,5) - for (int i = 28; i <= 30; i++) { - pstmt.setObject(i, null, java.sql.Types.DECIMAL, 10, 5); - } - - // numeric - for (int i = 31; i <= 33; i++) { - pstmt.setObject(i, null, java.sql.Types.NUMERIC); - } - - // numeric(8,2) - for (int i = 34; i <= 36; i++) { - pstmt.setObject(i, null, java.sql.Types.NUMERIC, 8, 2); - } - - // small money - for (int i = 37; i <= 39; i++) { - pstmt.setObject(i, null, microsoft.sql.Types.SMALLMONEY); - } - - // money - for (int i = 40; i <= 42; i++) { - pstmt.setObject(i, null, microsoft.sql.Types.MONEY); - } - - // decimal(28,4) - for (int i = 43; i <= 45; i++) { - pstmt.setObject(i, null, java.sql.Types.DECIMAL, 28, 4); - } - - // numeric - for (int i = 46; i <= 48; i++) { - pstmt.setObject(i, null, java.sql.Types.NUMERIC, 28, 4); - } - - pstmt.execute(); - Util.close(null, pstmt, null); - } - - private void populateNumericNullCase(String[] values) throws SQLException { - String sql = "insert into " + numericTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" - - + ")"; - - pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); - - // bit - for (int i = 1; i <= 3; i++) { - pstmt.setNull(i, java.sql.Types.BIT); - } - - // tinyint - for (int i = 4; i <= 6; i++) { - pstmt.setNull(i, java.sql.Types.TINYINT); - } - - // smallint - for (int i = 7; i <= 9; i++) { - pstmt.setNull(i, java.sql.Types.SMALLINT); - } - - // int - for (int i = 10; i <= 12; i++) { - pstmt.setNull(i, java.sql.Types.INTEGER); - } - - // bigint - for (int i = 13; i <= 15; i++) { - pstmt.setNull(i, java.sql.Types.BIGINT); - } - - // float default - for (int i = 16; i <= 18; i++) { - pstmt.setNull(i, java.sql.Types.DOUBLE); - } - - // float(30) - for (int i = 19; i <= 21; i++) { - pstmt.setNull(i, java.sql.Types.DOUBLE); - } - - // real - for (int i = 22; i <= 24; i++) { - pstmt.setNull(i, java.sql.Types.REAL); - } - - // decimal default - for (int i = 25; i <= 27; i++) { - pstmt.setBigDecimal(i, null); - } - - // decimal(10,5) - for (int i = 28; i <= 30; i++) { - pstmt.setBigDecimal(i, null, 10, 5); - } - - // numeric - for (int i = 31; i <= 33; i++) { - pstmt.setBigDecimal(i, null); - } - - // numeric(8,2) - for (int i = 34; i <= 36; i++) { - pstmt.setBigDecimal(i, null, 8, 2); - } - - // small money - for (int i = 37; i <= 39; i++) { - pstmt.setSmallMoney(i, null); - } - - // money - for (int i = 40; i <= 42; i++) { - pstmt.setMoney(i, null); - } - - // decimal(28,4) - for (int i = 43; i <= 45; i++) { - pstmt.setBigDecimal(i, null, 28, 4); - } - - // decimal(28,4) - for (int i = 46; i <= 48; i++) { - pstmt.setBigDecimal(i, null, 28, 4); - } - pstmt.execute(); - Util.close(null, pstmt, null); - } - - private void populateNumericNormalization(String[] numericValues) throws SQLException { - String sql = "insert into " + numericTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" - - + ")"; - - pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); - - // bit - for (int i = 1; i <= 3; i++) { - if (numericValues[0].equalsIgnoreCase("true")) { - pstmt.setBoolean(i, true); - } - else { - pstmt.setBoolean(i, false); - } - } - - // tinyint - for (int i = 4; i <= 6; i++) { - if (1 == Integer.valueOf(numericValues[1])) { - pstmt.setBoolean(i, true); - } - else { - pstmt.setBoolean(i, false); - } - } - - // smallint - for (int i = 7; i <= 9; i++) { - if (numericValues[2].equalsIgnoreCase("255")) { - pstmt.setByte(i, (byte) 255); - } - else { - pstmt.setByte(i, Byte.valueOf(numericValues[2])); - } - } - - // int - for (int i = 10; i <= 12; i++) { - pstmt.setShort(i, Short.valueOf(numericValues[3])); - } - - // bigint - for (int i = 13; i <= 15; i++) { - pstmt.setInt(i, Integer.valueOf(numericValues[4])); - } - - // float default - for (int i = 16; i <= 18; i++) { - pstmt.setDouble(i, Double.valueOf(numericValues[5])); - } - - // float(30) - for (int i = 19; i <= 21; i++) { - pstmt.setDouble(i, Double.valueOf(numericValues[6])); - } - - // real - for (int i = 22; i <= 24; i++) { - pstmt.setFloat(i, Float.valueOf(numericValues[7])); - } - - // decimal default - for (int i = 25; i <= 27; i++) { - pstmt.setBigDecimal(i, new BigDecimal(numericValues[8])); - } - - // decimal(10,5) - for (int i = 28; i <= 30; i++) { - pstmt.setBigDecimal(i, new BigDecimal(numericValues[9]), 10, 5); - } - - // numeric - for (int i = 31; i <= 33; i++) { - pstmt.setBigDecimal(i, new BigDecimal(numericValues[10])); - } - - // numeric(8,2) - for (int i = 34; i <= 36; i++) { - pstmt.setBigDecimal(i, new BigDecimal(numericValues[11]), 8, 2); - } - - // small money - for (int i = 37; i <= 39; i++) { - pstmt.setSmallMoney(i, new BigDecimal(numericValues[12])); - } - - // money - for (int i = 40; i <= 42; i++) { - pstmt.setSmallMoney(i, new BigDecimal(numericValues[13])); - } - - // decimal(28,4) - for (int i = 43; i <= 45; i++) { - pstmt.setBigDecimal(i, new BigDecimal(numericValues[14]), 28, 4); - } - - // numeric - for (int i = 46; i <= 48; i++) { - pstmt.setBigDecimal(i, new BigDecimal(numericValues[15]), 28, 4); - } - - pstmt.execute(); - Util.close(null, pstmt, null); - } - private void testChar(SQLServerStatement stmt, String[] values) throws SQLException { String sql = "select * from " + charTable; @@ -2377,91 +1161,4 @@ else if (expectedValue.equalsIgnoreCase("-3.4E+38")) { "\nDecryption failed with getBigDecimal(): " + value1 + ", " + value2 + ", " + value3 + ".\nExpected Value: " + expectedValue); } - private String[] createCharValues() { - - boolean encrypted = true; - String char20 = RandomData.generateCharTypes("20", nullable, encrypted); - String varchar50 = RandomData.generateCharTypes("50", nullable, encrypted); - String varcharmax = RandomData.generateCharTypes("max", nullable, encrypted); - String nchar30 = RandomData.generateNCharTypes("30", nullable, encrypted); - String nvarchar60 = RandomData.generateNCharTypes("60", nullable, encrypted); - String nvarcharmax = RandomData.generateNCharTypes("max", nullable, encrypted); - String varchar8000 = RandomData.generateCharTypes("8000", nullable, encrypted); - String nvarchar4000 = RandomData.generateNCharTypes("4000", nullable, encrypted); - - String[] values = {char20.trim(), varchar50, varcharmax, nchar30, nvarchar60, nvarcharmax, uid, varchar8000, nvarchar4000}; - - return values; - } - - private LinkedList createbinaryValues(boolean nullable) { - - boolean encrypted = true; - RandomData.returnNull = nullable; - - byte[] binary20 = RandomData.generateBinaryTypes("20", nullable, encrypted); - byte[] varbinary50 = RandomData.generateBinaryTypes("50", nullable, encrypted); - byte[] varbinarymax = RandomData.generateBinaryTypes("max", nullable, encrypted); - byte[] binary512 = RandomData.generateBinaryTypes("512", nullable, encrypted); - byte[] varbinary8000 = RandomData.generateBinaryTypes("8000", nullable, encrypted); - - LinkedList list = new LinkedList<>(); - list.add(binary20); - list.add(varbinary50); - list.add(varbinarymax); - list.add(binary512); - list.add(varbinary8000); - - return list; - } - - private String[] createNumericValues() { - - Boolean boolValue = RandomData.generateBoolean(nullable); - Short tinyIntValue = RandomData.generateTinyint(nullable); - Short smallIntValue = RandomData.generateSmallint(nullable); - Integer intValue = RandomData.generateInt(nullable); - Long bigintValue = RandomData.generateLong(nullable); - Double floatValue = RandomData.generateFloat(24, nullable); - Double floatValuewithPrecision = RandomData.generateFloat(53, nullable); - Float realValue = RandomData.generateReal(nullable); - BigDecimal decimal = RandomData.generateDecimalNumeric(18, 0, nullable); - BigDecimal decimalPrecisionScale = RandomData.generateDecimalNumeric(10, 5, nullable); - BigDecimal numeric = RandomData.generateDecimalNumeric(18, 0, nullable); - BigDecimal numericPrecisionScale = RandomData.generateDecimalNumeric(8, 2, nullable); - BigDecimal smallMoney = RandomData.generateSmallMoney(nullable); - BigDecimal money = RandomData.generateMoney(nullable); - BigDecimal decimalPrecisionScale2 = RandomData.generateDecimalNumeric(28, 4, nullable); - BigDecimal numericPrecisionScale2 = RandomData.generateDecimalNumeric(28, 4, nullable); - - String[] numericValues = {"" + boolValue, "" + tinyIntValue, "" + smallIntValue, "" + intValue, "" + bigintValue, "" + floatValue, - "" + floatValuewithPrecision, "" + realValue, "" + decimal, "" + decimalPrecisionScale, "" + numeric, "" + numericPrecisionScale, - "" + smallMoney, "" + money, "" + decimalPrecisionScale2, "" + numericPrecisionScale2}; - - return numericValues; - } - - private LinkedList createTemporalTypes() { - - Date date = RandomData.generateDate(nullable); - Timestamp datetime2 = RandomData.generateDatetime2(7, nullable); - DateTimeOffset datetimeoffset = RandomData.generateDatetimeoffset(7, nullable); - Time time = RandomData.generateTime(7, nullable); - Timestamp datetime = RandomData.generateDatetime(nullable); - Timestamp smalldatetime = RandomData.generateSmalldatetime(nullable); - - LinkedList list = new LinkedList<>(); - list.add(date); - list.add(datetime2); - list.add(datetimeoffset); - list.add(time); - list.add(datetime); - list.add(smalldatetime); - - return list; - } - - private void skipTestForJava7() throws TestAbortedException, SQLException { - assumeTrue(Util.supportJDBC42(con)); // With Java 7, skip tests for JDBCType. - } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java new file mode 100644 index 000000000..4a53e88fd --- /dev/null +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java @@ -0,0 +1,554 @@ +/* + * Microsoft JDBC Driver for SQL Server + * + * Copyright(c) Microsoft Corporation All rights reserved. + * + * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information. + */ +package com.microsoft.sqlserver.jdbc.AlwaysEncrypted; + +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +import java.math.BigDecimal; +import java.sql.Date; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Time; +import java.sql.Timestamp; +import java.util.ArrayList; + +import org.junit.jupiter.api.Test; + +import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement; +import com.microsoft.sqlserver.jdbc.SQLServerResultSet; +import com.microsoft.sqlserver.testframework.util.Util; + +public class PrecisionScaleTest extends AESetup { + private static SQLServerPreparedStatement pstmt = null; + + private static java.util.Date date = new Date(1450812362177L); + + @Test + public void testNumericPrecision8Scale2() throws Exception { + dropTables(stmt); + + String[] numeric = {"1.12345", "12345.12", "567.70"}; + + createNumericPrecisionTable(30, 8, 2); + populateNumericNormalCase(numeric, 8, 2); + populateNumericSetObject(numeric, 8, 2); + + testNumeric(numeric); + } + + @Test + public void testDateScale2() throws Exception { + dropTables(stmt); + + String[] dateNormalCase = {"2015-12-22 11:26:02.18", "2015-12-22 11:26:02.1770000", "2015-12-22 19:27:02.1770000 +00:01", "11:26:02.1770000", + "11:26:02.18", "2015-12-22 19:27:02.18 +00:01"}; + String[] dateSetObject = {"2015-12-22 11:26:02.18", "2015-12-22 11:26:02.177", "2015-12-22 19:27:02.177 +00:01", "11:26:02", "11:26:02", + "2015-12-22 19:27:02.18 +00:01"}; + + createDatePrecisionTable(2); + populateDateNormalCase(2); + populateDateSetObject(2); + + testDate(dateNormalCase, dateSetObject); + } + + @Test + public void testNumericPrecision8Scale0() throws Exception { + dropTables(stmt); + + String[] numeric2 = {"1.12345", "12345", "567"}; + + createNumericPrecisionTable(30, 8, 0); + populateNumericNormalCase(numeric2, 8, 0); + populateNumericSetObject(numeric2, 8, 0); + + testNumeric(numeric2); + } + + @Test + public void testDateScale0() throws Exception { + dropTables(stmt); + + String[] dateNormalCase2 = {"2015-12-22 11:26:02", "2015-12-22 11:26:02.1770000", "2015-12-22 19:27:02.1770000 +00:01", "11:26:02.1770000", + "11:26:02", "2015-12-22 19:27:02 +00:01"}; + String[] dateSetObject2 = {"2015-12-22 11:26:02.0", "2015-12-22 11:26:02.177", "2015-12-22 19:27:02.177 +00:01", "11:26:02", "11:26:02", + "2015-12-22 19:27:02 +00:01"}; + + createDatePrecisionTable(0); + populateDateNormalCase(0); + populateDateSetObject(0); + + testDate(dateNormalCase2, dateSetObject2); + } + + @Test + public void testNumericPrecision8Scale2_Null() throws Exception { + dropTables(stmt); + + String[] numericNull = {"null", "null", "null"}; + + createNumericPrecisionTable(30, 8, 2); + populateNumericSetObjectNull(8, 2); + + testNumeric(numericNull); + } + + @Test + public void testDateScale2_Null() throws Exception { + dropTables(stmt); + + String[] dateSetObjectNull = {"null", "null", "null", "null", "null", "null"}; + + createDatePrecisionTable(2); + populateDateSetObjectNull(2); + + testDate(dateSetObjectNull, dateSetObjectNull); + } + + @Test + public void testDateScale5_Null() throws Exception { + dropTables(stmt); + + String[] dateSetObjectNull = {"null", "null", "null", "null", "null", "null"}; + + createDatePrecisionTable(5); + populateDateNormalCaseNull(5); + testDate(dateSetObjectNull, dateSetObjectNull); + } + + private void testNumeric(String[] numeric) throws SQLException { + + ResultSet rs = stmt.executeQuery("select * from " + numericTable); + int numberOfColumns = rs.getMetaData().getColumnCount(); + + ArrayList skipMax = new ArrayList<>(); + + while (rs.next()) { + testGetString(rs, numberOfColumns, skipMax, numeric); + testGetBigDecimal(rs, numberOfColumns, numeric); + testGetObject(rs, numberOfColumns, skipMax, numeric); + } + + if (null != rs) { + rs.close(); + } + } + + private void testDate(String[] dateNormalCase, + String[] dateSetObject) throws Exception { + + ResultSet rs = stmt.executeQuery("select * from " + dateTable); + int numberOfColumns = rs.getMetaData().getColumnCount(); + + ArrayList skipMax = new ArrayList<>(); + + while (rs.next()) { + testGetString(rs, numberOfColumns, skipMax, dateNormalCase); + testGetObject(rs, numberOfColumns, skipMax, dateSetObject); + testGetDate(rs, numberOfColumns, dateSetObject); + } + + if (null != rs) { + rs.close(); + } + } + + private void testGetString(ResultSet rs, + int numberOfColumns, + ArrayList skipMax, + String[] values) throws SQLException { + int index = 0; + for (int i = 1; i <= numberOfColumns; i = i + 3) { + if (skipMax.contains(i)) { + continue; + } + + String stringValue1 = "" + rs.getString(i); + String stringValue2 = "" + rs.getString(i + 1); + String stringValue3 = "" + rs.getString(i + 2); + + try { + if (rs.getMetaData().getColumnTypeName(i).equalsIgnoreCase("time")) { + assertTrue(stringValue2.equalsIgnoreCase("" + values[index]) && stringValue3.equalsIgnoreCase("" + values[index]), + "\nDecryption failed with getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 + + ".\nExpected Value: " + values[index]); + } + else { + assertTrue( + values[index].contains(stringValue1) && stringValue2.equalsIgnoreCase("" + values[index]) + && stringValue3.equalsIgnoreCase("" + values[index]), + "\nDecryption failed with getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 + + ".\nExpected Value: " + values[index]); + } + } + finally { + index++; + } + } + } + + private void testGetBigDecimal(ResultSet rs, + int numberOfColumns, + String[] values) throws SQLException { + int index = 0; + for (int i = 1; i <= numberOfColumns; i = i + 3) { + + String decimalValue1 = "" + rs.getBigDecimal(i); + String decimalValue2 = "" + rs.getBigDecimal(i + 1); + String decimalValue3 = "" + rs.getBigDecimal(i + 2); + + try { + assertTrue( + decimalValue1.equalsIgnoreCase(values[index]) && decimalValue2.equalsIgnoreCase(values[index]) + && decimalValue3.equalsIgnoreCase(values[index]), + "Decryption failed with getBigDecimal(): " + decimalValue1 + ", " + decimalValue2 + ", " + decimalValue3 + + "\nExpected value: " + values[index]); + + } + finally { + index++; + } + } + } + + private void testGetObject(ResultSet rs, + int numberOfColumns, + ArrayList skipMax, + String[] values) throws SQLException { + int index = 0; + for (int i = 1; i <= numberOfColumns; i = i + 3) { + if (skipMax.contains(i)) { + continue; + } + + try { + String objectValue1 = "" + rs.getObject(i); + String objectValue2 = "" + rs.getObject(i + 1); + String objectValue3 = "" + rs.getObject(i + 2); + + assertTrue( + objectValue1.equalsIgnoreCase(values[index]) && objectValue2.equalsIgnoreCase(values[index]) + && objectValue3.equalsIgnoreCase(values[index]), + "Decryption failed with getObject(): " + objectValue1 + ", " + objectValue2 + ", " + objectValue3 + "\nExpected value: " + + values[index]); + + } + finally { + index++; + } + } + } + + private void testGetDate(ResultSet rs, + int numberOfColumns, + String[] dates) throws Exception { + int index = 0; + for (int i = 1; i <= numberOfColumns; i = i + 3) { + + if (rs instanceof SQLServerResultSet) { + + String stringValue1 = null; + String stringValue2 = null; + String stringValue3 = null; + + switch (i) { + + case 1: + stringValue1 = "" + ((SQLServerResultSet) rs).getTimestamp(i); + stringValue2 = "" + ((SQLServerResultSet) rs).getTimestamp(i + 1); + stringValue3 = "" + ((SQLServerResultSet) rs).getTimestamp(i + 2); + break; + + case 4: + stringValue1 = "" + ((SQLServerResultSet) rs).getTimestamp(i); + stringValue2 = "" + ((SQLServerResultSet) rs).getTimestamp(i + 1); + stringValue3 = "" + ((SQLServerResultSet) rs).getTimestamp(i + 2); + break; + + case 7: + stringValue1 = "" + ((SQLServerResultSet) rs).getDateTimeOffset(i); + stringValue2 = "" + ((SQLServerResultSet) rs).getDateTimeOffset(i + 1); + stringValue3 = "" + ((SQLServerResultSet) rs).getDateTimeOffset(i + 2); + break; + + case 10: + stringValue1 = "" + ((SQLServerResultSet) rs).getTime(i); + stringValue2 = "" + ((SQLServerResultSet) rs).getTime(i + 1); + stringValue3 = "" + ((SQLServerResultSet) rs).getTime(i + 2); + break; + + case 13: + stringValue1 = "" + ((SQLServerResultSet) rs).getTime(i); + stringValue2 = "" + ((SQLServerResultSet) rs).getTime(i + 1); + stringValue3 = "" + ((SQLServerResultSet) rs).getTime(i + 2); + break; + + case 16: + stringValue1 = "" + ((SQLServerResultSet) rs).getDateTimeOffset(i); + stringValue2 = "" + ((SQLServerResultSet) rs).getDateTimeOffset(i + 1); + stringValue3 = "" + ((SQLServerResultSet) rs).getDateTimeOffset(i + 2); + break; + + default: + fail("Switch case is not matched with data"); + } + + try { + assertTrue( + stringValue1.equalsIgnoreCase(dates[index]) && stringValue2.equalsIgnoreCase(dates[index]) + && stringValue3.equalsIgnoreCase(dates[index]), + "Decryption failed with getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 + "\nExpected value: " + + dates[index]); + } + finally { + index++; + } + } + + else { + throw new Exception("Result set is not instance of SQLServerResultSet"); + } + } + } + + private void populateDateNormalCase(int scale) throws SQLException { + String sql = "insert into " + dateTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); + + // datetime2(5) + for (int i = 1; i <= 3; i++) { + pstmt.setTimestamp(i, new Timestamp(date.getTime()), scale); + } + + // datetime2 default + for (int i = 4; i <= 6; i++) { + pstmt.setTimestamp(i, new Timestamp(date.getTime())); + } + + // datetimeoffset default + for (int i = 7; i <= 9; i++) { + pstmt.setDateTimeOffset(i, microsoft.sql.DateTimeOffset.valueOf(new Timestamp(date.getTime()), 1)); + } + + // time default + for (int i = 10; i <= 12; i++) { + pstmt.setTime(i, new Time(date.getTime())); + } + + // time(3) + for (int i = 13; i <= 15; i++) { + pstmt.setTime(i, new Time(date.getTime()), scale); + } + + // datetimeoffset(2) + for (int i = 16; i <= 18; i++) { + pstmt.setDateTimeOffset(i, microsoft.sql.DateTimeOffset.valueOf(new Timestamp(date.getTime()), 1), scale); + } + + pstmt.execute(); + Util.close(null, pstmt, null); + } + + private void populateDateNormalCaseNull(int scale) throws SQLException { + String sql = "insert into " + dateTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); + + // datetime2(5) + for (int i = 1; i <= 3; i++) { + pstmt.setTimestamp(i, null, scale); + } + + // datetime2 default + for (int i = 4; i <= 6; i++) { + pstmt.setTimestamp(i, null); + } + + // datetimeoffset default + for (int i = 7; i <= 9; i++) { + pstmt.setDateTimeOffset(i, null); + } + + // time default + for (int i = 10; i <= 12; i++) { + pstmt.setTime(i, null); + } + + // time(3) + for (int i = 13; i <= 15; i++) { + pstmt.setTime(i, null, scale); + } + + // datetimeoffset(2) + for (int i = 16; i <= 18; i++) { + pstmt.setDateTimeOffset(i, null, scale); + } + + pstmt.execute(); + Util.close(null, pstmt, null); + } + + private void populateNumericNormalCase(String[] numeric, + int precision, + int scale) throws SQLException { + String sql = "insert into " + numericTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); + + // float(30) + for (int i = 1; i <= 3; i++) { + pstmt.setDouble(i, Double.valueOf(numeric[0])); + } + + // decimal(10,5) + for (int i = 4; i <= 6; i++) { + pstmt.setBigDecimal(i, new BigDecimal(numeric[1]), precision, scale); + } + + // numeric(8,2) + for (int i = 7; i <= 9; i++) { + pstmt.setBigDecimal(i, new BigDecimal(numeric[2]), precision, scale); + } + + pstmt.execute(); + Util.close(null, pstmt, null); + } + + private void populateNumericSetObject(String[] numeric, + int precision, + int scale) throws SQLException { + String sql = "insert into " + numericTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); + + // float(30) + for (int i = 1; i <= 3; i++) { + pstmt.setObject(i, Double.valueOf(numeric[0])); + + } + + // decimal(10,5) + for (int i = 4; i <= 6; i++) { + pstmt.setObject(i, new BigDecimal(numeric[1]), java.sql.Types.DECIMAL, precision, scale); + } + + // numeric(8,2) + for (int i = 7; i <= 9; i++) { + pstmt.setObject(i, new BigDecimal(numeric[2]), java.sql.Types.NUMERIC, precision, scale); + } + + pstmt.execute(); + Util.close(null, pstmt, null); + } + + private void populateNumericSetObjectNull(int precision, + int scale) throws SQLException { + String sql = "insert into " + numericTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); + + // float(30) + for (int i = 1; i <= 3; i++) { + pstmt.setObject(i, null, java.sql.Types.DOUBLE); + + } + + // decimal(10,5) + for (int i = 4; i <= 6; i++) { + pstmt.setObject(i, null, java.sql.Types.DECIMAL, precision, scale); + } + + // numeric(8,2) + for (int i = 7; i <= 9; i++) { + pstmt.setObject(i, null, java.sql.Types.NUMERIC, precision, scale); + } + + pstmt.execute(); + Util.close(null, pstmt, null); + } + + private void populateDateSetObject(int scale) throws SQLException { + String sql = "insert into " + dateTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); + + // datetime2(5) + for (int i = 1; i <= 3; i++) { + pstmt.setObject(i, new Timestamp(date.getTime()), java.sql.Types.TIMESTAMP, scale); + } + + // datetime2 default + for (int i = 4; i <= 6; i++) { + pstmt.setObject(i, new Timestamp(date.getTime()), java.sql.Types.TIMESTAMP); + } + + // datetimeoffset default + for (int i = 7; i <= 9; i++) { + pstmt.setObject(i, microsoft.sql.DateTimeOffset.valueOf(new Timestamp(date.getTime()), 1), microsoft.sql.Types.DATETIMEOFFSET); + } + + // time default + for (int i = 10; i <= 12; i++) { + pstmt.setObject(i, new Time(date.getTime()), java.sql.Types.TIME); + } + + // time(3) + for (int i = 13; i <= 15; i++) { + pstmt.setObject(i, new Time(date.getTime()), java.sql.Types.TIME, scale); + } + + // datetimeoffset(2) + for (int i = 16; i <= 18; i++) { + pstmt.setObject(i, microsoft.sql.DateTimeOffset.valueOf(new Timestamp(date.getTime()), 1), microsoft.sql.Types.DATETIMEOFFSET, scale); + } + + pstmt.execute(); + Util.close(null, pstmt, null); + } + + private void populateDateSetObjectNull(int scale) throws SQLException { + String sql = "insert into " + dateTable + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting); + + // datetime2(5) + for (int i = 1; i <= 3; i++) { + pstmt.setObject(i, null, java.sql.Types.TIMESTAMP, scale); + } + + // datetime2 default + for (int i = 4; i <= 6; i++) { + pstmt.setObject(i, null, java.sql.Types.TIMESTAMP); + } + + // datetimeoffset default + for (int i = 7; i <= 9; i++) { + pstmt.setObject(i, null, microsoft.sql.Types.DATETIMEOFFSET); + } + + // time default + for (int i = 10; i <= 12; i++) { + pstmt.setObject(i, null, java.sql.Types.TIME); + } + + // time(3) + for (int i = 13; i <= 15; i++) { + pstmt.setObject(i, null, java.sql.Types.TIME, scale); + } + + // datetimeoffset(2) + for (int i = 16; i <= 18; i++) { + pstmt.setObject(i, null, microsoft.sql.Types.DATETIMEOFFSET, scale); + } + + pstmt.execute(); + Util.close(null, pstmt, null); + } +} diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/RandomData.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/RandomData.java deleted file mode 100644 index 074dbe9c1..000000000 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/RandomData.java +++ /dev/null @@ -1,651 +0,0 @@ -package com.microsoft.sqlserver.jdbc.datatypes; - -import java.math.BigDecimal; -import java.math.BigInteger; -import java.sql.Date; -import java.sql.Time; -import java.sql.Timestamp; -import java.util.Calendar; -import java.util.Random; - -import microsoft.sql.DateTimeOffset; - -public class RandomData { - - private static Random r = new Random(); - - public static boolean returnNull = (0 == r.nextInt(5)); //20% chance of return null - public static boolean returnFullLength = (0 == r.nextInt(2)); //50% chance of return full length for char/nchar and binary types - public static boolean returnMinMax = (0 == r.nextInt(5)); //20% chance of return Min/Max value - public static boolean returnZero = (0 == r.nextInt(10)); //10% chance of return zero - - private static String specicalCharSet = "ÀÂÃÄËßîðÐ"; - private static String normalCharSet = "1234567890-=!@#$%^&*()_+qwertyuiop[]\\asdfghjkl;'zxcvbnm,./QWERTYUIOP{}|ASDFGHJKL:\"ZXCVBNM<>?"; - - private static String unicodeCharSet = "♠♣♥♦林花謝了春紅太匆匆無奈朝我附件为放假哇额外放我放问역사적으로본래한민족의영역은만주와연해주의일부를포함하였으나会和太空特工我來寒雨晚來風胭脂淚留人醉幾時重自是人生長恨水長東ྱོགས་སུ་འཁོར་བའི་ས་ཟླུུམ་ཞིག་ལ་ངོས་འཛིན་དགོས་ཏེ།ངག་ཕྱོαβγδεζηθικλμνξοπρστυφχψ太陽系の年齢もまた隕石の年代測定に依拠するので"; - private static String numberCharSet = "1234567890"; - private static String numberCharSet2 = "123456789"; - - //-------------------numeric types-------------------------------------------- - - public static Boolean generateBoolean(boolean nullable){ - if(nullable){ - if(returnNull){ - return null; - } - } - - return r.nextBoolean(); - } - - public static Integer generateInt(boolean nullable){ - if(nullable){ - if(returnNull){ - return null; - } - } - - if(returnZero){ - return 0; - } - - if(returnMinMax){ - if(r.nextBoolean()){ - return 2147483647; - } - else{ - return -2147483648; - } - } - - //can be either negative or positive - return r.nextInt(); - } - - public static Long generateLong(boolean nullable){ - if(nullable){ - if(returnNull){ - return null; - } - } - - if(returnZero){ - return 0L; - } - - if(returnMinMax){ - if(r.nextBoolean()){ - return 9223372036854775807L; - } - else{ - return -9223372036854775808L; - } - } - - //can be either negative or positive - return r.nextLong(); - } - - public static Short generateTinyint(boolean nullable){ - Integer value = pickInt(nullable, 255, 0); - - if(null != value){ - return value.shortValue(); - } - else{ - return null; - } - } - - public static Short generateSmallint(boolean nullable){ - Integer value = pickInt(nullable, 32767, -32768); - - if(null != value){ - return value.shortValue(); - } - else{ - return null; - } - } - - private static Integer pickInt(boolean nullable, int max, int min){ - if(nullable){ - if(returnNull){ - return null; - } - } - - if(returnZero){ - return 0; - } - - if(returnMinMax){ - if(r.nextBoolean()){ - return max; - } - else{ - return min; - } - } - - return (int) r.nextInt(max - min) + min; - } - - public static BigDecimal generateDecimalNumeric(int precision, int scale, boolean nullable){ - - if(nullable){ - if(returnNull){ - return null; - } - } - - if(returnZero){ - return BigDecimal.ZERO.setScale(scale); - - } - - if(returnMinMax){ - BigInteger n ; - if(r.nextBoolean()){ - n = BigInteger.TEN.pow(precision); - if(scale>0) - return new BigDecimal(n, scale).subtract(new BigDecimal(""+Math.pow(10, -scale)).setScale(scale, BigDecimal.ROUND_HALF_UP)).negate(); - else - return new BigDecimal(n, scale).subtract(new BigDecimal("1")).negate(); - } - else{ - n = BigInteger.TEN.pow(precision); - if(scale>0) - return new BigDecimal(n, scale).subtract(new BigDecimal(""+Math.pow(10, -scale)).setScale(scale, BigDecimal.ROUND_HALF_UP)).negate(); - else - return new BigDecimal(n, scale).subtract(new BigDecimal("1")).negate(); - - } - - } - BigInteger n = BigInteger.TEN.pow(precision); - if(r.nextBoolean()) { - return new BigDecimal(newRandomBigInteger(n, r, precision), scale); - } - return (new BigDecimal(newRandomBigInteger(n, r, precision), scale).negate()); - - } - private static BigInteger newRandomBigInteger(BigInteger n, Random rnd, int precision) { - BigInteger r; - do { - r = new BigInteger(n.bitLength(), rnd); - } while (r.toString().length() != precision); - - return r; - } - - public static Float generateReal(boolean nullable){ - Double doubleValue = generateFloat(24, nullable); - - if(null != doubleValue){ - return doubleValue.floatValue(); - } - else{ - return null; - } - } - - public static Double generateFloat(Integer n, boolean nullable){ - if(nullable){ - if(returnNull){ - return null; - } - } - - if(returnZero){ - return new Double(0); - } - - //only 2 options: 24 or 53 - //The default value of n is 53. If 1<=n<=24, n is treated as 24. If 25<=n<=53, n is treated as 53. - //https://msdn.microsoft.com/en-us/library/ms173773.aspx - if(null == n){ - n = 53; - } - else if(25 <= n && 53 >= n){ - n = 53; - } - else{ - n = 24; - } - - if(returnMinMax){ - if(53 == n){ - if(r.nextBoolean()){ - if(r.nextBoolean()){ - return Double.valueOf("1.79E+308"); - } - else{ - return Double.valueOf("2.23E-308"); - } - } - else{ - if(r.nextBoolean()){ - return Double.valueOf("-2.23E-308"); - } - else{ - return Double.valueOf("-1.79E+308"); - } - } - } - else{ - if(r.nextBoolean()){ - if(r.nextBoolean()){ - return Double.valueOf("3.40E+38"); - } - else{ - return Double.valueOf("1.18E-38"); - } - } - else{ - if(r.nextBoolean()){ - return Double.valueOf("-1.18E-38"); - } - else{ - return Double.valueOf("-3.40E+38"); - } - } - } - } - - String intPart = "" + r.nextInt(10); - - //generate n bits of binary data and convert to long, then use the long as decimal part - StringBuffer sb = new StringBuffer(); - for(int i = 0; i < n; i++){ - sb.append(r.nextInt(2)); - } - long longValue = Long.parseLong(sb.toString(), 2); - String stringValue = intPart + "." + longValue; - - return Double.valueOf(stringValue); - } - - public static BigDecimal generateMoney(boolean nullable){ - String charSet = numberCharSet; - BigDecimal max = new BigDecimal("922337203685477.5807"); - BigDecimal min = new BigDecimal("-922337203685477.5808"); - float multiplier = 10000; - return generateMoneyOrSmallMoney(nullable, max, min, multiplier, charSet); - } - - public static BigDecimal generateSmallMoney(boolean nullable){ - String charSet = numberCharSet; - BigDecimal max = new BigDecimal("214748.3647"); - BigDecimal min = new BigDecimal("-214748.3648"); - float multiplier = (float) (1.0/10000.0); - return generateMoneyOrSmallMoney(nullable, max, min, multiplier, charSet); - } - - private static BigDecimal generateMoneyOrSmallMoney(boolean nullable, BigDecimal max, BigDecimal min, float multiplier, String charSet){ - if(nullable){ - if(returnNull){ - return null; - } - } - - if(returnZero){ - return BigDecimal.ZERO.setScale(4); - } - - if(returnMinMax){ - if(r.nextBoolean()){ - return max; - } - else{ - return min; - } - } - - long intPart = (long)(r.nextInt() * multiplier); - - StringBuffer sb = new StringBuffer(); - for(int i = 0; i < 4; i++){ - char c = pickRandomChar(charSet); - sb.append(c); - } - - return new BigDecimal(intPart + "." + sb.toString()); - } - - - //----------------Char NChar types------------------------------------------ - - public static String generateCharTypes(String columnLength, boolean nullable, boolean encrypted){ - String charSet = normalCharSet; - - return buildCharOrNChar(columnLength, nullable, encrypted, charSet, 8001); - } - - public static String generateNCharTypes(String columnLength, boolean nullable, boolean encrypted){ - String charSet = specicalCharSet + normalCharSet + unicodeCharSet; - - return buildCharOrNChar(columnLength, nullable, encrypted, charSet, 4001); - } - - private static String buildCharOrNChar(String columnLength, boolean nullable, boolean encrypted, String charSet, int maxBound){ - - if(nullable){ - if(returnNull){ - return null; - } - } - - //if column is encrypted, string value cannot be "", not supported. - int minimumLength = 0; - if(encrypted){ - minimumLength = 1; - } - - int length; - if(columnLength.toLowerCase().equals("max")){ - //50% chance of return value longer than 8000/4000 - if(r.nextBoolean()){ - length = r.nextInt(100000) + maxBound; - return buildRandomString(length, charSet); - } - else{ - length = r.nextInt(maxBound - minimumLength) + minimumLength; - return buildRandomString(length, charSet); - } - } - else{ - int columnLengthInt = Integer.parseInt(columnLength); - if(returnFullLength){ - length = columnLengthInt; - return buildRandomString(length, charSet); - } - else{ - length = r.nextInt(columnLengthInt - minimumLength) + minimumLength; - return buildRandomString(length, charSet); - } - } - } - - private static String buildRandomString(int length, String charSet){ - StringBuffer sb = new StringBuffer(); - for(int i = 0; i < length; i++){ - char c = pickRandomChar(charSet); - sb.append(c); - } - - return sb.toString(); - } - - private static char pickRandomChar(String charSet){ - int charSetLength = charSet.length(); - - int randomIndex = r.nextInt(charSetLength); - return charSet.charAt(randomIndex); - } - - - //-----------------------Binary types-------------------------- - - public static byte[] generateBinaryTypes(String columnLength, boolean nullable, boolean encrypted){ - int maxBound = 8001; - - if(nullable){ - if(returnNull){ - return null; - } - } - - //if column is encrypted, string value cannot be "", not supported. - int minimumLength = 0; - if(encrypted){ - minimumLength = 1; - } - - int length; - if(columnLength.toLowerCase().equals("max")){ - //50% chance of return value longer than 8000/4000 - if(r.nextBoolean()){ - length = r.nextInt(100000) + maxBound; - byte[] bytes = new byte[length]; - r.nextBytes(bytes); - return bytes; - } - else{ - length = r.nextInt(maxBound - minimumLength) + minimumLength; - byte[] bytes = new byte[length]; - r.nextBytes(bytes); - return bytes; - } - } - else{ - int columnLengthInt = Integer.parseInt(columnLength); - if(returnFullLength){ - length = columnLengthInt; - byte[] bytes = new byte[length]; - r.nextBytes(bytes); - return bytes; - } - else{ - length = r.nextInt(columnLengthInt - minimumLength) + minimumLength; - byte[] bytes = new byte[length]; - r.nextBytes(bytes); - return bytes; - } - } - } - - - - //-----------------------Temporal types-------------------------- - - public static Date generateDate(boolean nullable){ - if(nullable){ - if(returnNull){ - return null; - } - } - - long max = Timestamp.valueOf("9999-12-31 00:00:00.000").getTime(); - long min = Timestamp.valueOf("0001-01-01 00:00:00.000").getTime(); - - if(returnMinMax){ - if(r.nextBoolean()){ - return new Date(max); - } - else{ - return new Date(min); - } - } - - while(true){ - long longValue = r.nextLong(); - - if(longValue >= min && longValue <= max){ - return new Date(longValue); - } - } - } - - public static Timestamp generateDatetime(boolean nullable){ - long max = Timestamp.valueOf("9999-12-31 23:59:59.997").getTime(); - long min = Timestamp.valueOf("1753-01-01 00:00:00.000").getTime(); - - return generateTimestamp(nullable, max, min); - } - - public static Timestamp generateSmalldatetime(boolean nullable){ - long max = Timestamp.valueOf("2079-06-06 23:59:00").getTime(); - long min = Timestamp.valueOf("1900-01-01 00:00:00").getTime(); - - return generateTimestamp(nullable, max, min); - } - - public static Timestamp generateDatetime2(Integer precision, boolean nullable){ - if(null == precision){ - precision = 7; - } - - long max = Timestamp.valueOf("9999-12-31 23:59:59").getTime(); - long min = Timestamp.valueOf("0001-01-01 00:00:00").getTime(); - - Timestamp ts = generateTimestamp(nullable, max, min); - - if(null == ts){ - return ts; - } - - if(returnMinMax){ - if(ts.getTime() == max){ - int precisionDigits = buildPrecision(precision, "9"); - ts.setNanos(precisionDigits); - return ts; - } - else{ - ts.setNanos(0); - return ts; - } - } - - int precisionDigits = buildPrecision(precision, numberCharSet2); //not to use 0 in the random data for now. E.g creates 9040330 and when set it is 904033. - ts.setNanos(precisionDigits); - return ts; - } - - public static Time generateTime(Integer precision, boolean nullable){ - if(null == precision){ - precision = 7; - } - - long max = Timestamp.valueOf("9999-12-31 23:59:59").getTime(); - long min = Timestamp.valueOf("0001-01-01 00:00:00").getTime(); - - Timestamp ts = generateTimestamp(nullable, max, min); - - if(null == ts){ - return null; - } - - if(returnMinMax){ - if(ts.getTime() == max){ - int precisionDigits = buildPrecision(precision, "9"); - ts.setNanos(precisionDigits); - return new Time(ts.getTime()); - } - else{ - ts.setNanos(0); - return new Time(ts.getTime()); - } - } - - int precisionDigits = buildPrecision(precision, numberCharSet); - ts.setNanos(precisionDigits); - return new Time(ts.getTime()); - } - - private static int buildPrecision(int precision, String charSet){ - String stringValue = calculatePrecisionDigits(precision, charSet); - return Integer.parseInt(stringValue); - } - - //setNanos(999999900) gives 00:00:00.9999999 - //so, this value has to be 9 digits - private static String calculatePrecisionDigits(int precision, String charSet){ - StringBuffer sb = new StringBuffer(); - for(int i = 0; i < precision; i++){ - char c = pickRandomChar(charSet); - sb.append(c); - } - - for(int i = sb.length(); i < 9; i++){ - sb.append("0"); - } - - return sb.toString(); - } - - private static Timestamp generateTimestamp(boolean nullable, long max, long min){ - if(nullable){ - if(returnNull){ - return null; - } - } - - if(returnMinMax){ - if(r.nextBoolean()){ - return new Timestamp(max); - } - else{ - return new Timestamp(min); - } - } - - while(true){ - long longValue = r.nextLong(); - - if(longValue >= min && longValue <= max){ - return new Timestamp(longValue); - } - } - } - - public static DateTimeOffset generateDatetimeoffset(Integer precision, boolean nullable){ - if(null == precision){ - precision = 7; - } - - DateTimeOffset maxDTS = calculateDateTimeOffsetMinMax("max", precision, "9999-12-31 23:59:59"); - DateTimeOffset minDTS = calculateDateTimeOffsetMinMax("min", precision, "0001-01-01 00:00:00"); - - long max = maxDTS.getTimestamp().getTime(); - long min = minDTS.getTimestamp().getTime(); - - Timestamp ts = generateTimestamp(nullable, max, min); - - if(null == ts){ - return null; - } - - if(returnMinMax){ - if(r.nextBoolean()){ - return maxDTS; - } - else{ - //return minDTS; - return calculateDateTimeOffsetMinMax("min", precision, "0001-01-01 00:00:00.0000000"); - } - } - - int precisionDigits = buildPrecision(precision, numberCharSet2); - ts.setNanos(precisionDigits); - - int randomTimeZoneInMinutes = r.nextInt(1681) - 840; - - return microsoft.sql.DateTimeOffset.valueOf(ts, randomTimeZoneInMinutes); - } - - private static DateTimeOffset calculateDateTimeOffsetMinMax(String maxOrMin, Integer precision, String tsMinMax){ - int providedTimeZoneInMinutes; - if(maxOrMin.toLowerCase().equals("max")){ - providedTimeZoneInMinutes = 840; - } - else{ - providedTimeZoneInMinutes = -840; - } - - Timestamp tsMax = Timestamp.valueOf(tsMinMax); - - Calendar cal = Calendar.getInstance(); - long offset = cal.get(Calendar.ZONE_OFFSET); //in milliseconds - - //max Timestamp + difference of current time zone and GMT - provided time zone in milliseconds - tsMax = new Timestamp(tsMax.getTime() + offset - (providedTimeZoneInMinutes * 60 * 1000)); - - if(maxOrMin.toLowerCase().equals("max")){ - int precisionDigits = buildPrecision(precision, "9"); - tsMax.setNanos(precisionDigits); - } - - return microsoft.sql.DateTimeOffset.valueOf(tsMax, providedTimeZoneInMinutes); - } -} diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java index fe5a6c339..bf14063a2 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java @@ -31,6 +31,7 @@ import com.microsoft.sqlserver.jdbc.SQLServerResultSet; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.Utils; +import com.microsoft.sqlserver.testframework.util.RandomData; /** * Tests for supporting sqlVariant diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/TVPWithSqlVariantTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/TVPWithSqlVariantTest.java index 23e0d18de..cd318ac67 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/TVPWithSqlVariantTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/TVPWithSqlVariantTest.java @@ -34,6 +34,7 @@ import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.Utils; import com.microsoft.sqlserver.testframework.sqlType.SqlDate; +import com.microsoft.sqlserver.testframework.util.RandomData; @RunWith(JUnitPlatform.class) public class TVPWithSqlVariantTest extends AbstractTest { From cf9ae2ec282b5f456fec07a0b43c9112962c20f1 Mon Sep 17 00:00:00 2001 From: Peter Bae Date: Thu, 3 Aug 2017 09:23:22 -0700 Subject: [PATCH 2/5] Fix timezone issues with testing --- .../sqlserver/jdbc/AlwaysEncrypted/AESetup.java | 10 +++++----- .../jdbc/AlwaysEncrypted/PrecisionScaleTest.java | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java index 5b4058ed5..6fc795a98 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java @@ -62,11 +62,11 @@ public class AESetup extends AbstractTest { static final String cmkName = "JDBC_CMK"; static final String cekName = "JDBC_CEK"; static final String secretstrJks = "password"; - static final String charTable = "JDBCEncrpytedCharTable"; - static final String binaryTable = "JDBCEncrpytedBinaryTable"; - static final String dateTable = "JDBCEncrpytedDateTable"; - static final String numericTable = "JDBCEncrpytedNumericTable"; - static final String scaleDateTable = "JDBCEncrpytedScaleDateTable"; + static final String charTable = "JDBCEncryptedCharTable"; + static final String binaryTable = "JDBCEncryptedBinaryTable"; + static final String dateTable = "JDBCEncryptedDateTable"; + static final String numericTable = "JDBCEncryptedNumericTable"; + static final String scaleDateTable = "JDBCEncryptedScaleDateTable"; static final String uid = "171fbe25-4331-4765-a838-b2e3eea3e7ea"; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java index 4a53e88fd..1f78a4c8f 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java @@ -11,12 +11,14 @@ import static org.junit.jupiter.api.Assertions.fail; import java.math.BigDecimal; -import java.sql.Date; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Time; import java.sql.Timestamp; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; +import java.util.TimeZone; import org.junit.jupiter.api.Test; @@ -27,7 +29,17 @@ public class PrecisionScaleTest extends AESetup { private static SQLServerPreparedStatement pstmt = null; - private static java.util.Date date = new Date(1450812362177L); + private static java.util.Date date = null; + + static { + TimeZone tz = TimeZone.getDefault(); + int offsetFromGMT = tz.getOffset(1450812362177L); + // since the Date object already accounts for timezone, subtracting the timezone difference will give us the + // GMT version of the Date object. + // Then we will subtract another 8 hours from it to make it PST. This will allow us to preserve our test data as it was + // and the test will work regardless of timezone. + date = new Date(1450812362177L - offsetFromGMT - 28800000); + } @Test public void testNumericPrecision8Scale2() throws Exception { From b0aa7fa5d33efb994e34d692647c9770a02d3d34 Mon Sep 17 00:00:00 2001 From: Peter Bae Date: Thu, 3 Aug 2017 10:41:13 -0700 Subject: [PATCH 3/5] Fix more issues with timezone --- .../AlwaysEncrypted/PrecisionScaleTest.java | 40 ++++++++++++------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java index 1f78a4c8f..4bc194687 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java @@ -30,15 +30,27 @@ public class PrecisionScaleTest extends AESetup { private static SQLServerPreparedStatement pstmt = null; private static java.util.Date date = null; + private static int offsetFromGMT = 0; + private static int offset = 60000; + private static String GMTDate = ""; + private static String GMTDateWithoutDate = ""; + private static String dateTimeOffsetExpectedValue = ""; static { TimeZone tz = TimeZone.getDefault(); - int offsetFromGMT = tz.getOffset(1450812362177L); - // since the Date object already accounts for timezone, subtracting the timezone difference will give us the - // GMT version of the Date object. - // Then we will subtract another 8 hours from it to make it PST. This will allow us to preserve our test data as it was - // and the test will work regardless of timezone. - date = new Date(1450812362177L - offsetFromGMT - 28800000); + offsetFromGMT = tz.getOffset(1450812362177L); + + // since the Date object already accounts for timezone, subtracting the timezone difference will always give us the + // GMT version of the Date object. I can't make this PST because there are datetimeoffset tests, so I have to use GMT. + date = new Date(1450812362177L - offsetFromGMT); + + // Cannot use date.toGMTString() here directly since the date object is used elsewhere for population of data. + GMTDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date); + GMTDateWithoutDate = new SimpleDateFormat("HH:mm:ss").format(date); + + // datetimeoffset is aware of timezone as well as Date, so we must apply the timezone value twice. + dateTimeOffsetExpectedValue = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") + .format(new Date(1450812362177L - offsetFromGMT - offsetFromGMT + offset)); } @Test @@ -58,10 +70,10 @@ public void testNumericPrecision8Scale2() throws Exception { public void testDateScale2() throws Exception { dropTables(stmt); - String[] dateNormalCase = {"2015-12-22 11:26:02.18", "2015-12-22 11:26:02.1770000", "2015-12-22 19:27:02.1770000 +00:01", "11:26:02.1770000", - "11:26:02.18", "2015-12-22 19:27:02.18 +00:01"}; - String[] dateSetObject = {"2015-12-22 11:26:02.18", "2015-12-22 11:26:02.177", "2015-12-22 19:27:02.177 +00:01", "11:26:02", "11:26:02", - "2015-12-22 19:27:02.18 +00:01"}; + String[] dateNormalCase = {GMTDate + ".18", GMTDate + ".1770000", dateTimeOffsetExpectedValue + ".1770000 +00:01", + GMTDateWithoutDate + ".1770000", GMTDateWithoutDate + ".18", dateTimeOffsetExpectedValue + ".18 +00:01"}; + String[] dateSetObject = {GMTDate + ".18", GMTDate + ".177", dateTimeOffsetExpectedValue + ".177 +00:01", GMTDateWithoutDate, + GMTDateWithoutDate, dateTimeOffsetExpectedValue + ".18 +00:01"}; createDatePrecisionTable(2); populateDateNormalCase(2); @@ -87,10 +99,10 @@ public void testNumericPrecision8Scale0() throws Exception { public void testDateScale0() throws Exception { dropTables(stmt); - String[] dateNormalCase2 = {"2015-12-22 11:26:02", "2015-12-22 11:26:02.1770000", "2015-12-22 19:27:02.1770000 +00:01", "11:26:02.1770000", - "11:26:02", "2015-12-22 19:27:02 +00:01"}; - String[] dateSetObject2 = {"2015-12-22 11:26:02.0", "2015-12-22 11:26:02.177", "2015-12-22 19:27:02.177 +00:01", "11:26:02", "11:26:02", - "2015-12-22 19:27:02 +00:01"}; + String[] dateNormalCase2 = {GMTDate, GMTDate + ".1770000", dateTimeOffsetExpectedValue + ".1770000 +00:01", GMTDateWithoutDate + ".1770000", + GMTDateWithoutDate, dateTimeOffsetExpectedValue + " +00:01"}; + String[] dateSetObject2 = {GMTDate + ".0", GMTDate + ".177", dateTimeOffsetExpectedValue + ".177 +00:01", GMTDateWithoutDate, + GMTDateWithoutDate, dateTimeOffsetExpectedValue + " +00:01"}; createDatePrecisionTable(0); populateDateNormalCase(0); From ddde6920f298fc1052827b545f711b7668b6e685 Mon Sep 17 00:00:00 2001 From: Peter Bae Date: Tue, 8 Aug 2017 11:09:07 -0700 Subject: [PATCH 4/5] Add javadoc/fix issues --- .../CallableStatementTest.java | 37 ++++++++++++------- .../JDBCEncryptionDecryptionTest.java | 9 ----- .../AlwaysEncrypted/PrecisionScaleTest.java | 11 +++++- .../testframework/util/RandomData.java | 1 - 4 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java index b9bdcce26..9c23e98c1 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java @@ -1,3 +1,10 @@ +/* + * Microsoft JDBC Driver for SQL Server + * + * Copyright(c) Microsoft Corporation All rights reserved. + * + * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information. + */ package com.microsoft.sqlserver.jdbc.AlwaysEncrypted; import static org.junit.jupiter.api.Assertions.fail; @@ -12,7 +19,6 @@ import java.math.BigDecimal; import java.sql.Date; -import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Time; @@ -20,16 +26,19 @@ import java.util.LinkedList; import com.microsoft.sqlserver.jdbc.SQLServerCallableStatement; -import com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionKeyStoreProvider; import com.microsoft.sqlserver.jdbc.SQLServerException; import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement; import com.microsoft.sqlserver.jdbc.SQLServerResultSet; -import com.microsoft.sqlserver.jdbc.SQLServerStatementColumnEncryptionSetting; +import com.microsoft.sqlserver.testframework.Utils; import com.microsoft.sqlserver.testframework.util.RandomData; import com.microsoft.sqlserver.testframework.util.Util; import microsoft.sql.DateTimeOffset; +/** + * Test cases related to SQLServerCallableStatement. + * + */ @RunWith(JUnitPlatform.class) public class CallableStatementTest extends AESetup { @@ -239,27 +248,27 @@ public void testOutputProcedure4() throws SQLException { } private static void dropTables() throws SQLException { - stmt.executeUpdate("if object_id('" + table1 + "','U') is not null" + " drop table " + table1); + Utils.dropTableIfExists(table1, stmt); - stmt.executeUpdate("if object_id('" + table2 + "','U') is not null" + " drop table " + table2); + Utils.dropTableIfExists(table2, stmt); - stmt.executeUpdate("if object_id('" + table3 + "','U') is not null" + " drop table " + table3); + Utils.dropTableIfExists(table3, stmt); - stmt.executeUpdate("if object_id('" + table4 + "','U') is not null" + " drop table " + table4); + Utils.dropTableIfExists(table4, stmt); - stmt.executeUpdate("if object_id('" + charTable + "','U') is not null" + " drop table " + charTable); + Utils.dropTableIfExists(charTable, stmt); - stmt.executeUpdate("if object_id('" + numericTable + "','U') is not null" + " drop table " + numericTable); + Utils.dropTableIfExists(numericTable, stmt); - stmt.executeUpdate("if object_id('" + binaryTable + "','U') is not null" + " drop table " + binaryTable); + Utils.dropTableIfExists(binaryTable, stmt); - stmt.executeUpdate("if object_id('" + dateTable + "','U') is not null" + " drop table " + dateTable); + Utils.dropTableIfExists(dateTable, stmt); - stmt.executeUpdate("if object_id('" + table5 + "','U') is not null" + " drop table " + table5); + Utils.dropTableIfExists(table5, stmt); - stmt.executeUpdate("if object_id('" + table6 + "','U') is not null" + " drop table " + table6); + Utils.dropTableIfExists(table6, stmt); - stmt.executeUpdate("if object_id('" + scaleDateTable + "','U') is not null" + " drop table " + scaleDateTable); + Utils.dropTableIfExists(scaleDateTable, stmt); } private static void createTables() throws SQLException { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java index 4e47429e9..0c1de2266 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java @@ -10,31 +10,22 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -import java.math.BigDecimal; -import java.sql.Date; -import java.sql.JDBCType; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import java.sql.Time; -import java.sql.Timestamp; import java.util.LinkedList; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; import org.opentest4j.TestAbortedException; -import com.microsoft.sqlserver.jdbc.SQLServerException; import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement; import com.microsoft.sqlserver.jdbc.SQLServerResultSet; import com.microsoft.sqlserver.jdbc.SQLServerStatement; import com.microsoft.sqlserver.testframework.util.RandomData; import com.microsoft.sqlserver.testframework.util.Util; -import microsoft.sql.DateTimeOffset; - /** * Tests Decryption and encryption of values * diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java index 4bc194687..3b0892234 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java @@ -21,17 +21,24 @@ import java.util.TimeZone; import org.junit.jupiter.api.Test; +import org.junit.platform.runner.JUnitPlatform; +import org.junit.runner.RunWith; import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement; import com.microsoft.sqlserver.jdbc.SQLServerResultSet; import com.microsoft.sqlserver.testframework.util.Util; +/** + * Tests datatypes that have precision and/or scale. + * + */ +@RunWith(JUnitPlatform.class) public class PrecisionScaleTest extends AESetup { private static SQLServerPreparedStatement pstmt = null; private static java.util.Date date = null; private static int offsetFromGMT = 0; - private static int offset = 60000; + private static final int offset = 60000; private static String GMTDate = ""; private static String GMTDateWithoutDate = ""; private static String dateTimeOffsetExpectedValue = ""; @@ -112,7 +119,7 @@ public void testDateScale0() throws Exception { } @Test - public void testNumericPrecision8Scale2_Null() throws Exception { + public void testNumericPrecision8Scale2Null() throws Exception { dropTables(stmt); String[] numericNull = {"null", "null", "null"}; diff --git a/src/test/java/com/microsoft/sqlserver/testframework/util/RandomData.java b/src/test/java/com/microsoft/sqlserver/testframework/util/RandomData.java index 139d3a752..21e12991b 100644 --- a/src/test/java/com/microsoft/sqlserver/testframework/util/RandomData.java +++ b/src/test/java/com/microsoft/sqlserver/testframework/util/RandomData.java @@ -3,7 +3,6 @@ import java.math.BigDecimal; import java.math.BigInteger; import java.sql.Date; -import java.sql.SQLException; import java.sql.Time; import java.sql.Timestamp; import java.util.Calendar; From 3f0baf03a4fa7420a981ab874bda18f693290edf Mon Sep 17 00:00:00 2001 From: Peter Bae Date: Tue, 8 Aug 2017 11:42:03 -0700 Subject: [PATCH 5/5] Got rid of all the underscores in method names --- .../AlwaysEncrypted/PrecisionScaleTest.java | 4 +-- .../jdbc/bulkCopy/BulkCopyAllTypes.java | 16 ++++----- .../jdbc/bulkCopy/BulkCopyConnectionTest.java | 16 ++++----- .../microsoft/sqlserver/jdbc/bvt/bvtTest.java | 4 +-- .../sqlserver/jdbc/tvp/TVPAllTypes.java | 34 +++++++++---------- .../sqlserver/jdbc/tvp/TVPIssuesTest.java | 4 +-- .../sqlserver/jdbc/tvp/TVPNumericTest.java | 2 +- .../sqlserver/jdbc/tvp/TVPSchemaTest.java | 16 ++++----- .../sqlserver/jdbc/tvp/TVPTypesTest.java | 12 +++---- .../sqlserver/jdbc/unit/lobs/lobsTest.java | 14 ++++---- .../statement/BatchExecuteWithErrorsTest.java | 2 +- .../jdbc/unit/statement/StatementTest.java | 8 ++--- 12 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java index 3b0892234..23dede74d 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java @@ -131,7 +131,7 @@ public void testNumericPrecision8Scale2Null() throws Exception { } @Test - public void testDateScale2_Null() throws Exception { + public void testDateScale2Null() throws Exception { dropTables(stmt); String[] dateSetObjectNull = {"null", "null", "null", "null", "null", "null"}; @@ -143,7 +143,7 @@ public void testDateScale2_Null() throws Exception { } @Test - public void testDateScale5_Null() throws Exception { + public void testDateScale5Null() throws Exception { dropTables(stmt); String[] dateSetObjectNull = {"null", "null", "null", "null", "null", "null"}; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyAllTypes.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyAllTypes.java index ebc89db63..d97726b27 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyAllTypes.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyAllTypes.java @@ -39,16 +39,16 @@ public class BulkCopyAllTypes extends AbstractTest { * @throws SQLException */ @Test - public void testTVP_ResultSet() throws SQLException { - testBulkCopy_ResultSet(false, null, null); - testBulkCopy_ResultSet(true, null, null); - testBulkCopy_ResultSet(false, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); - testBulkCopy_ResultSet(false, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); - testBulkCopy_ResultSet(false, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); - testBulkCopy_ResultSet(false, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); + public void testTVPResultSet() throws SQLException { + testBulkCopyResultSet(false, null, null); + testBulkCopyResultSet(true, null, null); + testBulkCopyResultSet(false, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + testBulkCopyResultSet(false, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); + testBulkCopyResultSet(false, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); + testBulkCopyResultSet(false, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); } - private void testBulkCopy_ResultSet(boolean setSelectMethod, + private void testBulkCopyResultSet(boolean setSelectMethod, Integer resultSetType, Integer resultSetConcurrency) throws SQLException { setupVariation(); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyConnectionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyConnectionTest.java index 0e2718fe3..b75584ede 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyConnectionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyConnectionTest.java @@ -44,7 +44,7 @@ public class BulkCopyConnectionTest extends BulkCopyTestSetUp { */ @TestFactory Stream generateBulkCopyConstructorTest() { - List testData = createTestData_testBulkCopyConstructor(); + List testData = createTestDatatestBulkCopyConstructor(); // had to avoid using lambdas as we need to test against java7 return testData.stream().map(new Function() { @Override @@ -66,7 +66,7 @@ public void execute() { */ @TestFactory Stream generateBulkCopyOptionsTest() { - List testData = createTestData_testBulkCopyOption(); + List testData = createTestDatatestBulkCopyOption(); return testData.stream().map(new Function() { @Override public DynamicTest apply(final BulkCopyTestWrapper datum) { @@ -85,7 +85,7 @@ public void execute() { */ @Test @DisplayName("BulkCopy:test uninitialized Connection") - void testInvalidConnection_1() { + void testInvalidConnection1() { assertThrows(SQLServerException.class, new org.junit.jupiter.api.function.Executable() { @Override public void execute() throws SQLServerException { @@ -100,7 +100,7 @@ public void execute() throws SQLServerException { */ @Test @DisplayName("BulkCopy:test uninitialized SQLServerConnection") - void testInvalidConnection_2() { + void testInvalidConnection2() { assertThrows(SQLServerException.class, new org.junit.jupiter.api.function.Executable() { @Override public void execute() throws SQLServerException { @@ -115,7 +115,7 @@ public void execute() throws SQLServerException { */ @Test @DisplayName("BulkCopy:test empty connenction string") - void testInvalidConnection_3() { + void testInvalidConnection3() { assertThrows(SQLServerException.class, new org.junit.jupiter.api.function.Executable() { @Override public void execute() throws SQLServerException { @@ -130,7 +130,7 @@ public void execute() throws SQLServerException { */ @Test @DisplayName("BulkCopy:test null connenction string") - void testInvalidConnection_4() { + void testInvalidConnection4() { assertThrows(SQLServerException.class, new org.junit.jupiter.api.function.Executable() { @Override public void execute() throws SQLServerException { @@ -159,7 +159,7 @@ void testEmptyBulkCopyOptions() { * * @return */ - List createTestData_testBulkCopyConstructor() { + List createTestDatatestBulkCopyConstructor() { String testCaseName = "BulkCopyConstructor "; List testData = new ArrayList(); BulkCopyTestWrapper bulkWrapper1 = new BulkCopyTestWrapper(connectionString); @@ -180,7 +180,7 @@ List createTestData_testBulkCopyConstructor() { * * @return */ - private List createTestData_testBulkCopyOption() { + private List createTestDatatestBulkCopyOption() { String testCaseName = "BulkCopyOption "; List testData = new ArrayList(); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bvt/bvtTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bvt/bvtTest.java index b6e6a34ae..8898be8b9 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bvt/bvtTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bvt/bvtTest.java @@ -296,7 +296,7 @@ public void testStmtScrollSensitiveUpdatable() throws SQLException { * @throws SQLException */ @Test - public void testStmtSS_ScrollDynamicOptimistic_CC() throws SQLException { + public void testStmtSSScrollDynamicOptimisticCC() throws SQLException { try { conn = new DBConnection(connectionString); @@ -321,7 +321,7 @@ public void testStmtSS_ScrollDynamicOptimistic_CC() throws SQLException { * @throws SQLException */ @Test - public void testStmtSS_SEVER_CURSOR_FORWARD_ONLY() throws SQLException { + public void testStmtSserverCursorForwardOnly() throws SQLException { try { conn = new DBConnection(connectionString); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPAllTypes.java b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPAllTypes.java index 99281a1fb..4b33f124e 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPAllTypes.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPAllTypes.java @@ -45,16 +45,16 @@ public class TVPAllTypes extends AbstractTest { * @throws SQLException */ @Test - public void testTVP_ResultSet() throws SQLException { - testTVP_ResultSet(false, null, null); - testTVP_ResultSet(true, null, null); - testTVP_ResultSet(false, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); - testTVP_ResultSet(false, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); - testTVP_ResultSet(false, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); - testTVP_ResultSet(false, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); + public void testTVPResultSet() throws SQLException { + testTVPResultSet(false, null, null); + testTVPResultSet(true, null, null); + testTVPResultSet(false, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + testTVPResultSet(false, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); + testTVPResultSet(false, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); + testTVPResultSet(false, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); } - private void testTVP_ResultSet(boolean setSelectMethod, + private void testTVPResultSet(boolean setSelectMethod, Integer resultSetType, Integer resultSetConcurrency) throws SQLException { setupVariation(); @@ -93,16 +93,16 @@ private void testTVP_ResultSet(boolean setSelectMethod, * @throws SQLException */ @Test - public void testTVP_StoredProcedure_ResultSet() throws SQLException { - testTVP_StoredProcedure_ResultSet(false, null, null); - testTVP_StoredProcedure_ResultSet(true, null, null); - testTVP_StoredProcedure_ResultSet(false, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); - testTVP_StoredProcedure_ResultSet(false, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); - testTVP_StoredProcedure_ResultSet(false, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); - testTVP_StoredProcedure_ResultSet(false, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); + public void testTVPStoredProcedureResultSet() throws SQLException { + testTVPStoredProcedureResultSet(false, null, null); + testTVPStoredProcedureResultSet(true, null, null); + testTVPStoredProcedureResultSet(false, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + testTVPStoredProcedureResultSet(false, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); + testTVPStoredProcedureResultSet(false, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); + testTVPStoredProcedureResultSet(false, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); } - private void testTVP_StoredProcedure_ResultSet(boolean setSelectMethod, + private void testTVPStoredProcedureResultSet(boolean setSelectMethod, Integer resultSetType, Integer resultSetConcurrency) throws SQLException { setupVariation(); @@ -141,7 +141,7 @@ private void testTVP_StoredProcedure_ResultSet(boolean setSelectMethod, * @throws SQLException */ @Test - public void testTVP_DataTable() throws SQLException { + public void testTVPDataTable() throws SQLException { setupVariation(); SQLServerDataTable dt = new SQLServerDataTable(); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPIssuesTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPIssuesTest.java index e2b88cf4d..26087ff36 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPIssuesTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPIssuesTest.java @@ -47,7 +47,7 @@ public class TVPIssuesTest extends AbstractTest { private static String expectedTime6value = "15:39:27.616667"; @Test - public void tryTVP_RS_varcharMax_4001_Issue() throws Exception { + public void tryTVPRSvarcharMax4000Issue() throws Exception { setup(); @@ -98,7 +98,7 @@ public void testExceptionWithInvalidStoredProcedureName() throws Exception { * @throws Exception */ @Test - public void tryTVP_Precision_missed_issue_315() throws Exception { + public void tryTVPPrecisionmissedissue315() throws Exception { setup(); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPNumericTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPNumericTest.java index bc4fed492..11225805a 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPNumericTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPNumericTest.java @@ -43,7 +43,7 @@ public class TVPNumericTest extends AbstractTest { * @throws SQLServerException */ @Test - public void testNumericPresicionIssue_211() throws SQLServerException { + public void testNumericPresicionIssue211() throws SQLServerException { tvp = new SQLServerDataTable(); tvp.addColumnMetadata("c1", java.sql.Types.NUMERIC); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPSchemaTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPSchemaTest.java index 517e9985c..7182646b3 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPSchemaTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPSchemaTest.java @@ -49,8 +49,8 @@ public class TVPSchemaTest extends AbstractTest { * @throws SQLException */ @Test - @DisplayName("TVPSchema_PreparedStatement_StoredProcedure()") - public void testTVPSchema_PreparedStatement_StoredProcedure() throws SQLException { + @DisplayName("TVPSchemaPreparedStatementStoredProcedure()") + public void testTVPSchemaPreparedStatementStoredProcedure() throws SQLException { final String sql = "{call " + procedureName + "(?)}"; @@ -72,8 +72,8 @@ public void testTVPSchema_PreparedStatement_StoredProcedure() throws SQLExceptio * @throws SQLException */ @Test - @DisplayName("TVPSchema_CallableStatement_StoredProcedure()") - public void testTVPSchema_CallableStatement_StoredProcedure() throws SQLException { + @DisplayName("TVPSchemaCallableStatementStoredProcedure()") + public void testTVPSchemaCallableStatementStoredProcedure() throws SQLException { final String sql = "{call " + procedureName + "(?)}"; @@ -96,8 +96,8 @@ public void testTVPSchema_CallableStatement_StoredProcedure() throws SQLExceptio * @throws IOException */ @Test - @DisplayName("TVPSchema_Prepared_InsertCommand") - public void testTVPSchema_Prepared_InsertCommand() throws SQLException, IOException { + @DisplayName("TVPSchemaPreparedInsertCommand") + public void testTVPSchemaPreparedInsertCommand() throws SQLException, IOException { SQLServerPreparedStatement P_C_stmt = (SQLServerPreparedStatement) connection .prepareStatement("INSERT INTO " + charTable + " select * from ? ;"); @@ -119,8 +119,8 @@ public void testTVPSchema_Prepared_InsertCommand() throws SQLException, IOExcept * @throws IOException */ @Test - @DisplayName("TVPSchema_Callable_InsertCommand()") - public void testTVPSchema_Callable_InsertCommand() throws SQLException, IOException { + @DisplayName("TVPSchemaCallableInsertCommand()") + public void testTVPSchemaCallableInsertCommand() throws SQLException, IOException { SQLServerCallableStatement P_C_stmt = (SQLServerCallableStatement) connection.prepareCall("INSERT INTO " + charTable + " select * from ? ;"); P_C_stmt.setStructured(1, tvpNameWithSchema, tvp); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPTypesTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPTypesTest.java index 27778be4c..01195e36e 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPTypesTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPTypesTest.java @@ -249,7 +249,7 @@ public void testImage() throws SQLException { * @throws SQLException */ @Test - public void testTVPLongVarchar_StoredProcedure() throws SQLException { + public void testTVPLongVarcharStoredProcedure() throws SQLException { createTables("varchar(max)"); createTVPS("varchar(max)"); createPreocedure(); @@ -284,7 +284,7 @@ public void testTVPLongVarchar_StoredProcedure() throws SQLException { * @throws SQLException */ @Test - public void testTVPLongNVarchar_StoredProcedure() throws SQLException { + public void testTVPLongNVarcharStoredProcedure() throws SQLException { createTables("nvarchar(max)"); createTVPS("nvarchar(max)"); createPreocedure(); @@ -318,7 +318,7 @@ public void testTVPLongNVarchar_StoredProcedure() throws SQLException { * @throws SQLException */ @Test - public void testTVPXML_StoredProcedure() throws SQLException { + public void testTVPXMLStoredProcedure() throws SQLException { createTables("xml"); createTVPS("xml"); createPreocedure(); @@ -351,7 +351,7 @@ public void testTVPXML_StoredProcedure() throws SQLException { * @throws SQLException */ @Test - public void testTVPText_StoredProcedure() throws SQLException { + public void testTVPTextStoredProcedure() throws SQLException { createTables("text"); createTVPS("text"); createPreocedure(); @@ -385,7 +385,7 @@ public void testTVPText_StoredProcedure() throws SQLException { * @throws SQLException */ @Test - public void testTVPNText_StoredProcedure() throws SQLException { + public void testTVPNTextStoredProcedure() throws SQLException { createTables("ntext"); createTVPS("ntext"); createPreocedure(); @@ -419,7 +419,7 @@ public void testTVPNText_StoredProcedure() throws SQLException { * @throws SQLException */ @Test - public void testTVPImage_StoredProcedure() throws SQLException { + public void testTVPImageStoredProcedure() throws SQLException { createTables("image"); createTVPS("image"); createPreocedure(); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/lobsTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/lobsTest.java index 9a66905a5..f433c0bf7 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/lobsTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/lobsTest.java @@ -285,10 +285,10 @@ private void testMultipleClose(Class streamClass) throws Exception { * @throws Exception */ @Test - @DisplayName("testlLobs_InsertRetrive") + @DisplayName("testlLobsInsertRetrive") public void testNClob() throws Exception { String types[] = {"nvarchar(max)"}; - testLobs_InsertRetrive(types, NClob.class); + testLobsInsertRetrive(types, NClob.class); } /** @@ -297,10 +297,10 @@ public void testNClob() throws Exception { * @throws Exception */ @Test - @DisplayName("testlLobs_InsertRetrive") + @DisplayName("testlLobsInsertRetrive") public void testBlob() throws Exception { String types[] = {"varbinary(max)"}; - testLobs_InsertRetrive(types, Blob.class); + testLobsInsertRetrive(types, Blob.class); } /** @@ -309,13 +309,13 @@ public void testBlob() throws Exception { * @throws Exception */ @Test - @DisplayName("testlLobs_InsertRetrive") + @DisplayName("testlLobsInsertRetrive") public void testClob() throws Exception { String types[] = {"varchar(max)"}; - testLobs_InsertRetrive(types, Clob.class); + testLobsInsertRetrive(types, Clob.class); } - private void testLobs_InsertRetrive(String types[], + private void testLobsInsertRetrive(String types[], Class lobClass) throws Exception { table = createTable(table, types, false); // create empty table int size = 10000; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecuteWithErrorsTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecuteWithErrorsTest.java index c5688eadb..afe9db6f7 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecuteWithErrorsTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecuteWithErrorsTest.java @@ -270,7 +270,7 @@ public void Repro47239() throws SQLException { */ @Test @DisplayName("Regression test for using 'large' methods") - public void Repro47239_large() throws Exception { + public void Repro47239large() throws Exception { assumeTrue("JDBC42".equals(Utils.getConfiguredProperty("JDBC_Version")), "Aborting test case as JDBC version is not compatible. "); // the DBConnection for detecting whether the server is SQL Azure or SQL Server. diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java index 4418a797e..88b6c5427 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java @@ -1082,7 +1082,7 @@ public void testConsecutiveQueries() throws Exception { * @throws Exception */ @Test - public void testLargeMaxRows_JDBC41() throws Exception { + public void testLargeMaxRowsJDBC41() throws Exception { assumeTrue("JDBC41".equals(Utils.getConfiguredProperty("JDBC_Version")), "Aborting test case as JDBC version is not compatible. "); Connection con = DriverManager.getConnection(connectionString); @@ -1121,7 +1121,7 @@ public void testLargeMaxRows_JDBC41() throws Exception { * @throws Exception */ @Test - public void testLargeMaxRows_JDBC42() throws Exception { + public void testLargeMaxRowsJDBC42() throws Exception { assumeTrue("JDBC42".equals(Utils.getConfiguredProperty("JDBC_Version")), "Aborting test case as JDBC version is not compatible. "); Connection dbcon = DriverManager.getConnection(connectionString); @@ -2615,7 +2615,7 @@ public void testUpdateCountAfterRaiseError() throws Exception { * @throws Exception */ @Test - public void testUpdateCountAfterErrorInTrigger_LastUpdateCountFalse() throws Exception { + public void testUpdateCountAfterErrorInTriggerLastUpdateCountFalse() throws Exception { Connection con = DriverManager.getConnection(connectionString + ";lastUpdateCount = false"); PreparedStatement pstmt = con.prepareStatement("INSERT INTO " + tableName + " VALUES (5)"); @@ -2666,7 +2666,7 @@ public void testUpdateCountAfterErrorInTrigger_LastUpdateCountFalse() throws Exc * @throws Exception */ @Test - public void testUpdateCountAfterErrorInTrigger_LastUpdateCountTrue() throws Exception { + public void testUpdateCountAfterErrorInTriggerLastUpdateCountTrue() throws Exception { Connection con = DriverManager.getConnection(connectionString + ";lastUpdateCount = true"); PreparedStatement pstmt = con.prepareStatement("INSERT INTO " + tableName + " VALUES (5)");