diff --git a/contrib/babelfishpg_tsql/sql/sys_function_helpers.sql b/contrib/babelfishpg_tsql/sql/sys_function_helpers.sql index 146e98c15e..594ae55879 100644 --- a/contrib/babelfishpg_tsql/sql/sys_function_helpers.sql +++ b/contrib/babelfishpg_tsql/sql/sys_function_helpers.sql @@ -9655,6 +9655,112 @@ $BODY$ LANGUAGE plpgsql STABLE; +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_varbinary(IN arg anyelement, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.varbinary +AS +$BODY$ +BEGIN + IF try THEN + RETURN sys.babelfish_try_conv_to_varbinary(arg, p_style); + ELSE + IF pg_typeof(arg) IN ('text'::regtype, 'sys.ntext'::regtype, 'sys.nvarchar'::regtype, 'sys.bpchar'::regtype, 'sys.nchar'::regtype) THEN + RETURN sys.babelfish_conv_string_to_varbinary(arg, p_style); + ELSE + RETURN CAST(arg AS sys.varbinary); + END IF; + END IF; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_varbinary(IN arg sys.VARCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.varbinary +AS +$BODY$ +BEGIN + IF try THEN + RETURN sys.babelfish_try_conv_string_to_varbinary(arg, p_style); + ELSE + RETURN sys.babelfish_conv_string_to_varbinary(arg, p_style); + END IF; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_string_to_varbinary(IN arg sys.VARCHAR, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.varbinary +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_string_to_varbinary(arg, p_style); + EXCEPTION + WHEN OTHERS THEN + RETURN NULL; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_to_varbinary(IN arg anyelement, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.varbinary +AS +$BODY$ +BEGIN + IF pg_typeof(arg) IN ('text'::regtype, 'sys.ntext'::regtype, 'sys.nvarchar'::regtype, 'sys.bpchar'::regtype, 'sys.nchar'::regtype) THEN + RETURN sys.babelfish_conv_string_to_varbinary(arg, p_style); + ELSE + RETURN CAST(arg AS sys.varbinary); + END IF; + EXCEPTION + WHEN OTHERS THEN + RETURN NULL; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +-- Helper function to convert to binary or varbinary +CREATE OR REPLACE FUNCTION sys.babelfish_conv_string_to_varbinary(IN input_value sys.VARCHAR, IN style NUMERIC DEFAULT 0) +RETURNS sys.varbinary +AS +$BODY$ +DECLARE + result bytea; +BEGIN + IF style = 0 THEN + RETURN CAST(input_value AS sys.varbinary); + ELSIF style = 1 THEN + -- Handle hexadecimal conversion + IF (PG_CATALOG.left(input_value, 2) = '0x' COLLATE "C" AND PG_CATALOG.length(input_value) % 2 = 0) THEN + result := decode(substring(input_value from 3), 'hex'); + ELSE + RAISE EXCEPTION 'Error converting data type varchar to varbinary.'; + END IF; + ELSIF style = 2 THEN + IF PG_CATALOG.left(input_value, 2) = '0x' COLLATE "C" THEN + RAISE EXCEPTION 'Error converting data type varchar to varbinary.'; + ELSE + result := decode(input_value, 'hex'); + END IF; + ELSE + RAISE EXCEPTION 'The style % is not supported for conversions from varchar to varbinary.', style; + END IF; + + RETURN CAST(result AS sys.varbinary); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE +STRICT; + -- convertion to varchar CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_varchar(IN typename TEXT, IN arg TEXT, diff --git a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--3.7.0--3.8.0.sql b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--3.7.0--3.8.0.sql index f6d772466a..06952f665c 100644 --- a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--3.7.0--3.8.0.sql +++ b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--3.7.0--3.8.0.sql @@ -9303,6 +9303,112 @@ end; $body$ language plpgsql immutable returns null on null input; +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_varbinary(IN arg anyelement, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.varbinary +AS +$BODY$ +BEGIN + IF try THEN + RETURN sys.babelfish_try_conv_to_varbinary(arg, p_style); + ELSE + IF pg_typeof(arg) IN ('text'::regtype, 'sys.ntext'::regtype, 'sys.nvarchar'::regtype, 'sys.bpchar'::regtype, 'sys.nchar'::regtype) THEN + RETURN sys.babelfish_conv_string_to_varbinary(arg, p_style); + ELSE + RETURN CAST(arg AS sys.varbinary); + END IF; + END IF; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_conv_helper_to_varbinary(IN arg sys.VARCHAR, + IN try BOOL, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.varbinary +AS +$BODY$ +BEGIN + IF try THEN + RETURN sys.babelfish_try_conv_string_to_varbinary(arg, p_style); + ELSE + RETURN sys.babelfish_conv_string_to_varbinary(arg, p_style); + END IF; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_string_to_varbinary(IN arg sys.VARCHAR, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.varbinary +AS +$BODY$ +BEGIN + RETURN sys.babelfish_conv_string_to_varbinary(arg, p_style); + EXCEPTION + WHEN OTHERS THEN + RETURN NULL; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +CREATE OR REPLACE FUNCTION sys.babelfish_try_conv_to_varbinary(IN arg anyelement, + IN p_style NUMERIC DEFAULT 0) +RETURNS sys.varbinary +AS +$BODY$ +BEGIN + IF pg_typeof(arg) IN ('text'::regtype, 'sys.ntext'::regtype, 'sys.nvarchar'::regtype, 'sys.bpchar'::regtype, 'sys.nchar'::regtype) THEN + RETURN sys.babelfish_conv_string_to_varbinary(arg, p_style); + ELSE + RETURN CAST(arg AS sys.varbinary); + END IF; + EXCEPTION + WHEN OTHERS THEN + RETURN NULL; +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE; + +-- Helper function to convert to binary or varbinary +CREATE OR REPLACE FUNCTION sys.babelfish_conv_string_to_varbinary(IN input_value sys.VARCHAR, IN style NUMERIC DEFAULT 0) +RETURNS sys.varbinary +AS +$BODY$ +DECLARE + result bytea; +BEGIN + IF style = 0 THEN + RETURN CAST(input_value AS sys.varbinary); + ELSIF style = 1 THEN + -- Handle hexadecimal conversion + IF (PG_CATALOG.left(input_value, 2) = '0x' COLLATE "C" AND PG_CATALOG.length(input_value) % 2 = 0) THEN + result := decode(substring(input_value from 3), 'hex'); + ELSE + RAISE EXCEPTION 'Error converting data type varchar to varbinary.'; + END IF; + ELSIF style = 2 THEN + IF PG_CATALOG.left(input_value, 2) = '0x' COLLATE "C" THEN + RAISE EXCEPTION 'Error converting data type varchar to varbinary.'; + ELSE + result := decode(input_value, 'hex'); + END IF; + ELSE + RAISE EXCEPTION 'The style % is not supported for conversions from varchar to varbinary.', style; + END IF; + + RETURN CAST(result AS sys.varbinary); +END; +$BODY$ +LANGUAGE plpgsql +IMMUTABLE +STRICT; + -- This is a temporary procedure which is called during upgrade to alter -- default privileges on all the schemas where the schema owner is not dbo/db_owner CREATE OR REPLACE PROCEDURE sys.babelfish_alter_default_privilege_on_schema() diff --git a/contrib/babelfishpg_tsql/src/backend_parser/gram-tsql-epilogue.y.c b/contrib/babelfishpg_tsql/src/backend_parser/gram-tsql-epilogue.y.c index e4635ad659..2579461ef4 100644 --- a/contrib/babelfishpg_tsql/src/backend_parser/gram-tsql-epilogue.y.c +++ b/contrib/babelfishpg_tsql/src/backend_parser/gram-tsql-epilogue.y.c @@ -216,6 +216,16 @@ TsqlFunctionConvert(TypeName *typename, Node *arg, Node *style, bool try, int lo */ result = makeTypeCast(helperFuncCall, typename, location); } + + else if (strcmp(typename_string, "binary") == 0 || strcmp(typename_string, "varbinary") == 0) + { + Node *helperFuncCall; + helperFuncCall = (Node *) makeFuncCall(TsqlSystemFuncName("babelfish_conv_helper_to_varbinary"), args, COERCE_EXPLICIT_CALL, location); + + // add a type cast on top of the CONVERT helper function so typmod can be applied + result = makeTypeCast(helperFuncCall, typename, location); + } + else { if (try) diff --git a/test/JDBC/expected/BABEL-2736-before-15_3-vu-cleanup.out b/test/JDBC/expected/BABEL-2736-before-15_3-vu-cleanup.out new file mode 100644 index 0000000000..54696f5204 --- /dev/null +++ b/test/JDBC/expected/BABEL-2736-before-15_3-vu-cleanup.out @@ -0,0 +1,173 @@ +-- Drop views +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v1; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v2; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v3; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v4; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v5; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v6; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v7; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v8_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v9_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v10_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v11; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v12; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v13; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v14_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v15_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v16_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v17; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v18; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v19; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v20; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v21; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v22; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v23; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v24; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v26; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v27; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v28; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v29; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v30; +Go + +-- Drop procedures +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p1; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p2; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p3; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p4; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p5; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p6; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p7; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p8; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p9; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p10; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p11; +Go + +-- Drop functions +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f1; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f2; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f3; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f4; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f5; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f7; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f8; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f9; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f10; +Go +-- Drop test table +DROP TABLE IF EXISTS BABEL_BINARY_test_table1; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table2; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table3; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table4; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table_compcol; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table_compcol1; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table_compcol2; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table_compcol3; +GO diff --git a/test/JDBC/expected/BABEL-2736-before-15_3-vu-prepare.out b/test/JDBC/expected/BABEL-2736-before-15_3-vu-prepare.out new file mode 100644 index 0000000000..e1d037210e --- /dev/null +++ b/test/JDBC/expected/BABEL-2736-before-15_3-vu-prepare.out @@ -0,0 +1,396 @@ +-- View to test binary conversion with style 0 (default) +CREATE VIEW BABEL_BINARY_vu_prepare_v1 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 0)); +GO + +-- Procedure to test binary conversion with style 0 (default) +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p1 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 0)); +GO + +-- Function to test binary conversion with style 0 (default) +CREATE FUNCTION BABEL_BINARY_vu_prepare_f1() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(10), '0904D00034', 0)); +END +GO + +-- View to test binary conversion with style 1 (with '0x' prefix) +CREATE VIEW BABEL_BINARY_vu_prepare_v2 AS +(SELECT CONVERT(BINARY(10), '0x0904D00034', 1)); +GO + +-- Procedure to test binary conversion with style 1 (with '0x' prefix) +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p2 AS +(SELECT CONVERT(BINARY(10), '0x0904D00034', 1)); +GO + +-- Function to test binary conversion with style 1 (with '0x' prefix) +CREATE FUNCTION BABEL_BINARY_vu_prepare_f2() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(10), '0x0904D00034', 1)); +END +GO + +-- View to test binary conversion with style 2 +CREATE VIEW BABEL_BINARY_vu_prepare_v3 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 2)); +GO + +-- Procedure to test binary conversion with style 2 +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p3 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 2)); +GO + +-- Function to test binary conversion with style 2 +CREATE FUNCTION BABEL_BINARY_vu_prepare_f3() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(10), '0904D00034', 2)); +END +GO + +-- View to test VARBINARY conversion +CREATE VIEW BABEL_BINARY_vu_prepare_v4 AS +(SELECT CONVERT(VARBINARY(10), '0904D00034', 0)); +GO + +-- Procedure to test VARBINARY conversion +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p4 AS +(SELECT CONVERT(VARBINARY(10), '0904D00034', 0)); +GO + +-- Function to test VARBINARY conversion +CREATE FUNCTION BABEL_BINARY_vu_prepare_f4() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(VARBINARY(10), '0904D00034', 0)); +END +GO + +-- Procedure to test invalid style (should cause an error) +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p5 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 3)); +GO + +-- Function to test NULL input +CREATE FUNCTION BABEL_BINARY_vu_prepare_f5() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(10), NULL, 0)); +END +GO + +-- Test case for CONVERT with a column reference +CREATE TABLE BABEL_BINARY_test_table1 (col1 VARCHAR(20)); +GO +INSERT INTO BABEL_BINARY_test_table1 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO +~~ROW COUNT: 3~~ + + +CREATE VIEW BABEL_BINARY_vu_prepare_v5 AS +(SELECT CONVERT(BINARY(5), col1, 1) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v6 AS +(SELECT CONVERT(BINARY(5), col1, 0) FROM BABEL_BINARY_test_table1); +GO + +CREATE TABLE BABEL_BINARY_test_table2 (col1 VARCHAR(20)); +GO +INSERT INTO BABEL_BINARY_test_table2 (col1) VALUES ('1234ABCD'), ('787980'), ('1234'); +GO +~~ROW COUNT: 3~~ + + +CREATE VIEW BABEL_BINARY_vu_prepare_v7 AS +(SELECT CONVERT(BINARY(5), col1, 2) FROM BABEL_BINARY_test_table2); +GO + +-- Test case for TRY_CONVERT with a column reference +CREATE TABLE BABEL_BINARY_test_table3 (col1 VARCHAR(20)); +GO +INSERT INTO BABEL_BINARY_test_table3 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO +~~ROW COUNT: 3~~ + + +CREATE VIEW BABEL_BINARY_vu_prepare_v8_try AS +(SELECT TRY_CONVERT(BINARY(5), col1, 1) FROM BABEL_BINARY_test_table3); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v9_try AS +(SELECT TRY_CONVERT(BINARY(5), col1, 0) FROM BABEL_BINARY_test_table3); +GO + +CREATE TABLE BABEL_BINARY_test_table4 (col1 VARCHAR(20)); +GO +INSERT INTO BABEL_BINARY_test_table4 (col1) VALUES ('1234ABCD'), ('787980'), ('1234'); +GO +~~ROW COUNT: 3~~ + + +CREATE VIEW BABEL_BINARY_vu_prepare_v10_try AS +(SELECT TRY_CONVERT(BINARY(5), col1, 2) FROM BABEL_BINARY_test_table4); +GO + + + +-- Test case for CONVERT with CAST with different styles +CREATE VIEW BABEL_BINARY_vu_prepare_v11 AS +(SELECT CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 1) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v12 AS +(SELECT CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 0) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v13 AS +(SELECT CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 2) FROM BABEL_BINARY_test_table1); +GO + +-- Test case for TRY_CONVERT with CAST with different styles +CREATE VIEW BABEL_BINARY_vu_prepare_v14_try AS +(SELECT TRY_CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 1) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v15_try AS +(SELECT TRY_CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 0) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v16_try AS +(SELECT TRY_CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 2) FROM BABEL_BINARY_test_table1); +GO + + +-- Test case for variable usage +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p6 AS +BEGIN + DECLARE @abc VARCHAR(30); + SET @abc = '0x1234ABCD'; + SELECT CONVERT(BINARY(5), @abc, 1); +END +GO + +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p7 AS +BEGIN + DECLARE @abc NVARCHAR(30); + SET @abc = '1234ABCD'; + SELECT CONVERT(BINARY(5), @abc, 0); +END +GO + +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p8 AS +BEGIN + DECLARE @abc CHAR(10); + SET @abc = '1234ABCD'; + SELECT CONVERT(BINARY(5), @abc, 2); +END +GO + +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p9 AS +BEGIN + DECLARE @abc VARCHAR(30); + SET @abc = '0x1234ABCD'; + SELECT TRY_CONVERT(BINARY(5), @abc, 1); +END +GO + +-- Using multiple variables and conversions +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p10 AS +BEGIN + DECLARE @abc VARCHAR(30), @def NVARCHAR(30); + SET @abc = '0x1234ABCD'; + SET @def = '5678EF'; + SELECT + CONVERT(BINARY(5), @abc, 1) AS ConvertResult, + TRY_CONVERT(BINARY(5), @def, 2) AS TryConvertResult; +END +GO + +-- Test case for UNION with different types +CREATE VIEW BABEL_BINARY_vu_prepare_v17 AS +SELECT CONVERT(BINARY(5), '0x1234', 1) +UNION ALL +SELECT CONVERT(BINARY(5), 12345, 0) +GO + +-- Using TRY_CONVERT +CREATE VIEW BABEL_BINARY_vu_prepare_v18 AS +SELECT TRY_CONVERT(BINARY(5), '0x1234', 1) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), 12345, 0) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), 'ABCDE', 2) +GO + +-- Using different output lengths +CREATE VIEW BABEL_BINARY_vu_prepare_v19 AS +SELECT CONVERT(BINARY(3), '0x1234', 1) +UNION ALL +SELECT CONVERT(BINARY(8), 12345, 0) +UNION ALL +SELECT CONVERT(BINARY(10), '0xABCDEF', 1) +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v20 AS +SELECT TRY_CONVERT(BINARY(3), '0x1234', 1) +UNION ALL +SELECT TRY_CONVERT(BINARY(8), 12345, 0) +UNION ALL +SELECT TRY_CONVERT(BINARY(10), '0xABCDEF', 1) +GO + +-- Using CAST and concatenation +CREATE VIEW BABEL_BINARY_vu_prepare_v21 AS +SELECT CONVERT(BINARY(5), CAST('0x' + '1234' AS VARCHAR(10)), 1) +UNION ALL +SELECT CONVERT(BINARY(5), CAST(123 + 45 AS VARCHAR(10)), 0) +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v22 AS +SELECT TRY_CONVERT(BINARY(5), CAST('0x' + '1234' AS VARCHAR(10)), 1) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), CAST(123 + 45 AS VARCHAR(10)), 0) +GO + +-- Using subqueries and constants +CREATE VIEW BABEL_BINARY_vu_prepare_v23 AS +SELECT CONVERT(BINARY(5), (SELECT '0x1234'), 1) +UNION ALL +SELECT CONVERT(BINARY(5), 0x1234, 0) +UNION ALL +SELECT CONVERT(BINARY(5), CHAR(65) + CHAR(66), 0) +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v24 AS +SELECT TRY_CONVERT(BINARY(5), (SELECT '0x1234'), 1) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), 0x1234, 0) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), CHAR(65) + CHAR(66), 0) +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v26 AS +SELECT TRY_CONVERT(BINARY(5), CAST('1234' AS NVARCHAR(10)), 2) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), CAST(12345 AS DECIMAL(10,2)), 0) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), LOWER('0xABCD'), 1) +GO + +-- Test case for CONVERT with NULL in different positions +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p11 AS +BEGIN + DECLARE @nullVar VARCHAR(10) = NULL; + SELECT + CONVERT(BINARY(5), NULL, 0) AS NullInput, + CONVERT(BINARY(5), '0x1234', NULL) AS NullStyle, + CONVERT(BINARY(5), @nullVar, 0) AS NullVariable; +END +GO + +-- Test case for CONVERT with decimal +CREATE FUNCTION BABEL_BINARY_vu_prepare_f7() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(5), 123.45, 0)); +END +GO + +CREATE FUNCTION BABEL_BINARY_vu_prepare_f8() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT TRY_CONVERT(BINARY(5), 123.45, 0)); +END +GO + +-- Test case for CONVERT with different styles +CREATE VIEW BABEL_BINARY_vu_prepare_v27 AS +SELECT + CONVERT(BINARY(5), '0x1234', 0) AS Style0, + CONVERT(BINARY(5), '0x1234', 1) AS Style1, + CONVERT(BINARY(5), '1234', 2) AS Style2; +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v28 AS +SELECT + TRY_CONVERT(BINARY(5), '0x1234', 0) AS Style0, + TRY_CONVERT(BINARY(5), '0x1234', 1) AS Style1, + TRY_CONVERT(BINARY(5), '1234', 2) AS Style2; +GO + +-- Test case for CONVERT with large binary and truncation +CREATE FUNCTION BABEL_BINARY_vu_prepare_f9() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(5), '0x123456789ABCDEF', 1)); +END +GO + +CREATE FUNCTION BABEL_BINARY_vu_prepare_f10() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT TRY_CONVERT(BINARY(5), '0x123456789ABCDEF', 1)); +END +GO + +-- Test case for CONVERT with different input types +CREATE VIEW BABEL_BINARY_vu_prepare_v29 AS +SELECT + CONVERT(BINARY(5), 12345, 0) AS IntInput, + CONVERT(BINARY(5), '2023-01-01', 0) AS DateInput, + CONVERT(BINARY(5), CAST('Hello, World!' AS NVARCHAR(20)), 0) AS NVarCharInput, + CONVERT(BINARY(5), CAST(0x1234ABCD AS VARBINARY(4)), 0) AS VarBinaryInput; +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v30 AS +SELECT + TRY_CONVERT(BINARY(5), 12345, 0) AS IntInput, + TRY_CONVERT(BINARY(5), '2023-01-01', 0) AS DateInput, + TRY_CONVERT(BINARY(5), CAST('Hello, World!' AS NVARCHAR(20)), 0) AS NVarCharInput, + TRY_CONVERT(BINARY(5), CAST(0x1234ABCD AS VARBINARY(4)), 0) AS VarBinaryInput; +GO + +CREATE TABLE BABEL_BINARY_test_table_compcol (col1 VARCHAR(20), col2 AS CONVERT(VARBINARY(20), col1)); +GO +INSERT INTO BABEL_BINARY_test_table_compcol (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO +~~ROW COUNT: 3~~ + + +CREATE TABLE BABEL_BINARY_test_table_compcol1 (col1 VARCHAR(20), col2 AS TRY_CONVERT(VARBINARY(20), col1)); +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: generation expression is not immutable)~~ + +INSERT INTO BABEL_BINARY_test_table_compcol1 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: relation "babel_binary_test_table_compcol1" does not exist)~~ + + +CREATE TABLE BABEL_BINARY_test_table_compcol2 (col1 VARCHAR(20), col2 AS CONVERT(VARBINARY(20), col1, 1)); +GO +INSERT INTO BABEL_BINARY_test_table_compcol2 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO +~~ROW COUNT: 3~~ + + +CREATE TABLE BABEL_BINARY_test_table_compcol3 (col1 VARCHAR(20), col2 AS TRY_CONVERT(VARBINARY(20), col1, 1)); +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: generation expression is not immutable)~~ + +INSERT INTO BABEL_BINARY_test_table_compcol3 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: relation "babel_binary_test_table_compcol3" does not exist)~~ + diff --git a/test/JDBC/expected/BABEL-2736-before-15_3-vu-verify.out b/test/JDBC/expected/BABEL-2736-before-15_3-vu-verify.out new file mode 100644 index 0000000000..f42fdddfd8 --- /dev/null +++ b/test/JDBC/expected/BABEL-2736-before-15_3-vu-verify.out @@ -0,0 +1,1231 @@ +-- Test view v1 (style 0) +SELECT * FROM BABEL_BINARY_vu_prepare_v1 +GO +~~START~~ +binary +30393034443030303334 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v1 +GO + +-- Test procedure p1 (style 0) +EXEC BABEL_BINARY_vu_prepare_p1 +GO +~~START~~ +binary +30393034443030303334 +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p1 +GO + +-- Test function f1 (style 0) +SELECT dbo.BABEL_BINARY_vu_prepare_f1() +GO +~~START~~ +varbinary +30393034443030303334 +~~END~~ + +DROP FUNCTION BABEL_BINARY_vu_prepare_f1 +GO + +-- Test view v2 (style 1) +SELECT * FROM BABEL_BINARY_vu_prepare_v2 +GO +~~START~~ +binary +30783039303444303030 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v2 +GO + +-- Test procedure p2 (style 1) +EXEC BABEL_BINARY_vu_prepare_p2 +GO +~~START~~ +binary +0904D000340000000000 +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p2 +GO + +-- Test function f2 (style 1) +SELECT dbo.BABEL_BINARY_vu_prepare_f2() +GO +~~START~~ +varbinary +0904D000340000000000 +~~END~~ + +DROP FUNCTION BABEL_BINARY_vu_prepare_f2 +GO + +-- Test view v3 (style 2) +SELECT * FROM BABEL_BINARY_vu_prepare_v3 +GO +~~START~~ +binary +30393034443030303334 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v3 +GO + +-- Test procedure p3 (style 2) +EXEC BABEL_BINARY_vu_prepare_p3 +GO +~~START~~ +binary +0904D000340000000000 +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p3 +GO + +-- Test function f3 (style 2) +SELECT dbo.BABEL_BINARY_vu_prepare_f3() +GO +~~START~~ +varbinary +0904D000340000000000 +~~END~~ + +DROP FUNCTION BABEL_BINARY_vu_prepare_f3 +GO + +-- Test view v4 (VARBINARY) +SELECT * FROM BABEL_BINARY_vu_prepare_v4 +GO +~~START~~ +varbinary +30393034443030303334 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v4 +GO + +-- Test procedure p4 (VARBINARY) +EXEC BABEL_BINARY_vu_prepare_p4 +GO +~~START~~ +varbinary +30393034443030303334 +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p4 +GO + +-- Test function f4 (VARBINARY) +SELECT dbo.BABEL_BINARY_vu_prepare_f4() +GO +~~START~~ +varbinary +30393034443030303334 +~~END~~ + +DROP FUNCTION BABEL_BINARY_vu_prepare_f4 +GO + +-- Test procedure p5 (invalid style - should cause an error) +EXEC BABEL_BINARY_vu_prepare_p5 +GO +~~ERROR (Code: 9809)~~ + +~~ERROR (Message: The style 3 is not supported for conversions from varchar to varbinary.)~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p5 +GO + +-- Test function f5 (NULL input) +SELECT dbo.BABEL_BINARY_vu_prepare_f5() +GO +~~START~~ +varbinary + +~~END~~ + +DROP FUNCTION BABEL_BINARY_vu_prepare_f5 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v5 +GO +~~START~~ +binary +3078313233 +3078373837 +3078313233 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v5 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v6 +GO +~~START~~ +binary +3078313233 +3078373837 +3078313233 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v6 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v7 +GO +~~START~~ +binary +3132333441 +3738373938 +3132333400 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v7 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v8_try +GO +~~START~~ +binary +30 +30 +30 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v8_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v9_try +GO +~~START~~ +binary +30 +30 +30 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v9_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v10_try +GO +~~START~~ +binary +31 +37 +31 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v10_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v11 +GO +~~START~~ +binary +3078313233 +3078373837 +3078313233 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v11 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v12 +GO +~~START~~ +binary +3078313233 +3078373837 +3078313233 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v12 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v13 +GO +~~START~~ +binary +3078313233 +3078373837 +3078313233 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v13 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v14_try +GO +~~START~~ +binary +30 +30 +30 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v14_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v15_try +GO +~~START~~ +binary +30 +30 +30 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v15_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v16_try +GO +~~START~~ +binary +30 +30 +30 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v16_try +GO + +EXEC BABEL_BINARY_vu_prepare_p6 +GO +~~START~~ +binary +1234ABCD00 +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p6 +GO + +EXEC BABEL_BINARY_vu_prepare_p7 +GO +~~START~~ +binary +3132333441 +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p7 +GO + +EXEC BABEL_BINARY_vu_prepare_p8 +GO +~~START~~ +binary +1234ABCD00 +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p8 +GO + +EXEC BABEL_BINARY_vu_prepare_p9 +GO +~~START~~ +binary +1234ABCD00 +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p9 +GO + +EXEC BABEL_BINARY_vu_prepare_p10 +GO +~~START~~ +binary#!#binary +1234ABCD00#!#5678EF0000 +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p10 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v17 +GO +~~START~~ +binary +3078313233 +0000003039 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v17 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v18 +GO +~~START~~ +binary +30 +00 +41 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v18 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v19 +GO +~~START~~ +binary +30 +00 +30 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v19 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v20 +GO +~~START~~ +binary +30 +00 +30 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v20 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v21 +GO +~~START~~ +binary +3078313233 +3136380000 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v21 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v22 +GO +~~START~~ +binary +30 +31 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v22 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v23 +GO +~~START~~ +binary +3078313233 +1234000000 +4142000000 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v23 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v24 +GO +~~START~~ +binary +30 +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type varbinary to "binary".)~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v24 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v26 +GO +~~START~~ +binary +31 +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type "decimal" to "binary".)~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v26 +GO + +EXEC BABEL_BINARY_vu_prepare_p11 +GO +~~START~~ +binary#!#binary#!#binary +#!##!# +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p11 +GO + +SELECT dbo.BABEL_BINARY_vu_prepare_f7() +DROP FUNCTION BABEL_BINARY_vu_prepare_f7 +GO +~~START~~ +varbinary +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type numeric to varbinary)~~ + + +SELECT dbo.BABEL_BINARY_vu_prepare_f8() +DROP FUNCTION BABEL_BINARY_vu_prepare_f8 +GO +~~START~~ +varbinary + +~~END~~ + + +SELECT * FROM BABEL_BINARY_vu_prepare_v27 +GO +~~START~~ +binary#!#binary#!#binary +3078313233#!#3078313233#!#3132333400 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v27 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v28 +GO +~~START~~ +binary#!#binary#!#binary +30#!#30#!#31 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v28 +GO + +SELECT dbo.BABEL_BINARY_vu_prepare_f9() +DROP FUNCTION BABEL_BINARY_vu_prepare_f9 +GO +~~START~~ +varbinary +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +SELECT dbo.BABEL_BINARY_vu_prepare_f10() +DROP FUNCTION BABEL_BINARY_vu_prepare_f10 +GO +~~START~~ +varbinary + +~~END~~ + + +SELECT * FROM BABEL_BINARY_vu_prepare_v29 +GO +~~START~~ +binary#!#binary#!#binary#!#binary +0000003039#!#323032332D#!#48656C6C6F#!#1234ABCD00 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v29 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v30 +GO +~~START~~ +binary#!#binary#!#binary#!#binary +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type varbinary to "binary".)~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v30 +GO + +SELECT * FROM BABEL_BINARY_test_table_compcol +GO +~~START~~ +varchar#!#varbinary +0x1234ABCD#!#30783132333441424344 +0x787980#!#3078373837393830 +0x1234#!#307831323334 +~~END~~ + +DROP TABLE BABEL_BINARY_test_table_compcol +GO + +SELECT * FROM BABEL_BINARY_test_table_compcol1 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: relation "babel_binary_test_table_compcol1" does not exist)~~ + +DROP TABLE BABEL_BINARY_test_table_compcol1 +GO +~~ERROR (Code: 3701)~~ + +~~ERROR (Message: table "babel_binary_test_table_compcol1" does not exist)~~ + + +SELECT * FROM BABEL_BINARY_test_table_compcol2 +GO +~~START~~ +varchar#!#varbinary +0x1234ABCD#!#30783132333441424344 +0x787980#!#3078373837393830 +0x1234#!#307831323334 +~~END~~ + +DROP TABLE BABEL_BINARY_test_table_compcol2 +GO + +SELECT * FROM BABEL_BINARY_test_table_compcol3 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: relation "babel_binary_test_table_compcol3" does not exist)~~ + +DROP TABLE BABEL_BINARY_test_table_compcol3 +GO +~~ERROR (Code: 3701)~~ + +~~ERROR (Message: table "babel_binary_test_table_compcol3" does not exist)~~ + + + +-- Additional test cases +-- 1. Testing style 0 (default, ASCII conversion): +-- even length string +SELECT CONVERT(BINARY(5), '0904D00034', 0) +Go +~~START~~ +binary +3039303444 +~~END~~ + + +-- odd length string +SELECT CONVERT(BINARY(10), '0904D000341', 0) +Go +~~START~~ +binary +30393034443030303334 +~~END~~ + + +-- default style selected as 0 +SELECT CONVERT(BINARY(5), '0904D00034') +Go +~~START~~ +binary +3039303444 +~~END~~ + + +-- string with prefix '0x' and even length +SELECT CONVERT(BINARY(10), '0x0904D00034', 0) +Go +~~START~~ +binary +30783039303444303030 +~~END~~ + + +-- string with prefix '0x' and odd length +SELECT CONVERT(BINARY(10), '0x0904D000341', 0) +Go +~~START~~ +binary +30783039303444303030 +~~END~~ + + +SELECT CONVERT(BINARY(5), 'Hello', 0) +Go +~~START~~ +binary +48656C6C6F +~~END~~ + + +-- padding +SELECT CONVERT(BINARY(20), 'Hello', 0) +Go +~~START~~ +binary +48656C6C6F000000000000000000000000000000 +~~END~~ + + +-- string with blank spaces +SELECT CONVERT(BINARY(10), 'Hello World', 0) +Go +~~START~~ +binary +48656C6C6F20576F726C +~~END~~ + + +-- special characters +SELECT CONVERT(BINARY(15), '0904D000341!@', 0) +Go +~~START~~ +binary +303930344430303033343121400000 +~~END~~ + + +-- empty string +SELECT CONVERT(BINARY(5), '', 0) +Go +~~START~~ +binary +0000000000 +~~END~~ + + + + + +-- 2. Testing style 1 (hexadecimal conversion with '0x' prefix): +-- even length string +SELECT CONVERT(BINARY(5), '0x0904D00034', 1); +Go +~~START~~ +binary +0904D00034 +~~END~~ + + +-- odd length string (should cause an error) +SELECT CONVERT(BINARY(10), '0x0904D000341', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- string without '0x' prefix (should cause an error) +SELECT CONVERT(BINARY(10), '0904D00034', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- string with '0x' prefix and odd length (should cause an error) +SELECT CONVERT(BINARY(10), '0x0904D000341', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- non-hexadecimal string (should cause an error) +SELECT CONVERT(BINARY(5), 'Hello', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- hexadecimal with padding +SELECT CONVERT(BINARY(20), '0x48656C6C6F', 1) +Go +~~START~~ +binary +48656C6C6F000000000000000000000000000000 +~~END~~ + + +-- special characters in hexadecimal (should cause an error) +SELECT CONVERT(BINARY(15), '0x0904D000341213440', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- non-hexadecimal characters after '0x' (should cause an error) +SELECT CONVERT(BINARY(16), '0x0904D000341!@', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- odd number of hexadecimal digits (should cause an error) +SELECT CONVERT(BINARY(5), '0x0904D0003', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- empty string (should cause an error) +SELECT CONVERT(BINARY(5), '', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + + + + +-- 3. Testing style 2 (hexadecimal conversion without '0x' prefix): +-- even length string +SELECT CONVERT(BINARY(5), '0904D00034', 2) +Go +~~START~~ +binary +0904D00034 +~~END~~ + + +-- odd length string (should cause an error) +SELECT CONVERT(BINARY(10), '0904D000341', 2) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: invalid hexadecimal data: odd number of digits)~~ + + +-- string with '0x' prefix (should cause an error) +SELECT CONVERT(BINARY(10), '0x0904D00034', 2) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- hexadecimal with padding +SELECT CONVERT(BINARY(20), '48656C6C6F', 2) +Go +~~START~~ +binary +48656C6C6F000000000000000000000000000000 +~~END~~ + + +-- non-hexadecimal characters (should cause an error) +SELECT CONVERT(BINARY(16), '0904D000341!@', 2) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: invalid hexadecimal digit: "!")~~ + + +-- empty string +SELECT CONVERT(BINARY(5), '', 2) +Go +~~START~~ +binary +0000000000 +~~END~~ + + +-- maximum length input (8000 bytes = 16000 hex digits) +SELECT CONVERT(BINARY(8000), REPLICATE('0', 16000), 2) +Go +~~START~~ +binary +0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +~~END~~ + + + + + +-- Testing null styles and empty strings +-- Style 0 (default, ASCII conversion) +-- Null input +SELECT CONVERT(BINARY(5), NULL, 0) +Go +~~START~~ +binary + +~~END~~ + + +-- Empty string +SELECT CONVERT(BINARY(5), '', 0) +Go +~~START~~ +binary +0000000000 +~~END~~ + + +-- Null style +SELECT CONVERT(BINARY(5), '0904D00034', NULL) +Go +~~START~~ +binary + +~~END~~ + + +-- Empty string with null style +SELECT CONVERT(BINARY(5), '', NULL) +Go +~~START~~ +binary + +~~END~~ + + + +-- Style 1 (hexadecimal conversion with '0x' prefix) +-- Null input +SELECT CONVERT(BINARY(5), NULL, 1) +Go +~~START~~ +binary + +~~END~~ + + +-- Empty string (should cause an error) +SELECT CONVERT(BINARY(5), '', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- Null style with '0x' prefix +SELECT CONVERT(BINARY(5), '0x0904D00034', NULL) +Go +~~START~~ +binary + +~~END~~ + + + +-- Style 2 (hexadecimal conversion without '0x' prefix) +-- Null input +SELECT CONVERT(BINARY(5), NULL, 2) +Go +~~START~~ +binary + +~~END~~ + + +-- Empty string +SELECT CONVERT(BINARY(5), '', 2) +Go +~~START~~ +binary +0000000000 +~~END~~ + + + +-- Additional edge cases +-- Null input with null style +SELECT CONVERT(BINARY(5), NULL, NULL) +Go +~~START~~ +binary + +~~END~~ + + +-- Empty string with large BINARY size +SELECT CONVERT(BINARY(8000), '', 0) +Go +~~START~~ +binary +0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +~~END~~ + + +-- Null input with large BINARY size +SELECT CONVERT(BINARY(8000), NULL, 0) +Go +~~START~~ +binary + +~~END~~ + + +-- Space-only string +SELECT CONVERT(BINARY(5), ' ', 0) +Go +~~START~~ +binary +2020202020 +~~END~~ + + +SELECT CONVERT(BINARY(5), ' ', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +SELECT CONVERT(BINARY(5), ' ', 2) +Go +~~START~~ +binary +0000000000 +~~END~~ + + +-- Invalid style +SELECT CONVERT(BINARY(10), '0904D00034', 3); +Go +~~ERROR (Code: 9809)~~ + +~~ERROR (Message: The style 3 is not supported for conversions from varchar to varbinary.)~~ + + +-- Length greater than maximum allowed length (8000) +SELECT CONVERT(BINARY(8001), '0904D00034', 2) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The size '8001' exceeds the maximum allowed (8000) for 'binary' datatype.)~~ + + +-- Minimum length (1 byte) for BINARY +SELECT CONVERT(BINARY(1), 'A', 0); +Go +~~START~~ +binary +41 +~~END~~ + + +-- Minimum length (1 byte) for VARBINARY +SELECT CONVERT(VARBINARY(1), 'A', 0); +Go +~~START~~ +varbinary +41 +~~END~~ + + +-- Negative length for BINARY +SELECT CONVERT(BINARY(-5), '0904D00034', 0); +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: syntax error near '(' at line 2 and character position 21)~~ + + +-- Zero length for BINARY +SELECT CONVERT(BINARY(0), '0904D00034', 0); +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: length for type varbinary must be at least 1)~~ + + + + +-- Varbinary +-- 1. Testing style 0 (default, ASCII conversion): +-- even length string +SELECT CONVERT(VARBINARY(10), '0904D00034', 0); +Go +~~START~~ +varbinary +30393034443030303334 +~~END~~ + + +-- odd length string +SELECT CONVERT(VARBINARY(10), '0904D000341', 0); +Go +~~START~~ +varbinary +30393034443030303334 +~~END~~ + + +-- default style (should be equivalent to style 0) +SELECT CONVERT(VARBINARY(10), '0904D00034'); +Go +~~START~~ +varbinary +30393034443030303334 +~~END~~ + + +-- string with prefix '0x' and even length +SELECT CONVERT(VARBINARY(10), '0x0904D00034', 0); +Go +~~START~~ +varbinary +30783039303444303030 +~~END~~ + + +-- string with blank spaces +SELECT CONVERT(VARBINARY(15), 'Hello World', 0); +Go +~~START~~ +varbinary +48656C6C6F20576F726C64 +~~END~~ + + +-- special characters +SELECT CONVERT(VARBINARY(15), '0904D000341!@', 0); +Go +~~START~~ +varbinary +30393034443030303334312140 +~~END~~ + + +-- empty string +SELECT CONVERT(VARBINARY(5), '', 0); +Go +~~START~~ +varbinary + +~~END~~ + + + +-- 2. Testing style 1 (hexadecimal conversion with '0x' prefix): +-- even length string +SELECT CONVERT(VARBINARY(10), '0x0904D00034', 1); +Go +~~START~~ +varbinary +0904D00034 +~~END~~ + + +-- odd length string (should cause an error) +SELECT CONVERT(VARBINARY(10), '0x0904D000341', 1); +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- string without '0x' prefix (should cause an error) +SELECT CONVERT(VARBINARY(10), '0904D00034', 1); +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- non-hexadecimal string (should cause an error) +SELECT CONVERT(VARBINARY(10), '0xHello', 1); +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + + +-- 3. Testing style 2 (hexadecimal conversion without '0x' prefix): +-- even length string +SELECT CONVERT(VARBINARY(10), '0904D00034', 2); +Go +~~START~~ +varbinary +0904D00034 +~~END~~ + + +-- odd length string (should cause an error) +SELECT CONVERT(VARBINARY(10), '0904D000341', 2); +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: invalid hexadecimal data: odd number of digits)~~ + + +-- string with '0x' prefix (should cause an error) +SELECT CONVERT(VARBINARY(10), '0x0904D00034', 2); +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- non-hexadecimal characters (should cause an error) +SELECT CONVERT(VARBINARY(16), '0904D000341!@', 2); +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: invalid hexadecimal digit: "!")~~ + + +-- empty string +SELECT CONVERT(VARBINARY(5), '', 2); +Go +~~START~~ +varbinary + +~~END~~ + + + +-- 4. Testing with larger sizes and edge cases: +-- maximum length input (8000 bytes = 16000 hex digits) +SELECT CONVERT(VARBINARY(8000), REPLICATE('0', 16000), 2); +Go +~~START~~ +varbinary +0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +~~END~~ + + +-- NULL input +SELECT CONVERT(VARBINARY(10), NULL, 0); +Go +~~START~~ +varbinary + +~~END~~ + + +SELECT CONVERT(VARBINARY(10), NULL, 1); +Go +~~START~~ +varbinary + +~~END~~ + + +SELECT CONVERT(VARBINARY(10), NULL, 2); +Go +~~START~~ +varbinary + +~~END~~ + + +-- NULL style +SELECT CONVERT(VARBINARY(10), '0904D00034', NULL); +Go +~~START~~ +varbinary + +~~END~~ + + +-- Invalid style +SELECT CONVERT(VARBINARY(10), '0904D00034', 3); +Go +~~ERROR (Code: 9809)~~ + +~~ERROR (Message: The style 3 is not supported for conversions from varchar to varbinary.)~~ + + +-- Length greater than maximum allowed length (8000) +SELECT CONVERT(VARBINARY(8001), '0904D00034', 2) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The size '8001' exceeds the maximum allowed (8000) for 'varbinary' datatype.)~~ + diff --git a/test/JDBC/expected/BABEL-2736-before-16_5-vu-cleanup.out b/test/JDBC/expected/BABEL-2736-before-16_5-vu-cleanup.out new file mode 100644 index 0000000000..54696f5204 --- /dev/null +++ b/test/JDBC/expected/BABEL-2736-before-16_5-vu-cleanup.out @@ -0,0 +1,173 @@ +-- Drop views +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v1; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v2; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v3; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v4; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v5; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v6; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v7; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v8_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v9_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v10_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v11; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v12; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v13; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v14_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v15_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v16_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v17; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v18; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v19; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v20; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v21; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v22; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v23; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v24; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v26; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v27; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v28; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v29; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v30; +Go + +-- Drop procedures +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p1; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p2; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p3; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p4; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p5; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p6; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p7; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p8; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p9; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p10; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p11; +Go + +-- Drop functions +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f1; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f2; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f3; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f4; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f5; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f7; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f8; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f9; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f10; +Go +-- Drop test table +DROP TABLE IF EXISTS BABEL_BINARY_test_table1; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table2; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table3; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table4; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table_compcol; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table_compcol1; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table_compcol2; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table_compcol3; +GO diff --git a/test/JDBC/expected/BABEL-2736-before-16_5-vu-prepare.out b/test/JDBC/expected/BABEL-2736-before-16_5-vu-prepare.out new file mode 100644 index 0000000000..e1d037210e --- /dev/null +++ b/test/JDBC/expected/BABEL-2736-before-16_5-vu-prepare.out @@ -0,0 +1,396 @@ +-- View to test binary conversion with style 0 (default) +CREATE VIEW BABEL_BINARY_vu_prepare_v1 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 0)); +GO + +-- Procedure to test binary conversion with style 0 (default) +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p1 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 0)); +GO + +-- Function to test binary conversion with style 0 (default) +CREATE FUNCTION BABEL_BINARY_vu_prepare_f1() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(10), '0904D00034', 0)); +END +GO + +-- View to test binary conversion with style 1 (with '0x' prefix) +CREATE VIEW BABEL_BINARY_vu_prepare_v2 AS +(SELECT CONVERT(BINARY(10), '0x0904D00034', 1)); +GO + +-- Procedure to test binary conversion with style 1 (with '0x' prefix) +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p2 AS +(SELECT CONVERT(BINARY(10), '0x0904D00034', 1)); +GO + +-- Function to test binary conversion with style 1 (with '0x' prefix) +CREATE FUNCTION BABEL_BINARY_vu_prepare_f2() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(10), '0x0904D00034', 1)); +END +GO + +-- View to test binary conversion with style 2 +CREATE VIEW BABEL_BINARY_vu_prepare_v3 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 2)); +GO + +-- Procedure to test binary conversion with style 2 +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p3 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 2)); +GO + +-- Function to test binary conversion with style 2 +CREATE FUNCTION BABEL_BINARY_vu_prepare_f3() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(10), '0904D00034', 2)); +END +GO + +-- View to test VARBINARY conversion +CREATE VIEW BABEL_BINARY_vu_prepare_v4 AS +(SELECT CONVERT(VARBINARY(10), '0904D00034', 0)); +GO + +-- Procedure to test VARBINARY conversion +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p4 AS +(SELECT CONVERT(VARBINARY(10), '0904D00034', 0)); +GO + +-- Function to test VARBINARY conversion +CREATE FUNCTION BABEL_BINARY_vu_prepare_f4() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(VARBINARY(10), '0904D00034', 0)); +END +GO + +-- Procedure to test invalid style (should cause an error) +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p5 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 3)); +GO + +-- Function to test NULL input +CREATE FUNCTION BABEL_BINARY_vu_prepare_f5() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(10), NULL, 0)); +END +GO + +-- Test case for CONVERT with a column reference +CREATE TABLE BABEL_BINARY_test_table1 (col1 VARCHAR(20)); +GO +INSERT INTO BABEL_BINARY_test_table1 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO +~~ROW COUNT: 3~~ + + +CREATE VIEW BABEL_BINARY_vu_prepare_v5 AS +(SELECT CONVERT(BINARY(5), col1, 1) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v6 AS +(SELECT CONVERT(BINARY(5), col1, 0) FROM BABEL_BINARY_test_table1); +GO + +CREATE TABLE BABEL_BINARY_test_table2 (col1 VARCHAR(20)); +GO +INSERT INTO BABEL_BINARY_test_table2 (col1) VALUES ('1234ABCD'), ('787980'), ('1234'); +GO +~~ROW COUNT: 3~~ + + +CREATE VIEW BABEL_BINARY_vu_prepare_v7 AS +(SELECT CONVERT(BINARY(5), col1, 2) FROM BABEL_BINARY_test_table2); +GO + +-- Test case for TRY_CONVERT with a column reference +CREATE TABLE BABEL_BINARY_test_table3 (col1 VARCHAR(20)); +GO +INSERT INTO BABEL_BINARY_test_table3 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO +~~ROW COUNT: 3~~ + + +CREATE VIEW BABEL_BINARY_vu_prepare_v8_try AS +(SELECT TRY_CONVERT(BINARY(5), col1, 1) FROM BABEL_BINARY_test_table3); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v9_try AS +(SELECT TRY_CONVERT(BINARY(5), col1, 0) FROM BABEL_BINARY_test_table3); +GO + +CREATE TABLE BABEL_BINARY_test_table4 (col1 VARCHAR(20)); +GO +INSERT INTO BABEL_BINARY_test_table4 (col1) VALUES ('1234ABCD'), ('787980'), ('1234'); +GO +~~ROW COUNT: 3~~ + + +CREATE VIEW BABEL_BINARY_vu_prepare_v10_try AS +(SELECT TRY_CONVERT(BINARY(5), col1, 2) FROM BABEL_BINARY_test_table4); +GO + + + +-- Test case for CONVERT with CAST with different styles +CREATE VIEW BABEL_BINARY_vu_prepare_v11 AS +(SELECT CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 1) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v12 AS +(SELECT CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 0) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v13 AS +(SELECT CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 2) FROM BABEL_BINARY_test_table1); +GO + +-- Test case for TRY_CONVERT with CAST with different styles +CREATE VIEW BABEL_BINARY_vu_prepare_v14_try AS +(SELECT TRY_CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 1) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v15_try AS +(SELECT TRY_CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 0) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v16_try AS +(SELECT TRY_CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 2) FROM BABEL_BINARY_test_table1); +GO + + +-- Test case for variable usage +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p6 AS +BEGIN + DECLARE @abc VARCHAR(30); + SET @abc = '0x1234ABCD'; + SELECT CONVERT(BINARY(5), @abc, 1); +END +GO + +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p7 AS +BEGIN + DECLARE @abc NVARCHAR(30); + SET @abc = '1234ABCD'; + SELECT CONVERT(BINARY(5), @abc, 0); +END +GO + +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p8 AS +BEGIN + DECLARE @abc CHAR(10); + SET @abc = '1234ABCD'; + SELECT CONVERT(BINARY(5), @abc, 2); +END +GO + +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p9 AS +BEGIN + DECLARE @abc VARCHAR(30); + SET @abc = '0x1234ABCD'; + SELECT TRY_CONVERT(BINARY(5), @abc, 1); +END +GO + +-- Using multiple variables and conversions +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p10 AS +BEGIN + DECLARE @abc VARCHAR(30), @def NVARCHAR(30); + SET @abc = '0x1234ABCD'; + SET @def = '5678EF'; + SELECT + CONVERT(BINARY(5), @abc, 1) AS ConvertResult, + TRY_CONVERT(BINARY(5), @def, 2) AS TryConvertResult; +END +GO + +-- Test case for UNION with different types +CREATE VIEW BABEL_BINARY_vu_prepare_v17 AS +SELECT CONVERT(BINARY(5), '0x1234', 1) +UNION ALL +SELECT CONVERT(BINARY(5), 12345, 0) +GO + +-- Using TRY_CONVERT +CREATE VIEW BABEL_BINARY_vu_prepare_v18 AS +SELECT TRY_CONVERT(BINARY(5), '0x1234', 1) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), 12345, 0) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), 'ABCDE', 2) +GO + +-- Using different output lengths +CREATE VIEW BABEL_BINARY_vu_prepare_v19 AS +SELECT CONVERT(BINARY(3), '0x1234', 1) +UNION ALL +SELECT CONVERT(BINARY(8), 12345, 0) +UNION ALL +SELECT CONVERT(BINARY(10), '0xABCDEF', 1) +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v20 AS +SELECT TRY_CONVERT(BINARY(3), '0x1234', 1) +UNION ALL +SELECT TRY_CONVERT(BINARY(8), 12345, 0) +UNION ALL +SELECT TRY_CONVERT(BINARY(10), '0xABCDEF', 1) +GO + +-- Using CAST and concatenation +CREATE VIEW BABEL_BINARY_vu_prepare_v21 AS +SELECT CONVERT(BINARY(5), CAST('0x' + '1234' AS VARCHAR(10)), 1) +UNION ALL +SELECT CONVERT(BINARY(5), CAST(123 + 45 AS VARCHAR(10)), 0) +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v22 AS +SELECT TRY_CONVERT(BINARY(5), CAST('0x' + '1234' AS VARCHAR(10)), 1) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), CAST(123 + 45 AS VARCHAR(10)), 0) +GO + +-- Using subqueries and constants +CREATE VIEW BABEL_BINARY_vu_prepare_v23 AS +SELECT CONVERT(BINARY(5), (SELECT '0x1234'), 1) +UNION ALL +SELECT CONVERT(BINARY(5), 0x1234, 0) +UNION ALL +SELECT CONVERT(BINARY(5), CHAR(65) + CHAR(66), 0) +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v24 AS +SELECT TRY_CONVERT(BINARY(5), (SELECT '0x1234'), 1) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), 0x1234, 0) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), CHAR(65) + CHAR(66), 0) +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v26 AS +SELECT TRY_CONVERT(BINARY(5), CAST('1234' AS NVARCHAR(10)), 2) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), CAST(12345 AS DECIMAL(10,2)), 0) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), LOWER('0xABCD'), 1) +GO + +-- Test case for CONVERT with NULL in different positions +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p11 AS +BEGIN + DECLARE @nullVar VARCHAR(10) = NULL; + SELECT + CONVERT(BINARY(5), NULL, 0) AS NullInput, + CONVERT(BINARY(5), '0x1234', NULL) AS NullStyle, + CONVERT(BINARY(5), @nullVar, 0) AS NullVariable; +END +GO + +-- Test case for CONVERT with decimal +CREATE FUNCTION BABEL_BINARY_vu_prepare_f7() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(5), 123.45, 0)); +END +GO + +CREATE FUNCTION BABEL_BINARY_vu_prepare_f8() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT TRY_CONVERT(BINARY(5), 123.45, 0)); +END +GO + +-- Test case for CONVERT with different styles +CREATE VIEW BABEL_BINARY_vu_prepare_v27 AS +SELECT + CONVERT(BINARY(5), '0x1234', 0) AS Style0, + CONVERT(BINARY(5), '0x1234', 1) AS Style1, + CONVERT(BINARY(5), '1234', 2) AS Style2; +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v28 AS +SELECT + TRY_CONVERT(BINARY(5), '0x1234', 0) AS Style0, + TRY_CONVERT(BINARY(5), '0x1234', 1) AS Style1, + TRY_CONVERT(BINARY(5), '1234', 2) AS Style2; +GO + +-- Test case for CONVERT with large binary and truncation +CREATE FUNCTION BABEL_BINARY_vu_prepare_f9() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(5), '0x123456789ABCDEF', 1)); +END +GO + +CREATE FUNCTION BABEL_BINARY_vu_prepare_f10() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT TRY_CONVERT(BINARY(5), '0x123456789ABCDEF', 1)); +END +GO + +-- Test case for CONVERT with different input types +CREATE VIEW BABEL_BINARY_vu_prepare_v29 AS +SELECT + CONVERT(BINARY(5), 12345, 0) AS IntInput, + CONVERT(BINARY(5), '2023-01-01', 0) AS DateInput, + CONVERT(BINARY(5), CAST('Hello, World!' AS NVARCHAR(20)), 0) AS NVarCharInput, + CONVERT(BINARY(5), CAST(0x1234ABCD AS VARBINARY(4)), 0) AS VarBinaryInput; +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v30 AS +SELECT + TRY_CONVERT(BINARY(5), 12345, 0) AS IntInput, + TRY_CONVERT(BINARY(5), '2023-01-01', 0) AS DateInput, + TRY_CONVERT(BINARY(5), CAST('Hello, World!' AS NVARCHAR(20)), 0) AS NVarCharInput, + TRY_CONVERT(BINARY(5), CAST(0x1234ABCD AS VARBINARY(4)), 0) AS VarBinaryInput; +GO + +CREATE TABLE BABEL_BINARY_test_table_compcol (col1 VARCHAR(20), col2 AS CONVERT(VARBINARY(20), col1)); +GO +INSERT INTO BABEL_BINARY_test_table_compcol (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO +~~ROW COUNT: 3~~ + + +CREATE TABLE BABEL_BINARY_test_table_compcol1 (col1 VARCHAR(20), col2 AS TRY_CONVERT(VARBINARY(20), col1)); +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: generation expression is not immutable)~~ + +INSERT INTO BABEL_BINARY_test_table_compcol1 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: relation "babel_binary_test_table_compcol1" does not exist)~~ + + +CREATE TABLE BABEL_BINARY_test_table_compcol2 (col1 VARCHAR(20), col2 AS CONVERT(VARBINARY(20), col1, 1)); +GO +INSERT INTO BABEL_BINARY_test_table_compcol2 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO +~~ROW COUNT: 3~~ + + +CREATE TABLE BABEL_BINARY_test_table_compcol3 (col1 VARCHAR(20), col2 AS TRY_CONVERT(VARBINARY(20), col1, 1)); +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: generation expression is not immutable)~~ + +INSERT INTO BABEL_BINARY_test_table_compcol3 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: relation "babel_binary_test_table_compcol3" does not exist)~~ + diff --git a/test/JDBC/expected/BABEL-2736-before-16_5-vu-verify.out b/test/JDBC/expected/BABEL-2736-before-16_5-vu-verify.out new file mode 100644 index 0000000000..31690619b3 --- /dev/null +++ b/test/JDBC/expected/BABEL-2736-before-16_5-vu-verify.out @@ -0,0 +1,1230 @@ +-- Test view v1 (style 0) +SELECT * FROM BABEL_BINARY_vu_prepare_v1 +GO +~~START~~ +binary +30393034443030303334 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v1 +GO + +-- Test procedure p1 (style 0) +EXEC BABEL_BINARY_vu_prepare_p1 +GO +~~START~~ +binary +30393034443030303334 +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p1 +GO + +-- Test function f1 (style 0) +SELECT dbo.BABEL_BINARY_vu_prepare_f1() +GO +~~START~~ +varbinary +30393034443030303334 +~~END~~ + +DROP FUNCTION BABEL_BINARY_vu_prepare_f1 +GO + +-- Test view v2 (style 1) +SELECT * FROM BABEL_BINARY_vu_prepare_v2 +GO +~~START~~ +binary +30783039303444303030 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v2 +GO + +-- Test procedure p2 (style 1) +EXEC BABEL_BINARY_vu_prepare_p2 +GO +~~START~~ +binary +0904D000340000000000 +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p2 +GO + +-- Test function f2 (style 1) +SELECT dbo.BABEL_BINARY_vu_prepare_f2() +GO +~~START~~ +varbinary +0904D000340000000000 +~~END~~ + +DROP FUNCTION BABEL_BINARY_vu_prepare_f2 +GO + +-- Test view v3 (style 2) +SELECT * FROM BABEL_BINARY_vu_prepare_v3 +GO +~~START~~ +binary +30393034443030303334 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v3 +GO + +-- Test procedure p3 (style 2) +EXEC BABEL_BINARY_vu_prepare_p3 +GO +~~START~~ +binary +0904D000340000000000 +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p3 +GO + +-- Test function f3 (style 2) +SELECT dbo.BABEL_BINARY_vu_prepare_f3() +GO +~~START~~ +varbinary +0904D000340000000000 +~~END~~ + +DROP FUNCTION BABEL_BINARY_vu_prepare_f3 +GO + +-- Test view v4 (VARBINARY) +SELECT * FROM BABEL_BINARY_vu_prepare_v4 +GO +~~START~~ +varbinary +30393034443030303334 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v4 +GO + +-- Test procedure p4 (VARBINARY) +EXEC BABEL_BINARY_vu_prepare_p4 +GO +~~START~~ +varbinary +30393034443030303334 +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p4 +GO + +-- Test function f4 (VARBINARY) +SELECT dbo.BABEL_BINARY_vu_prepare_f4() +GO +~~START~~ +varbinary +30393034443030303334 +~~END~~ + +DROP FUNCTION BABEL_BINARY_vu_prepare_f4 +GO + +-- Test procedure p5 (invalid style - should cause an error) +EXEC BABEL_BINARY_vu_prepare_p5 +GO +~~ERROR (Code: 9809)~~ + +~~ERROR (Message: The style 3 is not supported for conversions from varchar to varbinary.)~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p5 +GO + +-- Test function f5 (NULL input) +SELECT dbo.BABEL_BINARY_vu_prepare_f5() +GO +~~START~~ +varbinary + +~~END~~ + +DROP FUNCTION BABEL_BINARY_vu_prepare_f5 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v5 +GO +~~START~~ +binary +3078313233 +3078373837 +3078313233 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v5 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v6 +GO +~~START~~ +binary +3078313233 +3078373837 +3078313233 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v6 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v7 +GO +~~START~~ +binary +3132333441 +3738373938 +3132333400 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v7 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v8_try +GO +~~START~~ +binary +30 +30 +30 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v8_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v9_try +GO +~~START~~ +binary +30 +30 +30 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v9_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v10_try +GO +~~START~~ +binary +31 +37 +31 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v10_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v11 +GO +~~START~~ +binary +3078313233 +3078373837 +3078313233 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v11 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v12 +GO +~~START~~ +binary +3078313233 +3078373837 +3078313233 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v12 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v13 +GO +~~START~~ +binary +3078313233 +3078373837 +3078313233 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v13 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v14_try +GO +~~START~~ +binary +30 +30 +30 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v14_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v15_try +GO +~~START~~ +binary +30 +30 +30 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v15_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v16_try +GO +~~START~~ +binary +30 +30 +30 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v16_try +GO + +EXEC BABEL_BINARY_vu_prepare_p6 +GO +~~START~~ +binary +1234ABCD00 +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p6 +GO + +EXEC BABEL_BINARY_vu_prepare_p7 +GO +~~START~~ +binary +3132333441 +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p7 +GO + +EXEC BABEL_BINARY_vu_prepare_p8 +GO +~~START~~ +binary +1234ABCD00 +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p8 +GO + +EXEC BABEL_BINARY_vu_prepare_p9 +GO +~~START~~ +binary +1234ABCD00 +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p9 +GO + +EXEC BABEL_BINARY_vu_prepare_p10 +GO +~~START~~ +binary#!#binary +1234ABCD00#!#5678EF0000 +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p10 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v17 +GO +~~START~~ +binary +3078313233 +0000003039 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v17 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v18 +GO +~~START~~ +binary +30 +00 +41 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v18 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v19 +GO +~~START~~ +binary +30783100000000000000 +00000000000030390000 +30784142434445460000 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v19 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v20 +GO +~~START~~ +binary +30 +00 +30 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v20 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v21 +GO +~~START~~ +binary +3078313233 +3136380000 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v21 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v22 +GO +~~START~~ +binary +30 +31 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v22 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v23 +GO +~~START~~ +binary +3078313233 +1234000000 +4142000000 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v23 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v24 +GO +~~START~~ +binary +30 +30 +41 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v24 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v26 +GO +~~START~~ +binary +31 +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type "decimal" to "binary".)~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v26 +GO + +EXEC BABEL_BINARY_vu_prepare_p11 +GO +~~START~~ +binary#!#binary#!#binary +#!##!# +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p11 +GO + +SELECT dbo.BABEL_BINARY_vu_prepare_f7() +DROP FUNCTION BABEL_BINARY_vu_prepare_f7 +GO +~~START~~ +varbinary +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type numeric to varbinary)~~ + + +SELECT dbo.BABEL_BINARY_vu_prepare_f8() +DROP FUNCTION BABEL_BINARY_vu_prepare_f8 +GO +~~START~~ +varbinary + +~~END~~ + + +SELECT * FROM BABEL_BINARY_vu_prepare_v27 +GO +~~START~~ +binary#!#binary#!#binary +3078313233#!#3078313233#!#3132333400 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v27 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v28 +GO +~~START~~ +binary#!#binary#!#binary +30#!#30#!#31 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v28 +GO + +SELECT dbo.BABEL_BINARY_vu_prepare_f9() +DROP FUNCTION BABEL_BINARY_vu_prepare_f9 +GO +~~START~~ +varbinary +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +SELECT dbo.BABEL_BINARY_vu_prepare_f10() +DROP FUNCTION BABEL_BINARY_vu_prepare_f10 +GO +~~START~~ +varbinary + +~~END~~ + + +SELECT * FROM BABEL_BINARY_vu_prepare_v29 +GO +~~START~~ +binary#!#binary#!#binary#!#binary +0000003039#!#323032332D#!#48656C6C6F#!#1234ABCD00 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v29 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v30 +GO +~~START~~ +binary#!#binary#!#binary#!#binary +00#!#32#!#48#!#30 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v30 +GO + +SELECT * FROM BABEL_BINARY_test_table_compcol +GO +~~START~~ +varchar#!#varbinary +0x1234ABCD#!#30783132333441424344 +0x787980#!#3078373837393830 +0x1234#!#307831323334 +~~END~~ + +DROP TABLE BABEL_BINARY_test_table_compcol +GO + +SELECT * FROM BABEL_BINARY_test_table_compcol1 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: relation "babel_binary_test_table_compcol1" does not exist)~~ + +DROP TABLE BABEL_BINARY_test_table_compcol1 +GO +~~ERROR (Code: 3701)~~ + +~~ERROR (Message: table "babel_binary_test_table_compcol1" does not exist)~~ + + +SELECT * FROM BABEL_BINARY_test_table_compcol2 +GO +~~START~~ +varchar#!#varbinary +0x1234ABCD#!#30783132333441424344 +0x787980#!#3078373837393830 +0x1234#!#307831323334 +~~END~~ + +DROP TABLE BABEL_BINARY_test_table_compcol2 +GO + +SELECT * FROM BABEL_BINARY_test_table_compcol3 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: relation "babel_binary_test_table_compcol3" does not exist)~~ + +DROP TABLE BABEL_BINARY_test_table_compcol3 +GO +~~ERROR (Code: 3701)~~ + +~~ERROR (Message: table "babel_binary_test_table_compcol3" does not exist)~~ + + + +-- Additional test cases +-- 1. Testing style 0 (default, ASCII conversion): +-- even length string +SELECT CONVERT(BINARY(5), '0904D00034', 0) +Go +~~START~~ +binary +3039303444 +~~END~~ + + +-- odd length string +SELECT CONVERT(BINARY(10), '0904D000341', 0) +Go +~~START~~ +binary +30393034443030303334 +~~END~~ + + +-- default style selected as 0 +SELECT CONVERT(BINARY(5), '0904D00034') +Go +~~START~~ +binary +3039303444 +~~END~~ + + +-- string with prefix '0x' and even length +SELECT CONVERT(BINARY(10), '0x0904D00034', 0) +Go +~~START~~ +binary +30783039303444303030 +~~END~~ + + +-- string with prefix '0x' and odd length +SELECT CONVERT(BINARY(10), '0x0904D000341', 0) +Go +~~START~~ +binary +30783039303444303030 +~~END~~ + + +SELECT CONVERT(BINARY(5), 'Hello', 0) +Go +~~START~~ +binary +48656C6C6F +~~END~~ + + +-- padding +SELECT CONVERT(BINARY(20), 'Hello', 0) +Go +~~START~~ +binary +48656C6C6F000000000000000000000000000000 +~~END~~ + + +-- string with blank spaces +SELECT CONVERT(BINARY(10), 'Hello World', 0) +Go +~~START~~ +binary +48656C6C6F20576F726C +~~END~~ + + +-- special characters +SELECT CONVERT(BINARY(15), '0904D000341!@', 0) +Go +~~START~~ +binary +303930344430303033343121400000 +~~END~~ + + +-- empty string +SELECT CONVERT(BINARY(5), '', 0) +Go +~~START~~ +binary +0000000000 +~~END~~ + + + + + +-- 2. Testing style 1 (hexadecimal conversion with '0x' prefix): +-- even length string +SELECT CONVERT(BINARY(5), '0x0904D00034', 1); +Go +~~START~~ +binary +0904D00034 +~~END~~ + + +-- odd length string (should cause an error) +SELECT CONVERT(BINARY(10), '0x0904D000341', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- string without '0x' prefix (should cause an error) +SELECT CONVERT(BINARY(10), '0904D00034', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- string with '0x' prefix and odd length (should cause an error) +SELECT CONVERT(BINARY(10), '0x0904D000341', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- non-hexadecimal string (should cause an error) +SELECT CONVERT(BINARY(5), 'Hello', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- hexadecimal with padding +SELECT CONVERT(BINARY(20), '0x48656C6C6F', 1) +Go +~~START~~ +binary +48656C6C6F000000000000000000000000000000 +~~END~~ + + +-- special characters in hexadecimal (should cause an error) +SELECT CONVERT(BINARY(15), '0x0904D000341213440', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- non-hexadecimal characters after '0x' (should cause an error) +SELECT CONVERT(BINARY(16), '0x0904D000341!@', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- odd number of hexadecimal digits (should cause an error) +SELECT CONVERT(BINARY(5), '0x0904D0003', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- empty string (should cause an error) +SELECT CONVERT(BINARY(5), '', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + + + + +-- 3. Testing style 2 (hexadecimal conversion without '0x' prefix): +-- even length string +SELECT CONVERT(BINARY(5), '0904D00034', 2) +Go +~~START~~ +binary +0904D00034 +~~END~~ + + +-- odd length string (should cause an error) +SELECT CONVERT(BINARY(10), '0904D000341', 2) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: invalid hexadecimal data: odd number of digits)~~ + + +-- string with '0x' prefix (should cause an error) +SELECT CONVERT(BINARY(10), '0x0904D00034', 2) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- hexadecimal with padding +SELECT CONVERT(BINARY(20), '48656C6C6F', 2) +Go +~~START~~ +binary +48656C6C6F000000000000000000000000000000 +~~END~~ + + +-- non-hexadecimal characters (should cause an error) +SELECT CONVERT(BINARY(16), '0904D000341!@', 2) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: invalid hexadecimal digit: "!")~~ + + +-- empty string +SELECT CONVERT(BINARY(5), '', 2) +Go +~~START~~ +binary +0000000000 +~~END~~ + + +-- maximum length input (8000 bytes = 16000 hex digits) +SELECT CONVERT(BINARY(8000), REPLICATE('0', 16000), 2) +Go +~~START~~ +binary +0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +~~END~~ + + + + + +-- Testing null styles and empty strings +-- Style 0 (default, ASCII conversion) +-- Null input +SELECT CONVERT(BINARY(5), NULL, 0) +Go +~~START~~ +binary + +~~END~~ + + +-- Empty string +SELECT CONVERT(BINARY(5), '', 0) +Go +~~START~~ +binary +0000000000 +~~END~~ + + +-- Null style +SELECT CONVERT(BINARY(5), '0904D00034', NULL) +Go +~~START~~ +binary + +~~END~~ + + +-- Empty string with null style +SELECT CONVERT(BINARY(5), '', NULL) +Go +~~START~~ +binary + +~~END~~ + + + +-- Style 1 (hexadecimal conversion with '0x' prefix) +-- Null input +SELECT CONVERT(BINARY(5), NULL, 1) +Go +~~START~~ +binary + +~~END~~ + + +-- Empty string (should cause an error) +SELECT CONVERT(BINARY(5), '', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- Null style with '0x' prefix +SELECT CONVERT(BINARY(5), '0x0904D00034', NULL) +Go +~~START~~ +binary + +~~END~~ + + + +-- Style 2 (hexadecimal conversion without '0x' prefix) +-- Null input +SELECT CONVERT(BINARY(5), NULL, 2) +Go +~~START~~ +binary + +~~END~~ + + +-- Empty string +SELECT CONVERT(BINARY(5), '', 2) +Go +~~START~~ +binary +0000000000 +~~END~~ + + + +-- Additional edge cases +-- Null input with null style +SELECT CONVERT(BINARY(5), NULL, NULL) +Go +~~START~~ +binary + +~~END~~ + + +-- Empty string with large BINARY size +SELECT CONVERT(BINARY(8000), '', 0) +Go +~~START~~ +binary +0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +~~END~~ + + +-- Null input with large BINARY size +SELECT CONVERT(BINARY(8000), NULL, 0) +Go +~~START~~ +binary + +~~END~~ + + +-- Space-only string +SELECT CONVERT(BINARY(5), ' ', 0) +Go +~~START~~ +binary +2020202020 +~~END~~ + + +SELECT CONVERT(BINARY(5), ' ', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +SELECT CONVERT(BINARY(5), ' ', 2) +Go +~~START~~ +binary +0000000000 +~~END~~ + + +-- Invalid style +SELECT CONVERT(BINARY(10), '0904D00034', 3); +Go +~~ERROR (Code: 9809)~~ + +~~ERROR (Message: The style 3 is not supported for conversions from varchar to varbinary.)~~ + + +-- Length greater than maximum allowed length (8000) +SELECT CONVERT(BINARY(8001), '0904D00034', 2) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The size '8001' exceeds the maximum allowed (8000) for 'binary' datatype.)~~ + + +-- Minimum length (1 byte) for BINARY +SELECT CONVERT(BINARY(1), 'A', 0); +Go +~~START~~ +binary +41 +~~END~~ + + +-- Minimum length (1 byte) for VARBINARY +SELECT CONVERT(VARBINARY(1), 'A', 0); +Go +~~START~~ +varbinary +41 +~~END~~ + + +-- Negative length for BINARY +SELECT CONVERT(BINARY(-5), '0904D00034', 0); +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: syntax error near '(' at line 2 and character position 21)~~ + + +-- Zero length for BINARY +SELECT CONVERT(BINARY(0), '0904D00034', 0); +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: length for type varbinary must be at least 1)~~ + + + + +-- Varbinary +-- 1. Testing style 0 (default, ASCII conversion): +-- even length string +SELECT CONVERT(VARBINARY(10), '0904D00034', 0); +Go +~~START~~ +varbinary +30393034443030303334 +~~END~~ + + +-- odd length string +SELECT CONVERT(VARBINARY(10), '0904D000341', 0); +Go +~~START~~ +varbinary +30393034443030303334 +~~END~~ + + +-- default style (should be equivalent to style 0) +SELECT CONVERT(VARBINARY(10), '0904D00034'); +Go +~~START~~ +varbinary +30393034443030303334 +~~END~~ + + +-- string with prefix '0x' and even length +SELECT CONVERT(VARBINARY(10), '0x0904D00034', 0); +Go +~~START~~ +varbinary +30783039303444303030 +~~END~~ + + +-- string with blank spaces +SELECT CONVERT(VARBINARY(15), 'Hello World', 0); +Go +~~START~~ +varbinary +48656C6C6F20576F726C64 +~~END~~ + + +-- special characters +SELECT CONVERT(VARBINARY(15), '0904D000341!@', 0); +Go +~~START~~ +varbinary +30393034443030303334312140 +~~END~~ + + +-- empty string +SELECT CONVERT(VARBINARY(5), '', 0); +Go +~~START~~ +varbinary + +~~END~~ + + + +-- 2. Testing style 1 (hexadecimal conversion with '0x' prefix): +-- even length string +SELECT CONVERT(VARBINARY(10), '0x0904D00034', 1); +Go +~~START~~ +varbinary +0904D00034 +~~END~~ + + +-- odd length string (should cause an error) +SELECT CONVERT(VARBINARY(10), '0x0904D000341', 1); +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- string without '0x' prefix (should cause an error) +SELECT CONVERT(VARBINARY(10), '0904D00034', 1); +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- non-hexadecimal string (should cause an error) +SELECT CONVERT(VARBINARY(10), '0xHello', 1); +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + + +-- 3. Testing style 2 (hexadecimal conversion without '0x' prefix): +-- even length string +SELECT CONVERT(VARBINARY(10), '0904D00034', 2); +Go +~~START~~ +varbinary +0904D00034 +~~END~~ + + +-- odd length string (should cause an error) +SELECT CONVERT(VARBINARY(10), '0904D000341', 2); +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: invalid hexadecimal data: odd number of digits)~~ + + +-- string with '0x' prefix (should cause an error) +SELECT CONVERT(VARBINARY(10), '0x0904D00034', 2); +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- non-hexadecimal characters (should cause an error) +SELECT CONVERT(VARBINARY(16), '0904D000341!@', 2); +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: invalid hexadecimal digit: "!")~~ + + +-- empty string +SELECT CONVERT(VARBINARY(5), '', 2); +Go +~~START~~ +varbinary + +~~END~~ + + + +-- 4. Testing with larger sizes and edge cases: +-- maximum length input (8000 bytes = 16000 hex digits) +SELECT CONVERT(VARBINARY(8000), REPLICATE('0', 16000), 2); +Go +~~START~~ +varbinary +0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +~~END~~ + + +-- NULL input +SELECT CONVERT(VARBINARY(10), NULL, 0); +Go +~~START~~ +varbinary + +~~END~~ + + +SELECT CONVERT(VARBINARY(10), NULL, 1); +Go +~~START~~ +varbinary + +~~END~~ + + +SELECT CONVERT(VARBINARY(10), NULL, 2); +Go +~~START~~ +varbinary + +~~END~~ + + +-- NULL style +SELECT CONVERT(VARBINARY(10), '0904D00034', NULL); +Go +~~START~~ +varbinary + +~~END~~ + + +-- Invalid style +SELECT CONVERT(VARBINARY(10), '0904D00034', 3); +Go +~~ERROR (Code: 9809)~~ + +~~ERROR (Message: The style 3 is not supported for conversions from varchar to varbinary.)~~ + + +-- Length greater than maximum allowed length (8000) +SELECT CONVERT(VARBINARY(8001), '0904D00034', 2) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The size '8001' exceeds the maximum allowed (8000) for 'varbinary' datatype.)~~ + diff --git a/test/JDBC/expected/BABEL-2736-vu-cleanup.out b/test/JDBC/expected/BABEL-2736-vu-cleanup.out new file mode 100644 index 0000000000..54696f5204 --- /dev/null +++ b/test/JDBC/expected/BABEL-2736-vu-cleanup.out @@ -0,0 +1,173 @@ +-- Drop views +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v1; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v2; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v3; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v4; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v5; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v6; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v7; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v8_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v9_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v10_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v11; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v12; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v13; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v14_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v15_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v16_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v17; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v18; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v19; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v20; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v21; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v22; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v23; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v24; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v26; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v27; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v28; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v29; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v30; +Go + +-- Drop procedures +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p1; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p2; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p3; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p4; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p5; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p6; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p7; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p8; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p9; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p10; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p11; +Go + +-- Drop functions +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f1; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f2; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f3; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f4; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f5; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f7; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f8; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f9; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f10; +Go +-- Drop test table +DROP TABLE IF EXISTS BABEL_BINARY_test_table1; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table2; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table3; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table4; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table_compcol; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table_compcol1; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table_compcol2; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table_compcol3; +GO diff --git a/test/JDBC/expected/BABEL-2736-vu-prepare.out b/test/JDBC/expected/BABEL-2736-vu-prepare.out new file mode 100644 index 0000000000..7c29454ea5 --- /dev/null +++ b/test/JDBC/expected/BABEL-2736-vu-prepare.out @@ -0,0 +1,384 @@ +-- View to test binary conversion with style 0 (default) +CREATE VIEW BABEL_BINARY_vu_prepare_v1 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 0)); +GO + +-- Procedure to test binary conversion with style 0 (default) +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p1 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 0)); +GO + +-- Function to test binary conversion with style 0 (default) +CREATE FUNCTION BABEL_BINARY_vu_prepare_f1() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(10), '0904D00034', 0)); +END +GO + +-- View to test binary conversion with style 1 (with '0x' prefix) +CREATE VIEW BABEL_BINARY_vu_prepare_v2 AS +(SELECT CONVERT(BINARY(10), '0x0904D00034', 1)); +GO + +-- Procedure to test binary conversion with style 1 (with '0x' prefix) +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p2 AS +(SELECT CONVERT(BINARY(10), '0x0904D00034', 1)); +GO + +-- Function to test binary conversion with style 1 (with '0x' prefix) +CREATE FUNCTION BABEL_BINARY_vu_prepare_f2() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(10), '0x0904D00034', 1)); +END +GO + +-- View to test binary conversion with style 2 +CREATE VIEW BABEL_BINARY_vu_prepare_v3 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 2)); +GO + +-- Procedure to test binary conversion with style 2 +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p3 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 2)); +GO + +-- Function to test binary conversion with style 2 +CREATE FUNCTION BABEL_BINARY_vu_prepare_f3() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(10), '0904D00034', 2)); +END +GO + +-- View to test VARBINARY conversion +CREATE VIEW BABEL_BINARY_vu_prepare_v4 AS +(SELECT CONVERT(VARBINARY(10), '0904D00034', 0)); +GO + +-- Procedure to test VARBINARY conversion +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p4 AS +(SELECT CONVERT(VARBINARY(10), '0904D00034', 0)); +GO + +-- Function to test VARBINARY conversion +CREATE FUNCTION BABEL_BINARY_vu_prepare_f4() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(VARBINARY(10), '0904D00034', 0)); +END +GO + +-- Procedure to test invalid style (should cause an error) +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p5 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 3)); +GO + +-- Function to test NULL input +CREATE FUNCTION BABEL_BINARY_vu_prepare_f5() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(10), NULL, 0)); +END +GO + +-- Test case for CONVERT with a column reference +CREATE TABLE BABEL_BINARY_test_table1 (col1 VARCHAR(20)); +GO +INSERT INTO BABEL_BINARY_test_table1 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO +~~ROW COUNT: 3~~ + + +CREATE VIEW BABEL_BINARY_vu_prepare_v5 AS +(SELECT CONVERT(BINARY(5), col1, 1) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v6 AS +(SELECT CONVERT(BINARY(5), col1, 0) FROM BABEL_BINARY_test_table1); +GO + +CREATE TABLE BABEL_BINARY_test_table2 (col1 VARCHAR(20)); +GO +INSERT INTO BABEL_BINARY_test_table2 (col1) VALUES ('1234ABCD'), ('787980'), ('1234'); +GO +~~ROW COUNT: 3~~ + + +CREATE VIEW BABEL_BINARY_vu_prepare_v7 AS +(SELECT CONVERT(BINARY(5), col1, 2) FROM BABEL_BINARY_test_table2); +GO + +-- Test case for TRY_CONVERT with a column reference +CREATE TABLE BABEL_BINARY_test_table3 (col1 VARCHAR(20)); +GO +INSERT INTO BABEL_BINARY_test_table3 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO +~~ROW COUNT: 3~~ + + +CREATE VIEW BABEL_BINARY_vu_prepare_v8_try AS +(SELECT TRY_CONVERT(BINARY(5), col1, 1) FROM BABEL_BINARY_test_table3); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v9_try AS +(SELECT TRY_CONVERT(BINARY(5), col1, 0) FROM BABEL_BINARY_test_table3); +GO + +CREATE TABLE BABEL_BINARY_test_table4 (col1 VARCHAR(20)); +GO +INSERT INTO BABEL_BINARY_test_table4 (col1) VALUES ('1234ABCD'), ('787980'), ('1234'); +GO +~~ROW COUNT: 3~~ + + +CREATE VIEW BABEL_BINARY_vu_prepare_v10_try AS +(SELECT TRY_CONVERT(BINARY(5), col1, 2) FROM BABEL_BINARY_test_table4); +GO + + + +-- Test case for CONVERT with CAST with different styles +CREATE VIEW BABEL_BINARY_vu_prepare_v11 AS +(SELECT CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 1) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v12 AS +(SELECT CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 0) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v13 AS +(SELECT CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 2) FROM BABEL_BINARY_test_table1); +GO + +-- Test case for TRY_CONVERT with CAST with different styles +CREATE VIEW BABEL_BINARY_vu_prepare_v14_try AS +(SELECT TRY_CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 1) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v15_try AS +(SELECT TRY_CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 0) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v16_try AS +(SELECT TRY_CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 2) FROM BABEL_BINARY_test_table1); +GO + + +-- Test case for variable usage +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p6 AS +BEGIN + DECLARE @abc VARCHAR(30); + SET @abc = '0x1234ABCD'; + SELECT CONVERT(BINARY(5), @abc, 1); +END +GO + +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p7 AS +BEGIN + DECLARE @abc NVARCHAR(30); + SET @abc = '1234ABCD'; + SELECT CONVERT(BINARY(5), @abc, 0); +END +GO + +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p8 AS +BEGIN + DECLARE @abc CHAR(10); + SET @abc = '1234ABCD'; + SELECT CONVERT(BINARY(5), @abc, 2); +END +GO + +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p9 AS +BEGIN + DECLARE @abc VARCHAR(30); + SET @abc = '0x1234ABCD'; + SELECT TRY_CONVERT(BINARY(5), @abc, 1); +END +GO + +-- Using multiple variables and conversions +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p10 AS +BEGIN + DECLARE @abc VARCHAR(30), @def NVARCHAR(30); + SET @abc = '0x1234ABCD'; + SET @def = '5678EF'; + SELECT + CONVERT(BINARY(5), @abc, 1) AS ConvertResult, + TRY_CONVERT(BINARY(5), @def, 2) AS TryConvertResult; +END +GO + +-- Test case for UNION with different types +CREATE VIEW BABEL_BINARY_vu_prepare_v17 AS +SELECT CONVERT(BINARY(5), '0x1234', 1) +UNION ALL +SELECT CONVERT(BINARY(5), 12345, 0) +GO + +-- Using TRY_CONVERT +CREATE VIEW BABEL_BINARY_vu_prepare_v18 AS +SELECT TRY_CONVERT(BINARY(5), '0x1234', 1) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), 12345, 0) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), 'ABCDE', 2) +GO + +-- Using different output lengths +CREATE VIEW BABEL_BINARY_vu_prepare_v19 AS +SELECT CONVERT(BINARY(3), '0x1234', 1) +UNION ALL +SELECT CONVERT(BINARY(8), 12345, 0) +UNION ALL +SELECT CONVERT(BINARY(10), '0xABCDEF', 1) +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v20 AS +SELECT TRY_CONVERT(BINARY(3), '0x1234', 1) +UNION ALL +SELECT TRY_CONVERT(BINARY(8), 12345, 0) +UNION ALL +SELECT TRY_CONVERT(BINARY(10), '0xABCDEF', 1) +GO + +-- Using CAST and concatenation +CREATE VIEW BABEL_BINARY_vu_prepare_v21 AS +SELECT CONVERT(BINARY(5), CAST('0x' + '1234' AS VARCHAR(10)), 1) +UNION ALL +SELECT CONVERT(BINARY(5), CAST(123 + 45 AS VARCHAR(10)), 0) +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v22 AS +SELECT TRY_CONVERT(BINARY(5), CAST('0x' + '1234' AS VARCHAR(10)), 1) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), CAST(123 + 45 AS VARCHAR(10)), 0) +GO + +-- Using subqueries and constants +CREATE VIEW BABEL_BINARY_vu_prepare_v23 AS +SELECT CONVERT(BINARY(5), (SELECT '0x1234'), 1) +UNION ALL +SELECT CONVERT(BINARY(5), 0x1234, 0) +UNION ALL +SELECT CONVERT(BINARY(5), CHAR(65) + CHAR(66), 0) +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v24 AS +SELECT TRY_CONVERT(BINARY(5), (SELECT '0x1234'), 1) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), 0x1234, 0) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), CHAR(65) + CHAR(66), 0) +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v26 AS +SELECT TRY_CONVERT(BINARY(5), CAST('1234' AS NVARCHAR(10)), 2) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), CAST(12345 AS DECIMAL(10,2)), 0) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), LOWER('0xABCD'), 1) +GO + +-- Test case for CONVERT with NULL in different positions +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p11 AS +BEGIN + DECLARE @nullVar VARCHAR(10) = NULL; + SELECT + CONVERT(BINARY(5), NULL, 0) AS NullInput, + CONVERT(BINARY(5), '0x1234', NULL) AS NullStyle, + CONVERT(BINARY(5), @nullVar, 0) AS NullVariable; +END +GO + +-- Test case for CONVERT with decimal +CREATE FUNCTION BABEL_BINARY_vu_prepare_f7() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(5), 123.45, 0)); +END +GO + +CREATE FUNCTION BABEL_BINARY_vu_prepare_f8() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT TRY_CONVERT(BINARY(5), 123.45, 0)); +END +GO + +-- Test case for CONVERT with different styles +CREATE VIEW BABEL_BINARY_vu_prepare_v27 AS +SELECT + CONVERT(BINARY(5), '0x1234', 0) AS Style0, + CONVERT(BINARY(5), '0x1234', 1) AS Style1, + CONVERT(BINARY(5), '1234', 2) AS Style2; +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v28 AS +SELECT + TRY_CONVERT(BINARY(5), '0x1234', 0) AS Style0, + TRY_CONVERT(BINARY(5), '0x1234', 1) AS Style1, + TRY_CONVERT(BINARY(5), '1234', 2) AS Style2; +GO + +-- Test case for CONVERT with large binary and truncation +CREATE FUNCTION BABEL_BINARY_vu_prepare_f9() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(5), '0x123456789ABCDEF', 1)); +END +GO + +CREATE FUNCTION BABEL_BINARY_vu_prepare_f10() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT TRY_CONVERT(BINARY(5), '0x123456789ABCDEF', 1)); +END +GO + +-- Test case for CONVERT with different input types +CREATE VIEW BABEL_BINARY_vu_prepare_v29 AS +SELECT + CONVERT(BINARY(5), 12345, 0) AS IntInput, + CONVERT(BINARY(5), '2023-01-01', 0) AS DateInput, + CONVERT(BINARY(5), CAST('Hello, World!' AS NVARCHAR(20)), 0) AS NVarCharInput, + CONVERT(BINARY(5), CAST(0x1234ABCD AS VARBINARY(4)), 0) AS VarBinaryInput; +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v30 AS +SELECT + TRY_CONVERT(BINARY(5), 12345, 0) AS IntInput, + TRY_CONVERT(BINARY(5), '2023-01-01', 0) AS DateInput, + TRY_CONVERT(BINARY(5), CAST('Hello, World!' AS NVARCHAR(20)), 0) AS NVarCharInput, + TRY_CONVERT(BINARY(5), CAST(0x1234ABCD AS VARBINARY(4)), 0) AS VarBinaryInput; +GO + +CREATE TABLE BABEL_BINARY_test_table_compcol (col1 VARCHAR(20), col2 AS CONVERT(VARBINARY(20), col1)); +GO +INSERT INTO BABEL_BINARY_test_table_compcol (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO +~~ROW COUNT: 3~~ + + +CREATE TABLE BABEL_BINARY_test_table_compcol1 (col1 VARCHAR(20), col2 AS TRY_CONVERT(VARBINARY(20), col1)); +GO +INSERT INTO BABEL_BINARY_test_table_compcol1 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO +~~ROW COUNT: 3~~ + + +CREATE TABLE BABEL_BINARY_test_table_compcol2 (col1 VARCHAR(20), col2 AS CONVERT(VARBINARY(20), col1, 1)); +GO +INSERT INTO BABEL_BINARY_test_table_compcol2 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO +~~ROW COUNT: 3~~ + + +CREATE TABLE BABEL_BINARY_test_table_compcol3 (col1 VARCHAR(20), col2 AS TRY_CONVERT(VARBINARY(20), col1, 1)); +GO +INSERT INTO BABEL_BINARY_test_table_compcol3 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO +~~ROW COUNT: 3~~ + diff --git a/test/JDBC/expected/BABEL-2736-vu-verify.out b/test/JDBC/expected/BABEL-2736-vu-verify.out new file mode 100644 index 0000000000..81b78296d4 --- /dev/null +++ b/test/JDBC/expected/BABEL-2736-vu-verify.out @@ -0,0 +1,1227 @@ +-- Test view v1 (style 0) +SELECT * FROM BABEL_BINARY_vu_prepare_v1 +GO +~~START~~ +binary +30393034443030303334 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v1 +GO + +-- Test procedure p1 (style 0) +EXEC BABEL_BINARY_vu_prepare_p1 +GO +~~START~~ +binary +30393034443030303334 +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p1 +GO + +-- Test function f1 (style 0) +SELECT dbo.BABEL_BINARY_vu_prepare_f1() +GO +~~START~~ +varbinary +30393034443030303334 +~~END~~ + +DROP FUNCTION BABEL_BINARY_vu_prepare_f1 +GO + +-- Test view v2 (style 1) +SELECT * FROM BABEL_BINARY_vu_prepare_v2 +GO +~~START~~ +binary +0904D000340000000000 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v2 +GO + +-- Test procedure p2 (style 1) +EXEC BABEL_BINARY_vu_prepare_p2 +GO +~~START~~ +binary +0904D000340000000000 +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p2 +GO + +-- Test function f2 (style 1) +SELECT dbo.BABEL_BINARY_vu_prepare_f2() +GO +~~START~~ +varbinary +0904D000340000000000 +~~END~~ + +DROP FUNCTION BABEL_BINARY_vu_prepare_f2 +GO + +-- Test view v3 (style 2) +SELECT * FROM BABEL_BINARY_vu_prepare_v3 +GO +~~START~~ +binary +0904D000340000000000 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v3 +GO + +-- Test procedure p3 (style 2) +EXEC BABEL_BINARY_vu_prepare_p3 +GO +~~START~~ +binary +0904D000340000000000 +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p3 +GO + +-- Test function f3 (style 2) +SELECT dbo.BABEL_BINARY_vu_prepare_f3() +GO +~~START~~ +varbinary +0904D000340000000000 +~~END~~ + +DROP FUNCTION BABEL_BINARY_vu_prepare_f3 +GO + +-- Test view v4 (VARBINARY) +SELECT * FROM BABEL_BINARY_vu_prepare_v4 +GO +~~START~~ +varbinary +30393034443030303334 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v4 +GO + +-- Test procedure p4 (VARBINARY) +EXEC BABEL_BINARY_vu_prepare_p4 +GO +~~START~~ +varbinary +30393034443030303334 +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p4 +GO + +-- Test function f4 (VARBINARY) +SELECT dbo.BABEL_BINARY_vu_prepare_f4() +GO +~~START~~ +varbinary +30393034443030303334 +~~END~~ + +DROP FUNCTION BABEL_BINARY_vu_prepare_f4 +GO + +-- Test procedure p5 (invalid style - should cause an error) +EXEC BABEL_BINARY_vu_prepare_p5 +GO +~~ERROR (Code: 9809)~~ + +~~ERROR (Message: The style 3 is not supported for conversions from varchar to varbinary.)~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p5 +GO + +-- Test function f5 (NULL input) +SELECT dbo.BABEL_BINARY_vu_prepare_f5() +GO +~~START~~ +varbinary + +~~END~~ + +DROP FUNCTION BABEL_BINARY_vu_prepare_f5 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v5 +GO +~~START~~ +binary +1234ABCD00 +7879800000 +1234000000 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v5 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v6 +GO +~~START~~ +binary +3078313233 +3078373837 +3078313233 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v6 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v7 +GO +~~START~~ +binary +1234ABCD00 +7879800000 +1234000000 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v7 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v8_try +GO +~~START~~ +binary +1234ABCD00 +7879800000 +1234000000 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v8_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v9_try +GO +~~START~~ +binary +3078313233 +3078373837 +3078313233 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v9_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v10_try +GO +~~START~~ +binary +1234ABCD00 +7879800000 +1234000000 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v10_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v11 +GO +~~START~~ +binary +1234ABCD00 +7879800000 +1234000000 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v11 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v12 +GO +~~START~~ +binary +3078313233 +3078373837 +3078313233 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v12 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v13 +GO +~~START~~ +binary +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v13 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v14_try +GO +~~START~~ +binary +1234ABCD00 +7879800000 +1234000000 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v14_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v15_try +GO +~~START~~ +binary +3078313233 +3078373837 +3078313233 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v15_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v16_try +GO +~~START~~ +binary + + + +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v16_try +GO + +EXEC BABEL_BINARY_vu_prepare_p6 +GO +~~START~~ +binary +1234ABCD00 +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p6 +GO + +EXEC BABEL_BINARY_vu_prepare_p7 +GO +~~START~~ +binary +3132333441 +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p7 +GO + +EXEC BABEL_BINARY_vu_prepare_p8 +GO +~~START~~ +binary +1234ABCD00 +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p8 +GO + +EXEC BABEL_BINARY_vu_prepare_p9 +GO +~~START~~ +binary +1234ABCD00 +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p9 +GO + +EXEC BABEL_BINARY_vu_prepare_p10 +GO +~~START~~ +binary#!#binary +1234ABCD00#!#5678EF0000 +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p10 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v17 +GO +~~START~~ +binary +1234000000 +0000303900 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v17 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v18 +GO +~~START~~ +binary +1234000000 +0000303900 + +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v18 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v19 +GO +~~START~~ +binary +12340000000000000000 +00003039000000000000 +ABCDEF00000000000000 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v19 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v20 +GO +~~START~~ +binary +12340000000000000000 +00003039000000000000 +ABCDEF00000000000000 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v20 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v21 +GO +~~START~~ +binary +1234000000 +3136380000 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v21 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v22 +GO +~~START~~ +binary +1234000000 +3136380000 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v22 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v23 +GO +~~START~~ +binary +1234000000 +1234000000 +4142000000 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v23 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v24 +GO +~~START~~ +binary +1234000000 +1234000000 +4142000000 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v24 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v26 +GO +~~START~~ +binary +1234000000 + +ABCD000000 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v26 +GO + +EXEC BABEL_BINARY_vu_prepare_p11 +GO +~~START~~ +binary#!#binary#!#binary +#!##!# +~~END~~ + +DROP PROCEDURE BABEL_BINARY_vu_prepare_p11 +GO + +SELECT dbo.BABEL_BINARY_vu_prepare_f7() +DROP FUNCTION BABEL_BINARY_vu_prepare_f7 +GO +~~START~~ +varbinary +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cannot cast type numeric to varbinary)~~ + + +SELECT dbo.BABEL_BINARY_vu_prepare_f8() +DROP FUNCTION BABEL_BINARY_vu_prepare_f8 +GO +~~START~~ +varbinary + +~~END~~ + + +SELECT * FROM BABEL_BINARY_vu_prepare_v27 +GO +~~START~~ +binary#!#binary#!#binary +3078313233#!#1234000000#!#1234000000 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v27 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v28 +GO +~~START~~ +binary#!#binary#!#binary +3078313233#!#1234000000#!#1234000000 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v28 +GO + +SELECT dbo.BABEL_BINARY_vu_prepare_f9() +DROP FUNCTION BABEL_BINARY_vu_prepare_f9 +GO +~~START~~ +varbinary +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +SELECT dbo.BABEL_BINARY_vu_prepare_f10() +DROP FUNCTION BABEL_BINARY_vu_prepare_f10 +GO +~~START~~ +varbinary + +~~END~~ + + +SELECT * FROM BABEL_BINARY_vu_prepare_v29 +GO +~~START~~ +binary#!#binary#!#binary#!#binary +0000303900#!#323032332D#!#48656C6C6F#!#1234ABCD00 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v29 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v30 +GO +~~START~~ +binary#!#binary#!#binary#!#binary +0000303900#!#323032332D#!#48656C6C6F#!#1234ABCD00 +~~END~~ + +DROP VIEW BABEL_BINARY_vu_prepare_v30 +GO + +SELECT * FROM BABEL_BINARY_test_table_compcol +GO +~~START~~ +varchar#!#varbinary +0x1234ABCD#!#30783132333441424344 +0x787980#!#3078373837393830 +0x1234#!#307831323334 +~~END~~ + +DROP TABLE BABEL_BINARY_test_table_compcol +GO + +SELECT * FROM BABEL_BINARY_test_table_compcol1 +GO +~~START~~ +varchar#!#varbinary +0x1234ABCD#!#30783132333441424344 +0x787980#!#3078373837393830 +0x1234#!#307831323334 +~~END~~ + +DROP TABLE BABEL_BINARY_test_table_compcol1 +GO + +SELECT * FROM BABEL_BINARY_test_table_compcol2 +GO +~~START~~ +varchar#!#varbinary +0x1234ABCD#!#1234ABCD +0x787980#!#787980 +0x1234#!#1234 +~~END~~ + +DROP TABLE BABEL_BINARY_test_table_compcol2 +GO + +SELECT * FROM BABEL_BINARY_test_table_compcol3 +GO +~~START~~ +varchar#!#varbinary +0x1234ABCD#!#1234ABCD +0x787980#!#787980 +0x1234#!#1234 +~~END~~ + +DROP TABLE BABEL_BINARY_test_table_compcol3 +GO + + +-- Additional test cases +-- 1. Testing style 0 (default, ASCII conversion): +-- even length string +SELECT CONVERT(BINARY(5), '0904D00034', 0) +Go +~~START~~ +binary +3039303444 +~~END~~ + + +-- odd length string +SELECT CONVERT(BINARY(10), '0904D000341', 0) +Go +~~START~~ +binary +30393034443030303334 +~~END~~ + + +-- default style selected as 0 +SELECT CONVERT(BINARY(5), '0904D00034') +Go +~~START~~ +binary +3039303444 +~~END~~ + + +-- string with prefix '0x' and even length +SELECT CONVERT(BINARY(10), '0x0904D00034', 0) +Go +~~START~~ +binary +30783039303444303030 +~~END~~ + + +-- string with prefix '0x' and odd length +SELECT CONVERT(BINARY(10), '0x0904D000341', 0) +Go +~~START~~ +binary +30783039303444303030 +~~END~~ + + +SELECT CONVERT(BINARY(5), 'Hello', 0) +Go +~~START~~ +binary +48656C6C6F +~~END~~ + + +-- padding +SELECT CONVERT(BINARY(20), 'Hello', 0) +Go +~~START~~ +binary +48656C6C6F000000000000000000000000000000 +~~END~~ + + +-- string with blank spaces +SELECT CONVERT(BINARY(10), 'Hello World', 0) +Go +~~START~~ +binary +48656C6C6F20576F726C +~~END~~ + + +-- special characters +SELECT CONVERT(BINARY(15), '0904D000341!@', 0) +Go +~~START~~ +binary +303930344430303033343121400000 +~~END~~ + + +-- empty string +SELECT CONVERT(BINARY(5), '', 0) +Go +~~START~~ +binary +0000000000 +~~END~~ + + + + + +-- 2. Testing style 1 (hexadecimal conversion with '0x' prefix): +-- even length string +SELECT CONVERT(BINARY(5), '0x0904D00034', 1); +Go +~~START~~ +binary +0904D00034 +~~END~~ + + +-- odd length string (should cause an error) +SELECT CONVERT(BINARY(10), '0x0904D000341', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- string without '0x' prefix (should cause an error) +SELECT CONVERT(BINARY(10), '0904D00034', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- string with '0x' prefix and odd length (should cause an error) +SELECT CONVERT(BINARY(10), '0x0904D000341', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- non-hexadecimal string (should cause an error) +SELECT CONVERT(BINARY(5), 'Hello', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- hexadecimal with padding +SELECT CONVERT(BINARY(20), '0x48656C6C6F', 1) +Go +~~START~~ +binary +48656C6C6F000000000000000000000000000000 +~~END~~ + + +-- special characters in hexadecimal (should cause an error) +SELECT CONVERT(BINARY(15), '0x0904D000341213440', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- non-hexadecimal characters after '0x' (should cause an error) +SELECT CONVERT(BINARY(16), '0x0904D000341!@', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- odd number of hexadecimal digits (should cause an error) +SELECT CONVERT(BINARY(5), '0x0904D0003', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- empty string (should cause an error) +SELECT CONVERT(BINARY(5), '', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + + + + +-- 3. Testing style 2 (hexadecimal conversion without '0x' prefix): +-- even length string +SELECT CONVERT(BINARY(5), '0904D00034', 2) +Go +~~START~~ +binary +0904D00034 +~~END~~ + + +-- odd length string (should cause an error) +SELECT CONVERT(BINARY(10), '0904D000341', 2) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: invalid hexadecimal data: odd number of digits)~~ + + +-- string with '0x' prefix (should cause an error) +SELECT CONVERT(BINARY(10), '0x0904D00034', 2) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- hexadecimal with padding +SELECT CONVERT(BINARY(20), '48656C6C6F', 2) +Go +~~START~~ +binary +48656C6C6F000000000000000000000000000000 +~~END~~ + + +-- non-hexadecimal characters (should cause an error) +SELECT CONVERT(BINARY(16), '0904D000341!@', 2) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: invalid hexadecimal digit: "!")~~ + + +-- empty string +SELECT CONVERT(BINARY(5), '', 2) +Go +~~START~~ +binary +0000000000 +~~END~~ + + +-- maximum length input (8000 bytes = 16000 hex digits) +SELECT CONVERT(BINARY(8000), REPLICATE('0', 16000), 2) +Go +~~START~~ +binary +0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +~~END~~ + + + + + +-- Testing null styles and empty strings +-- Style 0 (default, ASCII conversion) +-- Null input +SELECT CONVERT(BINARY(5), NULL, 0) +Go +~~START~~ +binary + +~~END~~ + + +-- Empty string +SELECT CONVERT(BINARY(5), '', 0) +Go +~~START~~ +binary +0000000000 +~~END~~ + + +-- Null style +SELECT CONVERT(BINARY(5), '0904D00034', NULL) +Go +~~START~~ +binary + +~~END~~ + + +-- Empty string with null style +SELECT CONVERT(BINARY(5), '', NULL) +Go +~~START~~ +binary + +~~END~~ + + + +-- Style 1 (hexadecimal conversion with '0x' prefix) +-- Null input +SELECT CONVERT(BINARY(5), NULL, 1) +Go +~~START~~ +binary + +~~END~~ + + +-- Empty string (should cause an error) +SELECT CONVERT(BINARY(5), '', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- Null style with '0x' prefix +SELECT CONVERT(BINARY(5), '0x0904D00034', NULL) +Go +~~START~~ +binary + +~~END~~ + + + +-- Style 2 (hexadecimal conversion without '0x' prefix) +-- Null input +SELECT CONVERT(BINARY(5), NULL, 2) +Go +~~START~~ +binary + +~~END~~ + + +-- Empty string +SELECT CONVERT(BINARY(5), '', 2) +Go +~~START~~ +binary +0000000000 +~~END~~ + + + +-- Additional edge cases +-- Null input with null style +SELECT CONVERT(BINARY(5), NULL, NULL) +Go +~~START~~ +binary + +~~END~~ + + +-- Empty string with large BINARY size +SELECT CONVERT(BINARY(8000), '', 0) +Go +~~START~~ +binary +0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +~~END~~ + + +-- Null input with large BINARY size +SELECT CONVERT(BINARY(8000), NULL, 0) +Go +~~START~~ +binary + +~~END~~ + + +-- Space-only string +SELECT CONVERT(BINARY(5), ' ', 0) +Go +~~START~~ +binary +2020202020 +~~END~~ + + +SELECT CONVERT(BINARY(5), ' ', 1) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +SELECT CONVERT(BINARY(5), ' ', 2) +Go +~~START~~ +binary +0000000000 +~~END~~ + + +-- Invalid style +SELECT CONVERT(BINARY(10), '0904D00034', 3); +Go +~~ERROR (Code: 9809)~~ + +~~ERROR (Message: The style 3 is not supported for conversions from varchar to varbinary.)~~ + + +-- Length greater than maximum allowed length (8000) +SELECT CONVERT(BINARY(8001), '0904D00034', 2) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The size '8001' exceeds the maximum allowed (8000) for 'binary' datatype.)~~ + + +-- Minimum length (1 byte) for BINARY +SELECT CONVERT(BINARY(1), 'A', 0); +Go +~~START~~ +binary +41 +~~END~~ + + +-- Minimum length (1 byte) for VARBINARY +SELECT CONVERT(VARBINARY(1), 'A', 0); +Go +~~START~~ +varbinary +41 +~~END~~ + + +-- Negative length for BINARY +SELECT CONVERT(BINARY(-5), '0904D00034', 0); +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: syntax error near '(' at line 2 and character position 21)~~ + + +-- Zero length for BINARY +SELECT CONVERT(BINARY(0), '0904D00034', 0); +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: length for type varbinary must be at least 1)~~ + + + + +-- Varbinary +-- 1. Testing style 0 (default, ASCII conversion): +-- even length string +SELECT CONVERT(VARBINARY(10), '0904D00034', 0); +Go +~~START~~ +varbinary +30393034443030303334 +~~END~~ + + +-- odd length string +SELECT CONVERT(VARBINARY(10), '0904D000341', 0); +Go +~~START~~ +varbinary +30393034443030303334 +~~END~~ + + +-- default style (should be equivalent to style 0) +SELECT CONVERT(VARBINARY(10), '0904D00034'); +Go +~~START~~ +varbinary +30393034443030303334 +~~END~~ + + +-- string with prefix '0x' and even length +SELECT CONVERT(VARBINARY(10), '0x0904D00034', 0); +Go +~~START~~ +varbinary +30783039303444303030 +~~END~~ + + +-- string with blank spaces +SELECT CONVERT(VARBINARY(15), 'Hello World', 0); +Go +~~START~~ +varbinary +48656C6C6F20576F726C64 +~~END~~ + + +-- special characters +SELECT CONVERT(VARBINARY(15), '0904D000341!@', 0); +Go +~~START~~ +varbinary +30393034443030303334312140 +~~END~~ + + +-- empty string +SELECT CONVERT(VARBINARY(5), '', 0); +Go +~~START~~ +varbinary + +~~END~~ + + + +-- 2. Testing style 1 (hexadecimal conversion with '0x' prefix): +-- even length string +SELECT CONVERT(VARBINARY(10), '0x0904D00034', 1); +Go +~~START~~ +varbinary +0904D00034 +~~END~~ + + +-- odd length string (should cause an error) +SELECT CONVERT(VARBINARY(10), '0x0904D000341', 1); +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- string without '0x' prefix (should cause an error) +SELECT CONVERT(VARBINARY(10), '0904D00034', 1); +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- non-hexadecimal string (should cause an error) +SELECT CONVERT(VARBINARY(10), '0xHello', 1); +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + + +-- 3. Testing style 2 (hexadecimal conversion without '0x' prefix): +-- even length string +SELECT CONVERT(VARBINARY(10), '0904D00034', 2); +Go +~~START~~ +varbinary +0904D00034 +~~END~~ + + +-- odd length string (should cause an error) +SELECT CONVERT(VARBINARY(10), '0904D000341', 2); +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: invalid hexadecimal data: odd number of digits)~~ + + +-- string with '0x' prefix (should cause an error) +SELECT CONVERT(VARBINARY(10), '0x0904D00034', 2); +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Error converting data type varchar to varbinary.)~~ + + +-- non-hexadecimal characters (should cause an error) +SELECT CONVERT(VARBINARY(16), '0904D000341!@', 2); +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: invalid hexadecimal digit: "!")~~ + + +-- empty string +SELECT CONVERT(VARBINARY(5), '', 2); +Go +~~START~~ +varbinary + +~~END~~ + + + +-- 4. Testing with larger sizes and edge cases: +-- maximum length input (8000 bytes = 16000 hex digits) +SELECT CONVERT(VARBINARY(8000), REPLICATE('0', 16000), 2); +Go +~~START~~ +varbinary +0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +~~END~~ + + +-- NULL input +SELECT CONVERT(VARBINARY(10), NULL, 0); +Go +~~START~~ +varbinary + +~~END~~ + + +SELECT CONVERT(VARBINARY(10), NULL, 1); +Go +~~START~~ +varbinary + +~~END~~ + + +SELECT CONVERT(VARBINARY(10), NULL, 2); +Go +~~START~~ +varbinary + +~~END~~ + + +-- NULL style +SELECT CONVERT(VARBINARY(10), '0904D00034', NULL); +Go +~~START~~ +varbinary + +~~END~~ + + +-- Invalid style +SELECT CONVERT(VARBINARY(10), '0904D00034', 3); +Go +~~ERROR (Code: 9809)~~ + +~~ERROR (Message: The style 3 is not supported for conversions from varchar to varbinary.)~~ + + +-- Length greater than maximum allowed length (8000) +SELECT CONVERT(VARBINARY(8001), '0904D00034', 2) +Go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The size '8001' exceeds the maximum allowed (8000) for 'varbinary' datatype.)~~ + diff --git a/test/JDBC/input/BABEL-2736-before-15_3-vu-cleanup.sql b/test/JDBC/input/BABEL-2736-before-15_3-vu-cleanup.sql new file mode 100644 index 0000000000..54696f5204 --- /dev/null +++ b/test/JDBC/input/BABEL-2736-before-15_3-vu-cleanup.sql @@ -0,0 +1,173 @@ +-- Drop views +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v1; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v2; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v3; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v4; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v5; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v6; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v7; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v8_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v9_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v10_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v11; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v12; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v13; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v14_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v15_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v16_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v17; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v18; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v19; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v20; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v21; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v22; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v23; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v24; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v26; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v27; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v28; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v29; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v30; +Go + +-- Drop procedures +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p1; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p2; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p3; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p4; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p5; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p6; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p7; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p8; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p9; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p10; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p11; +Go + +-- Drop functions +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f1; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f2; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f3; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f4; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f5; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f7; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f8; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f9; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f10; +Go +-- Drop test table +DROP TABLE IF EXISTS BABEL_BINARY_test_table1; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table2; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table3; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table4; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table_compcol; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table_compcol1; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table_compcol2; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table_compcol3; +GO diff --git a/test/JDBC/input/BABEL-2736-before-15_3-vu-prepare.sql b/test/JDBC/input/BABEL-2736-before-15_3-vu-prepare.sql new file mode 100644 index 0000000000..2820157517 --- /dev/null +++ b/test/JDBC/input/BABEL-2736-before-15_3-vu-prepare.sql @@ -0,0 +1,368 @@ +-- View to test binary conversion with style 0 (default) +CREATE VIEW BABEL_BINARY_vu_prepare_v1 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 0)); +GO + +-- Procedure to test binary conversion with style 0 (default) +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p1 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 0)); +GO + +-- Function to test binary conversion with style 0 (default) +CREATE FUNCTION BABEL_BINARY_vu_prepare_f1() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(10), '0904D00034', 0)); +END +GO + +-- View to test binary conversion with style 1 (with '0x' prefix) +CREATE VIEW BABEL_BINARY_vu_prepare_v2 AS +(SELECT CONVERT(BINARY(10), '0x0904D00034', 1)); +GO + +-- Procedure to test binary conversion with style 1 (with '0x' prefix) +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p2 AS +(SELECT CONVERT(BINARY(10), '0x0904D00034', 1)); +GO + +-- Function to test binary conversion with style 1 (with '0x' prefix) +CREATE FUNCTION BABEL_BINARY_vu_prepare_f2() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(10), '0x0904D00034', 1)); +END +GO + +-- View to test binary conversion with style 2 +CREATE VIEW BABEL_BINARY_vu_prepare_v3 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 2)); +GO + +-- Procedure to test binary conversion with style 2 +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p3 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 2)); +GO + +-- Function to test binary conversion with style 2 +CREATE FUNCTION BABEL_BINARY_vu_prepare_f3() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(10), '0904D00034', 2)); +END +GO + +-- View to test VARBINARY conversion +CREATE VIEW BABEL_BINARY_vu_prepare_v4 AS +(SELECT CONVERT(VARBINARY(10), '0904D00034', 0)); +GO + +-- Procedure to test VARBINARY conversion +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p4 AS +(SELECT CONVERT(VARBINARY(10), '0904D00034', 0)); +GO + +-- Function to test VARBINARY conversion +CREATE FUNCTION BABEL_BINARY_vu_prepare_f4() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(VARBINARY(10), '0904D00034', 0)); +END +GO + +-- Procedure to test invalid style (should cause an error) +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p5 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 3)); +GO + +-- Function to test NULL input +CREATE FUNCTION BABEL_BINARY_vu_prepare_f5() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(10), NULL, 0)); +END +GO + +-- Test case for CONVERT with a column reference +CREATE TABLE BABEL_BINARY_test_table1 (col1 VARCHAR(20)); +GO +INSERT INTO BABEL_BINARY_test_table1 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v5 AS +(SELECT CONVERT(BINARY(5), col1, 1) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v6 AS +(SELECT CONVERT(BINARY(5), col1, 0) FROM BABEL_BINARY_test_table1); +GO + +CREATE TABLE BABEL_BINARY_test_table2 (col1 VARCHAR(20)); +GO +INSERT INTO BABEL_BINARY_test_table2 (col1) VALUES ('1234ABCD'), ('787980'), ('1234'); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v7 AS +(SELECT CONVERT(BINARY(5), col1, 2) FROM BABEL_BINARY_test_table2); +GO + +-- Test case for TRY_CONVERT with a column reference +CREATE TABLE BABEL_BINARY_test_table3 (col1 VARCHAR(20)); +GO +INSERT INTO BABEL_BINARY_test_table3 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v8_try AS +(SELECT TRY_CONVERT(BINARY(5), col1, 1) FROM BABEL_BINARY_test_table3); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v9_try AS +(SELECT TRY_CONVERT(BINARY(5), col1, 0) FROM BABEL_BINARY_test_table3); +GO + +CREATE TABLE BABEL_BINARY_test_table4 (col1 VARCHAR(20)); +GO +INSERT INTO BABEL_BINARY_test_table4 (col1) VALUES ('1234ABCD'), ('787980'), ('1234'); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v10_try AS +(SELECT TRY_CONVERT(BINARY(5), col1, 2) FROM BABEL_BINARY_test_table4); +GO + + + +-- Test case for CONVERT with CAST with different styles +CREATE VIEW BABEL_BINARY_vu_prepare_v11 AS +(SELECT CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 1) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v12 AS +(SELECT CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 0) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v13 AS +(SELECT CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 2) FROM BABEL_BINARY_test_table1); +GO + +-- Test case for TRY_CONVERT with CAST with different styles +CREATE VIEW BABEL_BINARY_vu_prepare_v14_try AS +(SELECT TRY_CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 1) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v15_try AS +(SELECT TRY_CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 0) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v16_try AS +(SELECT TRY_CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 2) FROM BABEL_BINARY_test_table1); +GO + + +-- Test case for variable usage +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p6 AS +BEGIN + DECLARE @abc VARCHAR(30); + SET @abc = '0x1234ABCD'; + SELECT CONVERT(BINARY(5), @abc, 1); +END +GO + +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p7 AS +BEGIN + DECLARE @abc NVARCHAR(30); + SET @abc = '1234ABCD'; + SELECT CONVERT(BINARY(5), @abc, 0); +END +GO + +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p8 AS +BEGIN + DECLARE @abc CHAR(10); + SET @abc = '1234ABCD'; + SELECT CONVERT(BINARY(5), @abc, 2); +END +GO + +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p9 AS +BEGIN + DECLARE @abc VARCHAR(30); + SET @abc = '0x1234ABCD'; + SELECT TRY_CONVERT(BINARY(5), @abc, 1); +END +GO + +-- Using multiple variables and conversions +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p10 AS +BEGIN + DECLARE @abc VARCHAR(30), @def NVARCHAR(30); + SET @abc = '0x1234ABCD'; + SET @def = '5678EF'; + SELECT + CONVERT(BINARY(5), @abc, 1) AS ConvertResult, + TRY_CONVERT(BINARY(5), @def, 2) AS TryConvertResult; +END +GO + +-- Test case for UNION with different types +CREATE VIEW BABEL_BINARY_vu_prepare_v17 AS +SELECT CONVERT(BINARY(5), '0x1234', 1) +UNION ALL +SELECT CONVERT(BINARY(5), 12345, 0) +GO + +-- Using TRY_CONVERT +CREATE VIEW BABEL_BINARY_vu_prepare_v18 AS +SELECT TRY_CONVERT(BINARY(5), '0x1234', 1) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), 12345, 0) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), 'ABCDE', 2) +GO + +-- Using different output lengths +CREATE VIEW BABEL_BINARY_vu_prepare_v19 AS +SELECT CONVERT(BINARY(3), '0x1234', 1) +UNION ALL +SELECT CONVERT(BINARY(8), 12345, 0) +UNION ALL +SELECT CONVERT(BINARY(10), '0xABCDEF', 1) +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v20 AS +SELECT TRY_CONVERT(BINARY(3), '0x1234', 1) +UNION ALL +SELECT TRY_CONVERT(BINARY(8), 12345, 0) +UNION ALL +SELECT TRY_CONVERT(BINARY(10), '0xABCDEF', 1) +GO + +-- Using CAST and concatenation +CREATE VIEW BABEL_BINARY_vu_prepare_v21 AS +SELECT CONVERT(BINARY(5), CAST('0x' + '1234' AS VARCHAR(10)), 1) +UNION ALL +SELECT CONVERT(BINARY(5), CAST(123 + 45 AS VARCHAR(10)), 0) +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v22 AS +SELECT TRY_CONVERT(BINARY(5), CAST('0x' + '1234' AS VARCHAR(10)), 1) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), CAST(123 + 45 AS VARCHAR(10)), 0) +GO + +-- Using subqueries and constants +CREATE VIEW BABEL_BINARY_vu_prepare_v23 AS +SELECT CONVERT(BINARY(5), (SELECT '0x1234'), 1) +UNION ALL +SELECT CONVERT(BINARY(5), 0x1234, 0) +UNION ALL +SELECT CONVERT(BINARY(5), CHAR(65) + CHAR(66), 0) +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v24 AS +SELECT TRY_CONVERT(BINARY(5), (SELECT '0x1234'), 1) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), 0x1234, 0) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), CHAR(65) + CHAR(66), 0) +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v26 AS +SELECT TRY_CONVERT(BINARY(5), CAST('1234' AS NVARCHAR(10)), 2) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), CAST(12345 AS DECIMAL(10,2)), 0) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), LOWER('0xABCD'), 1) +GO + +-- Test case for CONVERT with NULL in different positions +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p11 AS +BEGIN + DECLARE @nullVar VARCHAR(10) = NULL; + SELECT + CONVERT(BINARY(5), NULL, 0) AS NullInput, + CONVERT(BINARY(5), '0x1234', NULL) AS NullStyle, + CONVERT(BINARY(5), @nullVar, 0) AS NullVariable; +END +GO + +-- Test case for CONVERT with decimal +CREATE FUNCTION BABEL_BINARY_vu_prepare_f7() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(5), 123.45, 0)); +END +GO + +CREATE FUNCTION BABEL_BINARY_vu_prepare_f8() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT TRY_CONVERT(BINARY(5), 123.45, 0)); +END +GO + +-- Test case for CONVERT with different styles +CREATE VIEW BABEL_BINARY_vu_prepare_v27 AS +SELECT + CONVERT(BINARY(5), '0x1234', 0) AS Style0, + CONVERT(BINARY(5), '0x1234', 1) AS Style1, + CONVERT(BINARY(5), '1234', 2) AS Style2; +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v28 AS +SELECT + TRY_CONVERT(BINARY(5), '0x1234', 0) AS Style0, + TRY_CONVERT(BINARY(5), '0x1234', 1) AS Style1, + TRY_CONVERT(BINARY(5), '1234', 2) AS Style2; +GO + +-- Test case for CONVERT with large binary and truncation +CREATE FUNCTION BABEL_BINARY_vu_prepare_f9() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(5), '0x123456789ABCDEF', 1)); +END +GO + +CREATE FUNCTION BABEL_BINARY_vu_prepare_f10() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT TRY_CONVERT(BINARY(5), '0x123456789ABCDEF', 1)); +END +GO + +-- Test case for CONVERT with different input types +CREATE VIEW BABEL_BINARY_vu_prepare_v29 AS +SELECT + CONVERT(BINARY(5), 12345, 0) AS IntInput, + CONVERT(BINARY(5), '2023-01-01', 0) AS DateInput, + CONVERT(BINARY(5), CAST('Hello, World!' AS NVARCHAR(20)), 0) AS NVarCharInput, + CONVERT(BINARY(5), CAST(0x1234ABCD AS VARBINARY(4)), 0) AS VarBinaryInput; +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v30 AS +SELECT + TRY_CONVERT(BINARY(5), 12345, 0) AS IntInput, + TRY_CONVERT(BINARY(5), '2023-01-01', 0) AS DateInput, + TRY_CONVERT(BINARY(5), CAST('Hello, World!' AS NVARCHAR(20)), 0) AS NVarCharInput, + TRY_CONVERT(BINARY(5), CAST(0x1234ABCD AS VARBINARY(4)), 0) AS VarBinaryInput; +GO + +CREATE TABLE BABEL_BINARY_test_table_compcol (col1 VARCHAR(20), col2 AS CONVERT(VARBINARY(20), col1)); +GO +INSERT INTO BABEL_BINARY_test_table_compcol (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO + +CREATE TABLE BABEL_BINARY_test_table_compcol1 (col1 VARCHAR(20), col2 AS TRY_CONVERT(VARBINARY(20), col1)); +GO +INSERT INTO BABEL_BINARY_test_table_compcol1 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO + +CREATE TABLE BABEL_BINARY_test_table_compcol2 (col1 VARCHAR(20), col2 AS CONVERT(VARBINARY(20), col1, 1)); +GO +INSERT INTO BABEL_BINARY_test_table_compcol2 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO + +CREATE TABLE BABEL_BINARY_test_table_compcol3 (col1 VARCHAR(20), col2 AS TRY_CONVERT(VARBINARY(20), col1, 1)); +GO +INSERT INTO BABEL_BINARY_test_table_compcol3 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO diff --git a/test/JDBC/input/BABEL-2736-before-15_3-vu-verify.sql b/test/JDBC/input/BABEL-2736-before-15_3-vu-verify.sql new file mode 100644 index 0000000000..6f811b0a30 --- /dev/null +++ b/test/JDBC/input/BABEL-2736-before-15_3-vu-verify.sql @@ -0,0 +1,585 @@ +-- Test view v1 (style 0) +SELECT * FROM BABEL_BINARY_vu_prepare_v1 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v1 +GO + +-- Test procedure p1 (style 0) +EXEC BABEL_BINARY_vu_prepare_p1 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p1 +GO + +-- Test function f1 (style 0) +SELECT dbo.BABEL_BINARY_vu_prepare_f1() +GO +DROP FUNCTION BABEL_BINARY_vu_prepare_f1 +GO + +-- Test view v2 (style 1) +SELECT * FROM BABEL_BINARY_vu_prepare_v2 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v2 +GO + +-- Test procedure p2 (style 1) +EXEC BABEL_BINARY_vu_prepare_p2 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p2 +GO + +-- Test function f2 (style 1) +SELECT dbo.BABEL_BINARY_vu_prepare_f2() +GO +DROP FUNCTION BABEL_BINARY_vu_prepare_f2 +GO + +-- Test view v3 (style 2) +SELECT * FROM BABEL_BINARY_vu_prepare_v3 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v3 +GO + +-- Test procedure p3 (style 2) +EXEC BABEL_BINARY_vu_prepare_p3 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p3 +GO + +-- Test function f3 (style 2) +SELECT dbo.BABEL_BINARY_vu_prepare_f3() +GO +DROP FUNCTION BABEL_BINARY_vu_prepare_f3 +GO + +-- Test view v4 (VARBINARY) +SELECT * FROM BABEL_BINARY_vu_prepare_v4 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v4 +GO + +-- Test procedure p4 (VARBINARY) +EXEC BABEL_BINARY_vu_prepare_p4 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p4 +GO + +-- Test function f4 (VARBINARY) +SELECT dbo.BABEL_BINARY_vu_prepare_f4() +GO +DROP FUNCTION BABEL_BINARY_vu_prepare_f4 +GO + +-- Test procedure p5 (invalid style - should cause an error) +EXEC BABEL_BINARY_vu_prepare_p5 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p5 +GO + +-- Test function f5 (NULL input) +SELECT dbo.BABEL_BINARY_vu_prepare_f5() +GO +DROP FUNCTION BABEL_BINARY_vu_prepare_f5 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v5 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v5 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v6 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v6 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v7 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v7 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v8_try +GO +DROP VIEW BABEL_BINARY_vu_prepare_v8_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v9_try +GO +DROP VIEW BABEL_BINARY_vu_prepare_v9_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v10_try +GO +DROP VIEW BABEL_BINARY_vu_prepare_v10_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v11 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v11 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v12 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v12 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v13 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v13 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v14_try +GO +DROP VIEW BABEL_BINARY_vu_prepare_v14_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v15_try +GO +DROP VIEW BABEL_BINARY_vu_prepare_v15_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v16_try +GO +DROP VIEW BABEL_BINARY_vu_prepare_v16_try +GO + +EXEC BABEL_BINARY_vu_prepare_p6 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p6 +GO + +EXEC BABEL_BINARY_vu_prepare_p7 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p7 +GO + +EXEC BABEL_BINARY_vu_prepare_p8 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p8 +GO + +EXEC BABEL_BINARY_vu_prepare_p9 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p9 +GO + +EXEC BABEL_BINARY_vu_prepare_p10 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p10 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v17 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v17 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v18 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v18 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v19 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v19 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v20 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v20 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v21 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v21 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v22 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v22 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v23 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v23 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v24 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v24 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v26 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v26 +GO + +EXEC BABEL_BINARY_vu_prepare_p11 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p11 +GO + +SELECT dbo.BABEL_BINARY_vu_prepare_f7() +DROP FUNCTION BABEL_BINARY_vu_prepare_f7 +GO + +SELECT dbo.BABEL_BINARY_vu_prepare_f8() +DROP FUNCTION BABEL_BINARY_vu_prepare_f8 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v27 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v27 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v28 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v28 +GO + +SELECT dbo.BABEL_BINARY_vu_prepare_f9() +DROP FUNCTION BABEL_BINARY_vu_prepare_f9 +GO + +SELECT dbo.BABEL_BINARY_vu_prepare_f10() +DROP FUNCTION BABEL_BINARY_vu_prepare_f10 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v29 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v29 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v30 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v30 +GO + +SELECT * FROM BABEL_BINARY_test_table_compcol +GO +DROP TABLE BABEL_BINARY_test_table_compcol +GO + +SELECT * FROM BABEL_BINARY_test_table_compcol1 +GO +DROP TABLE BABEL_BINARY_test_table_compcol1 +GO + +SELECT * FROM BABEL_BINARY_test_table_compcol2 +GO +DROP TABLE BABEL_BINARY_test_table_compcol2 +GO + +SELECT * FROM BABEL_BINARY_test_table_compcol3 +GO +DROP TABLE BABEL_BINARY_test_table_compcol3 +GO + +-- Additional test cases +-- 1. Testing style 0 (default, ASCII conversion): + +-- even length string +SELECT CONVERT(BINARY(5), '0904D00034', 0) +Go + +-- odd length string +SELECT CONVERT(BINARY(10), '0904D000341', 0) +Go + +-- default style selected as 0 +SELECT CONVERT(BINARY(5), '0904D00034') +Go + +-- string with prefix '0x' and even length +SELECT CONVERT(BINARY(10), '0x0904D00034', 0) +Go + +-- string with prefix '0x' and odd length +SELECT CONVERT(BINARY(10), '0x0904D000341', 0) +Go + +SELECT CONVERT(BINARY(5), 'Hello', 0) +Go + +-- padding +SELECT CONVERT(BINARY(20), 'Hello', 0) +Go + +-- string with blank spaces +SELECT CONVERT(BINARY(10), 'Hello World', 0) +Go + +-- special characters +SELECT CONVERT(BINARY(15), '0904D000341!@', 0) +Go + +-- empty string +SELECT CONVERT(BINARY(5), '', 0) +Go + + +-- 2. Testing style 1 (hexadecimal conversion with '0x' prefix): + + +-- even length string +SELECT CONVERT(BINARY(5), '0x0904D00034', 1); +Go + +-- odd length string (should cause an error) +SELECT CONVERT(BINARY(10), '0x0904D000341', 1) +Go + +-- string without '0x' prefix (should cause an error) +SELECT CONVERT(BINARY(10), '0904D00034', 1) +Go + +-- string with '0x' prefix and odd length (should cause an error) +SELECT CONVERT(BINARY(10), '0x0904D000341', 1) +Go + +-- non-hexadecimal string (should cause an error) +SELECT CONVERT(BINARY(5), 'Hello', 1) +Go + +-- hexadecimal with padding +SELECT CONVERT(BINARY(20), '0x48656C6C6F', 1) +Go + +-- special characters in hexadecimal (should cause an error) +SELECT CONVERT(BINARY(15), '0x0904D000341213440', 1) +Go + +-- non-hexadecimal characters after '0x' (should cause an error) +SELECT CONVERT(BINARY(16), '0x0904D000341!@', 1) +Go + +-- odd number of hexadecimal digits (should cause an error) +SELECT CONVERT(BINARY(5), '0x0904D0003', 1) +Go + +-- empty string (should cause an error) +SELECT CONVERT(BINARY(5), '', 1) +Go + + +-- 3. Testing style 2 (hexadecimal conversion without '0x' prefix): + + +-- even length string +SELECT CONVERT(BINARY(5), '0904D00034', 2) +Go + +-- odd length string (should cause an error) +SELECT CONVERT(BINARY(10), '0904D000341', 2) +Go + +-- string with '0x' prefix (should cause an error) +SELECT CONVERT(BINARY(10), '0x0904D00034', 2) +Go + +-- hexadecimal with padding +SELECT CONVERT(BINARY(20), '48656C6C6F', 2) +Go + +-- non-hexadecimal characters (should cause an error) +SELECT CONVERT(BINARY(16), '0904D000341!@', 2) +Go + +-- empty string +SELECT CONVERT(BINARY(5), '', 2) +Go + +-- maximum length input (8000 bytes = 16000 hex digits) +SELECT CONVERT(BINARY(8000), REPLICATE('0', 16000), 2) +Go + + +-- Testing null styles and empty strings + +-- Style 0 (default, ASCII conversion) + +-- Null input +SELECT CONVERT(BINARY(5), NULL, 0) +Go + +-- Empty string +SELECT CONVERT(BINARY(5), '', 0) +Go + +-- Null style +SELECT CONVERT(BINARY(5), '0904D00034', NULL) +Go + +-- Empty string with null style +SELECT CONVERT(BINARY(5), '', NULL) +Go + +-- Style 1 (hexadecimal conversion with '0x' prefix) + +-- Null input +SELECT CONVERT(BINARY(5), NULL, 1) +Go + +-- Empty string (should cause an error) +SELECT CONVERT(BINARY(5), '', 1) +Go + +-- Null style with '0x' prefix +SELECT CONVERT(BINARY(5), '0x0904D00034', NULL) +Go + +-- Style 2 (hexadecimal conversion without '0x' prefix) + +-- Null input +SELECT CONVERT(BINARY(5), NULL, 2) +Go + +-- Empty string +SELECT CONVERT(BINARY(5), '', 2) +Go + +-- Additional edge cases + +-- Null input with null style +SELECT CONVERT(BINARY(5), NULL, NULL) +Go + +-- Empty string with large BINARY size +SELECT CONVERT(BINARY(8000), '', 0) +Go + +-- Null input with large BINARY size +SELECT CONVERT(BINARY(8000), NULL, 0) +Go + +-- Space-only string +SELECT CONVERT(BINARY(5), ' ', 0) +Go + +SELECT CONVERT(BINARY(5), ' ', 1) +Go + +SELECT CONVERT(BINARY(5), ' ', 2) +Go + +-- Invalid style +SELECT CONVERT(BINARY(10), '0904D00034', 3); +Go + +-- Length greater than maximum allowed length (8000) +SELECT CONVERT(BINARY(8001), '0904D00034', 2) +Go + +-- Minimum length (1 byte) for BINARY +SELECT CONVERT(BINARY(1), 'A', 0); +Go + +-- Minimum length (1 byte) for VARBINARY +SELECT CONVERT(VARBINARY(1), 'A', 0); +Go + +-- Negative length for BINARY +SELECT CONVERT(BINARY(-5), '0904D00034', 0); +Go + +-- Zero length for BINARY +SELECT CONVERT(BINARY(0), '0904D00034', 0); +Go + +-- Varbinary + +-- 1. Testing style 0 (default, ASCII conversion): + +-- even length string +SELECT CONVERT(VARBINARY(10), '0904D00034', 0); +Go + +-- odd length string +SELECT CONVERT(VARBINARY(10), '0904D000341', 0); +Go + +-- default style (should be equivalent to style 0) +SELECT CONVERT(VARBINARY(10), '0904D00034'); +Go + +-- string with prefix '0x' and even length +SELECT CONVERT(VARBINARY(10), '0x0904D00034', 0); +Go + +-- string with blank spaces +SELECT CONVERT(VARBINARY(15), 'Hello World', 0); +Go + +-- special characters +SELECT CONVERT(VARBINARY(15), '0904D000341!@', 0); +Go + +-- empty string +SELECT CONVERT(VARBINARY(5), '', 0); +Go + +-- 2. Testing style 1 (hexadecimal conversion with '0x' prefix): + +-- even length string +SELECT CONVERT(VARBINARY(10), '0x0904D00034', 1); +Go + +-- odd length string (should cause an error) +SELECT CONVERT(VARBINARY(10), '0x0904D000341', 1); +Go + +-- string without '0x' prefix (should cause an error) +SELECT CONVERT(VARBINARY(10), '0904D00034', 1); +Go + +-- non-hexadecimal string (should cause an error) +SELECT CONVERT(VARBINARY(10), '0xHello', 1); +Go + +-- 3. Testing style 2 (hexadecimal conversion without '0x' prefix): + +-- even length string +SELECT CONVERT(VARBINARY(10), '0904D00034', 2); +Go + +-- odd length string (should cause an error) +SELECT CONVERT(VARBINARY(10), '0904D000341', 2); +Go + +-- string with '0x' prefix (should cause an error) +SELECT CONVERT(VARBINARY(10), '0x0904D00034', 2); +Go + +-- non-hexadecimal characters (should cause an error) +SELECT CONVERT(VARBINARY(16), '0904D000341!@', 2); +Go + +-- empty string +SELECT CONVERT(VARBINARY(5), '', 2); +Go + +-- 4. Testing with larger sizes and edge cases: + +-- maximum length input (8000 bytes = 16000 hex digits) +SELECT CONVERT(VARBINARY(8000), REPLICATE('0', 16000), 2); +Go + +-- NULL input +SELECT CONVERT(VARBINARY(10), NULL, 0); +Go + +SELECT CONVERT(VARBINARY(10), NULL, 1); +Go + +SELECT CONVERT(VARBINARY(10), NULL, 2); +Go + +-- NULL style +SELECT CONVERT(VARBINARY(10), '0904D00034', NULL); +Go + +-- Invalid style +SELECT CONVERT(VARBINARY(10), '0904D00034', 3); +Go + +-- Length greater than maximum allowed length (8000) +SELECT CONVERT(VARBINARY(8001), '0904D00034', 2) +Go diff --git a/test/JDBC/input/BABEL-2736-before-16_5-vu-cleanup.sql b/test/JDBC/input/BABEL-2736-before-16_5-vu-cleanup.sql new file mode 100644 index 0000000000..54696f5204 --- /dev/null +++ b/test/JDBC/input/BABEL-2736-before-16_5-vu-cleanup.sql @@ -0,0 +1,173 @@ +-- Drop views +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v1; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v2; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v3; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v4; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v5; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v6; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v7; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v8_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v9_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v10_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v11; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v12; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v13; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v14_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v15_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v16_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v17; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v18; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v19; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v20; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v21; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v22; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v23; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v24; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v26; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v27; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v28; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v29; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v30; +Go + +-- Drop procedures +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p1; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p2; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p3; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p4; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p5; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p6; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p7; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p8; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p9; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p10; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p11; +Go + +-- Drop functions +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f1; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f2; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f3; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f4; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f5; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f7; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f8; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f9; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f10; +Go +-- Drop test table +DROP TABLE IF EXISTS BABEL_BINARY_test_table1; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table2; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table3; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table4; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table_compcol; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table_compcol1; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table_compcol2; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table_compcol3; +GO diff --git a/test/JDBC/input/BABEL-2736-before-16_5-vu-prepare.sql b/test/JDBC/input/BABEL-2736-before-16_5-vu-prepare.sql new file mode 100644 index 0000000000..2820157517 --- /dev/null +++ b/test/JDBC/input/BABEL-2736-before-16_5-vu-prepare.sql @@ -0,0 +1,368 @@ +-- View to test binary conversion with style 0 (default) +CREATE VIEW BABEL_BINARY_vu_prepare_v1 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 0)); +GO + +-- Procedure to test binary conversion with style 0 (default) +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p1 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 0)); +GO + +-- Function to test binary conversion with style 0 (default) +CREATE FUNCTION BABEL_BINARY_vu_prepare_f1() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(10), '0904D00034', 0)); +END +GO + +-- View to test binary conversion with style 1 (with '0x' prefix) +CREATE VIEW BABEL_BINARY_vu_prepare_v2 AS +(SELECT CONVERT(BINARY(10), '0x0904D00034', 1)); +GO + +-- Procedure to test binary conversion with style 1 (with '0x' prefix) +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p2 AS +(SELECT CONVERT(BINARY(10), '0x0904D00034', 1)); +GO + +-- Function to test binary conversion with style 1 (with '0x' prefix) +CREATE FUNCTION BABEL_BINARY_vu_prepare_f2() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(10), '0x0904D00034', 1)); +END +GO + +-- View to test binary conversion with style 2 +CREATE VIEW BABEL_BINARY_vu_prepare_v3 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 2)); +GO + +-- Procedure to test binary conversion with style 2 +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p3 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 2)); +GO + +-- Function to test binary conversion with style 2 +CREATE FUNCTION BABEL_BINARY_vu_prepare_f3() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(10), '0904D00034', 2)); +END +GO + +-- View to test VARBINARY conversion +CREATE VIEW BABEL_BINARY_vu_prepare_v4 AS +(SELECT CONVERT(VARBINARY(10), '0904D00034', 0)); +GO + +-- Procedure to test VARBINARY conversion +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p4 AS +(SELECT CONVERT(VARBINARY(10), '0904D00034', 0)); +GO + +-- Function to test VARBINARY conversion +CREATE FUNCTION BABEL_BINARY_vu_prepare_f4() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(VARBINARY(10), '0904D00034', 0)); +END +GO + +-- Procedure to test invalid style (should cause an error) +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p5 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 3)); +GO + +-- Function to test NULL input +CREATE FUNCTION BABEL_BINARY_vu_prepare_f5() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(10), NULL, 0)); +END +GO + +-- Test case for CONVERT with a column reference +CREATE TABLE BABEL_BINARY_test_table1 (col1 VARCHAR(20)); +GO +INSERT INTO BABEL_BINARY_test_table1 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v5 AS +(SELECT CONVERT(BINARY(5), col1, 1) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v6 AS +(SELECT CONVERT(BINARY(5), col1, 0) FROM BABEL_BINARY_test_table1); +GO + +CREATE TABLE BABEL_BINARY_test_table2 (col1 VARCHAR(20)); +GO +INSERT INTO BABEL_BINARY_test_table2 (col1) VALUES ('1234ABCD'), ('787980'), ('1234'); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v7 AS +(SELECT CONVERT(BINARY(5), col1, 2) FROM BABEL_BINARY_test_table2); +GO + +-- Test case for TRY_CONVERT with a column reference +CREATE TABLE BABEL_BINARY_test_table3 (col1 VARCHAR(20)); +GO +INSERT INTO BABEL_BINARY_test_table3 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v8_try AS +(SELECT TRY_CONVERT(BINARY(5), col1, 1) FROM BABEL_BINARY_test_table3); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v9_try AS +(SELECT TRY_CONVERT(BINARY(5), col1, 0) FROM BABEL_BINARY_test_table3); +GO + +CREATE TABLE BABEL_BINARY_test_table4 (col1 VARCHAR(20)); +GO +INSERT INTO BABEL_BINARY_test_table4 (col1) VALUES ('1234ABCD'), ('787980'), ('1234'); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v10_try AS +(SELECT TRY_CONVERT(BINARY(5), col1, 2) FROM BABEL_BINARY_test_table4); +GO + + + +-- Test case for CONVERT with CAST with different styles +CREATE VIEW BABEL_BINARY_vu_prepare_v11 AS +(SELECT CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 1) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v12 AS +(SELECT CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 0) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v13 AS +(SELECT CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 2) FROM BABEL_BINARY_test_table1); +GO + +-- Test case for TRY_CONVERT with CAST with different styles +CREATE VIEW BABEL_BINARY_vu_prepare_v14_try AS +(SELECT TRY_CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 1) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v15_try AS +(SELECT TRY_CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 0) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v16_try AS +(SELECT TRY_CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 2) FROM BABEL_BINARY_test_table1); +GO + + +-- Test case for variable usage +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p6 AS +BEGIN + DECLARE @abc VARCHAR(30); + SET @abc = '0x1234ABCD'; + SELECT CONVERT(BINARY(5), @abc, 1); +END +GO + +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p7 AS +BEGIN + DECLARE @abc NVARCHAR(30); + SET @abc = '1234ABCD'; + SELECT CONVERT(BINARY(5), @abc, 0); +END +GO + +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p8 AS +BEGIN + DECLARE @abc CHAR(10); + SET @abc = '1234ABCD'; + SELECT CONVERT(BINARY(5), @abc, 2); +END +GO + +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p9 AS +BEGIN + DECLARE @abc VARCHAR(30); + SET @abc = '0x1234ABCD'; + SELECT TRY_CONVERT(BINARY(5), @abc, 1); +END +GO + +-- Using multiple variables and conversions +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p10 AS +BEGIN + DECLARE @abc VARCHAR(30), @def NVARCHAR(30); + SET @abc = '0x1234ABCD'; + SET @def = '5678EF'; + SELECT + CONVERT(BINARY(5), @abc, 1) AS ConvertResult, + TRY_CONVERT(BINARY(5), @def, 2) AS TryConvertResult; +END +GO + +-- Test case for UNION with different types +CREATE VIEW BABEL_BINARY_vu_prepare_v17 AS +SELECT CONVERT(BINARY(5), '0x1234', 1) +UNION ALL +SELECT CONVERT(BINARY(5), 12345, 0) +GO + +-- Using TRY_CONVERT +CREATE VIEW BABEL_BINARY_vu_prepare_v18 AS +SELECT TRY_CONVERT(BINARY(5), '0x1234', 1) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), 12345, 0) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), 'ABCDE', 2) +GO + +-- Using different output lengths +CREATE VIEW BABEL_BINARY_vu_prepare_v19 AS +SELECT CONVERT(BINARY(3), '0x1234', 1) +UNION ALL +SELECT CONVERT(BINARY(8), 12345, 0) +UNION ALL +SELECT CONVERT(BINARY(10), '0xABCDEF', 1) +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v20 AS +SELECT TRY_CONVERT(BINARY(3), '0x1234', 1) +UNION ALL +SELECT TRY_CONVERT(BINARY(8), 12345, 0) +UNION ALL +SELECT TRY_CONVERT(BINARY(10), '0xABCDEF', 1) +GO + +-- Using CAST and concatenation +CREATE VIEW BABEL_BINARY_vu_prepare_v21 AS +SELECT CONVERT(BINARY(5), CAST('0x' + '1234' AS VARCHAR(10)), 1) +UNION ALL +SELECT CONVERT(BINARY(5), CAST(123 + 45 AS VARCHAR(10)), 0) +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v22 AS +SELECT TRY_CONVERT(BINARY(5), CAST('0x' + '1234' AS VARCHAR(10)), 1) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), CAST(123 + 45 AS VARCHAR(10)), 0) +GO + +-- Using subqueries and constants +CREATE VIEW BABEL_BINARY_vu_prepare_v23 AS +SELECT CONVERT(BINARY(5), (SELECT '0x1234'), 1) +UNION ALL +SELECT CONVERT(BINARY(5), 0x1234, 0) +UNION ALL +SELECT CONVERT(BINARY(5), CHAR(65) + CHAR(66), 0) +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v24 AS +SELECT TRY_CONVERT(BINARY(5), (SELECT '0x1234'), 1) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), 0x1234, 0) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), CHAR(65) + CHAR(66), 0) +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v26 AS +SELECT TRY_CONVERT(BINARY(5), CAST('1234' AS NVARCHAR(10)), 2) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), CAST(12345 AS DECIMAL(10,2)), 0) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), LOWER('0xABCD'), 1) +GO + +-- Test case for CONVERT with NULL in different positions +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p11 AS +BEGIN + DECLARE @nullVar VARCHAR(10) = NULL; + SELECT + CONVERT(BINARY(5), NULL, 0) AS NullInput, + CONVERT(BINARY(5), '0x1234', NULL) AS NullStyle, + CONVERT(BINARY(5), @nullVar, 0) AS NullVariable; +END +GO + +-- Test case for CONVERT with decimal +CREATE FUNCTION BABEL_BINARY_vu_prepare_f7() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(5), 123.45, 0)); +END +GO + +CREATE FUNCTION BABEL_BINARY_vu_prepare_f8() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT TRY_CONVERT(BINARY(5), 123.45, 0)); +END +GO + +-- Test case for CONVERT with different styles +CREATE VIEW BABEL_BINARY_vu_prepare_v27 AS +SELECT + CONVERT(BINARY(5), '0x1234', 0) AS Style0, + CONVERT(BINARY(5), '0x1234', 1) AS Style1, + CONVERT(BINARY(5), '1234', 2) AS Style2; +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v28 AS +SELECT + TRY_CONVERT(BINARY(5), '0x1234', 0) AS Style0, + TRY_CONVERT(BINARY(5), '0x1234', 1) AS Style1, + TRY_CONVERT(BINARY(5), '1234', 2) AS Style2; +GO + +-- Test case for CONVERT with large binary and truncation +CREATE FUNCTION BABEL_BINARY_vu_prepare_f9() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(5), '0x123456789ABCDEF', 1)); +END +GO + +CREATE FUNCTION BABEL_BINARY_vu_prepare_f10() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT TRY_CONVERT(BINARY(5), '0x123456789ABCDEF', 1)); +END +GO + +-- Test case for CONVERT with different input types +CREATE VIEW BABEL_BINARY_vu_prepare_v29 AS +SELECT + CONVERT(BINARY(5), 12345, 0) AS IntInput, + CONVERT(BINARY(5), '2023-01-01', 0) AS DateInput, + CONVERT(BINARY(5), CAST('Hello, World!' AS NVARCHAR(20)), 0) AS NVarCharInput, + CONVERT(BINARY(5), CAST(0x1234ABCD AS VARBINARY(4)), 0) AS VarBinaryInput; +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v30 AS +SELECT + TRY_CONVERT(BINARY(5), 12345, 0) AS IntInput, + TRY_CONVERT(BINARY(5), '2023-01-01', 0) AS DateInput, + TRY_CONVERT(BINARY(5), CAST('Hello, World!' AS NVARCHAR(20)), 0) AS NVarCharInput, + TRY_CONVERT(BINARY(5), CAST(0x1234ABCD AS VARBINARY(4)), 0) AS VarBinaryInput; +GO + +CREATE TABLE BABEL_BINARY_test_table_compcol (col1 VARCHAR(20), col2 AS CONVERT(VARBINARY(20), col1)); +GO +INSERT INTO BABEL_BINARY_test_table_compcol (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO + +CREATE TABLE BABEL_BINARY_test_table_compcol1 (col1 VARCHAR(20), col2 AS TRY_CONVERT(VARBINARY(20), col1)); +GO +INSERT INTO BABEL_BINARY_test_table_compcol1 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO + +CREATE TABLE BABEL_BINARY_test_table_compcol2 (col1 VARCHAR(20), col2 AS CONVERT(VARBINARY(20), col1, 1)); +GO +INSERT INTO BABEL_BINARY_test_table_compcol2 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO + +CREATE TABLE BABEL_BINARY_test_table_compcol3 (col1 VARCHAR(20), col2 AS TRY_CONVERT(VARBINARY(20), col1, 1)); +GO +INSERT INTO BABEL_BINARY_test_table_compcol3 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO diff --git a/test/JDBC/input/BABEL-2736-before-16_5-vu-verify.sql b/test/JDBC/input/BABEL-2736-before-16_5-vu-verify.sql new file mode 100644 index 0000000000..6f811b0a30 --- /dev/null +++ b/test/JDBC/input/BABEL-2736-before-16_5-vu-verify.sql @@ -0,0 +1,585 @@ +-- Test view v1 (style 0) +SELECT * FROM BABEL_BINARY_vu_prepare_v1 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v1 +GO + +-- Test procedure p1 (style 0) +EXEC BABEL_BINARY_vu_prepare_p1 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p1 +GO + +-- Test function f1 (style 0) +SELECT dbo.BABEL_BINARY_vu_prepare_f1() +GO +DROP FUNCTION BABEL_BINARY_vu_prepare_f1 +GO + +-- Test view v2 (style 1) +SELECT * FROM BABEL_BINARY_vu_prepare_v2 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v2 +GO + +-- Test procedure p2 (style 1) +EXEC BABEL_BINARY_vu_prepare_p2 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p2 +GO + +-- Test function f2 (style 1) +SELECT dbo.BABEL_BINARY_vu_prepare_f2() +GO +DROP FUNCTION BABEL_BINARY_vu_prepare_f2 +GO + +-- Test view v3 (style 2) +SELECT * FROM BABEL_BINARY_vu_prepare_v3 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v3 +GO + +-- Test procedure p3 (style 2) +EXEC BABEL_BINARY_vu_prepare_p3 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p3 +GO + +-- Test function f3 (style 2) +SELECT dbo.BABEL_BINARY_vu_prepare_f3() +GO +DROP FUNCTION BABEL_BINARY_vu_prepare_f3 +GO + +-- Test view v4 (VARBINARY) +SELECT * FROM BABEL_BINARY_vu_prepare_v4 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v4 +GO + +-- Test procedure p4 (VARBINARY) +EXEC BABEL_BINARY_vu_prepare_p4 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p4 +GO + +-- Test function f4 (VARBINARY) +SELECT dbo.BABEL_BINARY_vu_prepare_f4() +GO +DROP FUNCTION BABEL_BINARY_vu_prepare_f4 +GO + +-- Test procedure p5 (invalid style - should cause an error) +EXEC BABEL_BINARY_vu_prepare_p5 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p5 +GO + +-- Test function f5 (NULL input) +SELECT dbo.BABEL_BINARY_vu_prepare_f5() +GO +DROP FUNCTION BABEL_BINARY_vu_prepare_f5 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v5 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v5 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v6 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v6 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v7 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v7 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v8_try +GO +DROP VIEW BABEL_BINARY_vu_prepare_v8_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v9_try +GO +DROP VIEW BABEL_BINARY_vu_prepare_v9_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v10_try +GO +DROP VIEW BABEL_BINARY_vu_prepare_v10_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v11 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v11 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v12 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v12 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v13 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v13 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v14_try +GO +DROP VIEW BABEL_BINARY_vu_prepare_v14_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v15_try +GO +DROP VIEW BABEL_BINARY_vu_prepare_v15_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v16_try +GO +DROP VIEW BABEL_BINARY_vu_prepare_v16_try +GO + +EXEC BABEL_BINARY_vu_prepare_p6 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p6 +GO + +EXEC BABEL_BINARY_vu_prepare_p7 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p7 +GO + +EXEC BABEL_BINARY_vu_prepare_p8 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p8 +GO + +EXEC BABEL_BINARY_vu_prepare_p9 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p9 +GO + +EXEC BABEL_BINARY_vu_prepare_p10 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p10 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v17 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v17 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v18 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v18 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v19 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v19 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v20 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v20 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v21 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v21 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v22 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v22 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v23 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v23 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v24 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v24 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v26 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v26 +GO + +EXEC BABEL_BINARY_vu_prepare_p11 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p11 +GO + +SELECT dbo.BABEL_BINARY_vu_prepare_f7() +DROP FUNCTION BABEL_BINARY_vu_prepare_f7 +GO + +SELECT dbo.BABEL_BINARY_vu_prepare_f8() +DROP FUNCTION BABEL_BINARY_vu_prepare_f8 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v27 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v27 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v28 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v28 +GO + +SELECT dbo.BABEL_BINARY_vu_prepare_f9() +DROP FUNCTION BABEL_BINARY_vu_prepare_f9 +GO + +SELECT dbo.BABEL_BINARY_vu_prepare_f10() +DROP FUNCTION BABEL_BINARY_vu_prepare_f10 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v29 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v29 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v30 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v30 +GO + +SELECT * FROM BABEL_BINARY_test_table_compcol +GO +DROP TABLE BABEL_BINARY_test_table_compcol +GO + +SELECT * FROM BABEL_BINARY_test_table_compcol1 +GO +DROP TABLE BABEL_BINARY_test_table_compcol1 +GO + +SELECT * FROM BABEL_BINARY_test_table_compcol2 +GO +DROP TABLE BABEL_BINARY_test_table_compcol2 +GO + +SELECT * FROM BABEL_BINARY_test_table_compcol3 +GO +DROP TABLE BABEL_BINARY_test_table_compcol3 +GO + +-- Additional test cases +-- 1. Testing style 0 (default, ASCII conversion): + +-- even length string +SELECT CONVERT(BINARY(5), '0904D00034', 0) +Go + +-- odd length string +SELECT CONVERT(BINARY(10), '0904D000341', 0) +Go + +-- default style selected as 0 +SELECT CONVERT(BINARY(5), '0904D00034') +Go + +-- string with prefix '0x' and even length +SELECT CONVERT(BINARY(10), '0x0904D00034', 0) +Go + +-- string with prefix '0x' and odd length +SELECT CONVERT(BINARY(10), '0x0904D000341', 0) +Go + +SELECT CONVERT(BINARY(5), 'Hello', 0) +Go + +-- padding +SELECT CONVERT(BINARY(20), 'Hello', 0) +Go + +-- string with blank spaces +SELECT CONVERT(BINARY(10), 'Hello World', 0) +Go + +-- special characters +SELECT CONVERT(BINARY(15), '0904D000341!@', 0) +Go + +-- empty string +SELECT CONVERT(BINARY(5), '', 0) +Go + + +-- 2. Testing style 1 (hexadecimal conversion with '0x' prefix): + + +-- even length string +SELECT CONVERT(BINARY(5), '0x0904D00034', 1); +Go + +-- odd length string (should cause an error) +SELECT CONVERT(BINARY(10), '0x0904D000341', 1) +Go + +-- string without '0x' prefix (should cause an error) +SELECT CONVERT(BINARY(10), '0904D00034', 1) +Go + +-- string with '0x' prefix and odd length (should cause an error) +SELECT CONVERT(BINARY(10), '0x0904D000341', 1) +Go + +-- non-hexadecimal string (should cause an error) +SELECT CONVERT(BINARY(5), 'Hello', 1) +Go + +-- hexadecimal with padding +SELECT CONVERT(BINARY(20), '0x48656C6C6F', 1) +Go + +-- special characters in hexadecimal (should cause an error) +SELECT CONVERT(BINARY(15), '0x0904D000341213440', 1) +Go + +-- non-hexadecimal characters after '0x' (should cause an error) +SELECT CONVERT(BINARY(16), '0x0904D000341!@', 1) +Go + +-- odd number of hexadecimal digits (should cause an error) +SELECT CONVERT(BINARY(5), '0x0904D0003', 1) +Go + +-- empty string (should cause an error) +SELECT CONVERT(BINARY(5), '', 1) +Go + + +-- 3. Testing style 2 (hexadecimal conversion without '0x' prefix): + + +-- even length string +SELECT CONVERT(BINARY(5), '0904D00034', 2) +Go + +-- odd length string (should cause an error) +SELECT CONVERT(BINARY(10), '0904D000341', 2) +Go + +-- string with '0x' prefix (should cause an error) +SELECT CONVERT(BINARY(10), '0x0904D00034', 2) +Go + +-- hexadecimal with padding +SELECT CONVERT(BINARY(20), '48656C6C6F', 2) +Go + +-- non-hexadecimal characters (should cause an error) +SELECT CONVERT(BINARY(16), '0904D000341!@', 2) +Go + +-- empty string +SELECT CONVERT(BINARY(5), '', 2) +Go + +-- maximum length input (8000 bytes = 16000 hex digits) +SELECT CONVERT(BINARY(8000), REPLICATE('0', 16000), 2) +Go + + +-- Testing null styles and empty strings + +-- Style 0 (default, ASCII conversion) + +-- Null input +SELECT CONVERT(BINARY(5), NULL, 0) +Go + +-- Empty string +SELECT CONVERT(BINARY(5), '', 0) +Go + +-- Null style +SELECT CONVERT(BINARY(5), '0904D00034', NULL) +Go + +-- Empty string with null style +SELECT CONVERT(BINARY(5), '', NULL) +Go + +-- Style 1 (hexadecimal conversion with '0x' prefix) + +-- Null input +SELECT CONVERT(BINARY(5), NULL, 1) +Go + +-- Empty string (should cause an error) +SELECT CONVERT(BINARY(5), '', 1) +Go + +-- Null style with '0x' prefix +SELECT CONVERT(BINARY(5), '0x0904D00034', NULL) +Go + +-- Style 2 (hexadecimal conversion without '0x' prefix) + +-- Null input +SELECT CONVERT(BINARY(5), NULL, 2) +Go + +-- Empty string +SELECT CONVERT(BINARY(5), '', 2) +Go + +-- Additional edge cases + +-- Null input with null style +SELECT CONVERT(BINARY(5), NULL, NULL) +Go + +-- Empty string with large BINARY size +SELECT CONVERT(BINARY(8000), '', 0) +Go + +-- Null input with large BINARY size +SELECT CONVERT(BINARY(8000), NULL, 0) +Go + +-- Space-only string +SELECT CONVERT(BINARY(5), ' ', 0) +Go + +SELECT CONVERT(BINARY(5), ' ', 1) +Go + +SELECT CONVERT(BINARY(5), ' ', 2) +Go + +-- Invalid style +SELECT CONVERT(BINARY(10), '0904D00034', 3); +Go + +-- Length greater than maximum allowed length (8000) +SELECT CONVERT(BINARY(8001), '0904D00034', 2) +Go + +-- Minimum length (1 byte) for BINARY +SELECT CONVERT(BINARY(1), 'A', 0); +Go + +-- Minimum length (1 byte) for VARBINARY +SELECT CONVERT(VARBINARY(1), 'A', 0); +Go + +-- Negative length for BINARY +SELECT CONVERT(BINARY(-5), '0904D00034', 0); +Go + +-- Zero length for BINARY +SELECT CONVERT(BINARY(0), '0904D00034', 0); +Go + +-- Varbinary + +-- 1. Testing style 0 (default, ASCII conversion): + +-- even length string +SELECT CONVERT(VARBINARY(10), '0904D00034', 0); +Go + +-- odd length string +SELECT CONVERT(VARBINARY(10), '0904D000341', 0); +Go + +-- default style (should be equivalent to style 0) +SELECT CONVERT(VARBINARY(10), '0904D00034'); +Go + +-- string with prefix '0x' and even length +SELECT CONVERT(VARBINARY(10), '0x0904D00034', 0); +Go + +-- string with blank spaces +SELECT CONVERT(VARBINARY(15), 'Hello World', 0); +Go + +-- special characters +SELECT CONVERT(VARBINARY(15), '0904D000341!@', 0); +Go + +-- empty string +SELECT CONVERT(VARBINARY(5), '', 0); +Go + +-- 2. Testing style 1 (hexadecimal conversion with '0x' prefix): + +-- even length string +SELECT CONVERT(VARBINARY(10), '0x0904D00034', 1); +Go + +-- odd length string (should cause an error) +SELECT CONVERT(VARBINARY(10), '0x0904D000341', 1); +Go + +-- string without '0x' prefix (should cause an error) +SELECT CONVERT(VARBINARY(10), '0904D00034', 1); +Go + +-- non-hexadecimal string (should cause an error) +SELECT CONVERT(VARBINARY(10), '0xHello', 1); +Go + +-- 3. Testing style 2 (hexadecimal conversion without '0x' prefix): + +-- even length string +SELECT CONVERT(VARBINARY(10), '0904D00034', 2); +Go + +-- odd length string (should cause an error) +SELECT CONVERT(VARBINARY(10), '0904D000341', 2); +Go + +-- string with '0x' prefix (should cause an error) +SELECT CONVERT(VARBINARY(10), '0x0904D00034', 2); +Go + +-- non-hexadecimal characters (should cause an error) +SELECT CONVERT(VARBINARY(16), '0904D000341!@', 2); +Go + +-- empty string +SELECT CONVERT(VARBINARY(5), '', 2); +Go + +-- 4. Testing with larger sizes and edge cases: + +-- maximum length input (8000 bytes = 16000 hex digits) +SELECT CONVERT(VARBINARY(8000), REPLICATE('0', 16000), 2); +Go + +-- NULL input +SELECT CONVERT(VARBINARY(10), NULL, 0); +Go + +SELECT CONVERT(VARBINARY(10), NULL, 1); +Go + +SELECT CONVERT(VARBINARY(10), NULL, 2); +Go + +-- NULL style +SELECT CONVERT(VARBINARY(10), '0904D00034', NULL); +Go + +-- Invalid style +SELECT CONVERT(VARBINARY(10), '0904D00034', 3); +Go + +-- Length greater than maximum allowed length (8000) +SELECT CONVERT(VARBINARY(8001), '0904D00034', 2) +Go diff --git a/test/JDBC/input/BABEL-2736-vu-cleanup.sql b/test/JDBC/input/BABEL-2736-vu-cleanup.sql new file mode 100644 index 0000000000..54696f5204 --- /dev/null +++ b/test/JDBC/input/BABEL-2736-vu-cleanup.sql @@ -0,0 +1,173 @@ +-- Drop views +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v1; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v2; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v3; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v4; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v5; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v6; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v7; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v8_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v9_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v10_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v11; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v12; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v13; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v14_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v15_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v16_try; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v17; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v18; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v19; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v20; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v21; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v22; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v23; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v24; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v26; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v27; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v28; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v29; +Go + +DROP VIEW IF EXISTS BABEL_BINARY_vu_prepare_v30; +Go + +-- Drop procedures +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p1; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p2; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p3; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p4; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p5; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p6; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p7; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p8; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p9; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p10; +Go + +DROP PROCEDURE IF EXISTS BABEL_BINARY_vu_prepare_p11; +Go + +-- Drop functions +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f1; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f2; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f3; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f4; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f5; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f7; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f8; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f9; +Go + +DROP FUNCTION IF EXISTS BABEL_BINARY_vu_prepare_f10; +Go +-- Drop test table +DROP TABLE IF EXISTS BABEL_BINARY_test_table1; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table2; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table3; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table4; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table_compcol; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table_compcol1; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table_compcol2; +GO + +DROP TABLE IF EXISTS BABEL_BINARY_test_table_compcol3; +GO diff --git a/test/JDBC/input/BABEL-2736-vu-prepare.sql b/test/JDBC/input/BABEL-2736-vu-prepare.sql new file mode 100644 index 0000000000..2820157517 --- /dev/null +++ b/test/JDBC/input/BABEL-2736-vu-prepare.sql @@ -0,0 +1,368 @@ +-- View to test binary conversion with style 0 (default) +CREATE VIEW BABEL_BINARY_vu_prepare_v1 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 0)); +GO + +-- Procedure to test binary conversion with style 0 (default) +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p1 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 0)); +GO + +-- Function to test binary conversion with style 0 (default) +CREATE FUNCTION BABEL_BINARY_vu_prepare_f1() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(10), '0904D00034', 0)); +END +GO + +-- View to test binary conversion with style 1 (with '0x' prefix) +CREATE VIEW BABEL_BINARY_vu_prepare_v2 AS +(SELECT CONVERT(BINARY(10), '0x0904D00034', 1)); +GO + +-- Procedure to test binary conversion with style 1 (with '0x' prefix) +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p2 AS +(SELECT CONVERT(BINARY(10), '0x0904D00034', 1)); +GO + +-- Function to test binary conversion with style 1 (with '0x' prefix) +CREATE FUNCTION BABEL_BINARY_vu_prepare_f2() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(10), '0x0904D00034', 1)); +END +GO + +-- View to test binary conversion with style 2 +CREATE VIEW BABEL_BINARY_vu_prepare_v3 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 2)); +GO + +-- Procedure to test binary conversion with style 2 +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p3 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 2)); +GO + +-- Function to test binary conversion with style 2 +CREATE FUNCTION BABEL_BINARY_vu_prepare_f3() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(10), '0904D00034', 2)); +END +GO + +-- View to test VARBINARY conversion +CREATE VIEW BABEL_BINARY_vu_prepare_v4 AS +(SELECT CONVERT(VARBINARY(10), '0904D00034', 0)); +GO + +-- Procedure to test VARBINARY conversion +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p4 AS +(SELECT CONVERT(VARBINARY(10), '0904D00034', 0)); +GO + +-- Function to test VARBINARY conversion +CREATE FUNCTION BABEL_BINARY_vu_prepare_f4() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(VARBINARY(10), '0904D00034', 0)); +END +GO + +-- Procedure to test invalid style (should cause an error) +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p5 AS +(SELECT CONVERT(BINARY(10), '0904D00034', 3)); +GO + +-- Function to test NULL input +CREATE FUNCTION BABEL_BINARY_vu_prepare_f5() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(10), NULL, 0)); +END +GO + +-- Test case for CONVERT with a column reference +CREATE TABLE BABEL_BINARY_test_table1 (col1 VARCHAR(20)); +GO +INSERT INTO BABEL_BINARY_test_table1 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v5 AS +(SELECT CONVERT(BINARY(5), col1, 1) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v6 AS +(SELECT CONVERT(BINARY(5), col1, 0) FROM BABEL_BINARY_test_table1); +GO + +CREATE TABLE BABEL_BINARY_test_table2 (col1 VARCHAR(20)); +GO +INSERT INTO BABEL_BINARY_test_table2 (col1) VALUES ('1234ABCD'), ('787980'), ('1234'); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v7 AS +(SELECT CONVERT(BINARY(5), col1, 2) FROM BABEL_BINARY_test_table2); +GO + +-- Test case for TRY_CONVERT with a column reference +CREATE TABLE BABEL_BINARY_test_table3 (col1 VARCHAR(20)); +GO +INSERT INTO BABEL_BINARY_test_table3 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v8_try AS +(SELECT TRY_CONVERT(BINARY(5), col1, 1) FROM BABEL_BINARY_test_table3); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v9_try AS +(SELECT TRY_CONVERT(BINARY(5), col1, 0) FROM BABEL_BINARY_test_table3); +GO + +CREATE TABLE BABEL_BINARY_test_table4 (col1 VARCHAR(20)); +GO +INSERT INTO BABEL_BINARY_test_table4 (col1) VALUES ('1234ABCD'), ('787980'), ('1234'); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v10_try AS +(SELECT TRY_CONVERT(BINARY(5), col1, 2) FROM BABEL_BINARY_test_table4); +GO + + + +-- Test case for CONVERT with CAST with different styles +CREATE VIEW BABEL_BINARY_vu_prepare_v11 AS +(SELECT CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 1) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v12 AS +(SELECT CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 0) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v13 AS +(SELECT CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 2) FROM BABEL_BINARY_test_table1); +GO + +-- Test case for TRY_CONVERT with CAST with different styles +CREATE VIEW BABEL_BINARY_vu_prepare_v14_try AS +(SELECT TRY_CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 1) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v15_try AS +(SELECT TRY_CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 0) FROM BABEL_BINARY_test_table1); +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v16_try AS +(SELECT TRY_CONVERT(BINARY(5), CAST(col1 AS NVARCHAR(20)), 2) FROM BABEL_BINARY_test_table1); +GO + + +-- Test case for variable usage +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p6 AS +BEGIN + DECLARE @abc VARCHAR(30); + SET @abc = '0x1234ABCD'; + SELECT CONVERT(BINARY(5), @abc, 1); +END +GO + +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p7 AS +BEGIN + DECLARE @abc NVARCHAR(30); + SET @abc = '1234ABCD'; + SELECT CONVERT(BINARY(5), @abc, 0); +END +GO + +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p8 AS +BEGIN + DECLARE @abc CHAR(10); + SET @abc = '1234ABCD'; + SELECT CONVERT(BINARY(5), @abc, 2); +END +GO + +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p9 AS +BEGIN + DECLARE @abc VARCHAR(30); + SET @abc = '0x1234ABCD'; + SELECT TRY_CONVERT(BINARY(5), @abc, 1); +END +GO + +-- Using multiple variables and conversions +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p10 AS +BEGIN + DECLARE @abc VARCHAR(30), @def NVARCHAR(30); + SET @abc = '0x1234ABCD'; + SET @def = '5678EF'; + SELECT + CONVERT(BINARY(5), @abc, 1) AS ConvertResult, + TRY_CONVERT(BINARY(5), @def, 2) AS TryConvertResult; +END +GO + +-- Test case for UNION with different types +CREATE VIEW BABEL_BINARY_vu_prepare_v17 AS +SELECT CONVERT(BINARY(5), '0x1234', 1) +UNION ALL +SELECT CONVERT(BINARY(5), 12345, 0) +GO + +-- Using TRY_CONVERT +CREATE VIEW BABEL_BINARY_vu_prepare_v18 AS +SELECT TRY_CONVERT(BINARY(5), '0x1234', 1) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), 12345, 0) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), 'ABCDE', 2) +GO + +-- Using different output lengths +CREATE VIEW BABEL_BINARY_vu_prepare_v19 AS +SELECT CONVERT(BINARY(3), '0x1234', 1) +UNION ALL +SELECT CONVERT(BINARY(8), 12345, 0) +UNION ALL +SELECT CONVERT(BINARY(10), '0xABCDEF', 1) +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v20 AS +SELECT TRY_CONVERT(BINARY(3), '0x1234', 1) +UNION ALL +SELECT TRY_CONVERT(BINARY(8), 12345, 0) +UNION ALL +SELECT TRY_CONVERT(BINARY(10), '0xABCDEF', 1) +GO + +-- Using CAST and concatenation +CREATE VIEW BABEL_BINARY_vu_prepare_v21 AS +SELECT CONVERT(BINARY(5), CAST('0x' + '1234' AS VARCHAR(10)), 1) +UNION ALL +SELECT CONVERT(BINARY(5), CAST(123 + 45 AS VARCHAR(10)), 0) +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v22 AS +SELECT TRY_CONVERT(BINARY(5), CAST('0x' + '1234' AS VARCHAR(10)), 1) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), CAST(123 + 45 AS VARCHAR(10)), 0) +GO + +-- Using subqueries and constants +CREATE VIEW BABEL_BINARY_vu_prepare_v23 AS +SELECT CONVERT(BINARY(5), (SELECT '0x1234'), 1) +UNION ALL +SELECT CONVERT(BINARY(5), 0x1234, 0) +UNION ALL +SELECT CONVERT(BINARY(5), CHAR(65) + CHAR(66), 0) +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v24 AS +SELECT TRY_CONVERT(BINARY(5), (SELECT '0x1234'), 1) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), 0x1234, 0) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), CHAR(65) + CHAR(66), 0) +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v26 AS +SELECT TRY_CONVERT(BINARY(5), CAST('1234' AS NVARCHAR(10)), 2) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), CAST(12345 AS DECIMAL(10,2)), 0) +UNION ALL +SELECT TRY_CONVERT(BINARY(5), LOWER('0xABCD'), 1) +GO + +-- Test case for CONVERT with NULL in different positions +CREATE PROCEDURE BABEL_BINARY_vu_prepare_p11 AS +BEGIN + DECLARE @nullVar VARCHAR(10) = NULL; + SELECT + CONVERT(BINARY(5), NULL, 0) AS NullInput, + CONVERT(BINARY(5), '0x1234', NULL) AS NullStyle, + CONVERT(BINARY(5), @nullVar, 0) AS NullVariable; +END +GO + +-- Test case for CONVERT with decimal +CREATE FUNCTION BABEL_BINARY_vu_prepare_f7() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(5), 123.45, 0)); +END +GO + +CREATE FUNCTION BABEL_BINARY_vu_prepare_f8() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT TRY_CONVERT(BINARY(5), 123.45, 0)); +END +GO + +-- Test case for CONVERT with different styles +CREATE VIEW BABEL_BINARY_vu_prepare_v27 AS +SELECT + CONVERT(BINARY(5), '0x1234', 0) AS Style0, + CONVERT(BINARY(5), '0x1234', 1) AS Style1, + CONVERT(BINARY(5), '1234', 2) AS Style2; +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v28 AS +SELECT + TRY_CONVERT(BINARY(5), '0x1234', 0) AS Style0, + TRY_CONVERT(BINARY(5), '0x1234', 1) AS Style1, + TRY_CONVERT(BINARY(5), '1234', 2) AS Style2; +GO + +-- Test case for CONVERT with large binary and truncation +CREATE FUNCTION BABEL_BINARY_vu_prepare_f9() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT CONVERT(BINARY(5), '0x123456789ABCDEF', 1)); +END +GO + +CREATE FUNCTION BABEL_BINARY_vu_prepare_f10() +RETURNS VARBINARY(10) AS +BEGIN + RETURN (SELECT TRY_CONVERT(BINARY(5), '0x123456789ABCDEF', 1)); +END +GO + +-- Test case for CONVERT with different input types +CREATE VIEW BABEL_BINARY_vu_prepare_v29 AS +SELECT + CONVERT(BINARY(5), 12345, 0) AS IntInput, + CONVERT(BINARY(5), '2023-01-01', 0) AS DateInput, + CONVERT(BINARY(5), CAST('Hello, World!' AS NVARCHAR(20)), 0) AS NVarCharInput, + CONVERT(BINARY(5), CAST(0x1234ABCD AS VARBINARY(4)), 0) AS VarBinaryInput; +GO + +CREATE VIEW BABEL_BINARY_vu_prepare_v30 AS +SELECT + TRY_CONVERT(BINARY(5), 12345, 0) AS IntInput, + TRY_CONVERT(BINARY(5), '2023-01-01', 0) AS DateInput, + TRY_CONVERT(BINARY(5), CAST('Hello, World!' AS NVARCHAR(20)), 0) AS NVarCharInput, + TRY_CONVERT(BINARY(5), CAST(0x1234ABCD AS VARBINARY(4)), 0) AS VarBinaryInput; +GO + +CREATE TABLE BABEL_BINARY_test_table_compcol (col1 VARCHAR(20), col2 AS CONVERT(VARBINARY(20), col1)); +GO +INSERT INTO BABEL_BINARY_test_table_compcol (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO + +CREATE TABLE BABEL_BINARY_test_table_compcol1 (col1 VARCHAR(20), col2 AS TRY_CONVERT(VARBINARY(20), col1)); +GO +INSERT INTO BABEL_BINARY_test_table_compcol1 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO + +CREATE TABLE BABEL_BINARY_test_table_compcol2 (col1 VARCHAR(20), col2 AS CONVERT(VARBINARY(20), col1, 1)); +GO +INSERT INTO BABEL_BINARY_test_table_compcol2 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO + +CREATE TABLE BABEL_BINARY_test_table_compcol3 (col1 VARCHAR(20), col2 AS TRY_CONVERT(VARBINARY(20), col1, 1)); +GO +INSERT INTO BABEL_BINARY_test_table_compcol3 (col1) VALUES ('0x1234ABCD'), ('0x787980'), ('0x1234'); +GO diff --git a/test/JDBC/input/BABEL-2736-vu-verify.sql b/test/JDBC/input/BABEL-2736-vu-verify.sql new file mode 100644 index 0000000000..6f811b0a30 --- /dev/null +++ b/test/JDBC/input/BABEL-2736-vu-verify.sql @@ -0,0 +1,585 @@ +-- Test view v1 (style 0) +SELECT * FROM BABEL_BINARY_vu_prepare_v1 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v1 +GO + +-- Test procedure p1 (style 0) +EXEC BABEL_BINARY_vu_prepare_p1 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p1 +GO + +-- Test function f1 (style 0) +SELECT dbo.BABEL_BINARY_vu_prepare_f1() +GO +DROP FUNCTION BABEL_BINARY_vu_prepare_f1 +GO + +-- Test view v2 (style 1) +SELECT * FROM BABEL_BINARY_vu_prepare_v2 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v2 +GO + +-- Test procedure p2 (style 1) +EXEC BABEL_BINARY_vu_prepare_p2 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p2 +GO + +-- Test function f2 (style 1) +SELECT dbo.BABEL_BINARY_vu_prepare_f2() +GO +DROP FUNCTION BABEL_BINARY_vu_prepare_f2 +GO + +-- Test view v3 (style 2) +SELECT * FROM BABEL_BINARY_vu_prepare_v3 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v3 +GO + +-- Test procedure p3 (style 2) +EXEC BABEL_BINARY_vu_prepare_p3 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p3 +GO + +-- Test function f3 (style 2) +SELECT dbo.BABEL_BINARY_vu_prepare_f3() +GO +DROP FUNCTION BABEL_BINARY_vu_prepare_f3 +GO + +-- Test view v4 (VARBINARY) +SELECT * FROM BABEL_BINARY_vu_prepare_v4 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v4 +GO + +-- Test procedure p4 (VARBINARY) +EXEC BABEL_BINARY_vu_prepare_p4 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p4 +GO + +-- Test function f4 (VARBINARY) +SELECT dbo.BABEL_BINARY_vu_prepare_f4() +GO +DROP FUNCTION BABEL_BINARY_vu_prepare_f4 +GO + +-- Test procedure p5 (invalid style - should cause an error) +EXEC BABEL_BINARY_vu_prepare_p5 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p5 +GO + +-- Test function f5 (NULL input) +SELECT dbo.BABEL_BINARY_vu_prepare_f5() +GO +DROP FUNCTION BABEL_BINARY_vu_prepare_f5 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v5 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v5 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v6 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v6 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v7 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v7 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v8_try +GO +DROP VIEW BABEL_BINARY_vu_prepare_v8_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v9_try +GO +DROP VIEW BABEL_BINARY_vu_prepare_v9_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v10_try +GO +DROP VIEW BABEL_BINARY_vu_prepare_v10_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v11 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v11 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v12 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v12 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v13 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v13 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v14_try +GO +DROP VIEW BABEL_BINARY_vu_prepare_v14_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v15_try +GO +DROP VIEW BABEL_BINARY_vu_prepare_v15_try +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v16_try +GO +DROP VIEW BABEL_BINARY_vu_prepare_v16_try +GO + +EXEC BABEL_BINARY_vu_prepare_p6 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p6 +GO + +EXEC BABEL_BINARY_vu_prepare_p7 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p7 +GO + +EXEC BABEL_BINARY_vu_prepare_p8 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p8 +GO + +EXEC BABEL_BINARY_vu_prepare_p9 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p9 +GO + +EXEC BABEL_BINARY_vu_prepare_p10 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p10 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v17 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v17 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v18 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v18 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v19 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v19 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v20 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v20 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v21 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v21 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v22 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v22 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v23 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v23 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v24 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v24 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v26 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v26 +GO + +EXEC BABEL_BINARY_vu_prepare_p11 +GO +DROP PROCEDURE BABEL_BINARY_vu_prepare_p11 +GO + +SELECT dbo.BABEL_BINARY_vu_prepare_f7() +DROP FUNCTION BABEL_BINARY_vu_prepare_f7 +GO + +SELECT dbo.BABEL_BINARY_vu_prepare_f8() +DROP FUNCTION BABEL_BINARY_vu_prepare_f8 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v27 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v27 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v28 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v28 +GO + +SELECT dbo.BABEL_BINARY_vu_prepare_f9() +DROP FUNCTION BABEL_BINARY_vu_prepare_f9 +GO + +SELECT dbo.BABEL_BINARY_vu_prepare_f10() +DROP FUNCTION BABEL_BINARY_vu_prepare_f10 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v29 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v29 +GO + +SELECT * FROM BABEL_BINARY_vu_prepare_v30 +GO +DROP VIEW BABEL_BINARY_vu_prepare_v30 +GO + +SELECT * FROM BABEL_BINARY_test_table_compcol +GO +DROP TABLE BABEL_BINARY_test_table_compcol +GO + +SELECT * FROM BABEL_BINARY_test_table_compcol1 +GO +DROP TABLE BABEL_BINARY_test_table_compcol1 +GO + +SELECT * FROM BABEL_BINARY_test_table_compcol2 +GO +DROP TABLE BABEL_BINARY_test_table_compcol2 +GO + +SELECT * FROM BABEL_BINARY_test_table_compcol3 +GO +DROP TABLE BABEL_BINARY_test_table_compcol3 +GO + +-- Additional test cases +-- 1. Testing style 0 (default, ASCII conversion): + +-- even length string +SELECT CONVERT(BINARY(5), '0904D00034', 0) +Go + +-- odd length string +SELECT CONVERT(BINARY(10), '0904D000341', 0) +Go + +-- default style selected as 0 +SELECT CONVERT(BINARY(5), '0904D00034') +Go + +-- string with prefix '0x' and even length +SELECT CONVERT(BINARY(10), '0x0904D00034', 0) +Go + +-- string with prefix '0x' and odd length +SELECT CONVERT(BINARY(10), '0x0904D000341', 0) +Go + +SELECT CONVERT(BINARY(5), 'Hello', 0) +Go + +-- padding +SELECT CONVERT(BINARY(20), 'Hello', 0) +Go + +-- string with blank spaces +SELECT CONVERT(BINARY(10), 'Hello World', 0) +Go + +-- special characters +SELECT CONVERT(BINARY(15), '0904D000341!@', 0) +Go + +-- empty string +SELECT CONVERT(BINARY(5), '', 0) +Go + + +-- 2. Testing style 1 (hexadecimal conversion with '0x' prefix): + + +-- even length string +SELECT CONVERT(BINARY(5), '0x0904D00034', 1); +Go + +-- odd length string (should cause an error) +SELECT CONVERT(BINARY(10), '0x0904D000341', 1) +Go + +-- string without '0x' prefix (should cause an error) +SELECT CONVERT(BINARY(10), '0904D00034', 1) +Go + +-- string with '0x' prefix and odd length (should cause an error) +SELECT CONVERT(BINARY(10), '0x0904D000341', 1) +Go + +-- non-hexadecimal string (should cause an error) +SELECT CONVERT(BINARY(5), 'Hello', 1) +Go + +-- hexadecimal with padding +SELECT CONVERT(BINARY(20), '0x48656C6C6F', 1) +Go + +-- special characters in hexadecimal (should cause an error) +SELECT CONVERT(BINARY(15), '0x0904D000341213440', 1) +Go + +-- non-hexadecimal characters after '0x' (should cause an error) +SELECT CONVERT(BINARY(16), '0x0904D000341!@', 1) +Go + +-- odd number of hexadecimal digits (should cause an error) +SELECT CONVERT(BINARY(5), '0x0904D0003', 1) +Go + +-- empty string (should cause an error) +SELECT CONVERT(BINARY(5), '', 1) +Go + + +-- 3. Testing style 2 (hexadecimal conversion without '0x' prefix): + + +-- even length string +SELECT CONVERT(BINARY(5), '0904D00034', 2) +Go + +-- odd length string (should cause an error) +SELECT CONVERT(BINARY(10), '0904D000341', 2) +Go + +-- string with '0x' prefix (should cause an error) +SELECT CONVERT(BINARY(10), '0x0904D00034', 2) +Go + +-- hexadecimal with padding +SELECT CONVERT(BINARY(20), '48656C6C6F', 2) +Go + +-- non-hexadecimal characters (should cause an error) +SELECT CONVERT(BINARY(16), '0904D000341!@', 2) +Go + +-- empty string +SELECT CONVERT(BINARY(5), '', 2) +Go + +-- maximum length input (8000 bytes = 16000 hex digits) +SELECT CONVERT(BINARY(8000), REPLICATE('0', 16000), 2) +Go + + +-- Testing null styles and empty strings + +-- Style 0 (default, ASCII conversion) + +-- Null input +SELECT CONVERT(BINARY(5), NULL, 0) +Go + +-- Empty string +SELECT CONVERT(BINARY(5), '', 0) +Go + +-- Null style +SELECT CONVERT(BINARY(5), '0904D00034', NULL) +Go + +-- Empty string with null style +SELECT CONVERT(BINARY(5), '', NULL) +Go + +-- Style 1 (hexadecimal conversion with '0x' prefix) + +-- Null input +SELECT CONVERT(BINARY(5), NULL, 1) +Go + +-- Empty string (should cause an error) +SELECT CONVERT(BINARY(5), '', 1) +Go + +-- Null style with '0x' prefix +SELECT CONVERT(BINARY(5), '0x0904D00034', NULL) +Go + +-- Style 2 (hexadecimal conversion without '0x' prefix) + +-- Null input +SELECT CONVERT(BINARY(5), NULL, 2) +Go + +-- Empty string +SELECT CONVERT(BINARY(5), '', 2) +Go + +-- Additional edge cases + +-- Null input with null style +SELECT CONVERT(BINARY(5), NULL, NULL) +Go + +-- Empty string with large BINARY size +SELECT CONVERT(BINARY(8000), '', 0) +Go + +-- Null input with large BINARY size +SELECT CONVERT(BINARY(8000), NULL, 0) +Go + +-- Space-only string +SELECT CONVERT(BINARY(5), ' ', 0) +Go + +SELECT CONVERT(BINARY(5), ' ', 1) +Go + +SELECT CONVERT(BINARY(5), ' ', 2) +Go + +-- Invalid style +SELECT CONVERT(BINARY(10), '0904D00034', 3); +Go + +-- Length greater than maximum allowed length (8000) +SELECT CONVERT(BINARY(8001), '0904D00034', 2) +Go + +-- Minimum length (1 byte) for BINARY +SELECT CONVERT(BINARY(1), 'A', 0); +Go + +-- Minimum length (1 byte) for VARBINARY +SELECT CONVERT(VARBINARY(1), 'A', 0); +Go + +-- Negative length for BINARY +SELECT CONVERT(BINARY(-5), '0904D00034', 0); +Go + +-- Zero length for BINARY +SELECT CONVERT(BINARY(0), '0904D00034', 0); +Go + +-- Varbinary + +-- 1. Testing style 0 (default, ASCII conversion): + +-- even length string +SELECT CONVERT(VARBINARY(10), '0904D00034', 0); +Go + +-- odd length string +SELECT CONVERT(VARBINARY(10), '0904D000341', 0); +Go + +-- default style (should be equivalent to style 0) +SELECT CONVERT(VARBINARY(10), '0904D00034'); +Go + +-- string with prefix '0x' and even length +SELECT CONVERT(VARBINARY(10), '0x0904D00034', 0); +Go + +-- string with blank spaces +SELECT CONVERT(VARBINARY(15), 'Hello World', 0); +Go + +-- special characters +SELECT CONVERT(VARBINARY(15), '0904D000341!@', 0); +Go + +-- empty string +SELECT CONVERT(VARBINARY(5), '', 0); +Go + +-- 2. Testing style 1 (hexadecimal conversion with '0x' prefix): + +-- even length string +SELECT CONVERT(VARBINARY(10), '0x0904D00034', 1); +Go + +-- odd length string (should cause an error) +SELECT CONVERT(VARBINARY(10), '0x0904D000341', 1); +Go + +-- string without '0x' prefix (should cause an error) +SELECT CONVERT(VARBINARY(10), '0904D00034', 1); +Go + +-- non-hexadecimal string (should cause an error) +SELECT CONVERT(VARBINARY(10), '0xHello', 1); +Go + +-- 3. Testing style 2 (hexadecimal conversion without '0x' prefix): + +-- even length string +SELECT CONVERT(VARBINARY(10), '0904D00034', 2); +Go + +-- odd length string (should cause an error) +SELECT CONVERT(VARBINARY(10), '0904D000341', 2); +Go + +-- string with '0x' prefix (should cause an error) +SELECT CONVERT(VARBINARY(10), '0x0904D00034', 2); +Go + +-- non-hexadecimal characters (should cause an error) +SELECT CONVERT(VARBINARY(16), '0904D000341!@', 2); +Go + +-- empty string +SELECT CONVERT(VARBINARY(5), '', 2); +Go + +-- 4. Testing with larger sizes and edge cases: + +-- maximum length input (8000 bytes = 16000 hex digits) +SELECT CONVERT(VARBINARY(8000), REPLICATE('0', 16000), 2); +Go + +-- NULL input +SELECT CONVERT(VARBINARY(10), NULL, 0); +Go + +SELECT CONVERT(VARBINARY(10), NULL, 1); +Go + +SELECT CONVERT(VARBINARY(10), NULL, 2); +Go + +-- NULL style +SELECT CONVERT(VARBINARY(10), '0904D00034', NULL); +Go + +-- Invalid style +SELECT CONVERT(VARBINARY(10), '0904D00034', 3); +Go + +-- Length greater than maximum allowed length (8000) +SELECT CONVERT(VARBINARY(8001), '0904D00034', 2) +Go diff --git a/test/JDBC/jdbc_schedule b/test/JDBC/jdbc_schedule index 5abe4d273f..945aede0a6 100644 --- a/test/JDBC/jdbc_schedule +++ b/test/JDBC/jdbc_schedule @@ -81,6 +81,12 @@ ignore#!#test_like_for_AI-before-16_5-or-15_9-vu-cleanup ignore#!#BABEL-CASE_EXPR-before-16_5-or-15_9-vu-prepare ignore#!#BABEL-CASE_EXPR-before-16_5-or-15_9-vu-verify ignore#!#BABEL-CASE_EXPR-before-16_5-or-15_9-vu-cleanup +ignore#!#BABEL-2736-before-16_5-vu-prepare +ignore#!#BABEL-2736-before-16_5-vu-verify +ignore#!#BABEL-2736-before-16_5-vu-cleanup +ignore#!#BABEL-2736-before-15_3-vu-prepare +ignore#!#BABEL-2736-before-15_3-vu-verify +ignore#!#BABEL-2736-before-15_3-vu-cleanup # These tests are meant for upgrade scenario prior to (potential) 14_5 release ignore#!#BABEL-3147-before-14_5-vu-prepare diff --git a/test/JDBC/upgrade/15_1/schedule b/test/JDBC/upgrade/15_1/schedule index 205b3b7e50..5cca3cdcf7 100644 --- a/test/JDBC/upgrade/15_1/schedule +++ b/test/JDBC/upgrade/15_1/schedule @@ -435,4 +435,5 @@ binary-datatype-operators cast-varchar-to-time BABEL-CASE_EXPR-before-16_5-or-15_9 BABEL-5186 +BABEL-2736-before-15_3 diff --git a/test/JDBC/upgrade/15_2/schedule b/test/JDBC/upgrade/15_2/schedule index 7ebe26510a..06ed83e766 100644 --- a/test/JDBC/upgrade/15_2/schedule +++ b/test/JDBC/upgrade/15_2/schedule @@ -471,4 +471,5 @@ binary-datatype-operators cast-varchar-to-time BABEL-CASE_EXPR-before-16_5-or-15_9 BABEL-5186 +BABEL-2736-before-15_3 diff --git a/test/JDBC/upgrade/15_3/schedule b/test/JDBC/upgrade/15_3/schedule index e455b3cfc9..d88e7e3794 100644 --- a/test/JDBC/upgrade/15_3/schedule +++ b/test/JDBC/upgrade/15_3/schedule @@ -489,4 +489,5 @@ binary-datatype-operators cast-varchar-to-time BABEL-CASE_EXPR-before-16_5-or-15_9 BABEL-5186 +BABEL-2736-before-16_5 diff --git a/test/JDBC/upgrade/15_4/schedule b/test/JDBC/upgrade/15_4/schedule index 1d3c11d250..98cb65fc16 100644 --- a/test/JDBC/upgrade/15_4/schedule +++ b/test/JDBC/upgrade/15_4/schedule @@ -503,4 +503,5 @@ binary-datatype-operators cast-varchar-to-time BABEL-CASE_EXPR-before-16_5-or-15_9 BABEL-5186 +BABEL-2736-before-16_5 diff --git a/test/JDBC/upgrade/15_5/schedule b/test/JDBC/upgrade/15_5/schedule index fe041f3acb..179511d7aa 100644 --- a/test/JDBC/upgrade/15_5/schedule +++ b/test/JDBC/upgrade/15_5/schedule @@ -535,4 +535,5 @@ binary-datatype-operators cast-varchar-to-time BABEL-CASE_EXPR-before-16_5-or-15_9 BABEL-5186 +BABEL-2736-before-16_5 diff --git a/test/JDBC/upgrade/15_6/schedule b/test/JDBC/upgrade/15_6/schedule index 8315c5d8ec..00811d7a0a 100644 --- a/test/JDBC/upgrade/15_6/schedule +++ b/test/JDBC/upgrade/15_6/schedule @@ -551,4 +551,5 @@ binary-datatype-operators cast-varchar-to-time BABEL-CASE_EXPR-before-16_5-or-15_9 BABEL-5186 +BABEL-2736-before-16_5 diff --git a/test/JDBC/upgrade/15_7/schedule b/test/JDBC/upgrade/15_7/schedule index 18e0959719..f3bd4706f4 100644 --- a/test/JDBC/upgrade/15_7/schedule +++ b/test/JDBC/upgrade/15_7/schedule @@ -560,4 +560,5 @@ cast-varchar-to-time GRANT_SCHEMA-before-15_9-16_5 BABEL-CASE_EXPR-before-16_5-or-15_9 BABEL-5186 +BABEL-2736-before-16_5 diff --git a/test/JDBC/upgrade/15_8/schedule b/test/JDBC/upgrade/15_8/schedule index 0e15bbf319..509743456e 100644 --- a/test/JDBC/upgrade/15_8/schedule +++ b/test/JDBC/upgrade/15_8/schedule @@ -566,4 +566,5 @@ BABEL-5119 GRANT_SCHEMA-before-15_9-16_5 BABEL-CASE_EXPR-before-16_5-or-15_9 BABEL-5186 +BABEL-2736-before-16_5 diff --git a/test/JDBC/upgrade/latest/schedule b/test/JDBC/upgrade/latest/schedule index a427674a97..c1509788c5 100644 --- a/test/JDBC/upgrade/latest/schedule +++ b/test/JDBC/upgrade/latest/schedule @@ -570,4 +570,5 @@ BABEL-5129 BABEL-CASE_EXPR charindex_replace_patindex BABEL-5186 +BABEL-2736 diff --git a/test/python/expected/upgrade_validation/expected_dependency.out b/test/python/expected/upgrade_validation/expected_dependency.out index 31ae3d4363..6205d547cd 100644 --- a/test/python/expected/upgrade_validation/expected_dependency.out +++ b/test/python/expected/upgrade_validation/expected_dependency.out @@ -67,7 +67,6 @@ Collation sys.ukrainian_ci_as Collation sys.ukrainian_cs_as Collation sys.vietnamese_ci_ai Collation sys.vietnamese_ci_as -Function sys."binary"(sys."binary",integer,boolean) Function sys."char"(integer) Function sys."decimal"(sys."nchar",integer,boolean) Function sys."isnull"(bigint,bigint) @@ -111,6 +110,7 @@ Function sys.babelfish_conv_hijri_to_greg(timestamp without time zone) Function sys.babelfish_conv_string_to_date(text,numeric) Function sys.babelfish_conv_string_to_datetime(text,text,numeric) Function sys.babelfish_conv_string_to_time(text,text,numeric) +Function sys.babelfish_conv_string_to_varbinary(sys."varchar",numeric) Function sys.babelfish_conv_time_to_string(text,text,time without time zone,numeric) Function sys.babelfish_conv_to_varchar(text,anyelement,numeric) Function sys.babelfish_conv_to_varchar(text,text,numeric) @@ -201,10 +201,12 @@ Function sys.babelfish_try_conv_money_to_string(text,money,numeric) Function sys.babelfish_try_conv_string_to_date(text,numeric) Function sys.babelfish_try_conv_string_to_datetime(text,text,numeric) Function sys.babelfish_try_conv_string_to_time(text,text,numeric) +Function sys.babelfish_try_conv_string_to_varbinary(sys."varchar",numeric) Function sys.babelfish_try_conv_time_to_string(text,text,time without time zone,numeric) Function sys.babelfish_try_conv_to_date(anyelement) Function sys.babelfish_try_conv_to_datetime(anyelement) Function sys.babelfish_try_conv_to_time(anyelement) +Function sys.babelfish_try_conv_to_varbinary(anyelement,numeric) Function sys.babelfish_try_conv_to_varchar(text,anyelement,numeric) Function sys.babelfish_try_conv_to_varchar(text,text,numeric) Function sys.babelfish_try_parse_to_date(text,text) @@ -719,7 +721,6 @@ Function sys.uniqueidentifier_hash(sys.uniqueidentifier) Function sys.uniqueidentifier_sqlvariant(sys.uniqueidentifier) Function sys.update(text) Function sys.user_name_sysname() -Function sys.varbinary(sys.varbinary,integer,boolean) Function sys.varbinary2uniqueidentifier(sys.bbf_varbinary,integer,boolean) Function sys.varbinarybytea(sys.bbf_varbinary,integer,boolean) Function sys.varbinaryfloat4(sys.bbf_varbinary)