The best practice for using external APIs

2008-09-01 Thread bitkidoku

Hello everyone,

I need to generate an excel file and I am using an external API to
generate that excel file. If I wasn't using CakePHP I could include()
API's php file in my code and start writing it directly.

Since I am using CakePHP I am trying to avoid doing stupid things that
will break the design patterns. How should I wrap that API so I can
use it in CakePHP?

Thanks for the answers.
--~--~-~--~~~---~--~~
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: Defining hasOne - from which direction?

2008-09-01 Thread bitkidoku

Hello,

 Person hasOne Address
 Company hasOne Address

 Address belongsTo Person
 Address belongsTo Company

This one seems the best way to do it. Imagine if you ever needed to
enter multiple addresses for one Person, you only need to change the
relation from hasOne to hasMany.

What are your concerns about saveAll() ?

Baris


On Sep 1, 3:58 pm, Preloader [EMAIL PROTECTED] wrote:
 Hello bakers,

 I have the following relations:

 Person hasOne Address
 Company hasOne Address

 Address belongsTo Person
 Address belongsTo Company

 In this case Address should contain person_id and company_id.

 Is this the right way or should I do it the other way round:

 Person belongsTo Address
 Company belongsTo Address

 Address hasOne Person
 Address hasOne Company

 Both, Person and Company, must contain address_id now.

 Which one is the more practicable way? Does it matter at all, if I
 want to use saveAll()?

 Thanks in advance!

 Regards, Christoph
--~--~-~--~~~---~--~~
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: Defining hasOne - from which direction?

2008-09-01 Thread bitkidoku

Hi again,

Yes, if you define another hasOne relationship you have to add another
foreign key. Because of this, it is good to plan, write down the
models and the relationships between models before starting coding.
Besides adding another foreign key to an existing table is not too
much hassle.

I think saveAll() will work fine, but experimenting with it will give
you the best answer :)

Baris

On Sep 1, 4:37 pm, Preloader [EMAIL PROTECTED] wrote:
 Hi Baris,

 thank you for your answer.

 Ok, in this case are you right, but the Address relationship was
 just an example.

 Another thing: What if I add another objects, which have one Address?
 - Everytime I do this I have to add another foreign key to the Address
 table.

 My concerns about saveAll() ... hmmm ... the automagic setting of
 the foreign key. But I think that should be no problem. I just have to
 call the saveAll() method of the model which defines the hasOne, i
 think ... have to try this.

 Regards, Christoph
--~--~-~--~~~---~--~~
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: The best practice for using external APIs

2008-09-01 Thread bitkidoku

Thank you Daniel :) This was the thing I was looking for.

On Sep 1, 5:07 pm, Daniel Hofstetter [EMAIL PROTECTED] wrote:
 Hi,

  I need to generate an excel file and I am using an external API to
  generate that excel file. If I wasn't using CakePHP I could include()
  API's php file in my code and start writing it directly.

  Since I am using CakePHP I am trying to avoid doing stupid things that
  will break the design patterns. How should I wrap that API so I can
  use it in CakePHP?

 Third-part libraries are usually put to the vendors folder and then
 included with:

 App::import('Vendor', 'yourfile');

 Hope that helps!

 --
 Daniel Hofstetterhttp://cakebaker.42dh.com
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



find group parameter problem (GROUP BY problem)

2008-08-29 Thread bitkidoku

Hello all,

I am having problems executing a GROUP BY query. Let's say I have
'sales'  table containing 'id', 'product_id' and 'revenue'. I am
trying to find total revenue of a different products. So far I did:

$sales = $this-Sale-find( 'all', array(
'fields' = array('Sale.product_id', 'SUM(Sale.revenue) as 
total'),
'group' = 'Sale.product_id'
)
);


It does not work. It returns all of the sales. And I dont see any
'GROUP BY' clause in the query debug information.

Any help is appreciated. Thank you for your answers.
--~--~-~--~~~---~--~~
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: find group parameter problem (GROUP BY problem)

2008-08-29 Thread bitkidoku

A correction, I said it returns all the sales, that is not true, I get
the following error:

SQL Error: Column 'monthly_sales.product_id' is invalid in the select
list because it is not contained in either an aggregate function or
the GROUP BY clause.

I am using mssql, does it have something to do with it?

On Aug 29, 2:59 pm, bitkidoku [EMAIL PROTECTED] wrote:
 Hello all,

 I am having problems executing a GROUP BY query. Let's say I have
 'sales'  table containing 'id', 'product_id' and 'revenue'. I am
 trying to find total revenue of a different products. So far I did:

 $sales = $this-Sale-find( 'all', array(
                 'fields' = array('Sale.product_id', 'SUM(Sale.revenue) as 
 total'),
                 'group' = 'Sale.product_id'
         )
 );

 It does not work. It returns all of the sales. And I dont see any
 'GROUP BY' clause in the query debug information.

 Any help is appreciated. Thank you for your answers.
--~--~-~--~~~---~--~~
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: find group parameter problem (GROUP BY problem)

2008-08-29 Thread bitkidoku

Just as I suspected, in dbo_mssql.php GROUP BY clauses are not
included.

Should I open a bug report for this?

On Aug 29, 3:03 pm, bitkidoku [EMAIL PROTECTED] wrote:
 A correction, I said it returns all the sales, that is not true, I get
 the following error:

 SQL Error: Column 'monthly_sales.product_id' is invalid in the select
 list because it is not contained in either an aggregate function or
 the GROUP BY clause.

 I am using mssql, does it have something to do with it?

 On Aug 29, 2:59 pm, bitkidoku [EMAIL PROTECTED] wrote:

  Hello all,

  I am having problems executing a GROUP BY query. Let's say I have
  'sales'  table containing 'id', 'product_id' and 'revenue'. I am
  trying to find total revenue of a different products. So far I did:

  $sales = $this-Sale-find( 'all', array(
                  'fields' = array('Sale.product_id', 'SUM(Sale.revenue) as 
  total'),
                  'group' = 'Sale.product_id'
          )
  );

  It does not work. It returns all of the sales. And I dont see any
  'GROUP BY' clause in the query debug information.

  Any help is appreciated. Thank you for your answers.
--~--~-~--~~~---~--~~
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: find group parameter problem (GROUP BY problem)

2008-08-29 Thread bitkidoku

Yes, I am very sure, I have corrected local version of CakePHP and
checked the repository, and I didn't see any changes made that way in
the repository. And there are no open tickets about this issue.

On Aug 29, 4:34 pm, Rafael Bandeira aka rafaelbandeira3
[EMAIL PROTECTED] wrote:
  Should I open a bug report for this?

 If you're sure about it, yes
--~--~-~--~~~---~--~~
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: find group parameter problem (GROUP BY problem)

2008-08-29 Thread bitkidoku

I opened a ticket: https://trac.cakephp.org/ticket/5357

On Aug 29, 6:36 pm, bitkidoku [EMAIL PROTECTED] wrote:
 Yes, I am very sure, I have corrected local version of CakePHP and
 checked the repository, and I didn't see any changes made that way in
 the repository. And there are no open tickets about this issue.

 On Aug 29, 4:34 pm, Rafael Bandeira aka rafaelbandeira3

 [EMAIL PROTECTED] wrote:
   Should I open a bug report for this?

  If you're sure about it, yes
--~--~-~--~~~---~--~~
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: Clean urls in search form

2008-08-26 Thread bitkidoku

It looks a little bit dirty, but it works, it looks like this

function search() {
if( !empty($this-params['named']) ){
// finding the values and passing them to view is done 
here
}
else if( !empty($this-data) ){ // this is the post data, but 
we are
redirecting it to search
$url = $model.'/search/key:value';
$this-redirect($url, null, true);
}
}

On Aug 21, 4:09 pm, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 Check out this 
 thread:http://groups.google.com/group/cake-php/browse_thread/thread/d1c13c93...

 A few posts down there is a suggestion to POST the search to a proxy
 function which assembles a clean url and redirects to the real
 function. I am not aware of any cleaner way of doing it works fine in
 the cases I have used this technique.

 /Martin

 On Aug 21, 2:10 pm, bitkidoku [EMAIL PROTECTED] wrote:

  Hello everyone,

  I am implementing a search form. But I want to make search results
  linkable like: http://somehost/products/search/keyword; (keyword is
  the word that is being searched).

  What is the best practise to achieve this? And what if the user could
  search defining many parameters like title, content, ingredients etc.?

  I googled this but I couldn't find any meaningful results.

  Thank you very much for your answers.
--~--~-~--~~~---~--~~
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: Model-find() using group parameter

2008-08-21 Thread bitkidoku

right, thank you.

On Aug 20, 5:37 pm, teknoid [EMAIL PROTECTED] wrote:
 It's a feature, find('list') is usually done to build options for a
 select box.

 On Aug 20, 8:39 am, bitkidoku [EMAIL PROTECTED] wrote:

  What about using 'list' instead of 'all', it is failing:

  $this-Production-find('list', array('fields' = 'DISTINCT
  supplier'));

  CakePHP is trying to fetch Product.id as well. Is this a feature or a
  bug? :)

  On Aug 20, 3:12 pm, Amit Badkas [EMAIL PROTECTED] wrote:

   2008/8/20 Amit Badkas [EMAIL PROTECTED]

2008/8/20 bitkidoku [EMAIL PROTECTED]

Hello everyone,

I am using CakePHP to build an application that will run on en
existing database. The problem I am facing is simple, I have products
table and let's say it is like this: id, name, supplier

Some stupid programmer (yes I am angry to him) didn't created the
table with supplier_id. So every time a product is being added
supplier field must be entered manually. This is not my problem. What
I want to do is to retrieve all the unique supplier names.

- To get unique suppliers, run query, SELECT DISTINCT supplier FROM
products

   - Or using cake, $this-Production-find('all', array('fields' = 
   'DISTINCT
   supplier'));

I tried:

$this-Product-find(
       'all',
       array(
               'fields' = array('Product.supplier'),
               'group' = 'Product.supplier'
       )
);

It does not work. When I query the database manually using SELECT
supplier FROM table GROUP BY supplier it works.

Thank you very much for your answers.

   --
   Amit

  http://amitrb.wordpress.com/http://coppermine-gallery.net/http://chee...
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Clean urls in search form

2008-08-21 Thread bitkidoku

Hello everyone,

I am implementing a search form. But I want to make search results
linkable like: http://somehost/products/search/keyword; (keyword is
the word that is being searched).

What is the best practise to achieve this? And what if the user could
search defining many parameters like title, content, ingredients etc.?

I googled this but I couldn't find any meaningful results.

Thank you very much for your answers.
--~--~-~--~~~---~--~~
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: Clean urls in search form

2008-08-21 Thread bitkidoku

Thanks for the answers. I will look into it and write the results here
to share with everyone.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Model-find() using group parameter

2008-08-20 Thread bitkidoku

Hello everyone,

I am using CakePHP to build an application that will run on en
existing database. The problem I am facing is simple, I have products
table and let's say it is like this: id, name, supplier

Some stupid programmer (yes I am angry to him) didn't created the
table with supplier_id. So every time a product is being added
supplier field must be entered manually. This is not my problem. What
I want to do is to retrieve all the unique supplier names.

I tried:

$this-Product-find(
'all',
array(
'fields' = array('Product.supplier'),
'group' = 'Product.supplier'
)
);

It does not work. When I query the database manually using SELECT
supplier FROM table GROUP BY supplier it works.

Thank you very much for your answers.
--~--~-~--~~~---~--~~
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: Model-find() using group parameter

2008-08-20 Thread bitkidoku

Oh, I just got here to reply my own question, and there are two
answers already. Thanks for the answer!

On Aug 20, 3:12 pm, Amit Badkas [EMAIL PROTECTED] wrote:
 2008/8/20 Amit Badkas [EMAIL PROTECTED]





  2008/8/20 bitkidoku [EMAIL PROTECTED]

  Hello everyone,

  I am using CakePHP to build an application that will run on en
  existing database. The problem I am facing is simple, I have products
  table and let's say it is like this: id, name, supplier

  Some stupid programmer (yes I am angry to him) didn't created the
  table with supplier_id. So every time a product is being added
  supplier field must be entered manually. This is not my problem. What
  I want to do is to retrieve all the unique supplier names.

  - To get unique suppliers, run query, SELECT DISTINCT supplier FROM
  products

 - Or using cake, $this-Production-find('all', array('fields' = 'DISTINCT
 supplier'));





  I tried:

  $this-Product-find(
         'all',
         array(
                 'fields' = array('Product.supplier'),
                 'group' = 'Product.supplier'
         )
  );

  It does not work. When I query the database manually using SELECT
  supplier FROM table GROUP BY supplier it works.

  Thank you very much for your answers.

 --
 Amit

 http://amitrb.wordpress.com/http://coppermine-gallery.net/http://cheesecake-photoblog.org/http://www.sanisoft.com/blog/author/amitbadkas
--~--~-~--~~~---~--~~
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: Model-find() using group parameter

2008-08-20 Thread bitkidoku

What about using 'list' instead of 'all', it is failing:

$this-Production-find('list', array('fields' = 'DISTINCT
supplier'));

CakePHP is trying to fetch Product.id as well. Is this a feature or a
bug? :)

On Aug 20, 3:12 pm, Amit Badkas [EMAIL PROTECTED] wrote:
 2008/8/20 Amit Badkas [EMAIL PROTECTED]





  2008/8/20 bitkidoku [EMAIL PROTECTED]

  Hello everyone,

  I am using CakePHP to build an application that will run on en
  existing database. The problem I am facing is simple, I have products
  table and let's say it is like this: id, name, supplier

  Some stupid programmer (yes I am angry to him) didn't created the
  table with supplier_id. So every time a product is being added
  supplier field must be entered manually. This is not my problem. What
  I want to do is to retrieve all the unique supplier names.

  - To get unique suppliers, run query, SELECT DISTINCT supplier FROM
  products

 - Or using cake, $this-Production-find('all', array('fields' = 'DISTINCT
 supplier'));





  I tried:

  $this-Product-find(
         'all',
         array(
                 'fields' = array('Product.supplier'),
                 'group' = 'Product.supplier'
         )
  );

  It does not work. When I query the database manually using SELECT
  supplier FROM table GROUP BY supplier it works.

  Thank you very much for your answers.

 --
 Amit

 http://amitrb.wordpress.com/http://coppermine-gallery.net/http://cheesecake-photoblog.org/http://www.sanisoft.com/blog/author/amitbadkas
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



hasMany relation and retrieving data

2008-07-23 Thread bitkidoku

Hi everyone,
I have a question about using find() and retrieving some data.
Let's say I have two models Product and Category. Product belongsTo
Category, Category hasMany Product. I am using $this-Category-
find('all'); to retrieve every category and related products. But
there are some categories that does not contain any products. I don't
want to retrieve them. I can handle this on the view, but that doesn't
feel right. Is there a way to achieve this on controller side?

Thanks for your answers.
--~--~-~--~~~---~--~~
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-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 -
  ?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

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

Re: MSSQL ntext problem

2008-07-11 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.

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

Re: Translate behaviour documentation

2008-07-11 Thread bitkidoku

I have the same problem, I think it is missing. I am trying to solve
the mystery from the API reference, which is not very easy.

On Jul 9, 4:05 pm, boyracerr [EMAIL PROTECTED] wrote:
 I've been searching using whatever terms I can think of, and I can't
 find anything about the use of the Translate behaviour to create
 multilingual sites (ie, where dynamic content can be in different
 languages). Could anybody provide some links to information on this
 please?

 Thanks,
 Ben
--~--~-~--~~~---~--~~
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-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 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

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