diff --git a/.github/composite-actions/compile-antlr/action.yml b/.github/composite-actions/compile-antlr/action.yml index 6938167584..5e46480f94 100644 --- a/.github/composite-actions/compile-antlr/action.yml +++ b/.github/composite-actions/compile-antlr/action.yml @@ -1,6 +1,10 @@ name: 'Compile ANTLR' inputs: + version: + description: 'version of ANTLR to install' + required: no + default: 4.13.2 install_dir: description: 'Engine install directory' required: no @@ -12,9 +16,12 @@ runs: - name: Compile ANTLR run: | - ANTLR_VERSION=4.9.3 + ANTLR_VERSION=${{inputs.version}} cd contrib/babelfishpg_tsql/antlr/thirdparty/antlr/ + if [ ! -f antlr-$ANTLR_VERSION-complete.jar ]; then + wget "http://www.antlr.org/download/antlr-$ANTLR_VERSION-complete.jar" + fi sudo cp "antlr-$ANTLR_VERSION-complete.jar" /usr/local/lib cd .. wget "http://www.antlr.org/download/antlr4-cpp-runtime-$ANTLR_VERSION-source.zip" diff --git a/.github/composite-actions/dump-restore-util/action.yml b/.github/composite-actions/dump-restore-util/action.yml index a2090c93a7..f2be167391 100644 --- a/.github/composite-actions/dump-restore-util/action.yml +++ b/.github/composite-actions/dump-restore-util/action.yml @@ -33,6 +33,10 @@ inputs: description: "Dump type full or combination of schema-only and data-only" required: false default: 'full' + antlr_version: + description: "ANTLR version to use (based on Extension Branch)" + required: false + default: 4.13.2 runs: using: "composite" @@ -45,6 +49,7 @@ runs: engine_branch: ${{ inputs.engine_branch }} extension_branch: ${{ inputs.extension_branch }} pg_new_dir: ${{ inputs.pg_new_dir }} + antlr_version: ${{ inputs.antlr_version }} - name: Build latest dump/restore utilities id: build-dump-utils diff --git a/.github/composite-actions/major-version-upgrade-util/action.yml b/.github/composite-actions/major-version-upgrade-util/action.yml index 5d969dcb5a..c7de884d34 100644 --- a/.github/composite-actions/major-version-upgrade-util/action.yml +++ b/.github/composite-actions/major-version-upgrade-util/action.yml @@ -22,6 +22,10 @@ inputs: description: "Server collation name" required: false default: "default" + antlr_version: + description: "ANTLR version to use (based on Extension Branch)" + required: false + default: 4.13.2 runs: using: "composite" @@ -34,6 +38,7 @@ runs: engine_branch: ${{ inputs.engine_branch }} extension_branch: ${{ inputs.extension_branch }} pg_new_dir: ${{ inputs.pg_new_dir }} + antlr_version: ${{ inputs.antlr_version }} - name: Run pg_upgrade id: run-pg_upgrade diff --git a/.github/composite-actions/minor-version-upgrade-util/action.yml b/.github/composite-actions/minor-version-upgrade-util/action.yml index 9987f20f65..4a4cd3241f 100644 --- a/.github/composite-actions/minor-version-upgrade-util/action.yml +++ b/.github/composite-actions/minor-version-upgrade-util/action.yml @@ -16,18 +16,33 @@ inputs: description: "Server collation name" required: false default: "default" + antlr_version: + description: "ANTLR version to use (based on Extension Branch)" + required: false + default: 4.13.2 runs: using: "composite" steps: - name: Build and run tests for Postgres engine using ${{ inputs.engine_branch }} + id: build-modified-postgres-new + if: always() uses: ./.github/composite-actions/build-modified-postgres with: engine_branch: ${{ inputs.engine_branch }} install_dir: ${{ inputs.install_dir }} + - name: Compile new ANTLR + id: compile-new-antlr + if: always() && steps.build-modified-postgres-new.outcome == 'success' + uses: ./.github/composite-actions/compile-antlr + with: + version: ${{ inputs.antlr_version }} + install_dir: ${{inputs.install_dir}} + - name: Set env variables and build extensions using ${{ inputs.extension_branch }} id: build-extensions-newer + if: always() && steps.compile-new-antlr.outcome == 'success' uses: ./.github/composite-actions/build-extensions with: install_dir: ${{ inputs.install_dir }} diff --git a/.github/composite-actions/setup-base-version/action.yml b/.github/composite-actions/setup-base-version/action.yml index 0aa7fe5d04..87f0a90446 100644 --- a/.github/composite-actions/setup-base-version/action.yml +++ b/.github/composite-actions/setup-base-version/action.yml @@ -20,6 +20,10 @@ inputs: description: "Whether it is version upgrade or dump/restore" required: false default: 'false' + antlr_version: + description: "ANTLR version to use (based on Extension Branch)" + required: false + default: 4.13.2 runs: using: "composite" @@ -42,6 +46,7 @@ runs: if: always() && steps.build-modified-postgres.outcome == 'success' uses: ./.github/composite-actions/compile-antlr with: + version: ${{ inputs.antlr_version }} install_dir: ${{ inputs.install_dir }} - name: Set env variables and build extensions diff --git a/.github/composite-actions/setup-dump-restore-ca/action.yml b/.github/composite-actions/setup-dump-restore-ca/action.yml index 1ed3e2dc88..d8e3334def 100644 --- a/.github/composite-actions/setup-dump-restore-ca/action.yml +++ b/.github/composite-actions/setup-dump-restore-ca/action.yml @@ -40,6 +40,12 @@ runs: is_final_ver=false; [[ i -eq $LEN-1 ]] && is_final_ver=true pg_old_dir=$(echo psql$(awk -F. '{print $1}' <<< $previous_installed_version)) pg_new_dir=$(echo psql$(awk -F. '{print $1}' <<< $dump_restore_version)) + if [[ "$dump_restore_version" == 'target.latest' || "$dump_restore_version" -ge 16.7 ]] + then + antlr_version=4.13.2 + else + antlr_version=4.9.3 + fi if [[ "$previous_installed_version" == "$dump_restore_version" ]]; then pg_new_dir=$(echo $pg_new_dir.$i) @@ -56,7 +62,7 @@ runs: type_var=".\"dump-restore-version\"[${{ matrix.upgrade-path.id }}][$i].\"type\"" type=$(yq $type_var ${{ github.workspace }}/.github/configuration/dump-restore-test-configuration.yml) - printf " - name: Dump and Restore to version $dump_restore_version\n id: dump-restore-version-$i\n if: always() $temp\n uses: ${uses_file}\n with: \n engine_branch: ${engine_branch}\n extension_branch: ${extension_branch}\n is_final_ver: ${is_final_ver}\n pg_old_dir: ${pg_old_dir}\n pg_new_dir: ${pg_new_dir}\n migration_mode: 'multi-db'\n database_level: ${database_level}\n dump_data_as: ${dump_data_as}\n dump_format: ${dump_format}\n type: ${type}\n\n" >> $dump_restore_version_dir_path/action.yml + printf " - name: Dump and Restore to version $dump_restore_version\n id: dump-restore-version-$i\n if: always() $temp\n uses: ${uses_file}\n with: \n engine_branch: ${engine_branch}\n extension_branch: ${extension_branch}\n is_final_ver: ${is_final_ver}\n pg_old_dir: ${pg_old_dir}\n pg_new_dir: ${pg_new_dir}\n migration_mode: 'multi-db'\n database_level: ${database_level}\n dump_data_as: ${dump_data_as}\n dump_format: ${dump_format}\n type: ${type}\n antlr_version: ${antlr_version}\n\n" >> $dump_restore_version_dir_path/action.yml previous_installed_version=$dump_restore_version done diff --git a/.github/composite-actions/setup-new-version/action.yml b/.github/composite-actions/setup-new-version/action.yml index 2b1378f4cc..2138d1cf41 100644 --- a/.github/composite-actions/setup-new-version/action.yml +++ b/.github/composite-actions/setup-new-version/action.yml @@ -9,6 +9,10 @@ inputs: pg_new_dir: description: "Install new version in this directory" required: true + antlr_version: + description: "ANTLR version to use (based on Extension Branch)" + required: false + default: 4.13.2 runs: using: "composite" @@ -21,15 +25,17 @@ runs: engine_branch: ${{ inputs.engine_branch }} install_dir: ${{ inputs.pg_new_dir }} - - name: Copy ANTLR - id: copy-antlr + - name: Compile new ANTLR + id: compile-new-antlr if: always() && steps.build-modified-postgres-new.outcome == 'success' - run: cp "/usr/local/lib/libantlr4-runtime.so.4.9.3" ~/${{ inputs.pg_new_dir }}/lib/ - shell: bash + uses: ./.github/composite-actions/compile-antlr + with: + version: ${{ inputs.antlr_version }} + install_dir: ${{inputs.pg_new_dir}} - name: Build Extensions id: build-extensions-new - if: always() && steps.copy-antlr.outcome == 'success' + if: always() && steps.compile-new-antlr.outcome == 'success' uses: ./.github/composite-actions/build-extensions with: install_dir: ${{ inputs.pg_new_dir }} diff --git a/.github/composite-actions/setup-upgrade-version-ca/action.yml b/.github/composite-actions/setup-upgrade-version-ca/action.yml index 9ebd3b7ba0..c59d47a56b 100644 --- a/.github/composite-actions/setup-upgrade-version-ca/action.yml +++ b/.github/composite-actions/setup-upgrade-version-ca/action.yml @@ -45,6 +45,12 @@ runs: is_final_ver=false; [[ i -eq $LEN-1 ]] && is_final_ver=true pg_old_dir=$(echo psql$(awk -F. '{print $1}' <<< $previous_installed_version)) pg_new_dir=$(echo psql$(awk -F. '{print $1}' <<< $upgrade_version)) + if [[ "$upgrade_version" == 'target.latest' || "$upgrade_version" -ge 16.7 ]] + then + antlr_version=4.13.2 + else + antlr_version=4.9.3 + fi upgrade_type_var=".\"upgrade-version\"[${{ matrix.upgrade-path.id }}]."upgrade-path"[$i].\"upgrade-type\"" upgrade_type=$(yq $upgrade_type_var ${{ github.workspace }}/.github/configuration/upgrade-test-configuration.yml) @@ -60,9 +66,9 @@ runs: # Appending upgrade step in upgrade-version composite action based on upgrade type if [[ $upgrade_type == 'major' ]] then - printf " - name: Upgrade Version to $upgrade_version\n id: upgrade-version-$i\n if: always() $temp\n uses: ${uses_file}\n with: \n engine_branch: ${engine_branch}\n extension_branch: ${extension_branch}\n is_final_ver: ${is_final_ver}\n pg_old_dir: ${pg_old_dir}\n pg_new_dir: ${pg_new_dir}\n migration_mode: 'multi-db'\n server_collation_name: ${{ inputs.server_collation_name }}\n\n" >> $upgrade_version_dir_path/action.yml + printf " - name: Upgrade Version to $upgrade_version\n id: upgrade-version-$i\n if: always() $temp\n uses: ${uses_file}\n with: \n engine_branch: ${engine_branch}\n extension_branch: ${extension_branch}\n is_final_ver: ${is_final_ver}\n pg_old_dir: ${pg_old_dir}\n pg_new_dir: ${pg_new_dir}\n migration_mode: 'multi-db'\n server_collation_name: ${{ inputs.server_collation_name }}\n antlr_version: ${antlr_version}\n\n" >> $upgrade_version_dir_path/action.yml else - printf " - name: Upgrade Version to $upgrade_version\n id: upgrade-version-$i\n if: always() $temp\n uses: ${uses_file}\n with: \n engine_branch: ${engine_branch}\n extension_branch: ${extension_branch}\n is_final_ver: ${is_final_ver}\n install_dir: ${pg_new_dir}\n server_collation_name: ${{ inputs.server_collation_name }}\n\n" >> $upgrade_version_dir_path/action.yml + printf " - name: Upgrade Version to $upgrade_version\n id: upgrade-version-$i\n if: always() $temp\n uses: ${uses_file}\n with: \n engine_branch: ${engine_branch}\n extension_branch: ${extension_branch}\n is_final_ver: ${is_final_ver}\n install_dir: ${pg_new_dir}\n server_collation_name: ${{ inputs.server_collation_name }}\n antlr_version: ${antlr_version}\n\n" >> $upgrade_version_dir_path/action.yml fi previous_installed_version=$upgrade_version diff --git a/.github/configuration/upgrade-test-configuration.yml b/.github/configuration/upgrade-test-configuration.yml index a54192c0ec..9e60238dab 100644 --- a/.github/configuration/upgrade-test-configuration.yml +++ b/.github/configuration/upgrade-test-configuration.yml @@ -101,7 +101,7 @@ upgrade-version: [{ { upgrade-path: [ { - version: '14.15', + version: '14.16', upgrade-type: null }, { @@ -125,7 +125,7 @@ upgrade-version: [{ { upgrade-path: [ { - version: 15.9, + version: '15.10', upgrade-type: null }, { @@ -161,7 +161,7 @@ upgrade-version: [{ { upgrade-path: [ { - version: 16.5, + version: 16.6, upgrade-type: null }, { @@ -177,11 +177,11 @@ upgrade-version: [{ upgrade-type: null }, { - version: '14.15', + version: '14.16', upgrade-type: major }, { - version: '15.10', + version: '15.11', upgrade-type: major }, { @@ -207,7 +207,7 @@ upgrade-version: [{ { upgrade-path: [ { - version: '15.10', + version: '15.11', upgrade-type: null }, { @@ -220,7 +220,7 @@ upgrade-version: [{ { upgrade-path: [ { - version: '15.10', + version: '15.11', upgrade-type: null }, { @@ -237,7 +237,7 @@ upgrade-version: [{ upgrade-type: null }, { - version: '15.10', + version: '15.11', upgrade-type: minor }, { diff --git a/.github/template/version-branch-template.yml b/.github/template/version-branch-template.yml index 9b967e65c3..eba5f5dd4f 100644 --- a/.github/template/version-branch-template.yml +++ b/.github/template/version-branch-template.yml @@ -46,10 +46,10 @@ '14.13': engine_branch: BABEL_2_10_STABLE__PG_14_13 extension_branch: BABEL_2_10_STABLE -'14.14': - engine_branch: BABEL_2_11_STABLE__PG_14_14 - extension_branch: BABEL_2_11_STABLE '14.15': + engine_branch: BABEL_2_11_STABLE__PG_14_15 + extension_branch: BABEL_2_11_STABLE +'14.16': engine_branch: BABEL_2_X_DEV__PG_14_X extension_branch: BABEL_2_X_DEV '15.2': @@ -73,10 +73,10 @@ '15.8': engine_branch: BABEL_3_7_STABLE__PG_15_8 extension_branch: BABEL_3_7_STABLE -'15.9': - engine_branch: BABEL_3_8_STABLE__PG_15_9 - extension_branch: BABEL_3_8_STABLE '15.10': + engine_branch: BABEL_3_8_STABLE__PG_15_10 + extension_branch: BABEL_3_8_STABLE +'15.11': engine_branch: BABEL_3_X_DEV__PG_15_X extension_branch: BABEL_3_X_DEV '16.1': @@ -91,8 +91,8 @@ '16.4': engine_branch: BABEL_4_3_STABLE__PG_16_4 extension_branch: BABEL_4_3_STABLE -'16.5': - engine_branch: BABEL_4_4_STABLE__PG_16_5 +'16.6': + engine_branch: BABEL_4_4_STABLE__PG_16_6 extension_branch: BABEL_4_4_STABLE 'source.latest': engine_branch: latest diff --git a/.github/workflows/isolation-tests.yml b/.github/workflows/isolation-tests.yml index abbc98a984..af8c7d3916 100644 --- a/.github/workflows/isolation-tests.yml +++ b/.github/workflows/isolation-tests.yml @@ -53,12 +53,12 @@ jobs: curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list cd ~/work/babelfish_extensions/babelfish_extensions/test/python sudo ACCEPT_EULA=Y apt-get install -y msodbcsql17 python3-dev - pip3 install pyodbc pymssql pytest pytest-xdist antlr4-python3-runtime==4.9.3 + pip3 install pyodbc pymssql pytest pytest-xdist antlr4-python3-runtime==4.13.2 - name: Generate .spec file parser run: | cd ~/work/babelfish_extensions/babelfish_extensions/test/python/isolationtest/ - java -Xmx500M -cp /usr/local/lib/antlr-4.9.3-complete.jar org.antlr.v4.Tool -Dlanguage=Python3 ./parser/*.g4 -visitor -no-listener + java -Xmx500M -cp /usr/local/lib/antlr-4.13.2-complete.jar org.antlr.v4.Tool -Dlanguage=Python3 ./parser/*.g4 -visitor -no-listener - name: Run Isolation tests id: run-isolation-tests diff --git a/.github/workflows/major-version-upgrade.yml b/.github/workflows/major-version-upgrade.yml index 6ab90b1bd2..69dc58b3c0 100644 --- a/.github/workflows/major-version-upgrade.yml +++ b/.github/workflows/major-version-upgrade.yml @@ -38,6 +38,7 @@ jobs: if: always() && steps.build-modified-postgres-old.outcome == 'success' uses: ./.github/composite-actions/compile-antlr with: + version: 4.9.3 install_dir: ${{env.OLD_INSTALL_DIR}} - uses: actions/checkout@v2 @@ -136,13 +137,17 @@ jobs: with: install_dir: ${{env.NEW_INSTALL_DIR}} release_mode: 'yes' - - - name: Copy ANTLR - run: cp "/usr/local/lib/libantlr4-runtime.so.4.9.3" ~/${{env.NEW_INSTALL_DIR}}/lib/ + + - name: Compile new ANTLR + id: compile-new-antlr + if: always() && steps.build-modified-postgres-new.outcome == 'success' + uses: ./.github/composite-actions/compile-antlr + with: + install_dir: ${{env.NEW_INSTALL_DIR}} - name: Build Extensions using latest version id: build-extensions-new - if: always() && steps.build-modified-postgres-new.outcome == 'success' + if: always() && steps.compile-new-antlr.outcome == 'success' uses: ./.github/composite-actions/build-extensions with: install_dir: ${{env.NEW_INSTALL_DIR}} diff --git a/.github/workflows/minor-version-upgrade.yml b/.github/workflows/minor-version-upgrade.yml index 873354e4a6..e94fa56b08 100644 --- a/.github/workflows/minor-version-upgrade.yml +++ b/.github/workflows/minor-version-upgrade.yml @@ -29,6 +29,8 @@ jobs: id: compile-antlr if: always() && steps.build-modified-postgres-older.outcome == 'success' uses: ./.github/composite-actions/compile-antlr + with: + version: 4.9.3 - uses: actions/checkout@v2 with: @@ -115,9 +117,15 @@ jobs: id: build-modified-postgres-newer if: always() && steps.install-extensions-older.outcome == 'success' uses: ./.github/composite-actions/build-modified-postgres + + - name: Compile new ANTLR + id: compile-new-antlr + if: always() && steps.build-modified-postgres-newer.outcome == 'success' + uses: ./.github/composite-actions/compile-antlr - name: Set env variables and build extensions id: build-extensions-newer + if: always() && steps.compile-new-antlr.outcome == 'success' uses: ./.github/composite-actions/build-extensions - name: Build PostGIS Extension diff --git a/.github/workflows/pg_dump-restore-test.yml b/.github/workflows/pg_dump-restore-test.yml index 0807cf3dc0..be998791b0 100644 --- a/.github/workflows/pg_dump-restore-test.yml +++ b/.github/workflows/pg_dump-restore-test.yml @@ -74,6 +74,7 @@ jobs: install_dir: ${{ steps.find-branch.outputs.base-dir }} migration_mode: 'multi-db' dump_restore: 'true' + antlr_version: ${{ (steps.read-base-and-final-version.outputs.base-version == 'source.latest' || fromJSON(steps.read-base-and-final-version.outputs.base-version) >= 16.7 ) && '4.13.2' || '4.9.3' }} - name: Setup Dump Restore Composite Action id: setup-dump-restore-ca diff --git a/.github/workflows/singledb-version-upgrade.yml b/.github/workflows/singledb-version-upgrade.yml index a35d90dc18..67bbfd9f94 100644 --- a/.github/workflows/singledb-version-upgrade.yml +++ b/.github/workflows/singledb-version-upgrade.yml @@ -23,6 +23,7 @@ jobs: extension_branch: ${{ env.EXTENSION_BRANCH_FROM }} install_dir: ${{ env.OLD_INSTALL_DIR }} migration_mode: 'single-db' + antlr_version: 4.9.3 - name: Check Babelfish metadata inconsistency before Major Version Upgrade id: check-babelfish-inconsistency diff --git a/.github/workflows/tap-tests.yml b/.github/workflows/tap-tests.yml index 368122de58..e0bc7704dc 100644 --- a/.github/workflows/tap-tests.yml +++ b/.github/workflows/tap-tests.yml @@ -59,6 +59,7 @@ jobs: if: always() && steps.build-modified-postgres-old.outcome == 'success' uses: ./.github/composite-actions/compile-antlr with: + version: 4.9.3 install_dir: ${{env.OLD_INSTALL_DIR}} - name: Build PostGIS Extension using ${{env.EXTENSION_BRANCH_OLD}} @@ -116,13 +117,17 @@ jobs: with: tap_tests: 'yes' install_dir: ${{env.NEW_INSTALL_DIR}} - - - name: Copy ANTLR - run: cp "/usr/local/lib/libantlr4-runtime.so.4.9.3" ~/${{env.NEW_INSTALL_DIR}}/lib/ + + - name: Compile new ANTLR + id: compile-new-antlr + if: always() && steps.build-modified-postgres-new.outcome == 'success' + uses: ./.github/composite-actions/compile-antlr + with: + install_dir: ${{env.NEW_INSTALL_DIR}} - name: Build Extensions using latest version id: build-extensions-new - if: always() && steps.build-modified-postgres-new.outcome == 'success' + if: always() && steps.compile-new-antlr.outcome == 'success' uses: ./.github/composite-actions/build-extensions with: install_dir: ${{env.NEW_INSTALL_DIR}} diff --git a/.github/workflows/upgrade-test.yml b/.github/workflows/upgrade-test.yml index 29b24c9715..ceefda3d17 100644 --- a/.github/workflows/upgrade-test.yml +++ b/.github/workflows/upgrade-test.yml @@ -67,6 +67,7 @@ jobs: install_dir: ${{ steps.find-branch.outputs.base-dir }} migration_mode: 'multi-db' server_collation_name: ${{ matrix.upgrade-path.server_collation_name }} + antlr_version: ${{ (steps.read-base-and-final-version.outputs.base-version == 'source.latest' || fromJSON(steps.read-base-and-final-version.outputs.base-version) >= 16.7 ) && '4.13.2' || '4.9.3' }} - name: Setup Upgrade Version Composite Action id: setup-upgrade-ver-ca diff --git a/INSTALLING.md.tmpl b/INSTALLING.md.tmpl index fbd0bcb795..3d2311ed94 100644 --- a/INSTALLING.md.tmpl +++ b/INSTALLING.md.tmpl @@ -55,19 +55,19 @@ export PG_SRC=$(realpath $PWD) ### Compile ANTLR 4 -Unfortunately, there are [no prebuilt C++ binaries for the Antlr 4.9.3 runtime version](https://www.antlr.org/download.html) for Linux. You will need to compile and install ANTLR manually. +Unfortunately, there are [no prebuilt C++ binaries for the Antlr 4.13.2 runtime version](https://www.antlr.org/download.html) for Linux. You will need to compile and install ANTLR manually. First, define the following variables in your environment: ```sh -export ANTLR4_VERSION=4.9.3 +export ANTLR4_VERSION=4.13.2 export ANTLR4_JAVA_BIN=/usr/bin/java export ANTLR4_RUNTIME_LIBRARIES=/usr/include/antlr4-runtime export ANTLR_EXECUTABLE=/usr/local/lib/antlr-${ANTLR4_VERSION}-complete.jar export ANTLR_RUNTIME=~/antlr4 ``` -The [Antlr 4.9.3 Runtime](https://www.antlr.org/) files are distributed with the Babelfish source code. Use the following commands to copy the files into place: +The [Antlr 4.13.2 Runtime](https://www.antlr.org/) files are distributed with the Babelfish source code. Use the following commands to copy the files into place: ```sh sudo cp ${PG_SRC}/contrib/babelfishpg_tsql/antlr/thirdparty/antlr/antlr-${ANTLR4_VERSION}-complete.jar /usr/local/lib diff --git a/contrib/README.md b/contrib/README.md index c06c57a5ae..04b884c351 100644 --- a/contrib/README.md +++ b/contrib/README.md @@ -72,30 +72,30 @@ The following build instructions comply with Ubuntu 20.04 and Amazon Linux 2 env 2. Install ANTLR - The `babelfishpg_tsql` contrib has a plug-in parser generated by ANTLR, which depends on cmake and `antlr4-cpp-runtime-4.9.3`. Unfortunately, there aren't binaries for [C++ targets available](https://www.antlr.org/download.html). You'll also need have `uuid-devel` installed in order to install `antlr4-cpp-runtime-4.9.3`. + The `babelfishpg_tsql` contrib has a plug-in parser generated by ANTLR, which depends on cmake and `antlr4-cpp-runtime-4.13.2`. Unfortunately, there aren't binaries for [C++ targets available](https://www.antlr.org/download.html). You'll also need have `uuid-devel` installed in order to install `antlr4-cpp-runtime-4.13.2`. First copy the jar file in `contrib/babelfishpg_tsql/antlr/thirdparty/antlr/` to another location: ``` cd babelfish_extensions/contrib/babelfishpg_tsql/antlr/thirdparty/antlr/ - sudo cp antlr-4.9.3-complete.jar /usr/local/lib + sudo cp antlr-4.13.2-complete.jar /usr/local/lib ``` Compile antlr4: ``` - wget http://www.antlr.org/download/antlr4-cpp-runtime-4.9.3-source.zip - unzip -d antlr4 antlr4-cpp-runtime-4.9.3-source.zip + wget http://www.antlr.org/download/antlr4-cpp-runtime-4.13.2-source.zip + unzip -d antlr4 antlr4-cpp-runtime-4.13.2-source.zip cd antlr4 mkdir build && cd build - cmake .. -DANTLR_JAR_LOCATION=/usr/local/lib/antlr-4.9.3-complete.jar -DCMAKE_INSTALL_PREFIX=/usr/local -DWITH_DEMO=True + cmake .. -DANTLR_JAR_LOCATION=/usr/local/lib/antlr-4.13.2-complete.jar -DCMAKE_INSTALL_PREFIX=/usr/local -DWITH_DEMO=True make sudo make install ``` Copy libantlr4-runtime to postgres/lib ``` - cp /usr/local/lib/libantlr4-runtime.so.4.9.3 ~/postgres/lib/ + cp /usr/local/lib/libantlr4-runtime.so.4.13.2 ~/postgres/lib/ ``` - If you come across the error diff --git a/contrib/babelfishpg_tds/src/backend/tds/tdslogin.c b/contrib/babelfishpg_tds/src/backend/tds/tdslogin.c index f69b3b4c17..2bee2e341a 100644 --- a/contrib/babelfishpg_tds/src/backend/tds/tdslogin.c +++ b/contrib/babelfishpg_tds/src/backend/tds/tdslogin.c @@ -1143,6 +1143,17 @@ ProcessLoginFlags(LoginRequest loginInfo) } } +/* + * TdsResetLoginFlags - Resets the session properties which + * we provided during login time. + * Wrapper of ProcessLoginFlags, since we do not expose loginInfo. + */ +void +TdsResetLoginFlags() +{ + ProcessLoginFlags(loginInfo); +} + /* * ProcessLoginInternal - internal workhorse for processing login * request. diff --git a/contrib/babelfishpg_tds/src/backend/tds/tdsprotocol.c b/contrib/babelfishpg_tds/src/backend/tds/tdsprotocol.c index 4ffbcf2f1d..dd6bf5ccd2 100644 --- a/contrib/babelfishpg_tds/src/backend/tds/tdsprotocol.c +++ b/contrib/babelfishpg_tds/src/backend/tds/tdsprotocol.c @@ -154,6 +154,8 @@ ResetTDSConnection(void) TdsResetCache(); TdsResponseReset(); TdsResetBcpOffset(); + TdsResetLoginFlags(); + /* Retore previous isolation level when not called by sys.sp_reset_connection. */ if (!resetTdsConnectionFlag) { diff --git a/contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c b/contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c index 08b6163ff2..a1ab6b92d3 100644 --- a/contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c +++ b/contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c @@ -543,6 +543,19 @@ resolve_numeric_typmod_from_exp(Plan *plan, Node *expr) return -1; switch (nodeTag(expr)) { + case T_Param: + { + Param *param = (Param *) expr; + if (!is_numeric_datatype(param->paramtype)) + { + /* typmod is undefined */ + return -1; + } + else + { + return param->paramtypmod; + } + } case T_Const: { Const *con = (Const *) expr; diff --git a/contrib/babelfishpg_tds/src/include/tds_int.h b/contrib/babelfishpg_tds/src/include/tds_int.h index eb329ed01d..624d47ead8 100644 --- a/contrib/babelfishpg_tds/src/include/tds_int.h +++ b/contrib/babelfishpg_tds/src/include/tds_int.h @@ -311,6 +311,7 @@ extern void TdsSendLoginAck(Port *port); extern uint32_t GetClientTDSVersion(void); extern char *get_tds_login_domainname(void); extern void TdsSetDbContext(void); +extern void TdsResetLoginFlags(void); /* Functions in backend/tds/tdsprotocol.c */ extern int TdsSocketBackend(void); diff --git a/contrib/babelfishpg_tsql/Makefile b/contrib/babelfishpg_tsql/Makefile index c78039e504..74cdd1097c 100644 --- a/contrib/babelfishpg_tsql/Makefile +++ b/contrib/babelfishpg_tsql/Makefile @@ -90,6 +90,7 @@ PG_CXXFLAGS += -Wno-deprecated -Wno-error=attributes -Wno-suggest-attribute=form PG_CXXFLAGS += -Wno-undef -Wall -Wcpp PG_CXXFLAGS += -Wno-register # otherwise C++17 gags on PostgreSQL headers PG_CXXFLAGS += -I$(ANTLR4_RUNTIME_INCLUDE_DIR) +PG_CXXFLAGS += -std=c++17 PG_CFLAGS += -g -Werror -Wfloat-conversion PG_CFLAGS += -fstack-protector-strong PG_CPPFLAGS += -I$(TSQLSRC) -I$(PG_SRC) -DFAULT_INJECTOR -Wfloat-conversion diff --git a/contrib/babelfishpg_tsql/antlr/CMakeLists.txt b/contrib/babelfishpg_tsql/antlr/CMakeLists.txt index 4a6517d231..f6aae70699 100644 --- a/contrib/babelfishpg_tsql/antlr/CMakeLists.txt +++ b/contrib/babelfishpg_tsql/antlr/CMakeLists.txt @@ -3,8 +3,8 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.7 FATAL_ERROR) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake-dir) -# compiler must be 11 or 14 -set(CMAKE_CXX_STANDARD 14) +# compiler must be 17+ to support ANTLR-4.13 +set(CMAKE_CXX_STANDARD 17) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -O2 -ggdb -w -Wno-deprecated") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -O2 -ggdb -w -Wno-deprecated") @@ -17,7 +17,7 @@ include_directories(${MYDIR}) # set variable pointing to the antlr tool that supports C++ # this is not required if the jar file can be found under PATH environment -set(ANTLR_EXECUTABLE ${PROJECT_SOURCE_DIR}/thirdparty/antlr/antlr-4.9.3-complete.jar) +set(ANTLR_EXECUTABLE ${PROJECT_SOURCE_DIR}/thirdparty/antlr/antlr-4.13.2-complete.jar) # add macros to generate ANTLR Cpp code from grammar find_package(ANTLR REQUIRED) diff --git a/contrib/babelfishpg_tsql/antlr/TSqlParser.g4 b/contrib/babelfishpg_tsql/antlr/TSqlParser.g4 index 50a974d5d5..9c66780338 100644 --- a/contrib/babelfishpg_tsql/antlr/TSqlParser.g4 +++ b/contrib/babelfishpg_tsql/antlr/TSqlParser.g4 @@ -358,7 +358,7 @@ raiseerror_statement ; raiseerror_msg - : DECIMAL | char_string | LOCAL_ID + : DECIMAL | char_string | local_id ; raiseerror_option @@ -2004,7 +2004,7 @@ func_body_return_select_body ; func_body_returns_table - : RETURNS LOCAL_ID table_type_definition + : RETURNS local_id table_type_definition (WITH function_option (COMMA function_option)*)? AS? BEGIN sql_clauses* SEMI? END @@ -2031,7 +2031,7 @@ atomic_func_body // CREATE PROC p @p INT NULL --> this appears to be accepted syntax for non-native compiled procs, though formally not allowed procedure_param - : LOCAL_ID AS? data_type VARYING? (NOT? NULL_P)? (EQUAL default_val=expression)? param_option=(OUT | OUTPUT | READONLY)? + : local_id AS? data_type VARYING? (NOT? NULL_P)? (EQUAL default_val=expression)? param_option=(OUT | OUTPUT | READONLY)? ; // drop_procedure_param can be used in a DROP FUNCTION or DROP PROCEDURE command @@ -2640,7 +2640,7 @@ predict_function // https://msdn.microsoft.com/en-us/library/ms188927.aspx declare_statement - : DECLARE LOCAL_ID AS? table_type_definition SEMI? + : DECLARE local_id AS? table_type_definition SEMI? | DECLARE loc+=declare_local (COMMA loc+=declare_local)* SEMI? ; @@ -2842,7 +2842,7 @@ execute_statement_arg ; execute_statement_arg_named - : name=LOCAL_ID EQUAL value=execute_parameter + : name=local_id EQUAL value=execute_parameter ; execute_statement_arg_unnamed @@ -2851,13 +2851,13 @@ execute_statement_arg_unnamed execute_parameter : constant - | LOCAL_ID (OUTPUT | OUT)? + | local_id (OUTPUT | OUT)? | id | DEFAULT ; execute_var_string - : LOCAL_ID + : local_id | char_string ; @@ -3098,21 +3098,21 @@ set_statement // https://msdn.microsoft.com/en-us/library/ms174377.aspx transaction_statement // https://msdn.microsoft.com/en-us/library/ms188386.aspx - : BEGIN DISTRIBUTED (TRAN | TRANSACTION) (id | LOCAL_ID)? SEMI? + : BEGIN DISTRIBUTED (TRAN | TRANSACTION) (id | local_id)? SEMI? // https://msdn.microsoft.com/en-us/library/ms188929.aspx - | BEGIN (TRAN | TRANSACTION) ((id | LOCAL_ID) (WITH MARK char_string)?)? SEMI? + | BEGIN (TRAN | TRANSACTION) ((id | local_id) (WITH MARK char_string)?)? SEMI? // https://msdn.microsoft.com/en-us/library/ms190295.aspx - | COMMIT (TRAN | TRANSACTION) (id | LOCAL_ID)? (WITH LR_BRACKET DELAYED_DURABILITY EQUAL (OFF | ON) RR_BRACKET )? SEMI? + | COMMIT (TRAN | TRANSACTION) (id | local_id)? (WITH LR_BRACKET DELAYED_DURABILITY EQUAL (OFF | ON) RR_BRACKET )? SEMI? // https://msdn.microsoft.com/en-us/library/ms178628.aspx | COMMIT WORK? SEMI? | COMMIT id | ROLLBACK id // https://msdn.microsoft.com/en-us/library/ms181299.aspx - | ROLLBACK (TRAN | TRANSACTION) (id | LOCAL_ID)? SEMI? + | ROLLBACK (TRAN | TRANSACTION) (id | local_id)? SEMI? // https://msdn.microsoft.com/en-us/library/ms174973.aspx | ROLLBACK WORK? SEMI? // https://msdn.microsoft.com/en-us/library/ms188378.aspx - | SAVE (TRAN | TRANSACTION) (id | LOCAL_ID)? SEMI? + | SAVE (TRAN | TRANSACTION) (id | local_id)? SEMI? ; // https://msdn.microsoft.com/en-us/library/ms188366.aspx @@ -3135,7 +3135,7 @@ shutdown_statement ; dbcc_statement - : DBCC CHECKIDENT ( LR_BRACKET table_name_string ( (COMMA NORESEED) | (COMMA RESEED (COMMA MINUS? new_value=(DECIMAL | FLOAT))?) )? RR_BRACKET ) (WITH dbcc_options)? SEMI? + : DBCC CHECKIDENT ( LR_BRACKET dbcc_table_name ( (COMMA NORESEED) | (COMMA RESEED (COMMA MINUS? checkident_new_value)?) )? RR_BRACKET ) (WITH dbcc_options)? SEMI? | DBCC name=dbcc_command ( LR_BRACKET expression_list RR_BRACKET )? (WITH dbcc_options)? SEMI? //These are dbcc commands with strange syntax that doesn't fit the regular dbcc syntax | DBCC SHRINKLOG ( LR_BRACKET SIZE EQUAL (constant_expression| id | DEFAULT) (KB | MB | GB | TB)? RR_BRACKET )? (WITH dbcc_options)? SEMI? @@ -3175,12 +3175,17 @@ dbcc_options : ID (COMMA ID)? ; - -table_name_string +dbcc_table_name : table = id | char_string + | local_id ; +checkident_new_value + : DECIMAL + | FLOAT + | local_id + ; execute_as_clause : (EXECUTE|EXEC) AS (CALLER | SELF | OWNER | char_string) @@ -3459,7 +3464,7 @@ set_offsets_keyword constant_LOCAL_ID : constant - | LOCAL_ID + | local_id ; // https://docs.microsoft.com/en-us/sql/t-sql/language-elements/expressions-transact-sql @@ -4831,6 +4836,7 @@ keyword | PREDICATE | PREDICT | PRIMARY_ROLE + | PRIMARY_SQBRACKET | PRIOR | PRIORITY | PRIORITY_LEVEL diff --git a/contrib/babelfishpg_tsql/antlr/cmake-dir/FindANTLR.cmake b/contrib/babelfishpg_tsql/antlr/cmake-dir/FindANTLR.cmake index 968feded7a..185ea3cd2d 100644 --- a/contrib/babelfishpg_tsql/antlr/cmake-dir/FindANTLR.cmake +++ b/contrib/babelfishpg_tsql/antlr/cmake-dir/FindANTLR.cmake @@ -2,7 +2,7 @@ if(NOT ANTLR_EXECUTABLE) find_program(ANTLR_EXECUTABLE - NAMES antlr.jar antlr4.jar antlr-4.jar antlr-4.9.3-complete.jar) + NAMES antlr.jar antlr4.jar antlr-4.jar antlr-4.13.2-complete.jar) endif() set(Java_JAVA_EXECUTABLE $ENV{ANTLR4_JAVA_BIN}) @@ -18,7 +18,7 @@ if(ANTLR_EXECUTABLE AND Java_JAVA_EXECUTABLE) OUTPUT_STRIP_TRAILING_WHITESPACE) if(ANTLR_COMMAND_RESULT EQUAL 0) - string(REGEX MATCH "Version [0-9]+(\\.[0-9])*" ANTLR_VERSION ${ANTLR_COMMAND_OUTPUT}) + string(REGEX MATCH "Version [0-9]+(\\.[0-9]+)*" ANTLR_VERSION ${ANTLR_COMMAND_OUTPUT}) string(REPLACE "Version " "" ANTLR_VERSION ${ANTLR_VERSION}) else() message( diff --git a/contrib/babelfishpg_tsql/antlr/cmake-dir/README.md b/contrib/babelfishpg_tsql/antlr/cmake-dir/README.md index 0ebe1dd51e..3a4436258a 100644 --- a/contrib/babelfishpg_tsql/antlr/cmake-dir/README.md +++ b/contrib/babelfishpg_tsql/antlr/cmake-dir/README.md @@ -31,7 +31,7 @@ include_directories(${ANTLR4_INCLUDE_DIRS}) # set variable pointing to the antlr tool that supports C++ # this is not required if the jar file can be found under PATH environment -set(ANTLR_EXECUTABLE /home/user/antlr-4.9.3-complete.jar) +set(ANTLR_EXECUTABLE /home/user/antlr-4.13.2-complete.jar) # add macros to generate ANTLR Cpp code from grammar find_package(ANTLR REQUIRED) diff --git a/contrib/babelfishpg_tsql/antlr/thirdparty/antlr/antlr-4.13.2-complete.jar b/contrib/babelfishpg_tsql/antlr/thirdparty/antlr/antlr-4.13.2-complete.jar new file mode 100644 index 0000000000..75bfcc3976 Binary files /dev/null and b/contrib/babelfishpg_tsql/antlr/thirdparty/antlr/antlr-4.13.2-complete.jar differ diff --git a/contrib/babelfishpg_tsql/antlr/thirdparty/antlr/antlr-4.9.3-complete.jar b/contrib/babelfishpg_tsql/antlr/thirdparty/antlr/antlr-4.9.3-complete.jar deleted file mode 100644 index 749296fe7b..0000000000 Binary files a/contrib/babelfishpg_tsql/antlr/thirdparty/antlr/antlr-4.9.3-complete.jar and /dev/null differ diff --git a/contrib/babelfishpg_tsql/sql/sys_functions.sql b/contrib/babelfishpg_tsql/sql/sys_functions.sql index 20a7f613a6..06677db52c 100644 --- a/contrib/babelfishpg_tsql/sql/sys_functions.sql +++ b/contrib/babelfishpg_tsql/sql/sys_functions.sql @@ -5422,3 +5422,7 @@ CREATE OR REPLACE AGGREGATE sys.string_agg(sys.NVARCHAR, sys.VARCHAR) ( PARALLEL = SAFE ); +/* Helper function to update local variables dynamically during execution */ +CREATE OR REPLACE FUNCTION sys.pltsql_assign_var(dno INT, val ANYELEMENT) +RETURNS ANYELEMENT +AS 'babelfishpg_tsql', 'pltsql_assign_var' LANGUAGE C PARALLEL UNSAFE; diff --git a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--4.4.0--4.5.0.sql b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--4.4.0--4.5.0.sql index 9d5a796674..91bfb6f9d7 100644 --- a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--4.4.0--4.5.0.sql +++ b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--4.4.0--4.5.0.sql @@ -55,6 +55,21 @@ END; $$; +/* Helper function to update local variables dynamically during execution */ +CREATE OR REPLACE FUNCTION sys.pltsql_assign_var(dno INT, val ANYELEMENT) +RETURNS ANYELEMENT +AS 'babelfishpg_tsql', 'pltsql_assign_var' LANGUAGE C PARALLEL UNSAFE; + +-- This is a temporary procedure which is only meant to be called during upgrade +CREATE OR REPLACE PROCEDURE sys.babelfish_revoke_guest_from_mapped_logins() +LANGUAGE C +AS 'babelfishpg_tsql', 'revoke_guest_from_mapped_logins'; + +CALL sys.babelfish_revoke_guest_from_mapped_logins(); + +-- Drop this procedure after it gets executed once. +DROP PROCEDURE sys.babelfish_revoke_guest_from_mapped_logins(); + -- After upgrade, always run analyze for all babelfish catalogs. CALL sys.analyze_babelfish_catalogs(); diff --git a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--4.4.0--5.0.0.sql b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--4.4.0--5.0.0.sql index 4fde302d1a..394d92490c 100644 --- a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--4.4.0--5.0.0.sql +++ b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--4.4.0--5.0.0.sql @@ -81,6 +81,62 @@ BEGIN END; $$; +-- Update all grants to babelfish users to make bbf_role_admin as grantor. +DO +LANGUAGE plpgsql +$$ +DECLARE + temprow RECORD; + query TEXT; + init_user NAME; +BEGIN + SELECT r.rolname + INTO init_user + FROM pg_roles r + INNER JOIN pg_database d + ON r.oid = d.datdba + WHERE d.datname = current_database(); + + FOR temprow IN + WITH bbf_catalog AS ( + SELECT r.oid AS roleid, ext1.rolname + FROM sys.babelfish_authid_login_ext ext1 + INNER JOIN pg_roles r ON ext1.rolname = r.rolname + WHERE r.rolname != init_user + UNION + SELECT r.oid AS roleid, ext2.rolname + FROM sys.babelfish_authid_user_ext ext2 + INNER JOIN pg_roles r ON ext2.rolname = r.rolname + ) + SELECT cat.rolname AS rolname, cat2.rolname AS member, am.grantor::regrole + FROM pg_auth_members am + INNER JOIN bbf_catalog cat ON am.roleid = cat.roleid + INNER JOIN bbf_catalog cat2 ON am.member = cat2.roleid + WHERE am.admin_option = 'f' + AND am.grantor != 'bbf_role_admin'::regrole + LOOP + -- First revoke the existing grant + query := pg_catalog.format('REVOKE %I FROM %I GRANTED BY %s;', temprow.rolname, temprow.member, temprow.grantor); + EXECUTE query; + -- Now create the grant with bbf_role_admin as grantor + query := pg_catalog.format('GRANT %I TO %I GRANTED BY bbf_role_admin;', temprow.rolname, temprow.member); + EXECUTE query; + END LOOP; +END; +$$; + +/* Helper function to update local variables dynamically during execution */ +CREATE OR REPLACE FUNCTION sys.pltsql_assign_var(dno INT, val ANYELEMENT) +RETURNS ANYELEMENT +AS 'babelfishpg_tsql', 'pltsql_assign_var' LANGUAGE C PARALLEL UNSAFE; + +-- This is a temporary procedure which is only meant to be called during upgrade +CREATE OR REPLACE PROCEDURE sys.babelfish_revoke_guest_from_mapped_logins() +LANGUAGE C +AS 'babelfishpg_tsql', 'revoke_guest_from_mapped_logins'; + +CALL sys.babelfish_revoke_guest_from_mapped_logins(); + /* * Do this so that whenever we run grant statements during create logical database * bbf_role_admin is never picked as the grantor diff --git a/contrib/babelfishpg_tsql/src/catalog.c b/contrib/babelfishpg_tsql/src/catalog.c index 06d7825b7b..cad3ef2ec8 100644 --- a/contrib/babelfishpg_tsql/src/catalog.c +++ b/contrib/babelfishpg_tsql/src/catalog.c @@ -958,10 +958,10 @@ get_authid_user_ext_physical_name(const char *db_name, const char *login) { Relation bbf_authid_user_ext_rel; HeapTuple tuple_user_ext; - ScanKeyData key[2]; TableScanDesc scan; char *user_name = NULL; NameData *login_name; + ScanKeyData key[2]; if (!db_name || !login) return NULL; @@ -971,38 +971,24 @@ get_authid_user_ext_physical_name(const char *db_name, const char *login) login_name = (NameData *) palloc0(NAMEDATALEN); snprintf(login_name->data, NAMEDATALEN, "%s", login); + ScanKeyInit(&key[0], - Anum_bbf_authid_user_ext_login_name, - BTEqualStrategyNumber, F_NAMEEQ, - NameGetDatum(login_name)); + Anum_bbf_authid_user_ext_login_name, + BTEqualStrategyNumber, F_NAMEEQ, + NameGetDatum(login_name)); ScanKeyInit(&key[1], - Anum_bbf_authid_user_ext_database_name, - BTEqualStrategyNumber, F_TEXTEQ, - CStringGetTextDatum(db_name)); - + Anum_bbf_authid_user_ext_database_name, + BTEqualStrategyNumber, F_TEXTEQ, + CStringGetTextDatum(db_name)); scan = table_beginscan_catalog(bbf_authid_user_ext_rel, 2, key); tuple_user_ext = heap_getnext(scan, ForwardScanDirection); if (HeapTupleIsValid(tuple_user_ext)) { - Datum datum; - bool user_can_connect; - bool isnull; - - datum = heap_getattr(tuple_user_ext, Anum_bbf_authid_user_ext_user_can_connect, - RelationGetDescr(bbf_authid_user_ext_rel), &isnull); - Assert(!isnull); - user_can_connect = DatumGetInt32(datum); - - /* db_accessadmin members should always have connect permissions */ - if (user_can_connect == 1 || - (has_privs_of_role(get_role_oid(login, false), get_db_accessadmin_oid(db_name, false)))) - { - datum = heap_getattr(tuple_user_ext, Anum_bbf_authid_user_ext_rolname, - RelationGetDescr(bbf_authid_user_ext_rel), &isnull); - Assert(!isnull); - user_name = pstrdup(DatumGetCString(datum)); - } + Form_authid_user_ext userform; + + userform = (Form_authid_user_ext) GETSTRUCT(tuple_user_ext); + user_name = pstrdup(NameStr(userform->rolname)); } table_endscan(scan); @@ -1113,6 +1099,28 @@ get_authid_user_ext_db_users(const char *db_name, const char *dbo_name, Oid db_o return db_users_list; } +/* Checks if the user is enabled on a given database. */ +static bool +user_has_dbaccess(const char *user, const char *db_name) +{ + HeapTuple tuple; + bool has_access = false; + tuple = SearchSysCache1(AUTHIDUSEREXTROLENAME, CStringGetDatum(user)); + + if (HeapTupleIsValid(tuple)) + { + bool isnull = true; + int user_can_connect = 0; + Datum datum = SysCacheGetAttr(AUTHIDUSEREXTROLENAME, tuple, Anum_bbf_authid_user_ext_user_can_connect, &isnull); + Assert(!isnull); + user_can_connect = DatumGetInt32(datum); + if (user_can_connect == 1 || has_privs_of_role(get_role_oid(user, false), get_db_accessadmin_oid(db_name, false))) + has_access = true; + ReleaseSysCache(tuple); + } + return has_access; +} + /* * Checks if there exists any user for respective database and login, * if there is not any then use dbo or guest user. @@ -1130,6 +1138,9 @@ get_user_for_database(const char *db_name) user = get_authid_user_ext_physical_name(db_name, login); login_is_db_owner = 0 == strncmp(login, get_owner_of_db(db_name), NAMEDATALEN); + if (user && !user_has_dbaccess(user, db_name) && !guest_has_dbaccess((char *) db_name)) + user = NULL; + if (!user) { Oid datdba; @@ -3177,7 +3188,7 @@ create_guest_role_for_db(const char *dbname) if (list_length(logins) > 0) { stmt = parsetree_nth_stmt(res, i++); - update_GrantRoleStmt(stmt, list_make1(make_accesspriv_node(guest)), logins); + update_GrantRoleStmt(stmt, list_make1(make_accesspriv_node(guest)), logins, NULL); } GetUserIdAndSecContext(&save_userid, &save_sec_context); diff --git a/contrib/babelfishpg_tsql/src/collation.c b/contrib/babelfishpg_tsql/src/collation.c index 66bd381f7e..cd90bfd506 100644 --- a/contrib/babelfishpg_tsql/src/collation.c +++ b/contrib/babelfishpg_tsql/src/collation.c @@ -1136,6 +1136,16 @@ pltsql_planner_node_transformer(PlannerInfo *root, Node *expr, int kind) { + /* + * check if this is called to reset saved expression kind. Quickly return if so. + */ + if (kind == -1) + { + Assert(expr == NULL); + saved_expr_kind = -1; + return NULL; + } + /* * Fall out quickly if expression is empty. */ @@ -1144,6 +1154,7 @@ pltsql_planner_node_transformer(PlannerInfo *root, if (EXPRKIND_TARGET == kind) { + saved_expr_kind = EXPRKIND_TARGET; /* * If expr is NOT a Boolean expression then recurse through its * expresion tree diff --git a/contrib/babelfishpg_tsql/src/dbcmds.c b/contrib/babelfishpg_tsql/src/dbcmds.c index 9807d68d7f..6d80cc24a0 100644 --- a/contrib/babelfishpg_tsql/src/dbcmds.c +++ b/contrib/babelfishpg_tsql/src/dbcmds.c @@ -193,7 +193,7 @@ gen_createdb_subcmds(const char *dbname, const char *owner) /* Grant dbo role to owner */ stmt = parsetree_nth_stmt(res, i++); update_GrantRoleStmt(stmt, list_make1(make_accesspriv_node(dbo)), - list_make1(make_rolespec_node(owner))); + list_make1(make_rolespec_node(owner)), NULL); } stmt = parsetree_nth_stmt(res, i++); @@ -228,7 +228,7 @@ gen_createdb_subcmds(const char *dbname, const char *owner) if (list_length(logins) > 0) { stmt = parsetree_nth_stmt(res, i++); - update_GrantRoleStmt(stmt, list_make1(make_accesspriv_node(guest)), logins); + update_GrantRoleStmt(stmt, list_make1(make_accesspriv_node(guest)), logins, NULL); } } diff --git a/contrib/babelfishpg_tsql/src/guc.c b/contrib/babelfishpg_tsql/src/guc.c index 518e904ab6..d3cf909523 100644 --- a/contrib/babelfishpg_tsql/src/guc.c +++ b/contrib/babelfishpg_tsql/src/guc.c @@ -14,6 +14,7 @@ #define PLTSQL_SESSION_ISOLATION_LEVEL "default_transaction_isolation" #define PLTSQL_TRANSACTION_ISOLATION_LEVEL "transaction_isolation" +#define PLTSQL_MIGRATION_MODE "babelfishpg_tsql.migration_mode" #define PLTSQL_DEFAULT_LANGUAGE "us_english" static int migration_mode = SINGLE_DB; @@ -1657,7 +1658,9 @@ void pltsql_validate_set_config_function(char *name, char *value) { if (strncmp(name, PLTSQL_SESSION_ISOLATION_LEVEL, strlen(PLTSQL_SESSION_ISOLATION_LEVEL)) == 0 || - strncmp(name, PLTSQL_TRANSACTION_ISOLATION_LEVEL, strlen(PLTSQL_TRANSACTION_ISOLATION_LEVEL)) == 0) + strncmp(name, PLTSQL_TRANSACTION_ISOLATION_LEVEL, strlen(PLTSQL_TRANSACTION_ISOLATION_LEVEL)) == 0 || + strncmp(name, PLTSQL_MIGRATION_MODE, strlen(PLTSQL_MIGRATION_MODE)) == 0 || + strncmp(name, "role", strlen("role")) == 0) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), diff --git a/contrib/babelfishpg_tsql/src/pl_comp.c b/contrib/babelfishpg_tsql/src/pl_comp.c index db0d3e0282..7ccc2380fe 100644 --- a/contrib/babelfishpg_tsql/src/pl_comp.c +++ b/contrib/babelfishpg_tsql/src/pl_comp.c @@ -535,8 +535,16 @@ do_compile(FunctionCallInfo fcinfo, */ if (function->is_mstvf) { + /* + * For a user-defined @@var or @var# name, + * delimit with square brackets + */ + char *typname_fmt = "%s.\"%s\""; + if (!is_tsql_atatuservar(argdtype->typname)) + typname_fmt = pstrdup("%s.%s"); + tbl_dno = argvariable->dno; - tbl_typ = psprintf("%s.%s", + tbl_typ = psprintf(typname_fmt, get_namespace_name( get_rel_namespace(get_typ_typrelid(argtypeid))), argdtype->typname); diff --git a/contrib/babelfishpg_tsql/src/pl_exec-2.c b/contrib/babelfishpg_tsql/src/pl_exec-2.c index 7bc268f911..42e098f12c 100644 --- a/contrib/babelfishpg_tsql/src/pl_exec-2.c +++ b/contrib/babelfishpg_tsql/src/pl_exec-2.c @@ -132,6 +132,9 @@ static bool prev_insert_bulk_check_constraints = false; /* return a underlying node if n is implicit casting and underlying node is a certain type of node */ static Node *get_underlying_node_from_implicit_casting(Node *n, NodeTag underlying_nodetype); + +/* Enclose a user-defined @@var or @var# name in delimiters */ +static char *delimit_tsql_atatuservar(const char *src); /* * The pltsql_proc_return_code global variable is used to record the @@ -883,6 +886,17 @@ exec_stmt_exec(PLtsql_execstate *estate, PLtsql_stmt_exec *stmt) else estate->schema_name = NULL; + /* + * We need to disable the explain gucs incase of sp_reset_connection + * execution otherwise we will get explain output for it which is + * not intended. + */ + if (strcmp(stmt->proc_name, "sp_reset_connection") == 0) + { + pltsql_explain_only = false; + pltsql_explain_analyze = false; + } + /* PG_TRY to ensure we clear the plan link, if needed, on failure */ PG_TRY(); { @@ -943,7 +957,7 @@ exec_stmt_exec(PLtsql_execstate *estate, PLtsql_stmt_exec *stmt) stmt->is_scalar_func = is_scalar_func; - /* T-SQL doesn't allow call procedure in function */ + /* T-SQL doesn't allow procedure calls in a function */ if (estate->func && estate->func->fn_oid != InvalidOid && estate->func->fn_prokind == PROKIND_FUNCTION && estate->func->fn_is_trigger == PLTSQL_NOT_TRIGGER /* check EXEC is running * in the body of * function */ @@ -1365,6 +1379,7 @@ static int exec_stmt_decl_table(PLtsql_execstate *estate, PLtsql_stmt_decl_table *stmt) { char *tblname; + char *tblname_create; char *query; PLtsql_tbl *var = (PLtsql_tbl *) (estate->datums[stmt->dno]); int rc; @@ -1389,8 +1404,8 @@ exec_stmt_decl_table(PLtsql_execstate *estate, PLtsql_stmt_decl_table *stmt) /* * If the original refname was already >=63 characters (the max limit of PG identifiers), - * then the above construction of tblname will be >63 characters, which will violate the - * max length of PG identiefiers and cause issues down the road. Fix this by truncating + * then the above construction of tblname will be >63 characters, which will exceed the + * max length of PG identifiers and cause issues down the road. Fix this by truncating * tblname so that adding the "_<@@nestlevel>" suffix will be exactly 63 characters. */ if (strlen(tblname) >= NAMEDATALEN) @@ -1401,12 +1416,20 @@ exec_stmt_decl_table(PLtsql_execstate *estate, PLtsql_stmt_decl_table *stmt) tblname = psprintf("%s_%d", tblname, estate->nestlevel); } + /* + * Add delimiters for valid T-SQL variable names like @@var or @var# + */ + if (is_tsql_atatuservar(tblname)) + tblname_create = psprintf("[%s]", tblname); + else + tblname_create = psprintf("%s", tblname); + if (stmt->tbltypname) query = psprintf("CREATE TEMPORARY TABLE IF NOT EXISTS %s (like %s including all)", - tblname, stmt->tbltypname); + tblname_create, stmt->tbltypname); else query = psprintf("CREATE TEMPORARY TABLE IF NOT EXISTS %s%s", - tblname, stmt->coldef); + tblname_create, stmt->coldef); /* * If a table with the same name already exists, we should just use @@ -1475,7 +1498,15 @@ exec_stmt_return_table(PLtsql_execstate *estate, PLtsql_stmt_return_query *stmt) oldcontext = MemoryContextSwitchTo(estate->func->fn_cxt); expr = palloc0(sizeof(PLtsql_expr)); - expr->query = psprintf("select * from %s", tbl->tblname); + + /* + * Add delimiters for valid T-SQL variable names like @@var or @var# + */ + if (is_tsql_atatuservar(tbl->tblname)) + expr->query = psprintf("select * from [%s]", tbl->tblname); + else + expr->query = psprintf("select * from %s", tbl->tblname); + expr->plan = NULL; expr->paramnos = NULL; expr->rwparam = -1; @@ -1804,6 +1835,14 @@ exec_stmt_exec_sp(PLtsql_execstate *estate, PLtsql_stmt_exec_sp *stmt) char *querystr; int ret = 0; + /* T-SQL doesn't allow procedure calls in a function */ + if (estate->func && estate->func->fn_oid != InvalidOid && estate->func->fn_prokind == PROKIND_FUNCTION && estate->func->fn_is_trigger == PLTSQL_NOT_TRIGGER) + { + ereport(ERROR, + (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION), + errmsg("Only functions can be executed within a function"))); + } + switch (stmt->sp_type_code) { case PLTSQL_EXEC_SP_CURSOR: @@ -2494,6 +2533,179 @@ is_char_identpart(char c) (c >= '0' && c <= '9')); } +/* + * Check for allowed chars in @variable name + * ToDo: support non-standard ASCII chars (Unicode ranges) + * and align with is_identifier_char() + */ +static inline bool +is_variable_name_char(unsigned char c) +{ + bool valid = ( + isalpha(c) || + isdigit(c) || + c == '_' || + c == '@' || + c == '$' || + c == '#' + ); + + return valid; +} + +/* + * Put delimiters around a T-SQL variable/parameter that is + * named '@@var' or contains a hash, e.g. '@var#'. + * Without delimiters, the backend will raise an error. + * This is used for the parameter argument of sp_executesql, so the input + * string may contain multiple names, e.g.: @par1 int, @par2 varchar(20), ... + * This function calls palloc() to allocate a new string and returns a pointer + * to this string. + */ +static char * +delimit_tsql_atatuservar(const char *src) +{ + char *s = (char *) src; + char *varname_start = NULL; + bool add_delimiter = false; + + /* + * Reserving twice the amount of space of the input string: since the shortest possible + * parameter definition is 5 characters ('@@p x' , where x would be the type), this will + * always be enough for adding delimiters. + * Note that there can be multiple parameter names in the input string. + */ + char *result = (char *) palloc(sizeof(char)*strlen(src)*2); + char *tgt = result; + + while (*s) + { + /* Look for start of variable name, which is always '@' */ + if (*s != '@') + { + *tgt++ = *s++; + continue; + } + + /* Start of variable name found */ + add_delimiter = false; + + varname_start = s; + + /* Name starting with @@ */ + if (*(s+1)) + { + if (*(s+1) == '@') + { + add_delimiter = true; + } + } + + /* Find end of variable name */ + while (*s) + { + /* Check for allowed chars in @variable name */ + if (is_variable_name_char(*s)) + { + /* Name contains # */ + if (*s == '#') + { + add_delimiter = true; + } + + s++; + } + else + { + break; + } + } + + if (varname_start != src) + { + /* + * Do not add delimiters if the name is already delimited. + * Both square brackets and double quotes are used as delimiters for variable names. + */ + if ((*(varname_start-1) == '[') || (*(varname_start-1) == '"')) + { + add_delimiter = false; + } + } + + // Add delimiters to the name if required + if (add_delimiter) *tgt++ = '['; + while (varname_start != s) + { + *tgt++ = *varname_start++; + } + if (add_delimiter) *tgt++ = ']'; + } /* while */ + + *tgt = '\0'; + return result; +} + +/* + * Determine whether the passed name is a T-SQL variable/parameter name that is + * named '@@var' or contains a hash, e.g. '@var#'. + */ +bool +is_tsql_atatuservar(const char *varname) +{ + char *s = (char *) varname; + bool is_atatuservar = false; + + /* The variable names we're looking for are at least 3 chars */ + if (strlen(varname) <= 2) + { + return false; + } + + /* Variable name must start with '@' */ + if (*s != '@') + { + return false; + } + + /* Starts with '@@' ? */ + s++; + if (*s == '@') + { + is_atatuservar = true; + } + + while (*s) + { + /* Check for allowed chars in @variable name */ + if (is_variable_name_char(*s)) + { + /* Name contains # */ + if (*s == '#') + { + is_atatuservar = true; + } + + s++; + } + else + { + return false; + } + } /* while */ + + /* + * The variable name should continue until end of string; if not, + * something is wrong + * + * NB: The assertion below is logically true given the loop above, + * but kept in the code for clarity. + */ + Assert(*s == '\0'); + + return is_atatuservar; +} + /* * Read parameter definitions */ @@ -2519,10 +2731,11 @@ read_param_def(InlineCodeBlockArgs *args, const char *paramdefstr) /* * Create a fake CREATE PROCEDURE statement to get the param definition * parse tree. + * Delimiters will be applied around parameter names like @@par or @par#. */ initStringInfo(&proc_stmt); appendStringInfoString(&proc_stmt, str1); - appendStringInfoString(&proc_stmt, paramdefstr); + appendStringInfoString(&proc_stmt, delimit_tsql_atatuservar(paramdefstr)); appendStringInfoString(&proc_stmt, str2); parsetree = raw_parser(proc_stmt.data, RAW_PARSE_DEFAULT); @@ -3915,10 +4128,10 @@ exec_stmt_change_dbowner(PLtsql_execstate *estate, PLtsql_stmt_change_dbowner *s SetUserIdAndSecContext(get_bbf_role_admin_oid(), save_sec_context | SECURITY_LOCAL_USERID_CHANGE); /* Revoke dbo role from the previous owner */ - grant_revoke_dbo_to_login(get_owner_of_db(stmt->db_name), stmt->db_name, false); + grant_revoke_role_to_login(get_owner_of_db(stmt->db_name), get_dbo_role_name(stmt->db_name), NULL, false); /* Grant dbo role to the new owner */ - grant_revoke_dbo_to_login(stmt->new_owner_name, stmt->db_name, true); + grant_revoke_role_to_login(stmt->new_owner_name, get_dbo_role_name(stmt->db_name), NULL, true); update_db_owner(stmt->new_owner_name, stmt->db_name); } PG_FINALLY(); diff --git a/contrib/babelfishpg_tsql/src/pl_exec.c b/contrib/babelfishpg_tsql/src/pl_exec.c index f0dae9ebd7..40be3ec60e 100644 --- a/contrib/babelfishpg_tsql/src/pl_exec.c +++ b/contrib/babelfishpg_tsql/src/pl_exec.c @@ -62,7 +62,6 @@ #include "guc.h" #include "multidb.h" #include "session.h" -#include "guc.h" #include "catalog.h" uint64 rowcount_var = 0; @@ -70,6 +69,7 @@ List *columns_updated_list = NIL; static char *original_query_string = NULL; int fetch_status_var = 0; +int saved_expr_kind = -1; typedef struct { @@ -4368,6 +4368,7 @@ pltsql_estate_setup(PLtsql_execstate *estate, pltsql_init_exec_error_data(&(es_cs_entry->error_data)); es_cs_entry->next = exec_state_call_stack; exec_state_call_stack = es_cs_entry; + saved_expr_kind = -1; } /* ---------- @@ -7858,12 +7859,22 @@ pltsql_param_fetch(ParamListInfo params, } } + if (saved_expr_kind == EXPRKIND_TARGET) + { + /* Let extension to set value of param dynamically during execution when variables appears in TargetList */ + prm->pflags = 0; + } + else + { + /* For other cases, for example, Quals, we can always mark params as "const" for executor's purposes */ + prm->pflags = PARAM_FLAG_CONST; + } + /* Return "no such parameter" if not ok */ if (!ok) { prm->value = (Datum) 0; prm->isnull = true; - prm->pflags = 0; prm->ptype = InvalidOid; return prm; } @@ -7872,8 +7883,6 @@ pltsql_param_fetch(ParamListInfo params, exec_eval_datum(estate, datum, &prm->ptype, &prmtypmod, &prm->value, &prm->isnull); - /* We can always mark params as "const" for executor's purposes */ - prm->pflags = PARAM_FLAG_CONST; /* * If it's a read/write expanded datum, convert reference to read-only, @@ -10110,7 +10119,6 @@ pltsql_clean_table_variables(PLtsql_execstate *estate, PLtsql_function *func) int rc; PLtsql_tbl *tbl; bool old_pltsql_explain_only = pltsql_explain_only; - const char *query_fmt = "DROP TABLE %s"; const char *query; bool old_abort_curr_txn = AbortCurTransaction; @@ -10132,7 +10140,13 @@ pltsql_clean_table_variables(PLtsql_execstate *estate, PLtsql_function *func) if (!tbl->need_drop) continue; - query = psprintf(query_fmt, tbl->tblname); + /* + * Use delimiters for names like @@var or @var# + */ + if (is_tsql_atatuservar(tbl->tblname)) + query = psprintf("DROP TABLE [%s]", tbl->tblname); + else + query = psprintf("DROP TABLE %s", tbl->tblname); pltsql_explain_only = false; /* Drop temporary table even in * EXPLAIN ONLY mode */ @@ -10423,3 +10437,38 @@ pltsql_exec_function_cleanup(PLtsql_execstate *estate, PLtsql_function *func, Er } PG_END_TRY(); } + +PG_FUNCTION_INFO_V1(pltsql_assign_var); + +/* + * pltsql_assign_var - Helper function to update local variables dynamically during execution. + * Any statement which updates local variables as part of TargetList will be re-written using + * this function. for example, + * @var = expr will be re-written to @var=sys.pltsql_assign_var(dno, cast((expr) as type)). + */ +Datum +pltsql_assign_var(PG_FUNCTION_ARGS) +{ + int dno = PG_GETARG_INT32(0); + Datum data = PG_GETARG_DATUM(1); + Oid valtype = get_fn_expr_argtype(fcinfo->flinfo, 1); + bool isNull = PG_ARGISNULL(1); + int32 valtypmod = -1; + PLtsql_datum *target; + MemoryContext oldcontext; + + PLtsql_execstate *estate = get_current_tsql_estate(); + Assert(estate != NULL); + oldcontext = MemoryContextSwitchTo(estate->datum_context); + target = estate->datums[dno]; + + /* we will reuse exec_assign_value function here provided in pl_exec.c */ + exec_assign_value(estate, target, data, isNull, valtype, valtypmod); + + MemoryContextSwitchTo(oldcontext); + + if (isNull) + PG_RETURN_NULL(); + + PG_RETURN_DATUM(data); +} \ No newline at end of file diff --git a/contrib/babelfishpg_tsql/src/pl_funcs-2.c b/contrib/babelfishpg_tsql/src/pl_funcs-2.c index 12774b168c..618db9ebb5 100644 --- a/contrib/babelfishpg_tsql/src/pl_funcs-2.c +++ b/contrib/babelfishpg_tsql/src/pl_funcs-2.c @@ -405,6 +405,57 @@ check_restricted_stored_procedure(Oid proc_id) } } +/* Determine whether a variable name is a predefined T-SQL global variable */ +bool +is_tsql_atatglobalvar(const char *varname) +{ + size_t varname_len = strlen(varname); + if ((varname_len < 6) || (varname_len > 18)) + return false; + + // List of all T-SQL global "@@" variables: + if ( + (pg_strcasecmp("@@CONNECTIONS", varname) == 0) || + (pg_strcasecmp("@@CPU_BUSY", varname) == 0) || + (pg_strcasecmp("@@CURSOR_ROWS", varname) == 0) || + (pg_strcasecmp("@@DATEFIRST", varname) == 0) || + (pg_strcasecmp("@@DBTS", varname) == 0) || + (pg_strcasecmp("@@ERROR", varname) == 0) || + (pg_strcasecmp("@@PGERROR", varname) == 0) || // added by Babelfish + (pg_strcasecmp("@@FETCH_STATUS", varname) == 0) || + (pg_strcasecmp("@@IDENTITY", varname) == 0) || + (pg_strcasecmp("@@IDLE", varname) == 0) || + (pg_strcasecmp("@@IO_BUSY", varname) == 0) || + (pg_strcasecmp("@@LANGID", varname) == 0) || + (pg_strcasecmp("@@LANGUAGE", varname) == 0) || + (pg_strcasecmp("@@LOCK_TIMEOUT", varname) == 0) || + (pg_strcasecmp("@@MAX_CONNECTIONS", varname) == 0) || + (pg_strcasecmp("@@MAX_PRECISION", varname) == 0) || + (pg_strcasecmp("@@NESTLEVEL", varname) == 0) || + (pg_strcasecmp("@@OPTIONS", varname) == 0) || + (pg_strcasecmp("@@PACKET_ERRORS", varname) == 0) || + (pg_strcasecmp("@@PACK_RECEIVED", varname) == 0) || + (pg_strcasecmp("@@PACK_SENT", varname) == 0) || + (pg_strcasecmp("@@PROCID", varname) == 0) || + (pg_strcasecmp("@@REMSERVER", varname) == 0) || + (pg_strcasecmp("@@ROWCOUNT", varname) == 0) || + (pg_strcasecmp("@@SERVERNAME", varname) == 0) || + (pg_strcasecmp("@@SERVICENAME", varname) == 0) || + (pg_strcasecmp("@@SPID", varname) == 0) || + (pg_strcasecmp("@@TEXTSIZE", varname) == 0) || + (pg_strcasecmp("@@TIMETICKS", varname) == 0) || + (pg_strcasecmp("@@TOTAL_ERRORS", varname) == 0) || + (pg_strcasecmp("@@TOTAL_READ", varname) == 0) || + (pg_strcasecmp("@@TOTAL_WRITE", varname) == 0) || + (pg_strcasecmp("@@TRANCOUNT", varname) == 0) || + (pg_strcasecmp("@@VERSION", varname) == 0) || + (pg_strcasecmp("@@MICROSOFTVERSION", varname) == 0) + ) + return true; + else + return false; +} + /*********************************************************************************** * FREE FUNCTIONS **********************************************************************************/ diff --git a/contrib/babelfishpg_tsql/src/pltsql.h b/contrib/babelfishpg_tsql/src/pltsql.h index 4868f81ac5..fba89da533 100644 --- a/contrib/babelfishpg_tsql/src/pltsql.h +++ b/contrib/babelfishpg_tsql/src/pltsql.h @@ -2127,6 +2127,8 @@ extern void pltsql_dumptree(PLtsql_function *func); extern void pre_function_call_hook_impl(const char *funcName); extern int32 coalesce_typmod_hook_impl(const CoalesceExpr *cexpr); extern void check_restricted_stored_procedure(Oid proc_id); +extern bool is_tsql_atatglobalvar(const char *varname); +extern bool is_tsql_atatuservar(const char *varname); /* * Scanner functions in pl_scanner.c @@ -2205,7 +2207,7 @@ extern void update_CreateSchemaStmt(Node *n, const char *schemaname, const char extern void update_DropOwnedStmt(Node *n, List *role_list); extern void update_DropRoleStmt(Node *n, const char *role); extern void update_DropStmt(Node *n, const char *object); -extern void update_GrantRoleStmt(Node *n, List *privs, List *roles); +extern void update_GrantRoleStmt(Node *n, List *privs, List *roles, const char *grantor); extern void update_GrantStmt(Node *n, const char *object, const char *obj_schema, const char *grantee, const char *priv); extern void update_RenameStmt(Node *n, const char *old_name, const char *new_name); extern void update_ViewStmt(Node *n, const char *view_schema); @@ -2267,6 +2269,13 @@ extern bool pltsql_trace_exec_codes; extern bool pltsql_trace_exec_counts; extern bool pltsql_trace_exec_time; +/* + * saved_expr_kind - special context to store which kind of expression if being processed. + * This is useful specially when handling declared variables because variables are dynamic only when it appears + * in the TargetList. Should be folded as const otherwise. + */ +extern int saved_expr_kind; + /* * Functions in cursor.c */ @@ -2332,4 +2341,9 @@ extern void exec_alter_role_cmd(char *query_str, RoleSpec *role); extern bool validate_special_function(char *proc_nsname, char *proc_name, List* fargs, int nargs, Oid *input_typeids, bool num_args_match); extern void init_special_function_list(void); +/* + * Function in pltsql_ruleutils.c + */ +extern char *tsql_format_type_extended(Oid type_oid, int32 typemod, bits16 flags); + #endif /* PLTSQL_H */ diff --git a/contrib/babelfishpg_tsql/src/pltsql_ruleutils.c b/contrib/babelfishpg_tsql/src/pltsql_ruleutils.c index 462aebe5c7..42a21a672d 100644 --- a/contrib/babelfishpg_tsql/src/pltsql_ruleutils.c +++ b/contrib/babelfishpg_tsql/src/pltsql_ruleutils.c @@ -345,7 +345,6 @@ static char *tsql_get_constraintdef_worker(Oid constraintId, bool fullCommand, static text *tsql_get_expr_worker(text *expr, Oid relid, const char *relname, int prettyFlags); static char *tsql_printTypmod(const char *typname, int32 typmod, Oid typmodout); -static char *tsql_format_type_extended(Oid type_oid, int32 typemod, bits16 flags); int tsql_print_function_arguments(StringInfo buf, HeapTuple proctup, bool print_table_args, bool print_defaults, int **typmod_arr_arg, bool *has_tvp); char *tsql_quote_qualified_identifier(const char *qualifier, const char *ident); @@ -2793,7 +2792,7 @@ find_recursive_union(deparse_namespace *dpns, WorkTableScan *wtscan) * * Returns a palloc'd string. */ -static char * +char * tsql_format_type_extended(Oid type_oid, int32 typemod, bits16 flags) { HeapTuple tuple; diff --git a/contrib/babelfishpg_tsql/src/pltsql_utils.c b/contrib/babelfishpg_tsql/src/pltsql_utils.c index e6743a02c8..b984e345c4 100644 --- a/contrib/babelfishpg_tsql/src/pltsql_utils.c +++ b/contrib/babelfishpg_tsql/src/pltsql_utils.c @@ -1083,7 +1083,7 @@ update_DropStmt(Node *n, const char *object) } void -update_GrantRoleStmt(Node *n, List *privs, List *roles) +update_GrantRoleStmt(Node *n, List *privs, List *roles, const char *grantor) { GrantRoleStmt *stmt = (GrantRoleStmt *) n; @@ -1092,6 +1092,11 @@ update_GrantRoleStmt(Node *n, List *privs, List *roles) stmt->granted_roles = privs; stmt->grantee_roles = roles; + + if (grantor && stmt->grantor) + { + stmt->grantor->rolename = pstrdup(grantor); + } } void @@ -2640,5 +2645,5 @@ update_GrantRoleStmtByName(Node *n, const char *granted_role, const char *grante AccessPriv *granted_rolespec = make_accesspriv_node(granted_role); RoleSpec *grantee_rolespec = make_rolespec_node(grantee_role); - update_GrantRoleStmt(n, list_make1(granted_rolespec), list_make1(grantee_rolespec)); + update_GrantRoleStmt(n, list_make1(granted_rolespec), list_make1(grantee_rolespec), NULL); } diff --git a/contrib/babelfishpg_tsql/src/rolecmds.c b/contrib/babelfishpg_tsql/src/rolecmds.c index 19923651d0..58e54083f2 100644 --- a/contrib/babelfishpg_tsql/src/rolecmds.c +++ b/contrib/babelfishpg_tsql/src/rolecmds.c @@ -443,8 +443,24 @@ drop_bbf_authid_user_ext(ObjectAccessType access, tuple = systable_getnext(scan); if (HeapTupleIsValid(tuple)) + { + bool is_null; + + Datum datum = heap_getattr(tuple, + Anum_bbf_authid_user_ext_login_name, + RelationGetDescr(bbf_authid_user_ext_rel), + &is_null); + if (!is_null) + { + char *login = NameStr(*DatumGetName(datum)); + + /* Grant guest user to login if it's mapped user is being dropped. */ + if (strlen(login) > 0) + grant_revoke_role_to_login(login, get_guest_role_name(get_cur_db_name()), "bbf_role_admin", true); + } CatalogTupleDelete(bbf_authid_user_ext_rel, &tuple->t_self); + } systable_endscan(scan); table_close(bbf_authid_user_ext_rel, RowExclusiveLock); @@ -556,7 +572,7 @@ grant_guests_to_login(const char *login) /* Update the dummy statement with real values */ stmt = parsetree_nth_stmt(parsetree_list, 0); - update_GrantRoleStmt(stmt, guests, list_make1(make_rolespec_node(login))); + update_GrantRoleStmt(stmt, guests, list_make1(make_rolespec_node(login)), NULL); /* Run the built query */ /* need to make a wrapper PlannedStmt */ @@ -584,20 +600,19 @@ grant_guests_to_login(const char *login) } /* - * Grant/revoke dbo role from the login. + * Grant/revoke given role from the login. + * If grantor is provided then only GRANT/REVOKE specific to it will be affected. * The 'is_grant' flag determines if the action is grant/revoke. */ void -grant_revoke_dbo_to_login(const char* login, const char* db_name, bool is_grant) +grant_revoke_role_to_login(const char* login, const char *role_name, const char *grantor, bool is_grant) { StringInfoData query; List *parsetree_list; - List *dbo = NIL; + List *rolelist = NIL; Node *stmt; PlannedStmt *wrapper; - char *dbo_role_name = get_dbo_role_name(db_name); - /* * If login i.e old_owner/new_owner is master user * then skip grant/revoke dbo to login @@ -608,18 +623,22 @@ grant_revoke_dbo_to_login(const char* login, const char* db_name, bool is_grant) initStringInfo(&query); - dbo = lappend(dbo, make_accesspriv_node(dbo_role_name)); + rolelist = lappend(rolelist, make_accesspriv_node(role_name)); if (is_grant) { /* Build dummy GRANT statement to grant membership to login */ - appendStringInfo(&query, "GRANT dummy TO dummy; "); + appendStringInfo(&query, "GRANT dummy TO dummy"); } else { /* Build dummy REVOKE statement to revoke membership from login */ - appendStringInfo(&query, "REVOKE dummy FROM dummy; "); + appendStringInfo(&query, "REVOKE dummy FROM dummy"); } + if (grantor) + appendStringInfo(&query, " GRANTED BY dummy; "); + else + appendStringInfo(&query, "; "); parsetree_list = raw_parser(query.data, RAW_PARSE_DEFAULT); @@ -631,7 +650,7 @@ grant_revoke_dbo_to_login(const char* login, const char* db_name, bool is_grant) /* Update the dummy statement with real values */ stmt = parsetree_nth_stmt(parsetree_list, 0); - update_GrantRoleStmt(stmt, dbo, list_make1(make_rolespec_node(login))); + update_GrantRoleStmt(stmt, rolelist, list_make1(make_rolespec_node(login)), grantor); /* Run the built query */ /* need to make a wrapper PlannedStmt */ @@ -644,7 +663,7 @@ grant_revoke_dbo_to_login(const char* login, const char* db_name, bool is_grant) /* do this step */ ProcessUtility(wrapper, - "(ALTER DATABASE OWNER )", + "GRANT/REVOKE ROLE TO LOGIN", false, PROCESS_UTILITY_SUBCOMMAND, NULL, @@ -656,7 +675,6 @@ grant_revoke_dbo_to_login(const char* login, const char* db_name, bool is_grant) CommandCounterIncrement(); pfree(query.data); - pfree(dbo_role_name); } static List * @@ -826,7 +844,7 @@ user_name(PG_FUNCTION_ARGS) datum = heap_getattr(tuple, Anum_bbf_authid_user_ext_orig_username, - bbf_authid_user_ext_rel->rd_att, + RelationGetDescr(bbf_authid_user_ext_rel), &is_null); user = pstrdup(TextDatumGetCString(datum)); @@ -1311,8 +1329,32 @@ create_bbf_authid_user_ext(CreateRoleStmt *stmt, bool has_schema, bool has_login if (has_login) { + char *db_name = get_cur_db_name(); + int save_sec_context; + Oid save_userid; + verify_login_for_bbf_authid_user_ext(login); login_name_str = login->rolename; + /* Revoke guest user from login as login now has a mapped user in current database. */ + GetUserIdAndSecContext(&save_userid, &save_sec_context); + PG_TRY(); + { + /* + * Older version before APG16 did not store grantor information. + * After MVU to APG16, the grantor for these GRANTs on older roles + * becomes BOOTSTRAP_SUPERUSER. We need SA privilege to revoke the guest + * membership from these roles. + */ + SetUserIdAndSecContext(get_sa_role_oid(), save_sec_context | SECURITY_LOCAL_USERID_CHANGE); + grant_revoke_role_to_login(login_name_str, get_guest_role_name(db_name), NULL, false); + } + PG_FINALLY(); + { + SetUserIdAndSecContext(save_userid, save_sec_context); + } + PG_END_TRY(); + grant_revoke_role_to_login(login_name_str, get_guest_role_name(db_name), "bbf_role_admin", false); /* revoke even membership granted by bbf_role_admin */ + pfree(db_name); } /* Add to the catalog table. Adds current database name by default */ @@ -1467,6 +1509,58 @@ add_existing_users_to_catalog(PG_FUNCTION_ARGS) PG_RETURN_INT32(0); } +PG_FUNCTION_INFO_V1(revoke_guest_from_mapped_logins); +Datum +revoke_guest_from_mapped_logins(PG_FUNCTION_ARGS) +{ + Relation bbf_authid_user_ext_rel; + TableScanDesc scan; + HeapTuple tuple; + bool is_null; + + /* We only allow this to be called from an extension's SQL script. */ + if (!creating_extension) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("%s can only be called from an SQL script executed by CREATE/ALTER EXTENSION", + "add_existing_users_to_catalog()"))); + + bbf_authid_user_ext_rel = table_open(get_authid_user_ext_oid(), AccessShareLock); + scan = table_beginscan_catalog(bbf_authid_user_ext_rel, 0, NULL); + tuple = heap_getnext(scan, ForwardScanDirection); + + while (HeapTupleIsValid(tuple)) + { + Datum datum = heap_getattr(tuple, + Anum_bbf_authid_user_ext_login_name, + RelationGetDescr(bbf_authid_user_ext_rel), + &is_null); + if (!is_null) + { + char *login = NameStr(*DatumGetName(datum)); + + /* Revoke guest user from login as login already has a mapped database user. */ + if (strlen(login) > 0) + { + Datum name = heap_getattr(tuple, + Anum_bbf_authid_user_ext_database_name, + RelationGetDescr(bbf_authid_user_ext_rel), + &is_null); + + char *db_name = TextDatumGetCString(name); + grant_revoke_role_to_login(login, get_guest_role_name(db_name), NULL, false); + grant_revoke_role_to_login(login, get_guest_role_name(db_name), "bbf_role_admin", false); /* revoke even membership granted by bbf_role_admin */ + pfree(db_name); + } + } + tuple = heap_getnext(scan, ForwardScanDirection); + } + + table_endscan(scan); + table_close(bbf_authid_user_ext_rel, AccessShareLock); + PG_RETURN_INT32(0); +} + void alter_bbf_authid_user_ext(AlterRoleStmt *stmt) { @@ -1488,6 +1582,7 @@ alter_bbf_authid_user_ext(AlterRoleStmt *stmt) char *new_user_name = NULL; char *physical_name = NULL; char *login_name_str = NULL; + char *old_login_name = NULL; if (sql_dialect != SQL_DIALECT_TSQL) return; @@ -1583,8 +1678,16 @@ alter_bbf_authid_user_ext(AlterRoleStmt *stmt) if (login_name_str) { - namestrcpy(&login_name_str_namedata, login_name_str); + bool is_null; + Datum old_login = heap_getattr(tuple, + Anum_bbf_authid_user_ext_login_name, + bbf_authid_user_ext_dsc, + &is_null); + /* Fetch the login name which was previously mapped to this user. */ + if (!is_null) + old_login_name = pstrdup(NameStr(*DatumGetName(old_login))); + namestrcpy(&login_name_str_namedata, login_name_str); new_record_user_ext[USER_EXT_LOGIN_NAME] = NameGetDatum(&login_name_str_namedata); new_record_repl_user_ext[USER_EXT_LOGIN_NAME] = true; } @@ -1605,6 +1708,40 @@ alter_bbf_authid_user_ext(AlterRoleStmt *stmt) table_close(bbf_authid_user_ext_rel, RowExclusiveLock); + if (login_name_str) + { + int save_sec_context; + Oid save_userid; + if (old_login_name && strlen(old_login_name) > 0) + { + /* First revoke this user from old login as the user is being mapped to a new login. */ + grant_revoke_role_to_login(old_login_name, stmt->role->rolename, NULL, false); + grant_revoke_role_to_login(old_login_name, stmt->role->rolename, "bbf_role_admin", false); + /* Now grant guest user to old login as it's mapped user is being removed. */ + grant_revoke_role_to_login(old_login_name, get_guest_role_name(get_cur_db_name()), "bbf_role_admin", true); + } + + /* Revoke guest user from new login as login now has a mapped user in current database. */ + GetUserIdAndSecContext(&save_userid, &save_sec_context); + PG_TRY(); + { + /* + * Older version before APG16 did not store grantor information. + * After MVU to APG16, the grantor for these GRANTs on older roles + * becomes BOOTSTRAP_SUPERUSER. We need SA privilege to revoke the guest + * membership from these roles. + */ + SetUserIdAndSecContext(get_sa_role_oid(), save_sec_context | SECURITY_LOCAL_USERID_CHANGE); + grant_revoke_role_to_login(login_name_str, get_guest_role_name(get_cur_db_name()), NULL, false); + } + PG_FINALLY(); + { + SetUserIdAndSecContext(save_userid, save_sec_context); + } + PG_END_TRY(); + grant_revoke_role_to_login(login_name_str, get_guest_role_name(get_cur_db_name()), "bbf_role_admin", false); /* revoke even membership granted by bbf_role_admin */ + } + if (new_user_name) { StringInfoData query; @@ -2135,7 +2272,7 @@ has_user_in_db(const char *login, char **db_name) { Datum name = heap_getattr(tuple_user_ext, Anum_bbf_authid_user_ext_database_name, - bbf_authid_user_ext_rel->rd_att, &is_null); + RelationGetDescr(bbf_authid_user_ext_rel), &is_null); *db_name = pstrdup(TextDatumGetCString(name)); diff --git a/contrib/babelfishpg_tsql/src/rolecmds.h b/contrib/babelfishpg_tsql/src/rolecmds.h index c39c3cb14d..09c83deaef 100644 --- a/contrib/babelfishpg_tsql/src/rolecmds.h +++ b/contrib/babelfishpg_tsql/src/rolecmds.h @@ -85,7 +85,7 @@ extern bool windows_domain_contains_invalid_chars(char *input); extern bool check_windows_logon_length(char *input); extern char* get_windows_domain_name(char* input); extern bool windows_domain_is_not_supported(char* domain_name); -extern void grant_revoke_dbo_to_login(const char* login, const char* db_name, bool is_grant); +extern void grant_revoke_role_to_login(const char* login, const char *role_name, const char *grantor, bool is_grant); extern void exec_alter_dbowner_subcmds(GrantRoleStmt *stmt); extern bool is_grantee_role_db_owner(GrantRoleStmt *stmt); extern void change_object_owner_if_db_owner(void); diff --git a/contrib/babelfishpg_tsql/src/session.c b/contrib/babelfishpg_tsql/src/session.c index 0e5a9ab512..b370392dde 100644 --- a/contrib/babelfishpg_tsql/src/session.c +++ b/contrib/babelfishpg_tsql/src/session.c @@ -15,6 +15,7 @@ #include "dbcmds.h" #include "multidb.h" #include "session.h" +#include "pl_explain.h" #include "pltsql.h" #include "guc.h" #include "storage/shm_toc.h" @@ -222,6 +223,8 @@ reset_session_properties(void) { reset_cached_batch(); reset_cached_cursor(); + pltsql_explain_only = false; + pltsql_explain_analyze = false; } void diff --git a/contrib/babelfishpg_tsql/src/tsqlIface.cpp b/contrib/babelfishpg_tsql/src/tsqlIface.cpp index 958c2a6f1c..579cacb91a 100644 --- a/contrib/babelfishpg_tsql/src/tsqlIface.cpp +++ b/contrib/babelfishpg_tsql/src/tsqlIface.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #pragma GCC diagnostic ignored "-Wattributes" @@ -10,6 +11,7 @@ #include "antlr4-runtime.h" // antlr4-cpp-runtime #include "tree/ParseTreeWalker.h" // antlr4-cpp-runtime #include "tree/ParseTreeProperty.h" // antlr4-cpp-runtime +#include "support/Utf8.h" #include "../antlr/antlr4cpp_generated_src/TSqlLexer/TSqlLexer.h" #include "../antlr/antlr4cpp_generated_src/TSqlParser/TSqlParser.h" @@ -43,6 +45,7 @@ extern "C" { #include "catalog/namespace.h" #include "catalog/pg_proc.h" #include "parser/scansup.h" +#include "utils/builtins.h" #include "guc.h" @@ -177,7 +180,7 @@ TSqlParser::Query_specificationContext *get_query_specification(TSqlParser::Sele static bool is_top_level_query_specification(TSqlParser::Query_specificationContext *ctx); static bool is_quotation_needed_for_column_alias(TSqlParser::Column_aliasContext *ctx); static bool is_compiling_create_function(); -static void process_query_specification(TSqlParser::Query_specificationContext *qctx, PLtsql_expr_query_mutator *mutator); +static void process_query_specification(TSqlParser::Query_specificationContext *qctx, PLtsql_expr_query_mutator *mutator, bool process_local_id_assignment); static void process_select_statement(TSqlParser::Select_statementContext *selectCtx, PLtsql_expr_query_mutator *mutator); static void process_select_statement_standalone(TSqlParser::Select_statement_standaloneContext *standaloneCtx, PLtsql_expr_query_mutator *mutator, tsqlBuilder &builder); template static std::string rewrite_object_name_with_omitted_db_and_schema_name(T ctx, GetCtxFunc getDatabase, GetCtxFunc getSchema, GetCtxFunc getObject); @@ -217,6 +220,10 @@ static void handleOrderByOffsetFetch(TSqlParser::Order_by_clauseContext *ctx); static void rewrite_string_agg_query(TSqlParser::STRING_AGGContext *ctx); static bool setSysSchema = false; static void rewrite_function_trim_to_sys_trim(TSqlParser::TRIMContext *ctx); +static bool isAtAtUserVarName(const std::string name); +static bool isDelimitedAtAtUserVarName(const std::string name); +static void handleLocal_id(TSqlParser::Local_idContext *ctx, bool inSqlObject); +static std::string delimitIfAtAtUserVarName(const std::string name); /* * Structure / Utility function for general purpose of query string modification @@ -260,10 +267,13 @@ static void rewrite_function_trim_to_sys_trim(TSqlParser::TRIMContext *ctx); // global object is enough because no nesting is expected. static std::map> rewritten_query_fragment; -// Keeping poisitions of local_ids to quote them. -// local_id can be rewritten in differeny way in some cases (itvf), don't use rewritten_query_fragment. +// Keeping positions of local_ids to quote them. +// local_id can be rewritten in different ways in some cases (itvf), don't use rewritten_query_fragment. // TODO: incorporate local_id_positions with rewritten_query_fragment static std::map local_id_positions; + +// For user-defined variables like @@var or @var# in the RETURN clause of an ITVF +static std::map local_id_positions_atatuservar; // should be called before visiting subclause to make PLtsql_stmt. static void clear_rewritten_query_fragment(); @@ -489,10 +499,11 @@ attachPLtsql_fragment(ParseTree *node, PLtsql_stmt *fragment) { if (fragment) { - const char *tsqlDesc = pltsql_stmt_typename(fragment); - if (pltsql_enable_antlr_detailed_log) + { + const char *tsqlDesc = pltsql_stmt_typename(fragment); std::cout << " attachPLtsql_fragment(" << (void *) node << ", " << fragment << "[" << tsqlDesc << "])" << std::endl; + } fragments.put(node, fragment); } else @@ -560,7 +571,7 @@ format_errmsg(const char *fmt, const char *arg1, const char *arg2); inline std::u32string utf8_to_utf32(const char* s) { - return antlrcpp::utf8_to_utf32(s, s + strlen(s)); + return antlrcpp::Utf8::lenientDecode(std::string_view(s, strlen(s))); } class MyInputStream : public ANTLRInputStream @@ -574,7 +585,7 @@ class MyInputStream : public ANTLRInputStream void setText(size_t pos, const char *newText) { - UTF32String newText32 = utf8_to_utf32(newText); + std::u32string newText32 = utf8_to_utf32(newText); _data.replace(pos, newText32.size(), newText32); } @@ -715,7 +726,7 @@ void PLtsql_expr_query_mutator::run() rewritten_query += query.substr(cursor); // copy remaining expr->query // update query string - std::string new_query = antlrcpp::utf32_to_utf8(rewritten_query); + std::string new_query = antlrcpp::Utf8::lenientEncode(std::u32string_view(rewritten_query)); expr->query = pstrdup(new_query.c_str()); } @@ -1353,7 +1364,7 @@ class tsqlSelectStatementMutator : public TSqlParserBaseListener void exitQuery_specification(TSqlParser::Query_specificationContext *ctx) override { if (mutator) - process_query_specification(ctx, mutator); + process_query_specification(ctx, mutator, false); } void exitTable_source_item(TSqlParser::Table_source_itemContext *ctx) override @@ -1410,6 +1421,7 @@ class tsqlBuilder : public tsqlCommonMutator std::string db_name; bool is_function = false; bool is_schema_specified = false; + bool in_func_body_return_select_body = false; // We keep a stack of the containers that are active during a traversal. // A container will correspond to a block or a batch - these are containers @@ -1920,22 +1932,6 @@ class tsqlBuilder : public tsqlCommonMutator if (is_schema_specified) stmt->is_schema_specified = true; - if (is_cross_db) - { - if (ctx->select_statement_standalone() && - ctx->select_statement_standalone()->select_statement() && - ctx->select_statement_standalone()->select_statement()->query_expression() && - ctx->select_statement_standalone()->select_statement()->query_expression()->query_specification() && - ctx->select_statement_standalone()->select_statement()->query_expression()->query_specification()->INTO() && - ctx->select_statement_standalone()->select_statement()->query_expression()->query_specification()->table_name()) - { - throw PGErrorWrapperException(ERROR, - ERRCODE_FEATURE_NOT_SUPPORTED, - "cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.", - getLineAndPos(ctx->select_statement_standalone())); - } - } - if (is_compiling_create_function()) { /* select without destination should be blocked. We can use already information about desitnation, which is already processed. */ @@ -1951,8 +1947,13 @@ class tsqlBuilder : public tsqlCommonMutator throw PGErrorWrapperException(ERROR, ERRCODE_INVALID_FUNCTION_DEFINITION, "'INSERT EXEC' cannot be used within a function", getLineAndPos(ddl_object)); } else if (ddl_object && !ddl_object->local_id()) /* insert into non-local object */ - { - throw PGErrorWrapperException(ERROR, ERRCODE_INVALID_FUNCTION_DEFINITION, "'INSERT' cannot be used within a function", getLineAndPos(ddl_object)); + { + if (ddl_object && ddl_object->full_object_name() && isDelimitedAtAtUserVarName(getFullText(ddl_object->full_object_name()) )) + { + /* This is a table variable name enclosed in delimiters, which is OK */ + } + else + throw PGErrorWrapperException(ERROR, ERRCODE_INVALID_FUNCTION_DEFINITION, "'INSERT' cannot be used within a function", getLineAndPos(ddl_object)); } } else if (ctx->update_statement() || ctx->delete_statement()) @@ -1983,16 +1984,20 @@ class tsqlBuilder : public tsqlCommonMutator } else if (ddl_object && !ddl_object->local_id()) { - if (ddl_object && ddl_object->full_object_name()) + if (ddl_object && ddl_object->full_object_name() && isDelimitedAtAtUserVarName(getFullText(ddl_object->full_object_name()) )) { - // DML target can be an alias: verify that the alias is for a table variable - if (table_sources) + /* DML target is a table variable name enclosed in delimiters, which is OK */ + dmlTargetAllowed = true; + } + else + { + if (ddl_object && ddl_object->full_object_name()) { + /* DML target can be an alias: verify that the alias is for a table variable */ line_and_pos = getLineAndPos(ddl_object); - // DML target can be an alias: verify that the alias is for a table variable if (table_sources) { - line_and_pos = getLineAndPos(ddl_object->full_object_name()); + line_and_pos = getLineAndPos(ddl_object->full_object_name()); std::string dmlTarget = getFullText(ddl_object->full_object_name()); dmlTargetAllowed = dmlTargetIsTabvar(table_sources->table_source_item(), dmlTarget); } @@ -2073,7 +2078,13 @@ class tsqlBuilder : public tsqlCommonMutator if (table_source_item[i]->local_id()) { - // Table variable, with alias matching the DML target + // Table variable name, with alias matching the DML target + return true; + } + + if (isDelimitedAtAtUserVarName(getFullText(table_source_item[i]->full_object_name()))) + { + // Delimited table variable name, with alias matching the DML target return true; } } @@ -2218,7 +2229,12 @@ class tsqlBuilder : public tsqlCommonMutator PLtsql_stmt_print *stmt = (PLtsql_stmt_print *) getPLtsql_fragment(ctx); expr = (PLtsql_expr *) linitial(stmt->exprs); } - else if (ctx->raiseerror_statement() && ctx->raiseerror_statement()->raiseerror_msg() && ctx->raiseerror_statement()->raiseerror_msg()->char_string()) + else if (ctx->raiseerror_statement() && + ctx->raiseerror_statement()->raiseerror_msg() && + (ctx->raiseerror_statement()->raiseerror_msg()->char_string() || + ctx->raiseerror_statement()->raiseerror_msg()->local_id() + ) + ) { PLtsql_stmt_raiserror *stmt = (PLtsql_stmt_raiserror *) getPLtsql_fragment(ctx); expr = (PLtsql_expr *) linitial(stmt->params); @@ -2374,6 +2390,14 @@ class tsqlBuilder : public tsqlCommonMutator add_rewritten_query_fragment_to_mutator(&mutator); // move information of rewritten_query_fragment to mutator. mutator.run(); // expr->query will be rewitten here } + else if (stmt->cmd_type == PLTSQL_STMT_EXEC_BATCH) + { + PLtsql_stmt_exec_batch *stmtExec = (PLtsql_stmt_exec_batch *) getPLtsql_fragment(ctx); + PLtsql_expr_query_mutator mutator(stmtExec->expr, ctx); + mutator.markSelectFragment(ctx); + add_rewritten_query_fragment_to_mutator(&mutator); + mutator.run(); + } } else if (ctx->set_statement() && ctx->set_statement()->expression()) @@ -2387,7 +2411,17 @@ class tsqlBuilder : public tsqlCommonMutator add_rewritten_query_fragment_to_mutator(&mutator); mutator.run(); } - + else if (ctx->set_statement() && + ctx->set_statement()->set_special() && + ctx->set_statement()->set_special()->constant_LOCAL_ID() && + ctx->set_statement()->set_special()->constant_LOCAL_ID()->local_id()) + { + PLtsql_stmt_execsql *stmt = (PLtsql_stmt_execsql *) getPLtsql_fragment(ctx->set_statement()); + PLtsql_expr_query_mutator mutator(stmt->sqlstmt, ctx->set_statement()); + add_rewritten_query_fragment_to_mutator(&mutator); + mutator.run(); + } + else if (ctx->declare_statement()) { if (ctx->declare_statement()->declare_local().size() > 0) @@ -2415,10 +2449,17 @@ class tsqlBuilder : public tsqlCommonMutator } } } + else if (ctx->transaction_statement()) + { + PLtsql_stmt_execsql *stmt = (PLtsql_stmt_execsql *) getPLtsql_fragment(ctx); + PLtsql_expr_query_mutator mutator(stmt->sqlstmt, ctx); + add_rewritten_query_fragment_to_mutator(&mutator); + mutator.run(); + } // remove the offsets for processed fragments - selectFragmentOffsets.clear(); - + selectFragmentOffsets.clear(); + clear_rewritten_query_fragment(); } @@ -2600,20 +2641,25 @@ class tsqlBuilder : public tsqlCommonMutator ////////////////////////////////////////////////////////////////////////////// void enterLocal_id(TSqlParser::Local_idContext *ctx) override { - std::string local_id_str = ::getFullText(ctx); + std::string local_id_str = getFullText(ctx); if (local_id_str.length() > 2 && local_id_str[0] == '@' && local_id_str[1] == '@') { - // starting with "@@" is a global variable (or internal function). skip adding. + // Starting with '@@': this is a T-SQL global variable; these are handled separately return; } - // keep to add quote later + // Keep start position of the to add quotes around the vriable name later if (ctx->start) { local_id_positions.emplace(std::make_pair(ctx->start->getStartIndex(), local_id_str)); } } + void exitLocal_id(TSqlParser::Local_idContext *ctx) override + { + handleLocal_id(ctx, in_create_or_alter_procedure || in_create_or_alter_trigger); + } + void exitFull_object_name(TSqlParser::Full_object_nameContext *ctx) override { if (ctx && (ctx->DOT().size() <= 2) && ctx->schema) @@ -2662,6 +2708,20 @@ class tsqlBuilder : public tsqlCommonMutator void exitFull_column_name(TSqlParser::Full_column_nameContext *ctx) override { handleFullColumnNameCtx(ctx); + + if (in_func_body_return_select_body) + { + if (ctx->DOT().empty()) + { + std::string local_id_str = getFullText(ctx); + if (isDelimitedAtAtUserVarName(local_id_str)) { + // We're in the RETURN clause of an ITVF, and any variables names @@var or @var# will be delimited at this point. + // Downstream these need to be temporarily replaced with CAST(NULL as ), and to make that work we need + // to record their positions here. + local_id_positions_atatuservar.emplace(std::make_pair(ctx->start->getStartIndex(), local_id_str)); + } + } + } } /* We are adding handling for CLR_UDT Types in: @@ -2797,7 +2857,7 @@ class tsqlBuilder : public tsqlCommonMutator } has_identity_function = false; if (statementMutator) - process_query_specification(ctx, statementMutator.get()); + process_query_specification(ctx, statementMutator.get(), true); } void exitDrop_relational_or_xml_or_spatial_index(TSqlParser::Drop_relational_or_xml_or_spatial_indexContext *ctx) override @@ -2840,31 +2900,35 @@ class tsqlBuilder : public tsqlCommonMutator { // prepare rewriting clear_rewritten_query_fragment(); + local_id_positions_atatuservar.clear(); + in_func_body_return_select_body = true; } void exitFunc_body_return_select_body(TSqlParser::Func_body_return_select_bodyContext *ctx) override { handleITVFBody(ctx); clear_rewritten_query_fragment(); + local_id_positions_atatuservar.clear(); + in_func_body_return_select_body = false; } void enterExecute_body_batch(TSqlParser::Execute_body_batchContext *ctx) override { - in_execute_body_batch = true; + in_execute_body_batch = true; PLtsql_stmt *stmt = makeExecBodyBatch(ctx); attachPLtsql_fragment(ctx, stmt); graft(stmt, peekContainer()); - clear_rewritten_query_fragment(); + clear_rewritten_query_fragment(); } void exitExecute_body_batch(TSqlParser::Execute_body_batchContext *ctx) override { - in_execute_body_batch = false; + in_execute_body_batch = false; PLtsql_stmt_exec *stmt = (PLtsql_stmt_exec *) getPLtsql_fragment(ctx); PLtsql_expr_query_mutator mutator(stmt->expr, ctx); add_rewritten_query_fragment_to_mutator(&mutator); mutator.run(); - clear_rewritten_query_fragment(); + clear_rewritten_query_fragment(); } PLtsql_expr *rewrite_if_condition(TSqlParser::Search_conditionContext *ctx) @@ -2911,10 +2975,13 @@ class tsqlBuilder : public tsqlCommonMutator class tsqlMutator : public TSqlParserBaseListener { public: - const std::vector &ruleNames; - MyInputStream &stream; - bool in_procedure_parameter = false; - bool in_procedure_parameter_id = false; + const std::vector &ruleNames; + MyInputStream &stream; + bool in_procedure_parameter = false; + bool in_procedure_parameter_id = false; + bool in_func_body_return_select_body = false; + bool in_create_or_alter_procedure = false; + bool in_create_or_alter_trigger = false; std::vector double_quota_places; @@ -2972,6 +3039,22 @@ class tsqlMutator : public TSqlParserBaseListener return result; } + void enterCreate_or_alter_procedure(TSqlParser::Create_or_alter_procedureContext *ctx) override { + in_create_or_alter_procedure = true; + } + + void exitCreate_or_alter_procedure(TSqlParser::Create_or_alter_procedureContext *ctx) override { + in_create_or_alter_procedure = false; + } + + void enterCreate_or_alter_trigger(TSqlParser::Create_or_alter_triggerContext *ctx) override { + in_create_or_alter_trigger = true; + } + + void exitCreate_or_alter_trigger(TSqlParser::Create_or_alter_triggerContext *ctx) override { + in_create_or_alter_trigger = false; + } + void enterComparison_operator(TSqlParser::Comparison_operatorContext *ctx) override { // Handle multiple cases: @@ -3022,8 +3105,18 @@ class tsqlMutator : public TSqlParserBaseListener if (pltsql_enable_antlr_detailed_log) std::cout << "-leaving (tsqlMutator)" << (void *) ctx << "[" << desc << "]" << std::endl; - } + } + + void enterFunc_body_return_select_body(TSqlParser::Func_body_return_select_bodyContext *ctx) override + { + in_func_body_return_select_body = true; + } + void exitFunc_body_return_select_body(TSqlParser::Func_body_return_select_bodyContext *ctx) override + { + in_func_body_return_select_body = false; + } + void enterFunc_proc_name_server_database_schema(TSqlParser::Func_proc_name_server_database_schemaContext *ctx) override { // We are looking at a function name; it may be a function call, or a @@ -3164,16 +3257,21 @@ class tsqlMutator : public TSqlParserBaseListener in_procedure_parameter = true; } } - + void enterFull_column_name(TSqlParser::Full_column_nameContext *ctx) override { if (in_procedure_parameter) { in_procedure_parameter_id = true; - } + } + } + + void exitLocal_id(TSqlParser::Local_idContext *ctx) override + { + handleLocal_id(ctx, in_create_or_alter_procedure || in_create_or_alter_trigger); } void exitFunc_body_returns_scalar(TSqlParser::Func_body_returns_scalarContext *ctx) override - { + { // If no AS keyword is specified, insert it prior to the BEGIN keyword. // This only applies to scalar functions; for other function types, the optional AS keyword // is already supported. @@ -3252,6 +3350,24 @@ class tsqlMutator : public TSqlParserBaseListener } } + void enterChar_string(TSqlParser::Char_stringContext *ctx) override + { + std::string str = getFullText(ctx); + if ((str.front() == '"') && (str.back() == '"') && (str.length() == 2)) + { + // This means we have a double-quoted empty, zero-length string. The PG equivalent is a zero-length + // single-quoted string. + // Whenever we reference a double-quoted empty string inside the body of a T-SQL procedure, function or trigger, + // this is passed onto the PG backend where PG interprets double-quoted items as delimited identifiers. + // However those cannot be zero-length, so an error is then raised. + // By changing any double-quoted empty string to a single-quoted empty string we address this use case here. + // This also addresses any references outside those objects; those would otherwise have been rewritten as a + // single-quoted string by rewriteDoubleQuotedString() in the exitChar_string() functions, but doing it + // here preempts that and removes potential complexity from the rewriting in the mutator. + stream.setText(ctx->start->getStartIndex(), "''"); + } + } + // NB: similar code is in tsqlBuilder void exitChar_string(TSqlParser::Char_stringContext *ctx) override { @@ -3381,11 +3497,89 @@ class MyParserErrorListener: public antlr4::BaseErrorListener }; /* - * Necessary checks and mutations for query_specification + * handle_local_ids_for_expression - removes all the local_ids from local_id_positions of given expression. + * This is useful in case of local_id assignement as part of select elements for which we don't want to quote local_id. + */ +static void +handle_local_ids_for_expression(TSqlParser::ExpressionContext *ectx) +{ + std::vector keysToRemove; + for(auto &it : local_id_positions) + { + if (it.first >= ectx->start->getStartIndex() && it.first <= ectx->stop->getStopIndex()) + { + keysToRemove.push_back(it.first); + } + } + for (const auto &key : keysToRemove) local_id_positions.erase(key); + keysToRemove.clear(); +} + +/* + * add_rewritten_query_fragment_for_select_expression - should be called from the context of + * variable assignment expression. It will add all the already re-written query fragments to + * expression(). + */ +static void +add_rewritten_query_fragment_for_select_expression(PLtsql_expr_query_mutator *mutator) +{ + std::vector keysToRemove; + Assert(mutator); + TSqlParser::ExpressionContext *ectx = (TSqlParser::ExpressionContext *) mutator->ctx; + for (auto &entry : rewritten_query_fragment) + { + if (entry.first >= ectx->start->getStartIndex() && entry.first <= ectx->stop->getStopIndex()) + { + mutator->add(entry.first, entry.second.first, entry.second.second); + keysToRemove.push_back(entry.first); + } + } + for (const auto &key : keysToRemove) rewritten_query_fragment.erase(key); + keysToRemove.clear(); +} + +/* + * rewrite_assignment_expression - This will re-write assignment expression by adding already re-written fragments to it. + * It also add appropriate cast around expression needed by sys.pltsql_assign_var to assign value to var. + */ +static char * +rewrite_assignment_expression(PLtsql_var *var, TSqlParser::ExpressionContext *ectx) +{ + char *new_expr = NULL; + char *type_str = tsql_format_type_extended(var->datatype->typoid, var->datatype->atttypmod, FORMAT_TYPE_TYPEMOD_GIVEN); + PLtsql_expr *elem_expr = makeTsqlExpr(ectx, false); + PLtsql_expr_query_mutator expr_mutator(elem_expr, ectx); + add_rewritten_query_fragment_for_select_expression(&expr_mutator); + expr_mutator.run(); + + Assert(type_str); + /* + * Extra handling for type - If var->datatype->atttypmod = -1 and if "max" typmod is allowed for type (e.g., varchar, varbinary etc) + * then append explicit (max). Check implementation of parse_datatype and tsql_format_type_extended for more details. + */ + if (var->datatype->atttypmod == -1 && is_tsql_datatype_with_max_scale_expr_allowed(var->datatype->typoid)) + { + char *tmp = psprintf("%s(max)", type_str); + pfree(type_str); + type_str = tmp; + } + + new_expr = psprintf("cast((%s) as %s)", + elem_expr->query, + type_str); + + return new_expr; +} + +/* + * Necessary checks and mutations for query_specification. + * @process_local_id_assignment indicates whether local_id assignement should be re-written or not. Passed false when we are handling + * statement like create or alter function. */ static void process_query_specification( TSqlParser::Query_specificationContext *qctx, - PLtsql_expr_query_mutator *mutator) + PLtsql_expr_query_mutator *mutator, + bool process_local_id_assignment) { Assert(qctx->select_list()); std::vector select_elems = qctx->select_list()->select_list_elem(); @@ -3475,6 +3669,76 @@ static void process_query_specification( mutator->add(column_alias_as->start->getStartIndex(), "", " AS "); } } + else if(process_local_id_assignment && elem->LOCAL_ID() && elem->EQUAL()) + { + const char *var_str = downcase_truncate_identifier(::getFullText(elem->LOCAL_ID()).c_str(), ::getFullText(elem->LOCAL_ID()).length(), true); + PLtsql_nsitem *nse = pltsql_ns_lookup(pltsql_ns_top(), false, var_str, nullptr, nullptr, nullptr); + char *repl_text = NULL; + + Assert(elem->expression()); + if (!nse) + throw PGErrorWrapperException(ERROR, ERRCODE_SYNTAX_ERROR, format_errmsg("\"%s\" is not a known variable", ::getFullText(elem->LOCAL_ID()).c_str()), getLineAndPos(elem)); + + /* Rewrite @var = expr to @var=sys.pltsql_assign_var(dno, cast((expr) as type)) */ + repl_text = psprintf("sys.pltsql_assign_var(%d, %s)", + nse->itemno, + rewrite_assignment_expression((PLtsql_var *) pltsql_Datums[nse->itemno], + elem->expression())); + + handle_local_ids_for_expression(elem->expression()); + mutator->add(elem->expression()->start->getStartIndex(), ::getFullText(elem->expression()), std::string(repl_text)); + } + else if(process_local_id_assignment && elem->LOCAL_ID() && elem->assignment_operator()) + { + const char *var_str = downcase_truncate_identifier(::getFullText(elem->LOCAL_ID()).c_str(), ::getFullText(elem->LOCAL_ID()).length(), true); + PLtsql_nsitem *nse = pltsql_ns_lookup(pltsql_ns_top(), false, var_str, nullptr, nullptr, nullptr); + char *repl_text = NULL; + tree::TerminalNode *anode = nullptr; + + if (elem->assignment_operator()) + { + if (elem->assignment_operator()->PLUS_ASSIGN()) + anode = elem->assignment_operator()->PLUS_ASSIGN(); + else if (elem->assignment_operator()->MINUS_ASSIGN()) + anode = elem->assignment_operator()->MINUS_ASSIGN(); + else if (elem->assignment_operator()->MULT_ASSIGN()) + anode = elem->assignment_operator()->MULT_ASSIGN(); + else if (elem->assignment_operator()->DIV_ASSIGN()) + anode = elem->assignment_operator()->DIV_ASSIGN(); + else if (elem->assignment_operator()->MOD_ASSIGN()) + anode = elem->assignment_operator()->MOD_ASSIGN(); + else if (elem->assignment_operator()->AND_ASSIGN()) + anode = elem->assignment_operator()->AND_ASSIGN(); + else if (elem->assignment_operator()->XOR_ASSIGN()) + anode = elem->assignment_operator()->XOR_ASSIGN(); + else if (elem->assignment_operator()->OR_ASSIGN()) + anode = elem->assignment_operator()->OR_ASSIGN(); + else + Assert(0); + } + + Assert(elem->expression()); + if (!nse) + throw PGErrorWrapperException(ERROR, ERRCODE_SYNTAX_ERROR, + format_errmsg("\"%s\" is not a known variable", + ::getFullText(elem->LOCAL_ID()).c_str()), getLineAndPos(elem)); + + /* + * Rewrite @var += expr to @var += sys.pltsql_assign_var(dno, "@var" + cast((expr) as type)). + * Note that we only update expr with sys.pltsql_assign_var(dno, "@var" + (expr) here and + * additional handling of assignment opetator will be done in process_execsql_destination_select + * when we create target row. + */ + repl_text = psprintf("sys.pltsql_assign_var(%d, %s %s %s)", + nse->itemno, + delimitIfAtAtUserVarName(::getFullText(elem->LOCAL_ID())).c_str(), + rewrite_assign_operator(anode), + rewrite_assignment_expression((PLtsql_var *) pltsql_Datums[nse->itemno], + elem->expression())); + + handle_local_ids_for_expression(elem->expression()); + mutator->add(elem->expression()->start->getStartIndex(), ::getFullText(elem->expression()), std::string(repl_text)); + } } } @@ -4587,16 +4851,16 @@ makeTsqlExpr(const std::string &fragment, bool addSelect) PLtsql_expr *result = (PLtsql_expr *) palloc0(sizeof(*result)); if (addSelect) - result->query = pstrdup((fragment_SELECT_prefix + fragment).c_str()); + result->query = pstrdup((fragment_SELECT_prefix + delimitIfAtAtUserVarName(fragment)).c_str()); else - result->query = pstrdup(fragment.c_str()); - - result->plan = NULL; - result->paramnos = NULL; - result->rwparam = -1; - result->ns = pltsql_ns_top(); - - return result; + result->query = pstrdup(delimitIfAtAtUserVarName(fragment).c_str()); + + result->plan = NULL; + result->paramnos = NULL; + result->rwparam = -1; + result->ns = pltsql_ns_top(); + + return result; } PLtsql_expr * @@ -5103,19 +5367,32 @@ makeReturnQueryStmt(TSqlParser::Select_statement_standaloneContext *ctx, bool it add_rewritten_query_fragment_to_mutator(&itvf_mutator); std::u32string query = utf8_to_utf32(itvf_expr->query); + + /* + * Add the positions of @@var / @var# names to make the logic below work + * for getting the column list. + */ + for (const auto &entryA : local_id_positions_atatuservar) + { + std::string varName = delimitIfAtAtUserVarName(entryA.second); + local_id_positions.emplace(std::make_pair(entryA.first, varName)); + } + for (const auto &entry : local_id_positions) { const std::string& local_id = entry.second; + std::string local_id_lookup = local_id; + if (isDelimitedAtAtUserVarName(local_id)) local_id_lookup = local_id.substr(1,local_id.length()-2); const std::u32string& local_id_u32 = utf8_to_utf32(local_id.c_str()); size_t offset = entry.first - base_index; if (query.substr(offset, local_id_u32.length()) == local_id_u32) // local_id maybe already deleted in some cases such as select-assignment. check here if it still exists) { int dno; - PLtsql_nsitem *nse = pltsql_ns_lookup(pltsql_ns_top(), false, local_id.c_str(), nullptr, nullptr, nullptr); + PLtsql_nsitem *nse = pltsql_ns_lookup(pltsql_ns_top(), false, local_id_lookup.c_str(), nullptr, nullptr, nullptr); if (nse) dno = nse->itemno; else - throw PGErrorWrapperException(ERROR, ERRCODE_SYNTAX_ERROR, format_errmsg("\"%s\" is not a known variable", local_id.c_str()), getLineAndPos(ctx)); + throw PGErrorWrapperException(ERROR, ERRCODE_SYNTAX_ERROR, format_errmsg("\"%s\" is not a known variable", local_id_lookup.c_str()), getLineAndPos(ctx)); PLtsql_var *var = (PLtsql_var *) pltsql_Datums[dno]; std::string repl_text = std::string("CAST(NULL AS ") + std::string(var->datatype->typname) + std::string(")"); @@ -5204,7 +5481,7 @@ makeRaiseErrorStmt(TSqlParser::Raiseerror_statementContext *ctx) result->seterror = false; // msg, severity, state - result->params = lappend(result->params, makeTsqlExpr(ctx->msg->getText(), true)); + result->params = lappend(result->params, makeTsqlExpr(delimitIfAtAtUserVarName(ctx->msg->getText()), true)); recordSelectFragmentOffsets(ctx->parent, ctx->raiseerror_msg()); result->params = lappend(result->params, makeTsqlExpr(ctx->severity, true)); @@ -5285,10 +5562,10 @@ makeDeclareStmt(TSqlParser::Declare_statementContext *ctx, std::mapLOCAL_ID() && ctx->table_type_definition()) + if (ctx->local_id() && ctx->table_type_definition()) { - std::string nameStr = ::getFullText(ctx->LOCAL_ID()); - std::string typeStr = ::getFullText(ctx->table_type_definition()); + std::string nameStr = getFullText(ctx->local_id()); + std::string typeStr = getFullText(ctx->table_type_definition()); const char *name = downcase_truncate_identifier(nameStr.c_str(), nameStr.length(), true); check_dup_declare(name); PLtsql_type *type = parse_datatype(typeStr.c_str(), 0); @@ -5303,7 +5580,7 @@ makeDeclareStmt(TSqlParser::Declare_statementContext *ctx, std::mapLOCAL_ID()); + std::string nameStr = getFullText(local->LOCAL_ID()); const char *name = downcase_truncate_identifier(nameStr.c_str(), nameStr.length(), true); check_dup_declare(name); @@ -5433,7 +5710,7 @@ makeSQL(ParserRuleContext *ctx) static bool is_valid_set_option(std::string val) { - /* ON/OFF option and other special options (i.e. TRANSACTION ISOLATION LEVEL) are not incldued in this function because they are handled by grammar */ + /* ON/OFF option and other special options (i.e. TRANSACTION ISOLATION LEVEL) are not included in this function because they are handled by grammar */ return (pg_strcasecmp("DATEFIRST", val.c_str()) == 0) || (pg_strcasecmp("DATEFORMAT", val.c_str()) == 0) || (pg_strcasecmp("DEADLOCK_PRIORITY", val.c_str()) == 0) || @@ -5480,7 +5757,6 @@ makeSetStatement(TSqlParser::Set_statementContext *ctx, tsqlBuilder &builder) char *target = pstrdup(targetText.c_str()); pltsql_parse_word(target, target, &wdatum, &word); - PLtsql_stmt_assign *result = (PLtsql_stmt_assign *) makeInitializer(dno, getLineNo(ctx), expr); int posStart = expr->getStart()->getStartIndex(); @@ -5670,7 +5946,7 @@ makeSetStatement(TSqlParser::Set_statementContext *ctx, tsqlBuilder &builder) PLtsql_stmt_execsql *stmt = (PLtsql_stmt_execsql *) palloc0(sizeof(PLtsql_stmt_execsql)); std::string query; - query += "CALL bbf_set_context_info(convert(varbinary(128), "; + query += "CALL sys.bbf_set_context_info(convert(varbinary(128), "; query += param; query += "));"; @@ -5688,7 +5964,10 @@ makeSetStatement(TSqlParser::Set_statementContext *ctx, tsqlBuilder &builder) return (PLtsql_stmt *) stmt; } else + { + // We get here for other SET options that do not fall under set_on_off_option or special_variable, like DATEFORMAT return makeSQL(ctx); + } } else if (set_special_ctx->OFFSETS()) return nullptr; @@ -5713,7 +5992,7 @@ makeSetStatement(TSqlParser::Set_statementContext *ctx, tsqlBuilder &builder) { TSqlParser::Special_variableContext *guc_ctx = static_cast (set_special_ctx->special_variable()); /* build expression with the input variable */ - PLtsql_expr* input_expr = makeTsqlExpr(getFullText(set_special_ctx->LOCAL_ID()), true); + PLtsql_expr* input_expr = makeTsqlExpr(delimitIfAtAtUserVarName(getFullText(set_special_ctx->LOCAL_ID())), true); /* build target variable for this GUC, so that in backend we can identify that target is GUC */ PLtsql_var *target_var = build_babelfish_guc_variable(guc_ctx); /* assign expression to target */ @@ -5725,7 +6004,9 @@ makeSetStatement(TSqlParser::Set_statementContext *ctx, tsqlBuilder &builder) return (PLtsql_stmt *) result; } else + { return makeSQL(ctx); + } } else return nullptr; @@ -5908,11 +6189,15 @@ makeExecuteStatement(TSqlParser::Execute_statementContext *ctx) } std::string expr_query = ss.str(); result->expr = makeTsqlExpr(expr_query, true); - + if (!exec_strings.empty()) + { + recordSelectFragmentOffsets(ctx->parent, exec_strings[0]->getStart()->getStartIndex(), exec_strings[exec_strings.size()-1]->getStop()->getStopIndex(), 0); + } + return (PLtsql_stmt *) result; } else /* execute a stored procedure or function */ - { + { return makeExecuteProcedure(ctx, "execute_statement"); } } @@ -6071,8 +6356,9 @@ makeFetchCursorStatement(TSqlParser::Fetch_cursorContext *ctx) for (size_t i=0; iitemtype == PLTSQL_NSTYPE_REC || @@ -6398,7 +6684,7 @@ makeTransactionStatement(TSqlParser::Transaction_statementContext *ctx) PLtsql_stmt_execsql *stmt = (PLtsql_stmt_execsql *) result; stmt->txn_data = (PLtsql_txn_data *) palloc0(sizeof(PLtsql_txn_data)); - auto *localID = ctx->LOCAL_ID(); + auto *localID = ctx->local_id(); if (localID) { stmt->txn_data->txn_name_expr = makeTsqlExpr(::getFullText(localID), true); @@ -6444,7 +6730,7 @@ makeAnother(TSqlParser::Another_statementContext *ctx, tsqlBuilder &builder) for (PLtsql_stmt *stmt : result) { - // Associate each fragement with a tree node + // Associate each fragment with a tree node if (!declare_local_expr.empty() && declare_local_expr.find(stmt) != declare_local_expr.end()) { attachPLtsql_fragment(declare_local_expr.at(stmt), stmt); @@ -6490,7 +6776,7 @@ makeExecuteProcedure(ParserRuleContext *ctx, std::string call_type) std::string execKeywd = "EXEC"; // DO NOT CHANGE! int name_length = 0; - // Use a boolean vor convenience + // Use a boolean for convenience bool execute_statement = string_matches(call_type.c_str(), "execute_statement") ? true : false; size_t startPos = ctx->start->getStartIndex(); // start position of statement @@ -6741,29 +7027,47 @@ makeDbccCheckidentStatement(TSqlParser::Dbcc_statementContext *ctx) stmt->cmd_type = PLTSQL_STMT_DBCC; stmt->dbcc_stmt_type = PLTSQL_DBCC_CHECKIDENT; - if (ctx->table_name_string()) + /* + * FIXME: the table name and new value arguments can be local variables. The grammar supports this but + * the processing below does not yet. These cases are currently caught in TsqlUnsupportedFeatureHandler + * and a polite error message is raised. Consequently, we should never get here for those cases, and + * for clarity, the two Assert(0) statements are marking those locations which we should never arrive at. + */ + if (ctx->dbcc_table_name()) { - if(ctx->table_name_string()->table) + if (ctx->dbcc_table_name()->table) { - input_str = stripQuoteFromId(ctx->table_name_string()->table); + input_str = stripQuoteFromId(ctx->dbcc_table_name()->table); } - if (ctx->table_name_string()->char_string()) + else if (ctx->dbcc_table_name()->char_string()) { - input_str = ctx->table_name_string()->char_string()->STRING()->getSymbol()->getText(); + input_str = ctx->dbcc_table_name()->char_string()->STRING()->getSymbol()->getText(); if (input_str.length() <= 2) throw PGErrorWrapperException(ERROR, ERRCODE_INVALID_PARAMETER_VALUE, "Parameter 1 is incorrect for this DBCC statement", - getLineAndPos(ctx->table_name_string())); + getLineAndPos(ctx->dbcc_table_name())); input_str = input_str.substr(1, input_str.length()-2); } + else if (ctx->dbcc_table_name()->local_id()) + { + // This is already caught in TsqlUnsupportedFeatureHandler, so we should not get here + Assert(0); + } + if (ctx->RESEED()) { - if (ctx->new_value) + if (ctx->checkident_new_value()) { - if(ctx->MINUS()) - stmt->dbcc_stmt_data.dbcc_checkident.new_reseed_value = pstrdup((ctx->new_value->getText().insert(0,"-")).c_str()); + if (ctx->checkident_new_value()->local_id()) + { + // This is already caught in TsqlUnsupportedFeatureHandler, so we should not get here + Assert(0); + } + + if (ctx->MINUS()) + stmt->dbcc_stmt_data.dbcc_checkident.new_reseed_value = pstrdup((ctx->checkident_new_value()->getText().insert(0,"-")).c_str()); else - stmt->dbcc_stmt_data.dbcc_checkident.new_reseed_value = pstrdup((ctx->new_value->getText()).c_str()); + stmt->dbcc_stmt_data.dbcc_checkident.new_reseed_value = pstrdup((ctx->checkident_new_value()->getText()).c_str()); } } else if (ctx->NORESEED()) @@ -6843,8 +7147,9 @@ create_select_target_row(const char *refname, size_t nfields, int lineno) // Add target column to target row for assignment void add_assignment_target_field(PLtsql_row *target, antlr4::tree::TerminalNode *localId, size_t idx) { - auto targetText = ::getFullText(localId); - PLtsql_nsitem *nse = pltsql_ns_lookup(pltsql_ns_top(), false, targetText.c_str(), nullptr, nullptr, nullptr); + std::string targetText = getFullText(localId); + const char *nameLookup = downcase_truncate_identifier(targetText.c_str(), targetText.length(), true); + PLtsql_nsitem *nse = pltsql_ns_lookup(pltsql_ns_top(), false, nameLookup, nullptr, nullptr, nullptr); if (!nse) throw PGErrorWrapperException(ERROR, ERRCODE_SYNTAX_ERROR, format_errmsg("\"%s\" is not a known variable", targetText.c_str()), getLineAndPos(localId)); @@ -6896,8 +7201,12 @@ void process_execsql_destination_select(TSqlParser::Select_statement_standaloneC if (elem->EQUAL()) { - // in PG main parser, '@a=1' will be treated as a boolean expression to compare @a and 1. This is different T-SQL expected. - // We'll remove '@a=' from the query string so that main parser will return the expected result. + /* + * In PG main parser, @a=expr will be treated as a boolean expression to compare @a and expr. This is different T-SQL expected. + * We have re-written it as @a = sys.pltsql_assign_var(dno, expr) (check process_query_specification) so that appropriate result + * of expr is assigned to destination var dynamically and now we just need to remove '@a=' from the query string so that main parser + * will return the expected result. + */ removeTokenStringFromQuery(stmt->sqlstmt, elem->LOCAL_ID(), ctx); removeTokenStringFromQuery(stmt->sqlstmt, elem->EQUAL(), ctx); } @@ -6905,28 +7214,13 @@ void process_execsql_destination_select(TSqlParser::Select_statement_standaloneC { Assert(elem->assignment_operator()); - /* We'll rewrite the query similar with EQUAL() but we'll just remove '=' character from token */ - tree::TerminalNode *anode = nullptr; - if (elem->assignment_operator()->PLUS_ASSIGN()) - anode = elem->assignment_operator()->PLUS_ASSIGN(); - else if (elem->assignment_operator()->MINUS_ASSIGN()) - anode = elem->assignment_operator()->MINUS_ASSIGN(); - else if (elem->assignment_operator()->MULT_ASSIGN()) - anode = elem->assignment_operator()->MULT_ASSIGN(); - else if (elem->assignment_operator()->DIV_ASSIGN()) - anode = elem->assignment_operator()->DIV_ASSIGN(); - else if (elem->assignment_operator()->MOD_ASSIGN()) - anode = elem->assignment_operator()->MOD_ASSIGN(); - else if (elem->assignment_operator()->AND_ASSIGN()) - anode = elem->assignment_operator()->AND_ASSIGN(); - else if (elem->assignment_operator()->XOR_ASSIGN()) - anode = elem->assignment_operator()->XOR_ASSIGN(); - else if (elem->assignment_operator()->OR_ASSIGN()) - anode = elem->assignment_operator()->OR_ASSIGN(); - else - Assert(0); - - replaceTokenStringFromQuery(stmt->sqlstmt, anode, rewrite_assign_operator(anode), ctx); + /* + * select with assignment_operator must be re-written already, check process_query_specification. + * For example, @var += expr is already re-written to @var += sys.pltsql_assign_var(dno, "@var" + (expr)) + * Now, We'll rewrite the query similar with EQUAL() but we need to remove '@var +=' from query string. + */ + removeTokenStringFromQuery(stmt->sqlstmt, elem->LOCAL_ID(), ctx); + removeCtxStringFromQuery(stmt->sqlstmt, elem->assignment_operator(), ctx); } } else @@ -6985,29 +7279,80 @@ void process_execsql_destination_update(TSqlParser::Update_statementContext *uct auto elem = elems[i]; if (elem->LOCAL_ID()) { + const char *nameStr = downcase_truncate_identifier(::getFullText(elem->LOCAL_ID()).c_str(), ::getFullText(elem->LOCAL_ID()).length(), true); + PLtsql_nsitem *nse = pltsql_ns_lookup(pltsql_ns_top(), false, nameStr, nullptr, nullptr, nullptr); + PLtsql_var *var = (PLtsql_var *) pltsql_Datums[nse->itemno]; + add_assignment_target_field(target, elem->LOCAL_ID(), returning_col_cnt); if (returning_col_cnt > 0) appendStringInfo(&ds, ", "); ++returning_col_cnt; - if (elem->full_column_name()) + if (elem->EQUAL(0) && elem->full_column_name()) { - /* "SET @a=col=expr" => "SET col=expr ... RETURNING col" */ - appendStringInfo(&ds, "%s", ::getFullText(elem->full_column_name()).c_str()); + /* "SET @a=col=expr" => "SET col=expr ... RETURNING sys.pltsql_assign_var(dno, cast(expr as type))" */ + appendStringInfo(&ds, "sys.pltsql_assign_var(%d, %s)", + nse->itemno, + rewrite_assignment_expression(var, elem->expression())); removeTokenStringFromQuery(stmt->sqlstmt, elem->LOCAL_ID(), uctx); removeTokenStringFromQuery(stmt->sqlstmt, elem->EQUAL(0), uctx); } - else + else if(elem->EQUAL(0) && elem->expression()) { - /* "SET @a=expr, col=expr2" => "SET col=expr2 ... RETURNING expr" */ - appendStringInfo(&ds, "%s", ::getFullText(elem->expression()).c_str()); + /* "SET @a=expr, col=expr2" => "SET col=expr2 ... RETURNING sys.pltsql_assign_var(dno, cast(expr as type))" */ + appendStringInfo(&ds, "sys.pltsql_assign_var(%d, %s)", + nse->itemno, + rewrite_assignment_expression(var, elem->expression())); + handle_local_ids_for_expression(elem->expression()); removeTokenStringFromQuery(stmt->sqlstmt, elem->LOCAL_ID(), uctx); removeTokenStringFromQuery(stmt->sqlstmt, elem->EQUAL(0), uctx); removeCtxStringFromQuery(stmt->sqlstmt, elem->expression(), uctx); } + else if(elem->assignment_operator() && elem->expression()) + { + /* "SET @a+=expr, col=expr2" => "SET col=expr2 ... RETURNING sys.pltsql_assign_var(dno, "@var" + cast((expr) as type))" */ + tree::TerminalNode *anode = nullptr; + + if (elem->assignment_operator()) + { + if (elem->assignment_operator()->PLUS_ASSIGN()) + anode = elem->assignment_operator()->PLUS_ASSIGN(); + else if (elem->assignment_operator()->MINUS_ASSIGN()) + anode = elem->assignment_operator()->MINUS_ASSIGN(); + else if (elem->assignment_operator()->MULT_ASSIGN()) + anode = elem->assignment_operator()->MULT_ASSIGN(); + else if (elem->assignment_operator()->DIV_ASSIGN()) + anode = elem->assignment_operator()->DIV_ASSIGN(); + else if (elem->assignment_operator()->MOD_ASSIGN()) + anode = elem->assignment_operator()->MOD_ASSIGN(); + else if (elem->assignment_operator()->AND_ASSIGN()) + anode = elem->assignment_operator()->AND_ASSIGN(); + else if (elem->assignment_operator()->XOR_ASSIGN()) + anode = elem->assignment_operator()->XOR_ASSIGN(); + else if (elem->assignment_operator()->OR_ASSIGN()) + anode = elem->assignment_operator()->OR_ASSIGN(); + else + Assert(0); + } + appendStringInfo(&ds, "sys.pltsql_assign_var(%d, %s %s %s)", + nse->itemno, + delimitIfAtAtUserVarName(::getFullText(elem->LOCAL_ID())).c_str(), + rewrite_assign_operator(anode), + rewrite_assignment_expression(var, elem->expression())); + + handle_local_ids_for_expression(elem->expression()); + removeTokenStringFromQuery(stmt->sqlstmt, elem->LOCAL_ID(), uctx); + removeCtxStringFromQuery(stmt->sqlstmt, elem->assignment_operator(), uctx); + removeCtxStringFromQuery(stmt->sqlstmt, elem->expression(), uctx); + } + else + { + /* Syntax error should already be handled. */ + Assert(0); + } // Conceptually we have to remove any nearest COMMA. // But code is little bit dirty to handle some corner cases (the first few elems are removed or the last few elems are removed) @@ -7022,11 +7367,21 @@ void process_execsql_destination_update(TSqlParser::Update_statementContext *uct /* remove prev COMMA by default */ removeTokenStringFromQuery(stmt->sqlstmt, uctx->COMMA(i-1), uctx); } + } else comma_carry_over = false; } + /* + * Should remove semi colon before appending RETURNING clause. Otherwise syntax + * error will be thrown. + */ + if (uctx->SEMI()) + { + removeTokenStringFromQuery(stmt->sqlstmt, uctx->SEMI(), uctx); + } + pltsql_adddatum((PLtsql_datum *) target); stmt->target = (PLtsql_variable *)target; @@ -7785,7 +8140,8 @@ post_process_declare_cursor_statement(PLtsql_stmt_decl_cursor *stmt, TSqlParser: static PLtsql_var * lookup_cursor_variable(const char *varname) { - PLtsql_nsitem *nse = pltsql_ns_lookup(pltsql_ns_top(), false, varname, nullptr, nullptr, nullptr); + const char *varnameLookup = downcase_truncate_identifier(varname, strlen(varname), true); + PLtsql_nsitem *nse = pltsql_ns_lookup(pltsql_ns_top(), false, varnameLookup, nullptr, nullptr, nullptr); if (!nse) throw PGErrorWrapperException(ERROR, ERRCODE_SYNTAX_ERROR, format_errmsg("\"%s\" is not a known variable", varname), 0, 0); @@ -8110,23 +8466,25 @@ static tsql_exec_param * makeSpParam(TSqlParser::Execute_statement_arg_namedContext *ctx) { TSqlParser::Execute_parameterContext *exec_param = ctx->execute_parameter(); - Assert(exec_param && ctx->LOCAL_ID()); + Assert(exec_param && ctx->local_id()); tsql_exec_param *p = (tsql_exec_param *) palloc0(sizeof(*p)); - auto targetText = ::getFullText(ctx->LOCAL_ID()); + std::string targetText = ::getFullText(ctx->local_id()); p->name = pstrdup(targetText.c_str()); p->varno = -1; p->mode = FUNC_PARAM_IN; - if (exec_param->LOCAL_ID() && (exec_param->OUTPUT() || exec_param->OUT())) + if (exec_param->local_id() && (exec_param->OUTPUT() || exec_param->OUT())) { - auto *localID = exec_param->LOCAL_ID(); + auto *localID = exec_param->local_id()->LOCAL_ID(); p->varno = getVarno(localID); p->expr = makeTsqlExpr(::getFullText(localID), true); p->mode = FUNC_PARAM_INOUT; } else + { p->expr = makeTsqlExpr(exec_param, true); + } return p; } @@ -8142,15 +8500,17 @@ makeSpParam(TSqlParser::Execute_statement_arg_unnamedContext *ctx) p->varno = -1; p->mode = FUNC_PARAM_IN; - if (exec_param->LOCAL_ID() && (exec_param->OUTPUT() || exec_param->OUT())) + if (exec_param->local_id() && (exec_param->OUTPUT() || exec_param->OUT())) { - auto *localID = exec_param->LOCAL_ID(); + auto *localID = exec_param->local_id()->LOCAL_ID(); p->varno = getVarno(localID); p->expr = makeTsqlExpr(::getFullText(localID), true); p->mode = FUNC_PARAM_INOUT; } else + { p->expr = makeTsqlExpr(exec_param, true); + } return p; } @@ -8159,9 +8519,9 @@ static int getVarno(tree::TerminalNode *localID) { int dno = -1; - auto targetText = ::getFullText(localID); - - PLtsql_nsitem *nse = pltsql_ns_lookup(pltsql_ns_top(), false, targetText.c_str(), nullptr, nullptr, nullptr); + std::string targetText = getFullText(localID); + const char *nameLookup = downcase_truncate_identifier(targetText.c_str(), targetText.length(), true); + PLtsql_nsitem *nse = pltsql_ns_lookup(pltsql_ns_top(), false, nameLookup, nullptr, nullptr, nullptr); if (nse) dno = nse->itemno; @@ -9366,7 +9726,7 @@ handleOrderByOffsetFetch(TSqlParser::Order_by_clauseContext *ctx) // Do not rewrite the entire expression since that will break the logic in the mutator when there is something inside the // expression that also needs rewriting (like a local variable @p which needs to be rewritten as "@p"). // Instead, insert an opening and closing bracket in the right places. - // Also, do not add a rewrite at the start position of the expression since there may be an '@' for a local var + // Also, do not add a rewrite at the start position of the expression since there may be an '@' for a local var // at that position and the rewrite to double-quote the variable will be lost as a result. rewritten_query_fragment.emplace(std::make_pair((ctx->offset_exp->start->getStartIndex() - 1), std::make_pair("", " ("))); rewritten_query_fragment.emplace(std::make_pair((ctx->offset_exp->stop->getStopIndex() + 1), std::make_pair("", ") "))); @@ -9381,3 +9741,121 @@ handleOrderByOffsetFetch(TSqlParser::Order_by_clauseContext *ctx) return; } + +// Determine if a variable name contains a hash or starts with @@: these need special handling +// since the PG backend isn't able to process these names otherwise. +// For predefined global @@variables, these should not be delimited as the backend handles these already. +static bool +isAtAtUserVarName(const std::string name) +{ + if (name.length() >= 3) + { + if (name.front() == '@') + { + if ( + (name.find_first_of("#") != std::string::npos) || + (name[1] == '@') + ) + { + if (name.find_first_not_of("@#$_0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") == std::string::npos) + { + if (!is_tsql_atatglobalvar(name.c_str())) + { + return true; + } + } + } + } + } + return false; +} + +// Check for same variable name as above, but delimited +static bool +isDelimitedAtAtUserVarName(const std::string name) +{ + // Check for delimiters. Both square brackets and double quotes are used as delimiters for variable names. + if (((name.front() == '[') && (name.back() == ']')) || ((name.front() == '"') && (name.back() == '"'))) + { + if (isAtAtUserVarName(name.substr(1,name.length()-2))) + { + return true; + } + } + return false; +} + +// Set up rewrites for variables names containing a hash or starting with @@ +static void +handleLocal_id(TSqlParser::Local_idContext *ctx, bool inSqlObject) +{ + std::string local_id = ::getFullText(ctx); + + // Don't do anything for a predefined T-SQL global @@variable + if (!isAtAtUserVarName(local_id)) + { + return; + } + + // When this is for a table variable declaration, do not add delimiters at this point since internally the nestlevel will be attached first + Assert(ctx->parent); + auto parentCtx = ctx->parent; + if (dynamic_cast(parentCtx)) + { + TSqlParser::Declare_statementContext *declareCtx = static_cast(parentCtx); + if (declareCtx->table_type_definition() != nullptr) + { + return; + } + } + + // For some cases, an @@var or @var# name should not be delimited when it is referenced inside a procedure or trigger, + // as it will be delimited once the body is executed. + if (inSqlObject) + { + if (dynamic_cast(parentCtx)) + { + return; + } + if (dynamic_cast(parentCtx)) + { + return; + } + if (dynamic_cast(parentCtx)) + { + return; + } + if (dynamic_cast(parentCtx)) + { + return; + } + if (dynamic_cast(parentCtx)) + { + return; + } + if (dynamic_cast(parentCtx)) + { + Assert(parentCtx->parent); + if (dynamic_cast(parentCtx->parent)) + { + return; + } + } + } + + // Delimit a variable by rewriting. + // Using double quotes causes SELECT @@V to generate '@@V' as the result, so using square brackets instead. + rewritten_query_fragment.emplace(std::make_pair(ctx->start->getStartIndex(), std::make_pair(local_id, "[" + local_id + "]"))); +} + +// Delimit a variable name directly (rather than by rewriting) +static std::string +delimitIfAtAtUserVarName(const std::string name) +{ + std::string str = name; + if (isAtAtUserVarName(name)) + { + str = "[" + str + "]"; + } + return str; +} diff --git a/contrib/babelfishpg_tsql/src/tsqlUnsupportedFeatureHandler.cpp b/contrib/babelfishpg_tsql/src/tsqlUnsupportedFeatureHandler.cpp index 097444d5fe..fd86e02bc9 100644 --- a/contrib/babelfishpg_tsql/src/tsqlUnsupportedFeatureHandler.cpp +++ b/contrib/babelfishpg_tsql/src/tsqlUnsupportedFeatureHandler.cpp @@ -1333,6 +1333,24 @@ antlrcpp::Any TsqlUnsupportedFeatureHandlerImpl::visitTransaction_statement(TSql antlrcpp::Any TsqlUnsupportedFeatureHandlerImpl::visitDbcc_statement(TSqlParser::Dbcc_statementContext *ctx) { + if (ctx->CHECKIDENT()) + { + Assert(ctx->dbcc_table_name()); + if (ctx->dbcc_table_name()->local_id()) + { + throw PGErrorWrapperException(ERROR, ERRCODE_SYNTAX_ERROR, + "DBCC CHECKIDENT does not currently support a variable for the table name", + getLineAndPos(ctx->dbcc_table_name())); + } + + if (ctx->checkident_new_value()) + { + if (ctx->checkident_new_value()->local_id()) + throw PGErrorWrapperException(ERROR, ERRCODE_SYNTAX_ERROR, + "DBCC CHECKIDENT does not currently support a variable for the RESEED value", + getLineAndPos(ctx->checkident_new_value())); + } + } if (ctx->dbcc_command()) { diff --git a/dev-tools.sh b/dev-tools.sh index ab8681c2ab..c4ee7b3a84 100755 --- a/dev-tools.sh +++ b/dev-tools.sh @@ -187,7 +187,7 @@ init_pg() { make -j 4 make install cd contrib && make && sudo make install - cp "/usr/local/lib/libantlr4-runtime.so.4.9.3" $2/postgres/lib/ + cp "/usr/local/lib/libantlr4-runtime.so.4.13.2" $2/postgres/lib/ init_pghint $1 $2 } @@ -306,7 +306,7 @@ init_pg_coverage(){ make -j 4 make install cd contrib && make && sudo make install - sudo cp "/usr/local/lib/libantlr4-runtime.so.4.9.3" $2/postgres/lib/ + sudo cp "/usr/local/lib/libantlr4-runtime.so.4.13.2" $2/postgres/lib/ init_pghint $1 $2 } diff --git a/test/JDBC/expected/BABEL-3092.out b/test/JDBC/expected/BABEL-3092.out index ef55195463..748c1074f0 100644 --- a/test/JDBC/expected/BABEL-3092.out +++ b/test/JDBC/expected/BABEL-3092.out @@ -356,7 +356,7 @@ EXEC("SELECT * FROM t") GO ~~ERROR (Code: 33557097)~~ -~~ERROR (Message: column "select * from t" does not exist)~~ +~~ERROR (Message: relation "t" does not exist)~~ EXEC(@v) GO diff --git a/test/JDBC/expected/BABEL-5422.out b/test/JDBC/expected/BABEL-5422.out new file mode 100644 index 0000000000..7762b02e6b --- /dev/null +++ b/test/JDBC/expected/BABEL-5422.out @@ -0,0 +1,205 @@ +-- Create tables +CREATE TABLE babel_5422_table ( + [primary] INT PRIMARY KEY, + Name VARCHAR(50) +); +GO + +CREATE TABLE babel_5422_table2 ( + [PRIMARY] INT, + Age INT +); +GO + +CREATE TABLE #babel_5422_table3 ( + [primary_column] INT, + Age INT +); +GO + +-- Insert sample data +INSERT INTO babel_5422_table ([primary], Name) +VALUES (1, 'John'), (2, 'Jane'), (3, 'Bob'); +GO +~~ROW COUNT: 3~~ + + +INSERT INTO babel_5422_table2 ([primary], Age) +VALUES (1, 25), (3, 30); +GO +~~ROW COUNT: 2~~ + + +INSERT INTO #babel_5422_table3 ([primary_column], Age) +VALUES (1, 30), (3, 40); +GO +~~ROW COUNT: 2~~ + + +-- Aliasing +SELECT [primary] AS PrimaryKey, Name +FROM babel_5422_table; +GO +~~START~~ +int#!#varchar +1#!#John +2#!#Jane +3#!#Bob +~~END~~ + + +SELECT [primary_column] AS [Primary], Age +FROM #babel_5422_table3; +GO +~~START~~ +int#!#int +1#!#30 +3#!#40 +~~END~~ + + +-- Joining Tables +SELECT t1.[primary], t1.Name, t2.Age +FROM babel_5422_table t1 +JOIN babel_5422_table2 t2 ON t1.[primary] = t2.[primary]; +GO +~~START~~ +int#!#varchar#!#int +1#!#John#!#25 +3#!#Bob#!#30 +~~END~~ + + +-- Aggregation +SELECT COUNT([primary]) AS TotalRows +FROM babel_5422_table; +GO +~~START~~ +int +3 +~~END~~ + + +-- Ordering +SELECT * +FROM babel_5422_table +ORDER BY [primary] DESC; +GO +~~START~~ +int#!#varchar +3#!#Bob +2#!#Jane +1#!#John +~~END~~ + + +-- Checking for Existence +IF EXISTS (SELECT 1 FROM babel_5422_table WHERE [primary] = 3) + PRINT 'Row with [primary] = 3 exists'; +ELSE + PRINT 'Row with [primary] = 3 does not exist'; +GO + +-- Using in a CASE Statement +SELECT [primary], + CASE + WHEN [primary] = 1 THEN 'One' + WHEN [primary] = 2 THEN 'Two' + ELSE 'Other' + END AS PrimaryDescription +FROM babel_5422_table; +GO +~~START~~ +int#!#varchar +1#!#One +2#!#Two +3#!#Other +~~END~~ + + +-- Using in a Subquery +SELECT Name +FROM babel_5422_table +WHERE [primary] IN (SELECT [primary] FROM babel_5422_table2); +GO +~~START~~ +varchar +John +Bob +~~END~~ + + +-- Using in a View +CREATE VIEW babel_5422_view +AS +SELECT [primary], Name +FROM babel_5422_table; +GO + +SELECT * FROM babel_5422_view; +GO +~~START~~ +int#!#varchar +1#!#John +2#!#Jane +3#!#Bob +~~END~~ + + +-- Using in a Stored Procedure +CREATE PROCEDURE babel_5422_proc + @PrimaryKey INT +AS +BEGIN + SELECT [primary], Name + FROM babel_5422_table + WHERE [primary] = @PrimaryKey; +END +GO + +EXEC babel_5422_proc 2; +GO +~~START~~ +int#!#varchar +2#!#Jane +~~END~~ + + +-- Using in a User-Defined Function +CREATE FUNCTION babel_5422_func + (@PrimaryKey INT) +RETURNS TABLE +AS +RETURN( + SELECT [primary], Name + FROM babel_5422_table + WHERE [primary] = @PrimaryKey +) +GO + +SELECT babel_5422_func(3); +GO +~~START~~ +varchar +(3,Bob) +~~END~~ + + +-- Cleanup +DROP FUNCTION babel_5422_func; +GO + +DROP PROCEDURE babel_5422_proc; +GO + +DROP VIEW babel_5422_view; +GO + +DROP TABLE #babel_5422_table3 +GO + +DROP TABLE babel_5422_table2; +GO + +DROP TABLE babel_5422_table; +GO diff --git a/test/JDBC/expected/BABEL-CROSS-DB-vu-cleanup.out b/test/JDBC/expected/BABEL-CROSS-DB-vu-cleanup.out index 8cd04100a6..867c5cdcf8 100644 --- a/test/JDBC/expected/BABEL-CROSS-DB-vu-cleanup.out +++ b/test/JDBC/expected/BABEL-CROSS-DB-vu-cleanup.out @@ -39,6 +39,12 @@ GO DROP TABLE babel_cross_db_vu_prepare_s1.babel_cross_db_vu_prepare_t1; GO +DROP TABLE babel_cross_db_vu_prepare_t4; +GO + +DROP LOGIN babel_cross_db_vu_prepare_l3; +GO + DROP FUNCTION babel_cross_db_vu_prepare_s1.babel_cross_db_vu_prepare_f1; GO diff --git a/test/JDBC/expected/BABEL-CROSS-DB-vu-prepare.out b/test/JDBC/expected/BABEL-CROSS-DB-vu-prepare.out index de4fe280eb..5a9cf7047e 100644 --- a/test/JDBC/expected/BABEL-CROSS-DB-vu-prepare.out +++ b/test/JDBC/expected/BABEL-CROSS-DB-vu-prepare.out @@ -263,3 +263,19 @@ GO GRANT EXECUTE ON FUNCTION master_dbo.babel_cross_db_vu_prepare_pg_func to master_babel_cross_db_vu_prepare_u1; GO + +-- tsql +USE master; +GO + +CREATE LOGIN babel_cross_db_vu_prepare_l3 WITH PASSWORD = '12345678'; +GO + +CREATE USER babel_cross_db_vu_prepare_u3 FOR LOGIN babel_cross_db_vu_prepare_l3; +GO + +CREATE TABLE babel_cross_db_vu_prepare_t4 (a INT); +GO + +GRANT SELECT ON babel_cross_db_vu_prepare_t4 TO guest; +GO diff --git a/test/JDBC/expected/BABEL-CROSS-DB-vu-verify.out b/test/JDBC/expected/BABEL-CROSS-DB-vu-verify.out index e31bc1dfd8..2e11a0a057 100644 --- a/test/JDBC/expected/BABEL-CROSS-DB-vu-verify.out +++ b/test/JDBC/expected/BABEL-CROSS-DB-vu-verify.out @@ -417,6 +417,9 @@ GO ALTER LOGIN babel_cross_db_vu_prepare_l2 with password = '12345678'; GO +ALTER LOGIN babel_cross_db_vu_prepare_l3 with password = '12345678'; +GO + -- tsql user=babel_cross_db_vu_prepare_l1 password=12345678 USE master; GO @@ -673,9 +676,58 @@ int ~~END~~ +create user user_cannot_connect for login babel_cross_db_vu_prepare_l2; +go + +revoke connect from user_cannot_connect; +go + GRANT CONNECT TO guest; GO +grant select on babel_cross_db_vu_prepare_db1_t1 to guest; +go + +-- tsql user=babel_cross_db_vu_prepare_l2 password=12345678 +USE my_babel_cross_db_vu_prepare_db1 +GO + +select current_user +go +~~START~~ +varchar +user_cannot_connect +~~END~~ + + +select has_dbaccess('my_babel_cross_db_vu_prepare_db1'); +go +~~START~~ +int +1 +~~END~~ + + +select * from dbo.babel_cross_db_vu_prepare_db1_t1; -- should not use guest privilege +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: permission denied for table babel_cross_db_vu_prepare_db1_t1)~~ + + +USE master +GO + +-- tsql +USE my_babel_cross_db_vu_prepare_db1 +GO + +revoke select on babel_cross_db_vu_prepare_db1_t1 from guest; +go + +drop user user_cannot_connect; +go + -- tsql user=babel_cross_db_vu_prepare_l2 password=12345678 -- cross-db tests for guest user USE master @@ -714,6 +766,33 @@ int ~~END~~ +-- tsql user=babel_cross_db_vu_prepare_l3 password=12345678 +USE master +GO + +-- login babel_cross_db_vu_prepare_l3 has mapped user in master +-- database so following SELECT should fail. +SELECT * FROM babel_cross_db_vu_prepare_t4; +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: permission denied for table babel_cross_db_vu_prepare_t4)~~ + + +-- tsql +-- now moreve mapped user from login babel_cross_db_vu_prepare_l3 in master database +DROP USER babel_cross_db_vu_prepare_u3; +GO + +-- now that login babel_cross_db_vu_prepare_l3 does not have a mapped user in master +-- database so following SELECT should succeed as guest was granted SELECT privilege. +SELECT * FROM babel_cross_db_vu_prepare_t4; +GO +~~START~~ +int +~~END~~ + + -- tsql USE master GO diff --git a/test/JDBC/expected/BABEL-CROSS-DB.out b/test/JDBC/expected/BABEL-CROSS-DB.out index c57fb1821d..39e9e14917 100644 --- a/test/JDBC/expected/BABEL-CROSS-DB.out +++ b/test/JDBC/expected/BABEL-CROSS-DB.out @@ -1003,411 +1003,3 @@ GO DROP DATABASE db2; GO - --- BABEL-4934 Test blocking cross-db SELECT-INTO statement -CREATE DATABASE db_4934_1; -GO - -CREATE DATABASE db_4934_2; -GO - -USE master; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_1; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_2; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_1; -GO - --- #4934.1 It should be blocked -SELECT * INTO t222 FROM master.dbo.t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM master..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM db_4934_2..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM db_4934_2.dbo.t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM db_4934_2..t1, t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM t1, db_4934_1..t2; -GO - -SELECT * INTO t222 FROM master..t1, db_4934_2..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM (SELECT * FROM master..t1); -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM (SELECT * FROM t1, master..t1); -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM (SELECT *, (SELECT * FROM master..t1) FROM t1); -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM (SELECT *, (SELECT * FROM t1) FROM master..t3); -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO master..t222 FROM db_4934_2..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO db_4934_1..t222 FROM db_4934_2..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO master..t222 FROM master..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - --- #4934.2 Following statements will succeed across same database -SELECT * INTO t3 FROM db_4934_1.dbo.t1; -GO - -SELECT * INTO t4 FROM dbo.t1; -GO - -SELECT * INTO t5 FROM db_4934_1..t1; -GO - -SELECT * INTO t6 FROM db_4934_1..t1, db_4934_1..t2; -GO - -SELECT * INTO t7 FROM (SELECT * FROM db_4934_1..t1); -GO - -SELECT * INTO t8 FROM (SELECT *, (SELECT * FROM db_4934_1..t2) FROM db_4934_1..t1); -GO - --- validate the access -SELECT * FROM t3, t4, t5, t6, t7, t8; -GO -~~START~~ -int#!#int#!#int#!#int#!#int#!#int#!#int#!#int -~~END~~ - - -DROP TABLE t3, t4, t5, t6, t7, t8; -GO - --- #4934.3 Temporary table should not be blocked -SELECT * INTO #t1 FROM db_4934_1.dbo.t1; -GO - -SELECT * INTO #t2 FROM (SELECT * FROM db_4934_1.dbo.t1); -GO - --- validate the access -SELECT * FROM #t1, #t2; -GO -~~START~~ -int#!#int -~~END~~ - - -DROP TABLE #t1, #t2; -GO - --- Even though this is same as above statement, this will still fail since --- internally it considers as cross-db statement (This behaviour is general to --- all of the applicable DMLs) -SELECT * INTO tempdb..#t3 FROM db_4934_1.dbo.t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - - -USE master; -GO - -DROP TABLE t1, t2; -GO - -DROP DATABASE db_4934_1; -GO - -DROP DATABASE db_4934_2; -GO - --- Repeating tests with AI collated database --- BABEL-4934 Test blocking cross-db SELECT-INTO statement -CREATE DATABASE db_4934_1 COLLATE BBF_Unicode_CP1_CI_AI; -GO - -CREATE DATABASE db_4934_2 COLLATE BBF_Unicode_CP1_CI_AI; -GO - -USE master; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_1; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_2; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_1; -GO - --- #4934.1 It should be blocked -SELECT * INTO t222 FROM master.dbo.t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM master..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM db_4934_2..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM db_4934_2.dbo.t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM db_4934_2..t1, t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM t1, db_4934_1..t2; -GO - -SELECT * INTO t222 FROM master..t1, db_4934_2..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM (SELECT * FROM master..t1); -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM (SELECT * FROM t1, master..t1); -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM (SELECT *, (SELECT * FROM master..t1) FROM t1); -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM (SELECT *, (SELECT * FROM t1) FROM master..t3); -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO master..t222 FROM db_4934_2..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO db_4934_1..t222 FROM db_4934_2..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO master..t222 FROM master..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - --- #4934.2 Following statements will succeed across same database -SELECT * INTO t3 FROM db_4934_1.dbo.t1; -GO - -SELECT * INTO t4 FROM dbo.t1; -GO - -SELECT * INTO t5 FROM db_4934_1..t1; -GO - -SELECT * INTO t6 FROM db_4934_1..t1, db_4934_1..t2; -GO - -SELECT * INTO t7 FROM (SELECT * FROM db_4934_1..t1); -GO - -SELECT * INTO t8 FROM (SELECT *, (SELECT * FROM db_4934_1..t2) FROM db_4934_1..t1); -GO - --- validate the access -SELECT * FROM t3, t4, t5, t6, t7, t8; -GO -~~START~~ -int#!#int#!#int#!#int#!#int#!#int#!#int#!#int -~~END~~ - - -DROP TABLE t3, t4, t5, t6, t7, t8; -GO - --- #4934.3 Temporary table should not be blocked -SELECT * INTO #t1 FROM db_4934_1.dbo.t1; -GO - -SELECT * INTO #t2 FROM (SELECT * FROM db_4934_1.dbo.t1); -GO - --- validate the access -SELECT * FROM #t1, #t2; -GO -~~START~~ -int#!#int -~~END~~ - - -DROP TABLE #t1, #t2; -GO - --- Even though this is same as above statement, this will still fail since --- internally it considers as cross-db statement (This behaviour is general to --- all of the applicable DMLs) -SELECT * INTO tempdb..#t3 FROM db_4934_1.dbo.t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - - -USE master; -GO - -DROP TABLE t1, t2; -GO - -DROP DATABASE db_4934_1; -GO - -DROP DATABASE db_4934_2; -GO - diff --git a/test/JDBC/expected/BABEL-USER-vu-cleanup.out b/test/JDBC/expected/BABEL-USER-vu-cleanup.out index 0c17026b74..8a3c125629 100644 --- a/test/JDBC/expected/BABEL-USER-vu-cleanup.out +++ b/test/JDBC/expected/BABEL-USER-vu-cleanup.out @@ -22,5 +22,8 @@ GO DROP LOGIN babel_user_vu_prepare_test5 GO +DROP LOGIN babel_user_vu_prepare_test6 +GO + DROP LOGIN babel_user_vu_prepare_long_login_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA GO diff --git a/test/JDBC/expected/BABEL-USER-vu-prepare.out b/test/JDBC/expected/BABEL-USER-vu-prepare.out index 0bd1b6d37d..e95650c174 100644 --- a/test/JDBC/expected/BABEL-USER-vu-prepare.out +++ b/test/JDBC/expected/BABEL-USER-vu-prepare.out @@ -13,6 +13,9 @@ GO CREATE LOGIN babel_user_vu_prepare_test5 WITH PASSWORD = 'abc'; GO +CREATE LOGIN babel_user_vu_prepare_test6 WITH PASSWORD = 'abc'; +GO + CREATE LOGIN babel_user_vu_prepare_long_login_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA WITH PASSWORD = 'abc'; GO diff --git a/test/JDBC/expected/BABEL-USER-vu-verify.out b/test/JDBC/expected/BABEL-USER-vu-verify.out index fac3e3f2af..e0b61e3eda 100644 --- a/test/JDBC/expected/BABEL-USER-vu-verify.out +++ b/test/JDBC/expected/BABEL-USER-vu-verify.out @@ -239,6 +239,9 @@ babel_user_vu_prepare_test3#!#babel_user_vu_prepare_sch ALTER LOGIN babel_user_vu_prepare_test5 WITH PASSWORD = 'abc'; GO +ALTER LOGIN babel_user_vu_prepare_test6 WITH PASSWORD = 'abc'; +GO + -- tsql user=babel_user_vu_prepare_test5 password=abc SELECT CURRENT_USER; go @@ -258,6 +261,45 @@ t ~~END~~ +-- tsql +-- Now map user babel_user_vu_prepare_test3 to a different login babel_user_vu_prepare_test6 +ALTER USER babel_user_vu_prepare_test3 WITH LOGIN = babel_user_vu_prepare_test6; +GO + +-- psql +-- Login babel_user_vu_prepare_test5 should no longer be a member of user babel_user_vu_prepare_test3 +SELECT pg_has_role('babel_user_vu_prepare_test5', 'master_babel_user_vu_prepare_test3', 'member') +GO +~~START~~ +bool +f +~~END~~ + + +-- Login babel_user_vu_prepare_test6 should be a member of user babel_user_vu_prepare_test3 +SELECT pg_has_role('babel_user_vu_prepare_test6', 'master_babel_user_vu_prepare_test3', 'member') +GO +~~START~~ +bool +t +~~END~~ + + +-- tsql +-- Again map user babel_user_vu_prepare_test3 to login babel_user_vu_prepare_test5 +ALTER USER babel_user_vu_prepare_test3 WITH LOGIN = babel_user_vu_prepare_test5; +GO + +-- tsql user=babel_user_vu_prepare_test6 password=abc +-- Login babel_user_vu_prepare_test6 should now be mapped to guest user +SELECT CURRENT_USER; +go +~~START~~ +varchar +guest +~~END~~ + + -- tsql -- both of the commands below should fail ALTER USER babel_user_vu_prepare_test3 WITH LOGIN = babel_user_vu_prepare_test1; @@ -284,6 +326,7 @@ babel_user_vu_prepare_test2 babel_user_vu_prepare_test3 babel_user_vu_prepare_test4 babel_user_vu_prepare_test5 +babel_user_vu_prepare_test6 master_babel_user_vu_prepare_aacb2aa14e22b38c44e8614f1eae6949f8 master_babel_user_vu_prepare_test1_new master_babel_user_vu_prepare_test2 diff --git a/test/JDBC/expected/BABEL_GRANT_CONNECT-vu-cleanup.out b/test/JDBC/expected/BABEL_GRANT_CONNECT-vu-cleanup.out index 5fcd152d2d..90adad9212 100644 --- a/test/JDBC/expected/BABEL_GRANT_CONNECT-vu-cleanup.out +++ b/test/JDBC/expected/BABEL_GRANT_CONNECT-vu-cleanup.out @@ -2,7 +2,7 @@ use grant_connect_db1; go -drop user grant_connect_abc +drop user grant_connect_abc_new go drop table grant_connect_t1; diff --git a/test/JDBC/expected/BABEL_GRANT_CONNECT-vu-prepare.out b/test/JDBC/expected/BABEL_GRANT_CONNECT-vu-prepare.out index 941da73d0f..672acdf923 100644 --- a/test/JDBC/expected/BABEL_GRANT_CONNECT-vu-prepare.out +++ b/test/JDBC/expected/BABEL_GRANT_CONNECT-vu-prepare.out @@ -9,4 +9,3 @@ go create login grant_connect_abc with password = 'Babel123' go - diff --git a/test/JDBC/expected/BABEL_GRANT_CONNECT-vu-verify.out b/test/JDBC/expected/BABEL_GRANT_CONNECT-vu-verify.out index 7a9e3c3624..013bbe1c2e 100644 --- a/test/JDBC/expected/BABEL_GRANT_CONNECT-vu-verify.out +++ b/test/JDBC/expected/BABEL_GRANT_CONNECT-vu-verify.out @@ -92,6 +92,14 @@ go use grant_connect_db1; go +select has_dbaccess('grant_connect_db1'); +go +~~START~~ +int +1 +~~END~~ + + select user_name(); go ~~START~~ @@ -182,6 +190,9 @@ go grant connect to grant_connect_abc go +ALTER USER grant_connect_abc WITH NAME = grant_connect_abc_new; +go + -- tsql user=grant_connect_abc password=Babel123 -- should succeed because login has a user for grant_connect_db1 and it is enabled use grant_connect_db1 @@ -191,7 +202,14 @@ select user_name(); go ~~START~~ nvarchar -grant_connect_abc +grant_connect_abc_new ~~END~~ +select has_dbaccess('grant_connect_db1'); +go +~~START~~ +int +1 +~~END~~ + diff --git a/test/JDBC/expected/Test-sp_reset_connection.out b/test/JDBC/expected/Test-sp_reset_connection.out index 28dd97afb7..b66e9f8585 100644 --- a/test/JDBC/expected/Test-sp_reset_connection.out +++ b/test/JDBC/expected/Test-sp_reset_connection.out @@ -513,3 +513,212 @@ int drop table babel_cursor_t1; GO + + +-- GUCs testing +-- 1. Ansi defaults +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_nulls', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_warnings', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_null_dflt_on', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_padding', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.implicit_transactions', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.quoted_identifier', true); +GO +~~START~~ +text +on +~~END~~ + +~~START~~ +text +on +~~END~~ + +~~START~~ +text +on +~~END~~ + +~~START~~ +text +on +~~END~~ + +~~START~~ +text +off +~~END~~ + +~~START~~ +text +on +~~END~~ + + +SET ANSI_DEFAULTS ON +GO + +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_nulls', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_warnings', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_null_dflt_on', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_padding', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.implicit_transactions', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.quoted_identifier', true); +GO +~~START~~ +text +on +~~END~~ + +~~START~~ +text +on +~~END~~ + +~~START~~ +text +on +~~END~~ + +~~START~~ +text +on +~~END~~ + +~~START~~ +text +on +~~END~~ + +~~START~~ +text +on +~~END~~ + + +-- reset +exec sys.sp_reset_connection +GO + +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_nulls', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_warnings', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_null_dflt_on', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_padding', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.implicit_transactions', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.quoted_identifier', true); +GO +~~START~~ +text +on +~~END~~ + +~~START~~ +text +on +~~END~~ + +~~START~~ +text +on +~~END~~ + +~~START~~ +text +on +~~END~~ + +~~START~~ +text +off +~~END~~ + +~~START~~ +text +on +~~END~~ + + +-- babelfish_showplan_all +SET babelfish_showplan_all ON +GO + +-- explain output +SELECT 1; +GO +~~START~~ +text +Query Text: SELECT 1 +Result (cost=0.00..0.01 rows=1 width=4) +~~END~~ + +~~START~~ +text +Babelfish T-SQL Batch Parsing Time: 0.085 ms +~~END~~ + + +-- reset +exec sys.sp_reset_connection +GO + +-- 1 output +SELECT 1; +GO +~~START~~ +int +1 +~~END~~ + + + +-- set_config testing. +-- search_path has source < PGC_S_SESSION in TSQL but it gets reset during ResetAll Gucs. +-- Whereas role does not get reset since it uses GUC_NO_RESET_ALL, so we should not allow +-- set_config for this option. +SELECT CURRENT_SETTING('search_path', true) +SELECT CURRENT_SETTING('role', true) +GO +~~START~~ +text +master_dbo, "$user", sys, pg_catalog +~~END~~ + +~~START~~ +text +master_dbo +~~END~~ + + +SELECT set_config('search_path', 'sys', false); +GO +~~START~~ +text +sys +~~END~~ + +SELECT set_config('role', 'jdbc_user', false); +GO +~~START~~ +text +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: set_config not allowed for option role)~~ + + +-- reset +exec sp_reset_connection +GO + +SELECT CURRENT_SETTING('search_path', true) +SELECT CURRENT_SETTING('role', true) +GO +~~START~~ +text +master_dbo, "$user", sys, pg_catalog +~~END~~ + +~~START~~ +text +master_dbo +~~END~~ + diff --git a/test/JDBC/expected/Test-spatial-functions-vu-verify.out b/test/JDBC/expected/Test-spatial-functions-vu-verify.out index d782fabca1..1872298f3a 100644 --- a/test/JDBC/expected/Test-spatial-functions-vu-verify.out +++ b/test/JDBC/expected/Test-spatial-functions-vu-verify.out @@ -404,7 +404,7 @@ GO ~~START~~ numeric#!#int #!#1 -0#!#2 +0E-8#!#2 ~~END~~ @@ -810,7 +810,7 @@ bit ~~START~~ numeric#!#int #!#1 -0#!#2 +0E-8#!#2 ~~END~~ @@ -1027,6 +1027,8 @@ SET @point2 = 'Test_String'; SELECT @point1.STEquals(@point2); SELECT @point1.STContains(@point2); go +~~START~~ +bit ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: parse error - invalid geometry)~~ @@ -1038,6 +1040,8 @@ SET @point2 = 'Test_String'; SELECT @point1.STEquals(@point2); SELECT @point1.STContains(@point2); go +~~START~~ +bit ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: parse error - invalid geometry)~~ diff --git a/test/JDBC/expected/TestSpatialPoint-vu-verify.out b/test/JDBC/expected/TestSpatialPoint-vu-verify.out index d4d953a032..4f23dbaed3 100644 --- a/test/JDBC/expected/TestSpatialPoint-vu-verify.out +++ b/test/JDBC/expected/TestSpatialPoint-vu-verify.out @@ -223,6 +223,8 @@ SET @point1 = geometry::Point(22.34900, -47.65100, 4326);; SET @point2 = 'Test_String'; SELECT @point1.STDistance(@point2); Go +~~START~~ +float ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: parse error - invalid geometry)~~ @@ -2314,6 +2316,8 @@ SET @point1 = geography::Point(22.34900, -47.65100, 4326); SET @point2 = 'Test_String'; SELECT @point2.STDistance(@point1); Go +~~START~~ +float ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: parse error - invalid geometry)~~ diff --git a/test/JDBC/expected/alter_proc_recompile-vu-verify.out b/test/JDBC/expected/alter_proc_recompile-vu-verify.out index 88ec23f84d..9a06d8610c 100644 --- a/test/JDBC/expected/alter_proc_recompile-vu-verify.out +++ b/test/JDBC/expected/alter_proc_recompile-vu-verify.out @@ -176,7 +176,7 @@ Query Text: EXEC p_alter_recomp_01 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.150 ms +Babelfish T-SQL Batch Parsing Time: 0.183 ms ~~END~~ execute p_alter_recomp_02 0 -- created with recompile @@ -191,7 +191,7 @@ Query Text: EXEC p_alter_recomp_02 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.079 ms +Babelfish T-SQL Batch Parsing Time: 0.097 ms ~~END~~ execute p_alter_recomp_11 0 -- altered with recompile; for MVU test @@ -206,7 +206,7 @@ Query Text: EXEC p_alter_recomp_11 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.075 ms +Babelfish T-SQL Batch Parsing Time: 0.085 ms ~~END~~ execute p_alter_recomp_12 0 -- altered without recompile; for MVU test @@ -221,7 +221,7 @@ Query Text: EXEC p_alter_recomp_12 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.075 ms +Babelfish T-SQL Batch Parsing Time: 0.081 ms ~~END~~ set babelfish_showplan_all off @@ -244,7 +244,7 @@ Query Text: EXEC p_alter_recomp_01 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.066 ms +Babelfish T-SQL Batch Parsing Time: 0.069 ms ~~END~~ execute p_alter_recomp_02 0 -- created with recompile @@ -259,7 +259,7 @@ Query Text: EXEC p_alter_recomp_02 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.073 ms +Babelfish T-SQL Batch Parsing Time: 0.079 ms ~~END~~ set babelfish_showplan_all off @@ -364,7 +364,7 @@ Query Text: EXEC p_alter_recomp_01 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.067 ms +Babelfish T-SQL Batch Parsing Time: 0.072 ms ~~END~~ execute p_alter_recomp_02 0 -- altered without recompile @@ -379,7 +379,7 @@ Query Text: EXEC p_alter_recomp_02 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.075 ms +Babelfish T-SQL Batch Parsing Time: 0.079 ms ~~END~~ set babelfish_showplan_all off diff --git a/test/JDBC/expected/atatuservar-vu-cleanup.out b/test/JDBC/expected/atatuservar-vu-cleanup.out new file mode 100644 index 0000000000..3c57e1c16c --- /dev/null +++ b/test/JDBC/expected/atatuservar-vu-cleanup.out @@ -0,0 +1,167 @@ +drop procedure p1_atatuservar +go +drop procedure p2_atatuservar +go +drop function f1_atatuservar +go +drop function f2_atatuservar +go +drop procedure p3_atatuservar +go +drop function f3_atatuservar +go +drop procedure p4_atatuservar +go +drop procedure p19_atatuservar +go +drop procedure p5_atatuservar +go +drop procedure p6_atatuservar +go +drop procedure p7_atatuservar +go +drop procedure p8_atatuservar +go +drop procedure p9_atatuservar +go +drop procedure p10_atatuservar +go +drop procedure p11_atatuservar +go +drop function f4_atatuservar +go +drop procedure p22_atatuservar +go +drop procedure p12_atatuservar +go +drop procedure p13_atatuservar +go +drop procedure p14_atatuservar +go +drop function f1_atatuservar_extra_long_name_here +go +drop function f2_atatuservar_extra_long_name_here +go +drop procedure p15_atatuservar +go +drop procedure p16_atatuservar +go +drop procedure p17_atatuservar +go +drop procedure p18_atatuservar +go +drop procedure p1_raiserror_atatuservar +go +drop procedure p1_spexec_atatuservar +go +drop procedure p2_spexec_atatuservar +go +drop function f1_ins_atatuservar +go +drop function f1_upd_atatuservar +go +drop function f1_del_atatuservar +go +drop function f3_atatuservar_upd +go +drop function f3_atatuservar_del +go +drop function f3_upd_atatuservar +go +drop function f3_del_atatuservar +go +drop function f4_ins_atatuservar +go +drop function f4_upd_atatuservar +go +drop function f4_del_atatuservar +go +drop function f5_upd_atatuservar +go +drop function f5_del_atatuservar +go +drop function f6_upd_atatuservar +go +drop function f6_del_atatuservar +go +drop function f7_tabvar_udf_upd_atatuservar +go +drop function f9_tabvar_udf_del_atatuservar +go +drop function f10_tabvar_udf_del_atatuservar +go +drop function f4_atatuservar_tabvar_in_function_upd +go +drop function f14_del_atatuservar +go +drop function f15_upd_atatuservar +go +drop procedure p20_atatuservar +go +drop procedure p21_atatuservar +go +drop procedure p1_xactname_atatuservar +go +drop procedure p2_xactname_atatuservar +go + +drop table t1_atatuservar +go +drop table t2_atatuservar +go +drop table t3_atatuservar +go +drop table t_checkident_atatuservar +go +drop table t1_trigger_atatuservar +go +drop table t2_trigger_atatuservar +go +drop table t3_trigger_atatuservar +go +drop table t4_trigger_atatuservar +go +drop table t5_trigger_atatuservar +go +drop table t6_trigger_atatuservar +go +drop table t7_trigger_atatuservar +go +drop table t8_trigger_atatuservar +go +drop table t9_trigger_atatuservar +go +drop table t10_trigger_atatuservar +go +drop table t11_trigger_atatuservar +go +drop table t12_trigger_atatuservar +go +drop table t13_trigger_atatuservar +go +drop table t14_trigger_atatuservar +go +drop table t15_trigger_atatuservar +go +drop table t16_trigger_atatuservar +go +drop table t17_trigger_atatuservar +go +drop table t18_trigger_atatuservar +go +drop table t19_trigger_atatuservar +go +drop table t20_trigger_atatuservar +go +drop table t21_trigger_atatuservar +go +drop table t22_trigger_atatuservar +go +drop table t23_trigger_atatuservar +go +drop procedure p1_cursor_atatuservar +go +drop procedure p1_sysfunctions_atatuservar +go +drop function f1_sysfunctions_atatuservar +go diff --git a/test/JDBC/expected/atatuservar-vu-prepare.out b/test/JDBC/expected/atatuservar-vu-prepare.out new file mode 100644 index 0000000000..68eeafe85c --- /dev/null +++ b/test/JDBC/expected/atatuservar-vu-prepare.out @@ -0,0 +1,76 @@ +create table t1_atatuservar (c varchar(20)) +insert t1_atatuservar values ('row 1'), ('row 2'), ('row 3') +go +~~ROW COUNT: 3~~ + +create table t2_atatuservar (a int) +insert t2_atatuservar values(123) +go +~~ROW COUNT: 1~~ + +create table t3_atatuservar (a int) +insert t3_atatuservar values(123) +go +~~ROW COUNT: 1~~ + +create table t_checkident_atatuservar (a varchar(20), n int identity) +go +insert t_checkident_atatuservar values('one') +insert t_checkident_atatuservar values('two') +insert t_checkident_atatuservar values('three') +insert t_checkident_atatuservar values('four') +go +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +create table t1_trigger_atatuservar (a int) +go +create table t2_trigger_atatuservar (a int) +go +create table t3_trigger_atatuservar (a int) +go +create table t4_trigger_atatuservar (a int) +go +create table t5_trigger_atatuservar (a int) +go +create table t6_trigger_atatuservar (a int) +go +create table t7_trigger_atatuservar (a int) +go +create table t8_trigger_atatuservar (a int) +go +create table t9_trigger_atatuservar (a int) +go +create table t10_trigger_atatuservar(a int) +go +create table t11_trigger_atatuservar(a int) +go +create table t12_trigger_atatuservar(a int) +go +create table t13_trigger_atatuservar(a int) +go +create table t14_trigger_atatuservar(a int) +go +create table t15_trigger_atatuservar(a int) +go +create table t16_trigger_atatuservar(a int) +go +create table t17_trigger_atatuservar(a int) +go +create table t18_trigger_atatuservar(a int) +go +create table t19_trigger_atatuservar(a int) +go +create table t20_trigger_atatuservar(a int) +go +create table t21_trigger_atatuservar(a int) +go +create table t22_trigger_atatuservar(a int) +go +create table t23_trigger_atatuservar(a int) +go diff --git a/test/JDBC/expected/atatuservar-vu-verify.out b/test/JDBC/expected/atatuservar-vu-verify.out new file mode 100644 index 0000000000..81724023bf --- /dev/null +++ b/test/JDBC/expected/atatuservar-vu-verify.out @@ -0,0 +1,3856 @@ +-- simple variables in T-SQL batch +set quoted_identifier off +go +declare @@v int = 2 select @@v +go +~~START~~ +int +2 +~~END~~ + +declare @#v int = 2 select @#v +go +~~START~~ +int +2 +~~END~~ + +declare @@@$$@@@@v int = 2 select @@@$$@@@@v +go +~~START~~ +int +2 +~~END~~ + +declare @@@$$@@@@v##### int = 2 select @@@$$@@@@v##### +go +~~START~~ +int +2 +~~END~~ + +declare @@@$$@@@@#####v int = 2 select @@@$$@@@@#####v +go +~~START~~ +int +2 +~~END~~ + +declare @#############v int = 2 select @#############v +go +~~START~~ +int +2 +~~END~~ + + +-- 63 long +declare @@v63_7890123456789$123456789$123456789012345678901234567890123 int = 2 +select @@v63_7890123456789$123456789$123456789012345678901234567890123 +go +~~START~~ +int +2 +~~END~~ + +-- 64 long +declare @@v64_7890123456789$123456789$1234567890123456789012345678901234 int = 2 +select @@v64_7890123456789$123456789$1234567890123456789012345678901234 +go +~~START~~ +int +2 +~~END~~ + +-- maximum length in T-SQL is 128 +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int = 2 +select @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +go +~~START~~ +int +2 +~~END~~ + + +declare @#v63_7890123456789$123456789$123456789012345678901234567890123 int = 2 +select @#v63_7890123456789$123456789$123456789012345678901234567890123 +go +~~START~~ +int +2 +~~END~~ + +declare @#v64_7890123456789$123456789$1234567890123456789012345678901234 int = 2 +select @#v64_7890123456789$123456789$1234567890123456789012345678901234 +go +~~START~~ +int +2 +~~END~~ + +declare @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int = 2 +select @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +go +~~START~~ +int +2 +~~END~~ + +declare @@v128_@@@$$@@@@$$@########@@@$$@@@@$$@@@@$$@@@###__##@@@$$@@@@$$@@@@$$@@@@$$@@@______@@@$$@@@@$$@@@@$$@@@###########@@@$$@@@@@@ int = 2 +select @@v128_@@@$$@@@@$$@########@@@$$@@@@$$@@@@$$@@@###__##@@@$$@@@@$$@@@@$$@@@@$$@@@______@@@$$@@@@$$@@@@$$@@@###########@@@$$@@@@@@ +go +~~START~~ +int +2 +~~END~~ + + +-- referencing global @@variable, in T-SQL batch, procedure, trigger and function +declare @@v int +select 1 +set @@v = @@rowcount +select @@v +go +~~START~~ +int +1 +~~END~~ + +~~START~~ +int +1 +~~END~~ + + +declare @@@$$@@@@v int, @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int +select 1 +set @@@$$@@@@v = @@rowcount +set @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 = @@pgerror +select @@@$$@@@@v, @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +go +~~START~~ +int +1 +~~END~~ + +~~START~~ +int#!#int +1#!#0 +~~END~~ + + +declare @@v63_7890123456789$123456789$123456789012345678901234567890123 int +set @@v63_7890123456789$123456789$123456789012345678901234567890123 = @@rowcount +select @@v63_7890123456789$123456789$123456789012345678901234567890123 +go +~~START~~ +int +1 +~~END~~ + + +declare @#v64_7890123456789$123456789$1234567890123456789012345678901234 int +set @#v64_7890123456789$123456789$1234567890123456789012345678901234 = @@rowcount +select @#v64_7890123456789$123456789$1234567890123456789012345678901234 +go +~~START~~ +int +1 +~~END~~ + + +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int +set @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 = @@rowcount +select @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +go +~~START~~ +int +1 +~~END~~ + + + +create procedure p1_atatuservar +as +declare @@v int +select 1 +set @@v = @@rowcount +select @@v +declare @#v int +select 1 +set @#v = @@rowcount +select @#v +go +exec p1_atatuservar +go +~~START~~ +int +1 +~~END~~ + +~~START~~ +int +1 +~~END~~ + +~~START~~ +int +1 +~~END~~ + +~~START~~ +int +1 +~~END~~ + + + +create procedure p2_atatuservar +as +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int, @@p128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int +select 1 +set @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 = @@rowcount +select @@p128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 = @@pgerror +select @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678, @@p128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +declare @#v64_7890123456789$123456789$1234567890123456789012345678901234 int +select 1 +set @#v64_7890123456789$123456789$1234567890123456789012345678901234 = @@rowcount +select @#v64_7890123456789$123456789$1234567890123456789012345678901234 +go +exec p2_atatuservar +go +~~START~~ +int +1 +~~END~~ + +~~START~~ +int#!#int +1#!#0 +~~END~~ + +~~START~~ +int +1 +~~END~~ + +~~START~~ +int +1 +~~END~~ + + + +create trigger tr1_atatuservar on t1_trigger_atatuservar for insert +as +begin +select 'trigger tr1_atatuservar' +declare @@v int +select 1 +set @@v = @@rowcount +select @@v +declare @#v int +select 1 +set @#v = @@rowcount +select @#v +end +go +insert t1_trigger_atatuservar values (123) +go +~~START~~ +varchar +trigger tr1_atatuservar +~~END~~ + +~~START~~ +int +1 +~~END~~ + +~~START~~ +int +1 +~~END~~ + +~~START~~ +int +1 +~~END~~ + +~~START~~ +int +1 +~~END~~ + +~~ROW COUNT: 1~~ + + + + +create trigger tr2_atatuservar on t2_trigger_atatuservar for insert +as +begin +select 'trigger tr2_atatuservar' +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int +select 1 +set @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 = @@rowcount +select @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +declare @#v64_7890123456789$123456789$1234567890123456789012345678901234 int +select 1 +set @#v64_7890123456789$123456789$1234567890123456789012345678901234 = @@rowcount +select @#v64_7890123456789$123456789$1234567890123456789012345678901234 +end +go +insert t2_trigger_atatuservar values (123) +go +~~START~~ +varchar +trigger tr2_atatuservar +~~END~~ + +~~START~~ +int +1 +~~END~~ + +~~START~~ +int +1 +~~END~~ + +~~START~~ +int +1 +~~END~~ + +~~START~~ +int +1 +~~END~~ + +~~ROW COUNT: 1~~ + + + + +create function f1_atatuservar() returns int +as +begin +declare @@v int, @@v2 int +select @@v2 = count(*) from t1_atatuservar +set @@v = @@rowcount +declare @#v int, @#v2 int +select @#v2 = count(*) from t1_atatuservar +set @#v = @@rowcount +return @@v * @#v +end +go +select dbo.f1_atatuservar() +go +~~START~~ +int +1 +~~END~~ + + + +create function f2_atatuservar() returns int +as +begin +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int, @#v64_7890123456789$123456789$1234567890123456789012345678901234 int +select @#v64_7890123456789$123456789$1234567890123456789012345678901234 = count(*) from t1_atatuservar +set @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 = @@rowcount +return @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 * @#v64_7890123456789$123456789$1234567890123456789012345678901234 +end +go +select dbo.f2_atatuservar() +go +~~START~~ +int +3 +~~END~~ + + + +create trigger tr3_atatuservar on t3_trigger_atatuservar for insert +as +begin +select 'trigger tr3_atatuservar' +declare @@v int, @@v2 int +select @@v2 = count(*) from t1_atatuservar +set @@v = @@rowcount +select @@v +declare @#v int, @#v2 int +select @#v2 = count(*) from t1_atatuservar +set @#v = @@rowcount +select @#v +end +go +insert t3_trigger_atatuservar values (123) +go +~~START~~ +varchar +trigger tr3_atatuservar +~~END~~ + +~~START~~ +int +1 +~~END~~ + +~~START~~ +int +1 +~~END~~ + +~~ROW COUNT: 1~~ + + +-- assuming @@servername is BABELFISH +declare @v varchar(50) +set @v = @@servername +select @v +go +~~START~~ +varchar +BABELFISH +~~END~~ + + +declare @v int +set @v = len(@@servername) +select @v +go +~~START~~ +int +9 +~~END~~ + + + +create procedure p3_atatuservar +as +declare @v varchar(50) +set @v = @@servername +select @v +declare @v2 int +set @v2 = len(@@servername) +select @v2 +go +exec p3_atatuservar +go +~~START~~ +varchar +BABELFISH +~~END~~ + +~~START~~ +int +9 +~~END~~ + + +create function f3_atatuservar(@#p1 varchar(30)) returns int +as +begin +declare @@v int +set @@v = len(@@servername) +return @@v * len(@#p1) +end +go +select dbo.f3_atatuservar(@@servername) +go +~~START~~ +int +81 +~~END~~ + + +create trigger tr4_atatuservar on t4_trigger_atatuservar for insert +as +begin +select 'trigger tr4_atatuservar' +declare @@v int +set @@v = len(@@servername) +select @@v +end +go +insert t4_trigger_atatuservar values (123) +go +~~START~~ +varchar +trigger tr4_atatuservar +~~END~~ + +~~START~~ +int +9 +~~END~~ + +~~ROW COUNT: 1~~ + + +-- procedure call with named/unnamed arguments, output parameters, return status, in T-SQL batch, procedure, trigger +create procedure p4_atatuservar @@p1 int +as select @@p1 +return @@p1*-1 +go +exec p4_atatuservar 123 +go +~~START~~ +int +123 +~~END~~ + +exec p4_atatuservar @@p1=123 +go +~~START~~ +int +123 +~~END~~ + +declare @@v int = 987 +exec p4_atatuservar @@p1=@@v +go +~~START~~ +int +987 +~~END~~ + +declare @@v int +exec @@v = p4_atatuservar @@p1=123 +select @@v +go +~~START~~ +int +123 +~~END~~ + +~~START~~ +int +-123 +~~END~~ + + +create procedure p19_atatuservar @#p19_atatuservar int +as select @#p19_atatuservar +return @#p19_atatuservar*-1 +go +exec p19_atatuservar @@max_precision +go +~~START~~ +int +38 +~~END~~ + +exec p19_atatuservar @#p19_atatuservar=@@max_precision +go +~~START~~ +int +38 +~~END~~ + +declare @#v int = @@max_precision +exec p19_atatuservar @#p19_atatuservar=@#v +go +~~START~~ +int +38 +~~END~~ + +declare @#v int +exec @#v = p19_atatuservar @#p19_atatuservar=@@max_precision +select @#v +go +~~START~~ +int +38 +~~END~~ + +~~START~~ +int +-38 +~~END~~ + + + +create procedure p5_atatuservar +as +declare @@v int +exec @@v = p4_atatuservar @@p1=123 +select @@v +declare @#v int +exec @#v = p4_atatuservar @@p1=123 +select @#v +go +exec p5_atatuservar +go +~~START~~ +int +123 +~~END~~ + +~~START~~ +int +-123 +~~END~~ + +~~START~~ +int +123 +~~END~~ + +~~START~~ +int +-123 +~~END~~ + + +create procedure p6_atatuservar @@p4 int output +as +set @@p4 *= 2 +select @@p4 +return @@p4*-1 +go +declare @#v1 int, @@v2 int = 123 +exec @#v1 = p6_atatuservar @@v2 +select @#v1, @@v2 +go +~~START~~ +int +246 +~~END~~ + +~~START~~ +int#!#int +-246#!#123 +~~END~~ + + +declare @#v1 int, @@v2 int = 123 +exec @#v1 = p6_atatuservar @@p4 = @@v2 out +select @#v1, @@v2 +go +~~START~~ +int +246 +~~END~~ + +~~START~~ +int#!#int +-246#!#246 +~~END~~ + + +create procedure p7_atatuservar +as +declare @#v1 int, @@v2 int = 123 +exec @#v1 = p6_atatuservar @@v2 output +select @#v1, @@v2 +go + +create procedure p8_atatuservar @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int output +as +set @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 *= 2 +select @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +return @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678*-1 +go +declare @#v64_7890123456789$123456789$1234567890123456789012345678901234 int, @@v63_7890123456789$123456789$123456789012345678901234567890123 int = 123 +exec @#v64_7890123456789$123456789$1234567890123456789012345678901234 = p8_atatuservar @@v63_7890123456789$123456789$123456789012345678901234567890123 +select @#v64_7890123456789$123456789$1234567890123456789012345678901234, @@v63_7890123456789$123456789$123456789012345678901234567890123 +go +~~START~~ +int +246 +~~END~~ + +~~START~~ +int#!#int +-246#!#123 +~~END~~ + + +declare @#v64_7890123456789$123456789$1234567890123456789012345678901234 int, @@v63_7890123456789$123456789$123456789012345678901234567890123 int = 123 +exec @#v64_7890123456789$123456789$1234567890123456789012345678901234 = p8_atatuservar @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 = @@v63_7890123456789$123456789$123456789012345678901234567890123 out +select @#v64_7890123456789$123456789$1234567890123456789012345678901234, @@v63_7890123456789$123456789$123456789012345678901234567890123 +go +~~START~~ +int +246 +~~END~~ + +~~START~~ +int#!#int +-246#!#246 +~~END~~ + + +create procedure p9_atatuservar +as +declare @#v64_7890123456789$123456789$1234567890123456789012345678901234 int, @@v63_7890123456789$123456789$123456789012345678901234567890123 int = 123 +exec @#v64_7890123456789$123456789$1234567890123456789012345678901234 = p8_atatuservar @@v63_7890123456789$123456789$123456789012345678901234567890123 output +select @#v64_7890123456789$123456789$1234567890123456789012345678901234, @@v63_7890123456789$123456789$123456789012345678901234567890123 +go + + +create trigger tr5_atatuservar on t5_trigger_atatuservar for insert +as +begin +select 'trigger tr5_atatuservar' +declare @@v int +exec @@v = p4_atatuservar @@p1=123 +select @@v +declare @#v int +exec @#v = p4_atatuservar @@p1=123 +select @#v +end +go +insert t5_trigger_atatuservar values (123) +go +~~START~~ +varchar +trigger tr5_atatuservar +~~END~~ + +~~START~~ +int +123 +~~END~~ + +~~START~~ +int +-123 +~~END~~ + +~~START~~ +int +123 +~~END~~ + +~~START~~ +int +-123 +~~END~~ + +~~ROW COUNT: 1~~ + + + +create trigger tr6_atatuservar on t6_trigger_atatuservar for insert +as +begin +select 'trigger tr6_atatuservar' +declare @#v64_7890123456789$123456789$1234567890123456789012345678901234 int, @@v63_7890123456789$123456789$123456789012345678901234567890123 int = 123 +exec @#v64_7890123456789$123456789$1234567890123456789012345678901234 = p8_atatuservar @@v63_7890123456789$123456789$123456789012345678901234567890123 output +select @#v64_7890123456789$123456789$1234567890123456789012345678901234, @@v63_7890123456789$123456789$123456789012345678901234567890123 +end +go +insert t6_trigger_atatuservar values (123) +go +~~START~~ +varchar +trigger tr6_atatuservar +~~END~~ + +~~START~~ +int +246 +~~END~~ + +~~START~~ +int#!#int +-246#!#246 +~~END~~ + +~~ROW COUNT: 1~~ + + +-- misc variable usage in expressions +declare @#v int = 3 +set @#v *= -1 +set @#v = @#v + 10*@#v +select @#v = @#v + 1 +if @#v > 0 select 'positive' else select 'negative' +select @#v, @#V, '@#v' +print @#v -- PRINT output not captured by JDBC tests +go +~~START~~ +varchar +negative +~~END~~ + +~~START~~ +int#!#int#!#varchar +-32#!#-32#!#@#v +~~END~~ + + +declare @@v int = 3 +set @@v *= -1 +set @@v = @@v + 10*@@v +select @@v = @@v + 1 +if @@v > 0 select 'positive' else select 'negative' +select @@v , @@V, '@@v' +print @@V -- PRINT output not captured by JDBC tests +go +~~START~~ +varchar +negative +~~END~~ + +~~START~~ +int#!#int#!#varchar +-32#!#-32#!#@@v +~~END~~ + + + +create procedure p10_atatuservar +as +declare @#v int = 3 +set @#v *= -1 +set @#v = @#v + 10*@#v +select @#v = @#v + 1 +if @#v > 0 select 'positive' else select 'negative' +select @#v, @#V, '@#v' +print @#v -- PRINT output not captured by JDBC tests +declare @@v int = 3 +set @@v *= -1 +set @@v = @@v + 10*@@v +select @@v = @@v + 1 +if @@v > 0 select 'positive' else select 'negative' +select @@v , @@V, '@@v' +print @@V -- PRINT output not captured by JDBC tests +go +exec p10_atatuservar +go +~~START~~ +varchar +negative +~~END~~ + +~~START~~ +int#!#int#!#varchar +-32#!#-32#!#@#v +~~END~~ + +~~START~~ +varchar +negative +~~END~~ + +~~START~~ +int#!#int#!#varchar +-32#!#-32#!#@@v +~~END~~ + + +declare @@c varchar(20)='abcd', @#v1 int=2, @v2@# int=1 +select substring(@@c, @#v1, @v2@#) +go +~~START~~ +varchar +b +~~END~~ + + +declare @@v1 varchar(20)='row 1', @#v2 varchar(20)='row 3' +select * from t1_atatuservar where c in (@@v1, @#v2) order by 1 +go +~~START~~ +varchar +row 1 +row 3 +~~END~~ + + +declare @@v1 varchar(20)='1', @#v2 varchar(20)='3' +select * from t1_atatuservar where c like '%'+@@v1 or c like '%'+@#v2 order by 1 +go +~~START~~ +varchar +row 1 +row 3 +~~END~~ + + + + +create procedure p11_atatuservar +as +declare @@c varchar(20)='abcd', @#v int=2, @v@# int=1 +select substring(@@c, @#v, @v@#) +declare @@v1 varchar(20)='row 1', @#v1 varchar(20)='row 3' +select * from t1_atatuservar where c in (@@v1, @#v1) order by 1 +declare @@v2 varchar(20)='1', @#v2 varchar(20)='3' +select * from t1_atatuservar where c like '%'+@@v2 or c like '%'+@#v2 order by 1 +go +exec p11_atatuservar +go +~~START~~ +varchar +b +~~END~~ + +~~START~~ +varchar +row 1 +row 3 +~~END~~ + +~~START~~ +varchar +row 1 +row 3 +~~END~~ + + +create function f4_atatuservar (@@p1 int, @#p2 int, @p5_atatuservar int) +returns table +as +return (select @@p1*@#p2*@p5_atatuservar as x where @@p1 = 123 or @#p2 = 10 or @p5_atatuservar = 1) +go +select * from dbo.f4_atatuservar(123, 20, 2) +go +~~START~~ +int +4920 +~~END~~ + +select * from dbo.f4_atatuservar(345, 10, 2) +go +~~START~~ +int +6900 +~~END~~ + +select * from dbo.f4_atatuservar(345, 20, 1) +go +~~START~~ +int +6900 +~~END~~ + + +declare @@c varchar(30), @#v int=1, @#v2 int=2 +set @@c = case when @#v > 0 then '> zero' else '<- zero' end +select @@c +set @@c = case @#v when 0 then 'zero' else '<> zero' end +select @@c +set @@c = case @#v when 0 then 'zero' when @#v2 then 'case 2' else 'something else' end +select @@c +set @@c = case @#v+@#v when 0 then 'zero' when @#v2 then 'case 2' else 'something else' end +select @@c +go +~~START~~ +varchar +> zero +~~END~~ + +~~START~~ +varchar +<> zero +~~END~~ + +~~START~~ +varchar +something else +~~END~~ + +~~START~~ +varchar +case 2 +~~END~~ + + +create procedure p22_atatuservar +as +declare @@c varchar(30), @#v int=1, @#v2 int=2 +set @@c = case when @#v > 0 then '> zero' else '<- zero' end +select @@c +set @@c = case @#v when 0 then 'zero' else '<> zero' end +select @@c +set @@c = case @#v when 0 then 'zero' when @#v2 then 'case 2' else 'something else' end +select @@c +set @@c = case @#v+@#v when 0 then 'zero' when @#v2 then 'case 2' else 'something else' end +select @@c +go +exec p22_atatuservar +go +~~START~~ +varchar +> zero +~~END~~ + +~~START~~ +varchar +<> zero +~~END~~ + +~~START~~ +varchar +something else +~~END~~ + +~~START~~ +varchar +case 2 +~~END~~ + + + + + + + +create trigger tr7_atatuservar on t7_trigger_atatuservar for insert +as +begin +select 'trigger tr7_atatuservar' +declare @@z128_@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@_____############################################################ varchar(30), @#v64_7890123456789$123456789$1234567890123456789012345678901234 int=1, @#w64_7890123456789$123456789$1234567890123456789012345678901234 int=2 +set @@z128_@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@_____############################################################ = case when @#v64_7890123456789$123456789$1234567890123456789012345678901234 > 0 then '> zero' else '<- zero' end +select @@z128_@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@_____############################################################ +set @@z128_@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@_____############################################################ = case @#v64_7890123456789$123456789$1234567890123456789012345678901234 when 0 then 'zero' else '<> zero' end +select @@z128_@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@_____############################################################ +set @@z128_@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@_____############################################################ = case @#v64_7890123456789$123456789$1234567890123456789012345678901234 when 0 then 'zero' when @#w64_7890123456789$123456789$1234567890123456789012345678901234 then 'case 2' else 'something else' end +select @@z128_@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@_____############################################################ +set @@z128_@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@_____############################################################ = case @#v64_7890123456789$123456789$1234567890123456789012345678901234+@#v64_7890123456789$123456789$1234567890123456789012345678901234 when 0 then 'zero' when @#w64_7890123456789$123456789$1234567890123456789012345678901234 then 'case 2' else 'something else' end +declare @#x64_7890123456789$123456789$1234567890123456789012345678901234 int = 3 +set @#x64_7890123456789$123456789$1234567890123456789012345678901234 *= -1 +set @#x64_7890123456789$123456789$1234567890123456789012345678901234 = @#x64_7890123456789$123456789$1234567890123456789012345678901234 + 10*@#x64_7890123456789$123456789$1234567890123456789012345678901234 +select @#x64_7890123456789$123456789$1234567890123456789012345678901234 = @#x64_7890123456789$123456789$1234567890123456789012345678901234 + 1 +if @#x64_7890123456789$123456789$1234567890123456789012345678901234 > 0 select 'positive' else select 'negative' +select @#x64_7890123456789$123456789$1234567890123456789012345678901234, @#x64_7890123456789$123456789$1234567890123456789012345678901234, '@#x64_7890123456789$123456789$1234567890123456789012345678901234' +print @#x64_7890123456789$123456789$1234567890123456789012345678901234 -- PRINT output not captured by JDBC tests +declare @@v128_@@@$$@@@@$$@########@@@$$@@@@$$@@@@$$@@@###__##@@@$$@@@@$$@@@@$$@@@@$$@@@______@@@$$@@@@$$@@@@$$@@@###########@@@$$@@@@@@ int = 3 +set @@v128_@@@$$@@@@$$@########@@@$$@@@@$$@@@@$$@@@###__##@@@$$@@@@$$@@@@$$@@@@$$@@@______@@@$$@@@@$$@@@@$$@@@###########@@@$$@@@@@@ *= -1 +set @@v128_@@@$$@@@@$$@########@@@$$@@@@$$@@@@$$@@@###__##@@@$$@@@@$$@@@@$$@@@@$$@@@______@@@$$@@@@$$@@@@$$@@@###########@@@$$@@@@@@ = @@v128_@@@$$@@@@$$@########@@@$$@@@@$$@@@@$$@@@###__##@@@$$@@@@$$@@@@$$@@@@$$@@@______@@@$$@@@@$$@@@@$$@@@###########@@@$$@@@@@@ + 10*@@v128_@@@$$@@@@$$@########@@@$$@@@@$$@@@@$$@@@###__##@@@$$@@@@$$@@@@$$@@@@$$@@@______@@@$$@@@@$$@@@@$$@@@###########@@@$$@@@@@@ +select @@v128_@@@$$@@@@$$@########@@@$$@@@@$$@@@@$$@@@###__##@@@$$@@@@$$@@@@$$@@@@$$@@@______@@@$$@@@@$$@@@@$$@@@###########@@@$$@@@@@@ = @@v128_@@@$$@@@@$$@########@@@$$@@@@$$@@@@$$@@@###__##@@@$$@@@@$$@@@@$$@@@@$$@@@______@@@$$@@@@$$@@@@$$@@@###########@@@$$@@@@@@ + 1 +if @@v128_@@@$$@@@@$$@########@@@$$@@@@$$@@@@$$@@@###__##@@@$$@@@@$$@@@@$$@@@@$$@@@______@@@$$@@@@$$@@@@$$@@@###########@@@$$@@@@@@ > 0 select 'positive' else select 'negative' +select @@v128_@@@$$@@@@$$@########@@@$$@@@@$$@@@@$$@@@###__##@@@$$@@@@$$@@@@$$@@@@$$@@@______@@@$$@@@@$$@@@@$$@@@###########@@@$$@@@@@@ , @@v128_@@@$$@@@@$$@########@@@$$@@@@$$@@@@$$@@@###__##@@@$$@@@@$$@@@@$$@@@@$$@@@______@@@$$@@@@$$@@@@$$@@@###########@@@$$@@@@@@, '@@v128_@@@$$@@@@$$@########@@@$$@@@@$$@@@@$$@@@###__##@@@$$@@@@$$@@@@$$@@@@$$@@@______@@@$$@@@@$$@@@@$$@@@###########@@@$$@@@@@@' +print @@v128_@@@$$@@@@$$@########@@@$$@@@@$$@@@@$$@@@###__##@@@$$@@@@$$@@@@$$@@@@$$@@@______@@@$$@@@@$$@@@@$$@@@###########@@@$$@@@@@@ -- PRINT output not captured by JDBC tests +declare @@y128_############################################______@@@$$@@@@$$@@@@__###############@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@ varchar(20)='abcd', @#p64_7890123456789$123456789$1234567890123456789012345678901234 int=2, @@#q64_890123456789$123456789$1234567890123456789012345678901234 int=1 +select substring(@@y128_############################################______@@@$$@@@@$$@@@@__###############@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@, @#p64_7890123456789$123456789$1234567890123456789012345678901234, @@#q64_890123456789$123456789$1234567890123456789012345678901234) +declare @@q64_7890123456789$123456789$1234567890123456789012345678901234 varchar(20)='1', @#q4_7890123456789$123456789$1234567890123456789012345678901234 varchar(20)='3' +select * from t1_atatuservar where c like '%'+@@q64_7890123456789$123456789$1234567890123456789012345678901234 or c like '%'+@#q4_7890123456789$123456789$1234567890123456789012345678901234 order by 1 +end +go +insert t7_trigger_atatuservar values (123) +go +~~START~~ +varchar +trigger tr7_atatuservar +~~END~~ + +~~START~~ +varchar +> zero +~~END~~ + +~~START~~ +varchar +<> zero +~~END~~ + +~~START~~ +varchar +something else +~~END~~ + +~~START~~ +varchar +negative +~~END~~ + +~~START~~ +int#!#int#!#varchar +-32#!#-32#!#@#x64_7890123456789$123456789$1234567890123456789012345678901234 +~~END~~ + +~~START~~ +varchar +negative +~~END~~ + +~~START~~ +int#!#int#!#varchar +-32#!#-32#!#@@v128_@@@$$@@@@$$@########@@@$$@@@@$$@@@@$$@@@###__##@@@$$@@@@$$@@@@$$@@@@$$@@@______@@@$$@@@@$$@@@@$$@@@###########@@@$$@@@@@@ +~~END~~ + +~~START~~ +varchar +b +~~END~~ + +~~START~~ +varchar +row 1 +row 3 +~~END~~ + +~~ROW COUNT: 1~~ + + +-- table variables, in T-SQL batch, procedure and trigger (functions are below) +declare @@v table (a int) +insert @@v values (123) +select * from @@v +go +~~ROW COUNT: 1~~ + +~~START~~ +int +123 +~~END~~ + + +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 table (a int) +insert @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 values (123) +select * from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +go +~~ROW COUNT: 1~~ + +~~START~~ +int +123 +~~END~~ + + +declare @#v table (a int) +insert @#v values (123) +insert @#v select * from @#v +select * from @#v +update @#v set a = a + 1 +select * from @#v +set rowcount 1 +delete @#v +set rowcount 0 +select * from @#v +go +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~START~~ +int +123 +123 +~~END~~ + +~~ROW COUNT: 2~~ + +~~START~~ +int +124 +124 +~~END~~ + +~~ROW COUNT: 1~~ + +~~START~~ +int +124 +~~END~~ + + +declare @@V table (a int) +insert @@v values (123) +insert @@v select * from @@v +select * from @@v +update @@v set a = a + 1 +select * from @@v +set rowcount 1 +delete @@v +set rowcount 0 +select * from @@v +go +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~START~~ +int +123 +123 +~~END~~ + +~~ROW COUNT: 2~~ + +~~START~~ +int +124 +124 +~~END~~ + +~~ROW COUNT: 1~~ + +~~START~~ +int +124 +~~END~~ + + + +create procedure p12_atatuservar +as +declare @#v table (a int) +insert @#v values (123) +insert @#v select * from @#v +select * from @#v +update @#v set a = a + 1 +select * from @#v +set rowcount 1 +delete @#v +set rowcount 0 +select * from @#v +declare @@V table (a int) +insert @@v values (123) +insert @@v select * from @@v +select * from @@v +update @@v set a = a + 1 +select * from @@v +set rowcount 1 +delete @@v +set rowcount 0 +select * from @@v +go +exec p12_atatuservar +go +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~START~~ +int +123 +123 +~~END~~ + +~~ROW COUNT: 2~~ + +~~START~~ +int +124 +124 +~~END~~ + +~~ROW COUNT: 1~~ + +~~START~~ +int +124 +~~END~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~START~~ +int +123 +123 +~~END~~ + +~~ROW COUNT: 2~~ + +~~START~~ +int +124 +124 +~~END~~ + +~~ROW COUNT: 1~~ + +~~START~~ +int +124 +~~END~~ + + +create procedure p13_atatuservar +as +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 table (a int) +insert @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 values (123) +select * from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +insert @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 select * from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +select * from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +update @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 set a = a + 1 +select * from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +set rowcount 1 +delete @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +set rowcount 0 +select * from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +go +exec p13_atatuservar +go +~~ROW COUNT: 1~~ + +~~START~~ +int +123 +~~END~~ + +~~ROW COUNT: 1~~ + +~~START~~ +int +123 +123 +~~END~~ + +~~ROW COUNT: 2~~ + +~~START~~ +int +124 +124 +~~END~~ + +~~ROW COUNT: 1~~ + +~~START~~ +int +124 +~~END~~ + + + + +create trigger tr8_atatuservar on t8_trigger_atatuservar for insert +as +begin +select 'trigger tr8_atatuservar' +declare @#v table (a int) +insert @#v values (123) +insert @#v select * from @#v +select * from @#v +update @#v set a = a + 1 +select * from @#v +set rowcount 1 +delete @#v +set rowcount 0 +select * from @#v +declare @@V table (a int) +insert @@v values (123) +insert @@v select * from @@v +select * from @@v +update @@v set a = a + 1 +select * from @@v +set rowcount 1 +delete @@v +set rowcount 0 +select * from @@v +end +go +insert t8_trigger_atatuservar values (123) +go +~~START~~ +varchar +trigger tr8_atatuservar +~~END~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~START~~ +int +123 +123 +~~END~~ + +~~ROW COUNT: 2~~ + +~~START~~ +int +124 +124 +~~END~~ + +~~ROW COUNT: 1~~ + +~~START~~ +int +124 +~~END~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~START~~ +int +123 +123 +~~END~~ + +~~ROW COUNT: 2~~ + +~~START~~ +int +124 +124 +~~END~~ + +~~ROW COUNT: 1~~ + +~~START~~ +int +124 +~~END~~ + +~~ROW COUNT: 1~~ + + + +create trigger tr9_atatuservar on t9_trigger_atatuservar for insert +as +begin +select 'trigger tr9_atatuservar' +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 table (a int) +insert @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 values (123) +select * from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +insert @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 select * from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +select * from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +update @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 set a = a + 1 +select * from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +set rowcount 1 +delete @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +set rowcount 0 +select * from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +end +go +insert t9_trigger_atatuservar values (123) +go +~~START~~ +varchar +trigger tr9_atatuservar +~~END~~ + +~~ROW COUNT: 1~~ + +~~START~~ +int +123 +~~END~~ + +~~ROW COUNT: 1~~ + +~~START~~ +int +123 +123 +~~END~~ + +~~ROW COUNT: 2~~ + +~~START~~ +int +124 +124 +~~END~~ + +~~ROW COUNT: 1~~ + +~~START~~ +int +124 +~~END~~ + +~~ROW COUNT: 1~~ + + +-- @@rowcount +declare @@V int = 1 +set rowcount @@v +select * from t1_atatuservar order by 1 +set @@v = 0 +set rowcount @@v +select * from t1_atatuservar order by 1 +go +~~START~~ +varchar +row 1 +~~END~~ + +~~START~~ +varchar +row 1 +row 2 +row 3 +~~END~~ + + +declare @#V int = 1 +set rowcount @#v +select * from t1_atatuservar order by 1 +set @#v = 0 +set rowcount @#v +select * from t1_atatuservar order by 1 +go +~~START~~ +varchar +row 1 +~~END~~ + +~~START~~ +varchar +row 1 +row 2 +row 3 +~~END~~ + + + +create procedure p14_atatuservar +as +declare @@V int = 1 +set rowcount @@v +select * from t1_atatuservar order by 1 +set @@v = 0 +set rowcount @@v +select * from t1_atatuservar order by 1 +declare @#V int = 1 +set rowcount @#v +select * from t1_atatuservar order by 1 +set @#v = 0 +set rowcount @#v +select * from t1_atatuservar order by 1 +go +exec p14_atatuservar +go +~~START~~ +varchar +row 1 +~~END~~ + +~~START~~ +varchar +row 1 +row 2 +row 3 +~~END~~ + +~~START~~ +varchar +row 1 +~~END~~ + +~~START~~ +varchar +row 1 +row 2 +row 3 +~~END~~ + + + + +create trigger tr10_atatuservar on t10_trigger_atatuservar for insert +as +begin +select 'trigger tr10_atatuservar' +declare @@V int = 1 +set rowcount @@v +select * from t1_atatuservar order by 1 +set @@v = 0 +set rowcount @@v +select * from t1_atatuservar order by 1 +declare @#V int = 1 +set rowcount @#v +select * from t1_atatuservar order by 1 +set @#v = 0 +set rowcount @#v +select * from t1_atatuservar order by 1 +end +go +insert t10_trigger_atatuservar values (123) +go +~~START~~ +varchar +trigger tr10_atatuservar +~~END~~ + +~~START~~ +varchar +row 1 +~~END~~ + +~~START~~ +varchar +row 1 +row 2 +row 3 +~~END~~ + +~~START~~ +varchar +row 1 +~~END~~ + +~~START~~ +varchar +row 1 +row 2 +row 3 +~~END~~ + +~~ROW COUNT: 1~~ + + +create function f1_atatuservar_extra_long_name_here() +returns @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 table (a int) +as +begin +insert @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +values (123) +return +end +go +select * from f1_atatuservar_extra_long_name_here() +go +~~START~~ +int +123 +~~END~~ + + +create function f2_atatuservar_extra_long_name_here() +returns @#v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 table (a int) +as +begin +insert @#v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +values (123) +return +end +go +select * from f2_atatuservar_extra_long_name_here() +go +~~START~~ +int +123 +~~END~~ + + +-- in SET statements that support variable argument, procedure and trigger (functions are below) +declare @@v int = 4 +set datefirst @@v +select datepart(dw, '2024-10-21') +go +~~START~~ +int +5 +~~END~~ + +set datefirst 7 +go + +declare @#v int = 5 +set datefirst @#v +select datepart(dw, '2024-10-21') +go +~~START~~ +int +4 +~~END~~ + +set datefirst 7 +go + +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int = 5 +set datefirst @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +select datepart(dw, '2024-10-21') +go +~~START~~ +int +4 +~~END~~ + +set datefirst 7 +go + +-- SET DATEFORMAT currently ignores the argument and will always use 'mdy' +declare @@v varchar(10) = 'dmy' +set dateformat @@v +select cast('01/02/03' as datetime) +go +~~START~~ +datetime +2003-01-02 00:00:00.0 +~~END~~ + +set dateformat mdy +go + +-- SET DATEFORMAT currently silently ignores the argument and will always use 'mdy' +declare @#v varchar(10) = 'dmy' +set dateformat @#v +select cast('01/02/03' as datetime) +go +~~START~~ +datetime +2003-01-02 00:00:00.0 +~~END~~ + +set dateformat mdy +go + +-- SET DATEFORMAT currently silently ignores the argument and will always use 'mdy' +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(10) = 'dmy' +set dateformat @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +select cast('01/02/03' as datetime) +go +~~START~~ +datetime +2003-01-02 00:00:00.0 +~~END~~ + +set dateformat mdy +go + +-- SET LANGUAGE currently only supports english +declare @@v varchar(10) = 'dutch' +set language @@v +select @@language +go +~~WARNING (Code: 5703)~~ + +~~WARNING (Message: Changed language setting to 'us_english' Server SQLState: S0001)~~ + +~~START~~ +nvarchar +us_english +~~END~~ + +set language us_english +go +declare @#v varchar(10) = 'french' +set language @#v +select @@language +go +~~WARNING (Code: 5703)~~ + +~~WARNING (Message: Changed language setting to 'us_english' Server SQLState: S0001)~~ + +~~START~~ +nvarchar +us_english +~~END~~ + +set language us_english +go +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(10) = 'french' +set language @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +select @@language +go +~~WARNING (Code: 5703)~~ + +~~WARNING (Message: Changed language setting to 'us_english' Server SQLState: S0001)~~ + +~~START~~ +nvarchar +us_english +~~END~~ + +set language us_english +go + + + + +create procedure p15_atatuservar +as +declare @@v1 int = 4 +set datefirst @@v1 +select datepart(dw, '2024-10-21') +declare @#v1 int = 5 +set datefirst @#v1 +select datepart(dw, '2024-10-21') +declare @@v2 varchar(10) = 'dmy' +set dateformat @@v2 +select cast('01/02/03' as datetime) +declare @#v3 varchar(10) = 'dutch' +set language @#v3 +select @@language +go + +exec p15_atatuservar +go +~~START~~ +int +5 +~~END~~ + +~~START~~ +int +4 +~~END~~ + +~~START~~ +datetime +2003-01-02 00:00:00.0 +~~END~~ + +~~START~~ +nvarchar +us_english +~~END~~ + +set datefirst 7 +set dateformat mdy +set language us_english +go + + + +create procedure p16_atatuservar +as +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int = 4 +set datefirst @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +select datepart(dw, '2024-10-21') +declare @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int = 5 +set datefirst @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +select datepart(dw, '2024-10-21') +declare @@w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(10) = 'dmy' +set dateformat @@w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +select cast('01/02/03' as datetime) +declare @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(10) = 'dutch' +set language @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +select @@language +go +exec p15_atatuservar +go +~~START~~ +int +5 +~~END~~ + +~~START~~ +int +4 +~~END~~ + +~~START~~ +datetime +2003-01-02 00:00:00.0 +~~END~~ + +~~START~~ +nvarchar +us_english +~~END~~ + +set datefirst 7 +set dateformat mdy +set language us_english +go + + + + +create trigger tr11_atatuservar on t11_trigger_atatuservar for insert +as +begin +select 'trigger tr11_atatuservar' + +declare @@v1 int = 4 +set datefirst @@v1 +select datepart(dw, '2024-10-21') +declare @#v1 int = 5 +set datefirst @#v1 +select datepart(dw, '2024-10-21') +declare @@v2 varchar(10) = 'dmy' +set dateformat @@v2 +select cast('01/02/03' as datetime) +declare @#v3 varchar(10) = 'dutch' +set language @#v3 +select @@language +end +go +insert t11_trigger_atatuservar values (123) +go +~~START~~ +varchar +trigger tr11_atatuservar +~~END~~ + +~~START~~ +int +5 +~~END~~ + +~~START~~ +int +4 +~~END~~ + +~~START~~ +datetime +2003-01-02 00:00:00.0 +~~END~~ + +~~START~~ +nvarchar +us_english +~~END~~ + +~~ROW COUNT: 1~~ + +set datefirst 7 +set dateformat mdy +set language us_english +go + + + + +create trigger tr12_atatuservar on t12_trigger_atatuservar for insert +as +begin +select 'trigger tr12_atatuservar' + +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int = 4 +set datefirst @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +select datepart(dw, '2024-10-21') +declare @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int = 5 +set datefirst @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +select datepart(dw, '2024-10-21') +declare @@w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(10) = 'dmy' +set dateformat @@w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +select cast('01/02/03' as datetime) +declare @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(10) = 'dutch' +set language @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +select @@language +end +go +insert t12_trigger_atatuservar values (123) +go +~~START~~ +varchar +trigger tr12_atatuservar +~~END~~ + +~~START~~ +int +5 +~~END~~ + +~~START~~ +int +4 +~~END~~ + +~~START~~ +datetime +2003-01-02 00:00:00.0 +~~END~~ + +~~START~~ +nvarchar +us_english +~~END~~ + +~~ROW COUNT: 1~~ + +set datefirst 7 +set dateformat mdy +set language us_english +go + +-- execute-immediate, procedure and trigger +declare @@V varchar(50) = 'select 123' execute(@@v) +go +~~START~~ +int +123 +~~END~~ + + +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(50) = 'select 123' execute(@@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678) +go +~~START~~ +int +123 +~~END~~ + + +declare @@V varchar(50) = 'declare @#v int =123 select @#v' +execute(@@v) +go +~~START~~ +int +123 +~~END~~ + + +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(500) = 'declare @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int =123 select @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678' +execute(@@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678) +go +~~START~~ +int +123 +~~END~~ + + +declare @@V varchar(50) = 'declare @#v int =123 select @#v' +execute('select 456 ' + @@v) +go +~~START~~ +int +456 +~~END~~ + +~~START~~ +int +123 +~~END~~ + + +declare @#V varchar(50) = 'declare @@v int =123 select @@v' +execute(@#v) +go +~~START~~ +int +123 +~~END~~ + + +declare @#V varchar(50) = 'declare @@v int =123 select @@v' +execute('select 456 ' + @#v) +go +~~START~~ +int +456 +~~END~~ + +~~START~~ +int +123 +~~END~~ + + +declare @#V varchar(50) = 'select 123 ' +execute(@#v + @#v) +go +~~START~~ +int +123 +~~END~~ + +~~START~~ +int +123 +~~END~~ + + +declare @#V varchar(50) = 'select 123 ', @@V varchar(50) = 'select 456 ' +execute(@#v + @@v + @@v + @#v) +go +~~START~~ +int +123 +~~END~~ + +~~START~~ +int +456 +~~END~~ + +~~START~~ +int +456 +~~END~~ + +~~START~~ +int +123 +~~END~~ + + +declare @@V varchar(50) = 'select "abc''def" ' +execute(@@v + 'select "xy''z" ' + @@V) +go +~~START~~ +varchar +abc'def +~~END~~ + +~~START~~ +varchar +xy'z +~~END~~ + +~~START~~ +varchar +abc'def +~~END~~ + + + + + +create procedure p17_atatuservar +as +declare @#V1 varchar(50) = 'declare @@v int =123 select @@v' +execute('select 456 ' + @#v1) +declare @#V2 varchar(50) = 'select 123 ' +execute(@#v2 + @#v2) +declare @#V3 varchar(50) = 'select 123 ', @@V varchar(50) = 'select 456 ' +execute(@#v3 + @@v + @@v + @#v3) +declare @@V4 varchar(50) = 'select "abc''def" ' +execute(@@v4 + 'select "xy''z" ' + @@V4) +go +exec p17_atatuservar +go +~~START~~ +int +456 +~~END~~ + +~~START~~ +int +123 +~~END~~ + +~~START~~ +int +123 +~~END~~ + +~~START~~ +int +123 +~~END~~ + +~~START~~ +int +123 +~~END~~ + +~~START~~ +int +456 +~~END~~ + +~~START~~ +int +456 +~~END~~ + +~~START~~ +int +123 +~~END~~ + +~~START~~ +varchar +abc'def +~~END~~ + +~~START~~ +varchar +xy'z +~~END~~ + +~~START~~ +varchar +abc'def +~~END~~ + + + + + + +create trigger tr13_atatuservar on t13_trigger_atatuservar for insert +as +begin +select 'trigger tr13_atatuservar' +declare @#V1 varchar(50) = 'declare @@v int =123 select @@v' +execute('select 456 ' + @#v1) +declare @#V2 varchar(50) = 'select 123 ' +execute(@#v2 + @#v2) +declare @#V3 varchar(50) = 'select 123 ', @@V varchar(50) = 'select 456 ' +execute(@#v3 + @@v + @@v + @#v3) +declare @@V4 varchar(50) = 'select "abc''def" ' +execute(@@v4 + 'select "xy''z" ' + @@V4) +end +go +insert t13_trigger_atatuservar values (123) +go +~~START~~ +varchar +trigger tr13_atatuservar +~~END~~ + +~~START~~ +int +456 +~~END~~ + +~~START~~ +int +123 +~~END~~ + +~~START~~ +int +123 +~~END~~ + +~~START~~ +int +123 +~~END~~ + +~~START~~ +int +123 +~~END~~ + +~~START~~ +int +456 +~~END~~ + +~~START~~ +int +456 +~~END~~ + +~~START~~ +int +123 +~~END~~ + +~~START~~ +varchar +abc'def +~~END~~ + +~~START~~ +varchar +xy'z +~~END~~ + +~~START~~ +varchar +abc'def +~~END~~ + +~~ROW COUNT: 1~~ + + +create procedure p18_atatuservar +as +begin +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(500) = 'declare @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int =123 select @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678' +execute(@@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678) +end +go +exec p18_atatuservar +go +~~START~~ +int +123 +~~END~~ + + + +create trigger tr14_atatuservar on t14_trigger_atatuservar for insert +as +begin +select 'trigger tr14_atatuservar' +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(500) = 'declare @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int =123 select @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678' +execute(@@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678) +end +go +insert t14_trigger_atatuservar values (123) +go +~~START~~ +varchar +trigger tr14_atatuservar +~~END~~ + +~~START~~ +int +123 +~~END~~ + +~~ROW COUNT: 1~~ + + +-- RAISERROR, procedure and trigger +declare @@v int=50001 +raiserror(@@v,1,1) +go + +declare @@v int=50001, @@v2 int=1 +raiserror(@@v,@@v2,1) +go + +declare @@v int=50001, @@v2 int=1, @#v3 int=1 +raiserror(@@v,@@v2,@#v3) +go + +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int=50001, @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int=1, @@y128_############################################______@@@$$@@@@$$@@@@__###############@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@ int=1 +raiserror(@@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678, @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678, @@y128_############################################______@@@$$@@@@$$@@@@__###############@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@) +go + +create procedure p1_raiserror_atatuservar +as +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int=50001, @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int=1, @@y128_############################################______@@@$$@@@@$$@@@@__###############@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@ int=1 +raiserror(@@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678, @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678, @@y128_############################################______@@@$$@@@@$$@@@@__###############@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@) +go +exec p1_raiserror_atatuservar +go + +create trigger tr15_atatuservar on t15_trigger_atatuservar for insert +as +begin +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int=50001, @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int=1, @@y128_############################################______@@@$$@@@@$$@@@@__###############@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@ int=1 +raiserror(@@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678, @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678, @@y128_############################################______@@@$$@@@@$$@@@@__###############@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@) +end +go +insert t15_trigger_atatuservar values (123) +go +~~WARNING (Code: 0)~~ + +~~WARNING (Message: No. 50001 in sys.messages Server SQLState: S0001)~~ + +~~ROW COUNT: 1~~ + + + +-- sp_executesql with named/unnamed arguments, output parameters, in T-SQL batch, procedure, trigger +exec sp_executesql N'declare @@v int=123 select @@v' +go +~~START~~ +int +123 +~~END~~ + + +exec sp_executesql N'SELECT @@v1, @#v2', N'@@v1 int, @#v2 varchar(20)', @#v2='Hello, World!', @@v1=123 +go +~~START~~ +int#!#varchar +123#!#Hello, World! +~~END~~ + + +declare @@sql nvarchar(50)=N'SELECT @@v1, @#v2' +exec sp_executesql @@sql, N'@@v1 int, @#v2 varchar(20)', @#v2='Hello, World!', @@v1=123 +go +~~START~~ +int#!#varchar +123#!#Hello, World! +~~END~~ + + +declare @@params nvarchar(50)=N'@@v1 int, @#v2 varchar(20)' +exec sp_executesql N'SELECT @@v1, @#v2', @@params, @#v2='Hello, World!', @@v1=123 +go +~~START~~ +int#!#varchar +123#!#Hello, World! +~~END~~ + + +declare @@sql nvarchar(50)=N'SELECT @@v1, @#v2' +declare @@params nvarchar(50)=N'@@v1 int, @#v2 varchar(20)' +exec sp_executesql @@sql, @@params, @#v2='Hello, World!', @@v1=123 +go +~~START~~ +int#!#varchar +123#!#Hello, World! +~~END~~ + + +declare @@sql nvarchar(50)=N'SELECT @@v1, @#v2', @@params nvarchar(50)=N'@@v1 int, @#v2 varchar(20)', @@v3 int=123, @#v4 varchar(20)='Hello, World!' +exec sp_executesql @@sql, @@params, @#v2=@#v4, @@v1=@@v3 +go +~~START~~ +int#!#varchar +123#!#Hello, World! +~~END~~ + + +declare @@SQLString1 NVARCHAR(100); +declare @#SQLString2 NVARCHAR(max); +declare @@ParamDef NVARCHAR(100); +SET @@SQLString1 = N'SET @#a = @@b + @@b'; +SET @#SQLString2 = N'EXEC sp_executesql N''SET @#a = @@b + @@b'', N''@#a INT OUT, @@b INT'', @#a OUTPUT, @@b;'; +SET @@ParamDef = N'@#a INT OUTPUT, @@b INT'; +declare @@p INT; +declare @#a INT; +EXEC sp_executesql @@SQLString1, @@ParamDef, @#a = @@p OUT, @@b = 10; +EXEC sp_executesql @#SQLString2, @@ParamDef, @#a = @#a OUT, @@b = 11; +SELECT @@p, @#a; +go +~~START~~ +int#!#int +20#!#22 +~~END~~ + + +create procedure p1_spexec_atatuservar +as +declare @@sql nvarchar(50)=N'SELECT @@v1, @#v2', @@params nvarchar(50)=N'@@v1 int, @#v2 varchar(20)', @@v3 int=123, @#v4 varchar(20)='Hello, World!' +exec sp_executesql @@sql, @@params, @#v2=@#v4, @@v1=@@v3 +declare @@SQLString1 NVARCHAR(100) +declare @#SQLString2 NVARCHAR(max) +declare @@ParamDef NVARCHAR(100) +SET @@SQLString1 = N'SET @#a = @@b + @@b' +SET @#SQLString2 = N'EXEC sp_executesql N''SET @#a = @@b + @@b'', N''@#a INT OUT, @@b INT'', @#a OUT, @@b' +SET @@ParamDef = N'@#a INT OUTPUT, @@b INT' +declare @@p INT +declare @#a INT +EXEC sp_executesql @@SQLString1, @@ParamDef, @#a = @@p OUT, @@b = 10 +EXEC sp_executesql @#SQLString2, @@ParamDef, @#a = @#a OUT, @@b = 11 +SELECT @@p, @#a +go +exec p1_spexec_atatuservar +go +~~START~~ +int#!#varchar +123#!#Hello, World! +~~END~~ + +~~START~~ +int#!#int +20#!#22 +~~END~~ + + + +create trigger tr16_atatuservar on t16_trigger_atatuservar for insert +as +begin +select 'trigger tr16_atatuservar' +declare @@sql nvarchar(50)=N'SELECT @@v1, @#v2', @@params nvarchar(50)=N'@@v1 int, @#v2 varchar(20)', @@v3 int=123, @#v4 varchar(20)='Hello, World!' +exec sp_executesql @@sql, @@params, @#v2=@#v4, @@v1=@@v3 +declare @@SQLString1 NVARCHAR(100) +declare @#SQLString2 NVARCHAR(max) +declare @@ParamDef NVARCHAR(100) +SET @@SQLString1 = N'SET @#a = @@b + @@b' +SET @#SQLString2 = N'EXEC sp_executesql N''SET @#a = @@b + @@b'', N''@#a INT OUT, @@b INT'', @#a OUT, @@b' +SET @@ParamDef = N'@#a INT OUTPUT, @@b INT' +declare @@p INT +declare @#a INT +EXEC sp_executesql @@SQLString1, @@ParamDef, @#a = @@p OUT, @@b = 10 +EXEC sp_executesql @#SQLString2, @@ParamDef, @#a = @#a OUT, @@b = 11 +SELECT @@p, @#a +end +go +insert t16_trigger_atatuservar values (123) +go +~~START~~ +varchar +trigger tr16_atatuservar +~~END~~ + +~~START~~ +int#!#varchar +123#!#Hello, World! +~~END~~ + +~~START~~ +int#!#int +20#!#22 +~~END~~ + +~~ROW COUNT: 1~~ + + +declare @@v63_7890123456789$123456789$123456789012345678901234567890123 NVARCHAR(1000); +declare @#w63_7890123456789$123456789$123456789012345678901234567890123 NVARCHAR(max); +declare @@x63_7890123456789$123456789$123456789012345678901234567890123 NVARCHAR(1000); +SET @@v63_7890123456789$123456789$123456789012345678901234567890123 = N'SET @@z63_7890123456789$123456789$123456789012345678901234567890123 = @@p63_7890123456789$123456789$123456789012345678901234567890123 + @@p63_7890123456789$123456789$123456789012345678901234567890123'; +SET @#w63_7890123456789$123456789$123456789012345678901234567890123 = N'EXEC sp_executesql N''SET @@z63_7890123456789$123456789$123456789012345678901234567890123 = @@p63_7890123456789$123456789$123456789012345678901234567890123 + @@p63_7890123456789$123456789$123456789012345678901234567890123'', N''@@z63_7890123456789$123456789$123456789012345678901234567890123 INT OUT, @@p63_7890123456789$123456789$123456789012345678901234567890123 INT'', @@z63_7890123456789$123456789$123456789012345678901234567890123 OUTPUT, @@p63_7890123456789$123456789$123456789012345678901234567890123;'; +SET @@x63_7890123456789$123456789$123456789012345678901234567890123 = N'@@z63_7890123456789$123456789$123456789012345678901234567890123 INT OUTPUT, @@p63_7890123456789$123456789$123456789012345678901234567890123 INT'; +declare @#y63_7890123456789$123456789$123456789012345678901234567890123 INT; +declare @@z63_7890123456789$123456789$123456789012345678901234567890123 INT; +EXEC sp_executesql @@v63_7890123456789$123456789$123456789012345678901234567890123, @@x63_7890123456789$123456789$123456789012345678901234567890123, @@z63_7890123456789$123456789$123456789012345678901234567890123 = @#y63_7890123456789$123456789$123456789012345678901234567890123 OUT, @@p63_7890123456789$123456789$123456789012345678901234567890123 = 10; +EXEC sp_executesql @#w63_7890123456789$123456789$123456789012345678901234567890123, @@x63_7890123456789$123456789$123456789012345678901234567890123, @@z63_7890123456789$123456789$123456789012345678901234567890123 = @@z63_7890123456789$123456789$123456789012345678901234567890123 OUT, @@p63_7890123456789$123456789$123456789012345678901234567890123 = 11; +SELECT @#y63_7890123456789$123456789$123456789012345678901234567890123, @@z63_7890123456789$123456789$123456789012345678901234567890123; +go +~~START~~ +int#!#int +20#!#22 +~~END~~ + + +create procedure p2_spexec_atatuservar +as +declare @@v63_7890123456789$123456789$123456789012345678901234567890123 NVARCHAR(1000); +declare @#w63_7890123456789$123456789$123456789012345678901234567890123 NVARCHAR(max); +declare @@x63_7890123456789$123456789$123456789012345678901234567890123 NVARCHAR(1000); +SET @@v63_7890123456789$123456789$123456789012345678901234567890123 = N'SET @@z63_7890123456789$123456789$123456789012345678901234567890123 = @@p63_7890123456789$123456789$123456789012345678901234567890123 + @@p63_7890123456789$123456789$123456789012345678901234567890123'; +SET @#w63_7890123456789$123456789$123456789012345678901234567890123 = N'EXEC sp_executesql N''SET @@z63_7890123456789$123456789$123456789012345678901234567890123 = @@p63_7890123456789$123456789$123456789012345678901234567890123 + @@p63_7890123456789$123456789$123456789012345678901234567890123'', N''@@z63_7890123456789$123456789$123456789012345678901234567890123 INT OUT, @@p63_7890123456789$123456789$123456789012345678901234567890123 INT'', @@z63_7890123456789$123456789$123456789012345678901234567890123 OUTPUT, @@p63_7890123456789$123456789$123456789012345678901234567890123;'; +SET @@x63_7890123456789$123456789$123456789012345678901234567890123 = N'@@z63_7890123456789$123456789$123456789012345678901234567890123 INT OUTPUT, @@p63_7890123456789$123456789$123456789012345678901234567890123 INT'; +declare @#y63_7890123456789$123456789$123456789012345678901234567890123 INT; +declare @@z63_7890123456789$123456789$123456789012345678901234567890123 INT; +EXEC sp_executesql @@v63_7890123456789$123456789$123456789012345678901234567890123, @@x63_7890123456789$123456789$123456789012345678901234567890123, @@z63_7890123456789$123456789$123456789012345678901234567890123 = @#y63_7890123456789$123456789$123456789012345678901234567890123 OUT, @@p63_7890123456789$123456789$123456789012345678901234567890123 = 10; +EXEC sp_executesql @#w63_7890123456789$123456789$123456789012345678901234567890123, @@x63_7890123456789$123456789$123456789012345678901234567890123, @@z63_7890123456789$123456789$123456789012345678901234567890123 = @@z63_7890123456789$123456789$123456789012345678901234567890123 OUT, @@p63_7890123456789$123456789$123456789012345678901234567890123 = 11; +SELECT @#y63_7890123456789$123456789$123456789012345678901234567890123, @@z63_7890123456789$123456789$123456789012345678901234567890123; +go +exec p2_spexec_atatuservar +go +~~START~~ +int#!#int +20#!#22 +~~END~~ + + + + +create trigger tr17_atatuservar on t17_trigger_atatuservar for insert +as +begin +select 'trigger tr17_atatuservar' +declare @@v63_7890123456789$123456789$123456789012345678901234567890123 NVARCHAR(1000); +declare @#w63_7890123456789$123456789$123456789012345678901234567890123 NVARCHAR(max); +declare @@x63_7890123456789$123456789$123456789012345678901234567890123 NVARCHAR(1000); +SET @@v63_7890123456789$123456789$123456789012345678901234567890123 = N'SET @@z63_7890123456789$123456789$123456789012345678901234567890123 = @@p63_7890123456789$123456789$123456789012345678901234567890123 + @@p63_7890123456789$123456789$123456789012345678901234567890123'; +SET @#w63_7890123456789$123456789$123456789012345678901234567890123 = N'EXEC sp_executesql N''SET @@z63_7890123456789$123456789$123456789012345678901234567890123 = @@p63_7890123456789$123456789$123456789012345678901234567890123 + @@p63_7890123456789$123456789$123456789012345678901234567890123'', N''@@z63_7890123456789$123456789$123456789012345678901234567890123 INT OUT, @@p63_7890123456789$123456789$123456789012345678901234567890123 INT'', @@z63_7890123456789$123456789$123456789012345678901234567890123 OUTPUT, @@p63_7890123456789$123456789$123456789012345678901234567890123;'; +SET @@x63_7890123456789$123456789$123456789012345678901234567890123 = N'@@z63_7890123456789$123456789$123456789012345678901234567890123 INT OUTPUT, @@p63_7890123456789$123456789$123456789012345678901234567890123 INT'; +declare @#y63_7890123456789$123456789$123456789012345678901234567890123 INT; +declare @@z63_7890123456789$123456789$123456789012345678901234567890123 INT; +EXEC sp_executesql @@v63_7890123456789$123456789$123456789012345678901234567890123, @@x63_7890123456789$123456789$123456789012345678901234567890123, @@z63_7890123456789$123456789$123456789012345678901234567890123 = @#y63_7890123456789$123456789$123456789012345678901234567890123 OUT, @@p63_7890123456789$123456789$123456789012345678901234567890123 = 10; +EXEC sp_executesql @#w63_7890123456789$123456789$123456789012345678901234567890123, @@x63_7890123456789$123456789$123456789012345678901234567890123, @@z63_7890123456789$123456789$123456789012345678901234567890123 = @@z63_7890123456789$123456789$123456789012345678901234567890123 OUT, @@p63_7890123456789$123456789$123456789012345678901234567890123 = 11; +SELECT @#y63_7890123456789$123456789$123456789012345678901234567890123, @@z63_7890123456789$123456789$123456789012345678901234567890123; +end +go +insert t17_trigger_atatuservar values (123) +go +~~START~~ +varchar +trigger tr17_atatuservar +~~END~~ + +~~START~~ +int#!#int +20#!#22 +~~END~~ + +~~ROW COUNT: 1~~ + + +-- table variables in different types of functions +create function f1_ins_atatuservar(@@p1 int) +returns int +as +begin + declare @@tv table(a int) + insert @@tv values(@@p1) + return (select sum(a) from @@tv) +end +go +select dbo. f1_ins_atatuservar(123) +go +~~START~~ +int +123 +~~END~~ + + +create function f1_upd_atatuservar(@@p1 int) +returns int +as +begin + declare @@tv table(a int) + insert @@tv values(@@p1) + update @@tv set a = a + 1 + return (select sum(a) from @@tv) +end +go +select dbo. f1_upd_atatuservar(123) +go +~~START~~ +int +124 +~~END~~ + + +create function f1_del_atatuservar(@@p1 int) +returns int +as +begin + declare @@tv table(a int) + insert @@tv values(@@p1) + update @@tv set a = a + 1 + insert @@tv values(@@p1) + update @@tv set a = a + 1 + delete @@tv where a = 124 + return (select sum(a) from @@tv) +end +go +select dbo. f1_del_atatuservar(123) +go +~~START~~ +int +125 +~~END~~ + + +-- INSERT/UPDATE/DELETE on table variable in function +create function f3_atatuservar_upd(@@p1 int) +returns @@tv table(a int) +as +begin + insert @@tv values(@@p1) + update t set a = t.a + 1 from @@tv as t + return +end +go +select * from dbo. f3_atatuservar_upd(123) order by 1 +go +~~START~~ +int +124 +~~END~~ + + +create function f3_atatuservar_del(@@p1 int) +returns @@tv table(a int) +as +begin + insert @@tv values(@@p1) + update @@tv set a = a + 1 + insert @@tv values(@@p1) + delete t from @@tv as t where a = 124 + return +end +go +select * from dbo. f3_atatuservar_del(123) order by 1 +go +~~START~~ +int +123 +~~END~~ + + +create function f3_upd_atatuservar(@@p1 int) +returns @@tv table(a int) +as +begin + insert @@tv values(@@p1) + update t set a = t.a + 1 from t2_atatuservar, @@tv as t where t2_atatuservar.a = t.a + return +end +go +select * from dbo. f3_upd_atatuservar(123) order by 1 +go +~~START~~ +int +124 +~~END~~ + + +create function f3_del_atatuservar(@@p1 int) +returns @@tv table(a int) +as +begin + insert @@tv values(@@p1) + update @@tv set a = a + 1 + insert @@tv values(@@p1) + delete t from t2_atatuservar join @@tv as t on t2_atatuservar.a = t.a + return +end +go +select * from dbo. f3_del_atatuservar(123) order by 1 +go +~~START~~ +int +124 +~~END~~ + + +create function f4_ins_atatuservar(@#p1 int) +returns int +as +begin + declare @#tv table(a int) + insert @#tv values(@#p1) + return (select sum(a) from @#tv) +end +go +select dbo. f4_ins_atatuservar(123) +go +~~START~~ +int +123 +~~END~~ + + +create function f4_upd_atatuservar(@#p1 int) +returns int +as +begin + declare @#tv table(a int) + insert @#tv values(@#p1) + update @#tv set a = a + 1 + return (select sum(a) from @#tv) +end +go +select dbo. f4_upd_atatuservar(123) +go +~~START~~ +int +124 +~~END~~ + + +create function f4_del_atatuservar(@#p1 int) +returns int +as +begin + declare @#tv table(a int) + insert @#tv values(@#p1) + update @#tv set a = a + 1 + insert @#tv values(@#p1) + update @#tv set a = a + 1 + delete @#tv where a = 124 + return (select sum(a) from @#tv) +end +go +select dbo. f4_del_atatuservar(123) +go +~~START~~ +int +125 +~~END~~ + + +create function f5_upd_atatuservar(@#p1 int) +returns @#tv table(a int) +as +begin + insert @#tv values(@#p1) + update t set a = t.a + 1 from @#tv as t + return +end +go +select * from dbo. f5_upd_atatuservar(123) order by 1 +go +~~START~~ +int +124 +~~END~~ + + +create function f5_del_atatuservar(@#p1 int) +returns @#tv table(a int) +as +begin + insert @#tv values(@#p1) + update @#tv set a = a + 1 + insert @#tv values(@#p1) + delete t from @#tv as t where a = 124 + return +end +go +select * from dbo. f5_del_atatuservar(123) order by 1 +go +~~START~~ +int +123 +~~END~~ + + +create function f6_upd_atatuservar(@#p1 int) +returns @#tv table(a int) +as +begin + insert @#tv values(@#p1) + update t set a = t.a + 1 from t2_atatuservar, @#tv as t where t2_atatuservar.a = t.a + return +end +go +select * from dbo. f6_upd_atatuservar(123) order by 1 +go +~~START~~ +int +124 +~~END~~ + + +create function f6_del_atatuservar(@#p1 int) +returns @#tv table(a int) +as +begin + insert @#tv values(@#p1) + update @#tv set a = a + 1 + insert @#tv values(@#p1) + delete t from t2_atatuservar, @#tv as t where t2_atatuservar.a = t.a + return +end +go +select * from dbo. f6_del_atatuservar(123) order by 1 +go +~~START~~ +int +124 +~~END~~ + + +create function f7_tabvar_udf_upd_atatuservar(@@p1 int) +returns @#tv table(a int) +as +begin + insert @#tv values(@@p1) + update t set a = t.a + 1 from t2_atatuservar, @#tv as t where t2_atatuservar.a = t.a + return +end +go +select * from dbo. f7_tabvar_udf_upd_atatuservar(123) order by 1 +go +~~START~~ +int +124 +~~END~~ + + +create function f7a_tabvar_udf_upd_atatuservar(@@p1 int) +returns @#tv table(a int) +as +begin + insert @#tv values(@@p1) + update t set a = t.a + 1 from @#tv as tv, t2_atatuservar as t where tv.a = t.a + return +end +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: 'UPDATE' cannot be used within a function)~~ + + +create function f8_tabvar_udf_del_atatuservar(@@p1 int) +returns @#tv table(a int) +as +begin + insert @#tv values(@@p1) + update @#tv set a = a + 1 + insert @#tv values(@@p1) + delete t from @#tv as tv, t2_atatuservar as t where tv.a = t.a + return +end +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: 'DELETE' cannot be used within a function)~~ + + +create function f9_tabvar_udf_del_atatuservar(@p1 int) +returns @tv table(a int) +as +begin + insert @tv values(@p1) + update @tv set a = a + 1 + insert @tv values(@p1) + delete t from @tv as t inner join t2_atatuservar as tv on tv.a = t.a + return +end +go +select * from dbo.f9_tabvar_udf_del_atatuservar(123) +go +~~START~~ +int +124 +~~END~~ + + +create function f10_tabvar_udf_del_atatuservar(@#p1 int) +returns @@tv table(a int) +as +begin + insert @@tv values(@#p1) + update @@tv set a = a + 1 + insert @@tv values(@#p1) + delete t from t2_atatuservar as tv join @@tv as t on tv.a = t.a + return +end +go +select * from dbo.f10_tabvar_udf_del_atatuservar(123) +go +~~START~~ +int +124 +~~END~~ + + +create function f4_atatuservar_tabvar_in_function_upd(@#p1 int) +returns @@tv table(a int) +as +begin + insert @@tv values(@#p1) + update t set a = t.a + 1 from t2_atatuservar as t2_atatuservar left join t2_atatuservar as tv on tv.a = t2_atatuservar.a right join @@tv t on tv.a = t.a + return +end +go +select * from dbo.f4_atatuservar_tabvar_in_function_upd(123) +go +~~START~~ +int +124 +~~END~~ + + +create function f12_tabvar_udf_upd_atatuservar(@#p1 int) +returns @@tv table(a int) +as +begin + insert @@tv values(@#p1) + update t set a = t.a + 1 from @@tv as tv cross join t2_atatuservar as t + return +end +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: 'UPDATE' cannot be used within a function)~~ + + +create function f13_tabvar_udf_del_atatuservar(@#p1 int) +returns @@tv table(a int) +as +begin + insert @@tv values(@#p1) + update @@tv set a = a + 1 + insert @@tv values(@#p1) + delete t from @@tv as t2_atatuservar right join t2_atatuservar as tv on tv.a = t2_atatuservar.a full outer join t2_atatuservar t on tv.a = t.a + return +end +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: 'DELETE' cannot be used within a function)~~ + + +create function f14_del_atatuservar(@@p128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int) +returns int +as +begin + declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 table(a int) + insert @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 values(@@p128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678) + update @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 set a = a + 1 + insert @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 values(@@p128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678) + update @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 set a = a + 1 + delete @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 where a = 124 + return (select sum(a) from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678) +end +go +select dbo. f14_del_atatuservar(123) +go +~~START~~ +int +125 +~~END~~ + + +-- INSERT/UPDATE/DELETE on table variable in function +create function f15_upd_atatuservar(@@p128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int) +returns @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 table(a int) +as +begin + insert @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 values(@@p128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678) + update t set a = t.a + 1 from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 as t + return +end +go +select * from dbo. f15_upd_atatuservar(123) order by 1 +go +~~START~~ +int +124 +~~END~~ + + +create function f16_tabvar_udf_del_atatuservar(@#q128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int) +returns @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 table(a int) +as +begin + insert @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 values(@#q128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678) + update @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 set a = a + 1 + insert @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 values(@#q128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678) + delete t from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 as t2_atatuservar right join t2_atatuservar as tv on tv.a = t2_atatuservar.a full outer join t2_atatuservar t on tv.a = t.a + return +end +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: 'DELETE' cannot be used within a function)~~ + + +-- THROW +declare @@v int = 50001; +THROW @@v, 'Test message', 1; +go +~~ERROR (Code: 50001)~~ + +~~ERROR (Message: Test message)~~ + + +declare @@v int = 50001, @@v2 varchar(30) = 'Test message'; +THROW @@v, @@v2, 1 +go +~~ERROR (Code: 50001)~~ + +~~ERROR (Message: Test message)~~ + + +declare @@v int = 50001, @@v2 varchar(30) = 'Test message', @@v3 int=1; +THROW @@v, @@v2, @@v3 +go +~~ERROR (Code: 50001)~~ + +~~ERROR (Message: Test message)~~ + + +declare @#v int = 50001; +THROW @#v, 'Test message', 1; +go +~~ERROR (Code: 50001)~~ + +~~ERROR (Message: Test message)~~ + + +declare @#v int = 50001, @#v2 varchar(30) = 'Test message'; +THROW @#v, @#v2, 1 +go +~~ERROR (Code: 50001)~~ + +~~ERROR (Message: Test message)~~ + + +declare @#v int = 50001, @#v2 varchar(30) = 'Test message', @#v3 int=1; +THROW @#v, @#v2, @#v3 +go +~~ERROR (Code: 50001)~~ + +~~ERROR (Message: Test message)~~ + + + +create procedure p20_atatuservar @@p int +as +if @@p > 0 +begin +declare @@v int = 50001, @@v2 varchar(30) = 'Test message 1', @@v3 int=1; +THROW @@v, @@v2, @@v3 +end +declare @#v int = 50001, @#v2 varchar(30) = 'Test message 2', @#v3 int=1; +THROW @#v, @#v2, @#v3 +go +exec p20_atatuservar 1 +go +~~ERROR (Code: 50001)~~ + +~~ERROR (Message: Test message 1)~~ + +exec p20_atatuservar 0 +go +~~ERROR (Code: 50001)~~ + +~~ERROR (Message: Test message 2)~~ + + + +create trigger tr18_atatuservar on t18_trigger_atatuservar for insert +as +begin +select 'trigger tr18_atatuservar' +declare @#v int = 50001, @#v2 varchar(30) = 'Test message 2', @#v3 int=1; +THROW @#v, @#v2, @#v3 +end +go +insert t18_trigger_atatuservar values (123) +go +~~START~~ +varchar +trigger tr18_atatuservar +~~END~~ + +~~ERROR (Code: 50001)~~ + +~~ERROR (Message: Test message 2)~~ + + +declare @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int = 50001, @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$123456789012345678901234567890123456782 varchar(30) = 'Test message', @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$123456789012345678901234567890123456783 int=1; +THROW @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678, @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$123456789012345678901234567890123456782, @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$123456789012345678901234567890123456783 +go +~~ERROR (Code: 50001)~~ + +~~ERROR (Message: Test message)~~ + + +create procedure p21_atatuservar +as +declare @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int = 50001, @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$123456789012345678901234567890123456782 varchar(30) = 'Test message', @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$123456789012345678901234567890123456783 int=1; +THROW @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678, @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$123456789012345678901234567890123456782, @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$123456789012345678901234567890123456783 +go +exec p21_atatuservar +go +~~ERROR (Code: 50001)~~ + +~~ERROR (Message: Test message)~~ + + + +create trigger tr19_atatuservar on t19_trigger_atatuservar for insert +as +begin +select 'trigger tr19_atatuservar' +declare @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int = 50001, @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$123456789012345678901234567890123456782 varchar(30) = 'Test message', @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$123456789012345678901234567890123456783 int=1; +THROW @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678, @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$123456789012345678901234567890123456782, @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$123456789012345678901234567890123456783 +end +go +insert t19_trigger_atatuservar values (123) +go +~~START~~ +varchar +trigger tr19_atatuservar +~~END~~ + +~~ERROR (Code: 50001)~~ + +~~ERROR (Message: Test message)~~ + + +-- DBCC CHECKIDENT +declare @@TableName varchar(100)='mytab' +DBCC CHECKIDENT (@@TableName) +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: DBCC CHECKIDENT does not currently support a variable for the table name)~~ + +declare @@v int=2 +DBCC CHECKIDENT ('mytab', RESEED, @@v) +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: DBCC CHECKIDENT does not currently support a variable for the RESEED value)~~ + + +create procedure p1_checkident_atatuservar @@TableName varchar(100), @@v int +as +DBCC CHECKIDENT (@@TableName, RESEED, @@v) +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: DBCC CHECKIDENT does not currently support a variable for the table name)~~ + + +create trigger tr20_atatuservar on t20_trigger_atatuservar for insert +as +begin +select 'trigger tr20_atatuservar' +declare @@TableName varchar(100)='mytab', @@v int=2 +DBCC CHECKIDENT (@@TableName, RESEED, @@v) +end +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: DBCC CHECKIDENT does not currently support a variable for the table name)~~ + + +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int=2 +DBCC CHECKIDENT ('mytab', RESEED, @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678) +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: DBCC CHECKIDENT does not currently support a variable for the RESEED value)~~ + + +create procedure p2_checkident_atatuservar @@t128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(100), @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int +as +DBCC CHECKIDENT (@@t128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678, RESEED, @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678) +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: DBCC CHECKIDENT does not currently support a variable for the table name)~~ + + +create trigger tr21_atatuservar on t21_trigger_atatuservar for insert +as +begin +select 'trigger tr21_atatuservar' +declare @@t128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(100)='mytab', @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int=2 +DBCC CHECKIDENT (@@t128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678, RESEED, @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678) +end +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: DBCC CHECKIDENT does not currently support a variable for the table name)~~ + + +-- transaction name +declare @@V varchar(50) = 'myxact' +begin transaction @@v +insert t3_atatuservar values(234) +declare @#V varchar(50) = 'mysavept' +save transaction @#v +insert t3_atatuservar values(345) +set @#V = 'mysavept' +rollback transaction @#v +insert t3_atatuservar values(567) +commit transaction @@v +go +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +select * from t3_atatuservar +go +~~START~~ +int +123 +234 +567 +~~END~~ + + +create procedure p1_xactname_atatuservar +as +declare @@V varchar(50) = 'myxact' +delete t3_atatuservar where a > 123 +begin transaction @@v +insert t3_atatuservar values(234) +declare @#V varchar(50) = 'mysavept' +save transaction @#v +insert t3_atatuservar values(345) +set @#V = 'mysavept' +rollback transaction @#v +insert t3_atatuservar values(567) +commit transaction @@v +select * from t3_atatuservar +go +exec p1_xactname_atatuservar +go +~~ROW COUNT: 2~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~START~~ +int +123 +234 +567 +~~END~~ + + +delete t3_atatuservar where a > 123 +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(50) = 'myxact' +begin transaction @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +insert t3_atatuservar values(234) +declare @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(50) = 'mysavept' +save transaction @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +insert t3_atatuservar values(345) +set @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 = 'mysavept' +rollback transaction @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +insert t3_atatuservar values(567) +commit transaction @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +go +~~ROW COUNT: 2~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +select * from t3_atatuservar +go +~~START~~ +int +123 +234 +567 +~~END~~ + + +create procedure p2_xactname_atatuservar +as +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(50) = 'myxact' +delete t3_atatuservar where a > 123 +begin transaction @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +insert t3_atatuservar values(234) +declare @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(50) = 'mysavept' +save transaction @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +insert t3_atatuservar values(345) +set @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 = 'mysavept' +rollback transaction @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +insert t3_atatuservar values(567) +commit transaction @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +select * from t3_atatuservar +go +exec p2_xactname_atatuservar +go +~~ROW COUNT: 2~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~START~~ +int +123 +234 +567 +~~END~~ + + +-- cursor variable in T-SQL batch, stored procedure, trigger +declare @#v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(20) +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 cursor +set @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 = cursor for select a from t_checkident_atatuservar order by n +open @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +while 1=1 +begin + fetch from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 into @#v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 + if @@fetch_status <> 0 break + select @#v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +end +close @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +deallocate @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +go +~~START~~ +varchar +one +~~END~~ + +~~START~~ +varchar +two +~~END~~ + +~~START~~ +varchar +three +~~END~~ + +~~START~~ +varchar +four +~~END~~ + + +create procedure p1_cursor_atatuservar +as +begin + declare @#v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(20) + declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 cursor + set @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 = cursor for select a from t_checkident_atatuservar order by n + open @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 + while 1=1 + begin + fetch from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 into @#v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 + if @@fetch_status <> 0 break + select @#v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 + end + close @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 + deallocate @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +end +go +exec p1_cursor_atatuservar +go +~~START~~ +varchar +one +~~END~~ + +~~START~~ +varchar +two +~~END~~ + +~~START~~ +varchar +three +~~END~~ + +~~START~~ +varchar +four +~~END~~ + + + +create trigger tr22_atatuservar on t22_trigger_atatuservar for insert +as +begin + select 'trigger tr22_atatuservar' + declare @@v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(20) + declare @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 cursor + set @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 = cursor for select a from t_checkident_atatuservar order by n + open @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 + while 1=1 + begin + fetch from @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 into @@v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 + if @@fetch_status <> 0 break + select @@v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 + end + close @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 + deallocate @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +end +go +insert t22_trigger_atatuservar values (123) +go +~~START~~ +varchar +trigger tr22_atatuservar +~~END~~ + +~~START~~ +varchar +one +~~END~~ + +~~START~~ +varchar +two +~~END~~ + +~~START~~ +varchar +three +~~END~~ + +~~START~~ +varchar +four +~~END~~ + +~~ROW COUNT: 1~~ + +set quoted_identifier on +go + +-- user-defined variables that were previously mapped to internal sys. functions, e.g. sys.rand() +declare @@xact_state int=123 select @@xact_state, xact_state() +go +~~START~~ +int#!#smallint +123#!#0 +~~END~~ + +declare @@error_line int=123 select @@error_line, error_line() +go +~~START~~ +int#!#int +123#!# +~~END~~ + +declare @@error_message int=123 select @@error_message, error_message() +go +~~START~~ +int#!#nvarchar +123#!# +~~END~~ + +declare @@error_number int=123 select @@error_number, error_number() +go +~~START~~ +int#!#int +123#!# +~~END~~ + +declare @@error_procedure int=123 select @@error_procedure, error_procedure() +go +~~START~~ +int#!#nvarchar +123#!# +~~END~~ + +declare @@error_severity int=123 select @@error_severity, error_severity() +go +~~START~~ +int#!#int +123#!# +~~END~~ + +declare @@error_state int=123 select @@error_state, error_state() +go +~~START~~ +int#!#int +123#!# +~~END~~ + +declare @@db_id int=123 select @@db_id, db_id('master') +go +~~START~~ +int#!#smallint +123#!#1 +~~END~~ + +declare @@db_name int=123 select @@db_name, db_name() +go +~~START~~ +int#!#nvarchar +123#!#master +~~END~~ + +declare @@exp int=123 select @@exp, exp(1) +go +~~START~~ +int#!#float +123#!#2.718281828459045 +~~END~~ + +declare @@sign int=123 select @@sign, sign(1) +go +~~START~~ +int#!#int +123#!#1 +~~END~~ + +declare @@lock_timeout int=123 select @@lock_timeout, lock_timeout() +go +~~START~~ +int#!#int +-1#!#-1 +~~END~~ + +declare @@rand int=123 select @@rand, case when rand() <= 0 then 'too small, <= 0' when rand() >= 1 then ' too large, >= 1' else 'correct, >0 && <1' end +go +~~START~~ +int#!#varchar +123#!#correct, >0 && <1 +~~END~~ + +declare @@trigger_nestlevel int=123 select @@trigger_nestlevel, trigger_nestlevel() +go +~~START~~ +int#!#int +123#!#0 +~~END~~ + +declare @@atn2 int=123 select @@atn2, atn2(1,0) +go +~~START~~ +int#!#float +123#!#1.5707963267948966 +~~END~~ + +declare @@datepart int=123 select @@datepart, datepart(yy, '2024-11-12') +go +~~START~~ +int#!#int +123#!#2024 +~~END~~ + +declare @@datediff int=123 select @@datediff, datediff(dd, '2024-11-12', '2024-12-13') +go +~~START~~ +int#!#int +123#!#31 +~~END~~ + +declare @@datediff_big int=123 select @@datediff_big, datediff(dd, '2024-11-12', '2024-12-13') +go +~~START~~ +int#!#int +123#!#31 +~~END~~ + +declare @@dateadd int=123 select @@dateadd, datediff(dd, 3, '2024-11-12') +go +~~START~~ +int#!#int +123#!#45603 +~~END~~ + +declare @@datename int=123 select @@datename, datename(dw, '2024-11-12') +go +~~START~~ +int#!#text +123#!#Tuesday +~~END~~ + + +create proc p1_sysfunctions_atatuservar +as +begin +declare @@xact_state int=123 select @@xact_state, xact_state() +declare @@error_line int=123 select @@error_line, error_line() +declare @@error_message int=123 select @@error_message, error_message() +declare @@error_number int=123 select @@error_number, error_number() +declare @@error_procedure int=123 select @@error_procedure, error_procedure() +declare @@error_state int=123 select @@error_state, error_state() +declare @@db_id int=123 select @@db_id, db_id('master') +declare @@db_name int=123 select @@db_name, db_name() +declare @@exp int=123 select @@exp, exp(1) +declare @@sign int=123 select @@sign, sign(1) +declare @@lock_timeout int=123 select @@lock_timeout, lock_timeout() +declare @@rand int=123 select @@rand, case when rand() <= 0 then 'too small, <= 0' when rand() >= 1 then ' too large, >= 1' else 'correct, >0 && <1' end +declare @@trigger_nestlevel int=123 select @@trigger_nestlevel, trigger_nestlevel() +declare @@atn2 int=123 select @@atn2, atn2(1,0) +declare @@datepart int=123 select @@datepart, datepart(yy, '2024-11-12') +declare @@datediff int=123 select @@datediff, datediff(dd, '2024-11-12', '2024-12-13') +declare @@datediff_big int=123 select @@datediff_big, datediff(dd, '2024-11-12', '2024-12-13') +declare @@dateadd int=123 select @@dateadd, datediff(dd, 3, '2024-11-12') +declare @@datename int=123 select @@datename, datename(dw, '2024-11-12') +end +go +exec p1_sysfunctions_atatuservar +go +~~START~~ +int#!#smallint +123#!#0 +~~END~~ + +~~START~~ +int#!#int +123#!# +~~END~~ + +~~START~~ +int#!#nvarchar +123#!# +~~END~~ + +~~START~~ +int#!#int +123#!# +~~END~~ + +~~START~~ +int#!#nvarchar +123#!# +~~END~~ + +~~START~~ +int#!#int +123#!# +~~END~~ + +~~START~~ +int#!#smallint +123#!#1 +~~END~~ + +~~START~~ +int#!#nvarchar +123#!#master +~~END~~ + +~~START~~ +int#!#float +123#!#2.718281828459045 +~~END~~ + +~~START~~ +int#!#int +123#!#1 +~~END~~ + +~~START~~ +int#!#int +-1#!#-1 +~~END~~ + +~~START~~ +int#!#varchar +123#!#correct, >0 && <1 +~~END~~ + +~~START~~ +int#!#int +123#!#0 +~~END~~ + +~~START~~ +int#!#float +123#!#1.5707963267948966 +~~END~~ + +~~START~~ +int#!#int +123#!#2024 +~~END~~ + +~~START~~ +int#!#int +123#!#31 +~~END~~ + +~~START~~ +int#!#int +123#!#31 +~~END~~ + +~~START~~ +int#!#int +123#!#45603 +~~END~~ + +~~START~~ +int#!#text +123#!#Tuesday +~~END~~ + + +create function f1_sysfunctions_atatuservar() returns int +as +begin +declare @@xact_state int=123 +declare @@error_line int=123 +declare @@error_message int=123 +declare @@error_number int=123 +declare @@error_procedure int=123 +declare @@error_state int=123 +declare @@db_id int=123 +declare @@db_name int=123 +declare @@exp int=123 +declare @@sign int=123 +declare @@lock_timeout int=123 +declare @@rand int=123 +declare @@trigger_nestlevel int=123 +declare @@atn2 int=123 +declare @@datepart int=123 +declare @@datediff int=123 +declare @@datediff_big int=123 +declare @@dateadd int=123 +declare @@datename int=123 +return @@xact_state + @@error_line + @@error_message + @@error_number + @@error_procedure + @@error_state + @@db_id + @@db_name + @@exp + @@sign + @@lock_timeout + @@rand + @@trigger_nestlevel + @@atn2 + @@datepart + @@datediff + @@datediff_big + @@dateadd + @@datename +end +go +select dbo.f1_sysfunctions_atatuservar() +go +~~START~~ +int +2213 +~~END~~ + + +create trigger tr1_sysfunctions_atatuservar on t23_trigger_atatuservar for insert as +begin +declare @@xact_state int=123 select @@xact_state, xact_state() +declare @@error_line int=123 select @@error_line, error_line() +declare @@error_message int=123 select @@error_message, error_message() +declare @@error_number int=123 select @@error_number, error_number() +declare @@error_procedure int=123 select @@error_procedure, error_procedure() +declare @@error_state int=123 select @@error_state, error_state() +declare @@db_id int=123 select @@db_id, db_id('master') +declare @@db_name int=123 select @@db_name, db_name() +declare @@exp int=123 select @@exp, exp(1) +declare @@sign int=123 select @@sign, sign(1) +declare @@lock_timeout int=123 select @@lock_timeout, lock_timeout() +declare @@rand int=123 select @@rand, case when rand() <= 0 then 'too small, <= 0' when rand() >= 1 then ' too large, >= 1' else 'correct, >0 && <1' end +declare @@trigger_nestlevel int=123 select @@trigger_nestlevel, trigger_nestlevel() +declare @@atn2 int=123 select @@atn2, atn2(1,0) +declare @@datepart int=123 select @@datepart, datepart(yy, '2024-11-12') +declare @@datediff int=123 select @@datediff, datediff(dd, '2024-11-12', '2024-12-13') +declare @@datediff_big int=123 select @@datediff_big, datediff(dd, '2024-11-12', '2024-12-13') +declare @@dateadd int=123 select @@dateadd, datediff(dd, 3, '2024-11-12') +declare @@datename int=123 select @@datename, datename(dw, '2024-11-12') +end +go +insert t23_trigger_atatuservar values(1) +go +~~START~~ +int#!#smallint +123#!#1 +~~END~~ + +~~START~~ +int#!#int +123#!# +~~END~~ + +~~START~~ +int#!#nvarchar +123#!# +~~END~~ + +~~START~~ +int#!#int +123#!# +~~END~~ + +~~START~~ +int#!#nvarchar +123#!# +~~END~~ + +~~START~~ +int#!#int +123#!# +~~END~~ + +~~START~~ +int#!#smallint +123#!#1 +~~END~~ + +~~START~~ +int#!#nvarchar +123#!#master +~~END~~ + +~~START~~ +int#!#float +123#!#2.718281828459045 +~~END~~ + +~~START~~ +int#!#int +123#!#1 +~~END~~ + +~~START~~ +int#!#int +-1#!#-1 +~~END~~ + +~~START~~ +int#!#varchar +123#!#correct, >0 && <1 +~~END~~ + +~~START~~ +int#!#int +123#!#1 +~~END~~ + +~~START~~ +int#!#float +123#!#1.5707963267948966 +~~END~~ + +~~START~~ +int#!#int +123#!#2024 +~~END~~ + +~~START~~ +int#!#int +123#!#31 +~~END~~ + +~~START~~ +int#!#int +123#!#31 +~~END~~ + +~~START~~ +int#!#int +123#!#45603 +~~END~~ + +~~START~~ +int#!#text +123#!#Tuesday +~~END~~ + +~~ROW COUNT: 1~~ + diff --git a/test/JDBC/expected/babel_format_custom_date_time.out b/test/JDBC/expected/babel_format_custom_date_time.out index a6f9326c71..1cebfe44b3 100644 --- a/test/JDBC/expected/babel_format_custom_date_time.out +++ b/test/JDBC/expected/babel_format_custom_date_time.out @@ -4,6 +4,8 @@ DECLARE @curr_date date; SET @curr_date = '12/01/1999'; SELECT FORMAT(@curr_date, 'dd/yy/MM', 'dz-BT'); GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The culture parameter "dz-BT" provided in the function call is not supported.)~~ @@ -54,6 +56,8 @@ DECLARE @curr_datetime datetime; SET @curr_datetime = '1753-01-01 00:00:00.123'; SELECT FORMAT(@curr_datetime, 'dd/yy/MM', 'dz-BT'); GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The culture parameter "dz-BT" provided in the function call is not supported.)~~ @@ -104,6 +108,8 @@ DECLARE @curr_datetime_2 datetime2; SET @curr_datetime_2 = '0001-01-01 00:00:00.123'; SELECT FORMAT(@curr_datetime_2, 'dd/yy/MM', 'dz-BT'); GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The culture parameter "dz-BT" provided in the function call is not supported.)~~ diff --git a/test/JDBC/expected/empty_dq_string_in_object-vu-cleanup.out b/test/JDBC/expected/empty_dq_string_in_object-vu-cleanup.out new file mode 100644 index 0000000000..61bc654f33 --- /dev/null +++ b/test/JDBC/expected/empty_dq_string_in_object-vu-cleanup.out @@ -0,0 +1,58 @@ +drop table t1_empty_dq_string +go +drop table t2_empty_dq_string +go +drop table t3_empty_dq_string +go +drop table t4_empty_dq_string +go +drop table t5_empty_dq_string +go +drop table t6_empty_dq_string +go +drop table t7_empty_dq_string +go +drop procedure p1_empty_dq_string +go +drop function f1_empty_dq_string +go +drop procedure p2_empty_dq_string +go +drop function f2_empty_dq_string +go +drop procedure p2a_empty_dq_string +go +drop function f2a_empty_dq_string +go +drop procedure p2b_empty_dq_string +go +drop procedure p3_empty_dq_string +go +drop procedure p4_empty_dq_string +go +drop function f4_empty_dq_string +go +drop procedure p5_empty_dq_string +go +drop function f5_empty_dq_string +go +drop procedure p6_empty_dq_string +go +drop procedure p7_empty_dq_string +go +drop procedure p7a_empty_dq_string +go +drop procedure p7b_empty_dq_string +go +drop function f7b_empty_dq_string +go +drop procedure p7c_empty_dq_string +go +set quoted_identifier on +go +drop table "t8_empty_dq_string" +go +drop procedure "p8_empty_dq_string" +go +drop function "f8_empty_dq_string" +go diff --git a/test/JDBC/expected/empty_dq_string_in_object-vu-prepare.out b/test/JDBC/expected/empty_dq_string_in_object-vu-prepare.out new file mode 100644 index 0000000000..2afb2d9274 --- /dev/null +++ b/test/JDBC/expected/empty_dq_string_in_object-vu-prepare.out @@ -0,0 +1,31 @@ +create table t1_empty_dq_string(a int) +go +create table t2_empty_dq_string(a int) +go +create table t3_empty_dq_string(a int) +go +create table t4_empty_dq_string(a int) +go +create table t5_empty_dq_string(a int, b varchar(10)) +insert t5_empty_dq_string values(1, 'test 1') +go +~~ROW COUNT: 1~~ + +create table t6_empty_dq_string(a int, b varchar(10)) +insert t6_empty_dq_string values(1, 'test 1') +go +~~ROW COUNT: 1~~ + +create table t7_empty_dq_string(a int, b varchar(10)) +insert t7_empty_dq_string values(1, 'test 1') +go +~~ROW COUNT: 1~~ + + +set quoted_identifier on +go +create table "t8_empty_dq_string"("a" int, "b" varchar(10)) +insert "t8_empty_dq_string" values(1, 'test 1') +go +~~ROW COUNT: 1~~ + diff --git a/test/JDBC/expected/empty_dq_string_in_object-vu-verify.out b/test/JDBC/expected/empty_dq_string_in_object-vu-verify.out new file mode 100644 index 0000000000..517c6bb4a5 --- /dev/null +++ b/test/JDBC/expected/empty_dq_string_in_object-vu-verify.out @@ -0,0 +1,549 @@ + +-- Purpose: a double-quoted empty string inside a SQL object body should be treated as an empty string +set quoted_identifier off +go + +-- SELECT "" +select "" as empty_str +go +~~START~~ +varchar + +~~END~~ + +create procedure p1_empty_dq_string +as +select "" as empty_str +go +exec p1_empty_dq_string +go +~~START~~ +varchar + +~~END~~ + +create function f1_empty_dq_string() returns varchar(10) +as +begin +return "" +end +go +select dbo.f1_empty_dq_string(), len(dbo.f1_empty_dq_string()) +go +~~START~~ +varchar#!#int +#!#0 +~~END~~ + +create trigger tr1_empty_dq_string on t1_empty_dq_string for insert as +begin +select "" as empty_str +end +go +insert t1_empty_dq_string values(1) +go +~~START~~ +varchar + +~~END~~ + +~~ROW COUNT: 1~~ + + +-- variable declaration and assignment +declare @v varchar(10) = "" +set @v = "" +select @v +go +~~START~~ +varchar + +~~END~~ + +create procedure p2_empty_dq_string +as +declare @v varchar(10) = "" +set @v = "" +select @v +go +exec p2_empty_dq_string +go +~~START~~ +varchar + +~~END~~ + +create function f2_empty_dq_string() returns varchar(10) +as +begin +declare @v varchar(10) = "" +set @v = "" +return '['+@v+']' +end +go +select dbo.f2_empty_dq_string(), len(dbo.f2_empty_dq_string()) +go +~~START~~ +varchar#!#int +[]#!#2 +~~END~~ + +create trigger tr2_empty_dq_string on t2_empty_dq_string for insert as +begin +declare @v varchar(10) = "" +set @v = "" +select @v +end +go +insert t2_empty_dq_string values(1) +go +~~START~~ +varchar + +~~END~~ + +~~ROW COUNT: 1~~ + + +-- execute immediate +execute("") +go + +-- argument for procedure/function call +create procedure p2a_empty_dq_string @p varchar(10) +as +select '['+@p+']' as p, len(@p) as len +go +exec p2a_empty_dq_string "" +go +~~START~~ +varchar#!#int +[]#!#0 +~~END~~ + +exec p2a_empty_dq_string @p="" +go +~~START~~ +varchar#!#int +[]#!#0 +~~END~~ + +create function f2a_empty_dq_string(@p varchar(10)) returns varchar(10) +as +begin +return '['+@p+']' +end +go +select dbo.f2a_empty_dq_string(""), len(dbo.f2a_empty_dq_string("")) +go +~~START~~ +varchar#!#int +[]#!#2 +~~END~~ + + +create procedure p2b_empty_dq_string @p varchar(10) +as +exec p2a_empty_dq_string "" +exec p2a_empty_dq_string @p="" +select dbo.f2a_empty_dq_string(""), len(dbo.f2a_empty_dq_string("")) +go +exec p2b_empty_dq_string "" +go +~~START~~ +varchar#!#int +[]#!#0 +~~END~~ + +~~START~~ +varchar#!#int +[]#!#0 +~~END~~ + +~~START~~ +varchar#!#int +[]#!#2 +~~END~~ + + +-- print "" (not visible in JDBC test output) +print "" +go +create procedure p3_empty_dq_string +as +print "" +go +exec p3_empty_dq_string +go +create trigger tr3_empty_dq_string on t3_empty_dq_string for insert as +begin +select 'trigger' +print "" +end +go +insert t3_empty_dq_string values(1) +go +~~START~~ +varchar +trigger +~~END~~ + +~~ROW COUNT: 1~~ + + +-- usage in condition +if 'a' = "" select 'branch 1' else select 'branch 2' +go +~~START~~ +varchar +branch 2 +~~END~~ + +create procedure p4_empty_dq_string as +if 'a' = "" select 'branch 1' else select 'branch 2' +go +exec p4_empty_dq_string +go +~~START~~ +varchar +branch 2 +~~END~~ + +create function f4_empty_dq_string() returns int +as +begin +if 'a' = "" return 1 +return 2 +end +go +select dbo.f4_empty_dq_string() +go +~~START~~ +int +2 +~~END~~ + +create trigger tr4_empty_dq_string on t4_empty_dq_string for insert as +begin +if 'a' = "" select 'branch 1' else select 'branch 2' +end +go +insert t4_empty_dq_string values(1) +go +~~START~~ +varchar +branch 2 +~~END~~ + +~~ROW COUNT: 1~~ + + +-- usage in WHERE_clause +select * from t5_empty_dq_string where b = "" order by a +go +~~START~~ +int#!#varchar +~~END~~ + +create procedure p5_empty_dq_string as +select a, '['+b+']' as b from t5_empty_dq_string where b = "" order by a +go +exec p5_empty_dq_string +go +~~START~~ +int#!#varchar +~~END~~ + +create function f5_empty_dq_string() returns int +as +begin +declare @v int +select @v = count(*) from t5_empty_dq_string where b = "" +return '['+@v+']' +end +go +select dbo.f5_empty_dq_string() +go +~~START~~ +int +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: invalid input syntax for type integer: "[")~~ + +create trigger tr5_empty_dq_string on t5_empty_dq_string for insert as +begin +select a, '['+b+']' as b from t5_empty_dq_string where b = "" order by a +end +go +insert t5_empty_dq_string values(1, 'test 1') +go +~~START~~ +int#!#varchar +~~END~~ + +~~ROW COUNT: 1~~ + + +-- usage in insert +insert t6_empty_dq_string values (2, "") +go +~~ROW COUNT: 1~~ + +create procedure p6_empty_dq_string as +insert t6_empty_dq_string values (3, "") +go +exec p6_empty_dq_string +go +~~ROW COUNT: 1~~ + +select a, '['+b+']' as b from t6_empty_dq_string order by a +go +~~START~~ +int#!#varchar +1#!#[test 1] +2#!#[] +3#!#[] +~~END~~ + +create trigger tr6_empty_dq_string on t6_empty_dq_string for insert as +begin +insert t6_empty_dq_string values (4, "") +end +go +insert t6_empty_dq_string values(1, 'test 1') +go +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +select a, '['+b+']' as b from t6_empty_dq_string order by a +go +~~START~~ +int#!#varchar +1#!#[test 1] +1#!#[test 1] +2#!#[] +3#!#[] +4#!#[] +~~END~~ + + +-- usage in update +update t7_empty_dq_string set b = "" where a = 1 +go +~~ROW COUNT: 1~~ + +create procedure p7_empty_dq_string as +update t7_empty_dq_string set b = "" where a = 1 +go +exec p7_empty_dq_string +go +~~ROW COUNT: 1~~ + +select a, '['+b+']' as b from t7_empty_dq_string order by a +go +~~START~~ +int#!#varchar +1#!#[] +~~END~~ + +create trigger tr7_empty_dq_string on t7_empty_dq_string for insert as +begin +update t7_empty_dq_string set b = "" where a = 1 +end +go +insert t7_empty_dq_string values(2, 'test 2') +go +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +select a, '['+b+']' as b from t7_empty_dq_string order by a +go +~~START~~ +int#!#varchar +1#!#[] +2#!#[test 2] +~~END~~ + + +-- single-space string in update: not affected +create procedure p7a_empty_dq_string as +update t7_empty_dq_string set b = " " where a = 1 +go +exec p7a_empty_dq_string +go +~~ROW COUNT: 1~~ + +select a, '['+b+']' as b from t7_empty_dq_string order by a +go +~~START~~ +int#!#varchar +1#!#[ ] +2#!#[test 2] +~~END~~ + +create trigger tr7a_empty_dq_string on t7_empty_dq_string for insert as +begin +update t7_empty_dq_string set b = " " where a = 1 +end +go +insert t7_empty_dq_string values(3, 'test 3') +go +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +select a, '['+b+']' as b from t7_empty_dq_string order by a +go +~~START~~ +int#!#varchar +1#!#[ ] +2#!#[test 2] +3#!#[test 3] +~~END~~ + + + +-- single-space string: argument for procedure/function call +create procedure p7b_empty_dq_string @p varchar(10) +as +select '['+@p+']' as p, len(@p) as len +go +exec p7b_empty_dq_string " " +go +~~START~~ +varchar#!#int +[ ]#!#0 +~~END~~ + +exec p7b_empty_dq_string @p=" " +go +~~START~~ +varchar#!#int +[ ]#!#0 +~~END~~ + +create function f7b_empty_dq_string(@p varchar(10)) returns varchar(10) +as +begin +return '['+@p+']' +end +go +select dbo.f7b_empty_dq_string(" "), len(dbo.f7b_empty_dq_string(" ")) +go +~~START~~ +varchar#!#int +[ ]#!#3 +~~END~~ + + +create procedure p7c_empty_dq_string @p varchar(10) +as +exec p7b_empty_dq_string " " +exec p7b_empty_dq_string @p=" " +select dbo.f7b_empty_dq_string(" "), len(dbo.f7b_empty_dq_string(" ")) +go +exec p7c_empty_dq_string " " +go +~~START~~ +varchar#!#int +[ ]#!#0 +~~END~~ + +~~START~~ +varchar#!#int +[ ]#!#0 +~~END~~ + +~~START~~ +varchar#!#int +[ ]#!#3 +~~END~~ + + +-- double-quoted identifier: not affected +set quoted_identifier on +go + +-- SELECT "" +select * from "t8_empty_dq_string" order by "a" +go +~~START~~ +int#!#varchar +1#!#test 1 +~~END~~ + +create procedure "p8_empty_dq_string" +as +select * from "t8_empty_dq_string" order by "a" +go +exec "p8_empty_dq_string" +go +~~START~~ +int#!#varchar +1#!#test 1 +~~END~~ + +create function "f8_empty_dq_string"() returns varchar(10) +as +begin +return '' +end +go +select dbo."f8_empty_dq_string"(), len(dbo."f8_empty_dq_string"()) +go +~~START~~ +varchar#!#int +#!#0 +~~END~~ + +create trigger "tr8_empty_dq_string" on "t8_empty_dq_string" for insert as +begin +select * from "t8_empty_dq_string" order by "a" +end +go +insert "t8_empty_dq_string" values(2, 'test 2') +go +~~START~~ +int#!#varchar +1#!#test 1 +2#!#test 2 +~~END~~ + +~~ROW COUNT: 1~~ + +select * from "t8_empty_dq_string" order by "a" +go +~~START~~ +int#!#varchar +1#!#test 1 +2#!#test 2 +~~END~~ + + +-- double-quoted identifier of length 0: invalid in T-SQL, should raise error +create table "" (a int) +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: zero-length delimited identifier at or near """")~~ + +select * from "" +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: zero-length delimited identifier at or near """")~~ + +-- execute immediate +execute("") +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: syntax error near '""' at line 2 and character position 8)~~ + + +set quoted_identifier off +go diff --git a/test/JDBC/expected/exec_sp_in_udf-vu-cleanup.out b/test/JDBC/expected/exec_sp_in_udf-vu-cleanup.out new file mode 100644 index 0000000000..b6e8f98c3e --- /dev/null +++ b/test/JDBC/expected/exec_sp_in_udf-vu-cleanup.out @@ -0,0 +1,42 @@ +use master +go +drop table t1_exec_sp_in_udf +go +drop table t2_exec_sp_in_udf +go +drop procedure sp_myproc +go +drop procedure p1_exec_sp_in_udf +go +drop function f1_exec_sp_in_udf +go +drop function f2_exec_sp_in_udf +go +drop function f3_exec_sp_in_udf +go +drop function f4_exec_sp_in_udf +go +drop function f5_exec_sp_in_udf +go +drop function f6_exec_sp_in_udf +go +drop function f6a_exec_sp_in_udf +go +drop function f7_exec_sp_in_udf +go +drop function f8_exec_sp_in_udf +go +drop function f9_exec_sp_in_udf +go +drop function f_scalar_exec_sp_in_udf +go +drop function f_tvf_exec_sp_in_udf +go +drop function f_itvf_exec_sp_in_udf +go +use tempdb +go +drop procedure p_tempdb_exec_sp_in_udf +go +use master +go diff --git a/test/JDBC/expected/exec_sp_in_udf-vu-prepare.out b/test/JDBC/expected/exec_sp_in_udf-vu-prepare.out new file mode 100644 index 0000000000..bf1389e33e --- /dev/null +++ b/test/JDBC/expected/exec_sp_in_udf-vu-prepare.out @@ -0,0 +1,32 @@ +use master +go +create table t1_exec_sp_in_udf (a int) +go +create procedure sp_myproc as return 0 +go +create function f_scalar_exec_sp_in_udf(@p int) +returns int as +begin +return @p +end +go + +create function f_tvf_exec_sp_in_udf() +returns @tv table (a int) +begin + insert @tv values(123) + return +end +go + +create function f_itvf_exec_sp_in_udf() +returns table + return (select 123 as a) +go + +use tempdb +go +create procedure p_tempdb_exec_sp_in_udf as return 0 +go +use master +go diff --git a/test/JDBC/expected/exec_sp_in_udf-vu-verify.out b/test/JDBC/expected/exec_sp_in_udf-vu-verify.out new file mode 100644 index 0000000000..e374fa13f4 --- /dev/null +++ b/test/JDBC/expected/exec_sp_in_udf-vu-verify.out @@ -0,0 +1,284 @@ +use master +go + +create function f1_exec_sp_in_udf() +returns int as +begin +exec sp_executesql 'select 123' +return 0 +end +go +select dbo.f1_exec_sp_in_udf() +go +~~START~~ +int +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Only functions can be executed within a function)~~ + +declare @v int = dbo.f1_exec_sp_in_udf() +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Only functions can be executed within a function)~~ + +declare @v int +select @v = dbo.f1_exec_sp_in_udf() +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Only functions can be executed within a function)~~ + +declare @v int +set @v = dbo.f1_exec_sp_in_udf() +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Only functions can be executed within a function)~~ + +select * from t1_exec_sp_in_udf where a = dbo.f1_exec_sp_in_udf() +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Only functions can be executed within a function)~~ + +insert t1_exec_sp_in_udf values(dbo.f1_exec_sp_in_udf()) +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Only functions can be executed within a function)~~ + +delete t1_exec_sp_in_udf where a = dbo.f1_exec_sp_in_udf() +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Only functions can be executed within a function)~~ + +declare @v int +set @v = (select dbo.f1_exec_sp_in_udf()) +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Only functions can be executed within a function)~~ + +select sqrt(dbo.f1_exec_sp_in_udf()) +go +~~START~~ +float +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Only functions can be executed within a function)~~ + +create table t2_exec_sp_in_udf(a int, b int default dbo.f1_exec_sp_in_udf()) +go +insert t2_exec_sp_in_udf(a) values(1) +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Only functions can be executed within a function)~~ + + +create function f2_exec_sp_in_udf() +returns int as +begin +exec dbo.sp_helpdb +return 0 +end +go +select dbo.f2_exec_sp_in_udf() +go +~~START~~ +int +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Only functions can be executed within a function)~~ + + +create function f3_exec_sp_in_udf() +returns int as +begin +exec [sp_helpdb] +return 0 +end +go +select dbo.f3_exec_sp_in_udf() +go +~~START~~ +int +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Only functions can be executed within a function)~~ + + +create function f4_exec_sp_in_udf() +returns @tv table(a int) as +begin +exec sp_myproc +return +end +go +select * from dbo.f4_exec_sp_in_udf() +go +~~START~~ +int +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Only functions can be executed within a function)~~ + + +create function f5_exec_sp_in_udf() +returns @tv table(a int) as +begin +exec dbo.[sp_myproc] +return +end +go +select * from dbo.f5_exec_sp_in_udf() +go +~~START~~ +int +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Only functions can be executed within a function)~~ + + +create function f6_exec_sp_in_udf() +returns @tv table(a int) as +begin +exec tempdb..p_tempdb_exec_sp_in_udf +return +end +go +select * from dbo.f6_exec_sp_in_udf() +go +~~START~~ +int +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Only functions can be executed within a function)~~ + + +-- do not allow calling with EXEC +create function f6a_exec_sp_in_udf(@p int) +returns int as +begin +declare @v int +exec @v = f1_exec_sp_in_udf +return @v +end +go +select dbo.f6a_exec_sp_in_udf(123) +go +~~START~~ +int +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Only functions can be executed within a function)~~ + + +-- multi-statement TVF cannot be called with EXEC +exec dbo.f_tvf_exec_sp_in_udf +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: master_dbo.f_tvf_exec_sp_in_udf() is not a procedure)~~ + +create function f7_exec_sp_in_udf() +returns int +begin +exec dbo.f_tvf_exec_sp_in_udf +return +end +go +select * from dbo.f7_exec_sp_in_udf() +go +~~START~~ +int +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: master_dbo.f_tvf_exec_sp_in_udf() is not a procedure)~~ + + +-- inline TVF should not be callable with EXEC, but Babelfish currently allows this +-- when this gets fixed so that an error is raised, the result of this test will change +exec dbo.f_itvf_exec_sp_in_udf +go +create function f8_exec_sp_in_udf() +returns int +begin +exec dbo.f_itvf_exec_sp_in_udf +return +end +go +select * from dbo.f8_exec_sp_in_udf() +go +~~START~~ +int + +~~END~~ + + + +-- procedure and trigger are not affected: +create trigger tr1 on t1_exec_sp_in_udf for insert as +begin + exec sp_executesql 'select 123 as in_trigger' +end +go +insert t1_exec_sp_in_udf values(456) +go +~~START~~ +int +123 +~~END~~ + +~~ROW COUNT: 1~~ + +select * from t1_exec_sp_in_udf +go +~~START~~ +int +456 +~~END~~ + + +create procedure p1_exec_sp_in_udf +as +begin + exec sp_executesql 'select 123 as in_procedure' +end +go +exec p1_exec_sp_in_udf +go +~~START~~ +int +123 +~~END~~ + + +-- scalar UDF can still be called with EXEC +declare @v int +exec @v = f_scalar_exec_sp_in_udf 123 +select @v as f_scalar_exec_sp_in_udf +go +~~START~~ +int +123 +~~END~~ + + +create function f9_exec_sp_in_udf(@p int) +returns int as +begin +declare @v int +exec @v = f_scalar_exec_sp_in_udf @p +return @v +end +go +select dbo.f9_exec_sp_in_udf(123) +go +~~START~~ +int +123 +~~END~~ + diff --git a/test/JDBC/expected/left-before-15_8-or-16_4-vu-verify.out b/test/JDBC/expected/left-before-15_8-or-16_4-vu-verify.out index d8b4baed87..ed7d89548e 100644 --- a/test/JDBC/expected/left-before-15_8-or-16_4-vu-verify.out +++ b/test/JDBC/expected/left-before-15_8-or-16_4-vu-verify.out @@ -688,6 +688,8 @@ abc🙂d DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT LEFT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of left function.)~~ @@ -696,6 +698,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT LEFT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of left function.)~~ @@ -704,6 +708,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT LEFT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of left function.)~~ @@ -712,6 +718,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT LEFT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of left function.)~~ diff --git a/test/JDBC/expected/left-vu-verify.out b/test/JDBC/expected/left-vu-verify.out index 78832711ba..0a77159b6d 100644 --- a/test/JDBC/expected/left-vu-verify.out +++ b/test/JDBC/expected/left-vu-verify.out @@ -688,6 +688,8 @@ abc🙂d DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT LEFT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of left function.)~~ @@ -696,6 +698,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT LEFT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of left function.)~~ @@ -704,6 +708,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT LEFT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of left function.)~~ @@ -712,6 +718,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT LEFT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of left function.)~~ diff --git a/test/JDBC/expected/ltrim-before-15_8-or-16_4-vu-verify.out b/test/JDBC/expected/ltrim-before-15_8-or-16_4-vu-verify.out index b8b9ce4fca..76e7f84ef1 100644 --- a/test/JDBC/expected/ltrim-before-15_8-or-16_4-vu-verify.out +++ b/test/JDBC/expected/ltrim-before-15_8-or-16_4-vu-verify.out @@ -553,6 +553,8 @@ abc🙂defghi🙂🙂 DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT LTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of ltrim function.)~~ @@ -561,6 +563,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT LTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of ltrim function.)~~ @@ -569,6 +573,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT LTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of ltrim function.)~~ @@ -577,6 +583,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT LTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of ltrim function.)~~ diff --git a/test/JDBC/expected/ltrim-vu-verify.out b/test/JDBC/expected/ltrim-vu-verify.out index de546af507..cb65a74a9a 100644 --- a/test/JDBC/expected/ltrim-vu-verify.out +++ b/test/JDBC/expected/ltrim-vu-verify.out @@ -553,6 +553,8 @@ abc🙂defghi🙂🙂 DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT LTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of ltrim function.)~~ @@ -561,6 +563,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT LTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of ltrim function.)~~ @@ -569,6 +573,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT LTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of ltrim function.)~~ @@ -577,6 +583,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT LTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of ltrim function.)~~ diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/left-before-15_8-or-16_4-vu-verify.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/left-before-15_8-or-16_4-vu-verify.out index 028fff54cf..875692b55e 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/left-before-15_8-or-16_4-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/left-before-15_8-or-16_4-vu-verify.out @@ -688,6 +688,8 @@ abc🙂d DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT LEFT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of left function.)~~ @@ -696,6 +698,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT LEFT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of left function.)~~ @@ -704,6 +708,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT LEFT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of left function.)~~ @@ -712,6 +718,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT LEFT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of left function.)~~ diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/left-vu-verify.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/left-vu-verify.out index 0f941df9bc..a716f235db 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/left-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/left-vu-verify.out @@ -688,6 +688,8 @@ abc🙂d DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT LEFT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of left function.)~~ @@ -696,6 +698,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT LEFT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of left function.)~~ @@ -704,6 +708,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT LEFT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of left function.)~~ @@ -712,6 +718,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT LEFT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of left function.)~~ diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/ltrim-before-15_8-or-16_4-vu-verify.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/ltrim-before-15_8-or-16_4-vu-verify.out index d5c3d503c6..000837942e 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/ltrim-before-15_8-or-16_4-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/ltrim-before-15_8-or-16_4-vu-verify.out @@ -553,6 +553,8 @@ abc🙂defghi🙂🙂 DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT LTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of ltrim function.)~~ @@ -561,6 +563,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT LTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of ltrim function.)~~ @@ -569,6 +573,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT LTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of ltrim function.)~~ @@ -577,6 +583,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT LTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of ltrim function.)~~ diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/ltrim-vu-verify.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/ltrim-vu-verify.out index 88ad03f724..bc22eeff75 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/ltrim-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/ltrim-vu-verify.out @@ -553,6 +553,8 @@ abc🙂defghi🙂🙂 DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT LTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of ltrim function.)~~ @@ -561,6 +563,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT LTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of ltrim function.)~~ @@ -569,6 +573,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT LTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of ltrim function.)~~ @@ -577,6 +583,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT LTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of ltrim function.)~~ diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/replicate-before-15_8-or-16_4-vu-verify.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/replicate-before-15_8-or-16_4-vu-verify.out index 288621ee44..4f2c84729e 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/replicate-before-15_8-or-16_4-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/replicate-before-15_8-or-16_4-vu-verify.out @@ -601,6 +601,8 @@ abc🙂defghi🙂🙂abc🙂defghi🙂🙂abc🙂defghi🙂🙂abc🙂defghi🙂 DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT replicate(@inputString, 4) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of replicate function.)~~ @@ -609,6 +611,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT replicate(@inputString, 4) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of replicate function.)~~ @@ -617,6 +621,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT replicate(@inputString, 4) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of replicate function.)~~ @@ -625,6 +631,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT replicate(@inputString, 4) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of replicate function.)~~ diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/replicate-vu-verify.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/replicate-vu-verify.out index 867377f6cc..487678d933 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/replicate-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/replicate-vu-verify.out @@ -601,6 +601,8 @@ abc🙂defghi🙂🙂abc🙂defghi🙂🙂abc🙂defghi🙂🙂abc🙂defghi🙂 DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT replicate(@inputString, 4) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of replicate function.)~~ @@ -609,6 +611,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT replicate(@inputString, 4) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of replicate function.)~~ @@ -617,6 +621,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT replicate(@inputString, 4) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of replicate function.)~~ @@ -625,6 +631,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT replicate(@inputString, 4) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of replicate function.)~~ diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/reverse-before-15_8-or-16_4-vu-verify.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/reverse-before-15_8-or-16_4-vu-verify.out index a71a9d0565..b9efb57a7f 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/reverse-before-15_8-or-16_4-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/reverse-before-15_8-or-16_4-vu-verify.out @@ -545,6 +545,8 @@ nvarchar DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT reverse(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of reverse function.)~~ @@ -553,6 +555,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT reverse(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of reverse function.)~~ @@ -561,6 +565,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT reverse(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of reverse function.)~~ @@ -569,6 +575,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT reverse(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of reverse function.)~~ diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/reverse-vu-verify.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/reverse-vu-verify.out index 99256865d9..9af4688ccc 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/reverse-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/reverse-vu-verify.out @@ -545,6 +545,8 @@ nvarchar DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT reverse(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of reverse function.)~~ @@ -553,6 +555,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT reverse(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of reverse function.)~~ @@ -561,6 +565,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT reverse(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of reverse function.)~~ @@ -569,6 +575,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT reverse(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of reverse function.)~~ diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/right-before-15_8-or-16_4-vu-verify.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/right-before-15_8-or-16_4-vu-verify.out index 8d2dd65532..4d458af8e2 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/right-before-15_8-or-16_4-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/right-before-15_8-or-16_4-vu-verify.out @@ -659,6 +659,8 @@ ghi🙂🙂 DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT RIGHT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of right function.)~~ @@ -667,6 +669,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT RIGHT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of right function.)~~ @@ -675,6 +679,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT RIGHT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of right function.)~~ @@ -683,6 +689,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT RIGHT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of right function.)~~ diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/right-vu-verify.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/right-vu-verify.out index d5da998072..7ad571e90d 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/right-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/right-vu-verify.out @@ -659,6 +659,8 @@ ghi🙂🙂 DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT RIGHT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of right function.)~~ @@ -667,6 +669,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT RIGHT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of right function.)~~ @@ -675,6 +679,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT RIGHT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of right function.)~~ @@ -683,6 +689,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT RIGHT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of right function.)~~ diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/rtrim-before-15_8-or-16_4-vu-verify.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/rtrim-before-15_8-or-16_4-vu-verify.out index 49fdb73cc2..9d21019d38 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/rtrim-before-15_8-or-16_4-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/rtrim-before-15_8-or-16_4-vu-verify.out @@ -553,6 +553,8 @@ nvarchar DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT RTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of rtrim function.)~~ @@ -561,6 +563,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT RTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of rtrim function.)~~ @@ -569,6 +573,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT RTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of rtrim function.)~~ @@ -577,6 +583,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT RTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of rtrim function.)~~ diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/rtrim-vu-verify.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/rtrim-vu-verify.out index f45246480d..afcfd3a7ed 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/rtrim-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/rtrim-vu-verify.out @@ -553,6 +553,8 @@ nvarchar DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT RTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of rtrim function.)~~ @@ -561,6 +563,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT RTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of rtrim function.)~~ @@ -569,6 +573,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT RTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of rtrim function.)~~ @@ -577,6 +583,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT RTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of rtrim function.)~~ diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/substring-before-15_8-or-16_4-vu-verify.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/substring-before-15_8-or-16_4-vu-verify.out index df00300dd8..9d96df3e06 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/substring-before-15_8-or-16_4-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/substring-before-15_8-or-16_4-vu-verify.out @@ -251,6 +251,8 @@ varchar ~~END~~ +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -278,6 +280,8 @@ varchar ~~END~~ +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -305,6 +309,8 @@ varchar ~~END~~ +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -333,6 +339,8 @@ varchar ~~END~~ +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -360,6 +368,8 @@ varchar ~~END~~ +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -387,6 +397,8 @@ varchar ~~END~~ +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -517,6 +529,8 @@ nvarchar ~~END~~ +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -544,6 +558,8 @@ nvarchar ~~END~~ +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -582,6 +598,8 @@ nvarchar ~~END~~ +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -609,6 +627,8 @@ nvarchar ~~END~~ +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -637,6 +657,8 @@ varbinary ~~END~~ +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -665,6 +687,8 @@ varbinary ~~END~~ +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -798,6 +822,8 @@ de DECLARE @inputString date = '2016-12-21'; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type date is invalid for argument 1 of substring function.)~~ @@ -807,6 +833,8 @@ DECLARE @date date = '12-21-16'; DECLARE @inputString datetime = @date; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type datetime is invalid for argument 1 of substring function.)~~ @@ -815,6 +843,8 @@ GO DECLARE @inputString smalldatetime = '1955-12-13 12:43:10'; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type smalldatetime is invalid for argument 1 of substring function.)~~ @@ -823,6 +853,8 @@ GO DECLARE @inputString time(4) = '12:10:05.1237'; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type time is invalid for argument 1 of substring function.)~~ @@ -831,6 +863,8 @@ GO DECLARE @inputString datetimeoffset(4) = '1968-10-23 12:45:37.1234 +10:0'; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type datetimeoffset is invalid for argument 1 of substring function.)~~ @@ -839,6 +873,8 @@ GO DECLARE @inputString datetime2(4) = '1968-10-23 12:45:37.1237'; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type datetime2 is invalid for argument 1 of substring function.)~~ @@ -847,6 +883,8 @@ GO DECLARE @inputString decimal = 123456; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type decimal is invalid for argument 1 of substring function.)~~ @@ -855,6 +893,8 @@ GO DECLARE @inputString numeric = 12345.12; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type numeric is invalid for argument 1 of substring function.)~~ @@ -863,6 +903,8 @@ GO DECLARE @inputString float = 12345.1; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type float is invalid for argument 1 of substring function.)~~ @@ -871,6 +913,8 @@ GO DECLARE @inputString real = 12345.1; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type real is invalid for argument 1 of substring function.)~~ @@ -879,6 +923,8 @@ GO DECLARE @inputString bigint = 12345678; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type bigint is invalid for argument 1 of substring function.)~~ @@ -887,6 +933,8 @@ GO DECLARE @inputString int = 12345678; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type int is invalid for argument 1 of substring function.)~~ @@ -895,6 +943,8 @@ GO DECLARE @inputString smallint = 12356; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type smallint is invalid for argument 1 of substring function.)~~ @@ -903,6 +953,8 @@ GO DECLARE @inputString tinyint = 235; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type tinyint is invalid for argument 1 of substring function.)~~ @@ -911,6 +963,8 @@ GO DECLARE @inputString money = 12356; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type money is invalid for argument 1 of substring function.)~~ @@ -919,6 +973,8 @@ GO DECLARE @inputString smallmoney = 12356; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type smallmoney is invalid for argument 1 of substring function.)~~ @@ -927,6 +983,8 @@ GO DECLARE @inputString bit = 1; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type bit is invalid for argument 1 of substring function.)~~ @@ -935,6 +993,8 @@ GO DECLARE @inputString uniqueidentifier = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS uniqueidentifier) SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type uniqueidentifier is invalid for argument 1 of substring function.)~~ @@ -1056,6 +1116,8 @@ bc🙂defghi🙂🙂 DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of substring function.)~~ @@ -1064,6 +1126,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of substring function.)~~ @@ -1072,6 +1136,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of substring function.)~~ @@ -1080,6 +1146,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of substring function.)~~ diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/substring-vu-verify.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/substring-vu-verify.out index b3a2766835..c331ce56ea 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/substring-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/substring-vu-verify.out @@ -256,6 +256,8 @@ varchar DECLARE @inputString CHAR(25) = 'abc🙂defghi🙂🙂' SELECT substring(@inputString, 2, -1) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -296,6 +298,8 @@ varchar DECLARE @inputString CHAR(25) = '比尔·拉莫斯' SELECT substring(@inputString, 2, -1) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -336,6 +340,8 @@ varchar DECLARE @inputString CHAR(25) = '比尔·拉莫斯' SELECT substring(@inputString, 2, -1) COLLATE CHINESE_PRC_CI_AS GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -377,6 +383,8 @@ varchar DECLARE @inputString VARCHAR(25) = 'abc🙂defghi🙂🙂' SELECT substring(@inputString, 2, -1) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -417,6 +425,8 @@ varchar DECLARE @inputString VARCHAR(25) = '比尔·拉莫斯' SELECT substring(@inputString, 2, -1) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -457,6 +467,8 @@ varchar DECLARE @inputString VARCHAR(25) = '比尔·拉莫斯' SELECT substring(@inputString, 2, -1) COLLATE CHINESE_PRC_CI_AS GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -600,6 +612,8 @@ nvarchar DECLARE @inputString NCHAR(25) = N'abc🙂defghi🙂🙂' SELECT substring(@inputString, 2, -1) GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -640,6 +654,8 @@ nvarchar DECLARE @inputString NCHAR(25) = N'比尔·拉莫斯' SELECT substring(@inputString, 2, -1) GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -691,6 +707,8 @@ nvarchar DECLARE @inputString NVARCHAR(25) = N'abc🙂defghi🙂🙂' SELECT substring(@inputString, 2, -1) GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -731,6 +749,8 @@ nvarchar DECLARE @inputString NVARCHAR(25) = N'比尔·拉莫斯' SELECT substring(@inputString, 2, -1) GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -772,6 +792,8 @@ varbinary DECLARE @inputString BINARY(10) = 0x6162636465666768 SELECT substring(@inputString, 2, -1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -813,6 +835,8 @@ varbinary DECLARE @inputString VARBINARY(10) = 0x6162636465666768 SELECT substring(@inputString, 2, -1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -954,6 +978,8 @@ de DECLARE @inputString date = '2016-12-21'; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type date is invalid for argument 1 of substring function.)~~ @@ -963,6 +989,8 @@ DECLARE @date date = '12-21-16'; DECLARE @inputString datetime = @date; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type datetime is invalid for argument 1 of substring function.)~~ @@ -971,6 +999,8 @@ GO DECLARE @inputString smalldatetime = '1955-12-13 12:43:10'; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type smalldatetime is invalid for argument 1 of substring function.)~~ @@ -979,6 +1009,8 @@ GO DECLARE @inputString time(4) = '12:10:05.1237'; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type time is invalid for argument 1 of substring function.)~~ @@ -987,6 +1019,8 @@ GO DECLARE @inputString datetimeoffset(4) = '1968-10-23 12:45:37.1234 +10:0'; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type datetimeoffset is invalid for argument 1 of substring function.)~~ @@ -995,6 +1029,8 @@ GO DECLARE @inputString datetime2(4) = '1968-10-23 12:45:37.1237'; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type datetime2 is invalid for argument 1 of substring function.)~~ @@ -1003,6 +1039,8 @@ GO DECLARE @inputString decimal = 123456; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type decimal is invalid for argument 1 of substring function.)~~ @@ -1011,6 +1049,8 @@ GO DECLARE @inputString numeric = 12345.12; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type numeric is invalid for argument 1 of substring function.)~~ @@ -1019,6 +1059,8 @@ GO DECLARE @inputString float = 12345.1; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type float is invalid for argument 1 of substring function.)~~ @@ -1027,6 +1069,8 @@ GO DECLARE @inputString real = 12345.1; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type real is invalid for argument 1 of substring function.)~~ @@ -1035,6 +1079,8 @@ GO DECLARE @inputString bigint = 12345678; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type bigint is invalid for argument 1 of substring function.)~~ @@ -1043,6 +1089,8 @@ GO DECLARE @inputString int = 12345678; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type int is invalid for argument 1 of substring function.)~~ @@ -1051,6 +1099,8 @@ GO DECLARE @inputString smallint = 12356; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type smallint is invalid for argument 1 of substring function.)~~ @@ -1059,6 +1109,8 @@ GO DECLARE @inputString tinyint = 235; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type tinyint is invalid for argument 1 of substring function.)~~ @@ -1067,6 +1119,8 @@ GO DECLARE @inputString money = 12356; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type money is invalid for argument 1 of substring function.)~~ @@ -1075,6 +1129,8 @@ GO DECLARE @inputString smallmoney = 12356; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type smallmoney is invalid for argument 1 of substring function.)~~ @@ -1083,6 +1139,8 @@ GO DECLARE @inputString bit = 1; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type bit is invalid for argument 1 of substring function.)~~ @@ -1091,6 +1149,8 @@ GO DECLARE @inputString uniqueidentifier = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS uniqueidentifier) SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type uniqueidentifier is invalid for argument 1 of substring function.)~~ @@ -1212,6 +1272,8 @@ bc🙂defghi🙂🙂 DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of substring function.)~~ @@ -1220,6 +1282,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of substring function.)~~ @@ -1228,6 +1292,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of substring function.)~~ @@ -1236,6 +1302,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of substring function.)~~ diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/translate-before-15_8-or-16_4-vu-verify.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/translate-before-15_8-or-16_4-vu-verify.out index 40b420686e..f2f7c18cfd 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/translate-before-15_8-or-16_4-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/translate-before-15_8-or-16_4-vu-verify.out @@ -654,6 +654,8 @@ varchar DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters VARCHAR(20) = 'ab?', @translations VARCHAR(40) = 'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -694,6 +696,8 @@ GO DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -702,6 +706,8 @@ GO DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -751,6 +757,8 @@ varchar DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NVARCHAR(20) = N'ab?', @translations NVARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -791,6 +799,8 @@ GO DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = N'ab?', @translations CHAR(40) = N'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -799,6 +809,8 @@ GO DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = N'ab?', @translations CHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1013,6 +1025,8 @@ GO DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1021,6 +1035,8 @@ GO DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1061,6 +1077,8 @@ GO DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1069,6 +1087,8 @@ GO DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1118,6 +1138,8 @@ varchar DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NVARCHAR(20) = N'ab?', @translations NVARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1167,6 +1189,8 @@ varchar DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters VARCHAR(20) = N'ab?', @translations VARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1372,6 +1396,8 @@ GO DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1380,6 +1406,8 @@ GO DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1420,6 +1448,8 @@ GO DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1428,6 +1458,8 @@ GO DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1477,6 +1509,8 @@ nvarchar DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NVARCHAR(20) = N'ab?', @translations NVARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1526,6 +1560,8 @@ nvarchar DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters VARCHAR(20) = N'ab?', @translations VARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1731,6 +1767,8 @@ GO DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1739,6 +1777,8 @@ GO DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1779,6 +1819,8 @@ GO DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1787,6 +1829,8 @@ GO DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1836,6 +1880,8 @@ nvarchar DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NVARCHAR(20) = N'ab?', @translations NVARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1885,6 +1931,8 @@ nvarchar DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters VARCHAR(20) = N'ab?', @translations VARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/translate-vu-verify.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/translate-vu-verify.out index ef9bbc5a4e..a42c42b04f 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/translate-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/translate-vu-verify.out @@ -654,6 +654,8 @@ varchar DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters VARCHAR(20) = 'ab?', @translations VARCHAR(40) = 'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -694,6 +696,8 @@ GO DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -702,6 +706,8 @@ GO DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -751,6 +757,8 @@ varchar DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NVARCHAR(20) = N'ab?', @translations NVARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -791,6 +799,8 @@ GO DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = N'ab?', @translations CHAR(40) = N'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -799,6 +809,8 @@ GO DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = N'ab?', @translations CHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1013,6 +1025,8 @@ GO DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1021,6 +1035,8 @@ GO DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1061,6 +1077,8 @@ GO DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1069,6 +1087,8 @@ GO DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1118,6 +1138,8 @@ varchar DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NVARCHAR(20) = N'ab?', @translations NVARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1167,6 +1189,8 @@ varchar DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters VARCHAR(20) = N'ab?', @translations VARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1372,6 +1396,8 @@ GO DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1380,6 +1406,8 @@ GO DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1420,6 +1448,8 @@ GO DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1428,6 +1458,8 @@ GO DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1477,6 +1509,8 @@ nvarchar DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NVARCHAR(20) = N'ab?', @translations NVARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1526,6 +1560,8 @@ nvarchar DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters VARCHAR(20) = N'ab?', @translations VARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1731,6 +1767,8 @@ GO DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1739,6 +1777,8 @@ GO DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1779,6 +1819,8 @@ GO DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1787,6 +1829,8 @@ GO DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1836,6 +1880,8 @@ nvarchar DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NVARCHAR(20) = N'ab?', @translations NVARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1885,6 +1931,8 @@ nvarchar DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters VARCHAR(20) = N'ab?', @translations VARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/upper_lower-before-15_8-or-16_4-vu-verify.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/upper_lower-before-15_8-or-16_4-vu-verify.out index 82b27a0d8a..ab9b200b54 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/upper_lower-before-15_8-or-16_4-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/upper_lower-before-15_8-or-16_4-vu-verify.out @@ -530,6 +530,8 @@ DECLARE @myid sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_ SELECT UPPER(@myid) SELECT LOWER(@myid) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of upper function.)~~ @@ -539,6 +541,8 @@ DECLARE @myid xml = CAST ('' AS xml) SELECT UPPER(@myid) SELECT LOWER(@myid) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of upper function.)~~ @@ -548,6 +552,8 @@ DECLARE @myid geometry = geometry::STGeomFromText('POINT (1 2)', 0) SELECT UPPER(@myid) SELECT LOWER(@myid) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of upper function.)~~ @@ -815,6 +821,8 @@ adjnfjh declare @b dbo.MyUDT = CAST('scsdc' AS dbo.MyUDT) select upper(@b) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type image is invalid for argument 1 of upper function.)~~ diff --git a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/upper_lower-vu-verify.out b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/upper_lower-vu-verify.out index 35d13a4633..4d192c75f8 100644 --- a/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/upper_lower-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/chinese_prc_ci_as/upper_lower-vu-verify.out @@ -530,6 +530,8 @@ DECLARE @myid sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_ SELECT UPPER(@myid) SELECT LOWER(@myid) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of upper function.)~~ @@ -539,6 +541,8 @@ DECLARE @myid xml = CAST ('' AS xml) SELECT UPPER(@myid) SELECT LOWER(@myid) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of upper function.)~~ @@ -548,6 +552,8 @@ DECLARE @myid geometry = geometry::STGeomFromText('POINT (1 2)', 0) SELECT UPPER(@myid) SELECT LOWER(@myid) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of upper function.)~~ @@ -839,6 +845,8 @@ adjnfjh declare @b dbo.MyUDT = CAST('scsdc' AS dbo.MyUDT) select upper(@b) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type image is invalid for argument 1 of upper function.)~~ diff --git a/test/JDBC/expected/non_default_server_collation/japanese_ci_as/left-vu-verify.out b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/left-vu-verify.out index 08eacfbc41..42569cab00 100644 --- a/test/JDBC/expected/non_default_server_collation/japanese_ci_as/left-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/left-vu-verify.out @@ -688,6 +688,8 @@ abc🙂d DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT LEFT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of left function.)~~ @@ -696,6 +698,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT LEFT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of left function.)~~ @@ -704,6 +708,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT LEFT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of left function.)~~ @@ -712,6 +718,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT LEFT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of left function.)~~ diff --git a/test/JDBC/expected/non_default_server_collation/japanese_ci_as/ltrim-vu-verify.out b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/ltrim-vu-verify.out index 9d48cccb44..b9e14a0deb 100644 --- a/test/JDBC/expected/non_default_server_collation/japanese_ci_as/ltrim-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/ltrim-vu-verify.out @@ -553,6 +553,8 @@ abc🙂defghi🙂🙂 DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT LTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of ltrim function.)~~ @@ -561,6 +563,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT LTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of ltrim function.)~~ @@ -569,6 +573,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT LTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of ltrim function.)~~ @@ -577,6 +583,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT LTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of ltrim function.)~~ diff --git a/test/JDBC/expected/non_default_server_collation/japanese_ci_as/replicate-vu-verify.out b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/replicate-vu-verify.out index 6b996b7965..c6827d00c2 100644 --- a/test/JDBC/expected/non_default_server_collation/japanese_ci_as/replicate-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/replicate-vu-verify.out @@ -601,6 +601,8 @@ abc🙂defghi🙂🙂abc🙂defghi🙂🙂abc🙂defghi🙂🙂abc🙂defghi🙂 DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT replicate(@inputString, 4) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of replicate function.)~~ @@ -609,6 +611,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT replicate(@inputString, 4) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of replicate function.)~~ @@ -617,6 +621,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT replicate(@inputString, 4) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of replicate function.)~~ @@ -625,6 +631,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT replicate(@inputString, 4) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of replicate function.)~~ diff --git a/test/JDBC/expected/non_default_server_collation/japanese_ci_as/reverse-vu-verify.out b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/reverse-vu-verify.out index 855705d732..1e079cd2c3 100644 --- a/test/JDBC/expected/non_default_server_collation/japanese_ci_as/reverse-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/reverse-vu-verify.out @@ -545,6 +545,8 @@ nvarchar DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT reverse(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of reverse function.)~~ @@ -553,6 +555,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT reverse(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of reverse function.)~~ @@ -561,6 +565,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT reverse(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of reverse function.)~~ @@ -569,6 +575,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT reverse(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of reverse function.)~~ diff --git a/test/JDBC/expected/non_default_server_collation/japanese_ci_as/right-vu-verify.out b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/right-vu-verify.out index 0d822e07f0..d19a70b993 100644 --- a/test/JDBC/expected/non_default_server_collation/japanese_ci_as/right-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/right-vu-verify.out @@ -659,6 +659,8 @@ ghi🙂🙂 DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT RIGHT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of right function.)~~ @@ -667,6 +669,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT RIGHT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of right function.)~~ @@ -675,6 +679,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT RIGHT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of right function.)~~ @@ -683,6 +689,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT RIGHT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of right function.)~~ diff --git a/test/JDBC/expected/non_default_server_collation/japanese_ci_as/rtrim-vu-verify.out b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/rtrim-vu-verify.out index ca5eeff5d9..b01d4d2078 100644 --- a/test/JDBC/expected/non_default_server_collation/japanese_ci_as/rtrim-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/rtrim-vu-verify.out @@ -553,6 +553,8 @@ nvarchar DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT RTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of rtrim function.)~~ @@ -561,6 +563,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT RTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of rtrim function.)~~ @@ -569,6 +573,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT RTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of rtrim function.)~~ @@ -577,6 +583,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT RTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of rtrim function.)~~ diff --git a/test/JDBC/expected/non_default_server_collation/japanese_ci_as/substring-vu-verify.out b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/substring-vu-verify.out index 63af8f789b..18d66c6b3b 100644 --- a/test/JDBC/expected/non_default_server_collation/japanese_ci_as/substring-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/substring-vu-verify.out @@ -256,6 +256,8 @@ varchar DECLARE @inputString CHAR(25) = 'abc🙂defghi🙂🙂' SELECT substring(@inputString, 2, -1) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -296,6 +298,8 @@ varchar DECLARE @inputString CHAR(25) = '比尔·拉莫斯' SELECT substring(@inputString, 2, -1) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -336,6 +340,8 @@ varchar DECLARE @inputString CHAR(25) = '比尔·拉莫斯' SELECT substring(@inputString, 2, -1) COLLATE CHINESE_PRC_CI_AS GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -377,6 +383,8 @@ varchar DECLARE @inputString VARCHAR(25) = 'abc🙂defghi🙂🙂' SELECT substring(@inputString, 2, -1) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -417,6 +425,8 @@ varchar DECLARE @inputString VARCHAR(25) = '比尔·拉莫斯' SELECT substring(@inputString, 2, -1) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -457,6 +467,8 @@ varchar DECLARE @inputString VARCHAR(25) = '比尔·拉莫斯' SELECT substring(@inputString, 2, -1) COLLATE CHINESE_PRC_CI_AS GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -600,6 +612,8 @@ nvarchar DECLARE @inputString NCHAR(25) = N'abc🙂defghi🙂🙂' SELECT substring(@inputString, 2, -1) GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -640,6 +654,8 @@ nvarchar DECLARE @inputString NCHAR(25) = N'比尔·拉莫斯' SELECT substring(@inputString, 2, -1) GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -691,6 +707,8 @@ nvarchar DECLARE @inputString NVARCHAR(25) = N'abc🙂defghi🙂🙂' SELECT substring(@inputString, 2, -1) GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -731,6 +749,8 @@ nvarchar DECLARE @inputString NVARCHAR(25) = N'比尔·拉莫斯' SELECT substring(@inputString, 2, -1) GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -772,6 +792,8 @@ varbinary DECLARE @inputString BINARY(10) = 0x6162636465666768 SELECT substring(@inputString, 2, -1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -813,6 +835,8 @@ varbinary DECLARE @inputString VARBINARY(10) = 0x6162636465666768 SELECT substring(@inputString, 2, -1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -954,6 +978,8 @@ de DECLARE @inputString date = '2016-12-21'; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type date is invalid for argument 1 of substring function.)~~ @@ -963,6 +989,8 @@ DECLARE @date date = '12-21-16'; DECLARE @inputString datetime = @date; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type datetime is invalid for argument 1 of substring function.)~~ @@ -971,6 +999,8 @@ GO DECLARE @inputString smalldatetime = '1955-12-13 12:43:10'; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type smalldatetime is invalid for argument 1 of substring function.)~~ @@ -979,6 +1009,8 @@ GO DECLARE @inputString time(4) = '12:10:05.1237'; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type time is invalid for argument 1 of substring function.)~~ @@ -987,6 +1019,8 @@ GO DECLARE @inputString datetimeoffset(4) = '1968-10-23 12:45:37.1234 +10:0'; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type datetimeoffset is invalid for argument 1 of substring function.)~~ @@ -995,6 +1029,8 @@ GO DECLARE @inputString datetime2(4) = '1968-10-23 12:45:37.1237'; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type datetime2 is invalid for argument 1 of substring function.)~~ @@ -1003,6 +1039,8 @@ GO DECLARE @inputString decimal = 123456; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type decimal is invalid for argument 1 of substring function.)~~ @@ -1011,6 +1049,8 @@ GO DECLARE @inputString numeric = 12345.12; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type numeric is invalid for argument 1 of substring function.)~~ @@ -1019,6 +1059,8 @@ GO DECLARE @inputString float = 12345.1; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type float is invalid for argument 1 of substring function.)~~ @@ -1027,6 +1069,8 @@ GO DECLARE @inputString real = 12345.1; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type real is invalid for argument 1 of substring function.)~~ @@ -1035,6 +1079,8 @@ GO DECLARE @inputString bigint = 12345678; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type bigint is invalid for argument 1 of substring function.)~~ @@ -1043,6 +1089,8 @@ GO DECLARE @inputString int = 12345678; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type int is invalid for argument 1 of substring function.)~~ @@ -1051,6 +1099,8 @@ GO DECLARE @inputString smallint = 12356; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type smallint is invalid for argument 1 of substring function.)~~ @@ -1059,6 +1109,8 @@ GO DECLARE @inputString tinyint = 235; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type tinyint is invalid for argument 1 of substring function.)~~ @@ -1067,6 +1119,8 @@ GO DECLARE @inputString money = 12356; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type money is invalid for argument 1 of substring function.)~~ @@ -1075,6 +1129,8 @@ GO DECLARE @inputString smallmoney = 12356; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type smallmoney is invalid for argument 1 of substring function.)~~ @@ -1083,6 +1139,8 @@ GO DECLARE @inputString bit = 1; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type bit is invalid for argument 1 of substring function.)~~ @@ -1091,6 +1149,8 @@ GO DECLARE @inputString uniqueidentifier = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS uniqueidentifier) SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type uniqueidentifier is invalid for argument 1 of substring function.)~~ @@ -1212,6 +1272,8 @@ bc🙂defghi🙂🙂 DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of substring function.)~~ @@ -1220,6 +1282,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of substring function.)~~ @@ -1228,6 +1292,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of substring function.)~~ @@ -1236,6 +1302,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of substring function.)~~ diff --git a/test/JDBC/expected/non_default_server_collation/japanese_ci_as/translate-vu-verify.out b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/translate-vu-verify.out index 258cee2c7f..64ba5d69e2 100644 --- a/test/JDBC/expected/non_default_server_collation/japanese_ci_as/translate-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/translate-vu-verify.out @@ -576,6 +576,8 @@ varchar DECLARE @inputString CHAR(50) = ' 比尔·拉莫斯 ', @characters NCHAR(20) = N'比拉斯 ', @translations NCHAR(20) = N'尔·比?' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -653,6 +655,8 @@ varchar DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters VARCHAR(20) = 'ab?', @translations VARCHAR(40) = 'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -693,6 +697,8 @@ GO DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -701,6 +707,8 @@ GO DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -750,6 +758,8 @@ varchar DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NVARCHAR(20) = N'ab?', @translations NVARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -790,6 +800,8 @@ GO DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = N'ab?', @translations CHAR(40) = N'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -798,6 +810,8 @@ GO DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = N'ab?', @translations CHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -907,6 +921,8 @@ varchar DECLARE @inputString VARCHAR(50) = ' 比尔·拉莫斯 ', @characters CHAR(20) = '比拉斯 ', @translations CHAR(20) = '尔·比?' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -942,6 +958,8 @@ varchar DECLARE @inputString VARCHAR(50) = ' 比尔·拉莫斯 ', @characters NCHAR(20) = N'比拉斯 ', @translations NCHAR(20) = N'尔·比?' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1010,6 +1028,8 @@ GO DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1018,6 +1038,8 @@ GO DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1058,6 +1080,8 @@ GO DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1066,6 +1090,8 @@ GO DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1115,6 +1141,8 @@ varchar DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NVARCHAR(20) = N'ab?', @translations NVARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1164,6 +1192,8 @@ varchar DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters VARCHAR(20) = N'ab?', @translations VARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1273,6 +1303,8 @@ nvarchar DECLARE @inputString NCHAR(50) = N' 比尔·拉莫斯 ', @characters CHAR(20) = '比拉斯 ', @translations CHAR(20) = '尔·比?' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1368,6 +1400,8 @@ GO DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1376,6 +1410,8 @@ GO DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1416,6 +1452,8 @@ GO DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1424,6 +1462,8 @@ GO DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1473,6 +1513,8 @@ nvarchar DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NVARCHAR(20) = N'ab?', @translations NVARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1522,6 +1564,8 @@ nvarchar DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters VARCHAR(20) = N'ab?', @translations VARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1631,6 +1675,8 @@ nvarchar DECLARE @inputString NVARCHAR(50) = N' 比尔·拉莫斯 ', @characters CHAR(20) = '比拉斯 ', @translations CHAR(20) = '尔·比?' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1693,6 +1739,8 @@ nvarchar DECLARE @inputString NVARCHAR(50) = N' 比尔·拉莫斯 ', @characters NCHAR(20) = N'比拉斯 ', @translations NCHAR(20) = N'尔·比?' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1725,6 +1773,8 @@ GO DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1733,6 +1783,8 @@ GO DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1773,6 +1825,8 @@ GO DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1781,6 +1835,8 @@ GO DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1830,6 +1886,8 @@ nvarchar DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NVARCHAR(20) = N'ab?', @translations NVARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1879,6 +1937,8 @@ nvarchar DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters VARCHAR(20) = N'ab?', @translations VARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ diff --git a/test/JDBC/expected/non_default_server_collation/japanese_ci_as/upper_lower-vu-verify.out b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/upper_lower-vu-verify.out index 26adc8e18f..2988e433e5 100644 --- a/test/JDBC/expected/non_default_server_collation/japanese_ci_as/upper_lower-vu-verify.out +++ b/test/JDBC/expected/non_default_server_collation/japanese_ci_as/upper_lower-vu-verify.out @@ -530,6 +530,8 @@ DECLARE @myid sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_ SELECT UPPER(@myid) SELECT LOWER(@myid) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of upper function.)~~ @@ -539,6 +541,8 @@ DECLARE @myid xml = CAST ('' AS xml) SELECT UPPER(@myid) SELECT LOWER(@myid) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of upper function.)~~ @@ -548,6 +552,8 @@ DECLARE @myid geometry = geometry::STGeomFromText('POINT (1 2)', 0) SELECT UPPER(@myid) SELECT LOWER(@myid) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of upper function.)~~ @@ -838,6 +844,8 @@ adjnfjh declare @b dbo.MyUDT = CAST('scsdc' AS dbo.MyUDT) select upper(@b) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type image is invalid for argument 1 of upper function.)~~ diff --git a/test/JDBC/expected/parallel_query/BABEL-2844.out b/test/JDBC/expected/parallel_query/BABEL-2844.out index d4ec0b3755..86d2755dcd 100644 --- a/test/JDBC/expected/parallel_query/BABEL-2844.out +++ b/test/JDBC/expected/parallel_query/BABEL-2844.out @@ -21,7 +21,7 @@ Query Text: create table babel_2844_t1 (a1 int, b1 int); ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 63.926 ms +Babelfish T-SQL Batch Parsing Time: 64.356 ms ~~END~~ select * from babel_2844_t1 where b1 = 1; @@ -42,7 +42,7 @@ Function Scan on set_config (cost=0.00..0.01 rows=1 width=32) ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 23.541 ms +Babelfish T-SQL Batch Parsing Time: 24.000 ms ~~END~~ set BABELFISH_SHOWPLAN_ALL OFF; @@ -79,7 +79,7 @@ Insert on babel_2844_t1 (cost=0.00..0.01 rows=0 width=0) ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.175 ms +Babelfish T-SQL Batch Parsing Time: 0.178 ms ~~END~~ insert into babel_2844_t2 select * from babel_2844_t1 where a1 = 1; @@ -94,7 +94,7 @@ Insert on babel_2844_t2 (cost=0.00..38.25 rows=0 width=0) ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.550 ms +Babelfish T-SQL Batch Parsing Time: 0.580 ms ~~END~~ set BABELFISH_SHOWPLAN_ALL OFF; @@ -129,7 +129,7 @@ Gather (cost=0.00..0.01 rows=1 width=4) ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.158 ms +Babelfish T-SQL Batch Parsing Time: 0.161 ms ~~END~~ select * from babel_2844_t1 where b1 = 1; @@ -145,7 +145,7 @@ Gather (cost=0.00..19.11 rows=11 width=8) ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.200 ms +Babelfish T-SQL Batch Parsing Time: 0.205 ms ~~END~~ @@ -174,7 +174,7 @@ Gather (cost=0.00..19.11 rows=11 width=8) ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.109 ms +Babelfish T-SQL Batch Parsing Time: 0.145 ms ~~END~~ set BABELFISH_SHOWPLAN_ALL OFF; @@ -201,7 +201,7 @@ Gather (cost=0.00..19.11 rows=11 width=8) ~~START~~ text -[ "Babelfish T-SQL Batch Parsing Time": 0.118] +Babelfish T-SQL Batch Parsing Time: 0.126 ms ~~END~~ set BABELFISH_SHOWPLAN_ALL OFF; @@ -227,7 +227,7 @@ Gather (cost=0.00..19.11 rows=11 width=8) ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.228 +Babelfish T-SQL Batch Parsing Time: 0.241 ms ~~END~~ set BABELFISH_SHOWPLAN_ALL OFF; @@ -268,7 +268,7 @@ Gather (cost=0.00..17.29 rows=2260 width=8) ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 10.543 ms +Babelfish T-SQL Batch Parsing Time: 10.599 ms ~~END~~ @@ -313,7 +313,7 @@ Query Text: EXEC babel_2844_proc 3 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 25.537 ms +Babelfish T-SQL Batch Parsing Time: 25.709 ms ~~END~~ set BABELFISH_SHOWPLAN_ALL OFF; @@ -341,7 +341,7 @@ Query Text: EXEC SP_PREPARE @handle OUT, NULL, 'select * from babel_2844_t1' ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 27.045 ms +Babelfish T-SQL Batch Parsing Time: 26.758 ms ~~END~~ set BABELFISH_SHOWPLAN_ALL OFF; @@ -366,7 +366,7 @@ Function Scan on babel_2844_itvf (cost=0.25..10.25 rows=1000 width=8) ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.134 ms +Babelfish T-SQL Batch Parsing Time: 0.138 ms ~~END~~ set BABELFISH_SHOWPLAN_ALL OFF; @@ -395,7 +395,7 @@ Function Scan on babel_2844_mstvf (cost=0.25..10.25 rows=1000 width=8) ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.103 ms +Babelfish T-SQL Batch Parsing Time: 0.115 ms ~~END~~ set BABELFISH_SHOWPLAN_ALL OFF; @@ -445,7 +445,7 @@ Query Text: set BABELFISH_STATISTICS PROFILE ON; ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 3.448 ms +Babelfish T-SQL Batch Parsing Time: 3.442 ms ~~END~~ @@ -483,7 +483,7 @@ Query Text: SELECT * INTO t3 FROM t1 WHERE t1.b = 1 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 30.196 ms +Babelfish T-SQL Batch Parsing Time: 31.453 ms ~~END~~ @@ -507,7 +507,7 @@ Insert on t1 (cost=0.00..0.04 rows=0 width=0) ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.141 ms +Babelfish T-SQL Batch Parsing Time: 0.142 ms ~~END~~ @@ -523,7 +523,7 @@ Delete on t1 (cost=0.15..8.17 rows=0 width=0) ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 57.541 ms +Babelfish T-SQL Batch Parsing Time: 60.549 ms ~~END~~ @@ -539,7 +539,7 @@ Update on t1 (cost=0.15..8.17 rows=0 width=0) ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 46.745 ms +Babelfish T-SQL Batch Parsing Time: 49.259 ms ~~END~~ @@ -563,7 +563,7 @@ END ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 35.848 ms +Babelfish T-SQL Batch Parsing Time: 35.948 ms ~~END~~ diff --git a/test/JDBC/expected/parallel_query/Test-sp_reset_connection.out b/test/JDBC/expected/parallel_query/Test-sp_reset_connection.out new file mode 100644 index 0000000000..f588ae4fd0 --- /dev/null +++ b/test/JDBC/expected/parallel_query/Test-sp_reset_connection.out @@ -0,0 +1,727 @@ +-- tsql +-- 1. Test resets GUC variables +SELECT @@lock_timeout; +GO +~~START~~ +int +-1 +~~END~~ + +SET lock_timeout 0; +GO +SELECT @@lock_timeout; +GO +~~START~~ +int +0 +~~END~~ + +EXEC sys.sp_reset_connection +GO +SELECT @@lock_timeout; +GO +~~START~~ +int +-1 +~~END~~ + + +-- 2. Test open transactions are aborted on reset +DROP TABLE IF EXISTS sp_reset_connection_test_table; +CREATE TABLE sp_reset_connection_test_table(id int); +BEGIN TRANSACTION +INSERT INTO sp_reset_connection_test_table VALUES(1) +GO +~~ROW COUNT: 1~~ + +EXEC sys.sp_reset_connection +GO +COMMIT TRANSACTION +GO +~~ERROR (Code: 3902)~~ + +~~ERROR (Message: COMMIT can only be used in transaction blocks)~~ + +SELECT * FROM sp_reset_connection_test_table +GO +~~START~~ +int +~~END~~ + + +-- 3. Test temp tables are deleted on reset +CREATE TABLE #babel_temp_table (ID INT identity(1,1), Data INT) +INSERT INTO #babel_temp_table (Data) VALUES (100), (200), (300) +GO +~~ROW COUNT: 3~~ + +SELECT * from #babel_temp_table +GO +~~START~~ +int#!#int +1#!#100 +2#!#200 +3#!#300 +~~END~~ + +EXEC sys.sp_reset_connection +GO +SELECT * from #babel_temp_table +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: relation "#babel_temp_table" does not exist)~~ + + +-- 4. Test isolation level is reset +SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED +GO +select transaction_isolation_level from sys.dm_exec_sessions where session_id=@@SPID +GO +~~START~~ +smallint +1 +~~END~~ + +EXEC sys.sp_reset_connection +GO +select transaction_isolation_level from sys.dm_exec_sessions where session_id=@@SPID +GO +~~START~~ +smallint +2 +~~END~~ + + +-- 5. Test sp_reset_connection called with sp_prepexec +SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED +GO +select transaction_isolation_level from sys.dm_exec_sessions where session_id=@@SPID +GO +~~START~~ +smallint +1 +~~END~~ + +DECLARE @handle int; +EXEC SP_PREPARE @handle output, NULL, N'exec sys.sp_reset_connection' +EXEC SP_EXECUTE @handle +GO +GO +select transaction_isolation_level from sys.dm_exec_sessions where session_id=@@SPID +GO +~~START~~ +smallint +2 +~~END~~ + + +-- 6. Test Database Context being reset +-- Tests include negative cases where db is dropped or renamed +Create database reset_con_db1; +GO +Create database reset_con_db2; +GO + +-- tsql database=reset_con_db1 +select db_name(); +GO +~~START~~ +nvarchar +reset_con_db1 +~~END~~ + +exec sys.sp_reset_connection +GO +use master +GO +select db_name(); +GO +~~START~~ +nvarchar +master +~~END~~ + +exec sys.sp_reset_connection +GO +select db_name(); +GO +~~START~~ +nvarchar +reset_con_db1 +~~END~~ + +-- test db being dropped before resetting to same db +use master; +drop database reset_con_db1; +GO +exec sys.sp_reset_connection +GO +~~ERROR (Code: 911)~~ + +~~ERROR (Message: database "reset_con_db1" does not exist)~~ + +-- tsql database=reset_con_db2 +select db_name(); +GO +~~START~~ +nvarchar +reset_con_db2 +~~END~~ + +use master +GO +select db_name(); +GO +~~START~~ +nvarchar +master +~~END~~ + +ALTER DATABASE reset_con_db2 MODIFY NAME=reset_con_db3 +GO +exec sys.sp_reset_connection +GO +~~ERROR (Code: 911)~~ + +~~ERROR (Message: database "reset_con_db2" does not exist)~~ + + +-- tsql +DROP DATABASE reset_con_db3 +GO + +-- Cursor reset testing +CREATE TABLE babel_cursor_t1 (i INT, d double precision, c varchar(10), u uniqueidentifier, v sql_variant); +INSERT INTO babel_cursor_t1 VALUES (1, 1.1, 'a', '1E984725-C51C-4BF4-9960-E1C80E27ABA0', 1); +INSERT INTO babel_cursor_t1 VALUES (2, 22.22, 'bb', '2E984725-C51C-4BF4-9960-E1C80E27ABA0', 22.22); +INSERT INTO babel_cursor_t1 VALUES (3, 333.333, 'cccc', '3E984725-C51C-4BF4-9960-E1C80E27ABA0', 'cccc'); +INSERT INTO babel_cursor_t1 VALUES (4, 4444.4444, 'dddddd', '4E984725-C51C-4BF4-9960-E1C80E27ABA0', cast('4E984725-C51C-4BF4-9960-E1C80E27ABA0' as uniqueidentifier)); +INSERT INTO babel_cursor_t1 VALUES (NULL, NULL, NULL, NULL, NULL); +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +-- check the status of the cursor +DECLARE @Report CURSOR; +EXEC sys.sp_cursor_list @cursor_return = @Report OUTPUT,@cursor_scope = 2; FETCH NEXT from @Report; WHILE (@@FETCH_STATUS <> -1) BEGIN FETCH NEXT from @Report; END; +go +~~START~~ +varchar#!#varchar#!#smallint#!#smallint#!#smallint#!#smallint#!#smallint#!#smallint#!#numeric#!#smallint#!#smallint#!#numeric#!#smallint#!#int +~~END~~ + + +-- This will work since we declared 180150001 handle +EXEC sp_cursorfetch 180150001, 2, 0, 1; +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cursor "180150001" does not exist)~~ + +EXEC sp_cursor 180150001, 40, 1, 0; +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cursor "180150001" does not exist)~~ + + +exec sys.sp_reset_connection +GO + +-- Check cursor being cleaned up +DECLARE @Report CURSOR; +EXEC sys.sp_cursor_list @cursor_return = @Report OUTPUT,@cursor_scope = 2; +FETCH NEXT from @Report; WHILE (@@FETCH_STATUS <> -1) BEGIN FETCH NEXT from @Report; END; +SELECT sys.babelfish_pltsql_get_last_stmt_handle(); +SELECT sys.babelfish_pltsql_get_last_cursor_handle(); +SELECT @@cursor_rows; +GO +~~START~~ +varchar#!#varchar#!#smallint#!#smallint#!#smallint#!#smallint#!#smallint#!#smallint#!#numeric#!#smallint#!#smallint#!#numeric#!#smallint#!#int +~~END~~ + +~~START~~ +int +1073741824 +~~END~~ + +~~START~~ +int +180150000 +~~END~~ + +~~START~~ +int +0 +~~END~~ + +-- This will not work since we 80150001 handle should have been cleaned up +EXEC sp_cursorfetch 180150001, 2, 0, 1; +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cursor "180150001" does not exist)~~ + +EXEC sp_cursor 180150001, 40, 1, 0; +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: cursor "180150001" does not exist)~~ + + +-- Testing with only Cursor Open +DECLARE @cursor_handle int; +EXEC sp_cursoropen @cursor_handle OUTPUT, 'select i, d, c, u from babel_cursor_t1', 2, 8193; +GO + +-- check the status of the cursor +DECLARE @Report CURSOR; +EXEC sys.sp_cursor_list @cursor_return = @Report OUTPUT,@cursor_scope = 2; FETCH NEXT from @Report; WHILE (@@FETCH_STATUS <> -1) BEGIN FETCH NEXT from @Report; END; +go +~~START~~ +varchar#!#varchar#!#smallint#!#smallint#!#smallint#!#smallint#!#smallint#!#smallint#!#numeric#!#smallint#!#smallint#!#numeric#!#smallint#!#int +NULL#!#NULL#!#2#!#1#!#1#!#1#!#1#!#1#!#-1#!#0#!#4#!#0#!#1#!#180150001 +~~END~~ + +~~START~~ +varchar#!#varchar#!#smallint#!#smallint#!#smallint#!#smallint#!#smallint#!#smallint#!#numeric#!#smallint#!#smallint#!#numeric#!#smallint#!#int +~~END~~ + + +exec sys.sp_reset_connection +GO + +-- Check cursor being cleaned up +DECLARE @Report CURSOR; +EXEC sys.sp_cursor_list @cursor_return = @Report OUTPUT,@cursor_scope = 2; +FETCH NEXT from @Report; WHILE (@@FETCH_STATUS <> -1) BEGIN FETCH NEXT from @Report; END; +SELECT sys.babelfish_pltsql_get_last_stmt_handle(); +SELECT sys.babelfish_pltsql_get_last_cursor_handle(); +SELECT @@cursor_rows; +GO +~~START~~ +varchar#!#varchar#!#smallint#!#smallint#!#smallint#!#smallint#!#smallint#!#smallint#!#numeric#!#smallint#!#smallint#!#numeric#!#smallint#!#int +~~END~~ + +~~START~~ +int +1073741824 +~~END~~ + +~~START~~ +int +180150000 +~~END~~ + +~~START~~ +int +0 +~~END~~ + + +-- Testing with only Cursor Prepare +DECLARE @stmt_handle int; +EXEC sp_cursorprepare @stmt_handle OUTPUT, N'', 'select i, d, c, u from babel_cursor_t1', 0, 2, 1; +GO + +-- check the status of the cursor should give 1073741825 +SELECT sys.babelfish_pltsql_get_last_stmt_handle(); +exec sys.sp_reset_connection +GO +~~START~~ +int +1073741825 +~~END~~ + + +-- Check cursor being cleaned up +DECLARE @Report CURSOR; +EXEC sys.sp_cursor_list @cursor_return = @Report OUTPUT,@cursor_scope = 2; +FETCH NEXT from @Report; WHILE (@@FETCH_STATUS <> -1) BEGIN FETCH NEXT from @Report; END; +SELECT sys.babelfish_pltsql_get_last_stmt_handle(); +SELECT sys.babelfish_pltsql_get_last_cursor_handle(); +SELECT @@cursor_rows; +GO +~~START~~ +varchar#!#varchar#!#smallint#!#smallint#!#smallint#!#smallint#!#smallint#!#smallint#!#numeric#!#smallint#!#smallint#!#numeric#!#smallint#!#int +~~END~~ + +~~START~~ +int +1073741824 +~~END~~ + +~~START~~ +int +180150000 +~~END~~ + +~~START~~ +int +0 +~~END~~ + + +-- Testing with only Cursor Prepare and Fetch +DECLARE @stmt_handle int; +DECLARE @cursor_handle int; +DECLARE @cursor_handle2 int; +EXEC sp_cursorprepare @stmt_handle OUTPUT, N'', 'select i, d, c, u from babel_cursor_t1', 0, 2, 1; +EXEC sp_cursorexecute @stmt_handle, @cursor_handle OUTPUT, 2, 1; +EXEC sp_cursorfetch @cursor_handle, 2, 0, 1; +EXEC sp_cursorexecute @stmt_handle, @cursor_handle2 OUTPUT, 2, 1; +GO +~~START~~ +int#!#float#!#varchar#!#uniqueidentifier +1#!#1.1#!#a#!#1E984725-C51C-4BF4-9960-E1C80E27ABA0 +~~END~~ + + +-- check the status of the cursor +DECLARE @Report CURSOR; +EXEC sys.sp_cursor_list @cursor_return = @Report OUTPUT,@cursor_scope = 2; FETCH NEXT from @Report; WHILE (@@FETCH_STATUS <> -1) BEGIN FETCH NEXT from @Report; END; +go +~~START~~ +varchar#!#varchar#!#smallint#!#smallint#!#smallint#!#smallint#!#smallint#!#smallint#!#numeric#!#smallint#!#smallint#!#numeric#!#smallint#!#int +NULL#!#NULL#!#2#!#1#!#1#!#1#!#1#!#1#!#-1#!#0#!#4#!#1#!#2#!#180150001 +~~END~~ + +~~START~~ +varchar#!#varchar#!#smallint#!#smallint#!#smallint#!#smallint#!#smallint#!#smallint#!#numeric#!#smallint#!#smallint#!#numeric#!#smallint#!#int +NULL#!#NULL#!#2#!#1#!#1#!#1#!#1#!#1#!#-1#!#0#!#4#!#0#!#1#!#180150002 +~~END~~ + +~~START~~ +varchar#!#varchar#!#smallint#!#smallint#!#smallint#!#smallint#!#smallint#!#smallint#!#numeric#!#smallint#!#smallint#!#numeric#!#smallint#!#int +~~END~~ + +-- check the status of the cursor should give 1073741825 +SELECT sys.babelfish_pltsql_get_last_stmt_handle(); +exec sys.sp_reset_connection +GO +~~START~~ +int +1073741825 +~~END~~ + + +exec sys.sp_reset_connection +GO + +-- Check cursor being cleaned up +DECLARE @Report CURSOR; +EXEC sys.sp_cursor_list @cursor_return = @Report OUTPUT,@cursor_scope = 2; +FETCH NEXT from @Report; WHILE (@@FETCH_STATUS <> -1) BEGIN FETCH NEXT from @Report; END; +SELECT sys.babelfish_pltsql_get_last_stmt_handle(); +SELECT sys.babelfish_pltsql_get_last_cursor_handle(); +SELECT @@cursor_rows; +GO +~~START~~ +varchar#!#varchar#!#smallint#!#smallint#!#smallint#!#smallint#!#smallint#!#smallint#!#numeric#!#smallint#!#smallint#!#numeric#!#smallint#!#int +~~END~~ + +~~START~~ +int +1073741824 +~~END~~ + +~~START~~ +int +180150000 +~~END~~ + +~~START~~ +int +0 +~~END~~ + + +-- Testing with only Cursor Prepare and Fetch but this time calling cursor close +DECLARE @stmt_handle int; +DECLARE @cursor_handle int; +DECLARE @cursor_handle2 int; +EXEC sp_cursorprepare @stmt_handle OUTPUT, N'', 'select i, d, c, u from babel_cursor_t1', 0, 2, 1; +EXEC sp_cursorexecute @stmt_handle, @cursor_handle OUTPUT, 2, 1; +EXEC sp_cursorfetch @cursor_handle, 2, 0, 1; +EXEC sp_cursorexecute @stmt_handle, @cursor_handle2 OUTPUT, 2, 1; +EXEC sp_cursorclose @cursor_handle; +EXEC sp_cursorclose @cursor_handle2; +EXEC sp_cursorunprepare @stmt_handle; +GO +~~START~~ +int#!#float#!#varchar#!#uniqueidentifier +1#!#1.1#!#a#!#1E984725-C51C-4BF4-9960-E1C80E27ABA0 +~~END~~ + + +-- check the status of the cursor +DECLARE @Report CURSOR; +EXEC sys.sp_cursor_list @cursor_return = @Report OUTPUT,@cursor_scope = 2; FETCH NEXT from @Report; WHILE (@@FETCH_STATUS <> -1) BEGIN FETCH NEXT from @Report; END; +go +~~START~~ +varchar#!#varchar#!#smallint#!#smallint#!#smallint#!#smallint#!#smallint#!#smallint#!#numeric#!#smallint#!#smallint#!#numeric#!#smallint#!#int +~~END~~ + +-- check the status of the cursor should give 1073741825 +SELECT sys.babelfish_pltsql_get_last_stmt_handle(); +exec sys.sp_reset_connection +GO +~~START~~ +int +1073741825 +~~END~~ + + +exec sys.sp_reset_connection +GO + +-- Check cursor being cleaned up +DECLARE @Report CURSOR; +EXEC sys.sp_cursor_list @cursor_return = @Report OUTPUT,@cursor_scope = 2; +FETCH NEXT from @Report; WHILE (@@FETCH_STATUS <> -1) BEGIN FETCH NEXT from @Report; END; +SELECT sys.babelfish_pltsql_get_last_stmt_handle(); +SELECT sys.babelfish_pltsql_get_last_cursor_handle() +SELECT @@cursor_rows; +GO +~~START~~ +varchar#!#varchar#!#smallint#!#smallint#!#smallint#!#smallint#!#smallint#!#smallint#!#numeric#!#smallint#!#smallint#!#numeric#!#smallint#!#int +~~END~~ + +~~START~~ +int +1073741824 +~~END~~ + +~~START~~ +int +180150000 +~~END~~ + +~~START~~ +int +0 +~~END~~ + + +drop table babel_cursor_t1; +GO + + +-- GUCs testing +-- 1. Ansi defaults +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_nulls', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_warnings', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_null_dflt_on', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_padding', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.implicit_transactions', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.quoted_identifier', true); +GO +~~START~~ +text +on +~~END~~ + +~~START~~ +text +on +~~END~~ + +~~START~~ +text +on +~~END~~ + +~~START~~ +text +on +~~END~~ + +~~START~~ +text +off +~~END~~ + +~~START~~ +text +on +~~END~~ + + +SET ANSI_DEFAULTS ON +GO + +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_nulls', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_warnings', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_null_dflt_on', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_padding', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.implicit_transactions', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.quoted_identifier', true); +GO +~~START~~ +text +on +~~END~~ + +~~START~~ +text +on +~~END~~ + +~~START~~ +text +on +~~END~~ + +~~START~~ +text +on +~~END~~ + +~~START~~ +text +on +~~END~~ + +~~START~~ +text +on +~~END~~ + + +-- reset +exec sys.sp_reset_connection +GO + +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_nulls', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_warnings', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_null_dflt_on', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_padding', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.implicit_transactions', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.quoted_identifier', true); +GO +~~START~~ +text +on +~~END~~ + +~~START~~ +text +on +~~END~~ + +~~START~~ +text +on +~~END~~ + +~~START~~ +text +on +~~END~~ + +~~START~~ +text +off +~~END~~ + +~~START~~ +text +on +~~END~~ + + +-- babelfish_showplan_all +SET babelfish_showplan_all ON +GO + +-- explain output +SELECT 1; +GO +~~START~~ +text +Query Text: SELECT 1 +Gather (cost=0.00..0.01 rows=1 width=4) + Workers Planned: 1 + Single Copy: true + -> Result (cost=0.00..0.01 rows=1 width=4) +~~END~~ + +~~START~~ +text +Babelfish T-SQL Batch Parsing Time: 0.085 ms +~~END~~ + + +-- reset +exec sys.sp_reset_connection +GO + +-- 1 output +SELECT 1; +GO +~~START~~ +int +1 +~~END~~ + + + +-- set_config testing. +-- search_path has source < PGC_S_SESSION in TSQL but it gets reset during ResetAll Gucs. +-- Whereas role does not get reset since it uses GUC_NO_RESET_ALL, so we should not allow +-- set_config for this option. +SELECT CURRENT_SETTING('search_path', true) +SELECT CURRENT_SETTING('role', true) +GO +~~START~~ +text +master_dbo, "$user", sys, pg_catalog +~~END~~ + +~~START~~ +text +none +~~END~~ + + +SELECT set_config('search_path', 'sys', false); +GO +~~START~~ +text +sys +~~END~~ + +SELECT set_config('role', 'jdbc_user', false); +GO +~~START~~ +text +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: set_config not allowed for option role)~~ + + +-- reset +exec sp_reset_connection +GO + +SELECT CURRENT_SETTING('search_path', true) +SELECT CURRENT_SETTING('role', true) +GO +~~START~~ +text +master_dbo, "$user", sys, pg_catalog +~~END~~ + +~~START~~ +text +none +~~END~~ + diff --git a/test/JDBC/expected/parallel_query/alter_proc_recompile-vu-verify.out b/test/JDBC/expected/parallel_query/alter_proc_recompile-vu-verify.out index 093a9355ef..a54e7435ae 100644 --- a/test/JDBC/expected/parallel_query/alter_proc_recompile-vu-verify.out +++ b/test/JDBC/expected/parallel_query/alter_proc_recompile-vu-verify.out @@ -179,7 +179,7 @@ Query Text: EXEC p_alter_recomp_01 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.199 ms +Babelfish T-SQL Batch Parsing Time: 0.223 ms ~~END~~ execute p_alter_recomp_02 0 -- created with recompile @@ -197,7 +197,7 @@ Query Text: EXEC p_alter_recomp_02 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.100 ms +Babelfish T-SQL Batch Parsing Time: 0.104 ms ~~END~~ execute p_alter_recomp_11 0 -- altered with recompile; for MVU test @@ -215,7 +215,7 @@ Query Text: EXEC p_alter_recomp_11 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.081 ms +Babelfish T-SQL Batch Parsing Time: 0.123 ms ~~END~~ execute p_alter_recomp_12 0 -- altered without recompile; for MVU test @@ -233,7 +233,7 @@ Query Text: EXEC p_alter_recomp_12 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.075 ms +Babelfish T-SQL Batch Parsing Time: 0.118 ms ~~END~~ set babelfish_showplan_all off @@ -259,7 +259,7 @@ Query Text: EXEC p_alter_recomp_01 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.067 ms +Babelfish T-SQL Batch Parsing Time: 0.071 ms ~~END~~ execute p_alter_recomp_02 0 -- created with recompile @@ -277,7 +277,7 @@ Query Text: EXEC p_alter_recomp_02 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.074 ms +Babelfish T-SQL Batch Parsing Time: 0.115 ms ~~END~~ set babelfish_showplan_all off @@ -385,7 +385,7 @@ Query Text: EXEC p_alter_recomp_01 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.113 ms +Babelfish T-SQL Batch Parsing Time: 0.122 ms ~~END~~ execute p_alter_recomp_02 0 -- altered without recompile @@ -403,7 +403,7 @@ Query Text: EXEC p_alter_recomp_02 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.110 ms +Babelfish T-SQL Batch Parsing Time: 0.099 ms ~~END~~ set babelfish_showplan_all off diff --git a/test/JDBC/expected/parallel_query/test_dynamic_local_vars.out b/test/JDBC/expected/parallel_query/test_dynamic_local_vars.out new file mode 100644 index 0000000000..1c3c7a78ab --- /dev/null +++ b/test/JDBC/expected/parallel_query/test_dynamic_local_vars.out @@ -0,0 +1,2467 @@ +-- simple vars +declare @i int +declare @j int +set @i = 10 +set @j = @i + 10 +select @i, @j +GO +~~START~~ +int#!#int +10#!#20 +~~END~~ + + +declare @i int +declare @j int +select @i = 10, @j = @i + 10 +select @i, @j +GO +~~START~~ +int#!#int +10#!#20 +~~END~~ + + +declare @i int +declare @j int = 0; +select @i = 10, @j = @i + @j * 2 +select @i, @j +GO +~~START~~ +int#!#int +10#!#10 +~~END~~ + + +declare @i int +declare @j int +select @i = 10, @j = @i + 10 +select @j += 10 +select @i, @j +GO +~~START~~ +int#!#int +10#!#30 +~~END~~ + + +-- should throw an error +declare @i int +select @i = 0, @i += 2 +select @i +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Babelfish does not support assignment to the same variable in SELECT. variable name: "@i")~~ + + +declare @i int +select @i = 10, @i += 10 +select @i +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Babelfish does not support assignment to the same variable in SELECT. variable name: "@i")~~ + + +-- sub-expr +declare @i int +set @i = 10 +select @i += (5 - 1) +select @i +GO +~~START~~ +int +14 +~~END~~ + + +DECLARE @a int +select @a = (select ~cast('1' as int)) +select @a +go +~~START~~ +int +-2 +~~END~~ + + + +DECLARE @Counter INT = 1; +DECLARE @MaxValue INT = 10; +WHILE @Counter <= @MaxValue +BEGIN + DECLARE @IsEven BIT; + + IF @Counter % 2 = 0 + SET @IsEven = 1; + ELSE + SET @IsEven = 0; + + IF @IsEven = 1 + SELECT CAST(@Counter AS VARCHAR(2)) + ' is even'; + ELSE + SELECT CAST(@Counter AS VARCHAR(2)) + ' is odd'; + + SET @Counter = @Counter + 1; +END; +GO +~~START~~ +varchar +1 is odd +~~END~~ + +~~START~~ +varchar +2 is even +~~END~~ + +~~START~~ +varchar +3 is odd +~~END~~ + +~~START~~ +varchar +4 is even +~~END~~ + +~~START~~ +varchar +5 is odd +~~END~~ + +~~START~~ +varchar +6 is even +~~END~~ + +~~START~~ +varchar +7 is odd +~~END~~ + +~~START~~ +varchar +8 is even +~~END~~ + +~~START~~ +varchar +9 is odd +~~END~~ + +~~START~~ +varchar +10 is even +~~END~~ + + +declare @a numeric (10, 4); +declare @b numeric (10, 4); +SET @a=100.41; +SET @b=200.82; +SELECT @a, @b +select @a+@b as r; +GO +~~START~~ +numeric#!#numeric +100.4100#!#200.8200 +~~END~~ + +~~START~~ +numeric +301.2300 +~~END~~ + + +declare @a numeric; +declare @b numeric (10, 4); +SET @a=100.41; +SET @b=200.82; +SELECT @a, @b +select @a+@b as r; +GO +~~START~~ +numeric#!#numeric +100#!#200.8200 +~~END~~ + +~~START~~ +numeric +300.8200 +~~END~~ + + +declare @a varbinary +set @a = cast('test_bin' as varbinary) +select @a +GO +~~START~~ +varbinary +74 +~~END~~ + + +declare @a varbinary(max) +set @a = cast('test_bin' as varbinary) +select @a +GO +~~START~~ +varbinary +746573745F62696E +~~END~~ + + +declare @a varbinary(10) +set @a = cast('test_bin' as varbinary) +select @a +GO +~~START~~ +varbinary +746573745F62696E +~~END~~ + + +declare @a varbinary +declare @b varbinary +select @a = cast('test_bin' as varbinary), @b = @a +select @a, @b +GO +~~START~~ +varbinary#!#varbinary +74#!#74 +~~END~~ + + +declare @a varbinary(max) +select @a = cast('test_bin' as varbinary) +select @a +GO +~~START~~ +varbinary +746573745F62696E +~~END~~ + + +DECLARE @a varchar +set @a = '12345678901234567890123456789012345'; +SELECT LEN(@a), DATALENGTH(@a) +SELECT @a +GO +~~START~~ +int#!#int +1#!#1 +~~END~~ + +~~START~~ +varchar +1 +~~END~~ + + +DECLARE @v varchar(20); +SELECT @v = NULL; +SELECT ISNUMERIC(@v), LEN(@v), DATALENGTH(@v) +GO +~~START~~ +int#!#int#!#int +0#!##!# +~~END~~ + + +DECLARE @a varchar(max) +SELECT @a = '12345678901234567890123456789012345'; +SELECT LEN(@a), DATALENGTH(@a) +SELECT @a +GO +~~START~~ +int#!#int +35#!#35 +~~END~~ + +~~START~~ +varchar +12345678901234567890123456789012345 +~~END~~ + + +-- collate can not be used with local variables +DECLARE @v varchar(20) collate BBF_Unicode_CP1_CI_As = 'ci_as'; +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: syntax error near 'collate' at line 2 and character position 23)~~ + + +declare @source int; +declare @target sql_variant; +select @source = 1.0 +select @target = cast(@source as varchar(10)); +SELECT sql_variant_property(@target, 'basetype'); +select @target +GO +~~START~~ +sql_variant +varchar +~~END~~ + +~~START~~ +sql_variant +1 +~~END~~ + + +declare @source int; +declare @target varchar(10); +select @source = 1.0 +select cast(@source as varchar(10)) +select @target = cast(@source as varchar(10)); +select @target +GO +~~START~~ +varchar +1 +~~END~~ + +~~START~~ +varchar +1 +~~END~~ + + +DECLARE @a pg_catalog.varchar +SELECT @a = '12345678901234567890123456789012345'; +SELECT LEN(@a), DATALENGTH(@a) +SELECT @a +GO +~~START~~ +int#!#int +35#!#35 +~~END~~ + +~~START~~ +varchar +12345678901234567890123456789012345 +~~END~~ + + +DECLARE @a pg_catalog.varchar(100) +SELECT @a = '12345678901234567890123456789012345'; +SELECT LEN(@a), DATALENGTH(@a) +SELECT @a +GO +~~START~~ +int#!#int +35#!#35 +~~END~~ + +~~START~~ +varchar +12345678901234567890123456789012345 +~~END~~ + + +DECLARE @a pg_catalog.varchar(10) +SELECT @a = '12345678901234567890123456789012345'; +SELECT LEN(@a), DATALENGTH(@a) +SELECT @a +GO +~~START~~ +int#!#int +10#!#10 +~~END~~ + +~~START~~ +varchar +1234567890 +~~END~~ + + +DECLARE @a varchar +SELECT @a = '12345678901234567890123456789012345'; +SELECT LEN(@a), DATALENGTH(@a) +SELECT @a +GO +~~START~~ +int#!#int +1#!#1 +~~END~~ + +~~START~~ +varchar +1 +~~END~~ + + +DECLARE @a varchar(100) +SELECT @a = '12345678901234567890123456789012345'; +SELECT LEN(@a), DATALENGTH(@a) +SELECT @a +GO +~~START~~ +int#!#int +35#!#35 +~~END~~ + +~~START~~ +varchar +12345678901234567890123456789012345 +~~END~~ + + +DECLARE @a varchar(10) +SELECT @a = '12345678901234567890123456789012345'; +SELECT LEN(@a), DATALENGTH(@a) +SELECT @a +GO +~~START~~ +int#!#int +10#!#10 +~~END~~ + +~~START~~ +varchar +1234567890 +~~END~~ + + +DECLARE @a int +set @a = 0 +select @a ^= 1 +select @a +go +~~START~~ +int +1 +~~END~~ + + +DECLARE @a int +set @a = 0 +select @a += ~@a +select @a +go +~~START~~ +int +-1 +~~END~~ + + +SET QUOTED_IDENTIFIER OFF +GO + +-- quoted identifiers +declare @v varchar(20) = "ABC", @v2 varchar(20)="XYZ"; +select @v += "a""b''c'd", @v2 += "x""y''z"; +select @v, @v2 +GO +~~START~~ +varchar#!#varchar +ABCa"b''c'd#!#XYZx"y''z +~~END~~ + + +declare @v varchar(20) = "ABC", @v2 varchar(20)="XYZ"; +select @v += "a""b''c'd", @v2 += @v + "x""y''z"; +select @v, @v2 +GO +~~START~~ +varchar#!#varchar +ABCa"b''c'd#!#XYZABCa"b''c'dx"y''z +~~END~~ + + +declare @v varchar(20) = "ABC", @v2 varchar(20)="XYZ"; +select @v += reverse("a""b''c'd"), @v2 += @v + "x""y''z"; +select @v, @v2 +GO +~~START~~ +varchar#!#varchar +ABCd'c''b"a#!#XYZABCd'c''b"ax"y''z +~~END~~ + + +declare @v varchar(20) = "ABC", @v2 varchar(20)="XYZ"; +select @v += reverse("a""b''c'd"), @v2 += @v + reverse("x""y''z"); +select @v, @v2 +GO +~~START~~ +varchar#!#varchar +ABCd'c''b"a#!#XYZABCd'c''b"az''y"x +~~END~~ + + +declare @v varchar(20) = "ABC", @v2 varchar(20)="XYZ"; +select @v += reverse("a""b''c'd"), @v2 += REVERSE( @v + reverse("x""y''z")); +select @v, @v2 +GO +~~START~~ +varchar#!#varchar +ABCd'c''b"a#!#XYZx"y''za"b''c'dCBA +~~END~~ + + +SET QUOTED_IDENTIFIER ON +GO + +declare @v varchar(20) = 'ABC', @v2 varchar(20)='XYZ'; +select @v += 'abc', @v2 += 'xyz'; +select @v, @v2 +GO +~~START~~ +varchar#!#varchar +ABCabc#!#XYZxyz +~~END~~ + + +declare @a int = 1, @b int = 2; +select @a = 2, @b = @a + 2 +select @a, @b +GO +~~START~~ +int#!#int +2#!#4 +~~END~~ + + +declare @a int = 1, @b int = 2; +select @a += 2, @b -= @a + 2 +select @a, @b +GO +~~START~~ +int#!#int +3#!#-3 +~~END~~ + + +-- xml methods +DECLARE @a bit = 1 +DECLARE @xml XML = ' ' +SELECT @a |= @xml.exist('/artists/artist/@name') +select @a +GO +~~START~~ +bit +1 +~~END~~ + + +DECLARE @a bit = 1 +DECLARE @xml XML; +SELECT @xml = ' ', @a |= @xml.exist('/artists/artist/@name') +select @a +GO +~~START~~ +bit +1 +~~END~~ + + +-- test all kind of udts +create type udt from NCHAR +go + +declare @a udt +select @a = 'anc' +select @a +GO +~~START~~ +nchar +a +~~END~~ + + +DROP type udt +GO + +create type varchar_max from varchar(max) +GO + +DECLARE @a varchar_max +SELECT @a = '12345678901234567890123456789012345'; +SELECT LEN(@a), DATALENGTH(@a) +SELECT @a +GO +~~START~~ +int#!#int +35#!#35 +~~END~~ + +~~START~~ +varchar +12345678901234567890123456789012345 +~~END~~ + + +DROP type varchar_max +GO + +create type num_def from numeric +GO + +declare @a numeric; +declare @b num_def; +SET @a=100.41; +SET @b=200.82; +SELECT @a, @b +select @a+@b as r; +GO +~~START~~ +numeric#!#numeric +100#!#201 +~~END~~ + +~~START~~ +numeric +301 +~~END~~ + + +drop type num_def +GO + +/* + * select/update test + */ +create table local_var_tst (id int) +GO + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +insert into local_var_tst values (6) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +-- txn does not affect local variables +begin tran +declare @i int +update local_var_tst set id = 5, @i = id * 5 +select @i +ROLLBACK tran +select @i +GO +~~ROW COUNT: 3~~ + +~~START~~ +int +25 +~~END~~ + +~~START~~ +int +25 +~~END~~ + + +select * from local_var_tst; +GO +~~START~~ +int +1 +2 +6 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +-- should return 4 +declare @i int +select @i = 1 +select @i = id * 2 from local_var_tst where id = @i +select @i +GO +~~START~~ +int +2 +~~END~~ + + +declare @i int +select @i = 1 +select @i = @i + id * 2 from local_var_tst +select @i +GO +~~START~~ +int +7 +~~END~~ + + +declare @i int +select @i = 1 +select @i = id * 2 + @i from local_var_tst +select @i +GO +~~START~~ +int +7 +~~END~~ + + +declare @i int +select @i = 1 +select @i += id * 2 from local_var_tst +select @i +GO +~~START~~ +int +7 +~~END~~ + + +-- 3 parts name +declare @i int +select @i = 1 +select @i += master.dbo.local_var_tst.id * 2 from local_var_tst +select @i +GO +~~START~~ +int +7 +~~END~~ + + +-- local var name same as column +declare @id int = 1 +select @id += master.dbo.local_var_tst.id * 2 from local_var_tst +select @id +GO +~~START~~ +int +7 +~~END~~ + + +-- should throw an error +declare @i int +declare @j int +set @i = 10 +set @j = 0; +select @i += (select @j = @j + id from local_var_tst) +select @i +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: variable assignment can be used only in top-level SELECT)~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +DECLARE @ans INT +SELECT @ans = AVG(id) FROM local_var_tst +select @ans +GO +~~START~~ +int +1 +~~END~~ + + +-- local variable inside functions +CREATE FUNCTION var_inside_func() +RETURNS INT AS +BEGIN + DECLARE @ans INT + SELECT @ans = AVG(id) FROM local_var_tst + RETURN @ans +END +GO + +select var_inside_func(); +GO +~~START~~ +int +1 +~~END~~ + + +DROP FUNCTION var_inside_func(); +GO + +-- show throw an error +CREATE FUNCTION var_inside_func() +RETURNS @tab table (a int) as +BEGIN + DECLARE @ans INT + SELECT @ans += id from local_var_tst + select @ans +END +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: SELECT statement returning result to a client cannot be used in a function)~~ + + +drop function if exists var_inside_func +go + +CREATE FUNCTION var_inside_func() +RETURNS INT AS +BEGIN + DECLARE @ans INT + SELECT @ans += id FROM local_var_tst + RETURN @ans +END +GO + +select var_inside_func() +go +~~START~~ +int + +~~END~~ + + +drop function if exists var_inside_func +go + +CREATE FUNCTION var_inside_func(@def int) +RETURNS INT AS +BEGIN + DECLARE @ans INT; + select @ans = @def; + SELECT @ans += id FROM local_var_tst + RETURN @ans +END +GO + +select var_inside_func(0) +go +~~START~~ +int +3 +~~END~~ + + +declare @def int = 1; +select var_inside_func(@def) +go +~~START~~ +int +4 +~~END~~ + + +drop function if exists var_inside_func +go + +CREATE FUNCTION var_inside_func() +RETURNS INT AS +BEGIN + DECLARE @ans INT + select @ans = 0 + SELECT @ans += id + @ans FROM local_var_tst + RETURN @ans +END +GO + +select var_inside_func() +go +~~START~~ +int +4 +~~END~~ + + +drop function if exists var_inside_func +go + +-- variable with procedure +CREATE PROCEDURE var_with_procedure (@a numeric(10,4) OUTPUT) AS +BEGIN + SET @a=100.41; + select @a as a; +END; +GO + +exec var_with_procedure 2.000; +GO +~~START~~ +numeric +100.4100 +~~END~~ + + +-- value of @out should remain 2.000 +declare @out numeric(10,4); +set @out = 2.000; +exec var_with_procedure 2.000; +select @out +GO +~~START~~ +numeric +100.4100 +~~END~~ + +~~START~~ +numeric +2.0000 +~~END~~ + + +drop procedure var_with_procedure; +GO + +CREATE PROCEDURE var_with_procedure_1 (@a numeric(10,4) OUTPUT, @b numeric(10,4) OUTPUT) AS +BEGIN + SET @a=100.41; + SET @b=200.82; + select @a+@b as r; +END; +GO + +EXEC var_with_procedure_1 2.000, 3.000; +GO +~~START~~ +numeric +301.2300 +~~END~~ + + +-- value of @a should be 100 +DECLARE @a INT; +EXEC var_with_procedure_1 @a OUT, 3.000; +SELECT @a; +GO +~~START~~ +numeric +301.2300 +~~END~~ + +~~START~~ +int +100 +~~END~~ + + +drop procedure var_with_procedure_1; +GO + +CREATE PROCEDURE var_with_procedure_2 +AS +BEGIN + declare @a int + declare @b int + set @a = 1 + return + select @b=@a+1 +END +GO + +exec var_with_procedure_2 +GO + +DROP PROCEDURE var_with_procedure_2 +GO + +-- insert testing with local variables +truncate table dbo.local_var_tst +go + +-- should throw an error +declare @a int = 1 +insert into local_var_tst select @a = @a + 1 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: variable assignment can be used only in top-level SELECT)~~ + + +-- syntax error +declare @a int = 1 +insert into local_var_tst values (@a = @a + 1) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: syntax error near '=' at line 3 and character position 37)~~ + + +declare @a int = 1 +insert into local_var_tst values (@a + 1) +GO +~~ROW COUNT: 1~~ + + +-- output clause with insert +declare @a int = 1 +declare @mytbl table(a int) +insert local_var_tst output inserted.id into @mytbl values (@a + 1) +select * from @mytbl +GO +~~ROW COUNT: 1~~ + +~~START~~ +int +2 +~~END~~ + + +-- output clause with delete +declare @a int = 1 +declare @mytbl table(a int) +delete local_var_tst output deleted.id into @mytbl where id = @a + 1 +select * from @mytbl +GO +~~ROW COUNT: 2~~ + +~~START~~ +int +2 +2 +~~END~~ + + +drop table dbo.local_var_tst +go + +create table local_var_tst_1 (a int, b int) +GO + +insert into local_var_tst_1 values (1,3), (2, 4) +go +~~ROW COUNT: 2~~ + + + +-- select test with multi-variable assignment +declare @a int = 0 +declare @b int = 0 +select @a += a, @b += b from local_var_tst_1 +select @a, @b +go +~~START~~ +int#!#int +3#!#7 +~~END~~ + + +declare @a int = 0 +declare @b int = 0 +select @a += a, @b += @a + b from local_var_tst_1 +select @a, @b +go +~~START~~ +int#!#int +3#!#11 +~~END~~ + + +declare @a int = 0 +declare @b int = 0 +select @a += a, @b += @a + ~b from local_var_tst_1 +select @a, @b +go +~~START~~ +int#!#int +3#!#-5 +~~END~~ + + +drop table local_var_tst_1 +go + +create table local_var_str_tst (id varchar(100)) +GO + +insert into local_var_str_tst values ('abc'), (' '), ('def') +GO +~~ROW COUNT: 3~~ + + +declare @i varchar(1000) +set @i = '' +select @i = @i + id from local_var_str_tst +select @i +go +~~START~~ +varchar +abc def +~~END~~ + + +declare @i varchar(1000) +set @i = '' +select @i = id + @i from local_var_str_tst +select @i +go +~~START~~ +varchar +def abc +~~END~~ + + +declare @i varchar(1000) +set @i = '' +select @i += id from local_var_str_tst +select @i +go +~~START~~ +varchar +abc def +~~END~~ + + +declare @i varchar(1000) +set @i = '' +select @i = reverse(@i + 'id') from local_var_str_tst +select @i +go +~~START~~ +varchar +didiid +~~END~~ + + +declare @i varchar(1000) +set @i = '' +select @i += reverse(id) from local_var_str_tst +select @i +go +~~START~~ +varchar +cba fed +~~END~~ + + +declare @i varchar(1000) +set @i = 'abc' +select @i = reverse(@i) +select @i +go +~~START~~ +varchar +cba +~~END~~ + + +-- function call like trim, ltrim, etc will be rewritten by ANTLR +declare @i varchar(1000) +set @i = ' ' +select @i += id from local_var_str_tst +select len(@i), @i +select @i = trim(@i) +select len(@i), @i +go +~~START~~ +int#!#varchar +8#!# abc def +~~END~~ + +~~START~~ +int#!#varchar +7#!#abc def +~~END~~ + + +drop table local_var_str_tst; +go + +-- $PARTITION is rewritten by ANTLR +CREATE PARTITION FUNCTION RangePF1 ( INT ) +AS RANGE RIGHT FOR VALUES (10, 100, 1000) ; +GO + +declare @res int = -1; +SELECT @res = $PARTITION.RangePF1 (10); +select @res +select 1 where @res = $PARTITION.RangePF1 (10); +SELECT @res = $PARTITION.RangePF1 (@res); +select @res +GO +~~START~~ +int +2 +~~END~~ + +~~START~~ +int +1 +~~END~~ + +~~START~~ +int +1 +~~END~~ + + +DROP PARTITION FUNCTION RangePF1 +GO + +CREATE SEQUENCE CountBy1 + START WITH 1 + INCREMENT BY 1 ; +GO + +-- NEXT VALUE FOR gets re-written by ANTLR +DECLARE @myvar1 BIGINT = NEXT VALUE FOR CountBy1 ; +DECLARE @myvar2 BIGINT ; +DECLARE @myvar3 BIGINT ; +select @myvar2 = NEXT VALUE FOR CountBy1 ; +SELECT @myvar3 = NEXT VALUE FOR CountBy1 ; +SELECT @myvar1 AS myvar1, @myvar2 AS myvar2, @myvar3 AS myvar3 ; +GO +~~START~~ +bigint#!#bigint#!#bigint +1#!#2#!#3 +~~END~~ + + +DROP SEQUENCE CountBy1 +GO + +-- any @@ is also re-written by ANTLR +declare @pid int = 0 +select @pid += @@spid +select 1 where @pid = @@spid +go +~~START~~ +int +1 +~~END~~ + + +-- float point notation also gets rewritten by ANTLR e.g., 2.1E, -.2e+, -2.e- +declare @a float = 0 +select @a = 2.1E +select @a +select @a = -.2e+ +select @a +select @a = -2.e- +select @a +go +~~START~~ +float +2.1 +~~END~~ + +~~START~~ +float +-0.2 +~~END~~ + +~~START~~ +float +-2.0 +~~END~~ + + +-- variables only in select target list shows dynamic behavior +create table local_var_tst (id int) +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +insert into local_var_tst values (1) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +declare @i int = 1 +declare @j int = 0 +select @j += id, @i = id + 1 from local_var_tst where id = @i +select @i, @j +go +~~START~~ +int#!#int +2#!#2 +~~END~~ + + +declare @i int = 1 +select @i = id * 2 from local_var_tst where id = @i +select @i +GO +~~START~~ +int +2 +~~END~~ + + +select set_config('babelfishpg_tsql.explain_timing', 'off', false); +GO +~~START~~ +text +off +~~END~~ + + +select set_config('babelfishpg_tsql.explain_summary', 'off', false); +GO +~~START~~ +text +off +~~END~~ + + +set babelfish_statistics profile On; +GO + +declare @i int = 1 +declare @j int = 0 +select @j += id, @i = id + 1 from local_var_tst where id = @i +select @i, @j +go +~~START~~ +text +Query Text: select sys.pltsql_assign_var(3, @j + cast((id) as int)), sys.pltsql_assign_var(2, cast((id + 1) as int)) from local_var_tst where id = "@i" +Seq Scan on local_var_tst (cost=0.00..42.01 rows=13 width=8) (actual rows=2 loops=1) + Filter: (id = 1) + Rows Removed by Filter: 1 +~~END~~ + +~~START~~ +int#!#int +2#!#2 +~~END~~ + +~~START~~ +text +Query Text: select "@i", "@j" +Gather (cost=0.00..0.01 rows=1 width=8) (actual rows=1 loops=1) + Workers Planned: 1 + Workers Launched: 1 + Single Copy: true + -> Result (cost=0.00..0.01 rows=1 width=8) (actual rows=1 loops=1) +~~END~~ + + +declare @i int = 1 +select @i = @i * 2 from local_var_tst where id = @i +select @i +GO +~~START~~ +text +Query Text: select sys.pltsql_assign_var(2, cast((@i * 2) as int)) from local_var_tst where id = "@i" +Seq Scan on local_var_tst (cost=0.00..41.94 rows=13 width=4) (actual rows=2 loops=1) + Filter: (id = 1) + Rows Removed by Filter: 1 +~~END~~ + +~~START~~ +int +4 +~~END~~ + +~~START~~ +text +Query Text: select "@i" +Gather (cost=0.00..0.01 rows=1 width=4) (actual rows=1 loops=1) + Workers Planned: 1 + Workers Launched: 1 + Single Copy: true + -> Result (cost=0.00..0.01 rows=1 width=4) (actual rows=1 loops=1) +~~END~~ + + +set babelfish_statistics profile OFF +GO + +select set_config('babelfishpg_tsql.explain_timing', 'on', false); +GO +~~START~~ +text +on +~~END~~ + + +select set_config('babelfishpg_tsql.explain_summary', 'on', false); +GO +~~START~~ +text +on +~~END~~ + + +-- declared variable name with length > 63 +declare @abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr int = 1 +select @abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr += 1 +select @abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr +GO +~~START~~ +int +2 +~~END~~ + + +-- variable names starting with @@ +declare @@a int = 1; +select @@a = @@a + 1 +select @@a +GO +~~START~~ +int +2 +~~END~~ + + +declare @@a int = 1; +select @@a += 1 +select @@a +GO +~~START~~ +int +2 +~~END~~ + + +declare @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr int = 1 +select @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr = @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr + 1 +select @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr +GO +~~START~~ +int +2 +~~END~~ + + +truncate table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +insert into local_var_tst values (1) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +declare @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr int = 1 +select @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr = @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr + id from local_var_tst +select @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr +GO +~~START~~ +int +5 +~~END~~ + + +declare @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr int = 1 +select @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr = id + @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr from local_var_tst +select @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr +GO +~~START~~ +int +5 +~~END~~ + + +declare @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr int = 1 +select @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr += id from local_var_tst +select @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr +GO +~~START~~ +int +5 +~~END~~ + + +truncate table local_var_tst +GO + +insert into local_var_tst values (1) +GO +~~ROW COUNT: 1~~ + + +select set_config('babelfishpg_tsql.explain_timing', 'off', false); +GO +~~START~~ +text +off +~~END~~ + + +select set_config('babelfishpg_tsql.explain_summary', 'off', false); +GO +~~START~~ +text +off +~~END~~ + + +set babelfish_statistics profile On; +GO + +-- error while evaluating const expression +declare @a int = 1; +select @a = 1 / 0 from local_var_tst +select * from local_var_tst where id = @a +GO +~~ERROR (Code: 8134)~~ + +~~ERROR (Message: division by zero)~~ + +~~START~~ +int +1 +~~END~~ + +~~START~~ +text +Query Text: select * from local_var_tst where id = "@a" +Gather (cost=0.00..20.28 rows=13 width=4) (actual rows=1 loops=1) + Workers Planned: 3 + Workers Launched: 3 + -> Parallel Seq Scan on local_var_tst (cost=0.00..20.28 rows=4 width=4) (actual rows=0 loops=4) + Filter: (id = 1) +~~END~~ + + +set babelfish_statistics profile OFF +GO + +select set_config('babelfishpg_tsql.explain_timing', 'on', false); +GO +~~START~~ +text +on +~~END~~ + + +select set_config('babelfishpg_tsql.explain_summary', 'on', false); +GO +~~START~~ +text +on +~~END~~ + + +drop table local_var_tst +GO + +create table ident_tst(id_num INT IDENTITY(1, 1), b varchar(10)) +GO + +insert into ident_tst values ('test') +GO +~~ROW COUNT: 1~~ + + +declare @a int = 1 +select @a = @@IDENTITY +select @a +select 1 where @a = @@IDENTITY +GO +~~START~~ +int +1 +~~END~~ + +~~START~~ +int +1 +~~END~~ + + +-- additional testing for update with dynamic variables +GO + +create table local_var_tst (id int) +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + + +set QUOTED_IDENTIFIER on +GO + +declare @i varchar(100) +update local_var_tst set id = id + 10, @i = cast("xmax" as varchar(100)) +select 1 where @i IS NOT NULL +GO +~~ROW COUNT: 2~~ + +~~START~~ +int +1 +~~END~~ + + +set QUOTED_IDENTIFIER off +GO + +select * from local_var_tst order by id; +GO +~~START~~ +int +11 +12 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +-- long identifier with update +declare @incnjkdncjknxdjnkxnknvjkdfjvbdfbvjbdfhjbvjdbfvkjbdnjnlkanjfnvjnjfdlsahdnuejncdiebnjcnjksndjnjxndjcx int +update local_var_tst set id =10, @incnjkdncjknxdjnkxnknvjkdfjvbdfbvjbdfhjbvjdbfvkjbdnjnlkanjfnvjnjfdlsahdnuejncdiebnjcnjksndjnjxndjcx = id +select @incnjkdncjknxdjnkxnknvjkdfjvbdfbvjbdfhjbvjdbfvkjbdnjnlkanjfnvjnjfdlsahdnuejncdiebnjcnjksndjnjxndjcx +GO +~~ROW COUNT: 2~~ + +~~START~~ +int +10 +~~END~~ + + +select * from local_var_tst +GO +~~START~~ +int +10 +10 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +-- @@ variables +declare @@incnjkdnc int +update local_var_tst set id =10, @@incnjkdnc = id +select @@incnjkdnc +GO +~~ROW COUNT: 2~~ + +~~START~~ +int +10 +~~END~~ + + +select * from local_var_tst +GO +~~START~~ +int +10 +10 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +declare @i int +update local_var_tst set id = id + 2, @i = id * 5; +select @i +GO +~~ROW COUNT: 2~~ + +~~START~~ +int +20 +~~END~~ + + +select * from local_var_tst order by id; +GO +~~START~~ +int +3 +4 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +declare @i int, @j int; +update local_var_tst set id =10, @i = case when @j =0 then 1 else 0 end; +select @i, @j +go +~~ROW COUNT: 2~~ + +~~START~~ +int#!#int +0#!# +~~END~~ + + +select * from local_var_tst; +GO +~~START~~ +int +10 +10 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +declare @i int, @j int; +update local_var_tst set id = 10, @j = id, @i = case when @j =0 then 1 else 0 end; +select @i, @j +go +~~ROW COUNT: 2~~ + +~~START~~ +int#!#int +0#!#10 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +declare @i int, @j int = 0 +update local_var_tst set id =10, @i = charindex('a','a',@j) +select @i +GO +~~ROW COUNT: 2~~ + +~~START~~ +int +1 +~~END~~ + + +select * from local_var_tst; +GO +~~START~~ +int +10 +10 +~~END~~ + + +declare @i int, @j int = 0 +update local_var_tst set id =10, @i = charindex('a','a',@j); +select @i +GO +~~ROW COUNT: 2~~ + +~~START~~ +int +1 +~~END~~ + + +select * from local_var_tst; +GO +~~START~~ +int +10 +10 +~~END~~ + + +declare @i int, @j int; +update local_var_tst set id = 10, @j = id, @i = @j * 2 +select @i, @j +go +~~ROW COUNT: 2~~ + +~~START~~ +int#!#int +20#!#10 +~~END~~ + + +select * from local_var_tst; +GO +~~START~~ +int +10 +10 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +declare @i int = 1 +update local_var_tst set id = @i, @i = id * 2 where id = @i +select @i +GO +~~ROW COUNT: 1~~ + +~~START~~ +int +2 +~~END~~ + + +select * from local_var_tst +go +~~START~~ +int +2 +1 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +declare @i int = 1 +update local_var_tst set id = @i, @i += id * 2 where id = @i +select @i +GO +~~ROW COUNT: 1~~ + +~~START~~ +int +3 +~~END~~ + + +select * from local_var_tst +go +~~START~~ +int +2 +1 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +declare @i VARCHAR(200) = '' +update local_var_tst set id = id * 2, @i = @i + cast(id as varchar(20)) +select @i +GO +~~ROW COUNT: 2~~ + +~~START~~ +varchar +24 +~~END~~ + + +select * from local_var_tst order by id +go +~~START~~ +int +2 +4 +~~END~~ + + +-- @i should be NULL as no row passes the qual condition +declare @i int +update local_var_tst set id =10, @i = id * 5 where id = 1 +select @i +GO +~~START~~ +int + +~~END~~ + + +select * from local_var_tst order by id +go +~~START~~ +int +2 +4 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + + +declare @i int = 1 +update local_var_tst set id = @i, @i = id * 5 where id = @i +select @i +GO +~~ROW COUNT: 1~~ + +~~START~~ +int +5 +~~END~~ + + +select * from local_var_tst order by id +go +~~START~~ +int +1 +2 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +declare @i int +set @i = 0 +update local_var_tst set id = @i, @i = id * 5 +select @i +GO +~~ROW COUNT: 2~~ + +~~START~~ +int +0 +~~END~~ + + +select * from local_var_tst; +GO +~~START~~ +int +0 +0 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +-- trim is re-written by antlr +declare @i varchar(200) +select @i = '' +update local_var_tst set id = @i, @i = TRIM(@i + cast(id as varchar(10))); +select @i +GO +~~ROW COUNT: 2~~ + +~~START~~ +varchar +00 +~~END~~ + + +select * from local_var_tst; +GO +~~START~~ +int +0 +0 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + + +-- variables in the where clause should be treated as const +declare @i int = 1; +update local_var_tst set id = @i * 100, @i = id * 2 where id = @i +select @i +GO +~~ROW COUNT: 1~~ + +~~START~~ +int +200 +~~END~~ + + +select * from local_var_tst order by id; +GO +~~START~~ +int +2 +100 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +declare @i int = 1; +update local_var_tst set id = @i * 100, @i = @@IDENTITY +select @i +select 1 where @i = @@IDENTITY +GO +~~ROW COUNT: 2~~ + +~~START~~ +int +1 +~~END~~ + +~~START~~ +int +1 +~~END~~ + + +select * from local_var_tst +GO +~~START~~ +int +100 +100 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +CREATE PARTITION FUNCTION RangePF1 ( INT ) +AS RANGE RIGHT FOR VALUES (10, 100, 1000) ; +GO + +declare @i int = -1; +SELECT @i = $PARTITION.RangePF1 (10); +select @i +update local_var_tst set id = @i, @i = $PARTITION.RangePF1 (10); +select @i +GO +~~START~~ +int +2 +~~END~~ + +~~ROW COUNT: 2~~ + +~~START~~ +int +2 +~~END~~ + + +select * from local_var_tst; +GO +~~START~~ +int +2 +2 +~~END~~ + + +DROP PARTITION FUNCTION RangePF1 +GO + +CREATE PROCEDURE var_with_procedure (@i int, @a numeric(10,4) OUTPUT) AS +BEGIN + update local_var_tst set id = @i * 2, @a = id * 5 where id = @i + select @a +END; +GO + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +declare @input int = 1, @res int; +exec var_with_procedure @input, @res +select @res +GO +~~ROW COUNT: 1~~ + +~~START~~ +numeric +10.0000 +~~END~~ + +~~START~~ +int + +~~END~~ + + +select * from local_var_tst +go +~~START~~ +int +2 +2 +~~END~~ + + +declare @input int = 2, @a int; +exec var_with_procedure @input, @a +select @a +GO +~~ROW COUNT: 2~~ + +~~START~~ +numeric +20.0000 +~~END~~ + +~~START~~ +int + +~~END~~ + + +DROP PROCEDURE var_with_procedure; +GO + +DROP TABLE local_var_tst +GO + +create table local_var_tst_1 (id int) +GO + +insert into local_var_tst_1 values (1) +insert into local_var_tst_1 values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +create unique index idx_local_var_tst_1 on local_var_tst_1(id) +GO + + +SELECT set_config('enable_indexscan', '1', false); +SELECT set_config('enable_indexonlyscan', '0', false); +SELECT set_config('enable_seqscan', '0', false); +GO +~~START~~ +text +on +~~END~~ + +~~START~~ +text +off +~~END~~ + +~~START~~ +text +off +~~END~~ + + +declare @i int = 1 +update local_var_tst_1 set id = @i, @i = id * 5 where id = 1 +select @i +GO +~~ROW COUNT: 1~~ + +~~START~~ +int +5 +~~END~~ + + +declare @i int = 1 +update local_var_tst_1 set id = 10 output deleted.id where id = 1 +select @i +GO +~~START~~ +int +1 +~~END~~ + +~~START~~ +int +1 +~~END~~ + + +SELECT set_config('enable_indexscan', '1', false); +SELECT set_config('enable_indexonlyscan', '1', false); +SELECT set_config('enable_seqscan', '1', false); +GO +~~START~~ +text +on +~~END~~ + +~~START~~ +text +on +~~END~~ + +~~START~~ +text +on +~~END~~ + + +DROP TABLE local_var_tst_1 +GO + +CREATE TABLE update_test_tbl ( + age int, + fname char(10), + lname char(10), + city nchar(20) +) +GO + +TRUNCATE TABLE update_test_tbl +GO + +INSERT INTO update_test_tbl(age, fname, lname, city) +VALUES (50, 'fname1', 'lname1', 'london'), + (34, 'fname2', 'lname2', 'paris'), + (35, 'fname3', 'lname3', 'brussels'), + (90, 'fname4', 'lname4', 'new york'), + (26, 'fname5', 'lname5', 'los angeles'), + (74, 'fname6', 'lname6', 'tokyo'), + (44, 'fname7', 'lname7', 'oslo'), + (19, 'fname8', 'lname8', 'hong kong'), + (61, 'fname9', 'lname9', 'shanghai'), + (29, 'fname10', 'lname10', 'mumbai') +GO +~~ROW COUNT: 10~~ + + +CREATE TABLE update_test_tbl2 ( + year int, + lname char(10), +) +GO + +TRUNCATE TABLE update_test_tbl2 +GO + +INSERT INTO update_test_tbl2(year, lname) +VALUES (51, 'lname1'), + (34, 'lname3'), + (25, 'lname8'), + (95, 'lname9'), + (36, 'lname10') +GO +~~ROW COUNT: 5~~ + + +UPDATE update_test_tbl SET fname = 'fname13' +FROM update_test_tbl t1 +INNER JOIN update_test_tbl2 t2 +ON t1.lname = t2.lname +WHERE year > 50 +GO +~~ROW COUNT: 2~~ + + +declare @a varchar(4000) = ''; +UPDATE update_test_tbl SET fname = 'fname13', @a = @a + fname +FROM update_test_tbl t1 +INNER JOIN update_test_tbl2 t2 +ON t1.lname = t2.lname +WHERE year > 50 +select @a +GO +~~ROW COUNT: 2~~ + +~~START~~ +varchar +fname13 fname13 +~~END~~ + + +DROP TABLE update_test_tbl2; +GO + +DROP TABLE update_test_tbl +GO + +drop table ident_tst +GO + +create table local_var_tst (id int) +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +declare @i int = 0, @j int +update local_var_tst set id = id + 2, @i = id, @j = @i * 2, @i = @j +select @i, @j +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Babelfish does not support assignment to the same variable in SELECT. variable name: "@i")~~ + + +declare @i int = 0, @j int +update local_var_tst set id = id + 2, @i += id, @j = @i * 2 +select @i, @j +GO +~~ROW COUNT: 2~~ + +~~START~~ +int#!#int +7#!#14 +~~END~~ + + +select * from local_var_tst order by id +GO +~~START~~ +int +3 +4 +~~END~~ + + +drop table local_var_tst +GO diff --git a/test/JDBC/expected/parallel_query/with_recompile-vu-verify.out b/test/JDBC/expected/parallel_query/with_recompile-vu-verify.out index a858e9c8e4..a6d7e55d26 100644 --- a/test/JDBC/expected/parallel_query/with_recompile-vu-verify.out +++ b/test/JDBC/expected/parallel_query/with_recompile-vu-verify.out @@ -115,7 +115,7 @@ Query Text: EXEC p_recomp_11 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 156.798 ms +Babelfish T-SQL Batch Parsing Time: 197.649 ms ~~END~~ set babelfish_showplan_all off @@ -205,7 +205,7 @@ Query Text: EXEC p_recomp_12 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.187 ms +Babelfish T-SQL Batch Parsing Time: 0.261 ms ~~END~~ set babelfish_showplan_all off @@ -256,7 +256,7 @@ Query Text: EXEC p_recomp_11 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 3.990 ms +Babelfish T-SQL Batch Parsing Time: 7.061 ms ~~END~~ exec p_recomp_12 0 with recompile @@ -282,7 +282,7 @@ Query Text: EXEC p_recomp_12 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.096 ms +Babelfish T-SQL Batch Parsing Time: 0.173 ms ~~END~~ set babelfish_showplan_all off @@ -314,7 +314,7 @@ Query Text: EXEC p_recomp_12 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 2.406 ms +Babelfish T-SQL Batch Parsing Time: 4.194 ms ~~END~~ set babelfish_showplan_all off @@ -349,7 +349,7 @@ Query Text: EXEC p_recomp_11 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.875 ms +Babelfish T-SQL Batch Parsing Time: 1.439 ms ~~END~~ -- test case without execute keyword @@ -376,7 +376,7 @@ Query Text: EXEC p_recomp_11 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.102 ms +Babelfish T-SQL Batch Parsing Time: 0.165 ms ~~END~~ set babelfish_showplan_all off @@ -411,7 +411,7 @@ Query Text: EXEC p_recomp_13 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.226 ms +Babelfish T-SQL Batch Parsing Time: 0.395 ms ~~END~~ exec p_recomp_13 0 with recompile @@ -439,7 +439,7 @@ Query Text: EXEC p_recomp_13 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.085 ms +Babelfish T-SQL Batch Parsing Time: 0.145 ms ~~END~~ set babelfish_showplan_all off @@ -545,7 +545,7 @@ Query Text: EXEC p_recomp_11 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.114 ms +Babelfish T-SQL Batch Parsing Time: 0.133 ms ~~END~~ exec p_recomp_12 0 with recompile @@ -569,7 +569,7 @@ Query Text: EXEC p_recomp_12 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.113 ms +Babelfish T-SQL Batch Parsing Time: 0.174 ms ~~END~~ set babelfish_showplan_all off @@ -600,7 +600,7 @@ Query Text: EXEC p_recomp_12 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.068 ms +Babelfish T-SQL Batch Parsing Time: 0.117 ms ~~END~~ set babelfish_showplan_all off @@ -633,7 +633,7 @@ Query Text: EXEC p_recomp_13 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.074 ms +Babelfish T-SQL Batch Parsing Time: 0.126 ms ~~END~~ set babelfish_showplan_all off @@ -668,7 +668,7 @@ Query Text: EXEC p_recomp_13 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.063 ms +Babelfish T-SQL Batch Parsing Time: 0.109 ms ~~END~~ exec p_recomp_13 0 with recompile @@ -694,7 +694,7 @@ Query Text: EXEC p_recomp_13 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.080 ms +Babelfish T-SQL Batch Parsing Time: 0.127 ms ~~END~~ set babelfish_showplan_all off @@ -753,7 +753,7 @@ Query Text: EXEC p_recomp_21 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.291 ms +Babelfish T-SQL Batch Parsing Time: 0.470 ms ~~END~~ set babelfish_showplan_all off @@ -803,7 +803,7 @@ Query Text: EXEC p_recomp_21 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.105 ms +Babelfish T-SQL Batch Parsing Time: 0.179 ms ~~END~~ @@ -834,7 +834,7 @@ Query Text: EXEC p_recomp_22 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.243 ms +Babelfish T-SQL Batch Parsing Time: 0.469 ms ~~END~~ set babelfish_showplan_all off @@ -869,7 +869,7 @@ Query Text: EXEC p_recomp_22 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.067 ms +Babelfish T-SQL Batch Parsing Time: 0.124 ms ~~END~~ set babelfish_showplan_all off @@ -917,7 +917,7 @@ Query Text: EXEC p_recomp_21 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.083 ms +Babelfish T-SQL Batch Parsing Time: 0.183 ms ~~END~~ @@ -946,7 +946,7 @@ Query Text: EXEC p_recomp_22 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.080 ms +Babelfish T-SQL Batch Parsing Time: 0.139 ms ~~END~~ set babelfish_showplan_all off @@ -981,7 +981,7 @@ Query Text: EXEC p_recomp_22 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.063 ms +Babelfish T-SQL Batch Parsing Time: 0.100 ms ~~END~~ set babelfish_showplan_all off @@ -1038,7 +1038,7 @@ Query Text: EXEC p_recomp_31 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.304 ms +Babelfish T-SQL Batch Parsing Time: 0.318 ms ~~END~~ set babelfish_showplan_all off @@ -1089,7 +1089,7 @@ Query Text: EXEC p_recomp_31 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.099 ms +Babelfish T-SQL Batch Parsing Time: 0.123 ms ~~END~~ @@ -1120,7 +1120,7 @@ Query Text: EXEC p_recomp_32 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.232 ms +Babelfish T-SQL Batch Parsing Time: 0.404 ms ~~END~~ set babelfish_showplan_all off @@ -1155,7 +1155,7 @@ Query Text: EXEC p_recomp_32 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.071 ms +Babelfish T-SQL Batch Parsing Time: 0.116 ms ~~END~~ set babelfish_showplan_all off @@ -1190,7 +1190,7 @@ Query Text: EXEC p_recomp_33 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.219 ms +Babelfish T-SQL Batch Parsing Time: 0.370 ms ~~END~~ --- tb_recomp_33: with RECOMPILE: bitmap scans ---- @@ -1220,7 +1220,7 @@ Query Text: EXEC p_recomp_33 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.078 ms +Babelfish T-SQL Batch Parsing Time: 0.126 ms ~~END~~ set babelfish_showplan_all off @@ -1268,7 +1268,7 @@ Query Text: EXEC p_recomp_31 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.084 ms +Babelfish T-SQL Batch Parsing Time: 0.124 ms ~~END~~ --- p_recomp_32: EXEC with RECOMPILE: recompiled plan: index scan for paramtrized, bitmap scan for non-parametrized ---- @@ -1296,7 +1296,7 @@ Query Text: EXEC p_recomp_32 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.077 ms +Babelfish T-SQL Batch Parsing Time: 0.106 ms ~~END~~ set babelfish_showplan_all off @@ -1329,7 +1329,7 @@ Query Text: EXEC p_recomp_32 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.064 ms +Babelfish T-SQL Batch Parsing Time: 0.070 ms ~~END~~ set babelfish_showplan_all off @@ -1362,7 +1362,7 @@ Query Text: EXEC p_recomp_33 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.072 ms +Babelfish T-SQL Batch Parsing Time: 0.079 ms ~~END~~ set babelfish_showplan_all off @@ -1395,7 +1395,7 @@ Query Text: EXEC p_recomp_33 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.070 ms +Babelfish T-SQL Batch Parsing Time: 0.068 ms ~~END~~ --- tb_recomp_33 with RECOMPILE: index scan for paramtrized stmt, bitmap scan for non-param stmt ---- @@ -1423,7 +1423,7 @@ Query Text: EXEC p_recomp_33 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.076 ms +Babelfish T-SQL Batch Parsing Time: 0.150 ms ~~END~~ set babelfish_showplan_all off @@ -1608,7 +1608,7 @@ Query Text: EXEC p_recomp_61 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.213 ms +Babelfish T-SQL Batch Parsing Time: 0.161 ms ~~END~~ set babelfish_showplan_all off @@ -1675,7 +1675,7 @@ Query Text: EXEC p_recomp_61 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.117 ms +Babelfish T-SQL Batch Parsing Time: 0.142 ms ~~END~~ set babelfish_showplan_all off @@ -1724,7 +1724,7 @@ Query Text: EXEC p_recomp_61 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.206 ms +Babelfish T-SQL Batch Parsing Time: 0.319 ms ~~END~~ set babelfish_showplan_all off @@ -1787,7 +1787,7 @@ Query Text: EXEC p_recomp_61 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.110 ms +Babelfish T-SQL Batch Parsing Time: 0.149 ms ~~END~~ set babelfish_showplan_all off @@ -1832,7 +1832,7 @@ Query Text: EXEC p_recomp_61 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.116 ms +Babelfish T-SQL Batch Parsing Time: 0.142 ms ~~END~~ set babelfish_showplan_all off @@ -2317,7 +2317,7 @@ Query Text: EXEC p_recomp_51 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.118 ms +Babelfish T-SQL Batch Parsing Time: 0.113 ms ~~END~~ set babelfish_showplan_all off @@ -2453,7 +2453,7 @@ Query Text: EXEC p_recomp_51 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.111 ms +Babelfish T-SQL Batch Parsing Time: 0.110 ms ~~END~~ set babelfish_showplan_all off @@ -2574,7 +2574,7 @@ Query Text: EXEC p_recomp_51 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.104 ms +Babelfish T-SQL Batch Parsing Time: 0.157 ms ~~END~~ set babelfish_showplan_all off @@ -2701,7 +2701,7 @@ Query Text: EXEC p_recomp_51 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.090 ms +Babelfish T-SQL Batch Parsing Time: 0.111 ms ~~END~~ set babelfish_showplan_all off @@ -2811,7 +2811,7 @@ Query Text: EXEC p_recomp_51 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.095 ms +Babelfish T-SQL Batch Parsing Time: 0.152 ms ~~END~~ set babelfish_showplan_all off diff --git a/test/JDBC/expected/replicate-before-15_8-or-16_4-vu-verify.out b/test/JDBC/expected/replicate-before-15_8-or-16_4-vu-verify.out index f8b8073613..bb4e129853 100644 --- a/test/JDBC/expected/replicate-before-15_8-or-16_4-vu-verify.out +++ b/test/JDBC/expected/replicate-before-15_8-or-16_4-vu-verify.out @@ -601,6 +601,8 @@ abc🙂defghi🙂🙂abc🙂defghi🙂🙂abc🙂defghi🙂🙂abc🙂defghi🙂 DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT replicate(@inputString, 4) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of replicate function.)~~ @@ -609,6 +611,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT replicate(@inputString, 4) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of replicate function.)~~ @@ -617,6 +621,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT replicate(@inputString, 4) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of replicate function.)~~ @@ -625,6 +631,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT replicate(@inputString, 4) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of replicate function.)~~ diff --git a/test/JDBC/expected/replicate-vu-verify.out b/test/JDBC/expected/replicate-vu-verify.out index f454fa22a1..a38a5b2f1b 100644 --- a/test/JDBC/expected/replicate-vu-verify.out +++ b/test/JDBC/expected/replicate-vu-verify.out @@ -601,6 +601,8 @@ abc🙂defghi🙂🙂abc🙂defghi🙂🙂abc🙂defghi🙂🙂abc🙂defghi🙂 DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT replicate(@inputString, 4) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of replicate function.)~~ @@ -609,6 +611,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT replicate(@inputString, 4) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of replicate function.)~~ @@ -617,6 +621,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT replicate(@inputString, 4) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of replicate function.)~~ @@ -625,6 +631,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT replicate(@inputString, 4) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of replicate function.)~~ diff --git a/test/JDBC/expected/reverse-before-15_8-or-16_4-vu-verify.out b/test/JDBC/expected/reverse-before-15_8-or-16_4-vu-verify.out index e9ab22a861..cba16a2330 100644 --- a/test/JDBC/expected/reverse-before-15_8-or-16_4-vu-verify.out +++ b/test/JDBC/expected/reverse-before-15_8-or-16_4-vu-verify.out @@ -545,6 +545,8 @@ nvarchar DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT reverse(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of reverse function.)~~ @@ -553,6 +555,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT reverse(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of reverse function.)~~ @@ -561,6 +565,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT reverse(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of reverse function.)~~ @@ -569,6 +575,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT reverse(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of reverse function.)~~ diff --git a/test/JDBC/expected/reverse-vu-verify.out b/test/JDBC/expected/reverse-vu-verify.out index 3687359bdb..d5ed62036e 100644 --- a/test/JDBC/expected/reverse-vu-verify.out +++ b/test/JDBC/expected/reverse-vu-verify.out @@ -545,6 +545,8 @@ nvarchar DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT reverse(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of reverse function.)~~ @@ -553,6 +555,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT reverse(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of reverse function.)~~ @@ -561,6 +565,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT reverse(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of reverse function.)~~ @@ -569,6 +575,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT reverse(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of reverse function.)~~ diff --git a/test/JDBC/expected/right-before-15_8-or-16_4-vu-verify.out b/test/JDBC/expected/right-before-15_8-or-16_4-vu-verify.out index 47d6111894..1f86fb7009 100644 --- a/test/JDBC/expected/right-before-15_8-or-16_4-vu-verify.out +++ b/test/JDBC/expected/right-before-15_8-or-16_4-vu-verify.out @@ -659,6 +659,8 @@ ghi🙂🙂 DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT RIGHT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of right function.)~~ @@ -667,6 +669,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT RIGHT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of right function.)~~ @@ -675,6 +679,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT RIGHT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of right function.)~~ @@ -683,6 +689,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT RIGHT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of right function.)~~ diff --git a/test/JDBC/expected/right-vu-verify.out b/test/JDBC/expected/right-vu-verify.out index 8f10999211..3a868d57c2 100644 --- a/test/JDBC/expected/right-vu-verify.out +++ b/test/JDBC/expected/right-vu-verify.out @@ -659,6 +659,8 @@ ghi🙂🙂 DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT RIGHT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of right function.)~~ @@ -667,6 +669,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT RIGHT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of right function.)~~ @@ -675,6 +679,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT RIGHT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of right function.)~~ @@ -683,6 +689,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT RIGHT(@inputString, 3) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of right function.)~~ diff --git a/test/JDBC/expected/rtrim-before-15_8-or-16_4-vu-verify.out b/test/JDBC/expected/rtrim-before-15_8-or-16_4-vu-verify.out index 7c34054485..a762e62843 100644 --- a/test/JDBC/expected/rtrim-before-15_8-or-16_4-vu-verify.out +++ b/test/JDBC/expected/rtrim-before-15_8-or-16_4-vu-verify.out @@ -553,6 +553,8 @@ nvarchar DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT RTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of rtrim function.)~~ @@ -561,6 +563,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT RTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of rtrim function.)~~ @@ -569,6 +573,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT RTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of rtrim function.)~~ @@ -577,6 +583,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT RTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of rtrim function.)~~ diff --git a/test/JDBC/expected/rtrim-vu-verify.out b/test/JDBC/expected/rtrim-vu-verify.out index 0a1d5f8203..5eab13350c 100644 --- a/test/JDBC/expected/rtrim-vu-verify.out +++ b/test/JDBC/expected/rtrim-vu-verify.out @@ -553,6 +553,8 @@ nvarchar DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT RTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of rtrim function.)~~ @@ -561,6 +563,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT RTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of rtrim function.)~~ @@ -569,6 +573,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT RTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of rtrim function.)~~ @@ -577,6 +583,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT RTRIM(@inputString) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of rtrim function.)~~ diff --git a/test/JDBC/expected/single_db/TestSpatialPoint-vu-verify.out b/test/JDBC/expected/single_db/TestSpatialPoint-vu-verify.out index 352d3f6fb3..e82d355fd2 100644 --- a/test/JDBC/expected/single_db/TestSpatialPoint-vu-verify.out +++ b/test/JDBC/expected/single_db/TestSpatialPoint-vu-verify.out @@ -223,6 +223,8 @@ SET @point1 = geometry::Point(22.34900, -47.65100, 4326);; SET @point2 = 'Test_String'; SELECT @point1.STDistance(@point2); Go +~~START~~ +float ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: parse error - invalid geometry)~~ @@ -2314,6 +2316,8 @@ SET @point1 = geography::Point(22.34900, -47.65100, 4326); SET @point2 = 'Test_String'; SELECT @point2.STDistance(@point1); Go +~~START~~ +float ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: parse error - invalid geometry)~~ diff --git a/test/JDBC/expected/substring-before-15_8-or-16_4-vu-verify.out b/test/JDBC/expected/substring-before-15_8-or-16_4-vu-verify.out index acae233ba0..9a859de1a5 100644 --- a/test/JDBC/expected/substring-before-15_8-or-16_4-vu-verify.out +++ b/test/JDBC/expected/substring-before-15_8-or-16_4-vu-verify.out @@ -251,6 +251,8 @@ varchar ~~END~~ +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -278,6 +280,8 @@ varchar ~~END~~ +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -305,6 +309,8 @@ varchar ~~END~~ +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -333,6 +339,8 @@ varchar ~~END~~ +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -360,6 +368,8 @@ varchar ~~END~~ +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -387,6 +397,8 @@ varchar ~~END~~ +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -517,6 +529,8 @@ nvarchar ~~END~~ +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -544,6 +558,8 @@ nvarchar ~~END~~ +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -582,6 +598,8 @@ nvarchar ~~END~~ +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -609,6 +627,8 @@ nvarchar ~~END~~ +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -637,6 +657,8 @@ varbinary ~~END~~ +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -665,6 +687,8 @@ varbinary ~~END~~ +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -798,6 +822,8 @@ de DECLARE @inputString date = '2016-12-21'; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type date is invalid for argument 1 of substring function.)~~ @@ -807,6 +833,8 @@ DECLARE @date date = '12-21-16'; DECLARE @inputString datetime = @date; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type datetime is invalid for argument 1 of substring function.)~~ @@ -815,6 +843,8 @@ GO DECLARE @inputString smalldatetime = '1955-12-13 12:43:10'; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type smalldatetime is invalid for argument 1 of substring function.)~~ @@ -823,6 +853,8 @@ GO DECLARE @inputString time(4) = '12:10:05.1237'; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type time is invalid for argument 1 of substring function.)~~ @@ -831,6 +863,8 @@ GO DECLARE @inputString datetimeoffset(4) = '1968-10-23 12:45:37.1234 +10:0'; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type datetimeoffset is invalid for argument 1 of substring function.)~~ @@ -839,6 +873,8 @@ GO DECLARE @inputString datetime2(4) = '1968-10-23 12:45:37.1237'; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type datetime2 is invalid for argument 1 of substring function.)~~ @@ -847,6 +883,8 @@ GO DECLARE @inputString decimal = 123456; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type decimal is invalid for argument 1 of substring function.)~~ @@ -855,6 +893,8 @@ GO DECLARE @inputString numeric = 12345.12; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type numeric is invalid for argument 1 of substring function.)~~ @@ -863,6 +903,8 @@ GO DECLARE @inputString float = 12345.1; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type float is invalid for argument 1 of substring function.)~~ @@ -871,6 +913,8 @@ GO DECLARE @inputString real = 12345.1; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type real is invalid for argument 1 of substring function.)~~ @@ -879,6 +923,8 @@ GO DECLARE @inputString bigint = 12345678; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type bigint is invalid for argument 1 of substring function.)~~ @@ -887,6 +933,8 @@ GO DECLARE @inputString int = 12345678; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type int is invalid for argument 1 of substring function.)~~ @@ -895,6 +943,8 @@ GO DECLARE @inputString smallint = 12356; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type smallint is invalid for argument 1 of substring function.)~~ @@ -903,6 +953,8 @@ GO DECLARE @inputString tinyint = 235; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type tinyint is invalid for argument 1 of substring function.)~~ @@ -911,6 +963,8 @@ GO DECLARE @inputString money = 12356; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type money is invalid for argument 1 of substring function.)~~ @@ -919,6 +973,8 @@ GO DECLARE @inputString smallmoney = 12356; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type smallmoney is invalid for argument 1 of substring function.)~~ @@ -927,6 +983,8 @@ GO DECLARE @inputString bit = 1; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type bit is invalid for argument 1 of substring function.)~~ @@ -935,6 +993,8 @@ GO DECLARE @inputString uniqueidentifier = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS uniqueidentifier) SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type uniqueidentifier is invalid for argument 1 of substring function.)~~ @@ -1056,6 +1116,8 @@ bc🙂defghi🙂🙂 DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of substring function.)~~ @@ -1064,6 +1126,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of substring function.)~~ @@ -1072,6 +1136,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of substring function.)~~ @@ -1080,6 +1146,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of substring function.)~~ diff --git a/test/JDBC/expected/substring-vu-verify.out b/test/JDBC/expected/substring-vu-verify.out index 7eac10f0fc..a56f4777b7 100644 --- a/test/JDBC/expected/substring-vu-verify.out +++ b/test/JDBC/expected/substring-vu-verify.out @@ -256,6 +256,8 @@ varchar DECLARE @inputString CHAR(25) = 'abc🙂defghi🙂🙂' SELECT substring(@inputString, 2, -1) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -296,6 +298,8 @@ varchar DECLARE @inputString CHAR(25) = '比尔·拉莫斯' SELECT substring(@inputString, 2, -1) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -336,6 +340,8 @@ varchar DECLARE @inputString CHAR(25) = '比尔·拉莫斯' SELECT substring(@inputString, 2, -1) COLLATE CHINESE_PRC_CI_AS GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -377,6 +383,8 @@ varchar DECLARE @inputString VARCHAR(25) = 'abc🙂defghi🙂🙂' SELECT substring(@inputString, 2, -1) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -417,6 +425,8 @@ varchar DECLARE @inputString VARCHAR(25) = '比尔·拉莫斯' SELECT substring(@inputString, 2, -1) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -457,6 +467,8 @@ varchar DECLARE @inputString VARCHAR(25) = '比尔·拉莫斯' SELECT substring(@inputString, 2, -1) COLLATE CHINESE_PRC_CI_AS GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -600,6 +612,8 @@ nvarchar DECLARE @inputString NCHAR(25) = N'abc🙂defghi🙂🙂' SELECT substring(@inputString, 2, -1) GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -640,6 +654,8 @@ nvarchar DECLARE @inputString NCHAR(25) = N'比尔·拉莫斯' SELECT substring(@inputString, 2, -1) GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -691,6 +707,8 @@ nvarchar DECLARE @inputString NVARCHAR(25) = N'abc🙂defghi🙂🙂' SELECT substring(@inputString, 2, -1) GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -731,6 +749,8 @@ nvarchar DECLARE @inputString NVARCHAR(25) = N'比尔·拉莫斯' SELECT substring(@inputString, 2, -1) GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -772,6 +792,8 @@ varbinary DECLARE @inputString BINARY(10) = 0x6162636465666768 SELECT substring(@inputString, 2, -1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -813,6 +835,8 @@ varbinary DECLARE @inputString VARBINARY(10) = 0x6162636465666768 SELECT substring(@inputString, 2, -1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: negative substring length not allowed)~~ @@ -954,6 +978,8 @@ de DECLARE @inputString date = '2016-12-21'; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type date is invalid for argument 1 of substring function.)~~ @@ -963,6 +989,8 @@ DECLARE @date date = '12-21-16'; DECLARE @inputString datetime = @date; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type datetime is invalid for argument 1 of substring function.)~~ @@ -971,6 +999,8 @@ GO DECLARE @inputString smalldatetime = '1955-12-13 12:43:10'; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type smalldatetime is invalid for argument 1 of substring function.)~~ @@ -979,6 +1009,8 @@ GO DECLARE @inputString time(4) = '12:10:05.1237'; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type time is invalid for argument 1 of substring function.)~~ @@ -987,6 +1019,8 @@ GO DECLARE @inputString datetimeoffset(4) = '1968-10-23 12:45:37.1234 +10:0'; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type datetimeoffset is invalid for argument 1 of substring function.)~~ @@ -995,6 +1029,8 @@ GO DECLARE @inputString datetime2(4) = '1968-10-23 12:45:37.1237'; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type datetime2 is invalid for argument 1 of substring function.)~~ @@ -1003,6 +1039,8 @@ GO DECLARE @inputString decimal = 123456; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type decimal is invalid for argument 1 of substring function.)~~ @@ -1011,6 +1049,8 @@ GO DECLARE @inputString numeric = 12345.12; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type numeric is invalid for argument 1 of substring function.)~~ @@ -1019,6 +1059,8 @@ GO DECLARE @inputString float = 12345.1; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type float is invalid for argument 1 of substring function.)~~ @@ -1027,6 +1069,8 @@ GO DECLARE @inputString real = 12345.1; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type real is invalid for argument 1 of substring function.)~~ @@ -1035,6 +1079,8 @@ GO DECLARE @inputString bigint = 12345678; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type bigint is invalid for argument 1 of substring function.)~~ @@ -1043,6 +1089,8 @@ GO DECLARE @inputString int = 12345678; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type int is invalid for argument 1 of substring function.)~~ @@ -1051,6 +1099,8 @@ GO DECLARE @inputString smallint = 12356; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type smallint is invalid for argument 1 of substring function.)~~ @@ -1059,6 +1109,8 @@ GO DECLARE @inputString tinyint = 235; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type tinyint is invalid for argument 1 of substring function.)~~ @@ -1067,6 +1119,8 @@ GO DECLARE @inputString money = 12356; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type money is invalid for argument 1 of substring function.)~~ @@ -1075,6 +1129,8 @@ GO DECLARE @inputString smallmoney = 12356; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type smallmoney is invalid for argument 1 of substring function.)~~ @@ -1083,6 +1139,8 @@ GO DECLARE @inputString bit = 1; SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type bit is invalid for argument 1 of substring function.)~~ @@ -1091,6 +1149,8 @@ GO DECLARE @inputString uniqueidentifier = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS uniqueidentifier) SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type uniqueidentifier is invalid for argument 1 of substring function.)~~ @@ -1212,6 +1272,8 @@ bc🙂defghi🙂🙂 DECLARE @inputString sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_variant) SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of substring function.)~~ @@ -1220,6 +1282,8 @@ GO DECLARE @inputString xml = CAST ('' AS xml) SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of substring function.)~~ @@ -1228,6 +1292,8 @@ GO DECLARE @inputString geometry = geometry::STGeomFromText('POINT (1 2)', 0); SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of substring function.)~~ @@ -1236,6 +1302,8 @@ GO DECLARE @inputString geography = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); SELECT substring(@inputString, 4, 1) GO +~~START~~ +varbinary ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geography is invalid for argument 1 of substring function.)~~ diff --git a/test/JDBC/expected/test_dynamic_local_vars.out b/test/JDBC/expected/test_dynamic_local_vars.out new file mode 100644 index 0000000000..82da9b4fd6 --- /dev/null +++ b/test/JDBC/expected/test_dynamic_local_vars.out @@ -0,0 +1,2456 @@ +-- simple vars +declare @i int +declare @j int +set @i = 10 +set @j = @i + 10 +select @i, @j +GO +~~START~~ +int#!#int +10#!#20 +~~END~~ + + +declare @i int +declare @j int +select @i = 10, @j = @i + 10 +select @i, @j +GO +~~START~~ +int#!#int +10#!#20 +~~END~~ + + +declare @i int +declare @j int = 0; +select @i = 10, @j = @i + @j * 2 +select @i, @j +GO +~~START~~ +int#!#int +10#!#10 +~~END~~ + + +declare @i int +declare @j int +select @i = 10, @j = @i + 10 +select @j += 10 +select @i, @j +GO +~~START~~ +int#!#int +10#!#30 +~~END~~ + + +-- should throw an error +declare @i int +select @i = 0, @i += 2 +select @i +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Babelfish does not support assignment to the same variable in SELECT. variable name: "@i")~~ + + +declare @i int +select @i = 10, @i += 10 +select @i +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Babelfish does not support assignment to the same variable in SELECT. variable name: "@i")~~ + + +-- sub-expr +declare @i int +set @i = 10 +select @i += (5 - 1) +select @i +GO +~~START~~ +int +14 +~~END~~ + + +DECLARE @a int +select @a = (select ~cast('1' as int)) +select @a +go +~~START~~ +int +-2 +~~END~~ + + + +DECLARE @Counter INT = 1; +DECLARE @MaxValue INT = 10; +WHILE @Counter <= @MaxValue +BEGIN + DECLARE @IsEven BIT; + + IF @Counter % 2 = 0 + SET @IsEven = 1; + ELSE + SET @IsEven = 0; + + IF @IsEven = 1 + SELECT CAST(@Counter AS VARCHAR(2)) + ' is even'; + ELSE + SELECT CAST(@Counter AS VARCHAR(2)) + ' is odd'; + + SET @Counter = @Counter + 1; +END; +GO +~~START~~ +varchar +1 is odd +~~END~~ + +~~START~~ +varchar +2 is even +~~END~~ + +~~START~~ +varchar +3 is odd +~~END~~ + +~~START~~ +varchar +4 is even +~~END~~ + +~~START~~ +varchar +5 is odd +~~END~~ + +~~START~~ +varchar +6 is even +~~END~~ + +~~START~~ +varchar +7 is odd +~~END~~ + +~~START~~ +varchar +8 is even +~~END~~ + +~~START~~ +varchar +9 is odd +~~END~~ + +~~START~~ +varchar +10 is even +~~END~~ + + +declare @a numeric (10, 4); +declare @b numeric (10, 4); +SET @a=100.41; +SET @b=200.82; +SELECT @a, @b +select @a+@b as r; +GO +~~START~~ +numeric#!#numeric +100.4100#!#200.8200 +~~END~~ + +~~START~~ +numeric +301.2300 +~~END~~ + + +declare @a numeric; +declare @b numeric (10, 4); +SET @a=100.41; +SET @b=200.82; +SELECT @a, @b +select @a+@b as r; +GO +~~START~~ +numeric#!#numeric +100#!#200.8200 +~~END~~ + +~~START~~ +numeric +300.8200 +~~END~~ + + +declare @a varbinary +set @a = cast('test_bin' as varbinary) +select @a +GO +~~START~~ +varbinary +74 +~~END~~ + + +declare @a varbinary(max) +set @a = cast('test_bin' as varbinary) +select @a +GO +~~START~~ +varbinary +746573745F62696E +~~END~~ + + +declare @a varbinary(10) +set @a = cast('test_bin' as varbinary) +select @a +GO +~~START~~ +varbinary +746573745F62696E +~~END~~ + + +declare @a varbinary +declare @b varbinary +select @a = cast('test_bin' as varbinary), @b = @a +select @a, @b +GO +~~START~~ +varbinary#!#varbinary +74#!#74 +~~END~~ + + +declare @a varbinary(max) +select @a = cast('test_bin' as varbinary) +select @a +GO +~~START~~ +varbinary +746573745F62696E +~~END~~ + + +DECLARE @a varchar +set @a = '12345678901234567890123456789012345'; +SELECT LEN(@a), DATALENGTH(@a) +SELECT @a +GO +~~START~~ +int#!#int +1#!#1 +~~END~~ + +~~START~~ +varchar +1 +~~END~~ + + +DECLARE @v varchar(20); +SELECT @v = NULL; +SELECT ISNUMERIC(@v), LEN(@v), DATALENGTH(@v) +GO +~~START~~ +int#!#int#!#int +0#!##!# +~~END~~ + + +DECLARE @a varchar(max) +SELECT @a = '12345678901234567890123456789012345'; +SELECT LEN(@a), DATALENGTH(@a) +SELECT @a +GO +~~START~~ +int#!#int +35#!#35 +~~END~~ + +~~START~~ +varchar +12345678901234567890123456789012345 +~~END~~ + + +-- collate can not be used with local variables +DECLARE @v varchar(20) collate BBF_Unicode_CP1_CI_As = 'ci_as'; +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: syntax error near 'collate' at line 2 and character position 23)~~ + + +declare @source int; +declare @target sql_variant; +select @source = 1.0 +select @target = cast(@source as varchar(10)); +SELECT sql_variant_property(@target, 'basetype'); +select @target +GO +~~START~~ +sql_variant +varchar +~~END~~ + +~~START~~ +sql_variant +1 +~~END~~ + + +declare @source int; +declare @target varchar(10); +select @source = 1.0 +select cast(@source as varchar(10)) +select @target = cast(@source as varchar(10)); +select @target +GO +~~START~~ +varchar +1 +~~END~~ + +~~START~~ +varchar +1 +~~END~~ + + +DECLARE @a pg_catalog.varchar +SELECT @a = '12345678901234567890123456789012345'; +SELECT LEN(@a), DATALENGTH(@a) +SELECT @a +GO +~~START~~ +int#!#int +35#!#35 +~~END~~ + +~~START~~ +varchar +12345678901234567890123456789012345 +~~END~~ + + +DECLARE @a pg_catalog.varchar(100) +SELECT @a = '12345678901234567890123456789012345'; +SELECT LEN(@a), DATALENGTH(@a) +SELECT @a +GO +~~START~~ +int#!#int +35#!#35 +~~END~~ + +~~START~~ +varchar +12345678901234567890123456789012345 +~~END~~ + + +DECLARE @a pg_catalog.varchar(10) +SELECT @a = '12345678901234567890123456789012345'; +SELECT LEN(@a), DATALENGTH(@a) +SELECT @a +GO +~~START~~ +int#!#int +10#!#10 +~~END~~ + +~~START~~ +varchar +1234567890 +~~END~~ + + +DECLARE @a varchar +SELECT @a = '12345678901234567890123456789012345'; +SELECT LEN(@a), DATALENGTH(@a) +SELECT @a +GO +~~START~~ +int#!#int +1#!#1 +~~END~~ + +~~START~~ +varchar +1 +~~END~~ + + +DECLARE @a varchar(100) +SELECT @a = '12345678901234567890123456789012345'; +SELECT LEN(@a), DATALENGTH(@a) +SELECT @a +GO +~~START~~ +int#!#int +35#!#35 +~~END~~ + +~~START~~ +varchar +12345678901234567890123456789012345 +~~END~~ + + +DECLARE @a varchar(10) +SELECT @a = '12345678901234567890123456789012345'; +SELECT LEN(@a), DATALENGTH(@a) +SELECT @a +GO +~~START~~ +int#!#int +10#!#10 +~~END~~ + +~~START~~ +varchar +1234567890 +~~END~~ + + +DECLARE @a int +set @a = 0 +select @a ^= 1 +select @a +go +~~START~~ +int +1 +~~END~~ + + +DECLARE @a int +set @a = 0 +select @a += ~@a +select @a +go +~~START~~ +int +-1 +~~END~~ + + +SET QUOTED_IDENTIFIER OFF +GO + +-- quoted identifiers +declare @v varchar(20) = "ABC", @v2 varchar(20)="XYZ"; +select @v += "a""b''c'd", @v2 += "x""y''z"; +select @v, @v2 +GO +~~START~~ +varchar#!#varchar +ABCa"b''c'd#!#XYZx"y''z +~~END~~ + + +declare @v varchar(20) = "ABC", @v2 varchar(20)="XYZ"; +select @v += "a""b''c'd", @v2 += @v + "x""y''z"; +select @v, @v2 +GO +~~START~~ +varchar#!#varchar +ABCa"b''c'd#!#XYZABCa"b''c'dx"y''z +~~END~~ + + +declare @v varchar(20) = "ABC", @v2 varchar(20)="XYZ"; +select @v += reverse("a""b''c'd"), @v2 += @v + "x""y''z"; +select @v, @v2 +GO +~~START~~ +varchar#!#varchar +ABCd'c''b"a#!#XYZABCd'c''b"ax"y''z +~~END~~ + + +declare @v varchar(20) = "ABC", @v2 varchar(20)="XYZ"; +select @v += reverse("a""b''c'd"), @v2 += @v + reverse("x""y''z"); +select @v, @v2 +GO +~~START~~ +varchar#!#varchar +ABCd'c''b"a#!#XYZABCd'c''b"az''y"x +~~END~~ + + +declare @v varchar(20) = "ABC", @v2 varchar(20)="XYZ"; +select @v += reverse("a""b''c'd"), @v2 += REVERSE( @v + reverse("x""y''z")); +select @v, @v2 +GO +~~START~~ +varchar#!#varchar +ABCd'c''b"a#!#XYZx"y''za"b''c'dCBA +~~END~~ + + +SET QUOTED_IDENTIFIER ON +GO + +declare @v varchar(20) = 'ABC', @v2 varchar(20)='XYZ'; +select @v += 'abc', @v2 += 'xyz'; +select @v, @v2 +GO +~~START~~ +varchar#!#varchar +ABCabc#!#XYZxyz +~~END~~ + + +declare @a int = 1, @b int = 2; +select @a = 2, @b = @a + 2 +select @a, @b +GO +~~START~~ +int#!#int +2#!#4 +~~END~~ + + +declare @a int = 1, @b int = 2; +select @a += 2, @b -= @a + 2 +select @a, @b +GO +~~START~~ +int#!#int +3#!#-3 +~~END~~ + + +-- xml methods +DECLARE @a bit = 1 +DECLARE @xml XML = ' ' +SELECT @a |= @xml.exist('/artists/artist/@name') +select @a +GO +~~START~~ +bit +1 +~~END~~ + + +DECLARE @a bit = 1 +DECLARE @xml XML; +SELECT @xml = ' ', @a |= @xml.exist('/artists/artist/@name') +select @a +GO +~~START~~ +bit +1 +~~END~~ + + +-- test all kind of udts +create type udt from NCHAR +go + +declare @a udt +select @a = 'anc' +select @a +GO +~~START~~ +nchar +a +~~END~~ + + +DROP type udt +GO + +create type varchar_max from varchar(max) +GO + +DECLARE @a varchar_max +SELECT @a = '12345678901234567890123456789012345'; +SELECT LEN(@a), DATALENGTH(@a) +SELECT @a +GO +~~START~~ +int#!#int +35#!#35 +~~END~~ + +~~START~~ +varchar +12345678901234567890123456789012345 +~~END~~ + + +DROP type varchar_max +GO + +create type num_def from numeric +GO + +declare @a numeric; +declare @b num_def; +SET @a=100.41; +SET @b=200.82; +SELECT @a, @b +select @a+@b as r; +GO +~~START~~ +numeric#!#numeric +100#!#201 +~~END~~ + +~~START~~ +numeric +301 +~~END~~ + + +drop type num_def +GO + +/* + * select/update test + */ +create table local_var_tst (id int) +GO + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +insert into local_var_tst values (6) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +-- txn does not affect local variables +begin tran +declare @i int +update local_var_tst set id = 5, @i = id * 5 +select @i +ROLLBACK tran +select @i +GO +~~ROW COUNT: 3~~ + +~~START~~ +int +25 +~~END~~ + +~~START~~ +int +25 +~~END~~ + + +select * from local_var_tst; +GO +~~START~~ +int +1 +2 +6 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +-- should return 4 +declare @i int +select @i = 1 +select @i = id * 2 from local_var_tst where id = @i +select @i +GO +~~START~~ +int +2 +~~END~~ + + +declare @i int +select @i = 1 +select @i = @i + id * 2 from local_var_tst +select @i +GO +~~START~~ +int +7 +~~END~~ + + +declare @i int +select @i = 1 +select @i = id * 2 + @i from local_var_tst +select @i +GO +~~START~~ +int +7 +~~END~~ + + +declare @i int +select @i = 1 +select @i += id * 2 from local_var_tst +select @i +GO +~~START~~ +int +7 +~~END~~ + + +-- 3 parts name +declare @i int +select @i = 1 +select @i += master.dbo.local_var_tst.id * 2 from local_var_tst +select @i +GO +~~START~~ +int +7 +~~END~~ + + +-- local var name same as column +declare @id int = 1 +select @id += master.dbo.local_var_tst.id * 2 from local_var_tst +select @id +GO +~~START~~ +int +7 +~~END~~ + + +-- should throw an error +declare @i int +declare @j int +set @i = 10 +set @j = 0; +select @i += (select @j = @j + id from local_var_tst) +select @i +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: variable assignment can be used only in top-level SELECT)~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +DECLARE @ans INT +SELECT @ans = AVG(id) FROM local_var_tst +select @ans +GO +~~START~~ +int +1 +~~END~~ + + +-- local variable inside functions +CREATE FUNCTION var_inside_func() +RETURNS INT AS +BEGIN + DECLARE @ans INT + SELECT @ans = AVG(id) FROM local_var_tst + RETURN @ans +END +GO + +select var_inside_func(); +GO +~~START~~ +int +1 +~~END~~ + + +DROP FUNCTION var_inside_func(); +GO + +-- show throw an error +CREATE FUNCTION var_inside_func() +RETURNS @tab table (a int) as +BEGIN + DECLARE @ans INT + SELECT @ans += id from local_var_tst + select @ans +END +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: SELECT statement returning result to a client cannot be used in a function)~~ + + +drop function if exists var_inside_func +go + +CREATE FUNCTION var_inside_func() +RETURNS INT AS +BEGIN + DECLARE @ans INT + SELECT @ans += id FROM local_var_tst + RETURN @ans +END +GO + +select var_inside_func() +go +~~START~~ +int + +~~END~~ + + +drop function if exists var_inside_func +go + +CREATE FUNCTION var_inside_func(@def int) +RETURNS INT AS +BEGIN + DECLARE @ans INT; + select @ans = @def; + SELECT @ans += id FROM local_var_tst + RETURN @ans +END +GO + +select var_inside_func(0) +go +~~START~~ +int +3 +~~END~~ + + +declare @def int = 1; +select var_inside_func(@def) +go +~~START~~ +int +4 +~~END~~ + + +drop function if exists var_inside_func +go + +CREATE FUNCTION var_inside_func() +RETURNS INT AS +BEGIN + DECLARE @ans INT + select @ans = 0 + SELECT @ans += id + @ans FROM local_var_tst + RETURN @ans +END +GO + +select var_inside_func() +go +~~START~~ +int +4 +~~END~~ + + +drop function if exists var_inside_func +go + +-- variable with procedure +CREATE PROCEDURE var_with_procedure (@a numeric(10,4) OUTPUT) AS +BEGIN + SET @a=100.41; + select @a as a; +END; +GO + +exec var_with_procedure 2.000; +GO +~~START~~ +numeric +100.4100 +~~END~~ + + +-- value of @out should remain 2.000 +declare @out numeric(10,4); +set @out = 2.000; +exec var_with_procedure 2.000; +select @out +GO +~~START~~ +numeric +100.4100 +~~END~~ + +~~START~~ +numeric +2.0000 +~~END~~ + + +drop procedure var_with_procedure; +GO + +CREATE PROCEDURE var_with_procedure_1 (@a numeric(10,4) OUTPUT, @b numeric(10,4) OUTPUT) AS +BEGIN + SET @a=100.41; + SET @b=200.82; + select @a+@b as r; +END; +GO + +EXEC var_with_procedure_1 2.000, 3.000; +GO +~~START~~ +numeric +301.2300 +~~END~~ + + +-- value of @a should be 100 +DECLARE @a INT; +EXEC var_with_procedure_1 @a OUT, 3.000; +SELECT @a; +GO +~~START~~ +numeric +301.2300 +~~END~~ + +~~START~~ +int +100 +~~END~~ + + +drop procedure var_with_procedure_1; +GO + +CREATE PROCEDURE var_with_procedure_2 +AS +BEGIN + declare @a int + declare @b int + set @a = 1 + return + select @b=@a+1 +END +GO + +exec var_with_procedure_2 +GO + +DROP PROCEDURE var_with_procedure_2 +GO + +-- insert testing with local variables +truncate table dbo.local_var_tst +go + +-- should throw an error +declare @a int = 1 +insert into local_var_tst select @a = @a + 1 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: variable assignment can be used only in top-level SELECT)~~ + + +-- syntax error +declare @a int = 1 +insert into local_var_tst values (@a = @a + 1) +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: syntax error near '=' at line 3 and character position 37)~~ + + +declare @a int = 1 +insert into local_var_tst values (@a + 1) +GO +~~ROW COUNT: 1~~ + + +-- output clause with insert +declare @a int = 1 +declare @mytbl table(a int) +insert local_var_tst output inserted.id into @mytbl values (@a + 1) +select * from @mytbl +GO +~~ROW COUNT: 1~~ + +~~START~~ +int +2 +~~END~~ + + +-- output clause with delete +declare @a int = 1 +declare @mytbl table(a int) +delete local_var_tst output deleted.id into @mytbl where id = @a + 1 +select * from @mytbl +GO +~~ROW COUNT: 2~~ + +~~START~~ +int +2 +2 +~~END~~ + + +drop table dbo.local_var_tst +go + +create table local_var_tst_1 (a int, b int) +GO + +insert into local_var_tst_1 values (1,3), (2, 4) +go +~~ROW COUNT: 2~~ + + + +-- select test with multi-variable assignment +declare @a int = 0 +declare @b int = 0 +select @a += a, @b += b from local_var_tst_1 +select @a, @b +go +~~START~~ +int#!#int +3#!#7 +~~END~~ + + +declare @a int = 0 +declare @b int = 0 +select @a += a, @b += @a + b from local_var_tst_1 +select @a, @b +go +~~START~~ +int#!#int +3#!#11 +~~END~~ + + +declare @a int = 0 +declare @b int = 0 +select @a += a, @b += @a + ~b from local_var_tst_1 +select @a, @b +go +~~START~~ +int#!#int +3#!#-5 +~~END~~ + + +drop table local_var_tst_1 +go + +create table local_var_str_tst (id varchar(100)) +GO + +insert into local_var_str_tst values ('abc'), (' '), ('def') +GO +~~ROW COUNT: 3~~ + + +declare @i varchar(1000) +set @i = '' +select @i = @i + id from local_var_str_tst +select @i +go +~~START~~ +varchar +abc def +~~END~~ + + +declare @i varchar(1000) +set @i = '' +select @i = id + @i from local_var_str_tst +select @i +go +~~START~~ +varchar +def abc +~~END~~ + + +declare @i varchar(1000) +set @i = '' +select @i += id from local_var_str_tst +select @i +go +~~START~~ +varchar +abc def +~~END~~ + + +declare @i varchar(1000) +set @i = '' +select @i = reverse(@i + 'id') from local_var_str_tst +select @i +go +~~START~~ +varchar +didiid +~~END~~ + + +declare @i varchar(1000) +set @i = '' +select @i += reverse(id) from local_var_str_tst +select @i +go +~~START~~ +varchar +cba fed +~~END~~ + + +declare @i varchar(1000) +set @i = 'abc' +select @i = reverse(@i) +select @i +go +~~START~~ +varchar +cba +~~END~~ + + +-- function call like trim, ltrim, etc will be rewritten by ANTLR +declare @i varchar(1000) +set @i = ' ' +select @i += id from local_var_str_tst +select len(@i), @i +select @i = trim(@i) +select len(@i), @i +go +~~START~~ +int#!#varchar +8#!# abc def +~~END~~ + +~~START~~ +int#!#varchar +7#!#abc def +~~END~~ + + +drop table local_var_str_tst; +go + +-- $PARTITION is rewritten by ANTLR +CREATE PARTITION FUNCTION RangePF1 ( INT ) +AS RANGE RIGHT FOR VALUES (10, 100, 1000) ; +GO + +declare @res int = -1; +SELECT @res = $PARTITION.RangePF1 (10); +select @res +select 1 where @res = $PARTITION.RangePF1 (10); +SELECT @res = $PARTITION.RangePF1 (@res); +select @res +GO +~~START~~ +int +2 +~~END~~ + +~~START~~ +int +1 +~~END~~ + +~~START~~ +int +1 +~~END~~ + + +DROP PARTITION FUNCTION RangePF1 +GO + +CREATE SEQUENCE CountBy1 + START WITH 1 + INCREMENT BY 1 ; +GO + +-- NEXT VALUE FOR gets re-written by ANTLR +DECLARE @myvar1 BIGINT = NEXT VALUE FOR CountBy1 ; +DECLARE @myvar2 BIGINT ; +DECLARE @myvar3 BIGINT ; +select @myvar2 = NEXT VALUE FOR CountBy1 ; +SELECT @myvar3 = NEXT VALUE FOR CountBy1 ; +SELECT @myvar1 AS myvar1, @myvar2 AS myvar2, @myvar3 AS myvar3 ; +GO +~~START~~ +bigint#!#bigint#!#bigint +1#!#2#!#3 +~~END~~ + + +DROP SEQUENCE CountBy1 +GO + +-- any @@ is also re-written by ANTLR +declare @pid int = 0 +select @pid += @@spid +select 1 where @pid = @@spid +go +~~START~~ +int +1 +~~END~~ + + +-- float point notation also gets rewritten by ANTLR e.g., 2.1E, -.2e+, -2.e- +declare @a float = 0 +select @a = 2.1E +select @a +select @a = -.2e+ +select @a +select @a = -2.e- +select @a +go +~~START~~ +float +2.1 +~~END~~ + +~~START~~ +float +-0.2 +~~END~~ + +~~START~~ +float +-2.0 +~~END~~ + + +-- variables only in select target list shows dynamic behavior +create table local_var_tst (id int) +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +insert into local_var_tst values (1) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +declare @i int = 1 +declare @j int = 0 +select @j += id, @i = id + 1 from local_var_tst where id = @i +select @i, @j +go +~~START~~ +int#!#int +2#!#2 +~~END~~ + + +declare @i int = 1 +select @i = id * 2 from local_var_tst where id = @i +select @i +GO +~~START~~ +int +2 +~~END~~ + + +select set_config('babelfishpg_tsql.explain_timing', 'off', false); +GO +~~START~~ +text +off +~~END~~ + + +select set_config('babelfishpg_tsql.explain_summary', 'off', false); +GO +~~START~~ +text +off +~~END~~ + + +set babelfish_statistics profile On; +GO + +declare @i int = 1 +declare @j int = 0 +select @j += id, @i = id + 1 from local_var_tst where id = @i +select @i, @j +go +~~START~~ +text +Query Text: select sys.pltsql_assign_var(3, @j + cast((id) as int)), sys.pltsql_assign_var(2, cast((id + 1) as int)) from local_var_tst where id = "@i" +Seq Scan on local_var_tst (cost=0.00..42.01 rows=13 width=8) (actual rows=2 loops=1) + Filter: (id = 1) + Rows Removed by Filter: 1 +~~END~~ + +~~START~~ +int#!#int +2#!#2 +~~END~~ + +~~START~~ +text +Query Text: select "@i", "@j" +Result (cost=0.00..0.01 rows=1 width=8) (actual rows=1 loops=1) +~~END~~ + + +declare @i int = 1 +select @i = @i * 2 from local_var_tst where id = @i +select @i +GO +~~START~~ +text +Query Text: select sys.pltsql_assign_var(2, cast((@i * 2) as int)) from local_var_tst where id = "@i" +Seq Scan on local_var_tst (cost=0.00..41.94 rows=13 width=4) (actual rows=2 loops=1) + Filter: (id = 1) + Rows Removed by Filter: 1 +~~END~~ + +~~START~~ +int +4 +~~END~~ + +~~START~~ +text +Query Text: select "@i" +Result (cost=0.00..0.01 rows=1 width=4) (actual rows=1 loops=1) +~~END~~ + + +set babelfish_statistics profile OFF +GO + +select set_config('babelfishpg_tsql.explain_timing', 'on', false); +GO +~~START~~ +text +on +~~END~~ + + +select set_config('babelfishpg_tsql.explain_summary', 'on', false); +GO +~~START~~ +text +on +~~END~~ + + +-- declared variable name with length > 63 +declare @abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr int = 1 +select @abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr += 1 +select @abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr +GO +~~START~~ +int +2 +~~END~~ + + +-- variable names starting with @@ +declare @@a int = 1; +select @@a = @@a + 1 +select @@a +GO +~~START~~ +int +2 +~~END~~ + + +declare @@a int = 1; +select @@a += 1 +select @@a +GO +~~START~~ +int +2 +~~END~~ + + +declare @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr int = 1 +select @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr = @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr + 1 +select @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr +GO +~~START~~ +int +2 +~~END~~ + + +truncate table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +insert into local_var_tst values (1) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +declare @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr int = 1 +select @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr = @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr + id from local_var_tst +select @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr +GO +~~START~~ +int +5 +~~END~~ + + +declare @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr int = 1 +select @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr = id + @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr from local_var_tst +select @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr +GO +~~START~~ +int +5 +~~END~~ + + +declare @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr int = 1 +select @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr += id from local_var_tst +select @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr +GO +~~START~~ +int +5 +~~END~~ + + +truncate table local_var_tst +GO + +insert into local_var_tst values (1) +GO +~~ROW COUNT: 1~~ + + +select set_config('babelfishpg_tsql.explain_timing', 'off', false); +GO +~~START~~ +text +off +~~END~~ + + +select set_config('babelfishpg_tsql.explain_summary', 'off', false); +GO +~~START~~ +text +off +~~END~~ + + +set babelfish_statistics profile On; +GO + +-- error while evaluating const expression +declare @a int = 1; +select @a = 1 / 0 from local_var_tst +select * from local_var_tst where id = @a +GO +~~ERROR (Code: 8134)~~ + +~~ERROR (Message: division by zero)~~ + +~~START~~ +int +1 +~~END~~ + +~~START~~ +text +Query Text: select * from local_var_tst where id = "@a" +Seq Scan on local_var_tst (cost=0.00..41.88 rows=13 width=4) (actual rows=1 loops=1) + Filter: (id = 1) +~~END~~ + + +set babelfish_statistics profile OFF +GO + +select set_config('babelfishpg_tsql.explain_timing', 'on', false); +GO +~~START~~ +text +on +~~END~~ + + +select set_config('babelfishpg_tsql.explain_summary', 'on', false); +GO +~~START~~ +text +on +~~END~~ + + +drop table local_var_tst +GO + +create table ident_tst(id_num INT IDENTITY(1, 1), b varchar(10)) +GO + +insert into ident_tst values ('test') +GO +~~ROW COUNT: 1~~ + + +declare @a int = 1 +select @a = @@IDENTITY +select @a +select 1 where @a = @@IDENTITY +GO +~~START~~ +int +1 +~~END~~ + +~~START~~ +int +1 +~~END~~ + + +-- additional testing for update with dynamic variables +GO + +create table local_var_tst (id int) +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + + +set QUOTED_IDENTIFIER on +GO + +declare @i varchar(100) +update local_var_tst set id = id + 10, @i = cast("xmax" as varchar(100)) +select 1 where @i IS NOT NULL +GO +~~ROW COUNT: 2~~ + +~~START~~ +int +1 +~~END~~ + + +set QUOTED_IDENTIFIER off +GO + +select * from local_var_tst order by id; +GO +~~START~~ +int +11 +12 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +-- long identifier with update +declare @incnjkdncjknxdjnkxnknvjkdfjvbdfbvjbdfhjbvjdbfvkjbdnjnlkanjfnvjnjfdlsahdnuejncdiebnjcnjksndjnjxndjcx int +update local_var_tst set id =10, @incnjkdncjknxdjnkxnknvjkdfjvbdfbvjbdfhjbvjdbfvkjbdnjnlkanjfnvjnjfdlsahdnuejncdiebnjcnjksndjnjxndjcx = id +select @incnjkdncjknxdjnkxnknvjkdfjvbdfbvjbdfhjbvjdbfvkjbdnjnlkanjfnvjnjfdlsahdnuejncdiebnjcnjksndjnjxndjcx +GO +~~ROW COUNT: 2~~ + +~~START~~ +int +10 +~~END~~ + + +select * from local_var_tst +GO +~~START~~ +int +10 +10 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +-- @@ variables +declare @@incnjkdnc int +update local_var_tst set id =10, @@incnjkdnc = id +select @@incnjkdnc +GO +~~ROW COUNT: 2~~ + +~~START~~ +int +10 +~~END~~ + + +select * from local_var_tst +GO +~~START~~ +int +10 +10 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +declare @i int +update local_var_tst set id = id + 2, @i = id * 5; +select @i +GO +~~ROW COUNT: 2~~ + +~~START~~ +int +20 +~~END~~ + + +select * from local_var_tst order by id; +GO +~~START~~ +int +3 +4 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +declare @i int, @j int; +update local_var_tst set id =10, @i = case when @j =0 then 1 else 0 end; +select @i, @j +go +~~ROW COUNT: 2~~ + +~~START~~ +int#!#int +0#!# +~~END~~ + + +select * from local_var_tst; +GO +~~START~~ +int +10 +10 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +declare @i int, @j int; +update local_var_tst set id = 10, @j = id, @i = case when @j =0 then 1 else 0 end; +select @i, @j +go +~~ROW COUNT: 2~~ + +~~START~~ +int#!#int +0#!#10 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +declare @i int, @j int = 0 +update local_var_tst set id =10, @i = charindex('a','a',@j) +select @i +GO +~~ROW COUNT: 2~~ + +~~START~~ +int +1 +~~END~~ + + +select * from local_var_tst; +GO +~~START~~ +int +10 +10 +~~END~~ + + +declare @i int, @j int = 0 +update local_var_tst set id =10, @i = charindex('a','a',@j); +select @i +GO +~~ROW COUNT: 2~~ + +~~START~~ +int +1 +~~END~~ + + +select * from local_var_tst; +GO +~~START~~ +int +10 +10 +~~END~~ + + +declare @i int, @j int; +update local_var_tst set id = 10, @j = id, @i = @j * 2 +select @i, @j +go +~~ROW COUNT: 2~~ + +~~START~~ +int#!#int +20#!#10 +~~END~~ + + +select * from local_var_tst; +GO +~~START~~ +int +10 +10 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +declare @i int = 1 +update local_var_tst set id = @i, @i = id * 2 where id = @i +select @i +GO +~~ROW COUNT: 1~~ + +~~START~~ +int +2 +~~END~~ + + +select * from local_var_tst +go +~~START~~ +int +2 +1 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +declare @i int = 1 +update local_var_tst set id = @i, @i += id * 2 where id = @i +select @i +GO +~~ROW COUNT: 1~~ + +~~START~~ +int +3 +~~END~~ + + +select * from local_var_tst +go +~~START~~ +int +2 +1 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +declare @i VARCHAR(200) = '' +update local_var_tst set id = id * 2, @i = @i + cast(id as varchar(20)) +select @i +GO +~~ROW COUNT: 2~~ + +~~START~~ +varchar +24 +~~END~~ + + +select * from local_var_tst order by id +go +~~START~~ +int +2 +4 +~~END~~ + + +-- @i should be NULL as no row passes the qual condition +declare @i int +update local_var_tst set id =10, @i = id * 5 where id = 1 +select @i +GO +~~START~~ +int + +~~END~~ + + +select * from local_var_tst order by id +go +~~START~~ +int +2 +4 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + + +declare @i int = 1 +update local_var_tst set id = @i, @i = id * 5 where id = @i +select @i +GO +~~ROW COUNT: 1~~ + +~~START~~ +int +5 +~~END~~ + + +select * from local_var_tst order by id +go +~~START~~ +int +1 +2 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +declare @i int +set @i = 0 +update local_var_tst set id = @i, @i = id * 5 +select @i +GO +~~ROW COUNT: 2~~ + +~~START~~ +int +0 +~~END~~ + + +select * from local_var_tst; +GO +~~START~~ +int +0 +0 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +-- trim is re-written by antlr +declare @i varchar(200) +select @i = '' +update local_var_tst set id = @i, @i = TRIM(@i + cast(id as varchar(10))); +select @i +GO +~~ROW COUNT: 2~~ + +~~START~~ +varchar +00 +~~END~~ + + +select * from local_var_tst; +GO +~~START~~ +int +0 +0 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + + +-- variables in the where clause should be treated as const +declare @i int = 1; +update local_var_tst set id = @i * 100, @i = id * 2 where id = @i +select @i +GO +~~ROW COUNT: 1~~ + +~~START~~ +int +200 +~~END~~ + + +select * from local_var_tst order by id; +GO +~~START~~ +int +2 +100 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +declare @i int = 1; +update local_var_tst set id = @i * 100, @i = @@IDENTITY +select @i +select 1 where @i = @@IDENTITY +GO +~~ROW COUNT: 2~~ + +~~START~~ +int +1 +~~END~~ + +~~START~~ +int +1 +~~END~~ + + +select * from local_var_tst +GO +~~START~~ +int +100 +100 +~~END~~ + + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +CREATE PARTITION FUNCTION RangePF1 ( INT ) +AS RANGE RIGHT FOR VALUES (10, 100, 1000) ; +GO + +declare @i int = -1; +SELECT @i = $PARTITION.RangePF1 (10); +select @i +update local_var_tst set id = @i, @i = $PARTITION.RangePF1 (10); +select @i +GO +~~START~~ +int +2 +~~END~~ + +~~ROW COUNT: 2~~ + +~~START~~ +int +2 +~~END~~ + + +select * from local_var_tst; +GO +~~START~~ +int +2 +2 +~~END~~ + + +DROP PARTITION FUNCTION RangePF1 +GO + +CREATE PROCEDURE var_with_procedure (@i int, @a numeric(10,4) OUTPUT) AS +BEGIN + update local_var_tst set id = @i * 2, @a = id * 5 where id = @i + select @a +END; +GO + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +declare @input int = 1, @res int; +exec var_with_procedure @input, @res +select @res +GO +~~ROW COUNT: 1~~ + +~~START~~ +numeric +10.0000 +~~END~~ + +~~START~~ +int + +~~END~~ + + +select * from local_var_tst +go +~~START~~ +int +2 +2 +~~END~~ + + +declare @input int = 2, @a int; +exec var_with_procedure @input, @a +select @a +GO +~~ROW COUNT: 2~~ + +~~START~~ +numeric +20.0000 +~~END~~ + +~~START~~ +int + +~~END~~ + + +DROP PROCEDURE var_with_procedure; +GO + +DROP TABLE local_var_tst +GO + +create table local_var_tst_1 (id int) +GO + +insert into local_var_tst_1 values (1) +insert into local_var_tst_1 values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +create unique index idx_local_var_tst_1 on local_var_tst_1(id) +GO + + +SELECT set_config('enable_indexscan', '1', false); +SELECT set_config('enable_indexonlyscan', '0', false); +SELECT set_config('enable_seqscan', '0', false); +GO +~~START~~ +text +on +~~END~~ + +~~START~~ +text +off +~~END~~ + +~~START~~ +text +off +~~END~~ + + +declare @i int = 1 +update local_var_tst_1 set id = @i, @i = id * 5 where id = 1 +select @i +GO +~~ROW COUNT: 1~~ + +~~START~~ +int +5 +~~END~~ + + +declare @i int = 1 +update local_var_tst_1 set id = 10 output deleted.id where id = 1 +select @i +GO +~~START~~ +int +1 +~~END~~ + +~~START~~ +int +1 +~~END~~ + + +SELECT set_config('enable_indexscan', '1', false); +SELECT set_config('enable_indexonlyscan', '1', false); +SELECT set_config('enable_seqscan', '1', false); +GO +~~START~~ +text +on +~~END~~ + +~~START~~ +text +on +~~END~~ + +~~START~~ +text +on +~~END~~ + + +DROP TABLE local_var_tst_1 +GO + +CREATE TABLE update_test_tbl ( + age int, + fname char(10), + lname char(10), + city nchar(20) +) +GO + +TRUNCATE TABLE update_test_tbl +GO + +INSERT INTO update_test_tbl(age, fname, lname, city) +VALUES (50, 'fname1', 'lname1', 'london'), + (34, 'fname2', 'lname2', 'paris'), + (35, 'fname3', 'lname3', 'brussels'), + (90, 'fname4', 'lname4', 'new york'), + (26, 'fname5', 'lname5', 'los angeles'), + (74, 'fname6', 'lname6', 'tokyo'), + (44, 'fname7', 'lname7', 'oslo'), + (19, 'fname8', 'lname8', 'hong kong'), + (61, 'fname9', 'lname9', 'shanghai'), + (29, 'fname10', 'lname10', 'mumbai') +GO +~~ROW COUNT: 10~~ + + +CREATE TABLE update_test_tbl2 ( + year int, + lname char(10), +) +GO + +TRUNCATE TABLE update_test_tbl2 +GO + +INSERT INTO update_test_tbl2(year, lname) +VALUES (51, 'lname1'), + (34, 'lname3'), + (25, 'lname8'), + (95, 'lname9'), + (36, 'lname10') +GO +~~ROW COUNT: 5~~ + + +UPDATE update_test_tbl SET fname = 'fname13' +FROM update_test_tbl t1 +INNER JOIN update_test_tbl2 t2 +ON t1.lname = t2.lname +WHERE year > 50 +GO +~~ROW COUNT: 2~~ + + +declare @a varchar(4000) = ''; +UPDATE update_test_tbl SET fname = 'fname13', @a = @a + fname +FROM update_test_tbl t1 +INNER JOIN update_test_tbl2 t2 +ON t1.lname = t2.lname +WHERE year > 50 +select @a +GO +~~ROW COUNT: 2~~ + +~~START~~ +varchar +fname13 fname13 +~~END~~ + + +DROP TABLE update_test_tbl2; +GO + +DROP TABLE update_test_tbl +GO + +drop table ident_tst +GO + +create table local_var_tst (id int) +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +declare @i int = 0, @j int +update local_var_tst set id = id + 2, @i = id, @j = @i * 2, @i = @j +select @i, @j +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Babelfish does not support assignment to the same variable in SELECT. variable name: "@i")~~ + + +declare @i int = 0, @j int +update local_var_tst set id = id + 2, @i += id, @j = @i * 2 +select @i, @j +GO +~~ROW COUNT: 2~~ + +~~START~~ +int#!#int +7#!#14 +~~END~~ + + +select * from local_var_tst order by id +GO +~~START~~ +int +3 +4 +~~END~~ + + +drop table local_var_tst +GO diff --git a/test/JDBC/expected/translate-before-15_8-or-16_4-vu-verify.out b/test/JDBC/expected/translate-before-15_8-or-16_4-vu-verify.out index 13b05f6704..3d36bb191e 100644 --- a/test/JDBC/expected/translate-before-15_8-or-16_4-vu-verify.out +++ b/test/JDBC/expected/translate-before-15_8-or-16_4-vu-verify.out @@ -654,6 +654,8 @@ varchar DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters VARCHAR(20) = 'ab?', @translations VARCHAR(40) = 'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -694,6 +696,8 @@ GO DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -702,6 +706,8 @@ GO DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -751,6 +757,8 @@ varchar DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NVARCHAR(20) = N'ab?', @translations NVARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -791,6 +799,8 @@ GO DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = N'ab?', @translations CHAR(40) = N'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -799,6 +809,8 @@ GO DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = N'ab?', @translations CHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1013,6 +1025,8 @@ GO DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1021,6 +1035,8 @@ GO DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1061,6 +1077,8 @@ GO DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1069,6 +1087,8 @@ GO DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1118,6 +1138,8 @@ varchar DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NVARCHAR(20) = N'ab?', @translations NVARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1167,6 +1189,8 @@ varchar DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters VARCHAR(20) = N'ab?', @translations VARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1372,6 +1396,8 @@ GO DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1380,6 +1406,8 @@ GO DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1420,6 +1448,8 @@ GO DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1428,6 +1458,8 @@ GO DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1477,6 +1509,8 @@ nvarchar DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NVARCHAR(20) = N'ab?', @translations NVARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1526,6 +1560,8 @@ nvarchar DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters VARCHAR(20) = N'ab?', @translations VARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1731,6 +1767,8 @@ GO DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1739,6 +1777,8 @@ GO DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1779,6 +1819,8 @@ GO DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1787,6 +1829,8 @@ GO DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1836,6 +1880,8 @@ nvarchar DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NVARCHAR(20) = N'ab?', @translations NVARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1885,6 +1931,8 @@ nvarchar DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters VARCHAR(20) = N'ab?', @translations VARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ diff --git a/test/JDBC/expected/translate-vu-verify.out b/test/JDBC/expected/translate-vu-verify.out index 4f0f913424..76034cf8ab 100644 --- a/test/JDBC/expected/translate-vu-verify.out +++ b/test/JDBC/expected/translate-vu-verify.out @@ -654,6 +654,8 @@ varchar DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters VARCHAR(20) = 'ab?', @translations VARCHAR(40) = 'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -694,6 +696,8 @@ GO DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -702,6 +706,8 @@ GO DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -751,6 +757,8 @@ varchar DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NVARCHAR(20) = N'ab?', @translations NVARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -791,6 +799,8 @@ GO DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = N'ab?', @translations CHAR(40) = N'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -799,6 +809,8 @@ GO DECLARE @inputString CHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = N'ab?', @translations CHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1013,6 +1025,8 @@ GO DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1021,6 +1035,8 @@ GO DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1061,6 +1077,8 @@ GO DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1069,6 +1087,8 @@ GO DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1118,6 +1138,8 @@ varchar DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NVARCHAR(20) = N'ab?', @translations NVARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1167,6 +1189,8 @@ varchar DECLARE @inputString VARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters VARCHAR(20) = N'ab?', @translations VARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1372,6 +1396,8 @@ GO DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1380,6 +1406,8 @@ GO DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1420,6 +1448,8 @@ GO DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1428,6 +1458,8 @@ GO DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1477,6 +1509,8 @@ nvarchar DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NVARCHAR(20) = N'ab?', @translations NVARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1526,6 +1560,8 @@ nvarchar DECLARE @inputString NCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters VARCHAR(20) = N'ab?', @translations VARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1731,6 +1767,8 @@ GO DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1739,6 +1777,8 @@ GO DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters CHAR(20) = 'ab?', @translations CHAR(40) = 'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1779,6 +1819,8 @@ GO DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂y' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1787,6 +1829,8 @@ GO DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NCHAR(20) = N'ab?', @translations NCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1836,6 +1880,8 @@ nvarchar DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters NVARCHAR(20) = N'ab?', @translations NVARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ @@ -1885,6 +1931,8 @@ nvarchar DECLARE @inputString NVARCHAR(50) = ' abc🙂defghi🙂🙂 ', @characters VARCHAR(20) = N'ab?', @translations VARCHAR(40) = N'x🙂yw' SELECT '|' + TRANSLATE(@inputString, @characters, @translations) + '|' GO +~~START~~ +nvarchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: The second and third arguments of the TRANSLATE built-in function must contain an equal number of characters.)~~ diff --git a/test/JDBC/expected/unary_plus_op_string-vu-prepare.out b/test/JDBC/expected/unary_plus_op_string-vu-prepare.out index fa33ec42ae..c53ab72ebd 100644 --- a/test/JDBC/expected/unary_plus_op_string-vu-prepare.out +++ b/test/JDBC/expected/unary_plus_op_string-vu-prepare.out @@ -1,3 +1,5 @@ +set quoted_identifier off +go create table t1_unary_plus_op_string(i int, vc varchar(30)) go diff --git a/test/JDBC/expected/unquoted_string-vu-prepare.out b/test/JDBC/expected/unquoted_string-vu-prepare.out index 8025a74a6e..6c8e5b2547 100644 --- a/test/JDBC/expected/unquoted_string-vu-prepare.out +++ b/test/JDBC/expected/unquoted_string-vu-prepare.out @@ -119,15 +119,6 @@ go ~~ERROR (Message: column "@p1" does not exist)~~ --- should raise error: -create procedure unqStr_proc_6 @p1 varchar(20) = @@myvar -as select @p1 -go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: function sys.myvar() does not exist)~~ - - create procedure unqStr_proc_7 @p1 varchar(20) = N'aB"c''D', @p2 varchar(20) = dEfg, @p3 varchar(20) = "x'Y""z" as select @p1, @p2, @p3 go diff --git a/test/JDBC/expected/unquoted_string-vu-verify.out b/test/JDBC/expected/unquoted_string-vu-verify.out index 12969bad57..3143be75c4 100644 --- a/test/JDBC/expected/unquoted_string-vu-verify.out +++ b/test/JDBC/expected/unquoted_string-vu-verify.out @@ -713,6 +713,15 @@ go Position: 71 Server SQLState: 42703)~~ +-- should raise an error since variable is not defined +create procedure unqStr_proc_6 @p1 varchar(20) = @@myvar +as select @p1 +go +~~ERROR (Code: 0)~~ + +~~ERROR (Message: ERROR: syntax error at or near "@" + Position: 87 + Server SQLState: 42601)~~ -- should print 'aBc': select unqStr_pgfunc_1('aBc'); diff --git a/test/JDBC/expected/upper_lower-before-15_8-or-16_4-vu-verify.out b/test/JDBC/expected/upper_lower-before-15_8-or-16_4-vu-verify.out index 9b2585b16d..15ab10f69b 100644 --- a/test/JDBC/expected/upper_lower-before-15_8-or-16_4-vu-verify.out +++ b/test/JDBC/expected/upper_lower-before-15_8-or-16_4-vu-verify.out @@ -530,6 +530,8 @@ DECLARE @myid sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_ SELECT UPPER(@myid) SELECT LOWER(@myid) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of upper function.)~~ @@ -539,6 +541,8 @@ DECLARE @myid xml = CAST ('' AS xml) SELECT UPPER(@myid) SELECT LOWER(@myid) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of upper function.)~~ @@ -548,6 +552,8 @@ DECLARE @myid geometry = geometry::STGeomFromText('POINT (1 2)', 0) SELECT UPPER(@myid) SELECT LOWER(@myid) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of upper function.)~~ @@ -815,6 +821,8 @@ adjnfjh declare @b dbo.MyUDT = CAST('scsdc' AS dbo.MyUDT) select upper(@b) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type image is invalid for argument 1 of upper function.)~~ diff --git a/test/JDBC/expected/upper_lower-vu-verify.out b/test/JDBC/expected/upper_lower-vu-verify.out index 3c8a50e643..d10fef792e 100644 --- a/test/JDBC/expected/upper_lower-vu-verify.out +++ b/test/JDBC/expected/upper_lower-vu-verify.out @@ -530,6 +530,8 @@ DECLARE @myid sql_variant = CAST ('6F9619FF-8B86-D011-B42D-00C04FC964FF' AS sql_ SELECT UPPER(@myid) SELECT LOWER(@myid) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type sql_variant is invalid for argument 1 of upper function.)~~ @@ -539,6 +541,8 @@ DECLARE @myid xml = CAST ('' AS xml) SELECT UPPER(@myid) SELECT LOWER(@myid) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type xml is invalid for argument 1 of upper function.)~~ @@ -548,6 +552,8 @@ DECLARE @myid geometry = geometry::STGeomFromText('POINT (1 2)', 0) SELECT UPPER(@myid) SELECT LOWER(@myid) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type geometry is invalid for argument 1 of upper function.)~~ @@ -838,6 +844,8 @@ adjnfjh declare @b dbo.MyUDT = CAST('scsdc' AS dbo.MyUDT) select upper(@b) GO +~~START~~ +varchar ~~ERROR (Code: 33557097)~~ ~~ERROR (Message: Argument data type image is invalid for argument 1 of upper function.)~~ diff --git a/test/JDBC/expected/with_recompile-vu-verify.out b/test/JDBC/expected/with_recompile-vu-verify.out index 170f8f6b83..d2bbb373de 100644 --- a/test/JDBC/expected/with_recompile-vu-verify.out +++ b/test/JDBC/expected/with_recompile-vu-verify.out @@ -109,7 +109,7 @@ Query Text: EXEC p_recomp_11 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 156.942 ms +Babelfish T-SQL Batch Parsing Time: 168.130 ms ~~END~~ set babelfish_showplan_all off @@ -193,7 +193,7 @@ Query Text: EXEC p_recomp_12 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.172 ms +Babelfish T-SQL Batch Parsing Time: 0.117 ms ~~END~~ set babelfish_showplan_all off @@ -238,7 +238,7 @@ Query Text: EXEC p_recomp_11 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 4.244 ms +Babelfish T-SQL Batch Parsing Time: 3.643 ms ~~END~~ exec p_recomp_12 0 with recompile @@ -258,7 +258,7 @@ Query Text: EXEC p_recomp_12 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.124 ms +Babelfish T-SQL Batch Parsing Time: 0.092 ms ~~END~~ set babelfish_showplan_all off @@ -284,7 +284,7 @@ Query Text: EXEC p_recomp_12 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 3.839 ms +Babelfish T-SQL Batch Parsing Time: 2.300 ms ~~END~~ set babelfish_showplan_all off @@ -313,7 +313,7 @@ Query Text: EXEC p_recomp_11 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 1.338 ms +Babelfish T-SQL Batch Parsing Time: 0.856 ms ~~END~~ -- test case without execute keyword @@ -334,7 +334,7 @@ Query Text: EXEC p_recomp_11 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.148 ms +Babelfish T-SQL Batch Parsing Time: 0.139 ms ~~END~~ set babelfish_showplan_all off @@ -363,7 +363,7 @@ Query Text: EXEC p_recomp_13 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.321 ms +Babelfish T-SQL Batch Parsing Time: 0.210 ms ~~END~~ exec p_recomp_13 0 with recompile @@ -385,7 +385,7 @@ Query Text: EXEC p_recomp_13 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.119 ms +Babelfish T-SQL Batch Parsing Time: 0.085 ms ~~END~~ set babelfish_showplan_all off @@ -485,7 +485,7 @@ Query Text: EXEC p_recomp_11 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.113 ms +Babelfish T-SQL Batch Parsing Time: 0.073 ms ~~END~~ exec p_recomp_12 0 with recompile @@ -503,7 +503,7 @@ Query Text: EXEC p_recomp_12 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.114 ms +Babelfish T-SQL Batch Parsing Time: 0.082 ms ~~END~~ set babelfish_showplan_all off @@ -528,7 +528,7 @@ Query Text: EXEC p_recomp_12 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.102 ms +Babelfish T-SQL Batch Parsing Time: 0.064 ms ~~END~~ set babelfish_showplan_all off @@ -555,7 +555,7 @@ Query Text: EXEC p_recomp_13 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.110 ms +Babelfish T-SQL Batch Parsing Time: 0.069 ms ~~END~~ set babelfish_showplan_all off @@ -584,7 +584,7 @@ Query Text: EXEC p_recomp_13 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.096 ms +Babelfish T-SQL Batch Parsing Time: 0.062 ms ~~END~~ exec p_recomp_13 0 with recompile @@ -604,7 +604,7 @@ Query Text: EXEC p_recomp_13 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.118 ms +Babelfish T-SQL Batch Parsing Time: 0.078 ms ~~END~~ set babelfish_showplan_all off @@ -657,7 +657,7 @@ Query Text: EXEC p_recomp_21 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.330 ms +Babelfish T-SQL Batch Parsing Time: 0.217 ms ~~END~~ set babelfish_showplan_all off @@ -701,7 +701,7 @@ Query Text: EXEC p_recomp_21 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.117 ms +Babelfish T-SQL Batch Parsing Time: 0.071 ms ~~END~~ @@ -726,7 +726,7 @@ Query Text: EXEC p_recomp_22 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.299 ms +Babelfish T-SQL Batch Parsing Time: 0.196 ms ~~END~~ set babelfish_showplan_all off @@ -755,7 +755,7 @@ Query Text: EXEC p_recomp_22 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.105 ms +Babelfish T-SQL Batch Parsing Time: 0.064 ms ~~END~~ set babelfish_showplan_all off @@ -797,7 +797,7 @@ Query Text: EXEC p_recomp_21 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.114 ms +Babelfish T-SQL Batch Parsing Time: 0.071 ms ~~END~~ @@ -820,7 +820,7 @@ Query Text: EXEC p_recomp_22 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.114 ms +Babelfish T-SQL Batch Parsing Time: 0.075 ms ~~END~~ set babelfish_showplan_all off @@ -849,7 +849,7 @@ Query Text: EXEC p_recomp_22 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.100 ms +Babelfish T-SQL Batch Parsing Time: 0.064 ms ~~END~~ set babelfish_showplan_all off @@ -900,7 +900,7 @@ Query Text: EXEC p_recomp_31 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.324 ms +Babelfish T-SQL Batch Parsing Time: 0.229 ms ~~END~~ set babelfish_showplan_all off @@ -945,7 +945,7 @@ Query Text: EXEC p_recomp_31 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.111 ms +Babelfish T-SQL Batch Parsing Time: 0.070 ms ~~END~~ @@ -970,7 +970,7 @@ Query Text: EXEC p_recomp_32 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.302 ms +Babelfish T-SQL Batch Parsing Time: 0.191 ms ~~END~~ set babelfish_showplan_all off @@ -999,7 +999,7 @@ Query Text: EXEC p_recomp_32 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.102 ms +Babelfish T-SQL Batch Parsing Time: 0.064 ms ~~END~~ set babelfish_showplan_all off @@ -1028,7 +1028,7 @@ Query Text: EXEC p_recomp_33 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.309 ms +Babelfish T-SQL Batch Parsing Time: 0.190 ms ~~END~~ --- tb_recomp_33: with RECOMPILE: bitmap scans ---- @@ -1052,7 +1052,7 @@ Query Text: EXEC p_recomp_33 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.102 ms +Babelfish T-SQL Batch Parsing Time: 0.077 ms ~~END~~ set babelfish_showplan_all off @@ -1094,7 +1094,7 @@ Query Text: EXEC p_recomp_31 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.090 ms +Babelfish T-SQL Batch Parsing Time: 0.071 ms ~~END~~ --- p_recomp_32: EXEC with RECOMPILE: recompiled plan: index scan for paramtrized, bitmap scan for non-parametrized ---- @@ -1116,7 +1116,7 @@ Query Text: EXEC p_recomp_32 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.078 ms +Babelfish T-SQL Batch Parsing Time: 0.103 ms ~~END~~ set babelfish_showplan_all off @@ -1143,7 +1143,7 @@ Query Text: EXEC p_recomp_32 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.064 ms +Babelfish T-SQL Batch Parsing Time: 0.063 ms ~~END~~ set babelfish_showplan_all off @@ -1170,7 +1170,7 @@ Query Text: EXEC p_recomp_33 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.116 ms +Babelfish T-SQL Batch Parsing Time: 0.070 ms ~~END~~ set babelfish_showplan_all off @@ -1197,7 +1197,7 @@ Query Text: EXEC p_recomp_33 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.100 ms +Babelfish T-SQL Batch Parsing Time: 0.062 ms ~~END~~ --- tb_recomp_33 with RECOMPILE: index scan for paramtrized stmt, bitmap scan for non-param stmt ---- @@ -1219,7 +1219,7 @@ Query Text: EXEC p_recomp_33 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.114 ms +Babelfish T-SQL Batch Parsing Time: 0.073 ms ~~END~~ set babelfish_showplan_all off @@ -1392,7 +1392,7 @@ Query Text: EXEC p_recomp_61 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.094 ms +Babelfish T-SQL Batch Parsing Time: 0.161 ms ~~END~~ set babelfish_showplan_all off @@ -1447,7 +1447,7 @@ Query Text: EXEC p_recomp_61 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.093 ms +Babelfish T-SQL Batch Parsing Time: 0.158 ms ~~END~~ set babelfish_showplan_all off @@ -1484,7 +1484,7 @@ Query Text: EXEC p_recomp_61 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.150 ms +Babelfish T-SQL Batch Parsing Time: 0.231 ms ~~END~~ set babelfish_showplan_all off @@ -1535,7 +1535,7 @@ Query Text: EXEC p_recomp_61 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.093 ms +Babelfish T-SQL Batch Parsing Time: 0.094 ms ~~END~~ set babelfish_showplan_all off @@ -1568,7 +1568,7 @@ Query Text: EXEC p_recomp_61 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.110 ms +Babelfish T-SQL Batch Parsing Time: 0.108 ms ~~END~~ set babelfish_showplan_all off @@ -2011,7 +2011,7 @@ Query Text: EXEC p_recomp_51 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.065 ms +Babelfish T-SQL Batch Parsing Time: 0.074 ms ~~END~~ set babelfish_showplan_all off @@ -2105,7 +2105,7 @@ Query Text: EXEC p_recomp_51 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.105 ms +Babelfish T-SQL Batch Parsing Time: 0.067 ms ~~END~~ set babelfish_showplan_all off @@ -2184,7 +2184,7 @@ Query Text: EXEC p_recomp_51 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.109 ms +Babelfish T-SQL Batch Parsing Time: 0.075 ms ~~END~~ set babelfish_showplan_all off @@ -2269,7 +2269,7 @@ Query Text: EXEC p_recomp_51 0 ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.097 ms +Babelfish T-SQL Batch Parsing Time: 0.066 ms ~~END~~ set babelfish_showplan_all off @@ -2337,7 +2337,7 @@ Query Text: EXEC p_recomp_51 0 /* EXECUTE WITH RECOMPILE */ ~~START~~ text -Babelfish T-SQL Batch Parsing Time: 0.111 ms +Babelfish T-SQL Batch Parsing Time: 0.077 ms ~~END~~ set babelfish_showplan_all off diff --git a/test/JDBC/input/BABEL-5422.sql b/test/JDBC/input/BABEL-5422.sql new file mode 100644 index 0000000000..563106433b --- /dev/null +++ b/test/JDBC/input/BABEL-5422.sql @@ -0,0 +1,138 @@ +-- Create tables +CREATE TABLE babel_5422_table ( + [primary] INT PRIMARY KEY, + Name VARCHAR(50) +); +GO + +CREATE TABLE babel_5422_table2 ( + [PRIMARY] INT, + Age INT +); +GO + +CREATE TABLE #babel_5422_table3 ( + [primary_column] INT, + Age INT +); +GO + +-- Insert sample data +INSERT INTO babel_5422_table ([primary], Name) +VALUES (1, 'John'), (2, 'Jane'), (3, 'Bob'); +GO + +INSERT INTO babel_5422_table2 ([primary], Age) +VALUES (1, 25), (3, 30); +GO + +INSERT INTO #babel_5422_table3 ([primary_column], Age) +VALUES (1, 30), (3, 40); +GO + +-- Aliasing +SELECT [primary] AS PrimaryKey, Name +FROM babel_5422_table; +GO + +SELECT [primary_column] AS [Primary], Age +FROM #babel_5422_table3; +GO + +-- Joining Tables +SELECT t1.[primary], t1.Name, t2.Age +FROM babel_5422_table t1 +JOIN babel_5422_table2 t2 ON t1.[primary] = t2.[primary]; +GO + +-- Aggregation +SELECT COUNT([primary]) AS TotalRows +FROM babel_5422_table; +GO + +-- Ordering +SELECT * +FROM babel_5422_table +ORDER BY [primary] DESC; +GO + +-- Checking for Existence +IF EXISTS (SELECT 1 FROM babel_5422_table WHERE [primary] = 3) + PRINT 'Row with [primary] = 3 exists'; +ELSE + PRINT 'Row with [primary] = 3 does not exist'; +GO + +-- Using in a CASE Statement +SELECT [primary], + CASE + WHEN [primary] = 1 THEN 'One' + WHEN [primary] = 2 THEN 'Two' + ELSE 'Other' + END AS PrimaryDescription +FROM babel_5422_table; +GO + +-- Using in a Subquery +SELECT Name +FROM babel_5422_table +WHERE [primary] IN (SELECT [primary] FROM babel_5422_table2); +GO + +-- Using in a View +CREATE VIEW babel_5422_view +AS +SELECT [primary], Name +FROM babel_5422_table; +GO + +SELECT * FROM babel_5422_view; +GO + +-- Using in a Stored Procedure +CREATE PROCEDURE babel_5422_proc + @PrimaryKey INT +AS +BEGIN + SELECT [primary], Name + FROM babel_5422_table + WHERE [primary] = @PrimaryKey; +END +GO + +EXEC babel_5422_proc 2; +GO + +-- Using in a User-Defined Function +CREATE FUNCTION babel_5422_func + (@PrimaryKey INT) +RETURNS TABLE +AS +RETURN( + SELECT [primary], Name + FROM babel_5422_table + WHERE [primary] = @PrimaryKey +) +GO + +SELECT babel_5422_func(3); +GO + +-- Cleanup +DROP FUNCTION babel_5422_func; +GO + +DROP PROCEDURE babel_5422_proc; +GO + +DROP VIEW babel_5422_view; +GO + +DROP TABLE #babel_5422_table3 +GO + +DROP TABLE babel_5422_table2; +GO + +DROP TABLE babel_5422_table; +GO \ No newline at end of file diff --git a/test/JDBC/input/BABEL-CROSS-DB.mix b/test/JDBC/input/BABEL-CROSS-DB.mix index 65519d0547..05ebc64454 100644 --- a/test/JDBC/input/BABEL-CROSS-DB.mix +++ b/test/JDBC/input/BABEL-CROSS-DB.mix @@ -632,283 +632,3 @@ GO DROP DATABASE db2; GO - --- BABEL-4934 Test blocking cross-db SELECT-INTO statement -CREATE DATABASE db_4934_1; -GO - -CREATE DATABASE db_4934_2; -GO - -USE master; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_1; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_2; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_1; -GO - --- #4934.1 It should be blocked -SELECT * INTO t222 FROM master.dbo.t1; -GO - -SELECT * INTO t222 FROM master..t1; -GO - -SELECT * INTO t222 FROM db_4934_2..t1; -GO - -SELECT * INTO t222 FROM db_4934_2.dbo.t1; -GO - -SELECT * INTO t222 FROM db_4934_2..t1, t1; -GO - -SELECT * INTO t222 FROM t1, db_4934_1..t2; -GO - -SELECT * INTO t222 FROM master..t1, db_4934_2..t1; -GO - -SELECT * INTO t222 FROM (SELECT * FROM master..t1); -GO - -SELECT * INTO t222 FROM (SELECT * FROM t1, master..t1); -GO - -SELECT * INTO t222 FROM (SELECT *, (SELECT * FROM master..t1) FROM t1); -GO - -SELECT * INTO t222 FROM (SELECT *, (SELECT * FROM t1) FROM master..t3); -GO - -SELECT * INTO master..t222 FROM db_4934_2..t1; -GO - -SELECT * INTO db_4934_1..t222 FROM db_4934_2..t1; -GO - -SELECT * INTO master..t222 FROM master..t1; -GO - --- #4934.2 Following statements will succeed across same database -SELECT * INTO t3 FROM db_4934_1.dbo.t1; -GO - -SELECT * INTO t4 FROM dbo.t1; -GO - -SELECT * INTO t5 FROM db_4934_1..t1; -GO - -SELECT * INTO t6 FROM db_4934_1..t1, db_4934_1..t2; -GO - -SELECT * INTO t7 FROM (SELECT * FROM db_4934_1..t1); -GO - -SELECT * INTO t8 FROM (SELECT *, (SELECT * FROM db_4934_1..t2) FROM db_4934_1..t1); -GO - --- validate the access -SELECT * FROM t3, t4, t5, t6, t7, t8; -GO - -DROP TABLE t3, t4, t5, t6, t7, t8; -GO - --- #4934.3 Temporary table should not be blocked -SELECT * INTO #t1 FROM db_4934_1.dbo.t1; -GO - -SELECT * INTO #t2 FROM (SELECT * FROM db_4934_1.dbo.t1); -GO - --- validate the access -SELECT * FROM #t1, #t2; -GO - -DROP TABLE #t1, #t2; -GO - --- Even though this is same as above statement, this will still fail since --- internally it considers as cross-db statement (This behaviour is general to --- all of the applicable DMLs) -SELECT * INTO tempdb..#t3 FROM db_4934_1.dbo.t1; -GO - - -USE master; -GO - -DROP TABLE t1, t2; -GO - -DROP DATABASE db_4934_1; -GO - -DROP DATABASE db_4934_2; -GO - --- Repeating tests with AI collated database --- BABEL-4934 Test blocking cross-db SELECT-INTO statement -CREATE DATABASE db_4934_1 COLLATE BBF_Unicode_CP1_CI_AI; -GO - -CREATE DATABASE db_4934_2 COLLATE BBF_Unicode_CP1_CI_AI; -GO - -USE master; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_1; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_2; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_1; -GO - --- #4934.1 It should be blocked -SELECT * INTO t222 FROM master.dbo.t1; -GO - -SELECT * INTO t222 FROM master..t1; -GO - -SELECT * INTO t222 FROM db_4934_2..t1; -GO - -SELECT * INTO t222 FROM db_4934_2.dbo.t1; -GO - -SELECT * INTO t222 FROM db_4934_2..t1, t1; -GO - -SELECT * INTO t222 FROM t1, db_4934_1..t2; -GO - -SELECT * INTO t222 FROM master..t1, db_4934_2..t1; -GO - -SELECT * INTO t222 FROM (SELECT * FROM master..t1); -GO - -SELECT * INTO t222 FROM (SELECT * FROM t1, master..t1); -GO - -SELECT * INTO t222 FROM (SELECT *, (SELECT * FROM master..t1) FROM t1); -GO - -SELECT * INTO t222 FROM (SELECT *, (SELECT * FROM t1) FROM master..t3); -GO - -SELECT * INTO master..t222 FROM db_4934_2..t1; -GO - -SELECT * INTO db_4934_1..t222 FROM db_4934_2..t1; -GO - -SELECT * INTO master..t222 FROM master..t1; -GO - --- #4934.2 Following statements will succeed across same database -SELECT * INTO t3 FROM db_4934_1.dbo.t1; -GO - -SELECT * INTO t4 FROM dbo.t1; -GO - -SELECT * INTO t5 FROM db_4934_1..t1; -GO - -SELECT * INTO t6 FROM db_4934_1..t1, db_4934_1..t2; -GO - -SELECT * INTO t7 FROM (SELECT * FROM db_4934_1..t1); -GO - -SELECT * INTO t8 FROM (SELECT *, (SELECT * FROM db_4934_1..t2) FROM db_4934_1..t1); -GO - --- validate the access -SELECT * FROM t3, t4, t5, t6, t7, t8; -GO - -DROP TABLE t3, t4, t5, t6, t7, t8; -GO - --- #4934.3 Temporary table should not be blocked -SELECT * INTO #t1 FROM db_4934_1.dbo.t1; -GO - -SELECT * INTO #t2 FROM (SELECT * FROM db_4934_1.dbo.t1); -GO - --- validate the access -SELECT * FROM #t1, #t2; -GO - -DROP TABLE #t1, #t2; -GO - --- Even though this is same as above statement, this will still fail since --- internally it considers as cross-db statement (This behaviour is general to --- all of the applicable DMLs) -SELECT * INTO tempdb..#t3 FROM db_4934_1.dbo.t1; -GO - - -USE master; -GO - -DROP TABLE t1, t2; -GO - -DROP DATABASE db_4934_1; -GO - -DROP DATABASE db_4934_2; -GO - diff --git a/test/JDBC/input/BABEL_GRANT_CONNECT-vu-cleanup.mix b/test/JDBC/input/BABEL_GRANT_CONNECT-vu-cleanup.mix index 0bfdbcfd07..68ba8b00e8 100644 --- a/test/JDBC/input/BABEL_GRANT_CONNECT-vu-cleanup.mix +++ b/test/JDBC/input/BABEL_GRANT_CONNECT-vu-cleanup.mix @@ -2,7 +2,7 @@ use grant_connect_db1; go -drop user grant_connect_abc +drop user grant_connect_abc_new go drop table grant_connect_t1; diff --git a/test/JDBC/input/BABEL_GRANT_CONNECT-vu-prepare.sql b/test/JDBC/input/BABEL_GRANT_CONNECT-vu-prepare.sql index 941da73d0f..672acdf923 100644 --- a/test/JDBC/input/BABEL_GRANT_CONNECT-vu-prepare.sql +++ b/test/JDBC/input/BABEL_GRANT_CONNECT-vu-prepare.sql @@ -9,4 +9,3 @@ go create login grant_connect_abc with password = 'Babel123' go - diff --git a/test/JDBC/input/BABEL_GRANT_CONNECT-vu-verify.mix b/test/JDBC/input/BABEL_GRANT_CONNECT-vu-verify.mix index cf20153912..35441082fc 100644 --- a/test/JDBC/input/BABEL_GRANT_CONNECT-vu-verify.mix +++ b/test/JDBC/input/BABEL_GRANT_CONNECT-vu-verify.mix @@ -64,6 +64,9 @@ go use grant_connect_db1; go +select has_dbaccess('grant_connect_db1'); +go + select user_name(); go @@ -128,6 +131,9 @@ go grant connect to grant_connect_abc go +ALTER USER grant_connect_abc WITH NAME = grant_connect_abc_new; +go + -- tsql user=grant_connect_abc password=Babel123 -- should succeed because login has a user for grant_connect_db1 and it is enabled use grant_connect_db1 @@ -136,3 +142,5 @@ go select user_name(); go +select has_dbaccess('grant_connect_db1'); +go diff --git a/test/JDBC/input/atatuservar-vu-cleanup.sql b/test/JDBC/input/atatuservar-vu-cleanup.sql new file mode 100644 index 0000000000..37f2c4171f --- /dev/null +++ b/test/JDBC/input/atatuservar-vu-cleanup.sql @@ -0,0 +1,167 @@ +drop procedure p1_atatuservar +go +drop procedure p2_atatuservar +go +drop function f1_atatuservar +go +drop function f2_atatuservar +go +drop procedure p3_atatuservar +go +drop function f3_atatuservar +go +drop procedure p4_atatuservar +go +drop procedure p19_atatuservar +go +drop procedure p5_atatuservar +go +drop procedure p6_atatuservar +go +drop procedure p7_atatuservar +go +drop procedure p8_atatuservar +go +drop procedure p9_atatuservar +go +drop procedure p10_atatuservar +go +drop procedure p11_atatuservar +go +drop function f4_atatuservar +go +drop procedure p22_atatuservar +go +drop procedure p12_atatuservar +go +drop procedure p13_atatuservar +go +drop procedure p14_atatuservar +go +drop function f1_atatuservar_extra_long_name_here +go +drop function f2_atatuservar_extra_long_name_here +go +drop procedure p15_atatuservar +go +drop procedure p16_atatuservar +go +drop procedure p17_atatuservar +go +drop procedure p18_atatuservar +go +drop procedure p1_raiserror_atatuservar +go +drop procedure p1_spexec_atatuservar +go +drop procedure p2_spexec_atatuservar +go +drop function f1_ins_atatuservar +go +drop function f1_upd_atatuservar +go +drop function f1_del_atatuservar +go +drop function f3_atatuservar_upd +go +drop function f3_atatuservar_del +go +drop function f3_upd_atatuservar +go +drop function f3_del_atatuservar +go +drop function f4_ins_atatuservar +go +drop function f4_upd_atatuservar +go +drop function f4_del_atatuservar +go +drop function f5_upd_atatuservar +go +drop function f5_del_atatuservar +go +drop function f6_upd_atatuservar +go +drop function f6_del_atatuservar +go +drop function f7_tabvar_udf_upd_atatuservar +go +drop function f9_tabvar_udf_del_atatuservar +go +drop function f10_tabvar_udf_del_atatuservar +go +drop function f4_atatuservar_tabvar_in_function_upd +go +drop function f14_del_atatuservar +go +drop function f15_upd_atatuservar +go +drop procedure p20_atatuservar +go +drop procedure p21_atatuservar +go +drop procedure p1_xactname_atatuservar +go +drop procedure p2_xactname_atatuservar +go + +drop table t1_atatuservar +go +drop table t2_atatuservar +go +drop table t3_atatuservar +go +drop table t_checkident_atatuservar +go +drop table t1_trigger_atatuservar +go +drop table t2_trigger_atatuservar +go +drop table t3_trigger_atatuservar +go +drop table t4_trigger_atatuservar +go +drop table t5_trigger_atatuservar +go +drop table t6_trigger_atatuservar +go +drop table t7_trigger_atatuservar +go +drop table t8_trigger_atatuservar +go +drop table t9_trigger_atatuservar +go +drop table t10_trigger_atatuservar +go +drop table t11_trigger_atatuservar +go +drop table t12_trigger_atatuservar +go +drop table t13_trigger_atatuservar +go +drop table t14_trigger_atatuservar +go +drop table t15_trigger_atatuservar +go +drop table t16_trigger_atatuservar +go +drop table t17_trigger_atatuservar +go +drop table t18_trigger_atatuservar +go +drop table t19_trigger_atatuservar +go +drop table t20_trigger_atatuservar +go +drop table t21_trigger_atatuservar +go +drop table t22_trigger_atatuservar +go +drop table t23_trigger_atatuservar +go +drop procedure p1_cursor_atatuservar +go +drop procedure p1_sysfunctions_atatuservar +go +drop function f1_sysfunctions_atatuservar +go \ No newline at end of file diff --git a/test/JDBC/input/atatuservar-vu-prepare.sql b/test/JDBC/input/atatuservar-vu-prepare.sql new file mode 100644 index 0000000000..00efc2b954 --- /dev/null +++ b/test/JDBC/input/atatuservar-vu-prepare.sql @@ -0,0 +1,62 @@ +create table t1_atatuservar (c varchar(20)) +insert t1_atatuservar values ('row 1'), ('row 2'), ('row 3') +go +create table t2_atatuservar (a int) +insert t2_atatuservar values(123) +go +create table t3_atatuservar (a int) +insert t3_atatuservar values(123) +go +create table t_checkident_atatuservar (a varchar(20), n int identity) +go +insert t_checkident_atatuservar values('one') +insert t_checkident_atatuservar values('two') +insert t_checkident_atatuservar values('three') +insert t_checkident_atatuservar values('four') +go +create table t1_trigger_atatuservar (a int) +go +create table t2_trigger_atatuservar (a int) +go +create table t3_trigger_atatuservar (a int) +go +create table t4_trigger_atatuservar (a int) +go +create table t5_trigger_atatuservar (a int) +go +create table t6_trigger_atatuservar (a int) +go +create table t7_trigger_atatuservar (a int) +go +create table t8_trigger_atatuservar (a int) +go +create table t9_trigger_atatuservar (a int) +go +create table t10_trigger_atatuservar(a int) +go +create table t11_trigger_atatuservar(a int) +go +create table t12_trigger_atatuservar(a int) +go +create table t13_trigger_atatuservar(a int) +go +create table t14_trigger_atatuservar(a int) +go +create table t15_trigger_atatuservar(a int) +go +create table t16_trigger_atatuservar(a int) +go +create table t17_trigger_atatuservar(a int) +go +create table t18_trigger_atatuservar(a int) +go +create table t19_trigger_atatuservar(a int) +go +create table t20_trigger_atatuservar(a int) +go +create table t21_trigger_atatuservar(a int) +go +create table t22_trigger_atatuservar(a int) +go +create table t23_trigger_atatuservar(a int) +go \ No newline at end of file diff --git a/test/JDBC/input/atatuservar-vu-verify.sql b/test/JDBC/input/atatuservar-vu-verify.sql new file mode 100644 index 0000000000..dd7e1b2f1c --- /dev/null +++ b/test/JDBC/input/atatuservar-vu-verify.sql @@ -0,0 +1,1842 @@ +-- simple variables in T-SQL batch +set quoted_identifier off +go +declare @@v int = 2 select @@v +go +declare @#v int = 2 select @#v +go +declare @@@$$@@@@v int = 2 select @@@$$@@@@v +go +declare @@@$$@@@@v##### int = 2 select @@@$$@@@@v##### +go +declare @@@$$@@@@#####v int = 2 select @@@$$@@@@#####v +go +declare @#############v int = 2 select @#############v +go + +-- 63 long +declare @@v63_7890123456789$123456789$123456789012345678901234567890123 int = 2 +select @@v63_7890123456789$123456789$123456789012345678901234567890123 +go +-- 64 long +declare @@v64_7890123456789$123456789$1234567890123456789012345678901234 int = 2 +select @@v64_7890123456789$123456789$1234567890123456789012345678901234 +go +-- maximum length in T-SQL is 128 +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int = 2 +select @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +go + +declare @#v63_7890123456789$123456789$123456789012345678901234567890123 int = 2 +select @#v63_7890123456789$123456789$123456789012345678901234567890123 +go +declare @#v64_7890123456789$123456789$1234567890123456789012345678901234 int = 2 +select @#v64_7890123456789$123456789$1234567890123456789012345678901234 +go +declare @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int = 2 +select @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +go +declare @@v128_@@@$$@@@@$$@########@@@$$@@@@$$@@@@$$@@@###__##@@@$$@@@@$$@@@@$$@@@@$$@@@______@@@$$@@@@$$@@@@$$@@@###########@@@$$@@@@@@ int = 2 +select @@v128_@@@$$@@@@$$@########@@@$$@@@@$$@@@@$$@@@###__##@@@$$@@@@$$@@@@$$@@@@$$@@@______@@@$$@@@@$$@@@@$$@@@###########@@@$$@@@@@@ +go + +-- referencing global @@variable, in T-SQL batch, procedure, trigger and function +declare @@v int +select 1 +set @@v = @@rowcount +select @@v +go + +declare @@@$$@@@@v int, @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int +select 1 +set @@@$$@@@@v = @@rowcount +set @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 = @@pgerror +select @@@$$@@@@v, @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +go + +declare @@v63_7890123456789$123456789$123456789012345678901234567890123 int +set @@v63_7890123456789$123456789$123456789012345678901234567890123 = @@rowcount +select @@v63_7890123456789$123456789$123456789012345678901234567890123 +go + +declare @#v64_7890123456789$123456789$1234567890123456789012345678901234 int +set @#v64_7890123456789$123456789$1234567890123456789012345678901234 = @@rowcount +select @#v64_7890123456789$123456789$1234567890123456789012345678901234 +go + +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int +set @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 = @@rowcount +select @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +go + +create procedure p1_atatuservar +as +declare @@v int +select 1 +set @@v = @@rowcount +select @@v + +declare @#v int +select 1 +set @#v = @@rowcount +select @#v +go +exec p1_atatuservar +go + +create procedure p2_atatuservar +as +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int, @@p128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int +select 1 +set @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 = @@rowcount +select @@p128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 = @@pgerror +select @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678, @@p128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 + +declare @#v64_7890123456789$123456789$1234567890123456789012345678901234 int +select 1 +set @#v64_7890123456789$123456789$1234567890123456789012345678901234 = @@rowcount +select @#v64_7890123456789$123456789$1234567890123456789012345678901234 +go +exec p2_atatuservar +go + +create trigger tr1_atatuservar on t1_trigger_atatuservar for insert +as +begin +select 'trigger tr1_atatuservar' +declare @@v int +select 1 +set @@v = @@rowcount +select @@v + +declare @#v int +select 1 +set @#v = @@rowcount +select @#v +end +go +insert t1_trigger_atatuservar values (123) +go + +create trigger tr2_atatuservar on t2_trigger_atatuservar for insert +as +begin +select 'trigger tr2_atatuservar' + +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int +select 1 +set @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 = @@rowcount +select @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 + +declare @#v64_7890123456789$123456789$1234567890123456789012345678901234 int +select 1 +set @#v64_7890123456789$123456789$1234567890123456789012345678901234 = @@rowcount +select @#v64_7890123456789$123456789$1234567890123456789012345678901234 +end +go +insert t2_trigger_atatuservar values (123) +go + +create function f1_atatuservar() returns int +as +begin +declare @@v int, @@v2 int +select @@v2 = count(*) from t1_atatuservar +set @@v = @@rowcount + +declare @#v int, @#v2 int +select @#v2 = count(*) from t1_atatuservar +set @#v = @@rowcount + +return @@v * @#v +end +go +select dbo.f1_atatuservar() +go + +create function f2_atatuservar() returns int +as +begin +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int, @#v64_7890123456789$123456789$1234567890123456789012345678901234 int +select @#v64_7890123456789$123456789$1234567890123456789012345678901234 = count(*) from t1_atatuservar +set @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 = @@rowcount + +return @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 * @#v64_7890123456789$123456789$1234567890123456789012345678901234 +end +go +select dbo.f2_atatuservar() +go + +create trigger tr3_atatuservar on t3_trigger_atatuservar for insert +as +begin +select 'trigger tr3_atatuservar' +declare @@v int, @@v2 int +select @@v2 = count(*) from t1_atatuservar +set @@v = @@rowcount +select @@v + +declare @#v int, @#v2 int +select @#v2 = count(*) from t1_atatuservar +set @#v = @@rowcount +select @#v +end +go +insert t3_trigger_atatuservar values (123) +go + +-- assuming @@servername is BABELFISH +declare @v varchar(50) +set @v = @@servername +select @v +go + +declare @v int +set @v = len(@@servername) +select @v +go + +create procedure p3_atatuservar +as +declare @v varchar(50) +set @v = @@servername +select @v + +declare @v2 int +set @v2 = len(@@servername) +select @v2 +go +exec p3_atatuservar +go + +create function f3_atatuservar(@#p1 varchar(30)) returns int +as +begin +declare @@v int +set @@v = len(@@servername) +return @@v * len(@#p1) +end +go +select dbo.f3_atatuservar(@@servername) +go + +create trigger tr4_atatuservar on t4_trigger_atatuservar for insert +as +begin +select 'trigger tr4_atatuservar' +declare @@v int +set @@v = len(@@servername) +select @@v +end +go +insert t4_trigger_atatuservar values (123) +go + +-- procedure call with named/unnamed arguments, output parameters, return status, in T-SQL batch, procedure, trigger +create procedure p4_atatuservar @@p1 int +as select @@p1 +return @@p1*-1 +go +exec p4_atatuservar 123 +go +exec p4_atatuservar @@p1=123 +go +declare @@v int = 987 +exec p4_atatuservar @@p1=@@v +go +declare @@v int +exec @@v = p4_atatuservar @@p1=123 +select @@v +go + +create procedure p19_atatuservar @#p19_atatuservar int +as select @#p19_atatuservar +return @#p19_atatuservar*-1 +go +exec p19_atatuservar @@max_precision +go +exec p19_atatuservar @#p19_atatuservar=@@max_precision +go +declare @#v int = @@max_precision +exec p19_atatuservar @#p19_atatuservar=@#v +go +declare @#v int +exec @#v = p19_atatuservar @#p19_atatuservar=@@max_precision +select @#v +go + +create procedure p5_atatuservar +as +declare @@v int +exec @@v = p4_atatuservar @@p1=123 +select @@v + +declare @#v int +exec @#v = p4_atatuservar @@p1=123 +select @#v +go +exec p5_atatuservar +go + +create procedure p6_atatuservar @@p4 int output +as +set @@p4 *= 2 +select @@p4 +return @@p4*-1 +go +declare @#v1 int, @@v2 int = 123 +exec @#v1 = p6_atatuservar @@v2 +select @#v1, @@v2 +go + +declare @#v1 int, @@v2 int = 123 +exec @#v1 = p6_atatuservar @@p4 = @@v2 out +select @#v1, @@v2 +go + +create procedure p7_atatuservar +as +declare @#v1 int, @@v2 int = 123 +exec @#v1 = p6_atatuservar @@v2 output +select @#v1, @@v2 +go + +create procedure p8_atatuservar @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int output +as +set @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 *= 2 +select @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +return @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678*-1 +go +declare @#v64_7890123456789$123456789$1234567890123456789012345678901234 int, @@v63_7890123456789$123456789$123456789012345678901234567890123 int = 123 +exec @#v64_7890123456789$123456789$1234567890123456789012345678901234 = p8_atatuservar @@v63_7890123456789$123456789$123456789012345678901234567890123 +select @#v64_7890123456789$123456789$1234567890123456789012345678901234, @@v63_7890123456789$123456789$123456789012345678901234567890123 +go + +declare @#v64_7890123456789$123456789$1234567890123456789012345678901234 int, @@v63_7890123456789$123456789$123456789012345678901234567890123 int = 123 +exec @#v64_7890123456789$123456789$1234567890123456789012345678901234 = p8_atatuservar @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 = @@v63_7890123456789$123456789$123456789012345678901234567890123 out +select @#v64_7890123456789$123456789$1234567890123456789012345678901234, @@v63_7890123456789$123456789$123456789012345678901234567890123 +go + +create procedure p9_atatuservar +as +declare @#v64_7890123456789$123456789$1234567890123456789012345678901234 int, @@v63_7890123456789$123456789$123456789012345678901234567890123 int = 123 +exec @#v64_7890123456789$123456789$1234567890123456789012345678901234 = p8_atatuservar @@v63_7890123456789$123456789$123456789012345678901234567890123 output +select @#v64_7890123456789$123456789$1234567890123456789012345678901234, @@v63_7890123456789$123456789$123456789012345678901234567890123 +go + +create trigger tr5_atatuservar on t5_trigger_atatuservar for insert +as +begin +select 'trigger tr5_atatuservar' +declare @@v int +exec @@v = p4_atatuservar @@p1=123 +select @@v + +declare @#v int +exec @#v = p4_atatuservar @@p1=123 +select @#v +end +go +insert t5_trigger_atatuservar values (123) +go + +create trigger tr6_atatuservar on t6_trigger_atatuservar for insert +as +begin +select 'trigger tr6_atatuservar' + +declare @#v64_7890123456789$123456789$1234567890123456789012345678901234 int, @@v63_7890123456789$123456789$123456789012345678901234567890123 int = 123 +exec @#v64_7890123456789$123456789$1234567890123456789012345678901234 = p8_atatuservar @@v63_7890123456789$123456789$123456789012345678901234567890123 output +select @#v64_7890123456789$123456789$1234567890123456789012345678901234, @@v63_7890123456789$123456789$123456789012345678901234567890123 +end +go +insert t6_trigger_atatuservar values (123) +go + +-- misc variable usage in expressions +declare @#v int = 3 +set @#v *= -1 +set @#v = @#v + 10*@#v +select @#v = @#v + 1 +if @#v > 0 select 'positive' else select 'negative' +select @#v, @#V, '@#v' +print @#v -- PRINT output not captured by JDBC tests +go + +declare @@v int = 3 +set @@v *= -1 +set @@v = @@v + 10*@@v +select @@v = @@v + 1 +if @@v > 0 select 'positive' else select 'negative' +select @@v , @@V, '@@v' +print @@V -- PRINT output not captured by JDBC tests +go + +create procedure p10_atatuservar +as +declare @#v int = 3 +set @#v *= -1 +set @#v = @#v + 10*@#v +select @#v = @#v + 1 +if @#v > 0 select 'positive' else select 'negative' +select @#v, @#V, '@#v' +print @#v -- PRINT output not captured by JDBC tests + +declare @@v int = 3 +set @@v *= -1 +set @@v = @@v + 10*@@v +select @@v = @@v + 1 +if @@v > 0 select 'positive' else select 'negative' +select @@v , @@V, '@@v' +print @@V -- PRINT output not captured by JDBC tests +go +exec p10_atatuservar +go + +declare @@c varchar(20)='abcd', @#v1 int=2, @v2@# int=1 +select substring(@@c, @#v1, @v2@#) +go + +declare @@v1 varchar(20)='row 1', @#v2 varchar(20)='row 3' +select * from t1_atatuservar where c in (@@v1, @#v2) order by 1 +go + +declare @@v1 varchar(20)='1', @#v2 varchar(20)='3' +select * from t1_atatuservar where c like '%'+@@v1 or c like '%'+@#v2 order by 1 +go + +create procedure p11_atatuservar +as +declare @@c varchar(20)='abcd', @#v int=2, @v@# int=1 +select substring(@@c, @#v, @v@#) + +declare @@v1 varchar(20)='row 1', @#v1 varchar(20)='row 3' +select * from t1_atatuservar where c in (@@v1, @#v1) order by 1 + +declare @@v2 varchar(20)='1', @#v2 varchar(20)='3' +select * from t1_atatuservar where c like '%'+@@v2 or c like '%'+@#v2 order by 1 +go +exec p11_atatuservar +go + +create function f4_atatuservar (@@p1 int, @#p2 int, @p5_atatuservar int) +returns table +as +return (select @@p1*@#p2*@p5_atatuservar as x where @@p1 = 123 or @#p2 = 10 or @p5_atatuservar = 1) +go +select * from dbo.f4_atatuservar(123, 20, 2) +go +select * from dbo.f4_atatuservar(345, 10, 2) +go +select * from dbo.f4_atatuservar(345, 20, 1) +go + +declare @@c varchar(30), @#v int=1, @#v2 int=2 +set @@c = case when @#v > 0 then '> zero' else '<- zero' end +select @@c +set @@c = case @#v when 0 then 'zero' else '<> zero' end +select @@c +set @@c = case @#v when 0 then 'zero' when @#v2 then 'case 2' else 'something else' end +select @@c +set @@c = case @#v+@#v when 0 then 'zero' when @#v2 then 'case 2' else 'something else' end +select @@c +go + +create procedure p22_atatuservar +as +declare @@c varchar(30), @#v int=1, @#v2 int=2 +set @@c = case when @#v > 0 then '> zero' else '<- zero' end +select @@c +set @@c = case @#v when 0 then 'zero' else '<> zero' end +select @@c +set @@c = case @#v when 0 then 'zero' when @#v2 then 'case 2' else 'something else' end +select @@c +set @@c = case @#v+@#v when 0 then 'zero' when @#v2 then 'case 2' else 'something else' end +select @@c +go +exec p22_atatuservar +go + +create trigger tr7_atatuservar on t7_trigger_atatuservar for insert +as +begin +select 'trigger tr7_atatuservar' + +declare @@z128_@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@_____############################################################ varchar(30), @#v64_7890123456789$123456789$1234567890123456789012345678901234 int=1, @#w64_7890123456789$123456789$1234567890123456789012345678901234 int=2 +set @@z128_@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@_____############################################################ = case when @#v64_7890123456789$123456789$1234567890123456789012345678901234 > 0 then '> zero' else '<- zero' end +select @@z128_@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@_____############################################################ +set @@z128_@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@_____############################################################ = case @#v64_7890123456789$123456789$1234567890123456789012345678901234 when 0 then 'zero' else '<> zero' end +select @@z128_@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@_____############################################################ +set @@z128_@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@_____############################################################ = case @#v64_7890123456789$123456789$1234567890123456789012345678901234 when 0 then 'zero' when @#w64_7890123456789$123456789$1234567890123456789012345678901234 then 'case 2' else 'something else' end +select @@z128_@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@_____############################################################ +set @@z128_@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@_____############################################################ = case @#v64_7890123456789$123456789$1234567890123456789012345678901234+@#v64_7890123456789$123456789$1234567890123456789012345678901234 when 0 then 'zero' when @#w64_7890123456789$123456789$1234567890123456789012345678901234 then 'case 2' else 'something else' end + +declare @#x64_7890123456789$123456789$1234567890123456789012345678901234 int = 3 +set @#x64_7890123456789$123456789$1234567890123456789012345678901234 *= -1 +set @#x64_7890123456789$123456789$1234567890123456789012345678901234 = @#x64_7890123456789$123456789$1234567890123456789012345678901234 + 10*@#x64_7890123456789$123456789$1234567890123456789012345678901234 +select @#x64_7890123456789$123456789$1234567890123456789012345678901234 = @#x64_7890123456789$123456789$1234567890123456789012345678901234 + 1 +if @#x64_7890123456789$123456789$1234567890123456789012345678901234 > 0 select 'positive' else select 'negative' +select @#x64_7890123456789$123456789$1234567890123456789012345678901234, @#x64_7890123456789$123456789$1234567890123456789012345678901234, '@#x64_7890123456789$123456789$1234567890123456789012345678901234' +print @#x64_7890123456789$123456789$1234567890123456789012345678901234 -- PRINT output not captured by JDBC tests + +declare @@v128_@@@$$@@@@$$@########@@@$$@@@@$$@@@@$$@@@###__##@@@$$@@@@$$@@@@$$@@@@$$@@@______@@@$$@@@@$$@@@@$$@@@###########@@@$$@@@@@@ int = 3 +set @@v128_@@@$$@@@@$$@########@@@$$@@@@$$@@@@$$@@@###__##@@@$$@@@@$$@@@@$$@@@@$$@@@______@@@$$@@@@$$@@@@$$@@@###########@@@$$@@@@@@ *= -1 +set @@v128_@@@$$@@@@$$@########@@@$$@@@@$$@@@@$$@@@###__##@@@$$@@@@$$@@@@$$@@@@$$@@@______@@@$$@@@@$$@@@@$$@@@###########@@@$$@@@@@@ = @@v128_@@@$$@@@@$$@########@@@$$@@@@$$@@@@$$@@@###__##@@@$$@@@@$$@@@@$$@@@@$$@@@______@@@$$@@@@$$@@@@$$@@@###########@@@$$@@@@@@ + 10*@@v128_@@@$$@@@@$$@########@@@$$@@@@$$@@@@$$@@@###__##@@@$$@@@@$$@@@@$$@@@@$$@@@______@@@$$@@@@$$@@@@$$@@@###########@@@$$@@@@@@ +select @@v128_@@@$$@@@@$$@########@@@$$@@@@$$@@@@$$@@@###__##@@@$$@@@@$$@@@@$$@@@@$$@@@______@@@$$@@@@$$@@@@$$@@@###########@@@$$@@@@@@ = @@v128_@@@$$@@@@$$@########@@@$$@@@@$$@@@@$$@@@###__##@@@$$@@@@$$@@@@$$@@@@$$@@@______@@@$$@@@@$$@@@@$$@@@###########@@@$$@@@@@@ + 1 +if @@v128_@@@$$@@@@$$@########@@@$$@@@@$$@@@@$$@@@###__##@@@$$@@@@$$@@@@$$@@@@$$@@@______@@@$$@@@@$$@@@@$$@@@###########@@@$$@@@@@@ > 0 select 'positive' else select 'negative' +select @@v128_@@@$$@@@@$$@########@@@$$@@@@$$@@@@$$@@@###__##@@@$$@@@@$$@@@@$$@@@@$$@@@______@@@$$@@@@$$@@@@$$@@@###########@@@$$@@@@@@ , @@v128_@@@$$@@@@$$@########@@@$$@@@@$$@@@@$$@@@###__##@@@$$@@@@$$@@@@$$@@@@$$@@@______@@@$$@@@@$$@@@@$$@@@###########@@@$$@@@@@@, '@@v128_@@@$$@@@@$$@########@@@$$@@@@$$@@@@$$@@@###__##@@@$$@@@@$$@@@@$$@@@@$$@@@______@@@$$@@@@$$@@@@$$@@@###########@@@$$@@@@@@' +print @@v128_@@@$$@@@@$$@########@@@$$@@@@$$@@@@$$@@@###__##@@@$$@@@@$$@@@@$$@@@@$$@@@______@@@$$@@@@$$@@@@$$@@@###########@@@$$@@@@@@ -- PRINT output not captured by JDBC tests + +declare @@y128_############################################______@@@$$@@@@$$@@@@__###############@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@ varchar(20)='abcd', @#p64_7890123456789$123456789$1234567890123456789012345678901234 int=2, @@#q64_890123456789$123456789$1234567890123456789012345678901234 int=1 +select substring(@@y128_############################################______@@@$$@@@@$$@@@@__###############@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@, @#p64_7890123456789$123456789$1234567890123456789012345678901234, @@#q64_890123456789$123456789$1234567890123456789012345678901234) + +declare @@q64_7890123456789$123456789$1234567890123456789012345678901234 varchar(20)='1', @#q4_7890123456789$123456789$1234567890123456789012345678901234 varchar(20)='3' +select * from t1_atatuservar where c like '%'+@@q64_7890123456789$123456789$1234567890123456789012345678901234 or c like '%'+@#q4_7890123456789$123456789$1234567890123456789012345678901234 order by 1 +end +go +insert t7_trigger_atatuservar values (123) +go + +-- table variables, in T-SQL batch, procedure and trigger (functions are below) +declare @@v table (a int) +insert @@v values (123) +select * from @@v +go + +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 table (a int) +insert @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 values (123) +select * from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +go + +declare @#v table (a int) +insert @#v values (123) +insert @#v select * from @#v +select * from @#v +update @#v set a = a + 1 +select * from @#v +set rowcount 1 +delete @#v +set rowcount 0 +select * from @#v +go + +declare @@V table (a int) +insert @@v values (123) +insert @@v select * from @@v +select * from @@v +update @@v set a = a + 1 +select * from @@v +set rowcount 1 +delete @@v +set rowcount 0 +select * from @@v +go + +create procedure p12_atatuservar +as +declare @#v table (a int) +insert @#v values (123) +insert @#v select * from @#v +select * from @#v +update @#v set a = a + 1 +select * from @#v +set rowcount 1 +delete @#v +set rowcount 0 +select * from @#v + +declare @@V table (a int) +insert @@v values (123) +insert @@v select * from @@v +select * from @@v +update @@v set a = a + 1 +select * from @@v +set rowcount 1 +delete @@v +set rowcount 0 +select * from @@v +go +exec p12_atatuservar +go + +create procedure p13_atatuservar +as +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 table (a int) +insert @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 values (123) +select * from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +insert @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 select * from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +select * from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +update @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 set a = a + 1 +select * from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +set rowcount 1 +delete @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +set rowcount 0 +select * from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +go +exec p13_atatuservar +go + +create trigger tr8_atatuservar on t8_trigger_atatuservar for insert +as +begin +select 'trigger tr8_atatuservar' + +declare @#v table (a int) +insert @#v values (123) +insert @#v select * from @#v +select * from @#v +update @#v set a = a + 1 +select * from @#v +set rowcount 1 +delete @#v +set rowcount 0 +select * from @#v + +declare @@V table (a int) +insert @@v values (123) +insert @@v select * from @@v +select * from @@v +update @@v set a = a + 1 +select * from @@v +set rowcount 1 +delete @@v +set rowcount 0 +select * from @@v +end +go +insert t8_trigger_atatuservar values (123) +go + +create trigger tr9_atatuservar on t9_trigger_atatuservar for insert +as +begin +select 'trigger tr9_atatuservar' + +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 table (a int) +insert @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 values (123) +select * from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +insert @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 select * from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +select * from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +update @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 set a = a + 1 +select * from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +set rowcount 1 +delete @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +set rowcount 0 +select * from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +end +go +insert t9_trigger_atatuservar values (123) +go + +-- @@rowcount +declare @@V int = 1 +set rowcount @@v +select * from t1_atatuservar order by 1 +set @@v = 0 +set rowcount @@v +select * from t1_atatuservar order by 1 +go + +declare @#V int = 1 +set rowcount @#v +select * from t1_atatuservar order by 1 +set @#v = 0 +set rowcount @#v +select * from t1_atatuservar order by 1 +go + +create procedure p14_atatuservar +as +declare @@V int = 1 +set rowcount @@v +select * from t1_atatuservar order by 1 +set @@v = 0 +set rowcount @@v +select * from t1_atatuservar order by 1 + +declare @#V int = 1 +set rowcount @#v +select * from t1_atatuservar order by 1 +set @#v = 0 +set rowcount @#v +select * from t1_atatuservar order by 1 +go +exec p14_atatuservar +go + +create trigger tr10_atatuservar on t10_trigger_atatuservar for insert +as +begin +select 'trigger tr10_atatuservar' + +declare @@V int = 1 +set rowcount @@v +select * from t1_atatuservar order by 1 +set @@v = 0 +set rowcount @@v +select * from t1_atatuservar order by 1 + +declare @#V int = 1 +set rowcount @#v +select * from t1_atatuservar order by 1 +set @#v = 0 +set rowcount @#v +select * from t1_atatuservar order by 1 +end +go +insert t10_trigger_atatuservar values (123) +go + +create function f1_atatuservar_extra_long_name_here() +returns @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 table (a int) +as +begin +insert @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +values (123) +return +end +go +select * from f1_atatuservar_extra_long_name_here() +go + +create function f2_atatuservar_extra_long_name_here() +returns @#v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 table (a int) +as +begin +insert @#v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +values (123) +return +end +go +select * from f2_atatuservar_extra_long_name_here() +go + +-- in SET statements that support variable argument, procedure and trigger (functions are below) +declare @@v int = 4 +set datefirst @@v +select datepart(dw, '2024-10-21') +go +set datefirst 7 +go + +declare @#v int = 5 +set datefirst @#v +select datepart(dw, '2024-10-21') +go +set datefirst 7 +go + +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int = 5 +set datefirst @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +select datepart(dw, '2024-10-21') +go +set datefirst 7 +go + +-- SET DATEFORMAT currently ignores the argument and will always use 'mdy' +declare @@v varchar(10) = 'dmy' +set dateformat @@v +select cast('01/02/03' as datetime) +go +set dateformat mdy +go + +-- SET DATEFORMAT currently silently ignores the argument and will always use 'mdy' +declare @#v varchar(10) = 'dmy' +set dateformat @#v +select cast('01/02/03' as datetime) +go +set dateformat mdy +go + +-- SET DATEFORMAT currently silently ignores the argument and will always use 'mdy' +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(10) = 'dmy' +set dateformat @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +select cast('01/02/03' as datetime) +go +set dateformat mdy +go + +-- SET LANGUAGE currently only supports english +declare @@v varchar(10) = 'dutch' +set language @@v +select @@language +go +set language us_english +go +declare @#v varchar(10) = 'french' +set language @#v +select @@language +go +set language us_english +go +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(10) = 'french' +set language @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +select @@language +go +set language us_english +go + +create procedure p15_atatuservar +as +declare @@v1 int = 4 +set datefirst @@v1 +select datepart(dw, '2024-10-21') + +declare @#v1 int = 5 +set datefirst @#v1 +select datepart(dw, '2024-10-21') + +declare @@v2 varchar(10) = 'dmy' +set dateformat @@v2 +select cast('01/02/03' as datetime) + +declare @#v3 varchar(10) = 'dutch' +set language @#v3 +select @@language +go + +exec p15_atatuservar +go +set datefirst 7 +set dateformat mdy +set language us_english +go +create procedure p16_atatuservar +as +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int = 4 +set datefirst @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +select datepart(dw, '2024-10-21') + +declare @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int = 5 +set datefirst @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +select datepart(dw, '2024-10-21') + +declare @@w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(10) = 'dmy' +set dateformat @@w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +select cast('01/02/03' as datetime) + +declare @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(10) = 'dutch' +set language @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +select @@language +go +exec p15_atatuservar +go +set datefirst 7 +set dateformat mdy +set language us_english +go + +create trigger tr11_atatuservar on t11_trigger_atatuservar for insert +as +begin +select 'trigger tr11_atatuservar' + +declare @@v1 int = 4 +set datefirst @@v1 +select datepart(dw, '2024-10-21') + +declare @#v1 int = 5 +set datefirst @#v1 +select datepart(dw, '2024-10-21') + +declare @@v2 varchar(10) = 'dmy' +set dateformat @@v2 +select cast('01/02/03' as datetime) + +declare @#v3 varchar(10) = 'dutch' +set language @#v3 +select @@language +end +go +insert t11_trigger_atatuservar values (123) +go +set datefirst 7 +set dateformat mdy +set language us_english +go + +create trigger tr12_atatuservar on t12_trigger_atatuservar for insert +as +begin +select 'trigger tr12_atatuservar' + +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int = 4 +set datefirst @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +select datepart(dw, '2024-10-21') + +declare @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int = 5 +set datefirst @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +select datepart(dw, '2024-10-21') + +declare @@w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(10) = 'dmy' +set dateformat @@w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +select cast('01/02/03' as datetime) + +declare @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(10) = 'dutch' +set language @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +select @@language +end +go +insert t12_trigger_atatuservar values (123) +go +set datefirst 7 +set dateformat mdy +set language us_english +go + +-- execute-immediate, procedure and trigger +declare @@V varchar(50) = 'select 123' execute(@@v) +go + +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(50) = 'select 123' execute(@@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678) +go + +declare @@V varchar(50) = 'declare @#v int =123 select @#v' +execute(@@v) +go + +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(500) = 'declare @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int =123 select @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678' +execute(@@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678) +go + +declare @@V varchar(50) = 'declare @#v int =123 select @#v' +execute('select 456 ' + @@v) +go + +declare @#V varchar(50) = 'declare @@v int =123 select @@v' +execute(@#v) +go + +declare @#V varchar(50) = 'declare @@v int =123 select @@v' +execute('select 456 ' + @#v) +go + +declare @#V varchar(50) = 'select 123 ' +execute(@#v + @#v) +go + +declare @#V varchar(50) = 'select 123 ', @@V varchar(50) = 'select 456 ' +execute(@#v + @@v + @@v + @#v) +go + +declare @@V varchar(50) = 'select "abc''def" ' +execute(@@v + 'select "xy''z" ' + @@V) +go + +create procedure p17_atatuservar +as +declare @#V1 varchar(50) = 'declare @@v int =123 select @@v' +execute('select 456 ' + @#v1) + +declare @#V2 varchar(50) = 'select 123 ' +execute(@#v2 + @#v2) + +declare @#V3 varchar(50) = 'select 123 ', @@V varchar(50) = 'select 456 ' +execute(@#v3 + @@v + @@v + @#v3) + +declare @@V4 varchar(50) = 'select "abc''def" ' +execute(@@v4 + 'select "xy''z" ' + @@V4) +go +exec p17_atatuservar +go + +create trigger tr13_atatuservar on t13_trigger_atatuservar for insert +as +begin +select 'trigger tr13_atatuservar' + +declare @#V1 varchar(50) = 'declare @@v int =123 select @@v' +execute('select 456 ' + @#v1) + +declare @#V2 varchar(50) = 'select 123 ' +execute(@#v2 + @#v2) + +declare @#V3 varchar(50) = 'select 123 ', @@V varchar(50) = 'select 456 ' +execute(@#v3 + @@v + @@v + @#v3) + +declare @@V4 varchar(50) = 'select "abc''def" ' +execute(@@v4 + 'select "xy''z" ' + @@V4) +end +go +insert t13_trigger_atatuservar values (123) +go + +create procedure p18_atatuservar +as +begin +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(500) = 'declare @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int =123 select @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678' +execute(@@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678) +end +go +exec p18_atatuservar +go + +create trigger tr14_atatuservar on t14_trigger_atatuservar for insert +as +begin +select 'trigger tr14_atatuservar' + +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(500) = 'declare @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int =123 select @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678' +execute(@@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678) +end +go +insert t14_trigger_atatuservar values (123) +go + +-- RAISERROR, procedure and trigger +declare @@v int=50001 +raiserror(@@v,1,1) +go + +declare @@v int=50001, @@v2 int=1 +raiserror(@@v,@@v2,1) +go + +declare @@v int=50001, @@v2 int=1, @#v3 int=1 +raiserror(@@v,@@v2,@#v3) +go + +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int=50001, @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int=1, @@y128_############################################______@@@$$@@@@$$@@@@__###############@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@ int=1 +raiserror(@@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678, @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678, @@y128_############################################______@@@$$@@@@$$@@@@__###############@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@) +go + +create procedure p1_raiserror_atatuservar +as +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int=50001, @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int=1, @@y128_############################################______@@@$$@@@@$$@@@@__###############@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@ int=1 +raiserror(@@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678, @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678, @@y128_############################################______@@@$$@@@@$$@@@@__###############@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@) +go +exec p1_raiserror_atatuservar +go + +create trigger tr15_atatuservar on t15_trigger_atatuservar for insert +as +begin +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int=50001, @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int=1, @@y128_############################################______@@@$$@@@@$$@@@@__###############@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@ int=1 +raiserror(@@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678, @#w128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678, @@y128_############################################______@@@$$@@@@$$@@@@__###############@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@$$@@@@) +end +go +insert t15_trigger_atatuservar values (123) +go + + +-- sp_executesql with named/unnamed arguments, output parameters, in T-SQL batch, procedure, trigger +exec sp_executesql N'declare @@v int=123 select @@v' +go + +exec sp_executesql N'SELECT @@v1, @#v2', N'@@v1 int, @#v2 varchar(20)', @#v2='Hello, World!', @@v1=123 +go + +declare @@sql nvarchar(50)=N'SELECT @@v1, @#v2' +exec sp_executesql @@sql, N'@@v1 int, @#v2 varchar(20)', @#v2='Hello, World!', @@v1=123 +go + +declare @@params nvarchar(50)=N'@@v1 int, @#v2 varchar(20)' +exec sp_executesql N'SELECT @@v1, @#v2', @@params, @#v2='Hello, World!', @@v1=123 +go + +declare @@sql nvarchar(50)=N'SELECT @@v1, @#v2' +declare @@params nvarchar(50)=N'@@v1 int, @#v2 varchar(20)' +exec sp_executesql @@sql, @@params, @#v2='Hello, World!', @@v1=123 +go + +declare @@sql nvarchar(50)=N'SELECT @@v1, @#v2', @@params nvarchar(50)=N'@@v1 int, @#v2 varchar(20)', @@v3 int=123, @#v4 varchar(20)='Hello, World!' +exec sp_executesql @@sql, @@params, @#v2=@#v4, @@v1=@@v3 +go + +declare @@SQLString1 NVARCHAR(100); +declare @#SQLString2 NVARCHAR(max); +declare @@ParamDef NVARCHAR(100); +SET @@SQLString1 = N'SET @#a = @@b + @@b'; +SET @#SQLString2 = N'EXEC sp_executesql N''SET @#a = @@b + @@b'', N''@#a INT OUT, @@b INT'', @#a OUTPUT, @@b;'; +SET @@ParamDef = N'@#a INT OUTPUT, @@b INT'; +declare @@p INT; +declare @#a INT; +EXEC sp_executesql @@SQLString1, @@ParamDef, @#a = @@p OUT, @@b = 10; +EXEC sp_executesql @#SQLString2, @@ParamDef, @#a = @#a OUT, @@b = 11; +SELECT @@p, @#a; +go + +create procedure p1_spexec_atatuservar +as +declare @@sql nvarchar(50)=N'SELECT @@v1, @#v2', @@params nvarchar(50)=N'@@v1 int, @#v2 varchar(20)', @@v3 int=123, @#v4 varchar(20)='Hello, World!' +exec sp_executesql @@sql, @@params, @#v2=@#v4, @@v1=@@v3 +declare @@SQLString1 NVARCHAR(100) +declare @#SQLString2 NVARCHAR(max) +declare @@ParamDef NVARCHAR(100) +SET @@SQLString1 = N'SET @#a = @@b + @@b' +SET @#SQLString2 = N'EXEC sp_executesql N''SET @#a = @@b + @@b'', N''@#a INT OUT, @@b INT'', @#a OUT, @@b' +SET @@ParamDef = N'@#a INT OUTPUT, @@b INT' +declare @@p INT +declare @#a INT +EXEC sp_executesql @@SQLString1, @@ParamDef, @#a = @@p OUT, @@b = 10 +EXEC sp_executesql @#SQLString2, @@ParamDef, @#a = @#a OUT, @@b = 11 +SELECT @@p, @#a +go +exec p1_spexec_atatuservar +go + +create trigger tr16_atatuservar on t16_trigger_atatuservar for insert +as +begin +select 'trigger tr16_atatuservar' + +declare @@sql nvarchar(50)=N'SELECT @@v1, @#v2', @@params nvarchar(50)=N'@@v1 int, @#v2 varchar(20)', @@v3 int=123, @#v4 varchar(20)='Hello, World!' +exec sp_executesql @@sql, @@params, @#v2=@#v4, @@v1=@@v3 +declare @@SQLString1 NVARCHAR(100) +declare @#SQLString2 NVARCHAR(max) +declare @@ParamDef NVARCHAR(100) +SET @@SQLString1 = N'SET @#a = @@b + @@b' +SET @#SQLString2 = N'EXEC sp_executesql N''SET @#a = @@b + @@b'', N''@#a INT OUT, @@b INT'', @#a OUT, @@b' +SET @@ParamDef = N'@#a INT OUTPUT, @@b INT' +declare @@p INT +declare @#a INT +EXEC sp_executesql @@SQLString1, @@ParamDef, @#a = @@p OUT, @@b = 10 +EXEC sp_executesql @#SQLString2, @@ParamDef, @#a = @#a OUT, @@b = 11 +SELECT @@p, @#a +end +go +insert t16_trigger_atatuservar values (123) +go + +declare @@v63_7890123456789$123456789$123456789012345678901234567890123 NVARCHAR(1000); +declare @#w63_7890123456789$123456789$123456789012345678901234567890123 NVARCHAR(max); +declare @@x63_7890123456789$123456789$123456789012345678901234567890123 NVARCHAR(1000); +SET @@v63_7890123456789$123456789$123456789012345678901234567890123 = N'SET @@z63_7890123456789$123456789$123456789012345678901234567890123 = @@p63_7890123456789$123456789$123456789012345678901234567890123 + @@p63_7890123456789$123456789$123456789012345678901234567890123'; +SET @#w63_7890123456789$123456789$123456789012345678901234567890123 = N'EXEC sp_executesql N''SET @@z63_7890123456789$123456789$123456789012345678901234567890123 = @@p63_7890123456789$123456789$123456789012345678901234567890123 + @@p63_7890123456789$123456789$123456789012345678901234567890123'', N''@@z63_7890123456789$123456789$123456789012345678901234567890123 INT OUT, @@p63_7890123456789$123456789$123456789012345678901234567890123 INT'', @@z63_7890123456789$123456789$123456789012345678901234567890123 OUTPUT, @@p63_7890123456789$123456789$123456789012345678901234567890123;'; +SET @@x63_7890123456789$123456789$123456789012345678901234567890123 = N'@@z63_7890123456789$123456789$123456789012345678901234567890123 INT OUTPUT, @@p63_7890123456789$123456789$123456789012345678901234567890123 INT'; +declare @#y63_7890123456789$123456789$123456789012345678901234567890123 INT; +declare @@z63_7890123456789$123456789$123456789012345678901234567890123 INT; +EXEC sp_executesql @@v63_7890123456789$123456789$123456789012345678901234567890123, @@x63_7890123456789$123456789$123456789012345678901234567890123, @@z63_7890123456789$123456789$123456789012345678901234567890123 = @#y63_7890123456789$123456789$123456789012345678901234567890123 OUT, @@p63_7890123456789$123456789$123456789012345678901234567890123 = 10; +EXEC sp_executesql @#w63_7890123456789$123456789$123456789012345678901234567890123, @@x63_7890123456789$123456789$123456789012345678901234567890123, @@z63_7890123456789$123456789$123456789012345678901234567890123 = @@z63_7890123456789$123456789$123456789012345678901234567890123 OUT, @@p63_7890123456789$123456789$123456789012345678901234567890123 = 11; +SELECT @#y63_7890123456789$123456789$123456789012345678901234567890123, @@z63_7890123456789$123456789$123456789012345678901234567890123; +go + +create procedure p2_spexec_atatuservar +as +declare @@v63_7890123456789$123456789$123456789012345678901234567890123 NVARCHAR(1000); +declare @#w63_7890123456789$123456789$123456789012345678901234567890123 NVARCHAR(max); +declare @@x63_7890123456789$123456789$123456789012345678901234567890123 NVARCHAR(1000); +SET @@v63_7890123456789$123456789$123456789012345678901234567890123 = N'SET @@z63_7890123456789$123456789$123456789012345678901234567890123 = @@p63_7890123456789$123456789$123456789012345678901234567890123 + @@p63_7890123456789$123456789$123456789012345678901234567890123'; +SET @#w63_7890123456789$123456789$123456789012345678901234567890123 = N'EXEC sp_executesql N''SET @@z63_7890123456789$123456789$123456789012345678901234567890123 = @@p63_7890123456789$123456789$123456789012345678901234567890123 + @@p63_7890123456789$123456789$123456789012345678901234567890123'', N''@@z63_7890123456789$123456789$123456789012345678901234567890123 INT OUT, @@p63_7890123456789$123456789$123456789012345678901234567890123 INT'', @@z63_7890123456789$123456789$123456789012345678901234567890123 OUTPUT, @@p63_7890123456789$123456789$123456789012345678901234567890123;'; +SET @@x63_7890123456789$123456789$123456789012345678901234567890123 = N'@@z63_7890123456789$123456789$123456789012345678901234567890123 INT OUTPUT, @@p63_7890123456789$123456789$123456789012345678901234567890123 INT'; +declare @#y63_7890123456789$123456789$123456789012345678901234567890123 INT; +declare @@z63_7890123456789$123456789$123456789012345678901234567890123 INT; +EXEC sp_executesql @@v63_7890123456789$123456789$123456789012345678901234567890123, @@x63_7890123456789$123456789$123456789012345678901234567890123, @@z63_7890123456789$123456789$123456789012345678901234567890123 = @#y63_7890123456789$123456789$123456789012345678901234567890123 OUT, @@p63_7890123456789$123456789$123456789012345678901234567890123 = 10; +EXEC sp_executesql @#w63_7890123456789$123456789$123456789012345678901234567890123, @@x63_7890123456789$123456789$123456789012345678901234567890123, @@z63_7890123456789$123456789$123456789012345678901234567890123 = @@z63_7890123456789$123456789$123456789012345678901234567890123 OUT, @@p63_7890123456789$123456789$123456789012345678901234567890123 = 11; +SELECT @#y63_7890123456789$123456789$123456789012345678901234567890123, @@z63_7890123456789$123456789$123456789012345678901234567890123; +go +exec p2_spexec_atatuservar +go + + +create trigger tr17_atatuservar on t17_trigger_atatuservar for insert +as +begin +select 'trigger tr17_atatuservar' + +declare @@v63_7890123456789$123456789$123456789012345678901234567890123 NVARCHAR(1000); +declare @#w63_7890123456789$123456789$123456789012345678901234567890123 NVARCHAR(max); +declare @@x63_7890123456789$123456789$123456789012345678901234567890123 NVARCHAR(1000); +SET @@v63_7890123456789$123456789$123456789012345678901234567890123 = N'SET @@z63_7890123456789$123456789$123456789012345678901234567890123 = @@p63_7890123456789$123456789$123456789012345678901234567890123 + @@p63_7890123456789$123456789$123456789012345678901234567890123'; +SET @#w63_7890123456789$123456789$123456789012345678901234567890123 = N'EXEC sp_executesql N''SET @@z63_7890123456789$123456789$123456789012345678901234567890123 = @@p63_7890123456789$123456789$123456789012345678901234567890123 + @@p63_7890123456789$123456789$123456789012345678901234567890123'', N''@@z63_7890123456789$123456789$123456789012345678901234567890123 INT OUT, @@p63_7890123456789$123456789$123456789012345678901234567890123 INT'', @@z63_7890123456789$123456789$123456789012345678901234567890123 OUTPUT, @@p63_7890123456789$123456789$123456789012345678901234567890123;'; +SET @@x63_7890123456789$123456789$123456789012345678901234567890123 = N'@@z63_7890123456789$123456789$123456789012345678901234567890123 INT OUTPUT, @@p63_7890123456789$123456789$123456789012345678901234567890123 INT'; +declare @#y63_7890123456789$123456789$123456789012345678901234567890123 INT; +declare @@z63_7890123456789$123456789$123456789012345678901234567890123 INT; +EXEC sp_executesql @@v63_7890123456789$123456789$123456789012345678901234567890123, @@x63_7890123456789$123456789$123456789012345678901234567890123, @@z63_7890123456789$123456789$123456789012345678901234567890123 = @#y63_7890123456789$123456789$123456789012345678901234567890123 OUT, @@p63_7890123456789$123456789$123456789012345678901234567890123 = 10; +EXEC sp_executesql @#w63_7890123456789$123456789$123456789012345678901234567890123, @@x63_7890123456789$123456789$123456789012345678901234567890123, @@z63_7890123456789$123456789$123456789012345678901234567890123 = @@z63_7890123456789$123456789$123456789012345678901234567890123 OUT, @@p63_7890123456789$123456789$123456789012345678901234567890123 = 11; +SELECT @#y63_7890123456789$123456789$123456789012345678901234567890123, @@z63_7890123456789$123456789$123456789012345678901234567890123; +end +go +insert t17_trigger_atatuservar values (123) +go + +-- table variables in different types of functions +create function f1_ins_atatuservar(@@p1 int) +returns int +as +begin + declare @@tv table(a int) + insert @@tv values(@@p1) + return (select sum(a) from @@tv) +end +go +select dbo. f1_ins_atatuservar(123) +go + +create function f1_upd_atatuservar(@@p1 int) +returns int +as +begin + declare @@tv table(a int) + insert @@tv values(@@p1) + update @@tv set a = a + 1 + return (select sum(a) from @@tv) +end +go +select dbo. f1_upd_atatuservar(123) +go + +create function f1_del_atatuservar(@@p1 int) +returns int +as +begin + declare @@tv table(a int) + insert @@tv values(@@p1) + update @@tv set a = a + 1 + insert @@tv values(@@p1) + update @@tv set a = a + 1 + delete @@tv where a = 124 + return (select sum(a) from @@tv) +end +go +select dbo. f1_del_atatuservar(123) +go + +-- INSERT/UPDATE/DELETE on table variable in function +create function f3_atatuservar_upd(@@p1 int) +returns @@tv table(a int) +as +begin + insert @@tv values(@@p1) + update t set a = t.a + 1 from @@tv as t + return +end +go +select * from dbo. f3_atatuservar_upd(123) order by 1 +go + +create function f3_atatuservar_del(@@p1 int) +returns @@tv table(a int) +as +begin + insert @@tv values(@@p1) + update @@tv set a = a + 1 + insert @@tv values(@@p1) + delete t from @@tv as t where a = 124 + return +end +go +select * from dbo. f3_atatuservar_del(123) order by 1 +go + +create function f3_upd_atatuservar(@@p1 int) +returns @@tv table(a int) +as +begin + insert @@tv values(@@p1) + update t set a = t.a + 1 from t2_atatuservar, @@tv as t where t2_atatuservar.a = t.a + return +end +go +select * from dbo. f3_upd_atatuservar(123) order by 1 +go + +create function f3_del_atatuservar(@@p1 int) +returns @@tv table(a int) +as +begin + insert @@tv values(@@p1) + update @@tv set a = a + 1 + insert @@tv values(@@p1) + delete t from t2_atatuservar join @@tv as t on t2_atatuservar.a = t.a + return +end +go +select * from dbo. f3_del_atatuservar(123) order by 1 +go + +create function f4_ins_atatuservar(@#p1 int) +returns int +as +begin + declare @#tv table(a int) + insert @#tv values(@#p1) + return (select sum(a) from @#tv) +end +go +select dbo. f4_ins_atatuservar(123) +go + +create function f4_upd_atatuservar(@#p1 int) +returns int +as +begin + declare @#tv table(a int) + insert @#tv values(@#p1) + update @#tv set a = a + 1 + return (select sum(a) from @#tv) +end +go +select dbo. f4_upd_atatuservar(123) +go + +create function f4_del_atatuservar(@#p1 int) +returns int +as +begin + declare @#tv table(a int) + insert @#tv values(@#p1) + update @#tv set a = a + 1 + insert @#tv values(@#p1) + update @#tv set a = a + 1 + delete @#tv where a = 124 + return (select sum(a) from @#tv) +end +go +select dbo. f4_del_atatuservar(123) +go + +create function f5_upd_atatuservar(@#p1 int) +returns @#tv table(a int) +as +begin + insert @#tv values(@#p1) + update t set a = t.a + 1 from @#tv as t + return +end +go +select * from dbo. f5_upd_atatuservar(123) order by 1 +go + +create function f5_del_atatuservar(@#p1 int) +returns @#tv table(a int) +as +begin + insert @#tv values(@#p1) + update @#tv set a = a + 1 + insert @#tv values(@#p1) + delete t from @#tv as t where a = 124 + return +end +go +select * from dbo. f5_del_atatuservar(123) order by 1 +go + +create function f6_upd_atatuservar(@#p1 int) +returns @#tv table(a int) +as +begin + insert @#tv values(@#p1) + update t set a = t.a + 1 from t2_atatuservar, @#tv as t where t2_atatuservar.a = t.a + return +end +go +select * from dbo. f6_upd_atatuservar(123) order by 1 +go + +create function f6_del_atatuservar(@#p1 int) +returns @#tv table(a int) +as +begin + insert @#tv values(@#p1) + update @#tv set a = a + 1 + insert @#tv values(@#p1) + delete t from t2_atatuservar, @#tv as t where t2_atatuservar.a = t.a + return +end +go +select * from dbo. f6_del_atatuservar(123) order by 1 +go + +create function f7_tabvar_udf_upd_atatuservar(@@p1 int) +returns @#tv table(a int) +as +begin + insert @#tv values(@@p1) + update t set a = t.a + 1 from t2_atatuservar, @#tv as t where t2_atatuservar.a = t.a + return +end +go +select * from dbo. f7_tabvar_udf_upd_atatuservar(123) order by 1 +go + +create function f7a_tabvar_udf_upd_atatuservar(@@p1 int) +returns @#tv table(a int) +as +begin + insert @#tv values(@@p1) + update t set a = t.a + 1 from @#tv as tv, t2_atatuservar as t where tv.a = t.a + return +end +go + +create function f8_tabvar_udf_del_atatuservar(@@p1 int) +returns @#tv table(a int) +as +begin + insert @#tv values(@@p1) + update @#tv set a = a + 1 + insert @#tv values(@@p1) + delete t from @#tv as tv, t2_atatuservar as t where tv.a = t.a + return +end +go + +create function f9_tabvar_udf_del_atatuservar(@p1 int) +returns @tv table(a int) +as +begin + insert @tv values(@p1) + update @tv set a = a + 1 + insert @tv values(@p1) + delete t from @tv as t inner join t2_atatuservar as tv on tv.a = t.a + return +end +go +select * from dbo.f9_tabvar_udf_del_atatuservar(123) +go + +create function f10_tabvar_udf_del_atatuservar(@#p1 int) +returns @@tv table(a int) +as +begin + insert @@tv values(@#p1) + update @@tv set a = a + 1 + insert @@tv values(@#p1) + delete t from t2_atatuservar as tv join @@tv as t on tv.a = t.a + return +end +go +select * from dbo.f10_tabvar_udf_del_atatuservar(123) +go + +create function f4_atatuservar_tabvar_in_function_upd(@#p1 int) +returns @@tv table(a int) +as +begin + insert @@tv values(@#p1) + update t set a = t.a + 1 from t2_atatuservar as t2_atatuservar left join t2_atatuservar as tv on tv.a = t2_atatuservar.a right join @@tv t on tv.a = t.a + return +end +go +select * from dbo.f4_atatuservar_tabvar_in_function_upd(123) +go + +create function f12_tabvar_udf_upd_atatuservar(@#p1 int) +returns @@tv table(a int) +as +begin + insert @@tv values(@#p1) + update t set a = t.a + 1 from @@tv as tv cross join t2_atatuservar as t + return +end +go + +create function f13_tabvar_udf_del_atatuservar(@#p1 int) +returns @@tv table(a int) +as +begin + insert @@tv values(@#p1) + update @@tv set a = a + 1 + insert @@tv values(@#p1) + delete t from @@tv as t2_atatuservar right join t2_atatuservar as tv on tv.a = t2_atatuservar.a full outer join t2_atatuservar t on tv.a = t.a + return +end +go + +create function f14_del_atatuservar(@@p128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int) +returns int +as +begin + declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 table(a int) + insert @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 values(@@p128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678) + update @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 set a = a + 1 + insert @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 values(@@p128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678) + update @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 set a = a + 1 + delete @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 where a = 124 + return (select sum(a) from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678) +end +go +select dbo. f14_del_atatuservar(123) +go + +-- INSERT/UPDATE/DELETE on table variable in function +create function f15_upd_atatuservar(@@p128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int) +returns @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 table(a int) +as +begin + insert @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 values(@@p128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678) + update t set a = t.a + 1 from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 as t + return +end +go +select * from dbo. f15_upd_atatuservar(123) order by 1 +go + +create function f16_tabvar_udf_del_atatuservar(@#q128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int) +returns @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 table(a int) +as +begin + insert @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 values(@#q128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678) + update @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 set a = a + 1 + insert @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 values(@#q128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678) + delete t from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 as t2_atatuservar right join t2_atatuservar as tv on tv.a = t2_atatuservar.a full outer join t2_atatuservar t on tv.a = t.a + return +end +go + +-- THROW +declare @@v int = 50001; +THROW @@v, 'Test message', 1; +go + +declare @@v int = 50001, @@v2 varchar(30) = 'Test message'; +THROW @@v, @@v2, 1 +go + +declare @@v int = 50001, @@v2 varchar(30) = 'Test message', @@v3 int=1; +THROW @@v, @@v2, @@v3 +go + +declare @#v int = 50001; +THROW @#v, 'Test message', 1; +go + +declare @#v int = 50001, @#v2 varchar(30) = 'Test message'; +THROW @#v, @#v2, 1 +go + +declare @#v int = 50001, @#v2 varchar(30) = 'Test message', @#v3 int=1; +THROW @#v, @#v2, @#v3 +go + +create procedure p20_atatuservar @@p int +as +if @@p > 0 +begin +declare @@v int = 50001, @@v2 varchar(30) = 'Test message 1', @@v3 int=1; +THROW @@v, @@v2, @@v3 +end + +declare @#v int = 50001, @#v2 varchar(30) = 'Test message 2', @#v3 int=1; +THROW @#v, @#v2, @#v3 +go +exec p20_atatuservar 1 +go +exec p20_atatuservar 0 +go + +create trigger tr18_atatuservar on t18_trigger_atatuservar for insert +as +begin +select 'trigger tr18_atatuservar' + +declare @#v int = 50001, @#v2 varchar(30) = 'Test message 2', @#v3 int=1; +THROW @#v, @#v2, @#v3 +end +go +insert t18_trigger_atatuservar values (123) +go + +declare @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int = 50001, @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$123456789012345678901234567890123456782 varchar(30) = 'Test message', @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$123456789012345678901234567890123456783 int=1; +THROW @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678, @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$123456789012345678901234567890123456782, @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$123456789012345678901234567890123456783 +go + +create procedure p21_atatuservar +as +declare @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int = 50001, @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$123456789012345678901234567890123456782 varchar(30) = 'Test message', @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$123456789012345678901234567890123456783 int=1; +THROW @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678, @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$123456789012345678901234567890123456782, @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$123456789012345678901234567890123456783 +go +exec p21_atatuservar +go + +create trigger tr19_atatuservar on t19_trigger_atatuservar for insert +as +begin +select 'trigger tr19_atatuservar' + +declare @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int = 50001, @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$123456789012345678901234567890123456782 varchar(30) = 'Test message', @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$123456789012345678901234567890123456783 int=1; +THROW @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678, @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$123456789012345678901234567890123456782, @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$123456789012345678901234567890123456783 +end +go +insert t19_trigger_atatuservar values (123) +go + +-- DBCC CHECKIDENT +declare @@TableName varchar(100)='mytab' +DBCC CHECKIDENT (@@TableName) +go +declare @@v int=2 +DBCC CHECKIDENT ('mytab', RESEED, @@v) +go + +create procedure p1_checkident_atatuservar @@TableName varchar(100), @@v int +as +DBCC CHECKIDENT (@@TableName, RESEED, @@v) +go + +create trigger tr20_atatuservar on t20_trigger_atatuservar for insert +as +begin +select 'trigger tr20_atatuservar' +declare @@TableName varchar(100)='mytab', @@v int=2 +DBCC CHECKIDENT (@@TableName, RESEED, @@v) +end +go + +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int=2 +DBCC CHECKIDENT ('mytab', RESEED, @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678) +go + +create procedure p2_checkident_atatuservar @@t128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(100), @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int +as +DBCC CHECKIDENT (@@t128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678, RESEED, @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678) +go + +create trigger tr21_atatuservar on t21_trigger_atatuservar for insert +as +begin +select 'trigger tr21_atatuservar' +declare @@t128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(100)='mytab', @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 int=2 +DBCC CHECKIDENT (@@t128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678, RESEED, @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678) +end +go + +-- transaction name +declare @@V varchar(50) = 'myxact' +begin transaction @@v +insert t3_atatuservar values(234) +declare @#V varchar(50) = 'mysavept' +save transaction @#v +insert t3_atatuservar values(345) +set @#V = 'mysavept' +rollback transaction @#v +insert t3_atatuservar values(567) +commit transaction @@v +go +select * from t3_atatuservar +go + +create procedure p1_xactname_atatuservar +as +declare @@V varchar(50) = 'myxact' +delete t3_atatuservar where a > 123 +begin transaction @@v +insert t3_atatuservar values(234) +declare @#V varchar(50) = 'mysavept' +save transaction @#v +insert t3_atatuservar values(345) +set @#V = 'mysavept' +rollback transaction @#v +insert t3_atatuservar values(567) +commit transaction @@v +select * from t3_atatuservar +go +exec p1_xactname_atatuservar +go + +delete t3_atatuservar where a > 123 +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(50) = 'myxact' +begin transaction @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +insert t3_atatuservar values(234) +declare @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(50) = 'mysavept' +save transaction @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +insert t3_atatuservar values(345) +set @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 = 'mysavept' +rollback transaction @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +insert t3_atatuservar values(567) +commit transaction @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +go +select * from t3_atatuservar +go + +create procedure p2_xactname_atatuservar +as +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(50) = 'myxact' +delete t3_atatuservar where a > 123 +begin transaction @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +insert t3_atatuservar values(234) +declare @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(50) = 'mysavept' +save transaction @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +insert t3_atatuservar values(345) +set @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 = 'mysavept' +rollback transaction @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +insert t3_atatuservar values(567) +commit transaction @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +select * from t3_atatuservar +go +exec p2_xactname_atatuservar +go + +-- cursor variable in T-SQL batch, stored procedure, trigger +declare @#v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(20) +declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 cursor +set @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 = cursor for select a from t_checkident_atatuservar order by n +open @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +while 1=1 +begin + fetch from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 into @#v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 + if @@fetch_status <> 0 break + select @#v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +end +close @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +deallocate @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +go + +create procedure p1_cursor_atatuservar +as +begin + declare @#v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(20) + declare @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 cursor + set @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 = cursor for select a from t_checkident_atatuservar order by n + open @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 + while 1=1 + begin + fetch from @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 into @#v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 + if @@fetch_status <> 0 break + select @#v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 + end + close @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 + deallocate @@v128_890123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +end +go +exec p1_cursor_atatuservar +go + +create trigger tr22_atatuservar on t22_trigger_atatuservar for insert +as +begin + select 'trigger tr22_atatuservar' + + declare @@v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 varchar(20) + declare @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 cursor + set @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 = cursor for select a from t_checkident_atatuservar order by n + open @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 + while 1=1 + begin + fetch from @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 into @@v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 + if @@fetch_status <> 0 break + select @@v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 + end + close @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 + deallocate @#v128_90123456789$123456789$1234567890123456789$123456789$1234567890123456789$123456789$12345678901234567890123456789012345678 +end +go +insert t22_trigger_atatuservar values (123) +go +set quoted_identifier on +go + +-- user-defined variables that were previously mapped to internal sys. functions, e.g. sys.rand() +declare @@xact_state int=123 select @@xact_state, xact_state() +go +declare @@error_line int=123 select @@error_line, error_line() +go +declare @@error_message int=123 select @@error_message, error_message() +go +declare @@error_number int=123 select @@error_number, error_number() +go +declare @@error_procedure int=123 select @@error_procedure, error_procedure() +go +declare @@error_severity int=123 select @@error_severity, error_severity() +go +declare @@error_state int=123 select @@error_state, error_state() +go +declare @@db_id int=123 select @@db_id, db_id('master') +go +declare @@db_name int=123 select @@db_name, db_name() +go +declare @@exp int=123 select @@exp, exp(1) +go +declare @@sign int=123 select @@sign, sign(1) +go +declare @@lock_timeout int=123 select @@lock_timeout, lock_timeout() +go +declare @@rand int=123 select @@rand, case when rand() <= 0 then 'too small, <= 0' when rand() >= 1 then ' too large, >= 1' else 'correct, >0 && <1' end +go +declare @@trigger_nestlevel int=123 select @@trigger_nestlevel, trigger_nestlevel() +go +declare @@atn2 int=123 select @@atn2, atn2(1,0) +go +declare @@datepart int=123 select @@datepart, datepart(yy, '2024-11-12') +go +declare @@datediff int=123 select @@datediff, datediff(dd, '2024-11-12', '2024-12-13') +go +declare @@datediff_big int=123 select @@datediff_big, datediff(dd, '2024-11-12', '2024-12-13') +go +declare @@dateadd int=123 select @@dateadd, datediff(dd, 3, '2024-11-12') +go +declare @@datename int=123 select @@datename, datename(dw, '2024-11-12') +go + +create proc p1_sysfunctions_atatuservar +as +begin +declare @@xact_state int=123 select @@xact_state, xact_state() +declare @@error_line int=123 select @@error_line, error_line() +declare @@error_message int=123 select @@error_message, error_message() +declare @@error_number int=123 select @@error_number, error_number() +declare @@error_procedure int=123 select @@error_procedure, error_procedure() +declare @@error_state int=123 select @@error_state, error_state() +declare @@db_id int=123 select @@db_id, db_id('master') +declare @@db_name int=123 select @@db_name, db_name() +declare @@exp int=123 select @@exp, exp(1) +declare @@sign int=123 select @@sign, sign(1) +declare @@lock_timeout int=123 select @@lock_timeout, lock_timeout() +declare @@rand int=123 select @@rand, case when rand() <= 0 then 'too small, <= 0' when rand() >= 1 then ' too large, >= 1' else 'correct, >0 && <1' end +declare @@trigger_nestlevel int=123 select @@trigger_nestlevel, trigger_nestlevel() +declare @@atn2 int=123 select @@atn2, atn2(1,0) +declare @@datepart int=123 select @@datepart, datepart(yy, '2024-11-12') +declare @@datediff int=123 select @@datediff, datediff(dd, '2024-11-12', '2024-12-13') +declare @@datediff_big int=123 select @@datediff_big, datediff(dd, '2024-11-12', '2024-12-13') +declare @@dateadd int=123 select @@dateadd, datediff(dd, 3, '2024-11-12') +declare @@datename int=123 select @@datename, datename(dw, '2024-11-12') +end +go +exec p1_sysfunctions_atatuservar +go + +create function f1_sysfunctions_atatuservar() returns int +as +begin +declare @@xact_state int=123 +declare @@error_line int=123 +declare @@error_message int=123 +declare @@error_number int=123 +declare @@error_procedure int=123 +declare @@error_state int=123 +declare @@db_id int=123 +declare @@db_name int=123 +declare @@exp int=123 +declare @@sign int=123 +declare @@lock_timeout int=123 +declare @@rand int=123 +declare @@trigger_nestlevel int=123 +declare @@atn2 int=123 +declare @@datepart int=123 +declare @@datediff int=123 +declare @@datediff_big int=123 +declare @@dateadd int=123 +declare @@datename int=123 +return @@xact_state + @@error_line + @@error_message + @@error_number + @@error_procedure + @@error_state + @@db_id + @@db_name + @@exp + @@sign + @@lock_timeout + @@rand + @@trigger_nestlevel + @@atn2 + @@datepart + @@datediff + @@datediff_big + @@dateadd + @@datename +end +go +select dbo.f1_sysfunctions_atatuservar() +go + +create trigger tr1_sysfunctions_atatuservar on t23_trigger_atatuservar for insert as +begin +declare @@xact_state int=123 select @@xact_state, xact_state() +declare @@error_line int=123 select @@error_line, error_line() +declare @@error_message int=123 select @@error_message, error_message() +declare @@error_number int=123 select @@error_number, error_number() +declare @@error_procedure int=123 select @@error_procedure, error_procedure() +declare @@error_state int=123 select @@error_state, error_state() +declare @@db_id int=123 select @@db_id, db_id('master') +declare @@db_name int=123 select @@db_name, db_name() +declare @@exp int=123 select @@exp, exp(1) +declare @@sign int=123 select @@sign, sign(1) +declare @@lock_timeout int=123 select @@lock_timeout, lock_timeout() +declare @@rand int=123 select @@rand, case when rand() <= 0 then 'too small, <= 0' when rand() >= 1 then ' too large, >= 1' else 'correct, >0 && <1' end +declare @@trigger_nestlevel int=123 select @@trigger_nestlevel, trigger_nestlevel() +declare @@atn2 int=123 select @@atn2, atn2(1,0) +declare @@datepart int=123 select @@datepart, datepart(yy, '2024-11-12') +declare @@datediff int=123 select @@datediff, datediff(dd, '2024-11-12', '2024-12-13') +declare @@datediff_big int=123 select @@datediff_big, datediff(dd, '2024-11-12', '2024-12-13') +declare @@dateadd int=123 select @@dateadd, datediff(dd, 3, '2024-11-12') +declare @@datename int=123 select @@datename, datename(dw, '2024-11-12') +end +go +insert t23_trigger_atatuservar values(1) +go diff --git a/test/JDBC/input/empty_dq_string_in_object-vu-cleanup.sql b/test/JDBC/input/empty_dq_string_in_object-vu-cleanup.sql new file mode 100644 index 0000000000..c7531672ed --- /dev/null +++ b/test/JDBC/input/empty_dq_string_in_object-vu-cleanup.sql @@ -0,0 +1,58 @@ +drop table t1_empty_dq_string +go +drop table t2_empty_dq_string +go +drop table t3_empty_dq_string +go +drop table t4_empty_dq_string +go +drop table t5_empty_dq_string +go +drop table t6_empty_dq_string +go +drop table t7_empty_dq_string +go +drop procedure p1_empty_dq_string +go +drop function f1_empty_dq_string +go +drop procedure p2_empty_dq_string +go +drop function f2_empty_dq_string +go +drop procedure p2a_empty_dq_string +go +drop function f2a_empty_dq_string +go +drop procedure p2b_empty_dq_string +go +drop procedure p3_empty_dq_string +go +drop procedure p4_empty_dq_string +go +drop function f4_empty_dq_string +go +drop procedure p5_empty_dq_string +go +drop function f5_empty_dq_string +go +drop procedure p6_empty_dq_string +go +drop procedure p7_empty_dq_string +go +drop procedure p7a_empty_dq_string +go +drop procedure p7b_empty_dq_string +go +drop function f7b_empty_dq_string +go +drop procedure p7c_empty_dq_string +go +set quoted_identifier on +go +drop table "t8_empty_dq_string" +go +drop procedure "p8_empty_dq_string" +go +drop function "f8_empty_dq_string" +go \ No newline at end of file diff --git a/test/JDBC/input/empty_dq_string_in_object-vu-prepare.sql b/test/JDBC/input/empty_dq_string_in_object-vu-prepare.sql new file mode 100644 index 0000000000..84150a437a --- /dev/null +++ b/test/JDBC/input/empty_dq_string_in_object-vu-prepare.sql @@ -0,0 +1,23 @@ +create table t1_empty_dq_string(a int) +go +create table t2_empty_dq_string(a int) +go +create table t3_empty_dq_string(a int) +go +create table t4_empty_dq_string(a int) +go +create table t5_empty_dq_string(a int, b varchar(10)) +insert t5_empty_dq_string values(1, 'test 1') +go +create table t6_empty_dq_string(a int, b varchar(10)) +insert t6_empty_dq_string values(1, 'test 1') +go +create table t7_empty_dq_string(a int, b varchar(10)) +insert t7_empty_dq_string values(1, 'test 1') +go + +set quoted_identifier on +go +create table "t8_empty_dq_string"("a" int, "b" varchar(10)) +insert "t8_empty_dq_string" values(1, 'test 1') +go diff --git a/test/JDBC/input/empty_dq_string_in_object-vu-verify.sql b/test/JDBC/input/empty_dq_string_in_object-vu-verify.sql new file mode 100644 index 0000000000..08eca2a87d --- /dev/null +++ b/test/JDBC/input/empty_dq_string_in_object-vu-verify.sql @@ -0,0 +1,291 @@ +-- Purpose: a double-quoted empty string inside a SQL object body should be treated as an empty string + +set quoted_identifier off +go + +-- SELECT "" +select "" as empty_str +go +create procedure p1_empty_dq_string +as +select "" as empty_str +go +exec p1_empty_dq_string +go +create function f1_empty_dq_string() returns varchar(10) +as +begin +return "" +end +go +select dbo.f1_empty_dq_string(), len(dbo.f1_empty_dq_string()) +go +create trigger tr1_empty_dq_string on t1_empty_dq_string for insert as +begin +select "" as empty_str +end +go +insert t1_empty_dq_string values(1) +go + +-- variable declaration and assignment +declare @v varchar(10) = "" +set @v = "" +select @v +go +create procedure p2_empty_dq_string +as +declare @v varchar(10) = "" +set @v = "" +select @v +go +exec p2_empty_dq_string +go +create function f2_empty_dq_string() returns varchar(10) +as +begin +declare @v varchar(10) = "" +set @v = "" +return '['+@v+']' +end +go +select dbo.f2_empty_dq_string(), len(dbo.f2_empty_dq_string()) +go +create trigger tr2_empty_dq_string on t2_empty_dq_string for insert as +begin +declare @v varchar(10) = "" +set @v = "" +select @v +end +go +insert t2_empty_dq_string values(1) +go + +-- execute immediate +execute("") +go + +-- argument for procedure/function call +create procedure p2a_empty_dq_string @p varchar(10) +as +select '['+@p+']' as p, len(@p) as len +go +exec p2a_empty_dq_string "" +go +exec p2a_empty_dq_string @p="" +go +create function f2a_empty_dq_string(@p varchar(10)) returns varchar(10) +as +begin +return '['+@p+']' +end +go +select dbo.f2a_empty_dq_string(""), len(dbo.f2a_empty_dq_string("")) +go + +create procedure p2b_empty_dq_string @p varchar(10) +as +exec p2a_empty_dq_string "" +exec p2a_empty_dq_string @p="" +select dbo.f2a_empty_dq_string(""), len(dbo.f2a_empty_dq_string("")) +go +exec p2b_empty_dq_string "" +go + +-- print "" (not visible in JDBC test output) +print "" +go +create procedure p3_empty_dq_string +as +print "" +go +exec p3_empty_dq_string +go +create trigger tr3_empty_dq_string on t3_empty_dq_string for insert as +begin +select 'trigger' +print "" +end +go +insert t3_empty_dq_string values(1) +go + +-- usage in condition +if 'a' = "" select 'branch 1' else select 'branch 2' +go +create procedure p4_empty_dq_string as +if 'a' = "" select 'branch 1' else select 'branch 2' +go +exec p4_empty_dq_string +go +create function f4_empty_dq_string() returns int +as +begin +if 'a' = "" return 1 +return 2 +end +go +select dbo.f4_empty_dq_string() +go +create trigger tr4_empty_dq_string on t4_empty_dq_string for insert as +begin +if 'a' = "" select 'branch 1' else select 'branch 2' +end +go +insert t4_empty_dq_string values(1) +go + +-- usage in WHERE_clause +select * from t5_empty_dq_string where b = "" order by a +go +create procedure p5_empty_dq_string as +select a, '['+b+']' as b from t5_empty_dq_string where b = "" order by a +go +exec p5_empty_dq_string +go +create function f5_empty_dq_string() returns int +as +begin +declare @v int +select @v = count(*) from t5_empty_dq_string where b = "" +return '['+@v+']' +end +go +select dbo.f5_empty_dq_string() +go +create trigger tr5_empty_dq_string on t5_empty_dq_string for insert as +begin +select a, '['+b+']' as b from t5_empty_dq_string where b = "" order by a +end +go +insert t5_empty_dq_string values(1, 'test 1') +go + +-- usage in insert +insert t6_empty_dq_string values (2, "") +go +create procedure p6_empty_dq_string as +insert t6_empty_dq_string values (3, "") +go +exec p6_empty_dq_string +go +select a, '['+b+']' as b from t6_empty_dq_string order by a +go +create trigger tr6_empty_dq_string on t6_empty_dq_string for insert as +begin +insert t6_empty_dq_string values (4, "") +end +go +insert t6_empty_dq_string values(1, 'test 1') +go +select a, '['+b+']' as b from t6_empty_dq_string order by a +go + +-- usage in update +update t7_empty_dq_string set b = "" where a = 1 +go +create procedure p7_empty_dq_string as +update t7_empty_dq_string set b = "" where a = 1 +go +exec p7_empty_dq_string +go +select a, '['+b+']' as b from t7_empty_dq_string order by a +go +create trigger tr7_empty_dq_string on t7_empty_dq_string for insert as +begin +update t7_empty_dq_string set b = "" where a = 1 +end +go +insert t7_empty_dq_string values(2, 'test 2') +go +select a, '['+b+']' as b from t7_empty_dq_string order by a +go + +-- single-space string in update: not affected +create procedure p7a_empty_dq_string as +update t7_empty_dq_string set b = " " where a = 1 +go +exec p7a_empty_dq_string +go +select a, '['+b+']' as b from t7_empty_dq_string order by a +go +create trigger tr7a_empty_dq_string on t7_empty_dq_string for insert as +begin +update t7_empty_dq_string set b = " " where a = 1 +end +go +insert t7_empty_dq_string values(3, 'test 3') +go +select a, '['+b+']' as b from t7_empty_dq_string order by a +go + + +-- single-space string: argument for procedure/function call +create procedure p7b_empty_dq_string @p varchar(10) +as +select '['+@p+']' as p, len(@p) as len +go +exec p7b_empty_dq_string " " +go +exec p7b_empty_dq_string @p=" " +go +create function f7b_empty_dq_string(@p varchar(10)) returns varchar(10) +as +begin +return '['+@p+']' +end +go +select dbo.f7b_empty_dq_string(" "), len(dbo.f7b_empty_dq_string(" ")) +go + +create procedure p7c_empty_dq_string @p varchar(10) +as +exec p7b_empty_dq_string " " +exec p7b_empty_dq_string @p=" " +select dbo.f7b_empty_dq_string(" "), len(dbo.f7b_empty_dq_string(" ")) +go +exec p7c_empty_dq_string " " +go + +-- double-quoted identifier: not affected +set quoted_identifier on +go + +-- SELECT "" +select * from "t8_empty_dq_string" order by "a" +go +create procedure "p8_empty_dq_string" +as +select * from "t8_empty_dq_string" order by "a" +go +exec "p8_empty_dq_string" +go +create function "f8_empty_dq_string"() returns varchar(10) +as +begin +return '' +end +go +select dbo."f8_empty_dq_string"(), len(dbo."f8_empty_dq_string"()) +go +create trigger "tr8_empty_dq_string" on "t8_empty_dq_string" for insert as +begin +select * from "t8_empty_dq_string" order by "a" +end +go +insert "t8_empty_dq_string" values(2, 'test 2') +go +select * from "t8_empty_dq_string" order by "a" +go + +-- double-quoted identifier of length 0: invalid in T-SQL, should raise error +create table "" (a int) +go +select * from "" +go +-- execute immediate +execute("") +go + +set quoted_identifier off +go \ No newline at end of file diff --git a/test/JDBC/input/exec_sp_in_udf-vu-cleanup.sql b/test/JDBC/input/exec_sp_in_udf-vu-cleanup.sql new file mode 100644 index 0000000000..941ed5f9a1 --- /dev/null +++ b/test/JDBC/input/exec_sp_in_udf-vu-cleanup.sql @@ -0,0 +1,42 @@ +use master +go +drop table t1_exec_sp_in_udf +go +drop table t2_exec_sp_in_udf +go +drop procedure sp_myproc +go +drop procedure p1_exec_sp_in_udf +go +drop function f1_exec_sp_in_udf +go +drop function f2_exec_sp_in_udf +go +drop function f3_exec_sp_in_udf +go +drop function f4_exec_sp_in_udf +go +drop function f5_exec_sp_in_udf +go +drop function f6_exec_sp_in_udf +go +drop function f6a_exec_sp_in_udf +go +drop function f7_exec_sp_in_udf +go +drop function f8_exec_sp_in_udf +go +drop function f9_exec_sp_in_udf +go +drop function f_scalar_exec_sp_in_udf +go +drop function f_tvf_exec_sp_in_udf +go +drop function f_itvf_exec_sp_in_udf +go +use tempdb +go +drop procedure p_tempdb_exec_sp_in_udf +go +use master +go diff --git a/test/JDBC/input/exec_sp_in_udf-vu-prepare.sql b/test/JDBC/input/exec_sp_in_udf-vu-prepare.sql new file mode 100644 index 0000000000..7fefa6a81e --- /dev/null +++ b/test/JDBC/input/exec_sp_in_udf-vu-prepare.sql @@ -0,0 +1,32 @@ +use master +go +create table t1_exec_sp_in_udf (a int) +go +create procedure sp_myproc as return 0 +go +create function f_scalar_exec_sp_in_udf(@p int) +returns int as +begin +return @p +end +go + +create function f_tvf_exec_sp_in_udf() +returns @tv table (a int) +begin + insert @tv values(123) + return +end +go + +create function f_itvf_exec_sp_in_udf() +returns table + return (select 123 as a) +go + +use tempdb +go +create procedure p_tempdb_exec_sp_in_udf as return 0 +go +use master +go diff --git a/test/JDBC/input/exec_sp_in_udf-vu-verify.sql b/test/JDBC/input/exec_sp_in_udf-vu-verify.sql new file mode 100644 index 0000000000..a5c7b85b6f --- /dev/null +++ b/test/JDBC/input/exec_sp_in_udf-vu-verify.sql @@ -0,0 +1,162 @@ +use master +go + +create function f1_exec_sp_in_udf() +returns int as +begin +exec sp_executesql 'select 123' +return 0 +end +go +select dbo.f1_exec_sp_in_udf() +go +declare @v int = dbo.f1_exec_sp_in_udf() +go +declare @v int +select @v = dbo.f1_exec_sp_in_udf() +go +declare @v int +set @v = dbo.f1_exec_sp_in_udf() +go +select * from t1_exec_sp_in_udf where a = dbo.f1_exec_sp_in_udf() +go +insert t1_exec_sp_in_udf values(dbo.f1_exec_sp_in_udf()) +go +delete t1_exec_sp_in_udf where a = dbo.f1_exec_sp_in_udf() +go +declare @v int +set @v = (select dbo.f1_exec_sp_in_udf()) +go +select sqrt(dbo.f1_exec_sp_in_udf()) +go +create table t2_exec_sp_in_udf(a int, b int default dbo.f1_exec_sp_in_udf()) +go +insert t2_exec_sp_in_udf(a) values(1) +go + +create function f2_exec_sp_in_udf() +returns int as +begin +exec dbo.sp_helpdb +return 0 +end +go +select dbo.f2_exec_sp_in_udf() +go + +create function f3_exec_sp_in_udf() +returns int as +begin +exec [sp_helpdb] +return 0 +end +go +select dbo.f3_exec_sp_in_udf() +go + +create function f4_exec_sp_in_udf() +returns @tv table(a int) as +begin +exec sp_myproc +return +end +go +select * from dbo.f4_exec_sp_in_udf() +go + +create function f5_exec_sp_in_udf() +returns @tv table(a int) as +begin +exec dbo.[sp_myproc] +return +end +go +select * from dbo.f5_exec_sp_in_udf() +go + +create function f6_exec_sp_in_udf() +returns @tv table(a int) as +begin +exec tempdb..p_tempdb_exec_sp_in_udf +return +end +go +select * from dbo.f6_exec_sp_in_udf() +go + +-- do not allow calling with EXEC +create function f6a_exec_sp_in_udf(@p int) +returns int as +begin +declare @v int +exec @v = f1_exec_sp_in_udf +return @v +end +go +select dbo.f6a_exec_sp_in_udf(123) +go + +-- multi-statement TVF cannot be called with EXEC +exec dbo.f_tvf_exec_sp_in_udf +go +create function f7_exec_sp_in_udf() +returns int +begin +exec dbo.f_tvf_exec_sp_in_udf +return +end +go +select * from dbo.f7_exec_sp_in_udf() +go + +-- inline TVF should not be callable with EXEC, but Babelfish currently allows this +-- when this gets fixed so that an error is raised, the result of this test will change +exec dbo.f_itvf_exec_sp_in_udf +go +create function f8_exec_sp_in_udf() +returns int +begin +exec dbo.f_itvf_exec_sp_in_udf +return +end +go +select * from dbo.f8_exec_sp_in_udf() +go + + +-- procedure and trigger are not affected: +create trigger tr1 on t1_exec_sp_in_udf for insert as +begin + exec sp_executesql 'select 123 as in_trigger' +end +go +insert t1_exec_sp_in_udf values(456) +go +select * from t1_exec_sp_in_udf +go + +create procedure p1_exec_sp_in_udf +as +begin + exec sp_executesql 'select 123 as in_procedure' +end +go +exec p1_exec_sp_in_udf +go + +-- scalar UDF can still be called with EXEC +declare @v int +exec @v = f_scalar_exec_sp_in_udf 123 +select @v as f_scalar_exec_sp_in_udf +go + +create function f9_exec_sp_in_udf(@p int) +returns int as +begin +declare @v int +exec @v = f_scalar_exec_sp_in_udf @p +return @v +end +go +select dbo.f9_exec_sp_in_udf(123) +go diff --git a/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-cleanup.mix b/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-cleanup.mix index 8cd04100a6..867c5cdcf8 100644 --- a/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-cleanup.mix +++ b/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-cleanup.mix @@ -39,6 +39,12 @@ GO DROP TABLE babel_cross_db_vu_prepare_s1.babel_cross_db_vu_prepare_t1; GO +DROP TABLE babel_cross_db_vu_prepare_t4; +GO + +DROP LOGIN babel_cross_db_vu_prepare_l3; +GO + DROP FUNCTION babel_cross_db_vu_prepare_s1.babel_cross_db_vu_prepare_f1; GO diff --git a/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-prepare.mix b/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-prepare.mix index 296e33909e..425e73d24f 100644 --- a/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-prepare.mix +++ b/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-prepare.mix @@ -259,3 +259,19 @@ GO GRANT EXECUTE ON FUNCTION master_dbo.babel_cross_db_vu_prepare_pg_func to master_babel_cross_db_vu_prepare_u1; GO + +-- tsql +USE master; +GO + +CREATE LOGIN babel_cross_db_vu_prepare_l3 WITH PASSWORD = '12345678'; +GO + +CREATE USER babel_cross_db_vu_prepare_u3 FOR LOGIN babel_cross_db_vu_prepare_l3; +GO + +CREATE TABLE babel_cross_db_vu_prepare_t4 (a INT); +GO + +GRANT SELECT ON babel_cross_db_vu_prepare_t4 TO guest; +GO diff --git a/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-verify.mix b/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-verify.mix index 104676e420..19daa84a3b 100644 --- a/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-verify.mix +++ b/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-verify.mix @@ -254,6 +254,9 @@ GO ALTER LOGIN babel_cross_db_vu_prepare_l2 with password = '12345678'; GO +ALTER LOGIN babel_cross_db_vu_prepare_l3 with password = '12345678'; +GO + -- tsql user=babel_cross_db_vu_prepare_l1 password=12345678 USE master; GO @@ -347,9 +350,44 @@ GO SELECT * FROM master.dbo.babel_cross_db_vu_prepare_v1 ORDER BY id; GO +create user user_cannot_connect for login babel_cross_db_vu_prepare_l2; +go + +revoke connect from user_cannot_connect; +go + GRANT CONNECT TO guest; GO +grant select on babel_cross_db_vu_prepare_db1_t1 to guest; +go + +-- tsql user=babel_cross_db_vu_prepare_l2 password=12345678 +USE my_babel_cross_db_vu_prepare_db1 +GO + +select current_user +go + +select has_dbaccess('my_babel_cross_db_vu_prepare_db1'); +go + +select * from dbo.babel_cross_db_vu_prepare_db1_t1; -- should not use guest privilege +go + +USE master +GO + +-- tsql +USE my_babel_cross_db_vu_prepare_db1 +GO + +revoke select on babel_cross_db_vu_prepare_db1_t1 from guest; +go + +drop user user_cannot_connect; +go + -- cross-db tests for guest user -- tsql user=babel_cross_db_vu_prepare_l2 password=12345678 USE master @@ -374,6 +412,25 @@ GO SELECT * FROM dbo.babel_cross_db_vu_prepare_v1 ORDER BY id; GO +-- tsql user=babel_cross_db_vu_prepare_l3 password=12345678 +USE master +GO + +-- login babel_cross_db_vu_prepare_l3 has mapped user in master +-- database so following SELECT should fail. +SELECT * FROM babel_cross_db_vu_prepare_t4; +GO + +-- now moreve mapped user from login babel_cross_db_vu_prepare_l3 in master database +-- tsql +DROP USER babel_cross_db_vu_prepare_u3; +GO + +-- now that login babel_cross_db_vu_prepare_l3 does not have a mapped user in master +-- database so following SELECT should succeed as guest was granted SELECT privilege. +SELECT * FROM babel_cross_db_vu_prepare_t4; +GO + -- tsql USE master GO diff --git a/test/JDBC/input/ownership/BABEL-USER-vu-cleanup.sql b/test/JDBC/input/ownership/BABEL-USER-vu-cleanup.sql index 0c17026b74..8a3c125629 100644 --- a/test/JDBC/input/ownership/BABEL-USER-vu-cleanup.sql +++ b/test/JDBC/input/ownership/BABEL-USER-vu-cleanup.sql @@ -22,5 +22,8 @@ GO DROP LOGIN babel_user_vu_prepare_test5 GO +DROP LOGIN babel_user_vu_prepare_test6 +GO + DROP LOGIN babel_user_vu_prepare_long_login_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA GO diff --git a/test/JDBC/input/ownership/BABEL-USER-vu-prepare.sql b/test/JDBC/input/ownership/BABEL-USER-vu-prepare.sql index 0bd1b6d37d..e95650c174 100644 --- a/test/JDBC/input/ownership/BABEL-USER-vu-prepare.sql +++ b/test/JDBC/input/ownership/BABEL-USER-vu-prepare.sql @@ -13,6 +13,9 @@ GO CREATE LOGIN babel_user_vu_prepare_test5 WITH PASSWORD = 'abc'; GO +CREATE LOGIN babel_user_vu_prepare_test6 WITH PASSWORD = 'abc'; +GO + CREATE LOGIN babel_user_vu_prepare_long_login_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA WITH PASSWORD = 'abc'; GO diff --git a/test/JDBC/input/ownership/BABEL-USER-vu-verify.mix b/test/JDBC/input/ownership/BABEL-USER-vu-verify.mix index c285861236..5503c2306b 100644 --- a/test/JDBC/input/ownership/BABEL-USER-vu-verify.mix +++ b/test/JDBC/input/ownership/BABEL-USER-vu-verify.mix @@ -102,6 +102,9 @@ GO ALTER LOGIN babel_user_vu_prepare_test5 WITH PASSWORD = 'abc'; GO +ALTER LOGIN babel_user_vu_prepare_test6 WITH PASSWORD = 'abc'; +GO + -- tsql user=babel_user_vu_prepare_test5 password=abc SELECT CURRENT_USER; go @@ -111,6 +114,30 @@ go SELECT pg_has_role('babel_user_vu_prepare_test5', 'master_babel_user_vu_prepare_test3', 'member') GO +-- Now map user babel_user_vu_prepare_test3 to a different login babel_user_vu_prepare_test6 +-- tsql +ALTER USER babel_user_vu_prepare_test3 WITH LOGIN = babel_user_vu_prepare_test6; +GO + +-- Login babel_user_vu_prepare_test5 should no longer be a member of user babel_user_vu_prepare_test3 +-- psql +SELECT pg_has_role('babel_user_vu_prepare_test5', 'master_babel_user_vu_prepare_test3', 'member') +GO + +-- Login babel_user_vu_prepare_test6 should be a member of user babel_user_vu_prepare_test3 +SELECT pg_has_role('babel_user_vu_prepare_test6', 'master_babel_user_vu_prepare_test3', 'member') +GO + +-- Again map user babel_user_vu_prepare_test3 to login babel_user_vu_prepare_test5 +-- tsql +ALTER USER babel_user_vu_prepare_test3 WITH LOGIN = babel_user_vu_prepare_test5; +GO + +-- Login babel_user_vu_prepare_test6 should now be mapped to guest user +-- tsql user=babel_user_vu_prepare_test6 password=abc +SELECT CURRENT_USER; +go + -- tsql -- both of the commands below should fail ALTER USER babel_user_vu_prepare_test3 WITH LOGIN = babel_user_vu_prepare_test1; diff --git a/test/JDBC/input/storedProcedures/Test-sp_reset_connection.mix b/test/JDBC/input/storedProcedures/Test-sp_reset_connection.mix index 9282b5adaf..57cc553bc7 100644 --- a/test/JDBC/input/storedProcedures/Test-sp_reset_connection.mix +++ b/test/JDBC/input/storedProcedures/Test-sp_reset_connection.mix @@ -1,3 +1,4 @@ +-- parallel_query_expected -- tsql -- 1. Test resets GUC variables SELECT @@lock_timeout; @@ -244,4 +245,76 @@ SELECT @@cursor_rows; GO drop table babel_cursor_t1; +GO + +-- GUCs testing + +-- 1. Ansi defaults +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_nulls', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_warnings', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_null_dflt_on', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_padding', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.implicit_transactions', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.quoted_identifier', true); +GO + +SET ANSI_DEFAULTS ON +GO + +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_nulls', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_warnings', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_null_dflt_on', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_padding', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.implicit_transactions', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.quoted_identifier', true); +GO + +-- reset +exec sys.sp_reset_connection +GO + +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_nulls', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_warnings', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_null_dflt_on', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_padding', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.implicit_transactions', true); +SELECT CURRENT_SETTING('babelfishpg_tsql.quoted_identifier', true); +GO + +-- babelfish_showplan_all +SET babelfish_showplan_all ON +GO + +-- explain output +SELECT 1; +GO + +-- reset +exec sys.sp_reset_connection +GO + +-- 1 output +SELECT 1; +GO + +-- set_config testing. + +-- search_path has source < PGC_S_SESSION in TSQL but it gets reset during ResetAll Gucs. +-- Whereas role does not get reset since it uses GUC_NO_RESET_ALL, so we should not allow +-- set_config for this option. +SELECT CURRENT_SETTING('search_path', true) +SELECT CURRENT_SETTING('role', true) +GO + +SELECT set_config('search_path', 'sys', false); +GO +SELECT set_config('role', 'jdbc_user', false); +GO + +-- reset +exec sp_reset_connection +GO + +SELECT CURRENT_SETTING('search_path', true) +SELECT CURRENT_SETTING('role', true) GO \ No newline at end of file diff --git a/test/JDBC/input/test_dynamic_local_vars.sql b/test/JDBC/input/test_dynamic_local_vars.sql new file mode 100644 index 0000000000..3253d2d84c --- /dev/null +++ b/test/JDBC/input/test_dynamic_local_vars.sql @@ -0,0 +1,1278 @@ +-- parallel_query_expected +-- simple vars +declare @i int +declare @j int +set @i = 10 +set @j = @i + 10 +select @i, @j +GO + +declare @i int +declare @j int +select @i = 10, @j = @i + 10 +select @i, @j +GO + +declare @i int +declare @j int = 0; +select @i = 10, @j = @i + @j * 2 +select @i, @j +GO + +declare @i int +declare @j int +select @i = 10, @j = @i + 10 +select @j += 10 +select @i, @j +GO + +-- should throw an error +declare @i int +select @i = 0, @i += 2 +select @i +GO + +declare @i int +select @i = 10, @i += 10 +select @i +GO + +-- sub-expr +declare @i int +set @i = 10 +select @i += (5 - 1) +select @i +GO + +DECLARE @a int +select @a = (select ~cast('1' as int)) +select @a +go + +DECLARE @Counter INT = 1; +DECLARE @MaxValue INT = 10; + +WHILE @Counter <= @MaxValue +BEGIN + DECLARE @IsEven BIT; + + IF @Counter % 2 = 0 + SET @IsEven = 1; + ELSE + SET @IsEven = 0; + + IF @IsEven = 1 + SELECT CAST(@Counter AS VARCHAR(2)) + ' is even'; + ELSE + SELECT CAST(@Counter AS VARCHAR(2)) + ' is odd'; + + SET @Counter = @Counter + 1; +END; +GO + +declare @a numeric (10, 4); +declare @b numeric (10, 4); +SET @a=100.41; +SET @b=200.82; +SELECT @a, @b +select @a+@b as r; +GO + +declare @a numeric; +declare @b numeric (10, 4); +SET @a=100.41; +SET @b=200.82; +SELECT @a, @b +select @a+@b as r; +GO + +declare @a varbinary +set @a = cast('test_bin' as varbinary) +select @a +GO + +declare @a varbinary(max) +set @a = cast('test_bin' as varbinary) +select @a +GO + +declare @a varbinary(10) +set @a = cast('test_bin' as varbinary) +select @a +GO + +declare @a varbinary +declare @b varbinary +select @a = cast('test_bin' as varbinary), @b = @a +select @a, @b +GO + +declare @a varbinary(max) +select @a = cast('test_bin' as varbinary) +select @a +GO + +DECLARE @a varchar +set @a = '12345678901234567890123456789012345'; +SELECT LEN(@a), DATALENGTH(@a) +SELECT @a +GO + +DECLARE @v varchar(20); +SELECT @v = NULL; +SELECT ISNUMERIC(@v), LEN(@v), DATALENGTH(@v) +GO + +DECLARE @a varchar(max) +SELECT @a = '12345678901234567890123456789012345'; +SELECT LEN(@a), DATALENGTH(@a) +SELECT @a +GO + +-- collate can not be used with local variables +DECLARE @v varchar(20) collate BBF_Unicode_CP1_CI_As = 'ci_as'; +GO + +declare @source int; +declare @target sql_variant; +select @source = 1.0 +select @target = cast(@source as varchar(10)); +SELECT sql_variant_property(@target, 'basetype'); +select @target +GO + +declare @source int; +declare @target varchar(10); +select @source = 1.0 +select cast(@source as varchar(10)) +select @target = cast(@source as varchar(10)); +select @target +GO + +DECLARE @a pg_catalog.varchar +SELECT @a = '12345678901234567890123456789012345'; +SELECT LEN(@a), DATALENGTH(@a) +SELECT @a +GO + +DECLARE @a pg_catalog.varchar(100) +SELECT @a = '12345678901234567890123456789012345'; +SELECT LEN(@a), DATALENGTH(@a) +SELECT @a +GO + +DECLARE @a pg_catalog.varchar(10) +SELECT @a = '12345678901234567890123456789012345'; +SELECT LEN(@a), DATALENGTH(@a) +SELECT @a +GO + +DECLARE @a varchar +SELECT @a = '12345678901234567890123456789012345'; +SELECT LEN(@a), DATALENGTH(@a) +SELECT @a +GO + +DECLARE @a varchar(100) +SELECT @a = '12345678901234567890123456789012345'; +SELECT LEN(@a), DATALENGTH(@a) +SELECT @a +GO + +DECLARE @a varchar(10) +SELECT @a = '12345678901234567890123456789012345'; +SELECT LEN(@a), DATALENGTH(@a) +SELECT @a +GO + +DECLARE @a int +set @a = 0 +select @a ^= 1 +select @a +go + +DECLARE @a int +set @a = 0 +select @a += ~@a +select @a +go + +SET QUOTED_IDENTIFIER OFF +GO + +-- quoted identifiers +declare @v varchar(20) = "ABC", @v2 varchar(20)="XYZ"; +select @v += "a""b''c'd", @v2 += "x""y''z"; +select @v, @v2 +GO + +declare @v varchar(20) = "ABC", @v2 varchar(20)="XYZ"; +select @v += "a""b''c'd", @v2 += @v + "x""y''z"; +select @v, @v2 +GO + +declare @v varchar(20) = "ABC", @v2 varchar(20)="XYZ"; +select @v += reverse("a""b''c'd"), @v2 += @v + "x""y''z"; +select @v, @v2 +GO + +declare @v varchar(20) = "ABC", @v2 varchar(20)="XYZ"; +select @v += reverse("a""b''c'd"), @v2 += @v + reverse("x""y''z"); +select @v, @v2 +GO + +declare @v varchar(20) = "ABC", @v2 varchar(20)="XYZ"; +select @v += reverse("a""b''c'd"), @v2 += REVERSE( @v + reverse("x""y''z")); +select @v, @v2 +GO + +SET QUOTED_IDENTIFIER ON +GO + +declare @v varchar(20) = 'ABC', @v2 varchar(20)='XYZ'; +select @v += 'abc', @v2 += 'xyz'; +select @v, @v2 +GO + +declare @a int = 1, @b int = 2; +select @a = 2, @b = @a + 2 +select @a, @b +GO + +declare @a int = 1, @b int = 2; +select @a += 2, @b -= @a + 2 +select @a, @b +GO + +-- xml methods +DECLARE @a bit = 1 +DECLARE @xml XML = ' ' +SELECT @a |= @xml.exist('/artists/artist/@name') +select @a +GO + +DECLARE @a bit = 1 +DECLARE @xml XML; +SELECT @xml = ' ', @a |= @xml.exist('/artists/artist/@name') +select @a +GO + +-- test all kind of udts +create type udt from NCHAR +go + +declare @a udt +select @a = 'anc' +select @a +GO + +DROP type udt +GO + +create type varchar_max from varchar(max) +GO + +DECLARE @a varchar_max +SELECT @a = '12345678901234567890123456789012345'; +SELECT LEN(@a), DATALENGTH(@a) +SELECT @a +GO + +DROP type varchar_max +GO + +create type num_def from numeric +GO + +declare @a numeric; +declare @b num_def; +SET @a=100.41; +SET @b=200.82; +SELECT @a, @b +select @a+@b as r; +GO + +drop type num_def +GO + +/* + * select/update test + */ +create table local_var_tst (id int) +GO + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +insert into local_var_tst values (6) +GO + +-- txn does not affect local variables +begin tran +declare @i int +update local_var_tst set id = 5, @i = id * 5 +select @i +ROLLBACK tran +select @i +GO + +select * from local_var_tst; +GO + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO + +-- should return 4 +declare @i int +select @i = 1 +select @i = id * 2 from local_var_tst where id = @i +select @i +GO + +declare @i int +select @i = 1 +select @i = @i + id * 2 from local_var_tst +select @i +GO + +declare @i int +select @i = 1 +select @i = id * 2 + @i from local_var_tst +select @i +GO + +declare @i int +select @i = 1 +select @i += id * 2 from local_var_tst +select @i +GO + +-- 3 parts name +declare @i int +select @i = 1 +select @i += master.dbo.local_var_tst.id * 2 from local_var_tst +select @i +GO + +-- local var name same as column +declare @id int = 1 +select @id += master.dbo.local_var_tst.id * 2 from local_var_tst +select @id +GO + +-- should throw an error +declare @i int +declare @j int +set @i = 10 +set @j = 0; +select @i += (select @j = @j + id from local_var_tst) +select @i +GO + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO + +DECLARE @ans INT +SELECT @ans = AVG(id) FROM local_var_tst +select @ans +GO + +-- local variable inside functions +CREATE FUNCTION var_inside_func() +RETURNS INT AS +BEGIN + DECLARE @ans INT + SELECT @ans = AVG(id) FROM local_var_tst + RETURN @ans +END +GO + +select var_inside_func(); +GO + +DROP FUNCTION var_inside_func(); +GO + +-- show throw an error +CREATE FUNCTION var_inside_func() +RETURNS @tab table (a int) as +BEGIN + DECLARE @ans INT + SELECT @ans += id from local_var_tst + select @ans +END +GO + +drop function if exists var_inside_func +go + +CREATE FUNCTION var_inside_func() +RETURNS INT AS +BEGIN + DECLARE @ans INT + SELECT @ans += id FROM local_var_tst + RETURN @ans +END +GO + +select var_inside_func() +go + +drop function if exists var_inside_func +go + +CREATE FUNCTION var_inside_func(@def int) +RETURNS INT AS +BEGIN + DECLARE @ans INT; + select @ans = @def; + SELECT @ans += id FROM local_var_tst + RETURN @ans +END +GO + +select var_inside_func(0) +go + +declare @def int = 1; +select var_inside_func(@def) +go + +drop function if exists var_inside_func +go + +CREATE FUNCTION var_inside_func() +RETURNS INT AS +BEGIN + DECLARE @ans INT + select @ans = 0 + SELECT @ans += id + @ans FROM local_var_tst + RETURN @ans +END +GO + +select var_inside_func() +go + +drop function if exists var_inside_func +go + +-- variable with procedure +CREATE PROCEDURE var_with_procedure (@a numeric(10,4) OUTPUT) AS +BEGIN + SET @a=100.41; + select @a as a; +END; +GO + +exec var_with_procedure 2.000; +GO + +-- value of @out should remain 2.000 +declare @out numeric(10,4); +set @out = 2.000; +exec var_with_procedure 2.000; +select @out +GO + +drop procedure var_with_procedure; +GO + +CREATE PROCEDURE var_with_procedure_1 (@a numeric(10,4) OUTPUT, @b numeric(10,4) OUTPUT) AS +BEGIN + SET @a=100.41; + SET @b=200.82; + select @a+@b as r; +END; +GO + +EXEC var_with_procedure_1 2.000, 3.000; +GO + +-- value of @a should be 100 +DECLARE @a INT; +EXEC var_with_procedure_1 @a OUT, 3.000; +SELECT @a; +GO + +drop procedure var_with_procedure_1; +GO + +CREATE PROCEDURE var_with_procedure_2 +AS +BEGIN + declare @a int + declare @b int + set @a = 1 + return + select @b=@a+1 +END +GO + +exec var_with_procedure_2 +GO + +DROP PROCEDURE var_with_procedure_2 +GO + +-- insert testing with local variables +truncate table dbo.local_var_tst +go + +-- should throw an error +declare @a int = 1 +insert into local_var_tst select @a = @a + 1 +GO + +-- syntax error +declare @a int = 1 +insert into local_var_tst values (@a = @a + 1) +GO + +declare @a int = 1 +insert into local_var_tst values (@a + 1) +GO + +-- output clause with insert +declare @a int = 1 +declare @mytbl table(a int) +insert local_var_tst output inserted.id into @mytbl values (@a + 1) +select * from @mytbl +GO + +-- output clause with delete +declare @a int = 1 +declare @mytbl table(a int) +delete local_var_tst output deleted.id into @mytbl where id = @a + 1 +select * from @mytbl +GO + +drop table dbo.local_var_tst +go + +create table local_var_tst_1 (a int, b int) +GO + +insert into local_var_tst_1 values (1,3), (2, 4) +go + +-- select test with multi-variable assignment + +declare @a int = 0 +declare @b int = 0 +select @a += a, @b += b from local_var_tst_1 +select @a, @b +go + +declare @a int = 0 +declare @b int = 0 +select @a += a, @b += @a + b from local_var_tst_1 +select @a, @b +go + +declare @a int = 0 +declare @b int = 0 +select @a += a, @b += @a + ~b from local_var_tst_1 +select @a, @b +go + +drop table local_var_tst_1 +go + +create table local_var_str_tst (id varchar(100)) +GO + +insert into local_var_str_tst values ('abc'), (' '), ('def') +GO + +declare @i varchar(1000) +set @i = '' +select @i = @i + id from local_var_str_tst +select @i +go + +declare @i varchar(1000) +set @i = '' +select @i = id + @i from local_var_str_tst +select @i +go + +declare @i varchar(1000) +set @i = '' +select @i += id from local_var_str_tst +select @i +go + +declare @i varchar(1000) +set @i = '' +select @i = reverse(@i + 'id') from local_var_str_tst +select @i +go + +declare @i varchar(1000) +set @i = '' +select @i += reverse(id) from local_var_str_tst +select @i +go + +declare @i varchar(1000) +set @i = 'abc' +select @i = reverse(@i) +select @i +go + +-- function call like trim, ltrim, etc will be rewritten by ANTLR +declare @i varchar(1000) +set @i = ' ' +select @i += id from local_var_str_tst +select len(@i), @i +select @i = trim(@i) +select len(@i), @i +go + +drop table local_var_str_tst; +go + +-- $PARTITION is rewritten by ANTLR +CREATE PARTITION FUNCTION RangePF1 ( INT ) +AS RANGE RIGHT FOR VALUES (10, 100, 1000) ; +GO + +declare @res int = -1; +SELECT @res = $PARTITION.RangePF1 (10); +select @res +select 1 where @res = $PARTITION.RangePF1 (10); +SELECT @res = $PARTITION.RangePF1 (@res); +select @res +GO + +DROP PARTITION FUNCTION RangePF1 +GO + +CREATE SEQUENCE CountBy1 + START WITH 1 + INCREMENT BY 1 ; +GO + +-- NEXT VALUE FOR gets re-written by ANTLR +DECLARE @myvar1 BIGINT = NEXT VALUE FOR CountBy1 ; +DECLARE @myvar2 BIGINT ; +DECLARE @myvar3 BIGINT ; +select @myvar2 = NEXT VALUE FOR CountBy1 ; +SELECT @myvar3 = NEXT VALUE FOR CountBy1 ; +SELECT @myvar1 AS myvar1, @myvar2 AS myvar2, @myvar3 AS myvar3 ; +GO + +DROP SEQUENCE CountBy1 +GO + +-- any @@ is also re-written by ANTLR +declare @pid int = 0 +select @pid += @@spid +select 1 where @pid = @@spid +go + +-- float point notation also gets rewritten by ANTLR e.g., 2.1E, -.2e+, -2.e- +declare @a float = 0 +select @a = 2.1E +select @a +select @a = -.2e+ +select @a +select @a = -2.e- +select @a +go + +-- variables only in select target list shows dynamic behavior +create table local_var_tst (id int) +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +insert into local_var_tst values (1) +GO + +declare @i int = 1 +declare @j int = 0 +select @j += id, @i = id + 1 from local_var_tst where id = @i +select @i, @j +go + +declare @i int = 1 +select @i = id * 2 from local_var_tst where id = @i +select @i +GO + +select set_config('babelfishpg_tsql.explain_timing', 'off', false); +GO + +select set_config('babelfishpg_tsql.explain_summary', 'off', false); +GO + +set babelfish_statistics profile On; +GO + +declare @i int = 1 +declare @j int = 0 +select @j += id, @i = id + 1 from local_var_tst where id = @i +select @i, @j +go + +declare @i int = 1 +select @i = @i * 2 from local_var_tst where id = @i +select @i +GO + +set babelfish_statistics profile OFF +GO + +select set_config('babelfishpg_tsql.explain_timing', 'on', false); +GO + +select set_config('babelfishpg_tsql.explain_summary', 'on', false); +GO + +-- declared variable name with length > 63 +declare @abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr int = 1 +select @abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr += 1 +select @abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr +GO + +-- variable names starting with @@ +declare @@a int = 1; +select @@a = @@a + 1 +select @@a +GO + +declare @@a int = 1; +select @@a += 1 +select @@a +GO + +declare @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr int = 1 +select @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr = @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr + 1 +select @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr +GO + +truncate table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +insert into local_var_tst values (1) +GO + +declare @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr int = 1 +select @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr = @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr + id from local_var_tst +select @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr +GO + +declare @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr int = 1 +select @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr = id + @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr from local_var_tst +select @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr +GO + +declare @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr int = 1 +select @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr += id from local_var_tst +select @@abcbjbnjfbjrnfjrnfkrelnfksnrfenjkfrfrfrfrfrfnknslkrnflkernklfnkmklfr +GO + +truncate table local_var_tst +GO + +insert into local_var_tst values (1) +GO + +select set_config('babelfishpg_tsql.explain_timing', 'off', false); +GO + +select set_config('babelfishpg_tsql.explain_summary', 'off', false); +GO + +set babelfish_statistics profile On; +GO + +-- error while evaluating const expression +declare @a int = 1; +select @a = 1 / 0 from local_var_tst +select * from local_var_tst where id = @a +GO + +set babelfish_statistics profile OFF +GO + +select set_config('babelfishpg_tsql.explain_timing', 'on', false); +GO + +select set_config('babelfishpg_tsql.explain_summary', 'on', false); +GO + +drop table local_var_tst +GO + +create table ident_tst(id_num INT IDENTITY(1, 1), b varchar(10)) +GO + +insert into ident_tst values ('test') +GO + +declare @a int = 1 +select @a = @@IDENTITY +select @a +select 1 where @a = @@IDENTITY +GO + +-- additional testing for update with dynamic variables +GO + +create table local_var_tst (id int) +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO + + +set QUOTED_IDENTIFIER on +GO + +declare @i varchar(100) +update local_var_tst set id = id + 10, @i = cast("xmax" as varchar(100)) +select 1 where @i IS NOT NULL +GO + +set QUOTED_IDENTIFIER off +GO + +select * from local_var_tst order by id; +GO + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO + +-- long identifier with update +declare @incnjkdncjknxdjnkxnknvjkdfjvbdfbvjbdfhjbvjdbfvkjbdnjnlkanjfnvjnjfdlsahdnuejncdiebnjcnjksndjnjxndjcx int +update local_var_tst set id =10, @incnjkdncjknxdjnkxnknvjkdfjvbdfbvjbdfhjbvjdbfvkjbdnjnlkanjfnvjnjfdlsahdnuejncdiebnjcnjksndjnjxndjcx = id +select @incnjkdncjknxdjnkxnknvjkdfjvbdfbvjbdfhjbvjdbfvkjbdnjnlkanjfnvjnjfdlsahdnuejncdiebnjcnjksndjnjxndjcx +GO + +select * from local_var_tst +GO + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO + +-- @@ variables +declare @@incnjkdnc int +update local_var_tst set id =10, @@incnjkdnc = id +select @@incnjkdnc +GO + +select * from local_var_tst +GO + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO + +declare @i int +update local_var_tst set id = id + 2, @i = id * 5; +select @i +GO + +select * from local_var_tst order by id; +GO + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO + +declare @i int, @j int; +update local_var_tst set id =10, @i = case when @j =0 then 1 else 0 end; +select @i, @j +go + +select * from local_var_tst; +GO + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO + +declare @i int, @j int; +update local_var_tst set id = 10, @j = id, @i = case when @j =0 then 1 else 0 end; +select @i, @j +go + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO + +declare @i int, @j int = 0 +update local_var_tst set id =10, @i = charindex('a','a',@j) +select @i +GO + +select * from local_var_tst; +GO + +declare @i int, @j int = 0 +update local_var_tst set id =10, @i = charindex('a','a',@j); +select @i +GO + +select * from local_var_tst; +GO + +declare @i int, @j int; +update local_var_tst set id = 10, @j = id, @i = @j * 2 +select @i, @j +go + +select * from local_var_tst; +GO + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO + +declare @i int = 1 +update local_var_tst set id = @i, @i = id * 2 where id = @i +select @i +GO + +select * from local_var_tst +go + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO + +declare @i int = 1 +update local_var_tst set id = @i, @i += id * 2 where id = @i +select @i +GO + +select * from local_var_tst +go + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO + +declare @i VARCHAR(200) = '' +update local_var_tst set id = id * 2, @i = @i + cast(id as varchar(20)) +select @i +GO + +select * from local_var_tst order by id +go + +-- @i should be NULL as no row passes the qual condition +declare @i int +update local_var_tst set id =10, @i = id * 5 where id = 1 +select @i +GO + +select * from local_var_tst order by id +go + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO + + +declare @i int = 1 +update local_var_tst set id = @i, @i = id * 5 where id = @i +select @i +GO + +select * from local_var_tst order by id +go + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO + +declare @i int +set @i = 0 +update local_var_tst set id = @i, @i = id * 5 +select @i +GO + +select * from local_var_tst; +GO + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO + +-- trim is re-written by antlr +declare @i varchar(200) +select @i = '' +update local_var_tst set id = @i, @i = TRIM(@i + cast(id as varchar(10))); +select @i +GO + +select * from local_var_tst; +GO + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO + +-- variables in the where clause should be treated as const + +declare @i int = 1; +update local_var_tst set id = @i * 100, @i = id * 2 where id = @i +select @i +GO + +select * from local_var_tst order by id; +GO + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO + +declare @i int = 1; +update local_var_tst set id = @i * 100, @i = @@IDENTITY +select @i +select 1 where @i = @@IDENTITY +GO + +select * from local_var_tst +GO + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO + +CREATE PARTITION FUNCTION RangePF1 ( INT ) +AS RANGE RIGHT FOR VALUES (10, 100, 1000) ; +GO + +declare @i int = -1; +SELECT @i = $PARTITION.RangePF1 (10); +select @i +update local_var_tst set id = @i, @i = $PARTITION.RangePF1 (10); +select @i +GO + +select * from local_var_tst; +GO + +DROP PARTITION FUNCTION RangePF1 +GO + +CREATE PROCEDURE var_with_procedure (@i int, @a numeric(10,4) OUTPUT) AS +BEGIN + update local_var_tst set id = @i * 2, @a = id * 5 where id = @i + select @a +END; +GO + +TRUNCATE table local_var_tst +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO + +declare @input int = 1, @res int; +exec var_with_procedure @input, @res +select @res +GO + +select * from local_var_tst +go + +declare @input int = 2, @a int; +exec var_with_procedure @input, @a +select @a +GO + +DROP PROCEDURE var_with_procedure; +GO + +DROP TABLE local_var_tst +GO + +create table local_var_tst_1 (id int) +GO + +insert into local_var_tst_1 values (1) +insert into local_var_tst_1 values (2) +GO + +create unique index idx_local_var_tst_1 on local_var_tst_1(id) +GO + + +SELECT set_config('enable_indexscan', '1', false); +SELECT set_config('enable_indexonlyscan', '0', false); +SELECT set_config('enable_seqscan', '0', false); +GO + +declare @i int = 1 +update local_var_tst_1 set id = @i, @i = id * 5 where id = 1 +select @i +GO + +declare @i int = 1 +update local_var_tst_1 set id = 10 output deleted.id where id = 1 +select @i +GO + +SELECT set_config('enable_indexscan', '1', false); +SELECT set_config('enable_indexonlyscan', '1', false); +SELECT set_config('enable_seqscan', '1', false); +GO + +DROP TABLE local_var_tst_1 +GO + +CREATE TABLE update_test_tbl ( + age int, + fname char(10), + lname char(10), + city nchar(20) +) +GO + +TRUNCATE TABLE update_test_tbl +GO + +INSERT INTO update_test_tbl(age, fname, lname, city) +VALUES (50, 'fname1', 'lname1', 'london'), + (34, 'fname2', 'lname2', 'paris'), + (35, 'fname3', 'lname3', 'brussels'), + (90, 'fname4', 'lname4', 'new york'), + (26, 'fname5', 'lname5', 'los angeles'), + (74, 'fname6', 'lname6', 'tokyo'), + (44, 'fname7', 'lname7', 'oslo'), + (19, 'fname8', 'lname8', 'hong kong'), + (61, 'fname9', 'lname9', 'shanghai'), + (29, 'fname10', 'lname10', 'mumbai') +GO + +CREATE TABLE update_test_tbl2 ( + year int, + lname char(10), +) +GO + +TRUNCATE TABLE update_test_tbl2 +GO + +INSERT INTO update_test_tbl2(year, lname) +VALUES (51, 'lname1'), + (34, 'lname3'), + (25, 'lname8'), + (95, 'lname9'), + (36, 'lname10') +GO + +UPDATE update_test_tbl SET fname = 'fname13' +FROM update_test_tbl t1 +INNER JOIN update_test_tbl2 t2 +ON t1.lname = t2.lname +WHERE year > 50 +GO + +declare @a varchar(4000) = ''; +UPDATE update_test_tbl SET fname = 'fname13', @a = @a + fname +FROM update_test_tbl t1 +INNER JOIN update_test_tbl2 t2 +ON t1.lname = t2.lname +WHERE year > 50 +select @a +GO + +DROP TABLE update_test_tbl2; +GO + +DROP TABLE update_test_tbl +GO + +drop table ident_tst +GO + +create table local_var_tst (id int) +GO + +insert into local_var_tst values (1) +insert into local_var_tst values (2) +GO + +declare @i int = 0, @j int +update local_var_tst set id = id + 2, @i = id, @j = @i * 2, @i = @j +select @i, @j +GO + +declare @i int = 0, @j int +update local_var_tst set id = id + 2, @i += id, @j = @i * 2 +select @i, @j +GO + +select * from local_var_tst order by id +GO + +drop table local_var_tst +GO diff --git a/test/JDBC/input/unary_plus_op_string-vu-prepare.sql b/test/JDBC/input/unary_plus_op_string-vu-prepare.sql index fa33ec42ae..c53ab72ebd 100644 --- a/test/JDBC/input/unary_plus_op_string-vu-prepare.sql +++ b/test/JDBC/input/unary_plus_op_string-vu-prepare.sql @@ -1,3 +1,5 @@ +set quoted_identifier off +go create table t1_unary_plus_op_string(i int, vc varchar(30)) go diff --git a/test/JDBC/input/unquoted_string-vu-prepare.mix b/test/JDBC/input/unquoted_string-vu-prepare.mix index 62d7b5a6f8..3fe27c23b7 100644 --- a/test/JDBC/input/unquoted_string-vu-prepare.mix +++ b/test/JDBC/input/unquoted_string-vu-prepare.mix @@ -109,11 +109,6 @@ create procedure unqStr_proc_5 @p1 varchar(20), @p2 varchar(20) = @p1 as select @p2 go --- should raise error: -create procedure unqStr_proc_6 @p1 varchar(20) = @@myvar -as select @p1 -go - create procedure unqStr_proc_7 @p1 varchar(20) = N'aB"c''D', @p2 varchar(20) = dEfg, @p3 varchar(20) = "x'Y""z" as select @p1, @p2, @p3 go diff --git a/test/JDBC/input/unquoted_string-vu-verify.mix b/test/JDBC/input/unquoted_string-vu-verify.mix index 1f436118c3..cf5b7a68af 100644 --- a/test/JDBC/input/unquoted_string-vu-verify.mix +++ b/test/JDBC/input/unquoted_string-vu-verify.mix @@ -311,7 +311,10 @@ go -- should raise an error about column not found: CALL unqStr_pgproc_1(aBc); go - +-- should raise an error since variable is not defined +create procedure unqStr_proc_6 @p1 varchar(20) = @@myvar +as select @p1 +go -- should print 'aBc': select unqStr_pgfunc_1('aBc'); go diff --git a/test/JDBC/jdbc_schedule b/test/JDBC/jdbc_schedule index 8749f00da6..279988dc0f 100644 --- a/test/JDBC/jdbc_schedule +++ b/test/JDBC/jdbc_schedule @@ -10,6 +10,17 @@ all +ignore#!#BABEL-1435 +ignore#!#BABEL-1446 +ignore#!#BABEL-4279 +ignore#!#TestSpatialPoint-vu-prepare +ignore#!#TestSpatialPoint-vu-verify +ignore#!#TestSpatialPoint-vu-cleanup +ignore#!#babelfish_migration_mode-vu-prepare +ignore#!#babelfish_migration_mode-vu-verify +ignore#!#babelfish_migration_mode-vu-cleanup +ignore#!#test_search_path + # BABEL-SP_FKEYS test is very slow and causing github action timeout. # JDBC bulk insert API seems to call SET FMTONLY ON without calling SET FMTONLY OFF, causing some spurious test failures. diff --git a/test/JDBC/upgrade/13_4/schedule b/test/JDBC/upgrade/13_4/schedule index a32d2c6365..f876456032 100644 --- a/test/JDBC/upgrade/13_4/schedule +++ b/test/JDBC/upgrade/13_4/schedule @@ -77,7 +77,6 @@ babel_datatype_sqlvariant BABEL-EXTENDEDPROPERTY-before-15_4 babelfish_authid_login_ext babelfish_cast_floor -babelfish_migration_mode babelfish_namespace_ext babelfish_sysdatabases babel_function_string-before-15-5-or-14-10 diff --git a/test/JDBC/upgrade/13_5/schedule b/test/JDBC/upgrade/13_5/schedule index ab89066ca5..38a5759930 100644 --- a/test/JDBC/upgrade/13_5/schedule +++ b/test/JDBC/upgrade/13_5/schedule @@ -83,7 +83,6 @@ babel_datatype_sqlvariant BABEL-EXTENDEDPROPERTY-before-15_4 babelfish_authid_login_ext babelfish_cast_floor -babelfish_migration_mode babelfish_namespace_ext babelfish_sysdatabases babel_function_string-before-15-5-or-14-10 diff --git a/test/JDBC/upgrade/13_6/schedule b/test/JDBC/upgrade/13_6/schedule index 2d24b9e5fb..699802a5f2 100644 --- a/test/JDBC/upgrade/13_6/schedule +++ b/test/JDBC/upgrade/13_6/schedule @@ -106,7 +106,6 @@ babelfish_authid_login_ext babelfish_authid_user_ext babelfish_cast_floor babelfish_inconsistent_metadata -babelfish_migration_mode babelfish_namespace_ext babelfish_sysdatabases babel_function_string-before-15-5-or-14-10 diff --git a/test/JDBC/upgrade/13_7/schedule b/test/JDBC/upgrade/13_7/schedule index 0500dfd72d..f25f359b33 100644 --- a/test/JDBC/upgrade/13_7/schedule +++ b/test/JDBC/upgrade/13_7/schedule @@ -104,7 +104,6 @@ babelfish_authid_login_ext babelfish_authid_user_ext babelfish_cast_floor babelfish_inconsistent_metadata -babelfish_migration_mode babelfish_namespace_ext babelfish_sysdatabases babel_function_string-before-15-5-or-14-10 diff --git a/test/JDBC/upgrade/13_8/schedule b/test/JDBC/upgrade/13_8/schedule index 8ced60486f..28d5356d2f 100644 --- a/test/JDBC/upgrade/13_8/schedule +++ b/test/JDBC/upgrade/13_8/schedule @@ -104,7 +104,6 @@ babelfish_authid_login_ext babelfish_authid_user_ext babelfish_cast_floor babelfish_inconsistent_metadata -babelfish_migration_mode babelfish_namespace_ext babelfish_sysdatabases babel_function_string-before-15-5-or-14-10 diff --git a/test/JDBC/upgrade/13_9/schedule b/test/JDBC/upgrade/13_9/schedule index 3d179581b1..18f85cd208 100644 --- a/test/JDBC/upgrade/13_9/schedule +++ b/test/JDBC/upgrade/13_9/schedule @@ -103,7 +103,6 @@ babelfish_authid_login_ext babelfish_authid_user_ext babelfish_cast_floor babelfish_inconsistent_metadata -babelfish_migration_mode babelfish_namespace_ext babelfish_sysdatabases babel_function_string-before-15-5-or-14-10 diff --git a/test/JDBC/upgrade/14_10/schedule b/test/JDBC/upgrade/14_10/schedule index 3a1236abb8..b9b298a117 100644 --- a/test/JDBC/upgrade/14_10/schedule +++ b/test/JDBC/upgrade/14_10/schedule @@ -178,7 +178,6 @@ babelfish_namespace_ext babelfish_authid_login_ext babelfish_authid_user_ext babelfish_inconsistent_metadata -babelfish_migration_mode schema_resolution_func BABEL-3147-before-16_3-or-15_7-or-14_12 collation_tests_arabic diff --git a/test/JDBC/upgrade/14_11/schedule b/test/JDBC/upgrade/14_11/schedule index 0d54676aa6..61626a1ae7 100644 --- a/test/JDBC/upgrade/14_11/schedule +++ b/test/JDBC/upgrade/14_11/schedule @@ -179,7 +179,6 @@ babelfish_namespace_ext babelfish_authid_login_ext babelfish_authid_user_ext babelfish_inconsistent_metadata -babelfish_migration_mode schema_resolution_func BABEL-3147-before-16_3-or-15_7-or-14_12 collation_tests_arabic diff --git a/test/JDBC/upgrade/14_12/schedule b/test/JDBC/upgrade/14_12/schedule index e3032c183d..cf7d06bb62 100644 --- a/test/JDBC/upgrade/14_12/schedule +++ b/test/JDBC/upgrade/14_12/schedule @@ -177,7 +177,6 @@ babelfish_namespace_ext babelfish_authid_login_ext babelfish_authid_user_ext babelfish_inconsistent_metadata -babelfish_migration_mode schema_resolution_func BABEL-3147 collation_tests_arabic diff --git a/test/JDBC/upgrade/14_13/schedule b/test/JDBC/upgrade/14_13/schedule index 8828c805a4..ce6b4b13a6 100644 --- a/test/JDBC/upgrade/14_13/schedule +++ b/test/JDBC/upgrade/14_13/schedule @@ -177,7 +177,6 @@ babelfish_namespace_ext babelfish_authid_login_ext babelfish_authid_user_ext babelfish_inconsistent_metadata -babelfish_migration_mode schema_resolution_func BABEL-3147 collation_tests_arabic diff --git a/test/JDBC/upgrade/14_15/schedule b/test/JDBC/upgrade/14_15/schedule index cfe77afa48..a90299cd63 100644 --- a/test/JDBC/upgrade/14_15/schedule +++ b/test/JDBC/upgrade/14_15/schedule @@ -177,7 +177,6 @@ babelfish_namespace_ext babelfish_authid_login_ext babelfish_authid_user_ext babelfish_inconsistent_metadata -babelfish_migration_mode schema_resolution_func BABEL-3147 collation_tests_arabic diff --git a/test/JDBC/upgrade/14_14/schedule b/test/JDBC/upgrade/14_16/schedule similarity index 98% rename from test/JDBC/upgrade/14_14/schedule rename to test/JDBC/upgrade/14_16/schedule index 8828c805a4..244315483a 100644 --- a/test/JDBC/upgrade/14_14/schedule +++ b/test/JDBC/upgrade/14_16/schedule @@ -60,7 +60,7 @@ column_domain_usage constraint_column_usage select-strip-parens-before-15_5 sp_describe_first_result_set -sys-host_name-before-15_8-or-16_4 +# sys-host_name-before-15_8-or-16_4 TODO:BABEL-5414 SYSTEM_USER indexproperty sys-all_parameters @@ -177,7 +177,6 @@ babelfish_namespace_ext babelfish_authid_login_ext babelfish_authid_user_ext babelfish_inconsistent_metadata -babelfish_migration_mode schema_resolution_func BABEL-3147 collation_tests_arabic @@ -240,7 +239,7 @@ sys-index_columns-dep sys-sp_databases-dep sys-syscolumns-dep sys-dm_exec_connections-dep -sys-dm_exec_sessions-dep +# sys-dm_exec_sessions-dep TODO:BABEL-5414 sys-table_types-before-dep sys-all_sql_modules-dep_before_16_5 sys-sql_modules-dep_before_16_5 diff --git a/test/JDBC/upgrade/14_3/schedule b/test/JDBC/upgrade/14_3/schedule index e5cc527e01..9be94180b4 100644 --- a/test/JDBC/upgrade/14_3/schedule +++ b/test/JDBC/upgrade/14_3/schedule @@ -109,7 +109,6 @@ babelfish_authid_login_ext babelfish_authid_user_ext babelfish_cast_floor babelfish_inconsistent_metadata -babelfish_migration_mode babelfish_namespace_ext babelfish_sysdatabases babel_function_string-before-15-5-or-14-10 diff --git a/test/JDBC/upgrade/14_5/schedule b/test/JDBC/upgrade/14_5/schedule index 1a0570d9a7..2f7889601b 100644 --- a/test/JDBC/upgrade/14_5/schedule +++ b/test/JDBC/upgrade/14_5/schedule @@ -108,7 +108,6 @@ babelfish_authid_login_ext babelfish_authid_user_ext babelfish_cast_floor babelfish_inconsistent_metadata -babelfish_migration_mode babelfish_namespace_ext babelfish_sysdatabases babel_function_string-before-15-5-or-14-10 diff --git a/test/JDBC/upgrade/14_6/schedule b/test/JDBC/upgrade/14_6/schedule index 49b77e0bad..28aad7c0ca 100644 --- a/test/JDBC/upgrade/14_6/schedule +++ b/test/JDBC/upgrade/14_6/schedule @@ -122,7 +122,6 @@ babelfish_authid_user_ext babelfish_cast_floor babelfish_inconsistent_metadata babelfish_integrity_checker -babelfish_migration_mode babelfish_namespace_ext babelfish_sysdatabases babel_function_string-before-15-5-or-14-10 diff --git a/test/JDBC/upgrade/14_7/schedule b/test/JDBC/upgrade/14_7/schedule index f6e1b01045..4e7cda551a 100644 --- a/test/JDBC/upgrade/14_7/schedule +++ b/test/JDBC/upgrade/14_7/schedule @@ -133,7 +133,6 @@ babelfish_authid_user_ext babelfish_cast_floor babelfish_inconsistent_metadata babelfish_integrity_checker -babelfish_migration_mode babelfish_namespace_ext babelfish_sysdatabases babel_function_string-before-15-5-or-14-10 diff --git a/test/JDBC/upgrade/14_8/schedule b/test/JDBC/upgrade/14_8/schedule index 47997ce1ff..864946c42b 100644 --- a/test/JDBC/upgrade/14_8/schedule +++ b/test/JDBC/upgrade/14_8/schedule @@ -131,7 +131,6 @@ babelfish_authid_user_ext babelfish_cast_floor babelfish_inconsistent_metadata babelfish_integrity_checker -babelfish_migration_mode babelfish_namespace_ext babelfish_sysdatabases babel_function_string-before-15-5-or-14-10 diff --git a/test/JDBC/upgrade/14_9/schedule b/test/JDBC/upgrade/14_9/schedule index b2004727b5..09fba72615 100644 --- a/test/JDBC/upgrade/14_9/schedule +++ b/test/JDBC/upgrade/14_9/schedule @@ -178,7 +178,6 @@ babelfish_namespace_ext babelfish_authid_login_ext babelfish_authid_user_ext babelfish_inconsistent_metadata -babelfish_migration_mode schema_resolution_func BABEL-3147-before-16_3-or-15_7-or-14_12 collation_tests_arabic diff --git a/test/JDBC/upgrade/15_1/schedule b/test/JDBC/upgrade/15_1/schedule index 7ec0a67477..b4641fe7bc 100644 --- a/test/JDBC/upgrade/15_1/schedule +++ b/test/JDBC/upgrade/15_1/schedule @@ -121,7 +121,6 @@ babelfish_authid_user_ext babelfish_cast_floor babelfish_inconsistent_metadata babelfish_integrity_checker -babelfish_migration_mode babelfish_namespace_ext babelfish_sysdatabases babel_function_string-before-15-5-or-14-10 diff --git a/test/JDBC/upgrade/15_10/schedule b/test/JDBC/upgrade/15_10/schedule index 6b1f911f6f..6ae3982753 100644 --- a/test/JDBC/upgrade/15_10/schedule +++ b/test/JDBC/upgrade/15_10/schedule @@ -150,7 +150,6 @@ babelfish_authid_user_ext babelfish_cast_floor babelfish_inconsistent_metadata babelfish_integrity_checker -babelfish_migration_mode babelfish_namespace_ext babelfish_sysdatabases babel_function_string @@ -428,7 +427,6 @@ TestRowVersion TestSmallDatetime TestSmallInt TestSmallMoney -TestSpatialPoint Test-sp_addrole Test-sp_addrolemember Test-sp_babelfish_volatility diff --git a/test/JDBC/upgrade/15_9/schedule b/test/JDBC/upgrade/15_11/schedule similarity index 99% rename from test/JDBC/upgrade/15_9/schedule rename to test/JDBC/upgrade/15_11/schedule index 9cccc654e2..ac6b961089 100644 --- a/test/JDBC/upgrade/15_9/schedule +++ b/test/JDBC/upgrade/15_11/schedule @@ -150,7 +150,6 @@ babelfish_authid_user_ext babelfish_cast_floor babelfish_inconsistent_metadata babelfish_integrity_checker -babelfish_migration_mode babelfish_namespace_ext babelfish_sysdatabases babel_function_string @@ -428,7 +427,6 @@ TestRowVersion TestSmallDatetime TestSmallInt TestSmallMoney -TestSpatialPoint Test-sp_addrole Test-sp_addrolemember Test-sp_babelfish_volatility diff --git a/test/JDBC/upgrade/15_2/schedule b/test/JDBC/upgrade/15_2/schedule index cfb64a60ed..dfc972fedf 100644 --- a/test/JDBC/upgrade/15_2/schedule +++ b/test/JDBC/upgrade/15_2/schedule @@ -132,7 +132,6 @@ babelfish_authid_user_ext babelfish_cast_floor babelfish_inconsistent_metadata babelfish_integrity_checker -babelfish_migration_mode babelfish_namespace_ext babelfish_sysdatabases babel_function_string-before-15-5-or-14-10 diff --git a/test/JDBC/upgrade/15_3/schedule b/test/JDBC/upgrade/15_3/schedule index d7d96ba181..123b1a8b7c 100644 --- a/test/JDBC/upgrade/15_3/schedule +++ b/test/JDBC/upgrade/15_3/schedule @@ -142,7 +142,6 @@ babelfish_authid_user_ext babelfish_cast_floor babelfish_inconsistent_metadata babelfish_integrity_checker -babelfish_migration_mode babelfish_namespace_ext babelfish_sysdatabases babel_function_string-before-15-5-or-14-10 diff --git a/test/JDBC/upgrade/15_4/schedule b/test/JDBC/upgrade/15_4/schedule index f06db0692c..8fa1c97c0f 100644 --- a/test/JDBC/upgrade/15_4/schedule +++ b/test/JDBC/upgrade/15_4/schedule @@ -144,7 +144,6 @@ babelfish_authid_user_ext babelfish_cast_floor babelfish_inconsistent_metadata babelfish_integrity_checker -babelfish_migration_mode babelfish_namespace_ext babelfish_sysdatabases babel_function_string-before-15-5-or-14-10 diff --git a/test/JDBC/upgrade/15_5/schedule b/test/JDBC/upgrade/15_5/schedule index 29887141fd..1f1809cb90 100644 --- a/test/JDBC/upgrade/15_5/schedule +++ b/test/JDBC/upgrade/15_5/schedule @@ -147,7 +147,6 @@ babelfish_authid_user_ext babelfish_cast_floor babelfish_inconsistent_metadata babelfish_integrity_checker -babelfish_migration_mode babelfish_namespace_ext babelfish_sysdatabases babel_function_string diff --git a/test/JDBC/upgrade/15_6/schedule b/test/JDBC/upgrade/15_6/schedule index 2e1bb32a5e..a9e06b9c32 100644 --- a/test/JDBC/upgrade/15_6/schedule +++ b/test/JDBC/upgrade/15_6/schedule @@ -150,7 +150,6 @@ babelfish_authid_user_ext babelfish_cast_floor babelfish_inconsistent_metadata babelfish_integrity_checker -babelfish_migration_mode babelfish_namespace_ext babelfish_sysdatabases babel_function_string @@ -430,7 +429,6 @@ TestRowVersion TestSmallDatetime TestSmallInt TestSmallMoney -TestSpatialPoint Test-sp_addrole Test-sp_addrolemember Test-sp_babelfish_volatility diff --git a/test/JDBC/upgrade/15_7/schedule b/test/JDBC/upgrade/15_7/schedule index 3cfda46d70..f937b7107b 100644 --- a/test/JDBC/upgrade/15_7/schedule +++ b/test/JDBC/upgrade/15_7/schedule @@ -151,7 +151,6 @@ babelfish_cast_floor babelfish_inconsistent_metadata babelfish_integrity_checker check_for_inconsistent_metadata -babelfish_migration_mode babelfish_namespace_ext babelfish_sysdatabases babel_function_string @@ -431,7 +430,6 @@ TestRowVersion TestSmallDatetime TestSmallInt TestSmallMoney -TestSpatialPoint Test-sp_addrole Test-sp_addrolemember Test-sp_babelfish_volatility diff --git a/test/JDBC/upgrade/15_8/schedule b/test/JDBC/upgrade/15_8/schedule index 89be82c55b..a856d2134a 100644 --- a/test/JDBC/upgrade/15_8/schedule +++ b/test/JDBC/upgrade/15_8/schedule @@ -150,7 +150,6 @@ babelfish_authid_user_ext babelfish_cast_floor babelfish_inconsistent_metadata babelfish_integrity_checker -babelfish_migration_mode babelfish_namespace_ext babelfish_sysdatabases babel_function_string @@ -428,7 +427,6 @@ TestRowVersion TestSmallDatetime TestSmallInt TestSmallMoney -TestSpatialPoint Test-sp_addrole Test-sp_addrolemember Test-sp_babelfish_volatility diff --git a/test/JDBC/upgrade/16_1/schedule b/test/JDBC/upgrade/16_1/schedule index 4372849b46..a61e52fd31 100644 --- a/test/JDBC/upgrade/16_1/schedule +++ b/test/JDBC/upgrade/16_1/schedule @@ -149,7 +149,6 @@ babelfish_authid_user_ext babelfish_cast_floor babelfish_inconsistent_metadata babelfish_integrity_checker -babelfish_migration_mode babelfish_namespace_ext babelfish_sysdatabases babel_function_string diff --git a/test/JDBC/upgrade/16_2/schedule b/test/JDBC/upgrade/16_2/schedule index dc35b85030..b161d8ef69 100644 --- a/test/JDBC/upgrade/16_2/schedule +++ b/test/JDBC/upgrade/16_2/schedule @@ -150,7 +150,6 @@ babelfish_authid_user_ext babelfish_cast_floor babelfish_inconsistent_metadata babelfish_integrity_checker -babelfish_migration_mode babelfish_namespace_ext babelfish_sysdatabases babel_function_string @@ -432,7 +431,6 @@ TestRowVersion TestSmallDatetime TestSmallInt TestSmallMoney -TestSpatialPoint Test-sp_addrole Test-sp_addrolemember Test-sp_babelfish_volatility diff --git a/test/JDBC/upgrade/16_3/schedule b/test/JDBC/upgrade/16_3/schedule index e0ab938838..0eba293d16 100644 --- a/test/JDBC/upgrade/16_3/schedule +++ b/test/JDBC/upgrade/16_3/schedule @@ -150,7 +150,6 @@ babelfish_cast_floor babelfish_inconsistent_metadata babelfish_integrity_checker check_for_inconsistent_metadata -babelfish_migration_mode babelfish_namespace_ext babelfish_sysdatabases babel_function_string @@ -433,7 +432,6 @@ TestRowVersion TestSmallDatetime TestSmallInt TestSmallMoney -TestSpatialPoint Test-sp_addrole Test-sp_addrolemember Test-sp_babelfish_volatility diff --git a/test/JDBC/upgrade/16_4/schedule b/test/JDBC/upgrade/16_4/schedule index 7b86843ace..bc1f1692c3 100644 --- a/test/JDBC/upgrade/16_4/schedule +++ b/test/JDBC/upgrade/16_4/schedule @@ -150,7 +150,6 @@ babelfish_cast_floor babelfish_inconsistent_metadata babelfish_integrity_checker check_for_inconsistent_metadata -babelfish_migration_mode babelfish_namespace_ext babelfish_sysdatabases babel_function_string @@ -434,7 +433,6 @@ TestRowVersion TestSmallDatetime TestSmallInt TestSmallMoney -TestSpatialPoint Test-spatial-functions Test-sp_addrole Test-sp_addrolemember diff --git a/test/JDBC/upgrade/16_5/schedule b/test/JDBC/upgrade/16_6/schedule similarity index 99% rename from test/JDBC/upgrade/16_5/schedule rename to test/JDBC/upgrade/16_6/schedule index c777f73d1d..49b2e5ff3a 100644 --- a/test/JDBC/upgrade/16_5/schedule +++ b/test/JDBC/upgrade/16_6/schedule @@ -150,7 +150,6 @@ babelfish_cast_floor babelfish_inconsistent_metadata babelfish_integrity_checker check_for_inconsistent_metadata -babelfish_migration_mode babelfish_namespace_ext babelfish_sysdatabases babel_function_string @@ -435,7 +434,6 @@ TestRowVersion TestSmallDatetime TestSmallInt TestSmallMoney -TestSpatialPoint Test-spatial-functions Test-sp_addrole Test-sp_addrolemember diff --git a/test/JDBC/upgrade/latest/schedule b/test/JDBC/upgrade/latest/schedule index 4db9a875fc..f298d42302 100644 --- a/test/JDBC/upgrade/latest/schedule +++ b/test/JDBC/upgrade/latest/schedule @@ -150,7 +150,6 @@ babelfish_cast_floor babelfish_inconsistent_metadata babelfish_integrity_checker check_for_inconsistent_metadata -babelfish_migration_mode babelfish_namespace_ext babelfish_sysdatabases babel_function_string @@ -435,7 +434,6 @@ TestRowVersion TestSmallDatetime TestSmallInt TestSmallMoney -TestSpatialPoint Test-spatial-functions Test-sp_addrole Test-sp_addrolemember @@ -498,6 +496,8 @@ alter_proc_recompile catalogs_dbo_sys_schema-upgrade unary_plus_op_string tabvar_in_function +atatuservar +exec_sp_in_udf BABEL-4217 Test_ISNULL BABEL-4270 diff --git a/test/python/expected/sql_validation_framework/expected_create.out b/test/python/expected/sql_validation_framework/expected_create.out index 6abda76486..9049176018 100644 --- a/test/python/expected/sql_validation_framework/expected_create.out +++ b/test/python/expected/sql_validation_framework/expected_create.out @@ -33,6 +33,7 @@ Could not find tests for function sys.openjson_simple Could not find tests for function sys.openjson_with Could not find tests for function sys.openquery_internal Could not find tests for function sys.patindex_ai_collations +Could not find tests for function sys.pltsql_assign_var Could not find tests for function sys.remove_accents_internal_using_cache Could not find tests for function sys.role_id Could not find tests for function sys.sp_columns_managed_internal @@ -116,9 +117,6 @@ Could not find upgrade tests for function sys.dateadd_internal Could not find upgrade tests for function sys.datediff_internal Could not find upgrade tests for function sys.datepart_internal Could not find upgrade tests for function sys.default_domain -Could not find upgrade tests for function sys.error_procedure -Could not find upgrade tests for function sys.exp -Could not find upgrade tests for function sys.fetch_status Could not find upgrade tests for function sys.floor Could not find upgrade tests for function sys.fn_helpcollations Could not find upgrade tests for function sys.formatmessage @@ -140,10 +138,9 @@ Could not find upgrade tests for function sys.openjson_with Could not find upgrade tests for function sys.openquery_internal Could not find upgrade tests for function sys.options Could not find upgrade tests for function sys.patindex_ai_collations -Could not find upgrade tests for function sys.pgerror +Could not find upgrade tests for function sys.pltsql_assign_var Could not find upgrade tests for function sys.remove_accents_internal_using_cache Could not find upgrade tests for function sys.role_id -Could not find upgrade tests for function sys.servername Could not find upgrade tests for function sys.sp_columns_managed_internal Could not find upgrade tests for function sys.sp_datatype_info_helper Could not find upgrade tests for function sys.sp_describe_first_result_set_internal diff --git a/test/python/expected/sql_validation_framework/expected_drop.out b/test/python/expected/sql_validation_framework/expected_drop.out index f2d6ebdb85..8712a71aa5 100644 --- a/test/python/expected/sql_validation_framework/expected_drop.out +++ b/test/python/expected/sql_validation_framework/expected_drop.out @@ -75,6 +75,7 @@ Unexpected drop found for procedure sys.babelfish_drop_deprecated_view in file b Unexpected drop found for procedure sys.babelfish_drop_deprecated_view in file babelfishpg_tsql--2.1.0--2.2.0.sql Unexpected drop found for procedure sys.babelfish_remove_object_from_extension in file babelfishpg_tsql--2.1.0--2.2.0.sql Unexpected drop found for procedure sys.babelfish_remove_object_from_extension in file babelfishpg_tsql--3.0.0--3.1.0.sql +Unexpected drop found for procedure sys.babelfish_revoke_guest_from_mapped_logins in file babelfishpg_tsql--4.4.0--4.5.0.sql Unexpected drop found for procedure sys.babelfish_update_collation_to_default in file babelfishpg_common--2.2.0--2.3.0.sql Unexpected drop found for procedure sys.babelfish_update_collation_to_default in file babelfishpg_tsql--2.2.0--2.3.0.sql Unexpected drop found for procedure sys.babelfish_update_collation_to_default in file babelfishpg_tsql--2.3.0--3.0.0.sql diff --git a/test/python/expected/upgrade_validation/expected_dependency.out b/test/python/expected/upgrade_validation/expected_dependency.out index c64d54241e..c92582bdb3 100644 --- a/test/python/expected/upgrade_validation/expected_dependency.out +++ b/test/python/expected/upgrade_validation/expected_dependency.out @@ -450,6 +450,7 @@ Function sys.geography(sys.bbf_varbinary) Function sys.geography(sys.bpchar) Function sys.geography(sys.geography,integer,boolean) Function sys.geography(text,integer,boolean) +Function sys.geography__point(double precision,double precision,integer) Function sys.geography__stflipcoordinates(sys.geography) Function sys.geography__stgeomfromtext(text,integer) Function sys.geography__stpointfromtext(text,integer) @@ -530,6 +531,7 @@ Function sys.language() Function sys.len(sys.bbf_varbinary) Function sys.len(text) Function sys.lock_timeout() +Function sys.long(sys.geography) Function sys.max_connections() Function sys.microsoftversion() Function sys.money_sqlvariant(sys.fixeddecimal) @@ -559,6 +561,7 @@ Function sys.options() Function sys.original_login() Function sys.patindex_ai_collations(character varying,character varying) Function sys.pgerror() +Function sys.pltsql_assign_var(integer,anyelement) Function sys.pltsql_call_handler() Function sys.pltsql_inline_handler(internal) Function sys.pltsql_validator(oid) @@ -657,12 +660,19 @@ Function sys.sqlvariant_varchar(sys.sql_variant) Function sys.square(double precision) Function sys.st_geometrytype(sys.geography) Function sys.st_geometrytype(sys.geometry) +Function sys.st_transform(sys.geography,integer) Function sys.st_zmflag(sys.geography) Function sys.st_zmflag(sys.geometry) +Function sys.stasbinary(sys.geography) +Function sys.stasbinary(sys.geometry) Function sys.stasbinary_helper(sys.geography) +Function sys.stastext(sys.geography) +Function sys.stastext(sys.geometry) Function sys.stastext_helper(sys.geography) Function sys.stcontains_helper(sys.geography,sys.geography) Function sys.stcontains_helper(sys.geometry,sys.geometry) +Function sys.stdistance(sys.geography,sys.geography) +Function sys.stdistance(sys.geometry,sys.geometry) Function sys.stdistance_helper(sys.geography,sys.geography) Function sys.stequals_helper(sys.geography,sys.geography) Function sys.stequals_helper(sys.geometry,sys.geometry) @@ -670,6 +680,7 @@ Function sys.stgeogfromtext_helper(text,integer) Function sys.stgeomfromtext_helper(text,integer) Function sys.string_escape(sys.nvarchar,text) Function sys.string_split(character varying,character varying) +Function sys.sty(sys.geometry) Function sys.suser_id() Function sys.suser_id_internal(text) Function sys.suser_name() @@ -897,6 +908,8 @@ Operator sys.<>(sys.fixeddecimal,integer) Operator sys.<>(sys.fixeddecimal,numeric) Operator sys.<>(sys.fixeddecimal,smallint) Operator sys.<>(sys.fixeddecimal,sys.fixeddecimal) +Operator sys.<>(sys.geography,sys.geography) +Operator sys.<>(sys.geometry,sys.geometry) Operator sys.<>(sys.rowversion,sys.rowversion) Operator sys.<>(sys.smalldatetime,date) Operator sys.<>(sys.smalldatetime,sys.smalldatetime) @@ -913,6 +926,8 @@ Operator sys.=(sys.fixeddecimal,bigint) Operator sys.=(sys.fixeddecimal,integer) Operator sys.=(sys.fixeddecimal,numeric) Operator sys.=(sys.fixeddecimal,smallint) +Operator sys.=(sys.geography,sys.geography) +Operator sys.=(sys.geometry,sys.geometry) Operator sys.=(sys.rowversion,sys.rowversion) Operator sys.=(sys.smalldatetime,date) Operator sys.=(sys.smalldatetime,sys.smalldatetime) diff --git a/test/python/isolationtest/specParserVisitorImpl.py b/test/python/isolationtest/specParserVisitorImpl.py index b376331cb2..e40a063149 100644 --- a/test/python/isolationtest/specParserVisitorImpl.py +++ b/test/python/isolationtest/specParserVisitorImpl.py @@ -2,7 +2,7 @@ from .parser.specParserVisitor import specParserVisitor -# Generated from specParser.g4 by ANTLR 4.9.3 +# Generated from specParser.g4 by ANTLR 4.13.2 from antlr4 import * from .parser.specParser import specParser