/** * Delete any existing settings from the database. Done inside a transaction * while saving new settings. * * @return void */ public function deleteCurrentSettings() { $this->dbAdapter->delete('dewdrop_field_groups', $this->dbAdapter->quoteInto('dewdrop_field_group_id IN ( SELECT dewdrop_field_group_id FROM dewdrop_sorted_fields WHERE component = ? )', $this->componentName)); $this->dbAdapter->delete('dewdrop_sorted_fields', $this->dbAdapter->quoteInto('component = ?', $this->componentName)); }
/** * Assemble WHERE clause for for finding a row by its primary key. * * @param array $args The primary key values * @return string */ public function assembleFindWhere(array $args) { $pkey = $this->getPrimaryKey(); foreach ($pkey as $index => $column) { if (!isset($args[$index])) { $pkeyColumnCount = count($pkey); throw new Exception("Db\\Table: You must specify a value for all {$pkeyColumnCount} primary key columns"); } $where[] = $this->db->quoteInto($this->db->quoteIdentifier($column) . ' = ?', $args[$index]); } return implode(' AND ', $where); }
/** * Returns an associative array containing all the unique constraints on a table. * * The array has the following format: * * <pre> * array( * 'key_name' => array( * sequence_in_index => 'column_name' * ) * ) * </pre> * * @param string $tableName * @return array */ public function listUniqueConstraints($tableName) { $sql = "SELECT\n co.oid,\n a.attname\n FROM pg_constraint co\n JOIN pg_class cl ON cl.oid = co.conrelid\n JOIN pg_namespace n ON cl.relnamespace = n.oid\n JOIN pg_attribute a ON a.attrelid = cl.oid\n WHERE\n cl.relname = ?\n AND co.contype = 'u'\n AND a.attnum = ANY(co.conkey)"; $sql = $this->adapter->quoteInto($sql, $tableName); $sql .= ' ORDER BY co.oid, a.attname'; $result = $this->fetchAll($sql, array(), Adapter::ARRAY_A); $constraints = array(); foreach ($result as $row) { if (!array_key_exists($row['oid'], $constraints)) { $constraints[$row['oid']] = array(); } $constraints[$row['oid']][] = $row['attname']; } return $constraints; }
/** * Internal function for creating the where clause * * @param string $condition * @param mixed $value optional * @param string $type optional * @param boolean $bool true = AND, false = OR * @return string clause */ protected function whereInternal($condition, $value = null, $type = null, $bool = true) { if (count($this->parts[self::UNION])) { throw new SelectException("Invalid use of where clause with " . self::SQL_UNION); } if ($value !== null) { $condition = $this->adapter->quoteInto($condition, $value, $type); } $cond = ""; if ($this->parts[self::WHERE]) { if ($bool === true) { $cond = self::SQL_AND . ' '; } else { $cond = self::SQL_OR . ' '; } } return $cond . "({$condition})"; }
/** * While saving, delete existing values. If the new values will be limited to the * logged-in user, we only delete any settings specific to that user. Otherwise, * we also delete any current values not specific to a user. * * @param boolean $applyToAllUsers */ protected function deleteExistingValuesForSave($applyToAllUsers) { $where = $this->dbAdapter->quoteInto('component = ?', $this->componentName); $references = $this->getUserReferenceValues(); // We always delete per-user settings foreach ($references as $column => $value) { $where .= $this->dbAdapter->quoteInto(sprintf(' AND %s = ?', $this->dbAdapter->quoteIdentifier($column)), $value); } $this->dbAdapter->delete($this->dbTableName, $where); // If applying settings to all users, we _also_ delete the current global settings if ($applyToAllUsers) { $where = $this->dbAdapter->quoteInto('component = ?', $this->componentName); foreach ($references as $column => $value) { $where .= sprintf(' AND %s IS NULL', $this->dbAdapter->quoteIdentifier($column)); } $this->dbAdapter->delete($this->dbTableName, $where); } }
/** * Build a WHERE clause for use in deleting cross-reference values while * saving. If we have no cross-reference values, we delete all cross-reference * rows with the given anchor value. Otherwise, we only delete those rows * that are not related to the newly supplied $xrefValues. * * @param DbAdapter $db * @param array $xrefValues * @param mixed $anchorValue * @return string */ private function buildDeleteWhereClause(DbAdapter $db, array $xrefValues, $anchorValue) { $anchorName = $db->quoteIdentifier("{$this->xrefTableName}.{$this->getXrefAnchorColumnName()}"); if (!count($xrefValues) || $this->allowDuplicateValues) { $where = "{$anchorName} = ?"; $where = $db->quoteInto($where, $anchorValue); } else { $refName = $db->quoteIdentifier("{$this->xrefTableName}.{$this->getXrefReferenceColumnName()}"); $where = "{$anchorName} = ? AND {$refName} NOT IN (?)"; $where = $db->quoteInto($where, $anchorValue, null, 1); $where = $db->quoteInto($where, $xrefValues, null, 1); } return $where; }