public function testInsertSucceedsWithExprValue() { $this->db->insert('dewdrop_test_fruits', array('name' => 'Kiwi', 'is_delicious' => 1, 'level_of_deliciousness' => new Expr(5))); $this->assertEquals(6, $this->db->lastInsertId()); $this->assertEquals(5, $this->db->fetchOne('SELECT level_of_deliciousness FROM dewdrop_test_fruits WHERE dewdrop_test_fruit_id = 6')); }
/** * Save the user's visible field selections back to the database. We expect * the selections array to just contain field IDs. Only those that match * IDs of fields in the supplied Fields object will be saved. * * @param Fields $fields * @param array $selections * @param boolean $applyToAllUsers * @return void */ public function save(Fields $fields, array $selections, $applyToAllUsers = false) { $visibleFields = []; foreach ($selections as $id) { if ($fields->has($id)) { $visibleFields[] = $id; } } if (count($visibleFields)) { $this->dbAdapter->beginTransaction(); $this->deleteExistingValuesForSave($applyToAllUsers); foreach ($visibleFields as $visibleFieldId) { $data = ['component' => $this->componentName, 'field_id' => $visibleFieldId]; if (!$applyToAllUsers) { foreach ($this->getUserReferenceValues() as $column => $value) { $data[$column] = $value; } } $this->dbAdapter->insert($this->dbTableName, $data); } $this->dbAdapter->commit(); // Reset selections so they'll be loaded again when filter is re-applied $this->selections = null; } }
/** * Log the execution of a SQL script to the changelog table. The * $startTime and $endTime params should be supplied in ISO format * (i.e. yyyy-mm-dd hh:mm:ss). The $file param should be the full * path to the file, not just the base file name. * * @param string $changesetName * @param int $number * @param string $file * @param string $appliedBy * @param string $startTime * @param string $endTime * @return int */ public function logAppliedFile($changesetName, $number, $file, $appliedBy, $startTime, $endTime) { if (!$this->tableExists()) { $this->createTable(); } return $this->dbAdapter->insert($this->tableName, array('delta_set' => $changesetName, 'change_number' => $number, 'description' => $file, 'applied_by' => $appliedBy, 'start_dt' => $startTime, 'complete_dt' => $endTime)); }
/** * Insert a new row. * * Data should be supplied as key value pairs, with the keys representing * the column names. * * We return the ID of the inserted row because if we do not return it from * insert(), it will be impossible to retrieve it, if we have many-to-many * or EAV fields that also inserted rows before this method returns. * * @param array $data * @return integer|null Last insert ID, if the table has auto-incrementing key. */ public function insert(array $data) { $this->db->insert($this->tableName, $this->augmentInsertedDataArrayWithWhenAndByWhom($this->filterDataArrayForPhysicalColumns($data))); $result = null; foreach ($this->getMetadata('columns') as $column => $metadata) { if ($metadata['IDENTITY'] && $metadata['PRIMARY']) { $result = $this->getAdapter()->lastInsertId(); break; } } $this->saveManyToManyRelationships($data, $result)->saveEav($data, $result); return $result; }
/** * Save the fields to the DB using the supplied group ID, which can be null * in the case of un-grouped fields. * * @param array $fields * @param integer $groupId * @return void */ protected function saveFields(array $fields, $groupId) { foreach ($fields as $index => $field) { $this->dbAdapter->insert('dewdrop_sorted_fields', array('component' => $this->componentName, 'field_id' => $field['id'], 'sort_index' => $index, 'dewdrop_field_group_id' => $groupId)); } }