Oh, PS - I modified the hack so that it only runs when it recognizes
an XML type from SQL 2005. If you change my
$fieldDescription[$fields[$i]]['type'] == 'xml' to
$fieldDescription[$fields[$i]]['type'] == 'text', it should work for
ntext fields in general.

- James

On Jul 10, 12:34 pm, James K <[EMAIL PROTECTED]> wrote:
> The official word from the CakePHP team is that "CakePHP does not
> support ntext fields". You're stuck using the text casting hack. I'm
> using MS SQL myself, and have had to use it, unfortunately.
>
> I'm using 1.2 RC2 and have successfully gotten that same hack to work
> - you have to change it a bit to work with the changes introduced in
> RC1. Here's my version of the fields function from RC2:
>
>         function fields(&$model, $alias = null, $fields = array(), $quote =
> true) {
>                 if (empty($alias)) {
>                         $alias = $model->alias;
>                 }
>                 $fields = parent::fields($model, $alias, $fields, false);
>                 $count = count($fields);
>
>                 $fieldDescription = $this->describe($model);
>
>                 if ($count >= 1 && $fields[0] != '*' && strpos($fields[0],
> 'COUNT(*)') === false) {
>                         for ($i = 0; $i < $count; $i++) {
>                                 $prepend = '';
>
>                                 if (strpos($fields[$i], 'DISTINCT') !== 
> false) {
>                                         $prepend = 'DISTINCT ';
>                                         $fields[$i] = 
> trim(str_replace('DISTINCT', '', $fields[$i]));
>                                 }
>                                 $fieldAlias = count($this->__fieldMappings);
>
>                                 if (!preg_match('/\s+AS\s+/i', $fields[$i])) {
>                                         if (strpos($fields[$i], '.') === 
> false) {
>                                                 $this->__fieldMappings[$alias 
> . '__' . $fieldAlias] = $alias .
> '.' . $fields[$i];
>                                                 if 
> ($fieldDescription[$fields[$i]]['type'] == 'xml') {
>                                                         $fieldName = 
> "CAST(CAST(".$this->name($alias . '.' .
> $fields[$i])." AS VARCHAR(8000)) AS TEXT)";
>                                                 } else {
>                                                         $fieldName  = 
> $this->name($alias . '.' . $fields[$i]);
>                                                 }
>                                                 $fieldAlias = 
> $this->name($alias . '__' . $fieldAlias);
>                                         } else {
>                                                 $build = explode('.', 
> $fields[$i]);
>                                                 
> $this->__fieldMappings[$build[0] . '__' . $fieldAlias] =
> $fields[$i];
>                                                 $fieldName  = 
> $this->name($build[0] . '.' . $build[1]);
>                                                 $fieldAlias = 
> $this->name(preg_replace("/^\[(.+)\]$/", "$1",
> $build[0]) . '__' . $fieldAlias);
>                                         }
>                                         if 
> ($model->getColumnType($fields[$i]) == 'datetime') {
>                                                 $fieldName = 
> "CONVERT(VARCHAR(20), {$fieldName}, 20)";
>                                         }
>                                         $fields[$i] =  "{$fieldName} AS 
> {$fieldAlias}";
>                                 }
>                                 $fields[$i] = $prepend . $fields[$i];
>                         }
>                 }
>                 return $fields;
>         }
>
> On Jul 10, 9:59 am, bitkidoku <[EMAIL PROTECTED]> wrote:
>
> > Hi everyone,
>
> > I have a problem using my existing MSSQL DB. I get the following
> > error:
> > "SQL Error: Unicode data in a Unicode-only collation or ntext data
> > cannot be sent to clients using DB-Library (such as ISQL) or ODBC
> > version 3.7 or earlier. [CORE\cake\libs\model\datasources
> > \dbo_source.php, line 512]"
>
> > I encountered this error before while writing my own PHP code. It can
> > be 'solved' casting ntext field to text. The closest solution for
> > CakePHP I found is this:https://trac.cakephp.org/ticket/4287
>
> > But since that applies to 1.2.0.6311 I couldn't make it work at the
> > moment.
>
> > Does anyone have any idea resolving this issue?
> > Thanks in advance :)
>
> > PS: Why do I insist on using MSSQL? Well, that is another story... I
> > am not very happy about that but I have to.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to