예제 #1
0
 public function testQueryUpdateSqlStringWithCondition()
 {
     $query = new QueryUpdate('MyTable');
     $query->setColumns(array('col1', 'col2'));
     $query->setCondition('col3 > 0');
     $requiredSql = 'UPDATE MyTable SET col1=?,col2=? WHERE col3 > 0';
     $this->assertEquals($query->__toString(), $requiredSql);
 }
예제 #2
0
 public function update($table, $colsAndValues, $condText = null, $condValues = null, $ignoreNulls = true)
 {
     $query = new QueryUpdate($table);
     if ($ignoreNulls) {
         $colsAndValues = array_filter($colsAndValues, 'Utils::is_not_null');
     }
     $query->setColumns(array_keys($colsAndValues))->setCondition($condText);
     $stmt = $this->_db->prepare($query);
     $index = 1;
     foreach ($colsAndValues as $column => $value) {
         $stmt->bindValue($index++, $value);
     }
     // If we have condition parameters to bind
     if ($condText !== null && $condValues !== null) {
         foreach ($condValues as $value) {
             $stmt->bindValue($index++, $value);
         }
     }
     return $stmt->execute();
 }
예제 #3
0
 /**
  * @covers Cradle\Sql\PostGreSql\QueryUpdate::set
  */
 public function testSet()
 {
     $instance = $this->object->set('foo', 'bar');
     $this->assertInstanceOf('Cradle\\Sql\\PostGreSql\\QueryUpdate', $instance);
 }