Błąd przy pdo->prepare() – [Microsoft][ODBC SQL Server Driver][SQL Server]The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.

Cała zabawa dotyczy błędu opisanego tu http://bugs.php.net/bug.php?id=36561. ([Microsoft][ODBC SQL Server
Driver][SQL Server]The text, ntext, and image data types cannot be
compared or sorted, except when using IS NULL or LIKE operator.).
Rozwiązaniem jest (jeżeli nie chcecie czkać na M$) użycie konwersji (rzutowania?) poprze CAST.
Ponieważ nie wolno rzutować TEXT na INT (a właśnie TEXT jest brane jako typ parametru “bindowanego”, trzeba rzutować na VARCHAR, a potem baza sama sobie zrobi resztę. Ponieważ integer jest od -9223372036854775808 through 9223372036854775807 (BIGINT) na opisanie go potrzeba 20 znaków (1 znak na ‘minus’ + 19 na cyfry).
Resume :)
Użyj TestID = CAST(:TestID AS VARCHAR(20)) zamiast TestID = :TestID. Niewiele roboty, a potrafi zaoszczędzić modyfikacji kodu php.

PDO/ODBC/MSSQL does not work with bound params.

Simple solution (if you dont want wait for M$) use CAST:
because integer is definded (sql2000) as -9223372036854775808 through 9223372036854775807 we need max 20 chars.

Use this:
SELECT TestID FROM zTest_TBL
WHERE TestID = CAST(:TestID AS VARCHAR(20)) AND TestID IN (SELECT TestID FROM zTest_TBL
)

instead this:
SELECT TestID FROM zTest_TBL
WHERE TestID = :TestID AND TestID IN (SELECT TestID FROM zTest_TBL
)

Dont convert to INT or BIGINT. Why? Try it ;)

I hope, this help to save many complicated solution in php code.

Tagi: ,

Dodaj komentarz

Wprowadź swoje dane lub kliknij jedną z tych ikon, aby się zalogować:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Zmień )

Twitter picture

You are commenting using your Twitter account. Log Out / Zmień )

Facebook photo

You are commenting using your Facebook account. Log Out / Zmień )

Connecting to %s


Follow

Otrzymuj każdy nowy wpis na swoją skrzynkę e-mail.