/** * @deprecated 2.0 always use ids only for storage * * @param string $groupName * @return null|string */ public function get_group_id($groupName) { $query = 'SELECT ' . $this->_db->NameQuote('id') . "\n FROM " . $this->_db->NameQuote('#__usergroups') . "\n WHERE " . $this->_db->NameQuote('title') . " = " . $this->_db->Quote($groupName); $this->_db->setQuery($query); $return = $this->_db->loadResult(); return $return; }
/** * Cleans and makes a value SQL safe depending on the type that is enforced. * * @param mixed $fieldValue * @param string $type * @return string */ protected function sqlCleanQuote($fieldValue, $type) { $typeArray = explode(':', $type, 3); if (count($typeArray) < 2) { $typeArray = array('const', $type); } switch ($typeArray[1]) { case 'int': $value = (int) $fieldValue; break; case 'float': $value = (double) $fieldValue; break; case 'formula': $value = $fieldValue; break; case 'field': // this is temporarly handled here $value = $this->_db->NameQuote($fieldValue); break; case 'datetime': if (preg_match('/^[0-9]{4}-[01][0-9]-[0-3][0-9] [0-2][0-9](:[0-5][0-9]){2}$/', $fieldValue)) { $value = $this->_db->Quote($fieldValue); } else { $value = "''"; } break; case 'date': if (preg_match('/^[0-9]{4}-[01][0-9]-[0-3][0-9]$/', $fieldValue)) { $value = $this->_db->Quote($fieldValue); } else { $value = "''"; } break; case 'string': $value = $this->_db->Quote($fieldValue); break; case 'null': if ($fieldValue != 'NULL') { trigger_error(sprintf('CBSQLUpgrader::_sqlCleanQuote: ERROR: field type sql:null has not NULL value')); } $value = 'NULL'; break; default: trigger_error('CBSQLUpgrader::_sqlQuoteValueType: ERROR_UNKNOWN_TYPE: ' . htmlspecialchars($type), E_USER_NOTICE); $value = $this->_db->Quote($fieldValue); // false; break; } return (string) $value; }
/** * Computes a safe WHERE statements as array to implode with ' AND ' or returns FALSE if none. * * @param int|string|array $keys Key-value to use for primary key condition, or array of key => value pairs to match * @param array $tableReferences Table references, e.g. array( $this->_tbl => 'm' ). (Must be SQL-safe) * @param string $defaultTableReference Default table reference, e.g. 'm' (Must be SQL-safe) * @return array|boolean Check for ! empty( $where ) before using the resulting array! * * @throws \UnexpectedValueException * @throws \InvalidArgumentException */ protected function getSafeWhereStatements($keys, $tableReferences = array(), $defaultTableReference = '') { // Determine the keys to use into $keys: $primaryKeysTypes = $this->getPrimaryKeysTypes(); $primaryKeys = array_keys($primaryKeysTypes); if (empty($keys)) { $keys = array(); // If empty, use the value of the current key foreach ($primaryKeys as $key) { if (empty($this->{$key})) { // If empty primary key there's is no need to load/delete anything: return false; } $keys[$key] = $this->{$key}; } } elseif (!is_array($keys)) { if (count($this->getPrimaryKeysTypes()) != 1) { throw new \InvalidArgumentException('Table has multiple primary keys specified (or none), and only one primary key value provided in load().'); } $keys = array($primaryKeys[0] => $keys); } // Determine the WHERE array: $properties = $this->getPublicProperties(); $where = array(); foreach ($keys as $whereField => $whereValue) { if (!in_array($whereField, $properties)) { throw new \UnexpectedValueException(sprintf('Missing where-field %s of load() in class %s.', $whereField, get_class($this))); } if (isset($primaryKeysTypes[$whereField]) && $primaryKeysTypes[$whereField] == 'int' || is_int($whereValue)) { $safeWhereValue = (int) $whereValue; } else { $safeWhereValue = $this->_db->Quote($whereValue); } $tableRefPrefix = isset($tableReferences[$whereField]) ? $tableReferences[$whereField] . '.' : ($defaultTableReference ? $defaultTableReference . '.' : ''); $where[] = $tableRefPrefix . $this->_db->NameQuote($whereField) . ' = ' . $safeWhereValue; } return $where; }
/** * Cleans a scalar $fieldValue to fit $type * * @param mixed $fieldValue * @param string $type * @param DatabaseDriverInterface $db * @return float|int|string */ protected static function cleanScalarType($fieldValue, $type, DatabaseDriverInterface $db) { switch ($type) { case 'int': $value = (int) $fieldValue; break; case 'float': $value = (double) $fieldValue; break; case 'formula': $value = $fieldValue; break; case 'datetime': if (preg_match('/[0-9]{4}-[01][0-9]-[0-3][0-9] [0-2][0-9](:[0-5][0-9]){2}/', $fieldValue)) { $value = $db->Quote($fieldValue); } else { $value = "''"; } break; case 'date': if (preg_match('/[0-9]{4}-[01][0-9]-[0-3][0-9]/', $fieldValue)) { $value = $db->Quote($fieldValue); } else { $value = "''"; } break; case 'time': if (preg_match('/-?[0-9]{1,3}(:[0-5][0-9]){2}/', $fieldValue)) { $value = $db->Quote($fieldValue); } else { $value = "''"; } break; case 'string': $value = $db->Quote($fieldValue); break; case 'null': $value = 'NULL'; break; default: trigger_error('SQLXML::sqlCleanQuote: ERROR_UNKNOWN_TYPE: ' . htmlspecialchars($type), E_USER_NOTICE); $value = $db->Quote($fieldValue); // false; break; } return $value; }