diff --git a/RedBeanPHP/Facade.php b/RedBeanPHP/Facade.php index a6b03829f..21408e278 100755 --- a/RedBeanPHP/Facade.php +++ b/RedBeanPHP/Facade.php @@ -619,10 +619,10 @@ public static function store( $bean, $unfreezeIfNeeded = FALSE ) $result = self::$redbean->store( $bean ); } catch (SQLException $exception) { $wasFrozen = self::$redbean->isFrozen(); - if ( !self::$allowHybridMode || !$wasFrozen ) throw $exception; + if ( !self::$allowHybridMode || !$unfreezeIfNeeded ) throw $exception; self::freeze( FALSE ); $result = self::$redbean->store( $bean ); - self::freeze( !$wasFrozen ); + self::freeze( $wasFrozen ); } return $result; } diff --git a/testing/RedUNIT/Base/Hybrid.php b/testing/RedUNIT/Base/Hybrid.php index f6630b5e7..1b230139c 100644 --- a/testing/RedUNIT/Base/Hybrid.php +++ b/testing/RedUNIT/Base/Hybrid.php @@ -37,7 +37,13 @@ public function testHybrid() R::setAllowHybridMode( FALSE ); $book->title = 'Tales of a misfit'; try { - R::store( $book ); + R::store( $book, TRUE ); + fail(); + } catch(\Exception $e) { + pass(); + } + try { + R::store( $book, FALSE ); fail(); } catch(\Exception $e) { pass(); @@ -48,6 +54,18 @@ public function testHybrid() $book->title = 'Tales of a misfit'; try { R::store( $book ); + fail(); + } catch(\Exception $e) { + pass(); + } + try { + R::store( $book, FALSE ); + fail(); + } catch(\Exception $e) { + pass(); + } + try { + R::store( $book, TRUE ); pass(); } catch(\Exception $e) { fail(); @@ -71,24 +89,28 @@ public function testHybridDataType() if ($this->currentlyActiveDriverID == 'sqlite') return; $book = R::dispense('book'); $book->pages = 1; - $id = R::store( $book ); + $id = R::store( $book, TRUE ); R::freeze( TRUE ); + asrt( R::getRedBean()->isFrozen(), TRUE ); R::setAllowHybridMode( FALSE ); $book->pages = 'too many'; try { - R::store( $book ); + R::store( $book, TRUE ); fail(); } catch(\Exception $e) { pass(); } + asrt( R::getRedBean()->isFrozen(), TRUE ); R::setAllowHybridMode( TRUE ); + asrt( R::getRedBean()->isFrozen(), TRUE ); R::debug(1); try { - R::store( $book ); + R::store( $book, TRUE ); pass(); } catch(\Exception $e) { fail(); } + asrt( R::getRedBean()->isFrozen(), TRUE ); $book = $book->fresh(); echo $book; asrt( $book->pages, 'too many' ); @@ -109,7 +131,7 @@ public function testHybridNonSQLException() R::freeze( TRUE ); R::setAllowHybridMode( TRUE ); try { - R::store( $toy ); + R::store( $toy, TRUE ); fail(); } catch(\Exception $e) { pass(); @@ -120,7 +142,7 @@ public function testHybridNonSQLException() R::freeze( TRUE ); R::setAllowHybridMode( TRUE ); try { - R::store( $toy ); + R::store( $toy, TRUE ); pass(); } catch(\Exception $e) { fail();