Re: Improvement suggested for the CakeTestFixture class. Keywords: $records crashes when using non-uniform columns; simpletest

2010-08-23 Thread BlueDuck
Yeah, I know.  Here's the issue.  Sometimes a table has 20 columns in
it.  One test might only use 2 columns across 3 users.  Another test
might use a different set of columns across other users.  With the
current cake_test_fixture code, every record has to contain the exact
same column set or else the multiinsert crashes.  Adding 18 null
fields for every records is a lot of typing.  And as I expand my test
suite, or add columns to my table, I don't want to have to go back
over all of my unit test sample records and add those columns in.  It
just increases the maintenance and makes it less likely that I'll
actually build the right tests.  You might be wondering, Why doesn't
he just use a uniform set of records for all his tests? Because these
are unit tests and I like having discrete records that I know no other
test is going to interfere with.  If that costs me some extra inserts
during my testing, I'm okay with that.  I'd rather suffer a small
performance hit on testing than add the maintenance overhead.  That's
the idea. Maybe the best solution here is to add a little bit of code
that builds the complete field set and then adds the null fields to
the records as needed.  Not sure.  I'm using postgres if that makes a
difference.

Also - while I'm at it, I have another issue that I probably haven't
properly solved for.  My sequence start started moving on me.  I was a
bit surprised.  The only thing that seems to fit is that the sequence
is being pulled in from my $default dbconfig instead of starting from
scratch on $test.  So, my fixture would say add record such-and-
such, and I'd assume that it would have id=1 since it was the first
insert.  But it's not predictable, (unless I specify id=1, but then
the dbo driver doesn't increment the sequence and everything crashes
when a primary key conflict comes up).  So I added something like this
to the truncate function so that I could specify the sequence name and
start value after each truncate.  What do you think?

 * Truncates the current fixture. Can be overwritten by classes
extending CakeFixture to trigger other events before / after
 * truncate.
 *
 * @param object $db A reference to a db instance
 * @return boolean
 * @access public
 */
function truncate($db) {
$fullDebug = $db-fullDebug;
$db-fullDebug = false;
$return = $db-truncate($this-table);
if (isset($this-sequenceValue)  isset($this-sequenceName))
{
$db-rawQuery('ALTER SEQUENCE ' . $this-sequenceName . '
START ' . $this-sequenceValue);
}
$db-fullDebug = $fullDebug;
return $return;
}








On Aug 16, 11:47 pm, AD7six andydawso...@gmail.com wrote:
 On Aug 16, 11:27 pm, BlueDuck holliph...@gmail.com wrote:

  It drives me absolutely batty that all the $records have to have the
  same columns or else themultiinsertfails.  

 Under what circumstances do rows in the same table have a different
 schema?

  Not sure if this is
  really the most optimal code here, but this change in /var/www/
  wednesdays/cake/tests/lib/cake_test_fixture.php in the insert function
  did the trick.  I'd suggest that someone do a little optimization and
  consider for the next release.

 The optimization is quite simply to not apply your suggested
 change :)



   Also - no need to publish this post if
  there you can route to the right place.

  Essentially, I move themultiinsertinto the loop so that the field
  list for each record is used instead of the field list from just the
  last record.

      function insert($db) {
          if (!isset($this-_insert)) {
              $values = array();

              if (isset($this-records)  !empty($this-records)) {
                  foreach ($this-records as $record) {
                      $fields = array_keys($record);
                      $values[0] = '(' . implode(', ', array_map(array(
  $db, 'value'), array_values($record))) . ')';
                      $result = $db-insertMulti($this-table, $fields,
  $values);
                      if ($result === false) return false;
                  }
              }
              return true;
          }
      }

 In doing that you've changed e.g. an insert with 500 items into 500
 individual inserts. Here's a 
 referencehttp://dev.mysql.com/doc/refman/5.1/en/insert.html

 The why you want to do this might yield a different and more useful
 bit of info.

 hth,

 AD

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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: Improvement suggested for the CakeTestFixture class. Keywords: $records crashes when using non-uniform columns; simpletest

2010-08-17 Thread AD7six


On Aug 16, 11:27 pm, BlueDuck holliph...@gmail.com wrote:
 It drives me absolutely batty that all the $records have to have the
 same columns or else the multiinsert fails.  

Under what circumstances do rows in the same table have a different
schema?

 Not sure if this is
 really the most optimal code here, but this change in /var/www/
 wednesdays/cake/tests/lib/cake_test_fixture.php in the insert function
 did the trick.  I'd suggest that someone do a little optimization and
 consider for the next release.

The optimization is quite simply to not apply your suggested
change :)

  Also - no need to publish this post if
 there you can route to the right place.

 Essentially, I move the multiinsert into the loop so that the field
 list for each record is used instead of the field list from just the
 last record.

     function insert($db) {
         if (!isset($this-_insert)) {
             $values = array();

             if (isset($this-records)  !empty($this-records)) {
                 foreach ($this-records as $record) {
                     $fields = array_keys($record);
                     $values[0] = '(' . implode(', ', array_map(array(
 $db, 'value'), array_values($record))) . ')';
                     $result = $db-insertMulti($this-table, $fields,
 $values);
                     if ($result === false) return false;
                 }
             }
             return true;
         }
     }


In doing that you've changed e.g. an insert with 500 items into 500
individual inserts. Here's a reference 
http://dev.mysql.com/doc/refman/5.1/en/insert.html

The why you want to do this might yield a different and more useful
bit of info.

hth,

AD

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Improvement suggested for the CakeTestFixture class. Keywords: $records crashes when using non-uniform columns; simpletest

2010-08-16 Thread BlueDuck
It drives me absolutely batty that all the $records have to have the
same columns or else the multiinsert fails.  Not sure if this is
really the most optimal code here, but this change in /var/www/
wednesdays/cake/tests/lib/cake_test_fixture.php in the insert function
did the trick.  I'd suggest that someone do a little optimization and
consider for the next release.  Also - no need to publish this post if
there you can route to the right place.

Essentially, I move the multiinsert into the loop so that the field
list for each record is used instead of the field list from just the
last record.

function insert($db) {
if (!isset($this-_insert)) {
$values = array();

if (isset($this-records)  !empty($this-records)) {
foreach ($this-records as $record) {
$fields = array_keys($record);
$values[0] = '(' . implode(', ', array_map(array(
$db, 'value'), array_values($record))) . ')';
$result = $db-insertMulti($this-table, $fields,
$values);
if ($result === false) return false;
}
}
return true;
}
}

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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