[DC-675] Doctrine_Connection_Mssql charset problem Created: 10/May/10  Updated: 23/Jul/14  Resolved: 08/Jun/10

Status: Resolved
Project: Doctrine 1
Component/s: None
Affects Version/s: None
Fix Version/s: 1.2.3

Type: Bug Priority: Major
Reporter: Steve Müller Assignee: Jonathan H. Wage
Resolution: Fixed Votes: 0
Labels: None


 Description   

Recently I got problems with converting UTF-8 data to iso ISO-8859-1 while trying to insert/update a Microsoft SQL Server database.
I wrote a task that exports data from an UTF-8 MySQL database to a latin1 Microsoft SQL Server database. When converting the data from UTF-8 to ISO-8859-1 the insert/update fails:

SQLSTATE[HY000]: General error: trying to execute an empty query

As i tracked the error down I realized, that the exception only occurs if I try to insert/update data with special characters like "ü", "ö", "ä", "ß" etc.
The error's origin seems to lie in the Doctrine_Connection_Mssql class, more precisely in the replaceBoundParamsWithInlineValuesInQuery() method.
Debugging this method shows that after replacing a bound param with data containing a special character (see above), the replace action for the next bound param replaces the whole query string with an empty string. Therefore the parent class's method exec() throws an exception as it tries to execute an empty query.

Example:

Task snippet:
// $src is UTF-8 data (MySQL DB)
// $dest ist latin1 data (MSSQL DB)

$dest->setZip($src->getZip());
$dest->setCity(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $src->getCity());
$dest->setStreet(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $src->getStreet());
$dest->save();

RESULTING DQL: UPDATE table SET zip = ?, city = ?, street = ? WHERE id = ?;

Params:
array(
'22307',
'München',
'Dummystreet 18'
'1'
)

After replaceBoundParamsWithInlineValuesInQuery() replaces param 'München', the query string is replaced by an empty string in the following iteration.

The root of the Problem seems to lie in the regex modifier 'u' which treats the pattern as UTF-8 in the param replacements. Removing this modifier solves the problem for me. What purpose has this modifier?






Generated at Fri Jul 25 17:44:05 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.