Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

With Column Encryption, insertion requires the column_list for tables with identity columns #1050

Closed
yitam opened this issue Nov 1, 2019 · 1 comment

Comments

@yitam
Copy link
Contributor

yitam commented Nov 1, 2019

When connecting with Column Encryption enabled, insertion into any table with an identity column requires explicit specification of the column_list.

Steps to reproduce:

  1. Connect with ColumnEncryption=Enabled
    $conn = new PDO( "sqlsrv:server=$server;Database = $DB;ColumnEncryption=Enabled;", 
                            $uid, $pwd);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  1. Create a new table with an identity column, like this
    CREATE TABLE testDescParam (ID int identity(1,1), Col1 NVARCHAR(100))

  2. Insert a value by binding param

    $val = 'BlahBlahBlah';
    $sql = "INSERT INTO testDescParam VALUES (:value)";
    $stmt = $conn->prepare($sql);
    $stmt->bindParam(':value', $val);
    $stmt->execute();

Expected behavior:

Expect the above to succeed. That is, 'BlahBlahBlah' should be inserted into the first row with ID = 1

Actual behavior:

Caught this exception:
SQLSTATE[22018]: [Microsoft][ODBC Driver 17 for SQL Server]Invalid character value for cast specification

To work around this, modify the above INSERT sql to
$sql = "INSERT INTO testDescParam (Col1) VALUES (:value)";

@v-chojas
Copy link

v-chojas commented Nov 4, 2019

This is a server-side limitation. With column encryption, the sp_describe_* method of getting parameter metadata doesn't work on encrypted columns, but the old method of FMTONLY can't identify IDENTITY columns either.

Regardless, it is always a good idea to specify the column list explicitly in an INSERT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants