Permalink
Browse files

PDO Adapter: Fixed critical bug where empty or null values could resu…

…lt in invalid SQL query syntax with more columns referenced than are bound
  • Loading branch information...
1 parent dfa5f24 commit 817aa7a630406055ad57a363f6e03268f5c012a7 @vlucas committed Feb 11, 2010
Showing with 17 additions and 1 deletion.
  1. +1 −1 Adapter/PDO.php
  2. +16 −0 tests/CRUDTest.php
View
@@ -523,7 +523,7 @@ public function statementBinds(array $conditions = array())
}
foreach($subConditions as $column => $value) {
// Can't bind array of values
- if(is_string($value)) {
+ if(!is_array($value) && !is_object($value)) {
// Column name with comparison operator
list($col) = explode(' ', $column);
$colParam = str_replace('.', '_', $col) . $ci;
View
@@ -42,6 +42,22 @@ public function testSampleNewsInsert()
$this->assertTrue(is_numeric($result));
}
+ public function testSampleNewsInsertWithEmpyNonRequiredFields()
+ {
+ $mapper = $this->blogMapper;
+ $post = $mapper->get();
+ $post->title = "Test Post With Empty Values";
+ $post->body = "<p>Test post here.</p>";
+ $post->date_created = null;
+ try {
+ $result = $mapper->insert($post); // returns an id
+ } catch(Exception $e) {
+ $mapper->debug();
+ }
+
+ $this->assertTrue(is_numeric($result));
+ }
+
public function testSampleNewsUpdate()
{
$mapper = $this->blogMapper;

0 comments on commit 817aa7a

Please sign in to comment.