function testAddFieldWithoutValueOnlyReservesAPlaceholder() { $query = new lmbInsertQuery('test_db_table', $this->conn); //$query->addField('id'); $query->addField('description'); $query->addField('title'); $stmt = $query->getStatement(); //$stmt->set('id', $id = 101); $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]['id'], $id); $this->assertEqual($arr[0]['description'], $description); $this->assertEqual($arr[0]['title'], $title); }
function insert($table, $values, $primary_key = 'id') { $query = new lmbInsertQuery($table, $this->conn); foreach ($values as $key => $value) { $query->addField($key, $value); } $stmt = $query->getStatement($this->conn); if ($primary_key) { if (isset($values[$primary_key])) { $stmt->execute(); return $values[$primary_key]; } else { return $stmt->insertId($primary_key); } } else { $stmt->execute(); } }
function _insertNewIndexRecord($uri, $content, $title) { $query = new lmbInsertQuery(FULL_TEXT_SEARCH_INDEXER_TABLE, $this->conn); $query->addField('uri', $uri->toString()); $query->addField('content', $content); $query->addField('last_modified', time()); $query->addField('title', $title); $stmt = $query->getStatement(); return $stmt->insertId('id'); }
function insert($row) { $filtered_row = $this->_filterRow($row); if (!count($filtered_row)) { throw new lmbException('All fields filtered! Insert statement must contain atleast one field!', array('table' => $this->_db_table_name, 'raw' => $row)); } $query = new lmbInsertQuery($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); }