akrabat/Akrabat — Issue #9: Format Default Values in Akrabat_Db_Adapter_Pdo_Sqlsrv
Author: voidstate
Created: 2011-12-16 11:32:08+00:00
State: open

MSSQL returns default values with formatting, eg. a boolean true or false is returned as ((0)) or ((1)). This was causing me problems when trying to fill default values in a Zend_Form.

I have created a patch to return the actual values:

```'DEFAULT' => $this->_formatDefaultValue( $row[$column_def] ),
'NULLABLE' => (bool) $row[$nullable],
'LENGTH' => $row[$length],
'SCALE' => $row[$scale],
'PRECISION' => $row[$precision],
'UNSIGNED' => null, // @todo
'PRIMARY' => $isPrimary,
'PRIMARY_POSITION' => $primaryPosition,
'IDENTITY' => $identity
);
}
return $desc;
}

protected function _formatDefaultValue( $value )
{
if( empty( $value ) )
{
return;
}

// take default minus first & last characters
$value = substr( $value, 1, strlen( $value ) - 2 );

// remove starting & ending apostrophes
if( $value{ 0 } == "'" && $value{ strlen( $value ) - 1 } == "'" )
{
$value = substr( $value, 1, strlen( $value ) - 2 );
}

// remove starting and ending brackets (1 and 0 have double brackets)
if( strlen( $value ) > 2 && $value{ 0 } == '(' && $value{ strlen( $value ) - 1 } == ')' )
{
$value = substr( $value, 1, strlen( $value ) - 2 );
}

//exit;

return $value;
}```

Note, this:

```'DEFAULT' => $this->_formatDefaultValue( $row[$column_def] ),```

and the new _formatDefaultValue() method.