Re: MSSQL ntext problem

2008-07-16 Thread bitkidoku

Hmm so I am on the right track. The change is same as I did in
dbo_mssql.php. I will look into it.

On Jul 15, 9:40 pm, Nate <[EMAIL PROTECTED]> wrote:
> If the code above is the same as the method you patched in the core,
> then it should work fine.  Try examining the query output, and/or
> running the query in Enterprise Manager to get to a more informative
> error message.
>
> On Jul 15, 8:22 am, bitkidoku <[EMAIL PROTECTED]> wrote:
>
> > When I change the source it works fine. But when I try to extend the
> > driver I get the same error saying:
> > Warning (2): mssql_query() [function.mssql-query]: Query failed [CORE
> > \cake\libs\model\datasources\dbo\dbo_mssql.php, line 176]
>
> > I changed the database config to 'my_mssql'. And created the following
> > extension. I am obviously missing something but what?
>
> > - CODE START -
> >  > require (LIBS . 'model' . DS . 'datasources' . DS . 'dbo' . DS .
> > 'dbo_mssql.php');
>
> > class DboMyMssql extends DboMssql {
>
> >         var $description = "MSSQL DBO Extension Driver";
>
> >         // override this method to make ntext problem solved
> >         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); // edit by 
> > b.e.d .
> > ref:https://trac.cakephp.org/attachment/ticket/4287/mssql_cake.patch
>
> >                 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];
> >                                                 // edit by b.e.d start
> >                                                 //-$fieldName  = 
> > $this->name($alias . '.' . $fields[$i]);
> >                                                 //-$fieldAlias = 
> > $this->name($alias . '__' . $fieldAlias);
> >                                                 if 
> > ($fieldDescription[$fields[$i]]['type'] == 'text')
> >                                                 {
> >                                                         $fieldName  = 
> > "CAST(CAST(".$this->name($alias) . '.' . $this->name($fields[$i]) ." AS 
> > VARCHAR(8000)) AS TEXT)";
>
> >                                                         $fieldAlias = 
> > $this->name($alias . '__' . $fieldAlias);
> >                                                 }
> >                                                 else
> >                                                 {
> >                                                         $fieldName = 
> > $this->name($alias) . '.' . $this->name($fields[$i]);
>
> >                                                         $fieldAlias = 
> > $this->name($alias . '__' . $fieldAlias);
> >                                                 }
> >                                                 // edit by b.e.d end
> >                                         } 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];
> >                         }
> >                 }
> >   

Re: MSSQL ntext problem

2008-07-15 Thread Nate

If the code above is the same as the method you patched in the core,
then it should work fine.  Try examining the query output, and/or
running the query in Enterprise Manager to get to a more informative
error message.

On Jul 15, 8:22 am, bitkidoku <[EMAIL PROTECTED]> wrote:
> When I change the source it works fine. But when I try to extend the
> driver I get the same error saying:
> Warning (2): mssql_query() [function.mssql-query]: Query failed [CORE
> \cake\libs\model\datasources\dbo\dbo_mssql.php, line 176]
>
> I changed the database config to 'my_mssql'. And created the following
> extension. I am obviously missing something but what?
>
> - CODE START -
>  require (LIBS . 'model' . DS . 'datasources' . DS . 'dbo' . DS .
> 'dbo_mssql.php');
>
> class DboMyMssql extends DboMssql {
>
>         var $description = "MSSQL DBO Extension Driver";
>
>         // override this method to make ntext problem solved
>         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); // edit by 
> b.e.d .
> ref:https://trac.cakephp.org/attachment/ticket/4287/mssql_cake.patch
>
>                 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];
>                                                 // edit by b.e.d start
>                                                 //-$fieldName  = 
> $this->name($alias . '.' . $fields[$i]);
>                                                 //-$fieldAlias = 
> $this->name($alias . '__' . $fieldAlias);
>                                                 if 
> ($fieldDescription[$fields[$i]]['type'] == 'text')
>                                                 {
>                                                         $fieldName  = 
> "CAST(CAST(".$this->name($alias) . '.' . $this->name($fields[$i]) ." AS 
> VARCHAR(8000)) AS TEXT)";
>
>                                                         $fieldAlias = 
> $this->name($alias . '__' . $fieldAlias);
>                                                 }
>                                                 else
>                                                 {
>                                                         $fieldName = 
> $this->name($alias) . '.' . $this->name($fields[$i]);
>
>                                                         $fieldAlias = 
> $this->name($alias . '__' . $fieldAlias);
>                                                 }
>                                                 // edit by b.e.d end
>                                         } 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;
>         }}
>
> ?>
> - CODE END -
>
> On Jul 11, 3:38 pm, Nate <[EMAIL PROTECTED]> wrote:
>
> > You don't need to change the source.  Just extend the driver and
> > override the correct method.
>
> > On Jul 10, 8:45 pm, bitkidoku <[EMAIL PROTECTED]> wrote:
>
> > > Thank you very much :-) I did a change

Re: MSSQL ntext problem

2008-07-15 Thread bitkidoku

When I change the source it works fine. But when I try to extend the
driver I get the same error saying:
Warning (2): mssql_query() [function.mssql-query]: Query failed [CORE
\cake\libs\model\datasources\dbo\dbo_mssql.php, line 176]

I changed the database config to 'my_mssql'. And created the following
extension. I am obviously missing something but what?

- CODE START -
alias;
}
$fields = parent::fields($model, $alias, $fields, false);
$count = count($fields);

$fieldDescription = $this-> describe($model); // edit by b.e.d .
ref: https://trac.cakephp.org/attachment/ticket/4287/mssql_cake.patch

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];
// edit by b.e.d start
//-$fieldName  = 
$this->name($alias . '.' . $fields[$i]);
//-$fieldAlias = 
$this->name($alias . '__' . $fieldAlias);
if 
($fieldDescription[$fields[$i]]['type'] == 'text')
{
$fieldName  = 
"CAST(CAST(".$this->name($alias) . '.' . $this-
>name($fields[$i]) ." AS VARCHAR(8000)) AS TEXT)";
$fieldAlias = 
$this->name($alias . '__' . $fieldAlias);
}
else
{
$fieldName = 
$this->name($alias) . '.' . $this-
>name($fields[$i]);
$fieldAlias = 
$this->name($alias . '__' . $fieldAlias);
}
// edit by b.e.d end
} 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;
}
}
?>
- CODE END -

On Jul 11, 3:38 pm, Nate <[EMAIL PROTECTED]> wrote:
> You don't need to change the source.  Just extend the driver and
> override the correct method.
>
> On Jul 10, 8:45 pm, bitkidoku <[EMAIL PROTECTED]> wrote:
>
> > Thank you very much :-) I did a change in the source in a similar way.
> > It is dirty but it works.
>
> > On Jul 11, 12:32 am, James K <[EMAIL PROTECTED]> wrote:
>
> > > 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
> > > > RC

Re: MSSQL ntext problem

2008-07-11 Thread bitkidoku

Thanks, good idea indeed. I added that to my todo list.

On Jul 11, 3:38 pm, Nate <[EMAIL PROTECTED]> wrote:
> You don't need to change the source.  Just extend the driver and
> override the correct method.
>
> On Jul 10, 8:45 pm, bitkidoku <[EMAIL PROTECTED]> wrote:
>
> > Thank you very much :-) I did a change in the source in a similar way.
> > It is dirty but it works.
>
> > On Jul 11, 12:32 am, James K <[EMAIL PROTECTED]> wrote:
>
> > > 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 ODB

Re: MSSQL ntext problem

2008-07-11 Thread Nate

You don't need to change the source.  Just extend the driver and
override the correct method.

On Jul 10, 8:45 pm, bitkidoku <[EMAIL PROTECTED]> wrote:
> Thank you very much :-) I did a change in the source in a similar way.
> It is dirty but it works.
>
> On Jul 11, 12:32 am, James K <[EMAIL PROTECTED]> wrote:
>
> > 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.cakep

Re: MSSQL ntext problem

2008-07-10 Thread bitkidoku

Thank you very much :-) I did a change in the source in a similar way.
It is dirty but it works.

On Jul 11, 12:32 am, James K <[EMAIL PROTECTED]> wrote:
> 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.

--~--~-~--~~---

Re: MSSQL ntext problem

2008-07-10 Thread James K

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
-~--~--

Re: MSSQL ntext problem

2008-07-10 Thread James K

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
-~--~~~~--~~--~--~---



MSSQL ntext problem

2008-07-10 Thread bitkidoku

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
-~--~~~~--~~--~--~---