diff --git a/contrib/babelfishpg_common/sql/binary.sql b/contrib/babelfishpg_common/sql/binary.sql index 3ad552287a..4ad6be24a7 100644 --- a/contrib/babelfishpg_common/sql/binary.sql +++ b/contrib/babelfishpg_common/sql/binary.sql @@ -66,6 +66,11 @@ LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; CREATE CAST (sys.VARCHAR AS sys.BBF_BINARY) WITH FUNCTION sys.varcharbinary (sys.VARCHAR, integer, boolean) AS ASSIGNMENT; +CREATE OR REPLACE FUNCTION sys.nvarcharbinary(sys.NVARCHAR, integer, boolean) +RETURNS sys.BBF_BINARY +AS 'babelfishpg_common', 'nvarcharbinary' +LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; + CREATE OR REPLACE FUNCTION sys.varcharbinary(pg_catalog.VARCHAR, integer, boolean) RETURNS sys.BBF_BINARY AS 'babelfishpg_common', 'varcharbinary' @@ -99,6 +104,11 @@ LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; CREATE CAST (sys.BBF_BINARY AS sys.VARCHAR) WITH FUNCTION sys.binarysysvarchar (sys.BBF_BINARY, integer, boolean) AS IMPLICIT; +CREATE OR REPLACE FUNCTION sys.binarysysnvarchar(sys.BBF_BINARY, integer, boolean) +RETURNS sys.NVARCHAR +AS 'babelfishpg_common', 'varbinarynvarchar' +LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; + CREATE OR REPLACE FUNCTION sys.binaryvarchar(sys.BBF_BINARY, integer, boolean) RETURNS pg_catalog.VARCHAR AS 'babelfishpg_common', 'varbinaryvarchar' diff --git a/contrib/babelfishpg_common/sql/upgrades/babelfish_common_helper--4.4.0--4.5.0.sql b/contrib/babelfishpg_common/sql/upgrades/babelfish_common_helper--4.4.0--4.5.0.sql index f27f85778a..8c0b96663f 100644 --- a/contrib/babelfishpg_common/sql/upgrades/babelfish_common_helper--4.4.0--4.5.0.sql +++ b/contrib/babelfishpg_common/sql/upgrades/babelfish_common_helper--4.4.0--4.5.0.sql @@ -7,6 +7,26 @@ SELECT set_config('search_path', 'sys, '||current_setting('search_path'), false); +CREATE OR REPLACE FUNCTION sys.nvarcharvarbinary(sys.NVARCHAR, integer, boolean) +RETURNS sys.BBF_VARBINARY +AS 'babelfishpg_common', 'nvarcharvarbinary' +LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.varbinarysysnvarchar(sys.BBF_VARBINARY, integer, boolean) +RETURNS sys.NVARCHAR +AS 'babelfishpg_common', 'varbinarynvarchar' +LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.binarysysnvarchar(sys.BBF_BINARY, integer, boolean) +RETURNS sys.NVARCHAR +AS 'babelfishpg_common', 'varbinarynvarchar' +LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.nvarcharbinary(sys.NVARCHAR, integer, boolean) +RETURNS sys.BBF_BINARY +AS 'babelfishpg_common', 'nvarcharbinary' +LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; + CREATE OR REPLACE FUNCTION sys.smalldatetime_date_cmp(sys.SMALLDATETIME, date) RETURNS INT4 AS 'timestamp_cmp_date' diff --git a/contrib/babelfishpg_common/sql/varbinary.sql b/contrib/babelfishpg_common/sql/varbinary.sql index 54f6b2d63a..80738194c7 100644 --- a/contrib/babelfishpg_common/sql/varbinary.sql +++ b/contrib/babelfishpg_common/sql/varbinary.sql @@ -71,6 +71,11 @@ LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; CREATE CAST (sys.BBF_VARBINARY AS pg_catalog.BYTEA) WITH FUNCTION sys.varbinarybytea(sys.BBF_VARBINARY, integer, boolean) AS ASSIGNMENT; +CREATE OR REPLACE FUNCTION sys.nvarcharvarbinary(sys.NVARCHAR, integer, boolean) +RETURNS sys.BBF_VARBINARY +AS 'babelfishpg_common', 'nvarcharvarbinary' +LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; + CREATE OR REPLACE FUNCTION sys.varcharvarbinary(sys.VARCHAR, integer, boolean) RETURNS sys.BBF_VARBINARY AS 'babelfishpg_common', 'varcharvarbinary' @@ -111,6 +116,11 @@ LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; CREATE CAST (sys.BBF_VARBINARY AS sys.VARCHAR) WITH FUNCTION sys.varbinarysysvarchar (sys.BBF_VARBINARY, integer, boolean) AS IMPLICIT; +CREATE OR REPLACE FUNCTION sys.varbinarysysnvarchar(sys.BBF_VARBINARY, integer, boolean) +RETURNS sys.NVARCHAR +AS 'babelfishpg_common', 'varbinarynvarchar' +LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; + CREATE OR REPLACE FUNCTION sys.varbinaryvarchar(sys.BBF_VARBINARY, integer, boolean) RETURNS pg_catalog.VARCHAR AS 'babelfishpg_common', 'varbinaryvarchar' diff --git a/contrib/babelfishpg_common/src/varbinary.c b/contrib/babelfishpg_common/src/varbinary.c index 3ab6f070e9..623202dac9 100644 --- a/contrib/babelfishpg_common/src/varbinary.c +++ b/contrib/babelfishpg_common/src/varbinary.c @@ -38,9 +38,13 @@ #include "utils/pg_locale.h" #include "utils/sortsupport.h" #include "utils/varlena.h" +#include "lib/stringinfo.h" #include "instr.h" #include "logical.h" +#include "varchar.h" +#include "babelfishpg_common.h" +#include "typecode.h" PG_FUNCTION_INFO_V1(varbinaryin); PG_FUNCTION_INFO_V1(varbinaryout); @@ -56,8 +60,11 @@ PG_FUNCTION_INFO_V1(varbinaryrowversion); PG_FUNCTION_INFO_V1(rowversionbinary); PG_FUNCTION_INFO_V1(rowversionvarbinary); PG_FUNCTION_INFO_V1(varcharvarbinary); +PG_FUNCTION_INFO_V1(nvarcharvarbinary); PG_FUNCTION_INFO_V1(bpcharvarbinary); +PG_FUNCTION_INFO_V1(nvarcharbinary); PG_FUNCTION_INFO_V1(varbinaryvarchar); +PG_FUNCTION_INFO_V1(varbinarynvarchar); PG_FUNCTION_INFO_V1(varcharbinary); PG_FUNCTION_INFO_V1(bpcharbinary); PG_FUNCTION_INFO_V1(varcharrowversion); @@ -721,6 +728,84 @@ varcharvarbinary(PG_FUNCTION_ARGS) PG_RETURN_BYTEA_P(result); } +/* + * For nvarchar we need to convert the input string to UTF-16 encoding irrespective of input encoding + * So the source string is in UTF-8 encoding, we will convert it to UTF-16 encoding + */ +Datum +nvarcharvarbinary(PG_FUNCTION_ARGS) +{ + VarChar *source = PG_GETARG_VARCHAR_PP(0); + char *data = VARDATA_ANY(source); /* Source string is UTF-8 */ + char *encoded_data; + char *rp; + size_t len = VARSIZE_ANY_EXHDR(source); + int32 typmod = PG_GETARG_INT32(1); + bool isExplicit = PG_GETARG_BOOL(2); + int32 maxlen; + bytea *result; + int encodedByteLen; + StringInfoData buf; + MemoryContext ccxt = CurrentMemoryContext; + + if (!isExplicit) + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("Implicit conversion from data type nvarchar to " + "varbinary is not allowed. Use the CONVERT function " + "to run this query."))); + + initStringInfo(&buf); + PG_TRY(); + { + /* + * For nvarchar convert the string to UTF16 from UTF8 irrespective of input encoding via TsqlUTF8toUTF16StringInfo() + * For this we need to prepare a StringInfoData() and assign the encoded_data, + * encodedByteLen from the string info data we prepared + */ + TsqlUTF8toUTF16StringInfo(&buf, data, len); + encoded_data = buf.data; + encodedByteLen= buf.len; + } + PG_CATCH(); + { + MemoryContext ectx; + ErrorData *errorData; + + ectx = MemoryContextSwitchTo(ccxt); + errorData = CopyErrorData(); + FlushErrorState(); + MemoryContextSwitchTo(ectx); + + ereport(ERROR, + (errcode(ERRCODE_INTERNAL_ERROR), + errmsg("Failed to convert from data type nvarchar to varbinary, %s", + errorData->message))); + } + PG_END_TRY(); + + /* + * If typmod is -1 (or invalid), use the actual length + * Length should be checked after encoding into server encoding + */ + if (typmod < (int32) VARHDRSZ) + maxlen = encodedByteLen; + else + maxlen = typmod - VARHDRSZ; + + if (encodedByteLen > maxlen) + encodedByteLen = maxlen; + + result = (bytea *) palloc0(encodedByteLen + VARHDRSZ); + SET_VARSIZE(result, encodedByteLen + VARHDRSZ); + + rp = VARDATA(result); + memcpy(rp, encoded_data, encodedByteLen); + pfree(buf.data); + + PG_RETURN_BYTEA_P(result); +} + Datum bpcharvarbinary(PG_FUNCTION_ARGS) { @@ -835,6 +920,79 @@ varbinaryvarchar(PG_FUNCTION_ARGS) PG_RETURN_VARCHAR_P(result); } +Datum +varbinarynvarchar(PG_FUNCTION_ARGS) +{ + bytea *source = PG_GETARG_BYTEA_PP(0); + char *data = VARDATA_ANY(source); + VarChar *result; + char *encoded_result; + size_t len = VARSIZE_ANY_EXHDR(source); + int32 typmod = -1; + int maxlen = -1; + int encodedByteLen; + StringInfoData buf; + char *paddedData = (char*)palloc0(len+1); + MemoryContext ccxt = CurrentMemoryContext; + + typmod = PG_GETARG_INT32(1); + maxlen = typmod - VARHDRSZ; + + /* + * Converts UTF-16 to UTF-8, handling odd-length inputs by padding. + * Respects maxlen if specified, otherwise processes full input. + * Uses TsqlUTF16toUTF8StringInfo for conversion, with error handling via PG_TRY. + */ + + /* truncating NULL bytes from end */ + while(len>0 && data[len-1] == '\0') + len -= 1; + + /* Do the Padding if lenngth is odd */ + memcpy(paddedData, data, len); + if(len % 2 != 0) + len = len + 1; + + if(!(maxlen < 0 || (len >> 1) <= maxlen)) + { + len = maxlen << 1; + } + + PG_TRY(); + { + /* Converts UTF-16 to UTF-8 using TsqlUTF16toUTF8StringInfo */ + initStringInfo(&buf); + TsqlUTF16toUTF8StringInfo(&buf, paddedData, len); + encoded_result = buf.data; + encodedByteLen= buf.len; + } + + + PG_CATCH(); + { + MemoryContext ectx; + ErrorData *errorData; + + ectx = MemoryContextSwitchTo(ccxt); + errorData = CopyErrorData(); + FlushErrorState(); + MemoryContextSwitchTo(ectx); + + ereport(ERROR, + (errcode(ERRCODE_INTERNAL_ERROR), + errmsg("Failed to convert from data type varbinary to nvarchar, %s", + errorData->message))); + } + PG_END_TRY(); + + result = (VarChar *) cstring_to_text_with_len(encoded_result, encodedByteLen); + pfree(buf.data); + pfree(paddedData); + + PG_RETURN_VARCHAR_P(result); +} + + Datum varcharbinary(PG_FUNCTION_ARGS) { @@ -874,6 +1032,49 @@ varcharbinary(PG_FUNCTION_ARGS) PG_RETURN_BYTEA_P(result); } +Datum +nvarcharbinary(PG_FUNCTION_ARGS) +{ + VarChar *source = PG_GETARG_VARCHAR_PP(0); + char *data = VARDATA_ANY(source); + char *rp; + size_t len = VARSIZE_ANY_EXHDR(source); + int32 typmod = PG_GETARG_INT32(1); + bool isExplicit = PG_GETARG_BOOL(2); + int32 maxlen; + bytea *result; + StringInfoData buf; + + if (!isExplicit) + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("Implicit conversion from data type nvarchar to " + "binary is not allowed. Use the CONVERT function " + "to run this query."))); + + initStringInfo(&buf); + TsqlUTF8toUTF16StringInfo(&buf, data, len); + data = buf.data; + len= buf.len; + + /* If typmod is -1 (or invalid), use the actual length */ + if (typmod < (int32) VARHDRSZ) + maxlen = len; + else + maxlen = typmod - VARHDRSZ; + + if (len > maxlen) + len = maxlen; + + result = (bytea *) palloc0(maxlen + VARHDRSZ); + SET_VARSIZE(result, maxlen + VARHDRSZ); + + rp = VARDATA(result); + memcpy(rp, data, len); + pfree(buf.data); + PG_RETURN_BYTEA_P(result); +} + Datum bpcharbinary(PG_FUNCTION_ARGS) { diff --git a/contrib/babelfishpg_common/src/varchar.c b/contrib/babelfishpg_common/src/varchar.c index d6ce302a7b..d39953019b 100644 --- a/contrib/babelfishpg_common/src/varchar.c +++ b/contrib/babelfishpg_common/src/varchar.c @@ -176,6 +176,178 @@ GetUTF8CodePoint(const unsigned char *in, int len, int *consumed_p) return code; } +static inline void +AddUTF16ToStringInfo(int32_t code, StringInfo buf) +{ + union + { + uint16_t value; + uint8_t half[2]; + } temp16; + + /* Check that this is a valid code point */ + if ((code > 0xD800 && code < 0xE000) || code < 0x0001 || code > 0x10FFFF) + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("invalid Unicode code point 0x%x", code))); + + /* Handle single 16-bit code point */ + if (code <= 0xFFFF) + { + appendStringInfoChar(buf, code & 0xFF); + appendStringInfoChar(buf, (code >> 8) & 0xFF); + return; + } + + temp16.value = 0xD800 + (((code - 0x010000) >> 10) & 0x03FF); + appendStringInfoChar(buf, temp16.half[0]); + appendStringInfoChar(buf, temp16.half[1]); + temp16.value = 0xDC00 + ((code - 0x010000) & 0x03FF); + appendStringInfoChar(buf, temp16.half[0]); + appendStringInfoChar(buf, temp16.half[1]); +} + +/* + * AddUTF8ToStringInfo - Add Unicode code point to a StringInfo in UTF-8 + */ +static inline void +AddUTF8ToStringInfo(int32_t code, StringInfo buf) +{ + /* Check that this is a valid code point */ + if ((code > 0xD800 && code < 0xE000) || code < 0x0001 || code > 0x10FFFF) + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("invalid Unicode code point 0x%x", code))); + + /* Range U+0000 .. U+007F (7 bit) */ + if (code <= 0x7F) + { + appendStringInfoChar(buf, code); + return; + } + + /* Range U+0080 .. U+07FF (11 bit) */ + if (code <= 0x7ff) + { + appendStringInfoChar(buf, 0xC0 | (code >> 6)); + appendStringInfoChar(buf, 0x80 | (code & 0x3F)); + return; + } + + /* Range U+0800 .. U+FFFF (16 bit) */ + if (code <= 0xFFFF) + { + appendStringInfoChar(buf, 0xE0 | (code >> 12)); + appendStringInfoChar(buf, 0x80 | ((code >> 6) & 0x3F)); + appendStringInfoChar(buf, 0x80 | (code & 0x3F)); + return; + } + + /* Range U+10000 .. U+10FFFF (21 bit) */ + appendStringInfoChar(buf, 0xF0 | (code >> 18)); + appendStringInfoChar(buf, 0x80 | ((code >> 12) & 0x3F)); + appendStringInfoChar(buf, 0x80 | ((code >> 6) & 0x3F)); + appendStringInfoChar(buf, 0x80 | (code & 0x3F)); +} + +static inline int32_t +GetUTF16CodePoint(const unsigned char *in, int len, int *consumed) +{ + uint16_t code1; + uint16_t code2; + int32_t result; + + /* Get the first 16 bits */ + code1 = in[1] << 8 | in[0]; + if (code1 < 0xD800 || code1 >= 0xE000) + { + /* + * This is a single 16 bit code point, which is equal to code1. + * PostgreSQL does not support NUL bytes in character data as it + * internally needs the ability to convert any datum to a NUL + * terminated C-string without explicit length information. + */ + if (code1 == 0) + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("invalid UTF16 byte sequence - " + "code point 0 not supported"))); + if (consumed) + *consumed = 2; + return (int32_t) code1; + } + + /* This is a surrogate pair - check that it is the high part */ + if (code1 >= 0xDC00) + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("invalid UTF16 byte sequence - " + "high part is (0x%02x, 0x%02x)", in[0], in[1]))); + + /* Check that there is a second surrogate half */ + if (len < 4) + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("invalid UTF16 byte sequence - " + "only 2 bytes (0x%02x, 0x%02x)", in[0], in[1]))); + + /* Get the second 16 bits (low part) */ + code2 = in[3] << 8 | in[2]; + if (code2 < 0xDC00 || code2 > 0xE000) + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("invalid UTF16 byte sequence - " + "low part is (0x%02x, 0x%02x)", in[2], in[3]))); + + /* Valid surrogate pair, convert to code point */ + result = ((code1 & 0x03FF) << 10 | (code2 & 0x03FF)) + 0x10000; + + /* Valid 32 bit surrogate code point */ + if (consumed) + *consumed = 4; + return result; +} + +void +TsqlUTF8toUTF16StringInfo(StringInfo out, const void *vin, size_t len) +{ + const unsigned char *in = vin; + size_t i; + int consumed; + int32_t code; + + for (i = 0; i < len;) + { + code = GetUTF8CodePoint(&in[i], len - i, &consumed); + AddUTF16ToStringInfo(code, out); + i += consumed; + } +} + +void +TsqlUTF16toUTF8StringInfo(StringInfo out, void *vin, int len) +{ + unsigned char *in = vin; + int i; + int consumed; + int32_t code; + + /* UTF16 data allways comes in 16-bit units */ + if ((len & 0x0001) != 0) + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("invalid UTF16 byte sequence - " + "input data has odd number of bytes"))); + + for (i = 0; i < len;) + { + code = GetUTF16CodePoint(&in[i], len - i, &consumed); + AddUTF8ToStringInfo(code, out); + i += consumed; + } +} + + /* * TsqlUTF8LengthInUTF16 - compute the length of a UTF8 string in number of * 16-bit units if we were to convert it into diff --git a/contrib/babelfishpg_common/src/varchar.h b/contrib/babelfishpg_common/src/varchar.h index eb3c07d484..77846ff284 100644 --- a/contrib/babelfishpg_common/src/varchar.h +++ b/contrib/babelfishpg_common/src/varchar.h @@ -7,5 +7,7 @@ extern int32_t GetUTF8CodePoint(const unsigned char *in, int len, int *consumed_ extern void *tsql_varchar_input(const char *s, size_t len, int32 atttypmod); extern void *tsql_bpchar_input(const char *s, size_t len, int32 atttypmod); extern int TsqlUTF8LengthInUTF16(const void *vin, int len); +extern void TsqlUTF8toUTF16StringInfo(StringInfo out, const void *vin, size_t len); +extern void TsqlUTF16toUTF8StringInfo(StringInfo out, void *vin, int len); #endif diff --git a/contrib/babelfishpg_tsql/src/pltsql_coerce.c b/contrib/babelfishpg_tsql/src/pltsql_coerce.c index b245878aaf..1250c369f4 100644 --- a/contrib/babelfishpg_tsql/src/pltsql_coerce.c +++ b/contrib/babelfishpg_tsql/src/pltsql_coerce.c @@ -70,6 +70,7 @@ PG_FUNCTION_INFO_V1(get_immediate_base_type_of_UDT); static Oid select_common_type_setop(ParseState *pstate, List *exprs, Node **which_expr, const char *context); static Oid select_common_type_for_isnull(ParseState *pstate, List *exprs); static Oid select_common_type_for_coalesce_function(ParseState *pstate, List *exprs); +static Oid get_immediate_base_type_of_UDT_internal(Oid typeid); /* Memory Context */ static MemoryContext pltsql_coercion_context = NULL; @@ -130,11 +131,13 @@ tsql_cast_raw_info_t tsql_cast_raw_infos[] = {PG_CAST_ENTRY, "sys", "bbf_varbinary", "pg_catalog", "int2", NULL, 'i', 'f'}, {TSQL_CAST_ENTRY, "sys", "bbf_varbinary", "sys", "rowversion", "varbinaryrowversion", 'i', 'f'}, {TSQL_CAST_ENTRY, "sys", "bbf_varbinary", "sys", "bbf_binary", "varbinarybinary", 'i', 'f'}, + {TSQL_CAST_ENTRY, "sys", "bbf_varbinary", "sys", "nvarchar", "varbinarysysnvarchar", 'i', 'f'}, /* binary {only allow to cast to integral data type) */ {PG_CAST_ENTRY, "sys", "bbf_binary", "pg_catalog", "int8", NULL, 'i', 'f'}, {PG_CAST_ENTRY, "sys", "bbf_binary", "pg_catalog", "int4", NULL, 'i', 'f'}, {PG_CAST_ENTRY, "sys", "bbf_binary", "pg_catalog", "int2", NULL, 'i', 'f'}, {TSQL_CAST_ENTRY, "sys", "bbf_binary", "sys", "rowversion", "binaryrowversion", 'i', 'f'}, + {TSQL_CAST_ENTRY, "sys", "bbf_binary", "sys", "nvarchar", "binarysysnvarchar", 'i', 'f'}, {TSQL_CAST_WITHOUT_FUNC_ENTRY, "sys", "bbf_binary", "sys", "bbf_varbinary", NULL, 'i', 'b'}, /* rowversion */ {PG_CAST_ENTRY, "sys", "rowversion", "pg_catalog", "int8", NULL, 'i', 'f'}, @@ -230,6 +233,8 @@ tsql_cast_raw_info_t tsql_cast_raw_infos[] = {TSQL_CAST_ENTRY, "sys", "bpchar", "pg_catalog", "name", "bpchar_to_name", 'i', 'f'}, {TSQL_CAST_ENTRY, "pg_catalog", "varchar", "pg_catalog", "name", "varchar_to_name", 'i', 'f'}, {TSQL_CAST_ENTRY, "sys", "varchar", "pg_catalog", "name", "varchar_to_name", 'i', 'f'}, + {TSQL_CAST_ENTRY, "sys", "nvarchar", "sys", "bbf_varbinary", "nvarcharvarbinary", 'a', 'f'}, + {TSQL_CAST_ENTRY, "sys", "nvarchar", "sys", "bbf_binary", "nvarcharbinary", 'a', 'f'}, /* string -> float8 via I/O */ {TSQL_CAST_WITHOUT_FUNC_ENTRY, "pg_catalog", "text", "pg_catalog", "float8", NULL, 'i', 'i'}, {TSQL_CAST_WITHOUT_FUNC_ENTRY, "pg_catalog", "bpchar", "pg_catalog", "float8", NULL, 'i', 'i'}, @@ -462,6 +467,18 @@ static tsql_cast_info_entry_t *tsql_cast_info_entries = NULL; static HTAB *ht_tsql_cast_info = NULL; bool inited_ht_tsql_cast_info = false; +/* Returns true if the oid belongs to binary, bbf_binary, varbinary, bbf_varbinary datatype */ +static bool +is_tsql_binary_family_datatype(Oid oid) +{ + if((*common_utility_plugin_ptr->is_tsql_binary_datatype)(oid) || (*common_utility_plugin_ptr->is_tsql_sys_varbinary_datatype)(oid) + || (*common_utility_plugin_ptr->is_tsql_sys_binary_datatype)(oid) || (*common_utility_plugin_ptr->is_tsql_varbinary_datatype)(oid)) + { + return true; + } + return false; +} + static CoercionPathType tsql_find_coercion_pathway(Oid sourceTypeId, Oid targetTypeId, CoercionContext ccontext, Oid *funcid) { @@ -475,8 +492,12 @@ tsql_find_coercion_pathway(Oid sourceTypeId, Oid targetTypeId, CoercionContext c bool isSqlVariantCast = false; bool isInt8Type = false; bool isInt8ToMoney = false; + bool isVarbinaryToNvarchar = false; + bool isNvarchartoVarbinary = false; Oid typeIds[2] = {sourceTypeId, targetTypeId}; + Oid UDT_sourceBaseType = InvalidOid; + Oid UDT_targetBaseType = InvalidOid; for (int i = 0; i < 2; i++) { @@ -507,22 +528,61 @@ tsql_find_coercion_pathway(Oid sourceTypeId, Oid targetTypeId, CoercionContext c ReleaseSysCache(tuple); break; } + if( i == 0 && strcmp(type_nsname, "sys") != 0 && strcmp(type_nsname, "pg_catalog") != 0) + { + UDT_sourceBaseType = get_immediate_base_type_of_UDT_internal(sourceTypeId); + } + + if(i == 1 && strcmp(type_nsname, "sys") != 0 && strcmp(type_nsname, "pg_catalog") != 0) + { + UDT_targetBaseType = get_immediate_base_type_of_UDT_internal(targetTypeId); + } + + ReleaseSysCache(tuple); } } + /* Check if the UDT's base type is nvarchar or varbinary. + * If so, use the immediate base type for further processing. + */ + if(UDT_sourceBaseType != InvalidOid && ((*common_utility_plugin_ptr->is_tsql_nvarchar_datatype)(UDT_sourceBaseType) || is_tsql_binary_family_datatype(UDT_sourceBaseType))) + { + typeIds[0] = UDT_sourceBaseType; + sourceTypeId = UDT_sourceBaseType; + } + + if(UDT_targetBaseType != InvalidOid && ((*common_utility_plugin_ptr->is_tsql_nvarchar_datatype)(UDT_targetBaseType) || is_tsql_binary_family_datatype(UDT_targetBaseType))) + { + typeIds[1] = UDT_targetBaseType; + targetTypeId = UDT_targetBaseType; + } + + /* We've found VARBINARY To NVARCHAR casting */ + if (is_tsql_binary_family_datatype(typeIds[0]) && (*common_utility_plugin_ptr->is_tsql_nvarchar_datatype)(typeIds[1])) + isVarbinaryToNvarchar = true; + + /* We've found NVARCHAR TO (bbf)(VAR)BINARY casting */ + if ((*common_utility_plugin_ptr->is_tsql_nvarchar_datatype)(typeIds[0]) && is_tsql_binary_family_datatype(typeIds[1])) + isNvarchartoVarbinary = true; + /* Perhaps the types are domains; if so, look at their base types */ if (!isSqlVariantCast) { - if (OidIsValid(sourceTypeId)) + /* + * if we are casting from NVARCHAR TO VARBINARY, don't look for base type of + * source so that it can call the cast function which matches with the + * exact types + */ + if (OidIsValid(sourceTypeId) && !isNvarchartoVarbinary) sourceTypeId = getBaseType(sourceTypeId); /* - * if we are casting from INT8 to MONEY, don't look for base type of + * if we are casting from INT8 to MONEY or VARBINARY To NVARCHAR, don't look for base type of * target so that it can call the cast function which matches with the * exact types */ - if (OidIsValid(targetTypeId) && !isInt8ToMoney) + if (OidIsValid(targetTypeId) && !isInt8ToMoney && !isVarbinaryToNvarchar) targetTypeId = getBaseType(targetTypeId); } diff --git a/test/JDBC/expected/babel_datatype.out b/test/JDBC/expected/babel_datatype.out index 821cc2f496..3ba0c04eed 100644 --- a/test/JDBC/expected/babel_datatype.out +++ b/test/JDBC/expected/babel_datatype.out @@ -2044,7 +2044,7 @@ select cast(cast('a' AS nvarchar(10)) as varbinary(2)); GO ~~START~~ varbinary -61 +6100 ~~END~~ select cast(cast(cast('a' AS nvarchar(10)) as varbinary(2)) as nvarchar(2)); @@ -2058,28 +2058,28 @@ select cast(cast('ab' AS nvarchar(10)) as varbinary(2)); GO ~~START~~ varbinary -6162 +6100 ~~END~~ select cast(cast(cast('ab' AS nvarchar(10)) as varbinary(2)) as nvarchar(2)); GO ~~START~~ nvarchar -ab +a ~~END~~ select cast(cast('abc' AS nvarchar(10)) as varbinary(2)); GO ~~START~~ varbinary -6162 +6100 ~~END~~ select cast(cast(cast('abc' AS nvarchar(10)) as varbinary(2)) as nvarchar(2)); GO ~~START~~ nvarchar -ab +a ~~END~~ @@ -2211,28 +2211,28 @@ select cast(cast('ab' AS nvarchar(10)) as binary(2)); GO ~~START~~ binary -6162 +6100 ~~END~~ select cast(cast(cast('ab' AS nvarchar(10)) as binary(2)) as nvarchar(2)); GO ~~START~~ nvarchar -ab +a ~~END~~ select cast(cast('abc' AS nvarchar(10)) as binary(2)); GO ~~START~~ binary -6162 +6100 ~~END~~ select cast(cast(cast('abc' AS nvarchar(10)) as binary(2)) as nvarchar(2)); GO ~~START~~ nvarchar -ab +a ~~END~~ diff --git a/test/JDBC/expected/cast_nvarchar_test-vu-cleanup.out b/test/JDBC/expected/cast_nvarchar_test-vu-cleanup.out new file mode 100644 index 0000000000..93d03855a1 --- /dev/null +++ b/test/JDBC/expected/cast_nvarchar_test-vu-cleanup.out @@ -0,0 +1,20 @@ +-- to do in hashbytes PR +-- DROP TABLE IF EXISTS TestHash; +-- GO +DROP type user_defined_varbinary; +GO +DROP type user_defined_nvarchar; +GO +DROP VIEW IF EXISTS dbo.CastDemoView; +GO +DROP VIEW IF EXISTS dbo.CastDemoView1; +GO +DROP FUNCTION IF EXISTS dbo.CastNVarcharToVarbinary; +GO +DROP FUNCTION IF EXISTS dbo.CastVarbinaryToNVarchar; +GO +DROP FUNCTION IF EXISTS dbo.CastbinaryToNVarchar; +GO +DROP TABLE IF EXISTS casttable; +GO + diff --git a/test/JDBC/expected/cast_nvarchar_test-vu-prepare.out b/test/JDBC/expected/cast_nvarchar_test-vu-prepare.out new file mode 100644 index 0000000000..bc788efc1e --- /dev/null +++ b/test/JDBC/expected/cast_nvarchar_test-vu-prepare.out @@ -0,0 +1,76 @@ + +-- to do in hashbytes PR +-- CREATE TABLE TestHash( +-- nvarchar_data nvarchar(32) NOT NULL, +-- varchar_data varchar(32) NOT NULL, +-- cast_hashbytes_nvarchar_data AS (cast ( hashbytes('sha1', nvarchar_data) AS varbinary(20) )) PERSISTED NOT NULL, +-- convert_hashbytes_nvarchar_data AS (convert( varbinary(20), hashbytes('sha1',nvarchar_data))) PERSISTED NOT NULL, +-- cast_hashbytes_varchar_data AS (cast ( hashbytes('sha1', varchar_data) AS varbinary(20) )) PERSISTED NOT NULL, +-- convert_hashbytes_varchar_data AS (convert( varbinary(20), hashbytes('sha1',varchar_data))) PERSISTED NOT NULL +-- ); +-- GO +-- Function to cast NVARCHAR to VARBINARY +CREATE FUNCTION dbo.CastNVarcharToVarbinary +( + @Input NVARCHAR(MAX) +) +RETURNS VARBINARY(MAX) +AS +BEGIN + RETURN CAST(@Input AS VARBINARY(MAX)); +END +GO + +-- Function to cast VARBINARY to NVARCHAR +CREATE FUNCTION dbo.CastVarbinaryToNVarchar +( + @Input VARBINARY(MAX) +) +RETURNS NVARCHAR(MAX) +AS +BEGIN + RETURN CAST(@Input AS NVARCHAR(MAX)); +END +GO + +-- Function to cast BINARY to NVARCHAR +CREATE FUNCTION dbo.CastbinaryToNVarchar +( + @Input BINARY +) +RETURNS NVARCHAR(MAX) +AS +BEGIN + RETURN CAST(@Input AS NVARCHAR(MAX)); +END +GO + +-- View that demonstrates both casts +CREATE VIEW dbo.CastDemoView +AS +SELECT + dbo.CastNVarcharToVarbinary(N'Hello, World!') AS NVarcharToVarbinary, + dbo.CastVarbinaryToNVarchar(0x48656C6C6F2C20576F726C6421) AS VarbinaryToNVarchar, + dbo.CastbinaryToNVarchar(0x48656C6C6F2C20576F726C6421) AS binaryToNVarchar +GO + +create table casttable(nvarchar_data nvarchar(max), varbinary_data varbinary(max), binary_data binary(15), nvarchar_binary_data nvarchar(max)); +GO +insert into casttable(nvarchar_data, varbinary_data, binary_data, nvarchar_binary_data) values (N'test string', 0x48656C6C6F2C20576F726C6421, 0x48656C6C6F2C20576F726C6421, N'test string') +GO +~~ROW COUNT: 1~~ + + +CREATE VIEW dbo.CastDemoView1 +AS +SELECT + CAST(nvarchar_data AS VARBINARY(MAX)), + CAST(varbinary_data AS NVARCHAR(MAX)), + CAST(binary_data AS NVARCHAR(MAX)), + CAST(nvarchar_binary_data AS BINARY(15)) +FROM casttable +GO + + + + diff --git a/test/JDBC/expected/cast_nvarchar_test-vu-verify.out b/test/JDBC/expected/cast_nvarchar_test-vu-verify.out new file mode 100644 index 0000000000..d63936ec67 --- /dev/null +++ b/test/JDBC/expected/cast_nvarchar_test-vu-verify.out @@ -0,0 +1,357 @@ + + + + + + + + + + +-- to do in hashbytes pr +-- -- TEST CASE 1: creating a table and then calling hashbytes for nvarchar and varchar input +-- insert into TestHash values('value1', 'value1'); +-- GO +-- SELECT DATALENGTH( nvarchar_data) as nvarchar_data_datalength +-- , LEN( nvarchar_data) AS nvarchar_data_len +-- , DATALENGTH( varchar_data) as varchar_data_btyes_datalength +-- , LEN( varchar_data) AS varchar_data_len +-- , * +-- from TestHash; +-- GO +-- -- TEST CASE 2: Casting nvarchar and varchar with different algorithms using Hashbytes +-- SELECT hashbytes( 'sha1', 'test string' ) as vary_string, hashbytes( 'sha1', N'test string' ) as unicode_string +-- GO +-- SELECT hashbytes( 'MD2', 'test string' ) as vary_string, hashbytes( 'MD2', N'test string' ) as unicode_string +-- GO +-- SELECT hashbytes( 'MD4', 'test string' ) as vary_string, hashbytes( 'MD4', N'test string' ) as unicode_string +-- GO +-- SELECT hashbytes( 'MD5', 'test string' ) as vary_string, hashbytes( 'MD5', N'test string' ) as unicode_string +-- GO +-- SELECT hashbytes( 'SHA2_256', 'test string' ) as vary_string, hashbytes( 'SHA2_256', N'test string' ) as unicode_string +-- GO +-- SELECT hashbytes( 'SHA2_512', 'test string' ) as vary_string, hashbytes( 'SHA2_512', N'test string' ) as unicode_string +-- GO +-- SELECT hashbytes( 'SHA', 'test string' ) as vary_string, hashbytes( 'SHA', N'test string' ) as unicode_string +-- GO +-- SELECT hashbytes( 'sha1', 'test string') +-- GO +-- --TEST CASE 3: testing hashbytes via casting a varchar to nvarchar +-- SELECT hashbytes('sha1',cast('test string' as sys.nvarchar)) +-- GO +--TEST CASE 4: Casting function for nvarchar to varbinary +SELECT cast(N'test string' as varbinary); +GO +~~START~~ +varbinary +7400650073007400200073007400720069006E006700 +~~END~~ + + +SELECT cast(cast(cast('ab' AS nvarchar(10)) as varbinary(2)) as nvarchar(2)); +GO +~~START~~ +nvarchar +a +~~END~~ + + + + + + +-- to do in hashbytes PR +-- -- Test Case 5: Empty strings and NULL values +-- SELECT HASHBYTES('SHA1', '') AS empty_varchar, +-- HASHBYTES('SHA1', N'') AS empty_nvarchar, +-- HASHBYTES('SHA1', NULL) AS null_input; +-- GO +-- -- Test Case 6: Unicode characters +-- SELECT HASHBYTES('SHA1', N'こんにちは') AS japanese, +-- HASHBYTES('SHA1', N'Здравствуйте') AS russian, +-- HASHBYTES('SHA1', N'🙂😊😀') AS emojis; +-- GO +-- -- Test Case 8: Different collations +-- SELECT HASHBYTES('SHA1', N'hello' COLLATE Latin1_General_CI_AS) AS ci_as, +-- HASHBYTES('SHA1', N'hello' COLLATE Latin1_General_CS_AS) AS cs_as; +-- GO +-- -- Test Case 9: Combining varchar and nvarchar +-- SELECT HASHBYTES('SHA1', 'hello' + N'world') AS combined; +-- GO +-- Test Case 10: Roundtrip conversions +SELECT CAST(CAST(N'test' AS VARBINARY(8)) AS NVARCHAR(4)) AS nvarchar_roundtrip, + CAST(CAST('test' AS VARBINARY(8)) AS VARCHAR(4)) AS varchar_roundtrip; +GO +~~START~~ +nvarchar#!#varchar +test#!#test +~~END~~ + + +-- Test Case 11: CAST and CONVERT between varchar, nvarchar, and varbinary +SELECT CAST(N'hello' AS VARBINARY(10)) AS nvarchar_to_varbinary, + CAST('hello' AS VARBINARY(10)) AS varchar_to_varbinary, + CONVERT(VARBINARY(10), N'hello') AS nvarchar_to_varbinary_convert, + CONVERT(VARBINARY(10), 'hello') AS varchar_to_varbinary_convert; +GO +~~START~~ +varbinary#!#varbinary#!#varbinary#!#varbinary +680065006C006C006F00#!#68656C6C6F#!#68656C6C6F#!#68656C6C6F +~~END~~ + + + +-- to do in hashbytes PR +-- -- Test Case 12: Testing with special characters +-- SELECT HASHBYTES('SHA1', 'Hello, World!') AS varchar_special, +-- HASHBYTES('SHA1', N'Hello, World!') AS nvarchar_special, +-- HASHBYTES('SHA1', 'Hello' + CHAR(13) + CHAR(10) + 'World') AS varchar_newline, +-- HASHBYTES('SHA1', N'Hello' + NCHAR(13) + NCHAR(10) + N'World') AS nvarchar_newline; +-- GO +-- Test Case 13: NVARCHAR -> VARBINARY -> VARCHAR -> NVARCHAR -> VARBINARY +SELECT CAST( + CAST( + CAST( + CAST(N'Hello World' AS VARBINARY(100)) + AS VARCHAR(100)) + AS NVARCHAR(100)) +AS VARBINARY(100)) AS four_casts; +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Failed to convert from data type varbinary to varchar, invalid byte sequence for encoding "WIN1252": 0x00)~~ + + +-- Test Case 14: VARCHAR -> NVARCHAR -> VARBINARY -> NVARCHAR -> VARCHAR +SELECT CAST( + CAST( + CAST( + CAST('Test String' AS NVARCHAR(50)) + AS VARBINARY(50)) + AS NVARCHAR(50)) +AS VARCHAR(50)) AS four_casts; +GO +~~START~~ +varchar +Test String +~~END~~ + + +-- Test Case 15: Implicit conversion from data type nvarchar to varbinary is not allowed. +DECLARE @a varbinary(10); SET @a = CAST(N'21' AS nvarchar(10)); SELECT @a +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Implicit conversion from data type nvarchar to varbinary is not allowed. Use the CONVERT function to run this query.)~~ + + +-- Test Case 16: Casting with UDT on nvarchar -> varbinary, UDT on varbinary to nvarchar, UDT on nvarchar to UDT on varbinary +create type user_defined_nvarchar from nvarchar(50); +select cast(cast(N'test string' as user_defined_nvarchar) as varbinary) +GO +~~START~~ +varbinary +7400650073007400200073007400720069006E006700 +~~END~~ + + +create type user_defined_varbinary from varbinary(50); +select cast(cast(0x7400650073007400200073007400720069006E006700 as user_defined_varbinary) as nvarchar) +GO +~~START~~ +nvarchar +test string +~~END~~ + + +select cast(cast(N'test string' as user_defined_nvarchar) as user_defined_varbinary) +go +~~START~~ +varbinary +7400650073007400200073007400720069006E006700 +~~END~~ + +-- Test Case 17: NVARCHAR-> BINARY +select cast(N'test string' as binary) +GO +~~START~~ +binary +7400650073007400200073007400720069006E0067000000000000000000 +~~END~~ + +-- Test Case 18: NVARCHAR-> User Defined varbinary +select cast(N'test string' as user_defined_varbinary) +GO +~~START~~ +varbinary +7400650073007400200073007400720069006E006700 +~~END~~ + + + + +-- to do in hashbytes PR +-- -- Test Case 19: User defined hashbytes function +-- create function dbo.hashbytes(@data sys.varchar)returns sys.varchar AS BEGIN return "dummy hashbytes";END +-- GO +-- SELECT hashbytes( 'SHA', 'test string' ) as vary_string, hashbytes( 'SHA', N'test string' ) as unicode_string +-- GO +-- select hashbytes('abc') +-- GO +-- drop function dbo.hashbytes +-- GO +-- Test 20: Calling the function, procedure, views from prepare scripts +-- Test CastNVarcharToVarbinary function +DECLARE @TestString NVARCHAR(100) = N'Test String'; +DECLARE @BinaryResult VARBINARY(MAX); +SET @BinaryResult = dbo.CastNVarcharToVarbinary(@TestString); +select cast (@BinaryResult as nvarchar) +GO +~~START~~ +nvarchar +Test String +~~END~~ + + + +-- Test CastVarbinaryToNVarchar function +DECLARE @TestBinary VARBINARY(100) = 0x54657374537472696E67; -- 'Test String' in ASCII +DECLARE @StringResult NVARCHAR(MAX); +SET @StringResult = dbo.CastVarbinaryToNVarchar(@TestBinary); +select cast (@StringResult as nvarchar) +GO +~~START~~ +nvarchar +敔瑳瑓楲杮 +~~END~~ + + + +-- Test CastbinaryToNVarchar function +DECLARE @TestBinary BINARY = 0x54657374537472696E67; -- 'Test String' in ASCII +DECLARE @StringResult NVARCHAR(MAX); +SET @StringResult = dbo.CastbinaryToNVarchar(@TestBinary); +select cast (@StringResult as nvarchar) +GO +~~START~~ +nvarchar +T +~~END~~ + + + +-- Test CastDemoView +DECLARE @ViewResult TABLE ( + NVarcharToVarbinary VARBINARY(MAX), + VarbinaryToNVarchar NVARCHAR(MAX), + binaryToNVarchar NVARCHAR(MAX) +); +INSERT INTO @ViewResult +SELECT * FROM dbo.CastDemoView; +go +~~ROW COUNT: 1~~ + + +SELECT * FROM dbo.CastDemoView1; +GO +~~START~~ +varbinary#!#nvarchar#!#nvarchar#!#binary +7400650073007400200073007400720069006E006700#!#效汬Ɐ圠牯摬!#!#效汬Ɐ圠牯摬!#!#740065007300740020007300740072 +~~END~~ + +-- TEST CASE 21: Assigned Casting +DECLARE @NVarcharValue NVARCHAR(100) = N'Hello, World!'; +DECLARE @AssignedVarbinary VARBINARY(100); +SET @AssignedVarbinary = CAST(@NVarcharValue AS VARBINARY(100)); +select CAST(@AssignedVarbinary AS NVARCHAR(100)); +GO +~~START~~ +nvarchar +Hello, World! +~~END~~ + + + + + +--TEST CASE 22: Calling hashbytes via function, procedure, views +-- Test the HashMultipleTypes function +DECLARE @TestVarchar VARCHAR(10) = 'Test'; +DECLARE @TestNVarchar NVARCHAR(10) = N'Test'; +DECLARE @TestVarbinary VARBINARY(10) = 0x54657374; -- 'Test' in ASCII +-- to do in hashbytes PR +-- SELECT * FROM dbo.HashMultipleTypes(@TestVarchar, @TestNVarchar, @TestVarbinary); +-- GO +-- -- Test the HashDemoView +-- SELECT * FROM dbo.HashDemoView; +-- GO +--TEST CASE 23: BINARY TO NVARCHAR +select cast(cast(N'test string' as binary) as nvarchar) +GO +~~START~~ +nvarchar +test string +~~END~~ + +--TEST CASE 24: NVARCHAR TO BINARY with maxlen < length of actual string +select cast(0x610061006100610061006100610061006100 as nvarchar(5)) +GO +~~START~~ +nvarchar +aaaaa +~~END~~ + +select cast(0x8765 as nvarchar(1)) +GO +~~START~~ +nvarchar +文 +~~END~~ + + + +--TEST CASE 25: Default typmod case with string getting truncated +select cast(N'Lorem ipsum dolor sit amet' as varbinary) +GO +~~START~~ +varbinary +4C006F00720065006D00200069007000730075006D00200064006F006C00 +~~END~~ + +select cast(0x4C006F00720065006D00200069007000730075006D00200064006F006C00 as nvarchar) +GO +~~START~~ +nvarchar +Lorem ipsum dol +~~END~~ + +--TEST CASE 26: String getting truncted with defined typmod i.e len > maxlen +select cast(N'tesst string' as varbinary(4)) +GO +~~START~~ +varbinary +74006500 +~~END~~ + +select cast(0x74006500 as nvarchar) +GO +~~START~~ +nvarchar +te +~~END~~ + + +select cast(N'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea' as varbinary(MAX)) +GO +~~START~~ +varbinary +4C006F00720065006D00200069007000730075006D00200064006F006C006F0072002000730069007400200061006D00650074002C00200063006F006E00730065006300740065007400750072002000610064006900700069007300630069006E006700200065006C00690074002E002000530065006400200064006F00200065006900750073006D006F0064002000740065006D0070006F007200200069006E006300690064006900640075006E00740020007500740020006C00610062006F0072006500200065007400200064006F006C006F007200650020006D00610067006E006100200061006C0069007100750061002E00200055007400200065006E0069006D0020006100640020006D0069006E0069006D002000760065006E00690061006D002C002000710075006900730020006E006F0073007400720075006400200065007800650072006300690074006100740069006F006E00200075006C006C0061006D0063006F0020006C00610062006F0072006900730020006E00690073006900200075007400200061006C0069007100750069007000200065007800200065006100200063006F006D006D006F0064006F00200063006F006E007300650071007500610074002E002000440075006900730020006100750074006500200069007200750072006500200064006F006C006F007200200069006E00200072006500700072006500680065006E0064006500720069007400200069006E00200076006F006C007500700074006100740065002000760065006C0069007400200065007300730065002000630069006C006C0075006D00200064006F006C006F0072006500200065007500200066007500670069006100740020006E0075006C006C0061002000700061007200690061007400750072002E0020004500780063006500700074006500750072002000730069006E00740020006F006300630061006500630061007400200063007500700069006400610074006100740020006E006F006E002000700072006F006900640065006E0074002C002000730075006E007400200069006E002000630075006C0070006100200071007500690020006F0066006600690063006900610020006400650073006500720075006E00740020006D006F006C006C0069007400200061006E0069006D00200069006400200065007300740020006C00610062006F00720075006D002E0020004C006F00720065006D00200069007000730075006D00200064006F006C006F0072002000730069007400200061006D00650074002C00200063006F006E00730065006300740065007400750072002000610064006900700069007300630069006E006700200065006C00690074002E002000530065006400200064006F00200065006900750073006D006F0064002000740065006D0070006F007200200069006E006300690064006900640075006E00740020007500740020006C00610062006F0072006500200065007400200064006F006C006F007200650020006D00610067006E006100200061006C0069007100750061002E00200055007400200065006E0069006D0020006100640020006D0069006E0069006D002000760065006E00690061006D002C002000710075006900730020006E006F0073007400720075006400200065007800650072006300690074006100740069006F006E00200075006C006C0061006D0063006F0020006C00610062006F0072006900730020006E00690073006900200075007400200061006C0069007100750069007000200065007800200065006100200063006F006D006D006F0064006F00200063006F006E007300650071007500610074002E002000440075006900730020006100750074006500200069007200750072006500200064006F006C006F007200200069006E00200072006500700072006500680065006E0064006500720069007400200069006E00200076006F006C007500700074006100740065002000760065006C0069007400200065007300730065002000630069006C006C0075006D00200064006F006C006F0072006500200065007500200066007500670069006100740020006E0075006C006C0061002000700061007200690061007400750072002E0020004500780063006500700074006500750072002000730069006E00740020006F006300630061006500630061007400200063007500700069006400610074006100740020006E006F006E002000700072006F006900640065006E0074002C002000730075006E007400200069006E002000630075006C0070006100200071007500690020006F0066006600690063006900610020006400650073006500720075006E00740020006D006F006C006C0069007400200061006E0069006D00200069006400200065007300740020006C00610062006F00720075006D002E0020004C006F00720065006D00200069007000730075006D00200064006F006C006F0072002000730069007400200061006D00650074002C00200063006F006E00730065006300740065007400750072002000610064006900700069007300630069006E006700200065006C00690074002E002000530065006400200064006F00200065006900750073006D006F0064002000740065006D0070006F007200200069006E006300690064006900640075006E00740020007500740020006C00610062006F0072006500200065007400200064006F006C006F007200650020006D00610067006E006100200061006C0069007100750061002E00200055007400200065006E0069006D0020006100640020006D0069006E0069006D002000760065006E00690061006D002C002000710075006900730020006E006F0073007400720075006400200065007800650072006300690074006100740069006F006E00200075006C006C0061006D0063006F0020006C00610062006F0072006900730020006E00690073006900200075007400200061006C0069007100750069007000200065007800200065006100200063006F006D006D006F0064006F00200063006F006E007300650071007500610074002E002000440075006900730020006100750074006500200069007200750072006500200064006F006C006F007200200069006E00200072006500700072006500680065006E0064006500720069007400200069006E00200076006F006C007500700074006100740065002000760065006C0069007400200065007300730065002000630069006C006C0075006D00200064006F006C006F0072006500200065007500200066007500670069006100740020006E0075006C006C0061002000700061007200690061007400750072002E0020004500780063006500700074006500750072002000730069006E00740020006F006300630061006500630061007400200063007500700069006400610074006100740020006E006F006E002000700072006F006900640065006E0074002C002000730075006E007400200069006E002000630075006C0070006100200071007500690020006F0066006600690063006900610020006400650073006500720075006E00740020006D006F006C006C0069007400200061006E0069006D00200069006400200065007300740020006C00610062006F00720075006D002E0020004C006F00720065006D00200069007000730075006D00200064006F006C006F0072002000730069007400200061006D00650074002C00200063006F006E00730065006300740065007400750072002000610064006900700069007300630069006E006700200065006C00690074002E002000530065006400200064006F00200065006900750073006D006F0064002000740065006D0070006F007200200069006E006300690064006900640075006E00740020007500740020006C00610062006F0072006500200065007400200064006F006C006F007200650020006D00610067006E006100200061006C0069007100750061002E00200055007400200065006E0069006D0020006100640020006D0069006E0069006D002000760065006E00690061006D002C002000710075006900730020006E006F0073007400720075006400200065007800650072006300690074006100740069006F006E00200075006C006C0061006D0063006F0020006C00610062006F0072006900730020006E00690073006900200075007400200061006C0069007100750069007000200065007800200065006100200063006F006D006D006F0064006F00200063006F006E007300650071007500610074002E002000440075006900730020006100750074006500200069007200750072006500200064006F006C006F007200200069006E00200072006500700072006500680065006E0064006500720069007400200069006E00200076006F006C007500700074006100740065002000760065006C0069007400200065007300730065002000630069006C006C0075006D00200064006F006C006F0072006500200065007500200066007500670069006100740020006E0075006C006C0061002000700061007200690061007400750072002E0020004500780063006500700074006500750072002000730069006E00740020006F006300630061006500630061007400200063007500700069006400610074006100740020006E006F006E002000700072006F006900640065006E0074002C002000730075006E007400200069006E002000630075006C0070006100200071007500690020006F0066006600690063006900610020006400650073006500720075006E00740020006D006F006C006C0069007400200061006E0069006D00200069006400200065007300740020006C00610062006F00720075006D002E0020004C006F00720065006D00200069007000730075006D00200064006F006C006F0072002000730069007400200061006D00650074002C00200063006F006E00730065006300740065007400750072002000610064006900700069007300630069006E006700200065006C00690074002E002000530065006400200064006F00200065006900750073006D006F0064002000740065006D0070006F007200200069006E006300690064006900640075006E00740020007500740020006C00610062006F0072006500200065007400200064006F006C006F007200650020006D00610067006E006100200061006C0069007100750061002E00200055007400200065006E0069006D0020006100640020006D0069006E0069006D002000760065006E00690061006D002C002000710075006900730020006E006F0073007400720075006400200065007800650072006300690074006100740069006F006E00200075006C006C0061006D0063006F0020006C00610062006F0072006900730020006E00690073006900200075007400200061006C0069007100750069007000200065007800200065006100 +~~END~~ + + +select cast(0x0006161 as nvarchar) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Failed to convert from data type varbinary to nvarchar, invalid UTF16 byte sequence - code point 0 not supported)~~ + diff --git a/test/JDBC/expected/cast_nvarchar_test_before_16_5-vu-cleanup.out b/test/JDBC/expected/cast_nvarchar_test_before_16_5-vu-cleanup.out new file mode 100644 index 0000000000..b84f229da8 --- /dev/null +++ b/test/JDBC/expected/cast_nvarchar_test_before_16_5-vu-cleanup.out @@ -0,0 +1,19 @@ +DROP TABLE IF EXISTS TestHash; +GO +DROP type user_defined_varbinary; +GO +DROP type user_defined_nvarchar; +GO +DROP VIEW IF EXISTS dbo.CastDemoView; +GO +DROP FUNCTION IF EXISTS dbo.CastNVarcharToVarbinary; +GO +DROP FUNCTION IF EXISTS dbo.CastVarbinaryToNVarchar; +GO +DROP FUNCTION IF EXISTS dbo.HashMultipleTypes; +GO +DROP PROCEDURE IF EXISTS dbo.PrintHashResults; +GO +DROP VIEW IF EXISTS dbo.HashDemoView; +GO + diff --git a/test/JDBC/expected/cast_nvarchar_test_before_16_5-vu-prepare.out b/test/JDBC/expected/cast_nvarchar_test_before_16_5-vu-prepare.out new file mode 100644 index 0000000000..0c2e397cf2 --- /dev/null +++ b/test/JDBC/expected/cast_nvarchar_test_before_16_5-vu-prepare.out @@ -0,0 +1,71 @@ +CREATE TABLE TestHash( +nvarchar_data nvarchar(32) NOT NULL, +varchar_data varchar(32) NOT NULL, +cast_hashbytes_nvarchar_data AS (cast ( hashbytes('sha1', nvarchar_data) AS varbinary(20) )) PERSISTED NOT NULL, +convert_hashbytes_nvarchar_data AS (convert( varbinary(20), hashbytes('sha1',nvarchar_data))) PERSISTED NOT NULL, +cast_hashbytes_varchar_data AS (cast ( hashbytes('sha1', varchar_data) AS varbinary(20) )) PERSISTED NOT NULL, +convert_hashbytes_varchar_data AS (convert( varbinary(20), hashbytes('sha1',varchar_data))) PERSISTED NOT NULL +); +GO + +-- Function to cast NVARCHAR to VARBINARY +CREATE FUNCTION dbo.CastNVarcharToVarbinary +( + @Input NVARCHAR(MAX) +) +RETURNS VARBINARY(MAX) +AS +BEGIN + RETURN CAST(@Input AS VARBINARY(MAX)); +END +GO + +-- Function to cast VARBINARY to NVARCHAR +CREATE FUNCTION dbo.CastVarbinaryToNVarchar +( + @Input VARBINARY(MAX) +) +RETURNS NVARCHAR(MAX) +AS +BEGIN + RETURN CAST(@Input AS NVARCHAR(MAX)); +END +GO + +-- View that demonstrates both casts +CREATE VIEW dbo.CastDemoView +AS +SELECT + dbo.CastNVarcharToVarbinary(N'Hello, World!') AS NVarcharToVarbinary, + dbo.CastVarbinaryToNVarchar(0x48656C6C6F2C20576F726C6421) AS VarbinaryToNVarchar +GO + + +-- Function to hash different input types +CREATE FUNCTION dbo.HashMultipleTypes +( + @VarcharInput VARCHAR(MAX), + @NVarcharInput NVARCHAR(MAX), + @VarbinaryInput VARBINARY(MAX) +) +RETURNS TABLE +AS +RETURN +( + SELECT + HASHBYTES('SHA2_256', @VarcharInput) AS VarcharHash, + HASHBYTES('SHA2_256', @NVarcharInput) AS NVarcharHash, + HASHBYTES('SHA2_256', @VarbinaryInput) AS VarbinaryHash +) +GO + + +-- View to demonstrate hashing +CREATE VIEW dbo.HashDemoView +AS +SELECT + HASHBYTES('SHA2_256', CAST('Hello' AS VARCHAR(MAX))) AS VarcharHash, + HASHBYTES('SHA2_256', CAST(N'Hello' AS NVARCHAR(MAX))) AS NVarcharHash, + HASHBYTES('SHA2_256', CAST(0x48656C6C6F AS VARBINARY(MAX))) AS VarbinaryHash +GO + diff --git a/test/JDBC/expected/cast_nvarchar_test_before_16_5-vu-verify.out b/test/JDBC/expected/cast_nvarchar_test_before_16_5-vu-verify.out new file mode 100644 index 0000000000..16e32de7ec --- /dev/null +++ b/test/JDBC/expected/cast_nvarchar_test_before_16_5-vu-verify.out @@ -0,0 +1,368 @@ +-- TEST CASE 1: creating a table and then calling hashbytes for nvarchar and varchar input +insert into TestHash values('value1', 'value1'); +GO +~~ROW COUNT: 1~~ + + +SELECT DATALENGTH( nvarchar_data) as nvarchar_data_datalength + , LEN( nvarchar_data) AS nvarchar_data_len + , DATALENGTH( varchar_data) as varchar_data_btyes_datalength + , LEN( varchar_data) AS varchar_data_len + , * +from TestHash; +GO +~~START~~ +int#!#int#!#int#!#int#!#nvarchar#!#varchar#!#varbinary#!#varbinary#!#varbinary#!#varbinary +6#!#6#!#6#!#6#!#value1#!#value1#!#8107759ABABCBFA34BCB02BC4309CAF6354982AB#!#8107759ABABCBFA34BCB02BC4309CAF6354982AB#!#8107759ABABCBFA34BCB02BC4309CAF6354982AB#!#8107759ABABCBFA34BCB02BC4309CAF6354982AB +~~END~~ + +-- TEST CASE 2: Casting nvarchar and varchar with different algorithms using Hashbytes +SELECT hashbytes( 'sha1', 'test string' ) as vary_string, hashbytes( 'sha1', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +661295C9CBF9D6B2F6428414504A8DEED3020641#!#661295C9CBF9D6B2F6428414504A8DEED3020641 +~~END~~ + + +SELECT hashbytes( 'MD2', 'test string' ) as vary_string, hashbytes( 'MD2', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +#!# +~~END~~ + + +SELECT hashbytes( 'MD4', 'test string' ) as vary_string, hashbytes( 'MD4', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +#!# +~~END~~ + + +SELECT hashbytes( 'MD5', 'test string' ) as vary_string, hashbytes( 'MD5', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +6F8DB599DE986FAB7A21625B7916589C#!#6F8DB599DE986FAB7A21625B7916589C +~~END~~ + + +SELECT hashbytes( 'SHA2_256', 'test string' ) as vary_string, hashbytes( 'SHA2_256', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +D5579C46DFCC7F18207013E65B44E4CB4E2C2298F4AC457BA8F82743F31E930B#!#D5579C46DFCC7F18207013E65B44E4CB4E2C2298F4AC457BA8F82743F31E930B +~~END~~ + + +SELECT hashbytes( 'SHA2_512', 'test string' ) as vary_string, hashbytes( 'SHA2_512', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +10E6D647AF44624442F388C2C14A787FF8B17E6165B83D767EC047768D8CBCB71A1A3226E7CC7816BC79C0427D94A9DA688C41A3992C7BF5E4D7CC3E0BE5DBAC#!#10E6D647AF44624442F388C2C14A787FF8B17E6165B83D767EC047768D8CBCB71A1A3226E7CC7816BC79C0427D94A9DA688C41A3992C7BF5E4D7CC3E0BE5DBAC +~~END~~ + + +SELECT hashbytes( 'SHA', 'test string' ) as vary_string, hashbytes( 'SHA', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +661295C9CBF9D6B2F6428414504A8DEED3020641#!#661295C9CBF9D6B2F6428414504A8DEED3020641 +~~END~~ + + +SELECT hashbytes( 'sha1', 'test string') +GO +~~START~~ +varbinary +661295C9CBF9D6B2F6428414504A8DEED3020641 +~~END~~ + +--TEST CASE 3: testing hashbytes via casting a varchar to nvarchar +SELECT hashbytes('sha1',cast('test string' as sys.nvarchar)) +GO +~~START~~ +varbinary +661295C9CBF9D6B2F6428414504A8DEED3020641 +~~END~~ + + + +--TEST CASE 4: Casting function for nvarchar to varbinary +SELECT cast(N'test string' as varbinary); +GO +~~START~~ +varbinary +7400650073007400200073007400720069006E006700 +~~END~~ + + +SELECT cast(cast(cast('ab' AS nvarchar(10)) as varbinary(2)) as nvarchar(2)); +GO +~~START~~ +nvarchar +a +~~END~~ + + +-- Test Case 5: Empty strings and NULL values +SELECT HASHBYTES('SHA1', '') AS empty_varchar, + HASHBYTES('SHA1', N'') AS empty_nvarchar, + HASHBYTES('SHA1', NULL) AS null_input; +GO +~~START~~ +varbinary#!#varbinary#!#varbinary +DA39A3EE5E6B4B0D3255BFEF95601890AFD80709#!#DA39A3EE5E6B4B0D3255BFEF95601890AFD80709#!# +~~END~~ + + +-- Test Case 6: Unicode characters +SELECT HASHBYTES('SHA1', N'こんにちは') AS japanese, + HASHBYTES('SHA1', N'Здравствуйте') AS russian, + HASHBYTES('SHA1', N'🙂😊😀') AS emojis; +GO +~~START~~ +varbinary#!#varbinary#!#varbinary +20427A708C3F6F07CF12AB23557982D9E6D23B61#!#E2D105A2541F2DC6C8B93DF73D07DF30B33FD80A#!#3B114970B215D62CB987A4D5644FEE7001C78234 +~~END~~ + + +-- Test Case 8: Different collations +SELECT HASHBYTES('SHA1', N'hello' COLLATE Latin1_General_CI_AS) AS ci_as, + HASHBYTES('SHA1', N'hello' COLLATE Latin1_General_CS_AS) AS cs_as; +GO +~~START~~ +varbinary#!#varbinary +AAF4C61DDCC5E8A2DABEDE0F3B482CD9AEA9434D#!#AAF4C61DDCC5E8A2DABEDE0F3B482CD9AEA9434D +~~END~~ + + +-- Test Case 9: Combining varchar and nvarchar +SELECT HASHBYTES('SHA1', 'hello' + N'world') AS combined; +GO +~~START~~ +varbinary +6ADFB183A4A2C94A2F92DAB5ADE762A47889A5A1 +~~END~~ + + +-- Test Case 10: Roundtrip conversions +SELECT CAST(CAST(N'test' AS VARBINARY(8)) AS NVARCHAR(4)) AS nvarchar_roundtrip, + CAST(CAST('test' AS VARBINARY(8)) AS VARCHAR(4)) AS varchar_roundtrip; +GO +~~START~~ +nvarchar#!#varchar +test#!#test +~~END~~ + + +-- Test Case 11: CAST and CONVERT between varchar, nvarchar, and varbinary +SELECT CAST(N'hello' AS VARBINARY(10)) AS nvarchar_to_varbinary, + CAST('hello' AS VARBINARY(10)) AS varchar_to_varbinary, + CONVERT(VARBINARY(10), N'hello') AS nvarchar_to_varbinary_convert, + CONVERT(VARBINARY(10), 'hello') AS varchar_to_varbinary_convert; +GO +~~START~~ +varbinary#!#varbinary#!#varbinary#!#varbinary +680065006C006C006F00#!#68656C6C6F#!#68656C6C6F#!#68656C6C6F +~~END~~ + + +-- Test Case 12: Testing with special characters +SELECT HASHBYTES('SHA1', 'Hello, World!') AS varchar_special, + HASHBYTES('SHA1', N'Hello, World!') AS nvarchar_special, + HASHBYTES('SHA1', 'Hello' + CHAR(13) + CHAR(10) + 'World') AS varchar_newline, + HASHBYTES('SHA1', N'Hello' + NCHAR(13) + NCHAR(10) + N'World') AS nvarchar_newline; +GO +~~START~~ +varbinary#!#varbinary#!#varbinary#!#varbinary +0A0A9F2A6772942557AB5355D76AF442F8F65E01#!#0A0A9F2A6772942557AB5355D76AF442F8F65E01#!#62E451F6ED58D1FF234A05B8467C0CEB1D4B285F#!#62E451F6ED58D1FF234A05B8467C0CEB1D4B285F +~~END~~ + + +-- Test Case 13: NVARCHAR -> VARBINARY -> VARCHAR -> NVARCHAR -> VARBINARY +SELECT CAST( + CAST( + CAST( + CAST(N'Hello World' AS VARBINARY(100)) + AS VARCHAR(100)) + AS NVARCHAR(100)) +AS VARBINARY(100)) AS four_casts; +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Failed to convert from data type varbinary to varchar, invalid byte sequence for encoding "WIN1252": 0x00)~~ + + +-- Test Case 14: VARCHAR -> NVARCHAR -> VARBINARY -> NVARCHAR -> VARCHAR +SELECT CAST( + CAST( + CAST( + CAST('Test String' AS NVARCHAR(50)) + AS VARBINARY(50)) + AS NVARCHAR(50)) +AS VARCHAR(50)) AS four_casts; +GO +~~START~~ +varchar +Test String +~~END~~ + + +-- Test Case 15: Implicit conversion from data type nvarchar to varbinary is not allowed. +DECLARE @a varbinary(10); SET @a = CAST(N'21' AS nvarchar(10)); SELECT @a +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Implicit conversion from data type nvarchar to varbinary is not allowed. Use the CONVERT function to run this query.)~~ + + +-- Test Case 16: Casting with UDT on nvarchar -> varbinary, UDT on varbinary to nvarchar, UDT on nvarchar to UDT on varbinary +create type user_defined_nvarchar from nvarchar(50); +select cast(cast(N'test string' as user_defined_nvarchar) as varbinary) +GO +~~START~~ +varbinary +7400650073007400200073007400720069006E006700 +~~END~~ + + +create type user_defined_varbinary from varbinary(50); +select cast(cast(0x7400650073007400200073007400720069006E006700 as user_defined_varbinary) as nvarchar) +GO +~~START~~ +nvarchar +test string +~~END~~ + + +select cast(cast(N'test string' as user_defined_nvarchar) as user_defined_varbinary) +go +~~START~~ +varbinary +7400650073007400200073007400720069006E006700 +~~END~~ + +-- Test Case 17: NVARCHAR-> BINARY +select cast(N'test string' as binary) +GO +~~START~~ +binary +7400650073007400200073007400720069006E0067000000000000000000 +~~END~~ + +-- Test Case 18: NVARCHAR-> User Defined varbinary +select cast(N'test string' as user_defined_varbinary) +GO +~~START~~ +varbinary +7400650073007400200073007400720069006E006700 +~~END~~ + +-- Test Case 19: User defined hashbytes function +create function dbo.hashbytes(@data sys.varchar)returns sys.varchar AS BEGIN return "dummy hashbytes";END +GO +SELECT hashbytes( 'SHA', 'test string' ) as vary_string, hashbytes( 'SHA', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +661295C9CBF9D6B2F6428414504A8DEED3020641#!#661295C9CBF9D6B2F6428414504A8DEED3020641 +~~END~~ + +select hashbytes('abc') +GO +~~START~~ +varchar +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: column "dummy hashbytes" does not exist)~~ + +drop function dbo.hashbytes +GO + + +-- Test 20: Calling the function, procedure, views from prepare scripts +-- Test CastNVarcharToVarbinary function +DECLARE @TestString NVARCHAR(100) = N'Test String'; +DECLARE @BinaryResult VARBINARY(MAX); +SET @BinaryResult = dbo.CastNVarcharToVarbinary(@TestString); +select cast (@BinaryResult as nvarchar) +GO +~~START~~ +nvarchar +Test String +~~END~~ + + + +-- Test CastVarbinaryToNVarchar function +DECLARE @TestBinary VARBINARY(100) = 0x54657374537472696E67; -- 'Test String' in ASCII +DECLARE @StringResult NVARCHAR(MAX); +SET @StringResult = dbo.CastVarbinaryToNVarchar(@TestBinary); +select cast (@StringResult as nvarchar) +GO +~~START~~ +nvarchar +敔瑳瑓楲杮 +~~END~~ + + + +-- Test CastDemoView +DECLARE @ViewResult TABLE ( + NVarcharToVarbinary VARBINARY(MAX), + VarbinaryToNVarchar NVARCHAR(MAX) +); +INSERT INTO @ViewResult +SELECT * FROM dbo.CastDemoView; +go +~~ROW COUNT: 1~~ + + +-- TEST CASE 21: Assigned Casting +DECLARE @NVarcharValue NVARCHAR(100) = N'Hello, World!'; +DECLARE @AssignedVarbinary VARBINARY(100); +SET @AssignedVarbinary = CAST(@NVarcharValue AS VARBINARY(100)); +select CAST(@AssignedVarbinary AS NVARCHAR(100)); +GO +~~START~~ +nvarchar +Hello, World! +~~END~~ + + + + +--TEST CASE 22: Calling hashbytes via function, procedure, views +-- Test the HashMultipleTypes function +DECLARE @TestVarchar VARCHAR(10) = 'Test'; +DECLARE @TestNVarchar NVARCHAR(10) = N'Test'; +DECLARE @TestVarbinary VARBINARY(10) = 0x54657374; -- 'Test' in ASCII +SELECT * FROM dbo.HashMultipleTypes(@TestVarchar, @TestNVarchar, @TestVarbinary); +GO +~~START~~ +varbinary#!#varbinary#!#varbinary +532EAABD9574880DBF76B9B8CC00832C20A6EC113D682299550D7A6E0F345E25#!#532EAABD9574880DBF76B9B8CC00832C20A6EC113D682299550D7A6E0F345E25#!#532EAABD9574880DBF76B9B8CC00832C20A6EC113D682299550D7A6E0F345E25 +~~END~~ + +-- Test the HashDemoView +SELECT * FROM dbo.HashDemoView; +GO +~~START~~ +varbinary#!#varbinary#!#varbinary +185F8DB32271FE25F561A6FC938B2E264306EC304EDA518007D1764826381969#!#185F8DB32271FE25F561A6FC938B2E264306EC304EDA518007D1764826381969#!#185F8DB32271FE25F561A6FC938B2E264306EC304EDA518007D1764826381969 +~~END~~ + + +--TEST CASE 23: BINARY TO NVARCHAR +select cast(cast(N'test string' as binary) as nvarchar) +GO +~~START~~ +nvarchar +test string +~~END~~ + + + diff --git a/test/JDBC/expected/concat-before-15_9-or-16_5-vu-verify.out b/test/JDBC/expected/concat-before-15_9-or-16_5-vu-verify.out index d833e844ee..6fcaf01fed 100644 --- a/test/JDBC/expected/concat-before-15_9-or-16_5-vu-verify.out +++ b/test/JDBC/expected/concat-before-15_9-or-16_5-vu-verify.out @@ -421,7 +421,7 @@ SELECT CONCAT( 'a', 'b', CAST('🙂🙂' AS nvarchar), 'd', 'e', CAST('f' AS cha GO ~~START~~ nvarchar -ab🙂🙂def比尔hijklmnopqrstuvwxyzABCDEFGHIJKLMefOPQRST🙂🙂VWXYZ0123456789.,-_!@#$%^&*()[]{}<>/\\|:;"\?+=~`abcdefg +ab🙂🙂def比尔hijklmnopqrstuvwxyzABCDEFGHIJKLM晥OPQRST🙂🙂VWXYZ0123456789.,-_!@#$%^&*()[]{}<>/\\|:;"\?+=~`abcde杦 ~~END~~ @@ -1165,16 +1165,16 @@ SELECT CONCAT(col_nvarchar, col_binary) from babel_3409_concat_t1 ORDER BY id GO ~~START~~ nvarchar -abcab -🙂defghicd -🙂🙂ef -比尔·拉gh -莫斯ip +abc扡 +🙂defghi摣 +🙂🙂晥 +比尔·拉桧 +莫斯灩 -Anikaitqr +Anikait牱 -Agrawalrs +Agrawal獲 ~~END~~ @@ -1182,16 +1182,16 @@ SELECT CONCAT(col_nvarchar, col_varbinary) from babel_3409_concat_t1 ORDER BY id GO ~~START~~ nvarchar -abcab -🙂defghicd -🙂🙂ef -比尔·拉gh -莫斯ip +abc扡 +🙂defghi摣 +🙂🙂晥 +比尔·拉桧 +莫斯灩 -Anikaitqr +Anikait牱 -Agrawalrs +Agrawal獲 ~~END~~ @@ -1483,16 +1483,16 @@ EXEC babel_3409_concat_dep_proc2 GO ~~START~~ nvarchar -abc12.00002000-12-12 12:43:102000-12-12 12:43:10ab2000-12-1212:43:102000-12-12 12:43:10.1234 +10:00 -🙂defghi13.00002000-12-13 12:43:102000-12-13 12:43:10cd2000-12-1312:43:102000-12-13 12:43:10.1234 +10:00 -🙂🙂14.00002000-12-14 12:43:102000-12-14 12:43:10ef2000-12-1412:43:102000-12-14 12:43:10.1234 +10:00 -比尔·拉15.00002000-12-15 12:43:102000-12-15 12:43:10gh2000-12-1512:43:102000-12-15 12:43:10.1234 +10:00 -莫斯16.00002000-12-16 12:43:102000-12-16 12:43:10ip2000-12-1612:43:102000-12-16 12:43:10.1234 +10:00 +abc12.00002000-12-12 12:43:102000-12-12 12:43:10扡2000-12-1212:43:102000-12-12 12:43:10.1234 +10:00 +🙂defghi13.00002000-12-13 12:43:102000-12-13 12:43:10摣2000-12-1312:43:102000-12-13 12:43:10.1234 +10:00 +🙂🙂14.00002000-12-14 12:43:102000-12-14 12:43:10晥2000-12-1412:43:102000-12-14 12:43:10.1234 +10:00 +比尔·拉15.00002000-12-15 12:43:102000-12-15 12:43:10桧2000-12-1512:43:102000-12-15 12:43:10.1234 +10:00 +莫斯16.00002000-12-16 12:43:102000-12-16 12:43:10灩2000-12-1612:43:102000-12-16 12:43:10.1234 +10:00 -Anikait17.00002000-12-17 12:43:102000-12-17 12:43:10qr2000-12-1712:43:102000-12-17 12:43:10.1234 +10:00 +Anikait17.00002000-12-17 12:43:102000-12-17 12:43:10牱2000-12-1712:43:102000-12-17 12:43:10.1234 +10:00 -Agrawal18.00002000-12-18 12:43:102000-12-18 12:43:10rs2000-12-1812:43:102000-12-18 12:43:10.1234 +10:00 +Agrawal18.00002000-12-18 12:43:102000-12-18 12:43:10獲2000-12-1812:43:102000-12-18 12:43:10.1234 +10:00 ~~END~~ @@ -1500,7 +1500,7 @@ SELECT babel_3409_concat_dep_func2() GO ~~START~~ nvarchar -abcababcabc +abc扡abcabc ~~END~~ diff --git a/test/JDBC/expected/concat-vu-verify.out b/test/JDBC/expected/concat-vu-verify.out index baddf13ebd..02afd2382a 100644 --- a/test/JDBC/expected/concat-vu-verify.out +++ b/test/JDBC/expected/concat-vu-verify.out @@ -421,7 +421,7 @@ SELECT CONCAT( 'a', 'b', CAST('🙂🙂' AS nvarchar), 'd', 'e', CAST('f' AS cha GO ~~START~~ nvarchar -ab🙂🙂def比尔hijklmnopqrstuvwxyzABCDEFGHIJKLMefOPQRST🙂🙂VWXYZ0123456789.,-_!@#$%^&*()[]{}<>/\\|:;"\?+=~`abcdefg +ab🙂🙂def比尔hijklmnopqrstuvwxyzABCDEFGHIJKLM晥OPQRST🙂🙂VWXYZ0123456789.,-_!@#$%^&*()[]{}<>/\\|:;"\?+=~`abcde杦 ~~END~~ @@ -1230,16 +1230,16 @@ SELECT CONCAT(col_nvarchar, col_binary) from babel_3409_concat_t1 ORDER BY id GO ~~START~~ nvarchar -abcab -🙂defghicd -🙂🙂ef -比尔·拉gh -莫斯ip +abc扡 +🙂defghi摣 +🙂🙂晥 +比尔·拉桧 +莫斯灩 -Anikaitqr +Anikait牱 -Agrawalrs +Agrawal獲 ~~END~~ @@ -1247,16 +1247,16 @@ SELECT CONCAT(col_nvarchar, col_varbinary) from babel_3409_concat_t1 ORDER BY id GO ~~START~~ nvarchar -abcab -🙂defghicd -🙂🙂ef -比尔·拉gh -莫斯ip +abc扡 +🙂defghi摣 +🙂🙂晥 +比尔·拉桧 +莫斯灩 -Anikaitqr +Anikait牱 -Agrawalrs +Agrawal獲 ~~END~~ @@ -1579,16 +1579,16 @@ EXEC babel_3409_concat_dep_proc2 GO ~~START~~ nvarchar -abc12.00002000-12-12 12:43:102000-12-12 12:43:10ab2000-12-1212:43:102000-12-12 12:43:10.1234 +10:00 -🙂defghi13.00002000-12-13 12:43:102000-12-13 12:43:10cd2000-12-1312:43:102000-12-13 12:43:10.1234 +10:00 -🙂🙂14.00002000-12-14 12:43:102000-12-14 12:43:10ef2000-12-1412:43:102000-12-14 12:43:10.1234 +10:00 -比尔·拉15.00002000-12-15 12:43:102000-12-15 12:43:10gh2000-12-1512:43:102000-12-15 12:43:10.1234 +10:00 -莫斯16.00002000-12-16 12:43:102000-12-16 12:43:10ip2000-12-1612:43:102000-12-16 12:43:10.1234 +10:00 +abc12.00002000-12-12 12:43:102000-12-12 12:43:10扡2000-12-1212:43:102000-12-12 12:43:10.1234 +10:00 +🙂defghi13.00002000-12-13 12:43:102000-12-13 12:43:10摣2000-12-1312:43:102000-12-13 12:43:10.1234 +10:00 +🙂🙂14.00002000-12-14 12:43:102000-12-14 12:43:10晥2000-12-1412:43:102000-12-14 12:43:10.1234 +10:00 +比尔·拉15.00002000-12-15 12:43:102000-12-15 12:43:10桧2000-12-1512:43:102000-12-15 12:43:10.1234 +10:00 +莫斯16.00002000-12-16 12:43:102000-12-16 12:43:10灩2000-12-1612:43:102000-12-16 12:43:10.1234 +10:00 -Anikait17.00002000-12-17 12:43:102000-12-17 12:43:10qr2000-12-1712:43:102000-12-17 12:43:10.1234 +10:00 +Anikait17.00002000-12-17 12:43:102000-12-17 12:43:10牱2000-12-1712:43:102000-12-17 12:43:10.1234 +10:00 -Agrawal18.00002000-12-18 12:43:102000-12-18 12:43:10rs2000-12-1812:43:102000-12-18 12:43:10.1234 +10:00 +Agrawal18.00002000-12-18 12:43:102000-12-18 12:43:10獲2000-12-1812:43:102000-12-18 12:43:10.1234 +10:00 ~~END~~ @@ -1596,7 +1596,7 @@ SELECT babel_3409_concat_dep_func2() GO ~~START~~ nvarchar -abcababcabc +abc扡abcabc ~~END~~ diff --git a/test/JDBC/expected/concat_ws-before-15_9-or-16_5-vu-verify.out b/test/JDBC/expected/concat_ws-before-15_9-or-16_5-vu-verify.out index 61124bb7e9..d0d3ae2a99 100644 --- a/test/JDBC/expected/concat_ws-before-15_9-or-16_5-vu-verify.out +++ b/test/JDBC/expected/concat_ws-before-15_9-or-16_5-vu-verify.out @@ -790,7 +790,7 @@ SELECT CONCAT_WS('-', 'a', 'b', CAST('🙂🙂' AS nvarchar), 'd', 'e', CAST('f' GO ~~START~~ nvarchar -a-b-🙂🙂-d-e-f-比尔-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-A-B-C-D-E-F-G-H-I-J-K-L-M-ef-O-P-Q-R-S-T-🙂🙂-V-W-X-Y-Z-0-1-2-3-4-5-6-7-8-9-.-,---_-!-@-#-$-%-^-&-*-(-)-[-]-{-}-<->-/-\\-|-:-;-"-\-?-+-=-~-`-a-b-c-d-fg +a-b-🙂🙂-d-e-f-比尔-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-A-B-C-D-E-F-G-H-I-J-K-L-M-晥-O-P-Q-R-S-T-🙂🙂-V-W-X-Y-Z-0-1-2-3-4-5-6-7-8-9-.-,---_-!-@-#-$-%-^-&-*-(-)-[-]-{-}-<->-/-\\-|-:-;-"-\-?-+-=-~-`-a-b-c-d-杦 ~~END~~ @@ -798,7 +798,7 @@ SELECT CONCAT_WS(N'-', 'a', 'b', CAST('🙂🙂' AS varchar), 'd', 'e', CAST('f' GO ~~START~~ nvarchar -a-b-🙂🙂-d-e-f-比尔-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-A-B-C-D-E-F-G-H-I-J-K-L-M-ef-O-P-Q-R-S-T-🙂🙂-V-W-X-Y-Z-0-1-2-3-4-5-6-7-8-9-.-,---_-!-@-#-$-%-^-&-*-(-)-[-]-{-}-<->-/-\\-|-:-;-"-\-?-+-=-~-`-a-b-c-d-fg +a-b-🙂🙂-d-e-f-比尔-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-A-B-C-D-E-F-G-H-I-J-K-L-M-晥-O-P-Q-R-S-T-🙂🙂-V-W-X-Y-Z-0-1-2-3-4-5-6-7-8-9-.-,---_-!-@-#-$-%-^-&-*-(-)-[-]-{-}-<->-/-\\-|-:-;-"-\-?-+-=-~-`-a-b-c-d-杦 ~~END~~ @@ -1382,16 +1382,16 @@ SELECT CONCAT_WS(col_nvarchar, col_varchar, col_binary) from babel_3409_concat_w GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -1416,16 +1416,16 @@ SELECT CONCAT_WS(col_nvarchar, col_varchar, col_varbinary) from babel_3409_conca GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -2277,16 +2277,16 @@ SELECT CONCAT_WS(col_varchar, col_nvarchar, col_binary) from babel_3409_concat_w GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -2294,16 +2294,16 @@ SELECT CONCAT_WS(col_nvarchar, col_nvarchar, col_binary) from babel_3409_concat_ GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -2311,16 +2311,16 @@ SELECT CONCAT_WS(col_varchar, col_nvarchar, col_varbinary) from babel_3409_conca GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -2328,16 +2328,16 @@ SELECT CONCAT_WS(col_nvarchar, col_nvarchar, col_varbinary) from babel_3409_conc GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -3009,16 +3009,16 @@ EXEC babel_3409_concat_ws_dep_proc2 GO ~~START~~ nvarchar -abc-12.0000-2000-12-12 12:43:10-2000-12-12 12:43:10-ab-2000-12-12-12:43:10-2000-12-12 12:43:10.1234 +10:00 -🙂defghi-13.0000-2000-12-13 12:43:10-2000-12-13 12:43:10-cd-2000-12-13-12:43:10-2000-12-13 12:43:10.1234 +10:00 -🙂🙂-14.0000-2000-12-14 12:43:10-2000-12-14 12:43:10-ef-2000-12-14-12:43:10-2000-12-14 12:43:10.1234 +10:00 -比尔·拉-15.0000-2000-12-15 12:43:10-2000-12-15 12:43:10-gh-2000-12-15-12:43:10-2000-12-15 12:43:10.1234 +10:00 -莫斯-16.0000-2000-12-16 12:43:10-2000-12-16 12:43:10-ip-2000-12-16-12:43:10-2000-12-16 12:43:10.1234 +10:00 +abc-12.0000-2000-12-12 12:43:10-2000-12-12 12:43:10-扡-2000-12-12-12:43:10-2000-12-12 12:43:10.1234 +10:00 +🙂defghi-13.0000-2000-12-13 12:43:10-2000-12-13 12:43:10-摣-2000-12-13-12:43:10-2000-12-13 12:43:10.1234 +10:00 +🙂🙂-14.0000-2000-12-14 12:43:10-2000-12-14 12:43:10-晥-2000-12-14-12:43:10-2000-12-14 12:43:10.1234 +10:00 +比尔·拉-15.0000-2000-12-15 12:43:10-2000-12-15 12:43:10-桧-2000-12-15-12:43:10-2000-12-15 12:43:10.1234 +10:00 +莫斯-16.0000-2000-12-16 12:43:10-2000-12-16 12:43:10-灩-2000-12-16-12:43:10-2000-12-16 12:43:10.1234 +10:00 -Anikait-17.0000-2000-12-17 12:43:10-2000-12-17 12:43:10-qr-2000-12-17-12:43:10-2000-12-17 12:43:10.1234 +10:00 +Anikait-17.0000-2000-12-17 12:43:10-2000-12-17 12:43:10-牱-2000-12-17-12:43:10-2000-12-17 12:43:10.1234 +10:00 -Agrawal-18.0000-2000-12-18 12:43:10-2000-12-18 12:43:10-rs-2000-12-18-12:43:10-2000-12-18 12:43:10.1234 +10:00 +Agrawal-18.0000-2000-12-18 12:43:10-2000-12-18 12:43:10-獲-2000-12-18-12:43:10-2000-12-18 12:43:10.1234 +10:00 ~~END~~ @@ -3026,7 +3026,7 @@ SELECT babel_3409_concat_ws_dep_func2() GO ~~START~~ nvarchar -abc-ab-abc-abc +abc-扡-abc-abc ~~END~~ diff --git a/test/JDBC/expected/concat_ws-vu-verify.out b/test/JDBC/expected/concat_ws-vu-verify.out index 72fd6e577b..273a0232fe 100644 --- a/test/JDBC/expected/concat_ws-vu-verify.out +++ b/test/JDBC/expected/concat_ws-vu-verify.out @@ -790,7 +790,7 @@ SELECT CONCAT_WS('-', 'a', 'b', CAST('🙂🙂' AS nvarchar), 'd', 'e', CAST('f' GO ~~START~~ nvarchar -a-b-🙂🙂-d-e-f-比尔-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-A-B-C-D-E-F-G-H-I-J-K-L-M-ef-O-P-Q-R-S-T-🙂🙂-V-W-X-Y-Z-0-1-2-3-4-5-6-7-8-9-.-,---_-!-@-#-$-%-^-&-*-(-)-[-]-{-}-<->-/-\\-|-:-;-"-\-?-+-=-~-`-a-b-c-d-fg +a-b-🙂🙂-d-e-f-比尔-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-A-B-C-D-E-F-G-H-I-J-K-L-M-晥-O-P-Q-R-S-T-🙂🙂-V-W-X-Y-Z-0-1-2-3-4-5-6-7-8-9-.-,---_-!-@-#-$-%-^-&-*-(-)-[-]-{-}-<->-/-\\-|-:-;-"-\-?-+-=-~-`-a-b-c-d-杦 ~~END~~ @@ -798,7 +798,7 @@ SELECT CONCAT_WS(N'-', 'a', 'b', CAST('🙂🙂' AS varchar), 'd', 'e', CAST('f' GO ~~START~~ nvarchar -a-b-🙂🙂-d-e-f-比尔-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-A-B-C-D-E-F-G-H-I-J-K-L-M-ef-O-P-Q-R-S-T-🙂🙂-V-W-X-Y-Z-0-1-2-3-4-5-6-7-8-9-.-,---_-!-@-#-$-%-^-&-*-(-)-[-]-{-}-<->-/-\\-|-:-;-"-\-?-+-=-~-`-a-b-c-d-fg +a-b-🙂🙂-d-e-f-比尔-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-A-B-C-D-E-F-G-H-I-J-K-L-M-晥-O-P-Q-R-S-T-🙂🙂-V-W-X-Y-Z-0-1-2-3-4-5-6-7-8-9-.-,---_-!-@-#-$-%-^-&-*-(-)-[-]-{-}-<->-/-\\-|-:-;-"-\-?-+-=-~-`-a-b-c-d-杦 ~~END~~ @@ -1416,16 +1416,16 @@ SELECT CONCAT_WS(col_nvarchar, col_varchar, col_binary) from babel_3409_concat_w GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -1450,16 +1450,16 @@ SELECT CONCAT_WS(col_nvarchar, col_varchar, col_varbinary) from babel_3409_conca GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -2407,16 +2407,16 @@ SELECT CONCAT_WS(col_varchar, col_nvarchar, col_binary) from babel_3409_concat_w GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -2424,16 +2424,16 @@ SELECT CONCAT_WS(col_nvarchar, col_nvarchar, col_binary) from babel_3409_concat_ GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -2441,16 +2441,16 @@ SELECT CONCAT_WS(col_varchar, col_nvarchar, col_varbinary) from babel_3409_conca GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -2458,16 +2458,16 @@ SELECT CONCAT_WS(col_nvarchar, col_nvarchar, col_varbinary) from babel_3409_conc GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -3232,16 +3232,16 @@ EXEC babel_3409_concat_ws_dep_proc2 GO ~~START~~ nvarchar -abc-12.0000-2000-12-12 12:43:10-2000-12-12 12:43:10-ab-2000-12-12-12:43:10-2000-12-12 12:43:10.1234 +10:00 -🙂defghi-13.0000-2000-12-13 12:43:10-2000-12-13 12:43:10-cd-2000-12-13-12:43:10-2000-12-13 12:43:10.1234 +10:00 -🙂🙂-14.0000-2000-12-14 12:43:10-2000-12-14 12:43:10-ef-2000-12-14-12:43:10-2000-12-14 12:43:10.1234 +10:00 -比尔·拉-15.0000-2000-12-15 12:43:10-2000-12-15 12:43:10-gh-2000-12-15-12:43:10-2000-12-15 12:43:10.1234 +10:00 -莫斯-16.0000-2000-12-16 12:43:10-2000-12-16 12:43:10-ip-2000-12-16-12:43:10-2000-12-16 12:43:10.1234 +10:00 +abc-12.0000-2000-12-12 12:43:10-2000-12-12 12:43:10-扡-2000-12-12-12:43:10-2000-12-12 12:43:10.1234 +10:00 +🙂defghi-13.0000-2000-12-13 12:43:10-2000-12-13 12:43:10-摣-2000-12-13-12:43:10-2000-12-13 12:43:10.1234 +10:00 +🙂🙂-14.0000-2000-12-14 12:43:10-2000-12-14 12:43:10-晥-2000-12-14-12:43:10-2000-12-14 12:43:10.1234 +10:00 +比尔·拉-15.0000-2000-12-15 12:43:10-2000-12-15 12:43:10-桧-2000-12-15-12:43:10-2000-12-15 12:43:10.1234 +10:00 +莫斯-16.0000-2000-12-16 12:43:10-2000-12-16 12:43:10-灩-2000-12-16-12:43:10-2000-12-16 12:43:10.1234 +10:00 -Anikait-17.0000-2000-12-17 12:43:10-2000-12-17 12:43:10-qr-2000-12-17-12:43:10-2000-12-17 12:43:10.1234 +10:00 +Anikait-17.0000-2000-12-17 12:43:10-2000-12-17 12:43:10-牱-2000-12-17-12:43:10-2000-12-17 12:43:10.1234 +10:00 -Agrawal-18.0000-2000-12-18 12:43:10-2000-12-18 12:43:10-rs-2000-12-18-12:43:10-2000-12-18 12:43:10.1234 +10:00 +Agrawal-18.0000-2000-12-18 12:43:10-2000-12-18 12:43:10-獲-2000-12-18-12:43:10-2000-12-18 12:43:10.1234 +10:00 ~~END~~ @@ -3249,7 +3249,7 @@ SELECT babel_3409_concat_ws_dep_func2() GO ~~START~~ nvarchar -abc-ab-abc-abc +abc-扡-abc-abc ~~END~~ diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/BABEL-1206.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/BABEL-1206.out index 3bbb0cb375..d5e3a243f0 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/BABEL-1206.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/BABEL-1206.out @@ -87,16 +87,14 @@ go insert into babel_1206_t3 values (0xaaa); go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: Failed to convert from data type varbinary to varchar, invalid byte sequence for encoding "GBK": 0xaa)~~ +~~ROW COUNT: 1~~ --should throw an error because of duplicate index key insert into babel_1206_t3 values (0xaaa); go -~~ERROR (Code: 33557097)~~ +~~ERROR (Code: 2627)~~ -~~ERROR (Message: Failed to convert from data type varbinary to varchar, invalid byte sequence for encoding "GBK": 0xaa)~~ +~~ERROR (Message: duplicate key value violates unique constraint "babel_1206_t3_i3")~~ drop table babel_1265_t1; diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/babel_datatype.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/babel_datatype.out index feb5e8f4bf..a9770af423 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/babel_datatype.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/babel_datatype.out @@ -2044,7 +2044,7 @@ select cast(cast('a' AS nvarchar(10)) as varbinary(2)); GO ~~START~~ varbinary -61 +6100 ~~END~~ select cast(cast(cast('a' AS nvarchar(10)) as varbinary(2)) as nvarchar(2)); @@ -2058,28 +2058,28 @@ select cast(cast('ab' AS nvarchar(10)) as varbinary(2)); GO ~~START~~ varbinary -6162 +6100 ~~END~~ select cast(cast(cast('ab' AS nvarchar(10)) as varbinary(2)) as nvarchar(2)); GO ~~START~~ nvarchar -ab +a ~~END~~ select cast(cast('abc' AS nvarchar(10)) as varbinary(2)); GO ~~START~~ varbinary -6162 +6100 ~~END~~ select cast(cast(cast('abc' AS nvarchar(10)) as varbinary(2)) as nvarchar(2)); GO ~~START~~ nvarchar -ab +a ~~END~~ @@ -2211,28 +2211,28 @@ select cast(cast('ab' AS nvarchar(10)) as binary(2)); GO ~~START~~ binary -6162 +6100 ~~END~~ select cast(cast(cast('ab' AS nvarchar(10)) as binary(2)) as nvarchar(2)); GO ~~START~~ nvarchar -ab +a ~~END~~ select cast(cast('abc' AS nvarchar(10)) as binary(2)); GO ~~START~~ binary -6162 +6100 ~~END~~ select cast(cast(cast('abc' AS nvarchar(10)) as binary(2)) as nvarchar(2)); GO ~~START~~ nvarchar -ab +a ~~END~~ diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/cast_nvarchar_test-vu-verify.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/cast_nvarchar_test-vu-verify.out new file mode 100644 index 0000000000..a587eccd56 --- /dev/null +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/cast_nvarchar_test-vu-verify.out @@ -0,0 +1,357 @@ + + + + + + + + + + +-- to do in hashbytes pr +-- -- TEST CASE 1: creating a table and then calling hashbytes for nvarchar and varchar input +-- insert into TestHash values('value1', 'value1'); +-- GO +-- SELECT DATALENGTH( nvarchar_data) as nvarchar_data_datalength +-- , LEN( nvarchar_data) AS nvarchar_data_len +-- , DATALENGTH( varchar_data) as varchar_data_btyes_datalength +-- , LEN( varchar_data) AS varchar_data_len +-- , * +-- from TestHash; +-- GO +-- -- TEST CASE 2: Casting nvarchar and varchar with different algorithms using Hashbytes +-- SELECT hashbytes( 'sha1', 'test string' ) as vary_string, hashbytes( 'sha1', N'test string' ) as unicode_string +-- GO +-- SELECT hashbytes( 'MD2', 'test string' ) as vary_string, hashbytes( 'MD2', N'test string' ) as unicode_string +-- GO +-- SELECT hashbytes( 'MD4', 'test string' ) as vary_string, hashbytes( 'MD4', N'test string' ) as unicode_string +-- GO +-- SELECT hashbytes( 'MD5', 'test string' ) as vary_string, hashbytes( 'MD5', N'test string' ) as unicode_string +-- GO +-- SELECT hashbytes( 'SHA2_256', 'test string' ) as vary_string, hashbytes( 'SHA2_256', N'test string' ) as unicode_string +-- GO +-- SELECT hashbytes( 'SHA2_512', 'test string' ) as vary_string, hashbytes( 'SHA2_512', N'test string' ) as unicode_string +-- GO +-- SELECT hashbytes( 'SHA', 'test string' ) as vary_string, hashbytes( 'SHA', N'test string' ) as unicode_string +-- GO +-- SELECT hashbytes( 'sha1', 'test string') +-- GO +-- --TEST CASE 3: testing hashbytes via casting a varchar to nvarchar +-- SELECT hashbytes('sha1',cast('test string' as sys.nvarchar)) +-- GO +--TEST CASE 4: Casting function for nvarchar to varbinary +SELECT cast(N'test string' as varbinary); +GO +~~START~~ +varbinary +7400650073007400200073007400720069006E006700 +~~END~~ + + +SELECT cast(cast(cast('ab' AS nvarchar(10)) as varbinary(2)) as nvarchar(2)); +GO +~~START~~ +nvarchar +a +~~END~~ + + + + + + +-- to do in hashbytes PR +-- -- Test Case 5: Empty strings and NULL values +-- SELECT HASHBYTES('SHA1', '') AS empty_varchar, +-- HASHBYTES('SHA1', N'') AS empty_nvarchar, +-- HASHBYTES('SHA1', NULL) AS null_input; +-- GO +-- -- Test Case 6: Unicode characters +-- SELECT HASHBYTES('SHA1', N'こんにちは') AS japanese, +-- HASHBYTES('SHA1', N'Здравствуйте') AS russian, +-- HASHBYTES('SHA1', N'🙂😊😀') AS emojis; +-- GO +-- -- Test Case 8: Different collations +-- SELECT HASHBYTES('SHA1', N'hello' COLLATE Latin1_General_CI_AS) AS ci_as, +-- HASHBYTES('SHA1', N'hello' COLLATE Latin1_General_CS_AS) AS cs_as; +-- GO +-- -- Test Case 9: Combining varchar and nvarchar +-- SELECT HASHBYTES('SHA1', 'hello' + N'world') AS combined; +-- GO +-- Test Case 10: Roundtrip conversions +SELECT CAST(CAST(N'test' AS VARBINARY(8)) AS NVARCHAR(4)) AS nvarchar_roundtrip, + CAST(CAST('test' AS VARBINARY(8)) AS VARCHAR(4)) AS varchar_roundtrip; +GO +~~START~~ +nvarchar#!#varchar +test#!#test +~~END~~ + + +-- Test Case 11: CAST and CONVERT between varchar, nvarchar, and varbinary +SELECT CAST(N'hello' AS VARBINARY(10)) AS nvarchar_to_varbinary, + CAST('hello' AS VARBINARY(10)) AS varchar_to_varbinary, + CONVERT(VARBINARY(10), N'hello') AS nvarchar_to_varbinary_convert, + CONVERT(VARBINARY(10), 'hello') AS varchar_to_varbinary_convert; +GO +~~START~~ +varbinary#!#varbinary#!#varbinary#!#varbinary +680065006C006C006F00#!#68656C6C6F#!#68656C6C6F#!#68656C6C6F +~~END~~ + + + +-- to do in hashbytes PR +-- -- Test Case 12: Testing with special characters +-- SELECT HASHBYTES('SHA1', 'Hello, World!') AS varchar_special, +-- HASHBYTES('SHA1', N'Hello, World!') AS nvarchar_special, +-- HASHBYTES('SHA1', 'Hello' + CHAR(13) + CHAR(10) + 'World') AS varchar_newline, +-- HASHBYTES('SHA1', N'Hello' + NCHAR(13) + NCHAR(10) + N'World') AS nvarchar_newline; +-- GO +-- Test Case 13: NVARCHAR -> VARBINARY -> VARCHAR -> NVARCHAR -> VARBINARY +SELECT CAST( + CAST( + CAST( + CAST(N'Hello World' AS VARBINARY(100)) + AS VARCHAR(100)) + AS NVARCHAR(100)) +AS VARBINARY(100)) AS four_casts; +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Failed to convert from data type varbinary to varchar, invalid byte sequence for encoding "GBK": 0x00)~~ + + +-- Test Case 14: VARCHAR -> NVARCHAR -> VARBINARY -> NVARCHAR -> VARCHAR +SELECT CAST( + CAST( + CAST( + CAST('Test String' AS NVARCHAR(50)) + AS VARBINARY(50)) + AS NVARCHAR(50)) +AS VARCHAR(50)) AS four_casts; +GO +~~START~~ +varchar +Test String +~~END~~ + + +-- Test Case 15: Implicit conversion from data type nvarchar to varbinary is not allowed. +DECLARE @a varbinary(10); SET @a = CAST(N'21' AS nvarchar(10)); SELECT @a +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Implicit conversion from data type nvarchar to varbinary is not allowed. Use the CONVERT function to run this query.)~~ + + +-- Test Case 16: Casting with UDT on nvarchar -> varbinary, UDT on varbinary to nvarchar, UDT on nvarchar to UDT on varbinary +create type user_defined_nvarchar from nvarchar(50); +select cast(cast(N'test string' as user_defined_nvarchar) as varbinary) +GO +~~START~~ +varbinary +7400650073007400200073007400720069006E006700 +~~END~~ + + +create type user_defined_varbinary from varbinary(50); +select cast(cast(0x7400650073007400200073007400720069006E006700 as user_defined_varbinary) as nvarchar) +GO +~~START~~ +nvarchar +test string +~~END~~ + + +select cast(cast(N'test string' as user_defined_nvarchar) as user_defined_varbinary) +go +~~START~~ +varbinary +7400650073007400200073007400720069006E006700 +~~END~~ + +-- Test Case 17: NVARCHAR-> BINARY +select cast(N'test string' as binary) +GO +~~START~~ +binary +7400650073007400200073007400720069006E0067000000000000000000 +~~END~~ + +-- Test Case 18: NVARCHAR-> User Defined varbinary +select cast(N'test string' as user_defined_varbinary) +GO +~~START~~ +varbinary +7400650073007400200073007400720069006E006700 +~~END~~ + + + + +-- to do in hashbytes PR +-- -- Test Case 19: User defined hashbytes function +-- create function dbo.hashbytes(@data sys.varchar)returns sys.varchar AS BEGIN return "dummy hashbytes";END +-- GO +-- SELECT hashbytes( 'SHA', 'test string' ) as vary_string, hashbytes( 'SHA', N'test string' ) as unicode_string +-- GO +-- select hashbytes('abc') +-- GO +-- drop function dbo.hashbytes +-- GO +-- Test 20: Calling the function, procedure, views from prepare scripts +-- Test CastNVarcharToVarbinary function +DECLARE @TestString NVARCHAR(100) = N'Test String'; +DECLARE @BinaryResult VARBINARY(MAX); +SET @BinaryResult = dbo.CastNVarcharToVarbinary(@TestString); +select cast (@BinaryResult as nvarchar) +GO +~~START~~ +nvarchar +Test String +~~END~~ + + + +-- Test CastVarbinaryToNVarchar function +DECLARE @TestBinary VARBINARY(100) = 0x54657374537472696E67; -- 'Test String' in ASCII +DECLARE @StringResult NVARCHAR(MAX); +SET @StringResult = dbo.CastVarbinaryToNVarchar(@TestBinary); +select cast (@StringResult as nvarchar) +GO +~~START~~ +nvarchar +敔瑳瑓楲杮 +~~END~~ + + + +-- Test CastbinaryToNVarchar function +DECLARE @TestBinary BINARY = 0x54657374537472696E67; -- 'Test String' in ASCII +DECLARE @StringResult NVARCHAR(MAX); +SET @StringResult = dbo.CastbinaryToNVarchar(@TestBinary); +select cast (@StringResult as nvarchar) +GO +~~START~~ +nvarchar +T +~~END~~ + + + +-- Test CastDemoView +DECLARE @ViewResult TABLE ( + NVarcharToVarbinary VARBINARY(MAX), + VarbinaryToNVarchar NVARCHAR(MAX), + binaryToNVarchar NVARCHAR(MAX) +); +INSERT INTO @ViewResult +SELECT * FROM dbo.CastDemoView; +go +~~ROW COUNT: 1~~ + + +SELECT * FROM dbo.CastDemoView1; +GO +~~START~~ +varbinary#!#nvarchar#!#nvarchar#!#binary +7400650073007400200073007400720069006E006700#!#效汬Ɐ圠牯摬!#!#效汬Ɐ圠牯摬!#!#740065007300740020007300740072 +~~END~~ + +-- TEST CASE 21: Assigned Casting +DECLARE @NVarcharValue NVARCHAR(100) = N'Hello, World!'; +DECLARE @AssignedVarbinary VARBINARY(100); +SET @AssignedVarbinary = CAST(@NVarcharValue AS VARBINARY(100)); +select CAST(@AssignedVarbinary AS NVARCHAR(100)); +GO +~~START~~ +nvarchar +Hello, World! +~~END~~ + + + + + +--TEST CASE 22: Calling hashbytes via function, procedure, views +-- Test the HashMultipleTypes function +DECLARE @TestVarchar VARCHAR(10) = 'Test'; +DECLARE @TestNVarchar NVARCHAR(10) = N'Test'; +DECLARE @TestVarbinary VARBINARY(10) = 0x54657374; -- 'Test' in ASCII +-- to do in hashbytes PR +-- SELECT * FROM dbo.HashMultipleTypes(@TestVarchar, @TestNVarchar, @TestVarbinary); +-- GO +-- -- Test the HashDemoView +-- SELECT * FROM dbo.HashDemoView; +-- GO +--TEST CASE 23: BINARY TO NVARCHAR +select cast(cast(N'test string' as binary) as nvarchar) +GO +~~START~~ +nvarchar +test string +~~END~~ + +--TEST CASE 24: NVARCHAR TO BINARY with maxlen < length of actual string +select cast(0x610061006100610061006100610061006100 as nvarchar(5)) +GO +~~START~~ +nvarchar +aaaaa +~~END~~ + +select cast(0x8765 as nvarchar(1)) +GO +~~START~~ +nvarchar +文 +~~END~~ + + + +--TEST CASE 25: Default typmod case with string getting truncated +select cast(N'Lorem ipsum dolor sit amet' as varbinary) +GO +~~START~~ +varbinary +4C006F00720065006D00200069007000730075006D00200064006F006C00 +~~END~~ + +select cast(0x4C006F00720065006D00200069007000730075006D00200064006F006C00 as nvarchar) +GO +~~START~~ +nvarchar +Lorem ipsum dol +~~END~~ + +--TEST CASE 26: String getting truncted with defined typmod i.e len > maxlen +select cast(N'tesst string' as varbinary(4)) +GO +~~START~~ +varbinary +74006500 +~~END~~ + +select cast(0x74006500 as nvarchar) +GO +~~START~~ +nvarchar +te +~~END~~ + + +select cast(N'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea' as varbinary(MAX)) +GO +~~START~~ +varbinary +4C006F00720065006D00200069007000730075006D00200064006F006C006F0072002000730069007400200061006D00650074002C00200063006F006E00730065006300740065007400750072002000610064006900700069007300630069006E006700200065006C00690074002E002000530065006400200064006F00200065006900750073006D006F0064002000740065006D0070006F007200200069006E006300690064006900640075006E00740020007500740020006C00610062006F0072006500200065007400200064006F006C006F007200650020006D00610067006E006100200061006C0069007100750061002E00200055007400200065006E0069006D0020006100640020006D0069006E0069006D002000760065006E00690061006D002C002000710075006900730020006E006F0073007400720075006400200065007800650072006300690074006100740069006F006E00200075006C006C0061006D0063006F0020006C00610062006F0072006900730020006E00690073006900200075007400200061006C0069007100750069007000200065007800200065006100200063006F006D006D006F0064006F00200063006F006E007300650071007500610074002E002000440075006900730020006100750074006500200069007200750072006500200064006F006C006F007200200069006E00200072006500700072006500680065006E0064006500720069007400200069006E00200076006F006C007500700074006100740065002000760065006C0069007400200065007300730065002000630069006C006C0075006D00200064006F006C006F0072006500200065007500200066007500670069006100740020006E0075006C006C0061002000700061007200690061007400750072002E0020004500780063006500700074006500750072002000730069006E00740020006F006300630061006500630061007400200063007500700069006400610074006100740020006E006F006E002000700072006F006900640065006E0074002C002000730075006E007400200069006E002000630075006C0070006100200071007500690020006F0066006600690063006900610020006400650073006500720075006E00740020006D006F006C006C0069007400200061006E0069006D00200069006400200065007300740020006C00610062006F00720075006D002E0020004C006F00720065006D00200069007000730075006D00200064006F006C006F0072002000730069007400200061006D00650074002C00200063006F006E00730065006300740065007400750072002000610064006900700069007300630069006E006700200065006C00690074002E002000530065006400200064006F00200065006900750073006D006F0064002000740065006D0070006F007200200069006E006300690064006900640075006E00740020007500740020006C00610062006F0072006500200065007400200064006F006C006F007200650020006D00610067006E006100200061006C0069007100750061002E00200055007400200065006E0069006D0020006100640020006D0069006E0069006D002000760065006E00690061006D002C002000710075006900730020006E006F0073007400720075006400200065007800650072006300690074006100740069006F006E00200075006C006C0061006D0063006F0020006C00610062006F0072006900730020006E00690073006900200075007400200061006C0069007100750069007000200065007800200065006100200063006F006D006D006F0064006F00200063006F006E007300650071007500610074002E002000440075006900730020006100750074006500200069007200750072006500200064006F006C006F007200200069006E00200072006500700072006500680065006E0064006500720069007400200069006E00200076006F006C007500700074006100740065002000760065006C0069007400200065007300730065002000630069006C006C0075006D00200064006F006C006F0072006500200065007500200066007500670069006100740020006E0075006C006C0061002000700061007200690061007400750072002E0020004500780063006500700074006500750072002000730069006E00740020006F006300630061006500630061007400200063007500700069006400610074006100740020006E006F006E002000700072006F006900640065006E0074002C002000730075006E007400200069006E002000630075006C0070006100200071007500690020006F0066006600690063006900610020006400650073006500720075006E00740020006D006F006C006C0069007400200061006E0069006D00200069006400200065007300740020006C00610062006F00720075006D002E0020004C006F00720065006D00200069007000730075006D00200064006F006C006F0072002000730069007400200061006D00650074002C00200063006F006E00730065006300740065007400750072002000610064006900700069007300630069006E006700200065006C00690074002E002000530065006400200064006F00200065006900750073006D006F0064002000740065006D0070006F007200200069006E006300690064006900640075006E00740020007500740020006C00610062006F0072006500200065007400200064006F006C006F007200650020006D00610067006E006100200061006C0069007100750061002E00200055007400200065006E0069006D0020006100640020006D0069006E0069006D002000760065006E00690061006D002C002000710075006900730020006E006F0073007400720075006400200065007800650072006300690074006100740069006F006E00200075006C006C0061006D0063006F0020006C00610062006F0072006900730020006E00690073006900200075007400200061006C0069007100750069007000200065007800200065006100200063006F006D006D006F0064006F00200063006F006E007300650071007500610074002E002000440075006900730020006100750074006500200069007200750072006500200064006F006C006F007200200069006E00200072006500700072006500680065006E0064006500720069007400200069006E00200076006F006C007500700074006100740065002000760065006C0069007400200065007300730065002000630069006C006C0075006D00200064006F006C006F0072006500200065007500200066007500670069006100740020006E0075006C006C0061002000700061007200690061007400750072002E0020004500780063006500700074006500750072002000730069006E00740020006F006300630061006500630061007400200063007500700069006400610074006100740020006E006F006E002000700072006F006900640065006E0074002C002000730075006E007400200069006E002000630075006C0070006100200071007500690020006F0066006600690063006900610020006400650073006500720075006E00740020006D006F006C006C0069007400200061006E0069006D00200069006400200065007300740020006C00610062006F00720075006D002E0020004C006F00720065006D00200069007000730075006D00200064006F006C006F0072002000730069007400200061006D00650074002C00200063006F006E00730065006300740065007400750072002000610064006900700069007300630069006E006700200065006C00690074002E002000530065006400200064006F00200065006900750073006D006F0064002000740065006D0070006F007200200069006E006300690064006900640075006E00740020007500740020006C00610062006F0072006500200065007400200064006F006C006F007200650020006D00610067006E006100200061006C0069007100750061002E00200055007400200065006E0069006D0020006100640020006D0069006E0069006D002000760065006E00690061006D002C002000710075006900730020006E006F0073007400720075006400200065007800650072006300690074006100740069006F006E00200075006C006C0061006D0063006F0020006C00610062006F0072006900730020006E00690073006900200075007400200061006C0069007100750069007000200065007800200065006100200063006F006D006D006F0064006F00200063006F006E007300650071007500610074002E002000440075006900730020006100750074006500200069007200750072006500200064006F006C006F007200200069006E00200072006500700072006500680065006E0064006500720069007400200069006E00200076006F006C007500700074006100740065002000760065006C0069007400200065007300730065002000630069006C006C0075006D00200064006F006C006F0072006500200065007500200066007500670069006100740020006E0075006C006C0061002000700061007200690061007400750072002E0020004500780063006500700074006500750072002000730069006E00740020006F006300630061006500630061007400200063007500700069006400610074006100740020006E006F006E002000700072006F006900640065006E0074002C002000730075006E007400200069006E002000630075006C0070006100200071007500690020006F0066006600690063006900610020006400650073006500720075006E00740020006D006F006C006C0069007400200061006E0069006D00200069006400200065007300740020006C00610062006F00720075006D002E0020004C006F00720065006D00200069007000730075006D00200064006F006C006F0072002000730069007400200061006D00650074002C00200063006F006E00730065006300740065007400750072002000610064006900700069007300630069006E006700200065006C00690074002E002000530065006400200064006F00200065006900750073006D006F0064002000740065006D0070006F007200200069006E006300690064006900640075006E00740020007500740020006C00610062006F0072006500200065007400200064006F006C006F007200650020006D00610067006E006100200061006C0069007100750061002E00200055007400200065006E0069006D0020006100640020006D0069006E0069006D002000760065006E00690061006D002C002000710075006900730020006E006F0073007400720075006400200065007800650072006300690074006100740069006F006E00200075006C006C0061006D0063006F0020006C00610062006F0072006900730020006E00690073006900200075007400200061006C0069007100750069007000200065007800200065006100 +~~END~~ + + +select cast(0x0006161 as nvarchar) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Failed to convert from data type varbinary to nvarchar, invalid UTF16 byte sequence - code point 0 not supported)~~ + diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/cast_nvarchar_test_before_16_5-vu-verify.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/cast_nvarchar_test_before_16_5-vu-verify.out new file mode 100644 index 0000000000..92a8a1fb09 --- /dev/null +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/cast_nvarchar_test_before_16_5-vu-verify.out @@ -0,0 +1,368 @@ +-- TEST CASE 1: creating a table and then calling hashbytes for nvarchar and varchar input +insert into TestHash values('value1', 'value1'); +GO +~~ROW COUNT: 1~~ + + +SELECT DATALENGTH( nvarchar_data) as nvarchar_data_datalength + , LEN( nvarchar_data) AS nvarchar_data_len + , DATALENGTH( varchar_data) as varchar_data_btyes_datalength + , LEN( varchar_data) AS varchar_data_len + , * +from TestHash; +GO +~~START~~ +int#!#int#!#int#!#int#!#nvarchar#!#varchar#!#varbinary#!#varbinary#!#varbinary#!#varbinary +6#!#6#!#6#!#6#!#value1#!#value1#!#8107759ABABCBFA34BCB02BC4309CAF6354982AB#!#8107759ABABCBFA34BCB02BC4309CAF6354982AB#!#8107759ABABCBFA34BCB02BC4309CAF6354982AB#!#8107759ABABCBFA34BCB02BC4309CAF6354982AB +~~END~~ + +-- TEST CASE 2: Casting nvarchar and varchar with different algorithms using Hashbytes +SELECT hashbytes( 'sha1', 'test string' ) as vary_string, hashbytes( 'sha1', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +661295C9CBF9D6B2F6428414504A8DEED3020641#!#661295C9CBF9D6B2F6428414504A8DEED3020641 +~~END~~ + + +SELECT hashbytes( 'MD2', 'test string' ) as vary_string, hashbytes( 'MD2', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +#!# +~~END~~ + + +SELECT hashbytes( 'MD4', 'test string' ) as vary_string, hashbytes( 'MD4', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +#!# +~~END~~ + + +SELECT hashbytes( 'MD5', 'test string' ) as vary_string, hashbytes( 'MD5', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +6F8DB599DE986FAB7A21625B7916589C#!#6F8DB599DE986FAB7A21625B7916589C +~~END~~ + + +SELECT hashbytes( 'SHA2_256', 'test string' ) as vary_string, hashbytes( 'SHA2_256', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +D5579C46DFCC7F18207013E65B44E4CB4E2C2298F4AC457BA8F82743F31E930B#!#D5579C46DFCC7F18207013E65B44E4CB4E2C2298F4AC457BA8F82743F31E930B +~~END~~ + + +SELECT hashbytes( 'SHA2_512', 'test string' ) as vary_string, hashbytes( 'SHA2_512', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +10E6D647AF44624442F388C2C14A787FF8B17E6165B83D767EC047768D8CBCB71A1A3226E7CC7816BC79C0427D94A9DA688C41A3992C7BF5E4D7CC3E0BE5DBAC#!#10E6D647AF44624442F388C2C14A787FF8B17E6165B83D767EC047768D8CBCB71A1A3226E7CC7816BC79C0427D94A9DA688C41A3992C7BF5E4D7CC3E0BE5DBAC +~~END~~ + + +SELECT hashbytes( 'SHA', 'test string' ) as vary_string, hashbytes( 'SHA', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +661295C9CBF9D6B2F6428414504A8DEED3020641#!#661295C9CBF9D6B2F6428414504A8DEED3020641 +~~END~~ + + +SELECT hashbytes( 'sha1', 'test string') +GO +~~START~~ +varbinary +661295C9CBF9D6B2F6428414504A8DEED3020641 +~~END~~ + +--TEST CASE 3: testing hashbytes via casting a varchar to nvarchar +SELECT hashbytes('sha1',cast('test string' as sys.nvarchar)) +GO +~~START~~ +varbinary +661295C9CBF9D6B2F6428414504A8DEED3020641 +~~END~~ + + + +--TEST CASE 4: Casting function for nvarchar to varbinary +SELECT cast(N'test string' as varbinary); +GO +~~START~~ +varbinary +7400650073007400200073007400720069006E006700 +~~END~~ + + +SELECT cast(cast(cast('ab' AS nvarchar(10)) as varbinary(2)) as nvarchar(2)); +GO +~~START~~ +nvarchar +a +~~END~~ + + +-- Test Case 5: Empty strings and NULL values +SELECT HASHBYTES('SHA1', '') AS empty_varchar, + HASHBYTES('SHA1', N'') AS empty_nvarchar, + HASHBYTES('SHA1', NULL) AS null_input; +GO +~~START~~ +varbinary#!#varbinary#!#varbinary +DA39A3EE5E6B4B0D3255BFEF95601890AFD80709#!#DA39A3EE5E6B4B0D3255BFEF95601890AFD80709#!# +~~END~~ + + +-- Test Case 6: Unicode characters +SELECT HASHBYTES('SHA1', N'こんにちは') AS japanese, + HASHBYTES('SHA1', N'Здравствуйте') AS russian, + HASHBYTES('SHA1', N'🙂😊😀') AS emojis; +GO +~~START~~ +varbinary#!#varbinary#!#varbinary +20427A708C3F6F07CF12AB23557982D9E6D23B61#!#E2D105A2541F2DC6C8B93DF73D07DF30B33FD80A#!#3B114970B215D62CB987A4D5644FEE7001C78234 +~~END~~ + + +-- Test Case 8: Different collations +SELECT HASHBYTES('SHA1', N'hello' COLLATE Latin1_General_CI_AS) AS ci_as, + HASHBYTES('SHA1', N'hello' COLLATE Latin1_General_CS_AS) AS cs_as; +GO +~~START~~ +varbinary#!#varbinary +AAF4C61DDCC5E8A2DABEDE0F3B482CD9AEA9434D#!#AAF4C61DDCC5E8A2DABEDE0F3B482CD9AEA9434D +~~END~~ + + +-- Test Case 9: Combining varchar and nvarchar +SELECT HASHBYTES('SHA1', 'hello' + N'world') AS combined; +GO +~~START~~ +varbinary +6ADFB183A4A2C94A2F92DAB5ADE762A47889A5A1 +~~END~~ + + +-- Test Case 10: Roundtrip conversions +SELECT CAST(CAST(N'test' AS VARBINARY(8)) AS NVARCHAR(4)) AS nvarchar_roundtrip, + CAST(CAST('test' AS VARBINARY(8)) AS VARCHAR(4)) AS varchar_roundtrip; +GO +~~START~~ +nvarchar#!#varchar +test#!#test +~~END~~ + + +-- Test Case 11: CAST and CONVERT between varchar, nvarchar, and varbinary +SELECT CAST(N'hello' AS VARBINARY(10)) AS nvarchar_to_varbinary, + CAST('hello' AS VARBINARY(10)) AS varchar_to_varbinary, + CONVERT(VARBINARY(10), N'hello') AS nvarchar_to_varbinary_convert, + CONVERT(VARBINARY(10), 'hello') AS varchar_to_varbinary_convert; +GO +~~START~~ +varbinary#!#varbinary#!#varbinary#!#varbinary +680065006C006C006F00#!#68656C6C6F#!#68656C6C6F#!#68656C6C6F +~~END~~ + + +-- Test Case 12: Testing with special characters +SELECT HASHBYTES('SHA1', 'Hello, World!') AS varchar_special, + HASHBYTES('SHA1', N'Hello, World!') AS nvarchar_special, + HASHBYTES('SHA1', 'Hello' + CHAR(13) + CHAR(10) + 'World') AS varchar_newline, + HASHBYTES('SHA1', N'Hello' + NCHAR(13) + NCHAR(10) + N'World') AS nvarchar_newline; +GO +~~START~~ +varbinary#!#varbinary#!#varbinary#!#varbinary +0A0A9F2A6772942557AB5355D76AF442F8F65E01#!#0A0A9F2A6772942557AB5355D76AF442F8F65E01#!#62E451F6ED58D1FF234A05B8467C0CEB1D4B285F#!#62E451F6ED58D1FF234A05B8467C0CEB1D4B285F +~~END~~ + + +-- Test Case 13: NVARCHAR -> VARBINARY -> VARCHAR -> NVARCHAR -> VARBINARY +SELECT CAST( + CAST( + CAST( + CAST(N'Hello World' AS VARBINARY(100)) + AS VARCHAR(100)) + AS NVARCHAR(100)) +AS VARBINARY(100)) AS four_casts; +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Failed to convert from data type varbinary to varchar, invalid byte sequence for encoding "GBK": 0x00)~~ + + +-- Test Case 14: VARCHAR -> NVARCHAR -> VARBINARY -> NVARCHAR -> VARCHAR +SELECT CAST( + CAST( + CAST( + CAST('Test String' AS NVARCHAR(50)) + AS VARBINARY(50)) + AS NVARCHAR(50)) +AS VARCHAR(50)) AS four_casts; +GO +~~START~~ +varchar +Test String +~~END~~ + + +-- Test Case 15: Implicit conversion from data type nvarchar to varbinary is not allowed. +DECLARE @a varbinary(10); SET @a = CAST(N'21' AS nvarchar(10)); SELECT @a +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Implicit conversion from data type nvarchar to varbinary is not allowed. Use the CONVERT function to run this query.)~~ + + +-- Test Case 16: Casting with UDT on nvarchar -> varbinary, UDT on varbinary to nvarchar, UDT on nvarchar to UDT on varbinary +create type user_defined_nvarchar from nvarchar(50); +select cast(cast(N'test string' as user_defined_nvarchar) as varbinary) +GO +~~START~~ +varbinary +7400650073007400200073007400720069006E006700 +~~END~~ + + +create type user_defined_varbinary from varbinary(50); +select cast(cast(0x7400650073007400200073007400720069006E006700 as user_defined_varbinary) as nvarchar) +GO +~~START~~ +nvarchar +test string +~~END~~ + + +select cast(cast(N'test string' as user_defined_nvarchar) as user_defined_varbinary) +go +~~START~~ +varbinary +7400650073007400200073007400720069006E006700 +~~END~~ + +-- Test Case 17: NVARCHAR-> BINARY +select cast(N'test string' as binary) +GO +~~START~~ +binary +7400650073007400200073007400720069006E0067000000000000000000 +~~END~~ + +-- Test Case 18: NVARCHAR-> User Defined varbinary +select cast(N'test string' as user_defined_varbinary) +GO +~~START~~ +varbinary +7400650073007400200073007400720069006E006700 +~~END~~ + +-- Test Case 19: User defined hashbytes function +create function dbo.hashbytes(@data sys.varchar)returns sys.varchar AS BEGIN return "dummy hashbytes";END +GO +SELECT hashbytes( 'SHA', 'test string' ) as vary_string, hashbytes( 'SHA', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +661295C9CBF9D6B2F6428414504A8DEED3020641#!#661295C9CBF9D6B2F6428414504A8DEED3020641 +~~END~~ + +select hashbytes('abc') +GO +~~START~~ +varchar +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: column "dummy hashbytes" does not exist)~~ + +drop function dbo.hashbytes +GO + + +-- Test 20: Calling the function, procedure, views from prepare scripts +-- Test CastNVarcharToVarbinary function +DECLARE @TestString NVARCHAR(100) = N'Test String'; +DECLARE @BinaryResult VARBINARY(MAX); +SET @BinaryResult = dbo.CastNVarcharToVarbinary(@TestString); +select cast (@BinaryResult as nvarchar) +GO +~~START~~ +nvarchar +Test String +~~END~~ + + + +-- Test CastVarbinaryToNVarchar function +DECLARE @TestBinary VARBINARY(100) = 0x54657374537472696E67; -- 'Test String' in ASCII +DECLARE @StringResult NVARCHAR(MAX); +SET @StringResult = dbo.CastVarbinaryToNVarchar(@TestBinary); +select cast (@StringResult as nvarchar) +GO +~~START~~ +nvarchar +敔瑳瑓楲杮 +~~END~~ + + + +-- Test CastDemoView +DECLARE @ViewResult TABLE ( + NVarcharToVarbinary VARBINARY(MAX), + VarbinaryToNVarchar NVARCHAR(MAX) +); +INSERT INTO @ViewResult +SELECT * FROM dbo.CastDemoView; +go +~~ROW COUNT: 1~~ + + +-- TEST CASE 21: Assigned Casting +DECLARE @NVarcharValue NVARCHAR(100) = N'Hello, World!'; +DECLARE @AssignedVarbinary VARBINARY(100); +SET @AssignedVarbinary = CAST(@NVarcharValue AS VARBINARY(100)); +select CAST(@AssignedVarbinary AS NVARCHAR(100)); +GO +~~START~~ +nvarchar +Hello, World! +~~END~~ + + + + +--TEST CASE 22: Calling hashbytes via function, procedure, views +-- Test the HashMultipleTypes function +DECLARE @TestVarchar VARCHAR(10) = 'Test'; +DECLARE @TestNVarchar NVARCHAR(10) = N'Test'; +DECLARE @TestVarbinary VARBINARY(10) = 0x54657374; -- 'Test' in ASCII +SELECT * FROM dbo.HashMultipleTypes(@TestVarchar, @TestNVarchar, @TestVarbinary); +GO +~~START~~ +varbinary#!#varbinary#!#varbinary +532EAABD9574880DBF76B9B8CC00832C20A6EC113D682299550D7A6E0F345E25#!#532EAABD9574880DBF76B9B8CC00832C20A6EC113D682299550D7A6E0F345E25#!#532EAABD9574880DBF76B9B8CC00832C20A6EC113D682299550D7A6E0F345E25 +~~END~~ + +-- Test the HashDemoView +SELECT * FROM dbo.HashDemoView; +GO +~~START~~ +varbinary#!#varbinary#!#varbinary +185F8DB32271FE25F561A6FC938B2E264306EC304EDA518007D1764826381969#!#185F8DB32271FE25F561A6FC938B2E264306EC304EDA518007D1764826381969#!#185F8DB32271FE25F561A6FC938B2E264306EC304EDA518007D1764826381969 +~~END~~ + + +--TEST CASE 23: BINARY TO NVARCHAR +select cast(cast(N'test string' as binary) as nvarchar) +GO +~~START~~ +nvarchar +test string +~~END~~ + + + diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/concat-before-15_9-or-16_5-vu-verify.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/concat-before-15_9-or-16_5-vu-verify.out index c9c08c5edb..47341c2d22 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/concat-before-15_9-or-16_5-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/concat-before-15_9-or-16_5-vu-verify.out @@ -421,7 +421,7 @@ SELECT CONCAT( 'a', 'b', CAST('🙂🙂' AS nvarchar), 'd', 'e', CAST('f' AS cha GO ~~START~~ nvarchar -ab🙂🙂def比尔hijklmnopqrstuvwxyzABCDEFGHIJKLMefOPQRST🙂🙂VWXYZ0123456789.,-_!@#$%^&*()[]{}<>/\\|:;"\?+=~`abcdefg +ab🙂🙂def比尔hijklmnopqrstuvwxyzABCDEFGHIJKLM晥OPQRST🙂🙂VWXYZ0123456789.,-_!@#$%^&*()[]{}<>/\\|:;"\?+=~`abcde杦 ~~END~~ @@ -1165,16 +1165,16 @@ SELECT CONCAT(col_nvarchar, col_binary) from babel_3409_concat_t1 ORDER BY id GO ~~START~~ nvarchar -abcab -🙂defghicd -🙂🙂ef -比尔·拉gh -莫斯ip +abc扡 +🙂defghi摣 +🙂🙂晥 +比尔·拉桧 +莫斯灩 -Anikaitqr +Anikait牱 -Agrawalrs +Agrawal獲 ~~END~~ @@ -1182,16 +1182,16 @@ SELECT CONCAT(col_nvarchar, col_varbinary) from babel_3409_concat_t1 ORDER BY id GO ~~START~~ nvarchar -abcab -🙂defghicd -🙂🙂ef -比尔·拉gh -莫斯ip +abc扡 +🙂defghi摣 +🙂🙂晥 +比尔·拉桧 +莫斯灩 -Anikaitqr +Anikait牱 -Agrawalrs +Agrawal獲 ~~END~~ @@ -1483,16 +1483,16 @@ EXEC babel_3409_concat_dep_proc2 GO ~~START~~ nvarchar -abc12.00002000-12-12 12:43:102000-12-12 12:43:10ab2000-12-1212:43:102000-12-12 12:43:10.1234 +10:00 -🙂defghi13.00002000-12-13 12:43:102000-12-13 12:43:10cd2000-12-1312:43:102000-12-13 12:43:10.1234 +10:00 -🙂🙂14.00002000-12-14 12:43:102000-12-14 12:43:10ef2000-12-1412:43:102000-12-14 12:43:10.1234 +10:00 -比尔·拉15.00002000-12-15 12:43:102000-12-15 12:43:10gh2000-12-1512:43:102000-12-15 12:43:10.1234 +10:00 -莫斯16.00002000-12-16 12:43:102000-12-16 12:43:10ip2000-12-1612:43:102000-12-16 12:43:10.1234 +10:00 +abc12.00002000-12-12 12:43:102000-12-12 12:43:10扡2000-12-1212:43:102000-12-12 12:43:10.1234 +10:00 +🙂defghi13.00002000-12-13 12:43:102000-12-13 12:43:10摣2000-12-1312:43:102000-12-13 12:43:10.1234 +10:00 +🙂🙂14.00002000-12-14 12:43:102000-12-14 12:43:10晥2000-12-1412:43:102000-12-14 12:43:10.1234 +10:00 +比尔·拉15.00002000-12-15 12:43:102000-12-15 12:43:10桧2000-12-1512:43:102000-12-15 12:43:10.1234 +10:00 +莫斯16.00002000-12-16 12:43:102000-12-16 12:43:10灩2000-12-1612:43:102000-12-16 12:43:10.1234 +10:00 -Anikait17.00002000-12-17 12:43:102000-12-17 12:43:10qr2000-12-1712:43:102000-12-17 12:43:10.1234 +10:00 +Anikait17.00002000-12-17 12:43:102000-12-17 12:43:10牱2000-12-1712:43:102000-12-17 12:43:10.1234 +10:00 -Agrawal18.00002000-12-18 12:43:102000-12-18 12:43:10rs2000-12-1812:43:102000-12-18 12:43:10.1234 +10:00 +Agrawal18.00002000-12-18 12:43:102000-12-18 12:43:10獲2000-12-1812:43:102000-12-18 12:43:10.1234 +10:00 ~~END~~ @@ -1500,7 +1500,7 @@ SELECT babel_3409_concat_dep_func2() GO ~~START~~ nvarchar -abcababcabc +abc扡abcabc ~~END~~ diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/concat-vu-verify.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/concat-vu-verify.out index 5b342ff4ed..a48245b542 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/concat-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/concat-vu-verify.out @@ -421,7 +421,7 @@ SELECT CONCAT( 'a', 'b', CAST('🙂🙂' AS nvarchar), 'd', 'e', CAST('f' AS cha GO ~~START~~ nvarchar -ab🙂🙂def比尔hijklmnopqrstuvwxyzABCDEFGHIJKLMefOPQRST🙂🙂VWXYZ0123456789.,-_!@#$%^&*()[]{}<>/\\|:;"\?+=~`abcdefg +ab🙂🙂def比尔hijklmnopqrstuvwxyzABCDEFGHIJKLM晥OPQRST🙂🙂VWXYZ0123456789.,-_!@#$%^&*()[]{}<>/\\|:;"\?+=~`abcde杦 ~~END~~ @@ -1230,16 +1230,16 @@ SELECT CONCAT(col_nvarchar, col_binary) from babel_3409_concat_t1 ORDER BY id GO ~~START~~ nvarchar -abcab -🙂defghicd -🙂🙂ef -比尔·拉gh -莫斯ip +abc扡 +🙂defghi摣 +🙂🙂晥 +比尔·拉桧 +莫斯灩 -Anikaitqr +Anikait牱 -Agrawalrs +Agrawal獲 ~~END~~ @@ -1247,16 +1247,16 @@ SELECT CONCAT(col_nvarchar, col_varbinary) from babel_3409_concat_t1 ORDER BY id GO ~~START~~ nvarchar -abcab -🙂defghicd -🙂🙂ef -比尔·拉gh -莫斯ip +abc扡 +🙂defghi摣 +🙂🙂晥 +比尔·拉桧 +莫斯灩 -Anikaitqr +Anikait牱 -Agrawalrs +Agrawal獲 ~~END~~ @@ -1579,16 +1579,16 @@ EXEC babel_3409_concat_dep_proc2 GO ~~START~~ nvarchar -abc12.00002000-12-12 12:43:102000-12-12 12:43:10ab2000-12-1212:43:102000-12-12 12:43:10.1234 +10:00 -🙂defghi13.00002000-12-13 12:43:102000-12-13 12:43:10cd2000-12-1312:43:102000-12-13 12:43:10.1234 +10:00 -🙂🙂14.00002000-12-14 12:43:102000-12-14 12:43:10ef2000-12-1412:43:102000-12-14 12:43:10.1234 +10:00 -比尔·拉15.00002000-12-15 12:43:102000-12-15 12:43:10gh2000-12-1512:43:102000-12-15 12:43:10.1234 +10:00 -莫斯16.00002000-12-16 12:43:102000-12-16 12:43:10ip2000-12-1612:43:102000-12-16 12:43:10.1234 +10:00 +abc12.00002000-12-12 12:43:102000-12-12 12:43:10扡2000-12-1212:43:102000-12-12 12:43:10.1234 +10:00 +🙂defghi13.00002000-12-13 12:43:102000-12-13 12:43:10摣2000-12-1312:43:102000-12-13 12:43:10.1234 +10:00 +🙂🙂14.00002000-12-14 12:43:102000-12-14 12:43:10晥2000-12-1412:43:102000-12-14 12:43:10.1234 +10:00 +比尔·拉15.00002000-12-15 12:43:102000-12-15 12:43:10桧2000-12-1512:43:102000-12-15 12:43:10.1234 +10:00 +莫斯16.00002000-12-16 12:43:102000-12-16 12:43:10灩2000-12-1612:43:102000-12-16 12:43:10.1234 +10:00 -Anikait17.00002000-12-17 12:43:102000-12-17 12:43:10qr2000-12-1712:43:102000-12-17 12:43:10.1234 +10:00 +Anikait17.00002000-12-17 12:43:102000-12-17 12:43:10牱2000-12-1712:43:102000-12-17 12:43:10.1234 +10:00 -Agrawal18.00002000-12-18 12:43:102000-12-18 12:43:10rs2000-12-1812:43:102000-12-18 12:43:10.1234 +10:00 +Agrawal18.00002000-12-18 12:43:102000-12-18 12:43:10獲2000-12-1812:43:102000-12-18 12:43:10.1234 +10:00 ~~END~~ @@ -1596,7 +1596,7 @@ SELECT babel_3409_concat_dep_func2() GO ~~START~~ nvarchar -abcababcabc +abc扡abcabc ~~END~~ diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/concat_ws-before-15_9-or-16_5-vu-verify.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/concat_ws-before-15_9-or-16_5-vu-verify.out index 23dd17a398..d10b8a9842 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/concat_ws-before-15_9-or-16_5-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/concat_ws-before-15_9-or-16_5-vu-verify.out @@ -790,7 +790,7 @@ SELECT CONCAT_WS('-', 'a', 'b', CAST('🙂🙂' AS nvarchar), 'd', 'e', CAST('f' GO ~~START~~ nvarchar -a-b-🙂🙂-d-e-f-比尔-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-A-B-C-D-E-F-G-H-I-J-K-L-M-ef-O-P-Q-R-S-T-🙂🙂-V-W-X-Y-Z-0-1-2-3-4-5-6-7-8-9-.-,---_-!-@-#-$-%-^-&-*-(-)-[-]-{-}-<->-/-\\-|-:-;-"-\-?-+-=-~-`-a-b-c-d-fg +a-b-🙂🙂-d-e-f-比尔-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-A-B-C-D-E-F-G-H-I-J-K-L-M-晥-O-P-Q-R-S-T-🙂🙂-V-W-X-Y-Z-0-1-2-3-4-5-6-7-8-9-.-,---_-!-@-#-$-%-^-&-*-(-)-[-]-{-}-<->-/-\\-|-:-;-"-\-?-+-=-~-`-a-b-c-d-杦 ~~END~~ @@ -798,7 +798,7 @@ SELECT CONCAT_WS(N'-', 'a', 'b', CAST('🙂🙂' AS varchar), 'd', 'e', CAST('f' GO ~~START~~ nvarchar -a-b-🙂🙂-d-e-f-比尔-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-A-B-C-D-E-F-G-H-I-J-K-L-M-ef-O-P-Q-R-S-T-🙂🙂-V-W-X-Y-Z-0-1-2-3-4-5-6-7-8-9-.-,---_-!-@-#-$-%-^-&-*-(-)-[-]-{-}-<->-/-\\-|-:-;-"-\-?-+-=-~-`-a-b-c-d-fg +a-b-🙂🙂-d-e-f-比尔-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-A-B-C-D-E-F-G-H-I-J-K-L-M-晥-O-P-Q-R-S-T-🙂🙂-V-W-X-Y-Z-0-1-2-3-4-5-6-7-8-9-.-,---_-!-@-#-$-%-^-&-*-(-)-[-]-{-}-<->-/-\\-|-:-;-"-\-?-+-=-~-`-a-b-c-d-杦 ~~END~~ @@ -1382,16 +1382,16 @@ SELECT CONCAT_WS(col_nvarchar, col_varchar, col_binary) from babel_3409_concat_w GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -1416,16 +1416,16 @@ SELECT CONCAT_WS(col_nvarchar, col_varchar, col_varbinary) from babel_3409_conca GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -2277,16 +2277,16 @@ SELECT CONCAT_WS(col_varchar, col_nvarchar, col_binary) from babel_3409_concat_w GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -2294,16 +2294,16 @@ SELECT CONCAT_WS(col_nvarchar, col_nvarchar, col_binary) from babel_3409_concat_ GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -2311,16 +2311,16 @@ SELECT CONCAT_WS(col_varchar, col_nvarchar, col_varbinary) from babel_3409_conca GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -2328,16 +2328,16 @@ SELECT CONCAT_WS(col_nvarchar, col_nvarchar, col_varbinary) from babel_3409_conc GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -3009,16 +3009,16 @@ EXEC babel_3409_concat_ws_dep_proc2 GO ~~START~~ nvarchar -abc-12.0000-2000-12-12 12:43:10-2000-12-12 12:43:10-ab-2000-12-12-12:43:10-2000-12-12 12:43:10.1234 +10:00 -🙂defghi-13.0000-2000-12-13 12:43:10-2000-12-13 12:43:10-cd-2000-12-13-12:43:10-2000-12-13 12:43:10.1234 +10:00 -🙂🙂-14.0000-2000-12-14 12:43:10-2000-12-14 12:43:10-ef-2000-12-14-12:43:10-2000-12-14 12:43:10.1234 +10:00 -比尔·拉-15.0000-2000-12-15 12:43:10-2000-12-15 12:43:10-gh-2000-12-15-12:43:10-2000-12-15 12:43:10.1234 +10:00 -莫斯-16.0000-2000-12-16 12:43:10-2000-12-16 12:43:10-ip-2000-12-16-12:43:10-2000-12-16 12:43:10.1234 +10:00 +abc-12.0000-2000-12-12 12:43:10-2000-12-12 12:43:10-扡-2000-12-12-12:43:10-2000-12-12 12:43:10.1234 +10:00 +🙂defghi-13.0000-2000-12-13 12:43:10-2000-12-13 12:43:10-摣-2000-12-13-12:43:10-2000-12-13 12:43:10.1234 +10:00 +🙂🙂-14.0000-2000-12-14 12:43:10-2000-12-14 12:43:10-晥-2000-12-14-12:43:10-2000-12-14 12:43:10.1234 +10:00 +比尔·拉-15.0000-2000-12-15 12:43:10-2000-12-15 12:43:10-桧-2000-12-15-12:43:10-2000-12-15 12:43:10.1234 +10:00 +莫斯-16.0000-2000-12-16 12:43:10-2000-12-16 12:43:10-灩-2000-12-16-12:43:10-2000-12-16 12:43:10.1234 +10:00 -Anikait-17.0000-2000-12-17 12:43:10-2000-12-17 12:43:10-qr-2000-12-17-12:43:10-2000-12-17 12:43:10.1234 +10:00 +Anikait-17.0000-2000-12-17 12:43:10-2000-12-17 12:43:10-牱-2000-12-17-12:43:10-2000-12-17 12:43:10.1234 +10:00 -Agrawal-18.0000-2000-12-18 12:43:10-2000-12-18 12:43:10-rs-2000-12-18-12:43:10-2000-12-18 12:43:10.1234 +10:00 +Agrawal-18.0000-2000-12-18 12:43:10-2000-12-18 12:43:10-獲-2000-12-18-12:43:10-2000-12-18 12:43:10.1234 +10:00 ~~END~~ @@ -3026,7 +3026,7 @@ SELECT babel_3409_concat_ws_dep_func2() GO ~~START~~ nvarchar -abc-ab-abc-abc +abc-扡-abc-abc ~~END~~ diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/concat_ws-vu-verify.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/concat_ws-vu-verify.out index b6e1c2519c..17e29e9b38 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/concat_ws-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/concat_ws-vu-verify.out @@ -790,7 +790,7 @@ SELECT CONCAT_WS('-', 'a', 'b', CAST('🙂🙂' AS nvarchar), 'd', 'e', CAST('f' GO ~~START~~ nvarchar -a-b-🙂🙂-d-e-f-比尔-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-A-B-C-D-E-F-G-H-I-J-K-L-M-ef-O-P-Q-R-S-T-🙂🙂-V-W-X-Y-Z-0-1-2-3-4-5-6-7-8-9-.-,---_-!-@-#-$-%-^-&-*-(-)-[-]-{-}-<->-/-\\-|-:-;-"-\-?-+-=-~-`-a-b-c-d-fg +a-b-🙂🙂-d-e-f-比尔-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-A-B-C-D-E-F-G-H-I-J-K-L-M-晥-O-P-Q-R-S-T-🙂🙂-V-W-X-Y-Z-0-1-2-3-4-5-6-7-8-9-.-,---_-!-@-#-$-%-^-&-*-(-)-[-]-{-}-<->-/-\\-|-:-;-"-\-?-+-=-~-`-a-b-c-d-杦 ~~END~~ @@ -798,7 +798,7 @@ SELECT CONCAT_WS(N'-', 'a', 'b', CAST('🙂🙂' AS varchar), 'd', 'e', CAST('f' GO ~~START~~ nvarchar -a-b-🙂🙂-d-e-f-比尔-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-A-B-C-D-E-F-G-H-I-J-K-L-M-ef-O-P-Q-R-S-T-🙂🙂-V-W-X-Y-Z-0-1-2-3-4-5-6-7-8-9-.-,---_-!-@-#-$-%-^-&-*-(-)-[-]-{-}-<->-/-\\-|-:-;-"-\-?-+-=-~-`-a-b-c-d-fg +a-b-🙂🙂-d-e-f-比尔-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-A-B-C-D-E-F-G-H-I-J-K-L-M-晥-O-P-Q-R-S-T-🙂🙂-V-W-X-Y-Z-0-1-2-3-4-5-6-7-8-9-.-,---_-!-@-#-$-%-^-&-*-(-)-[-]-{-}-<->-/-\\-|-:-;-"-\-?-+-=-~-`-a-b-c-d-杦 ~~END~~ @@ -1416,16 +1416,16 @@ SELECT CONCAT_WS(col_nvarchar, col_varchar, col_binary) from babel_3409_concat_w GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -1450,16 +1450,16 @@ SELECT CONCAT_WS(col_nvarchar, col_varchar, col_varbinary) from babel_3409_conca GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -2407,16 +2407,16 @@ SELECT CONCAT_WS(col_varchar, col_nvarchar, col_binary) from babel_3409_concat_w GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -2424,16 +2424,16 @@ SELECT CONCAT_WS(col_nvarchar, col_nvarchar, col_binary) from babel_3409_concat_ GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -2441,16 +2441,16 @@ SELECT CONCAT_WS(col_varchar, col_nvarchar, col_varbinary) from babel_3409_conca GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -2458,16 +2458,16 @@ SELECT CONCAT_WS(col_nvarchar, col_nvarchar, col_varbinary) from babel_3409_conc GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -3232,16 +3232,16 @@ EXEC babel_3409_concat_ws_dep_proc2 GO ~~START~~ nvarchar -abc-12.0000-2000-12-12 12:43:10-2000-12-12 12:43:10-ab-2000-12-12-12:43:10-2000-12-12 12:43:10.1234 +10:00 -🙂defghi-13.0000-2000-12-13 12:43:10-2000-12-13 12:43:10-cd-2000-12-13-12:43:10-2000-12-13 12:43:10.1234 +10:00 -🙂🙂-14.0000-2000-12-14 12:43:10-2000-12-14 12:43:10-ef-2000-12-14-12:43:10-2000-12-14 12:43:10.1234 +10:00 -比尔·拉-15.0000-2000-12-15 12:43:10-2000-12-15 12:43:10-gh-2000-12-15-12:43:10-2000-12-15 12:43:10.1234 +10:00 -莫斯-16.0000-2000-12-16 12:43:10-2000-12-16 12:43:10-ip-2000-12-16-12:43:10-2000-12-16 12:43:10.1234 +10:00 +abc-12.0000-2000-12-12 12:43:10-2000-12-12 12:43:10-扡-2000-12-12-12:43:10-2000-12-12 12:43:10.1234 +10:00 +🙂defghi-13.0000-2000-12-13 12:43:10-2000-12-13 12:43:10-摣-2000-12-13-12:43:10-2000-12-13 12:43:10.1234 +10:00 +🙂🙂-14.0000-2000-12-14 12:43:10-2000-12-14 12:43:10-晥-2000-12-14-12:43:10-2000-12-14 12:43:10.1234 +10:00 +比尔·拉-15.0000-2000-12-15 12:43:10-2000-12-15 12:43:10-桧-2000-12-15-12:43:10-2000-12-15 12:43:10.1234 +10:00 +莫斯-16.0000-2000-12-16 12:43:10-2000-12-16 12:43:10-灩-2000-12-16-12:43:10-2000-12-16 12:43:10.1234 +10:00 -Anikait-17.0000-2000-12-17 12:43:10-2000-12-17 12:43:10-qr-2000-12-17-12:43:10-2000-12-17 12:43:10.1234 +10:00 +Anikait-17.0000-2000-12-17 12:43:10-2000-12-17 12:43:10-牱-2000-12-17-12:43:10-2000-12-17 12:43:10.1234 +10:00 -Agrawal-18.0000-2000-12-18 12:43:10-2000-12-18 12:43:10-rs-2000-12-18-12:43:10-2000-12-18 12:43:10.1234 +10:00 +Agrawal-18.0000-2000-12-18 12:43:10-2000-12-18 12:43:10-獲-2000-12-18-12:43:10-2000-12-18 12:43:10.1234 +10:00 ~~END~~ @@ -3249,7 +3249,7 @@ SELECT babel_3409_concat_ws_dep_func2() GO ~~START~~ nvarchar -abc-ab-abc-abc +abc-扡-abc-abc ~~END~~ diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/replace-before-15_8-or-16_4-vu-verify.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/replace-before-15_8-or-16_4-vu-verify.out index a2a5a75a81..7d9d103e5f 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/replace-before-15_8-or-16_4-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/replace-before-15_8-or-16_4-vu-verify.out @@ -2139,7 +2139,7 @@ SELECT replace(@inputString, @pattern, @replacement) GO ~~START~~ nvarchar -尔·比 DEF +ABCDEF ~~END~~ @@ -2148,7 +2148,7 @@ SELECT replace(@inputString, @pattern, @replacement) GO ~~START~~ nvarchar -ABCD +䉁䑃 ~~END~~ diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/replace-vu-verify.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/replace-vu-verify.out index 7a0da102e9..44c47c7514 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/replace-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/replace-vu-verify.out @@ -2139,7 +2139,7 @@ SELECT replace(@inputString, @pattern, @replacement) GO ~~START~~ nvarchar -尔·比 DEF +ABCDEF ~~END~~ @@ -2148,7 +2148,7 @@ SELECT replace(@inputString, @pattern, @replacement) GO ~~START~~ nvarchar -ABCD +䉁䑃 ~~END~~ diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/stuff-before-15_8-or-16_4-vu-verify.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/stuff-before-15_8-or-16_4-vu-verify.out index 14bef8f622..ef87fe7872 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/stuff-before-15_8-or-16_4-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/stuff-before-15_8-or-16_4-vu-verify.out @@ -976,7 +976,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -abcefefghi?? +abc晥efghi?? ~~END~~ DECLARE @inputString NCHAR(25) = N'abc🙂defghi🙂🙂' @@ -985,7 +985,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -abcefefghi?? +abc晥efghi?? ~~END~~ DECLARE @inputString NCHAR(25) = N'abc🙂defghi🙂🙂' @@ -1070,7 +1070,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -比尔·ef斯 +比尔·晥斯 ~~END~~ DECLARE @inputString NCHAR(25) = N'比尔·拉莫斯' @@ -1079,7 +1079,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -比尔·ef斯 +比尔·晥斯 ~~END~~ DECLARE @inputString NCHAR(25) = N'比尔·拉莫斯' @@ -1164,7 +1164,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) COLLATE CHINESE_PRC_CI_AS GO ~~START~~ nvarchar -比尔·ef斯 +比尔·晥斯 ~~END~~ DECLARE @inputString NCHAR(25) = N'比尔·拉莫斯' @@ -1173,7 +1173,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) COLLATE CHINESE_PRC_CI_AS GO ~~START~~ nvarchar -比尔·ef斯 +比尔·晥斯 ~~END~~ DECLARE @inputString NCHAR(25) = N'比尔·拉莫斯' @@ -1270,7 +1270,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -abcefefghi🙂🙂 +abc晥efghi🙂🙂 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'abc🙂defghi🙂🙂' @@ -1279,7 +1279,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -abcefefghi🙂🙂 +abc晥efghi🙂🙂 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'abc🙂defghi🙂🙂' @@ -1364,7 +1364,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -比尔·ef斯 +比尔·晥斯 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'比尔·拉莫斯' @@ -1373,7 +1373,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -比尔·ef斯 +比尔·晥斯 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'比尔·拉莫斯' @@ -1458,7 +1458,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) COLLATE CHINESE_PRC_CI_AS GO ~~START~~ nvarchar -比尔·ef斯 +比尔·晥斯 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'比尔·拉莫斯' @@ -1467,7 +1467,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) COLLATE CHINESE_PRC_CI_AS GO ~~START~~ nvarchar -比尔·ef斯 +比尔·晥斯 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'比尔·拉莫斯' diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/stuff-vu-verify.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/stuff-vu-verify.out index 86f90d1b4d..821c160cab 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/stuff-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/stuff-vu-verify.out @@ -976,7 +976,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -abcefefghi?? +abc晥efghi?? ~~END~~ DECLARE @inputString NCHAR(25) = N'abc🙂defghi🙂🙂' @@ -985,7 +985,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -abcefefghi?? +abc晥efghi?? ~~END~~ DECLARE @inputString NCHAR(25) = N'abc🙂defghi🙂🙂' @@ -1070,7 +1070,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -比尔·ef斯 +比尔·晥斯 ~~END~~ DECLARE @inputString NCHAR(25) = N'比尔·拉莫斯' @@ -1079,7 +1079,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -比尔·ef斯 +比尔·晥斯 ~~END~~ DECLARE @inputString NCHAR(25) = N'比尔·拉莫斯' @@ -1164,7 +1164,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) COLLATE CHINESE_PRC_CI_AS GO ~~START~~ nvarchar -比尔·ef斯 +比尔·晥斯 ~~END~~ DECLARE @inputString NCHAR(25) = N'比尔·拉莫斯' @@ -1173,7 +1173,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) COLLATE CHINESE_PRC_CI_AS GO ~~START~~ nvarchar -比尔·ef斯 +比尔·晥斯 ~~END~~ DECLARE @inputString NCHAR(25) = N'比尔·拉莫斯' @@ -1270,7 +1270,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -abcefefghi🙂🙂 +abc晥efghi🙂🙂 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'abc🙂defghi🙂🙂' @@ -1279,7 +1279,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -abcefefghi🙂🙂 +abc晥efghi🙂🙂 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'abc🙂defghi🙂🙂' @@ -1364,7 +1364,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -比尔·ef斯 +比尔·晥斯 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'比尔·拉莫斯' @@ -1373,7 +1373,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -比尔·ef斯 +比尔·晥斯 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'比尔·拉莫斯' @@ -1458,7 +1458,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) COLLATE CHINESE_PRC_CI_AS GO ~~START~~ nvarchar -比尔·ef斯 +比尔·晥斯 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'比尔·拉莫斯' @@ -1467,7 +1467,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) COLLATE CHINESE_PRC_CI_AS GO ~~START~~ nvarchar -比尔·ef斯 +比尔·晥斯 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'比尔·拉莫斯' diff --git a/test/JDBC/expected/non_default_server_collation/japanese_ci_as/cast_nvarchar_test-vu-verify.out b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/cast_nvarchar_test-vu-verify.out new file mode 100644 index 0000000000..d7d02060a5 --- /dev/null +++ b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/cast_nvarchar_test-vu-verify.out @@ -0,0 +1,384 @@ +-- TEST CASE 1: creating a table and then calling hashbytes for nvarchar and varchar input +insert into TestHash values('value1', 'value1'); +GO +~~ROW COUNT: 1~~ + + +SELECT DATALENGTH( nvarchar_data) as nvarchar_data_datalength + , LEN( nvarchar_data) AS nvarchar_data_len + , DATALENGTH( varchar_data) as varchar_data_btyes_datalength + , LEN( varchar_data) AS varchar_data_len + , * +from TestHash; +GO +~~START~~ +int#!#int#!#int#!#int#!#nvarchar#!#varchar#!#varbinary#!#varbinary#!#varbinary#!#varbinary +6#!#6#!#6#!#6#!#value1#!#value1#!#BFF418C872BAFEE476F578F93BAD732F499B4193#!#BFF418C872BAFEE476F578F93BAD732F499B4193#!#8107759ABABCBFA34BCB02BC4309CAF6354982AB#!#8107759ABABCBFA34BCB02BC4309CAF6354982AB +~~END~~ + +-- TEST CASE 2: Casting nvarchar and varchar with different algorithms using Hashbytes +SELECT hashbytes( 'sha1', 'test string' ) as vary_string, hashbytes( 'sha1', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +661295C9CBF9D6B2F6428414504A8DEED3020641#!#B4AA115AEBADD046850F18E1DF71A8BF254CD688 +~~END~~ + + +SELECT hashbytes( 'MD2', 'test string' ) as vary_string, hashbytes( 'MD2', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +#!# +~~END~~ + + +SELECT hashbytes( 'MD4', 'test string' ) as vary_string, hashbytes( 'MD4', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +#!# +~~END~~ + + +SELECT hashbytes( 'MD5', 'test string' ) as vary_string, hashbytes( 'MD5', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +6F8DB599DE986FAB7A21625B7916589C#!#8EF34B0E4B64320AA590A0DDD043D0A8 +~~END~~ + + +SELECT hashbytes( 'SHA2_256', 'test string' ) as vary_string, hashbytes( 'SHA2_256', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +D5579C46DFCC7F18207013E65B44E4CB4E2C2298F4AC457BA8F82743F31E930B#!#BDB5A12B473383674D31C9068D13896278CA7979CF99CDD592C64B3994FCB5CE +~~END~~ + + +SELECT hashbytes( 'SHA2_512', 'test string' ) as vary_string, hashbytes( 'SHA2_512', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +10E6D647AF44624442F388C2C14A787FF8B17E6165B83D767EC047768D8CBCB71A1A3226E7CC7816BC79C0427D94A9DA688C41A3992C7BF5E4D7CC3E0BE5DBAC#!#7740DCE2348B37BDBD313DC4577E5FA91687EB35EE3B39A4BDA39B70EA20C5FE7865289F1612946E7CD89458CE42C8AC5577FB716975FAD0F9C53F3A28B10885 +~~END~~ + + +SELECT hashbytes( 'SHA', 'test string' ) as vary_string, hashbytes( 'SHA', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +661295C9CBF9D6B2F6428414504A8DEED3020641#!#B4AA115AEBADD046850F18E1DF71A8BF254CD688 +~~END~~ + + +SELECT hashbytes( 'sha1', 'test string') +GO +~~START~~ +varbinary +661295C9CBF9D6B2F6428414504A8DEED3020641 +~~END~~ + +--TEST CASE 3: testing hashbytes via casting a varchar to nvarchar +SELECT hashbytes('sha1',cast('test string' as sys.nvarchar)) +GO +~~START~~ +varbinary +B4AA115AEBADD046850F18E1DF71A8BF254CD688 +~~END~~ + + + +--TEST CASE 4: Casting function for nvarchar to varbinary +SELECT cast(N'test string' as varbinary); +GO +~~START~~ +varbinary +7400650073007400200073007400720069006E006700 +~~END~~ + + +SELECT cast(cast(cast('ab' AS nvarchar(10)) as varbinary(2)) as nvarchar(2)); +GO +~~START~~ +nvarchar +a +~~END~~ + + +-- Test Case 5: Empty strings and NULL values +SELECT HASHBYTES('SHA1', '') AS empty_varchar, + HASHBYTES('SHA1', N'') AS empty_nvarchar, + HASHBYTES('SHA1', NULL) AS null_input; +GO +~~START~~ +varbinary#!#varbinary#!#varbinary +DA39A3EE5E6B4B0D3255BFEF95601890AFD80709#!#DA39A3EE5E6B4B0D3255BFEF95601890AFD80709#!# +~~END~~ + + +-- Test Case 6: Unicode characters +SELECT HASHBYTES('SHA1', N'こんにちは') AS japanese, + HASHBYTES('SHA1', N'Здравствуйте') AS russian, + HASHBYTES('SHA1', N'🙂😊😀') AS emojis; +GO +~~START~~ +varbinary#!#varbinary#!#varbinary +468B7C156768A579085BBBD1630D2ED215D3A86C#!#EBFDE11B499DEA0130EE3DFCDC632ADEA0AD71F2#!#4D4A69489A61649C1330FB5B600191E00B76B6A0 +~~END~~ + + +-- Test Case 8: Different collations +SELECT HASHBYTES('SHA1', N'hello' COLLATE Latin1_General_CI_AS) AS ci_as, + HASHBYTES('SHA1', N'hello' COLLATE Latin1_General_CS_AS) AS cs_as; +GO +~~START~~ +varbinary#!#varbinary +B6D795FBD58CC7592D955A219374339A323801A9#!#B6D795FBD58CC7592D955A219374339A323801A9 +~~END~~ + + +-- Test Case 9: Combining varchar and nvarchar +SELECT HASHBYTES('SHA1', 'hello' + N'world') AS combined; +GO +~~START~~ +varbinary +D981D4B037201043FFDCBD310FCDE36F44D9AAC5 +~~END~~ + + +-- Test Case 10: Roundtrip conversions +SELECT CAST(CAST(N'test' AS VARBINARY(8)) AS NVARCHAR(4)) AS nvarchar_roundtrip, + CAST(CAST('test' AS VARBINARY(8)) AS VARCHAR(4)) AS varchar_roundtrip; +GO +~~START~~ +nvarchar#!#varchar +test#!#test +~~END~~ + + +-- Test Case 11: CAST and CONVERT between varchar, nvarchar, and varbinary +SELECT CAST(N'hello' AS VARBINARY(10)) AS nvarchar_to_varbinary, + CAST('hello' AS VARBINARY(10)) AS varchar_to_varbinary, + CONVERT(VARBINARY(10), N'hello') AS nvarchar_to_varbinary_convert, + CONVERT(VARBINARY(10), 'hello') AS varchar_to_varbinary_convert; +GO +~~START~~ +varbinary#!#varbinary#!#varbinary#!#varbinary +680065006C006C006F00#!#68656C6C6F#!#68656C6C6F#!#68656C6C6F +~~END~~ + + +-- Test Case 12: Testing with special characters +SELECT HASHBYTES('SHA1', 'Hello, World!') AS varchar_special, + HASHBYTES('SHA1', N'Hello, World!') AS nvarchar_special, + HASHBYTES('SHA1', 'Hello' + CHAR(13) + CHAR(10) + 'World') AS varchar_newline, + HASHBYTES('SHA1', N'Hello' + NCHAR(13) + NCHAR(10) + N'World') AS nvarchar_newline; +GO +~~START~~ +varbinary#!#varbinary#!#varbinary#!#varbinary +0A0A9F2A6772942557AB5355D76AF442F8F65E01#!#1F725EE9D69965F6F755140E66089A041B5AACC2#!#62E451F6ED58D1FF234A05B8467C0CEB1D4B285F#!#C97EDD9DE05497798CBA896371C594DF87043753 +~~END~~ + + +-- Test Case 13: NVARCHAR -> VARBINARY -> VARCHAR -> NVARCHAR -> VARBINARY +SELECT CAST( + CAST( + CAST( + CAST(N'Hello World' AS VARBINARY(100)) + AS VARCHAR(100)) + AS NVARCHAR(100)) +AS VARBINARY(100)) AS four_casts; +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Failed to convert from data type varbinary to varchar, invalid byte sequence for encoding "SJIS": 0x00)~~ + + +-- Test Case 14: VARCHAR -> NVARCHAR -> VARBINARY -> NVARCHAR -> VARCHAR +SELECT CAST( + CAST( + CAST( + CAST('Test String' AS NVARCHAR(50)) + AS VARBINARY(50)) + AS NVARCHAR(50)) +AS VARCHAR(50)) AS four_casts; +GO +~~START~~ +varchar +Test String +~~END~~ + + +-- Test Case 15: Implicit conversion from data type nvarchar to varbinary is not allowed. +DECLARE @a varbinary(10); SET @a = CAST(N'21' AS nvarchar(10)); SELECT @a +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Implicit conversion from data type nvarchar to varbinary is not allowed. Use the CONVERT function to run this query.)~~ + + +-- Test Case 16: Casting with UDT on nvarchar -> varbinary, UDT on varbinary to nvarchar, UDT on nvarchar to UDT on varbinary +create type user_defined_nvarchar from nvarchar(50); +select cast(cast(N'test string' as user_defined_nvarchar) as varbinary) +GO +~~START~~ +varbinary +7400650073007400200073007400720069006E006700 +~~END~~ + + +create type user_defined_varbinary from varbinary(50); +select cast(cast(0x7400650073007400200073007400720069006E006700 as user_defined_varbinary) as nvarchar) +GO +~~START~~ +nvarchar +test string +~~END~~ + + +select cast(cast(N'test string' as user_defined_nvarchar) as user_defined_varbinary) +go +~~START~~ +varbinary +7400650073007400200073007400720069006E006700 +~~END~~ + +-- Test Case 17: NVARCHAR-> BINARY +select cast(N'test string' as binary) +GO +~~START~~ +binary +7400650073007400200073007400720069006E0067000000000000000000 +~~END~~ + +-- Test Case 18: NVARCHAR-> User Defined varbinary +select cast(N'test string' as user_defined_varbinary) +GO +~~START~~ +varbinary +7400650073007400200073007400720069006E006700 +~~END~~ + +-- Test Case 19: User defined hashbytes function +create function dbo.hashbytes(@data sys.varchar)returns sys.varchar AS BEGIN return "dummy hashbytes";END +GO +SELECT hashbytes( 'SHA', 'test string' ) as vary_string, hashbytes( 'SHA', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +661295C9CBF9D6B2F6428414504A8DEED3020641#!#B4AA115AEBADD046850F18E1DF71A8BF254CD688 +~~END~~ + +select hashbytes('abc') +GO +~~START~~ +varchar +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: column "dummy hashbytes" does not exist)~~ + +drop function dbo.hashbytes +GO + + +-- Test 20: Calling the function, procedure, views from prepare scripts +-- Test CastNVarcharToVarbinary function +DECLARE @TestString NVARCHAR(100) = N'Test String'; +DECLARE @BinaryResult VARBINARY(MAX); +SET @BinaryResult = dbo.CastNVarcharToVarbinary(@TestString); +select cast (@BinaryResult as nvarchar) +GO +~~START~~ +nvarchar +Test String +~~END~~ + + + +-- Test CastVarbinaryToNVarchar function +DECLARE @TestBinary VARBINARY(100) = 0x54657374537472696E67; -- 'Test String' in ASCII +DECLARE @StringResult NVARCHAR(MAX); +SET @StringResult = dbo.CastVarbinaryToNVarchar(@TestBinary); +select cast (@StringResult as nvarchar) +GO +~~START~~ +nvarchar +敔瑳瑓楲杮 +~~END~~ + + + +-- Test CastDemoView +DECLARE @ViewResult TABLE ( + NVarcharToVarbinary VARBINARY(MAX), + VarbinaryToNVarchar NVARCHAR(MAX) +); +INSERT INTO @ViewResult +SELECT * FROM dbo.CastDemoView; +go +~~ROW COUNT: 1~~ + + +-- TEST CASE 21: Assigned Casting +DECLARE @NVarcharValue NVARCHAR(100) = N'Hello, World!'; +DECLARE @AssignedVarbinary VARBINARY(100); +SET @AssignedVarbinary = CAST(@NVarcharValue AS VARBINARY(100)); +select CAST(@AssignedVarbinary AS NVARCHAR(100)); +GO +~~START~~ +nvarchar +Hello, World! +~~END~~ + + + + +--TEST CASE 22: Calling hashbytes via function, procedure, views +-- Test the HashMultipleTypes function +DECLARE @TestVarchar VARCHAR(10) = 'Test'; +DECLARE @TestNVarchar NVARCHAR(10) = N'Test'; +DECLARE @TestVarbinary VARBINARY(10) = 0x54657374; -- 'Test' in ASCII +SELECT * FROM dbo.HashMultipleTypes(@TestVarchar, @TestNVarchar, @TestVarbinary); +GO +~~START~~ +varbinary#!#varbinary#!#varbinary +532EAABD9574880DBF76B9B8CC00832C20A6EC113D682299550D7A6E0F345E25#!#E6FA3CA87B1B641AB646D3B4933BBA8D0970763F030B6578A60ABDEAE7366247#!#532EAABD9574880DBF76B9B8CC00832C20A6EC113D682299550D7A6E0F345E25 +~~END~~ + +-- Test the HashDemoView +SELECT * FROM dbo.HashDemoView; +GO +~~START~~ +varbinary#!#varbinary#!#varbinary +185F8DB32271FE25F561A6FC938B2E264306EC304EDA518007D1764826381969#!#A07E4F7343246C82B26F32E56F85418D518D8B2F2DAE77F1D56FE7AF50DB97AF#!#185F8DB32271FE25F561A6FC938B2E264306EC304EDA518007D1764826381969 +~~END~~ + + +--TEST CASE 23: BINARY TO NVARCHAR +select cast(cast(N'test string' as binary) as nvarchar) +GO +~~START~~ +nvarchar +test string +~~END~~ + +--TEST CASE 24: NVARCHAR TO BINARY with maxlen < length of actual string +select cast(0x610061006100610061006100610061006100 as nvarchar(5)) +GO +~~START~~ +nvarchar +aaaaa +~~END~~ + +select cast(0x8765 as nvarchar(1)) +GO +~~START~~ +nvarchar +文 +~~END~~ + + + + diff --git a/test/JDBC/expected/non_default_server_collation/japanese_ci_as/cast_nvarchar_test_before_16_5-vu-verify.out b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/cast_nvarchar_test_before_16_5-vu-verify.out new file mode 100644 index 0000000000..0290e11330 --- /dev/null +++ b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/cast_nvarchar_test_before_16_5-vu-verify.out @@ -0,0 +1,368 @@ +-- TEST CASE 1: creating a table and then calling hashbytes for nvarchar and varchar input +insert into TestHash values('value1', 'value1'); +GO +~~ROW COUNT: 1~~ + + +SELECT DATALENGTH( nvarchar_data) as nvarchar_data_datalength + , LEN( nvarchar_data) AS nvarchar_data_len + , DATALENGTH( varchar_data) as varchar_data_btyes_datalength + , LEN( varchar_data) AS varchar_data_len + , * +from TestHash; +GO +~~START~~ +int#!#int#!#int#!#int#!#nvarchar#!#varchar#!#varbinary#!#varbinary#!#varbinary#!#varbinary +6#!#6#!#6#!#6#!#value1#!#value1#!#8107759ABABCBFA34BCB02BC4309CAF6354982AB#!#8107759ABABCBFA34BCB02BC4309CAF6354982AB#!#8107759ABABCBFA34BCB02BC4309CAF6354982AB#!#8107759ABABCBFA34BCB02BC4309CAF6354982AB +~~END~~ + +-- TEST CASE 2: Casting nvarchar and varchar with different algorithms using Hashbytes +SELECT hashbytes( 'sha1', 'test string' ) as vary_string, hashbytes( 'sha1', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +661295C9CBF9D6B2F6428414504A8DEED3020641#!#661295C9CBF9D6B2F6428414504A8DEED3020641 +~~END~~ + + +SELECT hashbytes( 'MD2', 'test string' ) as vary_string, hashbytes( 'MD2', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +#!# +~~END~~ + + +SELECT hashbytes( 'MD4', 'test string' ) as vary_string, hashbytes( 'MD4', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +#!# +~~END~~ + + +SELECT hashbytes( 'MD5', 'test string' ) as vary_string, hashbytes( 'MD5', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +6F8DB599DE986FAB7A21625B7916589C#!#6F8DB599DE986FAB7A21625B7916589C +~~END~~ + + +SELECT hashbytes( 'SHA2_256', 'test string' ) as vary_string, hashbytes( 'SHA2_256', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +D5579C46DFCC7F18207013E65B44E4CB4E2C2298F4AC457BA8F82743F31E930B#!#D5579C46DFCC7F18207013E65B44E4CB4E2C2298F4AC457BA8F82743F31E930B +~~END~~ + + +SELECT hashbytes( 'SHA2_512', 'test string' ) as vary_string, hashbytes( 'SHA2_512', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +10E6D647AF44624442F388C2C14A787FF8B17E6165B83D767EC047768D8CBCB71A1A3226E7CC7816BC79C0427D94A9DA688C41A3992C7BF5E4D7CC3E0BE5DBAC#!#10E6D647AF44624442F388C2C14A787FF8B17E6165B83D767EC047768D8CBCB71A1A3226E7CC7816BC79C0427D94A9DA688C41A3992C7BF5E4D7CC3E0BE5DBAC +~~END~~ + + +SELECT hashbytes( 'SHA', 'test string' ) as vary_string, hashbytes( 'SHA', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +661295C9CBF9D6B2F6428414504A8DEED3020641#!#661295C9CBF9D6B2F6428414504A8DEED3020641 +~~END~~ + + +SELECT hashbytes( 'sha1', 'test string') +GO +~~START~~ +varbinary +661295C9CBF9D6B2F6428414504A8DEED3020641 +~~END~~ + +--TEST CASE 3: testing hashbytes via casting a varchar to nvarchar +SELECT hashbytes('sha1',cast('test string' as sys.nvarchar)) +GO +~~START~~ +varbinary +661295C9CBF9D6B2F6428414504A8DEED3020641 +~~END~~ + + + +--TEST CASE 4: Casting function for nvarchar to varbinary +SELECT cast(N'test string' as varbinary); +GO +~~START~~ +varbinary +7400650073007400200073007400720069006E006700 +~~END~~ + + +SELECT cast(cast(cast('ab' AS nvarchar(10)) as varbinary(2)) as nvarchar(2)); +GO +~~START~~ +nvarchar +a +~~END~~ + + +-- Test Case 5: Empty strings and NULL values +SELECT HASHBYTES('SHA1', '') AS empty_varchar, + HASHBYTES('SHA1', N'') AS empty_nvarchar, + HASHBYTES('SHA1', NULL) AS null_input; +GO +~~START~~ +varbinary#!#varbinary#!#varbinary +DA39A3EE5E6B4B0D3255BFEF95601890AFD80709#!#DA39A3EE5E6B4B0D3255BFEF95601890AFD80709#!# +~~END~~ + + +-- Test Case 6: Unicode characters +SELECT HASHBYTES('SHA1', N'こんにちは') AS japanese, + HASHBYTES('SHA1', N'Здравствуйте') AS russian, + HASHBYTES('SHA1', N'🙂😊😀') AS emojis; +GO +~~START~~ +varbinary#!#varbinary#!#varbinary +20427A708C3F6F07CF12AB23557982D9E6D23B61#!#E2D105A2541F2DC6C8B93DF73D07DF30B33FD80A#!#3B114970B215D62CB987A4D5644FEE7001C78234 +~~END~~ + + +-- Test Case 8: Different collations +SELECT HASHBYTES('SHA1', N'hello' COLLATE Latin1_General_CI_AS) AS ci_as, + HASHBYTES('SHA1', N'hello' COLLATE Latin1_General_CS_AS) AS cs_as; +GO +~~START~~ +varbinary#!#varbinary +AAF4C61DDCC5E8A2DABEDE0F3B482CD9AEA9434D#!#AAF4C61DDCC5E8A2DABEDE0F3B482CD9AEA9434D +~~END~~ + + +-- Test Case 9: Combining varchar and nvarchar +SELECT HASHBYTES('SHA1', 'hello' + N'world') AS combined; +GO +~~START~~ +varbinary +6ADFB183A4A2C94A2F92DAB5ADE762A47889A5A1 +~~END~~ + + +-- Test Case 10: Roundtrip conversions +SELECT CAST(CAST(N'test' AS VARBINARY(8)) AS NVARCHAR(4)) AS nvarchar_roundtrip, + CAST(CAST('test' AS VARBINARY(8)) AS VARCHAR(4)) AS varchar_roundtrip; +GO +~~START~~ +nvarchar#!#varchar +test#!#test +~~END~~ + + +-- Test Case 11: CAST and CONVERT between varchar, nvarchar, and varbinary +SELECT CAST(N'hello' AS VARBINARY(10)) AS nvarchar_to_varbinary, + CAST('hello' AS VARBINARY(10)) AS varchar_to_varbinary, + CONVERT(VARBINARY(10), N'hello') AS nvarchar_to_varbinary_convert, + CONVERT(VARBINARY(10), 'hello') AS varchar_to_varbinary_convert; +GO +~~START~~ +varbinary#!#varbinary#!#varbinary#!#varbinary +680065006C006C006F00#!#68656C6C6F#!#68656C6C6F#!#68656C6C6F +~~END~~ + + +-- Test Case 12: Testing with special characters +SELECT HASHBYTES('SHA1', 'Hello, World!') AS varchar_special, + HASHBYTES('SHA1', N'Hello, World!') AS nvarchar_special, + HASHBYTES('SHA1', 'Hello' + CHAR(13) + CHAR(10) + 'World') AS varchar_newline, + HASHBYTES('SHA1', N'Hello' + NCHAR(13) + NCHAR(10) + N'World') AS nvarchar_newline; +GO +~~START~~ +varbinary#!#varbinary#!#varbinary#!#varbinary +0A0A9F2A6772942557AB5355D76AF442F8F65E01#!#0A0A9F2A6772942557AB5355D76AF442F8F65E01#!#62E451F6ED58D1FF234A05B8467C0CEB1D4B285F#!#62E451F6ED58D1FF234A05B8467C0CEB1D4B285F +~~END~~ + + +-- Test Case 13: NVARCHAR -> VARBINARY -> VARCHAR -> NVARCHAR -> VARBINARY +SELECT CAST( + CAST( + CAST( + CAST(N'Hello World' AS VARBINARY(100)) + AS VARCHAR(100)) + AS NVARCHAR(100)) +AS VARBINARY(100)) AS four_casts; +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Failed to convert from data type varbinary to varchar, invalid byte sequence for encoding "SJIS": 0x00)~~ + + +-- Test Case 14: VARCHAR -> NVARCHAR -> VARBINARY -> NVARCHAR -> VARCHAR +SELECT CAST( + CAST( + CAST( + CAST('Test String' AS NVARCHAR(50)) + AS VARBINARY(50)) + AS NVARCHAR(50)) +AS VARCHAR(50)) AS four_casts; +GO +~~START~~ +varchar +Test String +~~END~~ + + +-- Test Case 15: Implicit conversion from data type nvarchar to varbinary is not allowed. +DECLARE @a varbinary(10); SET @a = CAST(N'21' AS nvarchar(10)); SELECT @a +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Implicit conversion from data type nvarchar to varbinary is not allowed. Use the CONVERT function to run this query.)~~ + + +-- Test Case 16: Casting with UDT on nvarchar -> varbinary, UDT on varbinary to nvarchar, UDT on nvarchar to UDT on varbinary +create type user_defined_nvarchar from nvarchar(50); +select cast(cast(N'test string' as user_defined_nvarchar) as varbinary) +GO +~~START~~ +varbinary +7400650073007400200073007400720069006E006700 +~~END~~ + + +create type user_defined_varbinary from varbinary(50); +select cast(cast(0x7400650073007400200073007400720069006E006700 as user_defined_varbinary) as nvarchar) +GO +~~START~~ +nvarchar +test string +~~END~~ + + +select cast(cast(N'test string' as user_defined_nvarchar) as user_defined_varbinary) +go +~~START~~ +varbinary +7400650073007400200073007400720069006E006700 +~~END~~ + +-- Test Case 17: NVARCHAR-> BINARY +select cast(N'test string' as binary) +GO +~~START~~ +binary +7400650073007400200073007400720069006E0067000000000000000000 +~~END~~ + +-- Test Case 18: NVARCHAR-> User Defined varbinary +select cast(N'test string' as user_defined_varbinary) +GO +~~START~~ +varbinary +7400650073007400200073007400720069006E006700 +~~END~~ + +-- Test Case 19: User defined hashbytes function +create function dbo.hashbytes(@data sys.varchar)returns sys.varchar AS BEGIN return "dummy hashbytes";END +GO +SELECT hashbytes( 'SHA', 'test string' ) as vary_string, hashbytes( 'SHA', N'test string' ) as unicode_string +GO +~~START~~ +varbinary#!#varbinary +661295C9CBF9D6B2F6428414504A8DEED3020641#!#661295C9CBF9D6B2F6428414504A8DEED3020641 +~~END~~ + +select hashbytes('abc') +GO +~~START~~ +varchar +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: column "dummy hashbytes" does not exist)~~ + +drop function dbo.hashbytes +GO + + +-- Test 20: Calling the function, procedure, views from prepare scripts +-- Test CastNVarcharToVarbinary function +DECLARE @TestString NVARCHAR(100) = N'Test String'; +DECLARE @BinaryResult VARBINARY(MAX); +SET @BinaryResult = dbo.CastNVarcharToVarbinary(@TestString); +select cast (@BinaryResult as nvarchar) +GO +~~START~~ +nvarchar +Test String +~~END~~ + + + +-- Test CastVarbinaryToNVarchar function +DECLARE @TestBinary VARBINARY(100) = 0x54657374537472696E67; -- 'Test String' in ASCII +DECLARE @StringResult NVARCHAR(MAX); +SET @StringResult = dbo.CastVarbinaryToNVarchar(@TestBinary); +select cast (@StringResult as nvarchar) +GO +~~START~~ +nvarchar +敔瑳瑓楲杮 +~~END~~ + + + +-- Test CastDemoView +DECLARE @ViewResult TABLE ( + NVarcharToVarbinary VARBINARY(MAX), + VarbinaryToNVarchar NVARCHAR(MAX) +); +INSERT INTO @ViewResult +SELECT * FROM dbo.CastDemoView; +go +~~ROW COUNT: 1~~ + + +-- TEST CASE 21: Assigned Casting +DECLARE @NVarcharValue NVARCHAR(100) = N'Hello, World!'; +DECLARE @AssignedVarbinary VARBINARY(100); +SET @AssignedVarbinary = CAST(@NVarcharValue AS VARBINARY(100)); +select CAST(@AssignedVarbinary AS NVARCHAR(100)); +GO +~~START~~ +nvarchar +Hello, World! +~~END~~ + + + + +--TEST CASE 22: Calling hashbytes via function, procedure, views +-- Test the HashMultipleTypes function +DECLARE @TestVarchar VARCHAR(10) = 'Test'; +DECLARE @TestNVarchar NVARCHAR(10) = N'Test'; +DECLARE @TestVarbinary VARBINARY(10) = 0x54657374; -- 'Test' in ASCII +SELECT * FROM dbo.HashMultipleTypes(@TestVarchar, @TestNVarchar, @TestVarbinary); +GO +~~START~~ +varbinary#!#varbinary#!#varbinary +532EAABD9574880DBF76B9B8CC00832C20A6EC113D682299550D7A6E0F345E25#!#532EAABD9574880DBF76B9B8CC00832C20A6EC113D682299550D7A6E0F345E25#!#532EAABD9574880DBF76B9B8CC00832C20A6EC113D682299550D7A6E0F345E25 +~~END~~ + +-- Test the HashDemoView +SELECT * FROM dbo.HashDemoView; +GO +~~START~~ +varbinary#!#varbinary#!#varbinary +185F8DB32271FE25F561A6FC938B2E264306EC304EDA518007D1764826381969#!#185F8DB32271FE25F561A6FC938B2E264306EC304EDA518007D1764826381969#!#185F8DB32271FE25F561A6FC938B2E264306EC304EDA518007D1764826381969 +~~END~~ + + +--TEST CASE 23: BINARY TO NVARCHAR +select cast(cast(N'test string' as binary) as nvarchar) +GO +~~START~~ +nvarchar +test string +~~END~~ + + + diff --git a/test/JDBC/expected/non_default_server_collation/japanese_ci_as/concat-vu-verify.out b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/concat-vu-verify.out index 2030b1b4a0..048237bdea 100644 --- a/test/JDBC/expected/non_default_server_collation/japanese_ci_as/concat-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/concat-vu-verify.out @@ -421,7 +421,7 @@ SELECT CONCAT( 'a', 'b', CAST('🙂🙂' AS nvarchar), 'd', 'e', CAST('f' AS cha GO ~~START~~ nvarchar -ab🙂🙂def比尔hijklmnopqrstuvwxyzABCDEFGHIJKLMefOPQRST🙂🙂VWXYZ0123456789.,-_!@#$%^&*()[]{}<>/\\|:;"\?+=~`abcdefg +ab🙂🙂def比尔hijklmnopqrstuvwxyzABCDEFGHIJKLM晥OPQRST🙂🙂VWXYZ0123456789.,-_!@#$%^&*()[]{}<>/\\|:;"\?+=~`abcde杦 ~~END~~ @@ -1230,16 +1230,16 @@ SELECT CONCAT(col_nvarchar, col_binary) from babel_3409_concat_t1 ORDER BY id GO ~~START~~ nvarchar -abcab -🙂defghicd -🙂🙂ef -比尔·拉gh -莫斯ip +abc扡 +🙂defghi摣 +🙂🙂晥 +比尔·拉桧 +莫斯灩 -Anikaitqr +Anikait牱 -Agrawalrs +Agrawal獲 ~~END~~ @@ -1247,16 +1247,16 @@ SELECT CONCAT(col_nvarchar, col_varbinary) from babel_3409_concat_t1 ORDER BY id GO ~~START~~ nvarchar -abcab -🙂defghicd -🙂🙂ef -比尔·拉gh -莫斯ip +abc扡 +🙂defghi摣 +🙂🙂晥 +比尔·拉桧 +莫斯灩 -Anikaitqr +Anikait牱 -Agrawalrs +Agrawal獲 ~~END~~ @@ -1579,16 +1579,16 @@ EXEC babel_3409_concat_dep_proc2 GO ~~START~~ nvarchar -abc12.00002000-12-12 12:43:102000-12-12 12:43:10ab2000-12-1212:43:102000-12-12 12:43:10.1234 +10:00 -🙂defghi13.00002000-12-13 12:43:102000-12-13 12:43:10cd2000-12-1312:43:102000-12-13 12:43:10.1234 +10:00 -🙂🙂14.00002000-12-14 12:43:102000-12-14 12:43:10ef2000-12-1412:43:102000-12-14 12:43:10.1234 +10:00 -比尔·拉15.00002000-12-15 12:43:102000-12-15 12:43:10gh2000-12-1512:43:102000-12-15 12:43:10.1234 +10:00 -莫斯16.00002000-12-16 12:43:102000-12-16 12:43:10ip2000-12-1612:43:102000-12-16 12:43:10.1234 +10:00 +abc12.00002000-12-12 12:43:102000-12-12 12:43:10扡2000-12-1212:43:102000-12-12 12:43:10.1234 +10:00 +🙂defghi13.00002000-12-13 12:43:102000-12-13 12:43:10摣2000-12-1312:43:102000-12-13 12:43:10.1234 +10:00 +🙂🙂14.00002000-12-14 12:43:102000-12-14 12:43:10晥2000-12-1412:43:102000-12-14 12:43:10.1234 +10:00 +比尔·拉15.00002000-12-15 12:43:102000-12-15 12:43:10桧2000-12-1512:43:102000-12-15 12:43:10.1234 +10:00 +莫斯16.00002000-12-16 12:43:102000-12-16 12:43:10灩2000-12-1612:43:102000-12-16 12:43:10.1234 +10:00 -Anikait17.00002000-12-17 12:43:102000-12-17 12:43:10qr2000-12-1712:43:102000-12-17 12:43:10.1234 +10:00 +Anikait17.00002000-12-17 12:43:102000-12-17 12:43:10牱2000-12-1712:43:102000-12-17 12:43:10.1234 +10:00 -Agrawal18.00002000-12-18 12:43:102000-12-18 12:43:10rs2000-12-1812:43:102000-12-18 12:43:10.1234 +10:00 +Agrawal18.00002000-12-18 12:43:102000-12-18 12:43:10獲2000-12-1812:43:102000-12-18 12:43:10.1234 +10:00 ~~END~~ @@ -1596,7 +1596,7 @@ SELECT babel_3409_concat_dep_func2() GO ~~START~~ nvarchar -abcababcabc +abc扡abcabc ~~END~~ diff --git a/test/JDBC/expected/non_default_server_collation/japanese_ci_as/concat_ws-vu-verify.out b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/concat_ws-vu-verify.out index 2def5375cf..d838a4ef29 100644 --- a/test/JDBC/expected/non_default_server_collation/japanese_ci_as/concat_ws-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/concat_ws-vu-verify.out @@ -790,7 +790,7 @@ SELECT CONCAT_WS('-', 'a', 'b', CAST('🙂🙂' AS nvarchar), 'd', 'e', CAST('f' GO ~~START~~ nvarchar -a-b-🙂🙂-d-e-f-比尔-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-A-B-C-D-E-F-G-H-I-J-K-L-M-ef-O-P-Q-R-S-T-🙂🙂-V-W-X-Y-Z-0-1-2-3-4-5-6-7-8-9-.-,---_-!-@-#-$-%-^-&-*-(-)-[-]-{-}-<->-/-\\-|-:-;-"-\-?-+-=-~-`-a-b-c-d-fg +a-b-🙂🙂-d-e-f-比尔-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-A-B-C-D-E-F-G-H-I-J-K-L-M-晥-O-P-Q-R-S-T-🙂🙂-V-W-X-Y-Z-0-1-2-3-4-5-6-7-8-9-.-,---_-!-@-#-$-%-^-&-*-(-)-[-]-{-}-<->-/-\\-|-:-;-"-\-?-+-=-~-`-a-b-c-d-杦 ~~END~~ @@ -798,7 +798,7 @@ SELECT CONCAT_WS(N'-', 'a', 'b', CAST('🙂🙂' AS varchar), 'd', 'e', CAST('f' GO ~~START~~ nvarchar -a-b-🙂🙂-d-e-f-比尔-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-A-B-C-D-E-F-G-H-I-J-K-L-M-ef-O-P-Q-R-S-T-🙂🙂-V-W-X-Y-Z-0-1-2-3-4-5-6-7-8-9-.-,---_-!-@-#-$-%-^-&-*-(-)-[-]-{-}-<->-/-\\-|-:-;-"-\-?-+-=-~-`-a-b-c-d-fg +a-b-🙂🙂-d-e-f-比尔-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-A-B-C-D-E-F-G-H-I-J-K-L-M-晥-O-P-Q-R-S-T-🙂🙂-V-W-X-Y-Z-0-1-2-3-4-5-6-7-8-9-.-,---_-!-@-#-$-%-^-&-*-(-)-[-]-{-}-<->-/-\\-|-:-;-"-\-?-+-=-~-`-a-b-c-d-杦 ~~END~~ @@ -1416,16 +1416,16 @@ SELECT CONCAT_WS(col_nvarchar, col_varchar, col_binary) from babel_3409_concat_w GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -1450,16 +1450,16 @@ SELECT CONCAT_WS(col_nvarchar, col_varchar, col_varbinary) from babel_3409_conca GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -2407,16 +2407,16 @@ SELECT CONCAT_WS(col_varchar, col_nvarchar, col_binary) from babel_3409_concat_w GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -2424,16 +2424,16 @@ SELECT CONCAT_WS(col_nvarchar, col_nvarchar, col_binary) from babel_3409_concat_ GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -2441,16 +2441,16 @@ SELECT CONCAT_WS(col_varchar, col_nvarchar, col_varbinary) from babel_3409_conca GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -2458,16 +2458,16 @@ SELECT CONCAT_WS(col_nvarchar, col_nvarchar, col_varbinary) from babel_3409_conc GO ~~START~~ nvarchar -abcabcab -🙂defghi🙂defghicd -🙂🙂🙂🙂ef -比尔·拉比尔·拉gh -莫斯莫斯ip +abcabc扡 +🙂defghi🙂defghi摣 +🙂🙂🙂🙂晥 +比尔·拉比尔·拉桧 +莫斯莫斯灩 -AnikaitAnikaitqr +AnikaitAnikait牱 -AgrawalAgrawalrs +AgrawalAgrawal獲 ~~END~~ @@ -3232,16 +3232,16 @@ EXEC babel_3409_concat_ws_dep_proc2 GO ~~START~~ nvarchar -abc-12.0000-2000-12-12 12:43:10-2000-12-12 12:43:10-ab-2000-12-12-12:43:10-2000-12-12 12:43:10.1234 +10:00 -🙂defghi-13.0000-2000-12-13 12:43:10-2000-12-13 12:43:10-cd-2000-12-13-12:43:10-2000-12-13 12:43:10.1234 +10:00 -🙂🙂-14.0000-2000-12-14 12:43:10-2000-12-14 12:43:10-ef-2000-12-14-12:43:10-2000-12-14 12:43:10.1234 +10:00 -比尔·拉-15.0000-2000-12-15 12:43:10-2000-12-15 12:43:10-gh-2000-12-15-12:43:10-2000-12-15 12:43:10.1234 +10:00 -莫斯-16.0000-2000-12-16 12:43:10-2000-12-16 12:43:10-ip-2000-12-16-12:43:10-2000-12-16 12:43:10.1234 +10:00 +abc-12.0000-2000-12-12 12:43:10-2000-12-12 12:43:10-扡-2000-12-12-12:43:10-2000-12-12 12:43:10.1234 +10:00 +🙂defghi-13.0000-2000-12-13 12:43:10-2000-12-13 12:43:10-摣-2000-12-13-12:43:10-2000-12-13 12:43:10.1234 +10:00 +🙂🙂-14.0000-2000-12-14 12:43:10-2000-12-14 12:43:10-晥-2000-12-14-12:43:10-2000-12-14 12:43:10.1234 +10:00 +比尔·拉-15.0000-2000-12-15 12:43:10-2000-12-15 12:43:10-桧-2000-12-15-12:43:10-2000-12-15 12:43:10.1234 +10:00 +莫斯-16.0000-2000-12-16 12:43:10-2000-12-16 12:43:10-灩-2000-12-16-12:43:10-2000-12-16 12:43:10.1234 +10:00 -Anikait-17.0000-2000-12-17 12:43:10-2000-12-17 12:43:10-qr-2000-12-17-12:43:10-2000-12-17 12:43:10.1234 +10:00 +Anikait-17.0000-2000-12-17 12:43:10-2000-12-17 12:43:10-牱-2000-12-17-12:43:10-2000-12-17 12:43:10.1234 +10:00 -Agrawal-18.0000-2000-12-18 12:43:10-2000-12-18 12:43:10-rs-2000-12-18-12:43:10-2000-12-18 12:43:10.1234 +10:00 +Agrawal-18.0000-2000-12-18 12:43:10-2000-12-18 12:43:10-獲-2000-12-18-12:43:10-2000-12-18 12:43:10.1234 +10:00 ~~END~~ @@ -3249,7 +3249,7 @@ SELECT babel_3409_concat_ws_dep_func2() GO ~~START~~ nvarchar -abc-ab-abc-abc +abc-扡-abc-abc ~~END~~ diff --git a/test/JDBC/expected/non_default_server_collation/japanese_ci_as/replace-vu-verify.out b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/replace-vu-verify.out index c33713fff1..9a7af6144f 100644 --- a/test/JDBC/expected/non_default_server_collation/japanese_ci_as/replace-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/replace-vu-verify.out @@ -2139,7 +2139,7 @@ SELECT replace(@inputString, @pattern, @replacement) GO ~~START~~ nvarchar -??比 DEF +ABCDEF ~~END~~ @@ -2148,7 +2148,7 @@ SELECT replace(@inputString, @pattern, @replacement) GO ~~START~~ nvarchar -ABCD +䉁䑃 ~~END~~ diff --git a/test/JDBC/expected/non_default_server_collation/japanese_ci_as/stuff-vu-verify.out b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/stuff-vu-verify.out index ce7ec93466..f0d05527b3 100644 --- a/test/JDBC/expected/non_default_server_collation/japanese_ci_as/stuff-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/stuff-vu-verify.out @@ -976,7 +976,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -abcefefghi?? +abc晥efghi?? ~~END~~ DECLARE @inputString NCHAR(25) = N'abc🙂defghi🙂🙂' @@ -985,7 +985,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -abcefefghi?? +abc晥efghi?? ~~END~~ DECLARE @inputString NCHAR(25) = N'abc🙂defghi🙂🙂' @@ -1070,7 +1070,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -比??ef斯 +比??晥斯 ~~END~~ DECLARE @inputString NCHAR(25) = N'比尔·拉莫斯' @@ -1079,7 +1079,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -比??ef斯 +比??晥斯 ~~END~~ DECLARE @inputString NCHAR(25) = N'比尔·拉莫斯' @@ -1164,7 +1164,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) COLLATE CHINESE_PRC_CI_AS GO ~~START~~ nvarchar -比??ef斯 +比??晥斯 ~~END~~ DECLARE @inputString NCHAR(25) = N'比尔·拉莫斯' @@ -1173,7 +1173,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) COLLATE CHINESE_PRC_CI_AS GO ~~START~~ nvarchar -比??ef斯 +比??晥斯 ~~END~~ DECLARE @inputString NCHAR(25) = N'比尔·拉莫斯' @@ -1270,7 +1270,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -abcefefghi🙂🙂 +abc晥efghi🙂🙂 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'abc🙂defghi🙂🙂' @@ -1279,7 +1279,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -abcefefghi🙂🙂 +abc晥efghi🙂🙂 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'abc🙂defghi🙂🙂' @@ -1364,7 +1364,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -比尔·ef斯 +比尔·晥斯 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'比尔·拉莫斯' @@ -1373,7 +1373,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -比尔·ef斯 +比尔·晥斯 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'比尔·拉莫斯' @@ -1458,7 +1458,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) COLLATE CHINESE_PRC_CI_AS GO ~~START~~ nvarchar -比尔·ef斯 +比尔·晥斯 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'比尔·拉莫斯' @@ -1467,7 +1467,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) COLLATE CHINESE_PRC_CI_AS GO ~~START~~ nvarchar -比尔·ef斯 +比尔·晥斯 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'比尔·拉莫斯' diff --git a/test/JDBC/expected/replace-before-15_8-or-16_4-vu-verify.out b/test/JDBC/expected/replace-before-15_8-or-16_4-vu-verify.out index da262f1001..c7691882be 100644 --- a/test/JDBC/expected/replace-before-15_8-or-16_4-vu-verify.out +++ b/test/JDBC/expected/replace-before-15_8-or-16_4-vu-verify.out @@ -2139,7 +2139,7 @@ SELECT replace(@inputString, @pattern, @replacement) GO ~~START~~ nvarchar -?·? DEF +ABCDEF ~~END~~ @@ -2148,7 +2148,7 @@ SELECT replace(@inputString, @pattern, @replacement) GO ~~START~~ nvarchar -ABCD +䉁䑃 ~~END~~ diff --git a/test/JDBC/expected/replace-vu-verify.out b/test/JDBC/expected/replace-vu-verify.out index 42c396893a..a3282bc85d 100644 --- a/test/JDBC/expected/replace-vu-verify.out +++ b/test/JDBC/expected/replace-vu-verify.out @@ -2139,7 +2139,7 @@ SELECT replace(@inputString, @pattern, @replacement) GO ~~START~~ nvarchar -?·? DEF +ABCDEF ~~END~~ @@ -2148,7 +2148,7 @@ SELECT replace(@inputString, @pattern, @replacement) GO ~~START~~ nvarchar -ABCD +䉁䑃 ~~END~~ diff --git a/test/JDBC/expected/stuff-before-15_8-or-16_4-vu-verify.out b/test/JDBC/expected/stuff-before-15_8-or-16_4-vu-verify.out index 154ac0c45b..476d29571b 100644 --- a/test/JDBC/expected/stuff-before-15_8-or-16_4-vu-verify.out +++ b/test/JDBC/expected/stuff-before-15_8-or-16_4-vu-verify.out @@ -976,7 +976,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -abcefefghi?? +abc晥efghi?? ~~END~~ DECLARE @inputString NCHAR(25) = N'abc🙂defghi🙂🙂' @@ -985,7 +985,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -abcefefghi?? +abc晥efghi?? ~~END~~ DECLARE @inputString NCHAR(25) = N'abc🙂defghi🙂🙂' @@ -1070,7 +1070,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -??·ef? +??·晥? ~~END~~ DECLARE @inputString NCHAR(25) = N'比尔·拉莫斯' @@ -1079,7 +1079,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -??·ef? +??·晥? ~~END~~ DECLARE @inputString NCHAR(25) = N'比尔·拉莫斯' @@ -1164,7 +1164,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) COLLATE CHINESE_PRC_CI_AS GO ~~START~~ nvarchar -??·ef? +??·晥? ~~END~~ DECLARE @inputString NCHAR(25) = N'比尔·拉莫斯' @@ -1173,7 +1173,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) COLLATE CHINESE_PRC_CI_AS GO ~~START~~ nvarchar -??·ef? +??·晥? ~~END~~ DECLARE @inputString NCHAR(25) = N'比尔·拉莫斯' @@ -1270,7 +1270,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -abcefefghi🙂🙂 +abc晥efghi🙂🙂 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'abc🙂defghi🙂🙂' @@ -1279,7 +1279,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -abcefefghi🙂🙂 +abc晥efghi🙂🙂 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'abc🙂defghi🙂🙂' @@ -1364,7 +1364,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -比尔·ef斯 +比尔·晥斯 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'比尔·拉莫斯' @@ -1373,7 +1373,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -比尔·ef斯 +比尔·晥斯 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'比尔·拉莫斯' @@ -1458,7 +1458,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) COLLATE CHINESE_PRC_CI_AS GO ~~START~~ nvarchar -比尔·ef斯 +比尔·晥斯 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'比尔·拉莫斯' @@ -1467,7 +1467,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) COLLATE CHINESE_PRC_CI_AS GO ~~START~~ nvarchar -比尔·ef斯 +比尔·晥斯 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'比尔·拉莫斯' diff --git a/test/JDBC/expected/stuff-vu-verify.out b/test/JDBC/expected/stuff-vu-verify.out index 0be2102e05..ed769be49e 100644 --- a/test/JDBC/expected/stuff-vu-verify.out +++ b/test/JDBC/expected/stuff-vu-verify.out @@ -976,7 +976,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -abcefefghi?? +abc晥efghi?? ~~END~~ DECLARE @inputString NCHAR(25) = N'abc🙂defghi🙂🙂' @@ -985,7 +985,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -abcefefghi?? +abc晥efghi?? ~~END~~ DECLARE @inputString NCHAR(25) = N'abc🙂defghi🙂🙂' @@ -1070,7 +1070,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -??·ef? +??·晥? ~~END~~ DECLARE @inputString NCHAR(25) = N'比尔·拉莫斯' @@ -1079,7 +1079,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -??·ef? +??·晥? ~~END~~ DECLARE @inputString NCHAR(25) = N'比尔·拉莫斯' @@ -1164,7 +1164,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) COLLATE CHINESE_PRC_CI_AS GO ~~START~~ nvarchar -??·ef? +??·晥? ~~END~~ DECLARE @inputString NCHAR(25) = N'比尔·拉莫斯' @@ -1173,7 +1173,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) COLLATE CHINESE_PRC_CI_AS GO ~~START~~ nvarchar -??·ef? +??·晥? ~~END~~ DECLARE @inputString NCHAR(25) = N'比尔·拉莫斯' @@ -1270,7 +1270,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -abcefefghi🙂🙂 +abc晥efghi🙂🙂 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'abc🙂defghi🙂🙂' @@ -1279,7 +1279,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -abcefefghi🙂🙂 +abc晥efghi🙂🙂 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'abc🙂defghi🙂🙂' @@ -1364,7 +1364,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -比尔·ef斯 +比尔·晥斯 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'比尔·拉莫斯' @@ -1373,7 +1373,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) GO ~~START~~ nvarchar -比尔·ef斯 +比尔·晥斯 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'比尔·拉莫斯' @@ -1458,7 +1458,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) COLLATE CHINESE_PRC_CI_AS GO ~~START~~ nvarchar -比尔·ef斯 +比尔·晥斯 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'比尔·拉莫斯' @@ -1467,7 +1467,7 @@ SELECT stuff(@inputString, 4, 2, @replaceString) COLLATE CHINESE_PRC_CI_AS GO ~~START~~ nvarchar -比尔·ef斯 +比尔·晥斯 ~~END~~ DECLARE @inputString NVARCHAR(25) = N'比尔·拉莫斯' diff --git a/test/JDBC/input/cast_nvarchar_test-vu-cleanup.sql b/test/JDBC/input/cast_nvarchar_test-vu-cleanup.sql new file mode 100644 index 0000000000..dd1d5e875b --- /dev/null +++ b/test/JDBC/input/cast_nvarchar_test-vu-cleanup.sql @@ -0,0 +1,27 @@ +-- to do in hashbytes PR +-- DROP TABLE IF EXISTS TestHash; +-- GO +DROP type user_defined_varbinary; +GO +DROP type user_defined_nvarchar; +GO +DROP VIEW IF EXISTS dbo.CastDemoView; +GO +DROP VIEW IF EXISTS dbo.CastDemoView1; +GO +DROP FUNCTION IF EXISTS dbo.CastNVarcharToVarbinary; +GO +DROP FUNCTION IF EXISTS dbo.CastVarbinaryToNVarchar; +GO +DROP FUNCTION IF EXISTS dbo.CastbinaryToNVarchar; +GO +DROP TABLE IF EXISTS casttable; +GO +-- to do in hashbytes PR +-- DROP FUNCTION IF EXISTS dbo.HashMultipleTypes; +-- GO +-- DROP PROCEDURE IF EXISTS dbo.PrintHashResults; +-- GO +-- DROP VIEW IF EXISTS dbo.HashDemoView; +-- GO + diff --git a/test/JDBC/input/cast_nvarchar_test-vu-prepare.sql b/test/JDBC/input/cast_nvarchar_test-vu-prepare.sql new file mode 100644 index 0000000000..d031ff2a8e --- /dev/null +++ b/test/JDBC/input/cast_nvarchar_test-vu-prepare.sql @@ -0,0 +1,100 @@ +-- to do in hashbytes PR +-- CREATE TABLE TestHash( +-- nvarchar_data nvarchar(32) NOT NULL, +-- varchar_data varchar(32) NOT NULL, +-- cast_hashbytes_nvarchar_data AS (cast ( hashbytes('sha1', nvarchar_data) AS varbinary(20) )) PERSISTED NOT NULL, +-- convert_hashbytes_nvarchar_data AS (convert( varbinary(20), hashbytes('sha1',nvarchar_data))) PERSISTED NOT NULL, +-- cast_hashbytes_varchar_data AS (cast ( hashbytes('sha1', varchar_data) AS varbinary(20) )) PERSISTED NOT NULL, +-- convert_hashbytes_varchar_data AS (convert( varbinary(20), hashbytes('sha1',varchar_data))) PERSISTED NOT NULL +-- ); +-- GO + +-- Function to cast NVARCHAR to VARBINARY +CREATE FUNCTION dbo.CastNVarcharToVarbinary +( + @Input NVARCHAR(MAX) +) +RETURNS VARBINARY(MAX) +AS +BEGIN + RETURN CAST(@Input AS VARBINARY(MAX)); +END +GO + +-- Function to cast VARBINARY to NVARCHAR +CREATE FUNCTION dbo.CastVarbinaryToNVarchar +( + @Input VARBINARY(MAX) +) +RETURNS NVARCHAR(MAX) +AS +BEGIN + RETURN CAST(@Input AS NVARCHAR(MAX)); +END +GO + +-- Function to cast BINARY to NVARCHAR +CREATE FUNCTION dbo.CastbinaryToNVarchar +( + @Input BINARY +) +RETURNS NVARCHAR(MAX) +AS +BEGIN + RETURN CAST(@Input AS NVARCHAR(MAX)); +END +GO + +-- View that demonstrates both casts +CREATE VIEW dbo.CastDemoView +AS +SELECT + dbo.CastNVarcharToVarbinary(N'Hello, World!') AS NVarcharToVarbinary, + dbo.CastVarbinaryToNVarchar(0x48656C6C6F2C20576F726C6421) AS VarbinaryToNVarchar, + dbo.CastbinaryToNVarchar(0x48656C6C6F2C20576F726C6421) AS binaryToNVarchar +GO + +create table casttable(nvarchar_data nvarchar(max), varbinary_data varbinary(max), binary_data binary(15), nvarchar_binary_data nvarchar(max)); +GO +insert into casttable(nvarchar_data, varbinary_data, binary_data, nvarchar_binary_data) values (N'test string', 0x48656C6C6F2C20576F726C6421, 0x48656C6C6F2C20576F726C6421, N'test string') +GO + +CREATE VIEW dbo.CastDemoView1 +AS +SELECT + CAST(nvarchar_data AS VARBINARY(MAX)), + CAST(varbinary_data AS NVARCHAR(MAX)), + CAST(binary_data AS NVARCHAR(MAX)), + CAST(nvarchar_binary_data AS BINARY(15)) +FROM casttable +GO + +-- to do in hashbytes PR +-- -- Function hashbytes different input types +-- CREATE FUNCTION dbo.HashMultipleTypes +-- ( +-- @VarcharInput VARCHAR(MAX), +-- @NVarcharInput NVARCHAR(MAX), +-- @VarbinaryInput VARBINARY(MAX) +-- ) +-- RETURNS TABLE +-- AS +-- RETURN +-- ( +-- SELECT +-- HASHBYTES('SHA2_256', @VarcharInput) AS VarcharHash, +-- HASHBYTES('SHA2_256', @NVarcharInput) AS NVarcharHash, +-- HASHBYTES('SHA2_256', @VarbinaryInput) AS VarbinaryHash +-- ) +-- GO + + +-- -- View to demonstrate hashing +-- CREATE VIEW dbo.HashDemoView +-- AS +-- SELECT +-- HASHBYTES('SHA2_256', CAST('Hello' AS VARCHAR(MAX))) AS VarcharHash, +-- HASHBYTES('SHA2_256', CAST(N'Hello' AS NVARCHAR(MAX))) AS NVarcharHash, +-- HASHBYTES('SHA2_256', CAST(0x48656C6C6F AS VARBINARY(MAX))) AS VarbinaryHash +-- GO + diff --git a/test/JDBC/input/cast_nvarchar_test-vu-verify.sql b/test/JDBC/input/cast_nvarchar_test-vu-verify.sql new file mode 100644 index 0000000000..3157f20aa8 --- /dev/null +++ b/test/JDBC/input/cast_nvarchar_test-vu-verify.sql @@ -0,0 +1,228 @@ +-- to do in hashbytes pr +-- -- TEST CASE 1: creating a table and then calling hashbytes for nvarchar and varchar input +-- insert into TestHash values('value1', 'value1'); +-- GO + +-- SELECT DATALENGTH( nvarchar_data) as nvarchar_data_datalength +-- , LEN( nvarchar_data) AS nvarchar_data_len +-- , DATALENGTH( varchar_data) as varchar_data_btyes_datalength +-- , LEN( varchar_data) AS varchar_data_len +-- , * +-- from TestHash; +-- GO +-- -- TEST CASE 2: Casting nvarchar and varchar with different algorithms using Hashbytes +-- SELECT hashbytes( 'sha1', 'test string' ) as vary_string, hashbytes( 'sha1', N'test string' ) as unicode_string +-- GO + +-- SELECT hashbytes( 'MD2', 'test string' ) as vary_string, hashbytes( 'MD2', N'test string' ) as unicode_string +-- GO + +-- SELECT hashbytes( 'MD4', 'test string' ) as vary_string, hashbytes( 'MD4', N'test string' ) as unicode_string +-- GO + +-- SELECT hashbytes( 'MD5', 'test string' ) as vary_string, hashbytes( 'MD5', N'test string' ) as unicode_string +-- GO + +-- SELECT hashbytes( 'SHA2_256', 'test string' ) as vary_string, hashbytes( 'SHA2_256', N'test string' ) as unicode_string +-- GO + +-- SELECT hashbytes( 'SHA2_512', 'test string' ) as vary_string, hashbytes( 'SHA2_512', N'test string' ) as unicode_string +-- GO + +-- SELECT hashbytes( 'SHA', 'test string' ) as vary_string, hashbytes( 'SHA', N'test string' ) as unicode_string +-- GO + +-- SELECT hashbytes( 'sha1', 'test string') +-- GO +-- --TEST CASE 3: testing hashbytes via casting a varchar to nvarchar +-- SELECT hashbytes('sha1',cast('test string' as sys.nvarchar)) +-- GO + +--TEST CASE 4: Casting function for nvarchar to varbinary + +SELECT cast(N'test string' as varbinary); +GO + +SELECT cast(cast(cast('ab' AS nvarchar(10)) as varbinary(2)) as nvarchar(2)); +GO + +-- to do in hashbytes PR +-- -- Test Case 5: Empty strings and NULL values +-- SELECT HASHBYTES('SHA1', '') AS empty_varchar, +-- HASHBYTES('SHA1', N'') AS empty_nvarchar, +-- HASHBYTES('SHA1', NULL) AS null_input; +-- GO + +-- -- Test Case 6: Unicode characters +-- SELECT HASHBYTES('SHA1', N'こんにちは') AS japanese, +-- HASHBYTES('SHA1', N'Здравствуйте') AS russian, +-- HASHBYTES('SHA1', N'🙂😊😀') AS emojis; +-- GO + +-- -- Test Case 8: Different collations +-- SELECT HASHBYTES('SHA1', N'hello' COLLATE Latin1_General_CI_AS) AS ci_as, +-- HASHBYTES('SHA1', N'hello' COLLATE Latin1_General_CS_AS) AS cs_as; +-- GO + +-- -- Test Case 9: Combining varchar and nvarchar +-- SELECT HASHBYTES('SHA1', 'hello' + N'world') AS combined; +-- GO + +-- Test Case 10: Roundtrip conversions +SELECT CAST(CAST(N'test' AS VARBINARY(8)) AS NVARCHAR(4)) AS nvarchar_roundtrip, + CAST(CAST('test' AS VARBINARY(8)) AS VARCHAR(4)) AS varchar_roundtrip; +GO + +-- Test Case 11: CAST and CONVERT between varchar, nvarchar, and varbinary +SELECT CAST(N'hello' AS VARBINARY(10)) AS nvarchar_to_varbinary, + CAST('hello' AS VARBINARY(10)) AS varchar_to_varbinary, + CONVERT(VARBINARY(10), N'hello') AS nvarchar_to_varbinary_convert, + CONVERT(VARBINARY(10), 'hello') AS varchar_to_varbinary_convert; +GO + +-- to do in hashbytes PR +-- -- Test Case 12: Testing with special characters +-- SELECT HASHBYTES('SHA1', 'Hello, World!') AS varchar_special, +-- HASHBYTES('SHA1', N'Hello, World!') AS nvarchar_special, +-- HASHBYTES('SHA1', 'Hello' + CHAR(13) + CHAR(10) + 'World') AS varchar_newline, +-- HASHBYTES('SHA1', N'Hello' + NCHAR(13) + NCHAR(10) + N'World') AS nvarchar_newline; +-- GO + +-- Test Case 13: NVARCHAR -> VARBINARY -> VARCHAR -> NVARCHAR -> VARBINARY +SELECT CAST( + CAST( + CAST( + CAST(N'Hello World' AS VARBINARY(100)) + AS VARCHAR(100)) + AS NVARCHAR(100)) +AS VARBINARY(100)) AS four_casts; +GO + +-- Test Case 14: VARCHAR -> NVARCHAR -> VARBINARY -> NVARCHAR -> VARCHAR +SELECT CAST( + CAST( + CAST( + CAST('Test String' AS NVARCHAR(50)) + AS VARBINARY(50)) + AS NVARCHAR(50)) +AS VARCHAR(50)) AS four_casts; +GO + +-- Test Case 15: Implicit conversion from data type nvarchar to varbinary is not allowed. +DECLARE @a varbinary(10); SET @a = CAST(N'21' AS nvarchar(10)); SELECT @a +GO + +-- Test Case 16: Casting with UDT on nvarchar -> varbinary, UDT on varbinary to nvarchar, UDT on nvarchar to UDT on varbinary +create type user_defined_nvarchar from nvarchar(50); +select cast(cast(N'test string' as user_defined_nvarchar) as varbinary) +GO + +create type user_defined_varbinary from varbinary(50); +select cast(cast(0x7400650073007400200073007400720069006E006700 as user_defined_varbinary) as nvarchar) +GO + +select cast(cast(N'test string' as user_defined_nvarchar) as user_defined_varbinary) +go +-- Test Case 17: NVARCHAR-> BINARY +select cast(N'test string' as binary) +GO +-- Test Case 18: NVARCHAR-> User Defined varbinary +select cast(N'test string' as user_defined_varbinary) +GO + +-- to do in hashbytes PR +-- -- Test Case 19: User defined hashbytes function +-- create function dbo.hashbytes(@data sys.varchar)returns sys.varchar AS BEGIN return "dummy hashbytes";END +-- GO +-- SELECT hashbytes( 'SHA', 'test string' ) as vary_string, hashbytes( 'SHA', N'test string' ) as unicode_string +-- GO +-- select hashbytes('abc') +-- GO +-- drop function dbo.hashbytes +-- GO + +-- Test 20: Calling the function, procedure, views from prepare scripts + +-- Test CastNVarcharToVarbinary function +DECLARE @TestString NVARCHAR(100) = N'Test String'; +DECLARE @BinaryResult VARBINARY(MAX); +SET @BinaryResult = dbo.CastNVarcharToVarbinary(@TestString); +select cast (@BinaryResult as nvarchar) +GO + +-- Test CastVarbinaryToNVarchar function + +DECLARE @TestBinary VARBINARY(100) = 0x54657374537472696E67; -- 'Test String' in ASCII +DECLARE @StringResult NVARCHAR(MAX); +SET @StringResult = dbo.CastVarbinaryToNVarchar(@TestBinary); +select cast (@StringResult as nvarchar) +GO + +-- Test CastbinaryToNVarchar function + +DECLARE @TestBinary BINARY = 0x54657374537472696E67; -- 'Test String' in ASCII +DECLARE @StringResult NVARCHAR(MAX); +SET @StringResult = dbo.CastbinaryToNVarchar(@TestBinary); +select cast (@StringResult as nvarchar) +GO + +-- Test CastDemoView +DECLARE @ViewResult TABLE ( + NVarcharToVarbinary VARBINARY(MAX), + VarbinaryToNVarchar NVARCHAR(MAX), + binaryToNVarchar NVARCHAR(MAX) +); + +INSERT INTO @ViewResult +SELECT * FROM dbo.CastDemoView; +go + +SELECT * FROM dbo.CastDemoView1; +GO +-- TEST CASE 21: Assigned Casting +DECLARE @NVarcharValue NVARCHAR(100) = N'Hello, World!'; +DECLARE @AssignedVarbinary VARBINARY(100); +SET @AssignedVarbinary = CAST(@NVarcharValue AS VARBINARY(100)); +select CAST(@AssignedVarbinary AS NVARCHAR(100)); +GO + +--TEST CASE 22: Calling hashbytes via function, procedure, views + +-- Test the HashMultipleTypes function +DECLARE @TestVarchar VARCHAR(10) = 'Test'; +DECLARE @TestNVarchar NVARCHAR(10) = N'Test'; +DECLARE @TestVarbinary VARBINARY(10) = 0x54657374; -- 'Test' in ASCII + +-- to do in hashbytes PR +-- SELECT * FROM dbo.HashMultipleTypes(@TestVarchar, @TestNVarchar, @TestVarbinary); +-- GO +-- -- Test the HashDemoView +-- SELECT * FROM dbo.HashDemoView; +-- GO + +--TEST CASE 23: BINARY TO NVARCHAR +select cast(cast(N'test string' as binary) as nvarchar) +GO +--TEST CASE 24: NVARCHAR TO BINARY with maxlen < length of actual string +select cast(0x610061006100610061006100610061006100 as nvarchar(5)) +GO +select cast(0x8765 as nvarchar(1)) +GO + +--TEST CASE 25: Default typmod case with string getting truncated + +select cast(N'Lorem ipsum dolor sit amet' as varbinary) +GO +select cast(0x4C006F00720065006D00200069007000730075006D00200064006F006C00 as nvarchar) +GO +--TEST CASE 26: String getting truncted with defined typmod i.e len > maxlen +select cast(N'tesst string' as varbinary(4)) +GO +select cast(0x74006500 as nvarchar) +GO + +select cast(N'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea' as varbinary(MAX)) +GO + +select cast(0x0006161 as nvarchar) +GO diff --git a/test/JDBC/input/cast_nvarchar_test_before_16_5-vu-cleanup.sql b/test/JDBC/input/cast_nvarchar_test_before_16_5-vu-cleanup.sql new file mode 100644 index 0000000000..b84f229da8 --- /dev/null +++ b/test/JDBC/input/cast_nvarchar_test_before_16_5-vu-cleanup.sql @@ -0,0 +1,19 @@ +DROP TABLE IF EXISTS TestHash; +GO +DROP type user_defined_varbinary; +GO +DROP type user_defined_nvarchar; +GO +DROP VIEW IF EXISTS dbo.CastDemoView; +GO +DROP FUNCTION IF EXISTS dbo.CastNVarcharToVarbinary; +GO +DROP FUNCTION IF EXISTS dbo.CastVarbinaryToNVarchar; +GO +DROP FUNCTION IF EXISTS dbo.HashMultipleTypes; +GO +DROP PROCEDURE IF EXISTS dbo.PrintHashResults; +GO +DROP VIEW IF EXISTS dbo.HashDemoView; +GO + diff --git a/test/JDBC/input/cast_nvarchar_test_before_16_5-vu-prepare.sql b/test/JDBC/input/cast_nvarchar_test_before_16_5-vu-prepare.sql new file mode 100644 index 0000000000..0c2e397cf2 --- /dev/null +++ b/test/JDBC/input/cast_nvarchar_test_before_16_5-vu-prepare.sql @@ -0,0 +1,71 @@ +CREATE TABLE TestHash( +nvarchar_data nvarchar(32) NOT NULL, +varchar_data varchar(32) NOT NULL, +cast_hashbytes_nvarchar_data AS (cast ( hashbytes('sha1', nvarchar_data) AS varbinary(20) )) PERSISTED NOT NULL, +convert_hashbytes_nvarchar_data AS (convert( varbinary(20), hashbytes('sha1',nvarchar_data))) PERSISTED NOT NULL, +cast_hashbytes_varchar_data AS (cast ( hashbytes('sha1', varchar_data) AS varbinary(20) )) PERSISTED NOT NULL, +convert_hashbytes_varchar_data AS (convert( varbinary(20), hashbytes('sha1',varchar_data))) PERSISTED NOT NULL +); +GO + +-- Function to cast NVARCHAR to VARBINARY +CREATE FUNCTION dbo.CastNVarcharToVarbinary +( + @Input NVARCHAR(MAX) +) +RETURNS VARBINARY(MAX) +AS +BEGIN + RETURN CAST(@Input AS VARBINARY(MAX)); +END +GO + +-- Function to cast VARBINARY to NVARCHAR +CREATE FUNCTION dbo.CastVarbinaryToNVarchar +( + @Input VARBINARY(MAX) +) +RETURNS NVARCHAR(MAX) +AS +BEGIN + RETURN CAST(@Input AS NVARCHAR(MAX)); +END +GO + +-- View that demonstrates both casts +CREATE VIEW dbo.CastDemoView +AS +SELECT + dbo.CastNVarcharToVarbinary(N'Hello, World!') AS NVarcharToVarbinary, + dbo.CastVarbinaryToNVarchar(0x48656C6C6F2C20576F726C6421) AS VarbinaryToNVarchar +GO + + +-- Function to hash different input types +CREATE FUNCTION dbo.HashMultipleTypes +( + @VarcharInput VARCHAR(MAX), + @NVarcharInput NVARCHAR(MAX), + @VarbinaryInput VARBINARY(MAX) +) +RETURNS TABLE +AS +RETURN +( + SELECT + HASHBYTES('SHA2_256', @VarcharInput) AS VarcharHash, + HASHBYTES('SHA2_256', @NVarcharInput) AS NVarcharHash, + HASHBYTES('SHA2_256', @VarbinaryInput) AS VarbinaryHash +) +GO + + +-- View to demonstrate hashing +CREATE VIEW dbo.HashDemoView +AS +SELECT + HASHBYTES('SHA2_256', CAST('Hello' AS VARCHAR(MAX))) AS VarcharHash, + HASHBYTES('SHA2_256', CAST(N'Hello' AS NVARCHAR(MAX))) AS NVarcharHash, + HASHBYTES('SHA2_256', CAST(0x48656C6C6F AS VARBINARY(MAX))) AS VarbinaryHash +GO + diff --git a/test/JDBC/input/cast_nvarchar_test_before_16_5-vu-verify.sql b/test/JDBC/input/cast_nvarchar_test_before_16_5-vu-verify.sql new file mode 100644 index 0000000000..8090a06d1b --- /dev/null +++ b/test/JDBC/input/cast_nvarchar_test_before_16_5-vu-verify.sql @@ -0,0 +1,190 @@ +-- TEST CASE 1: creating a table and then calling hashbytes for nvarchar and varchar input +insert into TestHash values('value1', 'value1'); +GO + +SELECT DATALENGTH( nvarchar_data) as nvarchar_data_datalength + , LEN( nvarchar_data) AS nvarchar_data_len + , DATALENGTH( varchar_data) as varchar_data_btyes_datalength + , LEN( varchar_data) AS varchar_data_len + , * +from TestHash; +GO +-- TEST CASE 2: Casting nvarchar and varchar with different algorithms using Hashbytes +SELECT hashbytes( 'sha1', 'test string' ) as vary_string, hashbytes( 'sha1', N'test string' ) as unicode_string +GO + +SELECT hashbytes( 'MD2', 'test string' ) as vary_string, hashbytes( 'MD2', N'test string' ) as unicode_string +GO + +SELECT hashbytes( 'MD4', 'test string' ) as vary_string, hashbytes( 'MD4', N'test string' ) as unicode_string +GO + +SELECT hashbytes( 'MD5', 'test string' ) as vary_string, hashbytes( 'MD5', N'test string' ) as unicode_string +GO + +SELECT hashbytes( 'SHA2_256', 'test string' ) as vary_string, hashbytes( 'SHA2_256', N'test string' ) as unicode_string +GO + +SELECT hashbytes( 'SHA2_512', 'test string' ) as vary_string, hashbytes( 'SHA2_512', N'test string' ) as unicode_string +GO + +SELECT hashbytes( 'SHA', 'test string' ) as vary_string, hashbytes( 'SHA', N'test string' ) as unicode_string +GO + +SELECT hashbytes( 'sha1', 'test string') +GO +--TEST CASE 3: testing hashbytes via casting a varchar to nvarchar +SELECT hashbytes('sha1',cast('test string' as sys.nvarchar)) +GO + +--TEST CASE 4: Casting function for nvarchar to varbinary + +SELECT cast(N'test string' as varbinary); +GO + +SELECT cast(cast(cast('ab' AS nvarchar(10)) as varbinary(2)) as nvarchar(2)); +GO + +-- Test Case 5: Empty strings and NULL values +SELECT HASHBYTES('SHA1', '') AS empty_varchar, + HASHBYTES('SHA1', N'') AS empty_nvarchar, + HASHBYTES('SHA1', NULL) AS null_input; +GO + +-- Test Case 6: Unicode characters +SELECT HASHBYTES('SHA1', N'こんにちは') AS japanese, + HASHBYTES('SHA1', N'Здравствуйте') AS russian, + HASHBYTES('SHA1', N'🙂😊😀') AS emojis; +GO + +-- Test Case 8: Different collations +SELECT HASHBYTES('SHA1', N'hello' COLLATE Latin1_General_CI_AS) AS ci_as, + HASHBYTES('SHA1', N'hello' COLLATE Latin1_General_CS_AS) AS cs_as; +GO + +-- Test Case 9: Combining varchar and nvarchar +SELECT HASHBYTES('SHA1', 'hello' + N'world') AS combined; +GO + +-- Test Case 10: Roundtrip conversions +SELECT CAST(CAST(N'test' AS VARBINARY(8)) AS NVARCHAR(4)) AS nvarchar_roundtrip, + CAST(CAST('test' AS VARBINARY(8)) AS VARCHAR(4)) AS varchar_roundtrip; +GO + +-- Test Case 11: CAST and CONVERT between varchar, nvarchar, and varbinary +SELECT CAST(N'hello' AS VARBINARY(10)) AS nvarchar_to_varbinary, + CAST('hello' AS VARBINARY(10)) AS varchar_to_varbinary, + CONVERT(VARBINARY(10), N'hello') AS nvarchar_to_varbinary_convert, + CONVERT(VARBINARY(10), 'hello') AS varchar_to_varbinary_convert; +GO + +-- Test Case 12: Testing with special characters +SELECT HASHBYTES('SHA1', 'Hello, World!') AS varchar_special, + HASHBYTES('SHA1', N'Hello, World!') AS nvarchar_special, + HASHBYTES('SHA1', 'Hello' + CHAR(13) + CHAR(10) + 'World') AS varchar_newline, + HASHBYTES('SHA1', N'Hello' + NCHAR(13) + NCHAR(10) + N'World') AS nvarchar_newline; +GO + +-- Test Case 13: NVARCHAR -> VARBINARY -> VARCHAR -> NVARCHAR -> VARBINARY +SELECT CAST( + CAST( + CAST( + CAST(N'Hello World' AS VARBINARY(100)) + AS VARCHAR(100)) + AS NVARCHAR(100)) +AS VARBINARY(100)) AS four_casts; +GO + +-- Test Case 14: VARCHAR -> NVARCHAR -> VARBINARY -> NVARCHAR -> VARCHAR +SELECT CAST( + CAST( + CAST( + CAST('Test String' AS NVARCHAR(50)) + AS VARBINARY(50)) + AS NVARCHAR(50)) +AS VARCHAR(50)) AS four_casts; +GO + +-- Test Case 15: Implicit conversion from data type nvarchar to varbinary is not allowed. +DECLARE @a varbinary(10); SET @a = CAST(N'21' AS nvarchar(10)); SELECT @a +GO + +-- Test Case 16: Casting with UDT on nvarchar -> varbinary, UDT on varbinary to nvarchar, UDT on nvarchar to UDT on varbinary +create type user_defined_nvarchar from nvarchar(50); +select cast(cast(N'test string' as user_defined_nvarchar) as varbinary) +GO + +create type user_defined_varbinary from varbinary(50); +select cast(cast(0x7400650073007400200073007400720069006E006700 as user_defined_varbinary) as nvarchar) +GO + +select cast(cast(N'test string' as user_defined_nvarchar) as user_defined_varbinary) +go +-- Test Case 17: NVARCHAR-> BINARY +select cast(N'test string' as binary) +GO +-- Test Case 18: NVARCHAR-> User Defined varbinary +select cast(N'test string' as user_defined_varbinary) +GO +-- Test Case 19: User defined hashbytes function +create function dbo.hashbytes(@data sys.varchar)returns sys.varchar AS BEGIN return "dummy hashbytes";END +GO +SELECT hashbytes( 'SHA', 'test string' ) as vary_string, hashbytes( 'SHA', N'test string' ) as unicode_string +GO +select hashbytes('abc') +GO +drop function dbo.hashbytes +GO + +-- Test 20: Calling the function, procedure, views from prepare scripts + +-- Test CastNVarcharToVarbinary function +DECLARE @TestString NVARCHAR(100) = N'Test String'; +DECLARE @BinaryResult VARBINARY(MAX); +SET @BinaryResult = dbo.CastNVarcharToVarbinary(@TestString); +select cast (@BinaryResult as nvarchar) +GO + +-- Test CastVarbinaryToNVarchar function + +DECLARE @TestBinary VARBINARY(100) = 0x54657374537472696E67; -- 'Test String' in ASCII +DECLARE @StringResult NVARCHAR(MAX); +SET @StringResult = dbo.CastVarbinaryToNVarchar(@TestBinary); +select cast (@StringResult as nvarchar) +GO + +-- Test CastDemoView +DECLARE @ViewResult TABLE ( + NVarcharToVarbinary VARBINARY(MAX), + VarbinaryToNVarchar NVARCHAR(MAX) +); + +INSERT INTO @ViewResult +SELECT * FROM dbo.CastDemoView; +go + +-- TEST CASE 21: Assigned Casting +DECLARE @NVarcharValue NVARCHAR(100) = N'Hello, World!'; +DECLARE @AssignedVarbinary VARBINARY(100); +SET @AssignedVarbinary = CAST(@NVarcharValue AS VARBINARY(100)); +select CAST(@AssignedVarbinary AS NVARCHAR(100)); +GO + +--TEST CASE 22: Calling hashbytes via function, procedure, views + +-- Test the HashMultipleTypes function +DECLARE @TestVarchar VARCHAR(10) = 'Test'; +DECLARE @TestNVarchar NVARCHAR(10) = N'Test'; +DECLARE @TestVarbinary VARBINARY(10) = 0x54657374; -- 'Test' in ASCII + +SELECT * FROM dbo.HashMultipleTypes(@TestVarchar, @TestNVarchar, @TestVarbinary); +GO +-- Test the HashDemoView +SELECT * FROM dbo.HashDemoView; +GO + +--TEST CASE 23: BINARY TO NVARCHAR +select cast(cast(N'test string' as binary) as nvarchar) +GO + + diff --git a/test/JDBC/jdbc_schedule b/test/JDBC/jdbc_schedule index ecac1a20b8..c61b9179a8 100644 --- a/test/JDBC/jdbc_schedule +++ b/test/JDBC/jdbc_schedule @@ -476,7 +476,12 @@ ignore#!#BABEL-5119_before_16_5-vu-cleanup ignore#!#BABEL-5059_before_16_5-vu-prepare ignore#!#BABEL-5059_before_16_5-vu-verify ignore#!#BABEL-5059_before_16_5-vu-cleanup +ignore#!#cast_nvarchar_test_before_16_5-vu-prepare +ignore#!#cast_nvarchar_test_before_16_5-vu-verify +ignore#!#cast_nvarchar_test_before_16_5-vu-cleanup ignore#!#declare_atatglobalvars_upgrade-before-16_5-vu-cleanup ignore#!#declare_atatglobalvars_upgrade-before-16_5-vu-prepare ignore#!#declare_atatglobalvars_upgrade-before-16_5-vu-verify + + diff --git a/test/JDBC/upgrade/15_10/schedule b/test/JDBC/upgrade/15_10/schedule index 2c5286edc6..9287965cb9 100644 --- a/test/JDBC/upgrade/15_10/schedule +++ b/test/JDBC/upgrade/15_10/schedule @@ -555,3 +555,5 @@ db_ddladmin BABEL-5186 BABEL-2736 smalldatetime_date_cmp +cast_nvarchar_test_before_16_5 + diff --git a/test/JDBC/upgrade/15_11/schedule b/test/JDBC/upgrade/15_11/schedule index 74f8d07339..8b7c71d746 100644 --- a/test/JDBC/upgrade/15_11/schedule +++ b/test/JDBC/upgrade/15_11/schedule @@ -554,4 +554,6 @@ datareader_datawriter BABEL-5186 BABEL-2736 smalldatetime_date_cmp +cast_nvarchar_test_before_16_5 + diff --git a/test/JDBC/upgrade/15_3/schedule b/test/JDBC/upgrade/15_3/schedule index 149d640dec..5965c84994 100644 --- a/test/JDBC/upgrade/15_3/schedule +++ b/test/JDBC/upgrade/15_3/schedule @@ -493,5 +493,7 @@ BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter BABEL-5186 BABEL-2736-before-16_5 +smalldatetime_date_cmp +cast_nvarchar_test_before_16_5 smalldatetime_date_cmp-before-15_5-16_1 diff --git a/test/JDBC/upgrade/15_4/schedule b/test/JDBC/upgrade/15_4/schedule index c5ba86d4e8..dbb5107c0d 100644 --- a/test/JDBC/upgrade/15_4/schedule +++ b/test/JDBC/upgrade/15_4/schedule @@ -506,5 +506,7 @@ BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter BABEL-5186 BABEL-2736-before-16_5 +smalldatetime_date_cmp +cast_nvarchar_test_before_16_5 smalldatetime_date_cmp-before-15_5-16_1 diff --git a/test/JDBC/upgrade/15_5/schedule b/test/JDBC/upgrade/15_5/schedule index da2aed59a1..f077a96158 100644 --- a/test/JDBC/upgrade/15_5/schedule +++ b/test/JDBC/upgrade/15_5/schedule @@ -537,6 +537,7 @@ BABEL-CASE_EXPR-before-16_5-or-15_9 dbcreator_role BABEL-5186 BABEL-2736-before-16_5 +cast_nvarchar_test_before_16_5 smalldatetime_date_cmp securityadmin_role datareader_datawriter diff --git a/test/JDBC/upgrade/15_6/schedule b/test/JDBC/upgrade/15_6/schedule index d8fe8f9c1d..e3bb8406b3 100644 --- a/test/JDBC/upgrade/15_6/schedule +++ b/test/JDBC/upgrade/15_6/schedule @@ -553,6 +553,7 @@ BABEL-CASE_EXPR-before-16_5-or-15_9 dbcreator_role BABEL-5186 BABEL-2736-before-16_5 +cast_nvarchar_test_before_16_5 smalldatetime_date_cmp securityadmin_role datareader_datawriter diff --git a/test/JDBC/upgrade/15_7/schedule b/test/JDBC/upgrade/15_7/schedule index 13dc504c1e..fd4335c5a9 100644 --- a/test/JDBC/upgrade/15_7/schedule +++ b/test/JDBC/upgrade/15_7/schedule @@ -561,6 +561,7 @@ BABEL-CASE_EXPR-before-16_5-or-15_9 dbcreator_role BABEL-5186 BABEL-2736-before-16_5 +cast_nvarchar_test_before_16_5 smalldatetime_date_cmp securityadmin_role datareader_datawriter diff --git a/test/JDBC/upgrade/15_8/schedule b/test/JDBC/upgrade/15_8/schedule index a003b5dcc7..60069e9fff 100644 --- a/test/JDBC/upgrade/15_8/schedule +++ b/test/JDBC/upgrade/15_8/schedule @@ -552,6 +552,7 @@ BABEL-CASE_EXPR-before-16_5-or-15_9 dbcreator_role BABEL-5186 BABEL-2736-before-16_5 +cast_nvarchar_test_before_16_5 smalldatetime_date_cmp securityadmin_role datareader_datawriter diff --git a/test/JDBC/upgrade/16_1/schedule b/test/JDBC/upgrade/16_1/schedule index 62f3d3927b..6d255b070b 100644 --- a/test/JDBC/upgrade/16_1/schedule +++ b/test/JDBC/upgrade/16_1/schedule @@ -548,5 +548,6 @@ BABEL-CASE_EXPR-before-16_5-or-15_9 datareader_datawriter BABEL-5186 BABEL-2736-before-16_5 +cast_nvarchar_test_before_16_5 smalldatetime_date_cmp diff --git a/test/JDBC/upgrade/16_2/schedule b/test/JDBC/upgrade/16_2/schedule index ad458fda01..0d5687233a 100644 --- a/test/JDBC/upgrade/16_2/schedule +++ b/test/JDBC/upgrade/16_2/schedule @@ -562,6 +562,7 @@ BABEL-CASE_EXPR-before-16_5-or-15_9 declare_atatglobalvars_upgrade-before-16_5 BABEL-5186 BABEL-2736-before-16_5 +cast_nvarchar_test_before_16_5 smalldatetime_date_cmp securityadmin_role datareader_datawriter diff --git a/test/JDBC/upgrade/16_3/schedule b/test/JDBC/upgrade/16_3/schedule index 3c35a3fc75..3ce2be2a61 100644 --- a/test/JDBC/upgrade/16_3/schedule +++ b/test/JDBC/upgrade/16_3/schedule @@ -564,6 +564,7 @@ GRANT_SCHEMA-before-15_9-16_5 BABEL-CASE_EXPR-before-16_5-or-15_9 BABEL-5186 BABEL-2736-before-16_5 +cast_nvarchar_test_before_16_5 smalldatetime_date_cmp dbcreator_role securityadmin_role diff --git a/test/JDBC/upgrade/16_4/schedule b/test/JDBC/upgrade/16_4/schedule index efa6dc454b..a450cc7c59 100644 --- a/test/JDBC/upgrade/16_4/schedule +++ b/test/JDBC/upgrade/16_4/schedule @@ -579,6 +579,7 @@ declare_atatglobalvars_upgrade-before-16_5 dbcreator_role BABEL-5186 BABEL-2736-before-16_5 +cast_nvarchar_test_before_16_5 smalldatetime_date_cmp securityadmin_role datareader_datawriter diff --git a/test/JDBC/upgrade/16_6/schedule b/test/JDBC/upgrade/16_6/schedule index e25b92d182..73f4672746 100644 --- a/test/JDBC/upgrade/16_6/schedule +++ b/test/JDBC/upgrade/16_6/schedule @@ -579,6 +579,7 @@ BABEL-CASE_EXPR charindex_replace_patindex BABEL-5186 BABEL-2736 +cast_nvarchar_test_before_16_5 smalldatetime_date_cmp securityadmin_role db_accessadmin diff --git a/test/JDBC/upgrade/latest/schedule b/test/JDBC/upgrade/latest/schedule index 67c2e77d2e..e1b37df426 100644 --- a/test/JDBC/upgrade/latest/schedule +++ b/test/JDBC/upgrade/latest/schedule @@ -588,6 +588,7 @@ BABEL-CASE_EXPR charindex_replace_patindex BABEL-5186 BABEL-2736 +cast_nvarchar_test smalldatetime_date_cmp datareader_datawriter db_owner