Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FB4] A proposal for fixing #7880 #7882

Open
wants to merge 1 commit into
base: v4.0-release
Choose a base branch
from

Conversation

dmitry-lipetsk
Copy link
Contributor

These changes force a server to return correct datatype for CAST(something as array datatype) - array type instead type of element.

  1. Test of CAST(arrayColumn as ARRAY)
SQL> set sqlda_display on;
SQL> SELECT CAST(COL_I4 AS VARCHAR(128)[0:2]) FROM TEST_ARR1;

INPUT message field count: 0

OUTPUT message field count: 1
01: sqltype: 540 ARRAY Nullable scale: 0 subtype: 0 len: 8
  :  name: CAST  alias: CAST
  : table:   owner:

             CAST
=================
            111:0

Usage of UDFs with SCALAR_ARRAY-argument. These functions return different information about array: DIM, element DTYPE, element LENGTH

SQL> -- Bad column type: VARCHAR instead ARRAY
SQL> -- FETCH returns incorrect data
SQL> SELECT IBP_UDF__GET_ARR_DIM(CAST(COL_I4 AS VARCHAR(128)[0:2])) FROM TEST_ARR1;

IBP_UDF__GET_ARR_DIM
====================
                   1

SQL> SELECT IBP_UDF__GET_ARR_DESC_DTYPE(CAST(COL_I4 AS VARCHAR(128)[0:2])) FROM TEST_ARR1;

IBP_UDF__GET_ARR_DESC_DTYPE
===========================
                          9                                                                                                                                                                                                                                                                                                                                                                             

SQL> SELECT IBP_UDF__GET_ARR_DESC_LENGTH(CAST(COL_I4 AS VARCHAR(128)[0:2])) FROM TEST_ARR1;                                                                                                                                                                                                                                                                                                             IBP_UDF__GET_ARR_DESC_LENGTH
============================
                           4                                                                                                                                                                                                                                                                                                                                                                            

SQL> SELECT IBP_UDF__ADTYPE__VCH64(CAST(COL_I4 AS VARCHAR(128)[0:2])) FROM TEST_ARR1;                                                                                                                                                                                                                                                                                                                   IBP_UDF__ADTYPE__VCH64
======================
                     3                                                                                                                                                                                                                                                                                                                                                                                  

SQL> SELECT IBP_UDF__ADTYPE__CH64(CAST(COL_I4 AS VARCHAR(128)[0:2])) FROM TEST_ARR1;

IBP_UDF__ADTYPE__CH64
=====================
                    1

SQL> -- Bad column type: INTEGER instead ARRAY
SQL> -- FETCH returns conversion error from string "#x01#x01#x01#x00#x04# ....."
SQL> SELECT IBP_UDF__GET_ARR_DIM(CAST(COL_I4 AS INTEGER[0:2])) FROM TEST_ARR1;

IBP_UDF__GET_ARR_DIM
====================
                   1

SQL> SELECT IBP_UDF__GET_ARR_DESC_DTYPE(CAST(COL_I4 AS INTEGER[0:2])) FROM TEST_ARR1;

IBP_UDF__GET_ARR_DESC_DTYPE
===========================
                          9

SQL> SELECT IBP_UDF__ADTYPE__VCH64(CAST(COL_I4 AS INTEGER[0:2])) FROM TEST_ARR1;

IBP_UDF__ADTYPE__VCH64
======================
                     3

SQL> SELECT IBP_UDF__ADTYPE__CH64(CAST(COL_I4 AS INTEGER[0:2])) FROM TEST_ARR1;

IBP_UDF__ADTYPE__CH64
=====================
                    1

  1. TEST OF CAST(? AS array datatype)
SQL> set sqlda_display on;
SQL> SELECT CAST(? AS INTEGER[0:2]) FROM RDB$DATABASE;

INPUT message field count: 1
01: sqltype: 540 ARRAY Nullable scale: 0 subtype: 0 len: 8
  :  name:   alias:
  : table:   owner:

OUTPUT message field count: 1
01: sqltype: 540 ARRAY Nullable scale: 0 subtype: 0 len: 8
  :  name: CAST  alias: CAST
  : table:   owner:

             CAST
=================
Statement failed, SQLSTATE = 07002
Dynamic SQL Error
-SQLDA error
-No SQLDA for input values provided

These changes force a server to return correct datatype for CAST(something as array datatype) - array type instead type of element.

1) Test of CAST(arrayColumn as ARRAY)

SQL> set sqlda_display on;
SQL> SELECT CAST(COL_I4 AS VARCHAR(128)[0:2]) FROM TEST_ARR1;

INPUT message field count: 0

OUTPUT message field count: 1
01: sqltype: 540 ARRAY Nullable scale: 0 subtype: 0 len: 8
  :  name: CAST  alias: CAST
  : table:   owner:

             CAST
=================
            111:0

Usage of UDFs with SCALAR_ARRAY-argument. These functions return different information about array: DIM, DTYPE, SUBTYPE, SCALE

SQL> -- Bad column type: VARCHAR instead ARRAY
SQL> -- FETCH returns incorrect data
SQL> SELECT IBP_UDF__GET_ARR_DIM(CAST(COL_I4 AS VARCHAR(128)[0:2])) FROM TEST_ARR1;

IBP_UDF__GET_ARR_DIM
====================
                   1

SQL> SELECT IBP_UDF__GET_ARR_DESC_DTYPE(CAST(COL_I4 AS VARCHAR(128)[0:2])) FROM TEST_ARR1;

IBP_UDF__GET_ARR_DESC_DTYPE
===========================
                          9                                                                                                                                                                                                                                                                                                                                                                             SQL> SELECT IBP_UDF__GET_ARR_DESC_LENGTH(CAST(COL_I4 AS VARCHAR(128)[0:2])) FROM TEST_ARR1;                                                                                                                                                                                                                                                                                                             IBP_UDF__GET_ARR_DESC_LENGTH
============================
                           4                                                                                                                                                                                                                                                                                                                                                                            SQL> SELECT IBP_UDF__ADTYPE__VCH64(CAST(COL_I4 AS VARCHAR(128)[0:2])) FROM TEST_ARR1;                                                                                                                                                                                                                                                                                                                   IBP_UDF__ADTYPE__VCH64
======================
                     3                                                                                                                                                                                                                                                                                                                                                                                  SQL> SELECT IBP_UDF__ADTYPE__CH64(CAST(COL_I4 AS VARCHAR(128)[0:2])) FROM TEST_ARR1;

IBP_UDF__ADTYPE__CH64
=====================
                    1

SQL> -- Bad column type: INTEGER instead ARRAY
SQL> -- FETCH returns conversion error from string "#x01#x01#x01#x00#x04# ....."
SQL> SELECT IBP_UDF__GET_ARR_DIM(CAST(COL_I4 AS INTEGER[0:2])) FROM TEST_ARR1;

IBP_UDF__GET_ARR_DIM
====================
                   1

SQL> SELECT IBP_UDF__GET_ARR_DESC_DTYPE(CAST(COL_I4 AS INTEGER[0:2])) FROM TEST_ARR1;

IBP_UDF__GET_ARR_DESC_DTYPE
===========================
                          9

SQL> SELECT IBP_UDF__ADTYPE__VCH64(CAST(COL_I4 AS INTEGER[0:2])) FROM TEST_ARR1;

IBP_UDF__ADTYPE__VCH64
======================
                     3

SQL> SELECT IBP_UDF__ADTYPE__CH64(CAST(COL_I4 AS INTEGER[0:2])) FROM TEST_ARR1;

IBP_UDF__ADTYPE__CH64
=====================
                    1

2) TEST OF CAST(? AS array datatype)

SQL> set sqlda_display on;
SQL> SELECT CAST(? AS INTEGER[0:2]) FROM RDB$DATABASE;

INPUT message field count: 1
01: sqltype: 540 ARRAY Nullable scale: 0 subtype: 0 len: 8
  :  name:   alias:
  : table:   owner:

OUTPUT message field count: 1
01: sqltype: 540 ARRAY Nullable scale: 0 subtype: 0 len: 8
  :  name: CAST  alias: CAST
  : table:   owner:

             CAST
=================
Statement failed, SQLSTATE = 07002
Dynamic SQL Error
-SQLDA error
-No SQLDA for input values provided
@dmitry-lipetsk dmitry-lipetsk changed the title A proposal for fixing #7880 [FB4] A proposal for fixing #7880 Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant