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 -----
> > <?php
> > 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 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]);
> > > > > >                          
>
> ...
>
> read more »
--~--~---------~--~----~------------~-------~--~----~
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