PHP 有两个修复程序,Bug #54167 解决了 dblib 中的 NULL 问题。不幸的是,当它被合并到 PHP 中时,另一个 bug 导致了唯一标识符的另一个问题,使它们损坏。基本上,它们会失去较低的位(用零填充,如 E3407588-2B77-0000-0200-000000000000)。有一个 bug 修复程序,但它要等到 PHP 5.4 才能发布。
一般的解决方案是将唯一标识符转换为字符串,但 Doctrine 不处理这个问题。Doctrine 的一个简单补丁涉及将列定义从 string(36)
更改为 guid
,然后在 Query.php 文件中让 Doctrine 为您执行转换。一个示例:
// In the schema file
columns:
userid:
type: guid
fixed: false
unsigned: false
notnull: false
primary: true
autoincrement: false
// Which generates this in the base model
$this->hasColumn('userid', 'guid', null, array(
'type' => 'guid',
'fixed' => 0,
'unsigned' => false,
'notnull' => false,
'primary' => true,
'autoincrement' => false,
));
// Only after you change this in Doctrine/DataDict/Mssql.php on line 192-194
case 'uniqueidentifier':
$type[] = 'guid'; // changed from 'string'
$length = 36;
// Then to use the new guid datatype, edit Doctrine/Query.php starting on line 487
foreach ($fields as $fieldName) {
$columnName = $table->getColumnName($fieldName);
if (($owner = $table->getColumnOwner($columnName)) !== null &&
$owner !== $table->getComponentName()) {
$parent = $this->_conn->getTable($owner);
$columnName = $parent->getColumnName($fieldName);
$parentAlias = $this->getSqlTableAlias($componentAlias . '.' . $parent->getComponentName());
$sql[] = $this->_conn->quoteIdentifier($parentAlias) . '.' . $this->_conn->quoteIdentifier($columnName)
. ' AS '
. $this->_conn->quoteIdentifier($tableAlias . '__' . $columnName);
} else {
/* This new code will get the column definition, look for guid, then cast the column as a string to work around PHP bug 60033. Everything above this line is unchanged */
$columnName = $table->getColumnName($fieldName);
$columnDefinition = $table->getColumnDefinition($columnName);
if ($columnDefinition['type'] == 'guid') {
$sql[] = 'CAST(' . $this->_conn->quoteIdentifier($tableAlias) . '.' . $this->_conn->quoteIdentifier($columnName) . ' as VARCHAR(36))'
. ' AS '
. $this->_conn->quoteIdentifier($tableAlias . '__' . $columnName);
} else {
// this block is unchanged from the original
$sql[] = $this->_conn->quoteIdentifier($tableAlias) . '.' . $this->_conn->quoteIdentifier($columnName)
. ' AS '
. $this->_conn->quoteIdentifier($tableAlias . '__' . $columnName);
}
}
}
我不确定你是否需要在IF语句的第一部分添加相同的代码,但我添加了这段代码,现在所有我的唯一标识符都正确返回(下半部分不是零,像E3407588-2B77-0000-0276-3D9E8DE868D6)。也许Doctrine的开发人员会加入这个补丁,因为Doctrine在任何版本的PHP<5.4中使用SQL Server的唯一标识符都是无用的。
我知道手动编辑Doctrine代码是不推荐的,但这是在我尝试运行来自源代码的PHP 5.4 beta2并花费数小时尝试使更新的sqlsrv驱动程序在Doctrine 1.2中工作之后。此外,这些代码行比使用较旧的mssql_query代码重新编写所有查询要容易得多。
希望这可以帮助。