#3003: SQLite 3 support
----------------------------+-----------------------------------------------
Reporter: sebbarre | Owner: Any Developer
Type: Enhancement | Status: new
Priority: Low | Milestone: 2.0.0.x
Component: General | Version: 2.0.x.x
Severity: Trivial | Resolution:
Keywords: | Php_version: n/a
Cake_version: |
----------------------------+-----------------------------------------------
Comment (by lightglitch):
I think a found a way, I just convert all the fields in the form of * or
Table.* into the model field list. It was the best way I could find and
just needed to override the fields method.
Here is the patch:
{{{
/**
* Generates the fields list of an SQL query.
*
* @param Model $model
* @param string $alias Alias tablename
* @param mixed $fields
* @param boolean $quote If false, returns fields array unquoted
* @return array
*/
function fields(&$model, $alias = null, $fields = array(), $quote
= true) {
if (empty($alias)) {
$alias = $model->alias;
}
if (empty($fields)) {
$fields = array_keys($model->schema());
} elseif (!is_array($fields)) {
$fields = String::tokenize($fields);
}
$fields = array_values(array_filter($fields));
if (!$quote) {
return $fields;
}
$count = count($fields);
if ($count >= 1 && !in_array($fields[0], array('*',
'COUNT(*)'))) {
for ($i = 0; $i < $count; $i++) {
if (!preg_match('/^.+\\(.*\\)/',
$fields[$i])) {
$prepend = '';
if (strpos($fields[$i],
'DISTINCT') !== false) {
$prepend = 'DISTINCT ';
$fields[$i] =
trim(str_replace('DISTINCT', '', $fields[$i]));
}
$dot = strpos($fields[$i], '.');
if ($dot === false) {
$fields[$i] =
$this->name($alias . '.' . $fields[$i]);
} else {
$value = array();
$comma =
strpos($fields[$i], ',');
if ($comma === false) {
$build =
explode('.', $fields[$i]);
if
(!Set::numeric($build)) {
$fields[$i] = $this->name($build[0] . '.' . $build[1]);
}
$comma =
String::tokenize($fields[$i]);
foreach ($comma as
$string) {
if
(preg_match('/^[0-9]+\.[0-9]+$/', $string)) {
$value[] = $string;
} else {
$build = explode('.', $string);
if (trim($build[1]) == "*") {
$tmpmodelname =
str_replace($this->startQuote, '', $build[0]);
$tmpmodelname =
trim(str_replace($this->endQuote, '', $tmpmodelname));
if ($model->name != $tmpmodelname)
{
$tmpmodel =&
ClassRegistry::init($tmpmodelname);
$value = array_merge($value,
$this->fields($tmpmodel));
}
else {
$value = array_merge($value,
$this->fields($model));
}
//$value[] =
$this->name(trim($build[0]) . '.' . trim($build[1]));
}
else {
$value[] =
$this->name(trim($build[0]) . '.' . trim($build[1]));
}
}
}
$fields[$i] =
implode(', ', $value);
}
}
$fields[$i] = $prepend .
$fields[$i];
} elseif (preg_match('/\(([\.\w]+)\)/',
$fields[$i], $field)) {
if (isset($field[1])) {
if (strpos($field[1], '.')
=== false) {
$field[1] =
$this->name($alias . '.' . $field[1]);
} else {
$field[0] =
explode('.', $field[1]);
if
(!Set::numeric($field[0])) {
$field[0]
= join('.', array_map(array($this, 'name'), $field[0]));
$fields[$i] = preg_replace('/\(' . $field[1] . '\)/', '(' . $field[0] .
')', $fields[$i], 1);
}
}
}
}
}
}
else if ($count >= 1 && $fields[0] =='*') {
return $this->fields($model);
}
return array_unique($fields);
}
}}}
What do you think?
--
Ticket URL: <https://trac.cakephp.org/ticket/3003#comment:20>
CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/>
Cake is a rapid development framework for PHP which uses commonly known design
patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC.
Our primary goal is to provide a structured framework that enables PHP users at
all levels to rapidly develop robust web applications, without any loss to
flexibility.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"tickets cakephp" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/tickets-cakephp?hl=en
-~----------~----~----~----~------~----~------~--~---