function testAddFieldWithoutValueOnlyReservesAPlaceholder()
 {
     $query = new lmbInsertOnDuplicateUpdateQuery('test_db_table', $this->conn);
     $query->addField('description');
     $query->addField('title');
     $stmt = $query->getStatement();
     $stmt->set('description', $description = 'Some \'description\'');
     $stmt->set('title', $title = 'Some title');
     $stmt->execute();
     $rs = $this->db->select('test_db_table');
     $arr = $rs->getArray();
     $this->assertEqual(sizeof($arr), 1);
     $this->assertEqual($arr[0]['description'], $description);
     $this->assertEqual($arr[0]['title'], $title);
 }
 function testInsertOnDuplicateKeyUpdate()
 {
     $current_connection = lmbToolkit::instance()->getDefaultDbConnection();
     $is_supported = lmbInsertOnDuplicateUpdateQuery::isSupportedByDbConnection($current_connection);
     if (!$is_supported) {
         echo "Skip: " . $current_connection->getType() . " not support insert on duplicate update queries \n";
         return;
     }
     $id = $this->db_table_test->insertOnDuplicateUpdate(array('title' => 'wow', 'description' => 'wow!', 'junk!!!' => 'junk!!!'));
     $stmt = $this->conn->newStatement("SELECT * FROM test_db_table");
     $record = $stmt->getOneRecord();
     $this->assertEqual($record->get('title'), 'wow');
     $this->assertEqual($record->get('description'), 'wow!');
     $this->assertEqual($record->get('id'), $id);
     $id = $this->db_table_test->insertOnDuplicateUpdate(array('id' => $id, 'title' => 'wow', 'description' => 'new wow!', 'junk!!!' => 'junk!!!'));
     $stmt = $this->conn->newStatement("SELECT * FROM test_db_table");
     $record = $stmt->getOneRecord();
     $this->assertEqual($record->get('title'), 'wow');
     $this->assertEqual($record->get('description'), 'new wow!');
     $this->assertEqual($record->get('id'), $id);
 }
 function insertOnDuplicateUpdate($row)
 {
     $filtered_row = $this->_filterRow($row);
     if (!count($filtered_row)) {
         throw new lmbException('All fields filtered!! Insert statement must contain atleast one field!');
     }
     $query = new lmbInsertOnDuplicateUpdateQuery($this->_db_table_name, $this->_conn);
     $values = array();
     $update_sequence = false;
     foreach ($filtered_row as $key => $value) {
         if (is_null($value) && $this->isAutoIncrement($key)) {
             continue;
         }
         $query->addField($key);
         $values[$key] = $value;
     }
     $this->_stmt = $query->getStatement($this->_conn);
     $this->_bindValuesToStatement($this->_stmt, $values);
     return (int) $this->_stmt->insertId($this->_primary_key_name);
 }