Re: Tinyints cause big problems

2009-06-02 Thread AD7six



On Jun 2, 4:22 am, Miles J mileswjohn...@gmail.com wrote:
 Tinyints do not work in CakePHP, you must use smallint.
only tinyint(1) is considered a boolean by cake.

anything else (tinyint(2)) is what it says it is.

AD
--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Tinyints cause big problems

2009-06-01 Thread adallas

I just tracked a bug through Cake's Model code (specifically, model/
datasources/dbo_source.php). I was shocked at how small the scope of
the problem turned out to be.

My find('all'...) included a condition, Model.fld = 3. The results
were wrong and after some wasted time, I saw that the generated SQL
included Model.fld = 1. Cake wasn't just adding some identity
condition; or if it was, it was throwing my condition away. It's a
complicated model (Model, in this case, has 9 associations). I assumed
it had something to do with that, but it did not.

Cake thinks that Tinyints are booleans. Cake parses and reconstructs
your conditional phrases. Put those two facts together, and you see
that Model.fld = 0 will work. Model.fld = 1 will work.  Model.fld = 2
will morph into Model.fld = 3.

One solution is to use ints instead of tinyints. Ints take 4 bytes per
record, tinyints take 1. I can't bring myself to waste the space
without a good reason. I suppose that's the Cake way--if you'll be
treating the field like an ordinary int, use an ordinary int type.

The solution I used was the result of carefully plodding through the
dbo_source code--I override Model::getColumnType(). You can force any
type for a given key. The code is:

public function getColumnType($key)
{
if ($key == 'MyModel.fld') {
return 'integer';   // not 'int'
}
return parent::getColumnType($key);
}

I hope it helps someone avoid some debugging.

/alastair/

--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Tinyints cause big problems

2009-06-01 Thread Larry E. Masters aka PhpNut
I know this is documented and it is part of the CakePHP conventions.
Maybe it is time to upgrade your 1.44 floppy to something like a zip drive?

-- 
/**
* @author Larry E. Masters
* @var string $userName
* @param string $realName
* @returns string aka PhpNut
* @access  public
*/

On Mon, Jun 1, 2009 at 5:49 PM, adallas alastair.dal...@gmail.com wrote:


 I just tracked a bug through Cake's Model code (specifically, model/
 datasources/dbo_source.php). I was shocked at how small the scope of
 the problem turned out to be.

 My find('all'...) included a condition, Model.fld = 3. The results
 were wrong and after some wasted time, I saw that the generated SQL
 included Model.fld = 1. Cake wasn't just adding some identity
 condition; or if it was, it was throwing my condition away. It's a
 complicated model (Model, in this case, has 9 associations). I assumed
 it had something to do with that, but it did not.

 Cake thinks that Tinyints are booleans. Cake parses and reconstructs
 your conditional phrases. Put those two facts together, and you see
 that Model.fld = 0 will work. Model.fld = 1 will work.  Model.fld = 2
 will morph into Model.fld = 3.

 One solution is to use ints instead of tinyints. Ints take 4 bytes per
 record, tinyints take 1. I can't bring myself to waste the space
 without a good reason. I suppose that's the Cake way--if you'll be
 treating the field like an ordinary int, use an ordinary int type.

 The solution I used was the result of carefully plodding through the
 dbo_source code--I override Model::getColumnType(). You can force any
 type for a given key. The code is:

public function getColumnType($key)
{
if ($key == 'MyModel.fld') {
return 'integer';   // not 'int'
}
return parent::getColumnType($key);
}

 I hope it helps someone avoid some debugging.

 /alastair/

 

--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Tinyints cause big problems

2009-06-01 Thread Mark

@larry:
that was a good one :)

i dont think adallas will get very far with his special disk-space-
saving-techniques...


On 2 Jun., 01:09, Larry E. Masters aka PhpNut php...@gmail.com
wrote:
 I know this is documented and it is part of the CakePHP conventions.
 Maybe it is time to upgrade your 1.44 floppy to something like a zip drive?

 --
 /**
 * @author Larry E. Masters
 * @var string $userName
 * @param string $realName
 * @returns string aka PhpNut
 * @access  public
 */

 On Mon, Jun 1, 2009 at 5:49 PM, adallas alastair.dal...@gmail.com wrote:

  I just tracked a bug through Cake's Model code (specifically, model/
  datasources/dbo_source.php). I was shocked at how small the scope of
  the problem turned out to be.

  My find('all'...) included a condition, Model.fld = 3. The results
  were wrong and after some wasted time, I saw that the generated SQL
  included Model.fld = 1. Cake wasn't just adding some identity
  condition; or if it was, it was throwing my condition away. It's a
  complicated model (Model, in this case, has 9 associations). I assumed
  it had something to do with that, but it did not.

  Cake thinks that Tinyints are booleans. Cake parses and reconstructs
  your conditional phrases. Put those two facts together, and you see
  that Model.fld = 0 will work. Model.fld = 1 will work.  Model.fld = 2
  will morph into Model.fld = 3.

  One solution is to use ints instead of tinyints. Ints take 4 bytes per
  record, tinyints take 1. I can't bring myself to waste the space
  without a good reason. I suppose that's the Cake way--if you'll be
  treating the field like an ordinary int, use an ordinary int type.

  The solution I used was the result of carefully plodding through the
  dbo_source code--I override Model::getColumnType(). You can force any
  type for a given key. The code is:

         public function getColumnType($key)
         {
                 if ($key == 'MyModel.fld') {
                         return 'integer';           // not 'int'
                 }
                 return parent::getColumnType($key);
         }

  I hope it helps someone avoid some debugging.

  /alastair/
--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Tinyints cause big problems

2009-06-01 Thread Miles J

Tinyints do not work in CakePHP, you must use smallint.
--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Tinyints cause big problems

2009-06-01 Thread adallas

Ok. Trying to save some bytes is old school. But I know this is
documented? Why waste the time typing it if you can't cite a source?
Where is it documented, and for that matter where are these imaginary
CakePHP conventions documented?

The cookbook mentions tinyint only the context of forms. The api is
silent. Golding (Beginning CakePHP) and Chan/Omokore (Practical
CakePHP Projects) don't have tinyint in their indexes.

You might have been referring to trac ticket #1253, which described
the bug I ran into. It was written up three years ago, in some detail,
but was promptly closed by Nate, who wrote Cake interprets MySQL
tinyint(1) fields as virtual boolean fields, which can only have a
value of 0 or 1 (true or false). Use a different column type if you
don't want this behavior. In March 2008, another user tripped on the
same problem and wrote ticket #3903. Nate closed that, too. Google
'cakephp tinyint'--4,120 hits, many of them developer blogs trying to
help others over this speed bump.

I'm fairly new to Cake. Do I need to comb through the set of things
that real users thought were bugs to find the pearls of wisdom by
which the Cake developers explained their disinterest in fixing them?
Seriously, is this what you meant when you said you knew this was
documented?

Thanks, Mark and Larry, for welcoming me to Cake land.

/alastair/

On Jun 1, 4:09 pm, Larry E. Masters aka PhpNut php...@gmail.com
wrote:
 I know this is documented and it is part of the CakePHP conventions.
 Maybe it is time to upgrade your 1.44 floppy to something like a zip drive?

 --
 /**
 * @author Larry E. Masters
 * @var string $userName
 * @param string $realName
 * @returns string aka PhpNut
 * @access  public
 */

 On Mon, Jun 1, 2009 at 5:49 PM, adallas alastair.dal...@gmail.com wrote:

  I just tracked a bug through Cake's Model code (specifically, model/
  datasources/dbo_source.php). I was shocked at how small the scope of
  the problem turned out to be.

  My find('all'...) included a condition, Model.fld = 3. The results
  were wrong and after some wasted time, I saw that the generated SQL
  included Model.fld = 1. Cake wasn't just adding some identity
  condition; or if it was, it was throwing my condition away. It's a
  complicated model (Model, in this case, has 9 associations). I assumed
  it had something to do with that, but it did not.

  Cake thinks that Tinyints are booleans. Cake parses and reconstructs
  your conditional phrases. Put those two facts together, and you see
  that Model.fld = 0 will work. Model.fld = 1 will work.  Model.fld = 2
  will morph into Model.fld = 3.

  One solution is to use ints instead of tinyints. Ints take 4 bytes per
  record, tinyints take 1. I can't bring myself to waste the space
  without a good reason. I suppose that's the Cake way--if you'll be
  treating the field like an ordinary int, use an ordinary int type.

  The solution I used was the result of carefully plodding through the
  dbo_source code--I override Model::getColumnType(). You can force any
  type for a given key. The code is:

         public function getColumnType($key)
         {
                 if ($key == 'MyModel.fld') {
                         return 'integer';           // not 'int'
                 }
                 return parent::getColumnType($key);
         }

  I hope it helps someone avoid some debugging.

  /alastair/
--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Tinyints cause big problems

2009-06-01 Thread Larry E. Masters aka PhpNut
 Ok. Trying to save some bytes is old school. But I know this is
 documented? Why waste the time typing it if you can't cite a source?
 Where is it documented, and for that matter where are these imaginary
 CakePHP conventions documented?



http://book.cakephp.org/view/68/Creating-Database-Tables

-- 
/**
* @author Larry E. Masters
* @var string $userName
* @param string $realName
* @returns string aka PhpNut
* @access  public
*/




 The cookbook mentions tinyint only the context of forms. The api is
 silent. Golding (Beginning CakePHP) and Chan/Omokore (Practical
 CakePHP Projects) don't have tinyint in their indexes.

 You might have been referring to trac ticket #1253, which described
 the bug I ran into. It was written up three years ago, in some detail,
 but was promptly closed by Nate, who wrote Cake interprets MySQL
 tinyint(1) fields as virtual boolean fields, which can only have a
 value of 0 or 1 (true or false). Use a different column type if you
 don't want this behavior. In March 2008, another user tripped on the
 same problem and wrote ticket #3903. Nate closed that, too. Google
 'cakephp tinyint'--4,120 hits, many of them developer blogs trying to
 help others over this speed bump.

 I'm fairly new to Cake. Do I need to comb through the set of things
 that real users thought were bugs to find the pearls of wisdom by
 which the Cake developers explained their disinterest in fixing them?
 Seriously, is this what you meant when you said you knew this was
 documented?

 Thanks, Mark and Larry, for welcoming me to Cake land.

 /alastair/

 On Jun 1, 4:09 pm, Larry E. Masters aka PhpNut php...@gmail.com
 wrote:
  I know this is documented and it is part of the CakePHP conventions.
  Maybe it is time to upgrade your 1.44 floppy to something like a zip
 drive?
 
  --
  /**
  * @author Larry E. Masters
  * @var string $userName
  * @param string $realName
  * @returns string aka PhpNut
  * @access  public
  */
 
  On Mon, Jun 1, 2009 at 5:49 PM, adallas alastair.dal...@gmail.com
 wrote:
 
   I just tracked a bug through Cake's Model code (specifically, model/
   datasources/dbo_source.php). I was shocked at how small the scope of
   the problem turned out to be.
 
   My find('all'...) included a condition, Model.fld = 3. The results
   were wrong and after some wasted time, I saw that the generated SQL
   included Model.fld = 1. Cake wasn't just adding some identity
   condition; or if it was, it was throwing my condition away. It's a
   complicated model (Model, in this case, has 9 associations). I assumed
   it had something to do with that, but it did not.
 
   Cake thinks that Tinyints are booleans. Cake parses and reconstructs
   your conditional phrases. Put those two facts together, and you see
   that Model.fld = 0 will work. Model.fld = 1 will work.  Model.fld = 2
   will morph into Model.fld = 3.
 
   One solution is to use ints instead of tinyints. Ints take 4 bytes per
   record, tinyints take 1. I can't bring myself to waste the space
   without a good reason. I suppose that's the Cake way--if you'll be
   treating the field like an ordinary int, use an ordinary int type.
 
   The solution I used was the result of carefully plodding through the
   dbo_source code--I override Model::getColumnType(). You can force any
   type for a given key. The code is:
 
  public function getColumnType($key)
  {
  if ($key == 'MyModel.fld') {
  return 'integer';   // not 'int'
  }
  return parent::getColumnType($key);
  }
 
   I hope it helps someone avoid some debugging.
 
   /alastair/
 

--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---